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