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