*** 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;
aae628c1
CC
1195 case DW_OP_GNU_const_index:
1196 uvalue = read_leb128 (data, &bytes_read, 0);
1197 data += bytes_read;
1198 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1199 break;
e2a0d921
NC
1200
1201 /* HP extensions. */
1202 case DW_OP_HP_is_value:
1203 printf ("DW_OP_HP_is_value");
1204 /* FIXME: Is there data associated with this OP ? */
1205 break;
1206 case DW_OP_HP_fltconst4:
1207 printf ("DW_OP_HP_fltconst4");
1208 /* FIXME: Is there data associated with this OP ? */
1209 break;
1210 case DW_OP_HP_fltconst8:
1211 printf ("DW_OP_HP_fltconst8");
1212 /* FIXME: Is there data associated with this OP ? */
1213 break;
1214 case DW_OP_HP_mod_range:
1215 printf ("DW_OP_HP_mod_range");
1216 /* FIXME: Is there data associated with this OP ? */
1217 break;
1218 case DW_OP_HP_unmod_range:
1219 printf ("DW_OP_HP_unmod_range");
1220 /* FIXME: Is there data associated with this OP ? */
1221 break;
1222 case DW_OP_HP_tls:
1223 printf ("DW_OP_HP_tls");
1224 /* FIXME: Is there data associated with this OP ? */
19e6b90e
L
1225 break;
1226
35d60fe4
NC
1227 /* PGI (STMicroelectronics) extensions. */
1228 case DW_OP_PGI_omp_thread_num:
1229 /* Pushes the thread number for the current thread as it would be
1230 returned by the standard OpenMP library function:
1231 omp_get_thread_num(). The "current thread" is the thread for
1232 which the expression is being evaluated. */
1233 printf ("DW_OP_PGI_omp_thread_num");
1234 break;
1235
19e6b90e
L
1236 default:
1237 if (op >= DW_OP_lo_user
1238 && op <= DW_OP_hi_user)
1239 printf (_("(User defined location op)"));
1240 else
1241 printf (_("(Unknown location op)"));
1242 /* No way to tell where the next op is, so just bail. */
1243 return need_frame_base;
1244 }
1245
1246 /* Separate the ops. */
1247 if (data < end)
1248 printf ("; ");
1249 }
1250
1251 return need_frame_base;
1252}
1253
1254static unsigned char *
6e3d6dc1
NC
1255read_and_display_attr_value (unsigned long attribute,
1256 unsigned long form,
ec4d4525 1257 unsigned char * data,
467c65bc
NC
1258 dwarf_vma cu_offset,
1259 dwarf_vma pointer_size,
1260 dwarf_vma offset_size,
6e3d6dc1
NC
1261 int dwarf_version,
1262 debug_info * debug_info_p,
1263 int do_loc,
1264 struct dwarf_section * section)
19e6b90e 1265{
467c65bc 1266 dwarf_vma uvalue = 0;
19e6b90e 1267 unsigned char *block_start = NULL;
6e3d6dc1 1268 unsigned char * orig_data = data;
19e6b90e
L
1269 unsigned int bytes_read;
1270
1271 switch (form)
1272 {
1273 default:
1274 break;
1275
1276 case DW_FORM_ref_addr:
1277 if (dwarf_version == 2)
1278 {
1279 uvalue = byte_get (data, pointer_size);
1280 data += pointer_size;
1281 }
932fd279 1282 else if (dwarf_version == 3 || dwarf_version == 4)
19e6b90e
L
1283 {
1284 uvalue = byte_get (data, offset_size);
1285 data += offset_size;
1286 }
1287 else
467c65bc
NC
1288 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1289
19e6b90e
L
1290 break;
1291
1292 case DW_FORM_addr:
1293 uvalue = byte_get (data, pointer_size);
1294 data += pointer_size;
1295 break;
1296
1297 case DW_FORM_strp:
932fd279 1298 case DW_FORM_sec_offset:
a081f3cd
JJ
1299 case DW_FORM_GNU_ref_alt:
1300 case DW_FORM_GNU_strp_alt:
19e6b90e
L
1301 uvalue = byte_get (data, offset_size);
1302 data += offset_size;
1303 break;
1304
932fd279
JJ
1305 case DW_FORM_flag_present:
1306 uvalue = 1;
1307 break;
1308
19e6b90e
L
1309 case DW_FORM_ref1:
1310 case DW_FORM_flag:
1311 case DW_FORM_data1:
1312 uvalue = byte_get (data++, 1);
1313 break;
1314
1315 case DW_FORM_ref2:
1316 case DW_FORM_data2:
1317 uvalue = byte_get (data, 2);
1318 data += 2;
1319 break;
1320
1321 case DW_FORM_ref4:
1322 case DW_FORM_data4:
1323 uvalue = byte_get (data, 4);
1324 data += 4;
1325 break;
1326
1327 case DW_FORM_sdata:
1328 uvalue = read_leb128 (data, & bytes_read, 1);
1329 data += bytes_read;
1330 break;
1331
4723351a
CC
1332 case DW_FORM_GNU_str_index:
1333 uvalue = read_leb128 (data, & bytes_read, 0);
1334 data += bytes_read;
1335 break;
1336
19e6b90e
L
1337 case DW_FORM_ref_udata:
1338 case DW_FORM_udata:
1339 uvalue = read_leb128 (data, & bytes_read, 0);
1340 data += bytes_read;
1341 break;
1342
1343 case DW_FORM_indirect:
1344 form = read_leb128 (data, & bytes_read, 0);
1345 data += bytes_read;
1346 if (!do_loc)
1347 printf (" %s", get_FORM_name (form));
1348 return read_and_display_attr_value (attribute, form, data,
1349 cu_offset, pointer_size,
1350 offset_size, dwarf_version,
ec4d4525 1351 debug_info_p, do_loc,
6e3d6dc1 1352 section);
4723351a
CC
1353 case DW_FORM_GNU_addr_index:
1354 uvalue = read_leb128 (data, & bytes_read, 0);
1355 data += bytes_read;
1356 break;
19e6b90e
L
1357 }
1358
1359 switch (form)
1360 {
1361 case DW_FORM_ref_addr:
1362 if (!do_loc)
467c65bc 1363 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue));
19e6b90e
L
1364 break;
1365
a081f3cd
JJ
1366 case DW_FORM_GNU_ref_alt:
1367 if (!do_loc)
1368 printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue));
1369 break;
1370
19e6b90e
L
1371 case DW_FORM_ref1:
1372 case DW_FORM_ref2:
1373 case DW_FORM_ref4:
1374 case DW_FORM_ref_udata:
1375 if (!do_loc)
467c65bc 1376 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset));
19e6b90e
L
1377 break;
1378
1379 case DW_FORM_data4:
1380 case DW_FORM_addr:
932fd279 1381 case DW_FORM_sec_offset:
19e6b90e 1382 if (!do_loc)
467c65bc 1383 printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
19e6b90e
L
1384 break;
1385
932fd279 1386 case DW_FORM_flag_present:
19e6b90e
L
1387 case DW_FORM_flag:
1388 case DW_FORM_data1:
1389 case DW_FORM_data2:
1390 case DW_FORM_sdata:
1391 case DW_FORM_udata:
1392 if (!do_loc)
467c65bc 1393 printf (" %s", dwarf_vmatoa ("d", uvalue));
19e6b90e
L
1394 break;
1395
1396 case DW_FORM_ref8:
1397 case DW_FORM_data8:
1398 if (!do_loc)
1399 {
74bc6052
CC
1400 dwarf_vma high_bits;
1401 char buf[64];
1402
1403 byte_get_64 (data, &high_bits, &uvalue);
1404 printf (" 0x%s",
1405 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
19e6b90e
L
1406 }
1407 if ((do_loc || do_debug_loc || do_debug_ranges)
1408 && num_debug_info_entries == 0)
1409 {
1410 if (sizeof (uvalue) == 8)
1411 uvalue = byte_get (data, 8);
1412 else
467c65bc 1413 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
19e6b90e
L
1414 }
1415 data += 8;
1416 break;
1417
1418 case DW_FORM_string:
1419 if (!do_loc)
1420 printf (" %s", data);
1421 data += strlen ((char *) data) + 1;
1422 break;
1423
1424 case DW_FORM_block:
932fd279 1425 case DW_FORM_exprloc:
19e6b90e
L
1426 uvalue = read_leb128 (data, & bytes_read, 0);
1427 block_start = data + bytes_read;
1428 if (do_loc)
1429 data = block_start + uvalue;
1430 else
1431 data = display_block (block_start, uvalue);
1432 break;
1433
1434 case DW_FORM_block1:
1435 uvalue = byte_get (data, 1);
1436 block_start = data + 1;
1437 if (do_loc)
1438 data = block_start + uvalue;
1439 else
1440 data = display_block (block_start, uvalue);
1441 break;
1442
1443 case DW_FORM_block2:
1444 uvalue = byte_get (data, 2);
1445 block_start = data + 2;
1446 if (do_loc)
1447 data = block_start + uvalue;
1448 else
1449 data = display_block (block_start, uvalue);
1450 break;
1451
1452 case DW_FORM_block4:
1453 uvalue = byte_get (data, 4);
1454 block_start = data + 4;
1455 if (do_loc)
1456 data = block_start + uvalue;
1457 else
1458 data = display_block (block_start, uvalue);
1459 break;
1460
1461 case DW_FORM_strp:
1462 if (!do_loc)
47704ddf
KT
1463 printf (_(" (indirect string, offset: 0x%s): %s"),
1464 dwarf_vmatoa ("x", uvalue),
1465 fetch_indirect_string (uvalue));
19e6b90e
L
1466 break;
1467
4723351a
CC
1468 case DW_FORM_GNU_str_index:
1469 if (!do_loc)
1470 {
1471 const char *suffix = strrchr (section->name, '.');
1472 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
1473
1474 printf (_(" (indexed string: 0x%s): %s"),
1475 dwarf_vmatoa ("x", uvalue),
1476 fetch_indexed_string (uvalue, offset_size, dwo));
1477 }
1478 break;
1479
a081f3cd
JJ
1480 case DW_FORM_GNU_strp_alt:
1481 if (!do_loc)
1482 printf (_(" (alt indirect string, offset: 0x%s)"),
1483 dwarf_vmatoa ("x", uvalue));
1484 break;
1485
19e6b90e
L
1486 case DW_FORM_indirect:
1487 /* Handled above. */
1488 break;
1489
2b6f5997
CC
1490 case DW_FORM_ref_sig8:
1491 if (!do_loc)
1492 {
74bc6052
CC
1493 dwarf_vma high_bits;
1494 char buf[64];
1495
1496 byte_get_64 (data, &high_bits, &uvalue);
1497 printf (" signature: 0x%s",
1498 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
2b6f5997 1499 }
74bc6052 1500 data += 8;
2b6f5997
CC
1501 break;
1502
4723351a
CC
1503 case DW_FORM_GNU_addr_index:
1504 if (!do_loc)
1505 printf (_(" (addr_index: 0x%s): %s"),
1506 dwarf_vmatoa ("x", uvalue),
1507 fetch_indexed_value (uvalue * pointer_size, pointer_size));
1508 break;
1509
19e6b90e
L
1510 default:
1511 warn (_("Unrecognized form: %lu\n"), form);
1512 break;
1513 }
1514
19e6b90e 1515 if ((do_loc || do_debug_loc || do_debug_ranges)
fd2f0033
TT
1516 && num_debug_info_entries == 0
1517 && debug_info_p != NULL)
19e6b90e
L
1518 {
1519 switch (attribute)
1520 {
1521 case DW_AT_frame_base:
1522 have_frame_base = 1;
1523 case DW_AT_location:
e2a0d921
NC
1524 case DW_AT_string_length:
1525 case DW_AT_return_addr:
19e6b90e
L
1526 case DW_AT_data_member_location:
1527 case DW_AT_vtable_elem_location:
e2a0d921
NC
1528 case DW_AT_segment:
1529 case DW_AT_static_link:
1530 case DW_AT_use_location:
629e7ca8
JJ
1531 case DW_AT_GNU_call_site_value:
1532 case DW_AT_GNU_call_site_data_value:
1533 case DW_AT_GNU_call_site_target:
1534 case DW_AT_GNU_call_site_target_clobbered:
212b6063
JK
1535 if ((dwarf_version < 4
1536 && (form == DW_FORM_data4 || form == DW_FORM_data8))
932fd279 1537 || form == DW_FORM_sec_offset)
19e6b90e
L
1538 {
1539 /* Process location list. */
91d6fa6a 1540 unsigned int lmax = debug_info_p->max_loc_offsets;
19e6b90e
L
1541 unsigned int num = debug_info_p->num_loc_offsets;
1542
91d6fa6a 1543 if (lmax == 0 || num >= lmax)
19e6b90e 1544 {
91d6fa6a 1545 lmax += 1024;
467c65bc 1546 debug_info_p->loc_offsets = (dwarf_vma *)
3f5e193b 1547 xcrealloc (debug_info_p->loc_offsets,
91d6fa6a 1548 lmax, sizeof (*debug_info_p->loc_offsets));
3f5e193b
NC
1549 debug_info_p->have_frame_base = (int *)
1550 xcrealloc (debug_info_p->have_frame_base,
91d6fa6a
NC
1551 lmax, sizeof (*debug_info_p->have_frame_base));
1552 debug_info_p->max_loc_offsets = lmax;
19e6b90e
L
1553 }
1554 debug_info_p->loc_offsets [num] = uvalue;
1555 debug_info_p->have_frame_base [num] = have_frame_base;
1556 debug_info_p->num_loc_offsets++;
1557 }
1558 break;
e2a0d921 1559
19e6b90e
L
1560 case DW_AT_low_pc:
1561 if (need_base_address)
1562 debug_info_p->base_address = uvalue;
1563 break;
1564
4723351a
CC
1565 case DW_AT_GNU_addr_base:
1566 debug_info_p->addr_base = uvalue;
1567 break;
1568
1569 case DW_AT_GNU_ranges_base:
1570 debug_info_p->ranges_base = uvalue;
1571 break;
1572
19e6b90e 1573 case DW_AT_ranges:
212b6063
JK
1574 if ((dwarf_version < 4
1575 && (form == DW_FORM_data4 || form == DW_FORM_data8))
932fd279 1576 || form == DW_FORM_sec_offset)
19e6b90e
L
1577 {
1578 /* Process range list. */
91d6fa6a 1579 unsigned int lmax = debug_info_p->max_range_lists;
19e6b90e
L
1580 unsigned int num = debug_info_p->num_range_lists;
1581
91d6fa6a 1582 if (lmax == 0 || num >= lmax)
19e6b90e 1583 {
91d6fa6a 1584 lmax += 1024;
467c65bc 1585 debug_info_p->range_lists = (dwarf_vma *)
3f5e193b 1586 xcrealloc (debug_info_p->range_lists,
91d6fa6a
NC
1587 lmax, sizeof (*debug_info_p->range_lists));
1588 debug_info_p->max_range_lists = lmax;
19e6b90e
L
1589 }
1590 debug_info_p->range_lists [num] = uvalue;
1591 debug_info_p->num_range_lists++;
1592 }
1593 break;
1594
1595 default:
1596 break;
1597 }
1598 }
1599
4ccf1e31 1600 if (do_loc || attribute == 0)
19e6b90e
L
1601 return data;
1602
ec4d4525 1603 /* For some attributes we can display further information. */
19e6b90e
L
1604 printf ("\t");
1605
1606 switch (attribute)
1607 {
1608 case DW_AT_inline:
1609 switch (uvalue)
1610 {
1611 case DW_INL_not_inlined:
1612 printf (_("(not inlined)"));
1613 break;
1614 case DW_INL_inlined:
1615 printf (_("(inlined)"));
1616 break;
1617 case DW_INL_declared_not_inlined:
1618 printf (_("(declared as inline but ignored)"));
1619 break;
1620 case DW_INL_declared_inlined:
1621 printf (_("(declared as inline and inlined)"));
1622 break;
1623 default:
47704ddf
KT
1624 printf (_(" (Unknown inline attribute value: %s)"),
1625 dwarf_vmatoa ("x", uvalue));
19e6b90e
L
1626 break;
1627 }
1628 break;
1629
1630 case DW_AT_language:
1631 switch (uvalue)
1632 {
4b78141a 1633 /* Ordered by the numeric value of these constants. */
19e6b90e 1634 case DW_LANG_C89: printf ("(ANSI C)"); break;
4b78141a
NC
1635 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1636 case DW_LANG_Ada83: printf ("(Ada)"); break;
19e6b90e 1637 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
4b78141a
NC
1638 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1639 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
19e6b90e
L
1640 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1641 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
19e6b90e 1642 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
4b78141a 1643 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
19e6b90e 1644 /* DWARF 2.1 values. */
4b78141a 1645 case DW_LANG_Java: printf ("(Java)"); break;
19e6b90e
L
1646 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1647 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1648 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
4b78141a
NC
1649 /* DWARF 3 values. */
1650 case DW_LANG_PLI: printf ("(PLI)"); break;
1651 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1652 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1653 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1654 case DW_LANG_D: printf ("(D)"); break;
2b6f5997
CC
1655 /* DWARF 4 values. */
1656 case DW_LANG_Python: printf ("(Python)"); break;
3362e0d9
ILT
1657 /* DWARF 5 values. */
1658 case DW_LANG_Go: printf ("(Go)"); break;
19e6b90e
L
1659 /* MIPS extension. */
1660 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1661 /* UPC extension. */
1662 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1663 default:
4b78141a 1664 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
9cf03b7e 1665 printf (_("(implementation defined: %s)"),
467c65bc 1666 dwarf_vmatoa ("x", uvalue));
4b78141a 1667 else
9cf03b7e 1668 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
19e6b90e
L
1669 break;
1670 }
1671 break;
1672
1673 case DW_AT_encoding:
1674 switch (uvalue)
1675 {
1676 case DW_ATE_void: printf ("(void)"); break;
1677 case DW_ATE_address: printf ("(machine address)"); break;
1678 case DW_ATE_boolean: printf ("(boolean)"); break;
1679 case DW_ATE_complex_float: printf ("(complex float)"); break;
1680 case DW_ATE_float: printf ("(float)"); break;
1681 case DW_ATE_signed: printf ("(signed)"); break;
1682 case DW_ATE_signed_char: printf ("(signed char)"); break;
1683 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1684 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
e2a0d921 1685 /* DWARF 2.1 values: */
19e6b90e
L
1686 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1687 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
e2a0d921
NC
1688 /* DWARF 3 values: */
1689 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1690 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1691 case DW_ATE_edited: printf ("(edited)"); break;
1692 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1693 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1694 /* HP extensions: */
1695 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1696 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1697 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1698 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1699 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1700 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1701 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1702
19e6b90e
L
1703 default:
1704 if (uvalue >= DW_ATE_lo_user
1705 && uvalue <= DW_ATE_hi_user)
9cf03b7e 1706 printf (_("(user defined type)"));
19e6b90e 1707 else
9cf03b7e 1708 printf (_("(unknown type)"));
19e6b90e
L
1709 break;
1710 }
1711 break;
1712
1713 case DW_AT_accessibility:
1714 switch (uvalue)
1715 {
1716 case DW_ACCESS_public: printf ("(public)"); break;
1717 case DW_ACCESS_protected: printf ("(protected)"); break;
1718 case DW_ACCESS_private: printf ("(private)"); break;
1719 default:
9cf03b7e 1720 printf (_("(unknown accessibility)"));
19e6b90e
L
1721 break;
1722 }
1723 break;
1724
1725 case DW_AT_visibility:
1726 switch (uvalue)
1727 {
1728 case DW_VIS_local: printf ("(local)"); break;
1729 case DW_VIS_exported: printf ("(exported)"); break;
1730 case DW_VIS_qualified: printf ("(qualified)"); break;
9cf03b7e 1731 default: printf (_("(unknown visibility)")); break;
19e6b90e
L
1732 }
1733 break;
1734
1735 case DW_AT_virtuality:
1736 switch (uvalue)
1737 {
1738 case DW_VIRTUALITY_none: printf ("(none)"); break;
1739 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1740 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
9cf03b7e 1741 default: printf (_("(unknown virtuality)")); break;
19e6b90e
L
1742 }
1743 break;
1744
1745 case DW_AT_identifier_case:
1746 switch (uvalue)
1747 {
1748 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1749 case DW_ID_up_case: printf ("(up_case)"); break;
1750 case DW_ID_down_case: printf ("(down_case)"); break;
1751 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
9cf03b7e 1752 default: printf (_("(unknown case)")); break;
19e6b90e
L
1753 }
1754 break;
1755
1756 case DW_AT_calling_convention:
1757 switch (uvalue)
1758 {
1759 case DW_CC_normal: printf ("(normal)"); break;
1760 case DW_CC_program: printf ("(program)"); break;
1761 case DW_CC_nocall: printf ("(nocall)"); break;
1762 default:
1763 if (uvalue >= DW_CC_lo_user
1764 && uvalue <= DW_CC_hi_user)
9cf03b7e 1765 printf (_("(user defined)"));
19e6b90e 1766 else
9cf03b7e 1767 printf (_("(unknown convention)"));
19e6b90e
L
1768 }
1769 break;
1770
1771 case DW_AT_ordering:
1772 switch (uvalue)
1773 {
9cf03b7e 1774 case -1: printf (_("(undefined)")); break;
19e6b90e
L
1775 case 0: printf ("(row major)"); break;
1776 case 1: printf ("(column major)"); break;
1777 }
1778 break;
1779
1780 case DW_AT_frame_base:
1781 have_frame_base = 1;
1782 case DW_AT_location:
e2a0d921
NC
1783 case DW_AT_string_length:
1784 case DW_AT_return_addr:
19e6b90e
L
1785 case DW_AT_data_member_location:
1786 case DW_AT_vtable_elem_location:
e2a0d921
NC
1787 case DW_AT_segment:
1788 case DW_AT_static_link:
1789 case DW_AT_use_location:
629e7ca8
JJ
1790 case DW_AT_GNU_call_site_value:
1791 case DW_AT_GNU_call_site_data_value:
1792 case DW_AT_GNU_call_site_target:
1793 case DW_AT_GNU_call_site_target_clobbered:
212b6063
JK
1794 if ((dwarf_version < 4
1795 && (form == DW_FORM_data4 || form == DW_FORM_data8))
932fd279 1796 || form == DW_FORM_sec_offset)
e2a0d921
NC
1797 printf (_("(location list)"));
1798 /* Fall through. */
19e6b90e
L
1799 case DW_AT_allocated:
1800 case DW_AT_associated:
1801 case DW_AT_data_location:
1802 case DW_AT_stride:
1803 case DW_AT_upper_bound:
cecf136e 1804 case DW_AT_lower_bound:
19e6b90e
L
1805 if (block_start)
1806 {
1807 int need_frame_base;
1808
1809 printf ("(");
1810 need_frame_base = decode_location_expression (block_start,
1811 pointer_size,
b7807392
JJ
1812 offset_size,
1813 dwarf_version,
19e6b90e 1814 uvalue,
f1c4cc75 1815 cu_offset, section);
19e6b90e
L
1816 printf (")");
1817 if (need_frame_base && !have_frame_base)
1818 printf (_(" [without DW_AT_frame_base]"));
1819 }
19e6b90e
L
1820 break;
1821
ec4d4525
NC
1822 case DW_AT_import:
1823 {
a081f3cd
JJ
1824 if (form == DW_FORM_ref_sig8
1825 || form == DW_FORM_GNU_ref_alt)
2b6f5997
CC
1826 break;
1827
ec4d4525
NC
1828 if (form == DW_FORM_ref1
1829 || form == DW_FORM_ref2
a7a0b6a5
JK
1830 || form == DW_FORM_ref4
1831 || form == DW_FORM_ref_udata)
ec4d4525
NC
1832 uvalue += cu_offset;
1833
6e3d6dc1 1834 if (uvalue >= section->size)
47704ddf
KT
1835 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1836 dwarf_vmatoa ("x", uvalue),
1837 (unsigned long) (orig_data - section->start));
6e3d6dc1
NC
1838 else
1839 {
1840 unsigned long abbrev_number;
1841 abbrev_entry * entry;
1842
1843 abbrev_number = read_leb128 (section->start + uvalue, NULL, 0);
cecf136e 1844
9cf03b7e 1845 printf (_("[Abbrev Number: %ld"), abbrev_number);
afd6e1ff
JJ
1846 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
1847 use different abbrev table, and we don't track .debug_info chunks
1848 yet. */
1849 if (form != DW_FORM_ref_addr)
1850 {
1851 for (entry = first_abbrev; entry != NULL; entry = entry->next)
1852 if (entry->entry == abbrev_number)
1853 break;
1854 if (entry != NULL)
1855 printf (" (%s)", get_TAG_name (entry->tag));
1856 }
6e3d6dc1
NC
1857 printf ("]");
1858 }
ec4d4525
NC
1859 }
1860 break;
1861
19e6b90e
L
1862 default:
1863 break;
1864 }
1865
1866 return data;
1867}
1868
a19c41a7 1869static const char *
19e6b90e
L
1870get_AT_name (unsigned long attribute)
1871{
a19c41a7 1872 const char *name;
e2a0d921 1873
399c99f7
L
1874 if (attribute == 0)
1875 return "DW_AT value: 0";
1876
a19c41a7
TT
1877 /* One value is shared by the MIPS and HP extensions: */
1878 if (attribute == DW_AT_MIPS_fde)
1879 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
19e6b90e 1880
a19c41a7
TT
1881 name = get_DW_AT_name (attribute);
1882
1883 if (name == NULL)
1884 {
1885 static char buffer[100];
1886
1887 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1888 attribute);
1889 return buffer;
19e6b90e 1890 }
a19c41a7
TT
1891
1892 return name;
19e6b90e
L
1893}
1894
1895static unsigned char *
6e3d6dc1
NC
1896read_and_display_attr (unsigned long attribute,
1897 unsigned long form,
ec4d4525 1898 unsigned char * data,
467c65bc
NC
1899 dwarf_vma cu_offset,
1900 dwarf_vma pointer_size,
1901 dwarf_vma offset_size,
6e3d6dc1
NC
1902 int dwarf_version,
1903 debug_info * debug_info_p,
1904 int do_loc,
1905 struct dwarf_section * section)
19e6b90e
L
1906{
1907 if (!do_loc)
750f03b7 1908 printf (" %-18s:", get_AT_name (attribute));
19e6b90e
L
1909 data = read_and_display_attr_value (attribute, form, data, cu_offset,
1910 pointer_size, offset_size,
1911 dwarf_version, debug_info_p,
6e3d6dc1 1912 do_loc, section);
19e6b90e
L
1913 if (!do_loc)
1914 printf ("\n");
1915 return data;
1916}
1917
1918
1919/* Process the contents of a .debug_info section. If do_loc is non-zero
1920 then we are scanning for location lists and we do not want to display
2b6f5997
CC
1921 anything to the user. If do_types is non-zero, we are processing
1922 a .debug_types section instead of a .debug_info section. */
19e6b90e
L
1923
1924static int
6e3d6dc1
NC
1925process_debug_info (struct dwarf_section *section,
1926 void *file,
6f875884 1927 enum dwarf_section_display_enum abbrev_sec,
2b6f5997
CC
1928 int do_loc,
1929 int do_types)
19e6b90e
L
1930{
1931 unsigned char *start = section->start;
1932 unsigned char *end = start + section->size;
1933 unsigned char *section_begin;
1934 unsigned int unit;
1935 unsigned int num_units = 0;
1936
1937 if ((do_loc || do_debug_loc || do_debug_ranges)
2b6f5997
CC
1938 && num_debug_info_entries == 0
1939 && ! do_types)
19e6b90e 1940 {
767221a9 1941 dwarf_vma length;
19e6b90e
L
1942
1943 /* First scan the section to get the number of comp units. */
1944 for (section_begin = start, num_units = 0; section_begin < end;
1945 num_units ++)
1946 {
1947 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1948 will be the length. For a 64-bit DWARF section, it'll be
1949 the escape code 0xffffffff followed by an 8 byte length. */
1950 length = byte_get (section_begin, 4);
1951
1952 if (length == 0xffffffff)
1953 {
1954 length = byte_get (section_begin + 4, 8);
1955 section_begin += length + 12;
1956 }
ec4d4525
NC
1957 else if (length >= 0xfffffff0 && length < 0xffffffff)
1958 {
767221a9
NC
1959 warn (_("Reserved length value (0x%s) found in section %s\n"),
1960 dwarf_vmatoa ("x", length), section->name);
ec4d4525
NC
1961 return 0;
1962 }
19e6b90e
L
1963 else
1964 section_begin += length + 4;
aca88567
NC
1965
1966 /* Negative values are illegal, they may even cause infinite
1967 looping. This can happen if we can't accurately apply
1968 relocations to an object file. */
1969 if ((signed long) length <= 0)
1970 {
767221a9
NC
1971 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
1972 dwarf_vmatoa ("x", length), section->name);
aca88567
NC
1973 return 0;
1974 }
19e6b90e
L
1975 }
1976
1977 if (num_units == 0)
1978 {
1979 error (_("No comp units in %s section ?"), section->name);
1980 return 0;
1981 }
1982
1983 /* Then allocate an array to hold the information. */
3f5e193b
NC
1984 debug_information = (debug_info *) cmalloc (num_units,
1985 sizeof (* debug_information));
19e6b90e
L
1986 if (debug_information == NULL)
1987 {
1988 error (_("Not enough memory for a debug info array of %u entries"),
1989 num_units);
1990 return 0;
1991 }
1992 }
1993
1994 if (!do_loc)
1995 {
fd2f0033
TT
1996 if (dwarf_start_die == 0)
1997 printf (_("Contents of the %s section:\n\n"), section->name);
19e6b90e
L
1998
1999 load_debug_section (str, file);
4723351a
CC
2000 load_debug_section (str_dwo, file);
2001 load_debug_section (str_index, file);
2002 load_debug_section (str_index_dwo, file);
2003 load_debug_section (debug_addr, file);
19e6b90e
L
2004 }
2005
6f875884
TG
2006 load_debug_section (abbrev_sec, file);
2007 if (debug_displays [abbrev_sec].section.start == NULL)
19e6b90e
L
2008 {
2009 warn (_("Unable to locate %s section!\n"),
6f875884 2010 debug_displays [abbrev_sec].section.name);
19e6b90e
L
2011 return 0;
2012 }
2013
2014 for (section_begin = start, unit = 0; start < end; unit++)
2015 {
2016 DWARF2_Internal_CompUnit compunit;
2017 unsigned char *hdrptr;
19e6b90e 2018 unsigned char *tags;
fd2f0033 2019 int level, last_level, saved_level;
467c65bc 2020 dwarf_vma cu_offset;
19e6b90e
L
2021 int offset_size;
2022 int initial_length_size;
74bc6052
CC
2023 dwarf_vma signature_high = 0;
2024 dwarf_vma signature_low = 0;
767221a9 2025 dwarf_vma type_offset = 0;
19e6b90e
L
2026
2027 hdrptr = start;
2028
2029 compunit.cu_length = byte_get (hdrptr, 4);
2030 hdrptr += 4;
2031
2032 if (compunit.cu_length == 0xffffffff)
2033 {
2034 compunit.cu_length = byte_get (hdrptr, 8);
2035 hdrptr += 8;
2036 offset_size = 8;
2037 initial_length_size = 12;
2038 }
2039 else
2040 {
2041 offset_size = 4;
2042 initial_length_size = 4;
2043 }
2044
2045 compunit.cu_version = byte_get (hdrptr, 2);
2046 hdrptr += 2;
2047
2048 cu_offset = start - section_begin;
19e6b90e 2049
19e6b90e
L
2050 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
2051 hdrptr += offset_size;
2052
2053 compunit.cu_pointer_size = byte_get (hdrptr, 1);
2054 hdrptr += 1;
2b6f5997
CC
2055
2056 if (do_types)
2057 {
74bc6052
CC
2058 byte_get_64 (hdrptr, &signature_high, &signature_low);
2059 hdrptr += 8;
2b6f5997
CC
2060 type_offset = byte_get (hdrptr, offset_size);
2061 hdrptr += offset_size;
2062 }
2063
19e6b90e 2064 if ((do_loc || do_debug_loc || do_debug_ranges)
2b6f5997
CC
2065 && num_debug_info_entries == 0
2066 && ! do_types)
19e6b90e
L
2067 {
2068 debug_information [unit].cu_offset = cu_offset;
2069 debug_information [unit].pointer_size
2070 = compunit.cu_pointer_size;
b7807392
JJ
2071 debug_information [unit].offset_size = offset_size;
2072 debug_information [unit].dwarf_version = compunit.cu_version;
19e6b90e 2073 debug_information [unit].base_address = 0;
4723351a
CC
2074 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2075 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
19e6b90e
L
2076 debug_information [unit].loc_offsets = NULL;
2077 debug_information [unit].have_frame_base = NULL;
2078 debug_information [unit].max_loc_offsets = 0;
2079 debug_information [unit].num_loc_offsets = 0;
2080 debug_information [unit].range_lists = NULL;
2081 debug_information [unit].max_range_lists= 0;
2082 debug_information [unit].num_range_lists = 0;
2083 }
2084
fd2f0033 2085 if (!do_loc && dwarf_start_die == 0)
19e6b90e 2086 {
47704ddf
KT
2087 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2088 dwarf_vmatoa ("x", cu_offset));
2089 printf (_(" Length: 0x%s (%s)\n"),
2090 dwarf_vmatoa ("x", compunit.cu_length),
49e7b350 2091 offset_size == 8 ? "64-bit" : "32-bit");
19e6b90e 2092 printf (_(" Version: %d\n"), compunit.cu_version);
7282333f
AM
2093 printf (_(" Abbrev Offset: 0x%s\n"),
2094 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
19e6b90e 2095 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2b6f5997
CC
2096 if (do_types)
2097 {
74bc6052
CC
2098 char buf[64];
2099
2100 printf (_(" Signature: 0x%s\n"),
2101 dwarf_vmatoa64 (signature_high, signature_low,
2102 buf, sizeof (buf)));
2103 printf (_(" Type Offset: 0x%s\n"),
2104 dwarf_vmatoa ("x", type_offset));
2b6f5997 2105 }
19e6b90e
L
2106 }
2107
460c89ff
NS
2108 if (cu_offset + compunit.cu_length + initial_length_size
2109 > section->size)
2110 {
47704ddf
KT
2111 warn (_("Debug info is corrupted, length of CU at %s"
2112 " extends beyond end of section (length = %s)\n"),
2113 dwarf_vmatoa ("x", cu_offset),
2114 dwarf_vmatoa ("x", compunit.cu_length));
460c89ff
NS
2115 break;
2116 }
2117 tags = hdrptr;
2118 start += compunit.cu_length + initial_length_size;
2119
932fd279
JJ
2120 if (compunit.cu_version != 2
2121 && compunit.cu_version != 3
2122 && compunit.cu_version != 4)
19e6b90e 2123 {
47704ddf
KT
2124 warn (_("CU at offset %s contains corrupt or "
2125 "unsupported version number: %d.\n"),
2126 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
19e6b90e
L
2127 continue;
2128 }
2129
2130 free_abbrevs ();
2131
bfe2612a
L
2132 /* Process the abbrevs used by this compilation unit. DWARF
2133 sections under Mach-O have non-zero addresses. */
6f875884 2134 if (compunit.cu_abbrev_offset >= debug_displays [abbrev_sec].section.size)
ec4d4525
NC
2135 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2136 (unsigned long) compunit.cu_abbrev_offset,
6f875884 2137 (unsigned long) debug_displays [abbrev_sec].section.size);
460c89ff
NS
2138 else
2139 process_abbrev_section
6f875884 2140 ((unsigned char *) debug_displays [abbrev_sec].section.start
0ac6fba0 2141 + compunit.cu_abbrev_offset,
6f875884
TG
2142 (unsigned char *) debug_displays [abbrev_sec].section.start
2143 + debug_displays [abbrev_sec].section.size);
19e6b90e
L
2144
2145 level = 0;
fd2f0033
TT
2146 last_level = level;
2147 saved_level = -1;
19e6b90e
L
2148 while (tags < start)
2149 {
2150 unsigned int bytes_read;
2151 unsigned long abbrev_number;
ec4d4525 2152 unsigned long die_offset;
19e6b90e
L
2153 abbrev_entry *entry;
2154 abbrev_attr *attr;
fd2f0033 2155 int do_printing = 1;
19e6b90e 2156
ec4d4525
NC
2157 die_offset = tags - section_begin;
2158
19e6b90e
L
2159 abbrev_number = read_leb128 (tags, & bytes_read, 0);
2160 tags += bytes_read;
2161
eb7cc021
JK
2162 /* A null DIE marks the end of a list of siblings or it may also be
2163 a section padding. */
19e6b90e
L
2164 if (abbrev_number == 0)
2165 {
eb7cc021
JK
2166 /* Check if it can be a section padding for the last CU. */
2167 if (level == 0 && start == end)
2168 {
2169 unsigned char *chk;
2170
2171 for (chk = tags; chk < start; chk++)
2172 if (*chk != 0)
2173 break;
2174 if (chk == start)
2175 break;
2176 }
2177
399c99f7
L
2178 if (!do_loc && die_offset >= dwarf_start_die)
2179 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2180 level, die_offset);
2181
19e6b90e 2182 --level;
ec4d4525
NC
2183 if (level < 0)
2184 {
2185 static unsigned num_bogus_warns = 0;
2186
2187 if (num_bogus_warns < 3)
2188 {
4723351a
CC
2189 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2190 die_offset, section->name);
ec4d4525
NC
2191 num_bogus_warns ++;
2192 if (num_bogus_warns == 3)
2193 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2194 }
2195 }
fd2f0033
TT
2196 if (dwarf_start_die != 0 && level < saved_level)
2197 return 1;
19e6b90e
L
2198 continue;
2199 }
2200
4b78141a 2201 if (!do_loc)
fd2f0033
TT
2202 {
2203 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2204 do_printing = 0;
2205 else
2206 {
2207 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2208 saved_level = level;
2209 do_printing = (dwarf_cutoff_level == -1
2210 || level < dwarf_cutoff_level);
2211 if (do_printing)
2212 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2213 level, die_offset, abbrev_number);
2214 else if (dwarf_cutoff_level == -1
2215 || last_level < dwarf_cutoff_level)
2216 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2217 last_level = level;
2218 }
2219 }
cecf136e 2220
19e6b90e
L
2221 /* Scan through the abbreviation list until we reach the
2222 correct entry. */
2223 for (entry = first_abbrev;
2224 entry && entry->entry != abbrev_number;
2225 entry = entry->next)
2226 continue;
2227
2228 if (entry == NULL)
2229 {
fd2f0033 2230 if (!do_loc && do_printing)
4b78141a
NC
2231 {
2232 printf ("\n");
2233 fflush (stdout);
2234 }
cc86f28f
NC
2235 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2236 die_offset, abbrev_number);
19e6b90e
L
2237 return 0;
2238 }
2239
fd2f0033 2240 if (!do_loc && do_printing)
cc5914eb 2241 printf (" (%s)\n", get_TAG_name (entry->tag));
cecf136e 2242
19e6b90e
L
2243 switch (entry->tag)
2244 {
2245 default:
2246 need_base_address = 0;
2247 break;
2248 case DW_TAG_compile_unit:
2249 need_base_address = 1;
2250 break;
2251 case DW_TAG_entry_point:
19e6b90e
L
2252 case DW_TAG_subprogram:
2253 need_base_address = 0;
2254 /* Assuming that there is no DW_AT_frame_base. */
2255 have_frame_base = 0;
2256 break;
2257 }
2258
399c99f7
L
2259 for (attr = entry->first_attr;
2260 attr && attr->attribute;
2261 attr = attr->next)
4b78141a 2262 {
fd2f0033
TT
2263 debug_info *arg;
2264
2265 if (! do_loc && do_printing)
4b78141a 2266 /* Show the offset from where the tag was extracted. */
fd2f0033
TT
2267 printf (" <%lx>", (unsigned long)(tags - section_begin));
2268
2269 arg = debug_information;
2270 if (debug_information)
2271 arg += unit;
4b78141a
NC
2272
2273 tags = read_and_display_attr (attr->attribute,
2274 attr->form,
2275 tags, cu_offset,
2276 compunit.cu_pointer_size,
2277 offset_size,
2278 compunit.cu_version,
fd2f0033
TT
2279 arg,
2280 do_loc || ! do_printing, section);
4b78141a 2281 }
cecf136e 2282
19e6b90e
L
2283 if (entry->children)
2284 ++level;
2285 }
2286 }
cecf136e 2287
19e6b90e
L
2288 /* Set num_debug_info_entries here so that it can be used to check if
2289 we need to process .debug_loc and .debug_ranges sections. */
2290 if ((do_loc || do_debug_loc || do_debug_ranges)
2b6f5997
CC
2291 && num_debug_info_entries == 0
2292 && ! do_types)
19e6b90e 2293 num_debug_info_entries = num_units;
cecf136e 2294
19e6b90e 2295 if (!do_loc)
467c65bc 2296 printf ("\n");
cecf136e 2297
19e6b90e
L
2298 return 1;
2299}
2300
2301/* Locate and scan the .debug_info section in the file and record the pointer
2302 sizes and offsets for the compilation units in it. Usually an executable
2303 will have just one pointer size, but this is not guaranteed, and so we try
2304 not to make any assumptions. Returns zero upon failure, or the number of
2305 compilation units upon success. */
2306
2307static unsigned int
2308load_debug_info (void * file)
2309{
2310 /* Reset the last pointer size so that we can issue correct error
2311 messages if we are displaying the contents of more than one section. */
2312 last_pointer_size = 0;
2313 warned_about_missing_comp_units = FALSE;
2314
1febe64d
NC
2315 /* If we have already tried and failed to load the .debug_info
2316 section then do not bother to repear the task. */
cc86f28f 2317 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
1febe64d
NC
2318 return 0;
2319
19e6b90e
L
2320 /* If we already have the information there is nothing else to do. */
2321 if (num_debug_info_entries > 0)
2322 return num_debug_info_entries;
2323
2324 if (load_debug_section (info, file)
6f875884 2325 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
19e6b90e 2326 return num_debug_info_entries;
4723351a
CC
2327 else if (load_debug_section (info_dwo, file)
2328 && process_debug_info (&debug_displays [info_dwo].section, file,
2329 abbrev_dwo, 1, 0))
2330 return num_debug_info_entries;
1febe64d 2331
cc86f28f 2332 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
1febe64d 2333 return 0;
19e6b90e
L
2334}
2335
19e6b90e 2336static int
a262ae96
NC
2337display_debug_lines_raw (struct dwarf_section *section,
2338 unsigned char *data,
2339 unsigned char *end)
19e6b90e
L
2340{
2341 unsigned char *start = section->start;
19e6b90e 2342
a262ae96
NC
2343 printf (_("Raw dump of debug contents of section %s:\n\n"),
2344 section->name);
19e6b90e
L
2345
2346 while (data < end)
2347 {
91d6fa6a 2348 DWARF2_Internal_LineInfo linfo;
19e6b90e
L
2349 unsigned char *standard_opcodes;
2350 unsigned char *end_of_sequence;
2351 unsigned char *hdrptr;
6523721c 2352 unsigned long hdroff;
19e6b90e
L
2353 int initial_length_size;
2354 int offset_size;
2355 int i;
2356
2357 hdrptr = data;
6523721c 2358 hdroff = hdrptr - start;
19e6b90e
L
2359
2360 /* Check the length of the block. */
91d6fa6a 2361 linfo.li_length = byte_get (hdrptr, 4);
19e6b90e
L
2362 hdrptr += 4;
2363
91d6fa6a 2364 if (linfo.li_length == 0xffffffff)
19e6b90e
L
2365 {
2366 /* This section is 64-bit DWARF 3. */
91d6fa6a 2367 linfo.li_length = byte_get (hdrptr, 8);
19e6b90e
L
2368 hdrptr += 8;
2369 offset_size = 8;
2370 initial_length_size = 12;
2371 }
2372 else
2373 {
2374 offset_size = 4;
2375 initial_length_size = 4;
2376 }
2377
91d6fa6a 2378 if (linfo.li_length + initial_length_size > section->size)
19e6b90e
L
2379 {
2380 warn
cf13d699
NC
2381 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2382 section->name);
19e6b90e
L
2383 return 0;
2384 }
2385
2386 /* Check its version number. */
91d6fa6a 2387 linfo.li_version = byte_get (hdrptr, 2);
19e6b90e 2388 hdrptr += 2;
932fd279
JJ
2389 if (linfo.li_version != 2
2390 && linfo.li_version != 3
2391 && linfo.li_version != 4)
19e6b90e 2392 {
932fd279 2393 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
19e6b90e
L
2394 return 0;
2395 }
2396
91d6fa6a 2397 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
19e6b90e 2398 hdrptr += offset_size;
91d6fa6a 2399 linfo.li_min_insn_length = byte_get (hdrptr, 1);
19e6b90e 2400 hdrptr++;
a233b20c
JJ
2401 if (linfo.li_version >= 4)
2402 {
2403 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2404 hdrptr++;
2405 if (linfo.li_max_ops_per_insn == 0)
2406 {
2407 warn (_("Invalid maximum operations per insn.\n"));
2408 return 0;
2409 }
2410 }
2411 else
2412 linfo.li_max_ops_per_insn = 1;
91d6fa6a 2413 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
19e6b90e 2414 hdrptr++;
91d6fa6a 2415 linfo.li_line_base = byte_get (hdrptr, 1);
19e6b90e 2416 hdrptr++;
91d6fa6a 2417 linfo.li_line_range = byte_get (hdrptr, 1);
19e6b90e 2418 hdrptr++;
91d6fa6a 2419 linfo.li_opcode_base = byte_get (hdrptr, 1);
19e6b90e
L
2420 hdrptr++;
2421
2422 /* Sign extend the line base field. */
91d6fa6a
NC
2423 linfo.li_line_base <<= 24;
2424 linfo.li_line_base >>= 24;
19e6b90e 2425
6523721c 2426 printf (_(" Offset: 0x%lx\n"), hdroff);
47704ddf 2427 printf (_(" Length: %ld\n"), (long) linfo.li_length);
91d6fa6a
NC
2428 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2429 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2430 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
a233b20c
JJ
2431 if (linfo.li_version >= 4)
2432 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
91d6fa6a
NC
2433 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2434 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2435 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2436 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
19e6b90e 2437
91d6fa6a 2438 end_of_sequence = data + linfo.li_length + initial_length_size;
19e6b90e 2439
91d6fa6a 2440 reset_state_machine (linfo.li_default_is_stmt);
19e6b90e
L
2441
2442 /* Display the contents of the Opcodes table. */
2443 standard_opcodes = hdrptr;
2444
2445 printf (_("\n Opcodes:\n"));
2446
91d6fa6a 2447 for (i = 1; i < linfo.li_opcode_base; i++)
19e6b90e
L
2448 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2449
2450 /* Display the contents of the Directory table. */
91d6fa6a 2451 data = standard_opcodes + linfo.li_opcode_base - 1;
19e6b90e
L
2452
2453 if (*data == 0)
2454 printf (_("\n The Directory Table is empty.\n"));
2455 else
2456 {
2457 printf (_("\n The Directory Table:\n"));
2458
2459 while (*data != 0)
2460 {
cc5914eb 2461 printf (" %s\n", data);
19e6b90e
L
2462
2463 data += strlen ((char *) data) + 1;
2464 }
2465 }
2466
2467 /* Skip the NUL at the end of the table. */
2468 data++;
2469
2470 /* Display the contents of the File Name table. */
2471 if (*data == 0)
2472 printf (_("\n The File Name Table is empty.\n"));
2473 else
2474 {
2475 printf (_("\n The File Name Table:\n"));
2476 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2477
2478 while (*data != 0)
2479 {
2480 unsigned char *name;
2481 unsigned int bytes_read;
2482
cc5914eb 2483 printf (" %d\t", ++state_machine_regs.last_file_entry);
19e6b90e
L
2484 name = data;
2485
2486 data += strlen ((char *) data) + 1;
2487
467c65bc
NC
2488 printf ("%s\t",
2489 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
19e6b90e 2490 data += bytes_read;
467c65bc
NC
2491 printf ("%s\t",
2492 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
19e6b90e 2493 data += bytes_read;
467c65bc
NC
2494 printf ("%s\t",
2495 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
19e6b90e 2496 data += bytes_read;
cc5914eb 2497 printf ("%s\n", name);
19e6b90e
L
2498 }
2499 }
2500
2501 /* Skip the NUL at the end of the table. */
2502 data++;
2503
2504 /* Now display the statements. */
2505 printf (_("\n Line Number Statements:\n"));
2506
2507 while (data < end_of_sequence)
2508 {
2509 unsigned char op_code;
467c65bc
NC
2510 dwarf_signed_vma adv;
2511 dwarf_vma uladv;
19e6b90e
L
2512 unsigned int bytes_read;
2513
2514 op_code = *data++;
2515
91d6fa6a 2516 if (op_code >= linfo.li_opcode_base)
19e6b90e 2517 {
91d6fa6a 2518 op_code -= linfo.li_opcode_base;
a233b20c
JJ
2519 uladv = (op_code / linfo.li_line_range);
2520 if (linfo.li_max_ops_per_insn == 1)
2521 {
2522 uladv *= linfo.li_min_insn_length;
2523 state_machine_regs.address += uladv;
467c65bc
NC
2524 printf (_(" Special opcode %d: "
2525 "advance Address by %s to 0x%s"),
2526 op_code, dwarf_vmatoa ("u", uladv),
2527 dwarf_vmatoa ("x", state_machine_regs.address));
a233b20c
JJ
2528 }
2529 else
2530 {
2531 state_machine_regs.address
2532 += ((state_machine_regs.op_index + uladv)
2533 / linfo.li_max_ops_per_insn)
2534 * linfo.li_min_insn_length;
2535 state_machine_regs.op_index
2536 = (state_machine_regs.op_index + uladv)
2537 % linfo.li_max_ops_per_insn;
467c65bc
NC
2538 printf (_(" Special opcode %d: "
2539 "advance Address by %s to 0x%s[%d]"),
2540 op_code, dwarf_vmatoa ("u", uladv),
2541 dwarf_vmatoa ("x", state_machine_regs.address),
a233b20c
JJ
2542 state_machine_regs.op_index);
2543 }
91d6fa6a 2544 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
19e6b90e 2545 state_machine_regs.line += adv;
467c65bc
NC
2546 printf (_(" and Line by %s to %d\n"),
2547 dwarf_vmatoa ("d", adv), state_machine_regs.line);
19e6b90e
L
2548 }
2549 else switch (op_code)
2550 {
2551 case DW_LNS_extended_op:
91d6fa6a 2552 data += process_extended_line_op (data, linfo.li_default_is_stmt);
19e6b90e
L
2553 break;
2554
2555 case DW_LNS_copy:
2556 printf (_(" Copy\n"));
2557 break;
2558
2559 case DW_LNS_advance_pc:
2560 uladv = read_leb128 (data, & bytes_read, 0);
19e6b90e 2561 data += bytes_read;
a233b20c
JJ
2562 if (linfo.li_max_ops_per_insn == 1)
2563 {
2564 uladv *= linfo.li_min_insn_length;
2565 state_machine_regs.address += uladv;
467c65bc
NC
2566 printf (_(" Advance PC by %s to 0x%s\n"),
2567 dwarf_vmatoa ("u", uladv),
2568 dwarf_vmatoa ("x", state_machine_regs.address));
a233b20c
JJ
2569 }
2570 else
2571 {
2572 state_machine_regs.address
2573 += ((state_machine_regs.op_index + uladv)
2574 / linfo.li_max_ops_per_insn)
2575 * linfo.li_min_insn_length;
2576 state_machine_regs.op_index
2577 = (state_machine_regs.op_index + uladv)
2578 % linfo.li_max_ops_per_insn;
467c65bc
NC
2579 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2580 dwarf_vmatoa ("u", uladv),
2581 dwarf_vmatoa ("x", state_machine_regs.address),
a233b20c
JJ
2582 state_machine_regs.op_index);
2583 }
19e6b90e
L
2584 break;
2585
2586 case DW_LNS_advance_line:
467c65bc 2587 adv = read_sleb128 (data, & bytes_read);
19e6b90e
L
2588 data += bytes_read;
2589 state_machine_regs.line += adv;
467c65bc
NC
2590 printf (_(" Advance Line by %s to %d\n"),
2591 dwarf_vmatoa ("d", adv),
2592 state_machine_regs.line);
19e6b90e
L
2593 break;
2594
2595 case DW_LNS_set_file:
2596 adv = read_leb128 (data, & bytes_read, 0);
2597 data += bytes_read;
467c65bc
NC
2598 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2599 dwarf_vmatoa ("d", adv));
19e6b90e
L
2600 state_machine_regs.file = adv;
2601 break;
2602
2603 case DW_LNS_set_column:
2604 uladv = read_leb128 (data, & bytes_read, 0);
2605 data += bytes_read;
467c65bc
NC
2606 printf (_(" Set column to %s\n"),
2607 dwarf_vmatoa ("u", uladv));
19e6b90e
L
2608 state_machine_regs.column = uladv;
2609 break;
2610
2611 case DW_LNS_negate_stmt:
2612 adv = state_machine_regs.is_stmt;
2613 adv = ! adv;
467c65bc 2614 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
19e6b90e
L
2615 state_machine_regs.is_stmt = adv;
2616 break;
2617
2618 case DW_LNS_set_basic_block:
2619 printf (_(" Set basic block\n"));
2620 state_machine_regs.basic_block = 1;
2621 break;
2622
2623 case DW_LNS_const_add_pc:
a233b20c
JJ
2624 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2625 if (linfo.li_max_ops_per_insn)
2626 {
2627 uladv *= linfo.li_min_insn_length;
2628 state_machine_regs.address += uladv;
467c65bc
NC
2629 printf (_(" Advance PC by constant %s to 0x%s\n"),
2630 dwarf_vmatoa ("u", uladv),
2631 dwarf_vmatoa ("x", state_machine_regs.address));
a233b20c
JJ
2632 }
2633 else
2634 {
2635 state_machine_regs.address
2636 += ((state_machine_regs.op_index + uladv)
2637 / linfo.li_max_ops_per_insn)
2638 * linfo.li_min_insn_length;
2639 state_machine_regs.op_index
2640 = (state_machine_regs.op_index + uladv)
2641 % linfo.li_max_ops_per_insn;
467c65bc
NC
2642 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2643 dwarf_vmatoa ("u", uladv),
2644 dwarf_vmatoa ("x", state_machine_regs.address),
a233b20c
JJ
2645 state_machine_regs.op_index);
2646 }
19e6b90e
L
2647 break;
2648
2649 case DW_LNS_fixed_advance_pc:
2650 uladv = byte_get (data, 2);
2651 data += 2;
2652 state_machine_regs.address += uladv;
a233b20c 2653 state_machine_regs.op_index = 0;
467c65bc
NC
2654 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2655 dwarf_vmatoa ("u", uladv),
2656 dwarf_vmatoa ("x", state_machine_regs.address));
19e6b90e
L
2657 break;
2658
2659 case DW_LNS_set_prologue_end:
2660 printf (_(" Set prologue_end to true\n"));
2661 break;
2662
2663 case DW_LNS_set_epilogue_begin:
2664 printf (_(" Set epilogue_begin to true\n"));
2665 break;
2666
2667 case DW_LNS_set_isa:
2668 uladv = read_leb128 (data, & bytes_read, 0);
2669 data += bytes_read;
467c65bc 2670 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
19e6b90e
L
2671 break;
2672
2673 default:
2674 printf (_(" Unknown opcode %d with operands: "), op_code);
2675
2676 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2677 {
467c65bc
NC
2678 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
2679 &bytes_read, 0)),
19e6b90e
L
2680 i == 1 ? "" : ", ");
2681 data += bytes_read;
2682 }
2683 putchar ('\n');
2684 break;
2685 }
2686 }
2687 putchar ('\n');
2688 }
2689
2690 return 1;
2691}
2692
a262ae96
NC
2693typedef struct
2694{
467c65bc
NC
2695 unsigned char *name;
2696 unsigned int directory_index;
2697 unsigned int modification_date;
2698 unsigned int length;
a262ae96
NC
2699} File_Entry;
2700
2701/* Output a decoded representation of the .debug_line section. */
2702
2703static int
2704display_debug_lines_decoded (struct dwarf_section *section,
2705 unsigned char *data,
2706 unsigned char *end)
2707{
2708 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2709 section->name);
2710
2711 while (data < end)
2712 {
2713 /* This loop amounts to one iteration per compilation unit. */
91d6fa6a 2714 DWARF2_Internal_LineInfo linfo;
a262ae96
NC
2715 unsigned char *standard_opcodes;
2716 unsigned char *end_of_sequence;
2717 unsigned char *hdrptr;
2718 int initial_length_size;
2719 int offset_size;
2720 int i;
2721 File_Entry *file_table = NULL;
143a3db0 2722 unsigned int n_files = 0;
a262ae96 2723 unsigned char **directory_table = NULL;
143a3db0 2724 unsigned int n_directories = 0;
a262ae96
NC
2725
2726 hdrptr = data;
2727
2728 /* Extract information from the Line Number Program Header.
2729 (section 6.2.4 in the Dwarf3 doc). */
2730
2731 /* Get the length of this CU's line number information block. */
91d6fa6a 2732 linfo.li_length = byte_get (hdrptr, 4);
a262ae96
NC
2733 hdrptr += 4;
2734
91d6fa6a 2735 if (linfo.li_length == 0xffffffff)
a262ae96
NC
2736 {
2737 /* This section is 64-bit DWARF 3. */
91d6fa6a 2738 linfo.li_length = byte_get (hdrptr, 8);
a262ae96
NC
2739 hdrptr += 8;
2740 offset_size = 8;
2741 initial_length_size = 12;
2742 }
2743 else
2744 {
2745 offset_size = 4;
2746 initial_length_size = 4;
2747 }
2748
91d6fa6a 2749 if (linfo.li_length + initial_length_size > section->size)
a262ae96
NC
2750 {
2751 warn (_("The line info appears to be corrupt - "
2752 "the section is too small\n"));
2753 return 0;
2754 }
2755
2756 /* Get this CU's Line Number Block version number. */
91d6fa6a 2757 linfo.li_version = byte_get (hdrptr, 2);
a262ae96 2758 hdrptr += 2;
932fd279
JJ
2759 if (linfo.li_version != 2
2760 && linfo.li_version != 3
2761 && linfo.li_version != 4)
a262ae96 2762 {
932fd279 2763 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
a262ae96
NC
2764 "supported.\n"));
2765 return 0;
2766 }
2767
91d6fa6a 2768 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
a262ae96 2769 hdrptr += offset_size;
91d6fa6a 2770 linfo.li_min_insn_length = byte_get (hdrptr, 1);
a262ae96 2771 hdrptr++;
a233b20c
JJ
2772 if (linfo.li_version >= 4)
2773 {
2774 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2775 hdrptr++;
2776 if (linfo.li_max_ops_per_insn == 0)
2777 {
2778 warn (_("Invalid maximum operations per insn.\n"));
2779 return 0;
2780 }
2781 }
2782 else
2783 linfo.li_max_ops_per_insn = 1;
91d6fa6a 2784 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
a262ae96 2785 hdrptr++;
91d6fa6a 2786 linfo.li_line_base = byte_get (hdrptr, 1);
a262ae96 2787 hdrptr++;
91d6fa6a 2788 linfo.li_line_range = byte_get (hdrptr, 1);
a262ae96 2789 hdrptr++;
91d6fa6a 2790 linfo.li_opcode_base = byte_get (hdrptr, 1);
a262ae96
NC
2791 hdrptr++;
2792
2793 /* Sign extend the line base field. */
91d6fa6a
NC
2794 linfo.li_line_base <<= 24;
2795 linfo.li_line_base >>= 24;
a262ae96
NC
2796
2797 /* Find the end of this CU's Line Number Information Block. */
91d6fa6a 2798 end_of_sequence = data + linfo.li_length + initial_length_size;
a262ae96 2799
91d6fa6a 2800 reset_state_machine (linfo.li_default_is_stmt);
a262ae96
NC
2801
2802 /* Save a pointer to the contents of the Opcodes table. */
2803 standard_opcodes = hdrptr;
2804
2805 /* Traverse the Directory table just to count entries. */
91d6fa6a 2806 data = standard_opcodes + linfo.li_opcode_base - 1;
a262ae96
NC
2807 if (*data != 0)
2808 {
a262ae96 2809 unsigned char *ptr_directory_table = data;
a262ae96
NC
2810
2811 while (*data != 0)
2812 {
2813 data += strlen ((char *) data) + 1;
2814 n_directories++;
2815 }
2816
2817 /* Go through the directory table again to save the directories. */
3f5e193b
NC
2818 directory_table = (unsigned char **)
2819 xmalloc (n_directories * sizeof (unsigned char *));
a262ae96
NC
2820
2821 i = 0;
2822 while (*ptr_directory_table != 0)
2823 {
2824 directory_table[i] = ptr_directory_table;
2825 ptr_directory_table += strlen ((char *) ptr_directory_table) + 1;
2826 i++;
2827 }
2828 }
2829 /* Skip the NUL at the end of the table. */
2830 data++;
2831
2832 /* Traverse the File Name table just to count the entries. */
2833 if (*data != 0)
2834 {
a262ae96 2835 unsigned char *ptr_file_name_table = data;
a262ae96
NC
2836
2837 while (*data != 0)
2838 {
2839 unsigned int bytes_read;
2840
2841 /* Skip Name, directory index, last modification time and length
2842 of file. */
2843 data += strlen ((char *) data) + 1;
2844 read_leb128 (data, & bytes_read, 0);
2845 data += bytes_read;
2846 read_leb128 (data, & bytes_read, 0);
2847 data += bytes_read;
2848 read_leb128 (data, & bytes_read, 0);
2849 data += bytes_read;
2850
2851 n_files++;
2852 }
2853
2854 /* Go through the file table again to save the strings. */
3f5e193b 2855 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
a262ae96
NC
2856
2857 i = 0;
2858 while (*ptr_file_name_table != 0)
2859 {
2860 unsigned int bytes_read;
2861
2862 file_table[i].name = ptr_file_name_table;
2863 ptr_file_name_table += strlen ((char *) ptr_file_name_table) + 1;
2864
2865 /* We are not interested in directory, time or size. */
2866 file_table[i].directory_index = read_leb128 (ptr_file_name_table,
2867 & bytes_read, 0);
2868 ptr_file_name_table += bytes_read;
2869 file_table[i].modification_date = read_leb128 (ptr_file_name_table,
2870 & bytes_read, 0);
2871 ptr_file_name_table += bytes_read;
2872 file_table[i].length = read_leb128 (ptr_file_name_table, & bytes_read, 0);
2873 ptr_file_name_table += bytes_read;
2874 i++;
2875 }
2876 i = 0;
2877
2878 /* Print the Compilation Unit's name and a header. */
2879 if (directory_table == NULL)
2880 {
2881 printf (_("CU: %s:\n"), file_table[0].name);
2882 printf (_("File name Line number Starting address\n"));
2883 }
2884 else
2885 {
4eee63bc
CD
2886 unsigned int ix = file_table[0].directory_index;
2887 const char *directory = ix ? (char *)directory_table[ix - 1] : ".";
2888 if (do_wide || strlen (directory) < 76)
2889 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
a262ae96 2890 else
cc5914eb
AM
2891 printf ("%s:\n", file_table[0].name);
2892
a262ae96
NC
2893 printf (_("File name Line number Starting address\n"));
2894 }
2895 }
2896
2897 /* Skip the NUL at the end of the table. */
2898 data++;
2899
2900 /* This loop iterates through the Dwarf Line Number Program. */
2901 while (data < end_of_sequence)
2902 {
2903 unsigned char op_code;
2904 int adv;
2905 unsigned long int uladv;
2906 unsigned int bytes_read;
2907 int is_special_opcode = 0;
2908
2909 op_code = *data++;
a262ae96 2910
91d6fa6a 2911 if (op_code >= linfo.li_opcode_base)
a262ae96 2912 {
91d6fa6a 2913 op_code -= linfo.li_opcode_base;
a233b20c
JJ
2914 uladv = (op_code / linfo.li_line_range);
2915 if (linfo.li_max_ops_per_insn == 1)
2916 {
2917 uladv *= linfo.li_min_insn_length;
2918 state_machine_regs.address += uladv;
2919 }
2920 else
2921 {
2922 state_machine_regs.address
2923 += ((state_machine_regs.op_index + uladv)
2924 / linfo.li_max_ops_per_insn)
2925 * linfo.li_min_insn_length;
2926 state_machine_regs.op_index
2927 = (state_machine_regs.op_index + uladv)
2928 % linfo.li_max_ops_per_insn;
2929 }
a262ae96 2930
91d6fa6a 2931 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
a262ae96
NC
2932 state_machine_regs.line += adv;
2933 is_special_opcode = 1;
2934 }
2935 else switch (op_code)
2936 {
2937 case DW_LNS_extended_op:
2938 {
2939 unsigned int ext_op_code_len;
a262ae96
NC
2940 unsigned char ext_op_code;
2941 unsigned char *op_code_data = data;
2942
2943 ext_op_code_len = read_leb128 (op_code_data, &bytes_read, 0);
2944 op_code_data += bytes_read;
2945
2946 if (ext_op_code_len == 0)
2947 {
2948 warn (_("badly formed extended line op encountered!\n"));
2949 break;
2950 }
2951 ext_op_code_len += bytes_read;
2952 ext_op_code = *op_code_data++;
2953
2954 switch (ext_op_code)
2955 {
2956 case DW_LNE_end_sequence:
91d6fa6a 2957 reset_state_machine (linfo.li_default_is_stmt);
a262ae96
NC
2958 break;
2959 case DW_LNE_set_address:
2960 state_machine_regs.address =
2961 byte_get (op_code_data, ext_op_code_len - bytes_read - 1);
a233b20c 2962 state_machine_regs.op_index = 0;
a262ae96
NC
2963 break;
2964 case DW_LNE_define_file:
2965 {
143a3db0
TG
2966 file_table = (File_Entry *) xrealloc
2967 (file_table, (n_files + 1) * sizeof (File_Entry));
a262ae96
NC
2968
2969 ++state_machine_regs.last_file_entry;
143a3db0
TG
2970 /* Source file name. */
2971 file_table[n_files].name = op_code_data;
a262ae96 2972 op_code_data += strlen ((char *) op_code_data) + 1;
143a3db0
TG
2973 /* Directory index. */
2974 file_table[n_files].directory_index =
2975 read_leb128 (op_code_data, & bytes_read, 0);
a262ae96 2976 op_code_data += bytes_read;
143a3db0
TG
2977 /* Last modification time. */
2978 file_table[n_files].modification_date =
2979 read_leb128 (op_code_data, & bytes_read, 0);
a262ae96 2980 op_code_data += bytes_read;
143a3db0
TG
2981 /* File length. */
2982 file_table[n_files].length =
2983 read_leb128 (op_code_data, & bytes_read, 0);
a262ae96 2984
143a3db0 2985 n_files++;
a262ae96
NC
2986 break;
2987 }
143a3db0
TG
2988 case DW_LNE_set_discriminator:
2989 case DW_LNE_HP_set_sequence:
2990 /* Simply ignored. */
2991 break;
2992
a262ae96 2993 default:
143a3db0
TG
2994 printf (_("UNKNOWN (%u): length %d\n"),
2995 ext_op_code, ext_op_code_len - bytes_read);
a262ae96
NC
2996 break;
2997 }
2998 data += ext_op_code_len;
2999 break;
3000 }
3001 case DW_LNS_copy:
3002 break;
3003
3004 case DW_LNS_advance_pc:
3005 uladv = read_leb128 (data, & bytes_read, 0);
a262ae96 3006 data += bytes_read;
a233b20c
JJ
3007 if (linfo.li_max_ops_per_insn == 1)
3008 {
3009 uladv *= linfo.li_min_insn_length;
3010 state_machine_regs.address += uladv;
3011 }
3012 else
3013 {
3014 state_machine_regs.address
3015 += ((state_machine_regs.op_index + uladv)
3016 / linfo.li_max_ops_per_insn)
3017 * linfo.li_min_insn_length;
3018 state_machine_regs.op_index
3019 = (state_machine_regs.op_index + uladv)
3020 % linfo.li_max_ops_per_insn;
3021 }
a262ae96
NC
3022 break;
3023
3024 case DW_LNS_advance_line:
467c65bc 3025 adv = read_sleb128 (data, & bytes_read);
a262ae96
NC
3026 data += bytes_read;
3027 state_machine_regs.line += adv;
3028 break;
3029
3030 case DW_LNS_set_file:
3031 adv = read_leb128 (data, & bytes_read, 0);
3032 data += bytes_read;
3033 state_machine_regs.file = adv;
3034 if (file_table[state_machine_regs.file - 1].directory_index == 0)
3035 {
3036 /* If directory index is 0, that means current directory. */
cc5914eb 3037 printf ("\n./%s:[++]\n",
a262ae96
NC
3038 file_table[state_machine_regs.file - 1].name);
3039 }
3040 else
3041 {
3042 /* The directory index starts counting at 1. */
cc5914eb 3043 printf ("\n%s/%s:\n",
a262ae96
NC
3044 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
3045 file_table[state_machine_regs.file - 1].name);
3046 }
3047 break;
3048
3049 case DW_LNS_set_column:
3050 uladv = read_leb128 (data, & bytes_read, 0);
3051 data += bytes_read;
3052 state_machine_regs.column = uladv;
3053 break;
3054
3055 case DW_LNS_negate_stmt:
3056 adv = state_machine_regs.is_stmt;
3057 adv = ! adv;
3058 state_machine_regs.is_stmt = adv;
3059 break;
3060
3061 case DW_LNS_set_basic_block:
3062 state_machine_regs.basic_block = 1;
3063 break;
3064
3065 case DW_LNS_const_add_pc:
a233b20c
JJ
3066 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3067 if (linfo.li_max_ops_per_insn == 1)
3068 {
3069 uladv *= linfo.li_min_insn_length;
3070 state_machine_regs.address += uladv;
3071 }
3072 else
3073 {
3074 state_machine_regs.address
3075 += ((state_machine_regs.op_index + uladv)
3076 / linfo.li_max_ops_per_insn)
3077 * linfo.li_min_insn_length;
3078 state_machine_regs.op_index
3079 = (state_machine_regs.op_index + uladv)
3080 % linfo.li_max_ops_per_insn;
3081 }
a262ae96
NC
3082 break;
3083
3084 case DW_LNS_fixed_advance_pc:
3085 uladv = byte_get (data, 2);
3086 data += 2;
3087 state_machine_regs.address += uladv;
a233b20c 3088 state_machine_regs.op_index = 0;
a262ae96
NC
3089 break;
3090
3091 case DW_LNS_set_prologue_end:
3092 break;
3093
3094 case DW_LNS_set_epilogue_begin:
3095 break;
3096
3097 case DW_LNS_set_isa:
3098 uladv = read_leb128 (data, & bytes_read, 0);
3099 data += bytes_read;
3100 printf (_(" Set ISA to %lu\n"), uladv);
3101 break;
3102
3103 default:
3104 printf (_(" Unknown opcode %d with operands: "), op_code);
3105
3106 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3107 {
467c65bc
NC
3108 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
3109 &bytes_read, 0)),
a262ae96
NC
3110 i == 1 ? "" : ", ");
3111 data += bytes_read;
3112 }
3113 putchar ('\n');
3114 break;
3115 }
3116
3117 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3118 to the DWARF address/line matrix. */
3119 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3120 || (op_code == DW_LNS_copy))
3121 {
3122 const unsigned int MAX_FILENAME_LENGTH = 35;
3123 char *fileName = (char *)file_table[state_machine_regs.file - 1].name;
3124 char *newFileName = NULL;
3125 size_t fileNameLength = strlen (fileName);
3126
3127 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3128 {
3f5e193b 3129 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
a262ae96
NC
3130 /* Truncate file name */
3131 strncpy (newFileName,
3132 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3133 MAX_FILENAME_LENGTH + 1);
3134 }
3135 else
3136 {
3f5e193b 3137 newFileName = (char *) xmalloc (fileNameLength + 1);
a262ae96
NC
3138 strncpy (newFileName, fileName, fileNameLength + 1);
3139 }
3140
3141 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3142 {
a233b20c 3143 if (linfo.li_max_ops_per_insn == 1)
467c65bc
NC
3144 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3145 newFileName, state_machine_regs.line,
a233b20c
JJ
3146 state_machine_regs.address);
3147 else
467c65bc
NC
3148 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3149 newFileName, state_machine_regs.line,
a233b20c
JJ
3150 state_machine_regs.address,
3151 state_machine_regs.op_index);
a262ae96
NC
3152 }
3153 else
3154 {
a233b20c 3155 if (linfo.li_max_ops_per_insn == 1)
467c65bc
NC
3156 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3157 newFileName, state_machine_regs.line,
a233b20c
JJ
3158 state_machine_regs.address);
3159 else
467c65bc
NC
3160 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3161 newFileName, state_machine_regs.line,
a233b20c
JJ
3162 state_machine_regs.address,
3163 state_machine_regs.op_index);
a262ae96
NC
3164 }
3165
3166 if (op_code == DW_LNE_end_sequence)
3167 printf ("\n");
3168
3169 free (newFileName);
3170 }
3171 }
3172 free (file_table);
3173 file_table = NULL;
3174 free (directory_table);
3175 directory_table = NULL;
3176 putchar ('\n');
3177 }
3178
3179 return 1;
3180}
3181
3182static int
1c4cc746 3183display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
a262ae96
NC
3184{
3185 unsigned char *data = section->start;
3186 unsigned char *end = data + section->size;
4cb93e3b
TG
3187 int retValRaw = 1;
3188 int retValDecoded = 1;
a262ae96 3189
008f4c78
NC
3190 if (do_debug_lines == 0)
3191 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3192
4cb93e3b 3193 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
a262ae96
NC
3194 retValRaw = display_debug_lines_raw (section, data, end);
3195
4cb93e3b 3196 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
a262ae96
NC
3197 retValDecoded = display_debug_lines_decoded (section, data, end);
3198
4cb93e3b 3199 if (!retValRaw || !retValDecoded)
a262ae96
NC
3200 return 0;
3201
3202 return 1;
3203}
3204
6e3d6dc1
NC
3205static debug_info *
3206find_debug_info_for_offset (unsigned long offset)
3207{
3208 unsigned int i;
3209
3210 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3211 return NULL;
3212
3213 for (i = 0; i < num_debug_info_entries; i++)
3214 if (debug_information[i].cu_offset == offset)
3215 return debug_information + i;
3216
3217 return NULL;
3218}
3219
19e6b90e
L
3220static int
3221display_debug_pubnames (struct dwarf_section *section,
3222 void *file ATTRIBUTE_UNUSED)
3223{
91d6fa6a 3224 DWARF2_Internal_PubNames names;
19e6b90e
L
3225 unsigned char *start = section->start;
3226 unsigned char *end = start + section->size;
3227
6e3d6dc1
NC
3228 /* It does not matter if this load fails,
3229 we test for that later on. */
3230 load_debug_info (file);
3231
19e6b90e
L
3232 printf (_("Contents of the %s section:\n\n"), section->name);
3233
3234 while (start < end)
3235 {
3236 unsigned char *data;
3237 unsigned long offset;
3238 int offset_size, initial_length_size;
3239
3240 data = start;
3241
91d6fa6a 3242 names.pn_length = byte_get (data, 4);
19e6b90e 3243 data += 4;
91d6fa6a 3244 if (names.pn_length == 0xffffffff)
19e6b90e 3245 {
91d6fa6a 3246 names.pn_length = byte_get (data, 8);
19e6b90e
L
3247 data += 8;
3248 offset_size = 8;
3249 initial_length_size = 12;
3250 }
3251 else
3252 {
3253 offset_size = 4;
3254 initial_length_size = 4;
3255 }
3256
91d6fa6a 3257 names.pn_version = byte_get (data, 2);
19e6b90e 3258 data += 2;
6e3d6dc1 3259
91d6fa6a 3260 names.pn_offset = byte_get (data, offset_size);
19e6b90e 3261 data += offset_size;
6e3d6dc1
NC
3262
3263 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3264 && num_debug_info_entries > 0
91d6fa6a 3265 && find_debug_info_for_offset (names.pn_offset) == NULL)
6e3d6dc1 3266 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
47704ddf 3267 (unsigned long) names.pn_offset, section->name);
cecf136e 3268
91d6fa6a 3269 names.pn_size = byte_get (data, offset_size);
19e6b90e
L
3270 data += offset_size;
3271
91d6fa6a 3272 start += names.pn_length + initial_length_size;
19e6b90e 3273
91d6fa6a 3274 if (names.pn_version != 2 && names.pn_version != 3)
19e6b90e
L
3275 {
3276 static int warned = 0;
3277
3278 if (! warned)
3279 {
3280 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3281 warned = 1;
3282 }
3283
3284 continue;
3285 }
3286
3287 printf (_(" Length: %ld\n"),
47704ddf 3288 (long) names.pn_length);
19e6b90e 3289 printf (_(" Version: %d\n"),
91d6fa6a 3290 names.pn_version);
6e3d6dc1 3291 printf (_(" Offset into .debug_info section: 0x%lx\n"),
47704ddf 3292 (unsigned long) names.pn_offset);
19e6b90e 3293 printf (_(" Size of area in .debug_info section: %ld\n"),
47704ddf 3294 (long) names.pn_size);
19e6b90e
L
3295
3296 printf (_("\n Offset\tName\n"));
3297
3298 do
3299 {
3300 offset = byte_get (data, offset_size);
3301
3302 if (offset != 0)
3303 {
3304 data += offset_size;
80c35038 3305 printf (" %-6lx\t%s\n", offset, data);
19e6b90e
L
3306 data += strlen ((char *) data) + 1;
3307 }
3308 }
3309 while (offset != 0);
3310 }
3311
3312 printf ("\n");
3313 return 1;
3314}
3315
3316static int
3317display_debug_macinfo (struct dwarf_section *section,
3318 void *file ATTRIBUTE_UNUSED)
3319{
3320 unsigned char *start = section->start;
3321 unsigned char *end = start + section->size;
3322 unsigned char *curr = start;
3323 unsigned int bytes_read;
3324 enum dwarf_macinfo_record_type op;
3325
3326 printf (_("Contents of the %s section:\n\n"), section->name);
3327
3328 while (curr < end)
3329 {
3330 unsigned int lineno;
3331 const char *string;
3332
3f5e193b 3333 op = (enum dwarf_macinfo_record_type) *curr;
19e6b90e
L
3334 curr++;
3335
3336 switch (op)
3337 {
3338 case DW_MACINFO_start_file:
3339 {
3340 unsigned int filenum;
3341
3342 lineno = read_leb128 (curr, & bytes_read, 0);
3343 curr += bytes_read;
3344 filenum = read_leb128 (curr, & bytes_read, 0);
3345 curr += bytes_read;
3346
3347 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3348 lineno, filenum);
3349 }
3350 break;
3351
3352 case DW_MACINFO_end_file:
3353 printf (_(" DW_MACINFO_end_file\n"));
3354 break;
3355
3356 case DW_MACINFO_define:
3357 lineno = read_leb128 (curr, & bytes_read, 0);
3358 curr += bytes_read;
3359 string = (char *) curr;
3360 curr += strlen (string) + 1;
3361 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3362 lineno, string);
3363 break;
3364
3365 case DW_MACINFO_undef:
3366 lineno = read_leb128 (curr, & bytes_read, 0);
3367 curr += bytes_read;
3368 string = (char *) curr;
3369 curr += strlen (string) + 1;
3370 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3371 lineno, string);
3372 break;
3373
3374 case DW_MACINFO_vendor_ext:
3375 {
3376 unsigned int constant;
3377
3378 constant = read_leb128 (curr, & bytes_read, 0);
3379 curr += bytes_read;
3380 string = (char *) curr;
3381 curr += strlen (string) + 1;
3382 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3383 constant, string);
3384 }
3385 break;
3386 }
3387 }
3388
3389 return 1;
3390}
3391
4ccf1e31
JJ
3392/* Given LINE_OFFSET into the .debug_line section, attempt to return
3393 filename and dirname corresponding to file name table entry with index
3394 FILEIDX. Return NULL on failure. */
3395
3396static unsigned char *
3397get_line_filename_and_dirname (dwarf_vma line_offset, dwarf_vma fileidx,
3398 unsigned char **dir_name)
3399{
3400 struct dwarf_section *section = &debug_displays [line].section;
3401 unsigned char *hdrptr, *dirtable, *file_name;
3402 unsigned int offset_size, initial_length_size;
3403 unsigned int version, opcode_base, bytes_read;
3404 dwarf_vma length, diridx;
3405
3406 *dir_name = NULL;
3407 if (section->start == NULL
3408 || line_offset >= section->size
3409 || fileidx == 0)
3410 return NULL;
3411
3412 hdrptr = section->start + line_offset;
3413 length = byte_get (hdrptr, 4);
3414 hdrptr += 4;
3415 if (length == 0xffffffff)
3416 {
3417 /* This section is 64-bit DWARF 3. */
3418 length = byte_get (hdrptr, 8);
3419 hdrptr += 8;
3420 offset_size = 8;
3421 initial_length_size = 12;
3422 }
3423 else
3424 {
3425 offset_size = 4;
3426 initial_length_size = 4;
3427 }
3428 if (length + initial_length_size > section->size)
3429 return NULL;
3430 version = byte_get (hdrptr, 2);
3431 hdrptr += 2;
3432 if (version != 2 && version != 3 && version != 4)
3433 return NULL;
3434 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
3435 if (version >= 4)
3436 hdrptr++; /* Skip max_ops_per_insn. */
3437 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
3438 opcode_base = byte_get (hdrptr, 1);
3439 if (opcode_base == 0)
3440 return NULL;
3441 hdrptr++;
3442 hdrptr += opcode_base - 1;
3443 dirtable = hdrptr;
3444 /* Skip over dirname table. */
3445 while (*hdrptr != '\0')
3446 hdrptr += strlen ((char *) hdrptr) + 1;
3447 hdrptr++; /* Skip the NUL at the end of the table. */
3448 /* Now skip over preceding filename table entries. */
3449 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
3450 {
3451 hdrptr += strlen ((char *) hdrptr) + 1;
3452 read_leb128 (hdrptr, &bytes_read, 0);
3453 hdrptr += bytes_read;
3454 read_leb128 (hdrptr, &bytes_read, 0);
3455 hdrptr += bytes_read;
3456 read_leb128 (hdrptr, &bytes_read, 0);
3457 hdrptr += bytes_read;
3458 }
3459 if (*hdrptr == '\0')
3460 return NULL;
3461 file_name = hdrptr;
3462 hdrptr += strlen ((char *) hdrptr) + 1;
3463 diridx = read_leb128 (hdrptr, &bytes_read, 0);
3464 if (diridx == 0)
3465 return file_name;
3466 for (; *dirtable != '\0' && diridx > 1; diridx--)
3467 dirtable += strlen ((char *) dirtable) + 1;
3468 if (*dirtable == '\0')
3469 return NULL;
3470 *dir_name = dirtable;
3471 return file_name;
3472}
3473
3474static int
3475display_debug_macro (struct dwarf_section *section,
3476 void *file)
3477{
3478 unsigned char *start = section->start;
3479 unsigned char *end = start + section->size;
3480 unsigned char *curr = start;
3481 unsigned char *extended_op_buf[256];
3482 unsigned int bytes_read;
3483
3484 load_debug_section (str, file);
3485 load_debug_section (line, file);
3486
3487 printf (_("Contents of the %s section:\n\n"), section->name);
3488
3489 while (curr < end)
3490 {
3491 unsigned int lineno, version, flags;
3492 unsigned int offset_size = 4;
3493 const char *string;
3494 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
3495 unsigned char **extended_ops = NULL;
3496
3497 version = byte_get (curr, 2);
3498 curr += 2;
3499
3500 if (version != 4)
3501 {
3502 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3503 section->name);
3504 return 0;
3505 }
3506
3507 flags = byte_get (curr++, 1);
3508 if (flags & 1)
3509 offset_size = 8;
3510 printf (_(" Offset: 0x%lx\n"),
3511 (unsigned long) sec_offset);
3512 printf (_(" Version: %d\n"), version);
3513 printf (_(" Offset size: %d\n"), offset_size);
3514 if (flags & 2)
3515 {
3516 line_offset = byte_get (curr, offset_size);
3517 curr += offset_size;
3518 printf (_(" Offset into .debug_line: 0x%lx\n"),
3519 (unsigned long) line_offset);
3520 }
3521 if (flags & 4)
3522 {
3523 unsigned int i, count = byte_get (curr++, 1), op;
3524 dwarf_vma nargs, n;
3525 memset (extended_op_buf, 0, sizeof (extended_op_buf));
3526 extended_ops = extended_op_buf;
3527 if (count)
3528 {
3529 printf (_(" Extension opcode arguments:\n"));
3530 for (i = 0; i < count; i++)
3531 {
3532 op = byte_get (curr++, 1);
3533 extended_ops[op] = curr;
3534 nargs = read_leb128 (curr, &bytes_read, 0);
3535 curr += bytes_read;
3536 if (nargs == 0)
3537 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op);
3538 else
3539 {
3540 printf (_(" DW_MACRO_GNU_%02x arguments: "), op);
3541 for (n = 0; n < nargs; n++)
3542 {
3543 unsigned int form = byte_get (curr++, 1);
3544 printf ("%s%s", get_FORM_name (form),
3545 n == nargs - 1 ? "\n" : ", ");
3546 switch (form)
3547 {
3548 case DW_FORM_data1:
3549 case DW_FORM_data2:
3550 case DW_FORM_data4:
3551 case DW_FORM_data8:
3552 case DW_FORM_sdata:
3553 case DW_FORM_udata:
3554 case DW_FORM_block:
3555 case DW_FORM_block1:
3556 case DW_FORM_block2:
3557 case DW_FORM_block4:
3558 case DW_FORM_flag:
3559 case DW_FORM_string:
3560 case DW_FORM_strp:
3561 case DW_FORM_sec_offset:
3562 break;
3563 default:
3564 error (_("Invalid extension opcode form %s\n"),
3565 get_FORM_name (form));
3566 return 0;
3567 }
3568 }
3569 }
3570 }
3571 }
3572 }
3573 printf ("\n");
3574
3575 while (1)
3576 {
3577 unsigned int op;
3578
3579 if (curr >= end)
3580 {
3581 error (_(".debug_macro section not zero terminated\n"));
3582 return 0;
3583 }
3584
3585 op = byte_get (curr++, 1);
3586 if (op == 0)
3587 break;
3588
3589 switch (op)
3590 {
3591 case DW_MACRO_GNU_start_file:
3592 {
3593 unsigned int filenum;
3594 unsigned char *file_name = NULL, *dir_name = NULL;
3595
3596 lineno = read_leb128 (curr, &bytes_read, 0);
3597 curr += bytes_read;
3598 filenum = read_leb128 (curr, &bytes_read, 0);
3599 curr += bytes_read;
3600
3601 if ((flags & 2) == 0)
3602 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
3603 else
3604 file_name
3605 = get_line_filename_and_dirname (line_offset, filenum,
3606 &dir_name);
3607 if (file_name == NULL)
3608 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
3609 lineno, filenum);
3610 else
3611 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
3612 lineno, filenum,
3613 dir_name != NULL ? (const char *) dir_name : "",
3614 dir_name != NULL ? "/" : "", file_name);
3615 }
3616 break;
3617
3618 case DW_MACRO_GNU_end_file:
3619 printf (_(" DW_MACRO_GNU_end_file\n"));
3620 break;
3621
3622 case DW_MACRO_GNU_define:
3623 lineno = read_leb128 (curr, &bytes_read, 0);
3624 curr += bytes_read;
3625 string = (char *) curr;
3626 curr += strlen (string) + 1;
3627 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
3628 lineno, string);
3629 break;
3630
3631 case DW_MACRO_GNU_undef:
3632 lineno = read_leb128 (curr, &bytes_read, 0);
3633 curr += bytes_read;
3634 string = (char *) curr;
3635 curr += strlen (string) + 1;
3636 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
3637 lineno, string);
3638 break;
3639
3640 case DW_MACRO_GNU_define_indirect:
3641 lineno = read_leb128 (curr, &bytes_read, 0);
3642 curr += bytes_read;
3643 offset = byte_get (curr, offset_size);
3644 curr += offset_size;
3645 string = fetch_indirect_string (offset);
3646 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
3647 lineno, string);
3648 break;
3649
3650 case DW_MACRO_GNU_undef_indirect:
3651 lineno = read_leb128 (curr, &bytes_read, 0);
3652 curr += bytes_read;
3653 offset = byte_get (curr, offset_size);
3654 curr += offset_size;
3655 string = fetch_indirect_string (offset);
3656 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
3657 lineno, string);
3658 break;
3659
3660 case DW_MACRO_GNU_transparent_include:
3661 offset = byte_get (curr, offset_size);
3662 curr += offset_size;
3663 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
3664 (unsigned long) offset);
3665 break;
3666
a081f3cd
JJ
3667 case DW_MACRO_GNU_define_indirect_alt:
3668 lineno = read_leb128 (curr, &bytes_read, 0);
3669 curr += bytes_read;
3670 offset = byte_get (curr, offset_size);
3671 curr += offset_size;
3672 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
3673 lineno, (unsigned long) offset);
3674 break;
3675
3676 case DW_MACRO_GNU_undef_indirect_alt:
3677 lineno = read_leb128 (curr, &bytes_read, 0);
3678 curr += bytes_read;
3679 offset = byte_get (curr, offset_size);
3680 curr += offset_size;
3681 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
3682 lineno, (unsigned long) offset);
3683 break;
3684
3685 case DW_MACRO_GNU_transparent_include_alt:
3686 offset = byte_get (curr, offset_size);
3687 curr += offset_size;
3688 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
3689 (unsigned long) offset);
3690 break;
3691
4ccf1e31
JJ
3692 default:
3693 if (extended_ops == NULL || extended_ops[op] == NULL)
3694 {
3695 error (_(" Unknown macro opcode %02x seen\n"), op);
3696 return 0;
3697 }
3698 else
3699 {
3700 /* Skip over unhandled opcodes. */
3701 dwarf_vma nargs, n;
3702 unsigned char *desc = extended_ops[op];
3703 nargs = read_leb128 (desc, &bytes_read, 0);
3704 desc += bytes_read;
3705 if (nargs == 0)
3706 {
3707 printf (_(" DW_MACRO_GNU_%02x\n"), op);
3708 break;
3709 }
3710 printf (_(" DW_MACRO_GNU_%02x -"), op);
3711 for (n = 0; n < nargs; n++)
3712 {
3713 curr
3714 = read_and_display_attr_value (0, byte_get (desc++, 1),
3715 curr, 0, 0, offset_size,
3716 version, NULL, 0, NULL);
3717 if (n != nargs - 1)
3718 printf (",");
3719 }
3720 printf ("\n");
3721 }
3722 break;
3723 }
3724 }
3725
3726 printf ("\n");
3727 }
3728
3729 return 1;
3730}
3731
19e6b90e
L
3732static int
3733display_debug_abbrev (struct dwarf_section *section,
3734 void *file ATTRIBUTE_UNUSED)
3735{
3736 abbrev_entry *entry;
3737 unsigned char *start = section->start;
3738 unsigned char *end = start + section->size;
3739
3740 printf (_("Contents of the %s section:\n\n"), section->name);
3741
3742 do
3743 {
7282333f
AM
3744 unsigned char *last;
3745
19e6b90e
L
3746 free_abbrevs ();
3747
7282333f 3748 last = start;
19e6b90e
L
3749 start = process_abbrev_section (start, end);
3750
3751 if (first_abbrev == NULL)
3752 continue;
3753
7282333f 3754 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
19e6b90e
L
3755
3756 for (entry = first_abbrev; entry; entry = entry->next)
3757 {
3758 abbrev_attr *attr;
3759
cc5914eb 3760 printf (" %ld %s [%s]\n",
19e6b90e
L
3761 entry->entry,
3762 get_TAG_name (entry->tag),
3763 entry->children ? _("has children") : _("no children"));
3764
3765 for (attr = entry->first_attr; attr; attr = attr->next)
cc5914eb 3766 printf (" %-18s %s\n",
19e6b90e
L
3767 get_AT_name (attr->attribute),
3768 get_FORM_name (attr->form));
3769 }
3770 }
3771 while (start);
3772
3773 printf ("\n");
3774
3775 return 1;
3776}
3777
4723351a
CC
3778/* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
3779
3780static void
3781display_loc_list (struct dwarf_section *section,
3782 unsigned char **start_ptr,
3783 int debug_info_entry,
3784 unsigned long offset,
3785 unsigned long base_address,
3786 int has_frame_base)
3787{
3788 unsigned char *start = *start_ptr;
3789 unsigned char *section_end = section->start + section->size;
3790 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
3791 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
3792 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
3793 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
3794
3795 dwarf_vma begin;
3796 dwarf_vma end;
3797 unsigned short length;
3798 int need_frame_base;
3799
3800 while (1)
3801 {
3802 if (start + 2 * pointer_size > section_end)
3803 {
3804 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3805 offset);
3806 break;
3807 }
3808
3809 /* Note: we use sign extension here in order to be sure that we can detect
3810 the -1 escape value. Sign extension into the top 32 bits of a 32-bit
3811 address will not affect the values that we display since we always show
3812 hex values, and always the bottom 32-bits. */
3813 begin = byte_get_signed (start, pointer_size);
3814 start += pointer_size;
3815 end = byte_get_signed (start, pointer_size);
3816 start += pointer_size;
3817
3818 printf (" %8.8lx ", offset);
3819
3820 if (begin == 0 && end == 0)
3821 {
3822 printf (_("<End of list>\n"));
3823 break;
3824 }
3825
3826 /* Check base address specifiers. */
3827 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
3828 {
3829 base_address = end;
3830 print_dwarf_vma (begin, pointer_size);
3831 print_dwarf_vma (end, pointer_size);
3832 printf (_("(base address)\n"));
3833 continue;
3834 }
3835
3836 if (start + 2 > section_end)
3837 {
3838 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3839 offset);
3840 break;
3841 }
3842
3843 length = byte_get (start, 2);
3844 start += 2;
3845
3846 if (start + length > section_end)
3847 {
3848 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3849 offset);
3850 break;
3851 }
3852
3853 print_dwarf_vma (begin + base_address, pointer_size);
3854 print_dwarf_vma (end + base_address, pointer_size);
3855
3856 putchar ('(');
3857 need_frame_base = decode_location_expression (start,
3858 pointer_size,
3859 offset_size,
3860 dwarf_version,
3861 length,
3862 cu_offset, section);
3863 putchar (')');
3864
3865 if (need_frame_base && !has_frame_base)
3866 printf (_(" [without DW_AT_frame_base]"));
3867
3868 if (begin == end)
3869 fputs (_(" (start == end)"), stdout);
3870 else if (begin > end)
3871 fputs (_(" (start > end)"), stdout);
3872
3873 putchar ('\n');
3874
3875 start += length;
3876 }
3877
3878 *start_ptr = start;
3879}
3880
3881/* Display a location list from a .dwo section. It uses address indexes rather
3882 than embedded addresses. This code closely follows display_loc_list, but the
3883 two are sufficiently different that combining things is very ugly. */
3884
3885static void
3886display_loc_list_dwo (struct dwarf_section *section,
3887 unsigned char **start_ptr,
3888 int debug_info_entry,
3889 unsigned long offset,
3890 int has_frame_base)
3891{
3892 unsigned char *start = *start_ptr;
3893 unsigned char *section_end = section->start + section->size;
3894 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
3895 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
3896 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
3897 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
3898 int entry_type;
3899 unsigned short length;
3900 int need_frame_base;
3901 dwarf_vma idx;
3902 unsigned int bytes_read;
3903
3904 while (1)
3905 {
3906 printf (" %8.8lx ", offset);
3907
3908 if (start + 2 > section_end)
3909 {
3910 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3911 offset);
3912 break;
3913 }
3914
3915 entry_type = byte_get (start, 1);
3916 start++;
3917 switch (entry_type)
3918 {
3919 case 0: /* A terminating entry. */
3920 idx = byte_get (start, 1);
3921 start++;
3922 *start_ptr = start;
3923 if (idx == 0)
3924 printf (_("<End of list>\n"));
3925 else
3926 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3927 offset);
3928 return;
3929 case 1: /* A base-address entry. */
3930 idx = read_leb128 (start, &bytes_read, 0);
3931 start += bytes_read;
3932 print_dwarf_vma (idx, pointer_size);
3933 printf (_("(base address index)\n"));
3934 continue;
3935 case 2: /* A normal entry. */
3936 idx = read_leb128 (start, &bytes_read, 0);
3937 start += bytes_read;
3938 print_dwarf_vma (idx, pointer_size);
3939 idx = read_leb128 (start, &bytes_read, 0);
3940 start += bytes_read;
3941 print_dwarf_vma (idx, pointer_size);
3942 break;
3943 default:
3944 warn (_("Unknown location-list type 0x%x.\n"), entry_type);
3945 *start_ptr = start;
3946 return;
3947 }
3948
3949 if (start + 2 > section_end)
3950 {
3951 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3952 offset);
3953 break;
3954 }
3955
3956 length = byte_get (start, 2);
3957 start += 2;
3958
3959 if (start + length > section_end)
3960 {
3961 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3962 offset);
3963 break;
3964 }
3965
3966 putchar ('(');
3967 need_frame_base = decode_location_expression (start,
3968 pointer_size,
3969 offset_size,
3970 dwarf_version,
3971 length,
3972 cu_offset, section);
3973 putchar (')');
3974
3975 if (need_frame_base && !has_frame_base)
3976 printf (_(" [without DW_AT_frame_base]"));
3977
3978 putchar ('\n');
3979
3980 start += length;
3981 }
3982
3983 *start_ptr = start;
3984}
3985
51d0d03f
JJ
3986/* Sort array of indexes in ascending order of loc_offsets[idx]. */
3987
3988static dwarf_vma *loc_offsets;
3989
3990static int
3991loc_offsets_compar (const void *ap, const void *bp)
3992{
3993 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
3994 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
3995
3996 return (a > b) - (b > a);
3997}
3998
19e6b90e
L
3999static int
4000display_debug_loc (struct dwarf_section *section, void *file)
4001{
4002 unsigned char *start = section->start;
19e6b90e
L
4003 unsigned long bytes;
4004 unsigned char *section_begin = start;
4005 unsigned int num_loc_list = 0;
4006 unsigned long last_offset = 0;
4007 unsigned int first = 0;
4008 unsigned int i;
4009 unsigned int j;
51d0d03f 4010 unsigned int k;
19e6b90e 4011 int seen_first_offset = 0;
51d0d03f 4012 int locs_sorted = 1;
19e6b90e 4013 unsigned char *next;
51d0d03f 4014 unsigned int *array = NULL;
4723351a
CC
4015 const char *suffix = strrchr (section->name, '.');
4016 int is_dwo = 0;
4017
4018 if (suffix && strcmp (suffix, ".dwo") == 0)
4019 is_dwo = 1;
19e6b90e
L
4020
4021 bytes = section->size;
19e6b90e
L
4022
4023 if (bytes == 0)
4024 {
4025 printf (_("\nThe %s section is empty.\n"), section->name);
4026 return 0;
4027 }
4028
1febe64d
NC
4029 if (load_debug_info (file) == 0)
4030 {
4031 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4032 section->name);
4033 return 0;
4034 }
19e6b90e
L
4035
4036 /* Check the order of location list in .debug_info section. If
4037 offsets of location lists are in the ascending order, we can
4038 use `debug_information' directly. */
4039 for (i = 0; i < num_debug_info_entries; i++)
4040 {
4041 unsigned int num;
4042
4043 num = debug_information [i].num_loc_offsets;
51d0d03f
JJ
4044 if (num > num_loc_list)
4045 num_loc_list = num;
19e6b90e
L
4046
4047 /* Check if we can use `debug_information' directly. */
51d0d03f 4048 if (locs_sorted && num != 0)
19e6b90e
L
4049 {
4050 if (!seen_first_offset)
4051 {
4052 /* This is the first location list. */
4053 last_offset = debug_information [i].loc_offsets [0];
4054 first = i;
4055 seen_first_offset = 1;
4056 j = 1;
4057 }
4058 else
4059 j = 0;
4060
4061 for (; j < num; j++)
4062 {
4063 if (last_offset >
4064 debug_information [i].loc_offsets [j])
4065 {
51d0d03f 4066 locs_sorted = 0;
19e6b90e
L
4067 break;
4068 }
4069 last_offset = debug_information [i].loc_offsets [j];
4070 }
4071 }
4072 }
4073
19e6b90e
L
4074 if (!seen_first_offset)
4075 error (_("No location lists in .debug_info section!\n"));
4076
bfe2612a 4077 /* DWARF sections under Mach-O have non-zero addresses. */
d4bfc77b
AS
4078 if (debug_information [first].num_loc_offsets > 0
4079 && debug_information [first].loc_offsets [0] != section->address)
47704ddf
KT
4080 warn (_("Location lists in %s section start at 0x%s\n"),
4081 section->name,
4082 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
19e6b90e 4083
51d0d03f
JJ
4084 if (!locs_sorted)
4085 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
19e6b90e 4086 printf (_("Contents of the %s section:\n\n"), section->name);
4723351a
CC
4087 if (!is_dwo)
4088 printf (_(" Offset Begin End Expression\n"));
4089 else
4090 printf (_(" Offset Begin idx End idx Expression\n"));
19e6b90e
L
4091
4092 seen_first_offset = 0;
4093 for (i = first; i < num_debug_info_entries; i++)
4094 {
19e6b90e 4095 unsigned long offset;
19e6b90e 4096 unsigned long base_address;
19e6b90e
L
4097 int has_frame_base;
4098
51d0d03f
JJ
4099 if (!locs_sorted)
4100 {
4101 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4102 array[k] = k;
4103 loc_offsets = debug_information [i].loc_offsets;
4104 qsort (array, debug_information [i].num_loc_offsets,
4105 sizeof (*array), loc_offsets_compar);
4106 }
19e6b90e 4107
51d0d03f 4108 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
19e6b90e 4109 {
51d0d03f
JJ
4110 j = locs_sorted ? k : array[k];
4111 if (k
4112 && debug_information [i].loc_offsets [locs_sorted
4113 ? k - 1 : array [k - 1]]
4114 == debug_information [i].loc_offsets [j])
4115 continue;
19e6b90e 4116 has_frame_base = debug_information [i].have_frame_base [j];
bfe2612a 4117 /* DWARF sections under Mach-O have non-zero addresses. */
cecf136e 4118 offset = debug_information [i].loc_offsets [j] - section->address;
19e6b90e
L
4119 next = section_begin + offset;
4120 base_address = debug_information [i].base_address;
4121
4122 if (!seen_first_offset)
4123 seen_first_offset = 1;
4124 else
4125 {
4126 if (start < next)
4127 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
0af1713e
AM
4128 (unsigned long) (start - section_begin),
4129 (unsigned long) (next - section_begin));
19e6b90e
L
4130 else if (start > next)
4131 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
0af1713e
AM
4132 (unsigned long) (start - section_begin),
4133 (unsigned long) (next - section_begin));
19e6b90e
L
4134 }
4135 start = next;
4136
4137 if (offset >= bytes)
4138 {
4139 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4140 offset);
4141 continue;
4142 }
4143
4723351a
CC
4144 if (is_dwo)
4145 display_loc_list_dwo (section, &start, i, offset, has_frame_base);
4146 else
4147 display_loc_list (section, &start, i, offset, base_address,
4148 has_frame_base);
19e6b90e
L
4149 }
4150 }
031cd65f 4151
4723351a 4152 if (start < section->start + section->size)
031cd65f 4153 warn (_("There are %ld unused bytes at the end of section %s\n"),
4723351a 4154 (long) (section->start + section->size - start), section->name);
98fb390a 4155 putchar ('\n');
51d0d03f 4156 free (array);
19e6b90e
L
4157 return 1;
4158}
4159
4160static int
4161display_debug_str (struct dwarf_section *section,
4162 void *file ATTRIBUTE_UNUSED)
4163{
4164 unsigned char *start = section->start;
4165 unsigned long bytes = section->size;
4166 dwarf_vma addr = section->address;
4167
4168 if (bytes == 0)
4169 {
4170 printf (_("\nThe %s section is empty.\n"), section->name);
4171 return 0;
4172 }
4173
4174 printf (_("Contents of the %s section:\n\n"), section->name);
4175
4176 while (bytes)
4177 {
4178 int j;
4179 int k;
4180 int lbytes;
4181
4182 lbytes = (bytes > 16 ? 16 : bytes);
4183
4184 printf (" 0x%8.8lx ", (unsigned long) addr);
4185
4186 for (j = 0; j < 16; j++)
4187 {
4188 if (j < lbytes)
4189 printf ("%2.2x", start[j]);
4190 else
4191 printf (" ");
4192
4193 if ((j & 3) == 3)
4194 printf (" ");
4195 }
4196
4197 for (j = 0; j < lbytes; j++)
4198 {
4199 k = start[j];
4200 if (k >= ' ' && k < 0x80)
4201 printf ("%c", k);
4202 else
4203 printf (".");
4204 }
4205
4206 putchar ('\n');
4207
4208 start += lbytes;
4209 addr += lbytes;
4210 bytes -= lbytes;
4211 }
4212
4213 putchar ('\n');
4214
4215 return 1;
4216}
4217
19e6b90e
L
4218static int
4219display_debug_info (struct dwarf_section *section, void *file)
4220{
4723351a 4221 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
19e6b90e
L
4222}
4223
2b6f5997
CC
4224static int
4225display_debug_types (struct dwarf_section *section, void *file)
4226{
4723351a 4227 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
6f875884
TG
4228}
4229
4230static int
4231display_trace_info (struct dwarf_section *section, void *file)
4232{
4723351a 4233 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
2b6f5997 4234}
19e6b90e
L
4235
4236static int
4237display_debug_aranges (struct dwarf_section *section,
4238 void *file ATTRIBUTE_UNUSED)
4239{
4240 unsigned char *start = section->start;
4241 unsigned char *end = start + section->size;
4242
80c35038 4243 printf (_("Contents of the %s section:\n\n"), section->name);
19e6b90e 4244
6e3d6dc1
NC
4245 /* It does not matter if this load fails,
4246 we test for that later on. */
4247 load_debug_info (file);
4248
19e6b90e
L
4249 while (start < end)
4250 {
4251 unsigned char *hdrptr;
4252 DWARF2_Internal_ARange arange;
91d6fa6a 4253 unsigned char *addr_ranges;
2d9472a2
NC
4254 dwarf_vma length;
4255 dwarf_vma address;
53b8873b 4256 unsigned char address_size;
19e6b90e
L
4257 int excess;
4258 int offset_size;
4259 int initial_length_size;
4260
4261 hdrptr = start;
4262
4263 arange.ar_length = byte_get (hdrptr, 4);
4264 hdrptr += 4;
4265
4266 if (arange.ar_length == 0xffffffff)
4267 {
4268 arange.ar_length = byte_get (hdrptr, 8);
4269 hdrptr += 8;
4270 offset_size = 8;
4271 initial_length_size = 12;
4272 }
4273 else
4274 {
4275 offset_size = 4;
4276 initial_length_size = 4;
4277 }
4278
4279 arange.ar_version = byte_get (hdrptr, 2);
4280 hdrptr += 2;
4281
4282 arange.ar_info_offset = byte_get (hdrptr, offset_size);
4283 hdrptr += offset_size;
4284
6e3d6dc1
NC
4285 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4286 && num_debug_info_entries > 0
4287 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
4288 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
47704ddf 4289 (unsigned long) arange.ar_info_offset, section->name);
6e3d6dc1 4290
19e6b90e
L
4291 arange.ar_pointer_size = byte_get (hdrptr, 1);
4292 hdrptr += 1;
4293
4294 arange.ar_segment_size = byte_get (hdrptr, 1);
4295 hdrptr += 1;
4296
4297 if (arange.ar_version != 2 && arange.ar_version != 3)
4298 {
4299 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4300 break;
4301 }
4302
47704ddf
KT
4303 printf (_(" Length: %ld\n"),
4304 (long) arange.ar_length);
19e6b90e 4305 printf (_(" Version: %d\n"), arange.ar_version);
47704ddf
KT
4306 printf (_(" Offset into .debug_info: 0x%lx\n"),
4307 (unsigned long) arange.ar_info_offset);
19e6b90e
L
4308 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
4309 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
4310
53b8873b
NC
4311 address_size = arange.ar_pointer_size + arange.ar_segment_size;
4312
b3681d67
L
4313 if (address_size == 0)
4314 {
4315 error (_("Invalid address size in %s section!\n"),
4316 section->name);
4317 break;
4318 }
4319
53b8873b
NC
4320 /* The DWARF spec does not require that the address size be a power
4321 of two, but we do. This will have to change if we ever encounter
4322 an uneven architecture. */
4323 if ((address_size & (address_size - 1)) != 0)
4324 {
4325 warn (_("Pointer size + Segment size is not a power of two.\n"));
4326 break;
4327 }
cecf136e 4328
209c9a13
NC
4329 if (address_size > 4)
4330 printf (_("\n Address Length\n"));
4331 else
4332 printf (_("\n Address Length\n"));
19e6b90e 4333
91d6fa6a 4334 addr_ranges = hdrptr;
19e6b90e 4335
53b8873b
NC
4336 /* Must pad to an alignment boundary that is twice the address size. */
4337 excess = (hdrptr - start) % (2 * address_size);
19e6b90e 4338 if (excess)
91d6fa6a 4339 addr_ranges += (2 * address_size) - excess;
19e6b90e 4340
1617e571
AM
4341 start += arange.ar_length + initial_length_size;
4342
91d6fa6a 4343 while (addr_ranges + 2 * address_size <= start)
19e6b90e 4344 {
91d6fa6a 4345 address = byte_get (addr_ranges, address_size);
19e6b90e 4346
91d6fa6a 4347 addr_ranges += address_size;
19e6b90e 4348
91d6fa6a 4349 length = byte_get (addr_ranges, address_size);
19e6b90e 4350
91d6fa6a 4351 addr_ranges += address_size;
19e6b90e 4352
80c35038 4353 printf (" ");
2d9472a2
NC
4354 print_dwarf_vma (address, address_size);
4355 print_dwarf_vma (length, address_size);
4356 putchar ('\n');
19e6b90e 4357 }
19e6b90e
L
4358 }
4359
4360 printf ("\n");
4361
4362 return 1;
4363}
4364
4723351a
CC
4365/* Comparison function for qsort. */
4366static int
4367comp_addr_base (const void * v0, const void * v1)
4368{
4369 debug_info * info0 = (debug_info *) v0;
4370 debug_info * info1 = (debug_info *) v1;
4371 return info0->addr_base - info1->addr_base;
4372}
4373
4374/* Display the debug_addr section. */
4375static int
4376display_debug_addr (struct dwarf_section *section,
4377 void *file)
4378{
4379 debug_info **debug_addr_info;
4380 unsigned char *entry;
4381 unsigned char *end;
4382 unsigned int i;
4383 unsigned int count;
4384
4385 if (section->size == 0)
4386 {
4387 printf (_("\nThe %s section is empty.\n"), section->name);
4388 return 0;
4389 }
4390
4391 if (load_debug_info (file) == 0)
4392 {
4393 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4394 section->name);
4395 return 0;
4396 }
4397
4398 printf (_("Contents of the %s section:\n\n"), section->name);
4399
4400 debug_addr_info = (debug_info **) xmalloc (num_debug_info_entries + 1
4401 * sizeof (debug_info *));
4402
4403 count = 0;
4404 for (i = 0; i < num_debug_info_entries; i++)
4405 {
4406 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
4407 debug_addr_info [count++] = &debug_information [i];
4408 }
4409
4410 /* Add a sentinel to make iteration convenient. */
4411 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
4412 debug_addr_info [count]->addr_base = section->size;
4413
4414 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
4415 for (i = 0; i < count; i++)
4416 {
4417 unsigned int idx;
4418
4419 printf (_(" For compilation unit at offset 0x%s:\n"),
4420 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
4421
4422 printf (_("\tIndex\tOffset\n"));
4423 entry = section->start + debug_addr_info [i]->addr_base;
4424 end = section->start + debug_addr_info [i + 1]->addr_base;
4425 idx = 0;
4426 while (entry < end)
4427 {
4428 dwarf_vma base = byte_get (entry, debug_addr_info [i]->pointer_size);
4429 printf (_("\t%d:\t%s\n"), idx, dwarf_vmatoa ("x", base));
4430 entry += debug_addr_info [i]->pointer_size;
4431 idx++;
4432 }
4433 }
4434 printf ("\n");
4435
4436 free (debug_addr_info);
4437 return 1;
4438}
4439
4440/* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
4441static int
4442display_debug_str_offsets (struct dwarf_section *section,
4443 void *file ATTRIBUTE_UNUSED)
4444{
4445 if (section->size == 0)
4446 {
4447 printf (_("\nThe %s section is empty.\n"), section->name);
4448 return 0;
4449 }
4450 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
4451 what the offset size is for this section. */
4452 return 1;
4453}
4454
01a8f077
JK
4455/* Each debug_information[x].range_lists[y] gets this representation for
4456 sorting purposes. */
4457
4458struct range_entry
467c65bc
NC
4459{
4460 /* The debug_information[x].range_lists[y] value. */
4461 unsigned long ranges_offset;
01a8f077 4462
467c65bc
NC
4463 /* Original debug_information to find parameters of the data. */
4464 debug_info *debug_info_p;
4465};
01a8f077
JK
4466
4467/* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4468
4469static int
4470range_entry_compar (const void *ap, const void *bp)
4471{
3f5e193b
NC
4472 const struct range_entry *a_re = (const struct range_entry *) ap;
4473 const struct range_entry *b_re = (const struct range_entry *) bp;
01a8f077
JK
4474 const unsigned long a = a_re->ranges_offset;
4475 const unsigned long b = b_re->ranges_offset;
4476
4477 return (a > b) - (b > a);
4478}
4479
19e6b90e
L
4480static int
4481display_debug_ranges (struct dwarf_section *section,
4482 void *file ATTRIBUTE_UNUSED)
4483{
4484 unsigned char *start = section->start;
a2ff7a4b 4485 unsigned char *last_start = start;
19e6b90e
L
4486 unsigned long bytes;
4487 unsigned char *section_begin = start;
01a8f077
JK
4488 unsigned int num_range_list, i;
4489 struct range_entry *range_entries, *range_entry_fill;
19e6b90e
L
4490
4491 bytes = section->size;
19e6b90e
L
4492
4493 if (bytes == 0)
4494 {
4495 printf (_("\nThe %s section is empty.\n"), section->name);
4496 return 0;
4497 }
4498
1febe64d
NC
4499 if (load_debug_info (file) == 0)
4500 {
4501 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4502 section->name);
4503 return 0;
4504 }
19e6b90e 4505
01a8f077 4506 num_range_list = 0;
19e6b90e 4507 for (i = 0; i < num_debug_info_entries; i++)
01a8f077 4508 num_range_list += debug_information [i].num_range_lists;
19e6b90e 4509
01a8f077 4510 if (num_range_list == 0)
4723351a
CC
4511 {
4512 /* This can happen when the file was compiled with -gsplit-debug
4513 which removes references to range lists from the primary .o file. */
4514 printf (_("No range lists in .debug_info section.\n"));
4515 return 1;
4516 }
19e6b90e 4517
3f5e193b
NC
4518 range_entries = (struct range_entry *)
4519 xmalloc (sizeof (*range_entries) * num_range_list);
01a8f077 4520 range_entry_fill = range_entries;
19e6b90e 4521
01a8f077
JK
4522 for (i = 0; i < num_debug_info_entries; i++)
4523 {
4524 debug_info *debug_info_p = &debug_information[i];
4525 unsigned int j;
4526
4527 for (j = 0; j < debug_info_p->num_range_lists; j++)
4528 {
4529 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
4530 range_entry_fill->debug_info_p = debug_info_p;
4531 range_entry_fill++;
19e6b90e
L
4532 }
4533 }
4534
01a8f077
JK
4535 qsort (range_entries, num_range_list, sizeof (*range_entries),
4536 range_entry_compar);
19e6b90e 4537
bfe2612a 4538 /* DWARF sections under Mach-O have non-zero addresses. */
4723351a 4539 if (dwarf_check != 0 && range_entries[0].ranges_offset != section->address)
19e6b90e 4540 warn (_("Range lists in %s section start at 0x%lx\n"),
01a8f077 4541 section->name, range_entries[0].ranges_offset);
19e6b90e
L
4542
4543 printf (_("Contents of the %s section:\n\n"), section->name);
4544 printf (_(" Offset Begin End\n"));
4545
01a8f077 4546 for (i = 0; i < num_range_list; i++)
19e6b90e 4547 {
01a8f077
JK
4548 struct range_entry *range_entry = &range_entries[i];
4549 debug_info *debug_info_p = range_entry->debug_info_p;
19e6b90e 4550 unsigned int pointer_size;
01a8f077
JK
4551 unsigned long offset;
4552 unsigned char *next;
19e6b90e
L
4553 unsigned long base_address;
4554
01a8f077
JK
4555 pointer_size = debug_info_p->pointer_size;
4556
4557 /* DWARF sections under Mach-O have non-zero addresses. */
4558 offset = range_entry->ranges_offset - section->address;
4559 next = section_begin + offset;
4560 base_address = debug_info_p->base_address;
cecf136e 4561
4723351a 4562 if (dwarf_check != 0 && i > 0)
19e6b90e 4563 {
01a8f077
JK
4564 if (start < next)
4565 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4566 (unsigned long) (start - section_begin),
4567 (unsigned long) (next - section_begin), section->name);
4568 else if (start > next)
a2ff7a4b
AM
4569 {
4570 if (next == last_start)
4571 continue;
4572 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4573 (unsigned long) (start - section_begin),
4574 (unsigned long) (next - section_begin), section->name);
4575 }
01a8f077
JK
4576 }
4577 start = next;
a2ff7a4b 4578 last_start = next;
19e6b90e 4579
01a8f077
JK
4580 while (1)
4581 {
4582 dwarf_vma begin;
4583 dwarf_vma end;
4584
4585 /* Note: we use sign extension here in order to be sure that
4586 we can detect the -1 escape value. Sign extension into the
4587 top 32 bits of a 32-bit address will not affect the values
4588 that we display since we always show hex values, and always
4589 the bottom 32-bits. */
4590 begin = byte_get_signed (start, pointer_size);
4591 start += pointer_size;
4592 end = byte_get_signed (start, pointer_size);
4593 start += pointer_size;
4594
4595 printf (" %8.8lx ", offset);
4596
4597 if (begin == 0 && end == 0)
19e6b90e 4598 {
01a8f077
JK
4599 printf (_("<End of list>\n"));
4600 break;
19e6b90e 4601 }
19e6b90e 4602
01a8f077
JK
4603 /* Check base address specifiers. */
4604 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
19e6b90e 4605 {
01a8f077
JK
4606 base_address = end;
4607 print_dwarf_vma (begin, pointer_size);
4608 print_dwarf_vma (end, pointer_size);
4609 printf ("(base address)\n");
4610 continue;
4611 }
19e6b90e 4612
01a8f077
JK
4613 print_dwarf_vma (begin + base_address, pointer_size);
4614 print_dwarf_vma (end + base_address, pointer_size);
4a149252 4615
01a8f077
JK
4616 if (begin == end)
4617 fputs (_("(start == end)"), stdout);
4618 else if (begin > end)
4619 fputs (_("(start > end)"), stdout);
19e6b90e 4620
01a8f077 4621 putchar ('\n');
19e6b90e
L
4622 }
4623 }
4624 putchar ('\n');
01a8f077
JK
4625
4626 free (range_entries);
4627
19e6b90e
L
4628 return 1;
4629}
4630
4631typedef struct Frame_Chunk
4632{
4633 struct Frame_Chunk *next;
4634 unsigned char *chunk_start;
4635 int ncols;
4636 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4637 short int *col_type;
4638 int *col_offset;
4639 char *augmentation;
4640 unsigned int code_factor;
4641 int data_factor;
4642 unsigned long pc_begin;
4643 unsigned long pc_range;
4644 int cfa_reg;
4645 int cfa_offset;
4646 int ra;
4647 unsigned char fde_encoding;
4648 unsigned char cfa_exp;
604282a7
JJ
4649 unsigned char ptr_size;
4650 unsigned char segment_size;
19e6b90e
L
4651}
4652Frame_Chunk;
4653
665ce1f6
L
4654static const char *const *dwarf_regnames;
4655static unsigned int dwarf_regnames_count;
4656
19e6b90e
L
4657/* A marker for a col_type that means this column was never referenced
4658 in the frame info. */
4659#define DW_CFA_unreferenced (-1)
4660
665ce1f6
L
4661/* Return 0 if not more space is needed, 1 if more space is needed,
4662 -1 for invalid reg. */
4663
4664static int
4665frame_need_space (Frame_Chunk *fc, unsigned int reg)
19e6b90e
L
4666{
4667 int prev = fc->ncols;
4668
665ce1f6
L
4669 if (reg < (unsigned int) fc->ncols)
4670 return 0;
4671
4672 if (dwarf_regnames_count
4673 && reg > dwarf_regnames_count)
4674 return -1;
19e6b90e
L
4675
4676 fc->ncols = reg + 1;
3f5e193b
NC
4677 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
4678 sizeof (short int));
4679 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
19e6b90e
L
4680
4681 while (prev < fc->ncols)
4682 {
4683 fc->col_type[prev] = DW_CFA_unreferenced;
4684 fc->col_offset[prev] = 0;
4685 prev++;
4686 }
665ce1f6 4687 return 1;
19e6b90e
L
4688}
4689
2dc4cec1
L
4690static const char *const dwarf_regnames_i386[] =
4691{
4692 "eax", "ecx", "edx", "ebx",
4693 "esp", "ebp", "esi", "edi",
4694 "eip", "eflags", NULL,
4695 "st0", "st1", "st2", "st3",
4696 "st4", "st5", "st6", "st7",
4697 NULL, NULL,
4698 "xmm0", "xmm1", "xmm2", "xmm3",
4699 "xmm4", "xmm5", "xmm6", "xmm7",
4700 "mm0", "mm1", "mm2", "mm3",
4701 "mm4", "mm5", "mm6", "mm7",
4702 "fcw", "fsw", "mxcsr",
4703 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
a656ed5b 4704 "tr", "ldtr"
2dc4cec1
L
4705};
4706
b129eb0e
RH
4707void
4708init_dwarf_regnames_i386 (void)
4709{
4710 dwarf_regnames = dwarf_regnames_i386;
4711 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
4712}
4713
2dc4cec1
L
4714static const char *const dwarf_regnames_x86_64[] =
4715{
4716 "rax", "rdx", "rcx", "rbx",
4717 "rsi", "rdi", "rbp", "rsp",
4718 "r8", "r9", "r10", "r11",
4719 "r12", "r13", "r14", "r15",
4720 "rip",
4721 "xmm0", "xmm1", "xmm2", "xmm3",
4722 "xmm4", "xmm5", "xmm6", "xmm7",
4723 "xmm8", "xmm9", "xmm10", "xmm11",
4724 "xmm12", "xmm13", "xmm14", "xmm15",
4725 "st0", "st1", "st2", "st3",
4726 "st4", "st5", "st6", "st7",
4727 "mm0", "mm1", "mm2", "mm3",
4728 "mm4", "mm5", "mm6", "mm7",
4729 "rflags",
4730 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4731 "fs.base", "gs.base", NULL, NULL,
4732 "tr", "ldtr",
a656ed5b 4733 "mxcsr", "fcw", "fsw"
2dc4cec1
L
4734};
4735
b129eb0e
RH
4736void
4737init_dwarf_regnames_x86_64 (void)
4738{
4739 dwarf_regnames = dwarf_regnames_x86_64;
4740 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
4741}
4742
2dc4cec1
L
4743void
4744init_dwarf_regnames (unsigned int e_machine)
4745{
4746 switch (e_machine)
4747 {
4748 case EM_386:
4749 case EM_486:
b129eb0e 4750 init_dwarf_regnames_i386 ();
2dc4cec1
L
4751 break;
4752
4753 case EM_X86_64:
7f502d6c 4754 case EM_L1OM:
7a9068fe 4755 case EM_K1OM:
b129eb0e 4756 init_dwarf_regnames_x86_64 ();
2dc4cec1
L
4757 break;
4758
4759 default:
4760 break;
4761 }
4762}
4763
4764static const char *
4765regname (unsigned int regno, int row)
4766{
4767 static char reg[64];
4768 if (dwarf_regnames
4769 && regno < dwarf_regnames_count
4770 && dwarf_regnames [regno] != NULL)
4771 {
4772 if (row)
4773 return dwarf_regnames [regno];
4774 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
4775 dwarf_regnames [regno]);
4776 }
4777 else
4778 snprintf (reg, sizeof (reg), "r%d", regno);
4779 return reg;
4780}
4781
19e6b90e
L
4782static void
4783frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
4784{
4785 int r;
4786 char tmp[100];
4787
4788 if (*max_regs < fc->ncols)
4789 *max_regs = fc->ncols;
4790
4791 if (*need_col_headers)
4792 {
91d6fa6a 4793 static const char *sloc = " LOC";
2dc4cec1 4794
19e6b90e
L
4795 *need_col_headers = 0;
4796
91d6fa6a 4797 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
19e6b90e
L
4798
4799 for (r = 0; r < *max_regs; r++)
4800 if (fc->col_type[r] != DW_CFA_unreferenced)
4801 {
4802 if (r == fc->ra)
2dc4cec1 4803 printf ("ra ");
19e6b90e 4804 else
2dc4cec1 4805 printf ("%-5s ", regname (r, 1));
19e6b90e
L
4806 }
4807
4808 printf ("\n");
4809 }
4810
2dc4cec1 4811 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
19e6b90e
L
4812 if (fc->cfa_exp)
4813 strcpy (tmp, "exp");
4814 else
2dc4cec1 4815 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
19e6b90e
L
4816 printf ("%-8s ", tmp);
4817
4818 for (r = 0; r < fc->ncols; r++)
4819 {
4820 if (fc->col_type[r] != DW_CFA_unreferenced)
4821 {
4822 switch (fc->col_type[r])
4823 {
4824 case DW_CFA_undefined:
4825 strcpy (tmp, "u");
4826 break;
4827 case DW_CFA_same_value:
4828 strcpy (tmp, "s");
4829 break;
4830 case DW_CFA_offset:
4831 sprintf (tmp, "c%+d", fc->col_offset[r]);
4832 break;
12eae2d3
JJ
4833 case DW_CFA_val_offset:
4834 sprintf (tmp, "v%+d", fc->col_offset[r]);
4835 break;
19e6b90e 4836 case DW_CFA_register:
2dc4cec1 4837 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
19e6b90e
L
4838 break;
4839 case DW_CFA_expression:
4840 strcpy (tmp, "exp");
4841 break;
12eae2d3
JJ
4842 case DW_CFA_val_expression:
4843 strcpy (tmp, "vexp");
4844 break;
19e6b90e
L
4845 default:
4846 strcpy (tmp, "n/a");
4847 break;
4848 }
2dc4cec1 4849 printf ("%-5s ", tmp);
19e6b90e
L
4850 }
4851 }
4852 printf ("\n");
4853}
4854
19e6b90e
L
4855#define GET(N) byte_get (start, N); start += N
4856#define LEB() read_leb128 (start, & length_return, 0); start += length_return
467c65bc 4857#define SLEB() read_sleb128 (start, & length_return); start += length_return
19e6b90e
L
4858
4859static int
4860display_debug_frames (struct dwarf_section *section,
4861 void *file ATTRIBUTE_UNUSED)
4862{
4863 unsigned char *start = section->start;
4864 unsigned char *end = start + section->size;
4865 unsigned char *section_start = start;
4866 Frame_Chunk *chunks = 0;
4867 Frame_Chunk *remembered_state = 0;
4868 Frame_Chunk *rs;
4869 int is_eh = strcmp (section->name, ".eh_frame") == 0;
4870 unsigned int length_return;
4871 int max_regs = 0;
665ce1f6 4872 const char *bad_reg = _("bad register: ");
604282a7 4873 int saved_eh_addr_size = eh_addr_size;
19e6b90e 4874
80c35038 4875 printf (_("Contents of the %s section:\n"), section->name);
19e6b90e
L
4876
4877 while (start < end)
4878 {
4879 unsigned char *saved_start;
4880 unsigned char *block_end;
4881 unsigned long length;
4882 unsigned long cie_id;
4883 Frame_Chunk *fc;
4884 Frame_Chunk *cie;
4885 int need_col_headers = 1;
4886 unsigned char *augmentation_data = NULL;
4887 unsigned long augmentation_data_len = 0;
604282a7 4888 int encoded_ptr_size = saved_eh_addr_size;
19e6b90e
L
4889 int offset_size;
4890 int initial_length_size;
4891
4892 saved_start = start;
4893 length = byte_get (start, 4); start += 4;
4894
4895 if (length == 0)
4896 {
4897 printf ("\n%08lx ZERO terminator\n\n",
4898 (unsigned long)(saved_start - section_start));
b758e50f 4899 continue;
19e6b90e
L
4900 }
4901
4902 if (length == 0xffffffff)
4903 {
4904 length = byte_get (start, 8);
4905 start += 8;
4906 offset_size = 8;
4907 initial_length_size = 12;
4908 }
4909 else
4910 {
4911 offset_size = 4;
4912 initial_length_size = 4;
4913 }
4914
4915 block_end = saved_start + length + initial_length_size;
53b8873b
NC
4916 if (block_end > end)
4917 {
4918 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4919 length, (unsigned long)(saved_start - section_start));
4920 block_end = end;
4921 }
19e6b90e
L
4922 cie_id = byte_get (start, offset_size); start += offset_size;
4923
4924 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
4925 {
4926 int version;
4927
3f5e193b 4928 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
19e6b90e
L
4929 memset (fc, 0, sizeof (Frame_Chunk));
4930
4931 fc->next = chunks;
4932 chunks = fc;
4933 fc->chunk_start = saved_start;
4934 fc->ncols = 0;
3f5e193b
NC
4935 fc->col_type = (short int *) xmalloc (sizeof (short int));
4936 fc->col_offset = (int *) xmalloc (sizeof (int));
cc86f28f 4937 frame_need_space (fc, max_regs - 1);
19e6b90e
L
4938
4939 version = *start++;
4940
4941 fc->augmentation = (char *) start;
4942 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
4943
604282a7
JJ
4944 if (strcmp (fc->augmentation, "eh") == 0)
4945 start += eh_addr_size;
4946
4947 if (version >= 4)
19e6b90e 4948 {
604282a7
JJ
4949 fc->ptr_size = GET (1);
4950 fc->segment_size = GET (1);
4951 eh_addr_size = fc->ptr_size;
19e6b90e 4952 }
604282a7 4953 else
19e6b90e 4954 {
604282a7
JJ
4955 fc->ptr_size = eh_addr_size;
4956 fc->segment_size = 0;
4957 }
4958 fc->code_factor = LEB ();
4959 fc->data_factor = SLEB ();
4960 if (version == 1)
4961 {
4962 fc->ra = GET (1);
19e6b90e
L
4963 }
4964 else
4965 {
604282a7
JJ
4966 fc->ra = LEB ();
4967 }
4968
4969 if (fc->augmentation[0] == 'z')
4970 {
4971 augmentation_data_len = LEB ();
4972 augmentation_data = start;
4973 start += augmentation_data_len;
19e6b90e
L
4974 }
4975 cie = fc;
4976
4977 if (do_debug_frames_interp)
4978 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4979 (unsigned long)(saved_start - section_start), length, cie_id,
4980 fc->augmentation, fc->code_factor, fc->data_factor,
4981 fc->ra);
4982 else
4983 {
4984 printf ("\n%08lx %08lx %08lx CIE\n",
4985 (unsigned long)(saved_start - section_start), length, cie_id);
4986 printf (" Version: %d\n", version);
4987 printf (" Augmentation: \"%s\"\n", fc->augmentation);
604282a7
JJ
4988 if (version >= 4)
4989 {
4990 printf (" Pointer Size: %u\n", fc->ptr_size);
4991 printf (" Segment Size: %u\n", fc->segment_size);
4992 }
19e6b90e
L
4993 printf (" Code alignment factor: %u\n", fc->code_factor);
4994 printf (" Data alignment factor: %d\n", fc->data_factor);
4995 printf (" Return address column: %d\n", fc->ra);
4996
4997 if (augmentation_data_len)
4998 {
4999 unsigned long i;
5000 printf (" Augmentation data: ");
5001 for (i = 0; i < augmentation_data_len; ++i)
5002 printf (" %02x", augmentation_data[i]);
5003 putchar ('\n');
5004 }
5005 putchar ('\n');
5006 }
5007
5008 if (augmentation_data_len)
5009 {
5010 unsigned char *p, *q;
5011 p = (unsigned char *) fc->augmentation + 1;
5012 q = augmentation_data;
5013
5014 while (1)
5015 {
5016 if (*p == 'L')
5017 q++;
5018 else if (*p == 'P')
5019 q += 1 + size_of_encoded_value (*q);
5020 else if (*p == 'R')
5021 fc->fde_encoding = *q++;
d80e8de2
JB
5022 else if (*p == 'S')
5023 ;
19e6b90e
L
5024 else
5025 break;
5026 p++;
5027 }
5028
5029 if (fc->fde_encoding)
5030 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5031 }
5032
5033 frame_need_space (fc, fc->ra);
5034 }
5035 else
5036 {
5037 unsigned char *look_for;
5038 static Frame_Chunk fde_fc;
604282a7 5039 unsigned long segment_selector;
19e6b90e
L
5040
5041 fc = & fde_fc;
5042 memset (fc, 0, sizeof (Frame_Chunk));
5043
5044 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
5045
5046 for (cie = chunks; cie ; cie = cie->next)
5047 if (cie->chunk_start == look_for)
5048 break;
5049
5050 if (!cie)
5051 {
53b8873b 5052 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
1617e571 5053 cie_id, (unsigned long)(saved_start - section_start));
19e6b90e 5054 fc->ncols = 0;
3f5e193b
NC
5055 fc->col_type = (short int *) xmalloc (sizeof (short int));
5056 fc->col_offset = (int *) xmalloc (sizeof (int));
19e6b90e
L
5057 frame_need_space (fc, max_regs - 1);
5058 cie = fc;
5059 fc->augmentation = "";
5060 fc->fde_encoding = 0;
604282a7
JJ
5061 fc->ptr_size = eh_addr_size;
5062 fc->segment_size = 0;
19e6b90e
L
5063 }
5064 else
5065 {
5066 fc->ncols = cie->ncols;
3f5e193b
NC
5067 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
5068 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
19e6b90e
L
5069 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
5070 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
5071 fc->augmentation = cie->augmentation;
604282a7
JJ
5072 fc->ptr_size = cie->ptr_size;
5073 eh_addr_size = cie->ptr_size;
5074 fc->segment_size = cie->segment_size;
19e6b90e
L
5075 fc->code_factor = cie->code_factor;
5076 fc->data_factor = cie->data_factor;
5077 fc->cfa_reg = cie->cfa_reg;
5078 fc->cfa_offset = cie->cfa_offset;
5079 fc->ra = cie->ra;
cc86f28f 5080 frame_need_space (fc, max_regs - 1);
19e6b90e
L
5081 fc->fde_encoding = cie->fde_encoding;
5082 }
5083
5084 if (fc->fde_encoding)
5085 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5086
604282a7
JJ
5087 segment_selector = 0;
5088 if (fc->segment_size)
5089 {
5090 segment_selector = byte_get (start, fc->segment_size);
5091 start += fc->segment_size;
5092 }
bad62cf5 5093 fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section);
19e6b90e
L
5094 start += encoded_ptr_size;
5095 fc->pc_range = byte_get (start, encoded_ptr_size);
5096 start += encoded_ptr_size;
5097
5098 if (cie->augmentation[0] == 'z')
5099 {
5100 augmentation_data_len = LEB ();
5101 augmentation_data = start;
5102 start += augmentation_data_len;
5103 }
5104
604282a7 5105 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
19e6b90e 5106 (unsigned long)(saved_start - section_start), length, cie_id,
604282a7
JJ
5107 (unsigned long)(cie->chunk_start - section_start));
5108 if (fc->segment_size)
5109 printf ("%04lx:", segment_selector);
5110 printf ("%08lx..%08lx\n", fc->pc_begin, fc->pc_begin + fc->pc_range);
19e6b90e
L
5111 if (! do_debug_frames_interp && augmentation_data_len)
5112 {
5113 unsigned long i;
5114
5115 printf (" Augmentation data: ");
5116 for (i = 0; i < augmentation_data_len; ++i)
5117 printf (" %02x", augmentation_data[i]);
5118 putchar ('\n');
5119 putchar ('\n');
5120 }
5121 }
5122
5123 /* At this point, fc is the current chunk, cie (if any) is set, and
5124 we're about to interpret instructions for the chunk. */
5125 /* ??? At present we need to do this always, since this sizes the
5126 fc->col_type and fc->col_offset arrays, which we write into always.
5127 We should probably split the interpreted and non-interpreted bits
5128 into two different routines, since there's so much that doesn't
5129 really overlap between them. */
5130 if (1 || do_debug_frames_interp)
5131 {
5132 /* Start by making a pass over the chunk, allocating storage
5133 and taking note of what registers are used. */
5134 unsigned char *tmp = start;
5135
5136 while (start < block_end)
5137 {
5138 unsigned op, opa;
91d6fa6a 5139 unsigned long reg, temp;
19e6b90e
L
5140
5141 op = *start++;
5142 opa = op & 0x3f;
5143 if (op & 0xc0)
5144 op &= 0xc0;
5145
5146 /* Warning: if you add any more cases to this switch, be
5147 sure to add them to the corresponding switch below. */
5148 switch (op)
5149 {
5150 case DW_CFA_advance_loc:
5151 break;
5152 case DW_CFA_offset:
5153 LEB ();
665ce1f6
L
5154 if (frame_need_space (fc, opa) >= 0)
5155 fc->col_type[opa] = DW_CFA_undefined;
19e6b90e
L
5156 break;
5157 case DW_CFA_restore:
665ce1f6
L
5158 if (frame_need_space (fc, opa) >= 0)
5159 fc->col_type[opa] = DW_CFA_undefined;
19e6b90e
L
5160 break;
5161 case DW_CFA_set_loc:
5162 start += encoded_ptr_size;
5163 break;
5164 case DW_CFA_advance_loc1:
5165 start += 1;
5166 break;
5167 case DW_CFA_advance_loc2:
5168 start += 2;
5169 break;
5170 case DW_CFA_advance_loc4:
5171 start += 4;
5172 break;
5173 case DW_CFA_offset_extended:
12eae2d3 5174 case DW_CFA_val_offset:
19e6b90e 5175 reg = LEB (); LEB ();
665ce1f6
L
5176 if (frame_need_space (fc, reg) >= 0)
5177 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
5178 break;
5179 case DW_CFA_restore_extended:
5180 reg = LEB ();
5181 frame_need_space (fc, reg);
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_undefined:
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_same_value:
5191 reg = 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_register:
5196 reg = LEB (); LEB ();
665ce1f6
L
5197 if (frame_need_space (fc, reg) >= 0)
5198 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
5199 break;
5200 case DW_CFA_def_cfa:
5201 LEB (); LEB ();
5202 break;
5203 case DW_CFA_def_cfa_register:
5204 LEB ();
5205 break;
5206 case DW_CFA_def_cfa_offset:
5207 LEB ();
5208 break;
5209 case DW_CFA_def_cfa_expression:
91d6fa6a
NC
5210 temp = LEB ();
5211 start += temp;
19e6b90e
L
5212 break;
5213 case DW_CFA_expression:
12eae2d3 5214 case DW_CFA_val_expression:
19e6b90e 5215 reg = LEB ();
91d6fa6a
NC
5216 temp = LEB ();
5217 start += temp;
665ce1f6
L
5218 if (frame_need_space (fc, reg) >= 0)
5219 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
5220 break;
5221 case DW_CFA_offset_extended_sf:
12eae2d3 5222 case DW_CFA_val_offset_sf:
19e6b90e 5223 reg = LEB (); SLEB ();
665ce1f6
L
5224 if (frame_need_space (fc, reg) >= 0)
5225 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
5226 break;
5227 case DW_CFA_def_cfa_sf:
5228 LEB (); SLEB ();
5229 break;
5230 case DW_CFA_def_cfa_offset_sf:
5231 SLEB ();
5232 break;
5233 case DW_CFA_MIPS_advance_loc8:
5234 start += 8;
5235 break;
5236 case DW_CFA_GNU_args_size:
5237 LEB ();
5238 break;
5239 case DW_CFA_GNU_negative_offset_extended:
5240 reg = LEB (); LEB ();
665ce1f6
L
5241 if (frame_need_space (fc, reg) >= 0)
5242 fc->col_type[reg] = DW_CFA_undefined;
5243 break;
19e6b90e
L
5244 default:
5245 break;
5246 }
5247 }
5248 start = tmp;
5249 }
5250
5251 /* Now we know what registers are used, make a second pass over
5252 the chunk, this time actually printing out the info. */
5253
5254 while (start < block_end)
5255 {
5256 unsigned op, opa;
5257 unsigned long ul, reg, roffs;
5258 long l, ofs;
5259 dwarf_vma vma;
665ce1f6 5260 const char *reg_prefix = "";
19e6b90e
L
5261
5262 op = *start++;
5263 opa = op & 0x3f;
5264 if (op & 0xc0)
5265 op &= 0xc0;
5266
5267 /* Warning: if you add any more cases to this switch, be
5268 sure to add them to the corresponding switch above. */
5269 switch (op)
5270 {
5271 case DW_CFA_advance_loc:
5272 if (do_debug_frames_interp)
5273 frame_display_row (fc, &need_col_headers, &max_regs);
5274 else
5275 printf (" DW_CFA_advance_loc: %d to %08lx\n",
5276 opa * fc->code_factor,
5277 fc->pc_begin + opa * fc->code_factor);
5278 fc->pc_begin += opa * fc->code_factor;
5279 break;
5280
5281 case DW_CFA_offset:
5282 roffs = LEB ();
665ce1f6
L
5283 if (opa >= (unsigned int) fc->ncols)
5284 reg_prefix = bad_reg;
5285 if (! do_debug_frames_interp || *reg_prefix != '\0')
5286 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
5287 reg_prefix, regname (opa, 0),
5288 roffs * fc->data_factor);
5289 if (*reg_prefix == '\0')
5290 {
5291 fc->col_type[opa] = DW_CFA_offset;
5292 fc->col_offset[opa] = roffs * fc->data_factor;
5293 }
19e6b90e
L
5294 break;
5295
5296 case DW_CFA_restore:
665ce1f6
L
5297 if (opa >= (unsigned int) cie->ncols
5298 || opa >= (unsigned int) fc->ncols)
5299 reg_prefix = bad_reg;
5300 if (! do_debug_frames_interp || *reg_prefix != '\0')
5301 printf (" DW_CFA_restore: %s%s\n",
5302 reg_prefix, regname (opa, 0));
5303 if (*reg_prefix == '\0')
5304 {
5305 fc->col_type[opa] = cie->col_type[opa];
5306 fc->col_offset[opa] = cie->col_offset[opa];
b3f5b73b
ILT
5307 if (do_debug_frames_interp
5308 && fc->col_type[opa] == DW_CFA_unreferenced)
5309 fc->col_type[opa] = DW_CFA_undefined;
665ce1f6 5310 }
19e6b90e
L
5311 break;
5312
5313 case DW_CFA_set_loc:
bad62cf5 5314 vma = get_encoded_value (start, fc->fde_encoding, section);
19e6b90e
L
5315 start += encoded_ptr_size;
5316 if (do_debug_frames_interp)
5317 frame_display_row (fc, &need_col_headers, &max_regs);
5318 else
5319 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
5320 fc->pc_begin = vma;
5321 break;
5322
5323 case DW_CFA_advance_loc1:
5324 ofs = byte_get (start, 1); start += 1;
5325 if (do_debug_frames_interp)
5326 frame_display_row (fc, &need_col_headers, &max_regs);
5327 else
5328 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
5329 ofs * fc->code_factor,
5330 fc->pc_begin + ofs * fc->code_factor);
5331 fc->pc_begin += ofs * fc->code_factor;
5332 break;
5333
5334 case DW_CFA_advance_loc2:
5335 ofs = byte_get (start, 2); start += 2;
5336 if (do_debug_frames_interp)
5337 frame_display_row (fc, &need_col_headers, &max_regs);
5338 else
5339 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
5340 ofs * fc->code_factor,
5341 fc->pc_begin + ofs * fc->code_factor);
5342 fc->pc_begin += ofs * fc->code_factor;
5343 break;
5344
5345 case DW_CFA_advance_loc4:
5346 ofs = byte_get (start, 4); start += 4;
5347 if (do_debug_frames_interp)
5348 frame_display_row (fc, &need_col_headers, &max_regs);
5349 else
5350 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
5351 ofs * fc->code_factor,
5352 fc->pc_begin + ofs * fc->code_factor);
5353 fc->pc_begin += ofs * fc->code_factor;
5354 break;
5355
5356 case DW_CFA_offset_extended:
5357 reg = LEB ();
5358 roffs = LEB ();
665ce1f6
L
5359 if (reg >= (unsigned int) fc->ncols)
5360 reg_prefix = bad_reg;
5361 if (! do_debug_frames_interp || *reg_prefix != '\0')
5362 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
5363 reg_prefix, regname (reg, 0),
5364 roffs * fc->data_factor);
5365 if (*reg_prefix == '\0')
5366 {
5367 fc->col_type[reg] = DW_CFA_offset;
5368 fc->col_offset[reg] = roffs * fc->data_factor;
5369 }
19e6b90e
L
5370 break;
5371
12eae2d3
JJ
5372 case DW_CFA_val_offset:
5373 reg = LEB ();
5374 roffs = LEB ();
665ce1f6
L
5375 if (reg >= (unsigned int) fc->ncols)
5376 reg_prefix = bad_reg;
5377 if (! do_debug_frames_interp || *reg_prefix != '\0')
5378 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
5379 reg_prefix, regname (reg, 0),
5380 roffs * fc->data_factor);
5381 if (*reg_prefix == '\0')
5382 {
5383 fc->col_type[reg] = DW_CFA_val_offset;
5384 fc->col_offset[reg] = roffs * fc->data_factor;
5385 }
12eae2d3
JJ
5386 break;
5387
19e6b90e
L
5388 case DW_CFA_restore_extended:
5389 reg = LEB ();
665ce1f6
L
5390 if (reg >= (unsigned int) cie->ncols
5391 || reg >= (unsigned int) fc->ncols)
5392 reg_prefix = bad_reg;
5393 if (! do_debug_frames_interp || *reg_prefix != '\0')
5394 printf (" DW_CFA_restore_extended: %s%s\n",
5395 reg_prefix, regname (reg, 0));
5396 if (*reg_prefix == '\0')
5397 {
5398 fc->col_type[reg] = cie->col_type[reg];
5399 fc->col_offset[reg] = cie->col_offset[reg];
5400 }
19e6b90e
L
5401 break;
5402
5403 case DW_CFA_undefined:
5404 reg = LEB ();
665ce1f6
L
5405 if (reg >= (unsigned int) fc->ncols)
5406 reg_prefix = bad_reg;
5407 if (! do_debug_frames_interp || *reg_prefix != '\0')
5408 printf (" DW_CFA_undefined: %s%s\n",
5409 reg_prefix, regname (reg, 0));
5410 if (*reg_prefix == '\0')
5411 {
5412 fc->col_type[reg] = DW_CFA_undefined;
5413 fc->col_offset[reg] = 0;
5414 }
19e6b90e
L
5415 break;
5416
5417 case DW_CFA_same_value:
5418 reg = LEB ();
665ce1f6
L
5419 if (reg >= (unsigned int) fc->ncols)
5420 reg_prefix = bad_reg;
5421 if (! do_debug_frames_interp || *reg_prefix != '\0')
5422 printf (" DW_CFA_same_value: %s%s\n",
5423 reg_prefix, regname (reg, 0));
5424 if (*reg_prefix == '\0')
5425 {
5426 fc->col_type[reg] = DW_CFA_same_value;
5427 fc->col_offset[reg] = 0;
5428 }
19e6b90e
L
5429 break;
5430
5431 case DW_CFA_register:
5432 reg = LEB ();
5433 roffs = LEB ();
665ce1f6
L
5434 if (reg >= (unsigned int) fc->ncols)
5435 reg_prefix = bad_reg;
5436 if (! do_debug_frames_interp || *reg_prefix != '\0')
2dc4cec1 5437 {
665ce1f6
L
5438 printf (" DW_CFA_register: %s%s in ",
5439 reg_prefix, regname (reg, 0));
2dc4cec1
L
5440 puts (regname (roffs, 0));
5441 }
665ce1f6
L
5442 if (*reg_prefix == '\0')
5443 {
5444 fc->col_type[reg] = DW_CFA_register;
5445 fc->col_offset[reg] = roffs;
5446 }
19e6b90e
L
5447 break;
5448
5449 case DW_CFA_remember_state:
5450 if (! do_debug_frames_interp)
5451 printf (" DW_CFA_remember_state\n");
3f5e193b 5452 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
19e6b90e 5453 rs->ncols = fc->ncols;
3f5e193b
NC
5454 rs->col_type = (short int *) xcmalloc (rs->ncols,
5455 sizeof (short int));
5456 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int));
19e6b90e
L
5457 memcpy (rs->col_type, fc->col_type, rs->ncols);
5458 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
5459 rs->next = remembered_state;
5460 remembered_state = rs;
5461 break;
5462
5463 case DW_CFA_restore_state:
5464 if (! do_debug_frames_interp)
5465 printf (" DW_CFA_restore_state\n");
5466 rs = remembered_state;
5467 if (rs)
5468 {
5469 remembered_state = rs->next;
cc86f28f 5470 frame_need_space (fc, rs->ncols - 1);
19e6b90e
L
5471 memcpy (fc->col_type, rs->col_type, rs->ncols);
5472 memcpy (fc->col_offset, rs->col_offset,
5473 rs->ncols * sizeof (int));
5474 free (rs->col_type);
5475 free (rs->col_offset);
5476 free (rs);
5477 }
5478 else if (do_debug_frames_interp)
5479 printf ("Mismatched DW_CFA_restore_state\n");
5480 break;
5481
5482 case DW_CFA_def_cfa:
5483 fc->cfa_reg = LEB ();
5484 fc->cfa_offset = LEB ();
5485 fc->cfa_exp = 0;
5486 if (! do_debug_frames_interp)
2dc4cec1
L
5487 printf (" DW_CFA_def_cfa: %s ofs %d\n",
5488 regname (fc->cfa_reg, 0), fc->cfa_offset);
19e6b90e
L
5489 break;
5490
5491 case DW_CFA_def_cfa_register:
5492 fc->cfa_reg = LEB ();
5493 fc->cfa_exp = 0;
5494 if (! do_debug_frames_interp)
2dc4cec1
L
5495 printf (" DW_CFA_def_cfa_register: %s\n",
5496 regname (fc->cfa_reg, 0));
19e6b90e
L
5497 break;
5498
5499 case DW_CFA_def_cfa_offset:
5500 fc->cfa_offset = LEB ();
5501 if (! do_debug_frames_interp)
5502 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
5503 break;
5504
5505 case DW_CFA_nop:
5506 if (! do_debug_frames_interp)
5507 printf (" DW_CFA_nop\n");
5508 break;
5509
5510 case DW_CFA_def_cfa_expression:
5511 ul = LEB ();
5512 if (! do_debug_frames_interp)
5513 {
5514 printf (" DW_CFA_def_cfa_expression (");
b7807392
JJ
5515 decode_location_expression (start, eh_addr_size, 0, -1,
5516 ul, 0, section);
19e6b90e
L
5517 printf (")\n");
5518 }
5519 fc->cfa_exp = 1;
5520 start += ul;
5521 break;
5522
5523 case DW_CFA_expression:
5524 reg = LEB ();
5525 ul = LEB ();
665ce1f6
L
5526 if (reg >= (unsigned int) fc->ncols)
5527 reg_prefix = bad_reg;
5528 if (! do_debug_frames_interp || *reg_prefix != '\0')
19e6b90e 5529 {
665ce1f6
L
5530 printf (" DW_CFA_expression: %s%s (",
5531 reg_prefix, regname (reg, 0));
b7807392 5532 decode_location_expression (start, eh_addr_size, 0, -1,
f1c4cc75 5533 ul, 0, section);
19e6b90e
L
5534 printf (")\n");
5535 }
665ce1f6
L
5536 if (*reg_prefix == '\0')
5537 fc->col_type[reg] = DW_CFA_expression;
19e6b90e
L
5538 start += ul;
5539 break;
5540
12eae2d3
JJ
5541 case DW_CFA_val_expression:
5542 reg = LEB ();
5543 ul = LEB ();
665ce1f6
L
5544 if (reg >= (unsigned int) fc->ncols)
5545 reg_prefix = bad_reg;
5546 if (! do_debug_frames_interp || *reg_prefix != '\0')
12eae2d3 5547 {
665ce1f6
L
5548 printf (" DW_CFA_val_expression: %s%s (",
5549 reg_prefix, regname (reg, 0));
b7807392
JJ
5550 decode_location_expression (start, eh_addr_size, 0, -1,
5551 ul, 0, section);
12eae2d3
JJ
5552 printf (")\n");
5553 }
665ce1f6
L
5554 if (*reg_prefix == '\0')
5555 fc->col_type[reg] = DW_CFA_val_expression;
12eae2d3
JJ
5556 start += ul;
5557 break;
5558
19e6b90e
L
5559 case DW_CFA_offset_extended_sf:
5560 reg = LEB ();
5561 l = SLEB ();
665ce1f6
L
5562 if (frame_need_space (fc, reg) < 0)
5563 reg_prefix = bad_reg;
5564 if (! do_debug_frames_interp || *reg_prefix != '\0')
5565 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5566 reg_prefix, regname (reg, 0),
5567 l * fc->data_factor);
5568 if (*reg_prefix == '\0')
5569 {
5570 fc->col_type[reg] = DW_CFA_offset;
5571 fc->col_offset[reg] = l * fc->data_factor;
5572 }
19e6b90e
L
5573 break;
5574
12eae2d3
JJ
5575 case DW_CFA_val_offset_sf:
5576 reg = LEB ();
5577 l = SLEB ();
665ce1f6
L
5578 if (frame_need_space (fc, reg) < 0)
5579 reg_prefix = bad_reg;
5580 if (! do_debug_frames_interp || *reg_prefix != '\0')
5581 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5582 reg_prefix, regname (reg, 0),
5583 l * fc->data_factor);
5584 if (*reg_prefix == '\0')
5585 {
5586 fc->col_type[reg] = DW_CFA_val_offset;
5587 fc->col_offset[reg] = l * fc->data_factor;
5588 }
12eae2d3
JJ
5589 break;
5590
19e6b90e
L
5591 case DW_CFA_def_cfa_sf:
5592 fc->cfa_reg = LEB ();
5593 fc->cfa_offset = SLEB ();
5594 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5595 fc->cfa_exp = 0;
5596 if (! do_debug_frames_interp)
2dc4cec1
L
5597 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5598 regname (fc->cfa_reg, 0), fc->cfa_offset);
19e6b90e
L
5599 break;
5600
5601 case DW_CFA_def_cfa_offset_sf:
5602 fc->cfa_offset = SLEB ();
5603 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5604 if (! do_debug_frames_interp)
5605 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
5606 break;
5607
5608 case DW_CFA_MIPS_advance_loc8:
5609 ofs = byte_get (start, 8); start += 8;
5610 if (do_debug_frames_interp)
5611 frame_display_row (fc, &need_col_headers, &max_regs);
5612 else
5613 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5614 ofs * fc->code_factor,
5615 fc->pc_begin + ofs * fc->code_factor);
5616 fc->pc_begin += ofs * fc->code_factor;
5617 break;
5618
5619 case DW_CFA_GNU_window_save:
5620 if (! do_debug_frames_interp)
5621 printf (" DW_CFA_GNU_window_save\n");
5622 break;
5623
5624 case DW_CFA_GNU_args_size:
5625 ul = LEB ();
5626 if (! do_debug_frames_interp)
5627 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
5628 break;
5629
5630 case DW_CFA_GNU_negative_offset_extended:
5631 reg = LEB ();
5632 l = - LEB ();
665ce1f6
L
5633 if (frame_need_space (fc, reg) < 0)
5634 reg_prefix = bad_reg;
5635 if (! do_debug_frames_interp || *reg_prefix != '\0')
5636 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5637 reg_prefix, regname (reg, 0),
5638 l * fc->data_factor);
5639 if (*reg_prefix == '\0')
5640 {
5641 fc->col_type[reg] = DW_CFA_offset;
5642 fc->col_offset[reg] = l * fc->data_factor;
5643 }
19e6b90e
L
5644 break;
5645
5646 default:
53b8873b
NC
5647 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
5648 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
5649 else
cecf136e 5650 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
19e6b90e
L
5651 start = block_end;
5652 }
5653 }
5654
5655 if (do_debug_frames_interp)
5656 frame_display_row (fc, &need_col_headers, &max_regs);
5657
5658 start = block_end;
604282a7 5659 eh_addr_size = saved_eh_addr_size;
19e6b90e
L
5660 }
5661
5662 printf ("\n");
5663
5664 return 1;
5665}
5666
5667#undef GET
5668#undef LEB
5669#undef SLEB
5670
5bbdf3d5
DE
5671static int
5672display_gdb_index (struct dwarf_section *section,
5673 void *file ATTRIBUTE_UNUSED)
5674{
5675 unsigned char *start = section->start;
5676 uint32_t version;
5677 uint32_t cu_list_offset, tu_list_offset;
5678 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
5679 unsigned int cu_list_elements, tu_list_elements;
5680 unsigned int address_table_size, symbol_table_slots;
5681 unsigned char *cu_list, *tu_list;
5682 unsigned char *address_table, *symbol_table, *constant_pool;
5683 unsigned int i;
5684
5685 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5686
5687 printf (_("Contents of the %s section:\n"), section->name);
5688
5689 if (section->size < 6 * sizeof (uint32_t))
5690 {
5691 warn (_("Truncated header in the %s section.\n"), section->name);
5692 return 0;
5693 }
5694
5695 version = byte_get_little_endian (start, 4);
da88a764 5696 printf (_("Version %ld\n"), (long) version);
5bbdf3d5
DE
5697
5698 /* Prior versions are obsolete, and future versions may not be
5699 backwards compatible. */
8d6eee87 5700 if (version < 3 || version > 7)
5bbdf3d5 5701 {
da88a764 5702 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
5bbdf3d5
DE
5703 return 0;
5704 }
8d6eee87
TT
5705 if (version < 4)
5706 warn (_("The address table data in version 3 may be wrong.\n"));
5707 if (version < 5)
5708 warn (_("Version 4 does not support case insensitive lookups.\n"));
5709 if (version < 6)
5710 warn (_("Version 5 does not include inlined functions.\n"));
5711 if (version < 7)
5712 warn (_("Version 6 does not include symbol attributes.\n"));
5bbdf3d5
DE
5713
5714 cu_list_offset = byte_get_little_endian (start + 4, 4);
5715 tu_list_offset = byte_get_little_endian (start + 8, 4);
5716 address_table_offset = byte_get_little_endian (start + 12, 4);
5717 symbol_table_offset = byte_get_little_endian (start + 16, 4);
5718 constant_pool_offset = byte_get_little_endian (start + 20, 4);
5719
5720 if (cu_list_offset > section->size
5721 || tu_list_offset > section->size
5722 || address_table_offset > section->size
5723 || symbol_table_offset > section->size
5724 || constant_pool_offset > section->size)
5725 {
5726 warn (_("Corrupt header in the %s section.\n"), section->name);
5727 return 0;
5728 }
5729
5730 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
5731 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
5732 address_table_size = symbol_table_offset - address_table_offset;
5733 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
5734
5735 cu_list = start + cu_list_offset;
5736 tu_list = start + tu_list_offset;
5737 address_table = start + address_table_offset;
5738 symbol_table = start + symbol_table_offset;
5739 constant_pool = start + constant_pool_offset;
5740
5741 printf (_("\nCU table:\n"));
5742 for (i = 0; i < cu_list_elements; i += 2)
5743 {
5744 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
5745 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
5746
5747 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
5748 (unsigned long) cu_offset,
5749 (unsigned long) (cu_offset + cu_length - 1));
5750 }
5751
5752 printf (_("\nTU table:\n"));
5753 for (i = 0; i < tu_list_elements; i += 3)
5754 {
5755 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
5756 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
5757 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
5758
5759 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
5760 (unsigned long) tu_offset,
5761 (unsigned long) type_offset);
5762 print_dwarf_vma (signature, 8);
5763 printf ("\n");
5764 }
5765
5766 printf (_("\nAddress table:\n"));
5767 for (i = 0; i < address_table_size; i += 2 * 8 + 4)
5768 {
5769 uint64_t low = byte_get_little_endian (address_table + i, 8);
5770 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
5771 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
5772
5773 print_dwarf_vma (low, 8);
5774 print_dwarf_vma (high, 8);
da88a764 5775 printf (_("%lu\n"), (unsigned long) cu_index);
5bbdf3d5
DE
5776 }
5777
5778 printf (_("\nSymbol table:\n"));
5779 for (i = 0; i < symbol_table_slots; ++i)
5780 {
5781 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
5782 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
5783 uint32_t num_cus, cu;
5784
5785 if (name_offset != 0
5786 || cu_vector_offset != 0)
5787 {
5788 unsigned int j;
5789
5790 printf ("[%3u] %s:", i, constant_pool + name_offset);
5791 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
8d6eee87
TT
5792 if (num_cus > 1)
5793 printf ("\n");
5bbdf3d5
DE
5794 for (j = 0; j < num_cus; ++j)
5795 {
7c1cef97 5796 int is_static;
8d6eee87
TT
5797 gdb_index_symbol_kind kind;
5798
5bbdf3d5 5799 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
7c1cef97 5800 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
8d6eee87
TT
5801 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
5802 cu = GDB_INDEX_CU_VALUE (cu);
5bbdf3d5 5803 /* Convert to TU number if it's for a type unit. */
ad6b52dd 5804 if (cu >= cu_list_elements / 2)
8d6eee87
TT
5805 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
5806 (unsigned long) (cu - cu_list_elements / 2));
5bbdf3d5 5807 else
8d6eee87
TT
5808 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
5809
5810 switch (kind)
5811 {
5812 case GDB_INDEX_SYMBOL_KIND_NONE:
5813 printf (_(" [no symbol information]"));
5814 break;
5815 case GDB_INDEX_SYMBOL_KIND_TYPE:
7c1cef97
DE
5816 printf (is_static
5817 ? _(" [static type]")
5818 : _(" [global type]"));
8d6eee87
TT
5819 break;
5820 case GDB_INDEX_SYMBOL_KIND_VARIABLE:
7c1cef97
DE
5821 printf (is_static
5822 ? _(" [static variable]")
5823 : _(" [global variable]"));
8d6eee87
TT
5824 break;
5825 case GDB_INDEX_SYMBOL_KIND_FUNCTION:
7c1cef97
DE
5826 printf (is_static
5827 ? _(" [static function]")
5828 : _(" [global function]"));
8d6eee87
TT
5829 break;
5830 case GDB_INDEX_SYMBOL_KIND_OTHER:
7c1cef97
DE
5831 printf (is_static
5832 ? _(" [static other]")
5833 : _(" [global other]"));
8d6eee87
TT
5834 break;
5835 default:
7c1cef97
DE
5836 printf (is_static
5837 ? _(" [static unknown: %d]")
5838 : _(" [global unknown: %d]"),
5839 kind);
8d6eee87
TT
5840 break;
5841 }
5842 if (num_cus > 1)
5843 printf ("\n");
5bbdf3d5 5844 }
8d6eee87
TT
5845 if (num_cus <= 1)
5846 printf ("\n");
5bbdf3d5
DE
5847 }
5848 }
5849
5850 return 1;
5851}
5852
19e6b90e
L
5853static int
5854display_debug_not_supported (struct dwarf_section *section,
5855 void *file ATTRIBUTE_UNUSED)
5856{
5857 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5858 section->name);
5859
5860 return 1;
5861}
5862
5863void *
5864cmalloc (size_t nmemb, size_t size)
5865{
5866 /* Check for overflow. */
5867 if (nmemb >= ~(size_t) 0 / size)
5868 return NULL;
5869 else
5870 return malloc (nmemb * size);
5871}
5872
5873void *
5874xcmalloc (size_t nmemb, size_t size)
5875{
5876 /* Check for overflow. */
5877 if (nmemb >= ~(size_t) 0 / size)
5878 return NULL;
5879 else
5880 return xmalloc (nmemb * size);
5881}
5882
5883void *
5884xcrealloc (void *ptr, size_t nmemb, size_t size)
5885{
5886 /* Check for overflow. */
5887 if (nmemb >= ~(size_t) 0 / size)
5888 return NULL;
5889 else
5890 return xrealloc (ptr, nmemb * size);
5891}
5892
19e6b90e
L
5893void
5894free_debug_memory (void)
5895{
3f5e193b 5896 unsigned int i;
19e6b90e
L
5897
5898 free_abbrevs ();
5899
5900 for (i = 0; i < max; i++)
3f5e193b 5901 free_debug_section ((enum dwarf_section_display_enum) i);
19e6b90e 5902
cc86f28f 5903 if (debug_information != NULL)
19e6b90e 5904 {
cc86f28f 5905 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
19e6b90e 5906 {
cc86f28f 5907 for (i = 0; i < num_debug_info_entries; i++)
19e6b90e 5908 {
cc86f28f
NC
5909 if (!debug_information [i].max_loc_offsets)
5910 {
5911 free (debug_information [i].loc_offsets);
5912 free (debug_information [i].have_frame_base);
5913 }
5914 if (!debug_information [i].max_range_lists)
5915 free (debug_information [i].range_lists);
19e6b90e 5916 }
19e6b90e 5917 }
cc86f28f 5918
19e6b90e
L
5919 free (debug_information);
5920 debug_information = NULL;
5921 num_debug_info_entries = 0;
5922 }
19e6b90e
L
5923}
5924
4cb93e3b
TG
5925void
5926dwarf_select_sections_by_names (const char *names)
5927{
5928 typedef struct
5929 {
5930 const char * option;
5931 int * variable;
f9f0e732 5932 int val;
4cb93e3b
TG
5933 }
5934 debug_dump_long_opts;
5935
5936 static const debug_dump_long_opts opts_table [] =
5937 {
5938 /* Please keep this table alpha- sorted. */
5939 { "Ranges", & do_debug_ranges, 1 },
5940 { "abbrev", & do_debug_abbrevs, 1 },
5941 { "aranges", & do_debug_aranges, 1 },
5942 { "frames", & do_debug_frames, 1 },
5943 { "frames-interp", & do_debug_frames_interp, 1 },
5944 { "info", & do_debug_info, 1 },
5945 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
5946 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
5947 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
5948 { "loc", & do_debug_loc, 1 },
5949 { "macro", & do_debug_macinfo, 1 },
5950 { "pubnames", & do_debug_pubnames, 1 },
357da287 5951 { "pubtypes", & do_debug_pubtypes, 1 },
4cb93e3b
TG
5952 /* This entry is for compatability
5953 with earlier versions of readelf. */
5954 { "ranges", & do_debug_aranges, 1 },
5955 { "str", & do_debug_str, 1 },
5bbdf3d5
DE
5956 /* The special .gdb_index section. */
5957 { "gdb_index", & do_gdb_index, 1 },
6f875884
TG
5958 /* These trace_* sections are used by Itanium VMS. */
5959 { "trace_abbrev", & do_trace_abbrevs, 1 },
5960 { "trace_aranges", & do_trace_aranges, 1 },
5961 { "trace_info", & do_trace_info, 1 },
4cb93e3b
TG
5962 { NULL, NULL, 0 }
5963 };
5964
5965 const char *p;
467c65bc 5966
4cb93e3b
TG
5967 p = names;
5968 while (*p)
5969 {
5970 const debug_dump_long_opts * entry;
467c65bc 5971
4cb93e3b
TG
5972 for (entry = opts_table; entry->option; entry++)
5973 {
5974 size_t len = strlen (entry->option);
467c65bc 5975
4cb93e3b
TG
5976 if (strncmp (p, entry->option, len) == 0
5977 && (p[len] == ',' || p[len] == '\0'))
5978 {
5979 * entry->variable |= entry->val;
467c65bc 5980
4cb93e3b
TG
5981 /* The --debug-dump=frames-interp option also
5982 enables the --debug-dump=frames option. */
5983 if (do_debug_frames_interp)
5984 do_debug_frames = 1;
5985
5986 p += len;
5987 break;
5988 }
5989 }
467c65bc 5990
4cb93e3b
TG
5991 if (entry->option == NULL)
5992 {
5993 warn (_("Unrecognized debug option '%s'\n"), p);
5994 p = strchr (p, ',');
5995 if (p == NULL)
5996 break;
5997 }
467c65bc 5998
4cb93e3b
TG
5999 if (*p == ',')
6000 p++;
6001 }
6002}
6003
6004void
6005dwarf_select_sections_by_letters (const char *letters)
6006{
91d6fa6a 6007 unsigned int lindex = 0;
4cb93e3b 6008
91d6fa6a
NC
6009 while (letters[lindex])
6010 switch (letters[lindex++])
4cb93e3b
TG
6011 {
6012 case 'i':
6013 do_debug_info = 1;
6014 break;
467c65bc 6015
4cb93e3b
TG
6016 case 'a':
6017 do_debug_abbrevs = 1;
6018 break;
467c65bc 6019
4cb93e3b
TG
6020 case 'l':
6021 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
6022 break;
467c65bc 6023
4cb93e3b
TG
6024 case 'L':
6025 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
6026 break;
467c65bc 6027
4cb93e3b
TG
6028 case 'p':
6029 do_debug_pubnames = 1;
6030 break;
467c65bc 6031
f9f0e732
NC
6032 case 't':
6033 do_debug_pubtypes = 1;
6034 break;
467c65bc 6035
4cb93e3b
TG
6036 case 'r':
6037 do_debug_aranges = 1;
6038 break;
467c65bc 6039
4cb93e3b
TG
6040 case 'R':
6041 do_debug_ranges = 1;
6042 break;
467c65bc 6043
4cb93e3b
TG
6044 case 'F':
6045 do_debug_frames_interp = 1;
6046 case 'f':
6047 do_debug_frames = 1;
6048 break;
467c65bc 6049
4cb93e3b
TG
6050 case 'm':
6051 do_debug_macinfo = 1;
6052 break;
467c65bc 6053
4cb93e3b
TG
6054 case 's':
6055 do_debug_str = 1;
6056 break;
467c65bc 6057
4cb93e3b
TG
6058 case 'o':
6059 do_debug_loc = 1;
6060 break;
467c65bc 6061
4cb93e3b
TG
6062 default:
6063 warn (_("Unrecognized debug option '%s'\n"), optarg);
6064 break;
6065 }
6066}
6067
6068void
6069dwarf_select_sections_all (void)
6070{
6071 do_debug_info = 1;
6072 do_debug_abbrevs = 1;
6073 do_debug_lines = FLAG_DEBUG_LINES_RAW;
6074 do_debug_pubnames = 1;
f9f0e732 6075 do_debug_pubtypes = 1;
4cb93e3b
TG
6076 do_debug_aranges = 1;
6077 do_debug_ranges = 1;
6078 do_debug_frames = 1;
6079 do_debug_macinfo = 1;
6080 do_debug_str = 1;
6081 do_debug_loc = 1;
5bbdf3d5 6082 do_gdb_index = 1;
6f875884
TG
6083 do_trace_info = 1;
6084 do_trace_abbrevs = 1;
6085 do_trace_aranges = 1;
4cb93e3b
TG
6086}
6087
19e6b90e
L
6088struct dwarf_section_display debug_displays[] =
6089{
4723351a
CC
6090 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, abbrev },
6091 display_debug_abbrev, &do_debug_abbrevs, 0 },
6092 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, abbrev },
6093 display_debug_aranges, &do_debug_aranges, 1 },
6094 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, abbrev },
6095 display_debug_frames, &do_debug_frames, 1 },
6096 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev },
6097 display_debug_info, &do_debug_info, 1 },
6098 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, abbrev },
6099 display_debug_lines, &do_debug_lines, 1 },
6100 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, abbrev },
6101 display_debug_pubnames, &do_debug_pubnames, 0 },
6102 { { ".eh_frame", "", NULL, NULL, 0, 0, abbrev },
6103 display_debug_frames, &do_debug_frames, 1 },
6104 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, abbrev },
6105 display_debug_macinfo, &do_debug_macinfo, 0 },
6106 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, abbrev },
6107 display_debug_macro, &do_debug_macinfo, 1 },
6108 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, abbrev },
6109 display_debug_str, &do_debug_str, 0 },
6110 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, abbrev },
6111 display_debug_loc, &do_debug_loc, 1 },
6112 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, abbrev },
6113 display_debug_pubnames, &do_debug_pubtypes, 0 },
6114 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, abbrev },
6115 display_debug_ranges, &do_debug_ranges, 1 },
6116 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, abbrev },
6117 display_debug_not_supported, NULL, 0 },
6118 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, abbrev },
6119 display_debug_not_supported, NULL, 0 },
6120 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev },
6121 display_debug_types, &do_debug_info, 1 },
6122 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, abbrev },
6123 display_debug_not_supported, NULL, 0 },
6124 { { ".gdb_index", "", NULL, NULL, 0, 0, abbrev },
5bbdf3d5 6125 display_gdb_index, &do_gdb_index, 0 },
4723351a 6126 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev },
6f875884 6127 display_trace_info, &do_trace_info, 1 },
4723351a 6128 { { ".trace_abbrev", "", NULL, NULL, 0, 0, abbrev },
6f875884 6129 display_debug_abbrev, &do_trace_abbrevs, 0 },
4723351a
CC
6130 { { ".trace_aranges", "", NULL, NULL, 0, 0, abbrev },
6131 display_debug_aranges, &do_trace_aranges, 0 },
6132 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6133 display_debug_info, &do_debug_info, 1 },
6134 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6135 display_debug_abbrev, &do_debug_abbrevs, 0 },
6136 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6137 display_debug_types, &do_debug_info, 1 },
6138 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6139 display_debug_lines, &do_debug_lines, 1 },
6140 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6141 display_debug_loc, &do_debug_loc, 1 },
6142 { { ".debug_macro.dwo", ".zdebug_macro.dwo",NULL, NULL, 0, 0, abbrev },
6143 display_debug_macro, &do_debug_macinfo, 1 },
6144 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo",NULL, NULL, 0, 0, abbrev },
6145 display_debug_macinfo, &do_debug_macinfo, 0 },
6146 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, str_dwo },
6147 display_debug_str, &do_debug_str, 1 },
6148 { { ".debug_str_offsets",".zdebug_str_offsets", NULL, NULL, 0, 0, abbrev },
6149 display_debug_str_offsets, NULL, 0 },
6150 { { ".debug_str_offsets.dwo",".zdebug_str_offsets.dwo", NULL, NULL, 0, 0,
6151 abbrev },
6152 display_debug_str_offsets, NULL, 0 },
6153 { { ".debug_addr",".zdebug_addr", NULL, NULL, 0, 0, debug_addr },
6154 display_debug_addr, NULL, 1 },
19e6b90e 6155};
This page took 0.644307 seconds and 4 git commands to generate.