Avoid possible pointer wrap
[deliverable/binutils-gdb.git] / binutils / dwarf.c
CommitLineData
19e6b90e 1/* dwarf.c -- display DWARF contents of a BFD binary file
250d07de 2 Copyright (C) 2005-2021 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"
3dfb1b6d 24#include <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"
dda8d76d 31#include "filenames.h"
48467cb9 32#include "safe-ctype.h"
61364358
JK
33#include <assert.h>
34
301a9420
AM
35#ifdef HAVE_LIBDEBUGINFOD
36#include <elfutils/debuginfod.h>
37#endif
38
b9b204b3 39#include <limits.h>
b9b204b3
AM
40#ifndef CHAR_BIT
41#define CHAR_BIT 8
42#endif
43
61364358
JK
44#undef MAX
45#undef MIN
46#define MAX(a, b) ((a) > (b) ? (a) : (b))
47#define MIN(a, b) ((a) < (b) ? (a) : (b))
19e6b90e 48
18464d4d 49static const char *regname (unsigned int regno, int row);
1296bc99 50static const char *regname_internal_by_table_only (unsigned int regno);
18464d4d 51
19e6b90e
L
52static int have_frame_base;
53static int need_base_address;
54
19e6b90e 55static unsigned int num_debug_info_entries = 0;
82b1b41b 56static unsigned int alloc_num_debug_info_entries = 0;
19e6b90e 57static debug_info *debug_information = NULL;
cc86f28f
NC
58/* Special value for num_debug_info_entries to indicate
59 that the .debug_info section could not be loaded/parsed. */
60#define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
19e6b90e 61
24841daa
NC
62/* A .debug_info section can contain multiple links to separate
63 DWO object files. We use these structures to record these links. */
64typedef enum dwo_type
65{
66 DWO_NAME,
67 DWO_DIR,
68 DWO_ID
69} dwo_type;
70
71typedef struct dwo_info
72{
73 dwo_type type;
74 const char * value;
50ea0877 75 dwarf_vma cu_offset;
24841daa
NC
76 struct dwo_info * next;
77} dwo_info;
78
015dc7e1
AM
79static dwo_info *first_dwo_info = NULL;
80static bool need_dwo_info;
24841daa
NC
81
82separate_info * first_separate_info = NULL;
d85bf2ba 83
77ef8654 84unsigned int eh_addr_size;
19e6b90e
L
85
86int do_debug_info;
87int do_debug_abbrevs;
88int do_debug_lines;
89int do_debug_pubnames;
f9f0e732 90int do_debug_pubtypes;
19e6b90e
L
91int do_debug_aranges;
92int do_debug_ranges;
93int do_debug_frames;
94int do_debug_frames_interp;
95int do_debug_macinfo;
96int do_debug_str;
e4b7104b 97int do_debug_str_offsets;
19e6b90e 98int do_debug_loc;
5bbdf3d5 99int do_gdb_index;
6f875884
TG
100int do_trace_info;
101int do_trace_abbrevs;
102int do_trace_aranges;
657d0d47
CC
103int do_debug_addr;
104int do_debug_cu_index;
a262ae96 105int do_wide;
dda8d76d 106int do_debug_links;
c46b7066 107int do_follow_links = DEFAULT_FOR_FOLLOW_LINKS;
015dc7e1 108bool do_checks;
19e6b90e 109
fd2f0033
TT
110int dwarf_cutoff_level = -1;
111unsigned long dwarf_start_die;
112
4723351a
CC
113int dwarf_check = 0;
114
9f272209
AO
115/* Convenient constant, to avoid having to cast -1 to dwarf_vma when
116 testing whether e.g. a locview list is present. */
117static const dwarf_vma vm1 = -1;
118
341f9135
CC
119/* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
120 sections. For version 1 package files, each set is stored in SHNDX_POOL
121 as a zero-terminated list of section indexes comprising one set of debug
122 sections from a .dwo file. */
123
341f9135
CC
124static unsigned int *shndx_pool = NULL;
125static unsigned int shndx_pool_size = 0;
126static unsigned int shndx_pool_used = 0;
127
128/* For version 2 package files, each set contains an array of section offsets
129 and an array of section sizes, giving the offset and size of the
130 contribution from a CU or TU within one of the debug sections.
131 When displaying debug info from a package file, we need to use these
132 tables to locate the corresponding contributions to each section. */
133
134struct cu_tu_set
135{
ec1b0fbb
NC
136 uint64_t signature;
137 dwarf_vma section_offsets[DW_SECT_MAX];
138 size_t section_sizes[DW_SECT_MAX];
341f9135
CC
139};
140
141static int cu_count = 0;
142static int tu_count = 0;
143static struct cu_tu_set *cu_sets = NULL;
144static struct cu_tu_set *tu_sets = NULL;
145
015dc7e1 146static bool load_cu_tu_indexes (void *);
341f9135 147
ec1b0fbb
NC
148/* An array that indicates for a given level of CU nesting whether
149 the latest DW_AT_type seen for that level was a signed type or
150 an unsigned type. */
151#define MAX_CU_NESTING (1 << 8)
015dc7e1 152static bool level_type_signed[MAX_CU_NESTING];
ec1b0fbb 153
4cb93e3b
TG
154/* Values for do_debug_lines. */
155#define FLAG_DEBUG_LINES_RAW 1
156#define FLAG_DEBUG_LINES_DECODED 2
157
77ef8654 158static unsigned int
f1c4cc75
RH
159size_of_encoded_value (int encoding)
160{
161 switch (encoding & 0x7)
162 {
163 default: /* ??? */
164 case 0: return eh_addr_size;
165 case 2: return 2;
166 case 3: return 4;
167 case 4: return 8;
168 }
169}
170
171static dwarf_vma
041830e0 172get_encoded_value (unsigned char **pdata,
bad62cf5 173 int encoding,
041830e0
NC
174 struct dwarf_section *section,
175 unsigned char * end)
f1c4cc75 176{
041830e0 177 unsigned char * data = * pdata;
6937bb54 178 unsigned int size = size_of_encoded_value (encoding);
bad62cf5 179 dwarf_vma val;
f1c4cc75 180
041830e0
NC
181 if (data + size >= end)
182 {
183 warn (_("Encoded value extends past end of section\n"));
184 * pdata = end;
185 return 0;
186 }
187
6937bb54
NC
188 /* PR 17512: file: 002-829853-0.004. */
189 if (size > 8)
190 {
191 warn (_("Encoded size of %d is too large to read\n"), size);
192 * pdata = end;
193 return 0;
194 }
195
0a9d414a
NC
196 /* PR 17512: file: 1085-5603-0.004. */
197 if (size == 0)
198 {
199 warn (_("Encoded size of 0 is too small to read\n"));
200 * pdata = end;
201 return 0;
202 }
203
f1c4cc75 204 if (encoding & DW_EH_PE_signed)
bad62cf5 205 val = byte_get_signed (data, size);
f1c4cc75 206 else
bad62cf5
AM
207 val = byte_get (data, size);
208
209 if ((encoding & 0x70) == DW_EH_PE_pcrel)
210 val += section->address + (data - section->start);
041830e0
NC
211
212 * pdata = data + size;
bad62cf5 213 return val;
f1c4cc75
RH
214}
215
87b9f255 216#if SIZEOF_LONG_LONG > SIZEOF_LONG
4c219c2e
AM
217# ifndef __MINGW32__
218# define DWARF_VMA_FMT "ll"
219# define DWARF_VMA_FMT_LONG "%16.16llx"
220# else
221# define DWARF_VMA_FMT "I64"
222# define DWARF_VMA_FMT_LONG "%016I64x"
223# endif
2e14fae2 224#else
4c219c2e
AM
225# define DWARF_VMA_FMT "l"
226# define DWARF_VMA_FMT_LONG "%16.16lx"
2d9472a2
NC
227#endif
228
bf5117e3
NC
229/* Convert a dwarf vma value into a string. Returns a pointer to a static
230 buffer containing the converted VALUE. The value is converted according
231 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
232 it specifies the maximum number of bytes to be displayed in the converted
233 value and FMTCH is ignored - hex is always used. */
467c65bc 234
47704ddf 235static const char *
bf5117e3 236dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes)
47704ddf
KT
237{
238 /* As dwarf_vmatoa is used more then once in a printf call
239 for output, we are cycling through an fixed array of pointers
240 for return address. */
241 static int buf_pos = 0;
467c65bc
NC
242 static struct dwarf_vmatoa_buf
243 {
47704ddf
KT
244 char place[64];
245 } buf[16];
47704ddf
KT
246 char *ret;
247
47704ddf 248 ret = buf[buf_pos++].place;
467c65bc 249 buf_pos %= ARRAY_SIZE (buf);
47704ddf 250
bf5117e3
NC
251 if (num_bytes)
252 {
222c2bf0 253 /* Printf does not have a way of specifying a maximum field width for an
bf5117e3
NC
254 integer value, so we print the full value into a buffer and then select
255 the precision we need. */
256 snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value);
257 if (num_bytes > 8)
258 num_bytes = 8;
259 return ret + (16 - 2 * num_bytes);
260 }
261 else
262 {
263 char fmt[32];
264
0bae9e9e
NC
265 if (fmtch)
266 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
267 else
268 sprintf (fmt, "%%%s", DWARF_VMA_FMT);
bf5117e3
NC
269 snprintf (ret, sizeof (buf[0].place), fmt, value);
270 return ret;
271 }
272}
47704ddf 273
bf5117e3
NC
274static inline const char *
275dwarf_vmatoa (const char * fmtch, dwarf_vma value)
276{
277 return dwarf_vmatoa_1 (fmtch, value, 0);
278}
279
280/* Print a dwarf_vma value (typically an address, offset or length) in
281 hexadecimal format, followed by a space. The length of the VALUE (and
282 hence the precision displayed) is determined by the NUM_BYTES parameter. */
283
284static void
285print_dwarf_vma (dwarf_vma value, unsigned num_bytes)
286{
287 printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes));
47704ddf
KT
288}
289
9f272209
AO
290/* Print a view number in hexadecimal value, with the same width
291 print_dwarf_vma would have printed it with the same num_bytes.
292 Print blanks for zero view, unless force is nonzero. */
293
294static void
295print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force)
296{
297 int len;
298 if (!num_bytes)
299 len = 4;
300 else
301 len = num_bytes * 2;
302
303 assert (value == (unsigned long) value);
304 if (value || force)
305 printf ("v%0*lx ", len - 1, (unsigned long) value);
306 else
307 printf ("%*s", len + 1, "");
308}
309
74bc6052
CC
310/* Format a 64-bit value, given as two 32-bit values, in hex.
311 For reentrancy, this uses a buffer provided by the caller. */
312
313static const char *
314dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
315 unsigned int buf_len)
316{
317 int len = 0;
318
319 if (hvalue == 0)
320 snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
321 else
322 {
323 len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
324 snprintf (buf + len, buf_len - len,
325 "%08" DWARF_VMA_FMT "x", lvalue);
326 }
327
328 return buf;
329}
330
f6f0e17b
NC
331/* Read in a LEB128 encoded value starting at address DATA.
332 If SIGN is true, return a signed LEB128 value.
333 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
b9b204b3 334 If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the
cd30bcef
AM
335 terminating byte was not found and with bit 1 set if the value
336 overflows a dwarf_vma.
f6f0e17b
NC
337 No bytes will be read at address END or beyond. */
338
467c65bc 339dwarf_vma
f6f0e17b 340read_leb128 (unsigned char *data,
cd30bcef 341 const unsigned char *const end,
015dc7e1 342 bool sign,
cd30bcef
AM
343 unsigned int *length_return,
344 int *status_return)
19e6b90e 345{
467c65bc 346 dwarf_vma result = 0;
19e6b90e
L
347 unsigned int num_read = 0;
348 unsigned int shift = 0;
cd30bcef 349 int status = 1;
19e6b90e 350
f6f0e17b 351 while (data < end)
19e6b90e 352 {
cd30bcef 353 unsigned char byte = *data++;
b9b204b3 354 unsigned char lost, mask;
08d7da7d 355
19e6b90e
L
356 num_read++;
357
b9b204b3 358 if (shift < CHAR_BIT * sizeof (result))
cd30bcef 359 {
b9b204b3
AM
360 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
361 /* These bits overflowed. */
362 lost = byte ^ (result >> shift);
363 /* And this is the mask of possible overflow bits. */
364 mask = 0x7f ^ ((dwarf_vma) 0x7f << shift >> shift);
cd30bcef
AM
365 shift += 7;
366 }
b9b204b3 367 else
08d7da7d 368 {
b9b204b3
AM
369 lost = byte;
370 mask = 0x7f;
08d7da7d 371 }
b9b204b3
AM
372 if ((lost & mask) != (sign && (dwarf_signed_vma) result < 0 ? mask : 0))
373 status |= 2;
19e6b90e 374
b9b204b3 375 if ((byte & 0x80) == 0)
cd30bcef
AM
376 {
377 status &= ~1;
b9b204b3 378 if (sign && shift < CHAR_BIT * sizeof (result) && (byte & 0x40))
cd30bcef
AM
379 result |= -((dwarf_vma) 1 << shift);
380 break;
381 }
19e6b90e 382 }
19e6b90e
L
383
384 if (length_return != NULL)
385 *length_return = num_read;
cd30bcef
AM
386 if (status_return != NULL)
387 *status_return = status;
19e6b90e
L
388
389 return result;
390}
391
d11ae95e
NC
392/* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value.
393 Checks to make sure that the read will not reach or pass END
394 and that VAL is big enough to hold AMOUNT bytes. */
0c588247
NC
395#define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
396 do \
397 { \
398 unsigned int amount = (AMOUNT); \
34b9f729
NC
399 if (sizeof (VAL) < amount) \
400 { \
d3a49aa8
AM
401 error (ngettext ("internal error: attempt to read %d byte " \
402 "of data in to %d sized variable", \
403 "internal error: attempt to read %d bytes " \
404 "of data in to %d sized variable", \
405 amount), \
34b9f729
NC
406 amount, (int) sizeof (VAL)); \
407 amount = sizeof (VAL); \
408 } \
2d4b4986 409 if ((PTR) >= (END) - amount) \
0c588247
NC
410 { \
411 if ((PTR) < (END)) \
412 amount = (END) - (PTR); \
413 else \
414 amount = 0; \
415 } \
6937bb54 416 if (amount == 0 || amount > 8) \
0c588247 417 VAL = 0; \
6937bb54
NC
418 else \
419 VAL = byte_get ((PTR), amount); \
0c588247
NC
420 } \
421 while (0)
422
d11ae95e 423/* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */
0c588247
NC
424#define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
425 do \
426 { \
427 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
428 PTR += AMOUNT; \
429 } \
430 while (0)
431
d11ae95e 432/* Like SAFE_BYTE_GET, but reads a signed value. */
0c588247
NC
433#define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
434 do \
435 { \
436 unsigned int amount = (AMOUNT); \
2d4b4986 437 if ((PTR) >= (END) - amount) \
0c588247
NC
438 { \
439 if ((PTR) < (END)) \
440 amount = (END) - (PTR); \
441 else \
442 amount = 0; \
443 } \
444 if (amount) \
445 VAL = byte_get_signed ((PTR), amount); \
446 else \
447 VAL = 0; \
448 } \
449 while (0)
450
d11ae95e 451/* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */
0c588247
NC
452#define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
453 do \
454 { \
455 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
456 PTR += AMOUNT; \
457 } \
458 while (0)
459
460#define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
461 do \
462 { \
2d4b4986 463 if ((PTR) <= (END) - 8) \
0c588247
NC
464 { \
465 byte_get_64 ((PTR), (HIGH), (LOW)); \
466 } \
467 else \
468 { \
0c588247
NC
469 * (LOW) = * (HIGH) = 0; \
470 } \
471 } \
472 while (0)
473
19e6b90e
L
474typedef struct State_Machine_Registers
475{
467c65bc 476 dwarf_vma address;
ba8826a8 477 unsigned int view;
19e6b90e
L
478 unsigned int file;
479 unsigned int line;
480 unsigned int column;
481 int is_stmt;
482 int basic_block;
a233b20c
JJ
483 unsigned char op_index;
484 unsigned char end_sequence;
ba8826a8
AO
485 /* This variable hold the number of the last entry seen
486 in the File Table. */
19e6b90e
L
487 unsigned int last_file_entry;
488} SMR;
489
490static SMR state_machine_regs;
491
492static void
493reset_state_machine (int is_stmt)
494{
495 state_machine_regs.address = 0;
ba8826a8 496 state_machine_regs.view = 0;
a233b20c 497 state_machine_regs.op_index = 0;
19e6b90e
L
498 state_machine_regs.file = 1;
499 state_machine_regs.line = 1;
500 state_machine_regs.column = 0;
501 state_machine_regs.is_stmt = is_stmt;
502 state_machine_regs.basic_block = 0;
503 state_machine_regs.end_sequence = 0;
504 state_machine_regs.last_file_entry = 0;
505}
506
507/* Handled an extend line op.
508 Returns the number of bytes read. */
509
cd30bcef 510static size_t
f6f0e17b
NC
511process_extended_line_op (unsigned char * data,
512 int is_stmt,
513 unsigned char * end)
19e6b90e
L
514{
515 unsigned char op_code;
cd30bcef 516 size_t len, header_len;
19e6b90e 517 unsigned char *name;
143a3db0 518 unsigned char *orig_data = data;
cd30bcef 519 dwarf_vma adr, val;
19e6b90e 520
cd30bcef
AM
521 READ_ULEB (len, data, end);
522 header_len = data - orig_data;
19e6b90e 523
cd30bcef 524 if (len == 0 || data == end || len > (size_t) (end - data))
19e6b90e 525 {
f41e4712 526 warn (_("Badly formed extended line op encountered!\n"));
cd30bcef 527 return header_len;
19e6b90e
L
528 }
529
19e6b90e
L
530 op_code = *data++;
531
532 printf (_(" Extended opcode %d: "), op_code);
533
534 switch (op_code)
535 {
536 case DW_LNE_end_sequence:
537 printf (_("End of Sequence\n\n"));
538 reset_state_machine (is_stmt);
539 break;
540
541 case DW_LNE_set_address:
6937bb54 542 /* PR 17512: file: 002-100480-0.004. */
cd30bcef 543 if (len - 1 > 8)
77ef8654 544 {
cd30bcef
AM
545 warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"),
546 (unsigned long) len - 1);
77ef8654
NC
547 adr = 0;
548 }
549 else
cd30bcef 550 SAFE_BYTE_GET (adr, data, len - 1, end);
47704ddf 551 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
19e6b90e 552 state_machine_regs.address = adr;
ba8826a8 553 state_machine_regs.view = 0;
a233b20c 554 state_machine_regs.op_index = 0;
19e6b90e
L
555 break;
556
557 case DW_LNE_define_file:
143a3db0 558 printf (_("define new File Table entry\n"));
19e6b90e 559 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
cc5914eb 560 printf (" %d\t", ++state_machine_regs.last_file_entry);
f6f0e17b 561
d949ff56
NC
562 {
563 size_t l;
564
565 name = data;
566 l = strnlen ((char *) data, end - data);
cd30bcef
AM
567 data += l + 1;
568 READ_ULEB (val, data, end);
569 printf ("%s\t", dwarf_vmatoa ("u", val));
570 READ_ULEB (val, data, end);
571 printf ("%s\t", dwarf_vmatoa ("u", val));
572 READ_ULEB (val, data, end);
573 printf ("%s\t", dwarf_vmatoa ("u", val));
d949ff56
NC
574 printf ("%.*s\n\n", (int) l, name);
575 }
f6f0e17b 576
cd30bcef 577 if (((size_t) (data - orig_data) != len + header_len) || data == end)
b4eb7656 578 warn (_("DW_LNE_define_file: Bad opcode length\n"));
19e6b90e
L
579 break;
580
ed4a4bdf 581 case DW_LNE_set_discriminator:
cd30bcef
AM
582 READ_ULEB (val, data, end);
583 printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val));
ed4a4bdf
CC
584 break;
585
e2a0d921
NC
586 /* HP extensions. */
587 case DW_LNE_HP_negate_is_UV_update:
ed4a4bdf 588 printf ("DW_LNE_HP_negate_is_UV_update\n");
e2a0d921
NC
589 break;
590 case DW_LNE_HP_push_context:
ed4a4bdf 591 printf ("DW_LNE_HP_push_context\n");
e2a0d921
NC
592 break;
593 case DW_LNE_HP_pop_context:
ed4a4bdf 594 printf ("DW_LNE_HP_pop_context\n");
e2a0d921
NC
595 break;
596 case DW_LNE_HP_set_file_line_column:
ed4a4bdf 597 printf ("DW_LNE_HP_set_file_line_column\n");
e2a0d921
NC
598 break;
599 case DW_LNE_HP_set_routine_name:
ed4a4bdf 600 printf ("DW_LNE_HP_set_routine_name\n");
e2a0d921
NC
601 break;
602 case DW_LNE_HP_set_sequence:
ed4a4bdf 603 printf ("DW_LNE_HP_set_sequence\n");
e2a0d921
NC
604 break;
605 case DW_LNE_HP_negate_post_semantics:
ed4a4bdf 606 printf ("DW_LNE_HP_negate_post_semantics\n");
e2a0d921
NC
607 break;
608 case DW_LNE_HP_negate_function_exit:
ed4a4bdf 609 printf ("DW_LNE_HP_negate_function_exit\n");
e2a0d921
NC
610 break;
611 case DW_LNE_HP_negate_front_end_logical:
ed4a4bdf 612 printf ("DW_LNE_HP_negate_front_end_logical\n");
e2a0d921
NC
613 break;
614 case DW_LNE_HP_define_proc:
ed4a4bdf 615 printf ("DW_LNE_HP_define_proc\n");
e2a0d921 616 break;
43294ab7
TG
617 case DW_LNE_HP_source_file_correlation:
618 {
cd30bcef 619 unsigned char *edata = data + len - 1;
b4eb7656
AM
620
621 printf ("DW_LNE_HP_source_file_correlation\n");
622
623 while (data < edata)
624 {
625 unsigned int opc;
626
cd30bcef 627 READ_ULEB (opc, data, edata);
b4eb7656
AM
628
629 switch (opc)
630 {
631 case DW_LNE_HP_SFC_formfeed:
632 printf (" DW_LNE_HP_SFC_formfeed\n");
633 break;
634 case DW_LNE_HP_SFC_set_listing_line:
cd30bcef 635 READ_ULEB (val, data, edata);
b4eb7656 636 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
cd30bcef 637 dwarf_vmatoa ("u", val));
b4eb7656
AM
638 break;
639 case DW_LNE_HP_SFC_associate:
640 printf (" DW_LNE_HP_SFC_associate ");
cd30bcef
AM
641 READ_ULEB (val, data, edata);
642 printf ("(%s", dwarf_vmatoa ("u", val));
643 READ_ULEB (val, data, edata);
644 printf (",%s", dwarf_vmatoa ("u", val));
645 READ_ULEB (val, data, edata);
646 printf (",%s)\n", dwarf_vmatoa ("u", val));
b4eb7656
AM
647 break;
648 default:
649 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
650 data = edata;
651 break;
652 }
653 }
43294ab7
TG
654 }
655 break;
cecf136e 656
19e6b90e 657 default:
7e665af3 658 {
cd30bcef 659 unsigned int rlen = len - 1;
b4eb7656
AM
660
661 if (op_code >= DW_LNE_lo_user
662 /* The test against DW_LNW_hi_user is redundant due to
663 the limited range of the unsigned char data type used
664 for op_code. */
665 /*&& op_code <= DW_LNE_hi_user*/)
666 printf (_("user defined: "));
667 else
668 printf (_("UNKNOWN: "));
669 printf (_("length %d ["), rlen);
670 for (; rlen; rlen--)
671 printf (" %02x", *data++);
672 printf ("]\n");
7e665af3 673 }
19e6b90e
L
674 break;
675 }
676
cd30bcef 677 return len + header_len;
19e6b90e
L
678}
679
0c588247 680static const unsigned char *
467c65bc 681fetch_indirect_string (dwarf_vma offset)
19e6b90e
L
682{
683 struct dwarf_section *section = &debug_displays [str].section;
d949ff56 684 const unsigned char * ret;
19e6b90e
L
685
686 if (section->start == NULL)
0c588247 687 return (const unsigned char *) _("<no .debug_str section>");
19e6b90e 688
d949ff56 689 if (offset >= section->size)
19e6b90e 690 {
d296b736 691 warn (_("DW_FORM_strp offset too big: 0x%s\n"),
467c65bc 692 dwarf_vmatoa ("x", offset));
0c588247 693 return (const unsigned char *) _("<offset is too big>");
19e6b90e
L
694 }
695
d949ff56
NC
696 ret = section->start + offset;
697 /* Unfortunately we cannot rely upon the .debug_str section ending with a
698 NUL byte. Since our caller is expecting to receive a well formed C
699 string we test for the lack of a terminating byte here. */
700 if (strnlen ((const char *) ret, section->size - offset)
701 == section->size - offset)
702 ret = (const unsigned char *)
703 _("<no NUL byte at end of .debug_str section>");
704
521d4b19 705 return ret;
19e6b90e
L
706}
707
77145576
JK
708static const unsigned char *
709fetch_indirect_line_string (dwarf_vma offset)
710{
711 struct dwarf_section *section = &debug_displays [line_str].section;
d949ff56 712 const unsigned char * ret;
77145576
JK
713
714 if (section->start == NULL)
715 return (const unsigned char *) _("<no .debug_line_str section>");
716
d949ff56 717 if (offset >= section->size)
77145576 718 {
d296b736 719 warn (_("DW_FORM_line_strp offset too big: 0x%s\n"),
77145576
JK
720 dwarf_vmatoa ("x", offset));
721 return (const unsigned char *) _("<offset is too big>");
722 }
723
d949ff56
NC
724 ret = section->start + offset;
725 /* Unfortunately we cannot rely upon the .debug_line_str section ending
726 with a NUL byte. Since our caller is expecting to receive a well formed
727 C string we test for the lack of a terminating byte here. */
728 if (strnlen ((const char *) ret, section->size - offset)
729 == section->size - offset)
730 ret = (const unsigned char *)
731 _("<no NUL byte at end of .debug_line_str section>");
732
733 return ret;
77145576
JK
734}
735
4723351a 736static const char *
341f9135 737fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
015dc7e1 738 dwarf_vma offset_size, bool dwo)
4723351a
CC
739{
740 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
741 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
742 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
743 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
e4b7104b 744 dwarf_vma index_offset;
4723351a 745 dwarf_vma str_offset;
d949ff56 746 const char * ret;
e4b7104b
NC
747 unsigned char *curr = index_section->start;
748 const unsigned char *end = curr + index_section->size;
749 dwarf_vma length;
4723351a
CC
750
751 if (index_section->start == NULL)
752 return (dwo ? _("<no .debug_str_offsets.dwo section>")
753 : _("<no .debug_str_offsets section>"));
754
e4b7104b
NC
755 if (str_section->start == NULL)
756 return (dwo ? _("<no .debug_str.dwo section>")
757 : _("<no .debug_str section>"));
758
759 /* FIXME: We should cache the length... */
760 SAFE_BYTE_GET_AND_INC (length, curr, 4, end);
761 if (length == 0xffffffff)
762 {
763 if (offset_size != 8)
39f381cb 764 warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size));
e4b7104b
NC
765 SAFE_BYTE_GET_AND_INC (length, curr, 8, end);
766 }
767 else if (offset_size != 4)
768 {
39f381cb 769 warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size));
e4b7104b
NC
770 }
771
39f381cb 772 if (length == 0)
e4b7104b 773 {
39f381cb
NC
774 /* This is probably an old style .debug_str_offset section which
775 just contains offsets and no header (and the first offset is 0). */
776 curr = index_section->start;
777 length = index_section->size;
778 }
779 else
780 {
781 /* Skip the version and padding bytes.
782 We assume that they are correct. */
783 curr += 4;
784
785 /* FIXME: The code below assumes that there is only one table
786 in the .debug_str_offsets section, so check that now. */
787 if ((offset_size == 4 && curr + length < (end - 8))
788 || (offset_size == 8 && curr + length < (end - 16)))
789 {
790 warn (_("index table size is too small %s vs %s\n"),
791 dwarf_vmatoa ("x", length),
792 dwarf_vmatoa ("x", index_section->size));
793 return _("<table too small>");
794 }
e4b7104b
NC
795 }
796
797 index_offset = idx * offset_size;
521d4b19 798
341f9135
CC
799 if (this_set != NULL)
800 index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
e4b7104b
NC
801
802 if (index_offset >= length)
4723351a 803 {
d296b736 804 warn (_("DW_FORM_GNU_str_index offset too big: 0x%s vs 0x%s\n"),
e4b7104b
NC
805 dwarf_vmatoa ("x", index_offset),
806 dwarf_vmatoa ("x", length));
4723351a
CC
807 return _("<index offset is too big>");
808 }
809
e4b7104b 810 str_offset = byte_get (curr + index_offset, offset_size);
4723351a 811 str_offset -= str_section->address;
d949ff56 812 if (str_offset >= str_section->size)
4723351a 813 {
d296b736 814 warn (_("DW_FORM_GNU_str_index indirect offset too big: 0x%s\n"),
4723351a
CC
815 dwarf_vmatoa ("x", str_offset));
816 return _("<indirect index offset is too big>");
817 }
818
d949ff56
NC
819 ret = (const char *) str_section->start + str_offset;
820 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
821 Since our caller is expecting to receive a well formed C string we test
822 for the lack of a terminating byte here. */
823 if (strnlen (ret, str_section->size - str_offset)
824 == str_section->size - str_offset)
825 ret = (const char *) _("<no NUL byte at end of section>");
826
827 return ret;
4723351a
CC
828}
829
830static const char *
831fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
832{
833 struct dwarf_section *section = &debug_displays [debug_addr].section;
834
835 if (section->start == NULL)
836 return (_("<no .debug_addr section>"));
837
838 if (offset + bytes > section->size)
839 {
d296b736 840 warn (_("Offset into section %s too big: 0x%s\n"),
b4eb7656 841 section->name, dwarf_vmatoa ("x", offset));
4723351a
CC
842 return "<offset too big>";
843 }
844
845 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
846}
847
848
19e6b90e
L
849/* FIXME: There are better and more efficient ways to handle
850 these structures. For now though, I just want something that
851 is simple to implement. */
bcd213b2 852/* Records a single attribute in an abbrev. */
19e6b90e
L
853typedef struct abbrev_attr
854{
bcd213b2
NC
855 unsigned long attribute;
856 unsigned long form;
857 bfd_signed_vma implicit_const;
858 struct abbrev_attr * next;
19e6b90e
L
859}
860abbrev_attr;
861
bcd213b2 862/* Records a single abbrev. */
19e6b90e
L
863typedef struct abbrev_entry
864{
bcd213b2
NC
865 unsigned long number;
866 unsigned long tag;
867 int children;
868 struct abbrev_attr * first_attr;
869 struct abbrev_attr * last_attr;
870 struct abbrev_entry * next;
19e6b90e
L
871}
872abbrev_entry;
873
bcd213b2
NC
874/* Records a set of abbreviations. */
875typedef struct abbrev_list
876{
877 abbrev_entry * first_abbrev;
878 abbrev_entry * last_abbrev;
76868f36 879 dwarf_vma abbrev_base;
bcd213b2
NC
880 dwarf_vma abbrev_offset;
881 struct abbrev_list * next;
882 unsigned char * start_of_next_abbrevs;
883}
884abbrev_list;
885
886/* Records all the abbrevs found so far. */
887static struct abbrev_list * abbrev_lists = NULL;
888
889typedef struct abbrev_map
890{
891 dwarf_vma start;
892 dwarf_vma end;
893 abbrev_list * list;
894} abbrev_map;
895
896/* Maps between CU offsets and abbrev sets. */
897static abbrev_map * cu_abbrev_map = NULL;
898static unsigned long num_abbrev_map_entries = 0;
899static unsigned long next_free_abbrev_map_entry = 0;
900
901#define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
902#define ABBREV_MAP_ENTRIES_INCREMENT 8
903
904static void
905record_abbrev_list_for_cu (dwarf_vma start, dwarf_vma end, abbrev_list * list)
906{
907 if (cu_abbrev_map == NULL)
908 {
909 num_abbrev_map_entries = INITIAL_NUM_ABBREV_MAP_ENTRIES;
910 cu_abbrev_map = xmalloc (num_abbrev_map_entries * sizeof (* cu_abbrev_map));
911 }
912 else if (next_free_abbrev_map_entry == num_abbrev_map_entries)
913 {
914 num_abbrev_map_entries += ABBREV_MAP_ENTRIES_INCREMENT;
915 cu_abbrev_map = xrealloc (cu_abbrev_map, num_abbrev_map_entries * sizeof (* cu_abbrev_map));
916 }
917
918 cu_abbrev_map[next_free_abbrev_map_entry].start = start;
919 cu_abbrev_map[next_free_abbrev_map_entry].end = end;
920 cu_abbrev_map[next_free_abbrev_map_entry].list = list;
921 next_free_abbrev_map_entry ++;
922}
19e6b90e
L
923
924static void
bcd213b2 925free_all_abbrevs (void)
19e6b90e 926{
bcd213b2 927 abbrev_list * list;
19e6b90e 928
bcd213b2 929 for (list = abbrev_lists; list != NULL;)
19e6b90e 930 {
bcd213b2
NC
931 abbrev_list * next = list->next;
932 abbrev_entry * abbrv;
19e6b90e 933
bcd213b2 934 for (abbrv = list->first_abbrev; abbrv != NULL;)
19e6b90e 935 {
bcd213b2
NC
936 abbrev_entry * next_abbrev = abbrv->next;
937 abbrev_attr * attr;
938
939 for (attr = abbrv->first_attr; attr;)
940 {
941 abbrev_attr *next_attr = attr->next;
19e6b90e 942
bcd213b2
NC
943 free (attr);
944 attr = next_attr;
945 }
946
947 free (abbrv);
948 abbrv = next_abbrev;
19e6b90e
L
949 }
950
bcd213b2
NC
951 free (list);
952 list = next;
19e6b90e
L
953 }
954
bcd213b2
NC
955 abbrev_lists = NULL;
956}
957
958static abbrev_list *
76868f36 959new_abbrev_list (dwarf_vma abbrev_base, dwarf_vma abbrev_offset)
bcd213b2
NC
960{
961 abbrev_list * list = (abbrev_list *) xcalloc (sizeof * list, 1);
962
76868f36 963 list->abbrev_base = abbrev_base;
bcd213b2
NC
964 list->abbrev_offset = abbrev_offset;
965
966 list->next = abbrev_lists;
967 abbrev_lists = list;
968
969 return list;
970}
971
972static abbrev_list *
76868f36
L
973find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base,
974 dwarf_vma abbrev_offset)
bcd213b2
NC
975{
976 abbrev_list * list;
977
978 for (list = abbrev_lists; list != NULL; list = list->next)
76868f36
L
979 if (list->abbrev_base == abbrev_base
980 && list->abbrev_offset == abbrev_offset)
bcd213b2
NC
981 return list;
982
983 return NULL;
984}
985
986/* Find the abbreviation map for the CU that includes OFFSET.
987 OFFSET is an absolute offset from the start of the .debug_info section. */
988/* FIXME: This function is going to slow down readelf & objdump.
989 Consider using a better algorithm to mitigate this effect. */
990
991static abbrev_map *
992find_abbrev_map_by_offset (dwarf_vma offset)
993{
994 unsigned long i;
995
996 for (i = 0; i < next_free_abbrev_map_entry; i++)
997 if (cu_abbrev_map[i].start <= offset
998 && cu_abbrev_map[i].end > offset)
999 return cu_abbrev_map + i;
1000
1001 return NULL;
19e6b90e
L
1002}
1003
1004static void
bcd213b2
NC
1005add_abbrev (unsigned long number,
1006 unsigned long tag,
1007 int children,
1008 abbrev_list * list)
19e6b90e 1009{
bcd213b2 1010 abbrev_entry * entry;
19e6b90e 1011
bcd213b2 1012 entry = (abbrev_entry *) xmalloc (sizeof (*entry));
19e6b90e 1013
bcd213b2 1014 entry->number = number;
19e6b90e
L
1015 entry->tag = tag;
1016 entry->children = children;
1017 entry->first_attr = NULL;
1018 entry->last_attr = NULL;
1019 entry->next = NULL;
1020
bcd213b2
NC
1021 assert (list != NULL);
1022
1023 if (list->first_abbrev == NULL)
1024 list->first_abbrev = entry;
19e6b90e 1025 else
bcd213b2 1026 list->last_abbrev->next = entry;
19e6b90e 1027
bcd213b2 1028 list->last_abbrev = entry;
19e6b90e
L
1029}
1030
1031static void
bcd213b2
NC
1032add_abbrev_attr (unsigned long attribute,
1033 unsigned long form,
1034 bfd_signed_vma implicit_const,
1035 abbrev_list * list)
19e6b90e
L
1036{
1037 abbrev_attr *attr;
1038
bcd213b2 1039 attr = (abbrev_attr *) xmalloc (sizeof (*attr));
19e6b90e
L
1040
1041 attr->attribute = attribute;
1042 attr->form = form;
77145576 1043 attr->implicit_const = implicit_const;
19e6b90e
L
1044 attr->next = NULL;
1045
bcd213b2
NC
1046 assert (list != NULL && list->last_abbrev != NULL);
1047
1048 if (list->last_abbrev->first_attr == NULL)
1049 list->last_abbrev->first_attr = attr;
19e6b90e 1050 else
bcd213b2 1051 list->last_abbrev->last_attr->next = attr;
19e6b90e 1052
bcd213b2 1053 list->last_abbrev->last_attr = attr;
19e6b90e
L
1054}
1055
1056/* Processes the (partial) contents of a .debug_abbrev section.
1057 Returns NULL if the end of the section was encountered.
1058 Returns the address after the last byte read if the end of
1059 an abbreviation set was found. */
1060
1061static unsigned char *
bcd213b2
NC
1062process_abbrev_set (unsigned char * start,
1063 const unsigned char * end,
1064 abbrev_list * list)
19e6b90e 1065{
19e6b90e
L
1066 while (start < end)
1067 {
19e6b90e
L
1068 unsigned long entry;
1069 unsigned long tag;
1070 unsigned long attribute;
1071 int children;
1072
cd30bcef 1073 READ_ULEB (entry, start, end);
19e6b90e 1074
bcd213b2 1075 /* A single zero is supposed to end the set according
19e6b90e
L
1076 to the standard. If there's more, then signal that to
1077 the caller. */
f6f0e17b
NC
1078 if (start == end)
1079 return NULL;
19e6b90e 1080 if (entry == 0)
f6f0e17b 1081 return start;
19e6b90e 1082
cd30bcef 1083 READ_ULEB (tag, start, end);
f6f0e17b
NC
1084 if (start == end)
1085 return NULL;
19e6b90e
L
1086
1087 children = *start++;
1088
bcd213b2 1089 add_abbrev (entry, tag, children, list);
19e6b90e
L
1090
1091 do
1092 {
1093 unsigned long form;
77145576
JK
1094 /* Initialize it due to a false compiler warning. */
1095 bfd_signed_vma implicit_const = -1;
19e6b90e 1096
cd30bcef 1097 READ_ULEB (attribute, start, end);
f6f0e17b
NC
1098 if (start == end)
1099 break;
19e6b90e 1100
cd30bcef 1101 READ_ULEB (form, start, end);
f6f0e17b
NC
1102 if (start == end)
1103 break;
19e6b90e 1104
77145576
JK
1105 if (form == DW_FORM_implicit_const)
1106 {
cd30bcef 1107 READ_SLEB (implicit_const, start, end);
77145576
JK
1108 if (start == end)
1109 break;
1110 }
1111
bcd213b2 1112 add_abbrev_attr (attribute, form, implicit_const, list);
19e6b90e
L
1113 }
1114 while (attribute != 0);
1115 }
1116
399c99f7
L
1117 /* Report the missing single zero which ends the section. */
1118 error (_(".debug_abbrev section not zero terminated\n"));
1119
19e6b90e
L
1120 return NULL;
1121}
1122
a19c41a7 1123static const char *
19e6b90e
L
1124get_TAG_name (unsigned long tag)
1125{
04914e37 1126 const char *name = get_DW_TAG_name ((unsigned int) tag);
a19c41a7
TT
1127
1128 if (name == NULL)
19e6b90e 1129 {
a19c41a7 1130 static char buffer[100];
19e6b90e 1131
04914e37
NC
1132 if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user)
1133 snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag);
1134 else
1135 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag);
a19c41a7 1136 return buffer;
19e6b90e 1137 }
a19c41a7
TT
1138
1139 return name;
19e6b90e
L
1140}
1141
a19c41a7 1142static const char *
19e6b90e
L
1143get_FORM_name (unsigned long form)
1144{
399c99f7 1145 const char *name;
bf5117e3 1146
399c99f7
L
1147 if (form == 0)
1148 return "DW_FORM value: 0";
a19c41a7 1149
399c99f7 1150 name = get_DW_FORM_name (form);
a19c41a7 1151 if (name == NULL)
19e6b90e 1152 {
a19c41a7 1153 static char buffer[100];
19e6b90e 1154
a19c41a7
TT
1155 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
1156 return buffer;
19e6b90e 1157 }
a19c41a7
TT
1158
1159 return name;
19e6b90e
L
1160}
1161
61364358
JK
1162static const char *
1163get_IDX_name (unsigned long idx)
1164{
1165 const char *name = get_DW_IDX_name ((unsigned int) idx);
1166
1167 if (name == NULL)
1168 {
1169 static char buffer[100];
1170
1171 snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx);
1172 return buffer;
1173 }
1174
1175 return name;
1176}
1177
19e6b90e 1178static unsigned char *
0c588247
NC
1179display_block (unsigned char *data,
1180 dwarf_vma length,
ef0b5f1c 1181 const unsigned char * const end, char delimiter)
19e6b90e 1182{
0c588247
NC
1183 dwarf_vma maxlen;
1184
ef0b5f1c 1185 printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length));
a1165289
NC
1186 if (data > end)
1187 return (unsigned char *) end;
19e6b90e 1188
0c588247
NC
1189 maxlen = (dwarf_vma) (end - data);
1190 length = length > maxlen ? maxlen : length;
1191
19e6b90e
L
1192 while (length --)
1193 printf ("%lx ", (unsigned long) byte_get (data++, 1));
1194
1195 return data;
1196}
1197
1198static int
1199decode_location_expression (unsigned char * data,
1200 unsigned int pointer_size,
b7807392
JJ
1201 unsigned int offset_size,
1202 int dwarf_version,
467c65bc
NC
1203 dwarf_vma length,
1204 dwarf_vma cu_offset,
f1c4cc75 1205 struct dwarf_section * section)
19e6b90e
L
1206{
1207 unsigned op;
467c65bc 1208 dwarf_vma uvalue;
0c588247 1209 dwarf_signed_vma svalue;
19e6b90e
L
1210 unsigned char *end = data + length;
1211 int need_frame_base = 0;
1212
1213 while (data < end)
1214 {
1215 op = *data++;
1216
1217 switch (op)
1218 {
1219 case DW_OP_addr:
0c588247
NC
1220 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1221 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
19e6b90e
L
1222 break;
1223 case DW_OP_deref:
1224 printf ("DW_OP_deref");
1225 break;
1226 case DW_OP_const1u:
0c588247
NC
1227 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1228 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
19e6b90e
L
1229 break;
1230 case DW_OP_const1s:
0c588247
NC
1231 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
1232 printf ("DW_OP_const1s: %ld", (long) svalue);
19e6b90e
L
1233 break;
1234 case DW_OP_const2u:
87bc83b3 1235 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
0c588247 1236 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
19e6b90e
L
1237 break;
1238 case DW_OP_const2s:
0c588247
NC
1239 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1240 printf ("DW_OP_const2s: %ld", (long) svalue);
19e6b90e
L
1241 break;
1242 case DW_OP_const4u:
0c588247
NC
1243 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1244 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
19e6b90e
L
1245 break;
1246 case DW_OP_const4s:
0c588247
NC
1247 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1248 printf ("DW_OP_const4s: %ld", (long) svalue);
19e6b90e
L
1249 break;
1250 case DW_OP_const8u:
0c588247
NC
1251 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1252 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
1253 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1254 printf ("%lu", (unsigned long) uvalue);
19e6b90e
L
1255 break;
1256 case DW_OP_const8s:
0c588247
NC
1257 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1258 printf ("DW_OP_const8s: %ld ", (long) svalue);
1259 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1260 printf ("%ld", (long) svalue);
19e6b90e
L
1261 break;
1262 case DW_OP_constu:
cd30bcef
AM
1263 READ_ULEB (uvalue, data, end);
1264 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue));
19e6b90e
L
1265 break;
1266 case DW_OP_consts:
cd30bcef
AM
1267 READ_SLEB (svalue, data, end);
1268 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue));
19e6b90e
L
1269 break;
1270 case DW_OP_dup:
1271 printf ("DW_OP_dup");
1272 break;
1273 case DW_OP_drop:
1274 printf ("DW_OP_drop");
1275 break;
1276 case DW_OP_over:
1277 printf ("DW_OP_over");
1278 break;
1279 case DW_OP_pick:
0c588247
NC
1280 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1281 printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
19e6b90e
L
1282 break;
1283 case DW_OP_swap:
1284 printf ("DW_OP_swap");
1285 break;
1286 case DW_OP_rot:
1287 printf ("DW_OP_rot");
1288 break;
1289 case DW_OP_xderef:
1290 printf ("DW_OP_xderef");
1291 break;
1292 case DW_OP_abs:
1293 printf ("DW_OP_abs");
1294 break;
1295 case DW_OP_and:
1296 printf ("DW_OP_and");
1297 break;
1298 case DW_OP_div:
1299 printf ("DW_OP_div");
1300 break;
1301 case DW_OP_minus:
1302 printf ("DW_OP_minus");
1303 break;
1304 case DW_OP_mod:
1305 printf ("DW_OP_mod");
1306 break;
1307 case DW_OP_mul:
1308 printf ("DW_OP_mul");
1309 break;
1310 case DW_OP_neg:
1311 printf ("DW_OP_neg");
1312 break;
1313 case DW_OP_not:
1314 printf ("DW_OP_not");
1315 break;
1316 case DW_OP_or:
1317 printf ("DW_OP_or");
1318 break;
1319 case DW_OP_plus:
1320 printf ("DW_OP_plus");
1321 break;
1322 case DW_OP_plus_uconst:
cd30bcef
AM
1323 READ_ULEB (uvalue, data, end);
1324 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue));
19e6b90e
L
1325 break;
1326 case DW_OP_shl:
1327 printf ("DW_OP_shl");
1328 break;
1329 case DW_OP_shr:
1330 printf ("DW_OP_shr");
1331 break;
1332 case DW_OP_shra:
1333 printf ("DW_OP_shra");
1334 break;
1335 case DW_OP_xor:
1336 printf ("DW_OP_xor");
1337 break;
1338 case DW_OP_bra:
0c588247
NC
1339 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1340 printf ("DW_OP_bra: %ld", (long) svalue);
19e6b90e
L
1341 break;
1342 case DW_OP_eq:
1343 printf ("DW_OP_eq");
1344 break;
1345 case DW_OP_ge:
1346 printf ("DW_OP_ge");
1347 break;
1348 case DW_OP_gt:
1349 printf ("DW_OP_gt");
1350 break;
1351 case DW_OP_le:
1352 printf ("DW_OP_le");
1353 break;
1354 case DW_OP_lt:
1355 printf ("DW_OP_lt");
1356 break;
1357 case DW_OP_ne:
1358 printf ("DW_OP_ne");
1359 break;
1360 case DW_OP_skip:
0c588247
NC
1361 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1362 printf ("DW_OP_skip: %ld", (long) svalue);
19e6b90e
L
1363 break;
1364
1365 case DW_OP_lit0:
1366 case DW_OP_lit1:
1367 case DW_OP_lit2:
1368 case DW_OP_lit3:
1369 case DW_OP_lit4:
1370 case DW_OP_lit5:
1371 case DW_OP_lit6:
1372 case DW_OP_lit7:
1373 case DW_OP_lit8:
1374 case DW_OP_lit9:
1375 case DW_OP_lit10:
1376 case DW_OP_lit11:
1377 case DW_OP_lit12:
1378 case DW_OP_lit13:
1379 case DW_OP_lit14:
1380 case DW_OP_lit15:
1381 case DW_OP_lit16:
1382 case DW_OP_lit17:
1383 case DW_OP_lit18:
1384 case DW_OP_lit19:
1385 case DW_OP_lit20:
1386 case DW_OP_lit21:
1387 case DW_OP_lit22:
1388 case DW_OP_lit23:
1389 case DW_OP_lit24:
1390 case DW_OP_lit25:
1391 case DW_OP_lit26:
1392 case DW_OP_lit27:
1393 case DW_OP_lit28:
1394 case DW_OP_lit29:
1395 case DW_OP_lit30:
1396 case DW_OP_lit31:
1397 printf ("DW_OP_lit%d", op - DW_OP_lit0);
1398 break;
1399
1400 case DW_OP_reg0:
1401 case DW_OP_reg1:
1402 case DW_OP_reg2:
1403 case DW_OP_reg3:
1404 case DW_OP_reg4:
1405 case DW_OP_reg5:
1406 case DW_OP_reg6:
1407 case DW_OP_reg7:
1408 case DW_OP_reg8:
1409 case DW_OP_reg9:
1410 case DW_OP_reg10:
1411 case DW_OP_reg11:
1412 case DW_OP_reg12:
1413 case DW_OP_reg13:
1414 case DW_OP_reg14:
1415 case DW_OP_reg15:
1416 case DW_OP_reg16:
1417 case DW_OP_reg17:
1418 case DW_OP_reg18:
1419 case DW_OP_reg19:
1420 case DW_OP_reg20:
1421 case DW_OP_reg21:
1422 case DW_OP_reg22:
1423 case DW_OP_reg23:
1424 case DW_OP_reg24:
1425 case DW_OP_reg25:
1426 case DW_OP_reg26:
1427 case DW_OP_reg27:
1428 case DW_OP_reg28:
1429 case DW_OP_reg29:
1430 case DW_OP_reg30:
1431 case DW_OP_reg31:
18464d4d
JK
1432 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
1433 regname (op - DW_OP_reg0, 1));
19e6b90e
L
1434 break;
1435
1436 case DW_OP_breg0:
1437 case DW_OP_breg1:
1438 case DW_OP_breg2:
1439 case DW_OP_breg3:
1440 case DW_OP_breg4:
1441 case DW_OP_breg5:
1442 case DW_OP_breg6:
1443 case DW_OP_breg7:
1444 case DW_OP_breg8:
1445 case DW_OP_breg9:
1446 case DW_OP_breg10:
1447 case DW_OP_breg11:
1448 case DW_OP_breg12:
1449 case DW_OP_breg13:
1450 case DW_OP_breg14:
1451 case DW_OP_breg15:
1452 case DW_OP_breg16:
1453 case DW_OP_breg17:
1454 case DW_OP_breg18:
1455 case DW_OP_breg19:
1456 case DW_OP_breg20:
1457 case DW_OP_breg21:
1458 case DW_OP_breg22:
1459 case DW_OP_breg23:
1460 case DW_OP_breg24:
1461 case DW_OP_breg25:
1462 case DW_OP_breg26:
1463 case DW_OP_breg27:
1464 case DW_OP_breg28:
1465 case DW_OP_breg29:
1466 case DW_OP_breg30:
1467 case DW_OP_breg31:
cd30bcef
AM
1468 READ_SLEB (svalue, data, end);
1469 printf ("DW_OP_breg%d (%s): %s", op - DW_OP_breg0,
1470 regname (op - DW_OP_breg0, 1), dwarf_vmatoa ("d", svalue));
19e6b90e
L
1471 break;
1472
1473 case DW_OP_regx:
cd30bcef 1474 READ_ULEB (uvalue, data, end);
467c65bc
NC
1475 printf ("DW_OP_regx: %s (%s)",
1476 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
19e6b90e
L
1477 break;
1478 case DW_OP_fbreg:
1479 need_frame_base = 1;
cd30bcef
AM
1480 READ_SLEB (svalue, data, end);
1481 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue));
19e6b90e
L
1482 break;
1483 case DW_OP_bregx:
cd30bcef
AM
1484 READ_ULEB (uvalue, data, end);
1485 READ_SLEB (svalue, data, end);
467c65bc
NC
1486 printf ("DW_OP_bregx: %s (%s) %s",
1487 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
cd30bcef 1488 dwarf_vmatoa ("d", svalue));
19e6b90e
L
1489 break;
1490 case DW_OP_piece:
cd30bcef
AM
1491 READ_ULEB (uvalue, data, end);
1492 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue));
19e6b90e
L
1493 break;
1494 case DW_OP_deref_size:
0c588247
NC
1495 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1496 printf ("DW_OP_deref_size: %ld", (long) uvalue);
19e6b90e
L
1497 break;
1498 case DW_OP_xderef_size:
0c588247
NC
1499 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1500 printf ("DW_OP_xderef_size: %ld", (long) uvalue);
19e6b90e
L
1501 break;
1502 case DW_OP_nop:
1503 printf ("DW_OP_nop");
1504 break;
1505
1506 /* DWARF 3 extensions. */
1507 case DW_OP_push_object_address:
1508 printf ("DW_OP_push_object_address");
1509 break;
1510 case DW_OP_call2:
d85bf2ba 1511 /* FIXME: Strictly speaking for 64-bit DWARF3 files
19e6b90e 1512 this ought to be an 8-byte wide computation. */
0c588247 1513 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
467c65bc 1514 printf ("DW_OP_call2: <0x%s>",
0c588247 1515 dwarf_vmatoa ("x", svalue + cu_offset));
19e6b90e
L
1516 break;
1517 case DW_OP_call4:
d85bf2ba 1518 /* FIXME: Strictly speaking for 64-bit DWARF3 files
19e6b90e 1519 this ought to be an 8-byte wide computation. */
0c588247 1520 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
467c65bc 1521 printf ("DW_OP_call4: <0x%s>",
0c588247 1522 dwarf_vmatoa ("x", svalue + cu_offset));
19e6b90e
L
1523 break;
1524 case DW_OP_call_ref:
d85bf2ba 1525 /* FIXME: Strictly speaking for 64-bit DWARF3 files
e2a0d921 1526 this ought to be an 8-byte wide computation. */
b7807392
JJ
1527 if (dwarf_version == -1)
1528 {
1529 printf (_("(DW_OP_call_ref in frame info)"));
1530 /* No way to tell where the next op is, so just bail. */
1531 return need_frame_base;
1532 }
1533 if (dwarf_version == 2)
1534 {
0c588247 1535 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
b7807392
JJ
1536 }
1537 else
1538 {
0c588247 1539 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
b7807392 1540 }
0c588247 1541 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
19e6b90e 1542 break;
a87b0a59
NS
1543 case DW_OP_form_tls_address:
1544 printf ("DW_OP_form_tls_address");
1545 break;
e2a0d921
NC
1546 case DW_OP_call_frame_cfa:
1547 printf ("DW_OP_call_frame_cfa");
1548 break;
1549 case DW_OP_bit_piece:
1550 printf ("DW_OP_bit_piece: ");
cd30bcef
AM
1551 READ_ULEB (uvalue, data, end);
1552 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue));
1553 READ_ULEB (uvalue, data, end);
1554 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue));
e2a0d921 1555 break;
19e6b90e 1556
3244e8f5
JJ
1557 /* DWARF 4 extensions. */
1558 case DW_OP_stack_value:
1559 printf ("DW_OP_stack_value");
1560 break;
1561
1562 case DW_OP_implicit_value:
1563 printf ("DW_OP_implicit_value");
cd30bcef 1564 READ_ULEB (uvalue, data, end);
ef0b5f1c 1565 data = display_block (data, uvalue, end, ' ');
3244e8f5
JJ
1566 break;
1567
19e6b90e
L
1568 /* GNU extensions. */
1569 case DW_OP_GNU_push_tls_address:
9cf03b7e 1570 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
e2a0d921
NC
1571 break;
1572 case DW_OP_GNU_uninit:
1573 printf ("DW_OP_GNU_uninit");
1574 /* FIXME: Is there data associated with this OP ? */
1575 break;
f1c4cc75
RH
1576 case DW_OP_GNU_encoded_addr:
1577 {
6937bb54 1578 int encoding = 0;
f1c4cc75 1579 dwarf_vma addr;
467c65bc 1580
6937bb54
NC
1581 if (data < end)
1582 encoding = *data++;
041830e0 1583 addr = get_encoded_value (&data, encoding, section, end);
f1c4cc75
RH
1584
1585 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1586 print_dwarf_vma (addr, pointer_size);
1587 }
1588 break;
bc0a77d2 1589 case DW_OP_implicit_pointer:
b7807392 1590 case DW_OP_GNU_implicit_pointer:
d85bf2ba 1591 /* FIXME: Strictly speaking for 64-bit DWARF3 files
b7807392
JJ
1592 this ought to be an 8-byte wide computation. */
1593 if (dwarf_version == -1)
1594 {
bc0a77d2
JK
1595 printf (_("(%s in frame info)"),
1596 (op == DW_OP_implicit_pointer
1597 ? "DW_OP_implicit_pointer"
1598 : "DW_OP_GNU_implicit_pointer"));
b7807392
JJ
1599 /* No way to tell where the next op is, so just bail. */
1600 return need_frame_base;
1601 }
1602 if (dwarf_version == 2)
1603 {
0c588247 1604 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
b7807392
JJ
1605 }
1606 else
1607 {
0c588247 1608 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
b7807392 1609 }
cd30bcef 1610 READ_SLEB (svalue, data, end);
bc0a77d2
JK
1611 printf ("%s: <0x%s> %s",
1612 (op == DW_OP_implicit_pointer
1613 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
0c588247 1614 dwarf_vmatoa ("x", uvalue),
cd30bcef 1615 dwarf_vmatoa ("d", svalue));
b7807392 1616 break;
77145576 1617 case DW_OP_entry_value:
0892011d 1618 case DW_OP_GNU_entry_value:
cd30bcef 1619 READ_ULEB (uvalue, data, end);
058037d3
NC
1620 /* PR 17531: file: 0cc9cd00. */
1621 if (uvalue > (dwarf_vma) (end - data))
1622 uvalue = end - data;
77145576
JK
1623 printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value"
1624 : "DW_OP_GNU_entry_value"));
0892011d
JJ
1625 if (decode_location_expression (data, pointer_size, offset_size,
1626 dwarf_version, uvalue,
1627 cu_offset, section))
1628 need_frame_base = 1;
1629 putchar (')');
1630 data += uvalue;
6937bb54
NC
1631 if (data > end)
1632 data = end;
0892011d 1633 break;
bc0a77d2 1634 case DW_OP_const_type:
0892011d 1635 case DW_OP_GNU_const_type:
cd30bcef 1636 READ_ULEB (uvalue, data, end);
bc0a77d2
JK
1637 printf ("%s: <0x%s> ",
1638 (op == DW_OP_const_type ? "DW_OP_const_type"
1639 : "DW_OP_GNU_const_type"),
0892011d 1640 dwarf_vmatoa ("x", cu_offset + uvalue));
0c588247 1641 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
ef0b5f1c 1642 data = display_block (data, uvalue, end, ' ');
0892011d 1643 break;
bc0a77d2 1644 case DW_OP_regval_type:
0892011d 1645 case DW_OP_GNU_regval_type:
cd30bcef 1646 READ_ULEB (uvalue, data, end);
bc0a77d2
JK
1647 printf ("%s: %s (%s)",
1648 (op == DW_OP_regval_type ? "DW_OP_regval_type"
1649 : "DW_OP_GNU_regval_type"),
0892011d 1650 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
cd30bcef 1651 READ_ULEB (uvalue, data, end);
0892011d
JJ
1652 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1653 break;
bc0a77d2 1654 case DW_OP_deref_type:
0892011d 1655 case DW_OP_GNU_deref_type:
0c588247 1656 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
bc0a77d2
JK
1657 printf ("%s: %ld",
1658 (op == DW_OP_deref_type ? "DW_OP_deref_type"
1659 : "DW_OP_GNU_deref_type"),
1660 (long) uvalue);
cd30bcef 1661 READ_ULEB (uvalue, data, end);
0892011d
JJ
1662 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1663 break;
bc0a77d2 1664 case DW_OP_convert:
0892011d 1665 case DW_OP_GNU_convert:
cd30bcef 1666 READ_ULEB (uvalue, data, end);
bc0a77d2
JK
1667 printf ("%s <0x%s>",
1668 (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"),
f8b999f9 1669 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
0892011d 1670 break;
bc0a77d2 1671 case DW_OP_reinterpret:
0892011d 1672 case DW_OP_GNU_reinterpret:
cd30bcef 1673 READ_ULEB (uvalue, data, end);
bc0a77d2
JK
1674 printf ("%s <0x%s>",
1675 (op == DW_OP_reinterpret ? "DW_OP_reinterpret"
1676 : "DW_OP_GNU_reinterpret"),
f8b999f9
JJ
1677 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1678 break;
1679 case DW_OP_GNU_parameter_ref:
0c588247 1680 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
f8b999f9 1681 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
0c588247 1682 dwarf_vmatoa ("x", cu_offset + uvalue));
0892011d 1683 break;
b4eb7656 1684 case DW_OP_GNU_addr_index:
cd30bcef 1685 READ_ULEB (uvalue, data, end);
b4eb7656
AM
1686 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1687 break;
1688 case DW_OP_GNU_const_index:
cd30bcef 1689 READ_ULEB (uvalue, data, end);
b4eb7656
AM
1690 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1691 break;
f384a1f0
KB
1692 case DW_OP_GNU_variable_value:
1693 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1694 this ought to be an 8-byte wide computation. */
1695 if (dwarf_version == -1)
1696 {
1697 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1698 /* No way to tell where the next op is, so just bail. */
1699 return need_frame_base;
1700 }
1701 if (dwarf_version == 2)
1702 {
1703 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1704 }
1705 else
1706 {
1707 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1708 }
1709 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue));
1710 break;
e2a0d921
NC
1711
1712 /* HP extensions. */
1713 case DW_OP_HP_is_value:
1714 printf ("DW_OP_HP_is_value");
1715 /* FIXME: Is there data associated with this OP ? */
1716 break;
1717 case DW_OP_HP_fltconst4:
1718 printf ("DW_OP_HP_fltconst4");
1719 /* FIXME: Is there data associated with this OP ? */
1720 break;
1721 case DW_OP_HP_fltconst8:
1722 printf ("DW_OP_HP_fltconst8");
1723 /* FIXME: Is there data associated with this OP ? */
1724 break;
1725 case DW_OP_HP_mod_range:
1726 printf ("DW_OP_HP_mod_range");
1727 /* FIXME: Is there data associated with this OP ? */
1728 break;
1729 case DW_OP_HP_unmod_range:
1730 printf ("DW_OP_HP_unmod_range");
1731 /* FIXME: Is there data associated with this OP ? */
1732 break;
1733 case DW_OP_HP_tls:
1734 printf ("DW_OP_HP_tls");
1735 /* FIXME: Is there data associated with this OP ? */
19e6b90e
L
1736 break;
1737
35d60fe4
NC
1738 /* PGI (STMicroelectronics) extensions. */
1739 case DW_OP_PGI_omp_thread_num:
1740 /* Pushes the thread number for the current thread as it would be
1741 returned by the standard OpenMP library function:
1742 omp_get_thread_num(). The "current thread" is the thread for
1743 which the expression is being evaluated. */
1744 printf ("DW_OP_PGI_omp_thread_num");
1745 break;
1746
19e6b90e
L
1747 default:
1748 if (op >= DW_OP_lo_user
1749 && op <= DW_OP_hi_user)
0502a2b4 1750 printf (_("(User defined location op 0x%x)"), op);
19e6b90e 1751 else
0502a2b4 1752 printf (_("(Unknown location op 0x%x)"), op);
19e6b90e
L
1753 /* No way to tell where the next op is, so just bail. */
1754 return need_frame_base;
1755 }
1756
1757 /* Separate the ops. */
1758 if (data < end)
1759 printf ("; ");
1760 }
1761
1762 return need_frame_base;
1763}
1764
341f9135
CC
1765/* Find the CU or TU set corresponding to the given CU_OFFSET.
1766 This is used for DWARF package files. */
1767
1768static struct cu_tu_set *
1769find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
1770{
1771 struct cu_tu_set *p;
1772 unsigned int nsets;
1773 unsigned int dw_sect;
1774
1775 if (do_types)
1776 {
1777 p = tu_sets;
1778 nsets = tu_count;
1779 dw_sect = DW_SECT_TYPES;
1780 }
1781 else
1782 {
1783 p = cu_sets;
1784 nsets = cu_count;
1785 dw_sect = DW_SECT_INFO;
1786 }
1787 while (nsets > 0)
1788 {
1789 if (p->section_offsets [dw_sect] == cu_offset)
1790 return p;
1791 p++;
1792 nsets--;
1793 }
1794 return NULL;
1795}
1796
a69c4772
NC
1797/* Add INC to HIGH_BITS:LOW_BITS. */
1798static void
1799add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc)
1800{
1801 dwarf_vma tmp = * low_bits;
1802
1803 tmp += inc;
1804
1805 /* FIXME: There is probably a better way of handling this:
1806
1807 We need to cope with dwarf_vma being a 32-bit or 64-bit
1808 type. Plus regardless of its size LOW_BITS is meant to
1809 only hold 32-bits, so if there is overflow or wrap around
1810 we must propagate into HIGH_BITS. */
1811 if (tmp < * low_bits)
1812 {
1813 ++ * high_bits;
1814 }
1815 else if (sizeof (tmp) > 8
1816 && (tmp >> 31) > 1)
1817 {
1818 ++ * high_bits;
1819 tmp &= 0xFFFFFFFF;
1820 }
1821
1822 * low_bits = tmp;
1823}
1824
dda8d76d
NC
1825static const char *
1826fetch_alt_indirect_string (dwarf_vma offset)
1827{
24841daa 1828 separate_info * i;
dda8d76d
NC
1829
1830 if (! do_follow_links)
1831 return "";
1832
24841daa
NC
1833 if (first_separate_info == NULL)
1834 return _("<no links available>");
dda8d76d 1835
24841daa
NC
1836 for (i = first_separate_info; i != NULL; i = i->next)
1837 {
1838 struct dwarf_section * section;
1839 const char * ret;
dda8d76d 1840
24841daa
NC
1841 if (! load_debug_section (separate_debug_str, i->handle))
1842 continue;
dda8d76d 1843
24841daa 1844 section = &debug_displays [separate_debug_str].section;
dda8d76d 1845
24841daa
NC
1846 if (section->start == NULL)
1847 continue;
dda8d76d 1848
24841daa
NC
1849 if (offset >= section->size)
1850 continue;
1851
1852 ret = (const char *) (section->start + offset);
1853 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1854 NUL byte. Since our caller is expecting to receive a well formed C
1855 string we test for the lack of a terminating byte here. */
1856 if (strnlen ((const char *) ret, section->size - offset)
1857 == section->size - offset)
1858 return _("<no NUL byte at end of alt .debug_str section>");
1859
1860 return ret;
1861 }
521d4b19 1862
24841daa
NC
1863 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1864 dwarf_vmatoa ("x", offset));
1865 return _("<offset is too big>");
dda8d76d
NC
1866}
1867
d85bf2ba
NC
1868static const char *
1869get_AT_name (unsigned long attribute)
1870{
1871 const char *name;
1872
1873 if (attribute == 0)
1874 return "DW_AT value: 0";
1875
1876 /* One value is shared by the MIPS and HP extensions: */
1877 if (attribute == DW_AT_MIPS_fde)
1878 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1879
1880 name = get_DW_AT_name (attribute);
1881
1882 if (name == NULL)
1883 {
1884 static char buffer[100];
1885
1886 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1887 attribute);
1888 return buffer;
1889 }
1890
1891 return name;
1892}
1893
24841daa 1894static void
50ea0877 1895add_dwo_info (const char * value, dwarf_vma cu_offset, dwo_type type)
24841daa
NC
1896{
1897 dwo_info * dwinfo = xmalloc (sizeof * dwinfo);
1898
50ea0877
NC
1899 dwinfo->type = type;
1900 dwinfo->value = value;
1901 dwinfo->cu_offset = cu_offset;
1902 dwinfo->next = first_dwo_info;
24841daa
NC
1903 first_dwo_info = dwinfo;
1904}
1905
1906static void
50ea0877 1907add_dwo_name (const char * name, dwarf_vma cu_offset)
24841daa 1908{
50ea0877 1909 add_dwo_info (name, cu_offset, DWO_NAME);
24841daa
NC
1910}
1911
1912static void
50ea0877 1913add_dwo_dir (const char * dir, dwarf_vma cu_offset)
24841daa 1914{
50ea0877 1915 add_dwo_info (dir, cu_offset, DWO_DIR);
24841daa
NC
1916}
1917
1918static void
50ea0877 1919add_dwo_id (const char * id, dwarf_vma cu_offset)
24841daa 1920{
50ea0877 1921 add_dwo_info (id, cu_offset, DWO_ID);
24841daa
NC
1922}
1923
1924static void
1925free_dwo_info (void)
1926{
1927 dwo_info * dwinfo;
1928 dwo_info * next;
1929
1930 for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next)
1931 {
1932 next = dwinfo->next;
1933 free (dwinfo);
1934 }
1935 first_dwo_info = NULL;
1936}
1937
afc72f15
NC
1938/* Ensure that START + UVALUE is less than END.
1939 Return an adjusted UVALUE if necessary to ensure this relationship. */
1940
1941static inline dwarf_vma
1942check_uvalue (const unsigned char * start,
1943 dwarf_vma uvalue,
1944 const unsigned char * end)
1945{
1946 dwarf_vma max_uvalue = end - start;
1947
afc72f15
NC
1948 /* See PR 17512: file: 008-103549-0.001:0.1.
1949 and PR 24829 for examples of where these tests are triggered. */
a85eba51 1950 if (uvalue > max_uvalue)
afc72f15
NC
1951 {
1952 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1953 uvalue = max_uvalue;
1954 }
1955
1956 return uvalue;
1957}
1958
ec1b0fbb
NC
1959static unsigned char *
1960skip_attr_bytes (unsigned long form,
1961 unsigned char * data,
1962 unsigned const char * end,
1963 dwarf_vma pointer_size,
1964 dwarf_vma offset_size,
1965 int dwarf_version,
1966 dwarf_vma * value_return)
1967{
cd30bcef
AM
1968 dwarf_signed_vma svalue;
1969 dwarf_vma uvalue = 0;
ec1b0fbb
NC
1970
1971 * value_return = 0;
1972
1973 switch (form)
1974 {
1975 case DW_FORM_ref_addr:
1976 if (dwarf_version == 2)
1977 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
59624513 1978 else if (dwarf_version > 2)
ec1b0fbb
NC
1979 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1980 else
1981 return NULL;
1982 break;
1983
1984 case DW_FORM_addr:
1985 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1986 break;
1987
1988 case DW_FORM_strp:
1989 case DW_FORM_line_strp:
1990 case DW_FORM_sec_offset:
1991 case DW_FORM_GNU_ref_alt:
1992 case DW_FORM_GNU_strp_alt:
1993 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
1994 break;
1995
1996 case DW_FORM_flag_present:
1997 uvalue = 1;
1998 break;
1999
2000 case DW_FORM_ref1:
2001 case DW_FORM_flag:
2002 case DW_FORM_data1:
32e4f96c
TV
2003 case DW_FORM_strx1:
2004 case DW_FORM_addrx1:
ec1b0fbb
NC
2005 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
2006 break;
2007
32e4f96c
TV
2008 case DW_FORM_strx3:
2009 case DW_FORM_addrx3:
2010 SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end);
2011 break;
2012
ec1b0fbb
NC
2013 case DW_FORM_ref2:
2014 case DW_FORM_data2:
32e4f96c
TV
2015 case DW_FORM_strx2:
2016 case DW_FORM_addrx2:
ec1b0fbb
NC
2017 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
2018 break;
2019
2020 case DW_FORM_ref4:
2021 case DW_FORM_data4:
32e4f96c
TV
2022 case DW_FORM_strx4:
2023 case DW_FORM_addrx4:
ec1b0fbb
NC
2024 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
2025 break;
2026
2027 case DW_FORM_sdata:
cd30bcef
AM
2028 READ_SLEB (svalue, data, end);
2029 uvalue = svalue;
ec1b0fbb
NC
2030 break;
2031
2032 case DW_FORM_ref_udata:
2033 case DW_FORM_udata:
2034 case DW_FORM_GNU_str_index:
32e4f96c 2035 case DW_FORM_strx:
ec1b0fbb 2036 case DW_FORM_GNU_addr_index:
32e4f96c 2037 case DW_FORM_addrx:
cd30bcef 2038 READ_ULEB (uvalue, data, end);
ec1b0fbb
NC
2039 break;
2040
2041 case DW_FORM_ref8:
1f573141
NC
2042 {
2043 dwarf_vma high_bits;
2044
2045 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
2046 data += 8;
2047 if (sizeof (uvalue) > 4)
2048 uvalue += high_bits << 32;
2049 else if (high_bits != 0)
2050 {
2051 /* FIXME: What to do ? */
2052 return NULL;
2053 }
2054 break;
2055 }
2056
ec1b0fbb 2057 case DW_FORM_data8:
59624513 2058 case DW_FORM_ref_sig8:
ec1b0fbb
NC
2059 data += 8;
2060 break;
2061
2062 case DW_FORM_data16:
2063 data += 16;
2064 break;
2065
2066 case DW_FORM_string:
2067 data += strnlen ((char *) data, end - data) + 1;
2068 break;
2069
2070 case DW_FORM_block:
2071 case DW_FORM_exprloc:
cd30bcef 2072 READ_ULEB (uvalue, data, end);
59624513 2073 data += uvalue;
ec1b0fbb
NC
2074 break;
2075
2076 case DW_FORM_block1:
2077 SAFE_BYTE_GET (uvalue, data, 1, end);
2078 data += 1 + uvalue;
2079 break;
2080
2081 case DW_FORM_block2:
2082 SAFE_BYTE_GET (uvalue, data, 2, end);
2083 data += 2 + uvalue;
2084 break;
2085
2086 case DW_FORM_block4:
2087 SAFE_BYTE_GET (uvalue, data, 4, end);
2088 data += 4 + uvalue;
2089 break;
2090
ec1b0fbb 2091 case DW_FORM_indirect:
59624513
NC
2092 READ_ULEB (form, data, end);
2093 if (form == DW_FORM_implicit_const)
2094 SKIP_ULEB (data, end);
2095 return skip_attr_bytes (form, data, end, pointer_size, offset_size, dwarf_version, value_return);
2096
ec1b0fbb
NC
2097 default:
2098 return NULL;
2099 }
2100
2101 * value_return = uvalue;
2102 if (data > end)
2103 data = (unsigned char *) end;
2104 return data;
2105}
2106
bcd213b2
NC
2107/* Given form FORM with value UVALUE, locate and return the abbreviation
2108 associated with it. */
2109
2110static abbrev_entry *
2111get_type_abbrev_from_form (unsigned long form,
2112 unsigned long uvalue,
2113 dwarf_vma cu_offset,
2114 const struct dwarf_section * section,
2115 unsigned long * abbrev_num_return,
2116 unsigned char ** data_return,
2117 unsigned long * cu_offset_return)
2118{
2119 unsigned long abbrev_number;
2120 abbrev_map * map;
2121 abbrev_entry * entry;
2122 unsigned char * data;
2123
2124 if (abbrev_num_return != NULL)
2125 * abbrev_num_return = 0;
2126 if (data_return != NULL)
2127 * data_return = NULL;
2128
2129 switch (form)
2130 {
2131 case DW_FORM_GNU_ref_alt:
5f128a25 2132 case DW_FORM_ref_sig8:
bcd213b2
NC
2133 /* FIXME: We are unable to handle this form at the moment. */
2134 return NULL;
2135
2136 case DW_FORM_ref_addr:
2137 if (uvalue >= section->size)
2138 {
2139 warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
2140 uvalue, (long) section->size, section->name);
2141 return NULL;
2142 }
2143 break;
2144
e38332c2
NC
2145 case DW_FORM_ref_sup4:
2146 case DW_FORM_ref_sup8:
2147 break;
2148
bcd213b2
NC
2149 case DW_FORM_ref1:
2150 case DW_FORM_ref2:
2151 case DW_FORM_ref4:
1f573141 2152 case DW_FORM_ref8:
bcd213b2
NC
2153 case DW_FORM_ref_udata:
2154 if (uvalue + cu_offset > section->size)
2155 {
2156 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > section size %lx\n"),
2157 uvalue, (long) cu_offset, (long) section->size);
2158 return NULL;
2159 }
2160 uvalue += cu_offset;
2161 break;
2162
2163 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2164
2165 default:
2166 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form);
2167 return NULL;
2168 }
2169
2170 data = (unsigned char *) section->start + uvalue;
2171 map = find_abbrev_map_by_offset (uvalue);
521d4b19 2172
bcd213b2
NC
2173 if (map == NULL)
2174 {
2175 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue);
2176 return NULL;
2177 }
2178 if (map->list == NULL)
2179 {
2180 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue);
2181 return NULL;
2182 }
2183
2184 if (cu_offset_return != NULL)
2185 {
2186 if (form == DW_FORM_ref_addr)
2187 * cu_offset_return = map->start;
2188 else
2189 * cu_offset_return = cu_offset;
2190 }
2191
2192 READ_ULEB (abbrev_number, data, section->start + section->size);
2193
2194 for (entry = map->list->first_abbrev; entry != NULL; entry = entry->next)
2195 if (entry->number == abbrev_number)
2196 break;
521d4b19 2197
bcd213b2
NC
2198 if (abbrev_num_return != NULL)
2199 * abbrev_num_return = abbrev_number;
2200
2201 if (data_return != NULL)
2202 * data_return = data;
2203
2204 if (entry == NULL)
2205 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number);
2206
2207 return entry;
2208}
2209
2210/* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2211 can be determined to be a signed type. The data for ENTRY can be
2212 found starting at DATA. */
ec1b0fbb
NC
2213
2214static void
015dc7e1
AM
2215get_type_signedness (abbrev_entry *entry,
2216 const struct dwarf_section *section,
2217 unsigned char *data,
2218 unsigned const char *end,
2219 dwarf_vma cu_offset,
2220 dwarf_vma pointer_size,
2221 dwarf_vma offset_size,
2222 int dwarf_version,
2223 bool *is_signed,
2224 unsigned int nesting)
ec1b0fbb 2225{
ec1b0fbb
NC
2226 abbrev_attr * attr;
2227
015dc7e1 2228 * is_signed = false;
ec1b0fbb 2229
59624513
NC
2230#define MAX_NESTING 20
2231 if (nesting > MAX_NESTING)
2232 {
2233 /* FIXME: Warn - or is this expected ?
2234 NB/ We need to avoid infinite recursion. */
2235 return;
2236 }
2237
ec1b0fbb
NC
2238 for (attr = entry->first_attr;
2239 attr != NULL && attr->attribute;
2240 attr = attr->next)
2241 {
bcd213b2 2242 unsigned char * orig_data = data;
ec1b0fbb
NC
2243 dwarf_vma uvalue = 0;
2244
2245 data = skip_attr_bytes (attr->form, data, end, pointer_size,
2246 offset_size, dwarf_version, & uvalue);
2247 if (data == NULL)
2248 return;
2249
2250 switch (attr->attribute)
2251 {
bcd213b2 2252 case DW_AT_linkage_name:
ec1b0fbb 2253 case DW_AT_name:
bcd213b2
NC
2254 if (do_wide)
2255 {
2256 if (attr->form == DW_FORM_strp)
2257 printf (", %s", fetch_indirect_string (uvalue));
2258 else if (attr->form == DW_FORM_string)
2259 printf (", %s", orig_data);
2260 }
ec1b0fbb 2261 break;
bcd213b2 2262
ec1b0fbb
NC
2263 case DW_AT_type:
2264 /* Recurse. */
bcd213b2
NC
2265 {
2266 abbrev_entry * type_abbrev;
2267 unsigned char * type_data;
2268 unsigned long type_cu_offset;
2269
2270 type_abbrev = get_type_abbrev_from_form (attr->form,
2271 uvalue,
2272 cu_offset,
2273 section,
2274 NULL /* abbrev num return */,
2275 & type_data,
2276 & type_cu_offset);
2277 if (type_abbrev == NULL)
2278 break;
2279
2280 get_type_signedness (type_abbrev, section, type_data, end, type_cu_offset,
2281 pointer_size, offset_size, dwarf_version,
2282 is_signed, nesting + 1);
2283 }
ec1b0fbb
NC
2284 break;
2285
2286 case DW_AT_encoding:
2287 /* Determine signness. */
2288 switch (uvalue)
2289 {
2290 case DW_ATE_address:
2291 /* FIXME - some architectures have signed addresses. */
2292 case DW_ATE_boolean:
2293 case DW_ATE_unsigned:
2294 case DW_ATE_unsigned_char:
2295 case DW_ATE_unsigned_fixed:
015dc7e1 2296 * is_signed = false;
ec1b0fbb
NC
2297 break;
2298
2299 default:
2300 case DW_ATE_complex_float:
2301 case DW_ATE_float:
2302 case DW_ATE_signed:
2303 case DW_ATE_signed_char:
2304 case DW_ATE_imaginary_float:
2305 case DW_ATE_decimal_float:
2306 case DW_ATE_signed_fixed:
015dc7e1 2307 * is_signed = true;
ec1b0fbb
NC
2308 break;
2309 }
2310 break;
2311 }
2312 }
2313}
2314
2315static void
015dc7e1
AM
2316read_and_print_leb128 (unsigned char *data,
2317 unsigned int *bytes_read,
2318 unsigned const char *end,
2319 bool is_signed)
ec1b0fbb 2320{
cd30bcef
AM
2321 int status;
2322 dwarf_vma val = read_leb128 (data, end, is_signed, bytes_read, &status);
2323 if (status != 0)
1b513401 2324 report_leb_status (status, __FILE__, __LINE__);
ec1b0fbb 2325 else
cd30bcef 2326 printf ("%s", dwarf_vmatoa (is_signed ? "d" : "u", val));
ec1b0fbb
NC
2327}
2328
2329static void
2330display_discr_list (unsigned long form,
2331 dwarf_vma uvalue,
2332 unsigned char * data,
2333 unsigned const char * end,
2334 int level)
2335{
2336 if (uvalue == 0)
2337 {
2338 printf ("[default]");
2339 return;
2340 }
521d4b19 2341
ec1b0fbb
NC
2342 switch (form)
2343 {
2344 case DW_FORM_block:
2345 case DW_FORM_block1:
2346 case DW_FORM_block2:
2347 case DW_FORM_block4:
2348 /* Move data pointer back to the start of the byte array. */
2349 data -= uvalue;
2350 break;
2351 default:
2352 printf ("<corrupt>\n");
2353 warn (_("corrupt discr_list - not using a block form\n"));
2354 return;
2355 }
2356
2357 if (uvalue < 2)
2358 {
2359 printf ("<corrupt>\n");
2360 warn (_("corrupt discr_list - block not long enough\n"));
2361 return;
2362 }
2363
015dc7e1 2364 bool is_signed =
ec1b0fbb 2365 (level > 0 && level <= MAX_CU_NESTING)
015dc7e1 2366 ? level_type_signed [level - 1] : false;
521d4b19 2367
ec1b0fbb
NC
2368 printf ("(");
2369 while (uvalue)
2370 {
2371 unsigned char discriminant;
2372 unsigned int bytes_read;
2373
2374 SAFE_BYTE_GET (discriminant, data, 1, end);
2375 -- uvalue;
2376 data ++;
2377
2378 assert (uvalue > 0);
2379 switch (discriminant)
2380 {
2381 case DW_DSC_label:
2382 printf ("label ");
2383 read_and_print_leb128 (data, & bytes_read, end, is_signed);
2384 assert (bytes_read <= uvalue && bytes_read > 0);
2385 uvalue -= bytes_read;
2386 data += bytes_read;
2387 break;
2388
2389 case DW_DSC_range:
2390 printf ("range ");
2391 read_and_print_leb128 (data, & bytes_read, end, is_signed);
2392 assert (bytes_read <= uvalue && bytes_read > 0);
2393 uvalue -= bytes_read;
2394 data += bytes_read;
2395
2396 printf ("..");
2397 read_and_print_leb128 (data, & bytes_read, end, is_signed);
2398 assert (bytes_read <= uvalue && bytes_read > 0);
2399 uvalue -= bytes_read;
2400 data += bytes_read;
2401 break;
2402
2403 default:
2404 printf ("<corrupt>\n");
e38332c2 2405 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
ec1b0fbb
NC
2406 discriminant);
2407 return;
2408 }
2409
2410 if (uvalue)
2411 printf (", ");
2412 }
2413
2414 if (is_signed)
2415 printf (")(signed)");
2416 else
2417 printf (")(unsigned)");
2418}
2419
19e6b90e 2420static unsigned char *
dda8d76d
NC
2421read_and_display_attr_value (unsigned long attribute,
2422 unsigned long form,
2423 dwarf_signed_vma implicit_const,
ec1b0fbb 2424 unsigned char * start,
dda8d76d
NC
2425 unsigned char * data,
2426 unsigned char * end,
2427 dwarf_vma cu_offset,
2428 dwarf_vma pointer_size,
2429 dwarf_vma offset_size,
2430 int dwarf_version,
2431 debug_info * debug_info_p,
2432 int do_loc,
2433 struct dwarf_section * section,
2434 struct cu_tu_set * this_set,
ec1b0fbb
NC
2435 char delimiter,
2436 int level)
19e6b90e 2437{
cd30bcef 2438 dwarf_signed_vma svalue;
ec1b0fbb
NC
2439 dwarf_vma uvalue = 0;
2440 unsigned char * block_start = NULL;
2441 unsigned char * orig_data = data;
19e6b90e 2442
f41e4712 2443 if (data > end || (data == end && form != DW_FORM_flag_present))
0c588247 2444 {
f41e4712 2445 warn (_("Corrupt attribute\n"));
0c588247
NC
2446 return data;
2447 }
2448
521d4b19
NC
2449 if (do_wide && ! do_loc)
2450 {
2451 /* PR 26847: Display the name of the form. */
2452 const char * name = get_FORM_name (form);
2453
2454 /* For convenience we skip the DW_FORM_ prefix to the name. */
2455 if (name[0] == 'D')
2456 name += 8; /* strlen ("DW_FORM_") */
2457 printf ("%c(%s)", delimiter, name);
2458 }
2459
19e6b90e
L
2460 switch (form)
2461 {
2462 default:
2463 break;
2464
2465 case DW_FORM_ref_addr:
2466 if (dwarf_version == 2)
0c588247 2467 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
ec47b32a 2468 else if (dwarf_version > 2)
0c588247 2469 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
19e6b90e 2470 else
ec47b32a 2471 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
19e6b90e
L
2472 break;
2473
2474 case DW_FORM_addr:
0c588247 2475 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
19e6b90e
L
2476 break;
2477
e38332c2 2478 case DW_FORM_strp_sup:
19e6b90e 2479 case DW_FORM_strp:
77145576 2480 case DW_FORM_line_strp:
932fd279 2481 case DW_FORM_sec_offset:
a081f3cd
JJ
2482 case DW_FORM_GNU_ref_alt:
2483 case DW_FORM_GNU_strp_alt:
0c588247 2484 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
19e6b90e
L
2485 break;
2486
932fd279
JJ
2487 case DW_FORM_flag_present:
2488 uvalue = 1;
2489 break;
2490
19e6b90e
L
2491 case DW_FORM_ref1:
2492 case DW_FORM_flag:
2493 case DW_FORM_data1:
32e4f96c
TV
2494 case DW_FORM_strx1:
2495 case DW_FORM_addrx1:
0c588247 2496 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
19e6b90e
L
2497 break;
2498
2499 case DW_FORM_ref2:
2500 case DW_FORM_data2:
32e4f96c
TV
2501 case DW_FORM_strx2:
2502 case DW_FORM_addrx2:
0c588247 2503 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
19e6b90e
L
2504 break;
2505
32e4f96c
TV
2506 case DW_FORM_strx3:
2507 case DW_FORM_addrx3:
2508 SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end);
2509 break;
2510
e38332c2 2511 case DW_FORM_ref_sup4:
19e6b90e
L
2512 case DW_FORM_ref4:
2513 case DW_FORM_data4:
32e4f96c
TV
2514 case DW_FORM_strx4:
2515 case DW_FORM_addrx4:
0c588247 2516 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
19e6b90e
L
2517 break;
2518
2519 case DW_FORM_sdata:
cd30bcef
AM
2520 READ_SLEB (svalue, data, end);
2521 uvalue = svalue;
19e6b90e
L
2522 break;
2523
4723351a 2524 case DW_FORM_GNU_str_index:
32e4f96c 2525 case DW_FORM_strx:
19e6b90e
L
2526 case DW_FORM_ref_udata:
2527 case DW_FORM_udata:
cd30bcef 2528 case DW_FORM_GNU_addr_index:
32e4f96c 2529 case DW_FORM_addrx:
cd30bcef 2530 READ_ULEB (uvalue, data, end);
19e6b90e
L
2531 break;
2532
2533 case DW_FORM_indirect:
cd30bcef 2534 READ_ULEB (form, data, end);
19e6b90e 2535 if (!do_loc)
ef0b5f1c 2536 printf ("%c%s", delimiter, get_FORM_name (form));
77145576 2537 if (form == DW_FORM_implicit_const)
cd30bcef 2538 READ_SLEB (implicit_const, data, end);
ec1b0fbb
NC
2539 return read_and_display_attr_value (attribute, form, implicit_const,
2540 start, data, end,
2541 cu_offset, pointer_size,
19e6b90e 2542 offset_size, dwarf_version,
ec4d4525 2543 debug_info_p, do_loc,
ec1b0fbb 2544 section, this_set, delimiter, level);
19e6b90e
L
2545 }
2546
2547 switch (form)
2548 {
2549 case DW_FORM_ref_addr:
2550 if (!do_loc)
bcd213b2 2551 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue));
19e6b90e
L
2552 break;
2553
a081f3cd
JJ
2554 case DW_FORM_GNU_ref_alt:
2555 if (!do_loc)
521d4b19
NC
2556 {
2557 if (do_wide)
2558 /* We have already printed the form name. */
2559 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue));
2560 else
2561 printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x", uvalue));
2562 }
dda8d76d 2563 /* FIXME: Follow the reference... */
a081f3cd
JJ
2564 break;
2565
19e6b90e
L
2566 case DW_FORM_ref1:
2567 case DW_FORM_ref2:
2568 case DW_FORM_ref4:
e38332c2 2569 case DW_FORM_ref_sup4:
19e6b90e
L
2570 case DW_FORM_ref_udata:
2571 if (!do_loc)
ef0b5f1c 2572 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset));
19e6b90e
L
2573 break;
2574
2575 case DW_FORM_data4:
2576 case DW_FORM_addr:
932fd279 2577 case DW_FORM_sec_offset:
19e6b90e 2578 if (!do_loc)
ef0b5f1c 2579 printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue));
19e6b90e
L
2580 break;
2581
932fd279 2582 case DW_FORM_flag_present:
19e6b90e
L
2583 case DW_FORM_flag:
2584 case DW_FORM_data1:
2585 case DW_FORM_data2:
2586 case DW_FORM_sdata:
2587 case DW_FORM_udata:
2588 if (!do_loc)
ef0b5f1c 2589 printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue));
19e6b90e
L
2590 break;
2591
77145576
JK
2592 case DW_FORM_implicit_const:
2593 if (!do_loc)
2594 printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const));
2595 break;
2596
e38332c2 2597 case DW_FORM_ref_sup8:
19e6b90e
L
2598 case DW_FORM_ref8:
2599 case DW_FORM_data8:
2bc8690c 2600 if (!do_loc)
19e6b90e 2601 {
74bc6052 2602 dwarf_vma high_bits;
a69c4772 2603 dwarf_vma utmp;
74bc6052
CC
2604 char buf[64];
2605
0c588247 2606 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
a69c4772
NC
2607 utmp = uvalue;
2608 if (form == DW_FORM_ref8)
2609 add64 (& high_bits, & utmp, cu_offset);
ef0b5f1c 2610 printf ("%c0x%s", delimiter,
a69c4772 2611 dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf)));
19e6b90e 2612 }
0c588247 2613
19e6b90e
L
2614 if ((do_loc || do_debug_loc || do_debug_ranges)
2615 && num_debug_info_entries == 0)
2616 {
2617 if (sizeof (uvalue) == 8)
0c588247 2618 SAFE_BYTE_GET (uvalue, data, 8, end);
19e6b90e 2619 else
467c65bc 2620 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
19e6b90e 2621 }
0c588247 2622
19e6b90e
L
2623 data += 8;
2624 break;
2625
2f6cd591
JK
2626 case DW_FORM_data16:
2627 if (!do_loc)
2628 {
2629 dwarf_vma left_high_bits, left_low_bits;
2630 dwarf_vma right_high_bits, right_low_bits;
2631
2632 SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end);
2633 SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end);
2634 if (byte_get == byte_get_little_endian)
2635 {
2636 /* Swap them. */
2637 left_high_bits ^= right_high_bits;
2638 right_high_bits ^= left_high_bits;
2639 left_high_bits ^= right_high_bits;
2640 left_low_bits ^= right_low_bits;
2641 right_low_bits ^= left_low_bits;
2642 left_low_bits ^= right_low_bits;
2643 }
2644 printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x"
2645 "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x",
2646 left_high_bits, left_low_bits, right_high_bits,
2647 right_low_bits);
2648 }
2649 data += 16;
2650 break;
2651
19e6b90e
L
2652 case DW_FORM_string:
2653 if (!do_loc)
ef0b5f1c 2654 printf ("%c%.*s", delimiter, (int) (end - data), data);
0c588247 2655 data += strnlen ((char *) data, end - data) + 1;
19e6b90e
L
2656 break;
2657
2658 case DW_FORM_block:
932fd279 2659 case DW_FORM_exprloc:
cd30bcef
AM
2660 READ_ULEB (uvalue, data, end);
2661 do_block:
2662 block_start = data;
a1165289
NC
2663 if (block_start >= end)
2664 {
2665 warn (_("Block ends prematurely\n"));
2666 uvalue = 0;
2667 block_start = end;
2668 }
afc72f15
NC
2669
2670 uvalue = check_uvalue (block_start, uvalue, end);
2671
19e6b90e
L
2672 if (do_loc)
2673 data = block_start + uvalue;
2674 else
ef0b5f1c 2675 data = display_block (block_start, uvalue, end, delimiter);
19e6b90e
L
2676 break;
2677
2678 case DW_FORM_block1:
cd30bcef
AM
2679 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
2680 goto do_block;
19e6b90e
L
2681
2682 case DW_FORM_block2:
cd30bcef
AM
2683 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
2684 goto do_block;
19e6b90e
L
2685
2686 case DW_FORM_block4:
cd30bcef
AM
2687 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
2688 goto do_block;
19e6b90e
L
2689
2690 case DW_FORM_strp:
2691 if (!do_loc)
521d4b19
NC
2692 {
2693 if (do_wide)
2694 /* We have already displayed the form name. */
2695 printf (_("%c(offset: 0x%s): %s"), delimiter,
2696 dwarf_vmatoa ("x", uvalue),
2697 fetch_indirect_string (uvalue));
2698 else
2699 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter,
2700 dwarf_vmatoa ("x", uvalue),
2701 fetch_indirect_string (uvalue));
2702 }
19e6b90e
L
2703 break;
2704
77145576
JK
2705 case DW_FORM_line_strp:
2706 if (!do_loc)
521d4b19
NC
2707 {
2708 if (do_wide)
2709 /* We have already displayed the form name. */
2710 printf (_("%c(offset: 0x%s): %s"), delimiter,
2711 dwarf_vmatoa ("x", uvalue),
2712 fetch_indirect_line_string (uvalue));
2713 else
2714 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter,
2715 dwarf_vmatoa ("x", uvalue),
2716 fetch_indirect_line_string (uvalue));
2717 }
77145576
JK
2718 break;
2719
4723351a 2720 case DW_FORM_GNU_str_index:
32e4f96c
TV
2721 case DW_FORM_strx:
2722 case DW_FORM_strx1:
2723 case DW_FORM_strx2:
2724 case DW_FORM_strx3:
2725 case DW_FORM_strx4:
4723351a 2726 if (!do_loc)
b4eb7656 2727 {
63b4cc53 2728 const char *suffix = strrchr (section->name, '.');
015dc7e1 2729 bool dwo = suffix && strcmp (suffix, ".dwo") == 0;
b4eb7656 2730
521d4b19
NC
2731 if (do_wide)
2732 /* We have already displayed the form name. */
2733 printf (_("%c(offset: 0x%s): %s"), delimiter,
2734 dwarf_vmatoa ("x", uvalue),
2735 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
2736 else
2737 printf (_("%c(indexed string: 0x%s): %s"), delimiter,
2738 dwarf_vmatoa ("x", uvalue),
2739 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
b4eb7656 2740 }
4723351a
CC
2741 break;
2742
a081f3cd
JJ
2743 case DW_FORM_GNU_strp_alt:
2744 if (!do_loc)
dda8d76d 2745 {
521d4b19
NC
2746 if (do_wide)
2747 /* We have already displayed the form name. */
2748 printf (_("%c(offset: 0x%s) %s"), delimiter,
2749 dwarf_vmatoa ("x", uvalue),
2750 fetch_alt_indirect_string (uvalue));
2751 else
2752 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter,
2753 dwarf_vmatoa ("x", uvalue),
2754 fetch_alt_indirect_string (uvalue));
dda8d76d 2755 }
a081f3cd
JJ
2756 break;
2757
19e6b90e
L
2758 case DW_FORM_indirect:
2759 /* Handled above. */
2760 break;
2761
2b6f5997
CC
2762 case DW_FORM_ref_sig8:
2763 if (!do_loc)
2764 {
74bc6052
CC
2765 dwarf_vma high_bits;
2766 char buf[64];
2767
0c588247 2768 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
521d4b19
NC
2769 if (do_wide)
2770 /* We have already displayed the form name. */
2771 printf ("%c: 0x%s", delimiter,
2772 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
2773 else
2774 printf ("%csignature: 0x%s", delimiter,
2775 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
2b6f5997 2776 }
74bc6052 2777 data += 8;
2b6f5997
CC
2778 break;
2779
4723351a 2780 case DW_FORM_GNU_addr_index:
32e4f96c
TV
2781 case DW_FORM_addrx:
2782 case DW_FORM_addrx1:
2783 case DW_FORM_addrx2:
2784 case DW_FORM_addrx3:
2785 case DW_FORM_addrx4:
4723351a 2786 if (!do_loc)
521d4b19 2787 {
32e4f96c
TV
2788 dwarf_vma base;
2789 dwarf_vma offset;
2790
2791 if (debug_info_p == NULL)
2792 base = 0;
2793 else if (debug_info_p->addr_base == DEBUG_INFO_UNAVAILABLE)
2794 base = 0;
2795 else
2796 base = debug_info_p->addr_base;
2797
2798 offset = base + uvalue * pointer_size;
2799
521d4b19
NC
2800 if (do_wide)
2801 /* We have already displayed the form name. */
2802 printf (_("%c(index: 0x%s): %s"), delimiter,
2803 dwarf_vmatoa ("x", uvalue),
32e4f96c 2804 fetch_indexed_value (offset, pointer_size));
521d4b19
NC
2805 else
2806 printf (_("%c(addr_index: 0x%s): %s"), delimiter,
2807 dwarf_vmatoa ("x", uvalue),
32e4f96c 2808 fetch_indexed_value (offset, pointer_size));
521d4b19 2809 }
4723351a
CC
2810 break;
2811
e38332c2
NC
2812 case DW_FORM_strp_sup:
2813 if (!do_loc)
2814 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset));
2815 break;
2816
19e6b90e 2817 default:
e38332c2 2818 warn (_("Unrecognized form: 0x%lx\n"), form);
19e6b90e
L
2819 break;
2820 }
2821
19e6b90e 2822 if ((do_loc || do_debug_loc || do_debug_ranges)
fd2f0033
TT
2823 && num_debug_info_entries == 0
2824 && debug_info_p != NULL)
19e6b90e
L
2825 {
2826 switch (attribute)
2827 {
2828 case DW_AT_frame_base:
2829 have_frame_base = 1;
1a0670f3 2830 /* Fall through. */
19e6b90e 2831 case DW_AT_location:
9f272209 2832 case DW_AT_GNU_locviews:
e2a0d921
NC
2833 case DW_AT_string_length:
2834 case DW_AT_return_addr:
19e6b90e
L
2835 case DW_AT_data_member_location:
2836 case DW_AT_vtable_elem_location:
e2a0d921
NC
2837 case DW_AT_segment:
2838 case DW_AT_static_link:
2839 case DW_AT_use_location:
bc0a77d2 2840 case DW_AT_call_value:
629e7ca8 2841 case DW_AT_GNU_call_site_value:
bc0a77d2 2842 case DW_AT_call_data_value:
629e7ca8 2843 case DW_AT_GNU_call_site_data_value:
bc0a77d2 2844 case DW_AT_call_target:
629e7ca8 2845 case DW_AT_GNU_call_site_target:
bc0a77d2 2846 case DW_AT_call_target_clobbered:
629e7ca8 2847 case DW_AT_GNU_call_site_target_clobbered:
b4eb7656 2848 if ((dwarf_version < 4
212b6063 2849 && (form == DW_FORM_data4 || form == DW_FORM_data8))
932fd279 2850 || form == DW_FORM_sec_offset)
19e6b90e
L
2851 {
2852 /* Process location list. */
91d6fa6a 2853 unsigned int lmax = debug_info_p->max_loc_offsets;
19e6b90e
L
2854 unsigned int num = debug_info_p->num_loc_offsets;
2855
91d6fa6a 2856 if (lmax == 0 || num >= lmax)
19e6b90e 2857 {
91d6fa6a 2858 lmax += 1024;
467c65bc 2859 debug_info_p->loc_offsets = (dwarf_vma *)
b4eb7656
AM
2860 xcrealloc (debug_info_p->loc_offsets,
2861 lmax, sizeof (*debug_info_p->loc_offsets));
9f272209
AO
2862 debug_info_p->loc_views = (dwarf_vma *)
2863 xcrealloc (debug_info_p->loc_views,
2864 lmax, sizeof (*debug_info_p->loc_views));
3f5e193b 2865 debug_info_p->have_frame_base = (int *)
b4eb7656
AM
2866 xcrealloc (debug_info_p->have_frame_base,
2867 lmax, sizeof (*debug_info_p->have_frame_base));
91d6fa6a 2868 debug_info_p->max_loc_offsets = lmax;
19e6b90e 2869 }
341f9135 2870 if (this_set != NULL)
b4eb7656 2871 uvalue += this_set->section_offsets [DW_SECT_LOC];
19e6b90e 2872 debug_info_p->have_frame_base [num] = have_frame_base;
9f272209
AO
2873 if (attribute != DW_AT_GNU_locviews)
2874 {
a7504f87
NC
2875 /* Corrupt DWARF info can produce more offsets than views.
2876 See PR 23062 for an example. */
2877 if (debug_info_p->num_loc_offsets
2878 > debug_info_p->num_loc_views)
2879 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2880 else
2881 {
2882 debug_info_p->loc_offsets [num] = uvalue;
2883 debug_info_p->num_loc_offsets++;
2884 }
9f272209
AO
2885 }
2886 else
2887 {
2888 assert (debug_info_p->num_loc_views <= num);
2889 num = debug_info_p->num_loc_views;
a7504f87
NC
2890 if (num > debug_info_p->num_loc_offsets)
2891 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2892 else
2893 {
2894 debug_info_p->loc_views [num] = uvalue;
2895 debug_info_p->num_loc_views++;
2896 }
9f272209 2897 }
19e6b90e
L
2898 }
2899 break;
e2a0d921 2900
19e6b90e
L
2901 case DW_AT_low_pc:
2902 if (need_base_address)
2903 debug_info_p->base_address = uvalue;
2904 break;
2905
4723351a 2906 case DW_AT_GNU_addr_base:
32e4f96c 2907 case DW_AT_addr_base:
b4eb7656 2908 debug_info_p->addr_base = uvalue;
4723351a
CC
2909 break;
2910
2911 case DW_AT_GNU_ranges_base:
b4eb7656 2912 debug_info_p->ranges_base = uvalue;
4723351a
CC
2913 break;
2914
19e6b90e 2915 case DW_AT_ranges:
b4eb7656 2916 if ((dwarf_version < 4
212b6063 2917 && (form == DW_FORM_data4 || form == DW_FORM_data8))
932fd279 2918 || form == DW_FORM_sec_offset)
19e6b90e
L
2919 {
2920 /* Process range list. */
91d6fa6a 2921 unsigned int lmax = debug_info_p->max_range_lists;
19e6b90e
L
2922 unsigned int num = debug_info_p->num_range_lists;
2923
91d6fa6a 2924 if (lmax == 0 || num >= lmax)
19e6b90e 2925 {
91d6fa6a 2926 lmax += 1024;
467c65bc 2927 debug_info_p->range_lists = (dwarf_vma *)
b4eb7656
AM
2928 xcrealloc (debug_info_p->range_lists,
2929 lmax, sizeof (*debug_info_p->range_lists));
91d6fa6a 2930 debug_info_p->max_range_lists = lmax;
19e6b90e
L
2931 }
2932 debug_info_p->range_lists [num] = uvalue;
2933 debug_info_p->num_range_lists++;
2934 }
2935 break;
2936
d85bf2ba
NC
2937 case DW_AT_GNU_dwo_name:
2938 case DW_AT_dwo_name:
2939 if (need_dwo_info)
2940 switch (form)
2941 {
2942 case DW_FORM_strp:
50ea0877 2943 add_dwo_name ((const char *) fetch_indirect_string (uvalue), cu_offset);
d85bf2ba 2944 break;
5568cc9e 2945 case DW_FORM_GNU_strp_alt:
50ea0877 2946 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue), cu_offset);
5568cc9e 2947 break;
d85bf2ba 2948 case DW_FORM_GNU_str_index:
32e4f96c
TV
2949 case DW_FORM_strx:
2950 case DW_FORM_strx1:
2951 case DW_FORM_strx2:
2952 case DW_FORM_strx3:
2953 case DW_FORM_strx4:
015dc7e1 2954 add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, false), cu_offset);
d85bf2ba
NC
2955 break;
2956 case DW_FORM_string:
50ea0877 2957 add_dwo_name ((const char *) orig_data, cu_offset);
d85bf2ba
NC
2958 break;
2959 default:
2960 warn (_("Unsupported form (%s) for attribute %s\n"),
2961 get_FORM_name (form), get_AT_name (attribute));
d85bf2ba
NC
2962 break;
2963 }
2964 break;
521d4b19 2965
d85bf2ba
NC
2966 case DW_AT_comp_dir:
2967 /* FIXME: Also extract a build-id in a CU/TU. */
2968 if (need_dwo_info)
2969 switch (form)
2970 {
2971 case DW_FORM_strp:
50ea0877 2972 add_dwo_dir ((const char *) fetch_indirect_string (uvalue), cu_offset);
d85bf2ba 2973 break;
5568cc9e 2974 case DW_FORM_GNU_strp_alt:
50ea0877 2975 add_dwo_dir (fetch_alt_indirect_string (uvalue), cu_offset);
5568cc9e 2976 break;
d85bf2ba 2977 case DW_FORM_line_strp:
50ea0877 2978 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue), cu_offset);
d85bf2ba
NC
2979 break;
2980 case DW_FORM_GNU_str_index:
32e4f96c
TV
2981 case DW_FORM_strx:
2982 case DW_FORM_strx1:
2983 case DW_FORM_strx2:
2984 case DW_FORM_strx3:
2985 case DW_FORM_strx4:
015dc7e1 2986 add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, false), cu_offset);
d85bf2ba
NC
2987 break;
2988 case DW_FORM_string:
50ea0877 2989 add_dwo_dir ((const char *) orig_data, cu_offset);
d85bf2ba
NC
2990 break;
2991 default:
2992 warn (_("Unsupported form (%s) for attribute %s\n"),
2993 get_FORM_name (form), get_AT_name (attribute));
d85bf2ba
NC
2994 break;
2995 }
2996 break;
521d4b19 2997
d85bf2ba
NC
2998 case DW_AT_GNU_dwo_id:
2999 if (need_dwo_info)
3000 switch (form)
3001 {
3002 case DW_FORM_data8:
24841daa 3003 /* FIXME: Record the length of the ID as well ? */
50ea0877 3004 add_dwo_id ((const char *) (data - 8), cu_offset);
d85bf2ba
NC
3005 break;
3006 default:
3007 warn (_("Unsupported form (%s) for attribute %s\n"),
3008 get_FORM_name (form), get_AT_name (attribute));
d85bf2ba
NC
3009 break;
3010 }
3011 break;
521d4b19 3012
19e6b90e
L
3013 default:
3014 break;
3015 }
3016 }
3017
4ccf1e31 3018 if (do_loc || attribute == 0)
19e6b90e
L
3019 return data;
3020
ec4d4525 3021 /* For some attributes we can display further information. */
19e6b90e
L
3022 switch (attribute)
3023 {
ec1b0fbb 3024 case DW_AT_type:
b3fe587e
AM
3025 if (level >= 0 && level < MAX_CU_NESTING
3026 && uvalue < (size_t) (end - start))
ec1b0fbb 3027 {
015dc7e1
AM
3028 bool is_signed = false;
3029 abbrev_entry *type_abbrev;
3030 unsigned char *type_data;
3031 unsigned long type_cu_offset;
521d4b19 3032
bcd213b2
NC
3033 type_abbrev = get_type_abbrev_from_form (form, uvalue, cu_offset,
3034 section, NULL, & type_data, & type_cu_offset);
3035 if (type_abbrev != NULL)
3036 {
3037 get_type_signedness (type_abbrev, section, type_data, end, type_cu_offset,
3038 pointer_size, offset_size, dwarf_version,
3039 & is_signed, 0);
3040 }
ec1b0fbb
NC
3041 level_type_signed[level] = is_signed;
3042 }
3043 break;
521d4b19 3044
19e6b90e 3045 case DW_AT_inline:
2e9e81a8 3046 printf ("\t");
19e6b90e
L
3047 switch (uvalue)
3048 {
3049 case DW_INL_not_inlined:
3050 printf (_("(not inlined)"));
3051 break;
3052 case DW_INL_inlined:
3053 printf (_("(inlined)"));
3054 break;
3055 case DW_INL_declared_not_inlined:
3056 printf (_("(declared as inline but ignored)"));
3057 break;
3058 case DW_INL_declared_inlined:
3059 printf (_("(declared as inline and inlined)"));
3060 break;
3061 default:
47704ddf
KT
3062 printf (_(" (Unknown inline attribute value: %s)"),
3063 dwarf_vmatoa ("x", uvalue));
19e6b90e
L
3064 break;
3065 }
3066 break;
3067
3068 case DW_AT_language:
2e9e81a8 3069 printf ("\t");
19e6b90e
L
3070 switch (uvalue)
3071 {
4b78141a 3072 /* Ordered by the numeric value of these constants. */
19e6b90e 3073 case DW_LANG_C89: printf ("(ANSI C)"); break;
4b78141a
NC
3074 case DW_LANG_C: printf ("(non-ANSI C)"); break;
3075 case DW_LANG_Ada83: printf ("(Ada)"); break;
19e6b90e 3076 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
4b78141a
NC
3077 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
3078 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
19e6b90e
L
3079 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
3080 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
19e6b90e 3081 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
4b78141a 3082 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
19e6b90e 3083 /* DWARF 2.1 values. */
4b78141a 3084 case DW_LANG_Java: printf ("(Java)"); break;
19e6b90e
L
3085 case DW_LANG_C99: printf ("(ANSI C99)"); break;
3086 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
3087 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
4b78141a
NC
3088 /* DWARF 3 values. */
3089 case DW_LANG_PLI: printf ("(PLI)"); break;
3090 case DW_LANG_ObjC: printf ("(Objective C)"); break;
3091 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
3092 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
3093 case DW_LANG_D: printf ("(D)"); break;
2b6f5997
CC
3094 /* DWARF 4 values. */
3095 case DW_LANG_Python: printf ("(Python)"); break;
3362e0d9 3096 /* DWARF 5 values. */
2008a0db 3097 case DW_LANG_OpenCL: printf ("(OpenCL)"); break;
3362e0d9 3098 case DW_LANG_Go: printf ("(Go)"); break;
2008a0db
TT
3099 case DW_LANG_Modula3: printf ("(Modula 3)"); break;
3100 case DW_LANG_Haskell: printf ("(Haskell)"); break;
3101 case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break;
8bc10620 3102 case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break;
2008a0db
TT
3103 case DW_LANG_OCaml: printf ("(OCaml)"); break;
3104 case DW_LANG_Rust: printf ("(Rust)"); break;
6ddfe5b4 3105 case DW_LANG_C11: printf ("(C11)"); break;
2008a0db
TT
3106 case DW_LANG_Swift: printf ("(Swift)"); break;
3107 case DW_LANG_Julia: printf ("(Julia)"); break;
3108 case DW_LANG_Dylan: printf ("(Dylan)"); break;
8bc10620 3109 case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break;
5a195044
MW
3110 case DW_LANG_Fortran03: printf ("(Fortran 03)"); break;
3111 case DW_LANG_Fortran08: printf ("(Fortran 08)"); break;
2008a0db 3112 case DW_LANG_RenderScript: printf ("(RenderScript)"); break;
19e6b90e
L
3113 /* MIPS extension. */
3114 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
3115 /* UPC extension. */
3116 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
3117 default:
4b78141a 3118 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
9cf03b7e 3119 printf (_("(implementation defined: %s)"),
467c65bc 3120 dwarf_vmatoa ("x", uvalue));
4b78141a 3121 else
9cf03b7e 3122 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
19e6b90e
L
3123 break;
3124 }
3125 break;
3126
3127 case DW_AT_encoding:
2e9e81a8 3128 printf ("\t");
19e6b90e
L
3129 switch (uvalue)
3130 {
3131 case DW_ATE_void: printf ("(void)"); break;
3132 case DW_ATE_address: printf ("(machine address)"); break;
3133 case DW_ATE_boolean: printf ("(boolean)"); break;
3134 case DW_ATE_complex_float: printf ("(complex float)"); break;
3135 case DW_ATE_float: printf ("(float)"); break;
3136 case DW_ATE_signed: printf ("(signed)"); break;
3137 case DW_ATE_signed_char: printf ("(signed char)"); break;
3138 case DW_ATE_unsigned: printf ("(unsigned)"); break;
3139 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
e2a0d921 3140 /* DWARF 2.1 values: */
19e6b90e
L
3141 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
3142 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
e2a0d921
NC
3143 /* DWARF 3 values: */
3144 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
3145 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
3146 case DW_ATE_edited: printf ("(edited)"); break;
3147 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
3148 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
04914e37
NC
3149 /* DWARF 4 values: */
3150 case DW_ATE_UTF: printf ("(unicode string)"); break;
3151 /* DWARF 5 values: */
3152 case DW_ATE_UCS: printf ("(UCS)"); break;
3153 case DW_ATE_ASCII: printf ("(ASCII)"); break;
3154
e2a0d921
NC
3155 /* HP extensions: */
3156 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
3157 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
3158 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
3159 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
3160 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
3161 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
3162 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
3163
19e6b90e
L
3164 default:
3165 if (uvalue >= DW_ATE_lo_user
3166 && uvalue <= DW_ATE_hi_user)
9cf03b7e 3167 printf (_("(user defined type)"));
19e6b90e 3168 else
9cf03b7e 3169 printf (_("(unknown type)"));
19e6b90e
L
3170 break;
3171 }
3172 break;
3173
3174 case DW_AT_accessibility:
2e9e81a8 3175 printf ("\t");
19e6b90e
L
3176 switch (uvalue)
3177 {
3178 case DW_ACCESS_public: printf ("(public)"); break;
3179 case DW_ACCESS_protected: printf ("(protected)"); break;
3180 case DW_ACCESS_private: printf ("(private)"); break;
3181 default:
9cf03b7e 3182 printf (_("(unknown accessibility)"));
19e6b90e
L
3183 break;
3184 }
3185 break;
3186
3187 case DW_AT_visibility:
2e9e81a8 3188 printf ("\t");
19e6b90e
L
3189 switch (uvalue)
3190 {
3191 case DW_VIS_local: printf ("(local)"); break;
3192 case DW_VIS_exported: printf ("(exported)"); break;
3193 case DW_VIS_qualified: printf ("(qualified)"); break;
9cf03b7e 3194 default: printf (_("(unknown visibility)")); break;
19e6b90e
L
3195 }
3196 break;
3197
04914e37
NC
3198 case DW_AT_endianity:
3199 printf ("\t");
3200 switch (uvalue)
3201 {
3202 case DW_END_default: printf ("(default)"); break;
3203 case DW_END_big: printf ("(big)"); break;
3204 case DW_END_little: printf ("(little)"); break;
3205 default:
3206 if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user)
3207 printf (_("(user specified)"));
3208 else
3209 printf (_("(unknown endianity)"));
3210 break;
3211 }
3212 break;
3213
19e6b90e 3214 case DW_AT_virtuality:
2e9e81a8 3215 printf ("\t");
19e6b90e
L
3216 switch (uvalue)
3217 {
3218 case DW_VIRTUALITY_none: printf ("(none)"); break;
3219 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
3220 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
9cf03b7e 3221 default: printf (_("(unknown virtuality)")); break;
19e6b90e
L
3222 }
3223 break;
3224
3225 case DW_AT_identifier_case:
2e9e81a8 3226 printf ("\t");
19e6b90e
L
3227 switch (uvalue)
3228 {
3229 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
3230 case DW_ID_up_case: printf ("(up_case)"); break;
3231 case DW_ID_down_case: printf ("(down_case)"); break;
3232 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
9cf03b7e 3233 default: printf (_("(unknown case)")); break;
19e6b90e
L
3234 }
3235 break;
3236
3237 case DW_AT_calling_convention:
2e9e81a8 3238 printf ("\t");
19e6b90e
L
3239 switch (uvalue)
3240 {
3241 case DW_CC_normal: printf ("(normal)"); break;
3242 case DW_CC_program: printf ("(program)"); break;
3243 case DW_CC_nocall: printf ("(nocall)"); break;
04914e37
NC
3244 case DW_CC_pass_by_reference: printf ("(pass by ref)"); break;
3245 case DW_CC_pass_by_value: printf ("(pass by value)"); break;
3246 case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break;
3247 case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break;
19e6b90e
L
3248 default:
3249 if (uvalue >= DW_CC_lo_user
3250 && uvalue <= DW_CC_hi_user)
9cf03b7e 3251 printf (_("(user defined)"));
19e6b90e 3252 else
9cf03b7e 3253 printf (_("(unknown convention)"));
19e6b90e
L
3254 }
3255 break;
3256
3257 case DW_AT_ordering:
2e9e81a8 3258 printf ("\t");
19e6b90e
L
3259 switch (uvalue)
3260 {
04914e37 3261 case 255:
9cf03b7e 3262 case -1: printf (_("(undefined)")); break;
19e6b90e
L
3263 case 0: printf ("(row major)"); break;
3264 case 1: printf ("(column major)"); break;
3265 }
3266 break;
3267
04914e37
NC
3268 case DW_AT_decimal_sign:
3269 printf ("\t");
3270 switch (uvalue)
3271 {
3272 case DW_DS_unsigned: printf (_("(unsigned)")); break;
3273 case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break;
3274 case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break;
3275 case DW_DS_leading_separate: printf (_("(leading separate)")); break;
3276 case DW_DS_trailing_separate: printf (_("(trailing separate)")); break;
3277 default: printf (_("(unrecognised)")); break;
3278 }
3279 break;
3280
3281 case DW_AT_defaulted:
3282 printf ("\t");
3283 switch (uvalue)
3284 {
3285 case DW_DEFAULTED_no: printf (_("(no)")); break;
3286 case DW_DEFAULTED_in_class: printf (_("(in class)")); break;
3287 case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break;
3288 default: printf (_("(unrecognised)")); break;
3289 }
3290 break;
3291
3292 case DW_AT_discr_list:
3293 printf ("\t");
ec1b0fbb 3294 display_discr_list (form, uvalue, data, end, level);
04914e37 3295 break;
521d4b19 3296
19e6b90e
L
3297 case DW_AT_frame_base:
3298 have_frame_base = 1;
1a0670f3 3299 /* Fall through. */
19e6b90e 3300 case DW_AT_location:
e2a0d921
NC
3301 case DW_AT_string_length:
3302 case DW_AT_return_addr:
19e6b90e
L
3303 case DW_AT_data_member_location:
3304 case DW_AT_vtable_elem_location:
e2a0d921
NC
3305 case DW_AT_segment:
3306 case DW_AT_static_link:
3307 case DW_AT_use_location:
bc0a77d2 3308 case DW_AT_call_value:
629e7ca8 3309 case DW_AT_GNU_call_site_value:
bc0a77d2 3310 case DW_AT_call_data_value:
629e7ca8 3311 case DW_AT_GNU_call_site_data_value:
bc0a77d2 3312 case DW_AT_call_target:
629e7ca8 3313 case DW_AT_GNU_call_site_target:
bc0a77d2 3314 case DW_AT_call_target_clobbered:
629e7ca8 3315 case DW_AT_GNU_call_site_target_clobbered:
212b6063 3316 if ((dwarf_version < 4
b4eb7656 3317 && (form == DW_FORM_data4 || form == DW_FORM_data8))
932fd279 3318 || form == DW_FORM_sec_offset)
2e9e81a8 3319 printf (_(" (location list)"));
e2a0d921 3320 /* Fall through. */
19e6b90e
L
3321 case DW_AT_allocated:
3322 case DW_AT_associated:
3323 case DW_AT_data_location:
3324 case DW_AT_stride:
3325 case DW_AT_upper_bound:
cecf136e 3326 case DW_AT_lower_bound:
19e6b90e
L
3327 if (block_start)
3328 {
3329 int need_frame_base;
3330
2e9e81a8 3331 printf ("\t(");
19e6b90e
L
3332 need_frame_base = decode_location_expression (block_start,
3333 pointer_size,
b7807392
JJ
3334 offset_size,
3335 dwarf_version,
19e6b90e 3336 uvalue,
f1c4cc75 3337 cu_offset, section);
19e6b90e
L
3338 printf (")");
3339 if (need_frame_base && !have_frame_base)
3340 printf (_(" [without DW_AT_frame_base]"));
3341 }
19e6b90e
L
3342 break;
3343
c54207d3
NC
3344 case DW_AT_data_bit_offset:
3345 case DW_AT_byte_size:
3346 case DW_AT_bit_size:
3347 case DW_AT_string_length_byte_size:
3348 case DW_AT_string_length_bit_size:
3349 case DW_AT_bit_stride:
3350 if (form == DW_FORM_exprloc)
3351 {
3352 printf ("\t(");
3353 (void) decode_location_expression (block_start, pointer_size,
3354 offset_size, dwarf_version,
3355 uvalue, cu_offset, section);
3356 printf (")");
3357 }
3358 break;
3359
ec4d4525
NC
3360 case DW_AT_import:
3361 {
bcd213b2
NC
3362 unsigned long abbrev_number;
3363 abbrev_entry *entry;
2b6f5997 3364
bcd213b2
NC
3365 entry = get_type_abbrev_from_form (form, uvalue, cu_offset,
3366 section, & abbrev_number, NULL, NULL);
3367 if (entry == NULL)
3368 {
3369 if (form != DW_FORM_GNU_ref_alt)
3370 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3371 dwarf_vmatoa ("x", uvalue),
3372 (unsigned long) (orig_data - section->start));
3373 }
6e3d6dc1
NC
3374 else
3375 {
2e9e81a8 3376 printf (_("\t[Abbrev Number: %ld"), abbrev_number);
bcd213b2 3377 printf (" (%s)", get_TAG_name (entry->tag));
6e3d6dc1
NC
3378 printf ("]");
3379 }
ec4d4525
NC
3380 }
3381 break;
3382
19e6b90e
L
3383 default:
3384 break;
3385 }
3386
3387 return data;
3388}
3389
19e6b90e 3390static unsigned char *
dda8d76d
NC
3391read_and_display_attr (unsigned long attribute,
3392 unsigned long form,
3393 dwarf_signed_vma implicit_const,
ec1b0fbb 3394 unsigned char * start,
dda8d76d
NC
3395 unsigned char * data,
3396 unsigned char * end,
3397 dwarf_vma cu_offset,
3398 dwarf_vma pointer_size,
3399 dwarf_vma offset_size,
3400 int dwarf_version,
3401 debug_info * debug_info_p,
3402 int do_loc,
3403 struct dwarf_section * section,
ec1b0fbb
NC
3404 struct cu_tu_set * this_set,
3405 int level)
19e6b90e
L
3406{
3407 if (!do_loc)
750f03b7 3408 printf (" %-18s:", get_AT_name (attribute));
ec1b0fbb
NC
3409 data = read_and_display_attr_value (attribute, form, implicit_const,
3410 start, data, end,
f6f0e17b 3411 cu_offset, pointer_size, offset_size,
19e6b90e 3412 dwarf_version, debug_info_p,
ec1b0fbb 3413 do_loc, section, this_set, ' ', level);
19e6b90e
L
3414 if (!do_loc)
3415 printf ("\n");
3416 return data;
3417}
3418
dda8d76d 3419/* Like load_debug_section, but if the ordinary call fails, and we are
24841daa
NC
3420 following debug links, then attempt to load the requested section
3421 from one of the separate debug info files. */
dda8d76d 3422
015dc7e1 3423static bool
dda8d76d 3424load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum,
24841daa 3425 void * handle)
dda8d76d 3426{
24841daa 3427 if (load_debug_section (sec_enum, handle))
dda8d76d 3428 {
24841daa
NC
3429 if (debug_displays[sec_enum].section.filename == NULL)
3430 {
3431 /* See if we can associate a filename with this section. */
3432 separate_info * i;
3433
3434 for (i = first_separate_info; i != NULL; i = i->next)
3435 if (i->handle == handle)
3436 {
3437 debug_displays[sec_enum].section.filename = i->filename;
3438 break;
3439 }
3440 }
3441
015dc7e1 3442 return true;
dda8d76d
NC
3443 }
3444
24841daa
NC
3445 if (do_follow_links)
3446 {
3447 separate_info * i;
3448
3449 for (i = first_separate_info; i != NULL; i = i->next)
3450 {
3451 if (load_debug_section (sec_enum, i->handle))
3452 {
3453 debug_displays[sec_enum].section.filename = i->filename;
3454
3455 /* FIXME: We should check to see if any of the remaining debug info
3456 files also contain this section, and, umm, do something about it. */
015dc7e1 3457 return true;
24841daa
NC
3458 }
3459 }
3460 }
dda8d76d 3461
015dc7e1 3462 return false;
dda8d76d
NC
3463}
3464
3465static void
015dc7e1 3466introduce (struct dwarf_section * section, bool raw)
dda8d76d
NC
3467{
3468 if (raw)
3469 {
3470 if (do_follow_links && section->filename)
3471 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3472 section->name, section->filename);
3473 else
3474 printf (_("Raw dump of debug contents of section %s:\n\n"), section->name);
3475 }
3476 else
3477 {
3478 if (do_follow_links && section->filename)
3479 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3480 section->name, section->filename);
3481 else
3482 printf (_("Contents of the %s section:\n\n"), section->name);
3483 }
3484}
521d4b19 3485
d85bf2ba
NC
3486/* Process the contents of a .debug_info section.
3487 If do_loc is TRUE then we are scanning for location lists and dwo tags
3488 and we do not want to display anything to the user.
3489 If do_types is TRUE, we are processing a .debug_types section instead of
3490 a .debug_info section.
3491 The information displayed is restricted by the values in DWARF_START_DIE
3492 and DWARF_CUTOFF_LEVEL.
3493 Returns TRUE upon success. Otherwise an error or warning message is
3494 printed and FALSE is returned. */
19e6b90e 3495
015dc7e1
AM
3496static bool
3497process_debug_info (struct dwarf_section * section,
3498 void *file,
3499 enum dwarf_section_display_enum abbrev_sec,
3500 bool do_loc,
3501 bool do_types)
19e6b90e
L
3502{
3503 unsigned char *start = section->start;
3504 unsigned char *end = start + section->size;
3505 unsigned char *section_begin;
3506 unsigned int unit;
3507 unsigned int num_units = 0;
3508
3509 if ((do_loc || do_debug_loc || do_debug_ranges)
2b6f5997
CC
3510 && num_debug_info_entries == 0
3511 && ! do_types)
19e6b90e 3512 {
767221a9 3513 dwarf_vma length;
19e6b90e
L
3514
3515 /* First scan the section to get the number of comp units. */
3516 for (section_begin = start, num_units = 0; section_begin < end;
3517 num_units ++)
3518 {
3519 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3520 will be the length. For a 64-bit DWARF section, it'll be
3521 the escape code 0xffffffff followed by an 8 byte length. */
0c588247 3522 SAFE_BYTE_GET (length, section_begin, 4, end);
19e6b90e
L
3523
3524 if (length == 0xffffffff)
3525 {
0c588247 3526 SAFE_BYTE_GET (length, section_begin + 4, 8, end);
19e6b90e
L
3527 section_begin += length + 12;
3528 }
ec4d4525
NC
3529 else if (length >= 0xfffffff0 && length < 0xffffffff)
3530 {
767221a9
NC
3531 warn (_("Reserved length value (0x%s) found in section %s\n"),
3532 dwarf_vmatoa ("x", length), section->name);
015dc7e1 3533 return false;
ec4d4525 3534 }
19e6b90e
L
3535 else
3536 section_begin += length + 4;
aca88567
NC
3537
3538 /* Negative values are illegal, they may even cause infinite
3539 looping. This can happen if we can't accurately apply
f3853b34
NC
3540 relocations to an object file, or if the file is corrupt. */
3541 if ((signed long) length <= 0 || section_begin < start)
aca88567 3542 {
767221a9
NC
3543 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
3544 dwarf_vmatoa ("x", length), section->name);
015dc7e1 3545 return false;
aca88567 3546 }
19e6b90e
L
3547 }
3548
3549 if (num_units == 0)
3550 {
f41e4712 3551 error (_("No comp units in %s section ?\n"), section->name);
015dc7e1 3552 return false;
19e6b90e
L
3553 }
3554
3555 /* Then allocate an array to hold the information. */
3f5e193b 3556 debug_information = (debug_info *) cmalloc (num_units,
1306a742 3557 sizeof (* debug_information));
19e6b90e
L
3558 if (debug_information == NULL)
3559 {
f41e4712 3560 error (_("Not enough memory for a debug info array of %u entries\n"),
19e6b90e 3561 num_units);
82b1b41b 3562 alloc_num_debug_info_entries = num_debug_info_entries = 0;
015dc7e1 3563 return false;
19e6b90e 3564 }
d85bf2ba 3565
03a91817
NC
3566 /* PR 17531: file: 92ca3797.
3567 We cannot rely upon the debug_information array being initialised
3568 before it is used. A corrupt file could easily contain references
3569 to a unit for which information has not been made available. So
3570 we ensure that the array is zeroed here. */
b4eb7656
AM
3571 memset (debug_information, 0, num_units * sizeof (*debug_information));
3572
82b1b41b 3573 alloc_num_debug_info_entries = num_units;
19e6b90e
L
3574 }
3575
3576 if (!do_loc)
3577 {
dda8d76d
NC
3578 load_debug_section_with_follow (str, file);
3579 load_debug_section_with_follow (line_str, file);
3580 load_debug_section_with_follow (str_dwo, file);
3581 load_debug_section_with_follow (str_index, file);
3582 load_debug_section_with_follow (str_index_dwo, file);
3583 load_debug_section_with_follow (debug_addr, file);
19e6b90e 3584 }
521d4b19 3585
dda8d76d 3586 load_debug_section_with_follow (abbrev_sec, file);
6f875884 3587 if (debug_displays [abbrev_sec].section.start == NULL)
19e6b90e
L
3588 {
3589 warn (_("Unable to locate %s section!\n"),
dda8d76d 3590 debug_displays [abbrev_sec].section.uncompressed_name);
015dc7e1 3591 return false;
19e6b90e
L
3592 }
3593
dda8d76d 3594 if (!do_loc && dwarf_start_die == 0)
015dc7e1 3595 introduce (section, false);
bcd213b2
NC
3596
3597 free_all_abbrevs ();
3598 free (cu_abbrev_map);
3599 cu_abbrev_map = NULL;
3600 next_free_abbrev_map_entry = 0;
521d4b19 3601
bcd213b2
NC
3602 /* In order to be able to resolve DW_FORM_ref_attr forms we need
3603 to load *all* of the abbrevs for all CUs in this .debug_info
3604 section. This does effectively mean that we (partially) read
3605 every CU header twice. */
3606 for (section_begin = start; start < end;)
3607 {
3608 DWARF2_Internal_CompUnit compunit;
3609 unsigned char * hdrptr;
76868f36
L
3610 dwarf_vma abbrev_base;
3611 size_t abbrev_size;
bcd213b2
NC
3612 dwarf_vma cu_offset;
3613 unsigned int offset_size;
3614 unsigned int initial_length_size;
3615 struct cu_tu_set * this_set;
3616 abbrev_list * list;
3617
3618 hdrptr = start;
3619
3620 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
3621
3622 if (compunit.cu_length == 0xffffffff)
3623 {
3624 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
3625 offset_size = 8;
3626 initial_length_size = 12;
3627 }
3628 else
3629 {
3630 offset_size = 4;
3631 initial_length_size = 4;
3632 }
3633
3634 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
3635
3636 cu_offset = start - section_begin;
3637
3638 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
3639
3640 if (compunit.cu_version < 5)
3641 {
3642 compunit.cu_unit_type = DW_UT_compile;
3643 /* Initialize it due to a false compiler warning. */
3644 compunit.cu_pointer_size = -1;
3645 }
3646 else
3647 {
3648 SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end);
3649 do_types = (compunit.cu_unit_type == DW_UT_type);
3650
3651 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
3652 }
3653
3654 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
3655
9b87f84a
TV
3656 if (compunit.cu_unit_type == DW_UT_split_compile
3657 || compunit.cu_unit_type == DW_UT_skeleton)
3658 {
3659 uint64_t dwo_id;
3660 SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end);
3661 }
3662
76868f36
L
3663 if (this_set == NULL)
3664 {
3665 abbrev_base = 0;
3666 abbrev_size = debug_displays [abbrev_sec].section.size;
3667 }
3668 else
3669 {
3670 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
3671 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
3672 }
3673
3674 list = find_abbrev_list_by_abbrev_offset (abbrev_base,
3675 compunit.cu_abbrev_offset);
bcd213b2
NC
3676 if (list == NULL)
3677 {
bcd213b2
NC
3678 unsigned char * next;
3679
76868f36
L
3680 list = new_abbrev_list (abbrev_base,
3681 compunit.cu_abbrev_offset);
bcd213b2
NC
3682 next = process_abbrev_set
3683 (((unsigned char *) debug_displays [abbrev_sec].section.start
3684 + abbrev_base + compunit.cu_abbrev_offset),
3685 ((unsigned char *) debug_displays [abbrev_sec].section.start
3686 + abbrev_base + abbrev_size),
3687 list);
3688 list->start_of_next_abbrevs = next;
3689 }
521d4b19 3690
bcd213b2
NC
3691 start = section_begin + cu_offset + compunit.cu_length
3692 + initial_length_size;
3693 record_abbrev_list_for_cu (cu_offset, start - section_begin, list);
3694 }
3695
3696 for (start = section_begin, unit = 0; start < end; unit++)
19e6b90e
L
3697 {
3698 DWARF2_Internal_CompUnit compunit;
3699 unsigned char *hdrptr;
19e6b90e 3700 unsigned char *tags;
fd2f0033 3701 int level, last_level, saved_level;
467c65bc 3702 dwarf_vma cu_offset;
e98fdf1a 3703 unsigned long sec_off;
bf5117e3 3704 unsigned int offset_size;
19485196 3705 unsigned int initial_length_size;
74bc6052
CC
3706 dwarf_vma signature_high = 0;
3707 dwarf_vma signature_low = 0;
767221a9 3708 dwarf_vma type_offset = 0;
341f9135
CC
3709 struct cu_tu_set *this_set;
3710 dwarf_vma abbrev_base;
3711 size_t abbrev_size;
bcd213b2 3712 abbrev_list * list = NULL;
19e6b90e
L
3713
3714 hdrptr = start;
3715
0c588247 3716 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
19e6b90e
L
3717
3718 if (compunit.cu_length == 0xffffffff)
3719 {
0c588247 3720 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
19e6b90e
L
3721 offset_size = 8;
3722 initial_length_size = 12;
3723 }
3724 else
3725 {
3726 offset_size = 4;
3727 initial_length_size = 4;
3728 }
3729
0c588247 3730 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
19e6b90e
L
3731
3732 cu_offset = start - section_begin;
19e6b90e 3733
341f9135
CC
3734 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
3735
77145576
JK
3736 if (compunit.cu_version < 5)
3737 {
3738 compunit.cu_unit_type = DW_UT_compile;
3739 /* Initialize it due to a false compiler warning. */
3740 compunit.cu_pointer_size = -1;
3741 }
3742 else
3743 {
3744 SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end);
3745 do_types = (compunit.cu_unit_type == DW_UT_type);
3746
3747 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
3748 }
3749
0c588247 3750 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
19e6b90e 3751
341f9135
CC
3752 if (this_set == NULL)
3753 {
3754 abbrev_base = 0;
3755 abbrev_size = debug_displays [abbrev_sec].section.size;
3756 }
3757 else
3758 {
3759 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
3760 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
3761 }
3762
77145576
JK
3763 if (compunit.cu_version < 5)
3764 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
3765
015dc7e1 3766 bool do_dwo_id = false;
e6ca1878 3767 uint64_t dwo_id = 0;
9b87f84a
TV
3768 if (compunit.cu_unit_type == DW_UT_split_compile
3769 || compunit.cu_unit_type == DW_UT_skeleton)
3770 {
9b87f84a 3771 SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end);
015dc7e1 3772 do_dwo_id = true;
9b87f84a
TV
3773 }
3774
f41e4712
NC
3775 /* PR 17512: file: 001-108546-0.001:0.1. */
3776 if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
3777 {
3778 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3779 compunit.cu_pointer_size, offset_size);
3780 compunit.cu_pointer_size = offset_size;
3781 }
2b6f5997
CC
3782
3783 if (do_types)
b4eb7656 3784 {
0c588247 3785 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
f048b142 3786 hdrptr += 8;
0c588247 3787 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
b4eb7656 3788 }
2b6f5997 3789
ae7e7825
NC
3790 if (dwarf_start_die > (cu_offset + compunit.cu_length
3791 + initial_length_size))
3792 {
3793 start = section_begin + cu_offset + compunit.cu_length
3794 + initial_length_size;
3795 continue;
3796 }
3797
19e6b90e 3798 if ((do_loc || do_debug_loc || do_debug_ranges)
2b6f5997 3799 && num_debug_info_entries == 0
c4b2f181 3800 && alloc_num_debug_info_entries > unit
2b6f5997 3801 && ! do_types)
19e6b90e
L
3802 {
3803 debug_information [unit].cu_offset = cu_offset;
3804 debug_information [unit].pointer_size
3805 = compunit.cu_pointer_size;
b7807392
JJ
3806 debug_information [unit].offset_size = offset_size;
3807 debug_information [unit].dwarf_version = compunit.cu_version;
19e6b90e 3808 debug_information [unit].base_address = 0;
4723351a
CC
3809 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
3810 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
19e6b90e
L
3811 debug_information [unit].loc_offsets = NULL;
3812 debug_information [unit].have_frame_base = NULL;
3813 debug_information [unit].max_loc_offsets = 0;
3814 debug_information [unit].num_loc_offsets = 0;
3815 debug_information [unit].range_lists = NULL;
3816 debug_information [unit].max_range_lists= 0;
3817 debug_information [unit].num_range_lists = 0;
3818 }
3819
fd2f0033 3820 if (!do_loc && dwarf_start_die == 0)
19e6b90e 3821 {
47704ddf
KT
3822 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3823 dwarf_vmatoa ("x", cu_offset));
3824 printf (_(" Length: 0x%s (%s)\n"),
3825 dwarf_vmatoa ("x", compunit.cu_length),
49e7b350 3826 offset_size == 8 ? "64-bit" : "32-bit");
19e6b90e 3827 printf (_(" Version: %d\n"), compunit.cu_version);
debd1a62 3828 if (compunit.cu_version >= 5)
4896932e
MF
3829 {
3830 const char *name = get_DW_UT_name (compunit.cu_unit_type);
3831
3832 printf (_(" Unit Type: %s (%x)\n"),
3833 name ? name : "???",
3834 compunit.cu_unit_type);
3835 }
7282333f
AM
3836 printf (_(" Abbrev Offset: 0x%s\n"),
3837 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
19e6b90e 3838 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2b6f5997
CC
3839 if (do_types)
3840 {
74bc6052
CC
3841 char buf[64];
3842
3843 printf (_(" Signature: 0x%s\n"),
3844 dwarf_vmatoa64 (signature_high, signature_low,
3845 buf, sizeof (buf)));
3846 printf (_(" Type Offset: 0x%s\n"),
3847 dwarf_vmatoa ("x", type_offset));
2b6f5997 3848 }
d60f7998
TV
3849 if (do_dwo_id)
3850 printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id));
341f9135
CC
3851 if (this_set != NULL)
3852 {
3853 dwarf_vma *offsets = this_set->section_offsets;
3854 size_t *sizes = this_set->section_sizes;
3855
3856 printf (_(" Section contributions:\n"));
3857 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3858 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
3859 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
3860 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3861 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
3862 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
3863 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3864 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
3865 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
3866 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3867 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
3868 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
3869 }
19e6b90e
L
3870 }
3871
e98fdf1a
AM
3872 sec_off = cu_offset + initial_length_size;
3873 if (sec_off + compunit.cu_length < sec_off
3874 || sec_off + compunit.cu_length > section->size)
460c89ff 3875 {
e98fdf1a
AM
3876 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
3877 section->name,
3878 (unsigned long) cu_offset,
19485196
NC
3879 dwarf_vmatoa ("x", compunit.cu_length));
3880 num_units = unit;
3881 break;
3882 }
3883
460c89ff
NS
3884 tags = hdrptr;
3885 start += compunit.cu_length + initial_length_size;
3886
77145576 3887 if (compunit.cu_version < 2 || compunit.cu_version > 5)
19e6b90e 3888 {
47704ddf
KT
3889 warn (_("CU at offset %s contains corrupt or "
3890 "unsupported version number: %d.\n"),
3891 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
19e6b90e
L
3892 continue;
3893 }
3894
77145576 3895 if (compunit.cu_unit_type != DW_UT_compile
ec47b32a 3896 && compunit.cu_unit_type != DW_UT_partial
9b87f84a
TV
3897 && compunit.cu_unit_type != DW_UT_type
3898 && compunit.cu_unit_type != DW_UT_split_compile
3899 && compunit.cu_unit_type != DW_UT_skeleton)
77145576
JK
3900 {
3901 warn (_("CU at offset %s contains corrupt or "
3902 "unsupported unit type: %d.\n"),
3903 dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type);
3904 continue;
3905 }
3906
d493b283 3907 /* Process the abbrevs used by this compilation unit. */
341f9135 3908 if (compunit.cu_abbrev_offset >= abbrev_size)
ec4d4525
NC
3909 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
3910 (unsigned long) compunit.cu_abbrev_offset,
341f9135 3911 (unsigned long) abbrev_size);
b4eb7656 3912 /* PR 17531: file:4bcd9ce9. */
a0a3b04c
L
3913 else if ((abbrev_base + abbrev_size)
3914 > debug_displays [abbrev_sec].section.size)
3915 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
3916 (unsigned long) abbrev_base + abbrev_size,
3917 (unsigned long) debug_displays [abbrev_sec].section.size);
460c89ff 3918 else
bcd213b2 3919 {
76868f36
L
3920 list = find_abbrev_list_by_abbrev_offset (abbrev_base,
3921 compunit.cu_abbrev_offset);
bcd213b2
NC
3922 if (list == NULL)
3923 {
3924 unsigned char * next;
3925
76868f36
L
3926 list = new_abbrev_list (abbrev_base,
3927 compunit.cu_abbrev_offset);
bcd213b2
NC
3928 next = process_abbrev_set
3929 (((unsigned char *) debug_displays [abbrev_sec].section.start
3930 + abbrev_base + compunit.cu_abbrev_offset),
3931 ((unsigned char *) debug_displays [abbrev_sec].section.start
3932 + abbrev_base + abbrev_size),
3933 list);
3934 list->start_of_next_abbrevs = next;
3935 }
3936 }
19e6b90e
L
3937
3938 level = 0;
fd2f0033
TT
3939 last_level = level;
3940 saved_level = -1;
19e6b90e
L
3941 while (tags < start)
3942 {
19e6b90e 3943 unsigned long abbrev_number;
ec4d4525 3944 unsigned long die_offset;
19e6b90e
L
3945 abbrev_entry *entry;
3946 abbrev_attr *attr;
fd2f0033 3947 int do_printing = 1;
19e6b90e 3948
ec4d4525
NC
3949 die_offset = tags - section_begin;
3950
cd30bcef 3951 READ_ULEB (abbrev_number, tags, start);
19e6b90e 3952
eb7cc021
JK
3953 /* A null DIE marks the end of a list of siblings or it may also be
3954 a section padding. */
19e6b90e
L
3955 if (abbrev_number == 0)
3956 {
eb7cc021
JK
3957 /* Check if it can be a section padding for the last CU. */
3958 if (level == 0 && start == end)
3959 {
3960 unsigned char *chk;
3961
3962 for (chk = tags; chk < start; chk++)
3963 if (*chk != 0)
3964 break;
3965 if (chk == start)
3966 break;
3967 }
3968
4337774f
TT
3969 if (!do_loc && die_offset >= dwarf_start_die
3970 && (dwarf_cutoff_level == -1
3971 || level < dwarf_cutoff_level))
399c99f7
L
3972 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3973 level, die_offset);
3974
19e6b90e 3975 --level;
ec4d4525
NC
3976 if (level < 0)
3977 {
3978 static unsigned num_bogus_warns = 0;
3979
3980 if (num_bogus_warns < 3)
3981 {
4723351a
CC
3982 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3983 die_offset, section->name);
ec4d4525
NC
3984 num_bogus_warns ++;
3985 if (num_bogus_warns == 3)
3986 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3987 }
3988 }
fd2f0033 3989 if (dwarf_start_die != 0 && level < saved_level)
015dc7e1 3990 return true;
19e6b90e
L
3991 continue;
3992 }
3993
4b78141a 3994 if (!do_loc)
fd2f0033
TT
3995 {
3996 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
3997 do_printing = 0;
3998 else
3999 {
4000 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
4001 saved_level = level;
4002 do_printing = (dwarf_cutoff_level == -1
4003 || level < dwarf_cutoff_level);
4004 if (do_printing)
4005 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
4006 level, die_offset, abbrev_number);
4007 else if (dwarf_cutoff_level == -1
4008 || last_level < dwarf_cutoff_level)
4009 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
4010 last_level = level;
4011 }
4012 }
cecf136e 4013
19e6b90e
L
4014 /* Scan through the abbreviation list until we reach the
4015 correct entry. */
bcd213b2 4016 if (list == NULL)
19e6b90e
L
4017 continue;
4018
bcd213b2
NC
4019 for (entry = list->first_abbrev; entry != NULL; entry = entry->next)
4020 if (entry->number == abbrev_number)
4021 break;
4022
19e6b90e
L
4023 if (entry == NULL)
4024 {
fd2f0033 4025 if (!do_loc && do_printing)
4b78141a
NC
4026 {
4027 printf ("\n");
4028 fflush (stdout);
4029 }
f3853b34 4030 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
cc86f28f 4031 die_offset, abbrev_number);
015dc7e1 4032 return false;
19e6b90e
L
4033 }
4034
fd2f0033 4035 if (!do_loc && do_printing)
cc5914eb 4036 printf (" (%s)\n", get_TAG_name (entry->tag));
cecf136e 4037
19e6b90e
L
4038 switch (entry->tag)
4039 {
4040 default:
4041 need_base_address = 0;
4042 break;
4043 case DW_TAG_compile_unit:
d85bf2ba
NC
4044 need_base_address = 1;
4045 need_dwo_info = do_loc;
19e6b90e
L
4046 break;
4047 case DW_TAG_entry_point:
19e6b90e
L
4048 case DW_TAG_subprogram:
4049 need_base_address = 0;
4050 /* Assuming that there is no DW_AT_frame_base. */
4051 have_frame_base = 0;
4052 break;
4053 }
4054
9f272209
AO
4055 debug_info *debug_info_p =
4056 (debug_information && unit < alloc_num_debug_info_entries)
4057 ? debug_information + unit : NULL;
4058
4059 assert (!debug_info_p
4060 || (debug_info_p->num_loc_offsets
4061 == debug_info_p->num_loc_views));
4062
399c99f7
L
4063 for (attr = entry->first_attr;
4064 attr && attr->attribute;
4065 attr = attr->next)
4b78141a 4066 {
fd2f0033 4067 if (! do_loc && do_printing)
4b78141a 4068 /* Show the offset from where the tag was extracted. */
fd2f0033 4069 printf (" <%lx>", (unsigned long)(tags - section_begin));
4b78141a
NC
4070 tags = read_and_display_attr (attr->attribute,
4071 attr->form,
77145576 4072 attr->implicit_const,
ec1b0fbb 4073 section_begin,
341f9135 4074 tags,
f6f0e17b 4075 end,
341f9135 4076 cu_offset,
4b78141a
NC
4077 compunit.cu_pointer_size,
4078 offset_size,
4079 compunit.cu_version,
9f272209 4080 debug_info_p,
341f9135
CC
4081 do_loc || ! do_printing,
4082 section,
ec1b0fbb
NC
4083 this_set,
4084 level);
4b78141a 4085 }
cecf136e 4086
9f272209
AO
4087 /* If a locview attribute appears before a location one,
4088 make sure we don't associate it with an earlier
4089 loclist. */
4090 if (debug_info_p)
4091 switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views)
4092 {
4093 case 1:
4094 debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1;
4095 debug_info_p->num_loc_views++;
4096 assert (debug_info_p->num_loc_views
4097 == debug_info_p->num_loc_offsets);
4098 break;
4099
4100 case 0:
4101 break;
4102
4103 case -1:
4104 warn(_("DIE has locviews without loclist\n"));
4105 debug_info_p->num_loc_views--;
4106 break;
4107
4108 default:
4109 assert (0);
4110 }
4111
b4eb7656
AM
4112 if (entry->children)
4113 ++level;
4114 }
19e6b90e 4115 }
cecf136e 4116
19e6b90e
L
4117 /* Set num_debug_info_entries here so that it can be used to check if
4118 we need to process .debug_loc and .debug_ranges sections. */
4119 if ((do_loc || do_debug_loc || do_debug_ranges)
2b6f5997
CC
4120 && num_debug_info_entries == 0
4121 && ! do_types)
82b1b41b 4122 {
b4eb7656 4123 if (num_units > alloc_num_debug_info_entries)
82b1b41b
NC
4124 num_debug_info_entries = alloc_num_debug_info_entries;
4125 else
4126 num_debug_info_entries = num_units;
4127 }
cecf136e 4128
19e6b90e 4129 if (!do_loc)
467c65bc 4130 printf ("\n");
cecf136e 4131
015dc7e1 4132 return true;
19e6b90e
L
4133}
4134
4135/* Locate and scan the .debug_info section in the file and record the pointer
4136 sizes and offsets for the compilation units in it. Usually an executable
4137 will have just one pointer size, but this is not guaranteed, and so we try
4138 not to make any assumptions. Returns zero upon failure, or the number of
4139 compilation units upon success. */
4140
4141static unsigned int
4142load_debug_info (void * file)
4143{
1febe64d 4144 /* If we have already tried and failed to load the .debug_info
657d0d47 4145 section then do not bother to repeat the task. */
cc86f28f 4146 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
1febe64d
NC
4147 return 0;
4148
19e6b90e
L
4149 /* If we already have the information there is nothing else to do. */
4150 if (num_debug_info_entries > 0)
4151 return num_debug_info_entries;
4152
341f9135 4153 /* If this is a DWARF package file, load the CU and TU indexes. */
43a444f9 4154 (void) load_cu_tu_indexes (file);
341f9135 4155
dda8d76d 4156 if (load_debug_section_with_follow (info, file)
015dc7e1 4157 && process_debug_info (&debug_displays [info].section, file, abbrev, true, false))
19e6b90e 4158 return num_debug_info_entries;
82b1b41b 4159
dda8d76d 4160 if (load_debug_section_with_follow (info_dwo, file)
82b1b41b 4161 && process_debug_info (&debug_displays [info_dwo].section, file,
015dc7e1 4162 abbrev_dwo, true, false))
4723351a 4163 return num_debug_info_entries;
1febe64d 4164
cc86f28f 4165 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
1febe64d 4166 return 0;
19e6b90e
L
4167}
4168
b40bf0a2
NC
4169/* Read a DWARF .debug_line section header starting at DATA.
4170 Upon success returns an updated DATA pointer and the LINFO
4171 structure and the END_OF_SEQUENCE pointer will be filled in.
4172 Otherwise returns NULL. */
19e6b90e 4173
b40bf0a2
NC
4174static unsigned char *
4175read_debug_line_header (struct dwarf_section * section,
4176 unsigned char * data,
4177 unsigned char * end,
4178 DWARF2_Internal_LineInfo * linfo,
4179 unsigned char ** end_of_sequence)
4180{
4181 unsigned char *hdrptr;
b40bf0a2 4182 unsigned int initial_length_size;
19e6b90e 4183
b40bf0a2
NC
4184 /* Extract information from the Line Number Program Header.
4185 (section 6.2.4 in the Dwarf3 doc). */
6937bb54 4186 hdrptr = data;
19e6b90e 4187
b40bf0a2
NC
4188 /* Get and check the length of the block. */
4189 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
19e6b90e 4190
b40bf0a2 4191 if (linfo->li_length == 0xffffffff)
f41e4712
NC
4192 {
4193 /* This section is 64-bit DWARF 3. */
b40bf0a2 4194 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
77145576 4195 linfo->li_offset_size = 8;
f41e4712
NC
4196 initial_length_size = 12;
4197 }
4198 else
4199 {
77145576 4200 linfo->li_offset_size = 4;
f41e4712
NC
4201 initial_length_size = 4;
4202 }
19e6b90e 4203
b40bf0a2 4204 if (linfo->li_length + initial_length_size > section->size)
f41e4712 4205 {
8fcc61b4
NC
4206 /* If the length field has a relocation against it, then we should
4207 not complain if it is inaccurate (and probably negative). This
4208 happens in object files when the .debug_line section is actually
4209 comprised of several different .debug_line.* sections, (some of
4210 which may be removed by linker garbage collection), and a relocation
4211 is used to compute the correct length once that is done. */
77145576 4212 if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size))
b40bf0a2 4213 {
8fcc61b4 4214 linfo->li_length = (end - data) - initial_length_size;
b40bf0a2
NC
4215 }
4216 else
4217 {
8fcc61b4
NC
4218 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
4219 (long) linfo->li_length);
b40bf0a2
NC
4220 return NULL;
4221 }
f41e4712 4222 }
19e6b90e 4223
b40bf0a2
NC
4224 /* Get and check the version number. */
4225 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
4226
4227 if (linfo->li_version != 2
4228 && linfo->li_version != 3
77145576
JK
4229 && linfo->li_version != 4
4230 && linfo->li_version != 5)
f41e4712 4231 {
77145576
JK
4232 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4233 "is currently supported.\n"));
b40bf0a2 4234 return NULL;
f41e4712 4235 }
19e6b90e 4236
77145576
JK
4237 if (linfo->li_version >= 5)
4238 {
5496f3c6 4239 SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end);
77145576 4240
5496f3c6
NC
4241 SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end);
4242 if (linfo->li_segment_size != 0)
77145576
JK
4243 {
4244 warn (_("The %s section contains "
4245 "unsupported segment selector size: %d.\n"),
5496f3c6
NC
4246 section->name, linfo->li_segment_size);
4247 return NULL;
77145576
JK
4248 }
4249 }
4250
4251 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr,
4252 linfo->li_offset_size, end);
b40bf0a2 4253 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
0c588247 4254
b40bf0a2 4255 if (linfo->li_version >= 4)
f41e4712 4256 {
b40bf0a2 4257 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
0c588247 4258
b40bf0a2 4259 if (linfo->li_max_ops_per_insn == 0)
f41e4712
NC
4260 {
4261 warn (_("Invalid maximum operations per insn.\n"));
b40bf0a2 4262 return NULL;
a233b20c 4263 }
f41e4712
NC
4264 }
4265 else
b40bf0a2 4266 linfo->li_max_ops_per_insn = 1;
0c588247 4267
b40bf0a2 4268 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
65879393 4269 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
b40bf0a2
NC
4270 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
4271 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
19e6b90e 4272
b40bf0a2 4273 * end_of_sequence = data + linfo->li_length + initial_length_size;
b4eb7656 4274 /* PR 17512: file:002-117414-0.004. */
6937bb54
NC
4275 if (* end_of_sequence > end)
4276 {
4c219c2e
AM
4277 warn (_("Line length %s extends beyond end of section\n"),
4278 dwarf_vmatoa ("u", linfo->li_length));
6937bb54
NC
4279 * end_of_sequence = end;
4280 return NULL;
4281 }
4282
b40bf0a2
NC
4283 return hdrptr;
4284}
19e6b90e 4285
77145576 4286static unsigned char *
015dc7e1
AM
4287display_formatted_table (unsigned char *data,
4288 unsigned char *start,
4289 unsigned char *end,
4290 const DWARF2_Internal_LineInfo *linfo,
4291 struct dwarf_section *section,
4292 bool is_dir)
77145576
JK
4293{
4294 unsigned char *format_start, format_count, *format, formati;
4295 dwarf_vma data_count, datai;
cd30bcef 4296 unsigned int namepass, last_entry = 0;
5496f3c6 4297 const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table");
521d4b19 4298
77145576 4299 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
546cb2d8
NC
4300 if (do_checks && format_count > 5)
4301 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4302 table_name, format_count);
4303
77145576
JK
4304 format_start = data;
4305 for (formati = 0; formati < format_count; formati++)
4306 {
cd30bcef
AM
4307 SKIP_ULEB (data, end);
4308 SKIP_ULEB (data, end);
77145576
JK
4309 if (data == end)
4310 {
5496f3c6 4311 warn (_("%s: Corrupt format description entry\n"), table_name);
77145576
JK
4312 return data;
4313 }
4314 }
4315
cd30bcef 4316 READ_ULEB (data_count, data, end);
546cb2d8 4317 if (data_count == 0)
77145576 4318 {
546cb2d8 4319 printf (_("\n The %s is empty.\n"), table_name);
77145576
JK
4320 return data;
4321 }
546cb2d8 4322 else if (data == end)
77145576 4323 {
546cb2d8
NC
4324 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
4325 table_name, dwarf_vmatoa ("x", data_count));
77145576
JK
4326 return data;
4327 }
546cb2d8 4328
5496f3c6
NC
4329 else if (format_count == 0)
4330 {
4331 warn (_("%s: format count is zero, but the table is not empty\n"),
4332 table_name);
4333 return end;
4334 }
77145576 4335
5496f3c6
NC
4336 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
4337 table_name, (long) (data - start), dwarf_vmatoa ("u", data_count),
4338 format_count);
77145576
JK
4339
4340 printf (_(" Entry"));
521d4b19 4341 /* Delay displaying name as the last entry for better screen layout. */
77145576
JK
4342 for (namepass = 0; namepass < 2; namepass++)
4343 {
4344 format = format_start;
4345 for (formati = 0; formati < format_count; formati++)
4346 {
4347 dwarf_vma content_type;
4348
cd30bcef 4349 READ_ULEB (content_type, format, end);
77145576
JK
4350 if ((content_type == DW_LNCT_path) == (namepass == 1))
4351 switch (content_type)
4352 {
4353 case DW_LNCT_path:
4354 printf (_("\tName"));
4355 break;
4356 case DW_LNCT_directory_index:
4357 printf (_("\tDir"));
4358 break;
4359 case DW_LNCT_timestamp:
4360 printf (_("\tTime"));
4361 break;
4362 case DW_LNCT_size:
4363 printf (_("\tSize"));
4364 break;
4365 case DW_LNCT_MD5:
5496f3c6 4366 printf (_("\tMD5\t\t\t"));
77145576
JK
4367 break;
4368 default:
4369 printf (_("\t(Unknown format content type %s)"),
4370 dwarf_vmatoa ("u", content_type));
4371 }
cd30bcef 4372 SKIP_ULEB (format, end);
77145576
JK
4373 }
4374 }
4375 putchar ('\n');
4376
4377 for (datai = 0; datai < data_count; datai++)
4378 {
4379 unsigned char *datapass = data;
4380
4381 printf (" %d", last_entry++);
521d4b19 4382 /* Delay displaying name as the last entry for better screen layout. */
77145576
JK
4383 for (namepass = 0; namepass < 2; namepass++)
4384 {
4385 format = format_start;
4386 data = datapass;
4387 for (formati = 0; formati < format_count; formati++)
4388 {
4389 dwarf_vma content_type, form;
4390
cd30bcef
AM
4391 READ_ULEB (content_type, format, end);
4392 READ_ULEB (form, format, end);
4393 data = read_and_display_attr_value (0, form, 0, start, data, end,
4394 0, 0, linfo->li_offset_size,
77145576
JK
4395 linfo->li_version, NULL,
4396 ((content_type == DW_LNCT_path) != (namepass == 1)),
ec1b0fbb 4397 section, NULL, '\t', -1);
77145576
JK
4398 }
4399 }
5496f3c6
NC
4400
4401 if (data == end && (datai < data_count - 1))
77145576 4402 {
5496f3c6 4403 warn (_("\n%s: Corrupt entries list\n"), table_name);
77145576
JK
4404 return data;
4405 }
4406 putchar ('\n');
4407 }
4408 return data;
4409}
4410
e38332c2
NC
4411static int
4412display_debug_sup (struct dwarf_section * section,
4413 void * file ATTRIBUTE_UNUSED)
4414{
4415 unsigned char * start = section->start;
4416 unsigned char * end = section->start + section->size;
4417 unsigned int version;
4418 char is_supplementary;
4419 const unsigned char * sup_filename;
4420 size_t sup_filename_len;
4421 unsigned int num_read;
4422 int status;
4423 dwarf_vma checksum_len;
4424
4425
015dc7e1 4426 introduce (section, true);
e38332c2
NC
4427 if (section->size < 4)
4428 {
4429 error (_("corrupt .debug_sup section: size is too small\n"));
4430 return 0;
4431 }
4432
4433 /* Read the data. */
4434 SAFE_BYTE_GET_AND_INC (version, start, 2, end);
4435 if (version < 5)
4436 warn (_("corrupt .debug_sup section: version < 5"));
4437
4438 SAFE_BYTE_GET_AND_INC (is_supplementary, start, 1, end);
4439 if (is_supplementary != 0 && is_supplementary != 1)
4440 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4441
4442 sup_filename = start;
4443 if (is_supplementary && sup_filename[0] != 0)
4444 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4445
4446 sup_filename_len = strnlen ((const char *) start, end - start);
4447 if (sup_filename_len == (size_t) (end - start))
4448 {
4449 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4450 return 0;
4451 }
4452 start += sup_filename_len + 1;
4453
015dc7e1 4454 checksum_len = read_leb128 (start, end, false /* unsigned */, & num_read, & status);
e38332c2
NC
4455 if (status)
4456 {
4457 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4458 checksum_len = 0;
4459 }
4460 start += num_read;
4461 if (checksum_len > (dwarf_vma) (end - start))
4462 {
4463 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4464 checksum_len = end - start;
4465 }
4466 else if (checksum_len < (dwarf_vma) (end - start))
4467 {
4468 warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"),
4469 (long) ((end - start) - checksum_len));
4470 }
4471
4472 printf (_(" Version: %u\n"), version);
4473 printf (_(" Is Supp: %u\n"), is_supplementary);
4474 printf (_(" Filename: %s\n"), sup_filename);
4475 printf (_(" Checksum Len: %lu\n"), (long) checksum_len);
4476 if (checksum_len > 0)
4477 {
4478 printf (_(" Checksum: "));
4479 while (checksum_len--)
4480 printf ("0x%x ", * start++ );
4481 printf ("\n");
4482 }
4483 return 1;
4484}
4485
b40bf0a2 4486static int
dda8d76d
NC
4487display_debug_lines_raw (struct dwarf_section * section,
4488 unsigned char * data,
4489 unsigned char * end,
4490 void * file)
b40bf0a2
NC
4491{
4492 unsigned char *start = section->start;
ba8826a8 4493 int verbose_view = 0;
19e6b90e 4494
015dc7e1 4495 introduce (section, true);
19e6b90e 4496
b40bf0a2
NC
4497 while (data < end)
4498 {
4499 static DWARF2_Internal_LineInfo saved_linfo;
4500 DWARF2_Internal_LineInfo linfo;
4501 unsigned char *standard_opcodes;
4502 unsigned char *end_of_sequence;
fe59e83d 4503 int i;
19e6b90e 4504
24d127aa 4505 if (startswith (section->name, ".debug_line.")
4925cdd7
NC
4506 /* Note: the following does not apply to .debug_line.dwo sections.
4507 These are full debug_line sections. */
4508 && strcmp (section->name, ".debug_line.dwo") != 0)
19e6b90e 4509 {
b40bf0a2
NC
4510 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4511 section containing just the Line Number Statements. They are
4512 created by the assembler and intended to be used alongside gcc's
4513 -ffunction-sections command line option. When the linker's
4514 garbage collection decides to discard a .text.<foo> section it
4515 can then also discard the line number information in .debug_line.<foo>.
4516
4925cdd7 4517 Since the section is a fragment it does not have the details
b40bf0a2 4518 needed to fill out a LineInfo structure, so instead we use the
4925cdd7 4519 details from the last full debug_line section that we processed. */
b40bf0a2
NC
4520 end_of_sequence = end;
4521 standard_opcodes = NULL;
4522 linfo = saved_linfo;
058037d3
NC
4523 /* PR 17531: file: 0522b371. */
4524 if (linfo.li_line_range == 0)
4525 {
1306a742 4526 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
058037d3
NC
4527 return 0;
4528 }
b40bf0a2 4529 reset_state_machine (linfo.li_default_is_stmt);
19e6b90e 4530 }
19e6b90e
L
4531 else
4532 {
b40bf0a2 4533 unsigned char * hdrptr;
19e6b90e 4534
b40bf0a2
NC
4535 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
4536 & end_of_sequence)) == NULL)
4537 return 0;
19e6b90e 4538
b40bf0a2
NC
4539 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
4540 printf (_(" Length: %ld\n"), (long) linfo.li_length);
4541 printf (_(" DWARF Version: %d\n"), linfo.li_version);
5496f3c6
NC
4542 if (linfo.li_version >= 5)
4543 {
4544 printf (_(" Address size (bytes): %d\n"), linfo.li_address_size);
4545 printf (_(" Segment selector (bytes): %d\n"), linfo.li_segment_size);
4546 }
77ef8654 4547 printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length);
b40bf0a2
NC
4548 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
4549 if (linfo.li_version >= 4)
4550 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
4551 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
4552 printf (_(" Line Base: %d\n"), linfo.li_line_base);
4553 printf (_(" Line Range: %d\n"), linfo.li_line_range);
4554 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
19e6b90e 4555
0a9d414a
NC
4556 /* PR 17512: file: 1665-6428-0.004. */
4557 if (linfo.li_line_range == 0)
4558 {
4559 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4560 linfo.li_line_range = 1;
4561 }
77ef8654 4562
b40bf0a2 4563 reset_state_machine (linfo.li_default_is_stmt);
19e6b90e 4564
b40bf0a2
NC
4565 /* Display the contents of the Opcodes table. */
4566 standard_opcodes = hdrptr;
19e6b90e 4567
6937bb54
NC
4568 /* PR 17512: file: 002-417945-0.004. */
4569 if (standard_opcodes + linfo.li_opcode_base >= end)
4570 {
4571 warn (_("Line Base extends beyond end of section\n"));
4572 return 0;
4573 }
4574
b40bf0a2 4575 printf (_("\n Opcodes:\n"));
19e6b90e 4576
b40bf0a2 4577 for (i = 1; i < linfo.li_opcode_base; i++)
d3a49aa8
AM
4578 printf (ngettext (" Opcode %d has %d arg\n",
4579 " Opcode %d has %d args\n",
4580 standard_opcodes[i - 1]),
4581 i, standard_opcodes[i - 1]);
19e6b90e 4582
b40bf0a2
NC
4583 /* Display the contents of the Directory table. */
4584 data = standard_opcodes + linfo.li_opcode_base - 1;
19e6b90e 4585
77145576 4586 if (linfo.li_version >= 5)
b40bf0a2 4587 {
dda8d76d 4588 load_debug_section_with_follow (line_str, file);
19e6b90e 4589
77145576 4590 data = display_formatted_table (data, start, end, &linfo, section,
015dc7e1 4591 true);
77145576 4592 data = display_formatted_table (data, start, end, &linfo, section,
015dc7e1 4593 false);
77145576
JK
4594 }
4595 else
4596 {
4597 if (*data == 0)
4598 printf (_("\n The Directory Table is empty.\n"));
4599 else
a233b20c 4600 {
77145576 4601 unsigned int last_dir_entry = 0;
6937bb54 4602
77145576
JK
4603 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4604 (long)(data - start));
19e6b90e 4605
77145576
JK
4606 while (data < end && *data != 0)
4607 {
4608 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
19e6b90e 4609
77145576
JK
4610 data += strnlen ((char *) data, end - data) + 1;
4611 }
19e6b90e 4612
77145576
JK
4613 /* PR 17512: file: 002-132094-0.004. */
4614 if (data >= end - 1)
4615 break;
4616 }
19e6b90e 4617
77145576
JK
4618 /* Skip the NUL at the end of the table. */
4619 data++;
19e6b90e 4620
77145576
JK
4621 /* Display the contents of the File Name table. */
4622 if (*data == 0)
4623 printf (_("\n The File Name Table is empty.\n"));
4624 else
4625 {
4626 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4627 (long)(data - start));
4628 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
19e6b90e 4629
77145576 4630 while (data < end && *data != 0)
b40bf0a2 4631 {
77145576 4632 unsigned char *name;
cd30bcef 4633 dwarf_vma val;
77145576
JK
4634
4635 printf (" %d\t", ++state_machine_regs.last_file_entry);
4636 name = data;
4637 data += strnlen ((char *) data, end - data) + 1;
4638
cd30bcef
AM
4639 READ_ULEB (val, data, end);
4640 printf ("%s\t", dwarf_vmatoa ("u", val));
4641 READ_ULEB (val, data, end);
4642 printf ("%s\t", dwarf_vmatoa ("u", val));
4643 READ_ULEB (val, data, end);
4644 printf ("%s\t", dwarf_vmatoa ("u", val));
77145576
JK
4645 printf ("%.*s\n", (int)(end - name), name);
4646
4647 if (data == end)
4648 {
4649 warn (_("Corrupt file name table entry\n"));
4650 break;
4651 }
b40bf0a2 4652 }
a233b20c 4653 }
77145576
JK
4654
4655 /* Skip the NUL at the end of the table. */
4656 data++;
b40bf0a2 4657 }
19e6b90e 4658
b40bf0a2
NC
4659 putchar ('\n');
4660 saved_linfo = linfo;
4661 }
19e6b90e 4662
b40bf0a2
NC
4663 /* Now display the statements. */
4664 if (data >= end_of_sequence)
4665 printf (_(" No Line Number Statements.\n"));
4666 else
4667 {
4668 printf (_(" Line Number Statements:\n"));
19e6b90e 4669
b40bf0a2
NC
4670 while (data < end_of_sequence)
4671 {
4672 unsigned char op_code;
4673 dwarf_signed_vma adv;
4674 dwarf_vma uladv;
19e6b90e 4675
fe59e83d
CC
4676 printf (" [0x%08lx]", (long)(data - start));
4677
b40bf0a2 4678 op_code = *data++;
19e6b90e 4679
b40bf0a2 4680 if (op_code >= linfo.li_opcode_base)
19e6b90e 4681 {
b40bf0a2
NC
4682 op_code -= linfo.li_opcode_base;
4683 uladv = (op_code / linfo.li_line_range);
4684 if (linfo.li_max_ops_per_insn == 1)
4685 {
4686 uladv *= linfo.li_min_insn_length;
4687 state_machine_regs.address += uladv;
ba8826a8
AO
4688 if (uladv)
4689 state_machine_regs.view = 0;
b40bf0a2 4690 printf (_(" Special opcode %d: "
ba8826a8 4691 "advance Address by %s to 0x%s%s"),
b40bf0a2 4692 op_code, dwarf_vmatoa ("u", uladv),
ba8826a8
AO
4693 dwarf_vmatoa ("x", state_machine_regs.address),
4694 verbose_view && uladv
4695 ? _(" (reset view)") : "");
b40bf0a2
NC
4696 }
4697 else
4698 {
ba8826a8
AO
4699 unsigned addrdelta
4700 = ((state_machine_regs.op_index + uladv)
b40bf0a2
NC
4701 / linfo.li_max_ops_per_insn)
4702 * linfo.li_min_insn_length;
ba8826a8
AO
4703
4704 state_machine_regs.address += addrdelta;
b40bf0a2
NC
4705 state_machine_regs.op_index
4706 = (state_machine_regs.op_index + uladv)
4707 % linfo.li_max_ops_per_insn;
ba8826a8
AO
4708 if (addrdelta)
4709 state_machine_regs.view = 0;
b40bf0a2 4710 printf (_(" Special opcode %d: "
ba8826a8 4711 "advance Address by %s to 0x%s[%d]%s"),
b40bf0a2
NC
4712 op_code, dwarf_vmatoa ("u", uladv),
4713 dwarf_vmatoa ("x", state_machine_regs.address),
ba8826a8
AO
4714 state_machine_regs.op_index,
4715 verbose_view && addrdelta
4716 ? _(" (reset view)") : "");
b40bf0a2
NC
4717 }
4718 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
4719 state_machine_regs.line += adv;
ba8826a8 4720 printf (_(" and Line by %s to %d"),
b40bf0a2 4721 dwarf_vmatoa ("d", adv), state_machine_regs.line);
ba8826a8
AO
4722 if (verbose_view || state_machine_regs.view)
4723 printf (_(" (view %u)\n"), state_machine_regs.view);
4724 else
4725 putchar ('\n');
4726 state_machine_regs.view++;
19e6b90e 4727 }
cd30bcef
AM
4728 else
4729 switch (op_code)
4730 {
4731 case DW_LNS_extended_op:
4732 data += process_extended_line_op (data,
4733 linfo.li_default_is_stmt,
4734 end);
4735 break;
4736
4737 case DW_LNS_copy:
4738 printf (_(" Copy"));
4739 if (verbose_view || state_machine_regs.view)
4740 printf (_(" (view %u)\n"), state_machine_regs.view);
4741 else
4742 putchar ('\n');
4743 state_machine_regs.view++;
4744 break;
4745
4746 case DW_LNS_advance_pc:
4747 READ_ULEB (uladv, data, end);
4748 if (linfo.li_max_ops_per_insn == 1)
4749 {
4750 uladv *= linfo.li_min_insn_length;
4751 state_machine_regs.address += uladv;
4752 if (uladv)
4753 state_machine_regs.view = 0;
4754 printf (_(" Advance PC by %s to 0x%s%s\n"),
4755 dwarf_vmatoa ("u", uladv),
4756 dwarf_vmatoa ("x", state_machine_regs.address),
4757 verbose_view && uladv
4758 ? _(" (reset view)") : "");
4759 }
4760 else
4761 {
4762 unsigned addrdelta
4763 = ((state_machine_regs.op_index + uladv)
4764 / linfo.li_max_ops_per_insn)
4765 * linfo.li_min_insn_length;
4766 state_machine_regs.address
4767 += addrdelta;
4768 state_machine_regs.op_index
4769 = (state_machine_regs.op_index + uladv)
4770 % linfo.li_max_ops_per_insn;
4771 if (addrdelta)
4772 state_machine_regs.view = 0;
4773 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4774 dwarf_vmatoa ("u", uladv),
4775 dwarf_vmatoa ("x", state_machine_regs.address),
4776 state_machine_regs.op_index,
4777 verbose_view && addrdelta
4778 ? _(" (reset view)") : "");
4779 }
4780 break;
4781
4782 case DW_LNS_advance_line:
4783 READ_SLEB (adv, data, end);
4784 state_machine_regs.line += adv;
4785 printf (_(" Advance Line by %s to %d\n"),
4786 dwarf_vmatoa ("d", adv),
4787 state_machine_regs.line);
4788 break;
4789
4790 case DW_LNS_set_file:
4791 READ_ULEB (uladv, data, end);
4792 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4793 dwarf_vmatoa ("u", uladv));
4794 state_machine_regs.file = uladv;
4795 break;
4796
4797 case DW_LNS_set_column:
4798 READ_ULEB (uladv, data, end);
4799 printf (_(" Set column to %s\n"),
4800 dwarf_vmatoa ("u", uladv));
4801 state_machine_regs.column = uladv;
4802 break;
4803
4804 case DW_LNS_negate_stmt:
4805 adv = state_machine_regs.is_stmt;
4806 adv = ! adv;
4807 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
4808 state_machine_regs.is_stmt = adv;
4809 break;
4810
4811 case DW_LNS_set_basic_block:
4812 printf (_(" Set basic block\n"));
4813 state_machine_regs.basic_block = 1;
4814 break;
4815
4816 case DW_LNS_const_add_pc:
4817 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
4818 if (linfo.li_max_ops_per_insn)
4819 {
4820 uladv *= linfo.li_min_insn_length;
4821 state_machine_regs.address += uladv;
4822 if (uladv)
4823 state_machine_regs.view = 0;
4824 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4825 dwarf_vmatoa ("u", uladv),
4826 dwarf_vmatoa ("x", state_machine_regs.address),
4827 verbose_view && uladv
4828 ? _(" (reset view)") : "");
4829 }
4830 else
4831 {
4832 unsigned addrdelta
4833 = ((state_machine_regs.op_index + uladv)
4834 / linfo.li_max_ops_per_insn)
4835 * linfo.li_min_insn_length;
4836 state_machine_regs.address
4837 += addrdelta;
4838 state_machine_regs.op_index
4839 = (state_machine_regs.op_index + uladv)
4840 % linfo.li_max_ops_per_insn;
4841 if (addrdelta)
4842 state_machine_regs.view = 0;
4843 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4844 dwarf_vmatoa ("u", uladv),
4845 dwarf_vmatoa ("x", state_machine_regs.address),
4846 state_machine_regs.op_index,
4847 verbose_view && addrdelta
4848 ? _(" (reset view)") : "");
4849 }
4850 break;
4851
4852 case DW_LNS_fixed_advance_pc:
4853 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
4854 state_machine_regs.address += uladv;
4855 state_machine_regs.op_index = 0;
4856 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4857 dwarf_vmatoa ("u", uladv),
4858 dwarf_vmatoa ("x", state_machine_regs.address));
4859 /* Do NOT reset view. */
4860 break;
4861
4862 case DW_LNS_set_prologue_end:
4863 printf (_(" Set prologue_end to true\n"));
4864 break;
4865
4866 case DW_LNS_set_epilogue_begin:
4867 printf (_(" Set epilogue_begin to true\n"));
4868 break;
4869
4870 case DW_LNS_set_isa:
4871 READ_ULEB (uladv, data, end);
4872 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
4873 break;
4874
4875 default:
4876 printf (_(" Unknown opcode %d with operands: "), op_code);
4877
4878 if (standard_opcodes != NULL)
4879 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
4880 {
4881 READ_ULEB (uladv, data, end);
4882 printf ("0x%s%s", dwarf_vmatoa ("x", uladv),
4883 i == 1 ? "" : ", ");
4884 }
4885 putchar ('\n');
4886 break;
4887 }
19e6b90e 4888 }
b40bf0a2 4889 putchar ('\n');
19e6b90e 4890 }
19e6b90e
L
4891 }
4892
4893 return 1;
4894}
4895
a262ae96
NC
4896typedef struct
4897{
467c65bc
NC
4898 unsigned char *name;
4899 unsigned int directory_index;
4900 unsigned int modification_date;
4901 unsigned int length;
a262ae96
NC
4902} File_Entry;
4903
4904/* Output a decoded representation of the .debug_line section. */
4905
4906static int
dda8d76d 4907display_debug_lines_decoded (struct dwarf_section * section,
ec1b0fbb 4908 unsigned char * start,
dda8d76d
NC
4909 unsigned char * data,
4910 unsigned char * end,
4911 void * fileptr)
a262ae96 4912{
b40bf0a2
NC
4913 static DWARF2_Internal_LineInfo saved_linfo;
4914
015dc7e1 4915 introduce (section, false);
a262ae96
NC
4916
4917 while (data < end)
4918 {
4919 /* This loop amounts to one iteration per compilation unit. */
91d6fa6a 4920 DWARF2_Internal_LineInfo linfo;
a262ae96
NC
4921 unsigned char *standard_opcodes;
4922 unsigned char *end_of_sequence;
a262ae96
NC
4923 int i;
4924 File_Entry *file_table = NULL;
143a3db0 4925 unsigned int n_files = 0;
a262ae96 4926 unsigned char **directory_table = NULL;
77145576 4927 dwarf_vma n_directories = 0;
a262ae96 4928
24d127aa 4929 if (startswith (section->name, ".debug_line.")
4925cdd7
NC
4930 /* Note: the following does not apply to .debug_line.dwo sections.
4931 These are full debug_line sections. */
4932 && strcmp (section->name, ".debug_line.dwo") != 0)
b4eb7656 4933 {
4925cdd7 4934 /* See comment in display_debug_lines_raw(). */
b40bf0a2
NC
4935 end_of_sequence = end;
4936 standard_opcodes = NULL;
4937 linfo = saved_linfo;
058037d3
NC
4938 /* PR 17531: file: 0522b371. */
4939 if (linfo.li_line_range == 0)
4940 {
1306a742 4941 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
058037d3
NC
4942 return 0;
4943 }
b40bf0a2 4944 reset_state_machine (linfo.li_default_is_stmt);
b4eb7656 4945 }
a262ae96 4946 else
b4eb7656 4947 {
b40bf0a2 4948 unsigned char *hdrptr;
a262ae96 4949
b40bf0a2
NC
4950 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
4951 & end_of_sequence)) == NULL)
a233b20c 4952 return 0;
0c588247 4953
058037d3
NC
4954 /* PR 17531: file: 0522b371. */
4955 if (linfo.li_line_range == 0)
4956 {
4957 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4958 linfo.li_line_range = 1;
4959 }
b40bf0a2 4960 reset_state_machine (linfo.li_default_is_stmt);
a262ae96 4961
b40bf0a2
NC
4962 /* Save a pointer to the contents of the Opcodes table. */
4963 standard_opcodes = hdrptr;
a262ae96 4964
b40bf0a2
NC
4965 /* Traverse the Directory table just to count entries. */
4966 data = standard_opcodes + linfo.li_opcode_base - 1;
d8024a91
NC
4967 /* PR 20440 */
4968 if (data >= end)
4969 {
4970 warn (_("opcode base of %d extends beyond end of section\n"),
4971 linfo.li_opcode_base);
4972 return 0;
4973 }
4974
77145576 4975 if (linfo.li_version >= 5)
b40bf0a2 4976 {
77145576
JK
4977 unsigned char *format_start, format_count, *format;
4978 dwarf_vma formati, entryi;
a262ae96 4979
dda8d76d 4980 load_debug_section_with_follow (line_str, fileptr);
77145576
JK
4981
4982 /* Skip directories format. */
4983 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
546cb2d8
NC
4984 if (do_checks && format_count > 1)
4985 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4986 format_count);
77145576
JK
4987 format_start = data;
4988 for (formati = 0; formati < format_count; formati++)
b40bf0a2 4989 {
cd30bcef
AM
4990 SKIP_ULEB (data, end);
4991 SKIP_ULEB (data, end);
b40bf0a2 4992 }
a262ae96 4993
cd30bcef 4994 READ_ULEB (n_directories, data, end);
77145576 4995 if (data == end)
d8024a91 4996 {
77145576 4997 warn (_("Corrupt directories list\n"));
d8024a91
NC
4998 break;
4999 }
5000
070b775f
NC
5001 if (n_directories == 0)
5002 directory_table = NULL;
5003 else
5004 directory_table = (unsigned char **)
5005 xmalloc (n_directories * sizeof (unsigned char *));
a262ae96 5006
77145576 5007 for (entryi = 0; entryi < n_directories; entryi++)
b40bf0a2 5008 {
77145576 5009 unsigned char **pathp = &directory_table[entryi];
a262ae96 5010
77145576
JK
5011 format = format_start;
5012 for (formati = 0; formati < format_count; formati++)
5013 {
5014 dwarf_vma content_type, form;
5015 dwarf_vma uvalue;
5016
cd30bcef
AM
5017 READ_ULEB (content_type, format, end);
5018 READ_ULEB (form, format, end);
77145576
JK
5019 if (data == end)
5020 {
5021 warn (_("Corrupt directories list\n"));
5022 break;
5023 }
5024 switch (content_type)
5025 {
5026 case DW_LNCT_path:
5027 switch (form)
5028 {
5029 case DW_FORM_string:
5030 *pathp = data;
5031 break;
5032 case DW_FORM_line_strp:
5033 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
5034 end);
5035 /* Remove const by the cast. */
5036 *pathp = (unsigned char *)
5037 fetch_indirect_line_string (uvalue);
5038 break;
5039 }
5040 break;
5041 }
cd30bcef
AM
5042 data = read_and_display_attr_value (0, form, 0, start,
5043 data, end, 0, 0,
77145576
JK
5044 linfo.li_offset_size,
5045 linfo.li_version,
5046 NULL, 1, section,
ec1b0fbb 5047 NULL, '\t', -1);
77145576
JK
5048 }
5049 if (data == end)
5050 {
5051 warn (_("Corrupt directories list\n"));
5052 break;
5053 }
5054 }
a262ae96 5055
77145576
JK
5056 /* Skip files format. */
5057 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
546cb2d8
NC
5058 if (do_checks && format_count > 5)
5059 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5060 format_count);
77145576
JK
5061 format_start = data;
5062 for (formati = 0; formati < format_count; formati++)
b40bf0a2 5063 {
cd30bcef
AM
5064 SKIP_ULEB (data, end);
5065 SKIP_ULEB (data, end);
b40bf0a2 5066 }
a262ae96 5067
cd30bcef 5068 READ_ULEB (n_files, data, end);
070b775f 5069 if (data == end && n_files > 0)
d8024a91 5070 {
77145576 5071 warn (_("Corrupt file name list\n"));
d8024a91
NC
5072 break;
5073 }
5074
070b775f
NC
5075 if (n_files == 0)
5076 file_table = NULL;
5077 else
5078 file_table = (File_Entry *) xcalloc (1, n_files
5079 * sizeof (File_Entry));
a262ae96 5080
77145576 5081 for (entryi = 0; entryi < n_files; entryi++)
b40bf0a2 5082 {
77145576 5083 File_Entry *file = &file_table[entryi];
a262ae96 5084
77145576
JK
5085 format = format_start;
5086 for (formati = 0; formati < format_count; formati++)
5087 {
5088 dwarf_vma content_type, form;
5089 dwarf_vma uvalue;
cd30bcef 5090 unsigned char *tmp;
77145576 5091
cd30bcef
AM
5092 READ_ULEB (content_type, format, end);
5093 READ_ULEB (form, format, end);
77145576
JK
5094 if (data == end)
5095 {
5096 warn (_("Corrupt file name list\n"));
5097 break;
5098 }
5099 switch (content_type)
5100 {
5101 case DW_LNCT_path:
5102 switch (form)
5103 {
5104 case DW_FORM_string:
5105 file->name = data;
5106 break;
5107 case DW_FORM_line_strp:
5108 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
5109 end);
5110 /* Remove const by the cast. */
5111 file->name = (unsigned char *)
5112 fetch_indirect_line_string (uvalue);
5113 break;
5114 }
5115 break;
5116 case DW_LNCT_directory_index:
5117 switch (form)
5118 {
5119 case DW_FORM_data1:
5120 SAFE_BYTE_GET (file->directory_index, data, 1,
5121 end);
5122 break;
5123 case DW_FORM_data2:
5124 SAFE_BYTE_GET (file->directory_index, data, 2,
5125 end);
5126 break;
5127 case DW_FORM_udata:
cd30bcef
AM
5128 tmp = data;
5129 READ_ULEB (file->directory_index, tmp, end);
77145576
JK
5130 break;
5131 }
5132 break;
5133 }
cd30bcef
AM
5134 data = read_and_display_attr_value (0, form, 0, start,
5135 data, end, 0, 0,
77145576
JK
5136 linfo.li_offset_size,
5137 linfo.li_version,
5138 NULL, 1, section,
ec1b0fbb 5139 NULL, '\t', -1);
77145576
JK
5140 }
5141 if (data == end)
5142 {
5143 warn (_("Corrupt file name list\n"));
5144 break;
5145 }
5146 }
5147 }
5148 else
5149 {
5150 if (*data != 0)
b40bf0a2 5151 {
77145576
JK
5152 unsigned char *ptr_directory_table = data;
5153
5154 while (data < end && *data != 0)
5155 {
5156 data += strnlen ((char *) data, end - data) + 1;
5157 n_directories++;
5158 }
5159
5160 /* PR 20440 */
5161 if (data >= end)
5162 {
5163 warn (_("directory table ends unexpectedly\n"));
5164 n_directories = 0;
5165 break;
5166 }
5167
5168 /* Go through the directory table again to save the directories. */
5169 directory_table = (unsigned char **)
5170 xmalloc (n_directories * sizeof (unsigned char *));
5171
5172 i = 0;
5173 while (*ptr_directory_table != 0)
5174 {
5175 directory_table[i] = ptr_directory_table;
5176 ptr_directory_table += strnlen ((char *) ptr_directory_table,
5177 ptr_directory_table - end) + 1;
5178 i++;
5179 }
b40bf0a2 5180 }
77145576
JK
5181 /* Skip the NUL at the end of the table. */
5182 data++;
5183
5184 /* Traverse the File Name table just to count the entries. */
5185 if (data < end && *data != 0)
b40bf0a2 5186 {
77145576
JK
5187 unsigned char *ptr_file_name_table = data;
5188
5189 while (data < end && *data != 0)
db9537d2 5190 {
cd30bcef
AM
5191 /* Skip Name, directory index, last modification
5192 time and length of file. */
77145576 5193 data += strnlen ((char *) data, end - data) + 1;
cd30bcef
AM
5194 SKIP_ULEB (data, end);
5195 SKIP_ULEB (data, end);
5196 SKIP_ULEB (data, end);
77145576 5197 n_files++;
db9537d2 5198 }
a262ae96 5199
77145576
JK
5200 if (data >= end)
5201 {
5202 warn (_("file table ends unexpectedly\n"));
5203 n_files = 0;
5204 break;
5205 }
5206
5207 /* Go through the file table again to save the strings. */
5208 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
0c588247 5209
77145576
JK
5210 i = 0;
5211 while (*ptr_file_name_table != 0)
5212 {
77145576
JK
5213 file_table[i].name = ptr_file_name_table;
5214 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
5215 end - ptr_file_name_table) + 1;
5216
5217 /* We are not interested in directory, time or size. */
cd30bcef
AM
5218 READ_ULEB (file_table[i].directory_index,
5219 ptr_file_name_table, end);
5220 READ_ULEB (file_table[i].modification_date,
5221 ptr_file_name_table, end);
5222 READ_ULEB (file_table[i].length,
5223 ptr_file_name_table, end);
77145576
JK
5224 i++;
5225 }
5226 i = 0;
b40bf0a2 5227 }
77145576
JK
5228
5229 /* Skip the NUL at the end of the table. */
5230 data++;
b40bf0a2 5231 }
cc5914eb 5232
77145576 5233 /* Print the Compilation Unit's name and a header. */
f082820d 5234 if (file_table == NULL)
070b775f 5235 printf (_("CU: No directory table\n"));
f082820d
AM
5236 else if (directory_table == NULL)
5237 printf (_("CU: %s:\n"), file_table[0].name);
77145576
JK
5238 else
5239 {
5240 unsigned int ix = file_table[0].directory_index;
5241 const char *directory;
5242
5243 if (ix == 0)
5244 directory = ".";
5245 /* PR 20439 */
5246 else if (n_directories == 0)
5247 directory = _("<unknown>");
5248 else if (ix > n_directories)
5249 {
5250 warn (_("directory index %u > number of directories %s\n"),
5251 ix, dwarf_vmatoa ("u", n_directories));
5252 directory = _("<corrupt>");
5253 }
5254 else
5255 directory = (char *) directory_table[ix - 1];
5256
5257 if (do_wide || strlen (directory) < 76)
5258 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
5259 else
5260 printf ("%s:\n", file_table[0].name);
77145576 5261 }
a262ae96 5262
070b775f
NC
5263 if (n_files > 0)
5264 printf (_("File name Line number Starting address View Stmt\n"));
5265 else
5266 printf (_("CU: Empty file name table\n"));
b40bf0a2
NC
5267 saved_linfo = linfo;
5268 }
a262ae96
NC
5269
5270 /* This loop iterates through the Dwarf Line Number Program. */
5271 while (data < end_of_sequence)
b4eb7656 5272 {
a262ae96 5273 unsigned char op_code;
ba8826a8 5274 int xop;
b4eb7656
AM
5275 int adv;
5276 unsigned long int uladv;
b4eb7656 5277 int is_special_opcode = 0;
a262ae96 5278
b4eb7656 5279 op_code = *data++;
ba8826a8 5280 xop = op_code;
a262ae96 5281
b4eb7656 5282 if (op_code >= linfo.li_opcode_base)
a262ae96 5283 {
91d6fa6a 5284 op_code -= linfo.li_opcode_base;
a233b20c
JJ
5285 uladv = (op_code / linfo.li_line_range);
5286 if (linfo.li_max_ops_per_insn == 1)
5287 {
5288 uladv *= linfo.li_min_insn_length;
5289 state_machine_regs.address += uladv;
ba8826a8
AO
5290 if (uladv)
5291 state_machine_regs.view = 0;
a233b20c
JJ
5292 }
5293 else
5294 {
ba8826a8
AO
5295 unsigned addrdelta
5296 = ((state_machine_regs.op_index + uladv)
5297 / linfo.li_max_ops_per_insn)
b40bf0a2 5298 * linfo.li_min_insn_length;
ba8826a8
AO
5299 state_machine_regs.address
5300 += addrdelta;
a233b20c
JJ
5301 state_machine_regs.op_index
5302 = (state_machine_regs.op_index + uladv)
b40bf0a2 5303 % linfo.li_max_ops_per_insn;
ba8826a8
AO
5304 if (addrdelta)
5305 state_machine_regs.view = 0;
a233b20c 5306 }
a262ae96 5307
b4eb7656
AM
5308 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
5309 state_machine_regs.line += adv;
5310 is_special_opcode = 1;
ba8826a8 5311 /* Increment view after printing this row. */
b4eb7656 5312 }
cd30bcef
AM
5313 else
5314 switch (op_code)
5315 {
5316 case DW_LNS_extended_op:
5317 {
5318 unsigned int ext_op_code_len;
5319 unsigned char ext_op_code;
5320 unsigned char *op_code_end;
5321 unsigned char *op_code_data = data;
5322
5323 READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence);
5324 op_code_end = op_code_data + ext_op_code_len;
5325 if (ext_op_code_len == 0 || op_code_end > end_of_sequence)
5326 {
5327 warn (_("Badly formed extended line op encountered!\n"));
5328 break;
5329 }
5330 ext_op_code = *op_code_data++;
5331 xop = ext_op_code;
5332 xop = -xop;
5333
5334 switch (ext_op_code)
5335 {
5336 case DW_LNE_end_sequence:
5337 /* Reset stuff after printing this row. */
5338 break;
5339 case DW_LNE_set_address:
5340 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
5341 op_code_data,
5342 op_code_end - op_code_data,
5343 op_code_end);
5344 state_machine_regs.op_index = 0;
5345 state_machine_regs.view = 0;
5346 break;
5347 case DW_LNE_define_file:
5348 file_table = (File_Entry *) xrealloc
5349 (file_table, (n_files + 1) * sizeof (File_Entry));
5350
5351 ++state_machine_regs.last_file_entry;
5352 /* Source file name. */
5353 file_table[n_files].name = op_code_data;
5354 op_code_data += strlen ((char *) op_code_data) + 1;
5355 /* Directory index. */
5356 READ_ULEB (file_table[n_files].directory_index,
5357 op_code_data, op_code_end);
5358 /* Last modification time. */
5359 READ_ULEB (file_table[n_files].modification_date,
5360 op_code_data, op_code_end);
5361 /* File length. */
5362 READ_ULEB (file_table[n_files].length,
5363 op_code_data, op_code_end);
5364 n_files++;
5365 break;
5366
5367 case DW_LNE_set_discriminator:
5368 case DW_LNE_HP_set_sequence:
5369 /* Simply ignored. */
5370 break;
5371
5372 default:
5373 printf (_("UNKNOWN (%u): length %ld\n"),
27653fba 5374 ext_op_code, (long int) (op_code_data - data));
cd30bcef
AM
5375 break;
5376 }
5377 data = op_code_end;
5378 break;
5379 }
5380 case DW_LNS_copy:
5381 /* Increment view after printing this row. */
5382 break;
5383
5384 case DW_LNS_advance_pc:
5385 READ_ULEB (uladv, data, end);
5386 if (linfo.li_max_ops_per_insn == 1)
5387 {
5388 uladv *= linfo.li_min_insn_length;
5389 state_machine_regs.address += uladv;
5390 if (uladv)
5391 state_machine_regs.view = 0;
5392 }
5393 else
5394 {
5395 unsigned addrdelta
5396 = ((state_machine_regs.op_index + uladv)
5397 / linfo.li_max_ops_per_insn)
5398 * linfo.li_min_insn_length;
5399 state_machine_regs.address
5400 += addrdelta;
5401 state_machine_regs.op_index
5402 = (state_machine_regs.op_index + uladv)
5403 % linfo.li_max_ops_per_insn;
5404 if (addrdelta)
5405 state_machine_regs.view = 0;
5406 }
5407 break;
5408
5409 case DW_LNS_advance_line:
5410 READ_SLEB (adv, data, end);
5411 state_machine_regs.line += adv;
5412 break;
5413
5414 case DW_LNS_set_file:
5415 READ_ULEB (uladv, data, end);
5416 state_machine_regs.file = uladv;
5417
5418 {
5419 unsigned file = state_machine_regs.file - 1;
5420 unsigned dir;
5421
5422 if (file_table == NULL || n_files == 0)
5423 printf (_("\n [Use file table entry %d]\n"), file);
5424 /* PR 20439 */
5425 else if (file >= n_files)
5426 {
5427 warn (_("file index %u > number of files %u\n"), file + 1, n_files);
5428 printf (_("\n <over large file table index %u>"), file);
5429 }
5430 else if ((dir = file_table[file].directory_index) == 0)
5431 /* If directory index is 0, that means current directory. */
5432 printf ("\n./%s:[++]\n", file_table[file].name);
5433 else if (directory_table == NULL || n_directories == 0)
5434 printf (_("\n [Use file %s in directory table entry %d]\n"),
5435 file_table[file].name, dir);
5436 /* PR 20439 */
5437 else if (dir > n_directories)
5438 {
5439 warn (_("directory index %u > number of directories %s\n"),
5440 dir, dwarf_vmatoa ("u", n_directories));
5441 printf (_("\n <over large directory table entry %u>\n"), dir);
5442 }
5443 else
5444 printf ("\n%s/%s:\n",
5445 /* The directory index starts counting at 1. */
5446 directory_table[dir - 1], file_table[file].name);
5447 }
5448 break;
5449
5450 case DW_LNS_set_column:
5451 READ_ULEB (uladv, data, end);
5452 state_machine_regs.column = uladv;
5453 break;
5454
5455 case DW_LNS_negate_stmt:
5456 adv = state_machine_regs.is_stmt;
5457 adv = ! adv;
5458 state_machine_regs.is_stmt = adv;
5459 break;
5460
5461 case DW_LNS_set_basic_block:
5462 state_machine_regs.basic_block = 1;
5463 break;
5464
5465 case DW_LNS_const_add_pc:
5466 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
5467 if (linfo.li_max_ops_per_insn == 1)
5468 {
5469 uladv *= linfo.li_min_insn_length;
5470 state_machine_regs.address += uladv;
5471 if (uladv)
5472 state_machine_regs.view = 0;
5473 }
5474 else
5475 {
5476 unsigned addrdelta
5477 = ((state_machine_regs.op_index + uladv)
5478 / linfo.li_max_ops_per_insn)
5479 * linfo.li_min_insn_length;
5480 state_machine_regs.address
5481 += addrdelta;
5482 state_machine_regs.op_index
5483 = (state_machine_regs.op_index + uladv)
5484 % linfo.li_max_ops_per_insn;
5485 if (addrdelta)
5486 state_machine_regs.view = 0;
5487 }
5488 break;
5489
5490 case DW_LNS_fixed_advance_pc:
5491 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
5492 state_machine_regs.address += uladv;
5493 state_machine_regs.op_index = 0;
5494 /* Do NOT reset view. */
5495 break;
5496
5497 case DW_LNS_set_prologue_end:
5498 break;
5499
5500 case DW_LNS_set_epilogue_begin:
5501 break;
5502
5503 case DW_LNS_set_isa:
5504 READ_ULEB (uladv, data, end);
5505 printf (_(" Set ISA to %lu\n"), uladv);
5506 break;
5507
5508 default:
5509 printf (_(" Unknown opcode %d with operands: "), op_code);
5510
5511 if (standard_opcodes != NULL)
5512 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
5513 {
5514 dwarf_vma val;
5515
5516 READ_ULEB (val, data, end);
5517 printf ("0x%s%s", dwarf_vmatoa ("x", val),
5518 i == 1 ? "" : ", ");
5519 }
5520 putchar ('\n');
5521 break;
5522 }
a262ae96 5523
b4eb7656
AM
5524 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5525 to the DWARF address/line matrix. */
ba8826a8
AO
5526 if ((is_special_opcode) || (xop == -DW_LNE_end_sequence)
5527 || (xop == DW_LNS_copy))
b4eb7656
AM
5528 {
5529 const unsigned int MAX_FILENAME_LENGTH = 35;
5530 char *fileName;
5531 char *newFileName = NULL;
5532 size_t fileNameLength;
b40bf0a2
NC
5533
5534 if (file_table)
db9537d2
NC
5535 {
5536 unsigned indx = state_machine_regs.file - 1;
5537 /* PR 20439 */
5538 if (indx >= n_files)
5539 {
5540 warn (_("corrupt file index %u encountered\n"), indx);
5541 fileName = _("<corrupt>");
5542 }
5543 else
5544 fileName = (char *) file_table[indx].name;
5545 }
b40bf0a2 5546 else
db9537d2 5547 fileName = _("<unknown>");
b40bf0a2
NC
5548
5549 fileNameLength = strlen (fileName);
a262ae96 5550
b4eb7656
AM
5551 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
5552 {
5553 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
5554 /* Truncate file name */
5555 strncpy (newFileName,
5556 fileName + fileNameLength - MAX_FILENAME_LENGTH,
5557 MAX_FILENAME_LENGTH + 1);
e1104d08
NC
5558 /* FIXME: This is to pacify gcc-10 which can warn that the
5559 strncpy above might leave a non-NUL terminated string
5560 in newFileName. It won't, but gcc's analysis doesn't
5561 quite go far enough to discover this. */
5562 newFileName[MAX_FILENAME_LENGTH] = 0;
b4eb7656
AM
5563 }
5564 else
5565 {
5566 newFileName = (char *) xmalloc (fileNameLength + 1);
5567 strncpy (newFileName, fileName, fileNameLength + 1);
5568 }
5569
af2b3186
TV
5570 /* A row with end_seq set to true has a meaningful address, but
5571 the other information in the same row is not significant.
5572 In such a row, print line as "-", and don't print
5573 view/is_stmt. */
b4eb7656
AM
5574 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
5575 {
a233b20c 5576 if (linfo.li_max_ops_per_insn == 1)
af2b3186
TV
5577 {
5578 if (xop == -DW_LNE_end_sequence)
5579 printf ("%-35s %11s %#18" DWARF_VMA_FMT "x",
5580 newFileName, "-",
5581 state_machine_regs.address);
5582 else
5583 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x",
5584 newFileName, state_machine_regs.line,
5585 state_machine_regs.address);
5586 }
a233b20c 5587 else
af2b3186
TV
5588 {
5589 if (xop == -DW_LNE_end_sequence)
5590 printf ("%-35s %11s %#18" DWARF_VMA_FMT "x[%d]",
5591 newFileName, "-",
5592 state_machine_regs.address,
5593 state_machine_regs.op_index);
5594 else
5595 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]",
5596 newFileName, state_machine_regs.line,
5597 state_machine_regs.address,
5598 state_machine_regs.op_index);
5599 }
b4eb7656
AM
5600 }
5601 else
5602 {
a233b20c 5603 if (linfo.li_max_ops_per_insn == 1)
af2b3186
TV
5604 {
5605 if (xop == -DW_LNE_end_sequence)
5606 printf ("%s %11s %#18" DWARF_VMA_FMT "x",
5607 newFileName, "-",
5608 state_machine_regs.address);
5609 else
5610 printf ("%s %11d %#18" DWARF_VMA_FMT "x",
5611 newFileName, state_machine_regs.line,
5612 state_machine_regs.address);
5613 }
a233b20c 5614 else
af2b3186
TV
5615 {
5616 if (xop == -DW_LNE_end_sequence)
5617 printf ("%s %11s %#18" DWARF_VMA_FMT "x[%d]",
5618 newFileName, "-",
5619 state_machine_regs.address,
5620 state_machine_regs.op_index);
5621 else
5622 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]",
5623 newFileName, state_machine_regs.line,
5624 state_machine_regs.address,
5625 state_machine_regs.op_index);
5626 }
b4eb7656 5627 }
a262ae96 5628
af2b3186
TV
5629 if (xop != -DW_LNE_end_sequence)
5630 {
5631 if (state_machine_regs.view)
5632 printf (" %6u", state_machine_regs.view);
5633 else
5634 printf (" ");
17f6ade2 5635
af2b3186
TV
5636 if (state_machine_regs.is_stmt)
5637 printf (" x");
5638 }
17f6ade2
JD
5639
5640 putchar ('\n');
ba8826a8
AO
5641 state_machine_regs.view++;
5642
5643 if (xop == -DW_LNE_end_sequence)
5644 {
5645 reset_state_machine (linfo.li_default_is_stmt);
5646 putchar ('\n');
5647 }
a262ae96 5648
b4eb7656
AM
5649 free (newFileName);
5650 }
5651 }
b40bf0a2
NC
5652
5653 if (file_table)
5654 {
5655 free (file_table);
5656 file_table = NULL;
5657 n_files = 0;
5658 }
5659
5660 if (directory_table)
5661 {
5662 free (directory_table);
5663 directory_table = NULL;
5664 n_directories = 0;
5665 }
5666
a262ae96
NC
5667 putchar ('\n');
5668 }
5669
5670 return 1;
5671}
5672
5673static int
77145576 5674display_debug_lines (struct dwarf_section *section, void *file)
a262ae96
NC
5675{
5676 unsigned char *data = section->start;
5677 unsigned char *end = data + section->size;
4cb93e3b
TG
5678 int retValRaw = 1;
5679 int retValDecoded = 1;
a262ae96 5680
008f4c78
NC
5681 if (do_debug_lines == 0)
5682 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
5683
4cb93e3b 5684 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
77145576 5685 retValRaw = display_debug_lines_raw (section, data, end, file);
a262ae96 5686
4cb93e3b 5687 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
ec1b0fbb 5688 retValDecoded = display_debug_lines_decoded (section, data, data, end, file);
a262ae96 5689
4cb93e3b 5690 if (!retValRaw || !retValDecoded)
a262ae96
NC
5691 return 0;
5692
5693 return 1;
5694}
5695
6e3d6dc1
NC
5696static debug_info *
5697find_debug_info_for_offset (unsigned long offset)
5698{
5699 unsigned int i;
5700
5701 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
5702 return NULL;
5703
5704 for (i = 0; i < num_debug_info_entries; i++)
5705 if (debug_information[i].cu_offset == offset)
5706 return debug_information + i;
5707
5708 return NULL;
5709}
5710
459d52c8
DE
5711static const char *
5712get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
5713{
5714 /* See gdb/gdb-index.h. */
5715 static const char * const kinds[] =
5716 {
5717 N_ ("no info"),
5718 N_ ("type"),
5719 N_ ("variable"),
5720 N_ ("function"),
5721 N_ ("other"),
5722 N_ ("unused5"),
5723 N_ ("unused6"),
5724 N_ ("unused7")
5725 };
5726
5727 return _ (kinds[kind]);
5728}
5729
19e6b90e 5730static int
459d52c8
DE
5731display_debug_pubnames_worker (struct dwarf_section *section,
5732 void *file ATTRIBUTE_UNUSED,
5733 int is_gnu)
19e6b90e 5734{
91d6fa6a 5735 DWARF2_Internal_PubNames names;
19e6b90e
L
5736 unsigned char *start = section->start;
5737 unsigned char *end = start + section->size;
5738
6e3d6dc1
NC
5739 /* It does not matter if this load fails,
5740 we test for that later on. */
5741 load_debug_info (file);
5742
015dc7e1 5743 introduce (section, false);
19e6b90e
L
5744
5745 while (start < end)
5746 {
5747 unsigned char *data;
e98fdf1a 5748 unsigned long sec_off;
bf5117e3 5749 unsigned int offset_size, initial_length_size;
19e6b90e 5750
e98fdf1a 5751 SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end);
91d6fa6a 5752 if (names.pn_length == 0xffffffff)
19e6b90e 5753 {
e98fdf1a 5754 SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end);
19e6b90e
L
5755 offset_size = 8;
5756 initial_length_size = 12;
5757 }
5758 else
5759 {
5760 offset_size = 4;
5761 initial_length_size = 4;
5762 }
5763
e98fdf1a
AM
5764 sec_off = start - section->start;
5765 if (sec_off + names.pn_length < sec_off
5766 || sec_off + names.pn_length > section->size)
5767 {
5768 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5769 section->name,
5770 sec_off - initial_length_size,
5771 dwarf_vmatoa ("x", names.pn_length));
5772 break;
5773 }
5774
5775 data = start;
5776 start += names.pn_length;
5777
0c588247
NC
5778 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
5779 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
6e3d6dc1
NC
5780
5781 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
5782 && num_debug_info_entries > 0
91d6fa6a 5783 && find_debug_info_for_offset (names.pn_offset) == NULL)
6e3d6dc1 5784 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
47704ddf 5785 (unsigned long) names.pn_offset, section->name);
cecf136e 5786
0c588247 5787 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
19e6b90e 5788
058037d3
NC
5789 printf (_(" Length: %ld\n"),
5790 (long) names.pn_length);
5791 printf (_(" Version: %d\n"),
5792 names.pn_version);
5793 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5794 (unsigned long) names.pn_offset);
5795 printf (_(" Size of area in .debug_info section: %ld\n"),
5796 (long) names.pn_size);
19e6b90e 5797
91d6fa6a 5798 if (names.pn_version != 2 && names.pn_version != 3)
19e6b90e
L
5799 {
5800 static int warned = 0;
5801
5802 if (! warned)
5803 {
5804 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5805 warned = 1;
5806 }
5807
5808 continue;
5809 }
5810
459d52c8
DE
5811 if (is_gnu)
5812 printf (_("\n Offset Kind Name\n"));
5813 else
5814 printf (_("\n Offset\tName\n"));
19e6b90e 5815
e98fdf1a 5816 while (1)
19e6b90e 5817 {
f41e4712 5818 bfd_size_type maxprint;
e98fdf1a 5819 dwarf_vma offset;
f41e4712 5820
0c588247 5821 SAFE_BYTE_GET (offset, data, offset_size, end);
19e6b90e 5822
e98fdf1a
AM
5823 if (offset == 0)
5824 break;
b4eb7656 5825
e98fdf1a
AM
5826 data += offset_size;
5827 if (data >= end)
5828 break;
5829 maxprint = (end - data) - 1;
f41e4712 5830
e98fdf1a
AM
5831 if (is_gnu)
5832 {
5833 unsigned int kind_data;
5834 gdb_index_symbol_kind kind;
5835 const char *kind_name;
5836 int is_static;
5837
5838 SAFE_BYTE_GET (kind_data, data, 1, end);
5839 data++;
5840 maxprint --;
5841 /* GCC computes the kind as the upper byte in the CU index
5842 word, and then right shifts it by the CU index size.
5843 Left shift KIND to where the gdb-index.h accessor macros
5844 can use it. */
5845 kind_data <<= GDB_INDEX_CU_BITSIZE;
5846 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
5847 kind_name = get_gdb_index_symbol_kind_name (kind);
5848 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
5849 printf (" %-6lx %s,%-10s %.*s\n",
5850 (unsigned long) offset, is_static ? _("s") : _("g"),
5851 kind_name, (int) maxprint, data);
19e6b90e 5852 }
e98fdf1a
AM
5853 else
5854 printf (" %-6lx\t%.*s\n",
5855 (unsigned long) offset, (int) maxprint, data);
5856
5857 data += strnlen ((char *) data, maxprint) + 1;
5858 if (data >= end)
5859 break;
19e6b90e 5860 }
19e6b90e
L
5861 }
5862
5863 printf ("\n");
5864 return 1;
5865}
5866
459d52c8
DE
5867static int
5868display_debug_pubnames (struct dwarf_section *section, void *file)
5869{
5870 return display_debug_pubnames_worker (section, file, 0);
5871}
5872
5873static int
5874display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
5875{
5876 return display_debug_pubnames_worker (section, file, 1);
5877}
5878
19e6b90e
L
5879static int
5880display_debug_macinfo (struct dwarf_section *section,
5881 void *file ATTRIBUTE_UNUSED)
5882{
5883 unsigned char *start = section->start;
5884 unsigned char *end = start + section->size;
5885 unsigned char *curr = start;
19e6b90e
L
5886 enum dwarf_macinfo_record_type op;
5887
015dc7e1 5888 introduce (section, false);
19e6b90e
L
5889
5890 while (curr < end)
5891 {
5892 unsigned int lineno;
0c588247 5893 const unsigned char *string;
19e6b90e 5894
3f5e193b 5895 op = (enum dwarf_macinfo_record_type) *curr;
19e6b90e
L
5896 curr++;
5897
5898 switch (op)
5899 {
5900 case DW_MACINFO_start_file:
5901 {
5902 unsigned int filenum;
5903
cd30bcef
AM
5904 READ_ULEB (lineno, curr, end);
5905 READ_ULEB (filenum, curr, end);
19e6b90e
L
5906 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5907 lineno, filenum);
5908 }
5909 break;
5910
5911 case DW_MACINFO_end_file:
5912 printf (_(" DW_MACINFO_end_file\n"));
5913 break;
5914
5915 case DW_MACINFO_define:
cd30bcef 5916 READ_ULEB (lineno, curr, end);
0c588247
NC
5917 string = curr;
5918 curr += strnlen ((char *) string, end - string) + 1;
19e6b90e
L
5919 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
5920 lineno, string);
5921 break;
5922
5923 case DW_MACINFO_undef:
cd30bcef 5924 READ_ULEB (lineno, curr, end);
0c588247
NC
5925 string = curr;
5926 curr += strnlen ((char *) string, end - string) + 1;
19e6b90e
L
5927 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
5928 lineno, string);
5929 break;
5930
5931 case DW_MACINFO_vendor_ext:
5932 {
5933 unsigned int constant;
5934
cd30bcef 5935 READ_ULEB (constant, curr, end);
0c588247
NC
5936 string = curr;
5937 curr += strnlen ((char *) string, end - string) + 1;
19e6b90e
L
5938 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
5939 constant, string);
5940 }
5941 break;
5942 }
5943 }
5944
5945 return 1;
5946}
5947
4ccf1e31
JJ
5948/* Given LINE_OFFSET into the .debug_line section, attempt to return
5949 filename and dirname corresponding to file name table entry with index
5950 FILEIDX. Return NULL on failure. */
5951
5952static unsigned char *
f6f0e17b
NC
5953get_line_filename_and_dirname (dwarf_vma line_offset,
5954 dwarf_vma fileidx,
4ccf1e31
JJ
5955 unsigned char **dir_name)
5956{
5957 struct dwarf_section *section = &debug_displays [line].section;
5958 unsigned char *hdrptr, *dirtable, *file_name;
5959 unsigned int offset_size, initial_length_size;
cd30bcef 5960 unsigned int version, opcode_base;
4ccf1e31 5961 dwarf_vma length, diridx;
f6f0e17b 5962 const unsigned char * end;
4ccf1e31
JJ
5963
5964 *dir_name = NULL;
5965 if (section->start == NULL
5966 || line_offset >= section->size
5967 || fileidx == 0)
5968 return NULL;
5969
5970 hdrptr = section->start + line_offset;
f6f0e17b 5971 end = section->start + section->size;
0c588247
NC
5972
5973 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
4ccf1e31
JJ
5974 if (length == 0xffffffff)
5975 {
5976 /* This section is 64-bit DWARF 3. */
0c588247 5977 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
4ccf1e31
JJ
5978 offset_size = 8;
5979 initial_length_size = 12;
5980 }
5981 else
5982 {
5983 offset_size = 4;
5984 initial_length_size = 4;
5985 }
e98fdf1a
AM
5986 if (length + initial_length_size < length
5987 || length + initial_length_size > section->size)
4ccf1e31 5988 return NULL;
0c588247
NC
5989
5990 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
4ccf1e31
JJ
5991 if (version != 2 && version != 3 && version != 4)
5992 return NULL;
5993 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
5994 if (version >= 4)
5995 hdrptr++; /* Skip max_ops_per_insn. */
5996 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
0c588247
NC
5997
5998 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
4ccf1e31
JJ
5999 if (opcode_base == 0)
6000 return NULL;
0c588247 6001
4ccf1e31 6002 hdrptr += opcode_base - 1;
5c1c468d
NC
6003 if (hdrptr >= end)
6004 return NULL;
6005
4ccf1e31
JJ
6006 dirtable = hdrptr;
6007 /* Skip over dirname table. */
6008 while (*hdrptr != '\0')
5c1c468d
NC
6009 {
6010 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
6011 if (hdrptr >= end)
6012 return NULL;
6013 }
4ccf1e31 6014 hdrptr++; /* Skip the NUL at the end of the table. */
5c1c468d 6015
4ccf1e31 6016 /* Now skip over preceding filename table entries. */
5c1c468d 6017 for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--)
4ccf1e31 6018 {
0c588247 6019 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
cd30bcef
AM
6020 SKIP_ULEB (hdrptr, end);
6021 SKIP_ULEB (hdrptr, end);
6022 SKIP_ULEB (hdrptr, end);
4ccf1e31 6023 }
5c1c468d 6024 if (hdrptr >= end || *hdrptr == '\0')
4ccf1e31 6025 return NULL;
5c1c468d 6026
4ccf1e31 6027 file_name = hdrptr;
0c588247 6028 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
5c1c468d
NC
6029 if (hdrptr >= end)
6030 return NULL;
cd30bcef 6031 READ_ULEB (diridx, hdrptr, end);
4ccf1e31
JJ
6032 if (diridx == 0)
6033 return file_name;
5c1c468d 6034 for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--)
0c588247 6035 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
5c1c468d 6036 if (dirtable >= end || *dirtable == '\0')
4ccf1e31
JJ
6037 return NULL;
6038 *dir_name = dirtable;
6039 return file_name;
6040}
6041
6042static int
6043display_debug_macro (struct dwarf_section *section,
6044 void *file)
6045{
6046 unsigned char *start = section->start;
6047 unsigned char *end = start + section->size;
6048 unsigned char *curr = start;
6049 unsigned char *extended_op_buf[256];
015dc7e1 6050 bool is_dwo = false;
d296b736
NC
6051 const char *suffix = strrchr (section->name, '.');
6052
6053 if (suffix && strcmp (suffix, ".dwo") == 0)
015dc7e1 6054 is_dwo = true;
4ccf1e31 6055
dda8d76d
NC
6056 load_debug_section_with_follow (str, file);
6057 load_debug_section_with_follow (line, file);
e4b7104b 6058 load_debug_section_with_follow (str_index, file);
d296b736 6059
015dc7e1 6060 introduce (section, false);
4ccf1e31
JJ
6061
6062 while (curr < end)
6063 {
6064 unsigned int lineno, version, flags;
d296b736 6065 unsigned int offset_size;
0c588247 6066 const unsigned char *string;
4ccf1e31
JJ
6067 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
6068 unsigned char **extended_ops = NULL;
6069
0c588247 6070 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
7a7e1061 6071 if (version != 4 && version != 5)
4ccf1e31 6072 {
0e12f6c8
TV
6073 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6074 section->name, version);
4ccf1e31
JJ
6075 return 0;
6076 }
6077
0c588247 6078 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
d296b736 6079 offset_size = (flags & 1) ? 8 : 4;
4ccf1e31
JJ
6080 printf (_(" Offset: 0x%lx\n"),
6081 (unsigned long) sec_offset);
6082 printf (_(" Version: %d\n"), version);
6083 printf (_(" Offset size: %d\n"), offset_size);
6084 if (flags & 2)
6085 {
0c588247 6086 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
4ccf1e31
JJ
6087 printf (_(" Offset into .debug_line: 0x%lx\n"),
6088 (unsigned long) line_offset);
6089 }
6090 if (flags & 4)
6091 {
0c588247 6092 unsigned int i, count, op;
4ccf1e31 6093 dwarf_vma nargs, n;
0c588247
NC
6094
6095 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
bf5117e3 6096
4ccf1e31
JJ
6097 memset (extended_op_buf, 0, sizeof (extended_op_buf));
6098 extended_ops = extended_op_buf;
6099 if (count)
6100 {
6101 printf (_(" Extension opcode arguments:\n"));
6102 for (i = 0; i < count; i++)
6103 {
0c588247 6104 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4ccf1e31 6105 extended_ops[op] = curr;
cd30bcef 6106 READ_ULEB (nargs, curr, end);
4ccf1e31 6107 if (nargs == 0)
7a7e1061 6108 printf (_(" DW_MACRO_%02x has no arguments\n"), op);
4ccf1e31
JJ
6109 else
6110 {
7a7e1061 6111 printf (_(" DW_MACRO_%02x arguments: "), op);
4ccf1e31
JJ
6112 for (n = 0; n < nargs; n++)
6113 {
0c588247
NC
6114 unsigned int form;
6115
6116 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
4ccf1e31
JJ
6117 printf ("%s%s", get_FORM_name (form),
6118 n == nargs - 1 ? "\n" : ", ");
6119 switch (form)
6120 {
6121 case DW_FORM_data1:
6122 case DW_FORM_data2:
6123 case DW_FORM_data4:
6124 case DW_FORM_data8:
6125 case DW_FORM_sdata:
6126 case DW_FORM_udata:
6127 case DW_FORM_block:
6128 case DW_FORM_block1:
6129 case DW_FORM_block2:
6130 case DW_FORM_block4:
6131 case DW_FORM_flag:
6132 case DW_FORM_string:
6133 case DW_FORM_strp:
6134 case DW_FORM_sec_offset:
6135 break;
6136 default:
6137 error (_("Invalid extension opcode form %s\n"),
6138 get_FORM_name (form));
6139 return 0;
6140 }
6141 }
6142 }
6143 }
6144 }
6145 }
6146 printf ("\n");
6147
6148 while (1)
6149 {
6150 unsigned int op;
6151
6152 if (curr >= end)
6153 {
6154 error (_(".debug_macro section not zero terminated\n"));
6155 return 0;
6156 }
6157
0c588247 6158 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4ccf1e31
JJ
6159 if (op == 0)
6160 break;
6161
6162 switch (op)
6163 {
e4b7104b
NC
6164 case DW_MACRO_define:
6165 READ_ULEB (lineno, curr, end);
6166 string = curr;
6167 curr += strnlen ((char *) string, end - string) + 1;
6168 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
6169 lineno, string);
6170 break;
6171
6172 case DW_MACRO_undef:
6173 READ_ULEB (lineno, curr, end);
6174 string = curr;
6175 curr += strnlen ((char *) string, end - string) + 1;
6176 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
6177 lineno, string);
6178 break;
6179
7a7e1061 6180 case DW_MACRO_start_file:
4ccf1e31
JJ
6181 {
6182 unsigned int filenum;
6183 unsigned char *file_name = NULL, *dir_name = NULL;
6184
cd30bcef
AM
6185 READ_ULEB (lineno, curr, end);
6186 READ_ULEB (filenum, curr, end);
4ccf1e31
JJ
6187
6188 if ((flags & 2) == 0)
7a7e1061 6189 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
4ccf1e31
JJ
6190 else
6191 file_name
6192 = get_line_filename_and_dirname (line_offset, filenum,
6193 &dir_name);
6194 if (file_name == NULL)
7a7e1061 6195 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
4ccf1e31
JJ
6196 lineno, filenum);
6197 else
7a7e1061 6198 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4ccf1e31
JJ
6199 lineno, filenum,
6200 dir_name != NULL ? (const char *) dir_name : "",
6201 dir_name != NULL ? "/" : "", file_name);
6202 }
6203 break;
6204
7a7e1061
JK
6205 case DW_MACRO_end_file:
6206 printf (_(" DW_MACRO_end_file\n"));
4ccf1e31
JJ
6207 break;
6208
7a7e1061 6209 case DW_MACRO_define_strp:
cd30bcef 6210 READ_ULEB (lineno, curr, end);
d296b736
NC
6211 if (version == 4 && is_dwo)
6212 READ_ULEB (offset, curr, end);
6213 else
6214 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4ccf1e31 6215 string = fetch_indirect_string (offset);
7a7e1061 6216 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
4ccf1e31
JJ
6217 lineno, string);
6218 break;
6219
7a7e1061 6220 case DW_MACRO_undef_strp:
cd30bcef 6221 READ_ULEB (lineno, curr, end);
d296b736
NC
6222 if (version == 4 && is_dwo)
6223 READ_ULEB (offset, curr, end);
6224 else
6225 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4ccf1e31 6226 string = fetch_indirect_string (offset);
7a7e1061 6227 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
4ccf1e31
JJ
6228 lineno, string);
6229 break;
6230
7a7e1061 6231 case DW_MACRO_import:
0c588247 6232 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
7a7e1061 6233 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
4ccf1e31
JJ
6234 (unsigned long) offset);
6235 break;
6236
7a7e1061 6237 case DW_MACRO_define_sup:
cd30bcef 6238 READ_ULEB (lineno, curr, end);
0c588247 6239 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
7a7e1061 6240 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
a081f3cd
JJ
6241 lineno, (unsigned long) offset);
6242 break;
6243
7a7e1061 6244 case DW_MACRO_undef_sup:
cd30bcef 6245 READ_ULEB (lineno, curr, end);
0c588247 6246 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
7a7e1061 6247 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
a081f3cd
JJ
6248 lineno, (unsigned long) offset);
6249 break;
6250
7a7e1061 6251 case DW_MACRO_import_sup:
0c588247 6252 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
7a7e1061 6253 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
a081f3cd
JJ
6254 (unsigned long) offset);
6255 break;
6256
e4b7104b
NC
6257 case DW_MACRO_define_strx:
6258 case DW_MACRO_undef_strx:
6259 READ_ULEB (lineno, curr, end);
6260 READ_ULEB (offset, curr, end);
6261 string = (const unsigned char *)
015dc7e1 6262 fetch_indexed_string (offset, NULL, offset_size, false);
e4b7104b
NC
6263 if (op == DW_MACRO_define_strx)
6264 printf (" DW_MACRO_define_strx ");
6265 else
6266 printf (" DW_MACRO_undef_strx ");
6267 if (do_wide)
39f381cb 6268 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset));
e4b7104b
NC
6269 printf (_("lineno : %d macro : %s\n"),
6270 lineno, string);
6271 break;
6272
4ccf1e31 6273 default:
e4b7104b
NC
6274 if (op >= DW_MACRO_lo_user && op <= DW_MACRO_hi_user)
6275 {
6276 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op);
6277 break;
6278 }
6279
4ccf1e31
JJ
6280 if (extended_ops == NULL || extended_ops[op] == NULL)
6281 {
6282 error (_(" Unknown macro opcode %02x seen\n"), op);
6283 return 0;
6284 }
6285 else
6286 {
6287 /* Skip over unhandled opcodes. */
6288 dwarf_vma nargs, n;
6289 unsigned char *desc = extended_ops[op];
cd30bcef 6290 READ_ULEB (nargs, desc, end);
4ccf1e31
JJ
6291 if (nargs == 0)
6292 {
7a7e1061 6293 printf (_(" DW_MACRO_%02x\n"), op);
4ccf1e31
JJ
6294 break;
6295 }
7a7e1061 6296 printf (_(" DW_MACRO_%02x -"), op);
4ccf1e31
JJ
6297 for (n = 0; n < nargs; n++)
6298 {
0c588247
NC
6299 int val;
6300
77145576 6301 /* DW_FORM_implicit_const is not expected here. */
0c588247 6302 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
4ccf1e31 6303 curr
77145576 6304 = read_and_display_attr_value (0, val, 0,
ec1b0fbb 6305 start, curr, end, 0, 0, offset_size,
341f9135 6306 version, NULL, 0, NULL,
ec1b0fbb 6307 NULL, ' ', -1);
4ccf1e31
JJ
6308 if (n != nargs - 1)
6309 printf (",");
6310 }
6311 printf ("\n");
6312 }
6313 break;
6314 }
6315 }
6316
6317 printf ("\n");
b4eb7656 6318 }
4ccf1e31
JJ
6319
6320 return 1;
6321}
6322
19e6b90e
L
6323static int
6324display_debug_abbrev (struct dwarf_section *section,
6325 void *file ATTRIBUTE_UNUSED)
6326{
6327 abbrev_entry *entry;
6328 unsigned char *start = section->start;
bcd213b2 6329 const unsigned char *end = start + section->size;
19e6b90e 6330
015dc7e1 6331 introduce (section, false);
19e6b90e
L
6332
6333 do
6334 {
bcd213b2
NC
6335 abbrev_list * list;
6336 dwarf_vma offset;
7282333f 6337
bcd213b2 6338 offset = start - section->start;
76868f36 6339 list = find_abbrev_list_by_abbrev_offset (0, offset);
bcd213b2
NC
6340 if (list == NULL)
6341 {
76868f36 6342 list = new_abbrev_list (0, offset);
bcd213b2
NC
6343 start = process_abbrev_set (start, end, list);
6344 list->start_of_next_abbrevs = start;
6345 }
6346 else
6347 start = list->start_of_next_abbrevs;
19e6b90e 6348
bcd213b2 6349 if (list->first_abbrev == NULL)
19e6b90e
L
6350 continue;
6351
bcd213b2 6352 printf (_(" Number TAG (0x%lx)\n"), (long) offset);
19e6b90e 6353
bcd213b2 6354 for (entry = list->first_abbrev; entry; entry = entry->next)
19e6b90e
L
6355 {
6356 abbrev_attr *attr;
6357
cc5914eb 6358 printf (" %ld %s [%s]\n",
bcd213b2 6359 entry->number,
19e6b90e
L
6360 get_TAG_name (entry->tag),
6361 entry->children ? _("has children") : _("no children"));
6362
6363 for (attr = entry->first_attr; attr; attr = attr->next)
77145576
JK
6364 {
6365 printf (" %-18s %s",
6366 get_AT_name (attr->attribute),
6367 get_FORM_name (attr->form));
6368 if (attr->form == DW_FORM_implicit_const)
6369 printf (": %" BFD_VMA_FMT "d", attr->implicit_const);
6370 putchar ('\n');
6371 }
19e6b90e
L
6372 }
6373 }
6374 while (start);
6375
6376 printf ("\n");
6377
6378 return 1;
6379}
6380
42bcef4a
AB
6381/* Return true when ADDR is the maximum address, when addresses are
6382 POINTER_SIZE bytes long. */
6383
015dc7e1 6384static bool
42bcef4a
AB
6385is_max_address (dwarf_vma addr, unsigned int pointer_size)
6386{
6387 dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1));
6388 return ((addr & mask) == mask);
6389}
6390
9f272209
AO
6391/* Display a view pair list starting at *VSTART_PTR and ending at
6392 VLISTEND within SECTION. */
6393
6394static void
6395display_view_pair_list (struct dwarf_section *section,
6396 unsigned char **vstart_ptr,
6397 unsigned int debug_info_entry,
6398 unsigned char *vlistend)
6399{
6400 unsigned char *vstart = *vstart_ptr;
6401 unsigned char *section_end = section->start + section->size;
6402 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
6403
6404 if (vlistend < section_end)
6405 section_end = vlistend;
6406
6407 putchar ('\n');
6408
6409 while (vstart < section_end)
6410 {
6411 dwarf_vma off = vstart - section->start;
6412 dwarf_vma vbegin, vend;
6413
cd30bcef 6414 READ_ULEB (vbegin, vstart, section_end);
9f272209 6415 if (vstart == section_end)
cd30bcef 6416 break;
9f272209 6417
cd30bcef 6418 READ_ULEB (vend, vstart, section_end);
9f272209
AO
6419 printf (" %8.8lx ", (unsigned long) off);
6420
6421 print_dwarf_view (vbegin, pointer_size, 1);
6422 print_dwarf_view (vend, pointer_size, 1);
6423 printf (_("location view pair\n"));
6424 }
6425
6426 putchar ('\n');
6427 *vstart_ptr = vstart;
6428}
6429
4723351a
CC
6430/* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6431
6432static void
6433display_loc_list (struct dwarf_section *section,
b4eb7656
AM
6434 unsigned char **start_ptr,
6435 unsigned int debug_info_entry,
359ca075
JK
6436 dwarf_vma offset,
6437 dwarf_vma base_address,
9f272209 6438 unsigned char **vstart_ptr,
b4eb7656 6439 int has_frame_base)
4723351a 6440{
9f272209 6441 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
4723351a 6442 unsigned char *section_end = section->start + section->size;
82b1b41b
NC
6443 unsigned long cu_offset;
6444 unsigned int pointer_size;
6445 unsigned int offset_size;
6446 int dwarf_version;
4723351a
CC
6447
6448 dwarf_vma begin;
6449 dwarf_vma end;
6450 unsigned short length;
6451 int need_frame_base;
6452
82b1b41b
NC
6453 if (debug_info_entry >= num_debug_info_entries)
6454 {
6455 warn (_("No debug information available for loc lists of entry: %u\n"),
6456 debug_info_entry);
6457 return;
6458 }
b4eb7656 6459
82b1b41b
NC
6460 cu_offset = debug_information [debug_info_entry].cu_offset;
6461 pointer_size = debug_information [debug_info_entry].pointer_size;
6462 offset_size = debug_information [debug_info_entry].offset_size;
6463 dwarf_version = debug_information [debug_info_entry].dwarf_version;
b4eb7656 6464
f41e4712
NC
6465 if (pointer_size < 2 || pointer_size > 8)
6466 {
6467 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6468 pointer_size, debug_info_entry);
6469 return;
6470 }
6471
4723351a
CC
6472 while (1)
6473 {
359ca075 6474 dwarf_vma off = offset + (start - *start_ptr);
9f272209 6475 dwarf_vma vbegin = vm1, vend = vm1;
d1c4b12b 6476
4723351a 6477 if (start + 2 * pointer_size > section_end)
b4eb7656
AM
6478 {
6479 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 6480 (unsigned long) offset);
b4eb7656
AM
6481 break;
6482 }
4723351a 6483
359ca075 6484 printf (" %8.8lx ", (unsigned long) off);
fab128ef 6485
0c588247
NC
6486 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
6487 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
4723351a 6488
4723351a 6489 if (begin == 0 && end == 0)
b4eb7656 6490 {
d1c4b12b
NC
6491 /* PR 18374: In a object file we can have a location list that
6492 starts with a begin and end of 0 because there are relocations
6493 that need to be applied to the addresses. Actually applying
6494 the relocations now does not help as they will probably resolve
6495 to 0, since the object file has not been fully linked. Real
6496 end of list markers will not have any relocations against them. */
6497 if (! reloc_at (section, off)
6498 && ! reloc_at (section, off + pointer_size))
6499 {
6500 printf (_("<End of list>\n"));
6501 break;
6502 }
b4eb7656 6503 }
4723351a
CC
6504
6505 /* Check base address specifiers. */
42bcef4a
AB
6506 if (is_max_address (begin, pointer_size)
6507 && !is_max_address (end, pointer_size))
b4eb7656
AM
6508 {
6509 base_address = end;
6510 print_dwarf_vma (begin, pointer_size);
6511 print_dwarf_vma (end, pointer_size);
6512 printf (_("(base address)\n"));
6513 continue;
6514 }
4723351a 6515
9f272209
AO
6516 if (vstart)
6517 {
9f272209
AO
6518 off = offset + (vstart - *start_ptr);
6519
cd30bcef 6520 READ_ULEB (vbegin, vstart, section_end);
9f272209
AO
6521 print_dwarf_view (vbegin, pointer_size, 1);
6522
cd30bcef 6523 READ_ULEB (vend, vstart, section_end);
9f272209
AO
6524 print_dwarf_view (vend, pointer_size, 1);
6525
6526 printf (_("views at %8.8lx for:\n %*s "),
6527 (unsigned long) off, 8, "");
6528 }
6529
4723351a 6530 if (start + 2 > section_end)
b4eb7656
AM
6531 {
6532 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 6533 (unsigned long) offset);
b4eb7656
AM
6534 break;
6535 }
4723351a 6536
0c588247 6537 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4723351a
CC
6538
6539 if (start + length > section_end)
b4eb7656
AM
6540 {
6541 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 6542 (unsigned long) offset);
b4eb7656
AM
6543 break;
6544 }
4723351a
CC
6545
6546 print_dwarf_vma (begin + base_address, pointer_size);
6547 print_dwarf_vma (end + base_address, pointer_size);
6548
6549 putchar ('(');
6550 need_frame_base = decode_location_expression (start,
b4eb7656
AM
6551 pointer_size,
6552 offset_size,
6553 dwarf_version,
6554 length,
6555 cu_offset, section);
4723351a
CC
6556 putchar (')');
6557
6558 if (need_frame_base && !has_frame_base)
b4eb7656 6559 printf (_(" [without DW_AT_frame_base]"));
4723351a 6560
9f272209 6561 if (begin == end && vbegin == vend)
b4eb7656 6562 fputs (_(" (start == end)"), stdout);
9f272209 6563 else if (begin > end || (begin == end && vbegin > vend))
b4eb7656 6564 fputs (_(" (start > end)"), stdout);
4723351a
CC
6565
6566 putchar ('\n');
6567
6568 start += length;
6569 }
6570
6571 *start_ptr = start;
9f272209 6572 *vstart_ptr = vstart;
4723351a
CC
6573}
6574
77145576
JK
6575/* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6576
6577static void
6578display_loclists_list (struct dwarf_section *section,
6579 unsigned char **start_ptr,
6580 unsigned int debug_info_entry,
6581 dwarf_vma offset,
6582 dwarf_vma base_address,
9f272209 6583 unsigned char **vstart_ptr,
77145576
JK
6584 int has_frame_base)
6585{
9f272209 6586 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
77145576
JK
6587 unsigned char *section_end = section->start + section->size;
6588 unsigned long cu_offset;
6589 unsigned int pointer_size;
6590 unsigned int offset_size;
6591 int dwarf_version;
77145576 6592
9dfd0db9 6593 /* Initialize it due to a false compiler warning. */
9f272209
AO
6594 dwarf_vma begin = -1, vbegin = -1;
6595 dwarf_vma end = -1, vend = -1;
77145576
JK
6596 dwarf_vma length;
6597 int need_frame_base;
6598
6599 if (debug_info_entry >= num_debug_info_entries)
6600 {
6601 warn (_("No debug information available for "
6602 "loclists lists of entry: %u\n"),
6603 debug_info_entry);
6604 return;
6605 }
6606
6607 cu_offset = debug_information [debug_info_entry].cu_offset;
6608 pointer_size = debug_information [debug_info_entry].pointer_size;
6609 offset_size = debug_information [debug_info_entry].offset_size;
6610 dwarf_version = debug_information [debug_info_entry].dwarf_version;
6611
6612 if (pointer_size < 2 || pointer_size > 8)
6613 {
6614 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6615 pointer_size, debug_info_entry);
6616 return;
6617 }
6618
6619 while (1)
6620 {
6621 dwarf_vma off = offset + (start - *start_ptr);
6622 enum dwarf_location_list_entry_type llet;
6623
6624 if (start + 1 > section_end)
6625 {
6626 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6627 (unsigned long) offset);
6628 break;
6629 }
6630
6631 printf (" %8.8lx ", (unsigned long) off);
6632
6633 SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end);
6634
1c9f770d
MW
6635 if (vstart && (llet == DW_LLE_offset_pair
6636 || llet == DW_LLE_start_end
6637 || llet == DW_LLE_start_length))
9f272209
AO
6638 {
6639 off = offset + (vstart - *start_ptr);
6640
cd30bcef 6641 READ_ULEB (vbegin, vstart, section_end);
9f272209
AO
6642 print_dwarf_view (vbegin, pointer_size, 1);
6643
cd30bcef 6644 READ_ULEB (vend, vstart, section_end);
9f272209
AO
6645 print_dwarf_view (vend, pointer_size, 1);
6646
6647 printf (_("views at %8.8lx for:\n %*s "),
6648 (unsigned long) off, 8, "");
6649 }
6650
77145576
JK
6651 switch (llet)
6652 {
6653 case DW_LLE_end_of_list:
6654 printf (_("<End of list>\n"));
6655 break;
6656 case DW_LLE_offset_pair:
cd30bcef 6657 READ_ULEB (begin, start, section_end);
1c9f770d 6658 begin += base_address;
cd30bcef 6659 READ_ULEB (end, start, section_end);
1c9f770d
MW
6660 end += base_address;
6661 break;
6662 case DW_LLE_start_end:
6663 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
6664 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
6665 break;
6666 case DW_LLE_start_length:
6667 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
6668 READ_ULEB (end, start, section_end);
6669 end += begin;
77145576
JK
6670 break;
6671 case DW_LLE_base_address:
6672 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size,
6673 section_end);
6674 print_dwarf_vma (base_address, pointer_size);
6675 printf (_("(base address)\n"));
6676 break;
9f272209
AO
6677#ifdef DW_LLE_view_pair
6678 case DW_LLE_view_pair:
6679 if (vstart)
6680 printf (_("View pair entry in loclist with locviews attribute\n"));
cd30bcef 6681 READ_ULEB (vbegin, start, section_end);
9f272209
AO
6682 print_dwarf_view (vbegin, pointer_size, 1);
6683
cd30bcef 6684 READ_ULEB (vend, start, section_end);
9f272209
AO
6685 print_dwarf_view (vend, pointer_size, 1);
6686
6687 printf (_("views for:\n"));
6688 continue;
6689#endif
77145576
JK
6690 default:
6691 error (_("Invalid location list entry type %d\n"), llet);
6692 return;
6693 }
6694 if (llet == DW_LLE_end_of_list)
6695 break;
1c9f770d
MW
6696 if (llet != DW_LLE_offset_pair
6697 && llet != DW_LLE_start_end
6698 && llet != DW_LLE_start_length)
77145576
JK
6699 continue;
6700
6701 if (start + 2 > section_end)
6702 {
6703 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6704 (unsigned long) offset);
6705 break;
6706 }
6707
cd30bcef 6708 READ_ULEB (length, start, section_end);
77145576 6709
1c9f770d
MW
6710 print_dwarf_vma (begin, pointer_size);
6711 print_dwarf_vma (end, pointer_size);
77145576
JK
6712
6713 putchar ('(');
6714 need_frame_base = decode_location_expression (start,
6715 pointer_size,
6716 offset_size,
6717 dwarf_version,
6718 length,
6719 cu_offset, section);
6720 putchar (')');
6721
6722 if (need_frame_base && !has_frame_base)
6723 printf (_(" [without DW_AT_frame_base]"));
6724
9f272209 6725 if (begin == end && vbegin == vend)
77145576 6726 fputs (_(" (start == end)"), stdout);
9f272209 6727 else if (begin > end || (begin == end && vbegin > vend))
77145576
JK
6728 fputs (_(" (start > end)"), stdout);
6729
6730 putchar ('\n');
6731
6732 start += length;
9f272209 6733 vbegin = vend = -1;
77145576
JK
6734 }
6735
9f272209
AO
6736 if (vbegin != vm1 || vend != vm1)
6737 printf (_("Trailing view pair not used in a range"));
6738
77145576 6739 *start_ptr = start;
9f272209 6740 *vstart_ptr = vstart;
77145576
JK
6741}
6742
fab128ef
CC
6743/* Print a .debug_addr table index in decimal, surrounded by square brackets,
6744 right-adjusted in a field of length LEN, and followed by a space. */
6745
6746static void
6747print_addr_index (unsigned int idx, unsigned int len)
6748{
6749 static char buf[15];
6750 snprintf (buf, sizeof (buf), "[%d]", idx);
341f9135 6751 printf ("%*s ", len, buf);
fab128ef
CC
6752}
6753
4723351a
CC
6754/* Display a location list from a .dwo section. It uses address indexes rather
6755 than embedded addresses. This code closely follows display_loc_list, but the
6756 two are sufficiently different that combining things is very ugly. */
6757
6758static void
6759display_loc_list_dwo (struct dwarf_section *section,
b4eb7656
AM
6760 unsigned char **start_ptr,
6761 unsigned int debug_info_entry,
359ca075 6762 dwarf_vma offset,
9f272209 6763 unsigned char **vstart_ptr,
b4eb7656 6764 int has_frame_base)
4723351a 6765{
9f272209 6766 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
4723351a 6767 unsigned char *section_end = section->start + section->size;
82b1b41b
NC
6768 unsigned long cu_offset;
6769 unsigned int pointer_size;
6770 unsigned int offset_size;
6771 int dwarf_version;
4723351a
CC
6772 int entry_type;
6773 unsigned short length;
6774 int need_frame_base;
fab128ef 6775 unsigned int idx;
4723351a 6776
82b1b41b
NC
6777 if (debug_info_entry >= num_debug_info_entries)
6778 {
6779 warn (_("No debug information for loc lists of entry: %u\n"),
6780 debug_info_entry);
6781 return;
6782 }
6783
6784 cu_offset = debug_information [debug_info_entry].cu_offset;
6785 pointer_size = debug_information [debug_info_entry].pointer_size;
6786 offset_size = debug_information [debug_info_entry].offset_size;
6787 dwarf_version = debug_information [debug_info_entry].dwarf_version;
6788
f41e4712
NC
6789 if (pointer_size < 2 || pointer_size > 8)
6790 {
6791 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6792 pointer_size, debug_info_entry);
6793 return;
6794 }
6795
4723351a
CC
6796 while (1)
6797 {
359ca075 6798 printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr)));
4723351a 6799
fab128ef 6800 if (start >= section_end)
b4eb7656
AM
6801 {
6802 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 6803 (unsigned long) offset);
b4eb7656
AM
6804 break;
6805 }
4723351a 6806
0c588247 6807 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
9f272209
AO
6808
6809 if (vstart)
6810 switch (entry_type)
6811 {
6812 default:
6813 break;
6814
6815 case 2:
6816 case 3:
6817 case 4:
6818 {
6819 dwarf_vma view;
6820 dwarf_vma off = offset + (vstart - *start_ptr);
6821
cd30bcef 6822 READ_ULEB (view, vstart, section_end);
9f272209
AO
6823 print_dwarf_view (view, 8, 1);
6824
cd30bcef 6825 READ_ULEB (view, vstart, section_end);
9f272209
AO
6826 print_dwarf_view (view, 8, 1);
6827
6828 printf (_("views at %8.8lx for:\n %*s "),
6829 (unsigned long) off, 8, "");
6830
6831 }
6832 break;
6833 }
6834
4723351a 6835 switch (entry_type)
b4eb7656
AM
6836 {
6837 case 0: /* A terminating entry. */
6838 *start_ptr = start;
9f272209 6839 *vstart_ptr = vstart;
b4eb7656
AM
6840 printf (_("<End of list>\n"));
6841 return;
6842 case 1: /* A base-address entry. */
cd30bcef 6843 READ_ULEB (idx, start, section_end);
b4eb7656 6844 print_addr_index (idx, 8);
9f272209 6845 printf ("%*s", 9 + (vstart ? 2 * 6 : 0), "");
b4eb7656
AM
6846 printf (_("(base address selection entry)\n"));
6847 continue;
6848 case 2: /* A start/end entry. */
cd30bcef 6849 READ_ULEB (idx, start, section_end);
b4eb7656 6850 print_addr_index (idx, 8);
cd30bcef 6851 READ_ULEB (idx, start, section_end);
b4eb7656
AM
6852 print_addr_index (idx, 8);
6853 break;
6854 case 3: /* A start/length entry. */
cd30bcef 6855 READ_ULEB (idx, start, section_end);
b4eb7656
AM
6856 print_addr_index (idx, 8);
6857 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
6858 printf ("%08x ", idx);
6859 break;
6860 case 4: /* An offset pair entry. */
6861 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
6862 printf ("%08x ", idx);
6863 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
6864 printf ("%08x ", idx);
6865 break;
6866 default:
6867 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
6868 *start_ptr = start;
9f272209 6869 *vstart_ptr = vstart;
b4eb7656
AM
6870 return;
6871 }
4723351a
CC
6872
6873 if (start + 2 > section_end)
b4eb7656
AM
6874 {
6875 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 6876 (unsigned long) offset);
b4eb7656
AM
6877 break;
6878 }
4723351a 6879
0c588247 6880 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4723351a 6881 if (start + length > section_end)
b4eb7656
AM
6882 {
6883 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 6884 (unsigned long) offset);
b4eb7656
AM
6885 break;
6886 }
4723351a
CC
6887
6888 putchar ('(');
6889 need_frame_base = decode_location_expression (start,
b4eb7656
AM
6890 pointer_size,
6891 offset_size,
6892 dwarf_version,
6893 length,
6894 cu_offset, section);
4723351a
CC
6895 putchar (')');
6896
6897 if (need_frame_base && !has_frame_base)
b4eb7656 6898 printf (_(" [without DW_AT_frame_base]"));
4723351a
CC
6899
6900 putchar ('\n');
6901
6902 start += length;
6903 }
6904
6905 *start_ptr = start;
9f272209 6906 *vstart_ptr = vstart;
4723351a
CC
6907}
6908
9f272209
AO
6909/* Sort array of indexes in ascending order of loc_offsets[idx] and
6910 loc_views. */
51d0d03f 6911
9f272209 6912static dwarf_vma *loc_offsets, *loc_views;
51d0d03f
JJ
6913
6914static int
6915loc_offsets_compar (const void *ap, const void *bp)
6916{
6917 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
6918 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
6919
9f272209
AO
6920 int ret = (a > b) - (b > a);
6921 if (ret)
6922 return ret;
6923
6924 a = loc_views[*(const unsigned int *) ap];
6925 b = loc_views[*(const unsigned int *) bp];
6926
6927 ret = (a > b) - (b > a);
6928
6929 return ret;
51d0d03f
JJ
6930}
6931
19e6b90e
L
6932static int
6933display_debug_loc (struct dwarf_section *section, void *file)
6934{
9f272209 6935 unsigned char *start = section->start, *vstart = NULL;
19e6b90e
L
6936 unsigned long bytes;
6937 unsigned char *section_begin = start;
6938 unsigned int num_loc_list = 0;
6939 unsigned long last_offset = 0;
9f272209 6940 unsigned long last_view = 0;
19e6b90e
L
6941 unsigned int first = 0;
6942 unsigned int i;
6943 unsigned int j;
6944 int seen_first_offset = 0;
51d0d03f 6945 int locs_sorted = 1;
9f272209 6946 unsigned char *next = start, *vnext = vstart;
51d0d03f 6947 unsigned int *array = NULL;
4723351a 6948 const char *suffix = strrchr (section->name, '.');
015dc7e1 6949 bool is_dwo = false;
77145576
JK
6950 int is_loclists = strstr (section->name, "debug_loclists") != NULL;
6951 dwarf_vma expected_start = 0;
4723351a
CC
6952
6953 if (suffix && strcmp (suffix, ".dwo") == 0)
015dc7e1 6954 is_dwo = true;
19e6b90e
L
6955
6956 bytes = section->size;
19e6b90e
L
6957
6958 if (bytes == 0)
6959 {
6960 printf (_("\nThe %s section is empty.\n"), section->name);
6961 return 0;
6962 }
6963
77145576
JK
6964 if (is_loclists)
6965 {
6966 unsigned char *hdrptr = section_begin;
6967 dwarf_vma ll_length;
6968 unsigned short ll_version;
6969 unsigned char *end = section_begin + section->size;
6970 unsigned char address_size, segment_selector_size;
6971 uint32_t offset_entry_count;
6972
6973 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end);
6974 if (ll_length == 0xffffffff)
6975 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end);
6976
6977 SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end);
6978 if (ll_version != 5)
6979 {
6980 warn (_("The %s section contains corrupt or "
6981 "unsupported version number: %d.\n"),
6982 section->name, ll_version);
6983 return 0;
6984 }
6985
6986 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
6987
6988 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
6989 if (segment_selector_size != 0)
6990 {
6991 warn (_("The %s section contains "
6992 "unsupported segment selector size: %d.\n"),
6993 section->name, segment_selector_size);
6994 return 0;
6995 }
6996
6997 SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end);
6998 if (offset_entry_count != 0)
6999 {
7000 warn (_("The %s section contains "
7001 "unsupported offset entry count: %d.\n"),
7002 section->name, offset_entry_count);
7003 return 0;
7004 }
7005
7006 expected_start = hdrptr - section_begin;
7007 }
7008
1febe64d
NC
7009 if (load_debug_info (file) == 0)
7010 {
7011 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7012 section->name);
7013 return 0;
7014 }
19e6b90e
L
7015
7016 /* Check the order of location list in .debug_info section. If
7017 offsets of location lists are in the ascending order, we can
7018 use `debug_information' directly. */
7019 for (i = 0; i < num_debug_info_entries; i++)
7020 {
7021 unsigned int num;
7022
7023 num = debug_information [i].num_loc_offsets;
51d0d03f
JJ
7024 if (num > num_loc_list)
7025 num_loc_list = num;
19e6b90e
L
7026
7027 /* Check if we can use `debug_information' directly. */
51d0d03f 7028 if (locs_sorted && num != 0)
19e6b90e
L
7029 {
7030 if (!seen_first_offset)
7031 {
7032 /* This is the first location list. */
7033 last_offset = debug_information [i].loc_offsets [0];
9f272209 7034 last_view = debug_information [i].loc_views [0];
19e6b90e
L
7035 first = i;
7036 seen_first_offset = 1;
7037 j = 1;
7038 }
7039 else
7040 j = 0;
7041
7042 for (; j < num; j++)
7043 {
7044 if (last_offset >
9f272209
AO
7045 debug_information [i].loc_offsets [j]
7046 || (last_offset == debug_information [i].loc_offsets [j]
7047 && last_view > debug_information [i].loc_views [j]))
19e6b90e 7048 {
51d0d03f 7049 locs_sorted = 0;
19e6b90e
L
7050 break;
7051 }
7052 last_offset = debug_information [i].loc_offsets [j];
9f272209 7053 last_view = debug_information [i].loc_views [j];
19e6b90e
L
7054 }
7055 }
7056 }
7057
19e6b90e
L
7058 if (!seen_first_offset)
7059 error (_("No location lists in .debug_info section!\n"));
7060
d4bfc77b 7061 if (debug_information [first].num_loc_offsets > 0
9f272209
AO
7062 && debug_information [first].loc_offsets [0] != expected_start
7063 && debug_information [first].loc_views [0] != expected_start)
47704ddf
KT
7064 warn (_("Location lists in %s section start at 0x%s\n"),
7065 section->name,
7066 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
19e6b90e 7067
51d0d03f
JJ
7068 if (!locs_sorted)
7069 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
dda8d76d 7070
015dc7e1 7071 introduce (section, false);
dda8d76d 7072
d1c4b12b
NC
7073 if (reloc_at (section, 0))
7074 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
dda8d76d 7075
d1c4b12b 7076 printf (_(" Offset Begin End Expression\n"));
19e6b90e
L
7077
7078 seen_first_offset = 0;
7079 for (i = first; i < num_debug_info_entries; i++)
7080 {
9f272209 7081 dwarf_vma offset, voffset;
359ca075 7082 dwarf_vma base_address;
d1c4b12b 7083 unsigned int k;
19e6b90e
L
7084 int has_frame_base;
7085
51d0d03f
JJ
7086 if (!locs_sorted)
7087 {
7088 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
7089 array[k] = k;
7090 loc_offsets = debug_information [i].loc_offsets;
9f272209 7091 loc_views = debug_information [i].loc_views;
51d0d03f
JJ
7092 qsort (array, debug_information [i].num_loc_offsets,
7093 sizeof (*array), loc_offsets_compar);
7094 }
19e6b90e 7095
9f272209 7096 int adjacent_view_loclists = 1;
51d0d03f 7097 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
19e6b90e 7098 {
51d0d03f
JJ
7099 j = locs_sorted ? k : array[k];
7100 if (k
9f272209 7101 && (debug_information [i].loc_offsets [locs_sorted
51d0d03f 7102 ? k - 1 : array [k - 1]]
9f272209
AO
7103 == debug_information [i].loc_offsets [j])
7104 && (debug_information [i].loc_views [locs_sorted
7105 ? k - 1 : array [k - 1]]
7106 == debug_information [i].loc_views [j]))
51d0d03f 7107 continue;
19e6b90e 7108 has_frame_base = debug_information [i].have_frame_base [j];
d493b283 7109 offset = debug_information [i].loc_offsets [j];
19e6b90e 7110 next = section_begin + offset;
9f272209
AO
7111 voffset = debug_information [i].loc_views [j];
7112 if (voffset != vm1)
7113 vnext = section_begin + voffset;
7114 else
7115 vnext = NULL;
19e6b90e
L
7116 base_address = debug_information [i].base_address;
7117
9f272209
AO
7118 if (vnext && vnext < next)
7119 {
7120 vstart = vnext;
7121 display_view_pair_list (section, &vstart, i, next);
7122 if (start == vnext)
7123 start = vstart;
7124 }
7125
7126 if (!seen_first_offset || !adjacent_view_loclists)
19e6b90e
L
7127 seen_first_offset = 1;
7128 else
7129 {
7130 if (start < next)
7131 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
0af1713e 7132 (unsigned long) (start - section_begin),
c8071705 7133 (unsigned long) offset);
19e6b90e
L
7134 else if (start > next)
7135 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
0af1713e 7136 (unsigned long) (start - section_begin),
c8071705 7137 (unsigned long) offset);
19e6b90e
L
7138 }
7139 start = next;
9f272209 7140 vstart = vnext;
19e6b90e
L
7141
7142 if (offset >= bytes)
7143 {
7144 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
359ca075 7145 (unsigned long) offset);
19e6b90e
L
7146 continue;
7147 }
7148
9f272209
AO
7149 if (vnext && voffset >= bytes)
7150 {
7151 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
7152 (unsigned long) voffset);
7153 continue;
7154 }
7155
77145576
JK
7156 if (!is_loclists)
7157 {
7158 if (is_dwo)
7159 display_loc_list_dwo (section, &start, i, offset,
9f272209 7160 &vstart, has_frame_base);
77145576
JK
7161 else
7162 display_loc_list (section, &start, i, offset, base_address,
9f272209 7163 &vstart, has_frame_base);
77145576 7164 }
b4eb7656 7165 else
77145576
JK
7166 {
7167 if (is_dwo)
7168 warn (_("DWO is not yet supported.\n"));
7169 else
7170 display_loclists_list (section, &start, i, offset, base_address,
9f272209
AO
7171 &vstart, has_frame_base);
7172 }
7173
7174 /* FIXME: this arrangement is quite simplistic. Nothing
7175 requires locview lists to be adjacent to corresponding
7176 loclists, and a single loclist could be augmented by
7177 different locview lists, and vice-versa, unlikely as it
7178 is that it would make sense to do so. Hopefully we'll
7179 have view pair support built into loclists before we ever
7180 need to address all these possibilities. */
7181 if (adjacent_view_loclists && vnext
7182 && vnext != start && vstart != next)
7183 {
7184 adjacent_view_loclists = 0;
7185 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
77145576 7186 }
9f272209
AO
7187
7188 if (vnext && vnext == start)
7189 display_view_pair_list (section, &start, i, vstart);
19e6b90e
L
7190 }
7191 }
031cd65f 7192
4723351a 7193 if (start < section->start + section->size)
d3a49aa8
AM
7194 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7195 "There are %ld unused bytes at the end of section %s\n",
7196 (long) (section->start + section->size - start)),
4723351a 7197 (long) (section->start + section->size - start), section->name);
98fb390a 7198 putchar ('\n');
51d0d03f 7199 free (array);
19e6b90e
L
7200 return 1;
7201}
7202
7203static int
7204display_debug_str (struct dwarf_section *section,
7205 void *file ATTRIBUTE_UNUSED)
7206{
7207 unsigned char *start = section->start;
7208 unsigned long bytes = section->size;
7209 dwarf_vma addr = section->address;
7210
7211 if (bytes == 0)
7212 {
7213 printf (_("\nThe %s section is empty.\n"), section->name);
7214 return 0;
7215 }
7216
015dc7e1 7217 introduce (section, false);
19e6b90e
L
7218
7219 while (bytes)
7220 {
7221 int j;
7222 int k;
7223 int lbytes;
7224
7225 lbytes = (bytes > 16 ? 16 : bytes);
7226
7227 printf (" 0x%8.8lx ", (unsigned long) addr);
7228
7229 for (j = 0; j < 16; j++)
7230 {
7231 if (j < lbytes)
7232 printf ("%2.2x", start[j]);
7233 else
7234 printf (" ");
7235
7236 if ((j & 3) == 3)
7237 printf (" ");
7238 }
7239
7240 for (j = 0; j < lbytes; j++)
7241 {
7242 k = start[j];
7243 if (k >= ' ' && k < 0x80)
7244 printf ("%c", k);
7245 else
7246 printf (".");
7247 }
7248
7249 putchar ('\n');
7250
7251 start += lbytes;
7252 addr += lbytes;
7253 bytes -= lbytes;
7254 }
7255
7256 putchar ('\n');
7257
7258 return 1;
7259}
7260
19e6b90e
L
7261static int
7262display_debug_info (struct dwarf_section *section, void *file)
7263{
015dc7e1 7264 return process_debug_info (section, file, section->abbrev_sec, false, false);
19e6b90e
L
7265}
7266
2b6f5997
CC
7267static int
7268display_debug_types (struct dwarf_section *section, void *file)
7269{
015dc7e1 7270 return process_debug_info (section, file, section->abbrev_sec, false, true);
6f875884
TG
7271}
7272
7273static int
7274display_trace_info (struct dwarf_section *section, void *file)
7275{
015dc7e1 7276 return process_debug_info (section, file, section->abbrev_sec, false, true);
2b6f5997 7277}
19e6b90e
L
7278
7279static int
7280display_debug_aranges (struct dwarf_section *section,
7281 void *file ATTRIBUTE_UNUSED)
7282{
7283 unsigned char *start = section->start;
7284 unsigned char *end = start + section->size;
7285
015dc7e1 7286 introduce (section, false);
19e6b90e 7287
6e3d6dc1
NC
7288 /* It does not matter if this load fails,
7289 we test for that later on. */
7290 load_debug_info (file);
7291
19e6b90e
L
7292 while (start < end)
7293 {
7294 unsigned char *hdrptr;
7295 DWARF2_Internal_ARange arange;
91d6fa6a 7296 unsigned char *addr_ranges;
2d9472a2
NC
7297 dwarf_vma length;
7298 dwarf_vma address;
e98fdf1a 7299 unsigned long sec_off;
53b8873b 7300 unsigned char address_size;
19e6b90e 7301 int excess;
bf5117e3
NC
7302 unsigned int offset_size;
7303 unsigned int initial_length_size;
19e6b90e
L
7304
7305 hdrptr = start;
7306
0c588247 7307 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
19e6b90e
L
7308 if (arange.ar_length == 0xffffffff)
7309 {
0c588247 7310 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
19e6b90e
L
7311 offset_size = 8;
7312 initial_length_size = 12;
7313 }
7314 else
7315 {
7316 offset_size = 4;
7317 initial_length_size = 4;
7318 }
7319
e98fdf1a
AM
7320 sec_off = hdrptr - section->start;
7321 if (sec_off + arange.ar_length < sec_off
7322 || sec_off + arange.ar_length > section->size)
7323 {
7324 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
7325 section->name,
7326 sec_off - initial_length_size,
7327 dwarf_vmatoa ("x", arange.ar_length));
7328 break;
7329 }
7330
0c588247
NC
7331 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
7332 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
19e6b90e 7333
6e3d6dc1
NC
7334 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
7335 && num_debug_info_entries > 0
7336 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
7337 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
47704ddf 7338 (unsigned long) arange.ar_info_offset, section->name);
6e3d6dc1 7339
0c588247
NC
7340 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
7341 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
19e6b90e
L
7342
7343 if (arange.ar_version != 2 && arange.ar_version != 3)
7344 {
67f101ee
NC
7345 /* PR 19872: A version number of 0 probably means that there is
7346 padding at the end of the .debug_aranges section. Gold puts
7347 it there when performing an incremental link, for example.
7348 So do not generate a warning in this case. */
7349 if (arange.ar_version)
7350 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
19e6b90e
L
7351 break;
7352 }
7353
47704ddf
KT
7354 printf (_(" Length: %ld\n"),
7355 (long) arange.ar_length);
19e6b90e 7356 printf (_(" Version: %d\n"), arange.ar_version);
47704ddf
KT
7357 printf (_(" Offset into .debug_info: 0x%lx\n"),
7358 (unsigned long) arange.ar_info_offset);
19e6b90e
L
7359 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
7360 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
7361
53b8873b
NC
7362 address_size = arange.ar_pointer_size + arange.ar_segment_size;
7363
f41e4712
NC
7364 /* PR 17512: file: 001-108546-0.001:0.1. */
7365 if (address_size == 0 || address_size > 8)
b3681d67
L
7366 {
7367 error (_("Invalid address size in %s section!\n"),
7368 section->name);
7369 break;
7370 }
7371
53b8873b
NC
7372 /* The DWARF spec does not require that the address size be a power
7373 of two, but we do. This will have to change if we ever encounter
7374 an uneven architecture. */
7375 if ((address_size & (address_size - 1)) != 0)
7376 {
7377 warn (_("Pointer size + Segment size is not a power of two.\n"));
7378 break;
7379 }
cecf136e 7380
209c9a13
NC
7381 if (address_size > 4)
7382 printf (_("\n Address Length\n"));
7383 else
7384 printf (_("\n Address Length\n"));
19e6b90e 7385
91d6fa6a 7386 addr_ranges = hdrptr;
19e6b90e 7387
53b8873b
NC
7388 /* Must pad to an alignment boundary that is twice the address size. */
7389 excess = (hdrptr - start) % (2 * address_size);
19e6b90e 7390 if (excess)
91d6fa6a 7391 addr_ranges += (2 * address_size) - excess;
19e6b90e 7392
e98fdf1a 7393 start += arange.ar_length + initial_length_size;
1617e571 7394
91d6fa6a 7395 while (addr_ranges + 2 * address_size <= start)
19e6b90e 7396 {
0c588247
NC
7397 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
7398 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
19e6b90e 7399
80c35038 7400 printf (" ");
2d9472a2
NC
7401 print_dwarf_vma (address, address_size);
7402 print_dwarf_vma (length, address_size);
7403 putchar ('\n');
19e6b90e 7404 }
19e6b90e
L
7405 }
7406
7407 printf ("\n");
7408
7409 return 1;
7410}
7411
4723351a
CC
7412/* Comparison function for qsort. */
7413static int
7414comp_addr_base (const void * v0, const void * v1)
7415{
d367307b
AM
7416 debug_info *info0 = *(debug_info **) v0;
7417 debug_info *info1 = *(debug_info **) v1;
4723351a
CC
7418 return info0->addr_base - info1->addr_base;
7419}
7420
7421/* Display the debug_addr section. */
7422static int
7423display_debug_addr (struct dwarf_section *section,
b4eb7656 7424 void *file)
4723351a
CC
7425{
7426 debug_info **debug_addr_info;
7427 unsigned char *entry;
7428 unsigned char *end;
7429 unsigned int i;
7430 unsigned int count;
0e12f6c8 7431 unsigned char * header;
4723351a
CC
7432
7433 if (section->size == 0)
7434 {
7435 printf (_("\nThe %s section is empty.\n"), section->name);
7436 return 0;
7437 }
7438
7439 if (load_debug_info (file) == 0)
7440 {
7441 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7442 section->name);
7443 return 0;
7444 }
7445
015dc7e1 7446 introduce (section, false);
4723351a 7447
1306a742
NC
7448 /* PR 17531: file: cf38d01b.
7449 We use xcalloc because a corrupt file may not have initialised all of the
7450 fields in the debug_info structure, which means that the sort below might
7451 try to move uninitialised data. */
7452 debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
b4eb7656 7453 sizeof (debug_info *));
4723351a
CC
7454
7455 count = 0;
7456 for (i = 0; i < num_debug_info_entries; i++)
82b1b41b 7457 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
1306a742
NC
7458 {
7459 /* PR 17531: file: cf38d01b. */
7460 if (debug_information[i].addr_base >= section->size)
7461 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
7462 (unsigned long) debug_information[i].addr_base, i);
7463 else
7464 debug_addr_info [count++] = debug_information + i;
7465 }
4723351a
CC
7466
7467 /* Add a sentinel to make iteration convenient. */
7468 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
7469 debug_addr_info [count]->addr_base = section->size;
4723351a 7470 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
1306a742 7471
0e12f6c8 7472 header = section->start;
4723351a
CC
7473 for (i = 0; i < count; i++)
7474 {
7475 unsigned int idx;
fab128ef 7476 unsigned int address_size = debug_addr_info [i]->pointer_size;
4723351a
CC
7477
7478 printf (_(" For compilation unit at offset 0x%s:\n"),
b4eb7656 7479 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
4723351a 7480
fab128ef 7481 printf (_("\tIndex\tAddress\n"));
4723351a 7482 entry = section->start + debug_addr_info [i]->addr_base;
0e12f6c8
TV
7483 if (debug_addr_info [i]->dwarf_version >= 5)
7484 {
7485 size_t header_size = entry - header;
7486 unsigned char * curr_header = header;
7487 dwarf_vma length;
7488 int version;
7489 int segment_selector_size;
7490
7491 if (header_size != 8 && header_size != 16)
7492 {
7493 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"),
7494 section->name, (long) header_size);
7495 return 0;
7496 }
7497
7498 SAFE_BYTE_GET_AND_INC (length, curr_header, 4, entry);
7499 if (length == 0xffffffff)
7500 SAFE_BYTE_GET (length, curr_header, 8, entry);
7501 end = curr_header + length;
7502
7503 SAFE_BYTE_GET_AND_INC (version, curr_header, 2, entry);
7504 if (version != 5)
7505 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7506 section->name, version);
7507
7508 SAFE_BYTE_GET_AND_INC (address_size, curr_header, 1, entry);
7509 SAFE_BYTE_GET_AND_INC (segment_selector_size, curr_header, 1, entry);
7510 address_size += segment_selector_size;
7511 }
7512 else
7513 end = section->start + debug_addr_info [i + 1]->addr_base;
7514 header = end;
4723351a
CC
7515 idx = 0;
7516 while (entry < end)
b4eb7656
AM
7517 {
7518 dwarf_vma base = byte_get (entry, address_size);
7519 printf (_("\t%d:\t"), idx);
7520 print_dwarf_vma (base, address_size);
7521 printf ("\n");
7522 entry += address_size;
7523 idx++;
7524 }
4723351a
CC
7525 }
7526 printf ("\n");
7527
7528 free (debug_addr_info);
7529 return 1;
7530}
7531
7532/* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
24841daa 7533
4723351a
CC
7534static int
7535display_debug_str_offsets (struct dwarf_section *section,
b4eb7656 7536 void *file ATTRIBUTE_UNUSED)
4723351a 7537{
9f27c364
HPN
7538 unsigned long idx;
7539
4723351a
CC
7540 if (section->size == 0)
7541 {
7542 printf (_("\nThe %s section is empty.\n"), section->name);
7543 return 0;
7544 }
e4b7104b
NC
7545
7546 unsigned char *start = section->start;
7547 unsigned char *end = start + section->size;
7548 unsigned char *curr = start;
7549
63b4cc53 7550 const char *suffix = strrchr (section->name, '.');
015dc7e1 7551 bool dwo = suffix && strcmp (suffix, ".dwo") == 0;
39f381cb
NC
7552
7553 if (dwo)
7554 load_debug_section_with_follow (str_dwo, file);
7555 else
7556 load_debug_section_with_follow (str, file);
e4b7104b 7557
015dc7e1 7558 introduce (section, false);
e4b7104b
NC
7559
7560 while (curr < end)
7561 {
7562 dwarf_vma length;
7563 dwarf_vma entry_length;
7564
7565 SAFE_BYTE_GET_AND_INC (length, curr, 4, end);
7566 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7567 if (length == 0xffffffff)
7568 {
7569 SAFE_BYTE_GET (length, curr, 8, end);
7570 entry_length = 8;
7571 }
7572 else
7573 entry_length = 4;
7574
95abb394 7575 unsigned char *entries_end;
39f381cb
NC
7576 if (length == 0)
7577 {
7578 /* This is probably an old style .debug_str_offset section which
7579 just contains offsets and no header (and the first offset is 0). */
7580 length = section->size;
7581 curr = section->start;
95abb394 7582 entries_end = end;
e4b7104b 7583
39f381cb
NC
7584 printf (_(" Length: %#lx\n"), (unsigned long) length);
7585 printf (_(" Index Offset [String]\n"));
7586 }
7587 else
7588 {
95abb394
TV
7589 entries_end = curr + length;
7590
39f381cb
NC
7591 int version;
7592 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
7593 if (version != 5)
7594 warn (_("Unexpected version number in str_offset header: %#x\n"), version);
7595
7596 int padding;
7597 SAFE_BYTE_GET_AND_INC (padding, curr, 2, end);
7598 if (padding != 0)
7599 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding);
7600
7601 printf (_(" Length: %#lx\n"), (unsigned long) length);
7602 printf (_(" Version: %#lx\n"), (unsigned long) version);
7603 printf (_(" Index Offset [String]\n"));
7604 }
e4b7104b 7605
95abb394 7606 for (idx = 0; curr < entries_end; idx++)
e4b7104b
NC
7607 {
7608 dwarf_vma offset;
7609 const unsigned char * string;
7610
95abb394
TV
7611 if (curr + entry_length > entries_end)
7612 /* Not enough space to read one entry_length, give up. */
7613 return 0;
7614
e4b7104b 7615 SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, end);
39f381cb
NC
7616 if (dwo)
7617 string = (const unsigned char *)
9f27c364 7618 fetch_indexed_string (idx, NULL, entry_length, dwo);
39f381cb
NC
7619 else
7620 string = fetch_indirect_string (offset);
7621
9f27c364 7622 printf (" %8lu %8s %s\n", idx, dwarf_vmatoa ("x", offset),
e4b7104b
NC
7623 string);
7624 }
7625 }
39f381cb 7626
4723351a
CC
7627 return 1;
7628}
7629
01a8f077
JK
7630/* Each debug_information[x].range_lists[y] gets this representation for
7631 sorting purposes. */
7632
7633struct range_entry
467c65bc
NC
7634{
7635 /* The debug_information[x].range_lists[y] value. */
359ca075 7636 dwarf_vma ranges_offset;
01a8f077 7637
467c65bc
NC
7638 /* Original debug_information to find parameters of the data. */
7639 debug_info *debug_info_p;
7640};
01a8f077
JK
7641
7642/* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7643
7644static int
7645range_entry_compar (const void *ap, const void *bp)
7646{
3f5e193b
NC
7647 const struct range_entry *a_re = (const struct range_entry *) ap;
7648 const struct range_entry *b_re = (const struct range_entry *) bp;
359ca075
JK
7649 const dwarf_vma a = a_re->ranges_offset;
7650 const dwarf_vma b = b_re->ranges_offset;
01a8f077
JK
7651
7652 return (a > b) - (b > a);
7653}
7654
77145576
JK
7655static void
7656display_debug_ranges_list (unsigned char *start, unsigned char *finish,
7657 unsigned int pointer_size, unsigned long offset,
7658 unsigned long base_address)
7659{
7660 while (start < finish)
7661 {
7662 dwarf_vma begin;
7663 dwarf_vma end;
7664
7665 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
7666 if (start >= finish)
7667 break;
7668 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
7669
7670 printf (" %8.8lx ", offset);
7671
7672 if (begin == 0 && end == 0)
7673 {
7674 printf (_("<End of list>\n"));
7675 break;
7676 }
7677
7678 /* Check base address specifiers. */
7679 if (is_max_address (begin, pointer_size)
7680 && !is_max_address (end, pointer_size))
7681 {
7682 base_address = end;
7683 print_dwarf_vma (begin, pointer_size);
7684 print_dwarf_vma (end, pointer_size);
7685 printf ("(base address)\n");
7686 continue;
7687 }
7688
7689 print_dwarf_vma (begin + base_address, pointer_size);
7690 print_dwarf_vma (end + base_address, pointer_size);
7691
7692 if (begin == end)
7693 fputs (_("(start == end)"), stdout);
7694 else if (begin > end)
7695 fputs (_("(start > end)"), stdout);
7696
7697 putchar ('\n');
7698 }
7699}
7700
7701static void
7702display_debug_rnglists_list (unsigned char *start, unsigned char *finish,
7703 unsigned int pointer_size, unsigned long offset,
7704 unsigned long base_address)
7705{
7706 unsigned char *next = start;
7707
7708 while (1)
7709 {
7710 unsigned long off = offset + (start - next);
7711 enum dwarf_range_list_entry rlet;
9dfd0db9
JK
7712 /* Initialize it due to a false compiler warning. */
7713 dwarf_vma begin = -1, length, end = -1;
77145576
JK
7714
7715 if (start + 1 > finish)
7716 {
7717 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
7718 offset);
7719 break;
7720 }
7721
7722 printf (" %8.8lx ", off);
7723
7724 SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish);
7725
7726 switch (rlet)
7727 {
7728 case DW_RLE_end_of_list:
7729 printf (_("<End of list>\n"));
7730 break;
7731 case DW_RLE_base_address:
7732 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish);
7733 print_dwarf_vma (base_address, pointer_size);
7734 printf (_("(base address)\n"));
7735 break;
7736 case DW_RLE_start_length:
7737 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
cd30bcef 7738 READ_ULEB (length, start, finish);
77145576
JK
7739 end = begin + length;
7740 break;
7741 case DW_RLE_offset_pair:
cd30bcef
AM
7742 READ_ULEB (begin, start, finish);
7743 READ_ULEB (end, start, finish);
77145576
JK
7744 break;
7745 case DW_RLE_start_end:
7746 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
7747 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish);
7748 break;
7749 default:
7750 error (_("Invalid range list entry type %d\n"), rlet);
7751 rlet = DW_RLE_end_of_list;
7752 break;
7753 }
7754 if (rlet == DW_RLE_end_of_list)
7755 break;
7756 if (rlet == DW_RLE_base_address)
7757 continue;
7758
4d932715
BE
7759 /* Only a DW_RLE_offset_pair needs the base address added. */
7760 if (rlet == DW_RLE_offset_pair)
7761 {
7762 begin += base_address;
7763 end += base_address;
7764 }
7765
7766 print_dwarf_vma (begin, pointer_size);
7767 print_dwarf_vma (end, pointer_size);
77145576
JK
7768
7769 if (begin == end)
7770 fputs (_("(start == end)"), stdout);
7771 else if (begin > end)
7772 fputs (_("(start > end)"), stdout);
7773
7774 putchar ('\n');
7775 }
7776}
7777
19e6b90e
L
7778static int
7779display_debug_ranges (struct dwarf_section *section,
7780 void *file ATTRIBUTE_UNUSED)
7781{
7782 unsigned char *start = section->start;
a2ff7a4b 7783 unsigned char *last_start = start;
f6f0e17b 7784 unsigned long bytes = section->size;
19e6b90e 7785 unsigned char *section_begin = start;
f6f0e17b 7786 unsigned char *finish = start + bytes;
01a8f077
JK
7787 unsigned int num_range_list, i;
7788 struct range_entry *range_entries, *range_entry_fill;
77145576
JK
7789 int is_rnglists = strstr (section->name, "debug_rnglists") != NULL;
7790 /* Initialize it due to a false compiler warning. */
7791 unsigned char address_size = 0;
cb4c35cf 7792 dwarf_vma last_offset = 0;
19e6b90e 7793
19e6b90e
L
7794 if (bytes == 0)
7795 {
7796 printf (_("\nThe %s section is empty.\n"), section->name);
7797 return 0;
7798 }
7799
77145576
JK
7800 if (is_rnglists)
7801 {
7802 dwarf_vma initial_length;
7803 unsigned int initial_length_size;
7804 unsigned char segment_selector_size;
7805 unsigned int offset_size, offset_entry_count;
7806 unsigned short version;
7807
7808 /* Get and check the length of the block. */
7809 SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish);
7810
7811 if (initial_length == 0xffffffff)
7812 {
7813 /* This section is 64-bit DWARF 3. */
7814 SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish);
7815 offset_size = 8;
7816 initial_length_size = 12;
7817 }
7818 else
7819 {
7820 offset_size = 4;
7821 initial_length_size = 4;
7822 }
7823
7824 if (initial_length + initial_length_size > section->size)
7825 {
7826 /* If the length field has a relocation against it, then we should
7827 not complain if it is inaccurate (and probably negative).
7828 It is copied from .debug_line handling code. */
7829 if (reloc_at (section, (start - section->start) - offset_size))
7830 {
7831 initial_length = (finish - start) - initial_length_size;
7832 }
7833 else
7834 {
7835 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
7836 (long) initial_length);
7837 return 0;
7838 }
7839 }
7840
7841 /* Get and check the version number. */
7842 SAFE_BYTE_GET_AND_INC (version, start, 2, finish);
7843
7844 if (version != 5)
7845 {
7846 warn (_("Only DWARF version 5 debug_rnglists info "
7847 "is currently supported.\n"));
7848 return 0;
7849 }
7850
7851 SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish);
7852
7853 SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish);
7854 if (segment_selector_size != 0)
7855 {
7856 warn (_("The %s section contains "
7857 "unsupported segment selector size: %d.\n"),
7858 section->name, segment_selector_size);
7859 return 0;
7860 }
7861
7862 SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish);
7863 if (offset_entry_count != 0)
7864 {
7865 warn (_("The %s section contains "
7866 "unsupported offset entry count: %u.\n"),
7867 section->name, offset_entry_count);
7868 return 0;
7869 }
7870 }
7871
1febe64d
NC
7872 if (load_debug_info (file) == 0)
7873 {
7874 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7875 section->name);
7876 return 0;
7877 }
19e6b90e 7878
01a8f077 7879 num_range_list = 0;
19e6b90e 7880 for (i = 0; i < num_debug_info_entries; i++)
52ff20fe
TV
7881 {
7882 if (debug_information [i].dwarf_version < 5 && is_rnglists)
7883 /* Skip .debug_rnglists reference. */
7884 continue;
7885 if (debug_information [i].dwarf_version >= 5 && !is_rnglists)
7886 /* Skip .debug_range reference. */
7887 continue;
7888 num_range_list += debug_information [i].num_range_lists;
7889 }
19e6b90e 7890
01a8f077 7891 if (num_range_list == 0)
4723351a
CC
7892 {
7893 /* This can happen when the file was compiled with -gsplit-debug
b4eb7656 7894 which removes references to range lists from the primary .o file. */
4723351a
CC
7895 printf (_("No range lists in .debug_info section.\n"));
7896 return 1;
7897 }
19e6b90e 7898
3f5e193b
NC
7899 range_entries = (struct range_entry *)
7900 xmalloc (sizeof (*range_entries) * num_range_list);
01a8f077 7901 range_entry_fill = range_entries;
19e6b90e 7902
01a8f077
JK
7903 for (i = 0; i < num_debug_info_entries; i++)
7904 {
7905 debug_info *debug_info_p = &debug_information[i];
7906 unsigned int j;
7907
52ff20fe
TV
7908 if (debug_information [i].dwarf_version < 5 && is_rnglists)
7909 /* Skip .debug_rnglists reference. */
7910 continue;
7911 if (debug_information [i].dwarf_version >= 5 && !is_rnglists)
7912 /* Skip .debug_range reference. */
7913 continue;
7914
01a8f077
JK
7915 for (j = 0; j < debug_info_p->num_range_lists; j++)
7916 {
7917 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
7918 range_entry_fill->debug_info_p = debug_info_p;
7919 range_entry_fill++;
19e6b90e
L
7920 }
7921 }
7922
01a8f077
JK
7923 qsort (range_entries, num_range_list, sizeof (*range_entries),
7924 range_entry_compar);
19e6b90e 7925
d493b283 7926 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
19e6b90e 7927 warn (_("Range lists in %s section start at 0x%lx\n"),
359ca075 7928 section->name, (unsigned long) range_entries[0].ranges_offset);
19e6b90e 7929
015dc7e1 7930 introduce (section, false);
dda8d76d 7931
19e6b90e
L
7932 printf (_(" Offset Begin End\n"));
7933
01a8f077 7934 for (i = 0; i < num_range_list; i++)
19e6b90e 7935 {
01a8f077
JK
7936 struct range_entry *range_entry = &range_entries[i];
7937 debug_info *debug_info_p = range_entry->debug_info_p;
19e6b90e 7938 unsigned int pointer_size;
359ca075 7939 dwarf_vma offset;
01a8f077 7940 unsigned char *next;
359ca075 7941 dwarf_vma base_address;
19e6b90e 7942
77145576 7943 pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size);
d493b283 7944 offset = range_entry->ranges_offset;
01a8f077
JK
7945 next = section_begin + offset;
7946 base_address = debug_info_p->base_address;
cecf136e 7947
f41e4712
NC
7948 /* PR 17512: file: 001-101485-0.001:0.1. */
7949 if (pointer_size < 2 || pointer_size > 8)
7950 {
7951 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
359ca075 7952 pointer_size, (unsigned long) offset);
f41e4712
NC
7953 continue;
7954 }
b4eb7656 7955
d11ae95e
NC
7956 if (next < section_begin || next >= finish)
7957 {
7958 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7959 (unsigned long) offset, i);
7960 continue;
7961 }
7962
cb4c35cf
AB
7963 /* If multiple DWARF entities reference the same range then we will
7964 have multiple entries in the `range_entries' list for the same
7965 offset. Thanks to the sort above these will all be consecutive in
7966 the `range_entries' list, so we can easily ignore duplicates
7967 here. */
7968 if (i > 0 && last_offset == offset)
7969 continue;
7970 last_offset = offset;
7971
4723351a 7972 if (dwarf_check != 0 && i > 0)
19e6b90e 7973 {
01a8f077
JK
7974 if (start < next)
7975 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7976 (unsigned long) (start - section_begin),
7977 (unsigned long) (next - section_begin), section->name);
7978 else if (start > next)
a2ff7a4b
AM
7979 {
7980 if (next == last_start)
7981 continue;
7982 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7983 (unsigned long) (start - section_begin),
7984 (unsigned long) (next - section_begin), section->name);
7985 }
01a8f077 7986 }
d11ae95e 7987
01a8f077 7988 start = next;
a2ff7a4b 7989 last_start = next;
19e6b90e 7990
77145576
JK
7991 (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list)
7992 (start, finish, pointer_size, offset, base_address);
19e6b90e
L
7993 }
7994 putchar ('\n');
01a8f077
JK
7995
7996 free (range_entries);
7997
19e6b90e
L
7998 return 1;
7999}
8000
8001typedef struct Frame_Chunk
8002{
8003 struct Frame_Chunk *next;
8004 unsigned char *chunk_start;
a1165289 8005 unsigned int ncols;
19e6b90e
L
8006 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8007 short int *col_type;
8008 int *col_offset;
8009 char *augmentation;
8010 unsigned int code_factor;
8011 int data_factor;
bf5117e3
NC
8012 dwarf_vma pc_begin;
8013 dwarf_vma pc_range;
32ef3000 8014 unsigned int cfa_reg;
c8071705 8015 dwarf_vma cfa_offset;
a1165289 8016 unsigned int ra;
19e6b90e
L
8017 unsigned char fde_encoding;
8018 unsigned char cfa_exp;
604282a7
JJ
8019 unsigned char ptr_size;
8020 unsigned char segment_size;
19e6b90e
L
8021}
8022Frame_Chunk;
8023
1296bc99
AB
8024typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int);
8025static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func;
665ce1f6
L
8026static const char *const *dwarf_regnames;
8027static unsigned int dwarf_regnames_count;
8028
1296bc99 8029
19e6b90e
L
8030/* A marker for a col_type that means this column was never referenced
8031 in the frame info. */
8032#define DW_CFA_unreferenced (-1)
8033
a1165289 8034/* Return 0 if no more space is needed, 1 if more space is needed,
665ce1f6
L
8035 -1 for invalid reg. */
8036
8037static int
8038frame_need_space (Frame_Chunk *fc, unsigned int reg)
19e6b90e 8039{
a1165289 8040 unsigned int prev = fc->ncols;
19e6b90e 8041
665ce1f6
L
8042 if (reg < (unsigned int) fc->ncols)
8043 return 0;
8044
d9acf707 8045 if (dwarf_regnames_count > 0
665ce1f6
L
8046 && reg > dwarf_regnames_count)
8047 return -1;
19e6b90e
L
8048
8049 fc->ncols = reg + 1;
a1165289
NC
8050 /* PR 17512: file: 10450-2643-0.004.
8051 If reg == -1 then this can happen... */
8052 if (fc->ncols == 0)
8053 return -1;
8054
06614111 8055 /* PR 17512: file: 2844a11d. */
d9acf707 8056 if (fc->ncols > 1024 && dwarf_regnames_count == 0)
06614111
NC
8057 {
8058 error (_("Unfeasibly large register number: %u\n"), reg);
8059 fc->ncols = 0;
8060 /* FIXME: 1024 is an arbitrary limit. Increase it if
8061 we ever encounter a valid binary that exceeds it. */
8062 return -1;
8063 }
8064
3f5e193b 8065 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
b4eb7656 8066 sizeof (short int));
3f5e193b 8067 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
b4eb7656 8068 /* PR 17512: file:002-10025-0.005. */
041830e0
NC
8069 if (fc->col_type == NULL || fc->col_offset == NULL)
8070 {
8071 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8072 fc->ncols);
8073 fc->ncols = 0;
8074 return -1;
8075 }
19e6b90e
L
8076
8077 while (prev < fc->ncols)
8078 {
8079 fc->col_type[prev] = DW_CFA_unreferenced;
8080 fc->col_offset[prev] = 0;
8081 prev++;
8082 }
665ce1f6 8083 return 1;
19e6b90e
L
8084}
8085
2dc4cec1
L
8086static const char *const dwarf_regnames_i386[] =
8087{
43234a1e
L
8088 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8089 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8090 "eip", "eflags", NULL, /* 8 - 10 */
8091 "st0", "st1", "st2", "st3", /* 11 - 14 */
8092 "st4", "st5", "st6", "st7", /* 15 - 18 */
8093 NULL, NULL, /* 19 - 20 */
8094 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8095 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8096 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8097 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8098 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8099 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
8100 "tr", "ldtr", /* 48 - 49 */
8101 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
8102 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
8103 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
8104 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
8105 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
8106 NULL, NULL, NULL, /* 90 - 92 */
8107 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
2dc4cec1
L
8108};
8109
3d875af5
L
8110static const char *const dwarf_regnames_iamcu[] =
8111{
8112 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8113 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8114 "eip", "eflags", NULL, /* 8 - 10 */
8115 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */
8116 NULL, NULL, /* 19 - 20 */
8117 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */
8118 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */
8119 NULL, NULL, NULL, /* 37 - 39 */
8120 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
8121 "tr", "ldtr", /* 48 - 49 */
8122 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
8123 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
8124 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
8125 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
8126 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
8127 NULL, NULL, NULL, /* 90 - 92 */
8128 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */
8129};
8130
99f6fdd9 8131static void
b129eb0e
RH
8132init_dwarf_regnames_i386 (void)
8133{
8134 dwarf_regnames = dwarf_regnames_i386;
8135 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
1296bc99 8136 dwarf_regnames_lookup_func = regname_internal_by_table_only;
b129eb0e
RH
8137}
8138
99f6fdd9 8139static void
3d875af5
L
8140init_dwarf_regnames_iamcu (void)
8141{
8142 dwarf_regnames = dwarf_regnames_iamcu;
8143 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu);
1296bc99 8144 dwarf_regnames_lookup_func = regname_internal_by_table_only;
3d875af5
L
8145}
8146
2dc4cec1
L
8147static const char *const dwarf_regnames_x86_64[] =
8148{
8149 "rax", "rdx", "rcx", "rbx",
8150 "rsi", "rdi", "rbp", "rsp",
8151 "r8", "r9", "r10", "r11",
8152 "r12", "r13", "r14", "r15",
8153 "rip",
8154 "xmm0", "xmm1", "xmm2", "xmm3",
8155 "xmm4", "xmm5", "xmm6", "xmm7",
8156 "xmm8", "xmm9", "xmm10", "xmm11",
8157 "xmm12", "xmm13", "xmm14", "xmm15",
8158 "st0", "st1", "st2", "st3",
8159 "st4", "st5", "st6", "st7",
8160 "mm0", "mm1", "mm2", "mm3",
8161 "mm4", "mm5", "mm6", "mm7",
8162 "rflags",
8163 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
8164 "fs.base", "gs.base", NULL, NULL,
8165 "tr", "ldtr",
43234a1e
L
8166 "mxcsr", "fcw", "fsw",
8167 "xmm16", "xmm17", "xmm18", "xmm19",
8168 "xmm20", "xmm21", "xmm22", "xmm23",
8169 "xmm24", "xmm25", "xmm26", "xmm27",
8170 "xmm28", "xmm29", "xmm30", "xmm31",
8171 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
8172 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
8173 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
8174 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
8175 NULL, NULL, NULL, /* 115 - 117 */
8176 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
2dc4cec1
L
8177};
8178
99f6fdd9 8179static void
b129eb0e
RH
8180init_dwarf_regnames_x86_64 (void)
8181{
8182 dwarf_regnames = dwarf_regnames_x86_64;
8183 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
1296bc99 8184 dwarf_regnames_lookup_func = regname_internal_by_table_only;
b129eb0e
RH
8185}
8186
4ee22035
RH
8187static const char *const dwarf_regnames_aarch64[] =
8188{
b4eb7656
AM
8189 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8190 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
4ee22035
RH
8191 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8192 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8193 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
fab7c86e
TC
8194 NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr",
8195 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8196 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
b4eb7656
AM
8197 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8198 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
4ee22035
RH
8199 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8200 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
fab7c86e
TC
8201 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8202 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8203 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8204 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
4ee22035
RH
8205};
8206
99f6fdd9 8207static void
4ee22035
RH
8208init_dwarf_regnames_aarch64 (void)
8209{
8210 dwarf_regnames = dwarf_regnames_aarch64;
8211 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
1296bc99 8212 dwarf_regnames_lookup_func = regname_internal_by_table_only;
4ee22035
RH
8213}
8214
d6bb17b0
AA
8215static const char *const dwarf_regnames_s390[] =
8216{
8217 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8218 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
8219 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
8220 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8221 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8222 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8223 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8224 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8225 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8226 "pswm", "pswa",
8227 NULL, NULL,
8228 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8229 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8230};
8231
99f6fdd9 8232static void
d6bb17b0
AA
8233init_dwarf_regnames_s390 (void)
8234{
8235 dwarf_regnames = dwarf_regnames_s390;
8236 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390);
1296bc99 8237 dwarf_regnames_lookup_func = regname_internal_by_table_only;
d6bb17b0
AA
8238}
8239
5bb0830d
AB
8240static const char *const dwarf_regnames_riscv[] =
8241{
8242 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8243 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8244 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8245 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8246 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8247 "fs0", "fs1", /* 40 - 41 */
8248 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8249 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8250 "fs10", "fs11", /* 58 - 59 */
8251 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
8252};
8253
4762fe62
AB
8254/* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8255 the large number of CSRs. */
8256
8257static const char *
8258regname_internal_riscv (unsigned int regno)
8259{
8260 const char *name = NULL;
8261
8262 /* Lookup in the table first, this covers GPR and FPR. */
8263 if (regno < ARRAY_SIZE (dwarf_regnames_riscv))
8264 name = dwarf_regnames_riscv [regno];
8265 else if (regno >= 4096 && regno <= 8191)
8266 {
8267 /* This might be a CSR, these live in a sparse number space from 4096
8268 to 8191 These numbers are defined in the RISC-V ELF ABI
8269 document. */
8270 switch (regno)
8271 {
8f595e9b
NC
8272#define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8273 case VALUE + 4096: name = #NAME; break;
4762fe62
AB
8274#include "opcode/riscv-opc.h"
8275#undef DECLARE_CSR
8276
8277 default:
8278 {
8279 static char csr_name[10];
8280 snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096));
8281 name = csr_name;
8282 }
8283 break;
8284 }
8285 }
8286
8287 return name;
8288}
8289
99f6fdd9 8290static void
5bb0830d
AB
8291init_dwarf_regnames_riscv (void)
8292{
4762fe62
AB
8293 dwarf_regnames = NULL;
8294 dwarf_regnames_count = 8192;
8295 dwarf_regnames_lookup_func = regname_internal_riscv;
5bb0830d
AB
8296}
8297
2dc4cec1 8298void
955ff7fc 8299init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine)
2dc4cec1 8300{
1296bc99
AB
8301 dwarf_regnames_lookup_func = NULL;
8302
2dc4cec1
L
8303 switch (e_machine)
8304 {
8305 case EM_386:
b129eb0e 8306 init_dwarf_regnames_i386 ();
2dc4cec1
L
8307 break;
8308
3d875af5
L
8309 case EM_IAMCU:
8310 init_dwarf_regnames_iamcu ();
8311 break;
8312
2dc4cec1 8313 case EM_X86_64:
7f502d6c 8314 case EM_L1OM:
7a9068fe 8315 case EM_K1OM:
b129eb0e 8316 init_dwarf_regnames_x86_64 ();
2dc4cec1
L
8317 break;
8318
4ee22035
RH
8319 case EM_AARCH64:
8320 init_dwarf_regnames_aarch64 ();
8321 break;
8322
d6bb17b0
AA
8323 case EM_S390:
8324 init_dwarf_regnames_s390 ();
8325 break;
8326
5bb0830d
AB
8327 case EM_RISCV:
8328 init_dwarf_regnames_riscv ();
8329 break;
8330
2dc4cec1
L
8331 default:
8332 break;
8333 }
8334}
8335
229a22cf
AB
8336/* Initialize the DWARF register name lookup state based on the
8337 architecture and specific machine type of a BFD. */
8338
8339void
8340init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch,
8341 unsigned long mach)
8342{
1296bc99
AB
8343 dwarf_regnames_lookup_func = NULL;
8344
229a22cf
AB
8345 switch (arch)
8346 {
8347 case bfd_arch_i386:
8348 switch (mach)
8349 {
8350 case bfd_mach_x86_64:
8351 case bfd_mach_x86_64_intel_syntax:
229a22cf
AB
8352 case bfd_mach_x64_32:
8353 case bfd_mach_x64_32_intel_syntax:
229a22cf
AB
8354 init_dwarf_regnames_x86_64 ();
8355 break;
8356
8357 default:
8358 init_dwarf_regnames_i386 ();
8359 break;
8360 }
8361 break;
8362
8363 case bfd_arch_iamcu:
8364 init_dwarf_regnames_iamcu ();
8365 break;
8366
8367 case bfd_arch_aarch64:
8368 init_dwarf_regnames_aarch64();
8369 break;
8370
8371 case bfd_arch_s390:
8372 init_dwarf_regnames_s390 ();
8373 break;
8374
8375 case bfd_arch_riscv:
8376 init_dwarf_regnames_riscv ();
8377 break;
8378
8379 default:
8380 break;
8381 }
8382}
8383
2dc4cec1 8384static const char *
1296bc99 8385regname_internal_by_table_only (unsigned int regno)
2dc4cec1 8386{
1296bc99 8387 if (dwarf_regnames != NULL
2dc4cec1
L
8388 && regno < dwarf_regnames_count
8389 && dwarf_regnames [regno] != NULL)
1296bc99
AB
8390 return dwarf_regnames [regno];
8391
8392 return NULL;
8393}
8394
8395static const char *
8396regname (unsigned int regno, int name_only_p)
8397{
8398 static char reg[64];
8399
8400 const char *name = NULL;
8401
8402 if (dwarf_regnames_lookup_func != NULL)
8403 name = dwarf_regnames_lookup_func (regno);
8404
8405 if (name != NULL)
2dc4cec1 8406 {
1296bc99
AB
8407 if (name_only_p)
8408 return name;
8409 snprintf (reg, sizeof (reg), "r%d (%s)", regno, name);
2dc4cec1
L
8410 }
8411 else
8412 snprintf (reg, sizeof (reg), "r%d", regno);
8413 return reg;
8414}
8415
19e6b90e 8416static void
a1165289 8417frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
19e6b90e 8418{
a1165289 8419 unsigned int r;
19e6b90e
L
8420 char tmp[100];
8421
d8024a91 8422 if (*max_regs != fc->ncols)
19e6b90e
L
8423 *max_regs = fc->ncols;
8424
8425 if (*need_col_headers)
8426 {
8427 *need_col_headers = 0;
8428
288f0ba2 8429 printf ("%-*s CFA ", eh_addr_size * 2, " LOC");
19e6b90e
L
8430
8431 for (r = 0; r < *max_regs; r++)
8432 if (fc->col_type[r] != DW_CFA_unreferenced)
8433 {
8434 if (r == fc->ra)
50751e18 8435 printf ("ra ");
19e6b90e 8436 else
2dc4cec1 8437 printf ("%-5s ", regname (r, 1));
19e6b90e
L
8438 }
8439
8440 printf ("\n");
8441 }
8442
bf5117e3 8443 print_dwarf_vma (fc->pc_begin, eh_addr_size);
19e6b90e
L
8444 if (fc->cfa_exp)
8445 strcpy (tmp, "exp");
8446 else
c8071705 8447 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset);
19e6b90e
L
8448 printf ("%-8s ", tmp);
8449
8450 for (r = 0; r < fc->ncols; r++)
8451 {
8452 if (fc->col_type[r] != DW_CFA_unreferenced)
8453 {
8454 switch (fc->col_type[r])
8455 {
8456 case DW_CFA_undefined:
8457 strcpy (tmp, "u");
8458 break;
8459 case DW_CFA_same_value:
8460 strcpy (tmp, "s");
8461 break;
8462 case DW_CFA_offset:
8463 sprintf (tmp, "c%+d", fc->col_offset[r]);
8464 break;
12eae2d3
JJ
8465 case DW_CFA_val_offset:
8466 sprintf (tmp, "v%+d", fc->col_offset[r]);
8467 break;
19e6b90e 8468 case DW_CFA_register:
2dc4cec1 8469 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
19e6b90e
L
8470 break;
8471 case DW_CFA_expression:
8472 strcpy (tmp, "exp");
8473 break;
12eae2d3
JJ
8474 case DW_CFA_val_expression:
8475 strcpy (tmp, "vexp");
8476 break;
19e6b90e
L
8477 default:
8478 strcpy (tmp, "n/a");
8479 break;
8480 }
2dc4cec1 8481 printf ("%-5s ", tmp);
19e6b90e
L
8482 }
8483 }
8484 printf ("\n");
8485}
8486
49727e46 8487#define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
19e6b90e 8488
49727e46
AM
8489static unsigned char *
8490read_cie (unsigned char *start, unsigned char *end,
8491 Frame_Chunk **p_cie, int *p_version,
bf59c5d5 8492 bfd_size_type *p_aug_len, unsigned char **p_aug)
49727e46
AM
8493{
8494 int version;
8495 Frame_Chunk *fc;
49727e46 8496 unsigned char *augmentation_data = NULL;
bf59c5d5 8497 bfd_size_type augmentation_data_len = 0;
49727e46 8498
041830e0 8499 * p_cie = NULL;
f41e4712
NC
8500 /* PR 17512: file: 001-228113-0.004. */
8501 if (start >= end)
8502 return end;
8503
49727e46
AM
8504 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
8505 memset (fc, 0, sizeof (Frame_Chunk));
8506
8507 fc->col_type = (short int *) xmalloc (sizeof (short int));
8508 fc->col_offset = (int *) xmalloc (sizeof (int));
8509
8510 version = *start++;
8511
8512 fc->augmentation = (char *) start;
f41e4712
NC
8513 /* PR 17512: file: 001-228113-0.004.
8514 Skip past augmentation name, but avoid running off the end of the data. */
8515 while (start < end)
8516 if (* start ++ == '\0')
8517 break;
8518 if (start == end)
8519 {
8520 warn (_("No terminator for augmentation name\n"));
442a6ce8 8521 goto fail;
f41e4712 8522 }
49727e46
AM
8523
8524 if (strcmp (fc->augmentation, "eh") == 0)
8525 start += eh_addr_size;
8526
8527 if (version >= 4)
8528 {
8529 GET (fc->ptr_size, 1);
77ef8654
NC
8530 if (fc->ptr_size < 1 || fc->ptr_size > 8)
8531 {
8532 warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size);
442a6ce8 8533 goto fail;
77ef8654
NC
8534 }
8535
49727e46 8536 GET (fc->segment_size, 1);
77ef8654
NC
8537 /* PR 17512: file: e99d2804. */
8538 if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8)
8539 {
8540 warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size);
442a6ce8 8541 goto fail;
77ef8654
NC
8542 }
8543
49727e46
AM
8544 eh_addr_size = fc->ptr_size;
8545 }
8546 else
8547 {
8548 fc->ptr_size = eh_addr_size;
8549 fc->segment_size = 0;
8550 }
442a6ce8 8551
cd30bcef
AM
8552 READ_ULEB (fc->code_factor, start, end);
8553 READ_SLEB (fc->data_factor, start, end);
442a6ce8 8554
49727e46
AM
8555 if (version == 1)
8556 {
8557 GET (fc->ra, 1);
8558 }
8559 else
8560 {
cd30bcef 8561 READ_ULEB (fc->ra, start, end);
49727e46
AM
8562 }
8563
8564 if (fc->augmentation[0] == 'z')
8565 {
cd30bcef 8566 READ_ULEB (augmentation_data_len, start, end);
49727e46 8567 augmentation_data = start;
a1165289 8568 /* PR 17512: file: 11042-2589-0.004. */
bf59c5d5 8569 if (augmentation_data_len > (bfd_size_type) (end - start))
a1165289 8570 {
bf59c5d5
NC
8571 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8572 dwarf_vmatoa ("x", augmentation_data_len),
8573 (unsigned long) (end - start));
442a6ce8 8574 goto fail;
a1165289 8575 }
9c0f3d3f 8576 start += augmentation_data_len;
49727e46
AM
8577 }
8578
8579 if (augmentation_data_len)
8580 {
058037d3
NC
8581 unsigned char *p;
8582 unsigned char *q;
8583 unsigned char *qend;
b4eb7656 8584
49727e46
AM
8585 p = (unsigned char *) fc->augmentation + 1;
8586 q = augmentation_data;
058037d3
NC
8587 qend = q + augmentation_data_len;
8588
9c0f3d3f 8589 while (p < end && q < qend)
49727e46
AM
8590 {
8591 if (*p == 'L')
8592 q++;
8593 else if (*p == 'P')
8594 q += 1 + size_of_encoded_value (*q);
8595 else if (*p == 'R')
8596 fc->fde_encoding = *q++;
8597 else if (*p == 'S')
8598 ;
09038062
ST
8599 else if (*p == 'B')
8600 ;
49727e46
AM
8601 else
8602 break;
8603 p++;
8604 }
c361b9ac
NC
8605 /* Note - it is OK if this loop terminates with q < qend.
8606 Padding may have been inserted to align the end of the CIE. */
49727e46
AM
8607 }
8608
8609 *p_cie = fc;
8610 if (p_version)
8611 *p_version = version;
8612 if (p_aug_len)
8613 {
8614 *p_aug_len = augmentation_data_len;
8615 *p_aug = augmentation_data;
8616 }
8617 return start;
442a6ce8
NC
8618
8619 fail:
8620 free (fc->col_offset);
8621 free (fc->col_type);
8622 free (fc);
8623 return end;
49727e46
AM
8624}
8625
d85bf2ba
NC
8626/* Prints out the contents on the DATA array formatted as unsigned bytes.
8627 If do_wide is not enabled, then formats the output to fit into 80 columns.
8628 PRINTED contains the number of characters already written to the current
8629 output line. */
bf59c5d5
NC
8630
8631static void
d85bf2ba
NC
8632display_data (bfd_size_type printed,
8633 const unsigned char * data,
8634 const bfd_size_type len)
bf59c5d5 8635{
d85bf2ba
NC
8636 if (do_wide || len < ((80 - printed) / 3))
8637 for (printed = 0; printed < len; ++printed)
8638 printf (" %02x", data[printed]);
bf59c5d5
NC
8639 else
8640 {
d85bf2ba 8641 for (printed = 0; printed < len; ++printed)
bf59c5d5 8642 {
d85bf2ba 8643 if (printed % (80 / 3) == 0)
bf59c5d5 8644 putchar ('\n');
d85bf2ba 8645 printf (" %02x", data[printed]);
bf59c5d5
NC
8646 }
8647 }
d85bf2ba
NC
8648}
8649
8650/* Prints out the contents on the augmentation data array.
8651 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8652
8653static void
8654display_augmentation_data (const unsigned char * data, const bfd_size_type len)
8655{
8656 bfd_size_type i;
8657
8658 i = printf (_(" Augmentation data: "));
8659 display_data (i, data, len);
bf59c5d5
NC
8660}
8661
19e6b90e
L
8662static int
8663display_debug_frames (struct dwarf_section *section,
8664 void *file ATTRIBUTE_UNUSED)
8665{
8666 unsigned char *start = section->start;
8667 unsigned char *end = start + section->size;
8668 unsigned char *section_start = start;
3391569f
NC
8669 Frame_Chunk *chunks = NULL, *forward_refs = NULL;
8670 Frame_Chunk *remembered_state = NULL;
19e6b90e 8671 Frame_Chunk *rs;
015dc7e1 8672 bool is_eh = strcmp (section->name, ".eh_frame") == 0;
a1165289 8673 unsigned int max_regs = 0;
665ce1f6 8674 const char *bad_reg = _("bad register: ");
77ef8654 8675 unsigned int saved_eh_addr_size = eh_addr_size;
19e6b90e 8676
015dc7e1 8677 introduce (section, false);
19e6b90e
L
8678
8679 while (start < end)
8680 {
8681 unsigned char *saved_start;
8682 unsigned char *block_end;
bf5117e3
NC
8683 dwarf_vma length;
8684 dwarf_vma cie_id;
19e6b90e
L
8685 Frame_Chunk *fc;
8686 Frame_Chunk *cie;
8687 int need_col_headers = 1;
8688 unsigned char *augmentation_data = NULL;
bf59c5d5 8689 bfd_size_type augmentation_data_len = 0;
bf5117e3
NC
8690 unsigned int encoded_ptr_size = saved_eh_addr_size;
8691 unsigned int offset_size;
8692 unsigned int initial_length_size;
015dc7e1 8693 bool all_nops;
a788aedd 8694 static Frame_Chunk fde_fc;
19e6b90e
L
8695
8696 saved_start = start;
19e6b90e 8697
0c588247 8698 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
041830e0 8699
19e6b90e
L
8700 if (length == 0)
8701 {
8702 printf ("\n%08lx ZERO terminator\n\n",
8703 (unsigned long)(saved_start - section_start));
6937bb54
NC
8704 /* Skip any zero terminators that directly follow.
8705 A corrupt section size could have loaded a whole
8706 slew of zero filled memory bytes. eg
8707 PR 17512: file: 070-19381-0.004. */
8708 while (start < end && * start == 0)
8709 ++ start;
b758e50f 8710 continue;
19e6b90e
L
8711 }
8712
8713 if (length == 0xffffffff)
8714 {
0c588247 8715 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
19e6b90e
L
8716 offset_size = 8;
8717 initial_length_size = 12;
8718 }
8719 else
8720 {
8721 offset_size = 4;
8722 initial_length_size = 4;
8723 }
8724
8725 block_end = saved_start + length + initial_length_size;
041830e0 8726 if (block_end > end || block_end < start)
53b8873b 8727 {
bf5117e3
NC
8728 warn ("Invalid length 0x%s in FDE at %#08lx\n",
8729 dwarf_vmatoa_1 (NULL, length, offset_size),
8730 (unsigned long) (saved_start - section_start));
53b8873b
NC
8731 block_end = end;
8732 }
0c588247
NC
8733
8734 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
19e6b90e 8735
846a11e4
NC
8736 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
8737 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
19e6b90e
L
8738 {
8739 int version;
a1165289 8740 unsigned int mreg;
19e6b90e 8741
49727e46
AM
8742 start = read_cie (start, end, &cie, &version,
8743 &augmentation_data_len, &augmentation_data);
041830e0
NC
8744 /* PR 17512: file: 027-135133-0.005. */
8745 if (cie == NULL)
8746 break;
a1165289 8747
49727e46 8748 fc = cie;
19e6b90e
L
8749 fc->next = chunks;
8750 chunks = fc;
8751 fc->chunk_start = saved_start;
a1165289 8752 mreg = max_regs > 0 ? max_regs - 1 : 0;
49727e46
AM
8753 if (mreg < fc->ra)
8754 mreg = fc->ra;
06614111
NC
8755 if (frame_need_space (fc, mreg) < 0)
8756 break;
49727e46
AM
8757 if (fc->fde_encoding)
8758 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
19e6b90e 8759
bf5117e3
NC
8760 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
8761 print_dwarf_vma (length, fc->ptr_size);
9c41109d 8762 print_dwarf_vma (cie_id, offset_size);
bf5117e3 8763
19e6b90e 8764 if (do_debug_frames_interp)
bf5117e3
NC
8765 {
8766 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
8767 fc->code_factor, fc->data_factor, fc->ra);
8768 }
19e6b90e
L
8769 else
8770 {
bf5117e3 8771 printf ("CIE\n");
19e6b90e
L
8772 printf (" Version: %d\n", version);
8773 printf (" Augmentation: \"%s\"\n", fc->augmentation);
604282a7
JJ
8774 if (version >= 4)
8775 {
8776 printf (" Pointer Size: %u\n", fc->ptr_size);
8777 printf (" Segment Size: %u\n", fc->segment_size);
8778 }
19e6b90e
L
8779 printf (" Code alignment factor: %u\n", fc->code_factor);
8780 printf (" Data alignment factor: %d\n", fc->data_factor);
8781 printf (" Return address column: %d\n", fc->ra);
8782
8783 if (augmentation_data_len)
bf59c5d5 8784 display_augmentation_data (augmentation_data, augmentation_data_len);
a1165289 8785
19e6b90e
L
8786 putchar ('\n');
8787 }
19e6b90e
L
8788 }
8789 else
8790 {
8791 unsigned char *look_for;
604282a7 8792 unsigned long segment_selector;
19e6b90e 8793
49727e46
AM
8794 if (is_eh)
8795 {
8796 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
8797 look_for = start - 4 - ((cie_id ^ sign) - sign);
8798 }
8799 else
8800 look_for = section_start + cie_id;
19e6b90e 8801
49727e46
AM
8802 if (look_for <= saved_start)
8803 {
8804 for (cie = chunks; cie ; cie = cie->next)
8805 if (cie->chunk_start == look_for)
8806 break;
8807 }
8808 else
8809 {
8810 for (cie = forward_refs; cie ; cie = cie->next)
8811 if (cie->chunk_start == look_for)
8812 break;
8813 if (!cie)
8814 {
8815 unsigned int off_size;
8816 unsigned char *cie_scan;
19e6b90e 8817
49727e46
AM
8818 cie_scan = look_for;
8819 off_size = 4;
8820 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
8821 if (length == 0xffffffff)
8822 {
8823 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
8824 off_size = 8;
8825 }
8826 if (length != 0)
8827 {
8828 dwarf_vma c_id;
8829
8830 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
8831 if (is_eh
8832 ? c_id == 0
8833 : ((off_size == 4 && c_id == DW_CIE_ID)
8834 || (off_size == 8 && c_id == DW64_CIE_ID)))
8835 {
8836 int version;
a1165289 8837 unsigned int mreg;
49727e46
AM
8838
8839 read_cie (cie_scan, end, &cie, &version,
8840 &augmentation_data_len, &augmentation_data);
a1165289
NC
8841 /* PR 17512: file: 3450-2098-0.004. */
8842 if (cie == NULL)
8843 {
8844 warn (_("Failed to read CIE information\n"));
8845 break;
8846 }
49727e46
AM
8847 cie->next = forward_refs;
8848 forward_refs = cie;
8849 cie->chunk_start = look_for;
a1165289 8850 mreg = max_regs > 0 ? max_regs - 1 : 0;
49727e46
AM
8851 if (mreg < cie->ra)
8852 mreg = cie->ra;
06614111
NC
8853 if (frame_need_space (cie, mreg) < 0)
8854 {
8855 warn (_("Invalid max register\n"));
8856 break;
8857 }
49727e46
AM
8858 if (cie->fde_encoding)
8859 encoded_ptr_size
8860 = size_of_encoded_value (cie->fde_encoding);
8861 }
8862 }
8863 }
8864 }
8865
8866 fc = &fde_fc;
8867 memset (fc, 0, sizeof (Frame_Chunk));
19e6b90e
L
8868
8869 if (!cie)
8870 {
bf5117e3
NC
8871 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
8872 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
8873 (unsigned long) (saved_start - section_start));
19e6b90e 8874 fc->ncols = 0;
3f5e193b
NC
8875 fc->col_type = (short int *) xmalloc (sizeof (short int));
8876 fc->col_offset = (int *) xmalloc (sizeof (int));
06614111
NC
8877 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
8878 {
8879 warn (_("Invalid max register\n"));
8880 break;
8881 }
19e6b90e
L
8882 cie = fc;
8883 fc->augmentation = "";
8884 fc->fde_encoding = 0;
604282a7
JJ
8885 fc->ptr_size = eh_addr_size;
8886 fc->segment_size = 0;
19e6b90e
L
8887 }
8888 else
8889 {
8890 fc->ncols = cie->ncols;
3f5e193b
NC
8891 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
8892 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
19e6b90e
L
8893 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
8894 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
8895 fc->augmentation = cie->augmentation;
604282a7
JJ
8896 fc->ptr_size = cie->ptr_size;
8897 eh_addr_size = cie->ptr_size;
8898 fc->segment_size = cie->segment_size;
19e6b90e
L
8899 fc->code_factor = cie->code_factor;
8900 fc->data_factor = cie->data_factor;
8901 fc->cfa_reg = cie->cfa_reg;
8902 fc->cfa_offset = cie->cfa_offset;
8903 fc->ra = cie->ra;
06614111
NC
8904 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
8905 {
8906 warn (_("Invalid max register\n"));
8907 break;
8908 }
19e6b90e
L
8909 fc->fde_encoding = cie->fde_encoding;
8910 }
8911
8912 if (fc->fde_encoding)
8913 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
8914
604282a7
JJ
8915 segment_selector = 0;
8916 if (fc->segment_size)
c8071705
NC
8917 {
8918 if (fc->segment_size > sizeof (segment_selector))
8919 {
8920 /* PR 17512: file: 9e196b3e. */
8921 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size);
8922 fc->segment_size = 4;
8923 }
8924 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
8925 }
041830e0
NC
8926
8927 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
19e6b90e 8928
0c588247
NC
8929 /* FIXME: It appears that sometimes the final pc_range value is
8930 encoded in less than encoded_ptr_size bytes. See the x86_64
8931 run of the "objcopy on compressed debug sections" test for an
8932 example of this. */
8933 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
bf5117e3 8934
19e6b90e
L
8935 if (cie->augmentation[0] == 'z')
8936 {
cd30bcef 8937 READ_ULEB (augmentation_data_len, start, end);
19e6b90e 8938 augmentation_data = start;
bf59c5d5 8939 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
d292364e 8940 if (augmentation_data_len > (bfd_size_type) (end - start))
0a9d414a 8941 {
d292364e
AM
8942 warn (_("Augmentation data too long: 0x%s, "
8943 "expected at most %#lx\n"),
8944 dwarf_vmatoa ("x", augmentation_data_len),
8945 (unsigned long) (end - start));
0a9d414a
NC
8946 start = end;
8947 augmentation_data = NULL;
8948 augmentation_data_len = 0;
8949 }
d292364e 8950 start += augmentation_data_len;
19e6b90e
L
8951 }
8952
bf5117e3
NC
8953 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
8954 (unsigned long)(saved_start - section_start),
8955 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
9c41109d 8956 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
604282a7 8957 (unsigned long)(cie->chunk_start - section_start));
bf5117e3 8958
604282a7
JJ
8959 if (fc->segment_size)
8960 printf ("%04lx:", segment_selector);
bf5117e3
NC
8961
8962 printf ("%s..%s\n",
8963 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
8964 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
8965
19e6b90e
L
8966 if (! do_debug_frames_interp && augmentation_data_len)
8967 {
bf59c5d5 8968 display_augmentation_data (augmentation_data, augmentation_data_len);
19e6b90e
L
8969 putchar ('\n');
8970 }
8971 }
8972
8973 /* At this point, fc is the current chunk, cie (if any) is set, and
8974 we're about to interpret instructions for the chunk. */
8975 /* ??? At present we need to do this always, since this sizes the
8976 fc->col_type and fc->col_offset arrays, which we write into always.
8977 We should probably split the interpreted and non-interpreted bits
8978 into two different routines, since there's so much that doesn't
8979 really overlap between them. */
8980 if (1 || do_debug_frames_interp)
8981 {
8982 /* Start by making a pass over the chunk, allocating storage
8983 and taking note of what registers are used. */
8984 unsigned char *tmp = start;
8985
8986 while (start < block_end)
8987 {
041830e0
NC
8988 unsigned int reg, op, opa;
8989 unsigned long temp;
5929c344 8990 unsigned char * new_start;
19e6b90e
L
8991
8992 op = *start++;
8993 opa = op & 0x3f;
8994 if (op & 0xc0)
8995 op &= 0xc0;
8996
8997 /* Warning: if you add any more cases to this switch, be
8998 sure to add them to the corresponding switch below. */
8999 switch (op)
9000 {
9001 case DW_CFA_advance_loc:
9002 break;
9003 case DW_CFA_offset:
cd30bcef 9004 SKIP_ULEB (start, end);
665ce1f6
L
9005 if (frame_need_space (fc, opa) >= 0)
9006 fc->col_type[opa] = DW_CFA_undefined;
19e6b90e
L
9007 break;
9008 case DW_CFA_restore:
665ce1f6
L
9009 if (frame_need_space (fc, opa) >= 0)
9010 fc->col_type[opa] = DW_CFA_undefined;
19e6b90e
L
9011 break;
9012 case DW_CFA_set_loc:
9013 start += encoded_ptr_size;
9014 break;
9015 case DW_CFA_advance_loc1:
9016 start += 1;
9017 break;
9018 case DW_CFA_advance_loc2:
9019 start += 2;
9020 break;
9021 case DW_CFA_advance_loc4:
9022 start += 4;
9023 break;
9024 case DW_CFA_offset_extended:
12eae2d3 9025 case DW_CFA_val_offset:
cd30bcef
AM
9026 READ_ULEB (reg, start, end);
9027 SKIP_ULEB (start, end);
665ce1f6
L
9028 if (frame_need_space (fc, reg) >= 0)
9029 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
9030 break;
9031 case DW_CFA_restore_extended:
cd30bcef 9032 READ_ULEB (reg, start, end);
665ce1f6
L
9033 if (frame_need_space (fc, reg) >= 0)
9034 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
9035 break;
9036 case DW_CFA_undefined:
cd30bcef 9037 READ_ULEB (reg, start, end);
665ce1f6
L
9038 if (frame_need_space (fc, reg) >= 0)
9039 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
9040 break;
9041 case DW_CFA_same_value:
cd30bcef 9042 READ_ULEB (reg, start, end);
665ce1f6
L
9043 if (frame_need_space (fc, reg) >= 0)
9044 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
9045 break;
9046 case DW_CFA_register:
cd30bcef
AM
9047 READ_ULEB (reg, start, end);
9048 SKIP_ULEB (start, end);
665ce1f6
L
9049 if (frame_need_space (fc, reg) >= 0)
9050 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
9051 break;
9052 case DW_CFA_def_cfa:
cd30bcef
AM
9053 SKIP_ULEB (start, end);
9054 SKIP_ULEB (start, end);
19e6b90e
L
9055 break;
9056 case DW_CFA_def_cfa_register:
cd30bcef 9057 SKIP_ULEB (start, end);
19e6b90e
L
9058 break;
9059 case DW_CFA_def_cfa_offset:
cd30bcef 9060 SKIP_ULEB (start, end);
19e6b90e
L
9061 break;
9062 case DW_CFA_def_cfa_expression:
cd30bcef 9063 READ_ULEB (temp, start, end);
5929c344
NC
9064 new_start = start + temp;
9065 if (new_start < start)
041830e0
NC
9066 {
9067 warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
9068 start = block_end;
9069 }
9070 else
5929c344 9071 start = new_start;
19e6b90e
L
9072 break;
9073 case DW_CFA_expression:
12eae2d3 9074 case DW_CFA_val_expression:
cd30bcef
AM
9075 READ_ULEB (reg, start, end);
9076 READ_ULEB (temp, start, end);
5929c344
NC
9077 new_start = start + temp;
9078 if (new_start < start)
041830e0 9079 {
b4eb7656 9080 /* PR 17512: file:306-192417-0.005. */
041830e0
NC
9081 warn (_("Corrupt CFA expression value: %lu\n"), temp);
9082 start = block_end;
9083 }
9084 else
5929c344 9085 start = new_start;
665ce1f6
L
9086 if (frame_need_space (fc, reg) >= 0)
9087 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
9088 break;
9089 case DW_CFA_offset_extended_sf:
12eae2d3 9090 case DW_CFA_val_offset_sf:
cd30bcef
AM
9091 READ_ULEB (reg, start, end);
9092 SKIP_SLEB (start, end);
665ce1f6
L
9093 if (frame_need_space (fc, reg) >= 0)
9094 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
9095 break;
9096 case DW_CFA_def_cfa_sf:
cd30bcef
AM
9097 SKIP_ULEB (start, end);
9098 SKIP_SLEB (start, end);
19e6b90e
L
9099 break;
9100 case DW_CFA_def_cfa_offset_sf:
cd30bcef 9101 SKIP_SLEB (start, end);
19e6b90e
L
9102 break;
9103 case DW_CFA_MIPS_advance_loc8:
9104 start += 8;
9105 break;
9106 case DW_CFA_GNU_args_size:
cd30bcef 9107 SKIP_ULEB (start, end);
19e6b90e
L
9108 break;
9109 case DW_CFA_GNU_negative_offset_extended:
cd30bcef
AM
9110 READ_ULEB (reg, start, end);
9111 SKIP_ULEB (start, end);
665ce1f6
L
9112 if (frame_need_space (fc, reg) >= 0)
9113 fc->col_type[reg] = DW_CFA_undefined;
9114 break;
19e6b90e
L
9115 default:
9116 break;
9117 }
9118 }
9119 start = tmp;
9120 }
9121
015dc7e1 9122 all_nops = true;
5b6312fd 9123
19e6b90e
L
9124 /* Now we know what registers are used, make a second pass over
9125 the chunk, this time actually printing out the info. */
9126
9127 while (start < block_end)
9128 {
362beea4 9129 unsigned char * tmp;
19e6b90e 9130 unsigned op, opa;
7f2c8a1d
NC
9131 unsigned long ul, roffs;
9132 /* Note: It is tempting to use an unsigned long for 'reg' but there
9133 are various functions, notably frame_space_needed() that assume that
9134 reg is an unsigned int. */
9135 unsigned int reg;
9136 dwarf_signed_vma l;
bf5117e3 9137 dwarf_vma ofs;
19e6b90e 9138 dwarf_vma vma;
665ce1f6 9139 const char *reg_prefix = "";
19e6b90e
L
9140
9141 op = *start++;
9142 opa = op & 0x3f;
9143 if (op & 0xc0)
9144 op &= 0xc0;
9145
5b6312fd
NC
9146 /* Make a note if something other than DW_CFA_nop happens. */
9147 if (op != DW_CFA_nop)
015dc7e1 9148 all_nops = false;
5b6312fd 9149
19e6b90e
L
9150 /* Warning: if you add any more cases to this switch, be
9151 sure to add them to the corresponding switch above. */
9152 switch (op)
9153 {
9154 case DW_CFA_advance_loc:
9155 if (do_debug_frames_interp)
9156 frame_display_row (fc, &need_col_headers, &max_regs);
9157 else
bf5117e3 9158 printf (" DW_CFA_advance_loc: %d to %s\n",
19e6b90e 9159 opa * fc->code_factor,
b4eb7656 9160 dwarf_vmatoa_1 (NULL,
bf5117e3
NC
9161 fc->pc_begin + opa * fc->code_factor,
9162 fc->ptr_size));
19e6b90e
L
9163 fc->pc_begin += opa * fc->code_factor;
9164 break;
9165
9166 case DW_CFA_offset:
cd30bcef 9167 READ_ULEB (roffs, start, end);
665ce1f6
L
9168 if (opa >= (unsigned int) fc->ncols)
9169 reg_prefix = bad_reg;
9170 if (! do_debug_frames_interp || *reg_prefix != '\0')
9171 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
9172 reg_prefix, regname (opa, 0),
9173 roffs * fc->data_factor);
9174 if (*reg_prefix == '\0')
9175 {
9176 fc->col_type[opa] = DW_CFA_offset;
9177 fc->col_offset[opa] = roffs * fc->data_factor;
9178 }
19e6b90e
L
9179 break;
9180
9181 case DW_CFA_restore:
50751e18 9182 if (opa >= (unsigned int) fc->ncols)
665ce1f6
L
9183 reg_prefix = bad_reg;
9184 if (! do_debug_frames_interp || *reg_prefix != '\0')
9185 printf (" DW_CFA_restore: %s%s\n",
9186 reg_prefix, regname (opa, 0));
50751e18
AK
9187 if (*reg_prefix != '\0')
9188 break;
9189
9190 if (opa >= (unsigned int) cie->ncols
9191 || (do_debug_frames_interp
9192 && cie->col_type[opa] == DW_CFA_unreferenced))
9193 {
9194 fc->col_type[opa] = DW_CFA_undefined;
9195 fc->col_offset[opa] = 0;
9196 }
9197 else
665ce1f6
L
9198 {
9199 fc->col_type[opa] = cie->col_type[opa];
9200 fc->col_offset[opa] = cie->col_offset[opa];
9201 }
19e6b90e
L
9202 break;
9203
9204 case DW_CFA_set_loc:
6937bb54 9205 vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
19e6b90e
L
9206 if (do_debug_frames_interp)
9207 frame_display_row (fc, &need_col_headers, &max_regs);
9208 else
bf5117e3
NC
9209 printf (" DW_CFA_set_loc: %s\n",
9210 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
19e6b90e
L
9211 fc->pc_begin = vma;
9212 break;
9213
9214 case DW_CFA_advance_loc1:
0c588247 9215 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
19e6b90e
L
9216 if (do_debug_frames_interp)
9217 frame_display_row (fc, &need_col_headers, &max_regs);
9218 else
bf5117e3
NC
9219 printf (" DW_CFA_advance_loc1: %ld to %s\n",
9220 (unsigned long) (ofs * fc->code_factor),
9221 dwarf_vmatoa_1 (NULL,
9222 fc->pc_begin + ofs * fc->code_factor,
9223 fc->ptr_size));
19e6b90e
L
9224 fc->pc_begin += ofs * fc->code_factor;
9225 break;
9226
9227 case DW_CFA_advance_loc2:
6937bb54 9228 SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
19e6b90e
L
9229 if (do_debug_frames_interp)
9230 frame_display_row (fc, &need_col_headers, &max_regs);
9231 else
bf5117e3
NC
9232 printf (" DW_CFA_advance_loc2: %ld to %s\n",
9233 (unsigned long) (ofs * fc->code_factor),
9234 dwarf_vmatoa_1 (NULL,
9235 fc->pc_begin + ofs * fc->code_factor,
9236 fc->ptr_size));
19e6b90e
L
9237 fc->pc_begin += ofs * fc->code_factor;
9238 break;
9239
9240 case DW_CFA_advance_loc4:
6937bb54 9241 SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
19e6b90e
L
9242 if (do_debug_frames_interp)
9243 frame_display_row (fc, &need_col_headers, &max_regs);
9244 else
bf5117e3
NC
9245 printf (" DW_CFA_advance_loc4: %ld to %s\n",
9246 (unsigned long) (ofs * fc->code_factor),
9247 dwarf_vmatoa_1 (NULL,
9248 fc->pc_begin + ofs * fc->code_factor,
9249 fc->ptr_size));
19e6b90e
L
9250 fc->pc_begin += ofs * fc->code_factor;
9251 break;
9252
9253 case DW_CFA_offset_extended:
cd30bcef
AM
9254 READ_ULEB (reg, start, end);
9255 READ_ULEB (roffs, start, end);
665ce1f6
L
9256 if (reg >= (unsigned int) fc->ncols)
9257 reg_prefix = bad_reg;
9258 if (! do_debug_frames_interp || *reg_prefix != '\0')
9259 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9260 reg_prefix, regname (reg, 0),
9261 roffs * fc->data_factor);
9262 if (*reg_prefix == '\0')
9263 {
9264 fc->col_type[reg] = DW_CFA_offset;
9265 fc->col_offset[reg] = roffs * fc->data_factor;
9266 }
19e6b90e
L
9267 break;
9268
12eae2d3 9269 case DW_CFA_val_offset:
cd30bcef
AM
9270 READ_ULEB (reg, start, end);
9271 READ_ULEB (roffs, start, end);
665ce1f6
L
9272 if (reg >= (unsigned int) fc->ncols)
9273 reg_prefix = bad_reg;
9274 if (! do_debug_frames_interp || *reg_prefix != '\0')
084303b8 9275 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
665ce1f6
L
9276 reg_prefix, regname (reg, 0),
9277 roffs * fc->data_factor);
9278 if (*reg_prefix == '\0')
9279 {
9280 fc->col_type[reg] = DW_CFA_val_offset;
9281 fc->col_offset[reg] = roffs * fc->data_factor;
9282 }
12eae2d3
JJ
9283 break;
9284
19e6b90e 9285 case DW_CFA_restore_extended:
cd30bcef 9286 READ_ULEB (reg, start, end);
50751e18 9287 if (reg >= (unsigned int) fc->ncols)
665ce1f6
L
9288 reg_prefix = bad_reg;
9289 if (! do_debug_frames_interp || *reg_prefix != '\0')
9290 printf (" DW_CFA_restore_extended: %s%s\n",
9291 reg_prefix, regname (reg, 0));
50751e18
AK
9292 if (*reg_prefix != '\0')
9293 break;
9294
9295 if (reg >= (unsigned int) cie->ncols)
9296 {
9297 fc->col_type[reg] = DW_CFA_undefined;
9298 fc->col_offset[reg] = 0;
9299 }
9300 else
665ce1f6
L
9301 {
9302 fc->col_type[reg] = cie->col_type[reg];
9303 fc->col_offset[reg] = cie->col_offset[reg];
9304 }
19e6b90e
L
9305 break;
9306
9307 case DW_CFA_undefined:
cd30bcef 9308 READ_ULEB (reg, start, end);
665ce1f6
L
9309 if (reg >= (unsigned int) fc->ncols)
9310 reg_prefix = bad_reg;
9311 if (! do_debug_frames_interp || *reg_prefix != '\0')
9312 printf (" DW_CFA_undefined: %s%s\n",
9313 reg_prefix, regname (reg, 0));
9314 if (*reg_prefix == '\0')
9315 {
9316 fc->col_type[reg] = DW_CFA_undefined;
9317 fc->col_offset[reg] = 0;
9318 }
19e6b90e
L
9319 break;
9320
9321 case DW_CFA_same_value:
cd30bcef 9322 READ_ULEB (reg, start, end);
665ce1f6
L
9323 if (reg >= (unsigned int) fc->ncols)
9324 reg_prefix = bad_reg;
9325 if (! do_debug_frames_interp || *reg_prefix != '\0')
9326 printf (" DW_CFA_same_value: %s%s\n",
9327 reg_prefix, regname (reg, 0));
9328 if (*reg_prefix == '\0')
9329 {
9330 fc->col_type[reg] = DW_CFA_same_value;
9331 fc->col_offset[reg] = 0;
9332 }
19e6b90e
L
9333 break;
9334
9335 case DW_CFA_register:
cd30bcef
AM
9336 READ_ULEB (reg, start, end);
9337 READ_ULEB (roffs, start, end);
665ce1f6
L
9338 if (reg >= (unsigned int) fc->ncols)
9339 reg_prefix = bad_reg;
9340 if (! do_debug_frames_interp || *reg_prefix != '\0')
2dc4cec1 9341 {
665ce1f6
L
9342 printf (" DW_CFA_register: %s%s in ",
9343 reg_prefix, regname (reg, 0));
2dc4cec1
L
9344 puts (regname (roffs, 0));
9345 }
665ce1f6
L
9346 if (*reg_prefix == '\0')
9347 {
9348 fc->col_type[reg] = DW_CFA_register;
9349 fc->col_offset[reg] = roffs;
9350 }
19e6b90e
L
9351 break;
9352
9353 case DW_CFA_remember_state:
9354 if (! do_debug_frames_interp)
9355 printf (" DW_CFA_remember_state\n");
3f5e193b 9356 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
b4eb7656 9357 rs->cfa_offset = fc->cfa_offset;
d71ad7fc
RC
9358 rs->cfa_reg = fc->cfa_reg;
9359 rs->ra = fc->ra;
9360 rs->cfa_exp = fc->cfa_exp;
19e6b90e 9361 rs->ncols = fc->ncols;
3f5e193b 9362 rs->col_type = (short int *) xcmalloc (rs->ncols,
b4eb7656 9363 sizeof (* rs->col_type));
d71ad7fc
RC
9364 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
9365 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
9366 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
19e6b90e
L
9367 rs->next = remembered_state;
9368 remembered_state = rs;
9369 break;
9370
9371 case DW_CFA_restore_state:
9372 if (! do_debug_frames_interp)
9373 printf (" DW_CFA_restore_state\n");
9374 rs = remembered_state;
9375 if (rs)
9376 {
9377 remembered_state = rs->next;
d71ad7fc
RC
9378 fc->cfa_offset = rs->cfa_offset;
9379 fc->cfa_reg = rs->cfa_reg;
b4eb7656
AM
9380 fc->ra = rs->ra;
9381 fc->cfa_exp = rs->cfa_exp;
06614111
NC
9382 if (frame_need_space (fc, rs->ncols - 1) < 0)
9383 {
1306a742 9384 warn (_("Invalid column number in saved frame state\n"));
06614111
NC
9385 fc->ncols = 0;
9386 break;
9387 }
d71ad7fc 9388 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
19e6b90e 9389 memcpy (fc->col_offset, rs->col_offset,
d71ad7fc 9390 rs->ncols * sizeof (* rs->col_offset));
19e6b90e
L
9391 free (rs->col_type);
9392 free (rs->col_offset);
9393 free (rs);
9394 }
9395 else if (do_debug_frames_interp)
9396 printf ("Mismatched DW_CFA_restore_state\n");
9397 break;
9398
9399 case DW_CFA_def_cfa:
cd30bcef
AM
9400 READ_ULEB (fc->cfa_reg, start, end);
9401 READ_ULEB (fc->cfa_offset, start, end);
19e6b90e
L
9402 fc->cfa_exp = 0;
9403 if (! do_debug_frames_interp)
2dc4cec1 9404 printf (" DW_CFA_def_cfa: %s ofs %d\n",
c8071705 9405 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
19e6b90e
L
9406 break;
9407
9408 case DW_CFA_def_cfa_register:
cd30bcef 9409 READ_ULEB (fc->cfa_reg, start, end);
19e6b90e
L
9410 fc->cfa_exp = 0;
9411 if (! do_debug_frames_interp)
2dc4cec1
L
9412 printf (" DW_CFA_def_cfa_register: %s\n",
9413 regname (fc->cfa_reg, 0));
19e6b90e
L
9414 break;
9415
9416 case DW_CFA_def_cfa_offset:
cd30bcef 9417 READ_ULEB (fc->cfa_offset, start, end);
19e6b90e 9418 if (! do_debug_frames_interp)
c8071705 9419 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset);
19e6b90e
L
9420 break;
9421
9422 case DW_CFA_nop:
9423 if (! do_debug_frames_interp)
9424 printf (" DW_CFA_nop\n");
9425 break;
9426
9427 case DW_CFA_def_cfa_expression:
cd30bcef 9428 READ_ULEB (ul, start, end);
7460c0ab 9429 if (start >= block_end || ul > (unsigned long) (block_end - start))
6937bb54 9430 {
a1165289 9431 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
6937bb54
NC
9432 break;
9433 }
19e6b90e
L
9434 if (! do_debug_frames_interp)
9435 {
9436 printf (" DW_CFA_def_cfa_expression (");
b7807392
JJ
9437 decode_location_expression (start, eh_addr_size, 0, -1,
9438 ul, 0, section);
19e6b90e
L
9439 printf (")\n");
9440 }
9441 fc->cfa_exp = 1;
9442 start += ul;
9443 break;
9444
9445 case DW_CFA_expression:
cd30bcef
AM
9446 READ_ULEB (reg, start, end);
9447 READ_ULEB (ul, start, end);
665ce1f6
L
9448 if (reg >= (unsigned int) fc->ncols)
9449 reg_prefix = bad_reg;
6937bb54 9450 /* PR 17512: file: 069-133014-0.006. */
06614111 9451 /* PR 17512: file: 98c02eb4. */
362beea4
NC
9452 tmp = start + ul;
9453 if (start >= block_end || tmp > block_end || tmp < start)
6937bb54 9454 {
a1165289 9455 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
6937bb54
NC
9456 break;
9457 }
665ce1f6 9458 if (! do_debug_frames_interp || *reg_prefix != '\0')
19e6b90e 9459 {
665ce1f6
L
9460 printf (" DW_CFA_expression: %s%s (",
9461 reg_prefix, regname (reg, 0));
b7807392 9462 decode_location_expression (start, eh_addr_size, 0, -1,
f1c4cc75 9463 ul, 0, section);
19e6b90e
L
9464 printf (")\n");
9465 }
665ce1f6
L
9466 if (*reg_prefix == '\0')
9467 fc->col_type[reg] = DW_CFA_expression;
362beea4 9468 start = tmp;
19e6b90e
L
9469 break;
9470
12eae2d3 9471 case DW_CFA_val_expression:
cd30bcef
AM
9472 READ_ULEB (reg, start, end);
9473 READ_ULEB (ul, start, end);
665ce1f6
L
9474 if (reg >= (unsigned int) fc->ncols)
9475 reg_prefix = bad_reg;
362beea4
NC
9476 tmp = start + ul;
9477 if (start >= block_end || tmp > block_end || tmp < start)
6937bb54 9478 {
a1165289 9479 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
6937bb54
NC
9480 break;
9481 }
665ce1f6 9482 if (! do_debug_frames_interp || *reg_prefix != '\0')
12eae2d3 9483 {
665ce1f6
L
9484 printf (" DW_CFA_val_expression: %s%s (",
9485 reg_prefix, regname (reg, 0));
b7807392
JJ
9486 decode_location_expression (start, eh_addr_size, 0, -1,
9487 ul, 0, section);
12eae2d3
JJ
9488 printf (")\n");
9489 }
665ce1f6
L
9490 if (*reg_prefix == '\0')
9491 fc->col_type[reg] = DW_CFA_val_expression;
362beea4 9492 start = tmp;
12eae2d3
JJ
9493 break;
9494
19e6b90e 9495 case DW_CFA_offset_extended_sf:
cd30bcef
AM
9496 READ_ULEB (reg, start, end);
9497 READ_SLEB (l, start, end);
665ce1f6
L
9498 if (frame_need_space (fc, reg) < 0)
9499 reg_prefix = bad_reg;
9500 if (! do_debug_frames_interp || *reg_prefix != '\0')
9501 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9502 reg_prefix, regname (reg, 0),
c8071705 9503 (long)(l * fc->data_factor));
665ce1f6
L
9504 if (*reg_prefix == '\0')
9505 {
9506 fc->col_type[reg] = DW_CFA_offset;
9507 fc->col_offset[reg] = l * fc->data_factor;
9508 }
19e6b90e
L
9509 break;
9510
12eae2d3 9511 case DW_CFA_val_offset_sf:
cd30bcef
AM
9512 READ_ULEB (reg, start, end);
9513 READ_SLEB (l, start, end);
665ce1f6
L
9514 if (frame_need_space (fc, reg) < 0)
9515 reg_prefix = bad_reg;
9516 if (! do_debug_frames_interp || *reg_prefix != '\0')
084303b8 9517 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
665ce1f6 9518 reg_prefix, regname (reg, 0),
c8071705 9519 (long)(l * fc->data_factor));
665ce1f6
L
9520 if (*reg_prefix == '\0')
9521 {
9522 fc->col_type[reg] = DW_CFA_val_offset;
9523 fc->col_offset[reg] = l * fc->data_factor;
9524 }
12eae2d3
JJ
9525 break;
9526
19e6b90e 9527 case DW_CFA_def_cfa_sf:
cd30bcef
AM
9528 READ_ULEB (fc->cfa_reg, start, end);
9529 READ_ULEB (fc->cfa_offset, start, end);
19e6b90e
L
9530 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
9531 fc->cfa_exp = 0;
9532 if (! do_debug_frames_interp)
2dc4cec1 9533 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
c8071705 9534 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
19e6b90e
L
9535 break;
9536
9537 case DW_CFA_def_cfa_offset_sf:
cd30bcef 9538 READ_ULEB (fc->cfa_offset, start, end);
c8071705 9539 fc->cfa_offset *= fc->data_factor;
19e6b90e 9540 if (! do_debug_frames_interp)
c8071705 9541 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset);
19e6b90e
L
9542 break;
9543
9544 case DW_CFA_MIPS_advance_loc8:
6937bb54 9545 SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
19e6b90e
L
9546 if (do_debug_frames_interp)
9547 frame_display_row (fc, &need_col_headers, &max_regs);
9548 else
bf5117e3
NC
9549 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9550 (unsigned long) (ofs * fc->code_factor),
9551 dwarf_vmatoa_1 (NULL,
9552 fc->pc_begin + ofs * fc->code_factor,
9553 fc->ptr_size));
19e6b90e
L
9554 fc->pc_begin += ofs * fc->code_factor;
9555 break;
9556
9557 case DW_CFA_GNU_window_save:
9558 if (! do_debug_frames_interp)
9559 printf (" DW_CFA_GNU_window_save\n");
9560 break;
9561
9562 case DW_CFA_GNU_args_size:
cd30bcef 9563 READ_ULEB (ul, start, end);
19e6b90e
L
9564 if (! do_debug_frames_interp)
9565 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
9566 break;
9567
9568 case DW_CFA_GNU_negative_offset_extended:
cd30bcef
AM
9569 READ_ULEB (reg, start, end);
9570 READ_SLEB (l, start, end);
7f2c8a1d 9571 l = - l;
665ce1f6
L
9572 if (frame_need_space (fc, reg) < 0)
9573 reg_prefix = bad_reg;
9574 if (! do_debug_frames_interp || *reg_prefix != '\0')
9575 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
9576 reg_prefix, regname (reg, 0),
c8071705 9577 (long)(l * fc->data_factor));
665ce1f6
L
9578 if (*reg_prefix == '\0')
9579 {
9580 fc->col_type[reg] = DW_CFA_offset;
9581 fc->col_offset[reg] = l * fc->data_factor;
9582 }
19e6b90e
L
9583 break;
9584
9585 default:
53b8873b
NC
9586 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
9587 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
9588 else
f41e4712 9589 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
19e6b90e
L
9590 start = block_end;
9591 }
9592 }
9593
5b6312fd
NC
9594 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9595 if (do_debug_frames_interp && ! all_nops)
19e6b90e
L
9596 frame_display_row (fc, &need_col_headers, &max_regs);
9597
a788aedd
AM
9598 if (fde_fc.col_type != NULL)
9599 {
9600 free (fde_fc.col_type);
9601 fde_fc.col_type = NULL;
9602 }
9603 if (fde_fc.col_offset != NULL)
9604 {
9605 free (fde_fc.col_offset);
9606 fde_fc.col_offset = NULL;
9607 }
9608
19e6b90e 9609 start = block_end;
604282a7 9610 eh_addr_size = saved_eh_addr_size;
19e6b90e
L
9611 }
9612
9613 printf ("\n");
9614
3391569f
NC
9615 while (remembered_state != NULL)
9616 {
9617 rs = remembered_state;
9618 remembered_state = rs->next;
9619 free (rs->col_type);
9620 free (rs->col_offset);
9621 rs->next = NULL; /* Paranoia. */
9622 free (rs);
9623 }
9624
9625 while (chunks != NULL)
9626 {
9627 rs = chunks;
9628 chunks = rs->next;
9629 free (rs->col_type);
9630 free (rs->col_offset);
9631 rs->next = NULL; /* Paranoia. */
9632 free (rs);
9633 }
9634
9635 while (forward_refs != NULL)
9636 {
9637 rs = forward_refs;
9638 forward_refs = rs->next;
9639 free (rs->col_type);
9640 free (rs->col_offset);
9641 rs->next = NULL; /* Paranoia. */
9642 free (rs);
9643 }
9644
19e6b90e
L
9645 return 1;
9646}
9647
9648#undef GET
19e6b90e 9649
61364358
JK
9650static int
9651display_debug_names (struct dwarf_section *section, void *file)
9652{
9653 unsigned char *hdrptr = section->start;
9654 dwarf_vma unit_length;
9655 unsigned char *unit_start;
9656 const unsigned char *const section_end = section->start + section->size;
9657 unsigned char *unit_end;
9658
015dc7e1 9659 introduce (section, false);
61364358 9660
dda8d76d 9661 load_debug_section_with_follow (str, file);
61364358
JK
9662
9663 for (; hdrptr < section_end; hdrptr = unit_end)
9664 {
9665 unsigned int offset_size;
9666 uint16_t dwarf_version, padding;
9667 uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count;
9668 uint32_t bucket_count, name_count, abbrev_table_size;
9669 uint32_t augmentation_string_size;
9670 unsigned int i;
e98fdf1a 9671 unsigned long sec_off;
015dc7e1 9672 bool augmentation_printable;
48467cb9 9673 const char *augmentation_string;
61364358
JK
9674
9675 unit_start = hdrptr;
9676
9677 /* Get and check the length of the block. */
9678 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end);
9679
9680 if (unit_length == 0xffffffff)
9681 {
9682 /* This section is 64-bit DWARF. */
9683 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end);
9684 offset_size = 8;
9685 }
9686 else
9687 offset_size = 4;
9688 unit_end = hdrptr + unit_length;
9689
e98fdf1a
AM
9690 sec_off = hdrptr - section->start;
9691 if (sec_off + unit_length < sec_off
9692 || sec_off + unit_length > section->size)
61364358 9693 {
e98fdf1a
AM
9694 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
9695 section->name,
9696 (unsigned long) (unit_start - section->start),
9697 dwarf_vmatoa ("x", unit_length));
61364358
JK
9698 return 0;
9699 }
9700
9701 /* Get and check the version number. */
9702 SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end);
9703 printf (_("Version %ld\n"), (long) dwarf_version);
9704
9705 /* Prior versions did not exist, and future versions may not be
9706 backwards compatible. */
9707 if (dwarf_version != 5)
9708 {
9709 warn (_("Only DWARF version 5 .debug_names "
9710 "is currently supported.\n"));
9711 return 0;
9712 }
9713
9714 SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end);
9715 if (padding != 0)
9716 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
9717 padding);
9718
9719 SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end);
9720 if (comp_unit_count == 0)
9721 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
9722
9723 SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end);
9724 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end);
9725 SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end);
9726 SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end);
9727 SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end);
9728
9729 SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end);
9730 if (augmentation_string_size % 4 != 0)
9731 {
9732 warn (_("Augmentation string length %u must be rounded up "
9733 "to a multiple of 4 in .debug_names.\n"),
9734 augmentation_string_size);
9735 augmentation_string_size += (-augmentation_string_size) & 3;
9736 }
48467cb9 9737
61364358 9738 printf (_("Augmentation string:"));
48467cb9 9739
015dc7e1 9740 augmentation_printable = true;
48467cb9
TV
9741 augmentation_string = (const char *) hdrptr;
9742
61364358
JK
9743 for (i = 0; i < augmentation_string_size; i++)
9744 {
9745 unsigned char uc;
9746
9747 SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end);
9748 printf (" %02x", uc);
48467cb9
TV
9749
9750 if (uc != 0 && !ISPRINT (uc))
015dc7e1 9751 augmentation_printable = false;
48467cb9
TV
9752 }
9753
9754 if (augmentation_printable)
9755 {
9756 printf (" (\"");
9757 for (i = 0;
9758 i < augmentation_string_size && augmentation_string[i];
9759 ++i)
9760 putchar (augmentation_string[i]);
9761 printf ("\")");
61364358 9762 }
61364358
JK
9763 putchar ('\n');
9764
9765 printf (_("CU table:\n"));
9766 for (i = 0; i < comp_unit_count; i++)
9767 {
9768 uint64_t cu_offset;
9769
9770 SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end);
9771 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset);
9772 }
9773 putchar ('\n');
9774
9775 printf (_("TU table:\n"));
9776 for (i = 0; i < local_type_unit_count; i++)
9777 {
9778 uint64_t tu_offset;
9779
9780 SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end);
9781 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset);
9782 }
9783 putchar ('\n');
9784
9785 printf (_("Foreign TU table:\n"));
9786 for (i = 0; i < foreign_type_unit_count; i++)
9787 {
9788 uint64_t signature;
9789
9790 SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end);
9791 printf (_("[%3u] "), i);
9792 print_dwarf_vma (signature, 8);
9793 putchar ('\n');
9794 }
9795 putchar ('\n');
9796
9797 const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr;
9798 hdrptr += bucket_count * sizeof (uint32_t);
9799 const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr;
9800 hdrptr += name_count * sizeof (uint32_t);
9801 unsigned char *const name_table_string_offsets = hdrptr;
9802 hdrptr += name_count * offset_size;
9803 unsigned char *const name_table_entry_offsets = hdrptr;
9804 hdrptr += name_count * offset_size;
9805 unsigned char *const abbrev_table = hdrptr;
9806 hdrptr += abbrev_table_size;
9807 const unsigned char *const abbrev_table_end = hdrptr;
9808 unsigned char *const entry_pool = hdrptr;
9809 if (hdrptr > unit_end)
9810 {
9811 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
9812 "for unit 0x%lx in the debug_names\n"),
9813 (long) (hdrptr - section->start),
9814 (long) (unit_end - section->start),
9815 (long) (unit_start - section->start));
9816 return 0;
9817 }
9818
9819 size_t buckets_filled = 0;
9820 size_t bucketi;
9821 for (bucketi = 0; bucketi < bucket_count; bucketi++)
9822 {
9823 const uint32_t bucket = hash_table_buckets[bucketi];
9824
9825 if (bucket != 0)
9826 ++buckets_filled;
9827 }
d3a49aa8
AM
9828 printf (ngettext ("Used %zu of %lu bucket.\n",
9829 "Used %zu of %lu buckets.\n",
9830 bucket_count),
9831 buckets_filled, (unsigned long) bucket_count);
61364358 9832
0a79bef4 9833 uint32_t hash_prev = 0;
61364358
JK
9834 size_t hash_clash_count = 0;
9835 size_t longest_clash = 0;
9836 size_t this_length = 0;
9837 size_t hashi;
9838 for (hashi = 0; hashi < name_count; hashi++)
9839 {
9840 const uint32_t hash_this = hash_table_hashes[hashi];
9841
9842 if (hashi > 0)
9843 {
9844 if (hash_prev % bucket_count == hash_this % bucket_count)
9845 {
9846 ++hash_clash_count;
9847 ++this_length;
9848 longest_clash = MAX (longest_clash, this_length);
9849 }
9850 else
9851 this_length = 0;
9852 }
9853 hash_prev = hash_this;
9854 }
9855 printf (_("Out of %lu items there are %zu bucket clashes"
9856 " (longest of %zu entries).\n"),
9857 (unsigned long) name_count, hash_clash_count, longest_clash);
9858 assert (name_count == buckets_filled + hash_clash_count);
9859
9860 struct abbrev_lookup_entry
9861 {
9862 dwarf_vma abbrev_tag;
9863 unsigned char *abbrev_lookup_ptr;
9864 };
9865 struct abbrev_lookup_entry *abbrev_lookup = NULL;
9866 size_t abbrev_lookup_used = 0;
9867 size_t abbrev_lookup_allocated = 0;
9868
9869 unsigned char *abbrevptr = abbrev_table;
9870 for (;;)
9871 {
cd30bcef
AM
9872 dwarf_vma abbrev_tag;
9873
9874 READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end);
61364358
JK
9875 if (abbrev_tag == 0)
9876 break;
9877 if (abbrev_lookup_used == abbrev_lookup_allocated)
9878 {
9879 abbrev_lookup_allocated = MAX (0x100,
9880 abbrev_lookup_allocated * 2);
9881 abbrev_lookup = xrealloc (abbrev_lookup,
9882 (abbrev_lookup_allocated
9883 * sizeof (*abbrev_lookup)));
9884 }
9885 assert (abbrev_lookup_used < abbrev_lookup_allocated);
9886 struct abbrev_lookup_entry *entry;
9887 for (entry = abbrev_lookup;
9888 entry < abbrev_lookup + abbrev_lookup_used;
9889 entry++)
9890 if (entry->abbrev_tag == abbrev_tag)
9891 {
9892 warn (_("Duplicate abbreviation tag %lu "
9893 "in unit 0x%lx in the debug_names\n"),
9894 (long) abbrev_tag, (long) (unit_start - section->start));
9895 break;
9896 }
9897 entry = &abbrev_lookup[abbrev_lookup_used++];
9898 entry->abbrev_tag = abbrev_tag;
9899 entry->abbrev_lookup_ptr = abbrevptr;
9900
9901 /* Skip DWARF tag. */
cd30bcef 9902 SKIP_ULEB (abbrevptr, abbrev_table_end);
61364358
JK
9903 for (;;)
9904 {
cd30bcef
AM
9905 dwarf_vma xindex, form;
9906
9907 READ_ULEB (xindex, abbrevptr, abbrev_table_end);
9908 READ_ULEB (form, abbrevptr, abbrev_table_end);
1d827a72 9909 if (xindex == 0 && form == 0)
61364358
JK
9910 break;
9911 }
9912 }
9913
9914 printf (_("\nSymbol table:\n"));
9915 uint32_t namei;
9916 for (namei = 0; namei < name_count; ++namei)
9917 {
9918 uint64_t string_offset, entry_offset;
9919
9920 SAFE_BYTE_GET (string_offset,
9921 name_table_string_offsets + namei * offset_size,
9922 offset_size, unit_end);
9923 SAFE_BYTE_GET (entry_offset,
9924 name_table_entry_offsets + namei * offset_size,
9925 offset_size, unit_end);
9926
9927 printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei],
9928 fetch_indirect_string (string_offset));
9929
9930 unsigned char *entryptr = entry_pool + entry_offset;
9931
279edac5
AM
9932 /* We need to scan first whether there is a single or multiple
9933 entries. TAGNO is -2 for the first entry, it is -1 for the
9934 initial tag read of the second entry, then it becomes 0 for the
9935 first entry for real printing etc. */
61364358
JK
9936 int tagno = -2;
9937 /* Initialize it due to a false compiler warning. */
9938 dwarf_vma second_abbrev_tag = -1;
9939 for (;;)
9940 {
cd30bcef
AM
9941 dwarf_vma abbrev_tag;
9942 dwarf_vma dwarf_tag;
9943 const struct abbrev_lookup_entry *entry;
9944
9945 READ_ULEB (abbrev_tag, entryptr, unit_end);
61364358
JK
9946 if (tagno == -1)
9947 {
9948 second_abbrev_tag = abbrev_tag;
9949 tagno = 0;
9950 entryptr = entry_pool + entry_offset;
9951 continue;
9952 }
9953 if (abbrev_tag == 0)
9954 break;
9955 if (tagno >= 0)
9956 printf ("%s<%lu>",
9957 (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"),
9958 (unsigned long) abbrev_tag);
9959
61364358
JK
9960 for (entry = abbrev_lookup;
9961 entry < abbrev_lookup + abbrev_lookup_used;
9962 entry++)
9963 if (entry->abbrev_tag == abbrev_tag)
9964 break;
9965 if (entry >= abbrev_lookup + abbrev_lookup_used)
9966 {
9967 warn (_("Undefined abbreviation tag %lu "
9968 "in unit 0x%lx in the debug_names\n"),
9969 (long) abbrev_tag,
9970 (long) (unit_start - section->start));
9971 break;
9972 }
9973 abbrevptr = entry->abbrev_lookup_ptr;
cd30bcef 9974 READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end);
61364358
JK
9975 if (tagno >= 0)
9976 printf (" %s", get_TAG_name (dwarf_tag));
9977 for (;;)
9978 {
cd30bcef
AM
9979 dwarf_vma xindex, form;
9980
9981 READ_ULEB (xindex, abbrevptr, abbrev_table_end);
9982 READ_ULEB (form, abbrevptr, abbrev_table_end);
1d827a72 9983 if (xindex == 0 && form == 0)
61364358
JK
9984 break;
9985
9986 if (tagno >= 0)
1d827a72 9987 printf (" %s", get_IDX_name (xindex));
ec1b0fbb
NC
9988 entryptr = read_and_display_attr_value (0, form, 0,
9989 unit_start, entryptr, unit_end,
9990 0, 0, offset_size,
61364358
JK
9991 dwarf_version, NULL,
9992 (tagno < 0), NULL,
ec1b0fbb 9993 NULL, '=', -1);
61364358
JK
9994 }
9995 ++tagno;
9996 }
9997 if (tagno <= 0)
9998 printf (_(" <no entries>"));
9999 putchar ('\n');
10000 }
10001
10002 free (abbrev_lookup);
10003 }
10004
10005 return 1;
10006}
10007
dda8d76d 10008static int
d85bf2ba
NC
10009display_debug_links (struct dwarf_section * section,
10010 void * file ATTRIBUTE_UNUSED)
dda8d76d
NC
10011{
10012 const unsigned char * filename;
10013 unsigned int filelen;
10014
015dc7e1 10015 introduce (section, false);
dda8d76d
NC
10016
10017 /* The .gnu_debuglink section is formatted as:
10018 (c-string) Filename.
10019 (padding) If needed to reach a 4 byte boundary.
10020 (uint32_t) CRC32 value.
10021
10022 The .gun_debugaltlink section is formatted as:
10023 (c-string) Filename.
10024 (binary) Build-ID. */
521d4b19 10025
dda8d76d
NC
10026 filename = section->start;
10027 filelen = strnlen ((const char *) filename, section->size);
10028 if (filelen == section->size)
10029 {
10030 warn (_("The debuglink filename is corrupt/missing\n"));
10031 return 0;
10032 }
10033
10034 printf (_(" Separate debug info file: %s\n"), filename);
10035
24d127aa 10036 if (startswith (section->name, ".gnu_debuglink"))
dda8d76d
NC
10037 {
10038 unsigned int crc32;
10039 unsigned int crc_offset;
10040
10041 crc_offset = filelen + 1;
10042 crc_offset = (crc_offset + 3) & ~3;
10043 if (crc_offset + 4 > section->size)
10044 {
10045 warn (_("CRC offset missing/truncated\n"));
10046 return 0;
10047 }
10048
10049 crc32 = byte_get (filename + crc_offset, 4);
10050
10051 printf (_(" CRC value: %#x\n"), crc32);
10052
10053 if (crc_offset + 4 < section->size)
10054 {
10055 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
10056 (long)(section->size - (crc_offset + 4)));
10057 return 0;
10058 }
10059 }
24d127aa 10060 else /* startswith (section->name, ".gnu_debugaltlink") */
dda8d76d
NC
10061 {
10062 const unsigned char * build_id = section->start + filelen + 1;
10063 bfd_size_type build_id_len = section->size - (filelen + 1);
10064 bfd_size_type printed;
10065
10066 /* FIXME: Should we support smaller build-id notes ? */
10067 if (build_id_len < 0x14)
10068 {
10069 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len);
10070 return 0;
10071 }
10072
10073 printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len);
d85bf2ba 10074 display_data (printed, build_id, build_id_len);
dda8d76d
NC
10075 putchar ('\n');
10076 }
10077
10078 putchar ('\n');
10079 return 1;
10080}
10081
5bbdf3d5
DE
10082static int
10083display_gdb_index (struct dwarf_section *section,
10084 void *file ATTRIBUTE_UNUSED)
10085{
10086 unsigned char *start = section->start;
10087 uint32_t version;
10088 uint32_t cu_list_offset, tu_list_offset;
10089 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
10090 unsigned int cu_list_elements, tu_list_elements;
10091 unsigned int address_table_size, symbol_table_slots;
10092 unsigned char *cu_list, *tu_list;
10093 unsigned char *address_table, *symbol_table, *constant_pool;
10094 unsigned int i;
10095
10096 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10097
015dc7e1 10098 introduce (section, false);
5bbdf3d5
DE
10099
10100 if (section->size < 6 * sizeof (uint32_t))
10101 {
10102 warn (_("Truncated header in the %s section.\n"), section->name);
10103 return 0;
10104 }
10105
10106 version = byte_get_little_endian (start, 4);
da88a764 10107 printf (_("Version %ld\n"), (long) version);
5bbdf3d5
DE
10108
10109 /* Prior versions are obsolete, and future versions may not be
10110 backwards compatible. */
aa170720 10111 if (version < 3 || version > 8)
5bbdf3d5 10112 {
da88a764 10113 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
5bbdf3d5
DE
10114 return 0;
10115 }
8d6eee87
TT
10116 if (version < 4)
10117 warn (_("The address table data in version 3 may be wrong.\n"));
10118 if (version < 5)
10119 warn (_("Version 4 does not support case insensitive lookups.\n"));
10120 if (version < 6)
10121 warn (_("Version 5 does not include inlined functions.\n"));
10122 if (version < 7)
10123 warn (_("Version 6 does not include symbol attributes.\n"));
aa170720
DE
10124 /* Version 7 indices generated by Gold have bad type unit references,
10125 PR binutils/15021. But we don't know if the index was generated by
10126 Gold or not, so to avoid worrying users with gdb-generated indices
10127 we say nothing for version 7 here. */
5bbdf3d5
DE
10128
10129 cu_list_offset = byte_get_little_endian (start + 4, 4);
10130 tu_list_offset = byte_get_little_endian (start + 8, 4);
10131 address_table_offset = byte_get_little_endian (start + 12, 4);
10132 symbol_table_offset = byte_get_little_endian (start + 16, 4);
10133 constant_pool_offset = byte_get_little_endian (start + 20, 4);
10134
10135 if (cu_list_offset > section->size
10136 || tu_list_offset > section->size
10137 || address_table_offset > section->size
10138 || symbol_table_offset > section->size
10139 || constant_pool_offset > section->size)
10140 {
10141 warn (_("Corrupt header in the %s section.\n"), section->name);
10142 return 0;
10143 }
10144
53774b7e
NC
10145 /* PR 17531: file: 418d0a8a. */
10146 if (tu_list_offset < cu_list_offset)
10147 {
10148 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
10149 tu_list_offset, cu_list_offset);
10150 return 0;
10151 }
10152
5bbdf3d5 10153 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
53774b7e
NC
10154
10155 if (address_table_offset < tu_list_offset)
10156 {
10157 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
10158 address_table_offset, tu_list_offset);
10159 return 0;
10160 }
10161
5bbdf3d5 10162 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
53774b7e
NC
10163
10164 /* PR 17531: file: 18a47d3d. */
10165 if (symbol_table_offset < address_table_offset)
10166 {
13bace4a 10167 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
53774b7e
NC
10168 symbol_table_offset, address_table_offset);
10169 return 0;
10170 }
10171
5bbdf3d5 10172 address_table_size = symbol_table_offset - address_table_offset;
53774b7e
NC
10173
10174 if (constant_pool_offset < symbol_table_offset)
10175 {
10176 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
10177 constant_pool_offset, symbol_table_offset);
10178 return 0;
10179 }
10180
5bbdf3d5
DE
10181 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
10182
10183 cu_list = start + cu_list_offset;
10184 tu_list = start + tu_list_offset;
10185 address_table = start + address_table_offset;
10186 symbol_table = start + symbol_table_offset;
10187 constant_pool = start + constant_pool_offset;
10188
28d909e5 10189 if (address_table + address_table_size > section->start + section->size)
acff9664 10190 {
1306a742 10191 warn (_("Address table extends beyond end of section.\n"));
acff9664
NC
10192 return 0;
10193 }
b4eb7656 10194
5bbdf3d5
DE
10195 printf (_("\nCU table:\n"));
10196 for (i = 0; i < cu_list_elements; i += 2)
10197 {
10198 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
10199 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
10200
10201 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
10202 (unsigned long) cu_offset,
10203 (unsigned long) (cu_offset + cu_length - 1));
10204 }
10205
10206 printf (_("\nTU table:\n"));
10207 for (i = 0; i < tu_list_elements; i += 3)
10208 {
10209 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
10210 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
10211 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
10212
10213 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
10214 (unsigned long) tu_offset,
10215 (unsigned long) type_offset);
10216 print_dwarf_vma (signature, 8);
10217 printf ("\n");
10218 }
10219
10220 printf (_("\nAddress table:\n"));
acff9664
NC
10221 for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
10222 i += 2 * 8 + 4)
5bbdf3d5
DE
10223 {
10224 uint64_t low = byte_get_little_endian (address_table + i, 8);
10225 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
10226 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
10227
10228 print_dwarf_vma (low, 8);
10229 print_dwarf_vma (high, 8);
da88a764 10230 printf (_("%lu\n"), (unsigned long) cu_index);
5bbdf3d5
DE
10231 }
10232
10233 printf (_("\nSymbol table:\n"));
10234 for (i = 0; i < symbol_table_slots; ++i)
10235 {
10236 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
10237 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
10238 uint32_t num_cus, cu;
10239
10240 if (name_offset != 0
10241 || cu_vector_offset != 0)
10242 {
10243 unsigned int j;
362beea4 10244 unsigned char * adr;
5bbdf3d5 10245
362beea4 10246 adr = constant_pool + name_offset;
53774b7e 10247 /* PR 17531: file: 5b7b07ad. */
362beea4 10248 if (adr < constant_pool || adr >= section->start + section->size)
53774b7e
NC
10249 {
10250 printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
10251 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10252 name_offset, i);
10253 }
10254 else
acff9664
NC
10255 printf ("[%3u] %.*s:", i,
10256 (int) (section->size - (constant_pool_offset + name_offset)),
10257 constant_pool + name_offset);
53774b7e 10258
362beea4
NC
10259 adr = constant_pool + cu_vector_offset;
10260 if (adr < constant_pool || adr >= section->start + section->size - 3)
53774b7e
NC
10261 {
10262 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
10263 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10264 cu_vector_offset, i);
10265 continue;
10266 }
57028622 10267
362beea4 10268 num_cus = byte_get_little_endian (adr, 4);
53774b7e 10269
362beea4 10270 adr = constant_pool + cu_vector_offset + 4 + num_cus * 4;
acff9664 10271 if (num_cus * 4 < num_cus
362beea4
NC
10272 || adr >= section->start + section->size
10273 || adr < constant_pool)
53774b7e
NC
10274 {
10275 printf ("<invalid number of CUs: %d>\n", num_cus);
acff9664 10276 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
53774b7e
NC
10277 num_cus, i);
10278 continue;
10279 }
10280
8d6eee87
TT
10281 if (num_cus > 1)
10282 printf ("\n");
f3853b34 10283
5bbdf3d5
DE
10284 for (j = 0; j < num_cus; ++j)
10285 {
7c1cef97 10286 int is_static;
8d6eee87
TT
10287 gdb_index_symbol_kind kind;
10288
5bbdf3d5 10289 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
7c1cef97 10290 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
8d6eee87
TT
10291 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
10292 cu = GDB_INDEX_CU_VALUE (cu);
5bbdf3d5 10293 /* Convert to TU number if it's for a type unit. */
ad6b52dd 10294 if (cu >= cu_list_elements / 2)
8d6eee87
TT
10295 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
10296 (unsigned long) (cu - cu_list_elements / 2));
5bbdf3d5 10297 else
8d6eee87
TT
10298 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
10299
459d52c8
DE
10300 printf (" [%s, %s]",
10301 is_static ? _("static") : _("global"),
10302 get_gdb_index_symbol_kind_name (kind));
8d6eee87
TT
10303 if (num_cus > 1)
10304 printf ("\n");
5bbdf3d5 10305 }
8d6eee87
TT
10306 if (num_cus <= 1)
10307 printf ("\n");
5bbdf3d5
DE
10308 }
10309 }
10310
10311 return 1;
10312}
10313
657d0d47
CC
10314/* Pre-allocate enough space for the CU/TU sets needed. */
10315
10316static void
10317prealloc_cu_tu_list (unsigned int nshndx)
10318{
10319 if (shndx_pool == NULL)
10320 {
10321 shndx_pool_size = nshndx;
10322 shndx_pool_used = 0;
10323 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
10324 sizeof (unsigned int));
10325 }
10326 else
10327 {
10328 shndx_pool_size = shndx_pool_used + nshndx;
10329 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
10330 sizeof (unsigned int));
10331 }
10332}
10333
10334static void
10335add_shndx_to_cu_tu_entry (unsigned int shndx)
10336{
10337 if (shndx_pool_used >= shndx_pool_size)
10338 {
10339 error (_("Internal error: out of space in the shndx pool.\n"));
10340 return;
10341 }
10342 shndx_pool [shndx_pool_used++] = shndx;
10343}
10344
10345static void
10346end_cu_tu_entry (void)
10347{
10348 if (shndx_pool_used >= shndx_pool_size)
10349 {
10350 error (_("Internal error: out of space in the shndx pool.\n"));
10351 return;
10352 }
10353 shndx_pool [shndx_pool_used++] = 0;
10354}
10355
341f9135
CC
10356/* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10357
10358static const char *
10359get_DW_SECT_short_name (unsigned int dw_sect)
10360{
10361 static char buf[16];
10362
10363 switch (dw_sect)
10364 {
10365 case DW_SECT_INFO:
10366 return "info";
10367 case DW_SECT_TYPES:
10368 return "types";
10369 case DW_SECT_ABBREV:
10370 return "abbrev";
10371 case DW_SECT_LINE:
10372 return "line";
10373 case DW_SECT_LOC:
10374 return "loc";
10375 case DW_SECT_STR_OFFSETS:
10376 return "str_off";
10377 case DW_SECT_MACINFO:
10378 return "macinfo";
10379 case DW_SECT_MACRO:
10380 return "macro";
10381 default:
b4eb7656 10382 break;
341f9135
CC
10383 }
10384
10385 snprintf (buf, sizeof (buf), "%d", dw_sect);
10386 return buf;
10387}
10388
10389/* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10390 These sections are extensions for Fission.
10391 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
657d0d47
CC
10392
10393static int
10394process_cu_tu_index (struct dwarf_section *section, int do_display)
10395{
10396 unsigned char *phdr = section->start;
10397 unsigned char *limit = phdr + section->size;
10398 unsigned char *phash;
10399 unsigned char *pindex;
10400 unsigned char *ppool;
10401 unsigned int version;
341f9135 10402 unsigned int ncols = 0;
657d0d47
CC
10403 unsigned int nused;
10404 unsigned int nslots;
10405 unsigned int i;
341f9135
CC
10406 unsigned int j;
10407 dwarf_vma signature_high;
10408 dwarf_vma signature_low;
10409 char buf[64];
657d0d47 10410
6937bb54
NC
10411 /* PR 17512: file: 002-168123-0.004. */
10412 if (phdr == NULL)
10413 {
10414 warn (_("Section %s is empty\n"), section->name);
10415 return 0;
10416 }
10417 /* PR 17512: file: 002-376-0.004. */
10418 if (section->size < 24)
10419 {
72c61a0d 10420 warn (_("Section %s is too small to contain a CU/TU header\n"),
6937bb54
NC
10421 section->name);
10422 return 0;
10423 }
10424
10425 SAFE_BYTE_GET (version, phdr, 4, limit);
341f9135 10426 if (version >= 2)
6937bb54
NC
10427 SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
10428 SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
10429 SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
10430
657d0d47 10431 phash = phdr + 16;
8e2e3c6c
AM
10432 pindex = phash + (size_t) nslots * 8;
10433 ppool = pindex + (size_t) nslots * 4;
57028622 10434
657d0d47
CC
10435 if (do_display)
10436 {
015dc7e1 10437 introduce (section, false);
dda8d76d 10438
8e2e3c6c 10439 printf (_(" Version: %u\n"), version);
341f9135 10440 if (version >= 2)
8e2e3c6c
AM
10441 printf (_(" Number of columns: %u\n"), ncols);
10442 printf (_(" Number of used entries: %u\n"), nused);
10443 printf (_(" Number of slots: %u\n\n"), nslots);
657d0d47
CC
10444 }
10445
8e2e3c6c
AM
10446 /* PR 17531: file: 45d69832. */
10447 if ((size_t) nslots * 8 / 8 != nslots
10448 || phash < phdr || phash > limit
10449 || pindex < phash || pindex > limit
10450 || ppool < pindex || ppool > limit)
657d0d47 10451 {
8e2e3c6c
AM
10452 warn (ngettext ("Section %s is too small for %u slot\n",
10453 "Section %s is too small for %u slots\n",
10454 nslots),
657d0d47
CC
10455 section->name, nslots);
10456 return 0;
10457 }
10458
341f9135 10459 if (version == 1)
657d0d47 10460 {
341f9135
CC
10461 if (!do_display)
10462 prealloc_cu_tu_list ((limit - ppool) / 4);
10463 for (i = 0; i < nslots; i++)
657d0d47 10464 {
341f9135
CC
10465 unsigned char *shndx_list;
10466 unsigned int shndx;
10467
6937bb54 10468 SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
341f9135 10469 if (signature_high != 0 || signature_low != 0)
657d0d47 10470 {
6937bb54 10471 SAFE_BYTE_GET (j, pindex, 4, limit);
341f9135 10472 shndx_list = ppool + j * 4;
f3853b34
NC
10473 /* PR 17531: file: 705e010d. */
10474 if (shndx_list < ppool)
10475 {
10476 warn (_("Section index pool located before start of section\n"));
10477 return 0;
10478 }
10479
341f9135
CC
10480 if (do_display)
10481 printf (_(" [%3d] Signature: 0x%s Sections: "),
10482 i, dwarf_vmatoa64 (signature_high, signature_low,
10483 buf, sizeof (buf)));
10484 for (;;)
657d0d47 10485 {
341f9135
CC
10486 if (shndx_list >= limit)
10487 {
10488 warn (_("Section %s too small for shndx pool\n"),
10489 section->name);
10490 return 0;
10491 }
6937bb54 10492 SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
341f9135
CC
10493 if (shndx == 0)
10494 break;
10495 if (do_display)
10496 printf (" %d", shndx);
10497 else
10498 add_shndx_to_cu_tu_entry (shndx);
10499 shndx_list += 4;
657d0d47 10500 }
657d0d47 10501 if (do_display)
341f9135 10502 printf ("\n");
657d0d47 10503 else
341f9135
CC
10504 end_cu_tu_entry ();
10505 }
10506 phash += 8;
10507 pindex += 4;
10508 }
10509 }
10510 else if (version == 2)
10511 {
10512 unsigned int val;
10513 unsigned int dw_sect;
10514 unsigned char *ph = phash;
10515 unsigned char *pi = pindex;
8e2e3c6c
AM
10516 unsigned char *poffsets = ppool + (size_t) ncols * 4;
10517 unsigned char *psizes = poffsets + (size_t) nused * ncols * 4;
10518 unsigned char *pend = psizes + (size_t) nused * ncols * 4;
015dc7e1 10519 bool is_tu_index;
341f9135
CC
10520 struct cu_tu_set *this_set = NULL;
10521 unsigned int row;
10522 unsigned char *prow;
10523
10524 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
10525
362beea4 10526 /* PR 17531: file: 0dd159bf.
8e2e3c6c
AM
10527 Check for integer overflow (can occur when size_t is 32-bit)
10528 with overlarge ncols or nused values. */
4ac948a0
NC
10529 if (ncols > 0
10530 && ((size_t) ncols * 4 / 4 != ncols
10531 || (size_t) nused * ncols * 4 / ((size_t) ncols * 4) != nused
10532 || poffsets < ppool || poffsets > limit
10533 || psizes < poffsets || psizes > limit
10534 || pend < psizes || pend > limit))
341f9135
CC
10535 {
10536 warn (_("Section %s too small for offset and size tables\n"),
10537 section->name);
10538 return 0;
10539 }
10540
10541 if (do_display)
10542 {
10543 printf (_(" Offset table\n"));
10544 printf (" slot %-16s ",
10545 is_tu_index ? _("signature") : _("dwo_id"));
10546 }
10547 else
10548 {
10549 if (is_tu_index)
10550 {
10551 tu_count = nused;
72c61a0d 10552 tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
341f9135 10553 this_set = tu_sets;
657d0d47 10554 }
657d0d47 10555 else
341f9135
CC
10556 {
10557 cu_count = nused;
72c61a0d 10558 cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
341f9135
CC
10559 this_set = cu_sets;
10560 }
10561 }
6937bb54 10562
341f9135
CC
10563 if (do_display)
10564 {
10565 for (j = 0; j < ncols; j++)
10566 {
6937bb54 10567 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
341f9135
CC
10568 printf (" %8s", get_DW_SECT_short_name (dw_sect));
10569 }
10570 printf ("\n");
10571 }
6937bb54 10572
341f9135
CC
10573 for (i = 0; i < nslots; i++)
10574 {
6937bb54
NC
10575 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
10576
10577 SAFE_BYTE_GET (row, pi, 4, limit);
341f9135
CC
10578 if (row != 0)
10579 {
591f7597 10580 /* PR 17531: file: a05f6ab3. */
ef77750e 10581 if (row > nused)
591f7597
NC
10582 {
10583 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10584 row, nused);
10585 return 0;
10586 }
10587
341f9135 10588 if (!do_display)
6aea08d9
NC
10589 {
10590 size_t num_copy = sizeof (uint64_t);
10591
10592 /* PR 23064: Beware of buffer overflow. */
10593 if (ph + num_copy < limit)
10594 memcpy (&this_set[row - 1].signature, ph, num_copy);
10595 else
10596 {
10597 warn (_("Signature (%p) extends beyond end of space in section\n"), ph);
10598 return 0;
10599 }
10600 }
6937bb54 10601
341f9135 10602 prow = poffsets + (row - 1) * ncols * 4;
ffc0f143
NC
10603 /* PR 17531: file: b8ce60a8. */
10604 if (prow < poffsets || prow > limit)
10605 {
10606 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
10607 row, ncols);
10608 return 0;
10609 }
3aade688 10610
341f9135
CC
10611 if (do_display)
10612 printf (_(" [%3d] 0x%s"),
10613 i, dwarf_vmatoa64 (signature_high, signature_low,
10614 buf, sizeof (buf)));
10615 for (j = 0; j < ncols; j++)
10616 {
6937bb54 10617 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
341f9135
CC
10618 if (do_display)
10619 printf (" %8d", val);
10620 else
10621 {
6937bb54 10622 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
82b1b41b
NC
10623
10624 /* PR 17531: file: 10796eb3. */
10625 if (dw_sect >= DW_SECT_MAX)
10626 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
10627 else
10628 this_set [row - 1].section_offsets [dw_sect] = val;
341f9135
CC
10629 }
10630 }
6937bb54 10631
341f9135
CC
10632 if (do_display)
10633 printf ("\n");
10634 }
10635 ph += 8;
10636 pi += 4;
10637 }
10638
10639 ph = phash;
10640 pi = pindex;
10641 if (do_display)
b4eb7656 10642 {
341f9135
CC
10643 printf ("\n");
10644 printf (_(" Size table\n"));
10645 printf (" slot %-16s ",
10646 is_tu_index ? _("signature") : _("dwo_id"));
b4eb7656 10647 }
6937bb54 10648
341f9135
CC
10649 for (j = 0; j < ncols; j++)
10650 {
6937bb54 10651 SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
341f9135
CC
10652 if (do_display)
10653 printf (" %8s", get_DW_SECT_short_name (val));
10654 }
6937bb54 10655
341f9135
CC
10656 if (do_display)
10657 printf ("\n");
6937bb54 10658
341f9135
CC
10659 for (i = 0; i < nslots; i++)
10660 {
6937bb54
NC
10661 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
10662
10663 SAFE_BYTE_GET (row, pi, 4, limit);
341f9135
CC
10664 if (row != 0)
10665 {
10666 prow = psizes + (row - 1) * ncols * 4;
6937bb54 10667
341f9135
CC
10668 if (do_display)
10669 printf (_(" [%3d] 0x%s"),
10670 i, dwarf_vmatoa64 (signature_high, signature_low,
10671 buf, sizeof (buf)));
6937bb54 10672
341f9135
CC
10673 for (j = 0; j < ncols; j++)
10674 {
6937bb54 10675 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
341f9135
CC
10676 if (do_display)
10677 printf (" %8d", val);
10678 else
10679 {
6937bb54 10680 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
82b1b41b
NC
10681 if (dw_sect >= DW_SECT_MAX)
10682 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
10683 else
341f9135
CC
10684 this_set [row - 1].section_sizes [dw_sect] = val;
10685 }
10686 }
6937bb54 10687
341f9135
CC
10688 if (do_display)
10689 printf ("\n");
10690 }
6937bb54 10691
341f9135
CC
10692 ph += 8;
10693 pi += 4;
657d0d47 10694 }
657d0d47 10695 }
341f9135 10696 else if (do_display)
6937bb54 10697 printf (_(" Unsupported version (%d)\n"), version);
657d0d47
CC
10698
10699 if (do_display)
10700 printf ("\n");
10701
10702 return 1;
10703}
10704
288f0ba2
AM
10705static int cu_tu_indexes_read = -1; /* Tri-state variable. */
10706
657d0d47
CC
10707/* Load the CU and TU indexes if present. This will build a list of
10708 section sets that we can use to associate a .debug_info.dwo section
10709 with its associated .debug_abbrev.dwo section in a .dwp file. */
10710
015dc7e1 10711static bool
657d0d47
CC
10712load_cu_tu_indexes (void *file)
10713{
10714 /* If we have already loaded (or tried to load) the CU and TU indexes
10715 then do not bother to repeat the task. */
43a444f9
NC
10716 if (cu_tu_indexes_read == -1)
10717 {
015dc7e1 10718 cu_tu_indexes_read = true;
521d4b19 10719
dda8d76d 10720 if (load_debug_section_with_follow (dwp_cu_index, file))
43a444f9 10721 if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0))
015dc7e1 10722 cu_tu_indexes_read = false;
43a444f9 10723
dda8d76d 10724 if (load_debug_section_with_follow (dwp_tu_index, file))
43a444f9 10725 if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0))
015dc7e1 10726 cu_tu_indexes_read = false;
43a444f9 10727 }
657d0d47 10728
015dc7e1 10729 return (bool) cu_tu_indexes_read;
657d0d47
CC
10730}
10731
10732/* Find the set of sections that includes section SHNDX. */
10733
10734unsigned int *
10735find_cu_tu_set (void *file, unsigned int shndx)
10736{
10737 unsigned int i;
10738
43a444f9
NC
10739 if (! load_cu_tu_indexes (file))
10740 return NULL;
657d0d47
CC
10741
10742 /* Find SHNDX in the shndx pool. */
10743 for (i = 0; i < shndx_pool_used; i++)
10744 if (shndx_pool [i] == shndx)
10745 break;
10746
10747 if (i >= shndx_pool_used)
10748 return NULL;
10749
10750 /* Now backup to find the first entry in the set. */
10751 while (i > 0 && shndx_pool [i - 1] != 0)
10752 i--;
10753
10754 return shndx_pool + i;
10755}
10756
10757/* Display a .debug_cu_index or .debug_tu_index section. */
10758
10759static int
10760display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
10761{
10762 return process_cu_tu_index (section, 1);
10763}
10764
19e6b90e
L
10765static int
10766display_debug_not_supported (struct dwarf_section *section,
10767 void *file ATTRIBUTE_UNUSED)
10768{
10769 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10770 section->name);
10771
10772 return 1;
10773}
10774
1306a742
NC
10775/* Like malloc, but takes two parameters like calloc.
10776 Verifies that the first parameter is not too large.
82b1b41b 10777 Note: does *not* initialise the allocated memory to zero. */
dda8d76d 10778
19e6b90e
L
10779void *
10780cmalloc (size_t nmemb, size_t size)
10781{
10782 /* Check for overflow. */
10783 if (nmemb >= ~(size_t) 0 / size)
10784 return NULL;
82b1b41b
NC
10785
10786 return xmalloc (nmemb * size);
19e6b90e
L
10787}
10788
1306a742
NC
10789/* Like xmalloc, but takes two parameters like calloc.
10790 Verifies that the first parameter is not too large.
10791 Note: does *not* initialise the allocated memory to zero. */
dda8d76d 10792
72c61a0d 10793void *
1306a742 10794xcmalloc (size_t nmemb, size_t size)
72c61a0d
NC
10795{
10796 /* Check for overflow. */
10797 if (nmemb >= ~(size_t) 0 / size)
8490fb40
NC
10798 {
10799 fprintf (stderr,
10800 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
10801 (long) nmemb);
10802 xexit (1);
10803 }
72c61a0d 10804
1306a742 10805 return xmalloc (nmemb * size);
72c61a0d
NC
10806}
10807
1306a742
NC
10808/* Like xrealloc, but takes three parameters.
10809 Verifies that the second parameter is not too large.
10810 Note: does *not* initialise any new memory to zero. */
dda8d76d 10811
19e6b90e 10812void *
1306a742 10813xcrealloc (void *ptr, size_t nmemb, size_t size)
19e6b90e
L
10814{
10815 /* Check for overflow. */
10816 if (nmemb >= ~(size_t) 0 / size)
8490fb40 10817 {
dda8d76d
NC
10818 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
10819 (long) nmemb);
8490fb40
NC
10820 xexit (1);
10821 }
82b1b41b 10822
1306a742 10823 return xrealloc (ptr, nmemb * size);
19e6b90e
L
10824}
10825
1306a742 10826/* Like xcalloc, but verifies that the first parameter is not too large. */
dda8d76d 10827
19e6b90e 10828void *
1306a742 10829xcalloc2 (size_t nmemb, size_t size)
19e6b90e
L
10830{
10831 /* Check for overflow. */
10832 if (nmemb >= ~(size_t) 0 / size)
8490fb40 10833 {
dda8d76d
NC
10834 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
10835 (long) nmemb);
8490fb40
NC
10836 xexit (1);
10837 }
82b1b41b 10838
1306a742 10839 return xcalloc (nmemb, size);
19e6b90e
L
10840}
10841
dda8d76d
NC
10842static unsigned long
10843calc_gnu_debuglink_crc32 (unsigned long crc,
10844 const unsigned char * buf,
10845 bfd_size_type len)
10846{
10847 static const unsigned long crc32_table[256] =
10848 {
10849 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10850 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10851 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10852 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10853 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10854 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10855 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10856 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10857 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10858 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10859 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10860 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10861 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10862 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10863 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10864 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10865 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10866 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10867 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10868 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10869 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10870 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10871 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10872 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10873 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10874 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10875 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10876 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10877 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10878 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10879 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10880 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10881 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10882 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10883 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10884 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10885 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10886 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10887 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10888 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10889 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10890 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10891 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10892 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10893 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10894 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10895 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10896 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10897 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10898 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10899 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10900 0x2d02ef8d
10901 };
10902 const unsigned char *end;
10903
10904 crc = ~crc & 0xffffffff;
10905 for (end = buf + len; buf < end; ++ buf)
10906 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
10907 return ~crc & 0xffffffff;
10908}
10909
015dc7e1
AM
10910typedef bool (*check_func_type) (const char *, void *);
10911typedef const char *(* parse_func_type) (struct dwarf_section *, void *);
dda8d76d 10912
015dc7e1 10913static bool
dda8d76d
NC
10914check_gnu_debuglink (const char * pathname, void * crc_pointer)
10915{
10916 static unsigned char buffer [8 * 1024];
10917 FILE * f;
10918 bfd_size_type count;
10919 unsigned long crc = 0;
10920 void * sep_data;
10921
10922 sep_data = open_debug_file (pathname);
10923 if (sep_data == NULL)
015dc7e1 10924 return false;
dda8d76d
NC
10925
10926 /* Yes - we are opening the file twice... */
10927 f = fopen (pathname, "rb");
10928 if (f == NULL)
10929 {
10930 /* Paranoia: This should never happen. */
10931 close_debug_file (sep_data);
10932 warn (_("Unable to reopen separate debug info file: %s\n"), pathname);
015dc7e1 10933 return false;
dda8d76d
NC
10934 }
10935
10936 while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0)
10937 crc = calc_gnu_debuglink_crc32 (crc, buffer, count);
10938
10939 fclose (f);
10940
10941 if (crc != * (unsigned long *) crc_pointer)
10942 {
10943 close_debug_file (sep_data);
10944 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10945 pathname);
015dc7e1 10946 return false;
dda8d76d
NC
10947 }
10948
015dc7e1 10949 return true;
dda8d76d
NC
10950}
10951
10952static const char *
10953parse_gnu_debuglink (struct dwarf_section * section, void * data)
10954{
10955 const char * name;
10956 unsigned int crc_offset;
10957 unsigned long * crc32 = (unsigned long *) data;
10958
10959 /* The name is first.
10960 The CRC value is stored after the filename, aligned up to 4 bytes. */
10961 name = (const char *) section->start;
10962
10963 crc_offset = strnlen (name, section->size) + 1;
3d64c987
NC
10964 if (crc_offset == 1)
10965 return NULL;
dda8d76d
NC
10966 crc_offset = (crc_offset + 3) & ~3;
10967 if (crc_offset + 4 > section->size)
10968 return NULL;
10969
10970 * crc32 = byte_get (section->start + crc_offset, 4);
10971 return name;
10972}
10973
015dc7e1 10974static bool
dda8d76d
NC
10975check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED)
10976{
10977 void * sep_data = open_debug_file (filename);
10978
10979 if (sep_data == NULL)
015dc7e1 10980 return false;
dda8d76d
NC
10981
10982 /* FIXME: We should now extract the build-id in the separate file
10983 and check it... */
10984
015dc7e1 10985 return true;
dda8d76d
NC
10986}
10987
10988typedef struct build_id_data
10989{
10990 bfd_size_type len;
10991 const unsigned char * data;
10992} Build_id_data;
10993
10994static const char *
10995parse_gnu_debugaltlink (struct dwarf_section * section, void * data)
10996{
10997 const char * name;
10998 bfd_size_type namelen;
10999 bfd_size_type id_len;
11000 Build_id_data * build_id_data;
11001
11002 /* The name is first.
11003 The build-id follows immediately, with no padding, up to the section's end. */
11004
11005 name = (const char *) section->start;
11006 namelen = strnlen (name, section->size) + 1;
3d64c987
NC
11007 if (namelen == 1)
11008 return NULL;
dda8d76d
NC
11009 if (namelen >= section->size)
11010 return NULL;
11011
11012 id_len = section->size - namelen;
11013 if (id_len < 0x14)
11014 return NULL;
11015
dfbee680 11016 build_id_data = (Build_id_data *) data;
dda8d76d
NC
11017 build_id_data->len = id_len;
11018 build_id_data->data = section->start + namelen;
11019
dda8d76d
NC
11020 return name;
11021}
11022
24841daa
NC
11023static void
11024add_separate_debug_file (const char * filename, void * handle)
11025{
11026 separate_info * i = xmalloc (sizeof * i);
11027
11028 i->filename = filename;
11029 i->handle = handle;
11030 i->next = first_separate_info;
11031 first_separate_info = i;
11032}
11033
301a9420
AM
11034#if HAVE_LIBDEBUGINFOD
11035/* Query debuginfod servers for the target debuglink or debugaltlink
11036 file. If successful, store the path of the file in filename and
11037 return TRUE, otherwise return FALSE. */
11038
015dc7e1 11039static bool
301a9420
AM
11040debuginfod_fetch_separate_debug_info (struct dwarf_section * section,
11041 char ** filename,
11042 void * file)
11043{
11044 size_t build_id_len;
11045 unsigned char * build_id;
11046
11047 if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0)
11048 {
11049 /* Get the build-id of file. */
11050 build_id = get_build_id (file);
11051 build_id_len = 0;
11052 }
11053 else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0)
11054 {
11055 /* Get the build-id of the debugaltlink file. */
11056 unsigned int filelen;
11057
11058 filelen = strnlen ((const char *)section->start, section->size);
11059 if (filelen == section->size)
11060 /* Corrupt debugaltlink. */
015dc7e1 11061 return false;
301a9420
AM
11062
11063 build_id = section->start + filelen + 1;
11064 build_id_len = section->size - (filelen + 1);
11065
11066 if (build_id_len == 0)
015dc7e1 11067 return false;
301a9420
AM
11068 }
11069 else
015dc7e1 11070 return false;
301a9420
AM
11071
11072 if (build_id)
11073 {
11074 int fd;
11075 debuginfod_client * client;
11076
11077 client = debuginfod_begin ();
11078 if (client == NULL)
015dc7e1 11079 return false;
301a9420
AM
11080
11081 /* Query debuginfod servers for the target file. If found its path
11082 will be stored in filename. */
11083 fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename);
11084 debuginfod_end (client);
11085
11086 /* Only free build_id if we allocated space for a hex string
11087 in get_build_id (). */
11088 if (build_id_len == 0)
11089 free (build_id);
11090
11091 if (fd >= 0)
11092 {
11093 /* File successfully retrieved. Close fd since we want to
11094 use open_debug_file () on filename instead. */
11095 close (fd);
015dc7e1 11096 return true;
301a9420
AM
11097 }
11098 }
11099
015dc7e1 11100 return false;
301a9420
AM
11101}
11102#endif
11103
dda8d76d
NC
11104static void *
11105load_separate_debug_info (const char * main_filename,
2b63c337 11106 struct dwarf_section * xlink,
dda8d76d
NC
11107 parse_func_type parse_func,
11108 check_func_type check_func,
301a9420
AM
11109 void * func_data,
11110 void * file ATTRIBUTE_UNUSED)
dda8d76d
NC
11111{
11112 const char * separate_filename;
24841daa 11113 char * debug_filename;
dda8d76d
NC
11114 char * canon_dir;
11115 size_t canon_dirlen;
11116 size_t dirlen;
11117
2b63c337 11118 if ((separate_filename = parse_func (xlink, func_data)) == NULL)
dda8d76d
NC
11119 {
11120 warn (_("Corrupt debuglink section: %s\n"),
2b63c337 11121 xlink->name ? xlink->name : xlink->uncompressed_name);
ce139cd5 11122 return NULL;
dda8d76d 11123 }
521d4b19 11124
dda8d76d
NC
11125 /* Attempt to locate the separate file.
11126 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11127
11128 canon_dir = lrealpath (main_filename);
521d4b19 11129
dda8d76d
NC
11130 for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--)
11131 if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1]))
11132 break;
11133 canon_dir[canon_dirlen] = '\0';
11134
11135#ifndef DEBUGDIR
11136#define DEBUGDIR "/lib/debug"
11137#endif
11138#ifndef EXTRA_DEBUG_ROOT1
11139#define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11140#endif
11141#ifndef EXTRA_DEBUG_ROOT2
11142#define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11143#endif
11144
24841daa
NC
11145 debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1
11146 + canon_dirlen
11147 + strlen (".debug/")
dda8d76d 11148#ifdef EXTRA_DEBUG_ROOT1
24841daa 11149 + strlen (EXTRA_DEBUG_ROOT1)
dda8d76d
NC
11150#endif
11151#ifdef EXTRA_DEBUG_ROOT2
24841daa 11152 + strlen (EXTRA_DEBUG_ROOT2)
dda8d76d 11153#endif
24841daa
NC
11154 + strlen (separate_filename)
11155 + 1);
11156 if (debug_filename == NULL)
dda8d76d
NC
11157 {
11158 warn (_("Out of memory"));
3391569f 11159 free (canon_dir);
dda8d76d
NC
11160 return NULL;
11161 }
11162
11163 /* First try in the current directory. */
24841daa
NC
11164 sprintf (debug_filename, "%s", separate_filename);
11165 if (check_func (debug_filename, func_data))
dda8d76d
NC
11166 goto found;
11167
11168 /* Then try in a subdirectory called .debug. */
24841daa
NC
11169 sprintf (debug_filename, ".debug/%s", separate_filename);
11170 if (check_func (debug_filename, func_data))
dda8d76d
NC
11171 goto found;
11172
11173 /* Then try in the same directory as the original file. */
24841daa
NC
11174 sprintf (debug_filename, "%s%s", canon_dir, separate_filename);
11175 if (check_func (debug_filename, func_data))
dda8d76d
NC
11176 goto found;
11177
11178 /* And the .debug subdirectory of that directory. */
24841daa
NC
11179 sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename);
11180 if (check_func (debug_filename, func_data))
dda8d76d
NC
11181 goto found;
11182
11183#ifdef EXTRA_DEBUG_ROOT1
11184 /* Try the first extra debug file root. */
24841daa
NC
11185 sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename);
11186 if (check_func (debug_filename, func_data))
dda8d76d 11187 goto found;
39f0547e
NC
11188
11189 /* Try the first extra debug file root. */
11190 sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename);
11191 if (check_func (debug_filename, func_data))
11192 goto found;
dda8d76d
NC
11193#endif
11194
11195#ifdef EXTRA_DEBUG_ROOT2
11196 /* Try the second extra debug file root. */
24841daa
NC
11197 sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename);
11198 if (check_func (debug_filename, func_data))
dda8d76d
NC
11199 goto found;
11200#endif
11201
24841daa
NC
11202 /* Then try in the global debug_filename directory. */
11203 strcpy (debug_filename, DEBUGDIR);
dda8d76d
NC
11204 dirlen = strlen (DEBUGDIR) - 1;
11205 if (dirlen > 0 && DEBUGDIR[dirlen] != '/')
24841daa
NC
11206 strcat (debug_filename, "/");
11207 strcat (debug_filename, (const char *) separate_filename);
dda8d76d 11208
24841daa 11209 if (check_func (debug_filename, func_data))
dda8d76d
NC
11210 goto found;
11211
301a9420
AM
11212#if HAVE_LIBDEBUGINFOD
11213 {
11214 char * tmp_filename;
11215
11216 if (debuginfod_fetch_separate_debug_info (xlink,
11217 & tmp_filename,
11218 file))
11219 {
11220 /* File successfully downloaded from server, replace
11221 debug_filename with the file's path. */
11222 free (debug_filename);
11223 debug_filename = tmp_filename;
11224 goto found;
11225 }
11226 }
11227#endif
11228
ecd65684
L
11229 if (do_debug_links)
11230 {
11231 /* Failed to find the file. */
11232 warn (_("could not find separate debug file '%s'\n"),
11233 separate_filename);
11234 warn (_("tried: %s\n"), debug_filename);
dda8d76d
NC
11235
11236#ifdef EXTRA_DEBUG_ROOT2
ecd65684
L
11237 sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2,
11238 separate_filename);
11239 warn (_("tried: %s\n"), debug_filename);
dda8d76d
NC
11240#endif
11241
11242#ifdef EXTRA_DEBUG_ROOT1
ecd65684
L
11243 sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1,
11244 canon_dir, separate_filename);
11245 warn (_("tried: %s\n"), debug_filename);
39f0547e 11246
ecd65684
L
11247 sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1,
11248 separate_filename);
11249 warn (_("tried: %s\n"), debug_filename);
dda8d76d
NC
11250#endif
11251
ecd65684
L
11252 sprintf (debug_filename, "%s.debug/%s", canon_dir,
11253 separate_filename);
11254 warn (_("tried: %s\n"), debug_filename);
dda8d76d 11255
ecd65684
L
11256 sprintf (debug_filename, "%s%s", canon_dir, separate_filename);
11257 warn (_("tried: %s\n"), debug_filename);
dda8d76d 11258
ecd65684
L
11259 sprintf (debug_filename, ".debug/%s", separate_filename);
11260 warn (_("tried: %s\n"), debug_filename);
dda8d76d 11261
ecd65684
L
11262 sprintf (debug_filename, "%s", separate_filename);
11263 warn (_("tried: %s\n"), debug_filename);
dda8d76d 11264
301a9420 11265#if HAVE_LIBDEBUGINFOD
ecd65684
L
11266 {
11267 char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR);
11268 if (urls == NULL)
11269 urls = "";
301a9420 11270
ecd65684
L
11271 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls);
11272 }
301a9420 11273#endif
ecd65684 11274 }
301a9420 11275
dda8d76d 11276 free (canon_dir);
24841daa 11277 free (debug_filename);
dda8d76d
NC
11278 return NULL;
11279
11280 found:
11281 free (canon_dir);
11282
24841daa
NC
11283 void * debug_handle;
11284
dda8d76d 11285 /* Now open the file.... */
24841daa 11286 if ((debug_handle = open_debug_file (debug_filename)) == NULL)
dda8d76d 11287 {
24841daa
NC
11288 warn (_("failed to open separate debug file: %s\n"), debug_filename);
11289 free (debug_filename);
ce139cd5 11290 return NULL;
dda8d76d
NC
11291 }
11292
11293 /* FIXME: We do not check to see if there are any other separate debug info
11294 files that would also match. */
11295
ca0e11aa
NC
11296 if (do_debug_links)
11297 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename, debug_filename);
24841daa 11298 add_separate_debug_file (debug_filename, debug_handle);
dda8d76d 11299
24841daa 11300 /* Do not free debug_filename - it might be referenced inside
dda8d76d 11301 the structure returned by open_debug_file(). */
24841daa 11302 return debug_handle;
dda8d76d
NC
11303}
11304
d85bf2ba
NC
11305/* Attempt to load a separate dwarf object file. */
11306
11307static void *
24841daa 11308load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED)
d85bf2ba 11309{
24841daa
NC
11310 char * separate_filename;
11311 void * separate_handle;
d85bf2ba 11312
d9d9d8ef
TV
11313 if (IS_ABSOLUTE_PATH (name))
11314 separate_filename = strdup (name);
11315 else
11316 /* FIXME: Skip adding / if dwo_dir ends in /. */
11317 separate_filename = concat (dir, "/", name, NULL);
24841daa 11318 if (separate_filename == NULL)
d85bf2ba
NC
11319 {
11320 warn (_("Out of memory allocating dwo filename\n"));
11321 return NULL;
11322 }
11323
24841daa 11324 if ((separate_handle = open_debug_file (separate_filename)) == NULL)
d85bf2ba 11325 {
24841daa
NC
11326 warn (_("Unable to load dwo file: %s\n"), separate_filename);
11327 free (separate_filename);
d85bf2ba
NC
11328 return NULL;
11329 }
11330
11331 /* FIXME: We should check the dwo_id. */
11332
24841daa 11333 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename);
bfbfa6e7 11334
24841daa
NC
11335 add_separate_debug_file (separate_filename, separate_handle);
11336 /* Note - separate_filename will be freed in free_debug_memory(). */
11337 return separate_handle;
d85bf2ba
NC
11338}
11339
e38332c2
NC
11340static void
11341load_debug_sup_file (const char * main_filename, void * file)
11342{
11343 if (! load_debug_section (debug_sup, file))
11344 return; /* No .debug_sup section. */
11345
11346 struct dwarf_section * section;
11347 section = & debug_displays [debug_sup].section;
11348 assert (section != NULL);
11349
11350 if (section->start == NULL || section->size < 5)
11351 {
11352 warn (_(".debug_sup section is corrupt/empty\n"));
11353 return;
11354 }
11355
11356 if (section->start[2] != 0)
11357 return; /* This is a supplementary file. */
11358
11359 const char * filename = (const char *) section->start + 3;
11360 if (strnlen (filename, section->size - 3) == section->size - 3)
11361 {
11362 warn (_("filename in .debug_sup section is corrupt\n"));
11363 return;
11364 }
11365
11366 if (filename[0] != '/' && strchr (main_filename, '/'))
11367 {
11368 char * new_name;
bfbfa6e7
NC
11369 int new_len;
11370
11371 new_len = asprintf (& new_name, "%.*s/%s",
11372 (int) (strrchr (main_filename, '/') - main_filename),
11373 main_filename,
11374 filename);
11375 if (new_len < 3)
11376 {
11377 warn (_("unable to construct path for supplementary debug file"));
11378 if (new_len > -1)
11379 free (new_name);
11380 return;
11381 }
11382 filename = new_name;
11383 }
11384 else
11385 {
11386 /* PR 27796: Make sure that we pass a filename that can be free'd to
11387 add_separate_debug_file(). */
11388 filename = strdup (filename);
11389 if (filename == NULL)
11390 {
11391 warn (_("out of memory constructing filename for .debug_sup link\n"));
11392 return;
11393 }
e38332c2
NC
11394 }
11395
bfbfa6e7 11396 void * handle = open_debug_file (filename);
e38332c2
NC
11397 if (handle == NULL)
11398 {
11399 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename);
bfbfa6e7 11400 free ((void *) filename);
e38332c2
NC
11401 return;
11402 }
11403
11404 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename, filename);
11405
11406 /* FIXME: Compare the checksums, if present. */
11407 add_separate_debug_file (filename, handle);
11408}
11409
ce139cd5
NC
11410/* Load a debuglink section and/or a debugaltlink section, if either are present.
11411 Recursively check the loaded files for more of these sections.
e38332c2
NC
11412 Also follow any links in .debug_sup sections.
11413 FIXME: Should also check for DWO_* entries in the newly loaded files. */
ce139cd5
NC
11414
11415static void
11416check_for_and_load_links (void * file, const char * filename)
11417{
11418 void * handle = NULL;
11419
11420 if (load_debug_section (gnu_debugaltlink, file))
11421 {
11422 Build_id_data build_id_data;
11423
11424 handle = load_separate_debug_info (filename,
11425 & debug_displays[gnu_debugaltlink].section,
11426 parse_gnu_debugaltlink,
11427 check_gnu_debugaltlink,
11428 & build_id_data,
11429 file);
11430 if (handle)
11431 {
11432 assert (handle == first_separate_info->handle);
11433 check_for_and_load_links (first_separate_info->handle,
11434 first_separate_info->filename);
11435 }
11436 }
11437
11438 if (load_debug_section (gnu_debuglink, file))
11439 {
11440 unsigned long crc32;
11441
11442 handle = load_separate_debug_info (filename,
11443 & debug_displays[gnu_debuglink].section,
11444 parse_gnu_debuglink,
11445 check_gnu_debuglink,
11446 & crc32,
11447 file);
11448 if (handle)
11449 {
11450 assert (handle == first_separate_info->handle);
11451 check_for_and_load_links (first_separate_info->handle,
11452 first_separate_info->filename);
11453 }
11454 }
e38332c2
NC
11455
11456 load_debug_sup_file (filename, file);
ce139cd5
NC
11457}
11458
24841daa
NC
11459/* Load the separate debug info file(s) attached to FILE, if any exist.
11460 Returns TRUE if any were found, FALSE otherwise.
11461 If TRUE is returned then the linked list starting at first_separate_info
11462 will be populated with open file handles. */
dda8d76d 11463
015dc7e1 11464bool
24841daa 11465load_separate_debug_files (void * file, const char * filename)
dda8d76d 11466{
8de3a6e2
NC
11467 /* Skip this operation if we are not interested in debug links. */
11468 if (! do_follow_links && ! do_debug_links)
015dc7e1 11469 return false;
8de3a6e2 11470
24841daa 11471 /* See if there are any dwo links. */
d85bf2ba
NC
11472 if (load_debug_section (str, file)
11473 && load_debug_section (abbrev, file)
11474 && load_debug_section (info, file))
11475 {
24841daa 11476 free_dwo_info ();
d85bf2ba 11477
50ea0877 11478 if (process_debug_info (& debug_displays[info].section, file, abbrev,
015dc7e1 11479 true, false))
d85bf2ba 11480 {
015dc7e1
AM
11481 bool introduced = false;
11482 dwo_info *dwinfo;
11483 const char *dir = NULL;
11484 const char *id = NULL;
11485 const char *name = NULL;
24841daa
NC
11486
11487 for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next)
d85bf2ba 11488 {
50ea0877 11489 /* Accumulate NAME, DIR and ID fields. */
24841daa 11490 switch (dwinfo->type)
d85bf2ba 11491 {
24841daa 11492 case DWO_NAME:
50ea0877
NC
11493 if (name != NULL)
11494 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
11495 name = dwinfo->value;
11496 break;
11497
11498 case DWO_DIR:
11499 /* There can be multiple DW_AT_comp_dir entries in a CU,
11500 so do not complain. */
11501 dir = dwinfo->value;
11502 break;
11503
11504 case DWO_ID:
11505 if (id != NULL)
11506 warn (_("multiple DWO_IDs encountered for the same CU\n"));
11507 id = dwinfo->value;
11508 break;
11509
11510 default:
11511 error (_("Unexpected DWO INFO type"));
11512 break;
11513 }
11514
11515 /* If we have reached the end of our list, or we are changing
11516 CUs, then display the information that we have accumulated
11517 so far. */
11518 if (name != NULL
11519 && (dwinfo->next == NULL
11520 || dwinfo->next->cu_offset != dwinfo->cu_offset))
11521 {
24841daa
NC
11522 if (do_debug_links)
11523 {
11524 if (! introduced)
11525 {
11526 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11527 debug_displays [info].section.uncompressed_name);
015dc7e1 11528 introduced = true;
24841daa 11529 }
d85bf2ba 11530
50ea0877 11531 printf (_(" Name: %s\n"), name);
24841daa
NC
11532 printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>"));
11533 if (id != NULL)
11534 display_data (printf (_(" ID: ")), (unsigned char *) id, 8);
11535 else
50ea0877 11536 printf (_(" ID: <not specified>\n"));
24841daa
NC
11537 printf ("\n\n");
11538 }
11539
11540 if (do_follow_links)
50ea0877 11541 load_dwo_file (filename, name, dir, id);
24841daa 11542
50ea0877 11543 name = dir = id = NULL;
24841daa 11544 }
d85bf2ba
NC
11545 }
11546 }
11547 }
11548
dda8d76d 11549 if (! do_follow_links)
8de3a6e2
NC
11550 /* The other debug links will be displayed by display_debug_links()
11551 so we do not need to do any further processing here. */
015dc7e1 11552 return false;
dda8d76d
NC
11553
11554 /* FIXME: We do not check for the presence of both link sections in the same file. */
dda8d76d 11555 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
d85bf2ba 11556 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
dda8d76d 11557
ce139cd5 11558 check_for_and_load_links (file, filename);
24841daa 11559 if (first_separate_info != NULL)
015dc7e1 11560 return true;
24841daa 11561
dda8d76d 11562 do_follow_links = 0;
015dc7e1 11563 return false;
521d4b19 11564}
dda8d76d 11565
19e6b90e
L
11566void
11567free_debug_memory (void)
11568{
3f5e193b 11569 unsigned int i;
19e6b90e 11570
bcd213b2 11571 free_all_abbrevs ();
19e6b90e 11572
bcd213b2
NC
11573 free (cu_abbrev_map);
11574 cu_abbrev_map = NULL;
11575 next_free_abbrev_map_entry = 0;
521d4b19 11576
288f0ba2
AM
11577 free (shndx_pool);
11578 shndx_pool = NULL;
11579 shndx_pool_size = 0;
11580 shndx_pool_used = 0;
11581 free (cu_sets);
11582 cu_sets = NULL;
11583 cu_count = 0;
11584 free (tu_sets);
11585 tu_sets = NULL;
11586 tu_count = 0;
11587
11588 memset (level_type_signed, 0, sizeof level_type_signed);
11589 cu_tu_indexes_read = -1;
11590
19e6b90e 11591 for (i = 0; i < max; i++)
3f5e193b 11592 free_debug_section ((enum dwarf_section_display_enum) i);
19e6b90e 11593
cc86f28f 11594 if (debug_information != NULL)
19e6b90e 11595 {
82fcdb39 11596 for (i = 0; i < alloc_num_debug_info_entries; i++)
19e6b90e 11597 {
82fcdb39 11598 if (debug_information [i].max_loc_offsets)
19e6b90e 11599 {
82fcdb39
AM
11600 free (debug_information [i].loc_offsets);
11601 free (debug_information [i].have_frame_base);
19e6b90e 11602 }
82fcdb39
AM
11603 if (debug_information [i].max_range_lists)
11604 free (debug_information [i].range_lists);
19e6b90e
L
11605 }
11606 free (debug_information);
11607 debug_information = NULL;
82b1b41b 11608 alloc_num_debug_info_entries = num_debug_info_entries = 0;
19e6b90e 11609 }
dda8d76d 11610
24841daa
NC
11611 separate_info * d;
11612 separate_info * next;
dda8d76d 11613
24841daa
NC
11614 for (d = first_separate_info; d != NULL; d = next)
11615 {
11616 close_debug_file (d->handle);
11617 free ((void *) d->filename);
11618 next = d->next;
11619 free ((void *) d);
dda8d76d 11620 }
24841daa 11621 first_separate_info = NULL;
521d4b19 11622
24841daa 11623 free_dwo_info ();
19e6b90e
L
11624}
11625
4cb93e3b
TG
11626void
11627dwarf_select_sections_by_names (const char *names)
11628{
11629 typedef struct
11630 {
11631 const char * option;
11632 int * variable;
f9f0e732 11633 int val;
4cb93e3b
TG
11634 }
11635 debug_dump_long_opts;
11636
11637 static const debug_dump_long_opts opts_table [] =
11638 {
11639 /* Please keep this table alpha- sorted. */
11640 { "Ranges", & do_debug_ranges, 1 },
11641 { "abbrev", & do_debug_abbrevs, 1 },
657d0d47 11642 { "addr", & do_debug_addr, 1 },
4cb93e3b 11643 { "aranges", & do_debug_aranges, 1 },
657d0d47
CC
11644 { "cu_index", & do_debug_cu_index, 1 },
11645 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
dda8d76d 11646 { "follow-links", & do_follow_links, 1 },
4cb93e3b
TG
11647 { "frames", & do_debug_frames, 1 },
11648 { "frames-interp", & do_debug_frames_interp, 1 },
657d0d47
CC
11649 /* The special .gdb_index section. */
11650 { "gdb_index", & do_gdb_index, 1 },
4cb93e3b
TG
11651 { "info", & do_debug_info, 1 },
11652 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
dda8d76d 11653 { "links", & do_debug_links, 1 },
4cb93e3b
TG
11654 { "loc", & do_debug_loc, 1 },
11655 { "macro", & do_debug_macinfo, 1 },
c46b7066 11656 { "no-follow-links", & do_follow_links, 0 },
4cb93e3b 11657 { "pubnames", & do_debug_pubnames, 1 },
357da287 11658 { "pubtypes", & do_debug_pubtypes, 1 },
222c2bf0 11659 /* This entry is for compatibility
4cb93e3b
TG
11660 with earlier versions of readelf. */
11661 { "ranges", & do_debug_aranges, 1 },
657d0d47 11662 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
4cb93e3b 11663 { "str", & do_debug_str, 1 },
e4b7104b 11664 { "str-offsets", & do_debug_str_offsets, 1 },
6f875884
TG
11665 /* These trace_* sections are used by Itanium VMS. */
11666 { "trace_abbrev", & do_trace_abbrevs, 1 },
11667 { "trace_aranges", & do_trace_aranges, 1 },
11668 { "trace_info", & do_trace_info, 1 },
4cb93e3b
TG
11669 { NULL, NULL, 0 }
11670 };
11671
11672 const char *p;
467c65bc 11673
4cb93e3b
TG
11674 p = names;
11675 while (*p)
11676 {
11677 const debug_dump_long_opts * entry;
467c65bc 11678
4cb93e3b
TG
11679 for (entry = opts_table; entry->option; entry++)
11680 {
11681 size_t len = strlen (entry->option);
467c65bc 11682
4cb93e3b
TG
11683 if (strncmp (p, entry->option, len) == 0
11684 && (p[len] == ',' || p[len] == '\0'))
11685 {
c46b7066 11686 * entry->variable = entry->val;
467c65bc 11687
4cb93e3b
TG
11688 /* The --debug-dump=frames-interp option also
11689 enables the --debug-dump=frames option. */
11690 if (do_debug_frames_interp)
11691 do_debug_frames = 1;
11692
11693 p += len;
11694 break;
11695 }
11696 }
467c65bc 11697
4cb93e3b
TG
11698 if (entry->option == NULL)
11699 {
11700 warn (_("Unrecognized debug option '%s'\n"), p);
11701 p = strchr (p, ',');
11702 if (p == NULL)
11703 break;
11704 }
467c65bc 11705
4cb93e3b
TG
11706 if (*p == ',')
11707 p++;
11708 }
11709}
11710
11711void
11712dwarf_select_sections_by_letters (const char *letters)
11713{
91d6fa6a 11714 unsigned int lindex = 0;
4cb93e3b 11715
91d6fa6a
NC
11716 while (letters[lindex])
11717 switch (letters[lindex++])
4cb93e3b 11718 {
dda8d76d
NC
11719 case 'A': do_debug_addr = 1; break;
11720 case 'a': do_debug_abbrevs = 1; break;
11721 case 'c': do_debug_cu_index = 1; break;
11722 case 'F': do_debug_frames_interp = 1; /* Fall through. */
11723 case 'f': do_debug_frames = 1; break;
11724 case 'g': do_gdb_index = 1; break;
11725 case 'i': do_debug_info = 1; break;
11726 case 'K': do_follow_links = 1; break;
c46b7066 11727 case 'N': do_follow_links = 0; break;
dda8d76d
NC
11728 case 'k': do_debug_links = 1; break;
11729 case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break;
11730 case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break;
11731 case 'm': do_debug_macinfo = 1; break;
e4b7104b 11732 case 'O': do_debug_str_offsets = 1; break;
dda8d76d
NC
11733 case 'o': do_debug_loc = 1; break;
11734 case 'p': do_debug_pubnames = 1; break;
11735 case 'R': do_debug_ranges = 1; break;
11736 case 'r': do_debug_aranges = 1; break;
11737 case 's': do_debug_str = 1; break;
11738 case 'T': do_trace_aranges = 1; break;
11739 case 't': do_debug_pubtypes = 1; break;
11740 case 'U': do_trace_info = 1; break;
11741 case 'u': do_trace_abbrevs = 1; break;
467c65bc 11742
4cb93e3b 11743 default:
7cc78d07 11744 warn (_("Unrecognized debug option '%s'\n"), letters);
4cb93e3b
TG
11745 break;
11746 }
11747}
11748
11749void
11750dwarf_select_sections_all (void)
11751{
11752 do_debug_info = 1;
11753 do_debug_abbrevs = 1;
11754 do_debug_lines = FLAG_DEBUG_LINES_RAW;
11755 do_debug_pubnames = 1;
f9f0e732 11756 do_debug_pubtypes = 1;
4cb93e3b
TG
11757 do_debug_aranges = 1;
11758 do_debug_ranges = 1;
11759 do_debug_frames = 1;
11760 do_debug_macinfo = 1;
11761 do_debug_str = 1;
11762 do_debug_loc = 1;
5bbdf3d5 11763 do_gdb_index = 1;
6f875884
TG
11764 do_trace_info = 1;
11765 do_trace_abbrevs = 1;
11766 do_trace_aranges = 1;
657d0d47
CC
11767 do_debug_addr = 1;
11768 do_debug_cu_index = 1;
dda8d76d
NC
11769 do_follow_links = 1;
11770 do_debug_links = 1;
e4b7104b 11771 do_debug_str_offsets = 1;
4cb93e3b
TG
11772}
11773
208599d9
AM
11774#define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
11775#define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
dda8d76d
NC
11776
11777/* N.B. The order here must match the order in section_display_enum. */
11778
19e6b90e
L
11779struct dwarf_section_display debug_displays[] =
11780{
015dc7e1
AM
11781 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false },
11782 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, true },
11783 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true },
11784 { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, true },
11785 { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true },
11786 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, false },
11787 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, false },
11788 { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true },
11789 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false },
11790 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true },
11791 { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, false },
11792 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, false },
11793 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true },
11794 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true },
11795 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, false },
11796 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, false },
11797 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true },
11798 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true },
11799 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, false },
11800 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, false },
11801 { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, true },
11802 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, false },
11803 { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, false },
11804 { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, false },
11805 { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, true },
11806 { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, false },
11807 { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, false },
11808 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, true },
11809 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false },
11810 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, true },
11811 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true },
11812 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true },
11813 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true },
11814 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false },
11815 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, true },
11816 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true },
11817 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true },
11818 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, true },
11819 { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false },
11820 { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false },
11821 { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false },
11822 { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false },
11823 { { ".debug_sup", "", NO_ABBREVS }, display_debug_sup, &do_debug_links, false },
dda8d76d
NC
11824 /* Separate debug info files can containt their own .debug_str section,
11825 and this might be in *addition* to a .debug_str section already present
11826 in the main file. Hence we need to have two entries for .debug_str. */
015dc7e1 11827 { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, false },
19e6b90e 11828};
b451e98a
JK
11829
11830/* A static assertion. */
11831extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1];
This page took 1.532909 seconds and 4 git commands to generate.