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