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