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