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