aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorJim Blandy <jimb@codesourcery.com>1999-11-29 20:33:38 +0000
committerJim Blandy <jimb@codesourcery.com>1999-11-29 20:33:38 +0000
commit98d8431c7d2f12be9f39abae99af3f8e8efc524d (patch)
treed5a36252de8615ab8e8e953db2cd6d45d16d9ea2 /bfd
parenta64bcdd8d378b892077d2a9ba108f310fa2b9e5b (diff)
downloadgdb-98d8431c7d2f12be9f39abae99af3f8e8efc524d.zip
gdb-98d8431c7d2f12be9f39abae99af3f8e8efc524d.tar.gz
gdb-98d8431c7d2f12be9f39abae99af3f8e8efc524d.tar.bz2
* elf.c (bfd_get_elf_phdrs, bfd_get_elf_phdr_upper_bound): New
functions. * bfd-in2.h (bfd_get_elf_phdrs, bfd_get_elf_phdr_upper_bound): New declarations.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog7
-rw-r--r--bfd/bfd-in2.h16
-rw-r--r--bfd/elf.c48
3 files changed, 71 insertions, 0 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 2a2ff7b..ec7e767 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+1999-11-29 Jim Blandy <jimb@cygnus.com>
+
+ * elf.c (bfd_get_elf_phdrs, bfd_get_elf_phdr_upper_bound): New
+ functions.
+ * bfd-in2.h (bfd_get_elf_phdrs, bfd_get_elf_phdr_upper_bound): New
+ declarations.
+
1999-11-27 Michael Meissner <meissner@cygnus.com>
* reloc.c (BFD_RELOC_ALPHA_USER_LITERAL): New relocation for
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 9fe0cfb..50539b124 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -3091,6 +3091,22 @@ bfd_set_format PARAMS ((bfd *abfd, bfd_format format));
CONST char *
bfd_format_string PARAMS ((bfd_format format));
+
+/* Return an upper bound on the number of bytes required to store a
+ copy of ABFD's program header table entries. Return -1 if an error
+ occurs; bfd_get_error will return an appropriate code. */
+extern long bfd_get_elf_phdr_upper_bound PARAMS ((bfd *abfd));
+
+/* Copy ABFD's program header table entries to *PHDRS. The entries
+ will be stored as an array of Elf_Internal_Phdr structures, as
+ defined in include/elf/internal.h. To find out how large the
+ buffer needs to be, call bfd_get_elf_phdr_upper_bound.
+
+ Return the number of program header table entries read, or -1 if an
+ error occurs; bfd_get_error will return an appropriate code. */
+extern int bfd_get_elf_phdrs PARAMS ((bfd *abfd, void *phdrs));
+
+
#ifdef __cplusplus
}
#endif
diff --git a/bfd/elf.c b/bfd/elf.c
index d957476..4dc87af 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -5359,3 +5359,51 @@ _bfd_elfcore_section_from_phdr (abfd, phdr, sec_num)
return true;
}
+
+
+/* Providing external access to the ELF program header table. */
+
+/* Return an upper bound on the number of bytes required to store a
+ copy of ABFD's program header table entries. Return -1 if an error
+ occurs; bfd_get_error will return an appropriate code. */
+long
+bfd_get_elf_phdr_upper_bound (abfd)
+ bfd *abfd;
+{
+ if (abfd->xvec->flavour != bfd_target_elf_flavour)
+ {
+ bfd_set_error (bfd_error_wrong_format);
+ return -1;
+ }
+
+ return (elf_elfheader (abfd)->e_phnum
+ * sizeof (Elf_Internal_Phdr));
+}
+
+
+/* Copy ABFD's program header table entries to *PHDRS. The entries
+ will be stored as an array of Elf_Internal_Phdr structures, as
+ defined in include/elf/internal.h. To find out how large the
+ buffer needs to be, call bfd_get_elf_phdr_upper_bound.
+
+ Return the number of program header table entries read, or -1 if an
+ error occurs; bfd_get_error will return an appropriate code. */
+int
+bfd_get_elf_phdrs (abfd, phdrs)
+ bfd *abfd;
+ void *phdrs;
+{
+ int num_phdrs;
+
+ if (abfd->xvec->flavour != bfd_target_elf_flavour)
+ {
+ bfd_set_error (bfd_error_wrong_format);
+ return -1;
+ }
+
+ num_phdrs = elf_elfheader (abfd)->e_phnum;
+ memcpy (phdrs, elf_tdata (abfd)->phdr,
+ num_phdrs * sizeof (Elf_Internal_Phdr));
+
+ return num_phdrs;
+}