Print this page
10823 should ignore DW_TAG_subprogram with DW_AT_declaration tags
10824 GCC7-derived CTF can double qualifiers on arrays
10825 ctfdump -c drops last type
10826 ctfdump -c goes off the rails with a missing parent
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Jason King <jason.king@joyent.com>
Approved by: Jerry Jelinek <jerry.jelinek@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/common/ctf/ctf_impl.h
+++ new/usr/src/common/ctf/ctf_impl.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22
23 23 /*
24 24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25 25 * Use is subject to license terms.
26 26 */
27 27 /*
28 - * Copyright (c) 2015, Joyent, Inc. All rights reserved.
28 + * Copyright 2019, Joyent, Inc.
29 29 */
30 30
31 31 #ifndef _CTF_IMPL_H
32 32 #define _CTF_IMPL_H
33 33
34 34 #include <sys/types.h>
35 35 #include <sys/errno.h>
36 36 #include <sys/sysmacros.h>
37 37 #include <sys/ctf_api.h>
38 38
39 39 #ifdef _KERNEL
40 40
41 41 #include <sys/systm.h>
42 42 #include <sys/cmn_err.h>
43 43 #include <sys/varargs.h>
44 44 #include <sys/ddi.h>
45 45 #include <sys/sunddi.h>
46 46
47 47 #define isspace(c) \
48 48 ((c) == ' ' || (c) == '\t' || (c) == '\n' || \
49 49 (c) == '\r' || (c) == '\f' || (c) == '\v')
50 50
51 51 #define MAP_FAILED ((void *)-1)
52 52
53 53 #else /* _KERNEL */
54 54
55 55 #include <strings.h>
56 56 #include <stdlib.h>
57 57 #include <stdarg.h>
58 58 #include <stdio.h>
59 59 #include <limits.h>
60 60 #include <ctype.h>
61 61 #include <stddef.h>
62 62
63 63 #endif /* _KERNEL */
64 64
65 65 #ifdef __cplusplus
66 66 extern "C" {
67 67 #endif
68 68
69 69 typedef struct ctf_helem {
70 70 uint_t h_name; /* reference to name in string table */
71 71 ushort_t h_type; /* corresponding type ID number */
72 72 ushort_t h_next; /* index of next element in hash chain */
73 73 } ctf_helem_t;
74 74
75 75 typedef struct ctf_hash {
76 76 ushort_t *h_buckets; /* hash bucket array (chain indices) */
77 77 ctf_helem_t *h_chains; /* hash chains buffer */
78 78 ushort_t h_nbuckets; /* number of elements in bucket array */
79 79 ushort_t h_nelems; /* number of elements in hash table */
80 80 uint_t h_free; /* index of next free hash element */
81 81 } ctf_hash_t;
82 82
83 83 struct ctf_idhash_iter {
84 84 int cii_id; /* Current iteration id */
85 85 };
86 86
87 87 typedef struct ctf_strs {
88 88 const char *cts_strs; /* base address of string table */
89 89 size_t cts_len; /* size of string table in bytes */
90 90 } ctf_strs_t;
91 91
92 92 typedef struct ctf_dmodel {
93 93 const char *ctd_name; /* data model name */
94 94 int ctd_code; /* data model code */
95 95 size_t ctd_pointer; /* size of void * in bytes */
96 96 size_t ctd_char; /* size of char in bytes */
97 97 size_t ctd_short; /* size of short in bytes */
98 98 size_t ctd_int; /* size of int in bytes */
99 99 size_t ctd_long; /* size of long in bytes */
100 100 } ctf_dmodel_t;
101 101
102 102 typedef struct ctf_lookup {
103 103 const char *ctl_prefix; /* string prefix for this lookup */
104 104 size_t ctl_len; /* length of prefix string in bytes */
105 105 ctf_hash_t *ctl_hash; /* pointer to hash table for lookup */
106 106 } ctf_lookup_t;
107 107
108 108 typedef struct ctf_fileops {
109 109 ushort_t (*ctfo_get_kind)(ushort_t);
110 110 ushort_t (*ctfo_get_root)(ushort_t);
111 111 ushort_t (*ctfo_get_vlen)(ushort_t);
112 112 } ctf_fileops_t;
113 113
114 114 typedef struct ctf_list {
115 115 struct ctf_list *l_prev; /* previous pointer or tail pointer */
116 116 struct ctf_list *l_next; /* next pointer or head pointer */
117 117 } ctf_list_t;
118 118
119 119 typedef enum {
120 120 CTF_PREC_BASE,
121 121 CTF_PREC_POINTER,
122 122 CTF_PREC_ARRAY,
123 123 CTF_PREC_FUNCTION,
124 124 CTF_PREC_MAX
125 125 } ctf_decl_prec_t;
126 126
127 127 typedef struct ctf_decl_node {
128 128 ctf_list_t cd_list; /* linked list pointers */
129 129 ctf_id_t cd_type; /* type identifier */
130 130 uint_t cd_kind; /* type kind */
131 131 uint_t cd_n; /* type dimension if array */
132 132 } ctf_decl_node_t;
133 133
134 134 typedef struct ctf_decl {
135 135 ctf_list_t cd_nodes[CTF_PREC_MAX]; /* declaration node stacks */
136 136 int cd_order[CTF_PREC_MAX]; /* storage order of decls */
137 137 ctf_decl_prec_t cd_qualp; /* qualifier precision */
138 138 ctf_decl_prec_t cd_ordp; /* ordered precision */
139 139 char *cd_buf; /* buffer for output */
140 140 char *cd_ptr; /* buffer location */
141 141 char *cd_end; /* buffer limit */
142 142 size_t cd_len; /* buffer space required */
143 143 int cd_err; /* saved error value */
144 144 } ctf_decl_t;
145 145
146 146 typedef struct ctf_dmdef {
147 147 ctf_list_t dmd_list; /* list forward/back pointers */
148 148 char *dmd_name; /* name of this member */
149 149 ctf_id_t dmd_type; /* type of this member (for sou) */
150 150 ulong_t dmd_offset; /* offset of this member in bits (for sou) */
151 151 int dmd_value; /* value of this member (for enum) */
152 152 } ctf_dmdef_t;
153 153
154 154 typedef struct ctf_dtdef {
155 155 ctf_list_t dtd_list; /* list forward/back pointers */
156 156 struct ctf_dtdef *dtd_hash; /* hash chain pointer for ctf_dthash */
157 157 char *dtd_name; /* name associated with definition (if any) */
158 158 ctf_id_t dtd_type; /* type identifier for this definition */
159 159 ctf_type_t dtd_data; /* type node (see <sys/ctf.h>) */
160 160 int dtd_ref; /* recfount for dyanmic types */
161 161 union {
162 162 ctf_list_t dtu_members; /* struct, union, or enum */
163 163 ctf_arinfo_t dtu_arr; /* array */
164 164 ctf_encoding_t dtu_enc; /* integer or float */
165 165 ctf_id_t *dtu_argv; /* function */
166 166 } dtd_u;
167 167 } ctf_dtdef_t;
168 168
169 169 typedef struct ctf_dsdef {
170 170 ctf_list_t dsd_list; /* list forward/back pointers */
171 171 ulong_t dsd_symidx; /* symbol id */
172 172 ctf_id_t dsd_tid; /* type for obj, 0 if function */
173 173 uint_t dsd_nargs;
174 174 ctf_id_t *dsd_argc; /* function argv */
175 175 } ctf_dsdef_t;
176 176
177 177 typedef struct ctf_dldef {
178 178 ctf_list_t dld_list; /* list forward/back pointers */
179 179 char *dld_name; /* name of the label */
180 180 ctf_id_t dld_type; /* type ID associated with the label */
181 181 } ctf_dldef_t;
182 182
183 183 typedef struct ctf_bundle {
184 184 ctf_file_t *ctb_file; /* CTF container handle */
185 185 ctf_id_t ctb_type; /* CTF type identifier */
186 186 ctf_dtdef_t *ctb_dtd; /* CTF dynamic type definition (if any) */
187 187 } ctf_bundle_t;
188 188
189 189 /*
190 190 * The ctf_file is the structure used to represent a CTF container to library
191 191 * clients, who see it only as an opaque pointer. Modifications can therefore
192 192 * be made freely to this structure without regard to client versioning. The
193 193 * ctf_file_t typedef appears in <sys/ctf_api.h> and declares a forward tag.
194 194 *
195 195 * NOTE: ctf_update() requires that everything inside of ctf_file either be an
196 196 * immediate value, a pointer to dynamically allocated data *outside* of the
197 197 * ctf_file itself, or a pointer to statically allocated data. If you add a
198 198 * pointer to ctf_file that points to something within the ctf_file itself,
199 199 * you must make corresponding changes to ctf_update().
200 200 */
201 201 struct ctf_file {
202 202 const ctf_fileops_t *ctf_fileops; /* version-specific file operations */
203 203 ctf_sect_t ctf_data; /* CTF data from object file */
204 204 ctf_sect_t ctf_symtab; /* symbol table from object file */
205 205 ctf_sect_t ctf_strtab; /* string table from object file */
206 206 ctf_hash_t ctf_structs; /* hash table of struct types */
207 207 ctf_hash_t ctf_unions; /* hash table of union types */
208 208 ctf_hash_t ctf_enums; /* hash table of enum types */
209 209 ctf_hash_t ctf_names; /* hash table of remaining type names */
210 210 ctf_lookup_t ctf_lookups[5]; /* pointers to hashes for name lookup */
211 211 ctf_strs_t ctf_str[2]; /* array of string table base and bounds */
212 212 const uchar_t *ctf_base; /* base of CTF header + uncompressed buffer */
213 213 const uchar_t *ctf_buf; /* uncompressed CTF data buffer */
214 214 size_t ctf_size; /* size of CTF header + uncompressed data */
215 215 uint_t *ctf_sxlate; /* translation table for symtab entries */
216 216 ulong_t ctf_nsyms; /* number of entries in symtab xlate table */
217 217 uint_t *ctf_txlate; /* translation table for type IDs */
218 218 ushort_t *ctf_ptrtab; /* translation table for pointer-to lookups */
219 219 ulong_t ctf_typemax; /* maximum valid type ID number */
220 220 const ctf_dmodel_t *ctf_dmodel; /* data model pointer (see above) */
221 221 struct ctf_file *ctf_parent; /* parent CTF container (if any) */
222 222 const char *ctf_parlabel; /* label in parent container (if any) */
223 223 const char *ctf_parname; /* basename of parent (if any) */
224 224 uint_t ctf_refcnt; /* reference count (for parent links) */
225 225 uint_t ctf_flags; /* libctf flags (see below) */
226 226 int ctf_errno; /* error code for most recent error */
227 227 int ctf_version; /* CTF data version */
228 228 ctf_dtdef_t **ctf_dthash; /* hash of dynamic type definitions */
229 229 ulong_t ctf_dthashlen; /* size of dynamic type hash bucket array */
230 230 ctf_list_t ctf_dtdefs; /* list of dynamic type definitions */
231 231 size_t ctf_dtstrlen; /* total length of dynamic type strings */
232 232 ulong_t ctf_dtnextid; /* next dynamic type id to assign */
233 233 ulong_t ctf_dtoldid; /* oldest id that has been committed */
234 234 void *ctf_specific; /* data for ctf_get/setspecific */
235 235 ctf_list_t ctf_dsdefs; /* list of dynamic obj/func definitions */
236 236 ctf_list_t ctf_dldefs; /* list of dynamic labels */
237 237 uint_t ctf_hflags; /* original flags on the header */
238 238 };
239 239
240 240 #define LCTF_INDEX_TO_TYPEPTR(fp, i) \
241 241 ((ctf_type_t *)((uintptr_t)(fp)->ctf_buf + (fp)->ctf_txlate[(i)]))
242 242
243 243 #define LCTF_INFO_KIND(fp, info) ((fp)->ctf_fileops->ctfo_get_kind(info))
244 244 #define LCTF_INFO_ROOT(fp, info) ((fp)->ctf_fileops->ctfo_get_root(info))
245 245 #define LCTF_INFO_VLEN(fp, info) ((fp)->ctf_fileops->ctfo_get_vlen(info))
246 246
247 247 #define LCTF_MMAP 0x0001 /* libctf should munmap buffers on close */
248 248 #define LCTF_CHILD 0x0002 /* CTF container is a child */
249 249 #define LCTF_RDWR 0x0004 /* CTF container is writable */
250 250 #define LCTF_DIRTY 0x0008 /* CTF container has been modified */
251 251
252 252 #define CTF_ELF_SCN_NAME ".SUNW_ctf"
253 253
254 254 extern ssize_t ctf_get_ctt_size(const ctf_file_t *, const ctf_type_t *,
255 255 ssize_t *, ssize_t *);
256 256
257 257 extern const ctf_type_t *ctf_lookup_by_id(ctf_file_t **, ctf_id_t);
258 258
259 259 extern ctf_file_t *ctf_fdcreate_int(int, int *, ctf_sect_t *);
260 260
261 261 extern int ctf_hash_create(ctf_hash_t *, ulong_t);
262 262 extern int ctf_hash_insert(ctf_hash_t *, ctf_file_t *, ushort_t, uint_t);
263 263 extern int ctf_hash_define(ctf_hash_t *, ctf_file_t *, ushort_t, uint_t);
264 264 extern ctf_helem_t *ctf_hash_lookup(ctf_hash_t *, ctf_file_t *,
265 265 const char *, size_t);
266 266 extern uint_t ctf_hash_size(const ctf_hash_t *);
267 267 extern void ctf_hash_destroy(ctf_hash_t *);
268 268
269 269 #define ctf_list_prev(elem) ((void *)(((ctf_list_t *)(elem))->l_prev))
270 270 #define ctf_list_next(elem) ((void *)(((ctf_list_t *)(elem))->l_next))
271 271
272 272 extern void ctf_list_append(ctf_list_t *, void *);
273 273 extern void ctf_list_prepend(ctf_list_t *, void *);
274 274 extern void ctf_list_insert_before(ctf_list_t *, void *, void *);
275 275 extern void ctf_list_delete(ctf_list_t *, void *);
276 276
277 277 extern void ctf_dtd_insert(ctf_file_t *, ctf_dtdef_t *);
278 278 extern void ctf_dtd_delete(ctf_file_t *, ctf_dtdef_t *);
279 279 extern ctf_dtdef_t *ctf_dtd_lookup(ctf_file_t *, ctf_id_t);
280 280
281 281 extern void ctf_dsd_delete(ctf_file_t *, ctf_dsdef_t *);
282 282 extern void ctf_dld_delete(ctf_file_t *, ctf_dldef_t *);
283 283
284 284 extern void ctf_decl_init(ctf_decl_t *, char *, size_t);
285 285 extern void ctf_decl_fini(ctf_decl_t *);
286 286 extern void ctf_decl_push(ctf_decl_t *, ctf_file_t *, ctf_id_t);
287 287 extern void ctf_decl_sprintf(ctf_decl_t *, const char *, ...);
288 288
289 289 extern const char *ctf_strraw(ctf_file_t *, uint_t);
290 290 extern const char *ctf_strptr(ctf_file_t *, uint_t);
291 291
292 292 extern ctf_file_t *ctf_set_open_errno(int *, int);
293 293 extern long ctf_set_errno(ctf_file_t *, int);
294 294
295 295 extern const void *ctf_sect_mmap(ctf_sect_t *, int);
296 296 extern void ctf_sect_munmap(const ctf_sect_t *);
297 297
298 298 extern void *ctf_data_alloc(size_t);
299 299 extern void ctf_data_free(void *, size_t);
300 300 extern void ctf_data_protect(void *, size_t);
301 301
302 302 extern void *ctf_alloc(size_t);
303 303 extern void ctf_free(void *, size_t);
304 304
305 305 extern char *ctf_strdup(const char *);
306 306 extern const char *ctf_strerror(int);
307 307 extern void ctf_dprintf(const char *, ...);
↓ open down ↓ |
269 lines elided |
↑ open up ↑ |
308 308
309 309 extern void *ctf_zopen(int *);
310 310
311 311 extern ctf_id_t ctf_add_encoded(ctf_file_t *, uint_t, const char *,
312 312 const ctf_encoding_t *, uint_t);
313 313 extern ctf_id_t ctf_add_reftype(ctf_file_t *, uint_t, const char *, ctf_id_t,
314 314 uint_t);
315 315 extern boolean_t ctf_sym_valid(uintptr_t, int, uint16_t, uint64_t,
316 316 uint32_t);
317 317
318 +extern const ctf_type_t *ctf_dyn_lookup_by_id(ctf_file_t *, ctf_id_t);
319 +extern int ctf_dyn_array_info(ctf_file_t *, ctf_id_t, ctf_arinfo_t *);
320 +
318 321 extern const char _CTF_SECTION[]; /* name of CTF ELF section */
319 322 extern const char _CTF_NULLSTR[]; /* empty string */
320 323
321 324 extern int _libctf_version; /* library client version */
322 325 extern int _libctf_debug; /* debugging messages enabled */
323 326
324 327 #ifdef __cplusplus
325 328 }
326 329 #endif
327 330
328 331 #endif /* _CTF_IMPL_H */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX