xref: /onnv-gate/usr/src/uts/common/sys/ctf_api.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate /*
28*0Sstevel@tonic-gate  * This header file defines the interfaces available from the CTF debugger
29*0Sstevel@tonic-gate  * library, libctf, and an equivalent kernel module.  This API can be used by
30*0Sstevel@tonic-gate  * a debugger to operate on data in the Compact ANSI-C Type Format (CTF).
31*0Sstevel@tonic-gate  * This is NOT a public interface, although it may eventually become one in
32*0Sstevel@tonic-gate  * the fullness of time after we gain more experience with the interfaces.
33*0Sstevel@tonic-gate  *
34*0Sstevel@tonic-gate  * In the meantime, be aware that any program linked with this API in this
35*0Sstevel@tonic-gate  * release of Solaris is almost guaranteed to break in the next release.
36*0Sstevel@tonic-gate  *
37*0Sstevel@tonic-gate  * In short, do not user this header file or the CTF routines for any purpose.
38*0Sstevel@tonic-gate  */
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #ifndef	_CTF_API_H
41*0Sstevel@tonic-gate #define	_CTF_API_H
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate #include <sys/types.h>
46*0Sstevel@tonic-gate #include <sys/param.h>
47*0Sstevel@tonic-gate #include <sys/elf.h>
48*0Sstevel@tonic-gate #include <sys/ctf.h>
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate #ifdef	__cplusplus
51*0Sstevel@tonic-gate extern "C" {
52*0Sstevel@tonic-gate #endif
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate /*
55*0Sstevel@tonic-gate  * Clients can open one or more CTF containers and obtain a pointer to an
56*0Sstevel@tonic-gate  * opaque ctf_file_t.  Types are identified by an opaque ctf_id_t token.
57*0Sstevel@tonic-gate  * These opaque definitions allow libctf to evolve without breaking clients.
58*0Sstevel@tonic-gate  */
59*0Sstevel@tonic-gate typedef struct ctf_file ctf_file_t;
60*0Sstevel@tonic-gate typedef long ctf_id_t;
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate /*
63*0Sstevel@tonic-gate  * If the debugger needs to provide the CTF library with a set of raw buffers
64*0Sstevel@tonic-gate  * for use as the CTF data, symbol table, and string table, it can do so by
65*0Sstevel@tonic-gate  * filling in ctf_sect_t structures and passing them to ctf_bufopen():
66*0Sstevel@tonic-gate  */
67*0Sstevel@tonic-gate typedef struct ctf_sect {
68*0Sstevel@tonic-gate 	const char *cts_name;	/* section name (if any) */
69*0Sstevel@tonic-gate 	ulong_t cts_type;	/* section type (ELF SHT_... value) */
70*0Sstevel@tonic-gate 	ulong_t cts_flags;	/* section flags (ELF SHF_... value) */
71*0Sstevel@tonic-gate 	const void *cts_data;	/* pointer to section data */
72*0Sstevel@tonic-gate 	size_t cts_size;	/* size of data in bytes */
73*0Sstevel@tonic-gate 	size_t cts_entsize;	/* size of each section entry (symtab only) */
74*0Sstevel@tonic-gate 	off64_t cts_offset;	/* file offset of this section (if any) */
75*0Sstevel@tonic-gate } ctf_sect_t;
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate /*
78*0Sstevel@tonic-gate  * Encoding information for integers, floating-point values, and certain other
79*0Sstevel@tonic-gate  * intrinsics can be obtained by calling ctf_type_encoding(), below.  The flags
80*0Sstevel@tonic-gate  * field will contain values appropriate for the type defined in <sys/ctf.h>.
81*0Sstevel@tonic-gate  */
82*0Sstevel@tonic-gate typedef struct ctf_encoding {
83*0Sstevel@tonic-gate 	uint_t cte_format;	/* data format (CTF_INT_* or CTF_FP_* flags) */
84*0Sstevel@tonic-gate 	uint_t cte_offset;	/* offset of value in bits */
85*0Sstevel@tonic-gate 	uint_t cte_bits;	/* size of storage in bits */
86*0Sstevel@tonic-gate } ctf_encoding_t;
87*0Sstevel@tonic-gate 
88*0Sstevel@tonic-gate typedef struct ctf_membinfo {
89*0Sstevel@tonic-gate 	ctf_id_t ctm_type;	/* type of struct or union member */
90*0Sstevel@tonic-gate 	ulong_t ctm_offset;	/* offset of member in bits */
91*0Sstevel@tonic-gate } ctf_membinfo_t;
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate typedef struct ctf_arinfo {
94*0Sstevel@tonic-gate 	ctf_id_t ctr_contents;	/* type of array contents */
95*0Sstevel@tonic-gate 	ctf_id_t ctr_index;	/* type of array index */
96*0Sstevel@tonic-gate 	uint_t ctr_nelems;	/* number of elements */
97*0Sstevel@tonic-gate } ctf_arinfo_t;
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate typedef struct ctf_funcinfo {
100*0Sstevel@tonic-gate 	ctf_id_t ctc_return;	/* function return type */
101*0Sstevel@tonic-gate 	uint_t ctc_argc;	/* number of typed arguments to function */
102*0Sstevel@tonic-gate 	uint_t ctc_flags;	/* function attributes (see below) */
103*0Sstevel@tonic-gate } ctf_funcinfo_t;
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate typedef struct ctf_lblinfo {
106*0Sstevel@tonic-gate 	ctf_id_t ctb_typeidx;	/* last type associated with the label */
107*0Sstevel@tonic-gate } ctf_lblinfo_t;
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate #define	CTF_FUNC_VARARG	0x1	/* function arguments end with varargs */
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate /*
112*0Sstevel@tonic-gate  * Functions that return integer status or a ctf_id_t use the following value
113*0Sstevel@tonic-gate  * to indicate failure.  ctf_errno() can be used to obtain an error code.
114*0Sstevel@tonic-gate  */
115*0Sstevel@tonic-gate #define	CTF_ERR	(-1L)
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate /*
118*0Sstevel@tonic-gate  * The CTF data model is inferred to be the caller's data model or the data
119*0Sstevel@tonic-gate  * model of the given object, unless ctf_setmodel() is explicitly called.
120*0Sstevel@tonic-gate  */
121*0Sstevel@tonic-gate #define	CTF_MODEL_ILP32	1	/* object data model is ILP32 */
122*0Sstevel@tonic-gate #define	CTF_MODEL_LP64	2	/* object data model is LP64 */
123*0Sstevel@tonic-gate #ifdef _LP64
124*0Sstevel@tonic-gate #define	CTF_MODEL_NATIVE	CTF_MODEL_LP64
125*0Sstevel@tonic-gate #else
126*0Sstevel@tonic-gate #define	CTF_MODEL_NATIVE	CTF_MODEL_ILP32
127*0Sstevel@tonic-gate #endif
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate /*
130*0Sstevel@tonic-gate  * Dynamic CTF containers can be created using ctf_create().  The ctf_add_*
131*0Sstevel@tonic-gate  * routines can be used to add new definitions to the dynamic container.
132*0Sstevel@tonic-gate  * New types are labeled as root or non-root to determine whether they are
133*0Sstevel@tonic-gate  * visible at the top-level program scope when subsequently doing a lookup.
134*0Sstevel@tonic-gate  */
135*0Sstevel@tonic-gate #define	CTF_ADD_NONROOT	0	/* type only visible in nested scope */
136*0Sstevel@tonic-gate #define	CTF_ADD_ROOT	1	/* type visible at top-level scope */
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate /*
139*0Sstevel@tonic-gate  * These typedefs are used to define the signature for callback functions
140*0Sstevel@tonic-gate  * that can be used with the iteration and visit functions below:
141*0Sstevel@tonic-gate  */
142*0Sstevel@tonic-gate typedef int ctf_visit_f(const char *, ctf_id_t, ulong_t, int, void *);
143*0Sstevel@tonic-gate typedef int ctf_member_f(const char *, ctf_id_t, ulong_t, void *);
144*0Sstevel@tonic-gate typedef int ctf_enum_f(const char *, int, void *);
145*0Sstevel@tonic-gate typedef int ctf_type_f(ctf_id_t, void *);
146*0Sstevel@tonic-gate typedef int ctf_label_f(const char *, const ctf_lblinfo_t *, void *);
147*0Sstevel@tonic-gate 
148*0Sstevel@tonic-gate extern ctf_file_t *ctf_bufopen(const ctf_sect_t *, const ctf_sect_t *,
149*0Sstevel@tonic-gate     const ctf_sect_t *, int *);
150*0Sstevel@tonic-gate extern ctf_file_t *ctf_fdopen(int, int *);
151*0Sstevel@tonic-gate extern ctf_file_t *ctf_open(const char *, int *);
152*0Sstevel@tonic-gate extern ctf_file_t *ctf_create(int *);
153*0Sstevel@tonic-gate extern void ctf_close(ctf_file_t *);
154*0Sstevel@tonic-gate 
155*0Sstevel@tonic-gate extern ctf_file_t *ctf_parent_file(ctf_file_t *);
156*0Sstevel@tonic-gate extern const char *ctf_parent_name(ctf_file_t *);
157*0Sstevel@tonic-gate 
158*0Sstevel@tonic-gate extern int ctf_import(ctf_file_t *, ctf_file_t *);
159*0Sstevel@tonic-gate extern int ctf_setmodel(ctf_file_t *, int);
160*0Sstevel@tonic-gate extern int ctf_getmodel(ctf_file_t *);
161*0Sstevel@tonic-gate 
162*0Sstevel@tonic-gate extern void ctf_setspecific(ctf_file_t *, void *);
163*0Sstevel@tonic-gate extern void *ctf_getspecific(ctf_file_t *);
164*0Sstevel@tonic-gate 
165*0Sstevel@tonic-gate extern int ctf_errno(ctf_file_t *);
166*0Sstevel@tonic-gate extern const char *ctf_errmsg(int);
167*0Sstevel@tonic-gate extern int ctf_version(int);
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate extern int ctf_func_info(ctf_file_t *, ulong_t, ctf_funcinfo_t *);
170*0Sstevel@tonic-gate extern int ctf_func_args(ctf_file_t *, ulong_t, uint_t, ctf_id_t *);
171*0Sstevel@tonic-gate 
172*0Sstevel@tonic-gate extern ctf_id_t ctf_lookup_by_name(ctf_file_t *, const char *);
173*0Sstevel@tonic-gate extern ctf_id_t ctf_lookup_by_symbol(ctf_file_t *, ulong_t);
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate extern ctf_id_t ctf_type_resolve(ctf_file_t *, ctf_id_t);
176*0Sstevel@tonic-gate extern ssize_t ctf_type_lname(ctf_file_t *, ctf_id_t, char *, size_t);
177*0Sstevel@tonic-gate extern char *ctf_type_name(ctf_file_t *, ctf_id_t, char *, size_t);
178*0Sstevel@tonic-gate extern ssize_t ctf_type_size(ctf_file_t *, ctf_id_t);
179*0Sstevel@tonic-gate extern ssize_t ctf_type_align(ctf_file_t *, ctf_id_t);
180*0Sstevel@tonic-gate extern int ctf_type_kind(ctf_file_t *, ctf_id_t);
181*0Sstevel@tonic-gate extern ctf_id_t ctf_type_reference(ctf_file_t *, ctf_id_t);
182*0Sstevel@tonic-gate extern ctf_id_t ctf_type_pointer(ctf_file_t *, ctf_id_t);
183*0Sstevel@tonic-gate extern int ctf_type_encoding(ctf_file_t *, ctf_id_t, ctf_encoding_t *);
184*0Sstevel@tonic-gate extern int ctf_type_visit(ctf_file_t *, ctf_id_t, ctf_visit_f *, void *);
185*0Sstevel@tonic-gate extern int ctf_type_cmp(ctf_file_t *, ctf_id_t, ctf_file_t *, ctf_id_t);
186*0Sstevel@tonic-gate extern int ctf_type_compat(ctf_file_t *, ctf_id_t, ctf_file_t *, ctf_id_t);
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate extern int ctf_member_info(ctf_file_t *, ctf_id_t, const char *,
189*0Sstevel@tonic-gate     ctf_membinfo_t *);
190*0Sstevel@tonic-gate extern int ctf_array_info(ctf_file_t *, ctf_id_t, ctf_arinfo_t *);
191*0Sstevel@tonic-gate 
192*0Sstevel@tonic-gate extern const char *ctf_enum_name(ctf_file_t *, ctf_id_t, int);
193*0Sstevel@tonic-gate extern int ctf_enum_value(ctf_file_t *, ctf_id_t, const char *, int *);
194*0Sstevel@tonic-gate 
195*0Sstevel@tonic-gate extern const char *ctf_label_topmost(ctf_file_t *);
196*0Sstevel@tonic-gate extern int ctf_label_info(ctf_file_t *, const char *, ctf_lblinfo_t *);
197*0Sstevel@tonic-gate 
198*0Sstevel@tonic-gate extern int ctf_member_iter(ctf_file_t *, ctf_id_t, ctf_member_f *, void *);
199*0Sstevel@tonic-gate extern int ctf_enum_iter(ctf_file_t *, ctf_id_t, ctf_enum_f *, void *);
200*0Sstevel@tonic-gate extern int ctf_type_iter(ctf_file_t *, ctf_type_f *, void *);
201*0Sstevel@tonic-gate extern int ctf_label_iter(ctf_file_t *, ctf_label_f *, void *);
202*0Sstevel@tonic-gate 
203*0Sstevel@tonic-gate extern ctf_id_t ctf_add_array(ctf_file_t *, uint_t, const ctf_arinfo_t *);
204*0Sstevel@tonic-gate extern ctf_id_t ctf_add_const(ctf_file_t *, uint_t, ctf_id_t);
205*0Sstevel@tonic-gate extern ctf_id_t ctf_add_enum(ctf_file_t *, uint_t, const char *);
206*0Sstevel@tonic-gate extern ctf_id_t ctf_add_float(ctf_file_t *, uint_t,
207*0Sstevel@tonic-gate     const char *, const ctf_encoding_t *);
208*0Sstevel@tonic-gate extern ctf_id_t ctf_add_forward(ctf_file_t *, uint_t, const char *, uint_t);
209*0Sstevel@tonic-gate extern ctf_id_t ctf_add_function(ctf_file_t *, uint_t,
210*0Sstevel@tonic-gate     const ctf_funcinfo_t *, const ctf_id_t *);
211*0Sstevel@tonic-gate extern ctf_id_t ctf_add_integer(ctf_file_t *, uint_t,
212*0Sstevel@tonic-gate     const char *, const ctf_encoding_t *);
213*0Sstevel@tonic-gate extern ctf_id_t ctf_add_pointer(ctf_file_t *, uint_t, ctf_id_t);
214*0Sstevel@tonic-gate extern ctf_id_t ctf_add_type(ctf_file_t *, ctf_file_t *, ctf_id_t);
215*0Sstevel@tonic-gate extern ctf_id_t ctf_add_typedef(ctf_file_t *, uint_t, const char *, ctf_id_t);
216*0Sstevel@tonic-gate extern ctf_id_t ctf_add_restrict(ctf_file_t *, uint_t, ctf_id_t);
217*0Sstevel@tonic-gate extern ctf_id_t ctf_add_struct(ctf_file_t *, uint_t, const char *);
218*0Sstevel@tonic-gate extern ctf_id_t ctf_add_union(ctf_file_t *, uint_t, const char *);
219*0Sstevel@tonic-gate extern ctf_id_t ctf_add_volatile(ctf_file_t *, uint_t, ctf_id_t);
220*0Sstevel@tonic-gate 
221*0Sstevel@tonic-gate extern int ctf_add_enumerator(ctf_file_t *, ctf_id_t, const char *, int);
222*0Sstevel@tonic-gate extern int ctf_add_member(ctf_file_t *, ctf_id_t, const char *, ctf_id_t);
223*0Sstevel@tonic-gate 
224*0Sstevel@tonic-gate extern int ctf_set_array(ctf_file_t *, ctf_id_t, const ctf_arinfo_t *);
225*0Sstevel@tonic-gate 
226*0Sstevel@tonic-gate extern int ctf_update(ctf_file_t *);
227*0Sstevel@tonic-gate extern int ctf_discard(ctf_file_t *);
228*0Sstevel@tonic-gate extern int ctf_write(ctf_file_t *, int);
229*0Sstevel@tonic-gate 
230*0Sstevel@tonic-gate #ifdef _KERNEL
231*0Sstevel@tonic-gate 
232*0Sstevel@tonic-gate struct module;
233*0Sstevel@tonic-gate extern ctf_file_t *ctf_modopen(struct module *, int *);
234*0Sstevel@tonic-gate 
235*0Sstevel@tonic-gate #endif
236*0Sstevel@tonic-gate 
237*0Sstevel@tonic-gate #ifdef	__cplusplus
238*0Sstevel@tonic-gate }
239*0Sstevel@tonic-gate #endif
240*0Sstevel@tonic-gate 
241*0Sstevel@tonic-gate #endif	/* _CTF_API_H */
242