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