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