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