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