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