diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2020-11-20 13:34:04 +0000 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2020-11-20 13:34:11 +0000 |
commit | 2c78e92523a650c9cbd68130ce8a766570457cd6 (patch) | |
tree | 6733095bc7e3c14c32cebda4235f3756123e7e7a /include | |
parent | 0e28ade476e20bd8af917e01a3f1429a34cc1d83 (diff) | |
download | gdb-2c78e92523a650c9cbd68130ce8a766570457cd6.zip gdb-2c78e92523a650c9cbd68130ce8a766570457cd6.tar.gz gdb-2c78e92523a650c9cbd68130ce8a766570457cd6.tar.bz2 |
libctf, include: CTF-archive-wide symbol lookup
CTF archives may contain multiple dicts, each of which contain many
types and possibly a bunch of symtypetab entries relating to those
types: each symtypetab entry is going to appear in exactly one dict,
with the corresponding entries in the other dicts empty (either pads, or
indexed symtypetabs that do not mention that symbol). But users of
libctf usually want to get back the type associated with a symbol
without having to dig around to find out which dict that type might be
in.
This adds machinery to do that -- and since you probably want to do it
repeatedly, it adds internal caching to the ctf-archive machinery so
that iteration over archives via ctf_archive_next and repeated symbol
lookups do not have to repeatedly reopen the archive. (Iteration using
ctf_archive_iter will gain caching soon.)
Two new API functions:
ctf_dict_t *
ctf_arc_lookup_symbol (ctf_archive_t *arc, unsigned long symidx,
ctf_id_t *typep, int *errp);
This looks up the symbol with index SYMIDX in the archive ARC, returning
the dictionary in which it resides and optionally the type index as
well. Errors are returned in ERRP. The dict should be
ctf_dict_close()d when done, but is also cached inside the ctf_archive
so that the open cost is only paid once. The result of the symbol
lookup is also cached internally, so repeated lookups of the same symbol
are nearly free.
void ctf_arc_flush_caches (ctf_archive_t *arc);
Flush all the caches. Done at close time, but also available as an API
function if users want to do it by hand.
include/ChangeLog
2020-11-20 Nick Alcock <nick.alcock@oracle.com>
* ctf-api.h (ctf_arc_lookup_symbol): New.
(ctf_arc_flush_caches): Likewise.
* ctf.h: Document new auto-ctf_import behaviour.
libctf/ChangeLog
2020-11-20 Nick Alcock <nick.alcock@oracle.com>
* ctf-impl.h (struct ctf_archive_internal) <ctfi_dicts>: New, dicts
the archive machinery has opened and cached.
<ctfi_symdicts>: New, cache of dicts containing symbols looked up.
<ctfi_syms>: New, cache of types of symbols looked up.
* ctf-archive.c (ctf_arc_close): Free them on close.
(enosym): New, flag entry for 'symbol not present'.
(ctf_arc_import_parent): New, automatically import the parent from
".ctf" if this is a child in an archive and ".ctf" is present.
(ctf_dict_open_sections): Use it.
(ctf_archive_iter_internal): Likewise.
(ctf_cached_dict_close): New, thunk around ctf_dict_close.
(ctf_dict_open_cached): New, open and cache a dict.
(ctf_arc_flush_caches): New, flush the caches.
(ctf_arc_lookup_symbol): New, look up a symbol in (all members of)
an archive, and cache the lookup.
(ctf_archive_iter): Note the new caching behaviour.
(ctf_archive_next): Use ctf_dict_open_cached.
* libctf.ver: Add ctf_arc_lookup_symbol and ctf_arc_flush_caches.
Diffstat (limited to 'include')
-rw-r--r-- | include/ChangeLog | 6 | ||||
-rw-r--r-- | include/ctf-api.h | 6 | ||||
-rw-r--r-- | include/ctf.h | 9 |
3 files changed, 18 insertions, 3 deletions
diff --git a/include/ChangeLog b/include/ChangeLog index ad4c8a6..1d4eac9 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,5 +1,11 @@ 2020-11-20 Nick Alcock <nick.alcock@oracle.com> + * ctf-api.h (ctf_arc_lookup_symbol): New. + (ctf_arc_flush_caches): Likewise. + * ctf.h: Document new auto-ctf_import behaviour. + +2020-11-20 Nick Alcock <nick.alcock@oracle.com> + * ctf-api.h (ctf_symbol_next): New. (ctf_add_objt_sym): Likewise. (ctf_add_func_sym): Likewise. diff --git a/include/ctf-api.h b/include/ctf-api.h index 6dd37b9..f0c00c0 100644 --- a/include/ctf-api.h +++ b/include/ctf-api.h @@ -109,7 +109,9 @@ typedef enum ctf_sect_names CTF_SECT_HEADER, CTF_SECT_LABEL, CTF_SECT_OBJT, + CTF_SECT_OBJTIDX = CTF_SECT_OBJT, CTF_SECT_FUNC, + CTF_SECT_FUNCIDX = CTF_SECT_FUNC, CTF_SECT_VAR, CTF_SECT_TYPE, CTF_SECT_STR @@ -312,6 +314,10 @@ extern ctf_archive_t *ctf_arc_bufopen (const ctf_sect_t *, const ctf_sect_t *, int *); extern void ctf_arc_close (ctf_archive_t *); +extern ctf_dict_t *ctf_arc_lookup_symbol (ctf_archive_t *, + unsigned long symidx, + ctf_id_t *, int *errp); +extern void ctf_arc_flush_caches (ctf_archive_t *); extern ctf_dict_t *ctf_dict_open (const ctf_archive_t *, const char *, int *); extern ctf_dict_t *ctf_dict_open_sections (const ctf_archive_t *, diff --git a/include/ctf.h b/include/ctf.h index c7a1e43..0800287 100644 --- a/include/ctf.h +++ b/include/ctf.h @@ -116,9 +116,12 @@ extern "C" and libctf library are responsible for connecting the appropriate objects together so that the full set of types can be explored and manipulated. - This connection is done purely using the ctf_import() function. There is no - notation anywhere in the child CTF file indicating which parent it is - connected to: it is the debugger's responsibility to track this. */ + This connection is done purely using the ctf_import() function. The + ctf_archive machinery (and thus ctf_open et al) automatically imports archive + members named ".ctf" into child dicts if available in the same archive, to + match the relationship set up by the linker, but callers can call ctf_import + themselves as well if need be, if they know a different relationship is in + force. */ #define CTF_MAX_TYPE 0xfffffffe /* Max type identifier value. */ #define CTF_MAX_PTYPE 0x7fffffff /* Max parent type identifier value. */ |