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