mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2026-08-27 00:26:02 -04:00
The v4 symtypetab design is quite different from v3. Where v3 has a pair
of possibly indexed symtypetabs per dict, v4 uses a pair of symtypetabs
in two ELF sections, one per ELF object: one has straight ctf_id_t's in
it and relates to the parent dict, the other a pair of (index, ctF_id_t)
relating to other dicts. The symtypetab is always indexed: the old 1:1
"like the symtab if the symtypetab only contained STT_FUNC and
STT_OBJECT symbols, with some symbols dropped" scheme is gone entirely,
and with it all the arbitrary decisions that went with it (when to use
indexed versus 1:1 representation, which symbols to skip, etc) and its
fragility (if a single symbol is assigned to the wrong table, disaster
results: see commit 211bcd0133 for an example of this biting in real
life).
As a first phase, unify the object and function info sections and drop
the indexed/non-indexed representation. Symtypetab support in the
resulting library doesn't work any more, but it didn't work before now
in v4 anyway, so this is no loss. Future commits will fix this.
Also drop all the caching machinery for symbol lookups: it's only there
because we might need to consult many symtypetabs to look up types of
symbols in child dicts, which will no longer be true after these
changes.
(API changes introduced by this series will be indicated in the last
commit in the series.)
1416 lines
60 KiB
C
1416 lines
60 KiB
C
/* Public API to libctf.
|
|
Copyright (C) 2019-2025 Free Software Foundation, Inc.
|
|
|
|
This file is part of libctf.
|
|
|
|
libctf is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free
|
|
Software Foundation; either version 3, or (at your option) any later
|
|
version.
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; see the file COPYING. If not see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
/* This header file defines the interfaces available from the CTF debugger
|
|
library, libctf. This API can be used by a debugger to operate on data in
|
|
the Compact ANSI-C Type Format (CTF). */
|
|
|
|
#ifndef _CTF_API_H
|
|
#define _CTF_API_H
|
|
|
|
#include <sys/types.h>
|
|
#include <inttypes.h>
|
|
#include <ctf.h>
|
|
#include <zlib.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
#ifndef __libctf_attribute_deprecated__
|
|
# if defined (__GNUC__) && !defined(IN_LIBCTF)
|
|
# define __libctf_attribute_deprecated__(x) __attribute__((__deprecated__(x)))
|
|
# else
|
|
# define __libctf_attribute_deprecated__(x)
|
|
# endif
|
|
#endif
|
|
|
|
/* Version of the libctf API. */
|
|
|
|
#define LIBCTF_API_VERSION 2
|
|
|
|
/* Clients can open one or more CTF containers and obtain a pointer to an
|
|
opaque ctf_dict_t. Types are identified by an opaque ctf_id_t token.
|
|
They can also open or create read-only archives of CTF containers in a
|
|
ctf_archive_t.
|
|
|
|
These opaque definitions allow libctf to evolve without breaking clients. */
|
|
|
|
typedef struct ctf_dict ctf_dict_t;
|
|
typedef struct ctf_archive_internal ctf_archive_t;
|
|
typedef unsigned long ctf_id_t;
|
|
|
|
/* This typedef indicates that a function returns zero or negative on error. */
|
|
typedef int ctf_ret_t;
|
|
|
|
/* This typedef indicates that a function return 0 or 1, or negative on error. */
|
|
typedef int ctf_bool_t;
|
|
|
|
/* This typedef indiicates that a function returns a CTF error code, or an errno
|
|
value, or zero, on error (or takes one). C can make this an enum type: C++
|
|
must resort to int, because the type includes many values not in the enum
|
|
(all valid errnos, for instance). Similar patterns are seen for many flags
|
|
enums below, because we want to be able to pass 0 to mean "no flags set". */
|
|
|
|
#ifdef __cplusplus
|
|
typedef int ctf_error_t;
|
|
#endif
|
|
|
|
/* This opaque definition allows libctf to accept BFD data structures without
|
|
importing all the BFD noise into users' namespaces. */
|
|
|
|
struct bfd;
|
|
|
|
/* Symbolic names for CTF sections. */
|
|
|
|
typedef enum ctf_sect_names
|
|
{
|
|
CTF_SECT_HEADER,
|
|
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
|
|
} ctf_sect_names_t;
|
|
|
|
/* Symbolic names for ELF sections associated with CTF. */
|
|
typedef enum ctf_elfsect_names
|
|
{
|
|
CTF_ELF_SECT, /* The .ctf section. */
|
|
CTF_ELF_SYMSECT, /* The associated symtab. */
|
|
CTF_ELF_STRSECT, /* The ELF string table. */
|
|
} ctf_elfsect_names_t;
|
|
|
|
/* 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 et al via
|
|
the ctf_open_sect_t function.
|
|
|
|
At read time, the symbol table endianness is derived from the BFD target
|
|
(if BFD is in use): if a BFD target is not in use, please call
|
|
ctf_arc_symsect_endianness. */
|
|
|
|
typedef struct ctf_sect
|
|
{
|
|
/* Used by ctf_open_sect et al. Must be zero-initialized. */
|
|
struct
|
|
{
|
|
void *reserved1;
|
|
void *reserved2;
|
|
} reserved;
|
|
|
|
ctf_elfsect_names_t cts_section; /* ELF section this corresponds to. */
|
|
const char *cts_name; /* Section name (if any). */
|
|
const void *cts_data; /* Pointer to section data. */
|
|
size_t cts_size; /* Size of data in bytes. */
|
|
size_t cts_entsize; /* Size of each section entry (symtab only). */
|
|
} ctf_sect_t;
|
|
|
|
/* A minimal symbol extracted from a linker's internal symbol table
|
|
representation. The symbol name can be given either via st_name or via a
|
|
strtab offset in st_nameidx, which corresponds to one of the string offsets
|
|
communicated via the ctf_link_add_strtab callback. */
|
|
|
|
typedef struct ctf_link_sym
|
|
{
|
|
/* The st_name and st_nameidx will not be accessed outside the call to
|
|
ctf_link_shuffle_syms. If you set st_nameidx to offset zero, make sure
|
|
to set st_nameidx_set as well. */
|
|
|
|
const char *st_name;
|
|
size_t st_nameidx;
|
|
int st_nameidx_set;
|
|
uint32_t st_symidx;
|
|
uint32_t st_shndx;
|
|
uint32_t st_type;
|
|
uint32_t st_value;
|
|
} ctf_link_sym_t;
|
|
|
|
/* Flags applying to this specific link. */
|
|
|
|
#ifndef __cplusplus
|
|
typedef
|
|
#endif
|
|
enum ctf_link_flags
|
|
{
|
|
/* Share all types that are not in conflict. The default. */
|
|
CTF_LINK_SHARE_UNCONFLICTED = 0x0,
|
|
|
|
/* Share only types that are used by multiple inputs. */
|
|
CTF_LINK_SHARE_DUPLICATED = 0x1,
|
|
|
|
/* Do a nondeduplicating link, or otherwise deduplicate "less hard", trading
|
|
off CTF output size for link time. */
|
|
CTF_LINK_NONDEDUP = 0x2,
|
|
|
|
/* Create empty outputs for all registered CU mappings even if no types are
|
|
emitted into them. */
|
|
CTF_LINK_EMPTY_CU_MAPPINGS = 0x4,
|
|
|
|
/* Omit the content of the variables section. */
|
|
CTF_LINK_OMIT_VARIABLES_SECTION = 0x8,
|
|
|
|
/* If *unset*, filter out entries corresponding to linker-reported symbols
|
|
from the variable section, and filter out all entries with no
|
|
linker-reported symbols from the data object and function info sections:
|
|
if set, do no filtering and leave all entries in place. (This is a
|
|
negative-sense flag because it is rare to want symbols the linker has not
|
|
reported as present to stick around in the symtypetab sections
|
|
nonetheless: relocatable links are the only likely case.) */
|
|
|
|
CTF_LINK_NO_FILTER_REPORTED_SYMS = 0x10,
|
|
|
|
/* Dedup all archives but the first added against the first added.
|
|
ctf_link_against() automatically enables this. */
|
|
|
|
CTF_LINK_DEDUP_AGAINST_FIRST = 0x20
|
|
|
|
#ifndef __cplusplus
|
|
} ctf_link_flags_t;
|
|
#else
|
|
};
|
|
typedef int ctf_link_flags_t;
|
|
#endif
|
|
|
|
/* Encoding information for integers, floating-point values, and certain other
|
|
intrinsics can be obtained by calling ctf_type_encoding, below. The flags
|
|
field will contain values appropriate for the type defined in <ctf.h>.
|
|
|
|
For floats, only the first of these fields is meaningful. */
|
|
|
|
typedef struct ctf_encoding
|
|
{
|
|
uint32_t cte_format; /* Data format (CTF_INT_* or CTF_FP_* flags). */
|
|
uint32_t cte_offset; /* Offset of value in bits. */
|
|
uint32_t cte_bits; /* Size of storage in bits. */
|
|
} ctf_encoding_t;
|
|
|
|
/* "Not bitfield" here really means "not recorded as a bitfield in the
|
|
structure". ctf_type_encoding() may reveal that the base type or an
|
|
intervening slice has bitfield encoding nonetheless. */
|
|
|
|
typedef struct ctf_membinfo
|
|
{
|
|
ctf_id_t ctm_type; /* Type of struct or union member. */
|
|
size_t ctm_offset; /* Offset of member in bits. */
|
|
int ctm_bit_width; /* Width of member in bits: -1: not bitfield */
|
|
} ctf_membinfo_t;
|
|
|
|
typedef struct ctf_arinfo
|
|
{
|
|
ctf_id_t ctr_contents; /* Type of array contents. */
|
|
ctf_id_t ctr_index; /* Type of array index. */
|
|
size_t ctr_nelems; /* Number of elements. */
|
|
} ctf_arinfo_t;
|
|
|
|
typedef struct ctf_enum_value /* The value of an enumerator. Can just be
|
|
cast to an int/int64 if you like. */
|
|
{
|
|
#if !defined (__GNUC__) || !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L
|
|
#ifdef __GNUC__
|
|
__extension__
|
|
#endif
|
|
union
|
|
{
|
|
int64_t val;
|
|
uint64_t uval;
|
|
};
|
|
#else
|
|
union
|
|
{
|
|
int64_t val;
|
|
uint64_t uval;
|
|
} val;
|
|
#endif
|
|
ctf_encoding_t encoding;
|
|
} ctf_enum_value_t;
|
|
|
|
typedef struct ctf_snapshot_id
|
|
{
|
|
uint32_t dtd_id; /* Highest DTD ID at time of snapshot. */
|
|
uint32_t snapshot_id; /* Snapshot id at time of snapshot. */
|
|
|
|
/* Parent provisional-type state at snapshot time. */
|
|
|
|
uint32_t provtypemax;
|
|
uint32_t nprovtypes;
|
|
uint32_t idmax;
|
|
} ctf_snapshot_id_t;
|
|
|
|
#ifndef __cplusplus
|
|
typedef
|
|
#endif
|
|
enum ctf_func_type_flags
|
|
{
|
|
CTF_FUNC_VARARG = 0x1 /* Function arguments end with varargs. */
|
|
#ifndef __cplusplus
|
|
} ctf_func_type_flags_t;
|
|
#else
|
|
};
|
|
typedef int ctf_func_type_flags_t;
|
|
#endif
|
|
|
|
/* Functions that return a ctf_id_t use the following value to indicate failure.
|
|
ctf_errno can be used to obtain an error code. Functions that return
|
|
a straight integral -1 also use ctf_errno. */
|
|
#define CTF_ERR ((ctf_id_t) -1L)
|
|
|
|
/* Likewise, for return from ctf_member_next. */
|
|
#define CTF_MEMBER_ERR ((size_t) -1L)
|
|
|
|
/* Likewise, for size_t offset *inputs* which can also be 'next available member'
|
|
(for documentation purposes). */
|
|
#define CTF_NEXT_MEMBER ((size_t) -1L)
|
|
|
|
/* This macro holds information about all the available ctf errors.
|
|
It is used to form both an enum holding all the error constants,
|
|
and also the error strings themselves. To use, define _CTF_FIRST
|
|
and _CTF_ITEM to expand as you like, then mention the macro name.
|
|
See the enum after this for an example. */
|
|
#define _CTF_ERRORS \
|
|
_CTF_FIRST (ECTF_NEXT_END, "end of iteration") \
|
|
_CTF_ITEM (ECTF_FMT, "file is not in CTF or ELF format") \
|
|
_CTF_ITEM (ECTF_BFDERR, "BFD error") \
|
|
_CTF_ITEM (ECTF_CTFVERS, "BTF/CTF dict version is too new for libctf") \
|
|
_CTF_ITEM (ECTF_BFD_AMBIGUOUS, "ambiguous BFD target") \
|
|
_CTF_ITEM (ECTF_SYMTAB, "symbol table uses invalid entry size") \
|
|
_CTF_ITEM (ECTF_SYMBAD, "symbol table data buffer is not valid") \
|
|
_CTF_ITEM (ECTF_STRBAD, "string table data buffer is not valid") \
|
|
_CTF_ITEM (ECTF_CORRUPT, "file data structure corruption detected") \
|
|
_CTF_ITEM (ECTF_NOCTFDATA, "no .ctf or .BTF section") \
|
|
_CTF_ITEM (ECTF_NOCTFBUF, "buffer does not contain CTF data") \
|
|
_CTF_ITEM (ECTF_NOSYMTAB, "symbol table information is not available") \
|
|
_CTF_ITEM (ECTF_NOPARENT, "the parent CTF dictionary is needed but unavailable") \
|
|
_CTF_ITEM (ECTF_LINKADDEDLATE, "file added to link too late") \
|
|
_CTF_ITEM (ECTF_ZALLOC, "failed to allocate (de)compression buffer") \
|
|
_CTF_ITEM (ECTF_DECOMPRESS, "failed to decompress CTF data") \
|
|
_CTF_ITEM (ECTF_STRTAB, "external string table is not available") \
|
|
_CTF_ITEM (ECTF_BADNAME, "string name offset is corrupt") \
|
|
_CTF_ITEM (ECTF_BADID, "invalid type identifier") \
|
|
_CTF_ITEM (ECTF_WRONGKIND, "inappropriate type kind") \
|
|
_CTF_ITEM (ECTF_NOTREF, "type does not reference another type") \
|
|
_CTF_ITEM (ECTF_NAMELEN, "buffer is too small to hold type name") \
|
|
_CTF_ITEM (ECTF_NOTYPE, "no type found corresponding to name, type ID, or offset") \
|
|
_CTF_ITEM (ECTF_SYNTAX, "syntax error in type name") \
|
|
_CTF_ITEM (ECTF_NOTFUNC, "symbol table entry or type is not a function") \
|
|
_CTF_ITEM (ECTF_NOFUNCDAT, "no function information available for function") \
|
|
_CTF_ITEM (ECTF_NOTDATA, "symbol table entry does not refer to a data object") \
|
|
_CTF_ITEM (ECTF_NOTYPEDAT, "no type information available for symbol") \
|
|
_CTF_ITEM (ECTF_NOTSUP, "feature not supported") \
|
|
_CTF_ITEM (ECTF_RDONLY, "CTF dict is read-only") \
|
|
_CTF_ITEM (ECTF_FULL, "implementation limit: CTF dict or type is full") \
|
|
_CTF_ITEM (ECTF_DUPLICATE, "duplicate member, enumerator, datasec, or variable name") \
|
|
_CTF_ITEM (ECTF_CONFLICT, "conflicting type is already defined") \
|
|
_CTF_ITEM (ECTF_COMPRESS, "failed to compress CTF data") \
|
|
_CTF_ITEM (ECTF_ARCREATE, "error creating CTF archive") \
|
|
_CTF_ITEM (ECTF_ARNNAME, "name not found in CTF archive") \
|
|
_CTF_ITEM (ECTF_SLICEOVERFLOW, "overflow of type bitness or offset in slice") \
|
|
_CTF_ITEM (ECTF_DUMPSECTUNKNOWN, "unknown section number in dump") \
|
|
_CTF_ITEM (ECTF_DUMPSECTCHANGED, "section changed in middle of dump") \
|
|
_CTF_ITEM (ECTF_NOTYET, "feature not yet implemented") \
|
|
_CTF_ITEM (ECTF_INTERNAL, "internal error: assertion failure") \
|
|
_CTF_ITEM (ECTF_NONREPRESENTABLE, "type not representable in CTF") \
|
|
_CTF_ITEM (ECTF_NEXT_WRONGFUN, "wrong iteration function called") \
|
|
_CTF_ITEM (ECTF_NEXT_WRONGFP, "iteration entity changed in mid-iterate") \
|
|
_CTF_ITEM (ECTF_FLAGS, "CTF header contains flags unknown to libctf") \
|
|
_CTF_ITEM (ECTF_NEEDSBFD, "this feature needs a libctf with BFD support") \
|
|
_CTF_ITEM (ECTF_INCOMPLETE, "type is not a complete type") \
|
|
_CTF_ITEM (ECTF_NONAME, "invalid or nonexistent name") \
|
|
_CTF_ITEM (ECTF_BADFLAG, "invalid CTF dict flag specified") \
|
|
_CTF_ITEM (ECTF_CTFVERS_NO_SERIALIZE, "CTFv1 dicts are too old to serialize") \
|
|
_CTF_ITEM (ECTF_UNSTABLE, "attempt to write unstable file format version: set I_KNOW_LIBCTF_IS_UNSTABLE in the environment") \
|
|
_CTF_ITEM (ECTF_WRONGPARENT, "incorrect parent provided") \
|
|
_CTF_ITEM (ECTF_NOTSERIALIZED, "CTF dict must be serialized first") \
|
|
_CTF_ITEM (ECTF_BADCOMPONENT, "declaration tag component_idx is invalid") \
|
|
_CTF_ITEM (ECTF_DESCENDING, "structure offsets may not descend") \
|
|
_CTF_ITEM (ECTF_LINKAGE, "invalid linkage") \
|
|
_CTF_ITEM (ECTF_LINKKIND, "only functions and variables have linkage") \
|
|
_CTF_ITEM (ECTF_KIND_PROHIBITED, "writeout of suppressed kind attempted") \
|
|
_CTF_ITEM (ECTF_NOTBTF, "cannot write out this dict as BTF") \
|
|
_CTF_ITEM (ECTF_TOOLARGE, "prefix required for correct representation")
|
|
|
|
#define ECTF_BASE 1000 /* Base value for libctf errnos. */
|
|
|
|
/* Despite being an enum, this is a superset of errno, and all values are
|
|
potentially valid. */
|
|
#ifndef __cplusplus
|
|
typedef
|
|
#endif
|
|
enum
|
|
{
|
|
#define _CTF_FIRST(NAME, STR) NAME = ECTF_BASE
|
|
#define _CTF_ITEM(NAME, STR) , NAME
|
|
_CTF_ERRORS
|
|
#undef _CTF_ITEM
|
|
#undef _CTF_FIRST
|
|
#ifndef __cplusplus
|
|
} ctf_error_t;
|
|
#else
|
|
};
|
|
#endif
|
|
|
|
#define ECTF_NERR (ECTF_TOOLARGE - ECTF_BASE + 1) /* Count of CTF errors. */
|
|
|
|
/* The CTF data model is inferred to be the caller's data model or the data
|
|
model of the given object, unless ctf_setmodel is explicitly called. */
|
|
typedef enum ctf_model
|
|
{
|
|
CTF_MODEL_ILP32 = 1, /* Object data model is ILP32. */
|
|
CTF_MODEL_LP64 = 2, /* Object data model is LP64. */
|
|
#ifdef _LP64
|
|
CTF_MODEL_NATIVE = CTF_MODEL_LP64
|
|
#else
|
|
CTF_MODEL_NATIVE = CTF_MODEL_ILP32
|
|
#endif
|
|
} ctf_model_t;
|
|
|
|
/* Flags for ctf_member_next. */
|
|
|
|
#ifndef __cplusplus
|
|
typedef
|
|
#endif
|
|
enum ctf_member_next_flags
|
|
{
|
|
CTF_MN_RECURSE = 0x1 /* Recurse into unnamed members. */
|
|
#ifndef __cplusplus
|
|
} ctf_member_next_flags_t;
|
|
#else
|
|
};
|
|
typedef int ctf_member_next_flags_t;
|
|
#endif
|
|
|
|
/* Flags for ctf_dict_set_flag. */
|
|
|
|
typedef enum ctf_dict_flags
|
|
{
|
|
/* If set, duplicate enumerators in a single dict fail with
|
|
ECTF_DUPLICATE. */
|
|
CTF_STRICT_NO_DUP_ENUMERATORS = 0x1,
|
|
|
|
/* If set, this dict has at least one symbol -> type mapping. (This flag
|
|
merely reports a property of the dict and cannot be set.) */
|
|
CTF_DICT_HAS_SYMBOL_TYPES = 0x2
|
|
} ctf_dict_flags_t;
|
|
|
|
typedef int ctf_visit_f (ctf_dict_t *, const char *name, ctf_id_t type,
|
|
size_t offset, int bit_width, int depth,
|
|
void *arg);
|
|
typedef char *ctf_dump_decorate_f (ctf_sect_names_t sect,
|
|
char *line, void *arg);
|
|
|
|
typedef struct ctf_dump_state ctf_dump_state_t;
|
|
|
|
/* Iteration state for the _next functions, and allocators/copiers/freers for
|
|
it. (None of these are needed for the simple case of iterating to the end:
|
|
the _next functions allocate and free the iterators for you.)
|
|
|
|
The _next iterators all work in similar ways: they take things to query (a
|
|
dict, a name, a type ID, something like that), then a ctf_next_t iterator
|
|
arg which must be the address of a variable whose value is NULL on first
|
|
call, and will be set to NULL again once iteration has completed.
|
|
|
|
They return something important about the thing being iterated over (often a
|
|
type ID or a name); on end of iteration they instead return return CTF_ERR,
|
|
-1, or NULL and set the error ECTF_NEXT_END on the dict. They can often
|
|
provide more information too: this is done via pointer parameters (e.g. the
|
|
membname and membtype in ctf_member_next()). These parameters are always
|
|
optional and can be set to NULL if not needed.
|
|
|
|
Errors other than end-of-iteration will return CTF_ERR/-1/NULL and set the
|
|
error to something other than ECTF_NEXT_END, and *not* destroy the iterator:
|
|
you should either recover somehow and continue iterating, or call
|
|
ctf_next_destroy() on it. (You can call ctf_next_destroy() on a NULL
|
|
iterator, so it's safe to just unconditionally do it after iteration has
|
|
completed.) */
|
|
|
|
typedef struct ctf_next ctf_next_t;
|
|
extern ctf_next_t *ctf_next_create (void);
|
|
extern void ctf_next_destroy (ctf_next_t *);
|
|
extern ctf_next_t *ctf_next_copy (ctf_next_t *);
|
|
|
|
/* 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'.
|
|
|
|
All these functions except for ctf_close use BFD and can open anything BFD
|
|
can open, hunting down the .ctf section for you, so are not available in the
|
|
libctf-nobfd flavour of the library. If you want to provide some sections
|
|
yourself, you can do that using the optional ctf_open_sect_t argument to
|
|
ctf_bfdopen.
|
|
|
|
Some of these functions take a list of sections, constructed by the
|
|
ctf_open_sect function, which chains together ctf_open_sect_t structs (pass
|
|
the return value of each into the next call). These other sections are
|
|
optional and usually consist of symtab, strtab, and symtypetab sections. If
|
|
you don't pass the right sections in (usually symtypetab and associated
|
|
string and symbol tables linked via sh_link), opening will succeed but things
|
|
like symbol->type lookup will not be available, and the ctf_*_lookup_symbol
|
|
functions will fail with ECTF_NOSYMTAB. The structures returned by
|
|
ctf_open_sect are consumed by the open functions and should not be used
|
|
again. The ctf_sect_t's passed in, and the buffers they wrap, are still
|
|
owned by the caller; the ctf_sect_t's can be freed, but the buffers are in
|
|
use: do not free them until the archive, and all dicts derived from it, are
|
|
closed.
|
|
|
|
We do not define what happens if you pass in multiple sections of the same
|
|
type in ctf_open_sect (this is to enable us to define useful behaviour in the
|
|
future if need be).
|
|
|
|
ctf_open_sect cannot fail and can be called in a nested fashion in the
|
|
argument list of functions taking a ctf_open_sect_t to pass in multiple
|
|
sections easily. */
|
|
|
|
typedef struct ctf_open_sect ctf_open_sect_t;
|
|
extern ctf_open_sect_t *ctf_open_sect (ctf_open_sect_t *, ctf_sect_t *);
|
|
|
|
extern ctf_archive_t *ctf_bfdopen (struct bfd *, ctf_open_sect_t *,
|
|
ctf_error_t *);
|
|
extern ctf_archive_t *ctf_fdopen (int fd, const char *filename,
|
|
const char *target, ctf_error_t *);
|
|
extern ctf_archive_t *ctf_open (const char *filename,
|
|
const char *target, ctf_error_t *);
|
|
extern void ctf_close (ctf_archive_t *);
|
|
|
|
/* Set or unset dict-wide boolean flags, and get the value of these flags. Not
|
|
all flags can be set. */
|
|
|
|
extern ctf_ret_t ctf_dict_set_flag (ctf_dict_t *, ctf_dict_flags_t flag, int set);
|
|
extern ctf_bool_t ctf_dict_flag (ctf_dict_t *, ctf_dict_flags_t flag);
|
|
|
|
/* Return the data, symbol, or string sections used by a given CTF dict. */
|
|
extern ctf_sect_t ctf_elf_sect (const ctf_dict_t *, ctf_elfsect_names_t sect);
|
|
|
|
/* Return the data, symbol, or string sections used by a given CTF archive. */
|
|
extern ctf_sect_t ctf_arc_elf_sect (const ctf_archive_t *, ctf_elfsect_names_t sect);
|
|
|
|
/* Set the endianness of the symbol section, which may be different from
|
|
the endianness of the CTF dict. Done for you by ctf_open and ctf_fdopen,
|
|
but direct calls to ctf_bufopen etc with symbol sections provided must
|
|
do so explicitly. */
|
|
|
|
extern void ctf_arc_symsect_endianness (ctf_archive_t *, int little_endian);
|
|
|
|
/* Open CTF archives from files or raw section data, and close them again.
|
|
Closing may munmap() the data making up the archive, so should not be
|
|
done until all dicts are finished with and closed themselves.
|
|
|
|
Almost all functions that open archives will also open raw CTF dicts, which
|
|
are treated as if they were archives with only one member.
|
|
|
|
Like many other convenient opening functions, ctf_arc_open needs BFD and is
|
|
not available in libctf-nobfd. */
|
|
|
|
extern ctf_archive_t *ctf_arc_open (const char *, ctf_error_t *);
|
|
extern ctf_archive_t *ctf_arc_bufopen (ctf_open_sect_t *, ctf_error_t *);
|
|
extern void ctf_arc_close (ctf_archive_t *);
|
|
|
|
/* Get boolean properties of an archive. Only one property is defined so far: a
|
|
flag which, if set, indicates that the archive was generated by libctf's
|
|
deduplicator. -1 is returned when invalid flags are passed. */
|
|
|
|
typedef enum ctf_arc_flags
|
|
{
|
|
CTF_ARC_FLAGS_LIBCTF_CREATED = 0x01
|
|
} ctf_arc_flags_t;
|
|
|
|
extern ctf_bool_t ctf_arc_flag (ctf_archive_t *, ctf_arc_flags_t flag);
|
|
|
|
/* Get the CTF archive from which this ctf_dict_t is derived, or a new synthetic
|
|
one if not opened from an archive. Calling this bumps a refcount: the
|
|
archive should be closed when you're done with it.
|
|
|
|
If CTF_DICT_ARC_ORIGINAL is set in FLAGS, the actual original archive is
|
|
handed back (no refcount bumping: NULL returned if the dict was not derived
|
|
from an archive). This means you can use it to get back the original archive
|
|
from which a dict was opened in order to finally close that archive without
|
|
needing to lug the archive around everywhere along with the dict. (Calling
|
|
without this set, the common case, would bump the archive refcount in this
|
|
case, so closing the archive would never free it.)
|
|
|
|
Even this is safe if other dicts are opened from this archive -- each dict
|
|
opened from an archive always bumps its refcount, so closing an archive
|
|
returned from ctf_dict_arc (..., CTF_DICT_ARC_ORIGINAL) only frees the
|
|
archive if the dict itself has already been closed. */
|
|
|
|
#define CTF_DICT_ARC_ORIGINAL 0x1
|
|
|
|
extern ctf_archive_t *ctf_dict_arc (ctf_dict_t *, int flags);
|
|
|
|
/* Return the number of members in an archive. */
|
|
|
|
extern size_t ctf_archive_count (const ctf_archive_t *);
|
|
|
|
/* Open a dictionary with a given name, given a CTF archive. The dict should be
|
|
closed with ctf_dict_close() when done. The name NULL indicates the parent
|
|
dict of a multi-dict archive, or the only dict if this archive has only one.
|
|
|
|
(The low-level function ctf_bufopen returns ctf_dict_t's directly, and cannot
|
|
be used on CTF archives.) */
|
|
|
|
extern ctf_dict_t *ctf_dict_open (ctf_archive_t *,
|
|
const char *, ctf_error_t *);
|
|
|
|
/* Open a dictionary with a given index in an archive. Usable even for archives
|
|
where the members have no names, or where the names are duplicated. */
|
|
|
|
extern ctf_dict_t *ctf_dict_open_by_index (ctf_archive_t *,
|
|
size_t index, ctf_error_t *errp);
|
|
|
|
/* When dicts in archives are in parent/child relationships (see below), index 0
|
|
is usually the parent (unless the archive was written by a non-CTF-aware
|
|
linker, in which case all dicts are parents: the CTF opening machinery
|
|
compensates for this automatically). But there are unusual use cases (such
|
|
as ctf_link_against, below) in which archives may exist in which parents come
|
|
from different places and perhaps are not even stored in the same archive
|
|
(e.g. Linux kernel split BTF, where the parent is in vmlinux and the children
|
|
are in different kernel modules). You can specify a parent to be used when
|
|
opening dicts from this archive with ctf_arc_parent. A reference to this
|
|
dict is taken by the archive, so you can close it freely.
|
|
|
|
Some obscure features may not work with archives opened this way: in
|
|
particular, adding types to a parent you open this way before opening
|
|
children with that dict as a parent will cause opening of the children to
|
|
fail: for normal parents in archives, this works fine. */
|
|
|
|
extern ctf_ret_t ctf_arc_set_parent (ctf_archive_t *, ctf_dict_t *parent);
|
|
|
|
/* Look up symbols' types in archives by index or name, returning the dict
|
|
and optionally type ID in which the type is found. Lookup results are
|
|
cached so future lookups are faster. Needs symbol tables and (for name
|
|
lookups) string tables to be known for this CTF archive. */
|
|
|
|
extern ctf_dict_t *ctf_arc_lookup_symbol (ctf_archive_t *,
|
|
unsigned long symidx,
|
|
ctf_id_t *, ctf_error_t *errp);
|
|
extern ctf_dict_t *ctf_arc_lookup_symbol_name (ctf_archive_t *,
|
|
const char *name,
|
|
ctf_id_t *, ctf_error_t *errp);
|
|
extern void ctf_arc_flush_caches (ctf_archive_t *);
|
|
|
|
/* The next functions return or close real CTF files, not archives or ELF files
|
|
containing CTF content. They can be passed symbol and string table sections
|
|
if need be. (A sect of type CTF_ELF_SECT is obviously mandatory.)
|
|
|
|
Unlike ctf_dict_open et al above, these low-level functions expose the
|
|
parent/child relationship between CTF dicts (ctf_dict_open* opens parents as
|
|
needed automatically).
|
|
|
|
The child dicts are usually named after their originating compilation unit or
|
|
kernel module and contain definitions of types with different definitions in
|
|
that location. You open the parent first and pass it in when opening the
|
|
child. Child dicts may have the name of the parent recorded (but newer
|
|
dicts, CTFv4 or BTF, will not: this name is ignored by the libctf machinery
|
|
because every existing implementation always puts parents in the same place,
|
|
index 0 of the archive).
|
|
|
|
To determine whether a CTF type is in a child, use !ctf_type_isparent().
|
|
(ctf_type_isparent cannot fail.)
|
|
|
|
These relationships are initially created by the ctf_link machinery when
|
|
linking (deduplicating) multifile inputs: to create relationships based on
|
|
something other than input object files, see ctf_link_add_cu_mapping and
|
|
CTF_LINK_SHARE_*. */
|
|
|
|
extern ctf_dict_t *ctf_bufopen (ctf_open_sect_t *sects, ctf_dict_t *parent,
|
|
ctf_error_t *);
|
|
extern void ctf_dict_close (ctf_dict_t *);
|
|
|
|
extern const char *ctf_dict_cuname (ctf_dict_t *);
|
|
extern ctf_dict_t *ctf_dict_parent (ctf_dict_t *);
|
|
extern const char *ctf_dict_parent_name (ctf_dict_t *);
|
|
extern ctf_bool_t ctf_type_isparent (const ctf_dict_t *, ctf_id_t);
|
|
|
|
/* Set the cuname (used when creating dicts). (The parent name is obsolescent
|
|
and cannot be set.) */
|
|
|
|
extern ctf_ret_t ctf_dict_set_cuname (ctf_dict_t *, const char *);
|
|
|
|
/* Set and get the CTF data model (see above). */
|
|
|
|
extern ctf_ret_t ctf_dict_set_model (ctf_dict_t *, ctf_model_t);
|
|
extern ctf_model_t ctf_dict_model (ctf_dict_t *);
|
|
|
|
/* CTF dicts can carry a single (in-memory-only) non-persistent pointer to
|
|
arbitrary data. No meaning is attached to this data and the dict does
|
|
not own it: nothing is done to it when the dict is closed. */
|
|
|
|
extern void ctf_dict_specific_set (ctf_dict_t *, void *);
|
|
extern void *ctf_dict_specific (ctf_dict_t *);
|
|
|
|
/* Error handling. ctf dicts carry a system errno value or one of the
|
|
CTF_ERRORS above, which are returned via ctf_errno. The return value of
|
|
ctf_errno is only meaningful when the immediately preceding CTF function
|
|
call returns an error code.
|
|
|
|
There are four possible sorts of error return:
|
|
|
|
- From opening functions, a return value of NULL and the error returned
|
|
via an errp instead of via ctf_errno; all other functions return return
|
|
errors via ctf_errno.
|
|
|
|
- Functions returning a ctf_id_t are in error if the return value == CTF_ERR
|
|
- Functions returning an int are in error if their return value < 0
|
|
- Functions returning a pointer are in error if their return value ==
|
|
NULL. */
|
|
|
|
extern ctf_error_t ctf_errno (ctf_dict_t *);
|
|
extern const char *ctf_errmsg (ctf_error_t);
|
|
|
|
/* BTF/CTF writeout version info.
|
|
|
|
ctf_btf_mode has three levels, and one value used to prevent changes when
|
|
querying other properties of the API:
|
|
|
|
- LIBCTF_BTM_ALWAYS writes out full-blown CTFv4 at all times
|
|
- LIBCTF_BTM_POSSIBLE writes out CTFv4 if needed to avoid information loss,
|
|
BTF otherwise. If compressing, the same as LIBCTF_BTM_ALWAYS.
|
|
- LIBCTF_BTM_BTF writes out BTF always, and errors otherwise.
|
|
- LIBCTF_BTM_QUERY means "don't change the current level".
|
|
|
|
Note that no attempt is made to downgrade existing CTF dicts to BTF: if you
|
|
read in a CTF dict and turn on LIBCTF_BTM_POSSIBLE, you'll get a CTF dict; if
|
|
you turn on LIBCTF_BTM_BTF, you'll get an unconditional error. Thus, this is
|
|
really useful only when reading in BTF dicts or when creating new dicts. */
|
|
|
|
typedef enum ctf_btf_mode
|
|
{
|
|
LIBCTF_BTM_QUERY = 0,
|
|
LIBCTF_BTM_BTF = 1,
|
|
LIBCTF_BTM_POSSIBLE = 2,
|
|
LIBCTF_BTM_ALWAYS = 3
|
|
} ctf_btf_mode_t;
|
|
|
|
/* Set the CTF library client version to the specified version: this is the
|
|
version of dicts written out by the ctf_write* functions. If version is
|
|
zero, we just return the default library version number. The BTF version
|
|
(for CTFv4 and above) is indicated via btf_hdr_len, also zero for "no
|
|
change". (This is not the version written, but rather an indication of
|
|
whether reading a BTF header with the given length is supported.)
|
|
|
|
You can influence what type kinds are written out to a CTFv4 dict via the
|
|
ctf_write_suppress_kind() function. */
|
|
|
|
extern int ctf_version (int ctf_version_, size_t btf_hdr_len,
|
|
ctf_btf_mode_t btf_mode);
|
|
|
|
/* Given a type ID relating to a function type or function linkage type, return
|
|
an array of arg types, and optionally in the RET argument the return type
|
|
too. Vararg functions set CTF_FUNC_VARARG in the optional FLAG argument. The
|
|
NARGS arg gives the length of the array (optional because it will always
|
|
have the same value when you call both ctf_func_type and ctf_func_arg_names,
|
|
so you only need to get it from one of them).
|
|
|
|
Calling this on void functions may return NULL and set nargs to 0: the
|
|
ctf_errno will be reset to 0 in this case. */
|
|
|
|
extern ctf_id_t *ctf_func_type (ctf_dict_t *, ctf_id_t, ctf_id_t *ret_type,
|
|
ctf_func_type_flags_t *flags, size_t *nargs);
|
|
|
|
/* Likewise, for the argument names. */
|
|
|
|
extern const char **ctf_func_arg_names (ctf_dict_t *, ctf_id_t, size_t *nargs);
|
|
|
|
/* Get the linkage of a CTF_K_FUNC_LINKAGE or variable. Variables are name ->
|
|
type mappings with no specific relationship to a symbol table. Before
|
|
linking, everything with types in the symbol table will be in the variable
|
|
table as well; after linking, only those typed functions and data objects
|
|
that are not asssigned to symbols by the linker are left in the variable
|
|
table here.*/
|
|
|
|
extern ctf_linkages_t ctf_type_linkage (ctf_dict_t *, ctf_id_t);
|
|
|
|
/* Traverse all symbols in a dict, one by one, and return the type of each
|
|
and (if NAME is non-NULL) optionally its name. */
|
|
|
|
extern ctf_id_t ctf_symbol_next (ctf_dict_t *, ctf_next_t **, const char **name);
|
|
|
|
/* Look up an identifier (type or variable) by name: some simple C type parsing
|
|
is done, but this is by no means comprehensive. Structures, unions and enums
|
|
are in different namespaces, as in C, so need "struct ", "union " or "enum "
|
|
on the front. Some prefixes not seen in C exist as well: datasecs use
|
|
"datasec ". */
|
|
|
|
extern ctf_id_t ctf_lookup_by_name (ctf_dict_t *, const char *);
|
|
|
|
/* Look up a single enumerator by enumeration constant name. Returns the ID of
|
|
the enum it is contained within and optionally its value. Error out with
|
|
ECTF_DUPLICATE if multiple exist (which can happen in some older dicts). See
|
|
ctf_lookup_enumerator_next in that case. Enumeration constants in non-root
|
|
types are not returned, but constants in parents are, if not overridden by
|
|
an enum in the child. */
|
|
|
|
extern ctf_id_t ctf_lookup_enumerator (ctf_dict_t *, const char *,
|
|
ctf_enum_value_t *enum_value);
|
|
|
|
/* Look up an identifier of a given kind by name. This serves to look up kinds
|
|
in their own namespaces which do not have explicit lookup functions above:
|
|
variables, datasecs. The only kinds you can't look up with this function are
|
|
CTF_K_TYPE_TAG and CTF_K_DECL_TAG, since they may be associated with many
|
|
types: use ctf_tag_next. */
|
|
|
|
extern ctf_id_t ctf_lookup_by_kind (ctf_dict_t *, ctf_kind_t kind, const char *);
|
|
|
|
/* Type lookup functions. */
|
|
|
|
/* Strip qualifiers and typedefs off a type, returning the base type.
|
|
|
|
Stripping also stops when we hit slices (see ctf_add_slice below), so it is
|
|
possible (given a chain looking like const -> slice -> typedef -> int) to
|
|
still have a typedef after you're done with this, but in that case it is a
|
|
typedef of a type with a *different width* (because this slice has not been
|
|
applied to it).
|
|
|
|
May error with ECTF_NONREPRESENTABLE if type 0 is seen (rare, but can happen:
|
|
not only types GCC cannot encode, but also e.g. const void variables).
|
|
|
|
Most of the time you don't need to call this: the type-querying functions
|
|
will do it for you (as noted below). */
|
|
|
|
extern ctf_id_t ctf_type_resolve (ctf_dict_t *, ctf_id_t);
|
|
|
|
/* Get the name of a type, including any const/volatile/restrict qualifiers
|
|
(cvr-quals), and return it as a new dynamically-allocated string.
|
|
(The 'a' stands for 'a'llocated.) */
|
|
|
|
extern char *ctf_type_aname (ctf_dict_t *, ctf_id_t);
|
|
|
|
/* A raw name that is owned by the ctf_dict_t and will live as long as it
|
|
does. Do not change the value this function returns! */
|
|
|
|
extern const char *ctf_type_name_raw (ctf_dict_t *, ctf_id_t);
|
|
|
|
/* Like ctf_type_aname, but print the string into the passed buffer. If longer
|
|
than LEN, return NULL, set ECTF_NAMELEN on the errno, and put the actual
|
|
number of bytes needed into LEN. Consider using ctf_type_aname instead. */
|
|
|
|
__libctf_attribute_deprecated__ ("consider using ctf_type_aname instead")
|
|
extern char *ctf_type_sname (ctf_dict_t *, ctf_id_t, char *, size_t *);
|
|
|
|
/* Retrieve raw (BTF or CTF-format) type data for the type with a given ID.
|
|
The vlen follows the record returned in the usual way for a type.
|
|
|
|
If PREFIX is 0, return only the data for the type itself: if the type is too
|
|
large to be accurately represented without a CTF_K_BIG prefix, this will
|
|
fail with ECTF_TOOLARGE. Otherwise, return the entire type, includiung
|
|
any prefixes. */
|
|
|
|
extern const ctf_type_t *ctf_type_data (ctf_dict_t *, ctf_id_t, int prefix);
|
|
|
|
/* Return the size or alignment of a type. Types with no meaningful size, like
|
|
function types, return 0 as their size; incomplete types set ECTF_INCOMPLETE.
|
|
The type is resolved for you, so cvr-quals and typedefs can be passsed in. */
|
|
|
|
extern ssize_t ctf_type_size (ctf_dict_t *, ctf_id_t);
|
|
extern ssize_t ctf_type_align (ctf_dict_t *, ctf_id_t);
|
|
|
|
/* Return the kind of a type (CTF_K_* constant). Slices are considered to be
|
|
the kind they are a slice of. Forwards to incomplete structs, etc, return
|
|
CTF_K_FORWARD (but deduplication resolves most forwards to their concrete
|
|
types).
|
|
|
|
CTFv4 note: forwards to enums also return CTF_K_FORWARD, even though they
|
|
are encoded differently. */
|
|
|
|
extern ctf_kind_t ctf_type_kind (ctf_dict_t *, ctf_id_t);
|
|
|
|
/* Return the kind of a type (CTF_K_* constant). Slices are considered to be
|
|
the kind they are a slice of; forwards are considered to be the kind they are
|
|
a forward of. */
|
|
|
|
extern ctf_kind_t ctf_type_kind_forwarded (ctf_dict_t *, ctf_id_t);
|
|
|
|
/* Return nonzero if this type is conflicting, zero if it's not, < 0 on error; if
|
|
CUNAME is set, set it to the name of the conflicting compilation unit for the
|
|
passed-in type (which may be a null string if the cuname is not known, or if
|
|
this is not a conflicting type). */
|
|
|
|
extern ctf_bool_t ctf_type_conflicting (ctf_dict_t *, ctf_id_t, const char **cuname);
|
|
|
|
/* Return the type a pointer, typedef, cvr-qual, or slice refers to, or return
|
|
an ECTF_NOTREF error otherwise. ctf_type_kind pretends that slices are
|
|
actually the type they are a slice of: this is usually want you want, but if
|
|
you want to find out if a type was actually a slice of some (usually-wider)
|
|
base type, you can call ctf_type_reference on it: a non-error return means
|
|
it was a slice. */
|
|
|
|
extern ctf_id_t ctf_type_reference (ctf_dict_t *, ctf_id_t);
|
|
|
|
/* Return the encoding of a given type. No attempt is made to resolve the
|
|
type first, so passing in typedefs etc will yield an error. */
|
|
|
|
extern ctf_ret_t ctf_type_encoding (ctf_dict_t *, ctf_id_t, ctf_encoding_t *);
|
|
|
|
/* Given a type, return some other type that is a pointer to this type (if any
|
|
exists), or return ECTF_NOTYPE otherwise. If non exists, try resolving away
|
|
typedefs and cvr-quals and check again (so if you call this on foo_t, you
|
|
might get back foo *). No attempt is made to hunt for pointers to qualified
|
|
versions of the type passed in. */
|
|
|
|
extern ctf_id_t ctf_type_pointer (ctf_dict_t *, ctf_id_t);
|
|
|
|
/* Return 1 if two types are assignment-compatible. */
|
|
|
|
extern ctf_bool_t ctf_type_compat (ctf_dict_t *, ctf_id_t, ctf_dict_t *, ctf_id_t);
|
|
|
|
/* Recursively visit the members of any type, calling the ctf_visit_f for each. */
|
|
|
|
extern int ctf_type_visit (ctf_dict_t *, ctf_id_t, ctf_visit_f *, void *);
|
|
|
|
/* Comparison function that defines an ordering over types. If the types are in
|
|
different dicts, the ordering may vary between different openings of the same
|
|
dicts. */
|
|
|
|
extern int ctf_type_cmp (ctf_dict_t *, ctf_id_t, ctf_dict_t *, ctf_id_t);
|
|
|
|
/* Get the name of an enumerator given its value, or vice versa. If many
|
|
enumerators have the same value, the first with that value is returned.
|
|
If no name exists for a given value, or no value for a given name,
|
|
ECTF_NONAME is raised. */
|
|
|
|
extern const char *ctf_enum_name (ctf_dict_t *, ctf_id_t, ctf_enum_value_t);
|
|
extern ctf_ret_t ctf_enum_value (ctf_dict_t *, ctf_id_t, const char *,
|
|
ctf_enum_value_t *);
|
|
|
|
/* Return nonzero if this struct or union uses bitfield encoding. */
|
|
|
|
extern ctf_bool_t ctf_struct_bitfield (ctf_dict_t *, ctf_id_t);
|
|
|
|
/* Get the size and member type of an array. */
|
|
|
|
extern ctf_ret_t ctf_array_info (ctf_dict_t *, ctf_id_t, ctf_arinfo_t *);
|
|
|
|
/* Get info on specific named members of structs or unions, and count the number
|
|
of members in a struct, union, or enum. */
|
|
|
|
extern ctf_ret_t ctf_member_info (ctf_dict_t *, ctf_id_t, const char *,
|
|
ctf_membinfo_t *);
|
|
extern ssize_t ctf_member_count (ctf_dict_t *, ctf_id_t);
|
|
|
|
/* Search a datasec for a variable covering a given offset.
|
|
|
|
Errors with ECTF_NODATASEC if not found. */
|
|
|
|
extern ctf_id_t ctf_datasec_var_offset (ctf_dict_t *fp, ctf_id_t datasec,
|
|
uint32_t offset);
|
|
|
|
/* Return the datasec that a given variable appears in, or ECTF_NODATASEC if
|
|
none. */
|
|
|
|
extern ctf_id_t ctf_variable_datasec (ctf_dict_t *fp, ctf_id_t var);
|
|
|
|
/* Type and decl tags. */
|
|
|
|
/* Return the type ID of the type to which a given type tag is attached, or of
|
|
the type of the declaration to which a decl tag is attached (so a decl tag on
|
|
a function parameter would return the type ID of the parameter's type). */
|
|
|
|
extern ctf_id_t ctf_tag_reference (ctf_dict_t *, ctf_id_t tag);
|
|
|
|
/* Return the component ID and declaration to which a decl tag is attached.
|
|
-1 means "whole type". */
|
|
|
|
extern ctf_id_t ctf_decl_tag_reference (ctf_dict_t *, ctf_id_t decl_tag,
|
|
int64_t *component_idx);
|
|
|
|
/* Iterators. */
|
|
|
|
/* ctf_member_next is a _next-style iterator that can additionally traverse into
|
|
the members of unnamed structs nested within this struct as if they were
|
|
direct members, if CTF_MN_RECURSE is passed in the flags. Returns
|
|
CTF_MEMBER_ERR on end-of-iteration or error. */
|
|
|
|
extern size_t ctf_member_next (ctf_dict_t *, ctf_id_t, ctf_next_t **,
|
|
const char **name, ctf_id_t *membtype,
|
|
int *bit_width, ctf_member_next_flags_t flags);
|
|
|
|
/* Return all enumeration constants in a given enum type. */
|
|
extern const char *ctf_enum_next (ctf_dict_t *, ctf_id_t, ctf_next_t **,
|
|
ctf_enum_value_t *);
|
|
|
|
/* Return all enumeration constants with a given name in a given dict, similar
|
|
to ctf_lookup_enumerator above but capable of returning multiple values.
|
|
Enumerators in parent dictionaries are not returned: enumerators in non-root
|
|
types *are* returned. This operation internally iterates over all types in
|
|
the dict, so is relatively expensive in large dictionaries.
|
|
|
|
There is nothing preventing NAME from being changed by the caller in the
|
|
middle of iteration: the results might be slightly confusing, but they are
|
|
well-defined.
|
|
|
|
This function is only useful for dicts containing multiple enumerators with
|
|
the same name. These things are not valid C, and as of 2024 the deduplicator
|
|
will not produce them; so this function is somewhat deprecated. */
|
|
|
|
__libctf_attribute_deprecated__("consider using ctf_lookup_enumerator instead")
|
|
extern ctf_id_t ctf_lookup_enumerator_next (ctf_dict_t *, const char *name,
|
|
ctf_next_t **,
|
|
ctf_enum_value_t *enum_value);
|
|
|
|
/* Likewise, across all dicts in an archive (parent first). The DICT and ERRP
|
|
arguments are not optional: without the forer you can't tell which dict the
|
|
returned type is in, and without the latter you can't distinguish real errors
|
|
from end-of-iteration. DICT should be NULL before the first call and is set
|
|
to NULL after the last and on error: on successful call it is set to the dict
|
|
containing the returned enum, and it is the caller's responsibility to
|
|
ctf_dict_close() it. The caller should otherwise pass it back in unchanged
|
|
(do not reassign it during iteration, just as with the ctf_next_t iterator
|
|
itself). */
|
|
|
|
extern ctf_id_t ctf_arc_lookup_enumerator_next (ctf_archive_t *, const char *name,
|
|
ctf_next_t **,
|
|
ctf_enum_value_t *enum_value,
|
|
ctf_dict_t **dict, ctf_error_t *errp);
|
|
|
|
/* Iterate over all types, kinds or datasecs in a dict. ctf_type_next returns
|
|
all types in a dict in turn, allowing you to choose whether to see
|
|
conflicting types or not with the want_hidden arg: if set, the
|
|
CONFLICTING arg (if passed) returns the conflicting state of each type in
|
|
turn. Types in parent dictionaries are not returned. Note that this is
|
|
the opposite of the convention in the old API: a true value for the flag
|
|
argument used to mean it is visible; now it means it is conflicting.
|
|
|
|
These days, even variables are included in the things returned by ctf_type*()
|
|
(type kind CTF_K_VAR). */
|
|
|
|
extern ctf_id_t ctf_type_next (ctf_dict_t *, ctf_next_t **,
|
|
int *conflicting, int want_hidden);
|
|
extern ctf_id_t ctf_type_kind_next (ctf_dict_t *, ctf_next_t **, ctf_kind_t kind);
|
|
extern ctf_id_t ctf_datasec_var_next (ctf_dict_t *, ctf_id_t, ctf_next_t **,
|
|
size_t *size, size_t *offset);
|
|
|
|
/* Iterate over all tags with the given TAG, returning the ID of each tag. */
|
|
extern ctf_id_t ctf_tag_next (ctf_dict_t *, const char *tag, ctf_next_t **);
|
|
|
|
/* Return the decl tags that point to this declaration (if any). */
|
|
extern ctf_id_t ctf_decl_tag_next (ctf_dict_t *, ctf_id_t decl,
|
|
int64_t *component_idx, ctf_next_t **it);
|
|
|
|
/* ctf_archive_next opens each member dict for you, automatically importing any
|
|
parent dict as usual: the caller must close each dict returned once done with
|
|
it, though it may outlive the loop until the archive is closed; the cost of
|
|
opening is amortized so that repeated calls cost almost nothing. If
|
|
skip_parent is set, the parent dict is skipped on the basis that it's already
|
|
been seen in every child dict (but if no child dicts exist, this will lead to
|
|
nothing being returned).
|
|
|
|
If an open fails, ctf_archive_next both passes back the error in the passed
|
|
errp and allows you to iterate past errors (until the usual ECTF_NEXT_END is
|
|
returned). */
|
|
|
|
extern ctf_dict_t *ctf_archive_next (const ctf_archive_t *, ctf_next_t **,
|
|
const char **name, int skip_parent,
|
|
ctf_error_t *errp);
|
|
|
|
/* Iterate over raw archives, returning the name of each member and optionally
|
|
its content and length. Names may be repeated: in particular they may all be
|
|
"" for archives with no named members (as are produced by non-CTF-aware
|
|
linkers just doing straight concatenation of their inputs rather than
|
|
deduplication).
|
|
|
|
This function alone does not currently operate on CTF files masquerading as
|
|
archives, and returns -EINVAL: the raw data is no longer available. It is
|
|
expected to be used only by archiving tools, in any case, which have no need
|
|
to deal with non-archives at all. */
|
|
|
|
extern const char *ctf_archive_raw_next (const ctf_archive_t *,
|
|
ctf_next_t **, const void **contents,
|
|
size_t *len, ctf_error_t *errp);
|
|
|
|
/* Dump the contents of a section in a CTF dict. STATE is an
|
|
iterator which should be a pointer to a variable set to NULL. The decorator
|
|
is called with each line in turn and can modify it or allocate and return a
|
|
new one. ctf_dump accumulates all the results and returns a single giant
|
|
multiline string. */
|
|
|
|
extern char *ctf_dump (ctf_dict_t *, ctf_dump_state_t **state,
|
|
ctf_sect_names_t sect, ctf_dump_decorate_f *,
|
|
void *arg);
|
|
|
|
/* Return the size in bytes of a given CTF section, 0 if none, or -1 on
|
|
error. */
|
|
|
|
extern ssize_t ctf_sect_size (ctf_dict_t *, ctf_sect_names_t sect);
|
|
|
|
/* Error-warning reporting: an 'iterator' that returns errors and warnings from
|
|
the error/warning list, in order of emission. Errors and warnings are popped
|
|
after return: the caller must free the returned error-text pointer. */
|
|
extern char *ctf_errwarning_next (ctf_dict_t *, ctf_next_t **,
|
|
int *is_warning, ctf_error_t *errp);
|
|
|
|
/* Remove the most recent instance of some error (that you have already
|
|
handled and do not want reported) from the errwarning stream. If no
|
|
such error exists, does nothing. */
|
|
extern void ctf_errwarning_remove (ctf_dict_t *, ctf_error_t err);
|
|
|
|
/* Creation. */
|
|
|
|
/* Create a new, empty dict, optionally with a given PARENT. The PARENT need
|
|
not be fully laid out or even have any types in it at all. If creation
|
|
fails, return NULL and put a CTF error code in the passed-in ctf_error_t (if
|
|
set). */
|
|
|
|
extern ctf_dict_t *ctf_create (ctf_dict_t *parent, ctf_error_t *);
|
|
|
|
/* Add specific types to a dict. You can add new types to any dict, but you can
|
|
only add members to types that have been added since this dict was read in
|
|
(you cannot read in a dict, look up a type in it, then add members to
|
|
it). */
|
|
|
|
extern ctf_id_t ctf_add_array (ctf_dict_t *, const ctf_arinfo_t *);
|
|
|
|
/* enums are created signed by default: an encoding of NULL is permitted and
|
|
means "use the default". If you want an unsigned enum, use ctf_add_enum()
|
|
with an encoding of 0 (CTF_INT_SIGNED and everything else off).
|
|
|
|
The SIZE can be 0 (for 'architectural default'), or a size in bytes.
|
|
|
|
ENUM_64_UNKNOWN can be CTF_K_ENUM, CTF_K_ENUM64, or CTF_K_UNKNOWN (0), which
|
|
for now simply means an enum64, but may in future mean to use whichever is
|
|
appropriate. */
|
|
|
|
extern ctf_id_t ctf_add_enum (ctf_dict_t *, const char *,
|
|
ctf_kind_t enum_64_unknown,
|
|
size_t size, const ctf_encoding_t *);
|
|
|
|
extern ctf_id_t ctf_add_btf_float (ctf_dict_t *, const char *,
|
|
const ctf_encoding_t *);
|
|
extern ctf_id_t ctf_add_float (ctf_dict_t *, const char *,
|
|
const ctf_encoding_t *);
|
|
extern ctf_id_t ctf_add_forward (ctf_dict_t *, const char *, ctf_kind_t);
|
|
extern ctf_id_t ctf_add_integer (ctf_dict_t *, const char *,
|
|
const ctf_encoding_t *);
|
|
|
|
/* ctf_add_function adds an unnamed function with a bundle of arguments and a
|
|
return type. ctf_add_function_linkage provides a function with a name
|
|
and linkage, which is one of the CTF_FUNC_LINKAGE_* constants. */
|
|
|
|
extern ctf_id_t ctf_add_function (ctf_dict_t *fp, ctf_id_t ret_type,
|
|
ctf_func_type_flags_t flags,
|
|
const ctf_id_t *argv, const char **arg_names,
|
|
size_t nargs);
|
|
|
|
extern ctf_id_t ctf_add_function_linkage (ctf_dict_t *, ctf_id_t, const char *,
|
|
ctf_linkages_t linkage);
|
|
|
|
/* Add a "slice", which wraps some integral type and changes its encoding
|
|
(useful for bitfields, etc). In most respects slices are treated the same
|
|
kind as the type they wrap: only ctf_type_reference can see the difference,
|
|
returning the wrapped type. */
|
|
|
|
__libctf_attribute_deprecated__("slices are deprecated: use bitfield-capable structs")
|
|
extern ctf_id_t ctf_add_slice (ctf_dict_t *, ctf_id_t, const ctf_encoding_t *);
|
|
extern ctf_id_t ctf_add_pointer (ctf_dict_t *, ctf_id_t);
|
|
extern ctf_id_t ctf_add_type (ctf_dict_t *, ctf_dict_t *, ctf_id_t);
|
|
extern ctf_id_t ctf_add_typedef (ctf_dict_t *, const char *, ctf_id_t);
|
|
|
|
/* Add type and decl tags to whole types or (for decl tags) specific
|
|
components of types (parameter count for functions, member count for structs
|
|
and unions). */
|
|
extern ctf_id_t ctf_add_type_tag (ctf_dict_t *, ctf_id_t, const char *);
|
|
extern ctf_id_t ctf_add_decl_type_tag (ctf_dict_t *, ctf_id_t, const char *);
|
|
extern ctf_id_t ctf_add_decl_tag (ctf_dict_t *, ctf_id_t, const char *,
|
|
int component_idx);
|
|
|
|
/* Struct and union addition. STRUCT_UNION_UNKNOWN can be CTF_K_STRUCT,
|
|
CTF_K_UNION, or CTF_K_UNKNOWN (0) to mean "guess and do the right thing",
|
|
which for now simply adds a struct, but in future may extend to emit a struct
|
|
if the members (once added) don't overlap, and otherwise transform it into a
|
|
union.
|
|
|
|
If BITFIELD is CTF_STRUCT_BITFIELD this is a bitfield-capable struct:
|
|
otherwise it is not so capable. (In future libctf may learn to promote such
|
|
structs to bitfield-capable structs if bitfields are later added to them, but
|
|
for now adding bitfields to such structs is an error.)
|
|
|
|
The size of the struct starts at the specified SIZE, and grows on demand if
|
|
members are added with higher (offset + size). This allows the explicit
|
|
specification of padding, while still prohibiting structures smaller than
|
|
the members they contain. */
|
|
|
|
#ifndef __cplusplus
|
|
typedef
|
|
#endif
|
|
enum ctf_bitfield
|
|
{
|
|
CTF_STRUCT_NORMAL = 0,
|
|
CTF_STRUCT_BITFIELD = 1
|
|
#ifndef __cplusplus
|
|
} ctf_bitfield_t;
|
|
#else
|
|
};
|
|
typedef int ctf_bitfield_t;
|
|
#endif
|
|
|
|
extern ctf_id_t ctf_add_struct (ctf_dict_t *, const char *name,
|
|
ctf_kind_t struct_union_unknown,
|
|
ctf_bitfield_t bitfield, size_t size);
|
|
|
|
/* Note that CTF cannot encode a given type. This usually returns an
|
|
ECTF_NONREPRESENTABLE error when queried. Mostly useful for struct members,
|
|
variables, etc, to point to. */
|
|
|
|
extern ctf_id_t ctf_add_unknown (ctf_dict_t *, const char *);
|
|
|
|
/* Add an enumerator to an enum or enum64. If the enum is conflicting, all the
|
|
constants added to it by ctf_add_enumerator are also not visible and can
|
|
repeat. */
|
|
|
|
extern ctf_ret_t ctf_add_enumerator (ctf_dict_t *, ctf_id_t, const char *, int64_t);
|
|
|
|
/* Add a member to a struct or union at the given OFFSET in bits
|
|
(CTF_NEXT_MEMBER (-1) means "at the next available place, with suitable
|
|
padding for the alignment", everything else is an unsigned size_t). Offsets
|
|
need not be unique, but must be added in ascending order (excepting
|
|
CTF_NEXT_MEMBER). ctf_add_member_bitfield with a non-negative bit_width will
|
|
fail unless the struct was created with CTF_STRUCT_BITFIELD. (A negative
|
|
bit-width means "not a bitfield", as with ctf_member_info et al.) */
|
|
|
|
extern ctf_ret_t ctf_add_member (ctf_dict_t *, ctf_id_t, const char *, ctf_id_t,
|
|
size_t bit_offset);
|
|
extern ctf_ret_t ctf_add_member_bitfield (ctf_dict_t *, ctf_id_t souid,
|
|
const char *, ctf_id_t type,
|
|
size_t bit_offset, int bit_width);
|
|
|
|
extern ctf_id_t ctf_add_qualifier (ctf_dict_t *, ctf_kind_t cvr_qual, ctf_id_t);
|
|
|
|
/* ctf_add_variable adds variables to no datasec at all;
|
|
ctf_add_section_variable adds them to the given datasec, or to no datasec at
|
|
all if the datasec is NULL. */
|
|
|
|
extern ctf_id_t ctf_add_variable (ctf_dict_t *, const char *,
|
|
ctf_linkages_t linkage, ctf_id_t);
|
|
extern ctf_id_t ctf_add_section_variable (ctf_dict_t *, const char *datasec,
|
|
const char *name,
|
|
ctf_linkages_t linkage, ctf_id_t type,
|
|
size_t size, size_t offset);
|
|
|
|
/* Set the size and member and index types of an array. */
|
|
|
|
extern ctf_ret_t ctf_array_set_info (ctf_dict_t *, ctf_id_t, const ctf_arinfo_t *);
|
|
|
|
/* Mark a type as conflicting, residing in some other translation unit with
|
|
a given name (optional). The type is hidden from all name lookups. If
|
|
the type ID is zero, the next call to any ctf_add_* function that ends up
|
|
adding a type will add that type as conflicting as it is added (and not
|
|
check for name conflicts: all ctf_add* calls that add a new type clear
|
|
this flag when the type is successfully added, as does calling this
|
|
function with a type ID of zero and a NULL cuname. This is the equivalent
|
|
of the old CTF_ADD_NONROOT. */
|
|
|
|
extern ctf_ret_t ctf_type_set_conflicting (ctf_dict_t *, ctf_id_t type,
|
|
const char *cuname);
|
|
|
|
/* Add a type for a symbol with a particular name, without saying anything
|
|
about the actual symbol index. (The linker will then associate them with
|
|
actual symbol indexes using the ctf_link functions below.) */
|
|
|
|
extern ctf_ret_t ctf_add_sym (ctf_dict_t *fp, const char *name, ctf_id_t id);
|
|
|
|
/* Snapshot/rollback. Call ctf_snapshot to return a snapshot ID: pass
|
|
one of these IDs to ctf_rollback to discard all types added since the
|
|
corresponding call to ctf_snapshot. */
|
|
|
|
extern ctf_snapshot_id_t ctf_snapshot (ctf_dict_t *);
|
|
extern ctf_ret_t ctf_rollback (ctf_dict_t *, ctf_snapshot_id_t);
|
|
|
|
/* Dict writeout. See ctf_version().
|
|
|
|
ctf_write: write out a dict to an fd.
|
|
ctf_write_mem: write out a dict to a buffer and return it and its size.
|
|
|
|
If the ctf_btf_mode is not LIBCTF_BTM_ALWAYS, the resulting dict may be pure
|
|
BTF. */
|
|
|
|
extern int ctf_write (ctf_dict_t *, int);
|
|
extern unsigned char *ctf_write_mem (ctf_dict_t *, size_t *);
|
|
|
|
/* Create a CTF archive named FILE from CTF_DICTS inputs (or write it to the
|
|
passed-in fd). The member names are derived from the cunames of the
|
|
dicts. CTF_DICTS must be at least 1. */
|
|
|
|
typedef enum ctf_arc_write_flags
|
|
{
|
|
CTF_ARC_WRITE_NAMELESS = 1 /* No name table. */
|
|
} ctf_arc_write_flags_t;
|
|
|
|
extern ctf_error_t ctf_arc_write (const char *file, ctf_dict_t **ctf_dicts, size_t,
|
|
ctf_arc_write_flags_t);
|
|
extern ctf_error_t ctf_arc_write_fd (int, ctf_dict_t **, size_t,
|
|
ctf_arc_write_flags_t);
|
|
|
|
/* Prohibit writeout of this type kind: attempts to write it out cause
|
|
an ECTF_KIND_PROHIBITED error. */
|
|
|
|
extern ctf_ret_t ctf_write_suppress_kind (ctf_dict_t *fp, ctf_kind_t kind,
|
|
int prohibited);
|
|
|
|
/* Linking. These functions are used by ld to link .ctf sections in input
|
|
object files into a single .ctf section which is an archive possibly
|
|
containing members containing types whose names collide across multiple
|
|
compilation units, but they are usable by other programs as well and are not
|
|
private to the linker.
|
|
|
|
They should be called in the order they appear below, though some are
|
|
optional. If you call ctf_link_against, don't call ctf_link_add or
|
|
ctf_link. */
|
|
|
|
/* Add a CTF archive to the link with a given FILENAME (usually the name of the
|
|
containing object file); the CUNAME_PREFIX, if set, prefixes all input
|
|
cunames with a given string (used for archives). The dict added to is
|
|
usually a new dict created with ctf_create which will be filled with types
|
|
corresponding to the shared dict in the output (conflicting types in child
|
|
dicts in the output archive are stored in internal space inside this dict,
|
|
but are not easily visible until after ctf_link_write below).
|
|
|
|
This operation takes ownership of the archive passed in.
|
|
|
|
The FILENAME need not be unique (but usually is). */
|
|
|
|
extern ctf_ret_t ctf_link_add (ctf_dict_t *, ctf_archive_t *, const char *filename,
|
|
const char *cuname_prefix);
|
|
|
|
/* Set the cuname for the parent dict in an archive, without opening it,
|
|
if and only if it is currently unset. An efficiency hack for linkers. */
|
|
|
|
extern void ctf_link_set_default_parent_cuname (ctf_archive_t *arc,
|
|
const char *cuname);
|
|
|
|
/* Do the deduplicating link, filling the dict with types. The FLAGS are the
|
|
CTF_LINK_* flags above. */
|
|
|
|
extern ctf_ret_t ctf_link (ctf_dict_t *, ctf_link_flags_t flags);
|
|
|
|
/* Do a deduplicating link of one archive against another parent dict AGAINST,
|
|
without changing the parent dict. All types in every archive member are
|
|
smushed together into one dict, the child of AGAINST, using the cu-mapping
|
|
mechanism (see below). AGAINST is an archive but must contain only one dict.
|
|
You may not call ctf_link_add or ctf_link if you call this.
|
|
|
|
As with ctf_link_add, AGAINST is owned by FP after this call. */
|
|
|
|
extern ctf_ret_t ctf_link_against (ctf_dict_t *fp, ctf_archive_t *against,
|
|
ctf_archive_t *dict, const char *cuname,
|
|
ctf_link_flags_t flags);
|
|
|
|
/* Symtab linker handling, called after ctf_link to set up the symbol type
|
|
information used by ctf_*_lookup_symbol. Optional. */
|
|
|
|
/* Add strings to the link from the ELF string table, repeatedly calling
|
|
ADD_STRING to add each string and its corresponding offset in turn. */
|
|
|
|
typedef const char *ctf_link_strtab_string_f (uint32_t *offset, void *arg);
|
|
extern ctf_ret_t ctf_link_add_strtab (ctf_dict_t *,
|
|
ctf_link_strtab_string_f *add_string, void *);
|
|
|
|
/* Note that a given symbol will be public with a given set of properties.
|
|
If the symbol has been added with that name via ctf_add_funcobjt_sym,
|
|
this symbol type will end up in the symtypetabs and can be looked up via
|
|
ctf_*_lookup_symbol after the dict is read back in. */
|
|
|
|
extern ctf_ret_t ctf_link_add_linker_symbol (ctf_dict_t *, ctf_link_sym_t *);
|
|
|
|
/* Impose an ordering on symbols, as defined by the strtab and symbol
|
|
added by earlier calls to the above two functions. Optional. */
|
|
|
|
extern ctf_ret_t ctf_link_shuffle_syms (ctf_dict_t *);
|
|
|
|
/* Determine the file format of the dict that will be written out after the
|
|
calls above is compatible with pure BTF or would require CTF. (Other things
|
|
may nonetheless require CTF.) */
|
|
|
|
extern ctf_ret_t ctf_link_output_is_btf (ctf_dict_t *);
|
|
|
|
/* Return the serialized form of this ctf_linked dict as a new
|
|
dynamically-allocated string.
|
|
|
|
May be a CTF dict or a CTF archive (this library mostly papers over the
|
|
differences so you can open both the same way, treat both as ctf_archive_t
|
|
and so on). If ctf_link_against was used, a single dict is always written.
|
|
Concatenate a parent onto the front of it if you want to open it with
|
|
ctf_open*(), or open it with ctf_bufopen() and explicitly supply the parent.
|
|
|
|
If IS_BTF is set on return, the output is BTF-compatible and can be stored
|
|
in a .BTF section. */
|
|
|
|
extern unsigned char *ctf_link_write (ctf_dict_t *, size_t *size, int *is_btf);
|
|
|
|
/* Specialist linker functions. These functions are not used by ld, but can be
|
|
used by other programs making use of the linker machinery for other purposes
|
|
to customize its output. Must be called before ctf_link. */
|
|
|
|
/* Add an entry to rename a given compilation unit to some other name. This
|
|
is only used if conflicting types are found in that compilation unit: they
|
|
will instead be placed in the child dict named TO. Many FROMs can map to one
|
|
TO: all the types are placed together in that dict, with any whose names
|
|
collide as a result being marked as non-root types.
|
|
|
|
The TO mapping named "" is special: types in this are merged directly and
|
|
unconditionally into the shared parent dict, and are hidden (marked
|
|
conflicting) if they clash, rather than being moved into child dicts. */
|
|
|
|
extern ctf_ret_t ctf_link_add_cu_mapping (ctf_dict_t *, const char *from,
|
|
const char *to);
|
|
|
|
/* Allow cunames in CTF archives to be tweaked at the last minute before
|
|
writeout. Unlike cu-mappings, this cannot transform names so that they
|
|
collide: it's meant for unusual use cases that use names for archive members
|
|
that are not exactly the same as the names of compilation units but are
|
|
modified in some systematic way. */
|
|
typedef char *ctf_link_memb_name_changer_f (ctf_dict_t *,
|
|
const char *, void *);
|
|
extern void ctf_link_set_memb_name_changer
|
|
(ctf_dict_t *, ctf_link_memb_name_changer_f *, void *);
|
|
|
|
/* Filter out unwanted variables, which can be very voluminous, and cause the
|
|
CTF string table to grow to hold their names. The variable filter should
|
|
return nonzero if a variable (or symbol) should not appear in the output. */
|
|
typedef ctf_bool_t ctf_link_variable_filter_f (ctf_dict_t *, const char *,
|
|
ctf_id_t, void *);
|
|
extern ctf_bool_t ctf_link_set_variable_filter (ctf_dict_t *,
|
|
ctf_link_variable_filter_f *, void *);
|
|
|
|
/* Hash caching. This is useful if you're repeatedly deduplicating against the
|
|
same set of objects from the same inputs, and don't want to spend time
|
|
re-hashing them over and over again. The cache contains elements for every
|
|
type in the link. Must be called after ctf_link_add; ctf_link need not be
|
|
called. */
|
|
|
|
extern int ctf_link_hash_cache_save (ctf_dict_t *, const char *cache);
|
|
|
|
/* Load a saved hash. Cached inputs will not be rehashed: the cache will be
|
|
used instead. */
|
|
|
|
extern int ctf_link_hash_cache_load (ctf_dict_t *, const char *cache);
|
|
|
|
/* Turn debugging off and on. This is the same as setting LIBCTF_DEBUG in the
|
|
environment. Useful for conditional debugging. */
|
|
extern void ctf_setdebug (ctf_bool_t debug);
|
|
|
|
/* Deprecated aliases for existing types. */
|
|
|
|
typedef struct ctf_dict ctf_file_t;
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _CTF_API_H */
|