1*1424dfb3Schristos /* Public API to libctf. 2*1424dfb3Schristos Copyright (C) 2019-2020 Free Software Foundation, Inc. 3*1424dfb3Schristos 4*1424dfb3Schristos This file is part of libctf. 5*1424dfb3Schristos 6*1424dfb3Schristos libctf is free software; you can redistribute it and/or modify it under 7*1424dfb3Schristos the terms of the GNU General Public License as published by the Free 8*1424dfb3Schristos Software Foundation; either version 3, or (at your option) any later 9*1424dfb3Schristos version. 10*1424dfb3Schristos 11*1424dfb3Schristos This program is distributed in the hope that it will be useful, but 12*1424dfb3Schristos WITHOUT ANY WARRANTY; without even the implied warranty of 13*1424dfb3Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14*1424dfb3Schristos See the GNU General Public License for more details. 15*1424dfb3Schristos 16*1424dfb3Schristos You should have received a copy of the GNU General Public License 17*1424dfb3Schristos along with this program; see the file COPYING. If not see 18*1424dfb3Schristos <http://www.gnu.org/licenses/>. */ 19*1424dfb3Schristos 20*1424dfb3Schristos /* This header file defines the interfaces available from the CTF debugger 21*1424dfb3Schristos library, libctf. This API can be used by a debugger to operate on data in 22*1424dfb3Schristos the Compact ANSI-C Type Format (CTF). */ 23*1424dfb3Schristos 24*1424dfb3Schristos #ifndef _CTF_API_H 25*1424dfb3Schristos #define _CTF_API_H 26*1424dfb3Schristos 27*1424dfb3Schristos #include <sys/types.h> 28*1424dfb3Schristos #include <ctf.h> 29*1424dfb3Schristos #include <zlib.h> 30*1424dfb3Schristos 31*1424dfb3Schristos #ifdef __cplusplus 32*1424dfb3Schristos extern "C" 33*1424dfb3Schristos { 34*1424dfb3Schristos #endif 35*1424dfb3Schristos 36*1424dfb3Schristos /* Clients can open one or more CTF containers and obtain a pointer to an 37*1424dfb3Schristos opaque ctf_file_t. Types are identified by an opaque ctf_id_t token. 38*1424dfb3Schristos They can also open or create read-only archives of CTF containers in a 39*1424dfb3Schristos ctf_archive_t. 40*1424dfb3Schristos 41*1424dfb3Schristos These opaque definitions allow libctf to evolve without breaking clients. */ 42*1424dfb3Schristos 43*1424dfb3Schristos typedef struct ctf_file ctf_file_t; 44*1424dfb3Schristos typedef struct ctf_archive_internal ctf_archive_t; 45*1424dfb3Schristos typedef unsigned long ctf_id_t; 46*1424dfb3Schristos 47*1424dfb3Schristos /* This opaque definition allows libctf to accept BFD data structures without 48*1424dfb3Schristos importing all the BFD noise into users' namespaces. */ 49*1424dfb3Schristos 50*1424dfb3Schristos struct bfd; 51*1424dfb3Schristos 52*1424dfb3Schristos /* If the debugger needs to provide the CTF library with a set of raw buffers 53*1424dfb3Schristos for use as the CTF data, symbol table, and string table, it can do so by 54*1424dfb3Schristos filling in ctf_sect_t structures and passing them to ctf_bufopen(). 55*1424dfb3Schristos 56*1424dfb3Schristos The contents of this structure must always be in native endianness (no 57*1424dfb3Schristos byteswapping is performed). */ 58*1424dfb3Schristos 59*1424dfb3Schristos typedef struct ctf_sect 60*1424dfb3Schristos { 61*1424dfb3Schristos const char *cts_name; /* Section name (if any). */ 62*1424dfb3Schristos const void *cts_data; /* Pointer to section data. */ 63*1424dfb3Schristos size_t cts_size; /* Size of data in bytes. */ 64*1424dfb3Schristos size_t cts_entsize; /* Size of each section entry (symtab only). */ 65*1424dfb3Schristos } ctf_sect_t; 66*1424dfb3Schristos 67*1424dfb3Schristos /* A minimal symbol extracted from a linker's internal symbol table 68*1424dfb3Schristos representation. */ 69*1424dfb3Schristos 70*1424dfb3Schristos typedef struct ctf_link_sym 71*1424dfb3Schristos { 72*1424dfb3Schristos /* The st_name will not be accessed outside the call to 73*1424dfb3Schristos ctf_link_shuffle_syms(). */ 74*1424dfb3Schristos 75*1424dfb3Schristos const char *st_name; 76*1424dfb3Schristos uint32_t st_shndx; 77*1424dfb3Schristos uint32_t st_type; 78*1424dfb3Schristos uint32_t st_value; 79*1424dfb3Schristos } ctf_link_sym_t; 80*1424dfb3Schristos 81*1424dfb3Schristos /* Flags applying to this specific link. */ 82*1424dfb3Schristos 83*1424dfb3Schristos /* Share all types that are not in conflict. The default. */ 84*1424dfb3Schristos #define CTF_LINK_SHARE_UNCONFLICTED 0x0 85*1424dfb3Schristos 86*1424dfb3Schristos /* Share only types that are used by multiple inputs. */ 87*1424dfb3Schristos #define CTF_LINK_SHARE_DUPLICATED 0x1 88*1424dfb3Schristos 89*1424dfb3Schristos /* Do a nondeduplicating link. */ 90*1424dfb3Schristos #define CTF_LINK_NONDEDUP 0x2 91*1424dfb3Schristos 92*1424dfb3Schristos /* Create empty outputs for all registered CU mappings even if no types are 93*1424dfb3Schristos emitted into them. */ 94*1424dfb3Schristos #define CTF_LINK_EMPTY_CU_MAPPINGS 0x4 95*1424dfb3Schristos 96*1424dfb3Schristos /* Omit the content of the variables section. */ 97*1424dfb3Schristos #define CTF_LINK_OMIT_VARIABLES_SECTION 0x8 98*1424dfb3Schristos 99*1424dfb3Schristos /* Symbolic names for CTF sections. */ 100*1424dfb3Schristos 101*1424dfb3Schristos typedef enum ctf_sect_names 102*1424dfb3Schristos { 103*1424dfb3Schristos CTF_SECT_HEADER, 104*1424dfb3Schristos CTF_SECT_LABEL, 105*1424dfb3Schristos CTF_SECT_OBJT, 106*1424dfb3Schristos CTF_SECT_FUNC, 107*1424dfb3Schristos CTF_SECT_VAR, 108*1424dfb3Schristos CTF_SECT_TYPE, 109*1424dfb3Schristos CTF_SECT_STR 110*1424dfb3Schristos } ctf_sect_names_t; 111*1424dfb3Schristos 112*1424dfb3Schristos /* Encoding information for integers, floating-point values, and certain other 113*1424dfb3Schristos intrinsics can be obtained by calling ctf_type_encoding(), below. The flags 114*1424dfb3Schristos field will contain values appropriate for the type defined in <ctf.h>. */ 115*1424dfb3Schristos 116*1424dfb3Schristos typedef struct ctf_encoding 117*1424dfb3Schristos { 118*1424dfb3Schristos uint32_t cte_format; /* Data format (CTF_INT_* or CTF_FP_* flags). */ 119*1424dfb3Schristos uint32_t cte_offset; /* Offset of value in bits. */ 120*1424dfb3Schristos uint32_t cte_bits; /* Size of storage in bits. */ 121*1424dfb3Schristos } ctf_encoding_t; 122*1424dfb3Schristos 123*1424dfb3Schristos typedef struct ctf_membinfo 124*1424dfb3Schristos { 125*1424dfb3Schristos ctf_id_t ctm_type; /* Type of struct or union member. */ 126*1424dfb3Schristos unsigned long ctm_offset; /* Offset of member in bits. */ 127*1424dfb3Schristos } ctf_membinfo_t; 128*1424dfb3Schristos 129*1424dfb3Schristos typedef struct ctf_arinfo 130*1424dfb3Schristos { 131*1424dfb3Schristos ctf_id_t ctr_contents; /* Type of array contents. */ 132*1424dfb3Schristos ctf_id_t ctr_index; /* Type of array index. */ 133*1424dfb3Schristos uint32_t ctr_nelems; /* Number of elements. */ 134*1424dfb3Schristos } ctf_arinfo_t; 135*1424dfb3Schristos 136*1424dfb3Schristos typedef struct ctf_funcinfo 137*1424dfb3Schristos { 138*1424dfb3Schristos ctf_id_t ctc_return; /* Function return type. */ 139*1424dfb3Schristos uint32_t ctc_argc; /* Number of typed arguments to function. */ 140*1424dfb3Schristos uint32_t ctc_flags; /* Function attributes (see below). */ 141*1424dfb3Schristos } ctf_funcinfo_t; 142*1424dfb3Schristos 143*1424dfb3Schristos typedef struct ctf_lblinfo 144*1424dfb3Schristos { 145*1424dfb3Schristos ctf_id_t ctb_type; /* Last type associated with the label. */ 146*1424dfb3Schristos } ctf_lblinfo_t; 147*1424dfb3Schristos 148*1424dfb3Schristos typedef struct ctf_snapshot_id 149*1424dfb3Schristos { 150*1424dfb3Schristos unsigned long dtd_id; /* Highest DTD ID at time of snapshot. */ 151*1424dfb3Schristos unsigned long snapshot_id; /* Snapshot id at time of snapshot. */ 152*1424dfb3Schristos } ctf_snapshot_id_t; 153*1424dfb3Schristos 154*1424dfb3Schristos #define CTF_FUNC_VARARG 0x1 /* Function arguments end with varargs. */ 155*1424dfb3Schristos 156*1424dfb3Schristos /* Functions that return a ctf_id_t use the following value to indicate failure. 157*1424dfb3Schristos ctf_errno() can be used to obtain an error code. Functions that return 158*1424dfb3Schristos a straight integral -1 also use ctf_errno(). */ 159*1424dfb3Schristos #define CTF_ERR ((ctf_id_t) -1L) 160*1424dfb3Schristos 161*1424dfb3Schristos #define ECTF_BASE 1000 /* Base value for libctf errnos. */ 162*1424dfb3Schristos 163*1424dfb3Schristos 164*1424dfb3Schristos enum 165*1424dfb3Schristos { 166*1424dfb3Schristos ECTF_FMT = ECTF_BASE, /* File is not in CTF or ELF format. */ 167*1424dfb3Schristos ECTF_BFDERR, /* BFD error. */ 168*1424dfb3Schristos ECTF_CTFVERS, /* CTF dict version is too new for libctf. */ 169*1424dfb3Schristos ECTF_BFD_AMBIGUOUS, /* Ambiguous BFD target. */ 170*1424dfb3Schristos ECTF_SYMTAB, /* Symbol table uses invalid entry size. */ 171*1424dfb3Schristos ECTF_SYMBAD, /* Symbol table data buffer is not valid. */ 172*1424dfb3Schristos ECTF_STRBAD, /* String table data buffer is not valid. */ 173*1424dfb3Schristos ECTF_CORRUPT, /* File data structure corruption detected. */ 174*1424dfb3Schristos ECTF_NOCTFDATA, /* File does not contain CTF data. */ 175*1424dfb3Schristos ECTF_NOCTFBUF, /* Buffer does not contain CTF data. */ 176*1424dfb3Schristos ECTF_NOSYMTAB, /* Symbol table information is not available. */ 177*1424dfb3Schristos ECTF_NOPARENT, /* The parent CTF dictionary is unavailable. */ 178*1424dfb3Schristos ECTF_DMODEL, /* Data model mismatch. */ 179*1424dfb3Schristos ECTF_LINKADDEDLATE, /* File added to link too late. */ 180*1424dfb3Schristos ECTF_ZALLOC, /* Failed to allocate (de)compression buffer. */ 181*1424dfb3Schristos ECTF_DECOMPRESS, /* Failed to decompress CTF data. */ 182*1424dfb3Schristos ECTF_STRTAB, /* External string table is not available. */ 183*1424dfb3Schristos ECTF_BADNAME, /* String name offset is corrupt. */ 184*1424dfb3Schristos ECTF_BADID, /* Invalid type identifier. */ 185*1424dfb3Schristos ECTF_NOTSOU, /* Type is not a struct or union. */ 186*1424dfb3Schristos ECTF_NOTENUM, /* Type is not an enum. */ 187*1424dfb3Schristos ECTF_NOTSUE, /* Type is not a struct, union, or enum. */ 188*1424dfb3Schristos ECTF_NOTINTFP, /* Type is not an integer, float, or enum. */ 189*1424dfb3Schristos ECTF_NOTARRAY, /* Type is not an array. */ 190*1424dfb3Schristos ECTF_NOTREF, /* Type does not reference another type. */ 191*1424dfb3Schristos ECTF_NAMELEN, /* Buffer is too small to hold type name. */ 192*1424dfb3Schristos ECTF_NOTYPE, /* No type found corresponding to name. */ 193*1424dfb3Schristos ECTF_SYNTAX, /* Syntax error in type name. */ 194*1424dfb3Schristos ECTF_NOTFUNC, /* Symbol table entry or type is not a function. */ 195*1424dfb3Schristos ECTF_NOFUNCDAT, /* No function information available for function. */ 196*1424dfb3Schristos ECTF_NOTDATA, /* Symbol table entry does not refer to a data object. */ 197*1424dfb3Schristos ECTF_NOTYPEDAT, /* No type information available for symbol. */ 198*1424dfb3Schristos ECTF_NOLABEL, /* No label found corresponding to name. */ 199*1424dfb3Schristos ECTF_NOLABELDATA, /* File does not contain any labels. */ 200*1424dfb3Schristos ECTF_NOTSUP, /* Feature not supported. */ 201*1424dfb3Schristos ECTF_NOENUMNAM, /* Enum element name not found. */ 202*1424dfb3Schristos ECTF_NOMEMBNAM, /* Member name not found. */ 203*1424dfb3Schristos ECTF_RDONLY, /* CTF container is read-only. */ 204*1424dfb3Schristos ECTF_DTFULL, /* CTF type is full (no more members allowed). */ 205*1424dfb3Schristos ECTF_FULL, /* CTF container is full. */ 206*1424dfb3Schristos ECTF_DUPLICATE, /* Duplicate member or variable name. */ 207*1424dfb3Schristos ECTF_CONFLICT, /* Conflicting type is already defined. */ 208*1424dfb3Schristos ECTF_OVERROLLBACK, /* Attempt to roll back past a ctf_update. */ 209*1424dfb3Schristos ECTF_COMPRESS, /* Failed to compress CTF data. */ 210*1424dfb3Schristos ECTF_ARCREATE, /* Error creating CTF archive. */ 211*1424dfb3Schristos ECTF_ARNNAME, /* Name not found in CTF archive. */ 212*1424dfb3Schristos ECTF_SLICEOVERFLOW, /* Overflow of type bitness or offset in slice. */ 213*1424dfb3Schristos ECTF_DUMPSECTUNKNOWN, /* Unknown section number in dump. */ 214*1424dfb3Schristos ECTF_DUMPSECTCHANGED, /* Section changed in middle of dump. */ 215*1424dfb3Schristos ECTF_NOTYET, /* Feature not yet implemented. */ 216*1424dfb3Schristos ECTF_INTERNAL, /* Internal error: assertion failure. */ 217*1424dfb3Schristos ECTF_NONREPRESENTABLE, /* Type not representable in CTF. */ 218*1424dfb3Schristos ECTF_NEXT_END, /* End of iteration. */ 219*1424dfb3Schristos ECTF_NEXT_WRONGFUN, /* Wrong iteration function called. */ 220*1424dfb3Schristos ECTF_NEXT_WRONGFP, /* Iteration entity changed in mid-iterate. */ 221*1424dfb3Schristos ECTF_FLAGS, /* CTF header contains flags unknown to libctf. */ 222*1424dfb3Schristos ECTF_NEEDSBFD /* This feature needs a libctf with BFD support. */ 223*1424dfb3Schristos }; 224*1424dfb3Schristos 225*1424dfb3Schristos #define ECTF_NERR (ECTF_NEEDSBFD - ECTF_BASE + 1) /* Count of CTF errors. */ 226*1424dfb3Schristos 227*1424dfb3Schristos /* The CTF data model is inferred to be the caller's data model or the data 228*1424dfb3Schristos model of the given object, unless ctf_setmodel() is explicitly called. */ 229*1424dfb3Schristos #define CTF_MODEL_ILP32 1 /* Object data model is ILP32. */ 230*1424dfb3Schristos #define CTF_MODEL_LP64 2 /* Object data model is LP64. */ 231*1424dfb3Schristos #ifdef _LP64 232*1424dfb3Schristos # define CTF_MODEL_NATIVE CTF_MODEL_LP64 233*1424dfb3Schristos #else 234*1424dfb3Schristos # define CTF_MODEL_NATIVE CTF_MODEL_ILP32 235*1424dfb3Schristos #endif 236*1424dfb3Schristos 237*1424dfb3Schristos /* Dynamic CTF containers can be created using ctf_create(). The ctf_add_* 238*1424dfb3Schristos routines can be used to add new definitions to the dynamic container. 239*1424dfb3Schristos New types are labeled as root or non-root to determine whether they are 240*1424dfb3Schristos visible at the top-level program scope when subsequently doing a lookup. */ 241*1424dfb3Schristos 242*1424dfb3Schristos #define CTF_ADD_NONROOT 0 /* Type only visible in nested scope. */ 243*1424dfb3Schristos #define CTF_ADD_ROOT 1 /* Type visible at top-level scope. */ 244*1424dfb3Schristos 245*1424dfb3Schristos /* These typedefs are used to define the signature for callback functions that 246*1424dfb3Schristos can be used with the iteration and visit functions below. There is also a 247*1424dfb3Schristos family of iteration functions that do not require callbacks. */ 248*1424dfb3Schristos 249*1424dfb3Schristos typedef int ctf_visit_f (const char *name, ctf_id_t type, unsigned long offset, 250*1424dfb3Schristos int depth, void *arg); 251*1424dfb3Schristos typedef int ctf_member_f (const char *name, ctf_id_t membtype, 252*1424dfb3Schristos unsigned long offset, void *arg); 253*1424dfb3Schristos typedef int ctf_enum_f (const char *name, int val, void *arg); 254*1424dfb3Schristos typedef int ctf_variable_f (const char *name, ctf_id_t type, void *arg); 255*1424dfb3Schristos typedef int ctf_type_f (ctf_id_t type, void *arg); 256*1424dfb3Schristos typedef int ctf_type_all_f (ctf_id_t type, int flag, void *arg); 257*1424dfb3Schristos typedef int ctf_label_f (const char *name, const ctf_lblinfo_t *info, 258*1424dfb3Schristos void *arg); 259*1424dfb3Schristos typedef int ctf_archive_member_f (ctf_file_t *fp, const char *name, void *arg); 260*1424dfb3Schristos typedef int ctf_archive_raw_member_f (const char *name, const void *content, 261*1424dfb3Schristos size_t len, void *arg); 262*1424dfb3Schristos typedef char *ctf_dump_decorate_f (ctf_sect_names_t sect, 263*1424dfb3Schristos char *line, void *arg); 264*1424dfb3Schristos 265*1424dfb3Schristos typedef struct ctf_dump_state ctf_dump_state_t; 266*1424dfb3Schristos 267*1424dfb3Schristos /* Iteration state for the _next() functions, and allocators/copiers/freers for 268*1424dfb3Schristos it. (None of these are needed for the simple case of iterating to the end: 269*1424dfb3Schristos the _next() function allocate and free the iterators for you.) */ 270*1424dfb3Schristos 271*1424dfb3Schristos typedef struct ctf_next ctf_next_t; 272*1424dfb3Schristos extern ctf_next_t *ctf_next_create (void); 273*1424dfb3Schristos extern void ctf_next_destroy (ctf_next_t *); 274*1424dfb3Schristos extern ctf_next_t *ctf_next_copy (ctf_next_t *); 275*1424dfb3Schristos 276*1424dfb3Schristos /* Opening. These mostly return an abstraction over both CTF files and CTF 277*1424dfb3Schristos archives: so they can be used to open both. CTF files will appear to be an 278*1424dfb3Schristos archive with one member named '.ctf'. The low-level functions 279*1424dfb3Schristos ctf_simple_open() and ctf_bufopen() return ctf_file_t's directly, and cannot 280*1424dfb3Schristos be used on CTF archives. */ 281*1424dfb3Schristos 282*1424dfb3Schristos extern ctf_archive_t *ctf_bfdopen (struct bfd *, int *); 283*1424dfb3Schristos extern ctf_archive_t *ctf_bfdopen_ctfsect (struct bfd *, const ctf_sect_t *, 284*1424dfb3Schristos int *); 285*1424dfb3Schristos extern ctf_archive_t *ctf_fdopen (int fd, const char *filename, 286*1424dfb3Schristos const char *target, int *errp); 287*1424dfb3Schristos extern ctf_archive_t *ctf_open (const char *filename, 288*1424dfb3Schristos const char *target, int *errp); 289*1424dfb3Schristos extern void ctf_close (ctf_archive_t *); 290*1424dfb3Schristos extern ctf_sect_t ctf_getdatasect (const ctf_file_t *); 291*1424dfb3Schristos extern ctf_archive_t *ctf_get_arc (const ctf_file_t *); 292*1424dfb3Schristos extern ctf_archive_t *ctf_arc_open (const char *, int *); 293*1424dfb3Schristos extern ctf_archive_t *ctf_arc_bufopen (const ctf_sect_t *, 294*1424dfb3Schristos const ctf_sect_t *, 295*1424dfb3Schristos const ctf_sect_t *, 296*1424dfb3Schristos int *); 297*1424dfb3Schristos extern void ctf_arc_close (ctf_archive_t *); 298*1424dfb3Schristos extern ctf_file_t *ctf_arc_open_by_name (const ctf_archive_t *, 299*1424dfb3Schristos const char *, int *); 300*1424dfb3Schristos extern ctf_file_t *ctf_arc_open_by_name_sections (const ctf_archive_t *, 301*1424dfb3Schristos const ctf_sect_t *, 302*1424dfb3Schristos const ctf_sect_t *, 303*1424dfb3Schristos const char *, int *); 304*1424dfb3Schristos extern size_t ctf_archive_count (const ctf_archive_t *); 305*1424dfb3Schristos 306*1424dfb3Schristos /* The next functions return or close real CTF files, or write out CTF archives, 307*1424dfb3Schristos not opaque containers around either. */ 308*1424dfb3Schristos 309*1424dfb3Schristos extern ctf_file_t *ctf_simple_open (const char *, size_t, const char *, size_t, 310*1424dfb3Schristos size_t, const char *, size_t, int *); 311*1424dfb3Schristos extern ctf_file_t *ctf_bufopen (const ctf_sect_t *, const ctf_sect_t *, 312*1424dfb3Schristos const ctf_sect_t *, int *); 313*1424dfb3Schristos extern void ctf_ref (ctf_file_t *); 314*1424dfb3Schristos extern void ctf_file_close (ctf_file_t *); 315*1424dfb3Schristos 316*1424dfb3Schristos extern int ctf_arc_write (const char *, ctf_file_t **, size_t, 317*1424dfb3Schristos const char **, size_t); 318*1424dfb3Schristos extern int ctf_arc_write_fd (int, ctf_file_t **, size_t, const char **, 319*1424dfb3Schristos size_t); 320*1424dfb3Schristos 321*1424dfb3Schristos extern const char *ctf_cuname (ctf_file_t *); 322*1424dfb3Schristos extern int ctf_cuname_set (ctf_file_t *, const char *); 323*1424dfb3Schristos extern ctf_file_t *ctf_parent_file (ctf_file_t *); 324*1424dfb3Schristos extern const char *ctf_parent_name (ctf_file_t *); 325*1424dfb3Schristos extern int ctf_parent_name_set (ctf_file_t *, const char *); 326*1424dfb3Schristos extern int ctf_type_isparent (ctf_file_t *, ctf_id_t); 327*1424dfb3Schristos extern int ctf_type_ischild (ctf_file_t *, ctf_id_t); 328*1424dfb3Schristos 329*1424dfb3Schristos extern int ctf_import (ctf_file_t *, ctf_file_t *); 330*1424dfb3Schristos extern int ctf_setmodel (ctf_file_t *, int); 331*1424dfb3Schristos extern int ctf_getmodel (ctf_file_t *); 332*1424dfb3Schristos 333*1424dfb3Schristos extern void ctf_setspecific (ctf_file_t *, void *); 334*1424dfb3Schristos extern void *ctf_getspecific (ctf_file_t *); 335*1424dfb3Schristos 336*1424dfb3Schristos extern int ctf_errno (ctf_file_t *); 337*1424dfb3Schristos extern const char *ctf_errmsg (int); 338*1424dfb3Schristos extern int ctf_version (int); 339*1424dfb3Schristos 340*1424dfb3Schristos extern int ctf_func_info (ctf_file_t *, unsigned long, ctf_funcinfo_t *); 341*1424dfb3Schristos extern int ctf_func_args (ctf_file_t *, unsigned long, uint32_t, ctf_id_t *); 342*1424dfb3Schristos extern int ctf_func_type_info (ctf_file_t *, ctf_id_t, ctf_funcinfo_t *); 343*1424dfb3Schristos extern int ctf_func_type_args (ctf_file_t *, ctf_id_t, uint32_t, ctf_id_t *); 344*1424dfb3Schristos 345*1424dfb3Schristos extern ctf_id_t ctf_lookup_by_name (ctf_file_t *, const char *); 346*1424dfb3Schristos extern ctf_id_t ctf_lookup_by_symbol (ctf_file_t *, unsigned long); 347*1424dfb3Schristos extern ctf_id_t ctf_lookup_variable (ctf_file_t *, const char *); 348*1424dfb3Schristos 349*1424dfb3Schristos extern ctf_id_t ctf_type_resolve (ctf_file_t *, ctf_id_t); 350*1424dfb3Schristos extern char *ctf_type_aname (ctf_file_t *, ctf_id_t); 351*1424dfb3Schristos extern char *ctf_type_aname_raw (ctf_file_t *, ctf_id_t); 352*1424dfb3Schristos extern ssize_t ctf_type_lname (ctf_file_t *, ctf_id_t, char *, size_t); 353*1424dfb3Schristos extern char *ctf_type_name (ctf_file_t *, ctf_id_t, char *, size_t); 354*1424dfb3Schristos extern const char *ctf_type_name_raw (ctf_file_t *, ctf_id_t); 355*1424dfb3Schristos extern ssize_t ctf_type_size (ctf_file_t *, ctf_id_t); 356*1424dfb3Schristos extern ssize_t ctf_type_align (ctf_file_t *, ctf_id_t); 357*1424dfb3Schristos extern int ctf_type_kind (ctf_file_t *, ctf_id_t); 358*1424dfb3Schristos extern int ctf_type_kind_forwarded (ctf_file_t *, ctf_id_t); 359*1424dfb3Schristos extern ctf_id_t ctf_type_reference (ctf_file_t *, ctf_id_t); 360*1424dfb3Schristos extern ctf_id_t ctf_type_pointer (ctf_file_t *, ctf_id_t); 361*1424dfb3Schristos extern int ctf_type_encoding (ctf_file_t *, ctf_id_t, ctf_encoding_t *); 362*1424dfb3Schristos extern int ctf_type_visit (ctf_file_t *, ctf_id_t, ctf_visit_f *, void *); 363*1424dfb3Schristos extern int ctf_type_cmp (ctf_file_t *, ctf_id_t, ctf_file_t *, ctf_id_t); 364*1424dfb3Schristos extern int ctf_type_compat (ctf_file_t *, ctf_id_t, ctf_file_t *, ctf_id_t); 365*1424dfb3Schristos 366*1424dfb3Schristos extern int ctf_member_info (ctf_file_t *, ctf_id_t, const char *, 367*1424dfb3Schristos ctf_membinfo_t *); 368*1424dfb3Schristos extern int ctf_array_info (ctf_file_t *, ctf_id_t, ctf_arinfo_t *); 369*1424dfb3Schristos 370*1424dfb3Schristos extern const char *ctf_enum_name (ctf_file_t *, ctf_id_t, int); 371*1424dfb3Schristos extern int ctf_enum_value (ctf_file_t *, ctf_id_t, const char *, int *); 372*1424dfb3Schristos 373*1424dfb3Schristos extern void ctf_label_set (ctf_file_t *, const char *); 374*1424dfb3Schristos extern const char *ctf_label_get (ctf_file_t *); 375*1424dfb3Schristos 376*1424dfb3Schristos extern const char *ctf_label_topmost (ctf_file_t *); 377*1424dfb3Schristos extern int ctf_label_info (ctf_file_t *, const char *, ctf_lblinfo_t *); 378*1424dfb3Schristos 379*1424dfb3Schristos extern int ctf_member_count (ctf_file_t *, ctf_id_t); 380*1424dfb3Schristos extern int ctf_member_iter (ctf_file_t *, ctf_id_t, ctf_member_f *, void *); 381*1424dfb3Schristos extern ssize_t ctf_member_next (ctf_file_t *, ctf_id_t, ctf_next_t **, 382*1424dfb3Schristos const char **name, ctf_id_t *membtype); 383*1424dfb3Schristos extern int ctf_enum_iter (ctf_file_t *, ctf_id_t, ctf_enum_f *, void *); 384*1424dfb3Schristos extern const char *ctf_enum_next (ctf_file_t *, ctf_id_t, ctf_next_t **, 385*1424dfb3Schristos int *); 386*1424dfb3Schristos extern int ctf_type_iter (ctf_file_t *, ctf_type_f *, void *); 387*1424dfb3Schristos extern int ctf_type_iter_all (ctf_file_t *, ctf_type_all_f *, void *); 388*1424dfb3Schristos extern ctf_id_t ctf_type_next (ctf_file_t *, ctf_next_t **, 389*1424dfb3Schristos int *flag, int want_hidden); 390*1424dfb3Schristos extern int ctf_label_iter (ctf_file_t *, ctf_label_f *, void *); 391*1424dfb3Schristos extern int ctf_label_next (ctf_file_t *, ctf_next_t **, const char **); /* TBD */ 392*1424dfb3Schristos extern int ctf_variable_iter (ctf_file_t *, ctf_variable_f *, void *); 393*1424dfb3Schristos extern ctf_id_t ctf_variable_next (ctf_file_t *, ctf_next_t **, 394*1424dfb3Schristos const char **); 395*1424dfb3Schristos extern int ctf_archive_iter (const ctf_archive_t *, ctf_archive_member_f *, 396*1424dfb3Schristos void *); 397*1424dfb3Schristos extern ctf_file_t *ctf_archive_next (const ctf_archive_t *, ctf_next_t **, 398*1424dfb3Schristos const char **, int skip_parent, int *errp); 399*1424dfb3Schristos 400*1424dfb3Schristos /* This function alone does not currently operate on CTF files masquerading 401*1424dfb3Schristos as archives, and returns -EINVAL: the raw data is no longer available. It is 402*1424dfb3Schristos expected to be used only by archiving tools, in any case, which have no need 403*1424dfb3Schristos to deal with non-archives at all. */ 404*1424dfb3Schristos extern int ctf_archive_raw_iter (const ctf_archive_t *, 405*1424dfb3Schristos ctf_archive_raw_member_f *, void *); 406*1424dfb3Schristos extern char *ctf_dump (ctf_file_t *, ctf_dump_state_t **state, 407*1424dfb3Schristos ctf_sect_names_t sect, ctf_dump_decorate_f *, 408*1424dfb3Schristos void *arg); 409*1424dfb3Schristos 410*1424dfb3Schristos /* Error-warning reporting: an 'iterator' that returns errors and warnings from 411*1424dfb3Schristos the error/warning list, in order of emission. Errors and warnings are popped 412*1424dfb3Schristos after return: the caller must free the returned error-text pointer. */ 413*1424dfb3Schristos extern char *ctf_errwarning_next (ctf_file_t *, ctf_next_t **, 414*1424dfb3Schristos int *is_warning, int *errp); 415*1424dfb3Schristos 416*1424dfb3Schristos extern ctf_id_t ctf_add_array (ctf_file_t *, uint32_t, 417*1424dfb3Schristos const ctf_arinfo_t *); 418*1424dfb3Schristos extern ctf_id_t ctf_add_const (ctf_file_t *, uint32_t, ctf_id_t); 419*1424dfb3Schristos extern ctf_id_t ctf_add_enum_encoded (ctf_file_t *, uint32_t, const char *, 420*1424dfb3Schristos const ctf_encoding_t *); 421*1424dfb3Schristos extern ctf_id_t ctf_add_enum (ctf_file_t *, uint32_t, const char *); 422*1424dfb3Schristos extern ctf_id_t ctf_add_float (ctf_file_t *, uint32_t, 423*1424dfb3Schristos const char *, const ctf_encoding_t *); 424*1424dfb3Schristos extern ctf_id_t ctf_add_forward (ctf_file_t *, uint32_t, const char *, 425*1424dfb3Schristos uint32_t); 426*1424dfb3Schristos extern ctf_id_t ctf_add_function (ctf_file_t *, uint32_t, 427*1424dfb3Schristos const ctf_funcinfo_t *, const ctf_id_t *); 428*1424dfb3Schristos extern ctf_id_t ctf_add_integer (ctf_file_t *, uint32_t, const char *, 429*1424dfb3Schristos const ctf_encoding_t *); 430*1424dfb3Schristos extern ctf_id_t ctf_add_slice (ctf_file_t *, uint32_t, ctf_id_t, const ctf_encoding_t *); 431*1424dfb3Schristos extern ctf_id_t ctf_add_pointer (ctf_file_t *, uint32_t, ctf_id_t); 432*1424dfb3Schristos extern ctf_id_t ctf_add_type (ctf_file_t *, ctf_file_t *, ctf_id_t); 433*1424dfb3Schristos extern ctf_id_t ctf_add_typedef (ctf_file_t *, uint32_t, const char *, 434*1424dfb3Schristos ctf_id_t); 435*1424dfb3Schristos extern ctf_id_t ctf_add_restrict (ctf_file_t *, uint32_t, ctf_id_t); 436*1424dfb3Schristos extern ctf_id_t ctf_add_struct (ctf_file_t *, uint32_t, const char *); 437*1424dfb3Schristos extern ctf_id_t ctf_add_union (ctf_file_t *, uint32_t, const char *); 438*1424dfb3Schristos extern ctf_id_t ctf_add_struct_sized (ctf_file_t *, uint32_t, const char *, 439*1424dfb3Schristos size_t); 440*1424dfb3Schristos extern ctf_id_t ctf_add_union_sized (ctf_file_t *, uint32_t, const char *, 441*1424dfb3Schristos size_t); 442*1424dfb3Schristos extern ctf_id_t ctf_add_volatile (ctf_file_t *, uint32_t, ctf_id_t); 443*1424dfb3Schristos 444*1424dfb3Schristos extern int ctf_add_enumerator (ctf_file_t *, ctf_id_t, const char *, int); 445*1424dfb3Schristos extern int ctf_add_member (ctf_file_t *, ctf_id_t, const char *, ctf_id_t); 446*1424dfb3Schristos extern int ctf_add_member_offset (ctf_file_t *, ctf_id_t, const char *, 447*1424dfb3Schristos ctf_id_t, unsigned long); 448*1424dfb3Schristos extern int ctf_add_member_encoded (ctf_file_t *, ctf_id_t, const char *, 449*1424dfb3Schristos ctf_id_t, unsigned long, 450*1424dfb3Schristos const ctf_encoding_t); 451*1424dfb3Schristos 452*1424dfb3Schristos extern int ctf_add_variable (ctf_file_t *, const char *, ctf_id_t); 453*1424dfb3Schristos 454*1424dfb3Schristos extern int ctf_set_array (ctf_file_t *, ctf_id_t, const ctf_arinfo_t *); 455*1424dfb3Schristos 456*1424dfb3Schristos extern ctf_file_t *ctf_create (int *); 457*1424dfb3Schristos extern int ctf_update (ctf_file_t *); 458*1424dfb3Schristos extern ctf_snapshot_id_t ctf_snapshot (ctf_file_t *); 459*1424dfb3Schristos extern int ctf_rollback (ctf_file_t *, ctf_snapshot_id_t); 460*1424dfb3Schristos extern int ctf_discard (ctf_file_t *); 461*1424dfb3Schristos extern int ctf_write (ctf_file_t *, int); 462*1424dfb3Schristos extern int ctf_gzwrite (ctf_file_t *fp, gzFile fd); 463*1424dfb3Schristos extern int ctf_compress_write (ctf_file_t * fp, int fd); 464*1424dfb3Schristos extern unsigned char *ctf_write_mem (ctf_file_t *, size_t *, size_t threshold); 465*1424dfb3Schristos 466*1424dfb3Schristos extern int ctf_link_add_ctf (ctf_file_t *, ctf_archive_t *, const char *); 467*1424dfb3Schristos /* The variable filter should return nonzero if a variable should not 468*1424dfb3Schristos appear in the output. */ 469*1424dfb3Schristos typedef int ctf_link_variable_filter_f (ctf_file_t *, const char *, ctf_id_t, 470*1424dfb3Schristos void *); 471*1424dfb3Schristos extern int ctf_link_set_variable_filter (ctf_file_t *, 472*1424dfb3Schristos ctf_link_variable_filter_f *, void *); 473*1424dfb3Schristos extern int ctf_link (ctf_file_t *, int flags); 474*1424dfb3Schristos typedef const char *ctf_link_strtab_string_f (uint32_t *offset, void *arg); 475*1424dfb3Schristos extern int ctf_link_add_strtab (ctf_file_t *, ctf_link_strtab_string_f *, 476*1424dfb3Schristos void *); 477*1424dfb3Schristos typedef ctf_link_sym_t *ctf_link_iter_symbol_f (ctf_link_sym_t *dest, 478*1424dfb3Schristos void *arg); 479*1424dfb3Schristos extern int ctf_link_shuffle_syms (ctf_file_t *, ctf_link_iter_symbol_f *, 480*1424dfb3Schristos void *); 481*1424dfb3Schristos extern unsigned char *ctf_link_write (ctf_file_t *, size_t *size, 482*1424dfb3Schristos size_t threshold); 483*1424dfb3Schristos 484*1424dfb3Schristos /* Specialist linker functions. These functions are not used by ld, but can be 485*1424dfb3Schristos used by other programs making use of the linker machinery for other purposes 486*1424dfb3Schristos to customize its output. */ 487*1424dfb3Schristos extern int ctf_link_add_cu_mapping (ctf_file_t *, const char *from, 488*1424dfb3Schristos const char *to); 489*1424dfb3Schristos typedef char *ctf_link_memb_name_changer_f (ctf_file_t *, 490*1424dfb3Schristos const char *, void *); 491*1424dfb3Schristos extern void ctf_link_set_memb_name_changer 492*1424dfb3Schristos (ctf_file_t *, ctf_link_memb_name_changer_f *, void *); 493*1424dfb3Schristos 494*1424dfb3Schristos extern void ctf_setdebug (int debug); 495*1424dfb3Schristos extern int ctf_getdebug (void); 496*1424dfb3Schristos 497*1424dfb3Schristos #ifdef __cplusplus 498*1424dfb3Schristos } 499*1424dfb3Schristos #endif 500*1424dfb3Schristos 501*1424dfb3Schristos #endif /* _CTF_API_H */ 502