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