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