Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / bsd / libdwarf / dist / dwarf_dump.c
blob0e52376b763c97dc0471f5660f72377ff9b15fd6
1 /* $NetBSD$ */
3 /*-
4 * Copyright (c) 2007 John Birrell (jb@freebsd.org)
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
28 * $FreeBSD: src/lib/libdwarf/dwarf_dump.c,v 1.1.4.1 2009/08/03 08:13:06 kensmith Exp $
31 #include <stdlib.h>
32 #include <string.h>
33 #include "_libdwarf.h"
35 const char *
36 get_sht_desc(uint32_t sh_type)
38 switch (sh_type) {
39 case SHT_NULL:
40 return "inactive";
41 case SHT_PROGBITS:
42 return "program defined information";
43 case SHT_SYMTAB:
44 return "symbol table section";
45 case SHT_STRTAB:
46 return "string table section";
47 case SHT_RELA:
48 return "relocation section with addends";
49 case SHT_HASH:
50 return "symbol hash table section";
51 case SHT_DYNAMIC:
52 return "dynamic section";
53 case SHT_NOTE:
54 return "note section";
55 case SHT_NOBITS:
56 return "no space section";
57 case SHT_REL:
58 return "relocation section - no addends";
59 case SHT_SHLIB:
60 return "reserved - purpose unknown";
61 case SHT_DYNSYM:
62 return "dynamic symbol table section";
63 case SHT_INIT_ARRAY:
64 return "Initialization function pointers.";
65 case SHT_FINI_ARRAY:
66 return "Termination function pointers.";
67 case SHT_PREINIT_ARRAY:
68 return "Pre-initialization function ptrs.";
69 case SHT_GROUP:
70 return "Section group.";
71 case SHT_SYMTAB_SHNDX:
72 return "Section indexes (see SHN_XINDEX).";
73 case SHT_GNU_verdef:
74 return "Symbol versions provided";
75 case SHT_GNU_verneed:
76 return "Symbol versions required";
77 case SHT_GNU_versym:
78 return "Symbol version table";
79 case SHT_AMD64_UNWIND:
80 return "AMD64 unwind";
81 default:
82 return "Unknown";
86 const char *
87 get_attr_desc(uint32_t attr)
89 switch (attr) {
90 case DW_AT_abstract_origin:
91 return "DW_AT_abstract_origin";
92 case DW_AT_accessibility:
93 return "DW_AT_accessibility";
94 case DW_AT_address_class:
95 return "DW_AT_address_class";
96 case DW_AT_artificial:
97 return "DW_AT_artificial";
98 case DW_AT_base_types:
99 return "DW_AT_base_types";
100 case DW_AT_bit_offset:
101 return "DW_AT_bit_offset";
102 case DW_AT_bit_size:
103 return "DW_AT_bit_size";
104 case DW_AT_byte_size:
105 return "DW_AT_byte_size";
106 case DW_AT_calling_convention:
107 return "DW_AT_calling_convention";
108 case DW_AT_common_reference:
109 return "DW_AT_common_reference";
110 case DW_AT_comp_dir:
111 return "DW_AT_comp_dir";
112 case DW_AT_const_value:
113 return "DW_AT_const_value";
114 case DW_AT_containing_type:
115 return "DW_AT_containing_type";
116 case DW_AT_count:
117 return "DW_AT_count";
118 case DW_AT_data_member_location:
119 return "DW_AT_data_member_location";
120 case DW_AT_decl_column:
121 return "DW_AT_decl_column";
122 case DW_AT_decl_file:
123 return "DW_AT_decl_file";
124 case DW_AT_decl_line:
125 return "DW_AT_decl_line";
126 case DW_AT_declaration:
127 return "DW_AT_declaration";
128 case DW_AT_default_value:
129 return "DW_AT_default_value";
130 case DW_AT_discr:
131 return "DW_AT_discr";
132 case DW_AT_discr_list:
133 return "DW_AT_discr_list";
134 case DW_AT_discr_value:
135 return "DW_AT_discr_value";
136 case DW_AT_element_list:
137 return "DW_AT_element_list";
138 case DW_AT_encoding:
139 return "DW_AT_encoding";
140 case DW_AT_external:
141 return "DW_AT_external";
142 case DW_AT_frame_base:
143 return "DW_AT_frame_base";
144 case DW_AT_friend:
145 return "DW_AT_friend";
146 case DW_AT_high_pc:
147 return "DW_AT_high_pc";
148 case DW_AT_identifier_case:
149 return "DW_AT_identifier_case";
150 case DW_AT_import:
151 return "DW_AT_import";
152 case DW_AT_inline:
153 return "DW_AT_inline";
154 case DW_AT_is_optional:
155 return "DW_AT_is_optional";
156 case DW_AT_language:
157 return "DW_AT_language";
158 case DW_AT_location:
159 return "DW_AT_location";
160 case DW_AT_low_pc:
161 return "DW_AT_low_pc";
162 case DW_AT_lower_bound:
163 return "DW_AT_lower_bound";
164 case DW_AT_macro_info:
165 return "DW_AT_macro_info";
166 case DW_AT_member:
167 return "DW_AT_member";
168 case DW_AT_name:
169 return "DW_AT_name";
170 case DW_AT_namelist_item:
171 return "DW_AT_namelist_item";
172 case DW_AT_ordering:
173 return "DW_AT_ordering";
174 case DW_AT_priority:
175 return "DW_AT_priority";
176 case DW_AT_producer:
177 return "DW_AT_producer";
178 case DW_AT_prototyped:
179 return "DW_AT_prototyped";
180 case DW_AT_return_addr:
181 return "DW_AT_return_addr";
182 case DW_AT_segment:
183 return "DW_AT_segment";
184 case DW_AT_sibling:
185 return "DW_AT_sibling";
186 case DW_AT_specification:
187 return "DW_AT_specification";
188 case DW_AT_start_scope:
189 return "DW_AT_start_scope";
190 case DW_AT_static_link:
191 return "DW_AT_static_link";
192 case DW_AT_stmt_list:
193 return "DW_AT_stmt_list";
194 case DW_AT_stride_size:
195 return "DW_AT_stride_size";
196 case DW_AT_string_length:
197 return "DW_AT_string_length";
198 case DW_AT_subscr_data:
199 return "DW_AT_subscr_data";
200 case DW_AT_type:
201 return "DW_AT_type";
202 case DW_AT_upper_bound:
203 return "DW_AT_upper_bound";
204 case DW_AT_use_location:
205 return "DW_AT_use_location";
206 case DW_AT_variable_parameter:
207 return "DW_AT_variable_parameter";
208 case DW_AT_virtuality:
209 return "DW_AT_virtuality";
210 case DW_AT_visibility:
211 return "DW_AT_visibility";
212 case DW_AT_vtable_elem_location:
213 return "DW_AT_vtable_elem_location";
214 default:
215 break;
218 return "Unknown attribute";
221 const char *
222 get_form_desc(uint32_t form)
224 switch (form) {
225 case DW_FORM_addr:
226 return "DW_FORM_addr";
227 case DW_FORM_block:
228 return "DW_FORM_block";
229 case DW_FORM_block1:
230 return "DW_FORM_block1";
231 case DW_FORM_block2:
232 return "DW_FORM_block2";
233 case DW_FORM_block4:
234 return "DW_FORM_block4";
235 case DW_FORM_data1:
236 return "DW_FORM_data1";
237 case DW_FORM_data2:
238 return "DW_FORM_data2";
239 case DW_FORM_data4:
240 return "DW_FORM_data4";
241 case DW_FORM_data8:
242 return "DW_FORM_data8";
243 case DW_FORM_flag:
244 return "DW_FORM_flag";
245 case DW_FORM_indirect:
246 return "DW_FORM_indirect";
247 case DW_FORM_ref1:
248 return "DW_FORM_ref1";
249 case DW_FORM_ref2:
250 return "DW_FORM_ref2";
251 case DW_FORM_ref4:
252 return "DW_FORM_ref4";
253 case DW_FORM_ref8:
254 return "DW_FORM_ref8";
255 case DW_FORM_ref_addr:
256 return "DW_FORM_ref_addr";
257 case DW_FORM_ref_udata:
258 return "DW_FORM_ref_udata";
259 case DW_FORM_sdata:
260 return "DW_FORM_sdata";
261 case DW_FORM_string:
262 return "DW_FORM_string";
263 case DW_FORM_strp:
264 return "DW_FORM_strp";
265 case DW_FORM_udata:
266 return "DW_FORM_udata";
267 default:
268 break;
271 return "Unknown attribute";
274 const char *
275 get_tag_desc(uint32_t tag)
277 switch (tag) {
278 case DW_TAG_access_declaration:
279 return "DW_TAG_access_declaration";
280 case DW_TAG_array_type:
281 return "DW_TAG_array_type";
282 case DW_TAG_base_type:
283 return "DW_TAG_base_type";
284 case DW_TAG_catch_block:
285 return "DW_TAG_catch_block";
286 case DW_TAG_class_type:
287 return "DW_TAG_class_type";
288 case DW_TAG_common_block:
289 return "DW_TAG_common_block";
290 case DW_TAG_common_inclusion:
291 return "DW_TAG_common_inclusion";
292 case DW_TAG_compile_unit:
293 return "DW_TAG_compile_unit";
294 case DW_TAG_condition:
295 return "DW_TAG_condition";
296 case DW_TAG_const_type:
297 return "DW_TAG_const_type";
298 case DW_TAG_constant:
299 return "DW_TAG_constant";
300 case DW_TAG_dwarf_procedure:
301 return "DW_TAG_dwarf_procedure";
302 case DW_TAG_entry_point:
303 return "DW_TAG_entry_point";
304 case DW_TAG_enumeration_type:
305 return "DW_TAG_enumeration_type";
306 case DW_TAG_enumerator:
307 return "DW_TAG_enumerator";
308 case DW_TAG_formal_parameter:
309 return "DW_TAG_formal_parameter";
310 case DW_TAG_friend:
311 return "DW_TAG_friend";
312 case DW_TAG_imported_declaration:
313 return "DW_TAG_imported_declaration";
314 case DW_TAG_imported_module:
315 return "DW_TAG_imported_module";
316 case DW_TAG_imported_unit:
317 return "DW_TAG_imported_unit";
318 case DW_TAG_inheritance:
319 return "DW_TAG_inheritance";
320 case DW_TAG_inlined_subroutine:
321 return "DW_TAG_inlined_subroutine";
322 case DW_TAG_interface_type:
323 return "DW_TAG_interface_type";
324 case DW_TAG_label:
325 return "DW_TAG_label";
326 case DW_TAG_lexical_block:
327 return "DW_TAG_lexical_block";
328 case DW_TAG_member:
329 return "DW_TAG_member";
330 case DW_TAG_module:
331 return "DW_TAG_module";
332 case DW_TAG_namelist:
333 return "DW_TAG_namelist";
334 case DW_TAG_namelist_item:
335 return "DW_TAG_namelist_item";
336 case DW_TAG_namespace:
337 return "DW_TAG_namespace";
338 case DW_TAG_packed_type:
339 return "DW_TAG_packed_type";
340 case DW_TAG_partial_unit:
341 return "DW_TAG_partial_unit";
342 case DW_TAG_pointer_type:
343 return "DW_TAG_pointer_type";
344 case DW_TAG_ptr_to_member_type:
345 return "DW_TAG_ptr_to_member_type";
346 case DW_TAG_reference_type:
347 return "DW_TAG_reference_type";
348 case DW_TAG_restrict_type:
349 return "DW_TAG_restrict_type";
350 case DW_TAG_set_type:
351 return "DW_TAG_set_type";
352 case DW_TAG_shared_type:
353 return "DW_TAG_shared_type";
354 case DW_TAG_string_type:
355 return "DW_TAG_string_type";
356 case DW_TAG_structure_type:
357 return "DW_TAG_structure_type";
358 case DW_TAG_subprogram:
359 return "DW_TAG_subprogram";
360 case DW_TAG_subrange_type:
361 return "DW_TAG_subrange_type";
362 case DW_TAG_subroutine_type:
363 return "DW_TAG_subroutine_type";
364 case DW_TAG_template_type_parameter:
365 return "DW_TAG_template_type_parameter";
366 case DW_TAG_template_value_parameter:
367 return "DW_TAG_template_value_parameter";
368 case DW_TAG_thrown_type:
369 return "DW_TAG_thrown_type";
370 case DW_TAG_try_block:
371 return "DW_TAG_try_block";
372 case DW_TAG_typedef:
373 return "DW_TAG_typedef";
374 case DW_TAG_union_type:
375 return "DW_TAG_union_type";
376 case DW_TAG_unspecified_parameters:
377 return "DW_TAG_unspecified_parameters";
378 case DW_TAG_unspecified_type:
379 return "DW_TAG_unspecified_type";
380 case DW_TAG_variable:
381 return "DW_TAG_variable";
382 case DW_TAG_variant:
383 return "DW_TAG_variant";
384 case DW_TAG_variant_part:
385 return "DW_TAG_variant_part";
386 case DW_TAG_volatile_type:
387 return "DW_TAG_volatile_type";
388 case DW_TAG_with_stmt:
389 return "DW_TAG_with_stmt";
390 default:
391 break;
394 return "Unknown tag";
397 void
398 dwarf_dump_abbrev(Dwarf_Debug dbg)
400 Dwarf_Abbrev a;
401 Dwarf_Attribute at;
402 Dwarf_CU cu;
404 printf("Contents of the .debug_abbrev section:\n\nEntry Tag\n");
406 STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) {
407 STAILQ_FOREACH(a, &cu->cu_abbrev, a_next) {
408 printf("%5lu %-30s [%s children]\n",
409 (u_long) a->a_entry, get_tag_desc(a->a_tag),
410 (a->a_children == DW_CHILDREN_yes) ? "has" : "no");
412 STAILQ_FOREACH(at, &a->a_attrib, at_next)
413 printf(" %-30s %s\n", get_attr_desc(at->at_attrib),
414 get_form_desc(at->at_form));
418 #ifdef DOODAD
419 case DW_AT_inline:
420 switch (uvalue)
422 case DW_INL_not_inlined:
423 printf (_("(not inlined)"));
424 break;
425 case DW_INL_inlined:
426 printf (_("(inlined)"));
427 break;
428 case DW_INL_declared_not_inlined:
429 printf (_("(declared as inline but ignored)"));
430 break;
431 case DW_INL_declared_inlined:
432 printf (_("(declared as inline and inlined)"));
433 break;
434 default:
435 printf (_(" (Unknown inline attribute value: %lx)"), uvalue);
436 break;
438 break;
440 case DW_AT_language:
441 switch (uvalue)
443 case DW_LANG_C: printf ("(non-ANSI C)"); break;
444 case DW_LANG_C89: printf ("(ANSI C)"); break;
445 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
446 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
447 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
448 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
449 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
450 case DW_LANG_Ada83: printf ("(Ada)"); break;
451 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
452 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
453 /* DWARF 2.1 values. */
454 case DW_LANG_C99: printf ("(ANSI C99)"); break;
455 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
456 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
457 /* MIPS extension. */
458 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
459 /* UPC extension. */
460 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
461 default:
462 printf ("(Unknown: %lx)", uvalue);
463 break;
465 break;
467 case DW_AT_encoding:
468 switch (uvalue)
470 case DW_ATE_void: printf ("(void)"); break;
471 case DW_ATE_address: printf ("(machine address)"); break;
472 case DW_ATE_boolean: printf ("(boolean)"); break;
473 case DW_ATE_complex_float: printf ("(complex float)"); break;
474 case DW_ATE_float: printf ("(float)"); break;
475 case DW_ATE_signed: printf ("(signed)"); break;
476 case DW_ATE_signed_char: printf ("(signed char)"); break;
477 case DW_ATE_unsigned: printf ("(unsigned)"); break;
478 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
479 /* DWARF 2.1 value. */
480 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
481 default:
482 if (uvalue >= DW_ATE_lo_user
483 && uvalue <= DW_ATE_hi_user)
484 printf ("(user defined type)");
485 else
486 printf ("(unknown type)");
487 break;
489 break;
491 case DW_AT_accessibility:
492 switch (uvalue)
494 case DW_ACCESS_public: printf ("(public)"); break;
495 case DW_ACCESS_protected: printf ("(protected)"); break;
496 case DW_ACCESS_private: printf ("(private)"); break;
497 default:
498 printf ("(unknown accessibility)");
499 break;
501 break;
503 case DW_AT_visibility:
504 switch (uvalue)
506 case DW_VIS_local: printf ("(local)"); break;
507 case DW_VIS_exported: printf ("(exported)"); break;
508 case DW_VIS_qualified: printf ("(qualified)"); break;
509 default: printf ("(unknown visibility)"); break;
511 break;
513 case DW_AT_virtuality:
514 switch (uvalue)
516 case DW_VIRTUALITY_none: printf ("(none)"); break;
517 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
518 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
519 default: printf ("(unknown virtuality)"); break;
521 break;
523 case DW_AT_identifier_case:
524 switch (uvalue)
526 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
527 case DW_ID_up_case: printf ("(up_case)"); break;
528 case DW_ID_down_case: printf ("(down_case)"); break;
529 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
530 default: printf ("(unknown case)"); break;
532 break;
534 case DW_AT_calling_convention:
535 switch (uvalue)
537 case DW_CC_normal: printf ("(normal)"); break;
538 case DW_CC_program: printf ("(program)"); break;
539 case DW_CC_nocall: printf ("(nocall)"); break;
540 default:
541 if (uvalue >= DW_CC_lo_user
542 && uvalue <= DW_CC_hi_user)
543 printf ("(user defined)");
544 else
545 printf ("(unknown convention)");
547 break;
549 case DW_AT_ordering:
550 switch (uvalue)
552 case -1: printf ("(undefined)"); break;
553 case 0: printf ("(row major)"); break;
554 case 1: printf ("(column major)"); break;
556 break;
558 case DW_AT_frame_base:
559 case DW_AT_location:
560 case DW_AT_data_member_location:
561 case DW_AT_vtable_elem_location:
562 case DW_AT_allocated:
563 case DW_AT_associated:
564 case DW_AT_data_location:
565 case DW_AT_stride:
566 case DW_AT_upper_bound:
567 case DW_AT_lower_bound:
568 if (block_start)
570 printf ("(");
571 decode_location_expression (block_start, pointer_size, uvalue);
572 printf (")");
574 else if (form == DW_FORM_data4 || form == DW_FORM_data8)
576 printf ("(");
577 printf ("location list");
578 printf (")");
580 break;
581 #endif
583 static void
584 dwarf_dump_av_attr(Dwarf_Die die __unused, Dwarf_AttrValue av)
586 switch (av->av_attrib) {
587 case DW_AT_accessibility:
588 break;
590 case DW_AT_calling_convention:
591 break;
593 case DW_AT_encoding:
594 break;
596 case DW_AT_identifier_case:
597 break;
599 case DW_AT_inline:
600 break;
602 case DW_AT_language:
603 break;
605 case DW_AT_ordering:
606 break;
608 case DW_AT_virtuality:
609 break;
611 case DW_AT_visibility:
612 break;
614 case DW_AT_frame_base:
615 case DW_AT_location:
616 case DW_AT_data_member_location:
617 case DW_AT_vtable_elem_location:
618 case DW_AT_upper_bound:
619 case DW_AT_lower_bound:
620 break;
622 default:
623 break;
627 void
628 dwarf_dump_av(Dwarf_Die die, Dwarf_AttrValue av)
630 uint64_t i;
632 printf(" %-30s : %-16s ",
633 get_attr_desc(av->av_attrib),
634 get_form_desc(av->av_form));
636 switch (av->av_form) {
637 case DW_FORM_addr:
638 printf("0x%llx", (unsigned long long) av->u[0].u64);
639 break;
640 case DW_FORM_block:
641 case DW_FORM_block1:
642 case DW_FORM_block2:
643 case DW_FORM_block4:
644 printf("%lu byte block:", (u_long) av->u[0].u64);
645 for (i = 0; i < av->u[0].u64; i++)
646 printf(" %02x", av->u[1].u8p[i]);
647 break;
648 case DW_FORM_data1:
649 case DW_FORM_data2:
650 case DW_FORM_data4:
651 case DW_FORM_data8:
652 case DW_FORM_flag:
653 printf("%llu", (unsigned long long) av->u[0].u64);
654 break;
655 case DW_FORM_ref1:
656 case DW_FORM_ref2:
657 case DW_FORM_ref4:
658 case DW_FORM_ref8:
659 case DW_FORM_ref_udata:
660 printf("<%llx>", (unsigned long long) (av->u[0].u64 +
661 die->die_cu->cu_offset));
662 break;
663 case DW_FORM_string:
664 printf("%s", av->u[0].s);
665 break;
666 case DW_FORM_strp:
667 printf("(indirect string, offset 0x%llx): %s",
668 (unsigned long long) av->u[0].u64, av->u[1].s);
669 break;
670 default:
671 printf("unknown form");
672 break;
675 /* Dump any extra attribute-specific information. */
676 dwarf_dump_av_attr(die, av);
678 printf("\n");
681 void
682 dwarf_dump_die_at_offset(Dwarf_Debug dbg, Dwarf_Off off)
684 Dwarf_CU cu;
685 Dwarf_Die die;
687 if (dbg == NULL)
688 return;
690 STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) {
691 STAILQ_FOREACH(die, &cu->cu_die, die_next) {
692 if ((off_t) die->die_offset == off) {
693 dwarf_dump_die(die);
694 return;
700 void
701 dwarf_dump_die(Dwarf_Die die)
703 Dwarf_AttrValue av;
705 printf("<%d><%llx>: Abbrev number: %llu (%s)\n",
706 die->die_level, (unsigned long long) die->die_offset,
707 (unsigned long long) die->die_abnum,
708 get_tag_desc(die->die_a->a_tag));
710 STAILQ_FOREACH(av, &die->die_attrval, av_next)
711 dwarf_dump_av(die, av);
714 void
715 dwarf_dump_raw(Dwarf_Debug dbg)
717 Dwarf_CU cu;
718 char *p = (char *) dbg;
719 int i;
721 printf("dbg %p\n",dbg);
723 if (dbg == NULL)
724 return;
726 for (i = 0; i < (int) sizeof(*dbg); i++) {
727 if (*p >= 0x20 && *p < 0x7f) {
728 printf(" %c",*p++ & 0xff);
729 } else {
730 printf(" %02x",*p++ & 0xff);
733 printf("\n");
735 STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) {
736 p = (char *) cu;
737 printf("cu %p\n",cu);
738 for (i = 0; i < (int) sizeof(*cu); i++) {
739 if (*p >= 0x20 && *p < 0x7f) {
740 printf(" %c",*p++ & 0xff);
741 } else {
742 printf(" %02x",*p++ & 0xff);
745 printf("\n");
749 static void
750 dwarf_dump_tree_dies(Dwarf_Debug dbg, Dwarf_Die die, Dwarf_Error *error)
752 Dwarf_Die child;
753 int ret;
755 do {
756 dwarf_dump_die(die);
758 if ((ret = dwarf_child(die, &child, error) == DWARF_E_NO_ENTRY)) {
759 /* No children. */
760 } else if (ret != DWARF_E_NONE) {
761 printf("Error %s\n", dwarf_errmsg(error));
762 return;
763 } else
764 dwarf_dump_tree_dies(dbg, child, error);
766 if (dwarf_siblingof(dbg, die, &die, error) != DWARF_E_NONE)
767 die = NULL;
769 } while (die != NULL);
772 void
773 dwarf_dump_tree(Dwarf_Debug dbg)
775 Dwarf_CU cu;
776 Dwarf_Die die;
777 Dwarf_Error error;
778 Dwarf_Half cu_pointer_size;
779 Dwarf_Half cu_version;
780 Dwarf_Unsigned cu_abbrev_offset;
781 Dwarf_Unsigned cu_header_length;
782 Dwarf_Unsigned cu_next_offset;
784 STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) {
785 printf ("\nCompilation Unit @ offset %llx:\n",
786 (unsigned long long) cu->cu_offset);
787 printf (" Length: %lu\n", (u_long) cu->cu_length);
788 printf (" Version: %hu\n", cu->cu_version);
789 printf (" Abbrev Offset: %lu\n", (u_long) cu->cu_abbrev_offset);
790 printf (" Pointer Size: %u\n", (u_int) cu->cu_pointer_size);
792 if (dwarf_next_cu_header(dbg, &cu_header_length,
793 &cu_version, &cu_abbrev_offset, &cu_pointer_size,
794 &cu_next_offset, &error) != DWARF_E_NONE) {
795 printf("Error %s\n", dwarf_errmsg(&error));
796 return;
799 if (dwarf_siblingof(dbg, NULL, &die, &error) != DWARF_E_NONE) {
800 printf("Error %s\n", dwarf_errmsg(&error));
801 return;
804 dwarf_dump_tree_dies(dbg, die, &error);
809 void
810 dwarf_dump_info(Dwarf_Debug dbg)
812 Dwarf_CU cu;
813 Dwarf_Die die;
815 printf("Contents of the .debug_info section:\n");
817 STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) {
818 printf ("\nCompilation Unit @ offset %llx:\n",
819 (unsigned long long) cu->cu_offset);
820 printf (" Length: %lu\n", (u_long) cu->cu_length);
821 printf (" Version: %hu\n", cu->cu_version);
822 printf (" Abbrev Offset: %lu\n", (u_long) cu->cu_abbrev_offset);
823 printf (" Pointer Size: %u\n", (u_int) cu->cu_pointer_size);
825 STAILQ_FOREACH(die, &cu->cu_die, die_next)
826 dwarf_dump_die(die);
831 void
832 dwarf_dump_shstrtab(Dwarf_Debug dbg)
834 char *name;
835 int indx = 0;
837 printf("---------------------\nSection header string table contents:\n");
838 while ((name = elf_strptr(dbg->dbg_elf, dbg->dbg_stnum, indx)) != NULL) {
839 printf("%5d '%s'\n",indx,name);
840 indx += strlen(name) + 1;
844 void
845 dwarf_dump_strtab(Dwarf_Debug dbg)
847 char *name;
848 int indx = 0;
850 printf("---------------------\nString table contents:\n");
851 while ((name = elf_strptr(dbg->dbg_elf, dbg->dbg_s[DWARF_strtab].s_shnum, indx)) != NULL) {
852 printf("%5d '%s'\n",indx,name);
853 indx += strlen(name) + 1;
857 void
858 dwarf_dump_dbgstr(Dwarf_Debug dbg)
860 char *name;
861 int indx = 0;
863 printf("---------------------\nDebug string table contents:\n");
864 while ((name = elf_strptr(dbg->dbg_elf, dbg->dbg_s[DWARF_debug_str].s_shnum, indx)) != NULL) {
865 printf("%5d '%s'\n",indx,name);
866 indx += strlen(name) + 1;
870 void
871 dwarf_dump_symtab(Dwarf_Debug dbg)
873 GElf_Sym sym;
874 char *name;
875 int indx = 0;
877 printf("---------------------\nSymbol table contents:\n");
878 while (gelf_getsym(dbg->dbg_s[DWARF_symtab].s_data, indx++, &sym) != NULL) {
879 if ((name = elf_strptr(dbg->dbg_elf, dbg->dbg_s[DWARF_strtab].s_shnum, sym.st_name)) == NULL)
880 printf("sym.st_name %u indx %d sym.st_size %lu\n",sym.st_name,indx,(u_long) sym.st_size);
881 else
882 printf("'%s' sym.st_name %u indx %d sym.st_size %lu\n",name,sym.st_name,indx,(u_long) sym.st_size);
886 void
887 dwarf_dump(Dwarf_Debug dbg)
889 dwarf_dump_strtab(dbg);
890 dwarf_dump_shstrtab(dbg);
891 dwarf_dump_dbgstr(dbg);
892 dwarf_dump_symtab(dbg);
893 dwarf_dump_info(dbg);