4cac635e57e7c7f7ea220d19de6f52572e275094
[deliverable/binutils-gdb.git] / include / ctf-api.h
1 /* Public API to libctf.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3
4 This file is part of libctf.
5
6 libctf is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; see the file COPYING. If not see
18 <http://www.gnu.org/licenses/>. */
19
20 /* This header file defines the interfaces available from the CTF debugger
21 library, libctf. This API can be used by a debugger to operate on data in
22 the Compact ANSI-C Type Format (CTF). */
23
24 #ifndef _CTF_API_H
25 #define _CTF_API_H
26
27 #include <sys/param.h>
28 #include <sys/types.h>
29 #include <ctf.h>
30 #include <zlib.h>
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36
37 /* Clients can open one or more CTF containers and obtain a pointer to an
38 opaque ctf_file_t. Types are identified by an opaque ctf_id_t token.
39 They can also open or create read-only archives of CTF containers in a
40 ctf_archive_t.
41
42 These opaque definitions allow libctf to evolve without breaking clients. */
43
44 typedef struct ctf_file ctf_file_t;
45 typedef struct ctf_archive_internal ctf_archive_t;
46 typedef long ctf_id_t;
47
48 /* If the debugger needs to provide the CTF library with a set of raw buffers
49 for use as the CTF data, symbol table, and string table, it can do so by
50 filling in ctf_sect_t structures and passing them to ctf_bufopen().
51
52 The contents of this structure must always be in native endianness (no
53 byteswapping is performed). */
54
55 typedef struct ctf_sect
56 {
57 const char *cts_name; /* Section name (if any). */
58 unsigned long cts_type; /* Section type (ELF SHT_... value). */
59 unsigned long cts_flags; /* Section flags (ELF SHF_... value). */
60 const void *cts_data; /* Pointer to section data. */
61 size_t cts_size; /* Size of data in bytes. */
62 size_t cts_entsize; /* Size of each section entry (symtab only). */
63 off64_t cts_offset; /* File offset of this section (if any). */
64 } ctf_sect_t;
65
66 /* Symbolic names for CTF sections. */
67
68 typedef enum ctf_sect_names
69 {
70 CTF_SECT_HEADER,
71 CTF_SECT_LABEL,
72 CTF_SECT_OBJT,
73 CTF_SECT_FUNC,
74 CTF_SECT_VAR,
75 CTF_SECT_TYPE,
76 CTF_SECT_STR
77 } ctf_sect_names_t;
78
79 /* Encoding information for integers, floating-point values, and certain other
80 intrinsics can be obtained by calling ctf_type_encoding(), below. The flags
81 field will contain values appropriate for the type defined in <ctf.h>. */
82
83 typedef struct ctf_encoding
84 {
85 uint32_t cte_format; /* Data format (CTF_INT_* or CTF_FP_* flags). */
86 uint32_t cte_offset; /* Offset of value in bits. */
87 uint32_t cte_bits; /* Size of storage in bits. */
88 } ctf_encoding_t;
89
90 typedef struct ctf_membinfo
91 {
92 ctf_id_t ctm_type; /* Type of struct or union member. */
93 unsigned long ctm_offset; /* Offset of member in bits. */
94 } ctf_membinfo_t;
95
96 typedef struct ctf_arinfo
97 {
98 ctf_id_t ctr_contents; /* Type of array contents. */
99 ctf_id_t ctr_index; /* Type of array index. */
100 uint32_t ctr_nelems; /* Number of elements. */
101 } ctf_arinfo_t;
102
103 typedef struct ctf_funcinfo
104 {
105 ctf_id_t ctc_return; /* Function return type. */
106 uint32_t ctc_argc; /* Number of typed arguments to function. */
107 uint32_t ctc_flags; /* Function attributes (see below). */
108 } ctf_funcinfo_t;
109
110 typedef struct ctf_lblinfo
111 {
112 ctf_id_t ctb_type; /* Last type associated with the label. */
113 } ctf_lblinfo_t;
114
115 typedef struct ctf_snapshot_id
116 {
117 unsigned long dtd_id; /* Highest DTD ID at time of snapshot. */
118 unsigned long snapshot_id; /* Snapshot id at time of snapshot. */
119 } ctf_snapshot_id_t;
120
121 #define CTF_FUNC_VARARG 0x1 /* Function arguments end with varargs. */
122
123 /* Functions that return integer status or a ctf_id_t use the following value
124 to indicate failure. ctf_errno() can be used to obtain an error code. */
125 #define CTF_ERR (-1L)
126
127 #define ECTF_BASE 1000 /* Base value for libctf errnos. */
128
129
130 enum
131 {
132 ECTF_FMT = ECTF_BASE, /* File is not in CTF or ELF format. */
133 ECTF_BFDERR, /* BFD error. */
134 ECTF_CTFVERS, /* CTF version is more recent than libctf. */
135 ECTF_BFD_AMBIGUOUS, /* Ambiguous BFD target. */
136 ECTF_SYMTAB, /* Symbol table uses invalid entry size. */
137 ECTF_SYMBAD, /* Symbol table data buffer invalid. */
138 ECTF_STRBAD, /* String table data buffer invalid. */
139 ECTF_CORRUPT, /* File data corruption detected. */
140 ECTF_NOCTFDATA, /* ELF file does not contain CTF data. */
141 ECTF_NOCTFBUF, /* Buffer does not contain CTF data. */
142 ECTF_NOSYMTAB, /* Symbol table data is not available. */
143 ECTF_NOPARENT, /* Parent CTF container is not available. */
144 ECTF_DMODEL, /* Data model mismatch. */
145 ECTF_UNUSED, /* Unused error. */
146 ECTF_ZALLOC, /* Failed to allocate (de)compression buffer. */
147 ECTF_DECOMPRESS, /* Failed to decompress CTF data. */
148 ECTF_STRTAB, /* String table for this string is missing. */
149 ECTF_BADNAME, /* String offset is corrupt w.r.t. strtab. */
150 ECTF_BADID, /* Invalid type ID number. */
151 ECTF_NOTSOU, /* Type is not a struct or union. */
152 ECTF_NOTENUM, /* Type is not an enum. */
153 ECTF_NOTSUE, /* Type is not a struct, union, or enum. */
154 ECTF_NOTINTFP, /* Type is not an integer, float, or enum. */
155 ECTF_NOTARRAY, /* Type is not an array. */
156 ECTF_NOTREF, /* Type does not reference another type. */
157 ECTF_NAMELEN, /* Buffer is too small to hold type name. */
158 ECTF_NOTYPE, /* No type found corresponding to name. */
159 ECTF_SYNTAX, /* Syntax error in type name. */
160 ECTF_NOTFUNC, /* Symtab entry does not refer to a function. */
161 ECTF_NOFUNCDAT, /* No func info available for function. */
162 ECTF_NOTDATA, /* Symtab entry does not refer to a data obj. */
163 ECTF_NOTYPEDAT, /* No type info available for object. */
164 ECTF_NOLABEL, /* No label found corresponding to name. */
165 ECTF_NOLABELDATA, /* File does not contain any labels. */
166 ECTF_NOTSUP, /* Feature not supported. */
167 ECTF_NOENUMNAM, /* Enum element name not found. */
168 ECTF_NOMEMBNAM, /* Member name not found. */
169 ECTF_RDONLY, /* CTF container is read-only. */
170 ECTF_DTFULL, /* CTF type is full (no more members allowed). */
171 ECTF_FULL, /* CTF container is full. */
172 ECTF_DUPLICATE, /* Duplicate member or variable name. */
173 ECTF_CONFLICT, /* Conflicting type definition present. */
174 ECTF_OVERROLLBACK, /* Attempt to roll back past a ctf_update. */
175 ECTF_COMPRESS, /* Failed to compress CTF data. */
176 ECTF_ARCREATE, /* Error creating CTF archive. */
177 ECTF_ARNNAME, /* Name not found in CTF archive. */
178 ECTF_SLICEOVERFLOW, /* Overflow of type bitness or offset in slice. */
179 ECTF_DUMPSECTUNKNOWN, /* Unknown section number in dump. */
180 ECTF_DUMPSECTCHANGED /* Section changed in middle of dump. */
181 };
182
183 /* The CTF data model is inferred to be the caller's data model or the data
184 model of the given object, unless ctf_setmodel() is explicitly called. */
185 #define CTF_MODEL_ILP32 1 /* Object data model is ILP32. */
186 #define CTF_MODEL_LP64 2 /* Object data model is LP64. */
187 #ifdef _LP64
188 # define CTF_MODEL_NATIVE CTF_MODEL_LP64
189 #else
190 # define CTF_MODEL_NATIVE CTF_MODEL_ILP32
191 #endif
192
193 /* Dynamic CTF containers can be created using ctf_create(). The ctf_add_*
194 routines can be used to add new definitions to the dynamic container.
195 New types are labeled as root or non-root to determine whether they are
196 visible at the top-level program scope when subsequently doing a lookup. */
197
198 #define CTF_ADD_NONROOT 0 /* Type only visible in nested scope. */
199 #define CTF_ADD_ROOT 1 /* Type visible at top-level scope. */
200
201 /* These typedefs are used to define the signature for callback functions
202 that can be used with the iteration and visit functions below. */
203
204 typedef int ctf_archive_member_f (ctf_file_t *fp, const char *name, void *arg);
205 typedef int ctf_archive_raw_member_f (const char *name, const void *content,
206 size_t len, void *arg);
207
208 extern ctf_sect_t ctf_getdatasect (const ctf_file_t *);
209 extern ctf_archive_t *ctf_get_arc (const ctf_file_t *);
210 extern void ctf_arc_close (ctf_archive_t *);
211 extern ctf_file_t *ctf_arc_open_by_name (const ctf_archive_t *,
212 const char *, int *);
213 extern ctf_file_t *ctf_arc_open_by_name_sections (const ctf_archive_t *,
214 const ctf_sect_t *,
215 const ctf_sect_t *,
216 const char *, int *);
217
218 /* The next functions return or close real CTF files, or write out CTF archives,
219 not opaque containers around either. */
220
221 extern ctf_file_t *ctf_simple_open (const char *, size_t, const char *, size_t,
222 size_t, const char *, size_t, int *);
223 extern ctf_file_t *ctf_bufopen (const ctf_sect_t *, const ctf_sect_t *,
224 const ctf_sect_t *, int *);
225 extern void ctf_file_close (ctf_file_t *);
226
227 extern int ctf_arc_write (const char *, ctf_file_t **, size_t,
228 const char **, size_t);
229
230 extern ctf_file_t *ctf_parent_file (ctf_file_t *);
231 extern const char *ctf_parent_name (ctf_file_t *);
232 extern void ctf_parent_name_set (ctf_file_t *, const char *);
233
234 extern int ctf_import (ctf_file_t *, ctf_file_t *);
235 extern int ctf_setmodel (ctf_file_t *, int);
236 extern int ctf_getmodel (ctf_file_t *);
237
238 extern void ctf_setspecific (ctf_file_t *, void *);
239 extern void *ctf_getspecific (ctf_file_t *);
240
241 extern int ctf_errno (ctf_file_t *);
242 extern const char *ctf_errmsg (int);
243 extern int ctf_archive_iter (const ctf_archive_t *, ctf_archive_member_f *,
244 void *);
245 /* This function alone does not currently operate on CTF files masquerading
246 as archives, and returns -EINVAL: the raw data is no longer available. It is
247 expected to be used only by archiving tools, in any case, which have no need
248 to deal with non-archives at all. */
249 extern int ctf_archive_raw_iter (const ctf_archive_t *,
250 ctf_archive_raw_member_f *, void *);
251 extern ctf_id_t ctf_add_array (ctf_file_t *, uint32_t,
252 const ctf_arinfo_t *);
253 extern ctf_id_t ctf_add_const (ctf_file_t *, uint32_t, ctf_id_t);
254 extern ctf_id_t ctf_add_enum_encoded (ctf_file_t *, uint32_t, const char *,
255 const ctf_encoding_t *);
256 extern ctf_id_t ctf_add_enum (ctf_file_t *, uint32_t, const char *);
257 extern ctf_id_t ctf_add_float (ctf_file_t *, uint32_t,
258 const char *, const ctf_encoding_t *);
259 extern ctf_id_t ctf_add_forward (ctf_file_t *, uint32_t, const char *,
260 uint32_t);
261 extern ctf_id_t ctf_add_function (ctf_file_t *, uint32_t,
262 const ctf_funcinfo_t *, const ctf_id_t *);
263 extern ctf_id_t ctf_add_integer (ctf_file_t *, uint32_t, const char *,
264 const ctf_encoding_t *);
265 extern ctf_id_t ctf_add_slice (ctf_file_t *, uint32_t, ctf_id_t, const ctf_encoding_t *);
266 extern ctf_id_t ctf_add_pointer (ctf_file_t *, uint32_t, ctf_id_t);
267 extern ctf_id_t ctf_add_type (ctf_file_t *, ctf_file_t *, ctf_id_t);
268 extern ctf_id_t ctf_add_typedef (ctf_file_t *, uint32_t, const char *,
269 ctf_id_t);
270 extern ctf_id_t ctf_add_restrict (ctf_file_t *, uint32_t, ctf_id_t);
271 extern ctf_id_t ctf_add_struct (ctf_file_t *, uint32_t, const char *);
272 extern ctf_id_t ctf_add_union (ctf_file_t *, uint32_t, const char *);
273 extern ctf_id_t ctf_add_struct_sized (ctf_file_t *, uint32_t, const char *,
274 size_t);
275 extern ctf_id_t ctf_add_union_sized (ctf_file_t *, uint32_t, const char *,
276 size_t);
277 extern ctf_id_t ctf_add_volatile (ctf_file_t *, uint32_t, ctf_id_t);
278
279 extern int ctf_add_enumerator (ctf_file_t *, ctf_id_t, const char *, int);
280 extern int ctf_add_member (ctf_file_t *, ctf_id_t, const char *, ctf_id_t);
281 extern int ctf_add_member_offset (ctf_file_t *, ctf_id_t, const char *,
282 ctf_id_t, unsigned long);
283 extern int ctf_add_member_encoded (ctf_file_t *, ctf_id_t, const char *,
284 ctf_id_t, unsigned long,
285 const ctf_encoding_t);
286
287 extern int ctf_add_variable (ctf_file_t *, const char *, ctf_id_t);
288
289 extern int ctf_set_array (ctf_file_t *, ctf_id_t, const ctf_arinfo_t *);
290
291 extern ctf_file_t *ctf_create (int *);
292 extern int ctf_update (ctf_file_t *);
293 extern ctf_snapshot_id_t ctf_snapshot (ctf_file_t *);
294 extern int ctf_rollback (ctf_file_t *, ctf_snapshot_id_t);
295 extern int ctf_discard (ctf_file_t *);
296 extern int ctf_write (ctf_file_t *, int);
297 extern int ctf_gzwrite (ctf_file_t * fp, gzFile fd);
298 extern int ctf_compress_write (ctf_file_t * fp, int fd);
299
300 extern void ctf_setdebug (int debug);
301 extern int ctf_getdebug (void);
302
303 #ifdef __cplusplus
304 }
305 #endif
306
307 #endif /* _CTF_API_H */
This page took 0.035672 seconds and 4 git commands to generate.