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