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