* objcopy.c (copy_archive): Check bfd_openw result in unknown object
[deliverable/binutils-gdb.git] / binutils / dwarf.c
1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
4
5 This file is part of GNU Binutils.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
20 02110-1301, USA. */
21
22 #include "sysdep.h"
23 #include "libiberty.h"
24 #include "bfd.h"
25 #include "bfd_stdint.h"
26 #include "bucomm.h"
27 #include "elfcomm.h"
28 #include "elf/common.h"
29 #include "dwarf2.h"
30 #include "dwarf.h"
31
32 static const char *regname (unsigned int regno, int row);
33
34 static int have_frame_base;
35 static int need_base_address;
36
37 static unsigned int last_pointer_size = 0;
38 static int warned_about_missing_comp_units = FALSE;
39
40 static unsigned int num_debug_info_entries = 0;
41 static debug_info *debug_information = NULL;
42 /* Special value for num_debug_info_entries to indicate
43 that the .debug_info section could not be loaded/parsed. */
44 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
45
46 int eh_addr_size;
47
48 int do_debug_info;
49 int do_debug_abbrevs;
50 int do_debug_lines;
51 int do_debug_pubnames;
52 int do_debug_pubtypes;
53 int do_debug_aranges;
54 int do_debug_ranges;
55 int do_debug_frames;
56 int do_debug_frames_interp;
57 int do_debug_macinfo;
58 int do_debug_str;
59 int do_debug_loc;
60 int do_gdb_index;
61 int do_trace_info;
62 int do_trace_abbrevs;
63 int do_trace_aranges;
64 int do_wide;
65
66 int dwarf_cutoff_level = -1;
67 unsigned long dwarf_start_die;
68
69 /* Values for do_debug_lines. */
70 #define FLAG_DEBUG_LINES_RAW 1
71 #define FLAG_DEBUG_LINES_DECODED 2
72
73 static int
74 size_of_encoded_value (int encoding)
75 {
76 switch (encoding & 0x7)
77 {
78 default: /* ??? */
79 case 0: return eh_addr_size;
80 case 2: return 2;
81 case 3: return 4;
82 case 4: return 8;
83 }
84 }
85
86 static dwarf_vma
87 get_encoded_value (unsigned char *data,
88 int encoding,
89 struct dwarf_section *section)
90 {
91 int size = size_of_encoded_value (encoding);
92 dwarf_vma val;
93
94 if (encoding & DW_EH_PE_signed)
95 val = byte_get_signed (data, size);
96 else
97 val = byte_get (data, size);
98
99 if ((encoding & 0x70) == DW_EH_PE_pcrel)
100 val += section->address + (data - section->start);
101 return val;
102 }
103
104 /* Print a dwarf_vma value (typically an address, offset or length) in
105 hexadecimal format, followed by a space. The length of the value (and
106 hence the precision displayed) is determined by the byte_size parameter. */
107
108 static void
109 print_dwarf_vma (dwarf_vma val, unsigned byte_size)
110 {
111 static char buff[18];
112 int offset = 0;
113
114 /* Printf does not have a way of specifiying a maximum field width for an
115 integer value, so we print the full value into a buffer and then select
116 the precision we need. */
117 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
118 #ifndef __MINGW32__
119 snprintf (buff, sizeof (buff), "%16.16llx ", val);
120 #else
121 snprintf (buff, sizeof (buff), "%016I64x ", val);
122 #endif
123 #else
124 snprintf (buff, sizeof (buff), "%16.16lx ", val);
125 #endif
126
127 if (byte_size != 0)
128 {
129 if (byte_size > 0 && byte_size <= 8)
130 offset = 16 - 2 * byte_size;
131 else
132 error ("Wrong size in print_dwarf_vma");
133 }
134
135 fputs (buff + offset, stdout);
136 }
137
138 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
139 #ifndef __MINGW32__
140 #define DWARF_VMA_FMT "ll"
141 #else
142 #define DWARF_VMA_FMT "I64"
143 #endif
144 #else
145 #define DWARF_VMA_FMT "l"
146 #endif
147
148 static const char *
149 dwarf_vmatoa (const char *fmtch, dwarf_vma value)
150 {
151 /* As dwarf_vmatoa is used more then once in a printf call
152 for output, we are cycling through an fixed array of pointers
153 for return address. */
154 static int buf_pos = 0;
155 static struct dwarf_vmatoa_buf
156 {
157 char place[64];
158 } buf[16];
159 char fmt[32];
160 char *ret;
161
162 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
163
164 ret = buf[buf_pos++].place;
165 buf_pos %= ARRAY_SIZE (buf);
166
167 snprintf (ret, sizeof (buf[0].place), fmt, value);
168
169 return ret;
170 }
171
172 dwarf_vma
173 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
174 {
175 dwarf_vma result = 0;
176 unsigned int num_read = 0;
177 unsigned int shift = 0;
178 unsigned char byte;
179
180 do
181 {
182 byte = *data++;
183 num_read++;
184
185 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
186
187 shift += 7;
188
189 }
190 while (byte & 0x80);
191
192 if (length_return != NULL)
193 *length_return = num_read;
194
195 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
196 result |= -1L << shift;
197
198 return result;
199 }
200
201 /* Create a signed version to avoid painful typecasts. */
202 static dwarf_signed_vma
203 read_sleb128 (unsigned char *data, unsigned int *length_return)
204 {
205 return (dwarf_signed_vma) read_leb128 (data, length_return, 1);
206 }
207
208 typedef struct State_Machine_Registers
209 {
210 dwarf_vma address;
211 unsigned int file;
212 unsigned int line;
213 unsigned int column;
214 int is_stmt;
215 int basic_block;
216 unsigned char op_index;
217 unsigned char end_sequence;
218 /* This variable hold the number of the last entry seen
219 in the File Table. */
220 unsigned int last_file_entry;
221 } SMR;
222
223 static SMR state_machine_regs;
224
225 static void
226 reset_state_machine (int is_stmt)
227 {
228 state_machine_regs.address = 0;
229 state_machine_regs.op_index = 0;
230 state_machine_regs.file = 1;
231 state_machine_regs.line = 1;
232 state_machine_regs.column = 0;
233 state_machine_regs.is_stmt = is_stmt;
234 state_machine_regs.basic_block = 0;
235 state_machine_regs.end_sequence = 0;
236 state_machine_regs.last_file_entry = 0;
237 }
238
239 /* Handled an extend line op.
240 Returns the number of bytes read. */
241
242 static int
243 process_extended_line_op (unsigned char *data, int is_stmt)
244 {
245 unsigned char op_code;
246 unsigned int bytes_read;
247 unsigned int len;
248 unsigned char *name;
249 dwarf_vma adr;
250
251 len = read_leb128 (data, & bytes_read, 0);
252 data += bytes_read;
253
254 if (len == 0)
255 {
256 warn (_("badly formed extended line op encountered!\n"));
257 return bytes_read;
258 }
259
260 len += bytes_read;
261 op_code = *data++;
262
263 printf (_(" Extended opcode %d: "), op_code);
264
265 switch (op_code)
266 {
267 case DW_LNE_end_sequence:
268 printf (_("End of Sequence\n\n"));
269 reset_state_machine (is_stmt);
270 break;
271
272 case DW_LNE_set_address:
273 adr = byte_get (data, len - bytes_read - 1);
274 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
275 state_machine_regs.address = adr;
276 state_machine_regs.op_index = 0;
277 break;
278
279 case DW_LNE_define_file:
280 printf (_(" define new File Table entry\n"));
281 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
282
283 printf (" %d\t", ++state_machine_regs.last_file_entry);
284 name = data;
285 data += strlen ((char *) data) + 1;
286 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
287 data += bytes_read;
288 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
289 data += bytes_read;
290 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
291 printf ("%s\n\n", name);
292 break;
293
294 case DW_LNE_set_discriminator:
295 printf (_("set Discriminator to %s\n"),
296 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
297 break;
298
299 /* HP extensions. */
300 case DW_LNE_HP_negate_is_UV_update:
301 printf ("DW_LNE_HP_negate_is_UV_update\n");
302 break;
303 case DW_LNE_HP_push_context:
304 printf ("DW_LNE_HP_push_context\n");
305 break;
306 case DW_LNE_HP_pop_context:
307 printf ("DW_LNE_HP_pop_context\n");
308 break;
309 case DW_LNE_HP_set_file_line_column:
310 printf ("DW_LNE_HP_set_file_line_column\n");
311 break;
312 case DW_LNE_HP_set_routine_name:
313 printf ("DW_LNE_HP_set_routine_name\n");
314 break;
315 case DW_LNE_HP_set_sequence:
316 printf ("DW_LNE_HP_set_sequence\n");
317 break;
318 case DW_LNE_HP_negate_post_semantics:
319 printf ("DW_LNE_HP_negate_post_semantics\n");
320 break;
321 case DW_LNE_HP_negate_function_exit:
322 printf ("DW_LNE_HP_negate_function_exit\n");
323 break;
324 case DW_LNE_HP_negate_front_end_logical:
325 printf ("DW_LNE_HP_negate_front_end_logical\n");
326 break;
327 case DW_LNE_HP_define_proc:
328 printf ("DW_LNE_HP_define_proc\n");
329 break;
330 case DW_LNE_HP_source_file_correlation:
331 {
332 unsigned char *edata = data + len - bytes_read - 1;
333
334 printf ("DW_LNE_HP_source_file_correlation\n");
335
336 while (data < edata)
337 {
338 unsigned int opc;
339
340 opc = read_leb128 (data, & bytes_read, 0);
341 data += bytes_read;
342
343 switch (opc)
344 {
345 case DW_LNE_HP_SFC_formfeed:
346 printf (" DW_LNE_HP_SFC_formfeed\n");
347 break;
348 case DW_LNE_HP_SFC_set_listing_line:
349 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
350 dwarf_vmatoa ("u",
351 read_leb128 (data, & bytes_read, 0)));
352 data += bytes_read;
353 break;
354 case DW_LNE_HP_SFC_associate:
355 printf (" DW_LNE_HP_SFC_associate ");
356 printf (_("(%s"),
357 dwarf_vmatoa ("u",
358 read_leb128 (data, & bytes_read, 0)));
359 data += bytes_read;
360 printf (_(",%s"),
361 dwarf_vmatoa ("u",
362 read_leb128 (data, & bytes_read, 0)));
363 data += bytes_read;
364 printf (_(",%s)\n"),
365 dwarf_vmatoa ("u",
366 read_leb128 (data, & bytes_read, 0)));
367 data += bytes_read;
368 break;
369 default:
370 printf (" UNKNOW DW_LNE_HP_SFC opcode (%u)\n", opc);
371 data = edata;
372 break;
373 }
374 }
375 }
376 break;
377
378 default:
379 if (op_code >= DW_LNE_lo_user
380 /* The test against DW_LNW_hi_user is redundant due to
381 the limited range of the unsigned char data type used
382 for op_code. */
383 /*&& op_code <= DW_LNE_hi_user*/)
384 printf (_("user defined: length %d\n"), len - bytes_read);
385 else
386 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
387 break;
388 }
389
390 return len;
391 }
392
393 static const char *
394 fetch_indirect_string (dwarf_vma offset)
395 {
396 struct dwarf_section *section = &debug_displays [str].section;
397
398 if (section->start == NULL)
399 return _("<no .debug_str section>");
400
401 /* DWARF sections under Mach-O have non-zero addresses. */
402 offset -= section->address;
403 if (offset > section->size)
404 {
405 warn (_("DW_FORM_strp offset too big: %s\n"),
406 dwarf_vmatoa ("x", offset));
407 return _("<offset is too big>");
408 }
409
410 return (const char *) section->start + offset;
411 }
412
413 /* FIXME: There are better and more efficient ways to handle
414 these structures. For now though, I just want something that
415 is simple to implement. */
416 typedef struct abbrev_attr
417 {
418 unsigned long attribute;
419 unsigned long form;
420 struct abbrev_attr *next;
421 }
422 abbrev_attr;
423
424 typedef struct abbrev_entry
425 {
426 unsigned long entry;
427 unsigned long tag;
428 int children;
429 struct abbrev_attr *first_attr;
430 struct abbrev_attr *last_attr;
431 struct abbrev_entry *next;
432 }
433 abbrev_entry;
434
435 static abbrev_entry *first_abbrev = NULL;
436 static abbrev_entry *last_abbrev = NULL;
437
438 static void
439 free_abbrevs (void)
440 {
441 abbrev_entry *abbrv;
442
443 for (abbrv = first_abbrev; abbrv;)
444 {
445 abbrev_entry *next_abbrev = abbrv->next;
446 abbrev_attr *attr;
447
448 for (attr = abbrv->first_attr; attr;)
449 {
450 abbrev_attr *next_attr = attr->next;
451
452 free (attr);
453 attr = next_attr;
454 }
455
456 free (abbrv);
457 abbrv = next_abbrev;
458 }
459
460 last_abbrev = first_abbrev = NULL;
461 }
462
463 static void
464 add_abbrev (unsigned long number, unsigned long tag, int children)
465 {
466 abbrev_entry *entry;
467
468 entry = (abbrev_entry *) malloc (sizeof (*entry));
469 if (entry == NULL)
470 /* ugg */
471 return;
472
473 entry->entry = number;
474 entry->tag = tag;
475 entry->children = children;
476 entry->first_attr = NULL;
477 entry->last_attr = NULL;
478 entry->next = NULL;
479
480 if (first_abbrev == NULL)
481 first_abbrev = entry;
482 else
483 last_abbrev->next = entry;
484
485 last_abbrev = entry;
486 }
487
488 static void
489 add_abbrev_attr (unsigned long attribute, unsigned long form)
490 {
491 abbrev_attr *attr;
492
493 attr = (abbrev_attr *) malloc (sizeof (*attr));
494 if (attr == NULL)
495 /* ugg */
496 return;
497
498 attr->attribute = attribute;
499 attr->form = form;
500 attr->next = NULL;
501
502 if (last_abbrev->first_attr == NULL)
503 last_abbrev->first_attr = attr;
504 else
505 last_abbrev->last_attr->next = attr;
506
507 last_abbrev->last_attr = attr;
508 }
509
510 /* Processes the (partial) contents of a .debug_abbrev section.
511 Returns NULL if the end of the section was encountered.
512 Returns the address after the last byte read if the end of
513 an abbreviation set was found. */
514
515 static unsigned char *
516 process_abbrev_section (unsigned char *start, unsigned char *end)
517 {
518 if (first_abbrev != NULL)
519 return NULL;
520
521 while (start < end)
522 {
523 unsigned int bytes_read;
524 unsigned long entry;
525 unsigned long tag;
526 unsigned long attribute;
527 int children;
528
529 entry = read_leb128 (start, & bytes_read, 0);
530 start += bytes_read;
531
532 /* A single zero is supposed to end the section according
533 to the standard. If there's more, then signal that to
534 the caller. */
535 if (entry == 0)
536 return start == end ? NULL : start;
537
538 tag = read_leb128 (start, & bytes_read, 0);
539 start += bytes_read;
540
541 children = *start++;
542
543 add_abbrev (entry, tag, children);
544
545 do
546 {
547 unsigned long form;
548
549 attribute = read_leb128 (start, & bytes_read, 0);
550 start += bytes_read;
551
552 form = read_leb128 (start, & bytes_read, 0);
553 start += bytes_read;
554
555 if (attribute != 0)
556 add_abbrev_attr (attribute, form);
557 }
558 while (attribute != 0);
559 }
560
561 return NULL;
562 }
563
564 static char *
565 get_TAG_name (unsigned long tag)
566 {
567 switch (tag)
568 {
569 case DW_TAG_padding: return "DW_TAG_padding";
570 case DW_TAG_array_type: return "DW_TAG_array_type";
571 case DW_TAG_class_type: return "DW_TAG_class_type";
572 case DW_TAG_entry_point: return "DW_TAG_entry_point";
573 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
574 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
575 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
576 case DW_TAG_label: return "DW_TAG_label";
577 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
578 case DW_TAG_member: return "DW_TAG_member";
579 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
580 case DW_TAG_reference_type: return "DW_TAG_reference_type";
581 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
582 case DW_TAG_string_type: return "DW_TAG_string_type";
583 case DW_TAG_structure_type: return "DW_TAG_structure_type";
584 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
585 case DW_TAG_typedef: return "DW_TAG_typedef";
586 case DW_TAG_union_type: return "DW_TAG_union_type";
587 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
588 case DW_TAG_variant: return "DW_TAG_variant";
589 case DW_TAG_common_block: return "DW_TAG_common_block";
590 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
591 case DW_TAG_inheritance: return "DW_TAG_inheritance";
592 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
593 case DW_TAG_module: return "DW_TAG_module";
594 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
595 case DW_TAG_set_type: return "DW_TAG_set_type";
596 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
597 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
598 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
599 case DW_TAG_base_type: return "DW_TAG_base_type";
600 case DW_TAG_catch_block: return "DW_TAG_catch_block";
601 case DW_TAG_const_type: return "DW_TAG_const_type";
602 case DW_TAG_constant: return "DW_TAG_constant";
603 case DW_TAG_enumerator: return "DW_TAG_enumerator";
604 case DW_TAG_file_type: return "DW_TAG_file_type";
605 case DW_TAG_friend: return "DW_TAG_friend";
606 case DW_TAG_namelist: return "DW_TAG_namelist";
607 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
608 case DW_TAG_packed_type: return "DW_TAG_packed_type";
609 case DW_TAG_subprogram: return "DW_TAG_subprogram";
610 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
611 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
612 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
613 case DW_TAG_try_block: return "DW_TAG_try_block";
614 case DW_TAG_variant_part: return "DW_TAG_variant_part";
615 case DW_TAG_variable: return "DW_TAG_variable";
616 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
617 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
618 case DW_TAG_format_label: return "DW_TAG_format_label";
619 case DW_TAG_function_template: return "DW_TAG_function_template";
620 case DW_TAG_class_template: return "DW_TAG_class_template";
621 /* DWARF 2.1 values. */
622 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
623 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
624 case DW_TAG_interface_type: return "DW_TAG_interface_type";
625 case DW_TAG_namespace: return "DW_TAG_namespace";
626 case DW_TAG_imported_module: return "DW_TAG_imported_module";
627 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
628 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
629 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
630 case DW_TAG_condition: return "DW_TAG_condition";
631 case DW_TAG_shared_type: return "DW_TAG_shared_type";
632 /* DWARF 4 values. */
633 case DW_TAG_type_unit: return "DW_TAG_type_unit";
634 case DW_TAG_rvalue_reference_type: return "DW_TAG_rvalue_reference_type";
635 case DW_TAG_template_alias: return "DW_TAG_template_alias";
636 /* UPC values. */
637 case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type";
638 case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type";
639 case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type";
640 /* GNU values. */
641 case DW_TAG_GNU_call_site: return "DW_TAG_GNU_call_site";
642 case DW_TAG_GNU_call_site_parameter:return "DW_TAG_GNU_call_site_parameter";
643 default:
644 {
645 static char buffer[100];
646
647 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
648 return buffer;
649 }
650 }
651 }
652
653 static char *
654 get_FORM_name (unsigned long form)
655 {
656 switch (form)
657 {
658 case DW_FORM_addr: return "DW_FORM_addr";
659 case DW_FORM_block2: return "DW_FORM_block2";
660 case DW_FORM_block4: return "DW_FORM_block4";
661 case DW_FORM_data2: return "DW_FORM_data2";
662 case DW_FORM_data4: return "DW_FORM_data4";
663 case DW_FORM_data8: return "DW_FORM_data8";
664 case DW_FORM_string: return "DW_FORM_string";
665 case DW_FORM_block: return "DW_FORM_block";
666 case DW_FORM_block1: return "DW_FORM_block1";
667 case DW_FORM_data1: return "DW_FORM_data1";
668 case DW_FORM_flag: return "DW_FORM_flag";
669 case DW_FORM_sdata: return "DW_FORM_sdata";
670 case DW_FORM_strp: return "DW_FORM_strp";
671 case DW_FORM_udata: return "DW_FORM_udata";
672 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
673 case DW_FORM_ref1: return "DW_FORM_ref1";
674 case DW_FORM_ref2: return "DW_FORM_ref2";
675 case DW_FORM_ref4: return "DW_FORM_ref4";
676 case DW_FORM_ref8: return "DW_FORM_ref8";
677 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
678 case DW_FORM_indirect: return "DW_FORM_indirect";
679 /* DWARF 4 values. */
680 case DW_FORM_sec_offset: return "DW_FORM_sec_offset";
681 case DW_FORM_exprloc: return "DW_FORM_exprloc";
682 case DW_FORM_flag_present: return "DW_FORM_flag_present";
683 case DW_FORM_ref_sig8: return "DW_FORM_ref_sig8";
684 default:
685 {
686 static char buffer[100];
687
688 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
689 return buffer;
690 }
691 }
692 }
693
694 static unsigned char *
695 display_block (unsigned char *data, dwarf_vma length)
696 {
697 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length));
698
699 while (length --)
700 printf ("%lx ", (unsigned long) byte_get (data++, 1));
701
702 return data;
703 }
704
705 static int
706 decode_location_expression (unsigned char * data,
707 unsigned int pointer_size,
708 unsigned int offset_size,
709 int dwarf_version,
710 dwarf_vma length,
711 dwarf_vma cu_offset,
712 struct dwarf_section * section)
713 {
714 unsigned op;
715 unsigned int bytes_read;
716 dwarf_vma uvalue;
717 unsigned char *end = data + length;
718 int need_frame_base = 0;
719
720 while (data < end)
721 {
722 op = *data++;
723
724 switch (op)
725 {
726 case DW_OP_addr:
727 printf ("DW_OP_addr: %s",
728 dwarf_vmatoa ("x", byte_get (data, pointer_size)));
729 data += pointer_size;
730 break;
731 case DW_OP_deref:
732 printf ("DW_OP_deref");
733 break;
734 case DW_OP_const1u:
735 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
736 break;
737 case DW_OP_const1s:
738 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
739 break;
740 case DW_OP_const2u:
741 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
742 data += 2;
743 break;
744 case DW_OP_const2s:
745 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
746 data += 2;
747 break;
748 case DW_OP_const4u:
749 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
750 data += 4;
751 break;
752 case DW_OP_const4s:
753 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
754 data += 4;
755 break;
756 case DW_OP_const8u:
757 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
758 (unsigned long) byte_get (data + 4, 4));
759 data += 8;
760 break;
761 case DW_OP_const8s:
762 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
763 (long) byte_get (data + 4, 4));
764 data += 8;
765 break;
766 case DW_OP_constu:
767 printf ("DW_OP_constu: %s",
768 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
769 data += bytes_read;
770 break;
771 case DW_OP_consts:
772 printf ("DW_OP_consts: %s",
773 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
774 data += bytes_read;
775 break;
776 case DW_OP_dup:
777 printf ("DW_OP_dup");
778 break;
779 case DW_OP_drop:
780 printf ("DW_OP_drop");
781 break;
782 case DW_OP_over:
783 printf ("DW_OP_over");
784 break;
785 case DW_OP_pick:
786 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
787 break;
788 case DW_OP_swap:
789 printf ("DW_OP_swap");
790 break;
791 case DW_OP_rot:
792 printf ("DW_OP_rot");
793 break;
794 case DW_OP_xderef:
795 printf ("DW_OP_xderef");
796 break;
797 case DW_OP_abs:
798 printf ("DW_OP_abs");
799 break;
800 case DW_OP_and:
801 printf ("DW_OP_and");
802 break;
803 case DW_OP_div:
804 printf ("DW_OP_div");
805 break;
806 case DW_OP_minus:
807 printf ("DW_OP_minus");
808 break;
809 case DW_OP_mod:
810 printf ("DW_OP_mod");
811 break;
812 case DW_OP_mul:
813 printf ("DW_OP_mul");
814 break;
815 case DW_OP_neg:
816 printf ("DW_OP_neg");
817 break;
818 case DW_OP_not:
819 printf ("DW_OP_not");
820 break;
821 case DW_OP_or:
822 printf ("DW_OP_or");
823 break;
824 case DW_OP_plus:
825 printf ("DW_OP_plus");
826 break;
827 case DW_OP_plus_uconst:
828 printf ("DW_OP_plus_uconst: %s",
829 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
830 data += bytes_read;
831 break;
832 case DW_OP_shl:
833 printf ("DW_OP_shl");
834 break;
835 case DW_OP_shr:
836 printf ("DW_OP_shr");
837 break;
838 case DW_OP_shra:
839 printf ("DW_OP_shra");
840 break;
841 case DW_OP_xor:
842 printf ("DW_OP_xor");
843 break;
844 case DW_OP_bra:
845 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
846 data += 2;
847 break;
848 case DW_OP_eq:
849 printf ("DW_OP_eq");
850 break;
851 case DW_OP_ge:
852 printf ("DW_OP_ge");
853 break;
854 case DW_OP_gt:
855 printf ("DW_OP_gt");
856 break;
857 case DW_OP_le:
858 printf ("DW_OP_le");
859 break;
860 case DW_OP_lt:
861 printf ("DW_OP_lt");
862 break;
863 case DW_OP_ne:
864 printf ("DW_OP_ne");
865 break;
866 case DW_OP_skip:
867 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
868 data += 2;
869 break;
870
871 case DW_OP_lit0:
872 case DW_OP_lit1:
873 case DW_OP_lit2:
874 case DW_OP_lit3:
875 case DW_OP_lit4:
876 case DW_OP_lit5:
877 case DW_OP_lit6:
878 case DW_OP_lit7:
879 case DW_OP_lit8:
880 case DW_OP_lit9:
881 case DW_OP_lit10:
882 case DW_OP_lit11:
883 case DW_OP_lit12:
884 case DW_OP_lit13:
885 case DW_OP_lit14:
886 case DW_OP_lit15:
887 case DW_OP_lit16:
888 case DW_OP_lit17:
889 case DW_OP_lit18:
890 case DW_OP_lit19:
891 case DW_OP_lit20:
892 case DW_OP_lit21:
893 case DW_OP_lit22:
894 case DW_OP_lit23:
895 case DW_OP_lit24:
896 case DW_OP_lit25:
897 case DW_OP_lit26:
898 case DW_OP_lit27:
899 case DW_OP_lit28:
900 case DW_OP_lit29:
901 case DW_OP_lit30:
902 case DW_OP_lit31:
903 printf ("DW_OP_lit%d", op - DW_OP_lit0);
904 break;
905
906 case DW_OP_reg0:
907 case DW_OP_reg1:
908 case DW_OP_reg2:
909 case DW_OP_reg3:
910 case DW_OP_reg4:
911 case DW_OP_reg5:
912 case DW_OP_reg6:
913 case DW_OP_reg7:
914 case DW_OP_reg8:
915 case DW_OP_reg9:
916 case DW_OP_reg10:
917 case DW_OP_reg11:
918 case DW_OP_reg12:
919 case DW_OP_reg13:
920 case DW_OP_reg14:
921 case DW_OP_reg15:
922 case DW_OP_reg16:
923 case DW_OP_reg17:
924 case DW_OP_reg18:
925 case DW_OP_reg19:
926 case DW_OP_reg20:
927 case DW_OP_reg21:
928 case DW_OP_reg22:
929 case DW_OP_reg23:
930 case DW_OP_reg24:
931 case DW_OP_reg25:
932 case DW_OP_reg26:
933 case DW_OP_reg27:
934 case DW_OP_reg28:
935 case DW_OP_reg29:
936 case DW_OP_reg30:
937 case DW_OP_reg31:
938 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
939 regname (op - DW_OP_reg0, 1));
940 break;
941
942 case DW_OP_breg0:
943 case DW_OP_breg1:
944 case DW_OP_breg2:
945 case DW_OP_breg3:
946 case DW_OP_breg4:
947 case DW_OP_breg5:
948 case DW_OP_breg6:
949 case DW_OP_breg7:
950 case DW_OP_breg8:
951 case DW_OP_breg9:
952 case DW_OP_breg10:
953 case DW_OP_breg11:
954 case DW_OP_breg12:
955 case DW_OP_breg13:
956 case DW_OP_breg14:
957 case DW_OP_breg15:
958 case DW_OP_breg16:
959 case DW_OP_breg17:
960 case DW_OP_breg18:
961 case DW_OP_breg19:
962 case DW_OP_breg20:
963 case DW_OP_breg21:
964 case DW_OP_breg22:
965 case DW_OP_breg23:
966 case DW_OP_breg24:
967 case DW_OP_breg25:
968 case DW_OP_breg26:
969 case DW_OP_breg27:
970 case DW_OP_breg28:
971 case DW_OP_breg29:
972 case DW_OP_breg30:
973 case DW_OP_breg31:
974 printf ("DW_OP_breg%d (%s): %s",
975 op - DW_OP_breg0,
976 regname (op - DW_OP_breg0, 1),
977 dwarf_vmatoa ("d", (dwarf_signed_vma)
978 read_leb128 (data, &bytes_read, 1)));
979 data += bytes_read;
980 break;
981
982 case DW_OP_regx:
983 uvalue = read_leb128 (data, &bytes_read, 0);
984 data += bytes_read;
985 printf ("DW_OP_regx: %s (%s)",
986 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
987 break;
988 case DW_OP_fbreg:
989 need_frame_base = 1;
990 printf ("DW_OP_fbreg: %s",
991 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
992 data += bytes_read;
993 break;
994 case DW_OP_bregx:
995 uvalue = read_leb128 (data, &bytes_read, 0);
996 data += bytes_read;
997 printf ("DW_OP_bregx: %s (%s) %s",
998 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
999 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
1000 data += bytes_read;
1001 break;
1002 case DW_OP_piece:
1003 printf ("DW_OP_piece: %s",
1004 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1005 data += bytes_read;
1006 break;
1007 case DW_OP_deref_size:
1008 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
1009 break;
1010 case DW_OP_xderef_size:
1011 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
1012 break;
1013 case DW_OP_nop:
1014 printf ("DW_OP_nop");
1015 break;
1016
1017 /* DWARF 3 extensions. */
1018 case DW_OP_push_object_address:
1019 printf ("DW_OP_push_object_address");
1020 break;
1021 case DW_OP_call2:
1022 /* XXX: Strictly speaking for 64-bit DWARF3 files
1023 this ought to be an 8-byte wide computation. */
1024 printf ("DW_OP_call2: <0x%s>",
1025 dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 2)
1026 + cu_offset));
1027 data += 2;
1028 break;
1029 case DW_OP_call4:
1030 /* XXX: Strictly speaking for 64-bit DWARF3 files
1031 this ought to be an 8-byte wide computation. */
1032 printf ("DW_OP_call4: <0x%s>",
1033 dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 4)
1034 + cu_offset));
1035 data += 4;
1036 break;
1037 case DW_OP_call_ref:
1038 /* XXX: Strictly speaking for 64-bit DWARF3 files
1039 this ought to be an 8-byte wide computation. */
1040 if (dwarf_version == -1)
1041 {
1042 printf (_("(DW_OP_call_ref in frame info)"));
1043 /* No way to tell where the next op is, so just bail. */
1044 return need_frame_base;
1045 }
1046 if (dwarf_version == 2)
1047 {
1048 printf ("DW_OP_call_ref: <0x%s>",
1049 dwarf_vmatoa ("x", byte_get (data, pointer_size)));
1050 data += pointer_size;
1051 }
1052 else
1053 {
1054 printf ("DW_OP_call_ref: <0x%s>",
1055 dwarf_vmatoa ("x", byte_get (data, offset_size)));
1056 data += offset_size;
1057 }
1058 break;
1059 case DW_OP_form_tls_address:
1060 printf ("DW_OP_form_tls_address");
1061 break;
1062 case DW_OP_call_frame_cfa:
1063 printf ("DW_OP_call_frame_cfa");
1064 break;
1065 case DW_OP_bit_piece:
1066 printf ("DW_OP_bit_piece: ");
1067 printf ("size: %s ",
1068 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1069 data += bytes_read;
1070 printf ("offset: %s ",
1071 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1072 data += bytes_read;
1073 break;
1074
1075 /* DWARF 4 extensions. */
1076 case DW_OP_stack_value:
1077 printf ("DW_OP_stack_value");
1078 break;
1079
1080 case DW_OP_implicit_value:
1081 printf ("DW_OP_implicit_value");
1082 uvalue = read_leb128 (data, &bytes_read, 0);
1083 data += bytes_read;
1084 display_block (data, uvalue);
1085 data += uvalue;
1086 break;
1087
1088 /* GNU extensions. */
1089 case DW_OP_GNU_push_tls_address:
1090 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
1091 break;
1092 case DW_OP_GNU_uninit:
1093 printf ("DW_OP_GNU_uninit");
1094 /* FIXME: Is there data associated with this OP ? */
1095 break;
1096 case DW_OP_GNU_encoded_addr:
1097 {
1098 int encoding;
1099 dwarf_vma addr;
1100
1101 encoding = *data++;
1102 addr = get_encoded_value (data, encoding, section);
1103 data += size_of_encoded_value (encoding);
1104
1105 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1106 print_dwarf_vma (addr, pointer_size);
1107 }
1108 break;
1109 case DW_OP_GNU_implicit_pointer:
1110 /* XXX: Strictly speaking for 64-bit DWARF3 files
1111 this ought to be an 8-byte wide computation. */
1112 if (dwarf_version == -1)
1113 {
1114 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1115 /* No way to tell where the next op is, so just bail. */
1116 return need_frame_base;
1117 }
1118 if (dwarf_version == 2)
1119 {
1120 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1121 dwarf_vmatoa ("x", byte_get (data, pointer_size)),
1122 dwarf_vmatoa ("d", read_sleb128 (data + pointer_size,
1123 &bytes_read)));
1124 data += pointer_size + bytes_read;
1125 }
1126 else
1127 {
1128 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1129 dwarf_vmatoa ("x", byte_get (data, offset_size)),
1130 dwarf_vmatoa ("d", read_sleb128 (data + offset_size,
1131 &bytes_read)));
1132 data += offset_size + bytes_read;
1133 }
1134 break;
1135 case DW_OP_GNU_entry_value:
1136 uvalue = read_leb128 (data, &bytes_read, 0);
1137 data += bytes_read;
1138 printf ("DW_OP_GNU_entry_value: (");
1139 if (decode_location_expression (data, pointer_size, offset_size,
1140 dwarf_version, uvalue,
1141 cu_offset, section))
1142 need_frame_base = 1;
1143 putchar (')');
1144 data += uvalue;
1145 break;
1146 case DW_OP_GNU_const_type:
1147 uvalue = read_leb128 (data, &bytes_read, 0);
1148 data += bytes_read;
1149 printf ("DW_OP_GNU_const_type: <0x%s> ",
1150 dwarf_vmatoa ("x", cu_offset + uvalue));
1151 uvalue = byte_get (data++, 1);
1152 display_block (data, uvalue);
1153 data += uvalue;
1154 break;
1155 case DW_OP_GNU_regval_type:
1156 uvalue = read_leb128 (data, &bytes_read, 0);
1157 data += bytes_read;
1158 printf ("DW_OP_GNU_regval_type: %s (%s)",
1159 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1160 uvalue = read_leb128 (data, &bytes_read, 0);
1161 data += bytes_read;
1162 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1163 break;
1164 case DW_OP_GNU_deref_type:
1165 printf ("DW_OP_GNU_deref_type: %ld", (long) byte_get (data++, 1));
1166 uvalue = read_leb128 (data, &bytes_read, 0);
1167 data += bytes_read;
1168 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1169 break;
1170 case DW_OP_GNU_convert:
1171 uvalue = read_leb128 (data, &bytes_read, 0);
1172 data += bytes_read;
1173 printf ("DW_OP_GNU_convert <0x%s>",
1174 dwarf_vmatoa ("x", cu_offset + uvalue));
1175 break;
1176 case DW_OP_GNU_reinterpret:
1177 uvalue = read_leb128 (data, &bytes_read, 0);
1178 data += bytes_read;
1179 printf ("DW_OP_GNU_reinterpret <0x%s>",
1180 dwarf_vmatoa ("x", cu_offset + uvalue));
1181 break;
1182
1183 /* HP extensions. */
1184 case DW_OP_HP_is_value:
1185 printf ("DW_OP_HP_is_value");
1186 /* FIXME: Is there data associated with this OP ? */
1187 break;
1188 case DW_OP_HP_fltconst4:
1189 printf ("DW_OP_HP_fltconst4");
1190 /* FIXME: Is there data associated with this OP ? */
1191 break;
1192 case DW_OP_HP_fltconst8:
1193 printf ("DW_OP_HP_fltconst8");
1194 /* FIXME: Is there data associated with this OP ? */
1195 break;
1196 case DW_OP_HP_mod_range:
1197 printf ("DW_OP_HP_mod_range");
1198 /* FIXME: Is there data associated with this OP ? */
1199 break;
1200 case DW_OP_HP_unmod_range:
1201 printf ("DW_OP_HP_unmod_range");
1202 /* FIXME: Is there data associated with this OP ? */
1203 break;
1204 case DW_OP_HP_tls:
1205 printf ("DW_OP_HP_tls");
1206 /* FIXME: Is there data associated with this OP ? */
1207 break;
1208
1209 /* PGI (STMicroelectronics) extensions. */
1210 case DW_OP_PGI_omp_thread_num:
1211 /* Pushes the thread number for the current thread as it would be
1212 returned by the standard OpenMP library function:
1213 omp_get_thread_num(). The "current thread" is the thread for
1214 which the expression is being evaluated. */
1215 printf ("DW_OP_PGI_omp_thread_num");
1216 break;
1217
1218 default:
1219 if (op >= DW_OP_lo_user
1220 && op <= DW_OP_hi_user)
1221 printf (_("(User defined location op)"));
1222 else
1223 printf (_("(Unknown location op)"));
1224 /* No way to tell where the next op is, so just bail. */
1225 return need_frame_base;
1226 }
1227
1228 /* Separate the ops. */
1229 if (data < end)
1230 printf ("; ");
1231 }
1232
1233 return need_frame_base;
1234 }
1235
1236 static unsigned char *
1237 read_and_display_attr_value (unsigned long attribute,
1238 unsigned long form,
1239 unsigned char * data,
1240 dwarf_vma cu_offset,
1241 dwarf_vma pointer_size,
1242 dwarf_vma offset_size,
1243 int dwarf_version,
1244 debug_info * debug_info_p,
1245 int do_loc,
1246 struct dwarf_section * section)
1247 {
1248 dwarf_vma uvalue = 0;
1249 unsigned char *block_start = NULL;
1250 unsigned char * orig_data = data;
1251 unsigned int bytes_read;
1252
1253 switch (form)
1254 {
1255 default:
1256 break;
1257
1258 case DW_FORM_ref_addr:
1259 if (dwarf_version == 2)
1260 {
1261 uvalue = byte_get (data, pointer_size);
1262 data += pointer_size;
1263 }
1264 else if (dwarf_version == 3 || dwarf_version == 4)
1265 {
1266 uvalue = byte_get (data, offset_size);
1267 data += offset_size;
1268 }
1269 else
1270 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1271
1272 break;
1273
1274 case DW_FORM_addr:
1275 uvalue = byte_get (data, pointer_size);
1276 data += pointer_size;
1277 break;
1278
1279 case DW_FORM_strp:
1280 case DW_FORM_sec_offset:
1281 uvalue = byte_get (data, offset_size);
1282 data += offset_size;
1283 break;
1284
1285 case DW_FORM_flag_present:
1286 uvalue = 1;
1287 break;
1288
1289 case DW_FORM_ref1:
1290 case DW_FORM_flag:
1291 case DW_FORM_data1:
1292 uvalue = byte_get (data++, 1);
1293 break;
1294
1295 case DW_FORM_ref2:
1296 case DW_FORM_data2:
1297 uvalue = byte_get (data, 2);
1298 data += 2;
1299 break;
1300
1301 case DW_FORM_ref4:
1302 case DW_FORM_data4:
1303 uvalue = byte_get (data, 4);
1304 data += 4;
1305 break;
1306
1307 case DW_FORM_sdata:
1308 uvalue = read_leb128 (data, & bytes_read, 1);
1309 data += bytes_read;
1310 break;
1311
1312 case DW_FORM_ref_udata:
1313 case DW_FORM_udata:
1314 uvalue = read_leb128 (data, & bytes_read, 0);
1315 data += bytes_read;
1316 break;
1317
1318 case DW_FORM_indirect:
1319 form = read_leb128 (data, & bytes_read, 0);
1320 data += bytes_read;
1321 if (!do_loc)
1322 printf (" %s", get_FORM_name (form));
1323 return read_and_display_attr_value (attribute, form, data,
1324 cu_offset, pointer_size,
1325 offset_size, dwarf_version,
1326 debug_info_p, do_loc,
1327 section);
1328 }
1329
1330 switch (form)
1331 {
1332 case DW_FORM_ref_addr:
1333 if (!do_loc)
1334 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue));
1335 break;
1336
1337 case DW_FORM_ref1:
1338 case DW_FORM_ref2:
1339 case DW_FORM_ref4:
1340 case DW_FORM_ref_udata:
1341 if (!do_loc)
1342 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset));
1343 break;
1344
1345 case DW_FORM_data4:
1346 case DW_FORM_addr:
1347 case DW_FORM_sec_offset:
1348 if (!do_loc)
1349 printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
1350 break;
1351
1352 case DW_FORM_flag_present:
1353 case DW_FORM_flag:
1354 case DW_FORM_data1:
1355 case DW_FORM_data2:
1356 case DW_FORM_sdata:
1357 case DW_FORM_udata:
1358 if (!do_loc)
1359 printf (" %s", dwarf_vmatoa ("d", uvalue));
1360 break;
1361
1362 case DW_FORM_ref8:
1363 case DW_FORM_data8:
1364 if (!do_loc)
1365 {
1366 uvalue = byte_get (data, 4);
1367 printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
1368 printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4));
1369 }
1370 if ((do_loc || do_debug_loc || do_debug_ranges)
1371 && num_debug_info_entries == 0)
1372 {
1373 if (sizeof (uvalue) == 8)
1374 uvalue = byte_get (data, 8);
1375 else
1376 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1377 }
1378 data += 8;
1379 break;
1380
1381 case DW_FORM_string:
1382 if (!do_loc)
1383 printf (" %s", data);
1384 data += strlen ((char *) data) + 1;
1385 break;
1386
1387 case DW_FORM_block:
1388 case DW_FORM_exprloc:
1389 uvalue = read_leb128 (data, & bytes_read, 0);
1390 block_start = data + bytes_read;
1391 if (do_loc)
1392 data = block_start + uvalue;
1393 else
1394 data = display_block (block_start, uvalue);
1395 break;
1396
1397 case DW_FORM_block1:
1398 uvalue = byte_get (data, 1);
1399 block_start = data + 1;
1400 if (do_loc)
1401 data = block_start + uvalue;
1402 else
1403 data = display_block (block_start, uvalue);
1404 break;
1405
1406 case DW_FORM_block2:
1407 uvalue = byte_get (data, 2);
1408 block_start = data + 2;
1409 if (do_loc)
1410 data = block_start + uvalue;
1411 else
1412 data = display_block (block_start, uvalue);
1413 break;
1414
1415 case DW_FORM_block4:
1416 uvalue = byte_get (data, 4);
1417 block_start = data + 4;
1418 if (do_loc)
1419 data = block_start + uvalue;
1420 else
1421 data = display_block (block_start, uvalue);
1422 break;
1423
1424 case DW_FORM_strp:
1425 if (!do_loc)
1426 printf (_(" (indirect string, offset: 0x%s): %s"),
1427 dwarf_vmatoa ("x", uvalue),
1428 fetch_indirect_string (uvalue));
1429 break;
1430
1431 case DW_FORM_indirect:
1432 /* Handled above. */
1433 break;
1434
1435 case DW_FORM_ref_sig8:
1436 if (!do_loc)
1437 {
1438 int i;
1439 printf (" signature: ");
1440 for (i = 0; i < 8; i++)
1441 {
1442 printf ("%02x", (unsigned) byte_get (data, 1));
1443 data += 1;
1444 }
1445 }
1446 else
1447 data += 8;
1448 break;
1449
1450 default:
1451 warn (_("Unrecognized form: %lu\n"), form);
1452 break;
1453 }
1454
1455 if ((do_loc || do_debug_loc || do_debug_ranges)
1456 && num_debug_info_entries == 0
1457 && debug_info_p != NULL)
1458 {
1459 switch (attribute)
1460 {
1461 case DW_AT_frame_base:
1462 have_frame_base = 1;
1463 case DW_AT_location:
1464 case DW_AT_string_length:
1465 case DW_AT_return_addr:
1466 case DW_AT_data_member_location:
1467 case DW_AT_vtable_elem_location:
1468 case DW_AT_segment:
1469 case DW_AT_static_link:
1470 case DW_AT_use_location:
1471 case DW_AT_GNU_call_site_value:
1472 case DW_AT_GNU_call_site_data_value:
1473 case DW_AT_GNU_call_site_target:
1474 case DW_AT_GNU_call_site_target_clobbered:
1475 if (form == DW_FORM_data4
1476 || form == DW_FORM_data8
1477 || form == DW_FORM_sec_offset)
1478 {
1479 /* Process location list. */
1480 unsigned int lmax = debug_info_p->max_loc_offsets;
1481 unsigned int num = debug_info_p->num_loc_offsets;
1482
1483 if (lmax == 0 || num >= lmax)
1484 {
1485 lmax += 1024;
1486 debug_info_p->loc_offsets = (dwarf_vma *)
1487 xcrealloc (debug_info_p->loc_offsets,
1488 lmax, sizeof (*debug_info_p->loc_offsets));
1489 debug_info_p->have_frame_base = (int *)
1490 xcrealloc (debug_info_p->have_frame_base,
1491 lmax, sizeof (*debug_info_p->have_frame_base));
1492 debug_info_p->max_loc_offsets = lmax;
1493 }
1494 debug_info_p->loc_offsets [num] = uvalue;
1495 debug_info_p->have_frame_base [num] = have_frame_base;
1496 debug_info_p->num_loc_offsets++;
1497 }
1498 break;
1499
1500 case DW_AT_low_pc:
1501 if (need_base_address)
1502 debug_info_p->base_address = uvalue;
1503 break;
1504
1505 case DW_AT_ranges:
1506 if (form == DW_FORM_data4
1507 || form == DW_FORM_data8
1508 || form == DW_FORM_sec_offset)
1509 {
1510 /* Process range list. */
1511 unsigned int lmax = debug_info_p->max_range_lists;
1512 unsigned int num = debug_info_p->num_range_lists;
1513
1514 if (lmax == 0 || num >= lmax)
1515 {
1516 lmax += 1024;
1517 debug_info_p->range_lists = (dwarf_vma *)
1518 xcrealloc (debug_info_p->range_lists,
1519 lmax, sizeof (*debug_info_p->range_lists));
1520 debug_info_p->max_range_lists = lmax;
1521 }
1522 debug_info_p->range_lists [num] = uvalue;
1523 debug_info_p->num_range_lists++;
1524 }
1525 break;
1526
1527 default:
1528 break;
1529 }
1530 }
1531
1532 if (do_loc)
1533 return data;
1534
1535 /* For some attributes we can display further information. */
1536 printf ("\t");
1537
1538 switch (attribute)
1539 {
1540 case DW_AT_inline:
1541 switch (uvalue)
1542 {
1543 case DW_INL_not_inlined:
1544 printf (_("(not inlined)"));
1545 break;
1546 case DW_INL_inlined:
1547 printf (_("(inlined)"));
1548 break;
1549 case DW_INL_declared_not_inlined:
1550 printf (_("(declared as inline but ignored)"));
1551 break;
1552 case DW_INL_declared_inlined:
1553 printf (_("(declared as inline and inlined)"));
1554 break;
1555 default:
1556 printf (_(" (Unknown inline attribute value: %s)"),
1557 dwarf_vmatoa ("x", uvalue));
1558 break;
1559 }
1560 break;
1561
1562 case DW_AT_language:
1563 switch (uvalue)
1564 {
1565 /* Ordered by the numeric value of these constants. */
1566 case DW_LANG_C89: printf ("(ANSI C)"); break;
1567 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1568 case DW_LANG_Ada83: printf ("(Ada)"); break;
1569 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1570 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1571 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1572 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1573 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1574 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1575 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1576 /* DWARF 2.1 values. */
1577 case DW_LANG_Java: printf ("(Java)"); break;
1578 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1579 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1580 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1581 /* DWARF 3 values. */
1582 case DW_LANG_PLI: printf ("(PLI)"); break;
1583 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1584 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1585 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1586 case DW_LANG_D: printf ("(D)"); break;
1587 /* DWARF 4 values. */
1588 case DW_LANG_Python: printf ("(Python)"); break;
1589 /* MIPS extension. */
1590 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1591 /* UPC extension. */
1592 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1593 default:
1594 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1595 printf ("(implementation defined: %s)",
1596 dwarf_vmatoa ("x", uvalue));
1597 else
1598 printf ("(Unknown: %s)", dwarf_vmatoa ("x", uvalue));
1599 break;
1600 }
1601 break;
1602
1603 case DW_AT_encoding:
1604 switch (uvalue)
1605 {
1606 case DW_ATE_void: printf ("(void)"); break;
1607 case DW_ATE_address: printf ("(machine address)"); break;
1608 case DW_ATE_boolean: printf ("(boolean)"); break;
1609 case DW_ATE_complex_float: printf ("(complex float)"); break;
1610 case DW_ATE_float: printf ("(float)"); break;
1611 case DW_ATE_signed: printf ("(signed)"); break;
1612 case DW_ATE_signed_char: printf ("(signed char)"); break;
1613 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1614 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1615 /* DWARF 2.1 values: */
1616 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1617 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1618 /* DWARF 3 values: */
1619 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1620 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1621 case DW_ATE_edited: printf ("(edited)"); break;
1622 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1623 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1624 /* HP extensions: */
1625 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1626 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1627 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1628 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1629 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1630 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1631 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1632
1633 default:
1634 if (uvalue >= DW_ATE_lo_user
1635 && uvalue <= DW_ATE_hi_user)
1636 printf ("(user defined type)");
1637 else
1638 printf ("(unknown type)");
1639 break;
1640 }
1641 break;
1642
1643 case DW_AT_accessibility:
1644 switch (uvalue)
1645 {
1646 case DW_ACCESS_public: printf ("(public)"); break;
1647 case DW_ACCESS_protected: printf ("(protected)"); break;
1648 case DW_ACCESS_private: printf ("(private)"); break;
1649 default:
1650 printf ("(unknown accessibility)");
1651 break;
1652 }
1653 break;
1654
1655 case DW_AT_visibility:
1656 switch (uvalue)
1657 {
1658 case DW_VIS_local: printf ("(local)"); break;
1659 case DW_VIS_exported: printf ("(exported)"); break;
1660 case DW_VIS_qualified: printf ("(qualified)"); break;
1661 default: printf ("(unknown visibility)"); break;
1662 }
1663 break;
1664
1665 case DW_AT_virtuality:
1666 switch (uvalue)
1667 {
1668 case DW_VIRTUALITY_none: printf ("(none)"); break;
1669 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1670 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1671 default: printf ("(unknown virtuality)"); break;
1672 }
1673 break;
1674
1675 case DW_AT_identifier_case:
1676 switch (uvalue)
1677 {
1678 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1679 case DW_ID_up_case: printf ("(up_case)"); break;
1680 case DW_ID_down_case: printf ("(down_case)"); break;
1681 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1682 default: printf ("(unknown case)"); break;
1683 }
1684 break;
1685
1686 case DW_AT_calling_convention:
1687 switch (uvalue)
1688 {
1689 case DW_CC_normal: printf ("(normal)"); break;
1690 case DW_CC_program: printf ("(program)"); break;
1691 case DW_CC_nocall: printf ("(nocall)"); break;
1692 default:
1693 if (uvalue >= DW_CC_lo_user
1694 && uvalue <= DW_CC_hi_user)
1695 printf ("(user defined)");
1696 else
1697 printf ("(unknown convention)");
1698 }
1699 break;
1700
1701 case DW_AT_ordering:
1702 switch (uvalue)
1703 {
1704 case -1: printf ("(undefined)"); break;
1705 case 0: printf ("(row major)"); break;
1706 case 1: printf ("(column major)"); break;
1707 }
1708 break;
1709
1710 case DW_AT_frame_base:
1711 have_frame_base = 1;
1712 case DW_AT_location:
1713 case DW_AT_string_length:
1714 case DW_AT_return_addr:
1715 case DW_AT_data_member_location:
1716 case DW_AT_vtable_elem_location:
1717 case DW_AT_segment:
1718 case DW_AT_static_link:
1719 case DW_AT_use_location:
1720 case DW_AT_GNU_call_site_value:
1721 case DW_AT_GNU_call_site_data_value:
1722 case DW_AT_GNU_call_site_target:
1723 case DW_AT_GNU_call_site_target_clobbered:
1724 if (form == DW_FORM_data4
1725 || form == DW_FORM_data8
1726 || form == DW_FORM_sec_offset)
1727 printf (_("(location list)"));
1728 /* Fall through. */
1729 case DW_AT_allocated:
1730 case DW_AT_associated:
1731 case DW_AT_data_location:
1732 case DW_AT_stride:
1733 case DW_AT_upper_bound:
1734 case DW_AT_lower_bound:
1735 if (block_start)
1736 {
1737 int need_frame_base;
1738
1739 printf ("(");
1740 need_frame_base = decode_location_expression (block_start,
1741 pointer_size,
1742 offset_size,
1743 dwarf_version,
1744 uvalue,
1745 cu_offset, section);
1746 printf (")");
1747 if (need_frame_base && !have_frame_base)
1748 printf (_(" [without DW_AT_frame_base]"));
1749 }
1750 break;
1751
1752 case DW_AT_import:
1753 {
1754 if (form == DW_FORM_ref_sig8)
1755 break;
1756
1757 if (form == DW_FORM_ref1
1758 || form == DW_FORM_ref2
1759 || form == DW_FORM_ref4)
1760 uvalue += cu_offset;
1761
1762 if (uvalue >= section->size)
1763 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1764 dwarf_vmatoa ("x", uvalue),
1765 (unsigned long) (orig_data - section->start));
1766 else
1767 {
1768 unsigned long abbrev_number;
1769 abbrev_entry * entry;
1770
1771 abbrev_number = read_leb128 (section->start + uvalue, NULL, 0);
1772
1773 printf ("[Abbrev Number: %ld", abbrev_number);
1774 for (entry = first_abbrev; entry != NULL; entry = entry->next)
1775 if (entry->entry == abbrev_number)
1776 break;
1777 if (entry != NULL)
1778 printf (" (%s)", get_TAG_name (entry->tag));
1779 printf ("]");
1780 }
1781 }
1782 break;
1783
1784 default:
1785 break;
1786 }
1787
1788 return data;
1789 }
1790
1791 static char *
1792 get_AT_name (unsigned long attribute)
1793 {
1794 switch (attribute)
1795 {
1796 case DW_AT_sibling: return "DW_AT_sibling";
1797 case DW_AT_location: return "DW_AT_location";
1798 case DW_AT_name: return "DW_AT_name";
1799 case DW_AT_ordering: return "DW_AT_ordering";
1800 case DW_AT_subscr_data: return "DW_AT_subscr_data";
1801 case DW_AT_byte_size: return "DW_AT_byte_size";
1802 case DW_AT_bit_offset: return "DW_AT_bit_offset";
1803 case DW_AT_bit_size: return "DW_AT_bit_size";
1804 case DW_AT_element_list: return "DW_AT_element_list";
1805 case DW_AT_stmt_list: return "DW_AT_stmt_list";
1806 case DW_AT_low_pc: return "DW_AT_low_pc";
1807 case DW_AT_high_pc: return "DW_AT_high_pc";
1808 case DW_AT_language: return "DW_AT_language";
1809 case DW_AT_member: return "DW_AT_member";
1810 case DW_AT_discr: return "DW_AT_discr";
1811 case DW_AT_discr_value: return "DW_AT_discr_value";
1812 case DW_AT_visibility: return "DW_AT_visibility";
1813 case DW_AT_import: return "DW_AT_import";
1814 case DW_AT_string_length: return "DW_AT_string_length";
1815 case DW_AT_common_reference: return "DW_AT_common_reference";
1816 case DW_AT_comp_dir: return "DW_AT_comp_dir";
1817 case DW_AT_const_value: return "DW_AT_const_value";
1818 case DW_AT_containing_type: return "DW_AT_containing_type";
1819 case DW_AT_default_value: return "DW_AT_default_value";
1820 case DW_AT_inline: return "DW_AT_inline";
1821 case DW_AT_is_optional: return "DW_AT_is_optional";
1822 case DW_AT_lower_bound: return "DW_AT_lower_bound";
1823 case DW_AT_producer: return "DW_AT_producer";
1824 case DW_AT_prototyped: return "DW_AT_prototyped";
1825 case DW_AT_return_addr: return "DW_AT_return_addr";
1826 case DW_AT_start_scope: return "DW_AT_start_scope";
1827 case DW_AT_stride_size: return "DW_AT_stride_size";
1828 case DW_AT_upper_bound: return "DW_AT_upper_bound";
1829 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
1830 case DW_AT_accessibility: return "DW_AT_accessibility";
1831 case DW_AT_address_class: return "DW_AT_address_class";
1832 case DW_AT_artificial: return "DW_AT_artificial";
1833 case DW_AT_base_types: return "DW_AT_base_types";
1834 case DW_AT_calling_convention: return "DW_AT_calling_convention";
1835 case DW_AT_count: return "DW_AT_count";
1836 case DW_AT_data_member_location: return "DW_AT_data_member_location";
1837 case DW_AT_decl_column: return "DW_AT_decl_column";
1838 case DW_AT_decl_file: return "DW_AT_decl_file";
1839 case DW_AT_decl_line: return "DW_AT_decl_line";
1840 case DW_AT_declaration: return "DW_AT_declaration";
1841 case DW_AT_discr_list: return "DW_AT_discr_list";
1842 case DW_AT_encoding: return "DW_AT_encoding";
1843 case DW_AT_external: return "DW_AT_external";
1844 case DW_AT_frame_base: return "DW_AT_frame_base";
1845 case DW_AT_friend: return "DW_AT_friend";
1846 case DW_AT_identifier_case: return "DW_AT_identifier_case";
1847 case DW_AT_macro_info: return "DW_AT_macro_info";
1848 case DW_AT_namelist_items: return "DW_AT_namelist_items";
1849 case DW_AT_priority: return "DW_AT_priority";
1850 case DW_AT_segment: return "DW_AT_segment";
1851 case DW_AT_specification: return "DW_AT_specification";
1852 case DW_AT_static_link: return "DW_AT_static_link";
1853 case DW_AT_type: return "DW_AT_type";
1854 case DW_AT_use_location: return "DW_AT_use_location";
1855 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
1856 case DW_AT_virtuality: return "DW_AT_virtuality";
1857 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
1858 /* DWARF 2.1 values. */
1859 case DW_AT_allocated: return "DW_AT_allocated";
1860 case DW_AT_associated: return "DW_AT_associated";
1861 case DW_AT_data_location: return "DW_AT_data_location";
1862 case DW_AT_stride: return "DW_AT_stride";
1863 case DW_AT_entry_pc: return "DW_AT_entry_pc";
1864 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
1865 case DW_AT_extension: return "DW_AT_extension";
1866 case DW_AT_ranges: return "DW_AT_ranges";
1867 case DW_AT_trampoline: return "DW_AT_trampoline";
1868 case DW_AT_call_column: return "DW_AT_call_column";
1869 case DW_AT_call_file: return "DW_AT_call_file";
1870 case DW_AT_call_line: return "DW_AT_call_line";
1871 case DW_AT_description: return "DW_AT_description";
1872 case DW_AT_binary_scale: return "DW_AT_binary_scale";
1873 case DW_AT_decimal_scale: return "DW_AT_decimal_scale";
1874 case DW_AT_small: return "DW_AT_small";
1875 case DW_AT_decimal_sign: return "DW_AT_decimal_sign";
1876 case DW_AT_digit_count: return "DW_AT_digit_count";
1877 case DW_AT_picture_string: return "DW_AT_picture_string";
1878 case DW_AT_mutable: return "DW_AT_mutable";
1879 case DW_AT_threads_scaled: return "DW_AT_threads_scaled";
1880 case DW_AT_explicit: return "DW_AT_explicit";
1881 case DW_AT_object_pointer: return "DW_AT_object_pointer";
1882 case DW_AT_endianity: return "DW_AT_endianity";
1883 case DW_AT_elemental: return "DW_AT_elemental";
1884 case DW_AT_pure: return "DW_AT_pure";
1885 case DW_AT_recursive: return "DW_AT_recursive";
1886 /* DWARF 4 values. */
1887 case DW_AT_signature: return "DW_AT_signature";
1888 case DW_AT_main_subprogram: return "DW_AT_main_subprogram";
1889 case DW_AT_data_bit_offset: return "DW_AT_data_bit_offset";
1890 case DW_AT_const_expr: return "DW_AT_const_expr";
1891 case DW_AT_enum_class: return "DW_AT_enum_class";
1892 case DW_AT_linkage_name: return "DW_AT_linkage_name";
1893
1894 /* HP and SGI/MIPS extensions. */
1895 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
1896 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
1897 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
1898 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
1899 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
1900 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
1901 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
1902 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
1903 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
1904 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
1905
1906 /* HP Extensions. */
1907 case DW_AT_HP_block_index: return "DW_AT_HP_block_index";
1908 case DW_AT_HP_actuals_stmt_list: return "DW_AT_HP_actuals_stmt_list";
1909 case DW_AT_HP_proc_per_section: return "DW_AT_HP_proc_per_section";
1910 case DW_AT_HP_raw_data_ptr: return "DW_AT_HP_raw_data_ptr";
1911 case DW_AT_HP_pass_by_reference: return "DW_AT_HP_pass_by_reference";
1912 case DW_AT_HP_opt_level: return "DW_AT_HP_opt_level";
1913 case DW_AT_HP_prof_version_id: return "DW_AT_HP_prof_version_id";
1914 case DW_AT_HP_opt_flags: return "DW_AT_HP_opt_flags";
1915 case DW_AT_HP_cold_region_low_pc: return "DW_AT_HP_cold_region_low_pc";
1916 case DW_AT_HP_cold_region_high_pc: return "DW_AT_HP_cold_region_high_pc";
1917 case DW_AT_HP_all_variables_modifiable: return "DW_AT_HP_all_variables_modifiable";
1918 case DW_AT_HP_linkage_name: return "DW_AT_HP_linkage_name";
1919 case DW_AT_HP_prof_flags: return "DW_AT_HP_prof_flags";
1920
1921 /* One value is shared by the MIPS and HP extensions: */
1922 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1923
1924 /* GNU extensions. */
1925 case DW_AT_sf_names: return "DW_AT_sf_names";
1926 case DW_AT_src_info: return "DW_AT_src_info";
1927 case DW_AT_mac_info: return "DW_AT_mac_info";
1928 case DW_AT_src_coords: return "DW_AT_src_coords";
1929 case DW_AT_body_begin: return "DW_AT_body_begin";
1930 case DW_AT_body_end: return "DW_AT_body_end";
1931 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
1932 case DW_AT_GNU_guarded_by: return "DW_AT_GNU_guarded_by";
1933 case DW_AT_GNU_pt_guarded_by: return "DW_AT_GNU_pt_guarded_by";
1934 case DW_AT_GNU_guarded: return "DW_AT_GNU_guarded";
1935 case DW_AT_GNU_pt_guarded: return "DW_AT_GNU_pt_guarded";
1936 case DW_AT_GNU_locks_excluded: return "DW_AT_GNU_locks_excluded";
1937 case DW_AT_GNU_exclusive_locks_required: return "DW_AT_GNU_exclusive_locks_required";
1938 case DW_AT_GNU_shared_locks_required: return "DW_AT_GNU_shared_locks_required";
1939 case DW_AT_GNU_odr_signature: return "DW_AT_GNU_odr_signature";
1940 case DW_AT_use_GNAT_descriptive_type: return "DW_AT_use_GNAT_descriptive_type";
1941 case DW_AT_GNAT_descriptive_type: return "DW_AT_GNAT_descriptive_type";
1942 case DW_AT_GNU_call_site_value: return "DW_AT_GNU_call_site_value";
1943 case DW_AT_GNU_call_site_data_value: return "DW_AT_GNU_call_site_data_value";
1944 case DW_AT_GNU_call_site_target: return "DW_AT_GNU_call_site_target";
1945 case DW_AT_GNU_call_site_target_clobbered: return "DW_AT_GNU_call_site_target_clobbered";
1946 case DW_AT_GNU_tail_call: return "DW_AT_GNU_tail_call";
1947 case DW_AT_GNU_all_tail_call_sites: return "DW_AT_GNU_all_tail_call_sites";
1948 case DW_AT_GNU_all_call_sites: return "DW_AT_GNU_all_call_sites";
1949 case DW_AT_GNU_all_source_call_sites: return "DW_AT_GNU_all_source_call_sites";
1950
1951 /* UPC extension. */
1952 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
1953
1954 /* PGI (STMicroelectronics) extensions. */
1955 case DW_AT_PGI_lbase: return "DW_AT_PGI_lbase";
1956 case DW_AT_PGI_soffset: return "DW_AT_PGI_soffset";
1957 case DW_AT_PGI_lstride: return "DW_AT_PGI_lstride";
1958
1959 default:
1960 {
1961 static char buffer[100];
1962
1963 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1964 attribute);
1965 return buffer;
1966 }
1967 }
1968 }
1969
1970 static unsigned char *
1971 read_and_display_attr (unsigned long attribute,
1972 unsigned long form,
1973 unsigned char * data,
1974 dwarf_vma cu_offset,
1975 dwarf_vma pointer_size,
1976 dwarf_vma offset_size,
1977 int dwarf_version,
1978 debug_info * debug_info_p,
1979 int do_loc,
1980 struct dwarf_section * section)
1981 {
1982 if (!do_loc)
1983 printf (" %-18s:", get_AT_name (attribute));
1984 data = read_and_display_attr_value (attribute, form, data, cu_offset,
1985 pointer_size, offset_size,
1986 dwarf_version, debug_info_p,
1987 do_loc, section);
1988 if (!do_loc)
1989 printf ("\n");
1990 return data;
1991 }
1992
1993
1994 /* Process the contents of a .debug_info section. If do_loc is non-zero
1995 then we are scanning for location lists and we do not want to display
1996 anything to the user. If do_types is non-zero, we are processing
1997 a .debug_types section instead of a .debug_info section. */
1998
1999 static int
2000 process_debug_info (struct dwarf_section *section,
2001 void *file,
2002 enum dwarf_section_display_enum abbrev_sec,
2003 int do_loc,
2004 int do_types)
2005 {
2006 unsigned char *start = section->start;
2007 unsigned char *end = start + section->size;
2008 unsigned char *section_begin;
2009 unsigned int unit;
2010 unsigned int num_units = 0;
2011
2012 if ((do_loc || do_debug_loc || do_debug_ranges)
2013 && num_debug_info_entries == 0
2014 && ! do_types)
2015 {
2016 dwarf_vma length;
2017
2018 /* First scan the section to get the number of comp units. */
2019 for (section_begin = start, num_units = 0; section_begin < end;
2020 num_units ++)
2021 {
2022 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2023 will be the length. For a 64-bit DWARF section, it'll be
2024 the escape code 0xffffffff followed by an 8 byte length. */
2025 length = byte_get (section_begin, 4);
2026
2027 if (length == 0xffffffff)
2028 {
2029 length = byte_get (section_begin + 4, 8);
2030 section_begin += length + 12;
2031 }
2032 else if (length >= 0xfffffff0 && length < 0xffffffff)
2033 {
2034 warn (_("Reserved length value (0x%s) found in section %s\n"),
2035 dwarf_vmatoa ("x", length), section->name);
2036 return 0;
2037 }
2038 else
2039 section_begin += length + 4;
2040
2041 /* Negative values are illegal, they may even cause infinite
2042 looping. This can happen if we can't accurately apply
2043 relocations to an object file. */
2044 if ((signed long) length <= 0)
2045 {
2046 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2047 dwarf_vmatoa ("x", length), section->name);
2048 return 0;
2049 }
2050 }
2051
2052 if (num_units == 0)
2053 {
2054 error (_("No comp units in %s section ?"), section->name);
2055 return 0;
2056 }
2057
2058 /* Then allocate an array to hold the information. */
2059 debug_information = (debug_info *) cmalloc (num_units,
2060 sizeof (* debug_information));
2061 if (debug_information == NULL)
2062 {
2063 error (_("Not enough memory for a debug info array of %u entries"),
2064 num_units);
2065 return 0;
2066 }
2067 }
2068
2069 if (!do_loc)
2070 {
2071 if (dwarf_start_die == 0)
2072 printf (_("Contents of the %s section:\n\n"), section->name);
2073
2074 load_debug_section (str, file);
2075 }
2076
2077 load_debug_section (abbrev_sec, file);
2078 if (debug_displays [abbrev_sec].section.start == NULL)
2079 {
2080 warn (_("Unable to locate %s section!\n"),
2081 debug_displays [abbrev_sec].section.name);
2082 return 0;
2083 }
2084
2085 for (section_begin = start, unit = 0; start < end; unit++)
2086 {
2087 DWARF2_Internal_CompUnit compunit;
2088 unsigned char *hdrptr;
2089 unsigned char *tags;
2090 int level, last_level, saved_level;
2091 dwarf_vma cu_offset;
2092 int offset_size;
2093 int initial_length_size;
2094 unsigned char signature[8] = { 0 };
2095 dwarf_vma type_offset = 0;
2096
2097 hdrptr = start;
2098
2099 compunit.cu_length = byte_get (hdrptr, 4);
2100 hdrptr += 4;
2101
2102 if (compunit.cu_length == 0xffffffff)
2103 {
2104 compunit.cu_length = byte_get (hdrptr, 8);
2105 hdrptr += 8;
2106 offset_size = 8;
2107 initial_length_size = 12;
2108 }
2109 else
2110 {
2111 offset_size = 4;
2112 initial_length_size = 4;
2113 }
2114
2115 compunit.cu_version = byte_get (hdrptr, 2);
2116 hdrptr += 2;
2117
2118 cu_offset = start - section_begin;
2119
2120 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
2121 hdrptr += offset_size;
2122
2123 compunit.cu_pointer_size = byte_get (hdrptr, 1);
2124 hdrptr += 1;
2125
2126 if (do_types)
2127 {
2128 int i;
2129
2130 for (i = 0; i < 8; i++)
2131 {
2132 signature[i] = byte_get (hdrptr, 1);
2133 hdrptr += 1;
2134 }
2135
2136 type_offset = byte_get (hdrptr, offset_size);
2137 hdrptr += offset_size;
2138 }
2139
2140 if ((do_loc || do_debug_loc || do_debug_ranges)
2141 && num_debug_info_entries == 0
2142 && ! do_types)
2143 {
2144 debug_information [unit].cu_offset = cu_offset;
2145 debug_information [unit].pointer_size
2146 = compunit.cu_pointer_size;
2147 debug_information [unit].offset_size = offset_size;
2148 debug_information [unit].dwarf_version = compunit.cu_version;
2149 debug_information [unit].base_address = 0;
2150 debug_information [unit].loc_offsets = NULL;
2151 debug_information [unit].have_frame_base = NULL;
2152 debug_information [unit].max_loc_offsets = 0;
2153 debug_information [unit].num_loc_offsets = 0;
2154 debug_information [unit].range_lists = NULL;
2155 debug_information [unit].max_range_lists= 0;
2156 debug_information [unit].num_range_lists = 0;
2157 }
2158
2159 if (!do_loc && dwarf_start_die == 0)
2160 {
2161 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2162 dwarf_vmatoa ("x", cu_offset));
2163 printf (_(" Length: 0x%s (%s)\n"),
2164 dwarf_vmatoa ("x", compunit.cu_length),
2165 offset_size == 8 ? "64-bit" : "32-bit");
2166 printf (_(" Version: %d\n"), compunit.cu_version);
2167 printf (_(" Abbrev Offset: %s\n"),
2168 dwarf_vmatoa ("d", compunit.cu_abbrev_offset));
2169 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2170 if (do_types)
2171 {
2172 int i;
2173 printf (_(" Signature: "));
2174 for (i = 0; i < 8; i++)
2175 printf ("%02x", signature[i]);
2176 printf ("\n");
2177 printf (_(" Type Offset: 0x%s\n"),
2178 dwarf_vmatoa ("x", type_offset));
2179 }
2180 }
2181
2182 if (cu_offset + compunit.cu_length + initial_length_size
2183 > section->size)
2184 {
2185 warn (_("Debug info is corrupted, length of CU at %s"
2186 " extends beyond end of section (length = %s)\n"),
2187 dwarf_vmatoa ("x", cu_offset),
2188 dwarf_vmatoa ("x", compunit.cu_length));
2189 break;
2190 }
2191 tags = hdrptr;
2192 start += compunit.cu_length + initial_length_size;
2193
2194 if (compunit.cu_version != 2
2195 && compunit.cu_version != 3
2196 && compunit.cu_version != 4)
2197 {
2198 warn (_("CU at offset %s contains corrupt or "
2199 "unsupported version number: %d.\n"),
2200 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2201 continue;
2202 }
2203
2204 free_abbrevs ();
2205
2206 /* Process the abbrevs used by this compilation unit. DWARF
2207 sections under Mach-O have non-zero addresses. */
2208 if (compunit.cu_abbrev_offset >= debug_displays [abbrev_sec].section.size)
2209 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2210 (unsigned long) compunit.cu_abbrev_offset,
2211 (unsigned long) debug_displays [abbrev_sec].section.size);
2212 else
2213 process_abbrev_section
2214 ((unsigned char *) debug_displays [abbrev_sec].section.start
2215 + compunit.cu_abbrev_offset,
2216 (unsigned char *) debug_displays [abbrev_sec].section.start
2217 + debug_displays [abbrev_sec].section.size);
2218
2219 level = 0;
2220 last_level = level;
2221 saved_level = -1;
2222 while (tags < start)
2223 {
2224 unsigned int bytes_read;
2225 unsigned long abbrev_number;
2226 unsigned long die_offset;
2227 abbrev_entry *entry;
2228 abbrev_attr *attr;
2229 int do_printing = 1;
2230
2231 die_offset = tags - section_begin;
2232
2233 abbrev_number = read_leb128 (tags, & bytes_read, 0);
2234 tags += bytes_read;
2235
2236 /* A null DIE marks the end of a list of siblings or it may also be
2237 a section padding. */
2238 if (abbrev_number == 0)
2239 {
2240 /* Check if it can be a section padding for the last CU. */
2241 if (level == 0 && start == end)
2242 {
2243 unsigned char *chk;
2244
2245 for (chk = tags; chk < start; chk++)
2246 if (*chk != 0)
2247 break;
2248 if (chk == start)
2249 break;
2250 }
2251
2252 --level;
2253 if (level < 0)
2254 {
2255 static unsigned num_bogus_warns = 0;
2256
2257 if (num_bogus_warns < 3)
2258 {
2259 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2260 die_offset);
2261 num_bogus_warns ++;
2262 if (num_bogus_warns == 3)
2263 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2264 }
2265 }
2266 if (dwarf_start_die != 0 && level < saved_level)
2267 return 1;
2268 continue;
2269 }
2270
2271 if (!do_loc)
2272 {
2273 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2274 do_printing = 0;
2275 else
2276 {
2277 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2278 saved_level = level;
2279 do_printing = (dwarf_cutoff_level == -1
2280 || level < dwarf_cutoff_level);
2281 if (do_printing)
2282 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2283 level, die_offset, abbrev_number);
2284 else if (dwarf_cutoff_level == -1
2285 || last_level < dwarf_cutoff_level)
2286 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2287 last_level = level;
2288 }
2289 }
2290
2291 /* Scan through the abbreviation list until we reach the
2292 correct entry. */
2293 for (entry = first_abbrev;
2294 entry && entry->entry != abbrev_number;
2295 entry = entry->next)
2296 continue;
2297
2298 if (entry == NULL)
2299 {
2300 if (!do_loc && do_printing)
2301 {
2302 printf ("\n");
2303 fflush (stdout);
2304 }
2305 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2306 die_offset, abbrev_number);
2307 return 0;
2308 }
2309
2310 if (!do_loc && do_printing)
2311 printf (" (%s)\n", get_TAG_name (entry->tag));
2312
2313 switch (entry->tag)
2314 {
2315 default:
2316 need_base_address = 0;
2317 break;
2318 case DW_TAG_compile_unit:
2319 need_base_address = 1;
2320 break;
2321 case DW_TAG_entry_point:
2322 case DW_TAG_subprogram:
2323 need_base_address = 0;
2324 /* Assuming that there is no DW_AT_frame_base. */
2325 have_frame_base = 0;
2326 break;
2327 }
2328
2329 for (attr = entry->first_attr; attr; attr = attr->next)
2330 {
2331 debug_info *arg;
2332
2333 if (! do_loc && do_printing)
2334 /* Show the offset from where the tag was extracted. */
2335 printf (" <%lx>", (unsigned long)(tags - section_begin));
2336
2337 arg = debug_information;
2338 if (debug_information)
2339 arg += unit;
2340
2341 tags = read_and_display_attr (attr->attribute,
2342 attr->form,
2343 tags, cu_offset,
2344 compunit.cu_pointer_size,
2345 offset_size,
2346 compunit.cu_version,
2347 arg,
2348 do_loc || ! do_printing, section);
2349 }
2350
2351 if (entry->children)
2352 ++level;
2353 }
2354 }
2355
2356 /* Set num_debug_info_entries here so that it can be used to check if
2357 we need to process .debug_loc and .debug_ranges sections. */
2358 if ((do_loc || do_debug_loc || do_debug_ranges)
2359 && num_debug_info_entries == 0
2360 && ! do_types)
2361 num_debug_info_entries = num_units;
2362
2363 if (!do_loc)
2364 printf ("\n");
2365
2366 return 1;
2367 }
2368
2369 /* Locate and scan the .debug_info section in the file and record the pointer
2370 sizes and offsets for the compilation units in it. Usually an executable
2371 will have just one pointer size, but this is not guaranteed, and so we try
2372 not to make any assumptions. Returns zero upon failure, or the number of
2373 compilation units upon success. */
2374
2375 static unsigned int
2376 load_debug_info (void * file)
2377 {
2378 /* Reset the last pointer size so that we can issue correct error
2379 messages if we are displaying the contents of more than one section. */
2380 last_pointer_size = 0;
2381 warned_about_missing_comp_units = FALSE;
2382
2383 /* If we have already tried and failed to load the .debug_info
2384 section then do not bother to repear the task. */
2385 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2386 return 0;
2387
2388 /* If we already have the information there is nothing else to do. */
2389 if (num_debug_info_entries > 0)
2390 return num_debug_info_entries;
2391
2392 if (load_debug_section (info, file)
2393 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2394 return num_debug_info_entries;
2395
2396 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2397 return 0;
2398 }
2399
2400 static int
2401 display_debug_lines_raw (struct dwarf_section *section,
2402 unsigned char *data,
2403 unsigned char *end)
2404 {
2405 unsigned char *start = section->start;
2406
2407 printf (_("Raw dump of debug contents of section %s:\n\n"),
2408 section->name);
2409
2410 while (data < end)
2411 {
2412 DWARF2_Internal_LineInfo linfo;
2413 unsigned char *standard_opcodes;
2414 unsigned char *end_of_sequence;
2415 unsigned char *hdrptr;
2416 unsigned long hdroff;
2417 int initial_length_size;
2418 int offset_size;
2419 int i;
2420
2421 hdrptr = data;
2422 hdroff = hdrptr - start;
2423
2424 /* Check the length of the block. */
2425 linfo.li_length = byte_get (hdrptr, 4);
2426 hdrptr += 4;
2427
2428 if (linfo.li_length == 0xffffffff)
2429 {
2430 /* This section is 64-bit DWARF 3. */
2431 linfo.li_length = byte_get (hdrptr, 8);
2432 hdrptr += 8;
2433 offset_size = 8;
2434 initial_length_size = 12;
2435 }
2436 else
2437 {
2438 offset_size = 4;
2439 initial_length_size = 4;
2440 }
2441
2442 if (linfo.li_length + initial_length_size > section->size)
2443 {
2444 warn
2445 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2446 section->name);
2447 return 0;
2448 }
2449
2450 /* Check its version number. */
2451 linfo.li_version = byte_get (hdrptr, 2);
2452 hdrptr += 2;
2453 if (linfo.li_version != 2
2454 && linfo.li_version != 3
2455 && linfo.li_version != 4)
2456 {
2457 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2458 return 0;
2459 }
2460
2461 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2462 hdrptr += offset_size;
2463 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2464 hdrptr++;
2465 if (linfo.li_version >= 4)
2466 {
2467 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2468 hdrptr++;
2469 if (linfo.li_max_ops_per_insn == 0)
2470 {
2471 warn (_("Invalid maximum operations per insn.\n"));
2472 return 0;
2473 }
2474 }
2475 else
2476 linfo.li_max_ops_per_insn = 1;
2477 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2478 hdrptr++;
2479 linfo.li_line_base = byte_get (hdrptr, 1);
2480 hdrptr++;
2481 linfo.li_line_range = byte_get (hdrptr, 1);
2482 hdrptr++;
2483 linfo.li_opcode_base = byte_get (hdrptr, 1);
2484 hdrptr++;
2485
2486 /* Sign extend the line base field. */
2487 linfo.li_line_base <<= 24;
2488 linfo.li_line_base >>= 24;
2489
2490 printf (_(" Offset: 0x%lx\n"), hdroff);
2491 printf (_(" Length: %ld\n"), (long) linfo.li_length);
2492 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2493 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2494 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2495 if (linfo.li_version >= 4)
2496 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2497 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2498 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2499 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2500 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2501
2502 end_of_sequence = data + linfo.li_length + initial_length_size;
2503
2504 reset_state_machine (linfo.li_default_is_stmt);
2505
2506 /* Display the contents of the Opcodes table. */
2507 standard_opcodes = hdrptr;
2508
2509 printf (_("\n Opcodes:\n"));
2510
2511 for (i = 1; i < linfo.li_opcode_base; i++)
2512 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2513
2514 /* Display the contents of the Directory table. */
2515 data = standard_opcodes + linfo.li_opcode_base - 1;
2516
2517 if (*data == 0)
2518 printf (_("\n The Directory Table is empty.\n"));
2519 else
2520 {
2521 printf (_("\n The Directory Table:\n"));
2522
2523 while (*data != 0)
2524 {
2525 printf (" %s\n", data);
2526
2527 data += strlen ((char *) data) + 1;
2528 }
2529 }
2530
2531 /* Skip the NUL at the end of the table. */
2532 data++;
2533
2534 /* Display the contents of the File Name table. */
2535 if (*data == 0)
2536 printf (_("\n The File Name Table is empty.\n"));
2537 else
2538 {
2539 printf (_("\n The File Name Table:\n"));
2540 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2541
2542 while (*data != 0)
2543 {
2544 unsigned char *name;
2545 unsigned int bytes_read;
2546
2547 printf (" %d\t", ++state_machine_regs.last_file_entry);
2548 name = data;
2549
2550 data += strlen ((char *) data) + 1;
2551
2552 printf ("%s\t",
2553 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2554 data += bytes_read;
2555 printf ("%s\t",
2556 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2557 data += bytes_read;
2558 printf ("%s\t",
2559 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2560 data += bytes_read;
2561 printf ("%s\n", name);
2562 }
2563 }
2564
2565 /* Skip the NUL at the end of the table. */
2566 data++;
2567
2568 /* Now display the statements. */
2569 printf (_("\n Line Number Statements:\n"));
2570
2571 while (data < end_of_sequence)
2572 {
2573 unsigned char op_code;
2574 dwarf_signed_vma adv;
2575 dwarf_vma uladv;
2576 unsigned int bytes_read;
2577
2578 op_code = *data++;
2579
2580 if (op_code >= linfo.li_opcode_base)
2581 {
2582 op_code -= linfo.li_opcode_base;
2583 uladv = (op_code / linfo.li_line_range);
2584 if (linfo.li_max_ops_per_insn == 1)
2585 {
2586 uladv *= linfo.li_min_insn_length;
2587 state_machine_regs.address += uladv;
2588 printf (_(" Special opcode %d: "
2589 "advance Address by %s to 0x%s"),
2590 op_code, dwarf_vmatoa ("u", uladv),
2591 dwarf_vmatoa ("x", state_machine_regs.address));
2592 }
2593 else
2594 {
2595 state_machine_regs.address
2596 += ((state_machine_regs.op_index + uladv)
2597 / linfo.li_max_ops_per_insn)
2598 * linfo.li_min_insn_length;
2599 state_machine_regs.op_index
2600 = (state_machine_regs.op_index + uladv)
2601 % linfo.li_max_ops_per_insn;
2602 printf (_(" Special opcode %d: "
2603 "advance Address by %s to 0x%s[%d]"),
2604 op_code, dwarf_vmatoa ("u", uladv),
2605 dwarf_vmatoa ("x", state_machine_regs.address),
2606 state_machine_regs.op_index);
2607 }
2608 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2609 state_machine_regs.line += adv;
2610 printf (_(" and Line by %s to %d\n"),
2611 dwarf_vmatoa ("d", adv), state_machine_regs.line);
2612 }
2613 else switch (op_code)
2614 {
2615 case DW_LNS_extended_op:
2616 data += process_extended_line_op (data, linfo.li_default_is_stmt);
2617 break;
2618
2619 case DW_LNS_copy:
2620 printf (_(" Copy\n"));
2621 break;
2622
2623 case DW_LNS_advance_pc:
2624 uladv = read_leb128 (data, & bytes_read, 0);
2625 data += bytes_read;
2626 if (linfo.li_max_ops_per_insn == 1)
2627 {
2628 uladv *= linfo.li_min_insn_length;
2629 state_machine_regs.address += uladv;
2630 printf (_(" Advance PC by %s to 0x%s\n"),
2631 dwarf_vmatoa ("u", uladv),
2632 dwarf_vmatoa ("x", state_machine_regs.address));
2633 }
2634 else
2635 {
2636 state_machine_regs.address
2637 += ((state_machine_regs.op_index + uladv)
2638 / linfo.li_max_ops_per_insn)
2639 * linfo.li_min_insn_length;
2640 state_machine_regs.op_index
2641 = (state_machine_regs.op_index + uladv)
2642 % linfo.li_max_ops_per_insn;
2643 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2644 dwarf_vmatoa ("u", uladv),
2645 dwarf_vmatoa ("x", state_machine_regs.address),
2646 state_machine_regs.op_index);
2647 }
2648 break;
2649
2650 case DW_LNS_advance_line:
2651 adv = read_sleb128 (data, & bytes_read);
2652 data += bytes_read;
2653 state_machine_regs.line += adv;
2654 printf (_(" Advance Line by %s to %d\n"),
2655 dwarf_vmatoa ("d", adv),
2656 state_machine_regs.line);
2657 break;
2658
2659 case DW_LNS_set_file:
2660 adv = read_leb128 (data, & bytes_read, 0);
2661 data += bytes_read;
2662 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2663 dwarf_vmatoa ("d", adv));
2664 state_machine_regs.file = adv;
2665 break;
2666
2667 case DW_LNS_set_column:
2668 uladv = read_leb128 (data, & bytes_read, 0);
2669 data += bytes_read;
2670 printf (_(" Set column to %s\n"),
2671 dwarf_vmatoa ("u", uladv));
2672 state_machine_regs.column = uladv;
2673 break;
2674
2675 case DW_LNS_negate_stmt:
2676 adv = state_machine_regs.is_stmt;
2677 adv = ! adv;
2678 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
2679 state_machine_regs.is_stmt = adv;
2680 break;
2681
2682 case DW_LNS_set_basic_block:
2683 printf (_(" Set basic block\n"));
2684 state_machine_regs.basic_block = 1;
2685 break;
2686
2687 case DW_LNS_const_add_pc:
2688 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2689 if (linfo.li_max_ops_per_insn)
2690 {
2691 uladv *= linfo.li_min_insn_length;
2692 state_machine_regs.address += uladv;
2693 printf (_(" Advance PC by constant %s to 0x%s\n"),
2694 dwarf_vmatoa ("u", uladv),
2695 dwarf_vmatoa ("x", state_machine_regs.address));
2696 }
2697 else
2698 {
2699 state_machine_regs.address
2700 += ((state_machine_regs.op_index + uladv)
2701 / linfo.li_max_ops_per_insn)
2702 * linfo.li_min_insn_length;
2703 state_machine_regs.op_index
2704 = (state_machine_regs.op_index + uladv)
2705 % linfo.li_max_ops_per_insn;
2706 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2707 dwarf_vmatoa ("u", uladv),
2708 dwarf_vmatoa ("x", state_machine_regs.address),
2709 state_machine_regs.op_index);
2710 }
2711 break;
2712
2713 case DW_LNS_fixed_advance_pc:
2714 uladv = byte_get (data, 2);
2715 data += 2;
2716 state_machine_regs.address += uladv;
2717 state_machine_regs.op_index = 0;
2718 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2719 dwarf_vmatoa ("u", uladv),
2720 dwarf_vmatoa ("x", state_machine_regs.address));
2721 break;
2722
2723 case DW_LNS_set_prologue_end:
2724 printf (_(" Set prologue_end to true\n"));
2725 break;
2726
2727 case DW_LNS_set_epilogue_begin:
2728 printf (_(" Set epilogue_begin to true\n"));
2729 break;
2730
2731 case DW_LNS_set_isa:
2732 uladv = read_leb128 (data, & bytes_read, 0);
2733 data += bytes_read;
2734 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
2735 break;
2736
2737 default:
2738 printf (_(" Unknown opcode %d with operands: "), op_code);
2739
2740 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2741 {
2742 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
2743 &bytes_read, 0)),
2744 i == 1 ? "" : ", ");
2745 data += bytes_read;
2746 }
2747 putchar ('\n');
2748 break;
2749 }
2750 }
2751 putchar ('\n');
2752 }
2753
2754 return 1;
2755 }
2756
2757 typedef struct
2758 {
2759 unsigned char *name;
2760 unsigned int directory_index;
2761 unsigned int modification_date;
2762 unsigned int length;
2763 } File_Entry;
2764
2765 /* Output a decoded representation of the .debug_line section. */
2766
2767 static int
2768 display_debug_lines_decoded (struct dwarf_section *section,
2769 unsigned char *data,
2770 unsigned char *end)
2771 {
2772 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2773 section->name);
2774
2775 while (data < end)
2776 {
2777 /* This loop amounts to one iteration per compilation unit. */
2778 DWARF2_Internal_LineInfo linfo;
2779 unsigned char *standard_opcodes;
2780 unsigned char *end_of_sequence;
2781 unsigned char *hdrptr;
2782 int initial_length_size;
2783 int offset_size;
2784 int i;
2785 File_Entry *file_table = NULL;
2786 unsigned char **directory_table = NULL;
2787
2788 hdrptr = data;
2789
2790 /* Extract information from the Line Number Program Header.
2791 (section 6.2.4 in the Dwarf3 doc). */
2792
2793 /* Get the length of this CU's line number information block. */
2794 linfo.li_length = byte_get (hdrptr, 4);
2795 hdrptr += 4;
2796
2797 if (linfo.li_length == 0xffffffff)
2798 {
2799 /* This section is 64-bit DWARF 3. */
2800 linfo.li_length = byte_get (hdrptr, 8);
2801 hdrptr += 8;
2802 offset_size = 8;
2803 initial_length_size = 12;
2804 }
2805 else
2806 {
2807 offset_size = 4;
2808 initial_length_size = 4;
2809 }
2810
2811 if (linfo.li_length + initial_length_size > section->size)
2812 {
2813 warn (_("The line info appears to be corrupt - "
2814 "the section is too small\n"));
2815 return 0;
2816 }
2817
2818 /* Get this CU's Line Number Block version number. */
2819 linfo.li_version = byte_get (hdrptr, 2);
2820 hdrptr += 2;
2821 if (linfo.li_version != 2
2822 && linfo.li_version != 3
2823 && linfo.li_version != 4)
2824 {
2825 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2826 "supported.\n"));
2827 return 0;
2828 }
2829
2830 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2831 hdrptr += offset_size;
2832 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2833 hdrptr++;
2834 if (linfo.li_version >= 4)
2835 {
2836 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2837 hdrptr++;
2838 if (linfo.li_max_ops_per_insn == 0)
2839 {
2840 warn (_("Invalid maximum operations per insn.\n"));
2841 return 0;
2842 }
2843 }
2844 else
2845 linfo.li_max_ops_per_insn = 1;
2846 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2847 hdrptr++;
2848 linfo.li_line_base = byte_get (hdrptr, 1);
2849 hdrptr++;
2850 linfo.li_line_range = byte_get (hdrptr, 1);
2851 hdrptr++;
2852 linfo.li_opcode_base = byte_get (hdrptr, 1);
2853 hdrptr++;
2854
2855 /* Sign extend the line base field. */
2856 linfo.li_line_base <<= 24;
2857 linfo.li_line_base >>= 24;
2858
2859 /* Find the end of this CU's Line Number Information Block. */
2860 end_of_sequence = data + linfo.li_length + initial_length_size;
2861
2862 reset_state_machine (linfo.li_default_is_stmt);
2863
2864 /* Save a pointer to the contents of the Opcodes table. */
2865 standard_opcodes = hdrptr;
2866
2867 /* Traverse the Directory table just to count entries. */
2868 data = standard_opcodes + linfo.li_opcode_base - 1;
2869 if (*data != 0)
2870 {
2871 unsigned int n_directories = 0;
2872 unsigned char *ptr_directory_table = data;
2873
2874 while (*data != 0)
2875 {
2876 data += strlen ((char *) data) + 1;
2877 n_directories++;
2878 }
2879
2880 /* Go through the directory table again to save the directories. */
2881 directory_table = (unsigned char **)
2882 xmalloc (n_directories * sizeof (unsigned char *));
2883
2884 i = 0;
2885 while (*ptr_directory_table != 0)
2886 {
2887 directory_table[i] = ptr_directory_table;
2888 ptr_directory_table += strlen ((char *) ptr_directory_table) + 1;
2889 i++;
2890 }
2891 }
2892 /* Skip the NUL at the end of the table. */
2893 data++;
2894
2895 /* Traverse the File Name table just to count the entries. */
2896 if (*data != 0)
2897 {
2898 unsigned int n_files = 0;
2899 unsigned char *ptr_file_name_table = data;
2900
2901 while (*data != 0)
2902 {
2903 unsigned int bytes_read;
2904
2905 /* Skip Name, directory index, last modification time and length
2906 of file. */
2907 data += strlen ((char *) data) + 1;
2908 read_leb128 (data, & bytes_read, 0);
2909 data += bytes_read;
2910 read_leb128 (data, & bytes_read, 0);
2911 data += bytes_read;
2912 read_leb128 (data, & bytes_read, 0);
2913 data += bytes_read;
2914
2915 n_files++;
2916 }
2917
2918 /* Go through the file table again to save the strings. */
2919 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
2920
2921 i = 0;
2922 while (*ptr_file_name_table != 0)
2923 {
2924 unsigned int bytes_read;
2925
2926 file_table[i].name = ptr_file_name_table;
2927 ptr_file_name_table += strlen ((char *) ptr_file_name_table) + 1;
2928
2929 /* We are not interested in directory, time or size. */
2930 file_table[i].directory_index = read_leb128 (ptr_file_name_table,
2931 & bytes_read, 0);
2932 ptr_file_name_table += bytes_read;
2933 file_table[i].modification_date = read_leb128 (ptr_file_name_table,
2934 & bytes_read, 0);
2935 ptr_file_name_table += bytes_read;
2936 file_table[i].length = read_leb128 (ptr_file_name_table, & bytes_read, 0);
2937 ptr_file_name_table += bytes_read;
2938 i++;
2939 }
2940 i = 0;
2941
2942 /* Print the Compilation Unit's name and a header. */
2943 if (directory_table == NULL)
2944 {
2945 printf (_("CU: %s:\n"), file_table[0].name);
2946 printf (_("File name Line number Starting address\n"));
2947 }
2948 else
2949 {
2950 if (do_wide || strlen ((char *) directory_table[0]) < 76)
2951 printf (_("CU: %s/%s:\n"), directory_table[0],
2952 file_table[0].name);
2953 else
2954 printf ("%s:\n", file_table[0].name);
2955
2956 printf (_("File name Line number Starting address\n"));
2957 }
2958 }
2959
2960 /* Skip the NUL at the end of the table. */
2961 data++;
2962
2963 /* This loop iterates through the Dwarf Line Number Program. */
2964 while (data < end_of_sequence)
2965 {
2966 unsigned char op_code;
2967 int adv;
2968 unsigned long int uladv;
2969 unsigned int bytes_read;
2970 int is_special_opcode = 0;
2971
2972 op_code = *data++;
2973
2974 if (op_code >= linfo.li_opcode_base)
2975 {
2976 op_code -= linfo.li_opcode_base;
2977 uladv = (op_code / linfo.li_line_range);
2978 if (linfo.li_max_ops_per_insn == 1)
2979 {
2980 uladv *= linfo.li_min_insn_length;
2981 state_machine_regs.address += uladv;
2982 }
2983 else
2984 {
2985 state_machine_regs.address
2986 += ((state_machine_regs.op_index + uladv)
2987 / linfo.li_max_ops_per_insn)
2988 * linfo.li_min_insn_length;
2989 state_machine_regs.op_index
2990 = (state_machine_regs.op_index + uladv)
2991 % linfo.li_max_ops_per_insn;
2992 }
2993
2994 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2995 state_machine_regs.line += adv;
2996 is_special_opcode = 1;
2997 }
2998 else switch (op_code)
2999 {
3000 case DW_LNS_extended_op:
3001 {
3002 unsigned int ext_op_code_len;
3003 unsigned char ext_op_code;
3004 unsigned char *op_code_data = data;
3005
3006 ext_op_code_len = read_leb128 (op_code_data, &bytes_read, 0);
3007 op_code_data += bytes_read;
3008
3009 if (ext_op_code_len == 0)
3010 {
3011 warn (_("badly formed extended line op encountered!\n"));
3012 break;
3013 }
3014 ext_op_code_len += bytes_read;
3015 ext_op_code = *op_code_data++;
3016
3017 switch (ext_op_code)
3018 {
3019 case DW_LNE_end_sequence:
3020 reset_state_machine (linfo.li_default_is_stmt);
3021 break;
3022 case DW_LNE_set_address:
3023 state_machine_regs.address =
3024 byte_get (op_code_data, ext_op_code_len - bytes_read - 1);
3025 state_machine_regs.op_index = 0;
3026 break;
3027 case DW_LNE_define_file:
3028 {
3029 unsigned int dir_index = 0;
3030
3031 ++state_machine_regs.last_file_entry;
3032 op_code_data += strlen ((char *) op_code_data) + 1;
3033 dir_index = read_leb128 (op_code_data, & bytes_read, 0);
3034 op_code_data += bytes_read;
3035 read_leb128 (op_code_data, & bytes_read, 0);
3036 op_code_data += bytes_read;
3037 read_leb128 (op_code_data, & bytes_read, 0);
3038
3039 printf ("%s:\n", directory_table[dir_index]);
3040 break;
3041 }
3042 default:
3043 printf (_("UNKNOWN: length %d\n"), ext_op_code_len - bytes_read);
3044 break;
3045 }
3046 data += ext_op_code_len;
3047 break;
3048 }
3049 case DW_LNS_copy:
3050 break;
3051
3052 case DW_LNS_advance_pc:
3053 uladv = read_leb128 (data, & bytes_read, 0);
3054 data += bytes_read;
3055 if (linfo.li_max_ops_per_insn == 1)
3056 {
3057 uladv *= linfo.li_min_insn_length;
3058 state_machine_regs.address += uladv;
3059 }
3060 else
3061 {
3062 state_machine_regs.address
3063 += ((state_machine_regs.op_index + uladv)
3064 / linfo.li_max_ops_per_insn)
3065 * linfo.li_min_insn_length;
3066 state_machine_regs.op_index
3067 = (state_machine_regs.op_index + uladv)
3068 % linfo.li_max_ops_per_insn;
3069 }
3070 break;
3071
3072 case DW_LNS_advance_line:
3073 adv = read_sleb128 (data, & bytes_read);
3074 data += bytes_read;
3075 state_machine_regs.line += adv;
3076 break;
3077
3078 case DW_LNS_set_file:
3079 adv = read_leb128 (data, & bytes_read, 0);
3080 data += bytes_read;
3081 state_machine_regs.file = adv;
3082 if (file_table[state_machine_regs.file - 1].directory_index == 0)
3083 {
3084 /* If directory index is 0, that means current directory. */
3085 printf ("\n./%s:[++]\n",
3086 file_table[state_machine_regs.file - 1].name);
3087 }
3088 else
3089 {
3090 /* The directory index starts counting at 1. */
3091 printf ("\n%s/%s:\n",
3092 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
3093 file_table[state_machine_regs.file - 1].name);
3094 }
3095 break;
3096
3097 case DW_LNS_set_column:
3098 uladv = read_leb128 (data, & bytes_read, 0);
3099 data += bytes_read;
3100 state_machine_regs.column = uladv;
3101 break;
3102
3103 case DW_LNS_negate_stmt:
3104 adv = state_machine_regs.is_stmt;
3105 adv = ! adv;
3106 state_machine_regs.is_stmt = adv;
3107 break;
3108
3109 case DW_LNS_set_basic_block:
3110 state_machine_regs.basic_block = 1;
3111 break;
3112
3113 case DW_LNS_const_add_pc:
3114 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3115 if (linfo.li_max_ops_per_insn == 1)
3116 {
3117 uladv *= linfo.li_min_insn_length;
3118 state_machine_regs.address += uladv;
3119 }
3120 else
3121 {
3122 state_machine_regs.address
3123 += ((state_machine_regs.op_index + uladv)
3124 / linfo.li_max_ops_per_insn)
3125 * linfo.li_min_insn_length;
3126 state_machine_regs.op_index
3127 = (state_machine_regs.op_index + uladv)
3128 % linfo.li_max_ops_per_insn;
3129 }
3130 break;
3131
3132 case DW_LNS_fixed_advance_pc:
3133 uladv = byte_get (data, 2);
3134 data += 2;
3135 state_machine_regs.address += uladv;
3136 state_machine_regs.op_index = 0;
3137 break;
3138
3139 case DW_LNS_set_prologue_end:
3140 break;
3141
3142 case DW_LNS_set_epilogue_begin:
3143 break;
3144
3145 case DW_LNS_set_isa:
3146 uladv = read_leb128 (data, & bytes_read, 0);
3147 data += bytes_read;
3148 printf (_(" Set ISA to %lu\n"), uladv);
3149 break;
3150
3151 default:
3152 printf (_(" Unknown opcode %d with operands: "), op_code);
3153
3154 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3155 {
3156 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
3157 &bytes_read, 0)),
3158 i == 1 ? "" : ", ");
3159 data += bytes_read;
3160 }
3161 putchar ('\n');
3162 break;
3163 }
3164
3165 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3166 to the DWARF address/line matrix. */
3167 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3168 || (op_code == DW_LNS_copy))
3169 {
3170 const unsigned int MAX_FILENAME_LENGTH = 35;
3171 char *fileName = (char *)file_table[state_machine_regs.file - 1].name;
3172 char *newFileName = NULL;
3173 size_t fileNameLength = strlen (fileName);
3174
3175 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3176 {
3177 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
3178 /* Truncate file name */
3179 strncpy (newFileName,
3180 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3181 MAX_FILENAME_LENGTH + 1);
3182 }
3183 else
3184 {
3185 newFileName = (char *) xmalloc (fileNameLength + 1);
3186 strncpy (newFileName, fileName, fileNameLength + 1);
3187 }
3188
3189 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3190 {
3191 if (linfo.li_max_ops_per_insn == 1)
3192 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3193 newFileName, state_machine_regs.line,
3194 state_machine_regs.address);
3195 else
3196 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3197 newFileName, state_machine_regs.line,
3198 state_machine_regs.address,
3199 state_machine_regs.op_index);
3200 }
3201 else
3202 {
3203 if (linfo.li_max_ops_per_insn == 1)
3204 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3205 newFileName, state_machine_regs.line,
3206 state_machine_regs.address);
3207 else
3208 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3209 newFileName, state_machine_regs.line,
3210 state_machine_regs.address,
3211 state_machine_regs.op_index);
3212 }
3213
3214 if (op_code == DW_LNE_end_sequence)
3215 printf ("\n");
3216
3217 free (newFileName);
3218 }
3219 }
3220 free (file_table);
3221 file_table = NULL;
3222 free (directory_table);
3223 directory_table = NULL;
3224 putchar ('\n');
3225 }
3226
3227 return 1;
3228 }
3229
3230 static int
3231 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
3232 {
3233 unsigned char *data = section->start;
3234 unsigned char *end = data + section->size;
3235 int retValRaw = 1;
3236 int retValDecoded = 1;
3237
3238 if (do_debug_lines == 0)
3239 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3240
3241 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3242 retValRaw = display_debug_lines_raw (section, data, end);
3243
3244 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3245 retValDecoded = display_debug_lines_decoded (section, data, end);
3246
3247 if (!retValRaw || !retValDecoded)
3248 return 0;
3249
3250 return 1;
3251 }
3252
3253 static debug_info *
3254 find_debug_info_for_offset (unsigned long offset)
3255 {
3256 unsigned int i;
3257
3258 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3259 return NULL;
3260
3261 for (i = 0; i < num_debug_info_entries; i++)
3262 if (debug_information[i].cu_offset == offset)
3263 return debug_information + i;
3264
3265 return NULL;
3266 }
3267
3268 static int
3269 display_debug_pubnames (struct dwarf_section *section,
3270 void *file ATTRIBUTE_UNUSED)
3271 {
3272 DWARF2_Internal_PubNames names;
3273 unsigned char *start = section->start;
3274 unsigned char *end = start + section->size;
3275
3276 /* It does not matter if this load fails,
3277 we test for that later on. */
3278 load_debug_info (file);
3279
3280 printf (_("Contents of the %s section:\n\n"), section->name);
3281
3282 while (start < end)
3283 {
3284 unsigned char *data;
3285 unsigned long offset;
3286 int offset_size, initial_length_size;
3287
3288 data = start;
3289
3290 names.pn_length = byte_get (data, 4);
3291 data += 4;
3292 if (names.pn_length == 0xffffffff)
3293 {
3294 names.pn_length = byte_get (data, 8);
3295 data += 8;
3296 offset_size = 8;
3297 initial_length_size = 12;
3298 }
3299 else
3300 {
3301 offset_size = 4;
3302 initial_length_size = 4;
3303 }
3304
3305 names.pn_version = byte_get (data, 2);
3306 data += 2;
3307
3308 names.pn_offset = byte_get (data, offset_size);
3309 data += offset_size;
3310
3311 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3312 && num_debug_info_entries > 0
3313 && find_debug_info_for_offset (names.pn_offset) == NULL)
3314 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3315 (unsigned long) names.pn_offset, section->name);
3316
3317 names.pn_size = byte_get (data, offset_size);
3318 data += offset_size;
3319
3320 start += names.pn_length + initial_length_size;
3321
3322 if (names.pn_version != 2 && names.pn_version != 3)
3323 {
3324 static int warned = 0;
3325
3326 if (! warned)
3327 {
3328 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3329 warned = 1;
3330 }
3331
3332 continue;
3333 }
3334
3335 printf (_(" Length: %ld\n"),
3336 (long) names.pn_length);
3337 printf (_(" Version: %d\n"),
3338 names.pn_version);
3339 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3340 (unsigned long) names.pn_offset);
3341 printf (_(" Size of area in .debug_info section: %ld\n"),
3342 (long) names.pn_size);
3343
3344 printf (_("\n Offset\tName\n"));
3345
3346 do
3347 {
3348 offset = byte_get (data, offset_size);
3349
3350 if (offset != 0)
3351 {
3352 data += offset_size;
3353 printf (" %-6lx\t%s\n", offset, data);
3354 data += strlen ((char *) data) + 1;
3355 }
3356 }
3357 while (offset != 0);
3358 }
3359
3360 printf ("\n");
3361 return 1;
3362 }
3363
3364 static int
3365 display_debug_macinfo (struct dwarf_section *section,
3366 void *file ATTRIBUTE_UNUSED)
3367 {
3368 unsigned char *start = section->start;
3369 unsigned char *end = start + section->size;
3370 unsigned char *curr = start;
3371 unsigned int bytes_read;
3372 enum dwarf_macinfo_record_type op;
3373
3374 printf (_("Contents of the %s section:\n\n"), section->name);
3375
3376 while (curr < end)
3377 {
3378 unsigned int lineno;
3379 const char *string;
3380
3381 op = (enum dwarf_macinfo_record_type) *curr;
3382 curr++;
3383
3384 switch (op)
3385 {
3386 case DW_MACINFO_start_file:
3387 {
3388 unsigned int filenum;
3389
3390 lineno = read_leb128 (curr, & bytes_read, 0);
3391 curr += bytes_read;
3392 filenum = read_leb128 (curr, & bytes_read, 0);
3393 curr += bytes_read;
3394
3395 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3396 lineno, filenum);
3397 }
3398 break;
3399
3400 case DW_MACINFO_end_file:
3401 printf (_(" DW_MACINFO_end_file\n"));
3402 break;
3403
3404 case DW_MACINFO_define:
3405 lineno = read_leb128 (curr, & bytes_read, 0);
3406 curr += bytes_read;
3407 string = (char *) curr;
3408 curr += strlen (string) + 1;
3409 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3410 lineno, string);
3411 break;
3412
3413 case DW_MACINFO_undef:
3414 lineno = read_leb128 (curr, & bytes_read, 0);
3415 curr += bytes_read;
3416 string = (char *) curr;
3417 curr += strlen (string) + 1;
3418 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3419 lineno, string);
3420 break;
3421
3422 case DW_MACINFO_vendor_ext:
3423 {
3424 unsigned int constant;
3425
3426 constant = read_leb128 (curr, & bytes_read, 0);
3427 curr += bytes_read;
3428 string = (char *) curr;
3429 curr += strlen (string) + 1;
3430 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3431 constant, string);
3432 }
3433 break;
3434 }
3435 }
3436
3437 return 1;
3438 }
3439
3440 static int
3441 display_debug_abbrev (struct dwarf_section *section,
3442 void *file ATTRIBUTE_UNUSED)
3443 {
3444 abbrev_entry *entry;
3445 unsigned char *start = section->start;
3446 unsigned char *end = start + section->size;
3447
3448 printf (_("Contents of the %s section:\n\n"), section->name);
3449
3450 do
3451 {
3452 free_abbrevs ();
3453
3454 start = process_abbrev_section (start, end);
3455
3456 if (first_abbrev == NULL)
3457 continue;
3458
3459 printf (_(" Number TAG\n"));
3460
3461 for (entry = first_abbrev; entry; entry = entry->next)
3462 {
3463 abbrev_attr *attr;
3464
3465 printf (" %ld %s [%s]\n",
3466 entry->entry,
3467 get_TAG_name (entry->tag),
3468 entry->children ? _("has children") : _("no children"));
3469
3470 for (attr = entry->first_attr; attr; attr = attr->next)
3471 printf (" %-18s %s\n",
3472 get_AT_name (attr->attribute),
3473 get_FORM_name (attr->form));
3474 }
3475 }
3476 while (start);
3477
3478 printf ("\n");
3479
3480 return 1;
3481 }
3482
3483 static int
3484 display_debug_loc (struct dwarf_section *section, void *file)
3485 {
3486 unsigned char *start = section->start;
3487 unsigned char *section_end;
3488 unsigned long bytes;
3489 unsigned char *section_begin = start;
3490 unsigned int num_loc_list = 0;
3491 unsigned long last_offset = 0;
3492 unsigned int first = 0;
3493 unsigned int i;
3494 unsigned int j;
3495 int seen_first_offset = 0;
3496 int use_debug_info = 1;
3497 unsigned char *next;
3498
3499 bytes = section->size;
3500 section_end = start + bytes;
3501
3502 if (bytes == 0)
3503 {
3504 printf (_("\nThe %s section is empty.\n"), section->name);
3505 return 0;
3506 }
3507
3508 if (load_debug_info (file) == 0)
3509 {
3510 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3511 section->name);
3512 return 0;
3513 }
3514
3515 /* Check the order of location list in .debug_info section. If
3516 offsets of location lists are in the ascending order, we can
3517 use `debug_information' directly. */
3518 for (i = 0; i < num_debug_info_entries; i++)
3519 {
3520 unsigned int num;
3521
3522 num = debug_information [i].num_loc_offsets;
3523 num_loc_list += num;
3524
3525 /* Check if we can use `debug_information' directly. */
3526 if (use_debug_info && num != 0)
3527 {
3528 if (!seen_first_offset)
3529 {
3530 /* This is the first location list. */
3531 last_offset = debug_information [i].loc_offsets [0];
3532 first = i;
3533 seen_first_offset = 1;
3534 j = 1;
3535 }
3536 else
3537 j = 0;
3538
3539 for (; j < num; j++)
3540 {
3541 if (last_offset >
3542 debug_information [i].loc_offsets [j])
3543 {
3544 use_debug_info = 0;
3545 break;
3546 }
3547 last_offset = debug_information [i].loc_offsets [j];
3548 }
3549 }
3550 }
3551
3552 if (!use_debug_info)
3553 /* FIXME: Should we handle this case? */
3554 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3555
3556 if (!seen_first_offset)
3557 error (_("No location lists in .debug_info section!\n"));
3558
3559 /* DWARF sections under Mach-O have non-zero addresses. */
3560 if (debug_information [first].num_loc_offsets > 0
3561 && debug_information [first].loc_offsets [0] != section->address)
3562 warn (_("Location lists in %s section start at 0x%s\n"),
3563 section->name,
3564 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
3565
3566 printf (_("Contents of the %s section:\n\n"), section->name);
3567 printf (_(" Offset Begin End Expression\n"));
3568
3569 seen_first_offset = 0;
3570 for (i = first; i < num_debug_info_entries; i++)
3571 {
3572 dwarf_vma begin;
3573 dwarf_vma end;
3574 unsigned short length;
3575 unsigned long offset;
3576 unsigned int pointer_size;
3577 unsigned int offset_size;
3578 int dwarf_version;
3579 unsigned long cu_offset;
3580 unsigned long base_address;
3581 int need_frame_base;
3582 int has_frame_base;
3583
3584 pointer_size = debug_information [i].pointer_size;
3585 cu_offset = debug_information [i].cu_offset;
3586 offset_size = debug_information [i].offset_size;
3587 dwarf_version = debug_information [i].dwarf_version;
3588
3589 for (j = 0; j < debug_information [i].num_loc_offsets; j++)
3590 {
3591 has_frame_base = debug_information [i].have_frame_base [j];
3592 /* DWARF sections under Mach-O have non-zero addresses. */
3593 offset = debug_information [i].loc_offsets [j] - section->address;
3594 next = section_begin + offset;
3595 base_address = debug_information [i].base_address;
3596
3597 if (!seen_first_offset)
3598 seen_first_offset = 1;
3599 else
3600 {
3601 if (start < next)
3602 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3603 (unsigned long) (start - section_begin),
3604 (unsigned long) (next - section_begin));
3605 else if (start > next)
3606 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3607 (unsigned long) (start - section_begin),
3608 (unsigned long) (next - section_begin));
3609 }
3610 start = next;
3611
3612 if (offset >= bytes)
3613 {
3614 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3615 offset);
3616 continue;
3617 }
3618
3619 while (1)
3620 {
3621 if (start + 2 * pointer_size > section_end)
3622 {
3623 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3624 offset);
3625 break;
3626 }
3627
3628 /* Note: we use sign extension here in order to be sure that
3629 we can detect the -1 escape value. Sign extension into the
3630 top 32 bits of a 32-bit address will not affect the values
3631 that we display since we always show hex values, and always
3632 the bottom 32-bits. */
3633 begin = byte_get_signed (start, pointer_size);
3634 start += pointer_size;
3635 end = byte_get_signed (start, pointer_size);
3636 start += pointer_size;
3637
3638 printf (" %8.8lx ", offset);
3639
3640 if (begin == 0 && end == 0)
3641 {
3642 printf (_("<End of list>\n"));
3643 break;
3644 }
3645
3646 /* Check base address specifiers. */
3647 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
3648 {
3649 base_address = end;
3650 print_dwarf_vma (begin, pointer_size);
3651 print_dwarf_vma (end, pointer_size);
3652 printf (_("(base address)\n"));
3653 continue;
3654 }
3655
3656 if (start + 2 > section_end)
3657 {
3658 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3659 offset);
3660 break;
3661 }
3662
3663 length = byte_get (start, 2);
3664 start += 2;
3665
3666 if (start + length > section_end)
3667 {
3668 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3669 offset);
3670 break;
3671 }
3672
3673 print_dwarf_vma (begin + base_address, pointer_size);
3674 print_dwarf_vma (end + base_address, pointer_size);
3675
3676 putchar ('(');
3677 need_frame_base = decode_location_expression (start,
3678 pointer_size,
3679 offset_size,
3680 dwarf_version,
3681 length,
3682 cu_offset, section);
3683 putchar (')');
3684
3685 if (need_frame_base && !has_frame_base)
3686 printf (_(" [without DW_AT_frame_base]"));
3687
3688 if (begin == end)
3689 fputs (_(" (start == end)"), stdout);
3690 else if (begin > end)
3691 fputs (_(" (start > end)"), stdout);
3692
3693 putchar ('\n');
3694
3695 start += length;
3696 }
3697 }
3698 }
3699
3700 if (start < section_end)
3701 warn (_("There are %ld unused bytes at the end of section %s\n"),
3702 (long) (section_end - start), section->name);
3703 putchar ('\n');
3704 return 1;
3705 }
3706
3707 static int
3708 display_debug_str (struct dwarf_section *section,
3709 void *file ATTRIBUTE_UNUSED)
3710 {
3711 unsigned char *start = section->start;
3712 unsigned long bytes = section->size;
3713 dwarf_vma addr = section->address;
3714
3715 if (bytes == 0)
3716 {
3717 printf (_("\nThe %s section is empty.\n"), section->name);
3718 return 0;
3719 }
3720
3721 printf (_("Contents of the %s section:\n\n"), section->name);
3722
3723 while (bytes)
3724 {
3725 int j;
3726 int k;
3727 int lbytes;
3728
3729 lbytes = (bytes > 16 ? 16 : bytes);
3730
3731 printf (" 0x%8.8lx ", (unsigned long) addr);
3732
3733 for (j = 0; j < 16; j++)
3734 {
3735 if (j < lbytes)
3736 printf ("%2.2x", start[j]);
3737 else
3738 printf (" ");
3739
3740 if ((j & 3) == 3)
3741 printf (" ");
3742 }
3743
3744 for (j = 0; j < lbytes; j++)
3745 {
3746 k = start[j];
3747 if (k >= ' ' && k < 0x80)
3748 printf ("%c", k);
3749 else
3750 printf (".");
3751 }
3752
3753 putchar ('\n');
3754
3755 start += lbytes;
3756 addr += lbytes;
3757 bytes -= lbytes;
3758 }
3759
3760 putchar ('\n');
3761
3762 return 1;
3763 }
3764
3765 static int
3766 display_debug_info (struct dwarf_section *section, void *file)
3767 {
3768 return process_debug_info (section, file, abbrev, 0, 0);
3769 }
3770
3771 static int
3772 display_debug_types (struct dwarf_section *section, void *file)
3773 {
3774 return process_debug_info (section, file, abbrev, 0, 1);
3775 }
3776
3777 static int
3778 display_trace_info (struct dwarf_section *section, void *file)
3779 {
3780 return process_debug_info (section, file, trace_abbrev, 0, 0);
3781 }
3782
3783 static int
3784 display_debug_aranges (struct dwarf_section *section,
3785 void *file ATTRIBUTE_UNUSED)
3786 {
3787 unsigned char *start = section->start;
3788 unsigned char *end = start + section->size;
3789
3790 printf (_("Contents of the %s section:\n\n"), section->name);
3791
3792 /* It does not matter if this load fails,
3793 we test for that later on. */
3794 load_debug_info (file);
3795
3796 while (start < end)
3797 {
3798 unsigned char *hdrptr;
3799 DWARF2_Internal_ARange arange;
3800 unsigned char *addr_ranges;
3801 dwarf_vma length;
3802 dwarf_vma address;
3803 unsigned char address_size;
3804 int excess;
3805 int offset_size;
3806 int initial_length_size;
3807
3808 hdrptr = start;
3809
3810 arange.ar_length = byte_get (hdrptr, 4);
3811 hdrptr += 4;
3812
3813 if (arange.ar_length == 0xffffffff)
3814 {
3815 arange.ar_length = byte_get (hdrptr, 8);
3816 hdrptr += 8;
3817 offset_size = 8;
3818 initial_length_size = 12;
3819 }
3820 else
3821 {
3822 offset_size = 4;
3823 initial_length_size = 4;
3824 }
3825
3826 arange.ar_version = byte_get (hdrptr, 2);
3827 hdrptr += 2;
3828
3829 arange.ar_info_offset = byte_get (hdrptr, offset_size);
3830 hdrptr += offset_size;
3831
3832 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3833 && num_debug_info_entries > 0
3834 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
3835 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3836 (unsigned long) arange.ar_info_offset, section->name);
3837
3838 arange.ar_pointer_size = byte_get (hdrptr, 1);
3839 hdrptr += 1;
3840
3841 arange.ar_segment_size = byte_get (hdrptr, 1);
3842 hdrptr += 1;
3843
3844 if (arange.ar_version != 2 && arange.ar_version != 3)
3845 {
3846 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3847 break;
3848 }
3849
3850 printf (_(" Length: %ld\n"),
3851 (long) arange.ar_length);
3852 printf (_(" Version: %d\n"), arange.ar_version);
3853 printf (_(" Offset into .debug_info: 0x%lx\n"),
3854 (unsigned long) arange.ar_info_offset);
3855 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
3856 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
3857
3858 address_size = arange.ar_pointer_size + arange.ar_segment_size;
3859
3860 /* The DWARF spec does not require that the address size be a power
3861 of two, but we do. This will have to change if we ever encounter
3862 an uneven architecture. */
3863 if ((address_size & (address_size - 1)) != 0)
3864 {
3865 warn (_("Pointer size + Segment size is not a power of two.\n"));
3866 break;
3867 }
3868
3869 if (address_size > 4)
3870 printf (_("\n Address Length\n"));
3871 else
3872 printf (_("\n Address Length\n"));
3873
3874 addr_ranges = hdrptr;
3875
3876 /* Must pad to an alignment boundary that is twice the address size. */
3877 excess = (hdrptr - start) % (2 * address_size);
3878 if (excess)
3879 addr_ranges += (2 * address_size) - excess;
3880
3881 start += arange.ar_length + initial_length_size;
3882
3883 while (addr_ranges + 2 * address_size <= start)
3884 {
3885 address = byte_get (addr_ranges, address_size);
3886
3887 addr_ranges += address_size;
3888
3889 length = byte_get (addr_ranges, address_size);
3890
3891 addr_ranges += address_size;
3892
3893 printf (" ");
3894 print_dwarf_vma (address, address_size);
3895 print_dwarf_vma (length, address_size);
3896 putchar ('\n');
3897 }
3898 }
3899
3900 printf ("\n");
3901
3902 return 1;
3903 }
3904
3905 /* Each debug_information[x].range_lists[y] gets this representation for
3906 sorting purposes. */
3907
3908 struct range_entry
3909 {
3910 /* The debug_information[x].range_lists[y] value. */
3911 unsigned long ranges_offset;
3912
3913 /* Original debug_information to find parameters of the data. */
3914 debug_info *debug_info_p;
3915 };
3916
3917 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
3918
3919 static int
3920 range_entry_compar (const void *ap, const void *bp)
3921 {
3922 const struct range_entry *a_re = (const struct range_entry *) ap;
3923 const struct range_entry *b_re = (const struct range_entry *) bp;
3924 const unsigned long a = a_re->ranges_offset;
3925 const unsigned long b = b_re->ranges_offset;
3926
3927 return (a > b) - (b > a);
3928 }
3929
3930 static int
3931 display_debug_ranges (struct dwarf_section *section,
3932 void *file ATTRIBUTE_UNUSED)
3933 {
3934 unsigned char *start = section->start;
3935 unsigned long bytes;
3936 unsigned char *section_begin = start;
3937 unsigned int num_range_list, i;
3938 struct range_entry *range_entries, *range_entry_fill;
3939
3940 bytes = section->size;
3941
3942 if (bytes == 0)
3943 {
3944 printf (_("\nThe %s section is empty.\n"), section->name);
3945 return 0;
3946 }
3947
3948 if (load_debug_info (file) == 0)
3949 {
3950 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3951 section->name);
3952 return 0;
3953 }
3954
3955 num_range_list = 0;
3956 for (i = 0; i < num_debug_info_entries; i++)
3957 num_range_list += debug_information [i].num_range_lists;
3958
3959 if (num_range_list == 0)
3960 error (_("No range lists in .debug_info section!\n"));
3961
3962 range_entries = (struct range_entry *)
3963 xmalloc (sizeof (*range_entries) * num_range_list);
3964 range_entry_fill = range_entries;
3965
3966 for (i = 0; i < num_debug_info_entries; i++)
3967 {
3968 debug_info *debug_info_p = &debug_information[i];
3969 unsigned int j;
3970
3971 for (j = 0; j < debug_info_p->num_range_lists; j++)
3972 {
3973 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
3974 range_entry_fill->debug_info_p = debug_info_p;
3975 range_entry_fill++;
3976 }
3977 }
3978
3979 qsort (range_entries, num_range_list, sizeof (*range_entries),
3980 range_entry_compar);
3981
3982 /* DWARF sections under Mach-O have non-zero addresses. */
3983 if (range_entries[0].ranges_offset != section->address)
3984 warn (_("Range lists in %s section start at 0x%lx\n"),
3985 section->name, range_entries[0].ranges_offset);
3986
3987 printf (_("Contents of the %s section:\n\n"), section->name);
3988 printf (_(" Offset Begin End\n"));
3989
3990 for (i = 0; i < num_range_list; i++)
3991 {
3992 struct range_entry *range_entry = &range_entries[i];
3993 debug_info *debug_info_p = range_entry->debug_info_p;
3994 unsigned int pointer_size;
3995 unsigned long offset;
3996 unsigned char *next;
3997 unsigned long base_address;
3998
3999 pointer_size = debug_info_p->pointer_size;
4000
4001 /* DWARF sections under Mach-O have non-zero addresses. */
4002 offset = range_entry->ranges_offset - section->address;
4003 next = section_begin + offset;
4004 base_address = debug_info_p->base_address;
4005
4006 if (i > 0)
4007 {
4008 if (start < next)
4009 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4010 (unsigned long) (start - section_begin),
4011 (unsigned long) (next - section_begin), section->name);
4012 else if (start > next)
4013 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4014 (unsigned long) (start - section_begin),
4015 (unsigned long) (next - section_begin), section->name);
4016 }
4017 start = next;
4018
4019 while (1)
4020 {
4021 dwarf_vma begin;
4022 dwarf_vma end;
4023
4024 /* Note: we use sign extension here in order to be sure that
4025 we can detect the -1 escape value. Sign extension into the
4026 top 32 bits of a 32-bit address will not affect the values
4027 that we display since we always show hex values, and always
4028 the bottom 32-bits. */
4029 begin = byte_get_signed (start, pointer_size);
4030 start += pointer_size;
4031 end = byte_get_signed (start, pointer_size);
4032 start += pointer_size;
4033
4034 printf (" %8.8lx ", offset);
4035
4036 if (begin == 0 && end == 0)
4037 {
4038 printf (_("<End of list>\n"));
4039 break;
4040 }
4041
4042 /* Check base address specifiers. */
4043 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4044 {
4045 base_address = end;
4046 print_dwarf_vma (begin, pointer_size);
4047 print_dwarf_vma (end, pointer_size);
4048 printf ("(base address)\n");
4049 continue;
4050 }
4051
4052 print_dwarf_vma (begin + base_address, pointer_size);
4053 print_dwarf_vma (end + base_address, pointer_size);
4054
4055 if (begin == end)
4056 fputs (_("(start == end)"), stdout);
4057 else if (begin > end)
4058 fputs (_("(start > end)"), stdout);
4059
4060 putchar ('\n');
4061 }
4062 }
4063 putchar ('\n');
4064
4065 free (range_entries);
4066
4067 return 1;
4068 }
4069
4070 typedef struct Frame_Chunk
4071 {
4072 struct Frame_Chunk *next;
4073 unsigned char *chunk_start;
4074 int ncols;
4075 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4076 short int *col_type;
4077 int *col_offset;
4078 char *augmentation;
4079 unsigned int code_factor;
4080 int data_factor;
4081 unsigned long pc_begin;
4082 unsigned long pc_range;
4083 int cfa_reg;
4084 int cfa_offset;
4085 int ra;
4086 unsigned char fde_encoding;
4087 unsigned char cfa_exp;
4088 unsigned char ptr_size;
4089 unsigned char segment_size;
4090 }
4091 Frame_Chunk;
4092
4093 static const char *const *dwarf_regnames;
4094 static unsigned int dwarf_regnames_count;
4095
4096 /* A marker for a col_type that means this column was never referenced
4097 in the frame info. */
4098 #define DW_CFA_unreferenced (-1)
4099
4100 /* Return 0 if not more space is needed, 1 if more space is needed,
4101 -1 for invalid reg. */
4102
4103 static int
4104 frame_need_space (Frame_Chunk *fc, unsigned int reg)
4105 {
4106 int prev = fc->ncols;
4107
4108 if (reg < (unsigned int) fc->ncols)
4109 return 0;
4110
4111 if (dwarf_regnames_count
4112 && reg > dwarf_regnames_count)
4113 return -1;
4114
4115 fc->ncols = reg + 1;
4116 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
4117 sizeof (short int));
4118 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
4119
4120 while (prev < fc->ncols)
4121 {
4122 fc->col_type[prev] = DW_CFA_unreferenced;
4123 fc->col_offset[prev] = 0;
4124 prev++;
4125 }
4126 return 1;
4127 }
4128
4129 static const char *const dwarf_regnames_i386[] =
4130 {
4131 "eax", "ecx", "edx", "ebx",
4132 "esp", "ebp", "esi", "edi",
4133 "eip", "eflags", NULL,
4134 "st0", "st1", "st2", "st3",
4135 "st4", "st5", "st6", "st7",
4136 NULL, NULL,
4137 "xmm0", "xmm1", "xmm2", "xmm3",
4138 "xmm4", "xmm5", "xmm6", "xmm7",
4139 "mm0", "mm1", "mm2", "mm3",
4140 "mm4", "mm5", "mm6", "mm7",
4141 "fcw", "fsw", "mxcsr",
4142 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4143 "tr", "ldtr"
4144 };
4145
4146 void
4147 init_dwarf_regnames_i386 (void)
4148 {
4149 dwarf_regnames = dwarf_regnames_i386;
4150 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
4151 }
4152
4153 static const char *const dwarf_regnames_x86_64[] =
4154 {
4155 "rax", "rdx", "rcx", "rbx",
4156 "rsi", "rdi", "rbp", "rsp",
4157 "r8", "r9", "r10", "r11",
4158 "r12", "r13", "r14", "r15",
4159 "rip",
4160 "xmm0", "xmm1", "xmm2", "xmm3",
4161 "xmm4", "xmm5", "xmm6", "xmm7",
4162 "xmm8", "xmm9", "xmm10", "xmm11",
4163 "xmm12", "xmm13", "xmm14", "xmm15",
4164 "st0", "st1", "st2", "st3",
4165 "st4", "st5", "st6", "st7",
4166 "mm0", "mm1", "mm2", "mm3",
4167 "mm4", "mm5", "mm6", "mm7",
4168 "rflags",
4169 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4170 "fs.base", "gs.base", NULL, NULL,
4171 "tr", "ldtr",
4172 "mxcsr", "fcw", "fsw"
4173 };
4174
4175 void
4176 init_dwarf_regnames_x86_64 (void)
4177 {
4178 dwarf_regnames = dwarf_regnames_x86_64;
4179 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
4180 }
4181
4182 void
4183 init_dwarf_regnames (unsigned int e_machine)
4184 {
4185 switch (e_machine)
4186 {
4187 case EM_386:
4188 case EM_486:
4189 init_dwarf_regnames_i386 ();
4190 break;
4191
4192 case EM_X86_64:
4193 case EM_L1OM:
4194 init_dwarf_regnames_x86_64 ();
4195 break;
4196
4197 default:
4198 break;
4199 }
4200 }
4201
4202 static const char *
4203 regname (unsigned int regno, int row)
4204 {
4205 static char reg[64];
4206 if (dwarf_regnames
4207 && regno < dwarf_regnames_count
4208 && dwarf_regnames [regno] != NULL)
4209 {
4210 if (row)
4211 return dwarf_regnames [regno];
4212 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
4213 dwarf_regnames [regno]);
4214 }
4215 else
4216 snprintf (reg, sizeof (reg), "r%d", regno);
4217 return reg;
4218 }
4219
4220 static void
4221 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
4222 {
4223 int r;
4224 char tmp[100];
4225
4226 if (*max_regs < fc->ncols)
4227 *max_regs = fc->ncols;
4228
4229 if (*need_col_headers)
4230 {
4231 static const char *sloc = " LOC";
4232
4233 *need_col_headers = 0;
4234
4235 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
4236
4237 for (r = 0; r < *max_regs; r++)
4238 if (fc->col_type[r] != DW_CFA_unreferenced)
4239 {
4240 if (r == fc->ra)
4241 printf ("ra ");
4242 else
4243 printf ("%-5s ", regname (r, 1));
4244 }
4245
4246 printf ("\n");
4247 }
4248
4249 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
4250 if (fc->cfa_exp)
4251 strcpy (tmp, "exp");
4252 else
4253 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
4254 printf ("%-8s ", tmp);
4255
4256 for (r = 0; r < fc->ncols; r++)
4257 {
4258 if (fc->col_type[r] != DW_CFA_unreferenced)
4259 {
4260 switch (fc->col_type[r])
4261 {
4262 case DW_CFA_undefined:
4263 strcpy (tmp, "u");
4264 break;
4265 case DW_CFA_same_value:
4266 strcpy (tmp, "s");
4267 break;
4268 case DW_CFA_offset:
4269 sprintf (tmp, "c%+d", fc->col_offset[r]);
4270 break;
4271 case DW_CFA_val_offset:
4272 sprintf (tmp, "v%+d", fc->col_offset[r]);
4273 break;
4274 case DW_CFA_register:
4275 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
4276 break;
4277 case DW_CFA_expression:
4278 strcpy (tmp, "exp");
4279 break;
4280 case DW_CFA_val_expression:
4281 strcpy (tmp, "vexp");
4282 break;
4283 default:
4284 strcpy (tmp, "n/a");
4285 break;
4286 }
4287 printf ("%-5s ", tmp);
4288 }
4289 }
4290 printf ("\n");
4291 }
4292
4293 #define GET(N) byte_get (start, N); start += N
4294 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4295 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4296
4297 static int
4298 display_debug_frames (struct dwarf_section *section,
4299 void *file ATTRIBUTE_UNUSED)
4300 {
4301 unsigned char *start = section->start;
4302 unsigned char *end = start + section->size;
4303 unsigned char *section_start = start;
4304 Frame_Chunk *chunks = 0;
4305 Frame_Chunk *remembered_state = 0;
4306 Frame_Chunk *rs;
4307 int is_eh = strcmp (section->name, ".eh_frame") == 0;
4308 unsigned int length_return;
4309 int max_regs = 0;
4310 const char *bad_reg = _("bad register: ");
4311 int saved_eh_addr_size = eh_addr_size;
4312
4313 printf (_("Contents of the %s section:\n"), section->name);
4314
4315 while (start < end)
4316 {
4317 unsigned char *saved_start;
4318 unsigned char *block_end;
4319 unsigned long length;
4320 unsigned long cie_id;
4321 Frame_Chunk *fc;
4322 Frame_Chunk *cie;
4323 int need_col_headers = 1;
4324 unsigned char *augmentation_data = NULL;
4325 unsigned long augmentation_data_len = 0;
4326 int encoded_ptr_size = saved_eh_addr_size;
4327 int offset_size;
4328 int initial_length_size;
4329
4330 saved_start = start;
4331 length = byte_get (start, 4); start += 4;
4332
4333 if (length == 0)
4334 {
4335 printf ("\n%08lx ZERO terminator\n\n",
4336 (unsigned long)(saved_start - section_start));
4337 continue;
4338 }
4339
4340 if (length == 0xffffffff)
4341 {
4342 length = byte_get (start, 8);
4343 start += 8;
4344 offset_size = 8;
4345 initial_length_size = 12;
4346 }
4347 else
4348 {
4349 offset_size = 4;
4350 initial_length_size = 4;
4351 }
4352
4353 block_end = saved_start + length + initial_length_size;
4354 if (block_end > end)
4355 {
4356 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4357 length, (unsigned long)(saved_start - section_start));
4358 block_end = end;
4359 }
4360 cie_id = byte_get (start, offset_size); start += offset_size;
4361
4362 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
4363 {
4364 int version;
4365
4366 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4367 memset (fc, 0, sizeof (Frame_Chunk));
4368
4369 fc->next = chunks;
4370 chunks = fc;
4371 fc->chunk_start = saved_start;
4372 fc->ncols = 0;
4373 fc->col_type = (short int *) xmalloc (sizeof (short int));
4374 fc->col_offset = (int *) xmalloc (sizeof (int));
4375 frame_need_space (fc, max_regs - 1);
4376
4377 version = *start++;
4378
4379 fc->augmentation = (char *) start;
4380 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
4381
4382 if (strcmp (fc->augmentation, "eh") == 0)
4383 start += eh_addr_size;
4384
4385 if (version >= 4)
4386 {
4387 fc->ptr_size = GET (1);
4388 fc->segment_size = GET (1);
4389 eh_addr_size = fc->ptr_size;
4390 }
4391 else
4392 {
4393 fc->ptr_size = eh_addr_size;
4394 fc->segment_size = 0;
4395 }
4396 fc->code_factor = LEB ();
4397 fc->data_factor = SLEB ();
4398 if (version == 1)
4399 {
4400 fc->ra = GET (1);
4401 }
4402 else
4403 {
4404 fc->ra = LEB ();
4405 }
4406
4407 if (fc->augmentation[0] == 'z')
4408 {
4409 augmentation_data_len = LEB ();
4410 augmentation_data = start;
4411 start += augmentation_data_len;
4412 }
4413 cie = fc;
4414
4415 if (do_debug_frames_interp)
4416 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4417 (unsigned long)(saved_start - section_start), length, cie_id,
4418 fc->augmentation, fc->code_factor, fc->data_factor,
4419 fc->ra);
4420 else
4421 {
4422 printf ("\n%08lx %08lx %08lx CIE\n",
4423 (unsigned long)(saved_start - section_start), length, cie_id);
4424 printf (" Version: %d\n", version);
4425 printf (" Augmentation: \"%s\"\n", fc->augmentation);
4426 if (version >= 4)
4427 {
4428 printf (" Pointer Size: %u\n", fc->ptr_size);
4429 printf (" Segment Size: %u\n", fc->segment_size);
4430 }
4431 printf (" Code alignment factor: %u\n", fc->code_factor);
4432 printf (" Data alignment factor: %d\n", fc->data_factor);
4433 printf (" Return address column: %d\n", fc->ra);
4434
4435 if (augmentation_data_len)
4436 {
4437 unsigned long i;
4438 printf (" Augmentation data: ");
4439 for (i = 0; i < augmentation_data_len; ++i)
4440 printf (" %02x", augmentation_data[i]);
4441 putchar ('\n');
4442 }
4443 putchar ('\n');
4444 }
4445
4446 if (augmentation_data_len)
4447 {
4448 unsigned char *p, *q;
4449 p = (unsigned char *) fc->augmentation + 1;
4450 q = augmentation_data;
4451
4452 while (1)
4453 {
4454 if (*p == 'L')
4455 q++;
4456 else if (*p == 'P')
4457 q += 1 + size_of_encoded_value (*q);
4458 else if (*p == 'R')
4459 fc->fde_encoding = *q++;
4460 else if (*p == 'S')
4461 ;
4462 else
4463 break;
4464 p++;
4465 }
4466
4467 if (fc->fde_encoding)
4468 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4469 }
4470
4471 frame_need_space (fc, fc->ra);
4472 }
4473 else
4474 {
4475 unsigned char *look_for;
4476 static Frame_Chunk fde_fc;
4477 unsigned long segment_selector;
4478
4479 fc = & fde_fc;
4480 memset (fc, 0, sizeof (Frame_Chunk));
4481
4482 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
4483
4484 for (cie = chunks; cie ; cie = cie->next)
4485 if (cie->chunk_start == look_for)
4486 break;
4487
4488 if (!cie)
4489 {
4490 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4491 cie_id, (unsigned long)(saved_start - section_start));
4492 fc->ncols = 0;
4493 fc->col_type = (short int *) xmalloc (sizeof (short int));
4494 fc->col_offset = (int *) xmalloc (sizeof (int));
4495 frame_need_space (fc, max_regs - 1);
4496 cie = fc;
4497 fc->augmentation = "";
4498 fc->fde_encoding = 0;
4499 fc->ptr_size = eh_addr_size;
4500 fc->segment_size = 0;
4501 }
4502 else
4503 {
4504 fc->ncols = cie->ncols;
4505 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
4506 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
4507 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
4508 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
4509 fc->augmentation = cie->augmentation;
4510 fc->ptr_size = cie->ptr_size;
4511 eh_addr_size = cie->ptr_size;
4512 fc->segment_size = cie->segment_size;
4513 fc->code_factor = cie->code_factor;
4514 fc->data_factor = cie->data_factor;
4515 fc->cfa_reg = cie->cfa_reg;
4516 fc->cfa_offset = cie->cfa_offset;
4517 fc->ra = cie->ra;
4518 frame_need_space (fc, max_regs - 1);
4519 fc->fde_encoding = cie->fde_encoding;
4520 }
4521
4522 if (fc->fde_encoding)
4523 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4524
4525 segment_selector = 0;
4526 if (fc->segment_size)
4527 {
4528 segment_selector = byte_get (start, fc->segment_size);
4529 start += fc->segment_size;
4530 }
4531 fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section);
4532 start += encoded_ptr_size;
4533 fc->pc_range = byte_get (start, encoded_ptr_size);
4534 start += encoded_ptr_size;
4535
4536 if (cie->augmentation[0] == 'z')
4537 {
4538 augmentation_data_len = LEB ();
4539 augmentation_data = start;
4540 start += augmentation_data_len;
4541 }
4542
4543 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4544 (unsigned long)(saved_start - section_start), length, cie_id,
4545 (unsigned long)(cie->chunk_start - section_start));
4546 if (fc->segment_size)
4547 printf ("%04lx:", segment_selector);
4548 printf ("%08lx..%08lx\n", fc->pc_begin, fc->pc_begin + fc->pc_range);
4549 if (! do_debug_frames_interp && augmentation_data_len)
4550 {
4551 unsigned long i;
4552
4553 printf (" Augmentation data: ");
4554 for (i = 0; i < augmentation_data_len; ++i)
4555 printf (" %02x", augmentation_data[i]);
4556 putchar ('\n');
4557 putchar ('\n');
4558 }
4559 }
4560
4561 /* At this point, fc is the current chunk, cie (if any) is set, and
4562 we're about to interpret instructions for the chunk. */
4563 /* ??? At present we need to do this always, since this sizes the
4564 fc->col_type and fc->col_offset arrays, which we write into always.
4565 We should probably split the interpreted and non-interpreted bits
4566 into two different routines, since there's so much that doesn't
4567 really overlap between them. */
4568 if (1 || do_debug_frames_interp)
4569 {
4570 /* Start by making a pass over the chunk, allocating storage
4571 and taking note of what registers are used. */
4572 unsigned char *tmp = start;
4573
4574 while (start < block_end)
4575 {
4576 unsigned op, opa;
4577 unsigned long reg, temp;
4578
4579 op = *start++;
4580 opa = op & 0x3f;
4581 if (op & 0xc0)
4582 op &= 0xc0;
4583
4584 /* Warning: if you add any more cases to this switch, be
4585 sure to add them to the corresponding switch below. */
4586 switch (op)
4587 {
4588 case DW_CFA_advance_loc:
4589 break;
4590 case DW_CFA_offset:
4591 LEB ();
4592 if (frame_need_space (fc, opa) >= 0)
4593 fc->col_type[opa] = DW_CFA_undefined;
4594 break;
4595 case DW_CFA_restore:
4596 if (frame_need_space (fc, opa) >= 0)
4597 fc->col_type[opa] = DW_CFA_undefined;
4598 break;
4599 case DW_CFA_set_loc:
4600 start += encoded_ptr_size;
4601 break;
4602 case DW_CFA_advance_loc1:
4603 start += 1;
4604 break;
4605 case DW_CFA_advance_loc2:
4606 start += 2;
4607 break;
4608 case DW_CFA_advance_loc4:
4609 start += 4;
4610 break;
4611 case DW_CFA_offset_extended:
4612 case DW_CFA_val_offset:
4613 reg = LEB (); LEB ();
4614 if (frame_need_space (fc, reg) >= 0)
4615 fc->col_type[reg] = DW_CFA_undefined;
4616 break;
4617 case DW_CFA_restore_extended:
4618 reg = LEB ();
4619 frame_need_space (fc, reg);
4620 if (frame_need_space (fc, reg) >= 0)
4621 fc->col_type[reg] = DW_CFA_undefined;
4622 break;
4623 case DW_CFA_undefined:
4624 reg = LEB ();
4625 if (frame_need_space (fc, reg) >= 0)
4626 fc->col_type[reg] = DW_CFA_undefined;
4627 break;
4628 case DW_CFA_same_value:
4629 reg = LEB ();
4630 if (frame_need_space (fc, reg) >= 0)
4631 fc->col_type[reg] = DW_CFA_undefined;
4632 break;
4633 case DW_CFA_register:
4634 reg = LEB (); LEB ();
4635 if (frame_need_space (fc, reg) >= 0)
4636 fc->col_type[reg] = DW_CFA_undefined;
4637 break;
4638 case DW_CFA_def_cfa:
4639 LEB (); LEB ();
4640 break;
4641 case DW_CFA_def_cfa_register:
4642 LEB ();
4643 break;
4644 case DW_CFA_def_cfa_offset:
4645 LEB ();
4646 break;
4647 case DW_CFA_def_cfa_expression:
4648 temp = LEB ();
4649 start += temp;
4650 break;
4651 case DW_CFA_expression:
4652 case DW_CFA_val_expression:
4653 reg = LEB ();
4654 temp = LEB ();
4655 start += temp;
4656 if (frame_need_space (fc, reg) >= 0)
4657 fc->col_type[reg] = DW_CFA_undefined;
4658 break;
4659 case DW_CFA_offset_extended_sf:
4660 case DW_CFA_val_offset_sf:
4661 reg = LEB (); SLEB ();
4662 if (frame_need_space (fc, reg) >= 0)
4663 fc->col_type[reg] = DW_CFA_undefined;
4664 break;
4665 case DW_CFA_def_cfa_sf:
4666 LEB (); SLEB ();
4667 break;
4668 case DW_CFA_def_cfa_offset_sf:
4669 SLEB ();
4670 break;
4671 case DW_CFA_MIPS_advance_loc8:
4672 start += 8;
4673 break;
4674 case DW_CFA_GNU_args_size:
4675 LEB ();
4676 break;
4677 case DW_CFA_GNU_negative_offset_extended:
4678 reg = LEB (); LEB ();
4679 if (frame_need_space (fc, reg) >= 0)
4680 fc->col_type[reg] = DW_CFA_undefined;
4681 break;
4682 default:
4683 break;
4684 }
4685 }
4686 start = tmp;
4687 }
4688
4689 /* Now we know what registers are used, make a second pass over
4690 the chunk, this time actually printing out the info. */
4691
4692 while (start < block_end)
4693 {
4694 unsigned op, opa;
4695 unsigned long ul, reg, roffs;
4696 long l, ofs;
4697 dwarf_vma vma;
4698 const char *reg_prefix = "";
4699
4700 op = *start++;
4701 opa = op & 0x3f;
4702 if (op & 0xc0)
4703 op &= 0xc0;
4704
4705 /* Warning: if you add any more cases to this switch, be
4706 sure to add them to the corresponding switch above. */
4707 switch (op)
4708 {
4709 case DW_CFA_advance_loc:
4710 if (do_debug_frames_interp)
4711 frame_display_row (fc, &need_col_headers, &max_regs);
4712 else
4713 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4714 opa * fc->code_factor,
4715 fc->pc_begin + opa * fc->code_factor);
4716 fc->pc_begin += opa * fc->code_factor;
4717 break;
4718
4719 case DW_CFA_offset:
4720 roffs = LEB ();
4721 if (opa >= (unsigned int) fc->ncols)
4722 reg_prefix = bad_reg;
4723 if (! do_debug_frames_interp || *reg_prefix != '\0')
4724 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4725 reg_prefix, regname (opa, 0),
4726 roffs * fc->data_factor);
4727 if (*reg_prefix == '\0')
4728 {
4729 fc->col_type[opa] = DW_CFA_offset;
4730 fc->col_offset[opa] = roffs * fc->data_factor;
4731 }
4732 break;
4733
4734 case DW_CFA_restore:
4735 if (opa >= (unsigned int) cie->ncols
4736 || opa >= (unsigned int) fc->ncols)
4737 reg_prefix = bad_reg;
4738 if (! do_debug_frames_interp || *reg_prefix != '\0')
4739 printf (" DW_CFA_restore: %s%s\n",
4740 reg_prefix, regname (opa, 0));
4741 if (*reg_prefix == '\0')
4742 {
4743 fc->col_type[opa] = cie->col_type[opa];
4744 fc->col_offset[opa] = cie->col_offset[opa];
4745 }
4746 break;
4747
4748 case DW_CFA_set_loc:
4749 vma = get_encoded_value (start, fc->fde_encoding, section);
4750 start += encoded_ptr_size;
4751 if (do_debug_frames_interp)
4752 frame_display_row (fc, &need_col_headers, &max_regs);
4753 else
4754 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
4755 fc->pc_begin = vma;
4756 break;
4757
4758 case DW_CFA_advance_loc1:
4759 ofs = byte_get (start, 1); start += 1;
4760 if (do_debug_frames_interp)
4761 frame_display_row (fc, &need_col_headers, &max_regs);
4762 else
4763 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4764 ofs * fc->code_factor,
4765 fc->pc_begin + ofs * fc->code_factor);
4766 fc->pc_begin += ofs * fc->code_factor;
4767 break;
4768
4769 case DW_CFA_advance_loc2:
4770 ofs = byte_get (start, 2); start += 2;
4771 if (do_debug_frames_interp)
4772 frame_display_row (fc, &need_col_headers, &max_regs);
4773 else
4774 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4775 ofs * fc->code_factor,
4776 fc->pc_begin + ofs * fc->code_factor);
4777 fc->pc_begin += ofs * fc->code_factor;
4778 break;
4779
4780 case DW_CFA_advance_loc4:
4781 ofs = byte_get (start, 4); start += 4;
4782 if (do_debug_frames_interp)
4783 frame_display_row (fc, &need_col_headers, &max_regs);
4784 else
4785 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4786 ofs * fc->code_factor,
4787 fc->pc_begin + ofs * fc->code_factor);
4788 fc->pc_begin += ofs * fc->code_factor;
4789 break;
4790
4791 case DW_CFA_offset_extended:
4792 reg = LEB ();
4793 roffs = LEB ();
4794 if (reg >= (unsigned int) fc->ncols)
4795 reg_prefix = bad_reg;
4796 if (! do_debug_frames_interp || *reg_prefix != '\0')
4797 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
4798 reg_prefix, regname (reg, 0),
4799 roffs * fc->data_factor);
4800 if (*reg_prefix == '\0')
4801 {
4802 fc->col_type[reg] = DW_CFA_offset;
4803 fc->col_offset[reg] = roffs * fc->data_factor;
4804 }
4805 break;
4806
4807 case DW_CFA_val_offset:
4808 reg = LEB ();
4809 roffs = LEB ();
4810 if (reg >= (unsigned int) fc->ncols)
4811 reg_prefix = bad_reg;
4812 if (! do_debug_frames_interp || *reg_prefix != '\0')
4813 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4814 reg_prefix, regname (reg, 0),
4815 roffs * fc->data_factor);
4816 if (*reg_prefix == '\0')
4817 {
4818 fc->col_type[reg] = DW_CFA_val_offset;
4819 fc->col_offset[reg] = roffs * fc->data_factor;
4820 }
4821 break;
4822
4823 case DW_CFA_restore_extended:
4824 reg = LEB ();
4825 if (reg >= (unsigned int) cie->ncols
4826 || reg >= (unsigned int) fc->ncols)
4827 reg_prefix = bad_reg;
4828 if (! do_debug_frames_interp || *reg_prefix != '\0')
4829 printf (" DW_CFA_restore_extended: %s%s\n",
4830 reg_prefix, regname (reg, 0));
4831 if (*reg_prefix == '\0')
4832 {
4833 fc->col_type[reg] = cie->col_type[reg];
4834 fc->col_offset[reg] = cie->col_offset[reg];
4835 }
4836 break;
4837
4838 case DW_CFA_undefined:
4839 reg = LEB ();
4840 if (reg >= (unsigned int) fc->ncols)
4841 reg_prefix = bad_reg;
4842 if (! do_debug_frames_interp || *reg_prefix != '\0')
4843 printf (" DW_CFA_undefined: %s%s\n",
4844 reg_prefix, regname (reg, 0));
4845 if (*reg_prefix == '\0')
4846 {
4847 fc->col_type[reg] = DW_CFA_undefined;
4848 fc->col_offset[reg] = 0;
4849 }
4850 break;
4851
4852 case DW_CFA_same_value:
4853 reg = LEB ();
4854 if (reg >= (unsigned int) fc->ncols)
4855 reg_prefix = bad_reg;
4856 if (! do_debug_frames_interp || *reg_prefix != '\0')
4857 printf (" DW_CFA_same_value: %s%s\n",
4858 reg_prefix, regname (reg, 0));
4859 if (*reg_prefix == '\0')
4860 {
4861 fc->col_type[reg] = DW_CFA_same_value;
4862 fc->col_offset[reg] = 0;
4863 }
4864 break;
4865
4866 case DW_CFA_register:
4867 reg = LEB ();
4868 roffs = LEB ();
4869 if (reg >= (unsigned int) fc->ncols)
4870 reg_prefix = bad_reg;
4871 if (! do_debug_frames_interp || *reg_prefix != '\0')
4872 {
4873 printf (" DW_CFA_register: %s%s in ",
4874 reg_prefix, regname (reg, 0));
4875 puts (regname (roffs, 0));
4876 }
4877 if (*reg_prefix == '\0')
4878 {
4879 fc->col_type[reg] = DW_CFA_register;
4880 fc->col_offset[reg] = roffs;
4881 }
4882 break;
4883
4884 case DW_CFA_remember_state:
4885 if (! do_debug_frames_interp)
4886 printf (" DW_CFA_remember_state\n");
4887 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4888 rs->ncols = fc->ncols;
4889 rs->col_type = (short int *) xcmalloc (rs->ncols,
4890 sizeof (short int));
4891 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int));
4892 memcpy (rs->col_type, fc->col_type, rs->ncols);
4893 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
4894 rs->next = remembered_state;
4895 remembered_state = rs;
4896 break;
4897
4898 case DW_CFA_restore_state:
4899 if (! do_debug_frames_interp)
4900 printf (" DW_CFA_restore_state\n");
4901 rs = remembered_state;
4902 if (rs)
4903 {
4904 remembered_state = rs->next;
4905 frame_need_space (fc, rs->ncols - 1);
4906 memcpy (fc->col_type, rs->col_type, rs->ncols);
4907 memcpy (fc->col_offset, rs->col_offset,
4908 rs->ncols * sizeof (int));
4909 free (rs->col_type);
4910 free (rs->col_offset);
4911 free (rs);
4912 }
4913 else if (do_debug_frames_interp)
4914 printf ("Mismatched DW_CFA_restore_state\n");
4915 break;
4916
4917 case DW_CFA_def_cfa:
4918 fc->cfa_reg = LEB ();
4919 fc->cfa_offset = LEB ();
4920 fc->cfa_exp = 0;
4921 if (! do_debug_frames_interp)
4922 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4923 regname (fc->cfa_reg, 0), fc->cfa_offset);
4924 break;
4925
4926 case DW_CFA_def_cfa_register:
4927 fc->cfa_reg = LEB ();
4928 fc->cfa_exp = 0;
4929 if (! do_debug_frames_interp)
4930 printf (" DW_CFA_def_cfa_register: %s\n",
4931 regname (fc->cfa_reg, 0));
4932 break;
4933
4934 case DW_CFA_def_cfa_offset:
4935 fc->cfa_offset = LEB ();
4936 if (! do_debug_frames_interp)
4937 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
4938 break;
4939
4940 case DW_CFA_nop:
4941 if (! do_debug_frames_interp)
4942 printf (" DW_CFA_nop\n");
4943 break;
4944
4945 case DW_CFA_def_cfa_expression:
4946 ul = LEB ();
4947 if (! do_debug_frames_interp)
4948 {
4949 printf (" DW_CFA_def_cfa_expression (");
4950 decode_location_expression (start, eh_addr_size, 0, -1,
4951 ul, 0, section);
4952 printf (")\n");
4953 }
4954 fc->cfa_exp = 1;
4955 start += ul;
4956 break;
4957
4958 case DW_CFA_expression:
4959 reg = LEB ();
4960 ul = LEB ();
4961 if (reg >= (unsigned int) fc->ncols)
4962 reg_prefix = bad_reg;
4963 if (! do_debug_frames_interp || *reg_prefix != '\0')
4964 {
4965 printf (" DW_CFA_expression: %s%s (",
4966 reg_prefix, regname (reg, 0));
4967 decode_location_expression (start, eh_addr_size, 0, -1,
4968 ul, 0, section);
4969 printf (")\n");
4970 }
4971 if (*reg_prefix == '\0')
4972 fc->col_type[reg] = DW_CFA_expression;
4973 start += ul;
4974 break;
4975
4976 case DW_CFA_val_expression:
4977 reg = LEB ();
4978 ul = LEB ();
4979 if (reg >= (unsigned int) fc->ncols)
4980 reg_prefix = bad_reg;
4981 if (! do_debug_frames_interp || *reg_prefix != '\0')
4982 {
4983 printf (" DW_CFA_val_expression: %s%s (",
4984 reg_prefix, regname (reg, 0));
4985 decode_location_expression (start, eh_addr_size, 0, -1,
4986 ul, 0, section);
4987 printf (")\n");
4988 }
4989 if (*reg_prefix == '\0')
4990 fc->col_type[reg] = DW_CFA_val_expression;
4991 start += ul;
4992 break;
4993
4994 case DW_CFA_offset_extended_sf:
4995 reg = LEB ();
4996 l = SLEB ();
4997 if (frame_need_space (fc, reg) < 0)
4998 reg_prefix = bad_reg;
4999 if (! do_debug_frames_interp || *reg_prefix != '\0')
5000 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5001 reg_prefix, regname (reg, 0),
5002 l * fc->data_factor);
5003 if (*reg_prefix == '\0')
5004 {
5005 fc->col_type[reg] = DW_CFA_offset;
5006 fc->col_offset[reg] = l * fc->data_factor;
5007 }
5008 break;
5009
5010 case DW_CFA_val_offset_sf:
5011 reg = LEB ();
5012 l = SLEB ();
5013 if (frame_need_space (fc, reg) < 0)
5014 reg_prefix = bad_reg;
5015 if (! do_debug_frames_interp || *reg_prefix != '\0')
5016 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5017 reg_prefix, regname (reg, 0),
5018 l * fc->data_factor);
5019 if (*reg_prefix == '\0')
5020 {
5021 fc->col_type[reg] = DW_CFA_val_offset;
5022 fc->col_offset[reg] = l * fc->data_factor;
5023 }
5024 break;
5025
5026 case DW_CFA_def_cfa_sf:
5027 fc->cfa_reg = LEB ();
5028 fc->cfa_offset = SLEB ();
5029 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5030 fc->cfa_exp = 0;
5031 if (! do_debug_frames_interp)
5032 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5033 regname (fc->cfa_reg, 0), fc->cfa_offset);
5034 break;
5035
5036 case DW_CFA_def_cfa_offset_sf:
5037 fc->cfa_offset = SLEB ();
5038 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5039 if (! do_debug_frames_interp)
5040 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
5041 break;
5042
5043 case DW_CFA_MIPS_advance_loc8:
5044 ofs = byte_get (start, 8); start += 8;
5045 if (do_debug_frames_interp)
5046 frame_display_row (fc, &need_col_headers, &max_regs);
5047 else
5048 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5049 ofs * fc->code_factor,
5050 fc->pc_begin + ofs * fc->code_factor);
5051 fc->pc_begin += ofs * fc->code_factor;
5052 break;
5053
5054 case DW_CFA_GNU_window_save:
5055 if (! do_debug_frames_interp)
5056 printf (" DW_CFA_GNU_window_save\n");
5057 break;
5058
5059 case DW_CFA_GNU_args_size:
5060 ul = LEB ();
5061 if (! do_debug_frames_interp)
5062 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
5063 break;
5064
5065 case DW_CFA_GNU_negative_offset_extended:
5066 reg = LEB ();
5067 l = - LEB ();
5068 if (frame_need_space (fc, reg) < 0)
5069 reg_prefix = bad_reg;
5070 if (! do_debug_frames_interp || *reg_prefix != '\0')
5071 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5072 reg_prefix, regname (reg, 0),
5073 l * fc->data_factor);
5074 if (*reg_prefix == '\0')
5075 {
5076 fc->col_type[reg] = DW_CFA_offset;
5077 fc->col_offset[reg] = l * fc->data_factor;
5078 }
5079 break;
5080
5081 default:
5082 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
5083 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
5084 else
5085 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
5086 start = block_end;
5087 }
5088 }
5089
5090 if (do_debug_frames_interp)
5091 frame_display_row (fc, &need_col_headers, &max_regs);
5092
5093 start = block_end;
5094 eh_addr_size = saved_eh_addr_size;
5095 }
5096
5097 printf ("\n");
5098
5099 return 1;
5100 }
5101
5102 #undef GET
5103 #undef LEB
5104 #undef SLEB
5105
5106 static int
5107 display_gdb_index (struct dwarf_section *section,
5108 void *file ATTRIBUTE_UNUSED)
5109 {
5110 unsigned char *start = section->start;
5111 uint32_t version;
5112 uint32_t cu_list_offset, tu_list_offset;
5113 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
5114 unsigned int cu_list_elements, tu_list_elements;
5115 unsigned int address_table_size, symbol_table_slots;
5116 unsigned char *cu_list, *tu_list;
5117 unsigned char *address_table, *symbol_table, *constant_pool;
5118 unsigned int i;
5119
5120 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5121
5122 printf (_("Contents of the %s section:\n"), section->name);
5123
5124 if (section->size < 6 * sizeof (uint32_t))
5125 {
5126 warn (_("Truncated header in the %s section.\n"), section->name);
5127 return 0;
5128 }
5129
5130 version = byte_get_little_endian (start, 4);
5131 printf (_("Version %ld\n"), (long) version);
5132
5133 /* Prior versions are obsolete, and future versions may not be
5134 backwards compatible. */
5135 switch (version)
5136 {
5137 case 3:
5138 warn (_("The address table data in version 3 may be wrong.\n"));
5139 break;
5140 case 4:
5141 warn (_("Version 4 does not support case insensitive lookups.\n"));
5142 break;
5143 case 5:
5144 break;
5145 default:
5146 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
5147 return 0;
5148 }
5149
5150 cu_list_offset = byte_get_little_endian (start + 4, 4);
5151 tu_list_offset = byte_get_little_endian (start + 8, 4);
5152 address_table_offset = byte_get_little_endian (start + 12, 4);
5153 symbol_table_offset = byte_get_little_endian (start + 16, 4);
5154 constant_pool_offset = byte_get_little_endian (start + 20, 4);
5155
5156 if (cu_list_offset > section->size
5157 || tu_list_offset > section->size
5158 || address_table_offset > section->size
5159 || symbol_table_offset > section->size
5160 || constant_pool_offset > section->size)
5161 {
5162 warn (_("Corrupt header in the %s section.\n"), section->name);
5163 return 0;
5164 }
5165
5166 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
5167 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
5168 address_table_size = symbol_table_offset - address_table_offset;
5169 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
5170
5171 cu_list = start + cu_list_offset;
5172 tu_list = start + tu_list_offset;
5173 address_table = start + address_table_offset;
5174 symbol_table = start + symbol_table_offset;
5175 constant_pool = start + constant_pool_offset;
5176
5177 printf (_("\nCU table:\n"));
5178 for (i = 0; i < cu_list_elements; i += 2)
5179 {
5180 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
5181 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
5182
5183 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
5184 (unsigned long) cu_offset,
5185 (unsigned long) (cu_offset + cu_length - 1));
5186 }
5187
5188 printf (_("\nTU table:\n"));
5189 for (i = 0; i < tu_list_elements; i += 3)
5190 {
5191 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
5192 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
5193 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
5194
5195 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
5196 (unsigned long) tu_offset,
5197 (unsigned long) type_offset);
5198 print_dwarf_vma (signature, 8);
5199 printf ("\n");
5200 }
5201
5202 printf (_("\nAddress table:\n"));
5203 for (i = 0; i < address_table_size; i += 2 * 8 + 4)
5204 {
5205 uint64_t low = byte_get_little_endian (address_table + i, 8);
5206 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
5207 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
5208
5209 print_dwarf_vma (low, 8);
5210 print_dwarf_vma (high, 8);
5211 printf (_("%lu\n"), (unsigned long) cu_index);
5212 }
5213
5214 printf (_("\nSymbol table:\n"));
5215 for (i = 0; i < symbol_table_slots; ++i)
5216 {
5217 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
5218 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
5219 uint32_t num_cus, cu;
5220
5221 if (name_offset != 0
5222 || cu_vector_offset != 0)
5223 {
5224 unsigned int j;
5225
5226 printf ("[%3u] %s:", i, constant_pool + name_offset);
5227 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
5228 for (j = 0; j < num_cus; ++j)
5229 {
5230 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
5231 /* Convert to TU number if it's for a type unit. */
5232 if (cu >= cu_list_elements)
5233 printf (" T%lu", (unsigned long) (cu - cu_list_elements));
5234 else
5235 printf (" %lu", (unsigned long) cu);
5236 }
5237 printf ("\n");
5238 }
5239 }
5240
5241 return 1;
5242 }
5243
5244 static int
5245 display_debug_not_supported (struct dwarf_section *section,
5246 void *file ATTRIBUTE_UNUSED)
5247 {
5248 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5249 section->name);
5250
5251 return 1;
5252 }
5253
5254 void *
5255 cmalloc (size_t nmemb, size_t size)
5256 {
5257 /* Check for overflow. */
5258 if (nmemb >= ~(size_t) 0 / size)
5259 return NULL;
5260 else
5261 return malloc (nmemb * size);
5262 }
5263
5264 void *
5265 xcmalloc (size_t nmemb, size_t size)
5266 {
5267 /* Check for overflow. */
5268 if (nmemb >= ~(size_t) 0 / size)
5269 return NULL;
5270 else
5271 return xmalloc (nmemb * size);
5272 }
5273
5274 void *
5275 xcrealloc (void *ptr, size_t nmemb, size_t size)
5276 {
5277 /* Check for overflow. */
5278 if (nmemb >= ~(size_t) 0 / size)
5279 return NULL;
5280 else
5281 return xrealloc (ptr, nmemb * size);
5282 }
5283
5284 void
5285 free_debug_memory (void)
5286 {
5287 unsigned int i;
5288
5289 free_abbrevs ();
5290
5291 for (i = 0; i < max; i++)
5292 free_debug_section ((enum dwarf_section_display_enum) i);
5293
5294 if (debug_information != NULL)
5295 {
5296 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
5297 {
5298 for (i = 0; i < num_debug_info_entries; i++)
5299 {
5300 if (!debug_information [i].max_loc_offsets)
5301 {
5302 free (debug_information [i].loc_offsets);
5303 free (debug_information [i].have_frame_base);
5304 }
5305 if (!debug_information [i].max_range_lists)
5306 free (debug_information [i].range_lists);
5307 }
5308 }
5309
5310 free (debug_information);
5311 debug_information = NULL;
5312 num_debug_info_entries = 0;
5313 }
5314 }
5315
5316 void
5317 dwarf_select_sections_by_names (const char *names)
5318 {
5319 typedef struct
5320 {
5321 const char * option;
5322 int * variable;
5323 int val;
5324 }
5325 debug_dump_long_opts;
5326
5327 static const debug_dump_long_opts opts_table [] =
5328 {
5329 /* Please keep this table alpha- sorted. */
5330 { "Ranges", & do_debug_ranges, 1 },
5331 { "abbrev", & do_debug_abbrevs, 1 },
5332 { "aranges", & do_debug_aranges, 1 },
5333 { "frames", & do_debug_frames, 1 },
5334 { "frames-interp", & do_debug_frames_interp, 1 },
5335 { "info", & do_debug_info, 1 },
5336 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
5337 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
5338 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
5339 { "loc", & do_debug_loc, 1 },
5340 { "macro", & do_debug_macinfo, 1 },
5341 { "pubnames", & do_debug_pubnames, 1 },
5342 { "pubtypes", & do_debug_pubtypes, 1 },
5343 /* This entry is for compatability
5344 with earlier versions of readelf. */
5345 { "ranges", & do_debug_aranges, 1 },
5346 { "str", & do_debug_str, 1 },
5347 /* The special .gdb_index section. */
5348 { "gdb_index", & do_gdb_index, 1 },
5349 /* These trace_* sections are used by Itanium VMS. */
5350 { "trace_abbrev", & do_trace_abbrevs, 1 },
5351 { "trace_aranges", & do_trace_aranges, 1 },
5352 { "trace_info", & do_trace_info, 1 },
5353 { NULL, NULL, 0 }
5354 };
5355
5356 const char *p;
5357
5358 p = names;
5359 while (*p)
5360 {
5361 const debug_dump_long_opts * entry;
5362
5363 for (entry = opts_table; entry->option; entry++)
5364 {
5365 size_t len = strlen (entry->option);
5366
5367 if (strncmp (p, entry->option, len) == 0
5368 && (p[len] == ',' || p[len] == '\0'))
5369 {
5370 * entry->variable |= entry->val;
5371
5372 /* The --debug-dump=frames-interp option also
5373 enables the --debug-dump=frames option. */
5374 if (do_debug_frames_interp)
5375 do_debug_frames = 1;
5376
5377 p += len;
5378 break;
5379 }
5380 }
5381
5382 if (entry->option == NULL)
5383 {
5384 warn (_("Unrecognized debug option '%s'\n"), p);
5385 p = strchr (p, ',');
5386 if (p == NULL)
5387 break;
5388 }
5389
5390 if (*p == ',')
5391 p++;
5392 }
5393 }
5394
5395 void
5396 dwarf_select_sections_by_letters (const char *letters)
5397 {
5398 unsigned int lindex = 0;
5399
5400 while (letters[lindex])
5401 switch (letters[lindex++])
5402 {
5403 case 'i':
5404 do_debug_info = 1;
5405 break;
5406
5407 case 'a':
5408 do_debug_abbrevs = 1;
5409 break;
5410
5411 case 'l':
5412 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
5413 break;
5414
5415 case 'L':
5416 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
5417 break;
5418
5419 case 'p':
5420 do_debug_pubnames = 1;
5421 break;
5422
5423 case 't':
5424 do_debug_pubtypes = 1;
5425 break;
5426
5427 case 'r':
5428 do_debug_aranges = 1;
5429 break;
5430
5431 case 'R':
5432 do_debug_ranges = 1;
5433 break;
5434
5435 case 'F':
5436 do_debug_frames_interp = 1;
5437 case 'f':
5438 do_debug_frames = 1;
5439 break;
5440
5441 case 'm':
5442 do_debug_macinfo = 1;
5443 break;
5444
5445 case 's':
5446 do_debug_str = 1;
5447 break;
5448
5449 case 'o':
5450 do_debug_loc = 1;
5451 break;
5452
5453 default:
5454 warn (_("Unrecognized debug option '%s'\n"), optarg);
5455 break;
5456 }
5457 }
5458
5459 void
5460 dwarf_select_sections_all (void)
5461 {
5462 do_debug_info = 1;
5463 do_debug_abbrevs = 1;
5464 do_debug_lines = FLAG_DEBUG_LINES_RAW;
5465 do_debug_pubnames = 1;
5466 do_debug_pubtypes = 1;
5467 do_debug_aranges = 1;
5468 do_debug_ranges = 1;
5469 do_debug_frames = 1;
5470 do_debug_macinfo = 1;
5471 do_debug_str = 1;
5472 do_debug_loc = 1;
5473 do_gdb_index = 1;
5474 do_trace_info = 1;
5475 do_trace_abbrevs = 1;
5476 do_trace_aranges = 1;
5477 }
5478
5479 struct dwarf_section_display debug_displays[] =
5480 {
5481 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0 },
5482 display_debug_abbrev, &do_debug_abbrevs, 0 },
5483 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0 },
5484 display_debug_aranges, &do_debug_aranges, 1 },
5485 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0 },
5486 display_debug_frames, &do_debug_frames, 1 },
5487 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0 },
5488 display_debug_info, &do_debug_info, 1 },
5489 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0 },
5490 display_debug_lines, &do_debug_lines, 1 },
5491 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0 },
5492 display_debug_pubnames, &do_debug_pubnames, 0 },
5493 { { ".eh_frame", "", NULL, NULL, 0, 0 },
5494 display_debug_frames, &do_debug_frames, 1 },
5495 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0 },
5496 display_debug_macinfo, &do_debug_macinfo, 0 },
5497 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0 },
5498 display_debug_str, &do_debug_str, 0 },
5499 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0 },
5500 display_debug_loc, &do_debug_loc, 1 },
5501 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0 },
5502 display_debug_pubnames, &do_debug_pubtypes, 0 },
5503 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0 },
5504 display_debug_ranges, &do_debug_ranges, 1 },
5505 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0 },
5506 display_debug_not_supported, NULL, 0 },
5507 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0 },
5508 display_debug_not_supported, NULL, 0 },
5509 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0 },
5510 display_debug_types, &do_debug_info, 1 },
5511 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0 },
5512 display_debug_not_supported, NULL, 0 },
5513 { { ".gdb_index", "", NULL, NULL, 0, 0 },
5514 display_gdb_index, &do_gdb_index, 0 },
5515 { { ".trace_info", "", NULL, NULL, 0, 0 },
5516 display_trace_info, &do_trace_info, 1 },
5517 { { ".trace_abbrev", "", NULL, NULL, 0, 0 },
5518 display_debug_abbrev, &do_trace_abbrevs, 0 },
5519 { { ".trace_aranges", "", NULL, NULL, 0, 0 },
5520 display_debug_aranges, &do_trace_aranges, 0 }
5521 };
This page took 0.148106 seconds and 4 git commands to generate.