summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2019-04-24 10:46:39 +0100
committerNick Alcock <nick.alcock@oracle.com>2019-05-28 17:08:08 +0100
commit143dce8481f09f60704ab52b98cf8fe6d8b29fc9 (patch)
tree0c7fdc61341278f34fc4e0e6d7cce936971ec3dc /include
parent9402cc593f4aa54677203efa9a92c4f28d3033eb (diff)
downloadbinutils-gdb-143dce8481f09f60704ab52b98cf8fe6d8b29fc9.tar.gz
libctf: ELF file opening via BFD
These functions let you open an ELF file with a customarily-named CTF section in it, automatically opening the CTF file or archive and associating the symbol and string tables in the ELF file with the CTF container, so that you can look up the types of symbols in the ELF file via ctf_lookup_by_symbol(), and so that strings can be shared between the ELF file and CTF container, to save space. It uses BFD machinery to do so. This has now been lightly tested and seems to work. In particular, if you already have a bfd you can pass it in to ctf_bfdopen(), and if you want a bfd made for you you can call ctf_open() or ctf_fdopen(), optionally specifying a target (or try once without a target and then again with one if you get ECTF_BFD_AMBIGUOUS back). We use a forward declaration for the struct bfd in ctf-api.h, so that ctf-api.h users are not required to pull in <bfd.h>. (This is mostly for the sake of readelf.) libctf/ * ctf-open-bfd.c: New file. * ctf-open.c (ctf_close): New. * ctf-impl.h: Include bfd.h. (ctf_file): New members ctf_data_mmapped, ctf_data_mmapped_len. (ctf_archive_internal): New members ctfi_abfd, ctfi_data, ctfi_bfd_close. (ctf_bfdopen_ctfsect): New declaration. (_CTF_SECTION): likewise. include/ * ctf-api.h (struct bfd): New forward. (ctf_fdopen): New. (ctf_bfdopen): Likewise. (ctf_open): Likewise. (ctf_arc_open): Likewise.
Diffstat (limited to 'include')
-rw-r--r--include/ChangeLog8
-rw-r--r--include/ctf-api.h20
2 files changed, 28 insertions, 0 deletions
diff --git a/include/ChangeLog b/include/ChangeLog
index fb7bd884aa4..e8e80f872fc 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,5 +1,13 @@
2019-05-28 Nick Alcock <nick.alcock@oracle.com>
+ * ctf-api.h (struct bfd): New forward.
+ (ctf_fdopen): New.
+ (ctf_bfdopen): Likewise.
+ (ctf_open): Likewise.
+ (ctf_arc_open): Likewise.
+
+2019-05-28 Nick Alcock <nick.alcock@oracle.com>
+
* ctf.h (CTFA_MAGIC): New.
(struct ctf_archive): New.
(struct ctf_archive_modent): Likewise.
diff --git a/include/ctf-api.h b/include/ctf-api.h
index 4cac635e57e..ee68efefe37 100644
--- a/include/ctf-api.h
+++ b/include/ctf-api.h
@@ -45,6 +45,11 @@ typedef struct ctf_file ctf_file_t;
typedef struct ctf_archive_internal ctf_archive_t;
typedef long ctf_id_t;
+/* This opaque definition allows libctf to accept BFD data structures without
+ importing all the BFD noise into users' namespaces. */
+
+struct bfd;
+
/* If the debugger needs to provide the CTF library with a set of raw buffers
for use as the CTF data, symbol table, and string table, it can do so by
filling in ctf_sect_t structures and passing them to ctf_bufopen().
@@ -205,8 +210,23 @@ typedef int ctf_archive_member_f (ctf_file_t *fp, const char *name, void *arg);
typedef int ctf_archive_raw_member_f (const char *name, const void *content,
size_t len, void *arg);
+/* Opening. These mostly return an abstraction over both CTF files and CTF
+ archives: so they can be used to open both. CTF files will appear to be an
+ archive with one member named '.ctf'. The low-level functions
+ ctf_simple_open() and ctf_bufopen() return ctf_file_t's directly, and cannot
+ be used on CTF archives. */
+
+extern ctf_archive_t *ctf_bfdopen (struct bfd *, int *);
+extern ctf_archive_t *ctf_bfdopen_ctfsect (struct bfd *, const ctf_sect_t *,
+ int *);
+extern ctf_archive_t *ctf_fdopen (int fd, const char *filename,
+ const char *target, int *errp);
+extern ctf_archive_t *ctf_open (const char *filename,
+ const char *target, int *errp);
+extern void ctf_close (ctf_archive_t *);
extern ctf_sect_t ctf_getdatasect (const ctf_file_t *);
extern ctf_archive_t *ctf_get_arc (const ctf_file_t *);
+extern ctf_archive_t *ctf_arc_open (const char *, int *);
extern void ctf_arc_close (ctf_archive_t *);
extern ctf_file_t *ctf_arc_open_by_name (const ctf_archive_t *,
const char *, int *);