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