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