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