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