1 | /*
|
---|
2 | * CDDL HEADER START
|
---|
3 | *
|
---|
4 | * The contents of this file are subject to the terms of the
|
---|
5 | * Common Development and Distribution License, Version 1.0 only
|
---|
6 | * (the "License"). You may not use this file except in compliance
|
---|
7 | * with the License.
|
---|
8 | *
|
---|
9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
---|
10 | * or http://www.opensolaris.org/os/licensing.
|
---|
11 | * See the License for the specific language governing permissions
|
---|
12 | * and limitations under the License.
|
---|
13 | *
|
---|
14 | * When distributing Covered Code, include this CDDL HEADER in each
|
---|
15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
---|
16 | * If applicable, add the following below this CDDL HEADER, with the
|
---|
17 | * fields enclosed by brackets "[]" replaced with your own identifying
|
---|
18 | * information: Portions Copyright [yyyy] [name of copyright owner]
|
---|
19 | *
|
---|
20 | * CDDL HEADER END
|
---|
21 | */
|
---|
22 | /*
|
---|
23 | * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
|
---|
24 | * Use is subject to license terms.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef _CTF_H
|
---|
28 | #define _CTF_H
|
---|
29 |
|
---|
30 | #ifndef VBOX
|
---|
31 | # pragma ident "%Z%%M% %I% %E% SMI"
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #ifndef VBOX
|
---|
35 | # include <sys/types.h>
|
---|
36 | #else
|
---|
37 | # include "VBoxDTraceTypes.h"
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | #ifdef __cplusplus
|
---|
41 | extern "C" {
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | /*
|
---|
45 | * CTF - Compact ANSI-C Type Format
|
---|
46 | *
|
---|
47 | * This file format can be used to compactly represent the information needed
|
---|
48 | * by a debugger to interpret the ANSI-C types used by a given program.
|
---|
49 | * Traditionally, this kind of information is generated by the compiler when
|
---|
50 | * invoked with the -g flag and is stored in "stabs" strings or in the more
|
---|
51 | * modern DWARF format. CTF provides a representation of only the information
|
---|
52 | * that is relevant to debugging a complex, optimized C program such as the
|
---|
53 | * operating system kernel in a form that is significantly more compact than
|
---|
54 | * the equivalent stabs or DWARF representation. The format is data-model
|
---|
55 | * independent, so consumers do not need different code depending on whether
|
---|
56 | * they are 32-bit or 64-bit programs. CTF assumes that a standard ELF symbol
|
---|
57 | * table is available for use in the debugger, and uses the structure and data
|
---|
58 | * of the symbol table to avoid storing redundant information. The CTF data
|
---|
59 | * may be compressed on disk or in memory, indicated by a bit in the header.
|
---|
60 | * CTF may be interpreted in a raw disk file, or it may be stored in an ELF
|
---|
61 | * section, typically named .SUNW_ctf. Data structures are aligned so that
|
---|
62 | * a raw CTF file or CTF ELF section may be manipulated using mmap(2).
|
---|
63 | *
|
---|
64 | * The CTF file or section itself has the following structure:
|
---|
65 | *
|
---|
66 | * +--------+--------+---------+----------+-------+--------+
|
---|
67 | * | file | type | data | function | data | string |
|
---|
68 | * | header | labels | objects | info | types | table |
|
---|
69 | * +--------+--------+---------+----------+-------+--------+
|
---|
70 | *
|
---|
71 | * The file header stores a magic number and version information, encoding
|
---|
72 | * flags, and the byte offset of each of the sections relative to the end of the
|
---|
73 | * header itself. If the CTF data has been uniquified against another set of
|
---|
74 | * CTF data, a reference to that data also appears in the the header. This
|
---|
75 | * reference is the name of the label corresponding to the types uniquified
|
---|
76 | * against.
|
---|
77 | *
|
---|
78 | * Following the header is a list of labels, used to group the types included in
|
---|
79 | * the data types section. Each label is accompanied by a type ID i. A given
|
---|
80 | * label refers to the group of types whose IDs are in the range [0, i].
|
---|
81 | *
|
---|
82 | * Data object and function records are stored in the same order as they appear
|
---|
83 | * in the corresponding symbol table, except that symbols marked SHN_UNDEF are
|
---|
84 | * not stored and symbols that have no type data are padded out with zeroes.
|
---|
85 | * For each data object, the type ID (a small integer) is recorded. For each
|
---|
86 | * function, the type ID of the return type and argument types is recorded.
|
---|
87 | *
|
---|
88 | * The data types section is a list of variable size records that represent each
|
---|
89 | * type, in order by their ID. The types themselves form a directed graph,
|
---|
90 | * where each node may contain one or more outgoing edges to other type nodes,
|
---|
91 | * denoted by their ID.
|
---|
92 | *
|
---|
93 | * Strings are recorded as a string table ID (0 or 1) and a byte offset into the
|
---|
94 | * string table. String table 0 is the internal CTF string table. String table
|
---|
95 | * 1 is the external string table, which is the string table associated with the
|
---|
96 | * ELF symbol table for this object. CTF does not record any strings that are
|
---|
97 | * already in the symbol table, and the CTF string table does not contain any
|
---|
98 | * duplicated strings.
|
---|
99 | *
|
---|
100 | * If the CTF data has been merged with another parent CTF object, some outgoing
|
---|
101 | * edges may refer to type nodes that exist in another CTF object. The debugger
|
---|
102 | * and libctf library are responsible for connecting the appropriate objects
|
---|
103 | * together so that the full set of types can be explored and manipulated.
|
---|
104 | */
|
---|
105 |
|
---|
106 | #define CTF_MAX_TYPE 0xffff /* max type identifier value */
|
---|
107 | #define CTF_MAX_NAME 0x7fffffff /* max offset into a string table */
|
---|
108 | #define CTF_MAX_VLEN 0x3ff /* max struct, union, enum members or args */
|
---|
109 | #define CTF_MAX_INTOFF 0xff /* max offset of intrinsic value in bits */
|
---|
110 | #define CTF_MAX_INTBITS 0xffff /* max size of an intrinsic in bits */
|
---|
111 |
|
---|
112 | /* See ctf_type_t */
|
---|
113 | #define CTF_MAX_SIZE 0xfffe /* max size of a type in bytes */
|
---|
114 | #define CTF_LSIZE_SENT 0xffff /* sentinel for ctt_size */
|
---|
115 | #define CTF_MAX_LSIZE UINT64_MAX
|
---|
116 |
|
---|
117 | typedef struct ctf_preamble {
|
---|
118 | ushort_t ctp_magic; /* magic number (CTF_MAGIC) */
|
---|
119 | uchar_t ctp_version; /* data format version number (CTF_VERSION) */
|
---|
120 | uchar_t ctp_flags; /* flags (see below) */
|
---|
121 | } ctf_preamble_t;
|
---|
122 |
|
---|
123 | typedef struct ctf_header {
|
---|
124 | ctf_preamble_t cth_preamble;
|
---|
125 | uint_t cth_parlabel; /* ref to name of parent lbl uniq'd against */
|
---|
126 | uint_t cth_parname; /* ref to basename of parent */
|
---|
127 | uint_t cth_lbloff; /* offset of label section */
|
---|
128 | uint_t cth_objtoff; /* offset of object section */
|
---|
129 | uint_t cth_funcoff; /* offset of function section */
|
---|
130 | uint_t cth_typeoff; /* offset of type section */
|
---|
131 | uint_t cth_stroff; /* offset of string section */
|
---|
132 | uint_t cth_strlen; /* length of string section in bytes */
|
---|
133 | } ctf_header_t;
|
---|
134 |
|
---|
135 | #define cth_magic cth_preamble.ctp_magic
|
---|
136 | #define cth_version cth_preamble.ctp_version
|
---|
137 | #define cth_flags cth_preamble.ctp_flags
|
---|
138 |
|
---|
139 | #ifdef CTF_OLD_VERSIONS
|
---|
140 |
|
---|
141 | typedef struct ctf_header_v1 {
|
---|
142 | ctf_preamble_t cth_preamble;
|
---|
143 | uint_t cth_objtoff;
|
---|
144 | uint_t cth_funcoff;
|
---|
145 | uint_t cth_typeoff;
|
---|
146 | uint_t cth_stroff;
|
---|
147 | uint_t cth_strlen;
|
---|
148 | } ctf_header_v1_t;
|
---|
149 |
|
---|
150 | #endif /* CTF_OLD_VERSIONS */
|
---|
151 |
|
---|
152 | #define CTF_MAGIC 0xcff1 /* magic number identifying header */
|
---|
153 |
|
---|
154 | /* data format version number */
|
---|
155 | #define CTF_VERSION_1 1
|
---|
156 | #define CTF_VERSION_2 2
|
---|
157 | #define CTF_VERSION CTF_VERSION_2 /* current version */
|
---|
158 |
|
---|
159 | #define CTF_F_COMPRESS 0x1 /* data buffer is compressed */
|
---|
160 |
|
---|
161 | typedef struct ctf_lblent {
|
---|
162 | uint_t ctl_label; /* ref to name of label */
|
---|
163 | uint_t ctl_typeidx; /* last type associated with this label */
|
---|
164 | } ctf_lblent_t;
|
---|
165 |
|
---|
166 | typedef struct ctf_stype {
|
---|
167 | uint_t ctt_name; /* reference to name in string table */
|
---|
168 | ushort_t ctt_info; /* encoded kind, variant length (see below) */
|
---|
169 | union {
|
---|
170 | ushort_t _size; /* size of entire type in bytes */
|
---|
171 | ushort_t _type; /* reference to another type */
|
---|
172 | } _u;
|
---|
173 | } ctf_stype_t;
|
---|
174 |
|
---|
175 | /*
|
---|
176 | * type sizes, measured in bytes, come in two flavors. 99% of them fit within
|
---|
177 | * (USHRT_MAX - 1), and thus can be stored in the ctt_size member of a
|
---|
178 | * ctf_stype_t. The maximum value for these sizes is CTF_MAX_SIZE. The sizes
|
---|
179 | * larger than CTF_MAX_SIZE must be stored in the ctt_lsize member of a
|
---|
180 | * ctf_type_t. Use of this member is indicated by the presence of
|
---|
181 | * CTF_LSIZE_SENT in ctt_size.
|
---|
182 | */
|
---|
183 | typedef struct ctf_type {
|
---|
184 | uint_t ctt_name; /* reference to name in string table */
|
---|
185 | ushort_t ctt_info; /* encoded kind, variant length (see below) */
|
---|
186 | union {
|
---|
187 | ushort_t _size; /* always CTF_LSIZE_SENT */
|
---|
188 | ushort_t _type; /* do not use */
|
---|
189 | } _u;
|
---|
190 | uint_t ctt_lsizehi; /* high 32 bits of type size in bytes */
|
---|
191 | uint_t ctt_lsizelo; /* low 32 bits of type size in bytes */
|
---|
192 | } ctf_type_t;
|
---|
193 |
|
---|
194 | #define ctt_size _u._size /* for fundamental types that have a size */
|
---|
195 | #define ctt_type _u._type /* for types that reference another type */
|
---|
196 |
|
---|
197 | /*
|
---|
198 | * The following macros compose and decompose values for ctt_info and
|
---|
199 | * ctt_name, as well as other structures that contain name references.
|
---|
200 | *
|
---|
201 | * ------------------------
|
---|
202 | * ctt_info: | kind | isroot | vlen |
|
---|
203 | * ------------------------
|
---|
204 | * 15 11 10 9 0
|
---|
205 | *
|
---|
206 | * kind = CTF_INFO_KIND(c.ctt_info); <-- CTF_K_* value (see below)
|
---|
207 | * vlen = CTF_INFO_VLEN(c.ctt_info); <-- length of variable data list
|
---|
208 | *
|
---|
209 | * stid = CTF_NAME_STID(c.ctt_name); <-- string table id number (0 or 1)
|
---|
210 | * offset = CTF_NAME_OFFSET(c.ctt_name); <-- string table byte offset
|
---|
211 | *
|
---|
212 | * c.ctt_info = CTF_TYPE_INFO(kind, vlen);
|
---|
213 | * c.ctt_name = CTF_TYPE_NAME(stid, offset);
|
---|
214 | */
|
---|
215 |
|
---|
216 | #define CTF_INFO_KIND(info) (((info) & 0xf800) >> 11)
|
---|
217 | #define CTF_INFO_ISROOT(info) (((info) & 0x0400) >> 10)
|
---|
218 | #define CTF_INFO_VLEN(info) (((info) & CTF_MAX_VLEN))
|
---|
219 |
|
---|
220 | #define CTF_NAME_STID(name) ((name) >> 31)
|
---|
221 | #define CTF_NAME_OFFSET(name) ((name) & 0x7fffffff)
|
---|
222 |
|
---|
223 | #define CTF_TYPE_INFO(kind, isroot, vlen) \
|
---|
224 | (((kind) << 11) | (((isroot) ? 1 : 0) << 10) | ((vlen) & CTF_MAX_VLEN))
|
---|
225 |
|
---|
226 | #define CTF_TYPE_NAME(stid, offset) \
|
---|
227 | (((stid) << 31) | ((offset) & 0x7fffffff))
|
---|
228 |
|
---|
229 | #define CTF_TYPE_ISPARENT(id) ((id) < 0x8000)
|
---|
230 | #define CTF_TYPE_ISCHILD(id) ((id) > 0x7fff)
|
---|
231 |
|
---|
232 | #define CTF_TYPE_TO_INDEX(id) ((id) & 0x7fff)
|
---|
233 | #define CTF_INDEX_TO_TYPE(id, child) ((child) ? ((id) | 0x8000) : (id))
|
---|
234 | #define CTF_PARENT_SHIFT 15
|
---|
235 |
|
---|
236 | #define CTF_STRTAB_0 0 /* symbolic define for string table id 0 */
|
---|
237 | #define CTF_STRTAB_1 1 /* symbolic define for string table id 1 */
|
---|
238 |
|
---|
239 | #define CTF_TYPE_LSIZE(cttp) \
|
---|
240 | (((uint64_t)(cttp)->ctt_lsizehi) << 32 | (cttp)->ctt_lsizelo)
|
---|
241 | #define CTF_SIZE_TO_LSIZE_HI(size) ((uint32_t)((uint64_t)(size) >> 32))
|
---|
242 | #define CTF_SIZE_TO_LSIZE_LO(size) ((uint32_t)(size))
|
---|
243 |
|
---|
244 | #ifdef CTF_OLD_VERSIONS
|
---|
245 |
|
---|
246 | #define CTF_INFO_KIND_V1(info) (((info) & 0xf000) >> 12)
|
---|
247 | #define CTF_INFO_ISROOT_V1(info) (((info) & 0x0800) >> 11)
|
---|
248 | #define CTF_INFO_VLEN_V1(info) (((info) & 0x07ff))
|
---|
249 |
|
---|
250 | #define CTF_TYPE_INFO_V1(kind, isroot, vlen) \
|
---|
251 | (((kind) << 12) | (((isroot) ? 1 : 0) << 11) | ((vlen) & 0x07ff))
|
---|
252 |
|
---|
253 | #endif /* CTF_OLD_VERSIONS */
|
---|
254 |
|
---|
255 | /*
|
---|
256 | * Values for CTF_TYPE_KIND(). If the kind has an associated data list,
|
---|
257 | * CTF_INFO_VLEN() will extract the number of elements in the list, and
|
---|
258 | * the type of each element is shown in the comments below.
|
---|
259 | */
|
---|
260 | #define CTF_K_UNKNOWN 0 /* unknown type (used for padding) */
|
---|
261 | #define CTF_K_INTEGER 1 /* variant data is CTF_INT_DATA() (see below) */
|
---|
262 | #define CTF_K_FLOAT 2 /* variant data is CTF_FP_DATA() (see below) */
|
---|
263 | #define CTF_K_POINTER 3 /* ctt_type is referenced type */
|
---|
264 | #define CTF_K_ARRAY 4 /* variant data is single ctf_array_t */
|
---|
265 | #define CTF_K_FUNCTION 5 /* ctt_type is return type, variant data is */
|
---|
266 | /* list of argument types (ushort_t's) */
|
---|
267 | #define CTF_K_STRUCT 6 /* variant data is list of ctf_member_t's */
|
---|
268 | #define CTF_K_UNION 7 /* variant data is list of ctf_member_t's */
|
---|
269 | #define CTF_K_ENUM 8 /* variant data is list of ctf_enum_t's */
|
---|
270 | #define CTF_K_FORWARD 9 /* no additional data; ctt_name is tag */
|
---|
271 | #define CTF_K_TYPEDEF 10 /* ctt_type is referenced type */
|
---|
272 | #define CTF_K_VOLATILE 11 /* ctt_type is base type */
|
---|
273 | #define CTF_K_CONST 12 /* ctt_type is base type */
|
---|
274 | #define CTF_K_RESTRICT 13 /* ctt_type is base type */
|
---|
275 |
|
---|
276 | #define CTF_K_MAX 31 /* Maximum possible CTF_K_* value */
|
---|
277 |
|
---|
278 | /*
|
---|
279 | * Values for ctt_type when kind is CTF_K_INTEGER. The flags, offset in bits,
|
---|
280 | * and size in bits are encoded as a single word using the following macros.
|
---|
281 | */
|
---|
282 | #define CTF_INT_ENCODING(data) (((data) & 0xff000000) >> 24)
|
---|
283 | #define CTF_INT_OFFSET(data) (((data) & 0x00ff0000) >> 16)
|
---|
284 | #define CTF_INT_BITS(data) (((data) & 0x0000ffff))
|
---|
285 |
|
---|
286 | #define CTF_INT_DATA(encoding, offset, bits) \
|
---|
287 | (((encoding) << 24) | ((offset) << 16) | (bits))
|
---|
288 |
|
---|
289 | #define CTF_INT_SIGNED 0x01 /* integer is signed (otherwise unsigned) */
|
---|
290 | #define CTF_INT_CHAR 0x02 /* character display format */
|
---|
291 | #define CTF_INT_BOOL 0x04 /* boolean display format */
|
---|
292 | #define CTF_INT_VARARGS 0x08 /* varargs display format */
|
---|
293 |
|
---|
294 | /*
|
---|
295 | * Values for ctt_type when kind is CTF_K_FLOAT. The encoding, offset in bits,
|
---|
296 | * and size in bits are encoded as a single word using the following macros.
|
---|
297 | */
|
---|
298 | #define CTF_FP_ENCODING(data) (((data) & 0xff000000) >> 24)
|
---|
299 | #define CTF_FP_OFFSET(data) (((data) & 0x00ff0000) >> 16)
|
---|
300 | #define CTF_FP_BITS(data) (((data) & 0x0000ffff))
|
---|
301 |
|
---|
302 | #define CTF_FP_DATA(encoding, offset, bits) \
|
---|
303 | (((encoding) << 24) | ((offset) << 16) | (bits))
|
---|
304 |
|
---|
305 | #define CTF_FP_SINGLE 1 /* IEEE 32-bit float encoding */
|
---|
306 | #define CTF_FP_DOUBLE 2 /* IEEE 64-bit float encoding */
|
---|
307 | #define CTF_FP_CPLX 3 /* Complex encoding */
|
---|
308 | #define CTF_FP_DCPLX 4 /* Double complex encoding */
|
---|
309 | #define CTF_FP_LDCPLX 5 /* Long double complex encoding */
|
---|
310 | #define CTF_FP_LDOUBLE 6 /* Long double encoding */
|
---|
311 | #define CTF_FP_INTRVL 7 /* Interval (2x32-bit) encoding */
|
---|
312 | #define CTF_FP_DINTRVL 8 /* Double interval (2x64-bit) encoding */
|
---|
313 | #define CTF_FP_LDINTRVL 9 /* Long double interval (2x128-bit) encoding */
|
---|
314 | #define CTF_FP_IMAGRY 10 /* Imaginary (32-bit) encoding */
|
---|
315 | #define CTF_FP_DIMAGRY 11 /* Long imaginary (64-bit) encoding */
|
---|
316 | #define CTF_FP_LDIMAGRY 12 /* Long double imaginary (128-bit) encoding */
|
---|
317 |
|
---|
318 | #define CTF_FP_MAX 12 /* Maximum possible CTF_FP_* value */
|
---|
319 |
|
---|
320 | typedef struct ctf_array {
|
---|
321 | ushort_t cta_contents; /* reference to type of array contents */
|
---|
322 | ushort_t cta_index; /* reference to type of array index */
|
---|
323 | uint_t cta_nelems; /* number of elements */
|
---|
324 | } ctf_array_t;
|
---|
325 |
|
---|
326 | /*
|
---|
327 | * Most structure members have bit offsets that can be expressed using a
|
---|
328 | * short. Some don't. ctf_member_t is used for structs which cannot
|
---|
329 | * contain any of these large offsets, whereas ctf_lmember_t is used in the
|
---|
330 | * latter case. If ctt_size for a given struct is >= 8192 bytes, all members
|
---|
331 | * will be stored as type ctf_lmember_t.
|
---|
332 | */
|
---|
333 |
|
---|
334 | #define CTF_LSTRUCT_THRESH 8192
|
---|
335 |
|
---|
336 | typedef struct ctf_member {
|
---|
337 | uint_t ctm_name; /* reference to name in string table */
|
---|
338 | ushort_t ctm_type; /* reference to type of member */
|
---|
339 | ushort_t ctm_offset; /* offset of this member in bits */
|
---|
340 | } ctf_member_t;
|
---|
341 |
|
---|
342 | typedef struct ctf_lmember {
|
---|
343 | uint_t ctlm_name; /* reference to name in string table */
|
---|
344 | ushort_t ctlm_type; /* reference to type of member */
|
---|
345 | ushort_t ctlm_pad; /* padding */
|
---|
346 | uint_t ctlm_offsethi; /* high 32 bits of member offset in bits */
|
---|
347 | uint_t ctlm_offsetlo; /* low 32 bits of member offset in bits */
|
---|
348 | } ctf_lmember_t;
|
---|
349 |
|
---|
350 | #define CTF_LMEM_OFFSET(ctlmp) \
|
---|
351 | (((uint64_t)(ctlmp)->ctlm_offsethi) << 32 | (ctlmp)->ctlm_offsetlo)
|
---|
352 | #define CTF_OFFSET_TO_LMEMHI(offset) ((uint32_t)((uint64_t)(offset) >> 32))
|
---|
353 | #define CTF_OFFSET_TO_LMEMLO(offset) ((uint32_t)(offset))
|
---|
354 |
|
---|
355 | typedef struct ctf_enum {
|
---|
356 | uint_t cte_name; /* reference to name in string table */
|
---|
357 | int cte_value; /* value associated with this name */
|
---|
358 | } ctf_enum_t;
|
---|
359 |
|
---|
360 | #ifdef __cplusplus
|
---|
361 | }
|
---|
362 | #endif
|
---|
363 |
|
---|
364 | #endif /* _CTF_H */
|
---|