/* Public API to libctf.
- Copyright (C) 2019-2020 Free Software Foundation, Inc.
+ Copyright (C) 2019-2021 Free Software Foundation, Inc.
This file is part of libctf.
/* 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().
+ filling in ctf_sect_t structures and passing them to ctf_bufopen.
- The contents of this structure must always be in native endianness (no
- byteswapping is performed). */
+ The contents of this structure must always be in native endianness. 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_symsect_endianness or
+ ctf_arc_symsect_endianness. */
typedef struct ctf_sect
{
} ctf_sect_t;
/* A minimal symbol extracted from a linker's internal symbol table
- representation. */
+ 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 will not be accessed outside the call to
- ctf_link_shuffle_syms(). */
+ /* 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;
/* Omit the content of the variables section. */
#define 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.) */
+#define CTF_LINK_NO_FILTER_REPORTED_SYMS 0x10
+
/* Symbolic names for CTF sections. */
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
} ctf_sect_names_t;
/* Encoding information for integers, floating-point values, and certain other
- intrinsics can be obtained by calling ctf_type_encoding(), below. The flags
+ intrinsics can be obtained by calling ctf_type_encoding, below. The flags
field will contain values appropriate for the type defined in <ctf.h>. */
typedef struct ctf_encoding
#define CTF_FUNC_VARARG 0x1 /* Function arguments end with varargs. */
/* 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(). */
+ 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)
/* This macro holds information about all the available ctf errors.
_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_NEEDSBFD, "This feature needs a libctf with BFD support.") \
+ _CTF_ITEM (ECTF_INCOMPLETE, "Type is not a complete type.") \
+ _CTF_ITEM (ECTF_NONAME, "Type name must not be empty.")
#define ECTF_BASE 1000 /* Base value for libctf errnos. */
#undef _CTF_FIRST
};
-#define ECTF_NERR (ECTF_NEEDSBFD - ECTF_BASE + 1) /* Count of CTF errors. */
+#define ECTF_NERR (ECTF_NONAME - 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. */
+ model of the given object, unless ctf_setmodel is explicitly called. */
#define CTF_MODEL_ILP32 1 /* Object data model is ILP32. */
#define CTF_MODEL_LP64 2 /* Object data model is LP64. */
#ifdef _LP64
# define CTF_MODEL_NATIVE CTF_MODEL_ILP32
#endif
-/* Dynamic CTF containers can be created using ctf_create(). The ctf_add_*
+/* Dynamic CTF containers can be created using ctf_create. The ctf_add_*
routines can be used to add new definitions to the dynamic container.
New types are labeled as root or non-root to determine whether they are
visible at the top-level program scope when subsequently doing a lookup. */
#define CTF_ADD_NONROOT 0 /* Type only visible in nested scope. */
#define CTF_ADD_ROOT 1 /* Type visible at top-level scope. */
+/* Flags for ctf_member_next. */
+
+#define CTF_MN_RECURSE 0x1 /* Recurse into unnamed members. */
+
/* These typedefs are used to define the signature for callback functions that
can be used with the iteration and visit functions below. There is also a
family of iteration functions that do not require callbacks. */
typedef struct ctf_dump_state ctf_dump_state_t;
-/* Iteration state for the _next() functions, and allocators/copiers/freers for
+/* 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() function allocate and free the iterators for you.) */
+ the _next function allocate and free the iterators for you.) */
typedef struct ctf_next ctf_next_t;
extern ctf_next_t *ctf_next_create (void);
/* 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_dict_t's directly, and cannot
+ ctf_simple_open and ctf_bufopen return ctf_dict_t's directly, and cannot
be used on CTF archives. */
extern ctf_archive_t *ctf_bfdopen (struct bfd *, int *);
const char *target, int *errp);
extern void ctf_close (ctf_archive_t *);
extern ctf_sect_t ctf_getdatasect (const ctf_dict_t *);
+extern ctf_sect_t ctf_getsymsect (const ctf_dict_t *);
+extern ctf_sect_t ctf_getstrsect (const ctf_dict_t *);
+extern void ctf_symsect_endianness (ctf_dict_t *, int little_endian);
extern ctf_archive_t *ctf_get_arc (const ctf_dict_t *);
extern ctf_archive_t *ctf_arc_open (const char *, int *);
extern ctf_archive_t *ctf_arc_bufopen (const ctf_sect_t *,
const ctf_sect_t *,
const ctf_sect_t *,
int *);
+extern void ctf_arc_symsect_endianness (ctf_archive_t *, int little_endian);
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 *,
extern ctf_id_t ctf_lookup_by_name (ctf_dict_t *, const char *);
extern ctf_id_t ctf_lookup_by_symbol (ctf_dict_t *, unsigned long);
+extern ctf_id_t ctf_symbol_next (ctf_dict_t *, ctf_next_t **,
+ const char **name, int functions);
extern ctf_id_t ctf_lookup_variable (ctf_dict_t *, const char *);
extern ctf_id_t ctf_type_resolve (ctf_dict_t *, ctf_id_t);
extern int ctf_member_count (ctf_dict_t *, ctf_id_t);
extern int ctf_member_iter (ctf_dict_t *, ctf_id_t, ctf_member_f *, void *);
extern ssize_t ctf_member_next (ctf_dict_t *, ctf_id_t, ctf_next_t **,
- const char **name, ctf_id_t *membtype);
+ const char **name, ctf_id_t *membtype,
+ int flags);
extern int ctf_enum_iter (ctf_dict_t *, ctf_id_t, ctf_enum_f *, void *);
extern const char *ctf_enum_next (ctf_dict_t *, ctf_id_t, ctf_next_t **,
int *);
extern int ctf_add_variable (ctf_dict_t *, const char *, ctf_id_t);
+extern int ctf_add_objt_sym (ctf_dict_t *, const char *, ctf_id_t);
+extern int ctf_add_func_sym (ctf_dict_t *, const char *, ctf_id_t);
+
extern int ctf_set_array (ctf_dict_t *, ctf_id_t, const ctf_arinfo_t *);
extern ctf_dict_t *ctf_create (int *);
typedef const char *ctf_link_strtab_string_f (uint32_t *offset, void *arg);
extern int ctf_link_add_strtab (ctf_dict_t *, ctf_link_strtab_string_f *,
void *);
-typedef ctf_link_sym_t *ctf_link_iter_symbol_f (ctf_link_sym_t *dest,
- void *arg);
-extern int ctf_link_shuffle_syms (ctf_dict_t *, ctf_link_iter_symbol_f *,
- void *);
+extern int ctf_link_add_linker_symbol (ctf_dict_t *, ctf_link_sym_t *);
+extern int ctf_link_shuffle_syms (ctf_dict_t *);
extern unsigned char *ctf_link_write (ctf_dict_t *, size_t *size,
size_t threshold);