PR22216, infinite loop in readelf process_symbol_table
[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;
19e6b90e 2594 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 }
2742 tags = hdrptr;
2743 start += compunit.cu_length + initial_length_size;
2744
57028622
NC
2745 if (start > end)
2746 {
2747 warn (_("Debug info is corrupt. CU at %s extends beyond end of section"),
2748 dwarf_vmatoa ("x", cu_offset));
2749 start = end;
2750 }
2751
77145576 2752 if (compunit.cu_version < 2 || compunit.cu_version > 5)
19e6b90e 2753 {
47704ddf
KT
2754 warn (_("CU at offset %s contains corrupt or "
2755 "unsupported version number: %d.\n"),
2756 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
19e6b90e
L
2757 continue;
2758 }
2759
77145576
JK
2760 if (compunit.cu_unit_type != DW_UT_compile
2761 && compunit.cu_unit_type != DW_UT_type)
2762 {
2763 warn (_("CU at offset %s contains corrupt or "
2764 "unsupported unit type: %d.\n"),
2765 dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type);
2766 continue;
2767 }
2768
19e6b90e
L
2769 free_abbrevs ();
2770
d493b283 2771 /* Process the abbrevs used by this compilation unit. */
341f9135 2772 if (compunit.cu_abbrev_offset >= abbrev_size)
ec4d4525
NC
2773 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2774 (unsigned long) compunit.cu_abbrev_offset,
341f9135 2775 (unsigned long) abbrev_size);
b4eb7656 2776 /* PR 17531: file:4bcd9ce9. */
a0a3b04c
L
2777 else if ((abbrev_base + abbrev_size)
2778 > debug_displays [abbrev_sec].section.size)
2779 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2780 (unsigned long) abbrev_base + abbrev_size,
2781 (unsigned long) debug_displays [abbrev_sec].section.size);
460c89ff
NS
2782 else
2783 process_abbrev_section
341f9135
CC
2784 (((unsigned char *) debug_displays [abbrev_sec].section.start
2785 + abbrev_base + compunit.cu_abbrev_offset),
2786 ((unsigned char *) debug_displays [abbrev_sec].section.start
2787 + abbrev_base + abbrev_size));
19e6b90e
L
2788
2789 level = 0;
fd2f0033
TT
2790 last_level = level;
2791 saved_level = -1;
19e6b90e
L
2792 while (tags < start)
2793 {
2794 unsigned int bytes_read;
2795 unsigned long abbrev_number;
ec4d4525 2796 unsigned long die_offset;
19e6b90e
L
2797 abbrev_entry *entry;
2798 abbrev_attr *attr;
fd2f0033 2799 int do_printing = 1;
19e6b90e 2800
ec4d4525
NC
2801 die_offset = tags - section_begin;
2802
f6f0e17b 2803 abbrev_number = read_uleb128 (tags, & bytes_read, start);
19e6b90e
L
2804 tags += bytes_read;
2805
eb7cc021
JK
2806 /* A null DIE marks the end of a list of siblings or it may also be
2807 a section padding. */
19e6b90e
L
2808 if (abbrev_number == 0)
2809 {
eb7cc021
JK
2810 /* Check if it can be a section padding for the last CU. */
2811 if (level == 0 && start == end)
2812 {
2813 unsigned char *chk;
2814
2815 for (chk = tags; chk < start; chk++)
2816 if (*chk != 0)
2817 break;
2818 if (chk == start)
2819 break;
2820 }
2821
4337774f
TT
2822 if (!do_loc && die_offset >= dwarf_start_die
2823 && (dwarf_cutoff_level == -1
2824 || level < dwarf_cutoff_level))
399c99f7
L
2825 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2826 level, die_offset);
2827
19e6b90e 2828 --level;
ec4d4525
NC
2829 if (level < 0)
2830 {
2831 static unsigned num_bogus_warns = 0;
2832
2833 if (num_bogus_warns < 3)
2834 {
4723351a
CC
2835 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2836 die_offset, section->name);
ec4d4525
NC
2837 num_bogus_warns ++;
2838 if (num_bogus_warns == 3)
2839 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2840 }
2841 }
fd2f0033
TT
2842 if (dwarf_start_die != 0 && level < saved_level)
2843 return 1;
19e6b90e
L
2844 continue;
2845 }
2846
4b78141a 2847 if (!do_loc)
fd2f0033
TT
2848 {
2849 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2850 do_printing = 0;
2851 else
2852 {
2853 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2854 saved_level = level;
2855 do_printing = (dwarf_cutoff_level == -1
2856 || level < dwarf_cutoff_level);
2857 if (do_printing)
2858 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2859 level, die_offset, abbrev_number);
2860 else if (dwarf_cutoff_level == -1
2861 || last_level < dwarf_cutoff_level)
2862 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2863 last_level = level;
2864 }
2865 }
cecf136e 2866
19e6b90e
L
2867 /* Scan through the abbreviation list until we reach the
2868 correct entry. */
2869 for (entry = first_abbrev;
2870 entry && entry->entry != abbrev_number;
2871 entry = entry->next)
2872 continue;
2873
2874 if (entry == NULL)
2875 {
fd2f0033 2876 if (!do_loc && do_printing)
4b78141a
NC
2877 {
2878 printf ("\n");
2879 fflush (stdout);
2880 }
f3853b34 2881 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
cc86f28f 2882 die_offset, abbrev_number);
19e6b90e
L
2883 return 0;
2884 }
2885
fd2f0033 2886 if (!do_loc && do_printing)
cc5914eb 2887 printf (" (%s)\n", get_TAG_name (entry->tag));
cecf136e 2888
19e6b90e
L
2889 switch (entry->tag)
2890 {
2891 default:
2892 need_base_address = 0;
2893 break;
2894 case DW_TAG_compile_unit:
2895 need_base_address = 1;
2896 break;
2897 case DW_TAG_entry_point:
19e6b90e
L
2898 case DW_TAG_subprogram:
2899 need_base_address = 0;
2900 /* Assuming that there is no DW_AT_frame_base. */
2901 have_frame_base = 0;
2902 break;
2903 }
2904
9f272209
AO
2905 debug_info *debug_info_p =
2906 (debug_information && unit < alloc_num_debug_info_entries)
2907 ? debug_information + unit : NULL;
2908
2909 assert (!debug_info_p
2910 || (debug_info_p->num_loc_offsets
2911 == debug_info_p->num_loc_views));
2912
399c99f7
L
2913 for (attr = entry->first_attr;
2914 attr && attr->attribute;
2915 attr = attr->next)
4b78141a 2916 {
fd2f0033 2917 if (! do_loc && do_printing)
4b78141a 2918 /* Show the offset from where the tag was extracted. */
fd2f0033
TT
2919 printf (" <%lx>", (unsigned long)(tags - section_begin));
2920
4b78141a
NC
2921 tags = read_and_display_attr (attr->attribute,
2922 attr->form,
77145576 2923 attr->implicit_const,
341f9135 2924 tags,
f6f0e17b 2925 end,
341f9135 2926 cu_offset,
4b78141a
NC
2927 compunit.cu_pointer_size,
2928 offset_size,
2929 compunit.cu_version,
9f272209 2930 debug_info_p,
341f9135
CC
2931 do_loc || ! do_printing,
2932 section,
2933 this_set);
4b78141a 2934 }
cecf136e 2935
9f272209
AO
2936 /* If a locview attribute appears before a location one,
2937 make sure we don't associate it with an earlier
2938 loclist. */
2939 if (debug_info_p)
2940 switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views)
2941 {
2942 case 1:
2943 debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1;
2944 debug_info_p->num_loc_views++;
2945 assert (debug_info_p->num_loc_views
2946 == debug_info_p->num_loc_offsets);
2947 break;
2948
2949 case 0:
2950 break;
2951
2952 case -1:
2953 warn(_("DIE has locviews without loclist\n"));
2954 debug_info_p->num_loc_views--;
2955 break;
2956
2957 default:
2958 assert (0);
2959 }
2960
b4eb7656
AM
2961 if (entry->children)
2962 ++level;
2963 }
19e6b90e 2964 }
cecf136e 2965
19e6b90e
L
2966 /* Set num_debug_info_entries here so that it can be used to check if
2967 we need to process .debug_loc and .debug_ranges sections. */
2968 if ((do_loc || do_debug_loc || do_debug_ranges)
2b6f5997
CC
2969 && num_debug_info_entries == 0
2970 && ! do_types)
82b1b41b 2971 {
b4eb7656 2972 if (num_units > alloc_num_debug_info_entries)
82b1b41b
NC
2973 num_debug_info_entries = alloc_num_debug_info_entries;
2974 else
2975 num_debug_info_entries = num_units;
2976 }
cecf136e 2977
19e6b90e 2978 if (!do_loc)
467c65bc 2979 printf ("\n");
cecf136e 2980
19e6b90e
L
2981 return 1;
2982}
2983
2984/* Locate and scan the .debug_info section in the file and record the pointer
2985 sizes and offsets for the compilation units in it. Usually an executable
2986 will have just one pointer size, but this is not guaranteed, and so we try
2987 not to make any assumptions. Returns zero upon failure, or the number of
2988 compilation units upon success. */
2989
2990static unsigned int
2991load_debug_info (void * file)
2992{
1febe64d 2993 /* If we have already tried and failed to load the .debug_info
657d0d47 2994 section then do not bother to repeat the task. */
cc86f28f 2995 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
1febe64d
NC
2996 return 0;
2997
19e6b90e
L
2998 /* If we already have the information there is nothing else to do. */
2999 if (num_debug_info_entries > 0)
3000 return num_debug_info_entries;
3001
341f9135 3002 /* If this is a DWARF package file, load the CU and TU indexes. */
43a444f9 3003 (void) load_cu_tu_indexes (file);
341f9135 3004
19e6b90e 3005 if (load_debug_section (info, file)
6f875884 3006 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
19e6b90e 3007 return num_debug_info_entries;
82b1b41b
NC
3008
3009 if (load_debug_section (info_dwo, file)
3010 && process_debug_info (&debug_displays [info_dwo].section, file,
3011 abbrev_dwo, 1, 0))
4723351a 3012 return num_debug_info_entries;
1febe64d 3013
cc86f28f 3014 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
1febe64d 3015 return 0;
19e6b90e
L
3016}
3017
b40bf0a2
NC
3018/* Read a DWARF .debug_line section header starting at DATA.
3019 Upon success returns an updated DATA pointer and the LINFO
3020 structure and the END_OF_SEQUENCE pointer will be filled in.
3021 Otherwise returns NULL. */
19e6b90e 3022
b40bf0a2
NC
3023static unsigned char *
3024read_debug_line_header (struct dwarf_section * section,
3025 unsigned char * data,
3026 unsigned char * end,
3027 DWARF2_Internal_LineInfo * linfo,
3028 unsigned char ** end_of_sequence)
3029{
3030 unsigned char *hdrptr;
b40bf0a2 3031 unsigned int initial_length_size;
77145576 3032 unsigned char address_size, segment_selector_size;
19e6b90e 3033
b40bf0a2
NC
3034 /* Extract information from the Line Number Program Header.
3035 (section 6.2.4 in the Dwarf3 doc). */
6937bb54 3036 hdrptr = data;
19e6b90e 3037
b40bf0a2
NC
3038 /* Get and check the length of the block. */
3039 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
19e6b90e 3040
b40bf0a2 3041 if (linfo->li_length == 0xffffffff)
f41e4712
NC
3042 {
3043 /* This section is 64-bit DWARF 3. */
b40bf0a2 3044 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
77145576 3045 linfo->li_offset_size = 8;
f41e4712
NC
3046 initial_length_size = 12;
3047 }
3048 else
3049 {
77145576 3050 linfo->li_offset_size = 4;
f41e4712
NC
3051 initial_length_size = 4;
3052 }
19e6b90e 3053
b40bf0a2 3054 if (linfo->li_length + initial_length_size > section->size)
f41e4712 3055 {
8fcc61b4
NC
3056 /* If the length field has a relocation against it, then we should
3057 not complain if it is inaccurate (and probably negative). This
3058 happens in object files when the .debug_line section is actually
3059 comprised of several different .debug_line.* sections, (some of
3060 which may be removed by linker garbage collection), and a relocation
3061 is used to compute the correct length once that is done. */
77145576 3062 if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size))
b40bf0a2 3063 {
8fcc61b4 3064 linfo->li_length = (end - data) - initial_length_size;
b40bf0a2
NC
3065 }
3066 else
3067 {
8fcc61b4
NC
3068 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3069 (long) linfo->li_length);
b40bf0a2
NC
3070 return NULL;
3071 }
f41e4712 3072 }
19e6b90e 3073
b40bf0a2
NC
3074 /* Get and check the version number. */
3075 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
3076
3077 if (linfo->li_version != 2
3078 && linfo->li_version != 3
77145576
JK
3079 && linfo->li_version != 4
3080 && linfo->li_version != 5)
f41e4712 3081 {
77145576
JK
3082 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3083 "is currently supported.\n"));
b40bf0a2 3084 return NULL;
f41e4712 3085 }
19e6b90e 3086
77145576
JK
3087 if (linfo->li_version >= 5)
3088 {
3089 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
3090
3091 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
3092 if (segment_selector_size != 0)
3093 {
3094 warn (_("The %s section contains "
3095 "unsupported segment selector size: %d.\n"),
3096 section->name, segment_selector_size);
3097 return 0;
3098 }
3099 }
3100
3101 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr,
3102 linfo->li_offset_size, end);
b40bf0a2 3103 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
0c588247 3104
b40bf0a2 3105 if (linfo->li_version >= 4)
f41e4712 3106 {
b40bf0a2 3107 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
0c588247 3108
b40bf0a2 3109 if (linfo->li_max_ops_per_insn == 0)
f41e4712
NC
3110 {
3111 warn (_("Invalid maximum operations per insn.\n"));
b40bf0a2 3112 return NULL;
a233b20c 3113 }
f41e4712
NC
3114 }
3115 else
b40bf0a2 3116 linfo->li_max_ops_per_insn = 1;
0c588247 3117
b40bf0a2 3118 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
65879393 3119 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
b40bf0a2
NC
3120 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
3121 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
19e6b90e 3122
b40bf0a2 3123 * end_of_sequence = data + linfo->li_length + initial_length_size;
b4eb7656 3124 /* PR 17512: file:002-117414-0.004. */
6937bb54
NC
3125 if (* end_of_sequence > end)
3126 {
4c219c2e
AM
3127 warn (_("Line length %s extends beyond end of section\n"),
3128 dwarf_vmatoa ("u", linfo->li_length));
6937bb54
NC
3129 * end_of_sequence = end;
3130 return NULL;
3131 }
3132
b40bf0a2
NC
3133 return hdrptr;
3134}
19e6b90e 3135
77145576
JK
3136static unsigned char *
3137display_formatted_table (unsigned char *data,
3138 unsigned char *start, unsigned char *end,
3139 const DWARF2_Internal_LineInfo *linfo,
3140 struct dwarf_section *section, const char *what)
3141{
3142 unsigned char *format_start, format_count, *format, formati;
3143 dwarf_vma data_count, datai;
3144 unsigned int bytes_read, namepass, last_entry = 0;
3145
3146 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3147 format_start = data;
3148 for (formati = 0; formati < format_count; formati++)
3149 {
3150 read_uleb128 (data, & bytes_read, end);
3151 data += bytes_read;
3152 read_uleb128 (data, & bytes_read, end);
3153 data += bytes_read;
3154 if (data == end)
3155 {
14357de1 3156 warn (_("Corrupt %s format table entry\n"), what);
77145576
JK
3157 return data;
3158 }
3159 }
3160
3161 data_count = read_uleb128 (data, & bytes_read, end);
3162 data += bytes_read;
3163 if (data == end)
3164 {
3165 warn (_("Corrupt %s list\n"), what);
3166 return data;
3167 }
3168
3169 if (data_count == 0)
3170 {
3171 printf (_("\n The %s Table is empty.\n"), what);
3172 return data;
3173 }
3174
3175 printf (_("\n The %s Table (offset 0x%lx):\n"), what,
3176 (long)(data - start));
3177
3178 printf (_(" Entry"));
3179 /* Delay displaying name as the last entry for better screen layout. */
3180 for (namepass = 0; namepass < 2; namepass++)
3181 {
3182 format = format_start;
3183 for (formati = 0; formati < format_count; formati++)
3184 {
3185 dwarf_vma content_type;
3186
3187 content_type = read_uleb128 (format, & bytes_read, end);
3188 format += bytes_read;
3189 if ((content_type == DW_LNCT_path) == (namepass == 1))
3190 switch (content_type)
3191 {
3192 case DW_LNCT_path:
3193 printf (_("\tName"));
3194 break;
3195 case DW_LNCT_directory_index:
3196 printf (_("\tDir"));
3197 break;
3198 case DW_LNCT_timestamp:
3199 printf (_("\tTime"));
3200 break;
3201 case DW_LNCT_size:
3202 printf (_("\tSize"));
3203 break;
3204 case DW_LNCT_MD5:
3205 printf (_("\tMD5"));
3206 break;
3207 default:
3208 printf (_("\t(Unknown format content type %s)"),
3209 dwarf_vmatoa ("u", content_type));
3210 }
3211 read_uleb128 (format, & bytes_read, end);
3212 format += bytes_read;
3213 }
3214 }
3215 putchar ('\n');
3216
3217 for (datai = 0; datai < data_count; datai++)
3218 {
3219 unsigned char *datapass = data;
3220
3221 printf (" %d", last_entry++);
3222 /* Delay displaying name as the last entry for better screen layout. */
3223 for (namepass = 0; namepass < 2; namepass++)
3224 {
3225 format = format_start;
3226 data = datapass;
3227 for (formati = 0; formati < format_count; formati++)
3228 {
3229 dwarf_vma content_type, form;
3230
3231 content_type = read_uleb128 (format, & bytes_read, end);
3232 format += bytes_read;
3233 form = read_uleb128 (format, & bytes_read, end);
3234 format += bytes_read;
3235 data = read_and_display_attr_value (0, form, 0, data, end, 0, 0,
3236 linfo->li_offset_size,
3237 linfo->li_version, NULL,
3238 ((content_type == DW_LNCT_path) != (namepass == 1)),
3239 section, NULL, '\t');
3240 }
3241 }
3242 if (data == end)
3243 {
3244 warn (_("Corrupt %s entries list\n"), what);
3245 return data;
3246 }
3247 putchar ('\n');
3248 }
3249 return data;
3250}
3251
b40bf0a2
NC
3252static int
3253display_debug_lines_raw (struct dwarf_section *section,
3254 unsigned char *data,
77145576 3255 unsigned char *end, void *file)
b40bf0a2
NC
3256{
3257 unsigned char *start = section->start;
ba8826a8 3258 int verbose_view = 0;
19e6b90e 3259
b40bf0a2 3260 printf (_("Raw dump of debug contents of section %s:\n\n"),
b4eb7656 3261 section->name);
19e6b90e 3262
b40bf0a2
NC
3263 while (data < end)
3264 {
3265 static DWARF2_Internal_LineInfo saved_linfo;
3266 DWARF2_Internal_LineInfo linfo;
3267 unsigned char *standard_opcodes;
3268 unsigned char *end_of_sequence;
fe59e83d 3269 int i;
19e6b90e 3270
4925cdd7
NC
3271 if (const_strneq (section->name, ".debug_line.")
3272 /* Note: the following does not apply to .debug_line.dwo sections.
3273 These are full debug_line sections. */
3274 && strcmp (section->name, ".debug_line.dwo") != 0)
19e6b90e 3275 {
b40bf0a2
NC
3276 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3277 section containing just the Line Number Statements. They are
3278 created by the assembler and intended to be used alongside gcc's
3279 -ffunction-sections command line option. When the linker's
3280 garbage collection decides to discard a .text.<foo> section it
3281 can then also discard the line number information in .debug_line.<foo>.
3282
4925cdd7 3283 Since the section is a fragment it does not have the details
b40bf0a2 3284 needed to fill out a LineInfo structure, so instead we use the
4925cdd7 3285 details from the last full debug_line section that we processed. */
b40bf0a2
NC
3286 end_of_sequence = end;
3287 standard_opcodes = NULL;
3288 linfo = saved_linfo;
058037d3
NC
3289 /* PR 17531: file: 0522b371. */
3290 if (linfo.li_line_range == 0)
3291 {
1306a742 3292 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
058037d3
NC
3293 return 0;
3294 }
b40bf0a2 3295 reset_state_machine (linfo.li_default_is_stmt);
19e6b90e 3296 }
19e6b90e
L
3297 else
3298 {
b40bf0a2 3299 unsigned char * hdrptr;
19e6b90e 3300
b40bf0a2
NC
3301 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3302 & end_of_sequence)) == NULL)
3303 return 0;
19e6b90e 3304
b40bf0a2
NC
3305 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
3306 printf (_(" Length: %ld\n"), (long) linfo.li_length);
3307 printf (_(" DWARF Version: %d\n"), linfo.li_version);
77ef8654 3308 printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length);
b40bf0a2
NC
3309 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
3310 if (linfo.li_version >= 4)
3311 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
3312 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
3313 printf (_(" Line Base: %d\n"), linfo.li_line_base);
3314 printf (_(" Line Range: %d\n"), linfo.li_line_range);
3315 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
19e6b90e 3316
0a9d414a
NC
3317 /* PR 17512: file: 1665-6428-0.004. */
3318 if (linfo.li_line_range == 0)
3319 {
3320 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3321 linfo.li_line_range = 1;
3322 }
77ef8654 3323
b40bf0a2 3324 reset_state_machine (linfo.li_default_is_stmt);
19e6b90e 3325
b40bf0a2
NC
3326 /* Display the contents of the Opcodes table. */
3327 standard_opcodes = hdrptr;
19e6b90e 3328
6937bb54
NC
3329 /* PR 17512: file: 002-417945-0.004. */
3330 if (standard_opcodes + linfo.li_opcode_base >= end)
3331 {
3332 warn (_("Line Base extends beyond end of section\n"));
3333 return 0;
3334 }
3335
b40bf0a2 3336 printf (_("\n Opcodes:\n"));
19e6b90e 3337
b40bf0a2
NC
3338 for (i = 1; i < linfo.li_opcode_base; i++)
3339 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
19e6b90e 3340
b40bf0a2
NC
3341 /* Display the contents of the Directory table. */
3342 data = standard_opcodes + linfo.li_opcode_base - 1;
19e6b90e 3343
77145576 3344 if (linfo.li_version >= 5)
b40bf0a2 3345 {
77145576 3346 load_debug_section (line_str, file);
19e6b90e 3347
77145576
JK
3348 data = display_formatted_table (data, start, end, &linfo, section,
3349 _("Directory"));
3350 data = display_formatted_table (data, start, end, &linfo, section,
3351 _("File name"));
3352 }
3353 else
3354 {
3355 if (*data == 0)
3356 printf (_("\n The Directory Table is empty.\n"));
3357 else
a233b20c 3358 {
77145576 3359 unsigned int last_dir_entry = 0;
6937bb54 3360
77145576
JK
3361 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3362 (long)(data - start));
19e6b90e 3363
77145576
JK
3364 while (data < end && *data != 0)
3365 {
3366 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
19e6b90e 3367
77145576
JK
3368 data += strnlen ((char *) data, end - data) + 1;
3369 }
19e6b90e 3370
77145576
JK
3371 /* PR 17512: file: 002-132094-0.004. */
3372 if (data >= end - 1)
3373 break;
3374 }
19e6b90e 3375
77145576
JK
3376 /* Skip the NUL at the end of the table. */
3377 data++;
19e6b90e 3378
77145576
JK
3379 /* Display the contents of the File Name table. */
3380 if (*data == 0)
3381 printf (_("\n The File Name Table is empty.\n"));
3382 else
3383 {
3384 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3385 (long)(data - start));
3386 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
19e6b90e 3387
77145576 3388 while (data < end && *data != 0)
b40bf0a2 3389 {
77145576
JK
3390 unsigned char *name;
3391 unsigned int bytes_read;
3392
3393 printf (" %d\t", ++state_machine_regs.last_file_entry);
3394 name = data;
3395 data += strnlen ((char *) data, end - data) + 1;
3396
3397 printf ("%s\t",
3398 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3399 data += bytes_read;
3400 printf ("%s\t",
3401 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3402 data += bytes_read;
3403 printf ("%s\t",
3404 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3405 data += bytes_read;
3406 printf ("%.*s\n", (int)(end - name), name);
3407
3408 if (data == end)
3409 {
3410 warn (_("Corrupt file name table entry\n"));
3411 break;
3412 }
b40bf0a2 3413 }
a233b20c 3414 }
77145576
JK
3415
3416 /* Skip the NUL at the end of the table. */
3417 data++;
b40bf0a2 3418 }
19e6b90e 3419
b40bf0a2
NC
3420 putchar ('\n');
3421 saved_linfo = linfo;
3422 }
19e6b90e 3423
b40bf0a2
NC
3424 /* Now display the statements. */
3425 if (data >= end_of_sequence)
3426 printf (_(" No Line Number Statements.\n"));
3427 else
3428 {
3429 printf (_(" Line Number Statements:\n"));
19e6b90e 3430
b40bf0a2
NC
3431 while (data < end_of_sequence)
3432 {
3433 unsigned char op_code;
3434 dwarf_signed_vma adv;
3435 dwarf_vma uladv;
3436 unsigned int bytes_read;
19e6b90e 3437
fe59e83d
CC
3438 printf (" [0x%08lx]", (long)(data - start));
3439
b40bf0a2 3440 op_code = *data++;
19e6b90e 3441
b40bf0a2 3442 if (op_code >= linfo.li_opcode_base)
19e6b90e 3443 {
b40bf0a2
NC
3444 op_code -= linfo.li_opcode_base;
3445 uladv = (op_code / linfo.li_line_range);
3446 if (linfo.li_max_ops_per_insn == 1)
3447 {
3448 uladv *= linfo.li_min_insn_length;
3449 state_machine_regs.address += uladv;
ba8826a8
AO
3450 if (uladv)
3451 state_machine_regs.view = 0;
b40bf0a2 3452 printf (_(" Special opcode %d: "
ba8826a8 3453 "advance Address by %s to 0x%s%s"),
b40bf0a2 3454 op_code, dwarf_vmatoa ("u", uladv),
ba8826a8
AO
3455 dwarf_vmatoa ("x", state_machine_regs.address),
3456 verbose_view && uladv
3457 ? _(" (reset view)") : "");
b40bf0a2
NC
3458 }
3459 else
3460 {
ba8826a8
AO
3461 unsigned addrdelta
3462 = ((state_machine_regs.op_index + uladv)
b40bf0a2
NC
3463 / linfo.li_max_ops_per_insn)
3464 * linfo.li_min_insn_length;
ba8826a8
AO
3465
3466 state_machine_regs.address += addrdelta;
b40bf0a2
NC
3467 state_machine_regs.op_index
3468 = (state_machine_regs.op_index + uladv)
3469 % linfo.li_max_ops_per_insn;
ba8826a8
AO
3470 if (addrdelta)
3471 state_machine_regs.view = 0;
b40bf0a2 3472 printf (_(" Special opcode %d: "
ba8826a8 3473 "advance Address by %s to 0x%s[%d]%s"),
b40bf0a2
NC
3474 op_code, dwarf_vmatoa ("u", uladv),
3475 dwarf_vmatoa ("x", state_machine_regs.address),
ba8826a8
AO
3476 state_machine_regs.op_index,
3477 verbose_view && addrdelta
3478 ? _(" (reset view)") : "");
b40bf0a2
NC
3479 }
3480 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3481 state_machine_regs.line += adv;
ba8826a8 3482 printf (_(" and Line by %s to %d"),
b40bf0a2 3483 dwarf_vmatoa ("d", adv), state_machine_regs.line);
ba8826a8
AO
3484 if (verbose_view || state_machine_regs.view)
3485 printf (_(" (view %u)\n"), state_machine_regs.view);
3486 else
3487 putchar ('\n');
3488 state_machine_regs.view++;
19e6b90e 3489 }
b40bf0a2
NC
3490 else switch (op_code)
3491 {
3492 case DW_LNS_extended_op:
3493 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
3494 break;
3495
3496 case DW_LNS_copy:
ba8826a8
AO
3497 printf (_(" Copy"));
3498 if (verbose_view || state_machine_regs.view)
3499 printf (_(" (view %u)\n"), state_machine_regs.view);
3500 else
3501 putchar ('\n');
3502 state_machine_regs.view++;
b40bf0a2
NC
3503 break;
3504
3505 case DW_LNS_advance_pc:
3506 uladv = read_uleb128 (data, & bytes_read, end);
3507 data += bytes_read;
3508 if (linfo.li_max_ops_per_insn == 1)
3509 {
3510 uladv *= linfo.li_min_insn_length;
3511 state_machine_regs.address += uladv;
ba8826a8
AO
3512 if (uladv)
3513 state_machine_regs.view = 0;
3514 printf (_(" Advance PC by %s to 0x%s%s\n"),
b40bf0a2 3515 dwarf_vmatoa ("u", uladv),
ba8826a8
AO
3516 dwarf_vmatoa ("x", state_machine_regs.address),
3517 verbose_view && uladv
3518 ? _(" (reset view)") : "");
b40bf0a2
NC
3519 }
3520 else
3521 {
ba8826a8
AO
3522 unsigned addrdelta
3523 = ((state_machine_regs.op_index + uladv)
3524 / linfo.li_max_ops_per_insn)
b40bf0a2 3525 * linfo.li_min_insn_length;
ba8826a8
AO
3526 state_machine_regs.address
3527 += addrdelta;
b40bf0a2
NC
3528 state_machine_regs.op_index
3529 = (state_machine_regs.op_index + uladv)
3530 % linfo.li_max_ops_per_insn;
ba8826a8
AO
3531 if (addrdelta)
3532 state_machine_regs.view = 0;
3533 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
b40bf0a2
NC
3534 dwarf_vmatoa ("u", uladv),
3535 dwarf_vmatoa ("x", state_machine_regs.address),
ba8826a8
AO
3536 state_machine_regs.op_index,
3537 verbose_view && addrdelta
3538 ? _(" (reset view)") : "");
b40bf0a2
NC
3539 }
3540 break;
3541
3542 case DW_LNS_advance_line:
3543 adv = read_sleb128 (data, & bytes_read, end);
3544 data += bytes_read;
3545 state_machine_regs.line += adv;
3546 printf (_(" Advance Line by %s to %d\n"),
3547 dwarf_vmatoa ("d", adv),
3548 state_machine_regs.line);
3549 break;
3550
3551 case DW_LNS_set_file:
3552 adv = read_uleb128 (data, & bytes_read, end);
3553 data += bytes_read;
3554 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3555 dwarf_vmatoa ("d", adv));
3556 state_machine_regs.file = adv;
3557 break;
3558
3559 case DW_LNS_set_column:
3560 uladv = read_uleb128 (data, & bytes_read, end);
3561 data += bytes_read;
3562 printf (_(" Set column to %s\n"),
3563 dwarf_vmatoa ("u", uladv));
3564 state_machine_regs.column = uladv;
3565 break;
3566
3567 case DW_LNS_negate_stmt:
3568 adv = state_machine_regs.is_stmt;
3569 adv = ! adv;
3570 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
3571 state_machine_regs.is_stmt = adv;
3572 break;
3573
3574 case DW_LNS_set_basic_block:
3575 printf (_(" Set basic block\n"));
3576 state_machine_regs.basic_block = 1;
3577 break;
3578
3579 case DW_LNS_const_add_pc:
3580 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3581 if (linfo.li_max_ops_per_insn)
3582 {
3583 uladv *= linfo.li_min_insn_length;
3584 state_machine_regs.address += uladv;
ba8826a8
AO
3585 if (uladv)
3586 state_machine_regs.view = 0;
3587 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
b40bf0a2 3588 dwarf_vmatoa ("u", uladv),
ba8826a8
AO
3589 dwarf_vmatoa ("x", state_machine_regs.address),
3590 verbose_view && uladv
3591 ? _(" (reset view)") : "");
b40bf0a2
NC
3592 }
3593 else
3594 {
ba8826a8
AO
3595 unsigned addrdelta
3596 = ((state_machine_regs.op_index + uladv)
3597 / linfo.li_max_ops_per_insn)
b40bf0a2 3598 * linfo.li_min_insn_length;
ba8826a8
AO
3599 state_machine_regs.address
3600 += addrdelta;
b40bf0a2
NC
3601 state_machine_regs.op_index
3602 = (state_machine_regs.op_index + uladv)
3603 % linfo.li_max_ops_per_insn;
ba8826a8
AO
3604 if (addrdelta)
3605 state_machine_regs.view = 0;
3606 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
b40bf0a2
NC
3607 dwarf_vmatoa ("u", uladv),
3608 dwarf_vmatoa ("x", state_machine_regs.address),
ba8826a8
AO
3609 state_machine_regs.op_index,
3610 verbose_view && addrdelta
3611 ? _(" (reset view)") : "");
b40bf0a2
NC
3612 }
3613 break;
3614
3615 case DW_LNS_fixed_advance_pc:
3616 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3617 state_machine_regs.address += uladv;
3618 state_machine_regs.op_index = 0;
3619 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3620 dwarf_vmatoa ("u", uladv),
3621 dwarf_vmatoa ("x", state_machine_regs.address));
ba8826a8 3622 /* Do NOT reset view. */
b40bf0a2
NC
3623 break;
3624
3625 case DW_LNS_set_prologue_end:
3626 printf (_(" Set prologue_end to true\n"));
3627 break;
3628
3629 case DW_LNS_set_epilogue_begin:
3630 printf (_(" Set epilogue_begin to true\n"));
3631 break;
3632
3633 case DW_LNS_set_isa:
3634 uladv = read_uleb128 (data, & bytes_read, end);
3635 data += bytes_read;
3636 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
3637 break;
3638
3639 default:
3640 printf (_(" Unknown opcode %d with operands: "), op_code);
3641
3642 if (standard_opcodes != NULL)
3643 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3644 {
3645 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3646 &bytes_read, end)),
3647 i == 1 ? "" : ", ");
3648 data += bytes_read;
3649 }
3650 putchar ('\n');
3651 break;
3652 }
19e6b90e 3653 }
b40bf0a2 3654 putchar ('\n');
19e6b90e 3655 }
19e6b90e
L
3656 }
3657
3658 return 1;
3659}
3660
a262ae96
NC
3661typedef struct
3662{
467c65bc
NC
3663 unsigned char *name;
3664 unsigned int directory_index;
3665 unsigned int modification_date;
3666 unsigned int length;
a262ae96
NC
3667} File_Entry;
3668
3669/* Output a decoded representation of the .debug_line section. */
3670
3671static int
3672display_debug_lines_decoded (struct dwarf_section *section,
3673 unsigned char *data,
77145576 3674 unsigned char *end, void *fileptr)
a262ae96 3675{
b40bf0a2
NC
3676 static DWARF2_Internal_LineInfo saved_linfo;
3677
a262ae96 3678 printf (_("Decoded dump of debug contents of section %s:\n\n"),
b4eb7656 3679 section->name);
a262ae96
NC
3680
3681 while (data < end)
3682 {
3683 /* This loop amounts to one iteration per compilation unit. */
91d6fa6a 3684 DWARF2_Internal_LineInfo linfo;
a262ae96
NC
3685 unsigned char *standard_opcodes;
3686 unsigned char *end_of_sequence;
a262ae96
NC
3687 int i;
3688 File_Entry *file_table = NULL;
143a3db0 3689 unsigned int n_files = 0;
a262ae96 3690 unsigned char **directory_table = NULL;
77145576 3691 dwarf_vma n_directories = 0;
a262ae96 3692
4925cdd7
NC
3693 if (const_strneq (section->name, ".debug_line.")
3694 /* Note: the following does not apply to .debug_line.dwo sections.
3695 These are full debug_line sections. */
3696 && strcmp (section->name, ".debug_line.dwo") != 0)
b4eb7656 3697 {
4925cdd7 3698 /* See comment in display_debug_lines_raw(). */
b40bf0a2
NC
3699 end_of_sequence = end;
3700 standard_opcodes = NULL;
3701 linfo = saved_linfo;
058037d3
NC
3702 /* PR 17531: file: 0522b371. */
3703 if (linfo.li_line_range == 0)
3704 {
1306a742 3705 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
058037d3
NC
3706 return 0;
3707 }
b40bf0a2 3708 reset_state_machine (linfo.li_default_is_stmt);
b4eb7656 3709 }
a262ae96 3710 else
b4eb7656 3711 {
b40bf0a2 3712 unsigned char *hdrptr;
a262ae96 3713
b40bf0a2
NC
3714 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3715 & end_of_sequence)) == NULL)
a233b20c 3716 return 0;
0c588247 3717
058037d3
NC
3718 /* PR 17531: file: 0522b371. */
3719 if (linfo.li_line_range == 0)
3720 {
3721 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3722 linfo.li_line_range = 1;
3723 }
b40bf0a2 3724 reset_state_machine (linfo.li_default_is_stmt);
a262ae96 3725
b40bf0a2
NC
3726 /* Save a pointer to the contents of the Opcodes table. */
3727 standard_opcodes = hdrptr;
a262ae96 3728
b40bf0a2
NC
3729 /* Traverse the Directory table just to count entries. */
3730 data = standard_opcodes + linfo.li_opcode_base - 1;
d8024a91
NC
3731 /* PR 20440 */
3732 if (data >= end)
3733 {
3734 warn (_("opcode base of %d extends beyond end of section\n"),
3735 linfo.li_opcode_base);
3736 return 0;
3737 }
3738
77145576 3739 if (linfo.li_version >= 5)
b40bf0a2 3740 {
77145576
JK
3741 unsigned char *format_start, format_count, *format;
3742 dwarf_vma formati, entryi;
3743 unsigned int bytes_read;
a262ae96 3744
77145576
JK
3745 load_debug_section (line_str, fileptr);
3746
3747 /* Skip directories format. */
3748 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3749 format_start = data;
3750 for (formati = 0; formati < format_count; formati++)
b40bf0a2 3751 {
77145576
JK
3752 read_uleb128 (data, & bytes_read, end);
3753 data += bytes_read;
3754 read_uleb128 (data, & bytes_read, end);
3755 data += bytes_read;
b40bf0a2 3756 }
a262ae96 3757
77145576
JK
3758 n_directories = read_uleb128 (data, & bytes_read, end);
3759 data += bytes_read;
3760 if (data == end)
d8024a91 3761 {
77145576 3762 warn (_("Corrupt directories list\n"));
d8024a91
NC
3763 break;
3764 }
3765
b40bf0a2
NC
3766 directory_table = (unsigned char **)
3767 xmalloc (n_directories * sizeof (unsigned char *));
a262ae96 3768
77145576 3769 for (entryi = 0; entryi < n_directories; entryi++)
b40bf0a2 3770 {
77145576 3771 unsigned char **pathp = &directory_table[entryi];
a262ae96 3772
77145576
JK
3773 format = format_start;
3774 for (formati = 0; formati < format_count; formati++)
3775 {
3776 dwarf_vma content_type, form;
3777 dwarf_vma uvalue;
3778
3779 content_type = read_uleb128 (format, & bytes_read, end);
3780 format += bytes_read;
3781 form = read_uleb128 (format, & bytes_read, end);
3782 format += bytes_read;
3783 if (data == end)
3784 {
3785 warn (_("Corrupt directories list\n"));
3786 break;
3787 }
3788 switch (content_type)
3789 {
3790 case DW_LNCT_path:
3791 switch (form)
3792 {
3793 case DW_FORM_string:
3794 *pathp = data;
3795 break;
3796 case DW_FORM_line_strp:
3797 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
3798 end);
3799 /* Remove const by the cast. */
3800 *pathp = (unsigned char *)
3801 fetch_indirect_line_string (uvalue);
3802 break;
3803 }
3804 break;
3805 }
3806 data = read_and_display_attr_value (0, form, 0, data, end,
3807 0, 0,
3808 linfo.li_offset_size,
3809 linfo.li_version,
3810 NULL, 1, section,
3811 NULL, '\t');
3812 }
3813 if (data == end)
3814 {
3815 warn (_("Corrupt directories list\n"));
3816 break;
3817 }
3818 }
a262ae96 3819
77145576
JK
3820 /* Skip files format. */
3821 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3822 format_start = data;
3823 for (formati = 0; formati < format_count; formati++)
b40bf0a2 3824 {
b40bf0a2
NC
3825 read_uleb128 (data, & bytes_read, end);
3826 data += bytes_read;
3827 read_uleb128 (data, & bytes_read, end);
3828 data += bytes_read;
b40bf0a2 3829 }
a262ae96 3830
77145576
JK
3831 n_files = read_uleb128 (data, & bytes_read, end);
3832 data += bytes_read;
3833 if (data == end)
d8024a91 3834 {
77145576 3835 warn (_("Corrupt file name list\n"));
d8024a91
NC
3836 break;
3837 }
3838
77145576
JK
3839 file_table = (File_Entry *) xcalloc (1, n_files
3840 * sizeof (File_Entry));
a262ae96 3841
77145576 3842 for (entryi = 0; entryi < n_files; entryi++)
b40bf0a2 3843 {
77145576 3844 File_Entry *file = &file_table[entryi];
a262ae96 3845
77145576
JK
3846 format = format_start;
3847 for (formati = 0; formati < format_count; formati++)
3848 {
3849 dwarf_vma content_type, form;
3850 dwarf_vma uvalue;
3851
3852 content_type = read_uleb128 (format, & bytes_read, end);
3853 format += bytes_read;
3854 form = read_uleb128 (format, & bytes_read, end);
3855 format += bytes_read;
3856 if (data == end)
3857 {
3858 warn (_("Corrupt file name list\n"));
3859 break;
3860 }
3861 switch (content_type)
3862 {
3863 case DW_LNCT_path:
3864 switch (form)
3865 {
3866 case DW_FORM_string:
3867 file->name = data;
3868 break;
3869 case DW_FORM_line_strp:
3870 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
3871 end);
3872 /* Remove const by the cast. */
3873 file->name = (unsigned char *)
3874 fetch_indirect_line_string (uvalue);
3875 break;
3876 }
3877 break;
3878 case DW_LNCT_directory_index:
3879 switch (form)
3880 {
3881 case DW_FORM_data1:
3882 SAFE_BYTE_GET (file->directory_index, data, 1,
3883 end);
3884 break;
3885 case DW_FORM_data2:
3886 SAFE_BYTE_GET (file->directory_index, data, 2,
3887 end);
3888 break;
3889 case DW_FORM_udata:
3890 file->directory_index = read_uleb128 (data, NULL,
3891 end);
3892 break;
3893 }
3894 break;
3895 }
3896 data = read_and_display_attr_value (0, form, 0, data, end,
3897 0, 0,
3898 linfo.li_offset_size,
3899 linfo.li_version,
3900 NULL, 1, section,
3901 NULL, '\t');
3902 }
3903 if (data == end)
3904 {
3905 warn (_("Corrupt file name list\n"));
3906 break;
3907 }
3908 }
3909 }
3910 else
3911 {
3912 if (*data != 0)
b40bf0a2 3913 {
77145576
JK
3914 unsigned char *ptr_directory_table = data;
3915
3916 while (data < end && *data != 0)
3917 {
3918 data += strnlen ((char *) data, end - data) + 1;
3919 n_directories++;
3920 }
3921
3922 /* PR 20440 */
3923 if (data >= end)
3924 {
3925 warn (_("directory table ends unexpectedly\n"));
3926 n_directories = 0;
3927 break;
3928 }
3929
3930 /* Go through the directory table again to save the directories. */
3931 directory_table = (unsigned char **)
3932 xmalloc (n_directories * sizeof (unsigned char *));
3933
3934 i = 0;
3935 while (*ptr_directory_table != 0)
3936 {
3937 directory_table[i] = ptr_directory_table;
3938 ptr_directory_table += strnlen ((char *) ptr_directory_table,
3939 ptr_directory_table - end) + 1;
3940 i++;
3941 }
b40bf0a2 3942 }
77145576
JK
3943 /* Skip the NUL at the end of the table. */
3944 data++;
3945
3946 /* Traverse the File Name table just to count the entries. */
3947 if (data < end && *data != 0)
b40bf0a2 3948 {
77145576
JK
3949 unsigned char *ptr_file_name_table = data;
3950
3951 while (data < end && *data != 0)
db9537d2 3952 {
77145576
JK
3953 unsigned int bytes_read;
3954
3955 /* Skip Name, directory index, last modification time and length
3956 of file. */
3957 data += strnlen ((char *) data, end - data) + 1;
3958 read_uleb128 (data, & bytes_read, end);
3959 data += bytes_read;
3960 read_uleb128 (data, & bytes_read, end);
3961 data += bytes_read;
3962 read_uleb128 (data, & bytes_read, end);
3963 data += bytes_read;
3964
3965 n_files++;
db9537d2 3966 }
a262ae96 3967
77145576
JK
3968 if (data >= end)
3969 {
3970 warn (_("file table ends unexpectedly\n"));
3971 n_files = 0;
3972 break;
3973 }
3974
3975 /* Go through the file table again to save the strings. */
3976 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
0c588247 3977
77145576
JK
3978 i = 0;
3979 while (*ptr_file_name_table != 0)
3980 {
3981 unsigned int bytes_read;
3982
3983 file_table[i].name = ptr_file_name_table;
3984 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
3985 end - ptr_file_name_table) + 1;
3986
3987 /* We are not interested in directory, time or size. */
3988 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
3989 & bytes_read, end);
3990 ptr_file_name_table += bytes_read;
3991 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
3992 & bytes_read, end);
3993 ptr_file_name_table += bytes_read;
3994 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
3995 ptr_file_name_table += bytes_read;
3996 i++;
3997 }
3998 i = 0;
b40bf0a2 3999 }
77145576
JK
4000
4001 /* Skip the NUL at the end of the table. */
4002 data++;
b40bf0a2 4003 }
cc5914eb 4004
77145576 4005 /* Print the Compilation Unit's name and a header. */
f082820d
AM
4006 if (file_table == NULL)
4007 ;
4008 else if (directory_table == NULL)
4009 printf (_("CU: %s:\n"), file_table[0].name);
77145576
JK
4010 else
4011 {
4012 unsigned int ix = file_table[0].directory_index;
4013 const char *directory;
4014
4015 if (ix == 0)
4016 directory = ".";
4017 /* PR 20439 */
4018 else if (n_directories == 0)
4019 directory = _("<unknown>");
4020 else if (ix > n_directories)
4021 {
4022 warn (_("directory index %u > number of directories %s\n"),
4023 ix, dwarf_vmatoa ("u", n_directories));
4024 directory = _("<corrupt>");
4025 }
4026 else
4027 directory = (char *) directory_table[ix - 1];
4028
4029 if (do_wide || strlen (directory) < 76)
4030 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
4031 else
4032 printf ("%s:\n", file_table[0].name);
77145576 4033 }
a262ae96 4034
ba8826a8 4035 printf (_("File name Line number Starting address View\n"));
b40bf0a2
NC
4036 saved_linfo = linfo;
4037 }
a262ae96
NC
4038
4039 /* This loop iterates through the Dwarf Line Number Program. */
4040 while (data < end_of_sequence)
b4eb7656 4041 {
a262ae96 4042 unsigned char op_code;
ba8826a8 4043 int xop;
b4eb7656
AM
4044 int adv;
4045 unsigned long int uladv;
4046 unsigned int bytes_read;
4047 int is_special_opcode = 0;
a262ae96 4048
b4eb7656 4049 op_code = *data++;
ba8826a8 4050 xop = op_code;
a262ae96 4051
b4eb7656 4052 if (op_code >= linfo.li_opcode_base)
a262ae96 4053 {
91d6fa6a 4054 op_code -= linfo.li_opcode_base;
a233b20c
JJ
4055 uladv = (op_code / linfo.li_line_range);
4056 if (linfo.li_max_ops_per_insn == 1)
4057 {
4058 uladv *= linfo.li_min_insn_length;
4059 state_machine_regs.address += uladv;
ba8826a8
AO
4060 if (uladv)
4061 state_machine_regs.view = 0;
a233b20c
JJ
4062 }
4063 else
4064 {
ba8826a8
AO
4065 unsigned addrdelta
4066 = ((state_machine_regs.op_index + uladv)
4067 / linfo.li_max_ops_per_insn)
b40bf0a2 4068 * linfo.li_min_insn_length;
ba8826a8
AO
4069 state_machine_regs.address
4070 += addrdelta;
a233b20c
JJ
4071 state_machine_regs.op_index
4072 = (state_machine_regs.op_index + uladv)
b40bf0a2 4073 % linfo.li_max_ops_per_insn;
ba8826a8
AO
4074 if (addrdelta)
4075 state_machine_regs.view = 0;
a233b20c 4076 }
a262ae96 4077
b4eb7656
AM
4078 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
4079 state_machine_regs.line += adv;
4080 is_special_opcode = 1;
ba8826a8 4081 /* Increment view after printing this row. */
b4eb7656
AM
4082 }
4083 else switch (op_code)
b40bf0a2
NC
4084 {
4085 case DW_LNS_extended_op:
4086 {
4087 unsigned int ext_op_code_len;
4088 unsigned char ext_op_code;
4089 unsigned char *op_code_data = data;
4090
4091 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
4092 end_of_sequence);
4093 op_code_data += bytes_read;
4094
4095 if (ext_op_code_len == 0)
4096 {
f41e4712 4097 warn (_("Badly formed extended line op encountered!\n"));
b40bf0a2
NC
4098 break;
4099 }
4100 ext_op_code_len += bytes_read;
4101 ext_op_code = *op_code_data++;
ba8826a8
AO
4102 xop = ext_op_code;
4103 xop = -xop;
b40bf0a2
NC
4104
4105 switch (ext_op_code)
4106 {
4107 case DW_LNE_end_sequence:
ba8826a8 4108 /* Reset stuff after printing this row. */
b40bf0a2
NC
4109 break;
4110 case DW_LNE_set_address:
4111 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
87bc83b3
CC
4112 op_code_data,
4113 ext_op_code_len - bytes_read - 1,
b40bf0a2
NC
4114 end);
4115 state_machine_regs.op_index = 0;
ba8826a8 4116 state_machine_regs.view = 0;
b40bf0a2
NC
4117 break;
4118 case DW_LNE_define_file:
4119 {
4120 file_table = (File_Entry *) xrealloc
4121 (file_table, (n_files + 1) * sizeof (File_Entry));
4122
4123 ++state_machine_regs.last_file_entry;
4124 /* Source file name. */
4125 file_table[n_files].name = op_code_data;
4126 op_code_data += strlen ((char *) op_code_data) + 1;
4127 /* Directory index. */
4128 file_table[n_files].directory_index =
4129 read_uleb128 (op_code_data, & bytes_read,
4130 end_of_sequence);
4131 op_code_data += bytes_read;
4132 /* Last modification time. */
4133 file_table[n_files].modification_date =
4134 read_uleb128 (op_code_data, & bytes_read,
4135 end_of_sequence);
4136 op_code_data += bytes_read;
4137 /* File length. */
4138 file_table[n_files].length =
4139 read_uleb128 (op_code_data, & bytes_read,
4140 end_of_sequence);
4141
4142 n_files++;
4143 break;
4144 }
4145 case DW_LNE_set_discriminator:
4146 case DW_LNE_HP_set_sequence:
4147 /* Simply ignored. */
4148 break;
4149
4150 default:
4151 printf (_("UNKNOWN (%u): length %d\n"),
4152 ext_op_code, ext_op_code_len - bytes_read);
4153 break;
4154 }
4155 data += ext_op_code_len;
4156 break;
4157 }
4158 case DW_LNS_copy:
ba8826a8 4159 /* Increment view after printing this row. */
b40bf0a2
NC
4160 break;
4161
4162 case DW_LNS_advance_pc:
4163 uladv = read_uleb128 (data, & bytes_read, end);
4164 data += bytes_read;
4165 if (linfo.li_max_ops_per_insn == 1)
4166 {
4167 uladv *= linfo.li_min_insn_length;
4168 state_machine_regs.address += uladv;
ba8826a8
AO
4169 if (uladv)
4170 state_machine_regs.view = 0;
b40bf0a2
NC
4171 }
4172 else
4173 {
ba8826a8
AO
4174 unsigned addrdelta
4175 = ((state_machine_regs.op_index + uladv)
4176 / linfo.li_max_ops_per_insn)
b40bf0a2 4177 * linfo.li_min_insn_length;
ba8826a8
AO
4178 state_machine_regs.address
4179 += addrdelta;
b40bf0a2
NC
4180 state_machine_regs.op_index
4181 = (state_machine_regs.op_index + uladv)
4182 % linfo.li_max_ops_per_insn;
ba8826a8
AO
4183 if (addrdelta)
4184 state_machine_regs.view = 0;
b40bf0a2
NC
4185 }
4186 break;
4187
4188 case DW_LNS_advance_line:
4189 adv = read_sleb128 (data, & bytes_read, end);
4190 data += bytes_read;
4191 state_machine_regs.line += adv;
4192 break;
4193
4194 case DW_LNS_set_file:
4195 adv = read_uleb128 (data, & bytes_read, end);
4196 data += bytes_read;
4197 state_machine_regs.file = adv;
4198
db9537d2
NC
4199 {
4200 unsigned file = state_machine_regs.file - 1;
4201 unsigned dir;
4202
4203 if (file_table == NULL || n_files == 0)
4204 printf (_("\n [Use file table entry %d]\n"), file);
4205 /* PR 20439 */
4206 else if (file >= n_files)
4207 {
4208 warn (_("file index %u > number of files %u\n"), file + 1, n_files);
4209 printf (_("\n <over large file table index %u>"), file);
4210 }
4211 else if ((dir = file_table[file].directory_index) == 0)
4212 /* If directory index is 0, that means current directory. */
4213 printf ("\n./%s:[++]\n", file_table[file].name);
4214 else if (directory_table == NULL || n_directories == 0)
4215 printf (_("\n [Use file %s in directory table entry %d]\n"),
4216 file_table[file].name, dir);
4217 /* PR 20439 */
4218 else if (dir > n_directories)
4219 {
77145576
JK
4220 warn (_("directory index %u > number of directories %s\n"),
4221 dir, dwarf_vmatoa ("u", n_directories));
db9537d2
NC
4222 printf (_("\n <over large directory table entry %u>\n"), dir);
4223 }
4224 else
4225 printf ("\n%s/%s:\n",
4226 /* The directory index starts counting at 1. */
4227 directory_table[dir - 1], file_table[file].name);
4228 }
b40bf0a2
NC
4229 break;
4230
4231 case DW_LNS_set_column:
4232 uladv = read_uleb128 (data, & bytes_read, end);
4233 data += bytes_read;
4234 state_machine_regs.column = uladv;
4235 break;
4236
4237 case DW_LNS_negate_stmt:
4238 adv = state_machine_regs.is_stmt;
4239 adv = ! adv;
4240 state_machine_regs.is_stmt = adv;
4241 break;
4242
4243 case DW_LNS_set_basic_block:
4244 state_machine_regs.basic_block = 1;
4245 break;
4246
4247 case DW_LNS_const_add_pc:
4248 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
4249 if (linfo.li_max_ops_per_insn == 1)
4250 {
4251 uladv *= linfo.li_min_insn_length;
4252 state_machine_regs.address += uladv;
ba8826a8
AO
4253 if (uladv)
4254 state_machine_regs.view = 0;
b40bf0a2
NC
4255 }
4256 else
4257 {
ba8826a8
AO
4258 unsigned addrdelta
4259 = ((state_machine_regs.op_index + uladv)
4260 / linfo.li_max_ops_per_insn)
b40bf0a2 4261 * linfo.li_min_insn_length;
ba8826a8
AO
4262 state_machine_regs.address
4263 += addrdelta;
b40bf0a2
NC
4264 state_machine_regs.op_index
4265 = (state_machine_regs.op_index + uladv)
4266 % linfo.li_max_ops_per_insn;
ba8826a8
AO
4267 if (addrdelta)
4268 state_machine_regs.view = 0;
b40bf0a2
NC
4269 }
4270 break;
4271
4272 case DW_LNS_fixed_advance_pc:
4273 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
4274 state_machine_regs.address += uladv;
4275 state_machine_regs.op_index = 0;
ba8826a8 4276 /* Do NOT reset view. */
b40bf0a2
NC
4277 break;
4278
4279 case DW_LNS_set_prologue_end:
4280 break;
4281
4282 case DW_LNS_set_epilogue_begin:
4283 break;
4284
4285 case DW_LNS_set_isa:
4286 uladv = read_uleb128 (data, & bytes_read, end);
4287 data += bytes_read;
4288 printf (_(" Set ISA to %lu\n"), uladv);
4289 break;
4290
4291 default:
4292 printf (_(" Unknown opcode %d with operands: "), op_code);
4293
4294 if (standard_opcodes != NULL)
4295 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
4296 {
4297 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
4298 &bytes_read, end)),
4299 i == 1 ? "" : ", ");
4300 data += bytes_read;
4301 }
4302 putchar ('\n');
4303 break;
4304 }
a262ae96 4305
b4eb7656
AM
4306 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4307 to the DWARF address/line matrix. */
ba8826a8
AO
4308 if ((is_special_opcode) || (xop == -DW_LNE_end_sequence)
4309 || (xop == DW_LNS_copy))
b4eb7656
AM
4310 {
4311 const unsigned int MAX_FILENAME_LENGTH = 35;
4312 char *fileName;
4313 char *newFileName = NULL;
4314 size_t fileNameLength;
b40bf0a2
NC
4315
4316 if (file_table)
db9537d2
NC
4317 {
4318 unsigned indx = state_machine_regs.file - 1;
4319 /* PR 20439 */
4320 if (indx >= n_files)
4321 {
4322 warn (_("corrupt file index %u encountered\n"), indx);
4323 fileName = _("<corrupt>");
4324 }
4325 else
4326 fileName = (char *) file_table[indx].name;
4327 }
b40bf0a2 4328 else
db9537d2 4329 fileName = _("<unknown>");
b40bf0a2
NC
4330
4331 fileNameLength = strlen (fileName);
a262ae96 4332
b4eb7656
AM
4333 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
4334 {
4335 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
4336 /* Truncate file name */
4337 strncpy (newFileName,
4338 fileName + fileNameLength - MAX_FILENAME_LENGTH,
4339 MAX_FILENAME_LENGTH + 1);
4340 }
4341 else
4342 {
4343 newFileName = (char *) xmalloc (fileNameLength + 1);
4344 strncpy (newFileName, fileName, fileNameLength + 1);
4345 }
4346
4347 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
4348 {
a233b20c 4349 if (linfo.li_max_ops_per_insn == 1)
ba8826a8 4350 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x",
467c65bc 4351 newFileName, state_machine_regs.line,
a233b20c
JJ
4352 state_machine_regs.address);
4353 else
ba8826a8 4354 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]",
467c65bc 4355 newFileName, state_machine_regs.line,
a233b20c
JJ
4356 state_machine_regs.address,
4357 state_machine_regs.op_index);
b4eb7656
AM
4358 }
4359 else
4360 {
a233b20c 4361 if (linfo.li_max_ops_per_insn == 1)
ba8826a8 4362 printf ("%s %11d %#18" DWARF_VMA_FMT "x",
467c65bc 4363 newFileName, state_machine_regs.line,
a233b20c
JJ
4364 state_machine_regs.address);
4365 else
ba8826a8 4366 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]",
467c65bc 4367 newFileName, state_machine_regs.line,
a233b20c
JJ
4368 state_machine_regs.address,
4369 state_machine_regs.op_index);
b4eb7656 4370 }
a262ae96 4371
ba8826a8
AO
4372 if (state_machine_regs.view)
4373 printf (" %6u\n", state_machine_regs.view);
4374 else
4375 putchar ('\n');
4376 state_machine_regs.view++;
4377
4378 if (xop == -DW_LNE_end_sequence)
4379 {
4380 reset_state_machine (linfo.li_default_is_stmt);
4381 putchar ('\n');
4382 }
a262ae96 4383
b4eb7656
AM
4384 free (newFileName);
4385 }
4386 }
b40bf0a2
NC
4387
4388 if (file_table)
4389 {
4390 free (file_table);
4391 file_table = NULL;
4392 n_files = 0;
4393 }
4394
4395 if (directory_table)
4396 {
4397 free (directory_table);
4398 directory_table = NULL;
4399 n_directories = 0;
4400 }
4401
a262ae96
NC
4402 putchar ('\n');
4403 }
4404
4405 return 1;
4406}
4407
4408static int
77145576 4409display_debug_lines (struct dwarf_section *section, void *file)
a262ae96
NC
4410{
4411 unsigned char *data = section->start;
4412 unsigned char *end = data + section->size;
4cb93e3b
TG
4413 int retValRaw = 1;
4414 int retValDecoded = 1;
a262ae96 4415
008f4c78
NC
4416 if (do_debug_lines == 0)
4417 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
4418
4cb93e3b 4419 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
77145576 4420 retValRaw = display_debug_lines_raw (section, data, end, file);
a262ae96 4421
4cb93e3b 4422 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
77145576 4423 retValDecoded = display_debug_lines_decoded (section, data, end, file);
a262ae96 4424
4cb93e3b 4425 if (!retValRaw || !retValDecoded)
a262ae96
NC
4426 return 0;
4427
4428 return 1;
4429}
4430
6e3d6dc1
NC
4431static debug_info *
4432find_debug_info_for_offset (unsigned long offset)
4433{
4434 unsigned int i;
4435
4436 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
4437 return NULL;
4438
4439 for (i = 0; i < num_debug_info_entries; i++)
4440 if (debug_information[i].cu_offset == offset)
4441 return debug_information + i;
4442
4443 return NULL;
4444}
4445
459d52c8
DE
4446static const char *
4447get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
4448{
4449 /* See gdb/gdb-index.h. */
4450 static const char * const kinds[] =
4451 {
4452 N_ ("no info"),
4453 N_ ("type"),
4454 N_ ("variable"),
4455 N_ ("function"),
4456 N_ ("other"),
4457 N_ ("unused5"),
4458 N_ ("unused6"),
4459 N_ ("unused7")
4460 };
4461
4462 return _ (kinds[kind]);
4463}
4464
19e6b90e 4465static int
459d52c8
DE
4466display_debug_pubnames_worker (struct dwarf_section *section,
4467 void *file ATTRIBUTE_UNUSED,
4468 int is_gnu)
19e6b90e 4469{
91d6fa6a 4470 DWARF2_Internal_PubNames names;
19e6b90e
L
4471 unsigned char *start = section->start;
4472 unsigned char *end = start + section->size;
4473
6e3d6dc1
NC
4474 /* It does not matter if this load fails,
4475 we test for that later on. */
4476 load_debug_info (file);
4477
19e6b90e
L
4478 printf (_("Contents of the %s section:\n\n"), section->name);
4479
4480 while (start < end)
4481 {
4482 unsigned char *data;
362beea4 4483 unsigned char *adr;
834f871c 4484 dwarf_vma offset;
bf5117e3 4485 unsigned int offset_size, initial_length_size;
19e6b90e
L
4486
4487 data = start;
4488
0c588247 4489 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end);
91d6fa6a 4490 if (names.pn_length == 0xffffffff)
19e6b90e 4491 {
0c588247 4492 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end);
19e6b90e
L
4493 offset_size = 8;
4494 initial_length_size = 12;
4495 }
4496 else
4497 {
4498 offset_size = 4;
4499 initial_length_size = 4;
4500 }
4501
0c588247
NC
4502 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
4503 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
6e3d6dc1
NC
4504
4505 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4506 && num_debug_info_entries > 0
91d6fa6a 4507 && find_debug_info_for_offset (names.pn_offset) == NULL)
6e3d6dc1 4508 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
47704ddf 4509 (unsigned long) names.pn_offset, section->name);
cecf136e 4510
0c588247 4511 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
19e6b90e 4512
362beea4 4513 adr = start + names.pn_length + initial_length_size;
058037d3 4514 /* PR 17531: file: 7615b6b2. */
57028622
NC
4515 if ((dwarf_signed_vma) names.pn_length < 0
4516 /* PR 17531: file: a5dbeaa7. */
362beea4 4517 || adr < start)
058037d3
NC
4518 {
4519 warn (_("Negative length for public name: 0x%lx\n"), (long) names.pn_length);
4520 start = end;
4521 }
4522 else
362beea4 4523 start = adr;
b4eb7656 4524
058037d3
NC
4525 printf (_(" Length: %ld\n"),
4526 (long) names.pn_length);
4527 printf (_(" Version: %d\n"),
4528 names.pn_version);
4529 printf (_(" Offset into .debug_info section: 0x%lx\n"),
4530 (unsigned long) names.pn_offset);
4531 printf (_(" Size of area in .debug_info section: %ld\n"),
4532 (long) names.pn_size);
19e6b90e 4533
91d6fa6a 4534 if (names.pn_version != 2 && names.pn_version != 3)
19e6b90e
L
4535 {
4536 static int warned = 0;
4537
4538 if (! warned)
4539 {
4540 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
4541 warned = 1;
4542 }
4543
4544 continue;
4545 }
4546
459d52c8
DE
4547 if (is_gnu)
4548 printf (_("\n Offset Kind Name\n"));
4549 else
4550 printf (_("\n Offset\tName\n"));
19e6b90e
L
4551
4552 do
4553 {
f41e4712
NC
4554 bfd_size_type maxprint;
4555
0c588247 4556 SAFE_BYTE_GET (offset, data, offset_size, end);
19e6b90e
L
4557
4558 if (offset != 0)
4559 {
4560 data += offset_size;
f41e4712
NC
4561 if (data >= end)
4562 break;
4563 maxprint = (end - data) - 1;
b4eb7656 4564
459d52c8
DE
4565 if (is_gnu)
4566 {
4567 unsigned int kind_data;
4568 gdb_index_symbol_kind kind;
4569 const char *kind_name;
4570 int is_static;
4571
4572 SAFE_BYTE_GET (kind_data, data, 1, end);
4573 data++;
f41e4712 4574 maxprint --;
459d52c8
DE
4575 /* GCC computes the kind as the upper byte in the CU index
4576 word, and then right shifts it by the CU index size.
4577 Left shift KIND to where the gdb-index.h accessor macros
4578 can use it. */
4579 kind_data <<= GDB_INDEX_CU_BITSIZE;
4580 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
4581 kind_name = get_gdb_index_symbol_kind_name (kind);
4582 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
f41e4712 4583 printf (" %-6lx %s,%-10s %.*s\n",
834f871c 4584 (unsigned long) offset, is_static ? _("s") : _("g"),
f41e4712 4585 kind_name, (int) maxprint, data);
459d52c8
DE
4586 }
4587 else
b4eb7656
AM
4588 printf (" %-6lx\t%.*s\n",
4589 (unsigned long) offset, (int) maxprint, data);
f41e4712
NC
4590
4591 data += strnlen ((char *) data, maxprint) + 1;
4592 if (data >= end)
4593 break;
19e6b90e
L
4594 }
4595 }
4596 while (offset != 0);
4597 }
4598
4599 printf ("\n");
4600 return 1;
4601}
4602
459d52c8
DE
4603static int
4604display_debug_pubnames (struct dwarf_section *section, void *file)
4605{
4606 return display_debug_pubnames_worker (section, file, 0);
4607}
4608
4609static int
4610display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
4611{
4612 return display_debug_pubnames_worker (section, file, 1);
4613}
4614
19e6b90e
L
4615static int
4616display_debug_macinfo (struct dwarf_section *section,
4617 void *file ATTRIBUTE_UNUSED)
4618{
4619 unsigned char *start = section->start;
4620 unsigned char *end = start + section->size;
4621 unsigned char *curr = start;
4622 unsigned int bytes_read;
4623 enum dwarf_macinfo_record_type op;
4624
4625 printf (_("Contents of the %s section:\n\n"), section->name);
4626
4627 while (curr < end)
4628 {
4629 unsigned int lineno;
0c588247 4630 const unsigned char *string;
19e6b90e 4631
3f5e193b 4632 op = (enum dwarf_macinfo_record_type) *curr;
19e6b90e
L
4633 curr++;
4634
4635 switch (op)
4636 {
4637 case DW_MACINFO_start_file:
4638 {
4639 unsigned int filenum;
4640
f6f0e17b 4641 lineno = read_uleb128 (curr, & bytes_read, end);
19e6b90e 4642 curr += bytes_read;
f6f0e17b 4643 filenum = read_uleb128 (curr, & bytes_read, end);
19e6b90e
L
4644 curr += bytes_read;
4645
4646 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
4647 lineno, filenum);
4648 }
4649 break;
4650
4651 case DW_MACINFO_end_file:
4652 printf (_(" DW_MACINFO_end_file\n"));
4653 break;
4654
4655 case DW_MACINFO_define:
f6f0e17b 4656 lineno = read_uleb128 (curr, & bytes_read, end);
19e6b90e 4657 curr += bytes_read;
0c588247
NC
4658 string = curr;
4659 curr += strnlen ((char *) string, end - string) + 1;
19e6b90e
L
4660 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
4661 lineno, string);
4662 break;
4663
4664 case DW_MACINFO_undef:
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_undef - lineno : %d macro : %s\n"),
4670 lineno, string);
4671 break;
4672
4673 case DW_MACINFO_vendor_ext:
4674 {
4675 unsigned int constant;
4676
f6f0e17b 4677 constant = read_uleb128 (curr, & bytes_read, end);
19e6b90e 4678 curr += bytes_read;
0c588247
NC
4679 string = curr;
4680 curr += strnlen ((char *) string, end - string) + 1;
19e6b90e
L
4681 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4682 constant, string);
4683 }
4684 break;
4685 }
4686 }
4687
4688 return 1;
4689}
4690
4ccf1e31
JJ
4691/* Given LINE_OFFSET into the .debug_line section, attempt to return
4692 filename and dirname corresponding to file name table entry with index
4693 FILEIDX. Return NULL on failure. */
4694
4695static unsigned char *
f6f0e17b
NC
4696get_line_filename_and_dirname (dwarf_vma line_offset,
4697 dwarf_vma fileidx,
4ccf1e31
JJ
4698 unsigned char **dir_name)
4699{
4700 struct dwarf_section *section = &debug_displays [line].section;
4701 unsigned char *hdrptr, *dirtable, *file_name;
4702 unsigned int offset_size, initial_length_size;
4703 unsigned int version, opcode_base, bytes_read;
4704 dwarf_vma length, diridx;
f6f0e17b 4705 const unsigned char * end;
4ccf1e31
JJ
4706
4707 *dir_name = NULL;
4708 if (section->start == NULL
4709 || line_offset >= section->size
4710 || fileidx == 0)
4711 return NULL;
4712
4713 hdrptr = section->start + line_offset;
f6f0e17b 4714 end = section->start + section->size;
0c588247
NC
4715
4716 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
4ccf1e31
JJ
4717 if (length == 0xffffffff)
4718 {
4719 /* This section is 64-bit DWARF 3. */
0c588247 4720 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
4ccf1e31
JJ
4721 offset_size = 8;
4722 initial_length_size = 12;
4723 }
4724 else
4725 {
4726 offset_size = 4;
4727 initial_length_size = 4;
4728 }
4729 if (length + initial_length_size > section->size)
4730 return NULL;
0c588247
NC
4731
4732 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
4ccf1e31
JJ
4733 if (version != 2 && version != 3 && version != 4)
4734 return NULL;
4735 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
4736 if (version >= 4)
4737 hdrptr++; /* Skip max_ops_per_insn. */
4738 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
0c588247
NC
4739
4740 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
4ccf1e31
JJ
4741 if (opcode_base == 0)
4742 return NULL;
0c588247 4743
4ccf1e31 4744 hdrptr += opcode_base - 1;
5c1c468d
NC
4745 if (hdrptr >= end)
4746 return NULL;
4747
4ccf1e31
JJ
4748 dirtable = hdrptr;
4749 /* Skip over dirname table. */
4750 while (*hdrptr != '\0')
5c1c468d
NC
4751 {
4752 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4753 if (hdrptr >= end)
4754 return NULL;
4755 }
4ccf1e31 4756 hdrptr++; /* Skip the NUL at the end of the table. */
5c1c468d 4757
4ccf1e31 4758 /* Now skip over preceding filename table entries. */
5c1c468d 4759 for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--)
4ccf1e31 4760 {
0c588247 4761 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
f6f0e17b 4762 read_uleb128 (hdrptr, &bytes_read, end);
4ccf1e31 4763 hdrptr += bytes_read;
f6f0e17b 4764 read_uleb128 (hdrptr, &bytes_read, end);
4ccf1e31 4765 hdrptr += bytes_read;
f6f0e17b 4766 read_uleb128 (hdrptr, &bytes_read, end);
4ccf1e31
JJ
4767 hdrptr += bytes_read;
4768 }
5c1c468d 4769 if (hdrptr >= end || *hdrptr == '\0')
4ccf1e31 4770 return NULL;
5c1c468d 4771
4ccf1e31 4772 file_name = hdrptr;
0c588247 4773 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
5c1c468d
NC
4774 if (hdrptr >= end)
4775 return NULL;
f6f0e17b 4776 diridx = read_uleb128 (hdrptr, &bytes_read, end);
4ccf1e31
JJ
4777 if (diridx == 0)
4778 return file_name;
5c1c468d 4779 for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--)
0c588247 4780 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
5c1c468d 4781 if (dirtable >= end || *dirtable == '\0')
4ccf1e31
JJ
4782 return NULL;
4783 *dir_name = dirtable;
4784 return file_name;
4785}
4786
4787static int
4788display_debug_macro (struct dwarf_section *section,
4789 void *file)
4790{
4791 unsigned char *start = section->start;
4792 unsigned char *end = start + section->size;
4793 unsigned char *curr = start;
4794 unsigned char *extended_op_buf[256];
4795 unsigned int bytes_read;
4796
4797 load_debug_section (str, file);
4798 load_debug_section (line, file);
4799
4800 printf (_("Contents of the %s section:\n\n"), section->name);
4801
4802 while (curr < end)
4803 {
4804 unsigned int lineno, version, flags;
4805 unsigned int offset_size = 4;
0c588247 4806 const unsigned char *string;
4ccf1e31
JJ
4807 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
4808 unsigned char **extended_ops = NULL;
4809
0c588247 4810 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
7a7e1061 4811 if (version != 4 && version != 5)
4ccf1e31 4812 {
7a7e1061 4813 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
4ccf1e31
JJ
4814 section->name);
4815 return 0;
4816 }
4817
0c588247 4818 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
4ccf1e31
JJ
4819 if (flags & 1)
4820 offset_size = 8;
4821 printf (_(" Offset: 0x%lx\n"),
4822 (unsigned long) sec_offset);
4823 printf (_(" Version: %d\n"), version);
4824 printf (_(" Offset size: %d\n"), offset_size);
4825 if (flags & 2)
4826 {
0c588247 4827 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
4ccf1e31
JJ
4828 printf (_(" Offset into .debug_line: 0x%lx\n"),
4829 (unsigned long) line_offset);
4830 }
4831 if (flags & 4)
4832 {
0c588247 4833 unsigned int i, count, op;
4ccf1e31 4834 dwarf_vma nargs, n;
0c588247
NC
4835
4836 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
bf5117e3 4837
4ccf1e31
JJ
4838 memset (extended_op_buf, 0, sizeof (extended_op_buf));
4839 extended_ops = extended_op_buf;
4840 if (count)
4841 {
4842 printf (_(" Extension opcode arguments:\n"));
4843 for (i = 0; i < count; i++)
4844 {
0c588247 4845 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4ccf1e31 4846 extended_ops[op] = curr;
f6f0e17b 4847 nargs = read_uleb128 (curr, &bytes_read, end);
4ccf1e31
JJ
4848 curr += bytes_read;
4849 if (nargs == 0)
7a7e1061 4850 printf (_(" DW_MACRO_%02x has no arguments\n"), op);
4ccf1e31
JJ
4851 else
4852 {
7a7e1061 4853 printf (_(" DW_MACRO_%02x arguments: "), op);
4ccf1e31
JJ
4854 for (n = 0; n < nargs; n++)
4855 {
0c588247
NC
4856 unsigned int form;
4857
4858 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
4ccf1e31
JJ
4859 printf ("%s%s", get_FORM_name (form),
4860 n == nargs - 1 ? "\n" : ", ");
4861 switch (form)
4862 {
4863 case DW_FORM_data1:
4864 case DW_FORM_data2:
4865 case DW_FORM_data4:
4866 case DW_FORM_data8:
4867 case DW_FORM_sdata:
4868 case DW_FORM_udata:
4869 case DW_FORM_block:
4870 case DW_FORM_block1:
4871 case DW_FORM_block2:
4872 case DW_FORM_block4:
4873 case DW_FORM_flag:
4874 case DW_FORM_string:
4875 case DW_FORM_strp:
4876 case DW_FORM_sec_offset:
4877 break;
4878 default:
4879 error (_("Invalid extension opcode form %s\n"),
4880 get_FORM_name (form));
4881 return 0;
4882 }
4883 }
4884 }
4885 }
4886 }
4887 }
4888 printf ("\n");
4889
4890 while (1)
4891 {
4892 unsigned int op;
4893
4894 if (curr >= end)
4895 {
4896 error (_(".debug_macro section not zero terminated\n"));
4897 return 0;
4898 }
4899
0c588247 4900 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4ccf1e31
JJ
4901 if (op == 0)
4902 break;
4903
4904 switch (op)
4905 {
7a7e1061 4906 case DW_MACRO_start_file:
4ccf1e31
JJ
4907 {
4908 unsigned int filenum;
4909 unsigned char *file_name = NULL, *dir_name = NULL;
4910
f6f0e17b 4911 lineno = read_uleb128 (curr, &bytes_read, end);
4ccf1e31 4912 curr += bytes_read;
f6f0e17b 4913 filenum = read_uleb128 (curr, &bytes_read, end);
4ccf1e31
JJ
4914 curr += bytes_read;
4915
4916 if ((flags & 2) == 0)
7a7e1061 4917 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
4ccf1e31
JJ
4918 else
4919 file_name
4920 = get_line_filename_and_dirname (line_offset, filenum,
4921 &dir_name);
4922 if (file_name == NULL)
7a7e1061 4923 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
4ccf1e31
JJ
4924 lineno, filenum);
4925 else
7a7e1061 4926 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4ccf1e31
JJ
4927 lineno, filenum,
4928 dir_name != NULL ? (const char *) dir_name : "",
4929 dir_name != NULL ? "/" : "", file_name);
4930 }
4931 break;
4932
7a7e1061
JK
4933 case DW_MACRO_end_file:
4934 printf (_(" DW_MACRO_end_file\n"));
4ccf1e31
JJ
4935 break;
4936
7a7e1061 4937 case DW_MACRO_define:
f6f0e17b 4938 lineno = read_uleb128 (curr, &bytes_read, end);
4ccf1e31 4939 curr += bytes_read;
0c588247
NC
4940 string = curr;
4941 curr += strnlen ((char *) string, end - string) + 1;
7a7e1061 4942 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
4ccf1e31
JJ
4943 lineno, string);
4944 break;
4945
7a7e1061 4946 case DW_MACRO_undef:
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_undef - lineno : %d macro : %s\n"),
4ccf1e31
JJ
4952 lineno, string);
4953 break;
4954
7a7e1061 4955 case DW_MACRO_define_strp:
f6f0e17b 4956 lineno = read_uleb128 (curr, &bytes_read, end);
4ccf1e31 4957 curr += bytes_read;
0c588247 4958 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4ccf1e31 4959 string = fetch_indirect_string (offset);
7a7e1061 4960 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
4ccf1e31
JJ
4961 lineno, string);
4962 break;
4963
7a7e1061 4964 case DW_MACRO_undef_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_undef_strp - lineno : %d macro : %s\n"),
4ccf1e31
JJ
4970 lineno, string);
4971 break;
4972
7a7e1061 4973 case DW_MACRO_import:
0c588247 4974 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
7a7e1061 4975 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
4ccf1e31
JJ
4976 (unsigned long) offset);
4977 break;
4978
7a7e1061 4979 case DW_MACRO_define_sup:
f6f0e17b 4980 lineno = read_uleb128 (curr, &bytes_read, end);
a081f3cd 4981 curr += bytes_read;
0c588247 4982 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
7a7e1061 4983 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
a081f3cd
JJ
4984 lineno, (unsigned long) offset);
4985 break;
4986
7a7e1061 4987 case DW_MACRO_undef_sup:
f6f0e17b 4988 lineno = read_uleb128 (curr, &bytes_read, end);
a081f3cd 4989 curr += bytes_read;
0c588247 4990 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
7a7e1061 4991 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
a081f3cd
JJ
4992 lineno, (unsigned long) offset);
4993 break;
4994
7a7e1061 4995 case DW_MACRO_import_sup:
0c588247 4996 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
7a7e1061 4997 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
a081f3cd
JJ
4998 (unsigned long) offset);
4999 break;
5000
4ccf1e31
JJ
5001 default:
5002 if (extended_ops == NULL || extended_ops[op] == NULL)
5003 {
5004 error (_(" Unknown macro opcode %02x seen\n"), op);
5005 return 0;
5006 }
5007 else
5008 {
5009 /* Skip over unhandled opcodes. */
5010 dwarf_vma nargs, n;
5011 unsigned char *desc = extended_ops[op];
f6f0e17b 5012 nargs = read_uleb128 (desc, &bytes_read, end);
4ccf1e31
JJ
5013 desc += bytes_read;
5014 if (nargs == 0)
5015 {
7a7e1061 5016 printf (_(" DW_MACRO_%02x\n"), op);
4ccf1e31
JJ
5017 break;
5018 }
7a7e1061 5019 printf (_(" DW_MACRO_%02x -"), op);
4ccf1e31
JJ
5020 for (n = 0; n < nargs; n++)
5021 {
0c588247
NC
5022 int val;
5023
77145576 5024 /* DW_FORM_implicit_const is not expected here. */
0c588247 5025 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
4ccf1e31 5026 curr
77145576 5027 = read_and_display_attr_value (0, val, 0,
f6f0e17b 5028 curr, end, 0, 0, offset_size,
341f9135 5029 version, NULL, 0, NULL,
ef0b5f1c 5030 NULL, ' ');
4ccf1e31
JJ
5031 if (n != nargs - 1)
5032 printf (",");
5033 }
5034 printf ("\n");
5035 }
5036 break;
5037 }
5038 }
5039
5040 printf ("\n");
b4eb7656 5041 }
4ccf1e31
JJ
5042
5043 return 1;
5044}
5045
19e6b90e
L
5046static int
5047display_debug_abbrev (struct dwarf_section *section,
5048 void *file ATTRIBUTE_UNUSED)
5049{
5050 abbrev_entry *entry;
5051 unsigned char *start = section->start;
5052 unsigned char *end = start + section->size;
5053
5054 printf (_("Contents of the %s section:\n\n"), section->name);
5055
5056 do
5057 {
7282333f
AM
5058 unsigned char *last;
5059
19e6b90e
L
5060 free_abbrevs ();
5061
7282333f 5062 last = start;
19e6b90e
L
5063 start = process_abbrev_section (start, end);
5064
5065 if (first_abbrev == NULL)
5066 continue;
5067
7282333f 5068 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
19e6b90e
L
5069
5070 for (entry = first_abbrev; entry; entry = entry->next)
5071 {
5072 abbrev_attr *attr;
5073
cc5914eb 5074 printf (" %ld %s [%s]\n",
19e6b90e
L
5075 entry->entry,
5076 get_TAG_name (entry->tag),
5077 entry->children ? _("has children") : _("no children"));
5078
5079 for (attr = entry->first_attr; attr; attr = attr->next)
77145576
JK
5080 {
5081 printf (" %-18s %s",
5082 get_AT_name (attr->attribute),
5083 get_FORM_name (attr->form));
5084 if (attr->form == DW_FORM_implicit_const)
5085 printf (": %" BFD_VMA_FMT "d", attr->implicit_const);
5086 putchar ('\n');
5087 }
19e6b90e
L
5088 }
5089 }
5090 while (start);
5091
5092 printf ("\n");
5093
5094 return 1;
5095}
5096
42bcef4a
AB
5097/* Return true when ADDR is the maximum address, when addresses are
5098 POINTER_SIZE bytes long. */
5099
5100static bfd_boolean
5101is_max_address (dwarf_vma addr, unsigned int pointer_size)
5102{
5103 dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1));
5104 return ((addr & mask) == mask);
5105}
5106
9f272209
AO
5107/* Display a view pair list starting at *VSTART_PTR and ending at
5108 VLISTEND within SECTION. */
5109
5110static void
5111display_view_pair_list (struct dwarf_section *section,
5112 unsigned char **vstart_ptr,
5113 unsigned int debug_info_entry,
5114 unsigned char *vlistend)
5115{
5116 unsigned char *vstart = *vstart_ptr;
5117 unsigned char *section_end = section->start + section->size;
5118 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
5119
5120 if (vlistend < section_end)
5121 section_end = vlistend;
5122
5123 putchar ('\n');
5124
5125 while (vstart < section_end)
5126 {
5127 dwarf_vma off = vstart - section->start;
5128 dwarf_vma vbegin, vend;
5129
5130 unsigned int bytes_read;
5131 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5132 vstart += bytes_read;
5133 if (vstart == section_end)
5134 {
5135 vstart -= bytes_read;
5136 break;
5137 }
5138
5139 vend = read_uleb128 (vstart, &bytes_read, section_end);
5140 vstart += bytes_read;
5141
5142 printf (" %8.8lx ", (unsigned long) off);
5143
5144 print_dwarf_view (vbegin, pointer_size, 1);
5145 print_dwarf_view (vend, pointer_size, 1);
5146 printf (_("location view pair\n"));
5147 }
5148
5149 putchar ('\n');
5150 *vstart_ptr = vstart;
5151}
5152
4723351a
CC
5153/* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
5154
5155static void
5156display_loc_list (struct dwarf_section *section,
b4eb7656
AM
5157 unsigned char **start_ptr,
5158 unsigned int debug_info_entry,
359ca075
JK
5159 dwarf_vma offset,
5160 dwarf_vma base_address,
9f272209 5161 unsigned char **vstart_ptr,
b4eb7656 5162 int has_frame_base)
4723351a 5163{
9f272209 5164 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
4723351a 5165 unsigned char *section_end = section->start + section->size;
82b1b41b
NC
5166 unsigned long cu_offset;
5167 unsigned int pointer_size;
5168 unsigned int offset_size;
5169 int dwarf_version;
4723351a
CC
5170
5171 dwarf_vma begin;
5172 dwarf_vma end;
5173 unsigned short length;
5174 int need_frame_base;
5175
82b1b41b
NC
5176 if (debug_info_entry >= num_debug_info_entries)
5177 {
5178 warn (_("No debug information available for loc lists of entry: %u\n"),
5179 debug_info_entry);
5180 return;
5181 }
b4eb7656 5182
82b1b41b
NC
5183 cu_offset = debug_information [debug_info_entry].cu_offset;
5184 pointer_size = debug_information [debug_info_entry].pointer_size;
5185 offset_size = debug_information [debug_info_entry].offset_size;
5186 dwarf_version = debug_information [debug_info_entry].dwarf_version;
b4eb7656 5187
f41e4712
NC
5188 if (pointer_size < 2 || pointer_size > 8)
5189 {
5190 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5191 pointer_size, debug_info_entry);
5192 return;
5193 }
5194
4723351a
CC
5195 while (1)
5196 {
359ca075 5197 dwarf_vma off = offset + (start - *start_ptr);
9f272209 5198 dwarf_vma vbegin = vm1, vend = vm1;
d1c4b12b 5199
4723351a 5200 if (start + 2 * pointer_size > section_end)
b4eb7656
AM
5201 {
5202 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 5203 (unsigned long) offset);
b4eb7656
AM
5204 break;
5205 }
4723351a 5206
359ca075 5207 printf (" %8.8lx ", (unsigned long) off);
fab128ef 5208
0c588247
NC
5209 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
5210 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
4723351a 5211
4723351a 5212 if (begin == 0 && end == 0)
b4eb7656 5213 {
d1c4b12b
NC
5214 /* PR 18374: In a object file we can have a location list that
5215 starts with a begin and end of 0 because there are relocations
5216 that need to be applied to the addresses. Actually applying
5217 the relocations now does not help as they will probably resolve
5218 to 0, since the object file has not been fully linked. Real
5219 end of list markers will not have any relocations against them. */
5220 if (! reloc_at (section, off)
5221 && ! reloc_at (section, off + pointer_size))
5222 {
5223 printf (_("<End of list>\n"));
5224 break;
5225 }
b4eb7656 5226 }
4723351a
CC
5227
5228 /* Check base address specifiers. */
42bcef4a
AB
5229 if (is_max_address (begin, pointer_size)
5230 && !is_max_address (end, pointer_size))
b4eb7656
AM
5231 {
5232 base_address = end;
5233 print_dwarf_vma (begin, pointer_size);
5234 print_dwarf_vma (end, pointer_size);
5235 printf (_("(base address)\n"));
5236 continue;
5237 }
4723351a 5238
9f272209
AO
5239 if (vstart)
5240 {
5241 unsigned int bytes_read;
5242
5243 off = offset + (vstart - *start_ptr);
5244
5245 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5246 vstart += bytes_read;
5247 print_dwarf_view (vbegin, pointer_size, 1);
5248
5249 vend = read_uleb128 (vstart, &bytes_read, section_end);
5250 vstart += bytes_read;
5251 print_dwarf_view (vend, pointer_size, 1);
5252
5253 printf (_("views at %8.8lx for:\n %*s "),
5254 (unsigned long) off, 8, "");
5255 }
5256
4723351a 5257 if (start + 2 > section_end)
b4eb7656
AM
5258 {
5259 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 5260 (unsigned long) offset);
b4eb7656
AM
5261 break;
5262 }
4723351a 5263
0c588247 5264 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4723351a
CC
5265
5266 if (start + length > 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
CC
5272
5273 print_dwarf_vma (begin + base_address, pointer_size);
5274 print_dwarf_vma (end + base_address, pointer_size);
5275
5276 putchar ('(');
5277 need_frame_base = decode_location_expression (start,
b4eb7656
AM
5278 pointer_size,
5279 offset_size,
5280 dwarf_version,
5281 length,
5282 cu_offset, section);
4723351a
CC
5283 putchar (')');
5284
5285 if (need_frame_base && !has_frame_base)
b4eb7656 5286 printf (_(" [without DW_AT_frame_base]"));
4723351a 5287
9f272209 5288 if (begin == end && vbegin == vend)
b4eb7656 5289 fputs (_(" (start == end)"), stdout);
9f272209 5290 else if (begin > end || (begin == end && vbegin > vend))
b4eb7656 5291 fputs (_(" (start > end)"), stdout);
4723351a
CC
5292
5293 putchar ('\n');
5294
5295 start += length;
5296 }
5297
5298 *start_ptr = start;
9f272209 5299 *vstart_ptr = vstart;
4723351a
CC
5300}
5301
77145576
JK
5302/* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5303
5304static void
5305display_loclists_list (struct dwarf_section *section,
5306 unsigned char **start_ptr,
5307 unsigned int debug_info_entry,
5308 dwarf_vma offset,
5309 dwarf_vma base_address,
9f272209 5310 unsigned char **vstart_ptr,
77145576
JK
5311 int has_frame_base)
5312{
9f272209 5313 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
77145576
JK
5314 unsigned char *section_end = section->start + section->size;
5315 unsigned long cu_offset;
5316 unsigned int pointer_size;
5317 unsigned int offset_size;
5318 int dwarf_version;
5319 unsigned int bytes_read;
5320
9dfd0db9 5321 /* Initialize it due to a false compiler warning. */
9f272209
AO
5322 dwarf_vma begin = -1, vbegin = -1;
5323 dwarf_vma end = -1, vend = -1;
77145576
JK
5324 dwarf_vma length;
5325 int need_frame_base;
5326
5327 if (debug_info_entry >= num_debug_info_entries)
5328 {
5329 warn (_("No debug information available for "
5330 "loclists lists of entry: %u\n"),
5331 debug_info_entry);
5332 return;
5333 }
5334
5335 cu_offset = debug_information [debug_info_entry].cu_offset;
5336 pointer_size = debug_information [debug_info_entry].pointer_size;
5337 offset_size = debug_information [debug_info_entry].offset_size;
5338 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5339
5340 if (pointer_size < 2 || pointer_size > 8)
5341 {
5342 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5343 pointer_size, debug_info_entry);
5344 return;
5345 }
5346
5347 while (1)
5348 {
5349 dwarf_vma off = offset + (start - *start_ptr);
5350 enum dwarf_location_list_entry_type llet;
5351
5352 if (start + 1 > section_end)
5353 {
5354 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5355 (unsigned long) offset);
5356 break;
5357 }
5358
5359 printf (" %8.8lx ", (unsigned long) off);
5360
5361 SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end);
5362
9f272209
AO
5363 if (vstart && llet == DW_LLE_offset_pair)
5364 {
5365 off = offset + (vstart - *start_ptr);
5366
5367 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5368 vstart += bytes_read;
5369 print_dwarf_view (vbegin, pointer_size, 1);
5370
5371 vend = read_uleb128 (vstart, &bytes_read, section_end);
5372 vstart += bytes_read;
5373 print_dwarf_view (vend, pointer_size, 1);
5374
5375 printf (_("views at %8.8lx for:\n %*s "),
5376 (unsigned long) off, 8, "");
5377 }
5378
77145576
JK
5379 switch (llet)
5380 {
5381 case DW_LLE_end_of_list:
5382 printf (_("<End of list>\n"));
5383 break;
5384 case DW_LLE_offset_pair:
5385 begin = read_uleb128 (start, &bytes_read, section_end);
5386 start += bytes_read;
5387 end = read_uleb128 (start, &bytes_read, section_end);
5388 start += bytes_read;
5389 break;
5390 case DW_LLE_base_address:
5391 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size,
5392 section_end);
5393 print_dwarf_vma (base_address, pointer_size);
5394 printf (_("(base address)\n"));
5395 break;
9f272209
AO
5396#ifdef DW_LLE_view_pair
5397 case DW_LLE_view_pair:
5398 if (vstart)
5399 printf (_("View pair entry in loclist with locviews attribute\n"));
5400 vbegin = read_uleb128 (start, &bytes_read, section_end);
5401 start += bytes_read;
5402 print_dwarf_view (vbegin, pointer_size, 1);
5403
5404 vend = read_uleb128 (start, &bytes_read, section_end);
5405 start += bytes_read;
5406 print_dwarf_view (vend, pointer_size, 1);
5407
5408 printf (_("views for:\n"));
5409 continue;
5410#endif
77145576
JK
5411 default:
5412 error (_("Invalid location list entry type %d\n"), llet);
5413 return;
5414 }
5415 if (llet == DW_LLE_end_of_list)
5416 break;
5417 if (llet != DW_LLE_offset_pair)
5418 continue;
5419
5420 if (start + 2 > section_end)
5421 {
5422 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5423 (unsigned long) offset);
5424 break;
5425 }
5426
5427 length = read_uleb128 (start, &bytes_read, section_end);
5428 start += bytes_read;
5429
5430 print_dwarf_vma (begin + base_address, pointer_size);
5431 print_dwarf_vma (end + base_address, pointer_size);
5432
5433 putchar ('(');
5434 need_frame_base = decode_location_expression (start,
5435 pointer_size,
5436 offset_size,
5437 dwarf_version,
5438 length,
5439 cu_offset, section);
5440 putchar (')');
5441
5442 if (need_frame_base && !has_frame_base)
5443 printf (_(" [without DW_AT_frame_base]"));
5444
9f272209 5445 if (begin == end && vbegin == vend)
77145576 5446 fputs (_(" (start == end)"), stdout);
9f272209 5447 else if (begin > end || (begin == end && vbegin > vend))
77145576
JK
5448 fputs (_(" (start > end)"), stdout);
5449
5450 putchar ('\n');
5451
5452 start += length;
9f272209 5453 vbegin = vend = -1;
77145576
JK
5454 }
5455
9f272209
AO
5456 if (vbegin != vm1 || vend != vm1)
5457 printf (_("Trailing view pair not used in a range"));
5458
77145576 5459 *start_ptr = start;
9f272209 5460 *vstart_ptr = vstart;
77145576
JK
5461}
5462
fab128ef
CC
5463/* Print a .debug_addr table index in decimal, surrounded by square brackets,
5464 right-adjusted in a field of length LEN, and followed by a space. */
5465
5466static void
5467print_addr_index (unsigned int idx, unsigned int len)
5468{
5469 static char buf[15];
5470 snprintf (buf, sizeof (buf), "[%d]", idx);
341f9135 5471 printf ("%*s ", len, buf);
fab128ef
CC
5472}
5473
4723351a
CC
5474/* Display a location list from a .dwo section. It uses address indexes rather
5475 than embedded addresses. This code closely follows display_loc_list, but the
5476 two are sufficiently different that combining things is very ugly. */
5477
5478static void
5479display_loc_list_dwo (struct dwarf_section *section,
b4eb7656
AM
5480 unsigned char **start_ptr,
5481 unsigned int debug_info_entry,
359ca075 5482 dwarf_vma offset,
9f272209 5483 unsigned char **vstart_ptr,
b4eb7656 5484 int has_frame_base)
4723351a 5485{
9f272209 5486 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
4723351a 5487 unsigned char *section_end = section->start + section->size;
82b1b41b
NC
5488 unsigned long cu_offset;
5489 unsigned int pointer_size;
5490 unsigned int offset_size;
5491 int dwarf_version;
4723351a
CC
5492 int entry_type;
5493 unsigned short length;
5494 int need_frame_base;
fab128ef 5495 unsigned int idx;
4723351a
CC
5496 unsigned int bytes_read;
5497
82b1b41b
NC
5498 if (debug_info_entry >= num_debug_info_entries)
5499 {
5500 warn (_("No debug information for loc lists of entry: %u\n"),
5501 debug_info_entry);
5502 return;
5503 }
5504
5505 cu_offset = debug_information [debug_info_entry].cu_offset;
5506 pointer_size = debug_information [debug_info_entry].pointer_size;
5507 offset_size = debug_information [debug_info_entry].offset_size;
5508 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5509
f41e4712
NC
5510 if (pointer_size < 2 || pointer_size > 8)
5511 {
5512 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5513 pointer_size, debug_info_entry);
5514 return;
5515 }
5516
4723351a
CC
5517 while (1)
5518 {
359ca075 5519 printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr)));
4723351a 5520
fab128ef 5521 if (start >= section_end)
b4eb7656
AM
5522 {
5523 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 5524 (unsigned long) offset);
b4eb7656
AM
5525 break;
5526 }
4723351a 5527
0c588247 5528 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
9f272209
AO
5529
5530 if (vstart)
5531 switch (entry_type)
5532 {
5533 default:
5534 break;
5535
5536 case 2:
5537 case 3:
5538 case 4:
5539 {
5540 dwarf_vma view;
5541 dwarf_vma off = offset + (vstart - *start_ptr);
5542
5543 view = read_uleb128 (vstart, &bytes_read, section_end);
5544 vstart += bytes_read;
5545 print_dwarf_view (view, 8, 1);
5546
5547 view = read_uleb128 (vstart, &bytes_read, section_end);
5548 vstart += bytes_read;
5549 print_dwarf_view (view, 8, 1);
5550
5551 printf (_("views at %8.8lx for:\n %*s "),
5552 (unsigned long) off, 8, "");
5553
5554 }
5555 break;
5556 }
5557
4723351a 5558 switch (entry_type)
b4eb7656
AM
5559 {
5560 case 0: /* A terminating entry. */
5561 *start_ptr = start;
9f272209 5562 *vstart_ptr = vstart;
b4eb7656
AM
5563 printf (_("<End of list>\n"));
5564 return;
5565 case 1: /* A base-address entry. */
5566 idx = read_uleb128 (start, &bytes_read, section_end);
5567 start += bytes_read;
5568 print_addr_index (idx, 8);
9f272209 5569 printf ("%*s", 9 + (vstart ? 2 * 6 : 0), "");
b4eb7656
AM
5570 printf (_("(base address selection entry)\n"));
5571 continue;
5572 case 2: /* A start/end entry. */
5573 idx = read_uleb128 (start, &bytes_read, section_end);
5574 start += bytes_read;
5575 print_addr_index (idx, 8);
5576 idx = read_uleb128 (start, &bytes_read, section_end);
5577 start += bytes_read;
5578 print_addr_index (idx, 8);
5579 break;
5580 case 3: /* A start/length entry. */
5581 idx = read_uleb128 (start, &bytes_read, section_end);
5582 start += bytes_read;
5583 print_addr_index (idx, 8);
5584 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5585 printf ("%08x ", idx);
5586 break;
5587 case 4: /* An offset pair entry. */
5588 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5589 printf ("%08x ", idx);
5590 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5591 printf ("%08x ", idx);
5592 break;
5593 default:
5594 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
5595 *start_ptr = start;
9f272209 5596 *vstart_ptr = vstart;
b4eb7656
AM
5597 return;
5598 }
4723351a
CC
5599
5600 if (start + 2 > section_end)
b4eb7656
AM
5601 {
5602 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 5603 (unsigned long) offset);
b4eb7656
AM
5604 break;
5605 }
4723351a 5606
0c588247 5607 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4723351a 5608 if (start + length > section_end)
b4eb7656
AM
5609 {
5610 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 5611 (unsigned long) offset);
b4eb7656
AM
5612 break;
5613 }
4723351a
CC
5614
5615 putchar ('(');
5616 need_frame_base = decode_location_expression (start,
b4eb7656
AM
5617 pointer_size,
5618 offset_size,
5619 dwarf_version,
5620 length,
5621 cu_offset, section);
4723351a
CC
5622 putchar (')');
5623
5624 if (need_frame_base && !has_frame_base)
b4eb7656 5625 printf (_(" [without DW_AT_frame_base]"));
4723351a
CC
5626
5627 putchar ('\n');
5628
5629 start += length;
5630 }
5631
5632 *start_ptr = start;
9f272209 5633 *vstart_ptr = vstart;
4723351a
CC
5634}
5635
9f272209
AO
5636/* Sort array of indexes in ascending order of loc_offsets[idx] and
5637 loc_views. */
51d0d03f 5638
9f272209 5639static dwarf_vma *loc_offsets, *loc_views;
51d0d03f
JJ
5640
5641static int
5642loc_offsets_compar (const void *ap, const void *bp)
5643{
5644 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
5645 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
5646
9f272209
AO
5647 int ret = (a > b) - (b > a);
5648 if (ret)
5649 return ret;
5650
5651 a = loc_views[*(const unsigned int *) ap];
5652 b = loc_views[*(const unsigned int *) bp];
5653
5654 ret = (a > b) - (b > a);
5655
5656 return ret;
51d0d03f
JJ
5657}
5658
19e6b90e
L
5659static int
5660display_debug_loc (struct dwarf_section *section, void *file)
5661{
9f272209 5662 unsigned char *start = section->start, *vstart = NULL;
19e6b90e
L
5663 unsigned long bytes;
5664 unsigned char *section_begin = start;
5665 unsigned int num_loc_list = 0;
5666 unsigned long last_offset = 0;
9f272209 5667 unsigned long last_view = 0;
19e6b90e
L
5668 unsigned int first = 0;
5669 unsigned int i;
5670 unsigned int j;
5671 int seen_first_offset = 0;
51d0d03f 5672 int locs_sorted = 1;
9f272209 5673 unsigned char *next = start, *vnext = vstart;
51d0d03f 5674 unsigned int *array = NULL;
4723351a
CC
5675 const char *suffix = strrchr (section->name, '.');
5676 int is_dwo = 0;
77145576
JK
5677 int is_loclists = strstr (section->name, "debug_loclists") != NULL;
5678 dwarf_vma expected_start = 0;
4723351a
CC
5679
5680 if (suffix && strcmp (suffix, ".dwo") == 0)
5681 is_dwo = 1;
19e6b90e
L
5682
5683 bytes = section->size;
19e6b90e
L
5684
5685 if (bytes == 0)
5686 {
5687 printf (_("\nThe %s section is empty.\n"), section->name);
5688 return 0;
5689 }
5690
77145576
JK
5691 if (is_loclists)
5692 {
5693 unsigned char *hdrptr = section_begin;
5694 dwarf_vma ll_length;
5695 unsigned short ll_version;
5696 unsigned char *end = section_begin + section->size;
5697 unsigned char address_size, segment_selector_size;
5698 uint32_t offset_entry_count;
5699
5700 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end);
5701 if (ll_length == 0xffffffff)
5702 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end);
5703
5704 SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end);
5705 if (ll_version != 5)
5706 {
5707 warn (_("The %s section contains corrupt or "
5708 "unsupported version number: %d.\n"),
5709 section->name, ll_version);
5710 return 0;
5711 }
5712
5713 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
5714
5715 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
5716 if (segment_selector_size != 0)
5717 {
5718 warn (_("The %s section contains "
5719 "unsupported segment selector size: %d.\n"),
5720 section->name, segment_selector_size);
5721 return 0;
5722 }
5723
5724 SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end);
5725 if (offset_entry_count != 0)
5726 {
5727 warn (_("The %s section contains "
5728 "unsupported offset entry count: %d.\n"),
5729 section->name, offset_entry_count);
5730 return 0;
5731 }
5732
5733 expected_start = hdrptr - section_begin;
5734 }
5735
1febe64d
NC
5736 if (load_debug_info (file) == 0)
5737 {
5738 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5739 section->name);
5740 return 0;
5741 }
19e6b90e
L
5742
5743 /* Check the order of location list in .debug_info section. If
5744 offsets of location lists are in the ascending order, we can
5745 use `debug_information' directly. */
5746 for (i = 0; i < num_debug_info_entries; i++)
5747 {
5748 unsigned int num;
5749
5750 num = debug_information [i].num_loc_offsets;
51d0d03f
JJ
5751 if (num > num_loc_list)
5752 num_loc_list = num;
19e6b90e
L
5753
5754 /* Check if we can use `debug_information' directly. */
51d0d03f 5755 if (locs_sorted && num != 0)
19e6b90e
L
5756 {
5757 if (!seen_first_offset)
5758 {
5759 /* This is the first location list. */
5760 last_offset = debug_information [i].loc_offsets [0];
9f272209 5761 last_view = debug_information [i].loc_views [0];
19e6b90e
L
5762 first = i;
5763 seen_first_offset = 1;
5764 j = 1;
5765 }
5766 else
5767 j = 0;
5768
5769 for (; j < num; j++)
5770 {
5771 if (last_offset >
9f272209
AO
5772 debug_information [i].loc_offsets [j]
5773 || (last_offset == debug_information [i].loc_offsets [j]
5774 && last_view > debug_information [i].loc_views [j]))
19e6b90e 5775 {
51d0d03f 5776 locs_sorted = 0;
19e6b90e
L
5777 break;
5778 }
5779 last_offset = debug_information [i].loc_offsets [j];
9f272209 5780 last_view = debug_information [i].loc_views [j];
19e6b90e
L
5781 }
5782 }
5783 }
5784
19e6b90e
L
5785 if (!seen_first_offset)
5786 error (_("No location lists in .debug_info section!\n"));
5787
d4bfc77b 5788 if (debug_information [first].num_loc_offsets > 0
9f272209
AO
5789 && debug_information [first].loc_offsets [0] != expected_start
5790 && debug_information [first].loc_views [0] != expected_start)
47704ddf
KT
5791 warn (_("Location lists in %s section start at 0x%s\n"),
5792 section->name,
5793 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
19e6b90e 5794
51d0d03f
JJ
5795 if (!locs_sorted)
5796 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
19e6b90e 5797 printf (_("Contents of the %s section:\n\n"), section->name);
d1c4b12b
NC
5798 if (reloc_at (section, 0))
5799 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
5800 printf (_(" Offset Begin End Expression\n"));
19e6b90e
L
5801
5802 seen_first_offset = 0;
5803 for (i = first; i < num_debug_info_entries; i++)
5804 {
9f272209 5805 dwarf_vma offset, voffset;
359ca075 5806 dwarf_vma base_address;
d1c4b12b 5807 unsigned int k;
19e6b90e
L
5808 int has_frame_base;
5809
51d0d03f
JJ
5810 if (!locs_sorted)
5811 {
5812 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
5813 array[k] = k;
5814 loc_offsets = debug_information [i].loc_offsets;
9f272209 5815 loc_views = debug_information [i].loc_views;
51d0d03f
JJ
5816 qsort (array, debug_information [i].num_loc_offsets,
5817 sizeof (*array), loc_offsets_compar);
5818 }
19e6b90e 5819
9f272209 5820 int adjacent_view_loclists = 1;
51d0d03f 5821 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
19e6b90e 5822 {
51d0d03f
JJ
5823 j = locs_sorted ? k : array[k];
5824 if (k
9f272209 5825 && (debug_information [i].loc_offsets [locs_sorted
51d0d03f 5826 ? k - 1 : array [k - 1]]
9f272209
AO
5827 == debug_information [i].loc_offsets [j])
5828 && (debug_information [i].loc_views [locs_sorted
5829 ? k - 1 : array [k - 1]]
5830 == debug_information [i].loc_views [j]))
51d0d03f 5831 continue;
19e6b90e 5832 has_frame_base = debug_information [i].have_frame_base [j];
d493b283 5833 offset = debug_information [i].loc_offsets [j];
19e6b90e 5834 next = section_begin + offset;
9f272209
AO
5835 voffset = debug_information [i].loc_views [j];
5836 if (voffset != vm1)
5837 vnext = section_begin + voffset;
5838 else
5839 vnext = NULL;
19e6b90e
L
5840 base_address = debug_information [i].base_address;
5841
9f272209
AO
5842 if (vnext && vnext < next)
5843 {
5844 vstart = vnext;
5845 display_view_pair_list (section, &vstart, i, next);
5846 if (start == vnext)
5847 start = vstart;
5848 }
5849
5850 if (!seen_first_offset || !adjacent_view_loclists)
19e6b90e
L
5851 seen_first_offset = 1;
5852 else
5853 {
5854 if (start < next)
5855 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
0af1713e 5856 (unsigned long) (start - section_begin),
c8071705 5857 (unsigned long) offset);
19e6b90e
L
5858 else if (start > next)
5859 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
0af1713e 5860 (unsigned long) (start - section_begin),
c8071705 5861 (unsigned long) offset);
19e6b90e
L
5862 }
5863 start = next;
9f272209 5864 vstart = vnext;
19e6b90e
L
5865
5866 if (offset >= bytes)
5867 {
5868 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
359ca075 5869 (unsigned long) offset);
19e6b90e
L
5870 continue;
5871 }
5872
9f272209
AO
5873 if (vnext && voffset >= bytes)
5874 {
5875 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
5876 (unsigned long) voffset);
5877 continue;
5878 }
5879
77145576
JK
5880 if (!is_loclists)
5881 {
5882 if (is_dwo)
5883 display_loc_list_dwo (section, &start, i, offset,
9f272209 5884 &vstart, has_frame_base);
77145576
JK
5885 else
5886 display_loc_list (section, &start, i, offset, base_address,
9f272209 5887 &vstart, has_frame_base);
77145576 5888 }
b4eb7656 5889 else
77145576
JK
5890 {
5891 if (is_dwo)
5892 warn (_("DWO is not yet supported.\n"));
5893 else
5894 display_loclists_list (section, &start, i, offset, base_address,
9f272209
AO
5895 &vstart, has_frame_base);
5896 }
5897
5898 /* FIXME: this arrangement is quite simplistic. Nothing
5899 requires locview lists to be adjacent to corresponding
5900 loclists, and a single loclist could be augmented by
5901 different locview lists, and vice-versa, unlikely as it
5902 is that it would make sense to do so. Hopefully we'll
5903 have view pair support built into loclists before we ever
5904 need to address all these possibilities. */
5905 if (adjacent_view_loclists && vnext
5906 && vnext != start && vstart != next)
5907 {
5908 adjacent_view_loclists = 0;
5909 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
77145576 5910 }
9f272209
AO
5911
5912 if (vnext && vnext == start)
5913 display_view_pair_list (section, &start, i, vstart);
19e6b90e
L
5914 }
5915 }
031cd65f 5916
4723351a 5917 if (start < section->start + section->size)
031cd65f 5918 warn (_("There are %ld unused bytes at the end of section %s\n"),
4723351a 5919 (long) (section->start + section->size - start), section->name);
98fb390a 5920 putchar ('\n');
51d0d03f 5921 free (array);
19e6b90e
L
5922 return 1;
5923}
5924
5925static int
5926display_debug_str (struct dwarf_section *section,
5927 void *file ATTRIBUTE_UNUSED)
5928{
5929 unsigned char *start = section->start;
5930 unsigned long bytes = section->size;
5931 dwarf_vma addr = section->address;
5932
5933 if (bytes == 0)
5934 {
5935 printf (_("\nThe %s section is empty.\n"), section->name);
5936 return 0;
5937 }
5938
5939 printf (_("Contents of the %s section:\n\n"), section->name);
5940
5941 while (bytes)
5942 {
5943 int j;
5944 int k;
5945 int lbytes;
5946
5947 lbytes = (bytes > 16 ? 16 : bytes);
5948
5949 printf (" 0x%8.8lx ", (unsigned long) addr);
5950
5951 for (j = 0; j < 16; j++)
5952 {
5953 if (j < lbytes)
5954 printf ("%2.2x", start[j]);
5955 else
5956 printf (" ");
5957
5958 if ((j & 3) == 3)
5959 printf (" ");
5960 }
5961
5962 for (j = 0; j < lbytes; j++)
5963 {
5964 k = start[j];
5965 if (k >= ' ' && k < 0x80)
5966 printf ("%c", k);
5967 else
5968 printf (".");
5969 }
5970
5971 putchar ('\n');
5972
5973 start += lbytes;
5974 addr += lbytes;
5975 bytes -= lbytes;
5976 }
5977
5978 putchar ('\n');
5979
5980 return 1;
5981}
5982
19e6b90e
L
5983static int
5984display_debug_info (struct dwarf_section *section, void *file)
5985{
4723351a 5986 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
19e6b90e
L
5987}
5988
2b6f5997
CC
5989static int
5990display_debug_types (struct dwarf_section *section, void *file)
5991{
4723351a 5992 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
6f875884
TG
5993}
5994
5995static int
5996display_trace_info (struct dwarf_section *section, void *file)
5997{
4723351a 5998 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
2b6f5997 5999}
19e6b90e
L
6000
6001static int
6002display_debug_aranges (struct dwarf_section *section,
6003 void *file ATTRIBUTE_UNUSED)
6004{
6005 unsigned char *start = section->start;
6006 unsigned char *end = start + section->size;
6007
80c35038 6008 printf (_("Contents of the %s section:\n\n"), section->name);
19e6b90e 6009
6e3d6dc1
NC
6010 /* It does not matter if this load fails,
6011 we test for that later on. */
6012 load_debug_info (file);
6013
19e6b90e
L
6014 while (start < end)
6015 {
6016 unsigned char *hdrptr;
6017 DWARF2_Internal_ARange arange;
91d6fa6a 6018 unsigned char *addr_ranges;
2d9472a2
NC
6019 dwarf_vma length;
6020 dwarf_vma address;
53b8873b 6021 unsigned char address_size;
19e6b90e 6022 int excess;
bf5117e3
NC
6023 unsigned int offset_size;
6024 unsigned int initial_length_size;
19e6b90e
L
6025
6026 hdrptr = start;
6027
0c588247 6028 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
19e6b90e
L
6029 if (arange.ar_length == 0xffffffff)
6030 {
0c588247 6031 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
19e6b90e
L
6032 offset_size = 8;
6033 initial_length_size = 12;
6034 }
6035 else
6036 {
6037 offset_size = 4;
6038 initial_length_size = 4;
6039 }
6040
0c588247
NC
6041 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
6042 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
19e6b90e 6043
6e3d6dc1
NC
6044 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
6045 && num_debug_info_entries > 0
6046 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
6047 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
47704ddf 6048 (unsigned long) arange.ar_info_offset, section->name);
6e3d6dc1 6049
0c588247
NC
6050 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
6051 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
19e6b90e
L
6052
6053 if (arange.ar_version != 2 && arange.ar_version != 3)
6054 {
67f101ee
NC
6055 /* PR 19872: A version number of 0 probably means that there is
6056 padding at the end of the .debug_aranges section. Gold puts
6057 it there when performing an incremental link, for example.
6058 So do not generate a warning in this case. */
6059 if (arange.ar_version)
6060 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
19e6b90e
L
6061 break;
6062 }
6063
47704ddf
KT
6064 printf (_(" Length: %ld\n"),
6065 (long) arange.ar_length);
19e6b90e 6066 printf (_(" Version: %d\n"), arange.ar_version);
47704ddf
KT
6067 printf (_(" Offset into .debug_info: 0x%lx\n"),
6068 (unsigned long) arange.ar_info_offset);
19e6b90e
L
6069 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
6070 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
6071
53b8873b
NC
6072 address_size = arange.ar_pointer_size + arange.ar_segment_size;
6073
f41e4712
NC
6074 /* PR 17512: file: 001-108546-0.001:0.1. */
6075 if (address_size == 0 || address_size > 8)
b3681d67
L
6076 {
6077 error (_("Invalid address size in %s section!\n"),
6078 section->name);
6079 break;
6080 }
6081
53b8873b
NC
6082 /* The DWARF spec does not require that the address size be a power
6083 of two, but we do. This will have to change if we ever encounter
6084 an uneven architecture. */
6085 if ((address_size & (address_size - 1)) != 0)
6086 {
6087 warn (_("Pointer size + Segment size is not a power of two.\n"));
6088 break;
6089 }
cecf136e 6090
209c9a13
NC
6091 if (address_size > 4)
6092 printf (_("\n Address Length\n"));
6093 else
6094 printf (_("\n Address Length\n"));
19e6b90e 6095
91d6fa6a 6096 addr_ranges = hdrptr;
19e6b90e 6097
53b8873b
NC
6098 /* Must pad to an alignment boundary that is twice the address size. */
6099 excess = (hdrptr - start) % (2 * address_size);
19e6b90e 6100 if (excess)
91d6fa6a 6101 addr_ranges += (2 * address_size) - excess;
19e6b90e 6102
ffc0f143
NC
6103 hdrptr = start + arange.ar_length + initial_length_size;
6104 if (hdrptr < start || hdrptr > end)
6105 {
6106 error (_("Excessive header length: %lx\n"), (long) arange.ar_length);
6107 break;
6108 }
6109 start = hdrptr;
1617e571 6110
91d6fa6a 6111 while (addr_ranges + 2 * address_size <= start)
19e6b90e 6112 {
0c588247
NC
6113 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
6114 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
19e6b90e 6115
80c35038 6116 printf (" ");
2d9472a2
NC
6117 print_dwarf_vma (address, address_size);
6118 print_dwarf_vma (length, address_size);
6119 putchar ('\n');
19e6b90e 6120 }
19e6b90e
L
6121 }
6122
6123 printf ("\n");
6124
6125 return 1;
6126}
6127
4723351a
CC
6128/* Comparison function for qsort. */
6129static int
6130comp_addr_base (const void * v0, const void * v1)
6131{
6132 debug_info * info0 = (debug_info *) v0;
6133 debug_info * info1 = (debug_info *) v1;
6134 return info0->addr_base - info1->addr_base;
6135}
6136
6137/* Display the debug_addr section. */
6138static int
6139display_debug_addr (struct dwarf_section *section,
b4eb7656 6140 void *file)
4723351a
CC
6141{
6142 debug_info **debug_addr_info;
6143 unsigned char *entry;
6144 unsigned char *end;
6145 unsigned int i;
6146 unsigned int count;
6147
6148 if (section->size == 0)
6149 {
6150 printf (_("\nThe %s section is empty.\n"), section->name);
6151 return 0;
6152 }
6153
6154 if (load_debug_info (file) == 0)
6155 {
6156 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6157 section->name);
6158 return 0;
6159 }
6160
6161 printf (_("Contents of the %s section:\n\n"), section->name);
6162
1306a742
NC
6163 /* PR 17531: file: cf38d01b.
6164 We use xcalloc because a corrupt file may not have initialised all of the
6165 fields in the debug_info structure, which means that the sort below might
6166 try to move uninitialised data. */
6167 debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
b4eb7656 6168 sizeof (debug_info *));
4723351a
CC
6169
6170 count = 0;
6171 for (i = 0; i < num_debug_info_entries; i++)
82b1b41b 6172 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
1306a742
NC
6173 {
6174 /* PR 17531: file: cf38d01b. */
6175 if (debug_information[i].addr_base >= section->size)
6176 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
6177 (unsigned long) debug_information[i].addr_base, i);
6178 else
6179 debug_addr_info [count++] = debug_information + i;
6180 }
4723351a
CC
6181
6182 /* Add a sentinel to make iteration convenient. */
6183 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
6184 debug_addr_info [count]->addr_base = section->size;
4723351a 6185 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
1306a742 6186
4723351a
CC
6187 for (i = 0; i < count; i++)
6188 {
6189 unsigned int idx;
fab128ef 6190 unsigned int address_size = debug_addr_info [i]->pointer_size;
4723351a
CC
6191
6192 printf (_(" For compilation unit at offset 0x%s:\n"),
b4eb7656 6193 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
4723351a 6194
fab128ef 6195 printf (_("\tIndex\tAddress\n"));
4723351a
CC
6196 entry = section->start + debug_addr_info [i]->addr_base;
6197 end = section->start + debug_addr_info [i + 1]->addr_base;
6198 idx = 0;
6199 while (entry < end)
b4eb7656
AM
6200 {
6201 dwarf_vma base = byte_get (entry, address_size);
6202 printf (_("\t%d:\t"), idx);
6203 print_dwarf_vma (base, address_size);
6204 printf ("\n");
6205 entry += address_size;
6206 idx++;
6207 }
4723351a
CC
6208 }
6209 printf ("\n");
6210
6211 free (debug_addr_info);
6212 return 1;
6213}
6214
6215/* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
6216static int
6217display_debug_str_offsets (struct dwarf_section *section,
b4eb7656 6218 void *file ATTRIBUTE_UNUSED)
4723351a
CC
6219{
6220 if (section->size == 0)
6221 {
6222 printf (_("\nThe %s section is empty.\n"), section->name);
6223 return 0;
6224 }
6225 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
6226 what the offset size is for this section. */
6227 return 1;
6228}
6229
01a8f077
JK
6230/* Each debug_information[x].range_lists[y] gets this representation for
6231 sorting purposes. */
6232
6233struct range_entry
467c65bc
NC
6234{
6235 /* The debug_information[x].range_lists[y] value. */
359ca075 6236 dwarf_vma ranges_offset;
01a8f077 6237
467c65bc
NC
6238 /* Original debug_information to find parameters of the data. */
6239 debug_info *debug_info_p;
6240};
01a8f077
JK
6241
6242/* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
6243
6244static int
6245range_entry_compar (const void *ap, const void *bp)
6246{
3f5e193b
NC
6247 const struct range_entry *a_re = (const struct range_entry *) ap;
6248 const struct range_entry *b_re = (const struct range_entry *) bp;
359ca075
JK
6249 const dwarf_vma a = a_re->ranges_offset;
6250 const dwarf_vma b = b_re->ranges_offset;
01a8f077
JK
6251
6252 return (a > b) - (b > a);
6253}
6254
77145576
JK
6255static void
6256display_debug_ranges_list (unsigned char *start, unsigned char *finish,
6257 unsigned int pointer_size, unsigned long offset,
6258 unsigned long base_address)
6259{
6260 while (start < finish)
6261 {
6262 dwarf_vma begin;
6263 dwarf_vma end;
6264
6265 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6266 if (start >= finish)
6267 break;
6268 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
6269
6270 printf (" %8.8lx ", offset);
6271
6272 if (begin == 0 && end == 0)
6273 {
6274 printf (_("<End of list>\n"));
6275 break;
6276 }
6277
6278 /* Check base address specifiers. */
6279 if (is_max_address (begin, pointer_size)
6280 && !is_max_address (end, pointer_size))
6281 {
6282 base_address = end;
6283 print_dwarf_vma (begin, pointer_size);
6284 print_dwarf_vma (end, pointer_size);
6285 printf ("(base address)\n");
6286 continue;
6287 }
6288
6289 print_dwarf_vma (begin + base_address, pointer_size);
6290 print_dwarf_vma (end + base_address, pointer_size);
6291
6292 if (begin == end)
6293 fputs (_("(start == end)"), stdout);
6294 else if (begin > end)
6295 fputs (_("(start > end)"), stdout);
6296
6297 putchar ('\n');
6298 }
6299}
6300
6301static void
6302display_debug_rnglists_list (unsigned char *start, unsigned char *finish,
6303 unsigned int pointer_size, unsigned long offset,
6304 unsigned long base_address)
6305{
6306 unsigned char *next = start;
6307
6308 while (1)
6309 {
6310 unsigned long off = offset + (start - next);
6311 enum dwarf_range_list_entry rlet;
9dfd0db9
JK
6312 /* Initialize it due to a false compiler warning. */
6313 dwarf_vma begin = -1, length, end = -1;
77145576
JK
6314 unsigned int bytes_read;
6315
6316 if (start + 1 > finish)
6317 {
6318 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
6319 offset);
6320 break;
6321 }
6322
6323 printf (" %8.8lx ", off);
6324
6325 SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish);
6326
6327 switch (rlet)
6328 {
6329 case DW_RLE_end_of_list:
6330 printf (_("<End of list>\n"));
6331 break;
6332 case DW_RLE_base_address:
6333 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish);
6334 print_dwarf_vma (base_address, pointer_size);
6335 printf (_("(base address)\n"));
6336 break;
6337 case DW_RLE_start_length:
6338 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6339 length = read_uleb128 (start, &bytes_read, finish);
6340 start += bytes_read;
6341 end = begin + length;
6342 break;
6343 case DW_RLE_offset_pair:
6344 begin = read_uleb128 (start, &bytes_read, finish);
6345 start += bytes_read;
6346 end = read_uleb128 (start, &bytes_read, finish);
6347 start += bytes_read;
6348 break;
6349 case DW_RLE_start_end:
6350 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6351 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish);
6352 break;
6353 default:
6354 error (_("Invalid range list entry type %d\n"), rlet);
6355 rlet = DW_RLE_end_of_list;
6356 break;
6357 }
6358 if (rlet == DW_RLE_end_of_list)
6359 break;
6360 if (rlet == DW_RLE_base_address)
6361 continue;
6362
6363 print_dwarf_vma (begin + base_address, pointer_size);
6364 print_dwarf_vma (end + base_address, pointer_size);
6365
6366 if (begin == end)
6367 fputs (_("(start == end)"), stdout);
6368 else if (begin > end)
6369 fputs (_("(start > end)"), stdout);
6370
6371 putchar ('\n');
6372 }
6373}
6374
19e6b90e
L
6375static int
6376display_debug_ranges (struct dwarf_section *section,
6377 void *file ATTRIBUTE_UNUSED)
6378{
6379 unsigned char *start = section->start;
a2ff7a4b 6380 unsigned char *last_start = start;
f6f0e17b 6381 unsigned long bytes = section->size;
19e6b90e 6382 unsigned char *section_begin = start;
f6f0e17b 6383 unsigned char *finish = start + bytes;
01a8f077
JK
6384 unsigned int num_range_list, i;
6385 struct range_entry *range_entries, *range_entry_fill;
77145576
JK
6386 int is_rnglists = strstr (section->name, "debug_rnglists") != NULL;
6387 /* Initialize it due to a false compiler warning. */
6388 unsigned char address_size = 0;
19e6b90e 6389
19e6b90e
L
6390 if (bytes == 0)
6391 {
6392 printf (_("\nThe %s section is empty.\n"), section->name);
6393 return 0;
6394 }
6395
77145576
JK
6396 if (is_rnglists)
6397 {
6398 dwarf_vma initial_length;
6399 unsigned int initial_length_size;
6400 unsigned char segment_selector_size;
6401 unsigned int offset_size, offset_entry_count;
6402 unsigned short version;
6403
6404 /* Get and check the length of the block. */
6405 SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish);
6406
6407 if (initial_length == 0xffffffff)
6408 {
6409 /* This section is 64-bit DWARF 3. */
6410 SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish);
6411 offset_size = 8;
6412 initial_length_size = 12;
6413 }
6414 else
6415 {
6416 offset_size = 4;
6417 initial_length_size = 4;
6418 }
6419
6420 if (initial_length + initial_length_size > section->size)
6421 {
6422 /* If the length field has a relocation against it, then we should
6423 not complain if it is inaccurate (and probably negative).
6424 It is copied from .debug_line handling code. */
6425 if (reloc_at (section, (start - section->start) - offset_size))
6426 {
6427 initial_length = (finish - start) - initial_length_size;
6428 }
6429 else
6430 {
6431 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
6432 (long) initial_length);
6433 return 0;
6434 }
6435 }
6436
6437 /* Get and check the version number. */
6438 SAFE_BYTE_GET_AND_INC (version, start, 2, finish);
6439
6440 if (version != 5)
6441 {
6442 warn (_("Only DWARF version 5 debug_rnglists info "
6443 "is currently supported.\n"));
6444 return 0;
6445 }
6446
6447 SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish);
6448
6449 SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish);
6450 if (segment_selector_size != 0)
6451 {
6452 warn (_("The %s section contains "
6453 "unsupported segment selector size: %d.\n"),
6454 section->name, segment_selector_size);
6455 return 0;
6456 }
6457
6458 SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish);
6459 if (offset_entry_count != 0)
6460 {
6461 warn (_("The %s section contains "
6462 "unsupported offset entry count: %u.\n"),
6463 section->name, offset_entry_count);
6464 return 0;
6465 }
6466 }
6467
1febe64d
NC
6468 if (load_debug_info (file) == 0)
6469 {
6470 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6471 section->name);
6472 return 0;
6473 }
19e6b90e 6474
01a8f077 6475 num_range_list = 0;
19e6b90e 6476 for (i = 0; i < num_debug_info_entries; i++)
01a8f077 6477 num_range_list += debug_information [i].num_range_lists;
19e6b90e 6478
01a8f077 6479 if (num_range_list == 0)
4723351a
CC
6480 {
6481 /* This can happen when the file was compiled with -gsplit-debug
b4eb7656 6482 which removes references to range lists from the primary .o file. */
4723351a
CC
6483 printf (_("No range lists in .debug_info section.\n"));
6484 return 1;
6485 }
19e6b90e 6486
3f5e193b
NC
6487 range_entries = (struct range_entry *)
6488 xmalloc (sizeof (*range_entries) * num_range_list);
01a8f077 6489 range_entry_fill = range_entries;
19e6b90e 6490
01a8f077
JK
6491 for (i = 0; i < num_debug_info_entries; i++)
6492 {
6493 debug_info *debug_info_p = &debug_information[i];
6494 unsigned int j;
6495
6496 for (j = 0; j < debug_info_p->num_range_lists; j++)
6497 {
6498 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
6499 range_entry_fill->debug_info_p = debug_info_p;
6500 range_entry_fill++;
19e6b90e
L
6501 }
6502 }
6503
01a8f077
JK
6504 qsort (range_entries, num_range_list, sizeof (*range_entries),
6505 range_entry_compar);
19e6b90e 6506
d493b283 6507 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
19e6b90e 6508 warn (_("Range lists in %s section start at 0x%lx\n"),
359ca075 6509 section->name, (unsigned long) range_entries[0].ranges_offset);
19e6b90e
L
6510
6511 printf (_("Contents of the %s section:\n\n"), section->name);
6512 printf (_(" Offset Begin End\n"));
6513
01a8f077 6514 for (i = 0; i < num_range_list; i++)
19e6b90e 6515 {
01a8f077
JK
6516 struct range_entry *range_entry = &range_entries[i];
6517 debug_info *debug_info_p = range_entry->debug_info_p;
19e6b90e 6518 unsigned int pointer_size;
359ca075 6519 dwarf_vma offset;
01a8f077 6520 unsigned char *next;
359ca075 6521 dwarf_vma base_address;
19e6b90e 6522
77145576 6523 pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size);
d493b283 6524 offset = range_entry->ranges_offset;
01a8f077
JK
6525 next = section_begin + offset;
6526 base_address = debug_info_p->base_address;
cecf136e 6527
f41e4712
NC
6528 /* PR 17512: file: 001-101485-0.001:0.1. */
6529 if (pointer_size < 2 || pointer_size > 8)
6530 {
6531 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
359ca075 6532 pointer_size, (unsigned long) offset);
f41e4712
NC
6533 continue;
6534 }
b4eb7656 6535
4723351a 6536 if (dwarf_check != 0 && i > 0)
19e6b90e 6537 {
01a8f077
JK
6538 if (start < next)
6539 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
6540 (unsigned long) (start - section_begin),
6541 (unsigned long) (next - section_begin), section->name);
6542 else if (start > next)
a2ff7a4b
AM
6543 {
6544 if (next == last_start)
6545 continue;
6546 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
6547 (unsigned long) (start - section_begin),
6548 (unsigned long) (next - section_begin), section->name);
6549 }
01a8f077
JK
6550 }
6551 start = next;
a2ff7a4b 6552 last_start = next;
19e6b90e 6553
77145576
JK
6554 (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list)
6555 (start, finish, pointer_size, offset, base_address);
19e6b90e
L
6556 }
6557 putchar ('\n');
01a8f077
JK
6558
6559 free (range_entries);
6560
19e6b90e
L
6561 return 1;
6562}
6563
6564typedef struct Frame_Chunk
6565{
6566 struct Frame_Chunk *next;
6567 unsigned char *chunk_start;
a1165289 6568 unsigned int ncols;
19e6b90e
L
6569 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6570 short int *col_type;
6571 int *col_offset;
6572 char *augmentation;
6573 unsigned int code_factor;
6574 int data_factor;
bf5117e3
NC
6575 dwarf_vma pc_begin;
6576 dwarf_vma pc_range;
19e6b90e 6577 int cfa_reg;
c8071705 6578 dwarf_vma cfa_offset;
a1165289 6579 unsigned int ra;
19e6b90e
L
6580 unsigned char fde_encoding;
6581 unsigned char cfa_exp;
604282a7
JJ
6582 unsigned char ptr_size;
6583 unsigned char segment_size;
19e6b90e
L
6584}
6585Frame_Chunk;
6586
665ce1f6
L
6587static const char *const *dwarf_regnames;
6588static unsigned int dwarf_regnames_count;
6589
19e6b90e
L
6590/* A marker for a col_type that means this column was never referenced
6591 in the frame info. */
6592#define DW_CFA_unreferenced (-1)
6593
a1165289 6594/* Return 0 if no more space is needed, 1 if more space is needed,
665ce1f6
L
6595 -1 for invalid reg. */
6596
6597static int
6598frame_need_space (Frame_Chunk *fc, unsigned int reg)
19e6b90e 6599{
a1165289 6600 unsigned int prev = fc->ncols;
19e6b90e 6601
665ce1f6
L
6602 if (reg < (unsigned int) fc->ncols)
6603 return 0;
6604
6605 if (dwarf_regnames_count
6606 && reg > dwarf_regnames_count)
6607 return -1;
19e6b90e
L
6608
6609 fc->ncols = reg + 1;
a1165289
NC
6610 /* PR 17512: file: 10450-2643-0.004.
6611 If reg == -1 then this can happen... */
6612 if (fc->ncols == 0)
6613 return -1;
6614
06614111
NC
6615 /* PR 17512: file: 2844a11d. */
6616 if (fc->ncols > 1024)
6617 {
6618 error (_("Unfeasibly large register number: %u\n"), reg);
6619 fc->ncols = 0;
6620 /* FIXME: 1024 is an arbitrary limit. Increase it if
6621 we ever encounter a valid binary that exceeds it. */
6622 return -1;
6623 }
6624
3f5e193b 6625 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
b4eb7656 6626 sizeof (short int));
3f5e193b 6627 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
b4eb7656 6628 /* PR 17512: file:002-10025-0.005. */
041830e0
NC
6629 if (fc->col_type == NULL || fc->col_offset == NULL)
6630 {
6631 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
6632 fc->ncols);
6633 fc->ncols = 0;
6634 return -1;
6635 }
19e6b90e
L
6636
6637 while (prev < fc->ncols)
6638 {
6639 fc->col_type[prev] = DW_CFA_unreferenced;
6640 fc->col_offset[prev] = 0;
6641 prev++;
6642 }
665ce1f6 6643 return 1;
19e6b90e
L
6644}
6645
2dc4cec1
L
6646static const char *const dwarf_regnames_i386[] =
6647{
43234a1e
L
6648 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6649 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6650 "eip", "eflags", NULL, /* 8 - 10 */
6651 "st0", "st1", "st2", "st3", /* 11 - 14 */
6652 "st4", "st5", "st6", "st7", /* 15 - 18 */
6653 NULL, NULL, /* 19 - 20 */
6654 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
6655 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
6656 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
6657 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
6658 "fcw", "fsw", "mxcsr", /* 37 - 39 */
6659 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6660 "tr", "ldtr", /* 48 - 49 */
6661 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6662 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6663 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6664 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6665 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6666 NULL, NULL, NULL, /* 90 - 92 */
6667 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
2dc4cec1
L
6668};
6669
3d875af5
L
6670static const char *const dwarf_regnames_iamcu[] =
6671{
6672 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6673 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6674 "eip", "eflags", NULL, /* 8 - 10 */
6675 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */
6676 NULL, NULL, /* 19 - 20 */
6677 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */
6678 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */
6679 NULL, NULL, NULL, /* 37 - 39 */
6680 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6681 "tr", "ldtr", /* 48 - 49 */
6682 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6683 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6684 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6685 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6686 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6687 NULL, NULL, NULL, /* 90 - 92 */
6688 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */
6689};
6690
b129eb0e
RH
6691void
6692init_dwarf_regnames_i386 (void)
6693{
6694 dwarf_regnames = dwarf_regnames_i386;
6695 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
6696}
6697
3d875af5
L
6698void
6699init_dwarf_regnames_iamcu (void)
6700{
6701 dwarf_regnames = dwarf_regnames_iamcu;
6702 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu);
6703}
6704
2dc4cec1
L
6705static const char *const dwarf_regnames_x86_64[] =
6706{
6707 "rax", "rdx", "rcx", "rbx",
6708 "rsi", "rdi", "rbp", "rsp",
6709 "r8", "r9", "r10", "r11",
6710 "r12", "r13", "r14", "r15",
6711 "rip",
6712 "xmm0", "xmm1", "xmm2", "xmm3",
6713 "xmm4", "xmm5", "xmm6", "xmm7",
6714 "xmm8", "xmm9", "xmm10", "xmm11",
6715 "xmm12", "xmm13", "xmm14", "xmm15",
6716 "st0", "st1", "st2", "st3",
6717 "st4", "st5", "st6", "st7",
6718 "mm0", "mm1", "mm2", "mm3",
6719 "mm4", "mm5", "mm6", "mm7",
6720 "rflags",
6721 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
6722 "fs.base", "gs.base", NULL, NULL,
6723 "tr", "ldtr",
43234a1e
L
6724 "mxcsr", "fcw", "fsw",
6725 "xmm16", "xmm17", "xmm18", "xmm19",
6726 "xmm20", "xmm21", "xmm22", "xmm23",
6727 "xmm24", "xmm25", "xmm26", "xmm27",
6728 "xmm28", "xmm29", "xmm30", "xmm31",
6729 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
6730 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
6731 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
6732 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
6733 NULL, NULL, NULL, /* 115 - 117 */
6734 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
2dc4cec1
L
6735};
6736
b129eb0e
RH
6737void
6738init_dwarf_regnames_x86_64 (void)
6739{
6740 dwarf_regnames = dwarf_regnames_x86_64;
6741 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
6742}
6743
4ee22035
RH
6744static const char *const dwarf_regnames_aarch64[] =
6745{
b4eb7656
AM
6746 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
6747 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
4ee22035
RH
6748 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
6749 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
6750 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
6751 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6752 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6753 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
b4eb7656
AM
6754 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
6755 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
4ee22035
RH
6756 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
6757 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
6758};
6759
6760void
6761init_dwarf_regnames_aarch64 (void)
6762{
6763 dwarf_regnames = dwarf_regnames_aarch64;
6764 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
6765}
6766
d6bb17b0
AA
6767static const char *const dwarf_regnames_s390[] =
6768{
6769 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
6770 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6771 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6772 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
6773 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
6774 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
6775 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
6776 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
6777 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
6778 "pswm", "pswa",
6779 NULL, NULL,
6780 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
6781 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
6782};
6783
6784void
6785init_dwarf_regnames_s390 (void)
6786{
6787 dwarf_regnames = dwarf_regnames_s390;
6788 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390);
6789}
6790
2dc4cec1
L
6791void
6792init_dwarf_regnames (unsigned int e_machine)
6793{
6794 switch (e_machine)
6795 {
6796 case EM_386:
b129eb0e 6797 init_dwarf_regnames_i386 ();
2dc4cec1
L
6798 break;
6799
3d875af5
L
6800 case EM_IAMCU:
6801 init_dwarf_regnames_iamcu ();
6802 break;
6803
2dc4cec1 6804 case EM_X86_64:
7f502d6c 6805 case EM_L1OM:
7a9068fe 6806 case EM_K1OM:
b129eb0e 6807 init_dwarf_regnames_x86_64 ();
2dc4cec1
L
6808 break;
6809
4ee22035
RH
6810 case EM_AARCH64:
6811 init_dwarf_regnames_aarch64 ();
6812 break;
6813
d6bb17b0
AA
6814 case EM_S390:
6815 init_dwarf_regnames_s390 ();
6816 break;
6817
2dc4cec1
L
6818 default:
6819 break;
6820 }
6821}
6822
6823static const char *
6824regname (unsigned int regno, int row)
6825{
6826 static char reg[64];
7f2c8a1d 6827
2dc4cec1
L
6828 if (dwarf_regnames
6829 && regno < dwarf_regnames_count
6830 && dwarf_regnames [regno] != NULL)
6831 {
6832 if (row)
6833 return dwarf_regnames [regno];
6834 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
6835 dwarf_regnames [regno]);
6836 }
6837 else
6838 snprintf (reg, sizeof (reg), "r%d", regno);
6839 return reg;
6840}
6841
19e6b90e 6842static void
a1165289 6843frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
19e6b90e 6844{
a1165289 6845 unsigned int r;
19e6b90e
L
6846 char tmp[100];
6847
d8024a91 6848 if (*max_regs != fc->ncols)
19e6b90e
L
6849 *max_regs = fc->ncols;
6850
6851 if (*need_col_headers)
6852 {
91d6fa6a 6853 static const char *sloc = " LOC";
2dc4cec1 6854
19e6b90e
L
6855 *need_col_headers = 0;
6856
91d6fa6a 6857 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
19e6b90e
L
6858
6859 for (r = 0; r < *max_regs; r++)
6860 if (fc->col_type[r] != DW_CFA_unreferenced)
6861 {
6862 if (r == fc->ra)
50751e18 6863 printf ("ra ");
19e6b90e 6864 else
2dc4cec1 6865 printf ("%-5s ", regname (r, 1));
19e6b90e
L
6866 }
6867
6868 printf ("\n");
6869 }
6870
bf5117e3 6871 print_dwarf_vma (fc->pc_begin, eh_addr_size);
19e6b90e
L
6872 if (fc->cfa_exp)
6873 strcpy (tmp, "exp");
6874 else
c8071705 6875 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset);
19e6b90e
L
6876 printf ("%-8s ", tmp);
6877
6878 for (r = 0; r < fc->ncols; r++)
6879 {
6880 if (fc->col_type[r] != DW_CFA_unreferenced)
6881 {
6882 switch (fc->col_type[r])
6883 {
6884 case DW_CFA_undefined:
6885 strcpy (tmp, "u");
6886 break;
6887 case DW_CFA_same_value:
6888 strcpy (tmp, "s");
6889 break;
6890 case DW_CFA_offset:
6891 sprintf (tmp, "c%+d", fc->col_offset[r]);
6892 break;
12eae2d3
JJ
6893 case DW_CFA_val_offset:
6894 sprintf (tmp, "v%+d", fc->col_offset[r]);
6895 break;
19e6b90e 6896 case DW_CFA_register:
2dc4cec1 6897 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
19e6b90e
L
6898 break;
6899 case DW_CFA_expression:
6900 strcpy (tmp, "exp");
6901 break;
12eae2d3
JJ
6902 case DW_CFA_val_expression:
6903 strcpy (tmp, "vexp");
6904 break;
19e6b90e
L
6905 default:
6906 strcpy (tmp, "n/a");
6907 break;
6908 }
2dc4cec1 6909 printf ("%-5s ", tmp);
19e6b90e
L
6910 }
6911 }
6912 printf ("\n");
6913}
6914
49727e46 6915#define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
19e6b90e 6916
49727e46
AM
6917static unsigned char *
6918read_cie (unsigned char *start, unsigned char *end,
6919 Frame_Chunk **p_cie, int *p_version,
6920 unsigned long *p_aug_len, unsigned char **p_aug)
6921{
6922 int version;
6923 Frame_Chunk *fc;
6924 unsigned int length_return;
6925 unsigned char *augmentation_data = NULL;
6926 unsigned long augmentation_data_len = 0;
6927
041830e0 6928 * p_cie = NULL;
f41e4712
NC
6929 /* PR 17512: file: 001-228113-0.004. */
6930 if (start >= end)
6931 return end;
6932
49727e46
AM
6933 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
6934 memset (fc, 0, sizeof (Frame_Chunk));
6935
6936 fc->col_type = (short int *) xmalloc (sizeof (short int));
6937 fc->col_offset = (int *) xmalloc (sizeof (int));
6938
6939 version = *start++;
6940
6941 fc->augmentation = (char *) start;
f41e4712
NC
6942 /* PR 17512: file: 001-228113-0.004.
6943 Skip past augmentation name, but avoid running off the end of the data. */
6944 while (start < end)
6945 if (* start ++ == '\0')
6946 break;
6947 if (start == end)
6948 {
6949 warn (_("No terminator for augmentation name\n"));
6950 return start;
6951 }
49727e46
AM
6952
6953 if (strcmp (fc->augmentation, "eh") == 0)
6954 start += eh_addr_size;
6955
6956 if (version >= 4)
6957 {
6958 GET (fc->ptr_size, 1);
77ef8654
NC
6959 if (fc->ptr_size < 1 || fc->ptr_size > 8)
6960 {
6961 warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size);
6962 return end;
6963 }
6964
49727e46 6965 GET (fc->segment_size, 1);
77ef8654
NC
6966 /* PR 17512: file: e99d2804. */
6967 if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8)
6968 {
6969 warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size);
6970 return end;
6971 }
6972
49727e46
AM
6973 eh_addr_size = fc->ptr_size;
6974 }
6975 else
6976 {
6977 fc->ptr_size = eh_addr_size;
6978 fc->segment_size = 0;
6979 }
7f2c8a1d
NC
6980 READ_ULEB (fc->code_factor);
6981 READ_SLEB (fc->data_factor);
49727e46
AM
6982 if (version == 1)
6983 {
6984 GET (fc->ra, 1);
6985 }
6986 else
6987 {
7f2c8a1d 6988 READ_ULEB (fc->ra);
49727e46
AM
6989 }
6990
6991 if (fc->augmentation[0] == 'z')
6992 {
7f2c8a1d 6993 READ_ULEB (augmentation_data_len);
49727e46
AM
6994 augmentation_data = start;
6995 start += augmentation_data_len;
a1165289
NC
6996 /* PR 17512: file: 11042-2589-0.004. */
6997 if (start > end)
6998 {
7f2c8a1d
NC
6999 warn (_("Augmentation data too long: %#lx, expected at most %#lx\n"),
7000 augmentation_data_len, (long)((end - start) + augmentation_data_len));
a1165289
NC
7001 return end;
7002 }
49727e46
AM
7003 }
7004
7005 if (augmentation_data_len)
7006 {
058037d3
NC
7007 unsigned char *p;
7008 unsigned char *q;
7009 unsigned char *qend;
b4eb7656 7010
49727e46
AM
7011 p = (unsigned char *) fc->augmentation + 1;
7012 q = augmentation_data;
058037d3
NC
7013 qend = q + augmentation_data_len;
7014
7015 /* PR 17531: file: 015adfaa. */
7016 if (qend < q)
7017 {
7018 warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len);
7019 augmentation_data_len = 0;
7020 }
49727e46 7021
a1165289 7022 while (p < end && q < augmentation_data + augmentation_data_len)
49727e46
AM
7023 {
7024 if (*p == 'L')
7025 q++;
7026 else if (*p == 'P')
7027 q += 1 + size_of_encoded_value (*q);
7028 else if (*p == 'R')
7029 fc->fde_encoding = *q++;
7030 else if (*p == 'S')
7031 ;
7032 else
7033 break;
7034 p++;
7035 }
c361b9ac
NC
7036 /* Note - it is OK if this loop terminates with q < qend.
7037 Padding may have been inserted to align the end of the CIE. */
49727e46
AM
7038 }
7039
7040 *p_cie = fc;
7041 if (p_version)
7042 *p_version = version;
7043 if (p_aug_len)
7044 {
7045 *p_aug_len = augmentation_data_len;
7046 *p_aug = augmentation_data;
7047 }
7048 return start;
7049}
7050
19e6b90e
L
7051static int
7052display_debug_frames (struct dwarf_section *section,
7053 void *file ATTRIBUTE_UNUSED)
7054{
7055 unsigned char *start = section->start;
7056 unsigned char *end = start + section->size;
7057 unsigned char *section_start = start;
49727e46 7058 Frame_Chunk *chunks = 0, *forward_refs = 0;
19e6b90e
L
7059 Frame_Chunk *remembered_state = 0;
7060 Frame_Chunk *rs;
7061 int is_eh = strcmp (section->name, ".eh_frame") == 0;
7062 unsigned int length_return;
a1165289 7063 unsigned int max_regs = 0;
665ce1f6 7064 const char *bad_reg = _("bad register: ");
77ef8654 7065 unsigned int saved_eh_addr_size = eh_addr_size;
19e6b90e 7066
80c35038 7067 printf (_("Contents of the %s section:\n"), section->name);
19e6b90e
L
7068
7069 while (start < end)
7070 {
7071 unsigned char *saved_start;
7072 unsigned char *block_end;
bf5117e3
NC
7073 dwarf_vma length;
7074 dwarf_vma cie_id;
19e6b90e
L
7075 Frame_Chunk *fc;
7076 Frame_Chunk *cie;
7077 int need_col_headers = 1;
7078 unsigned char *augmentation_data = NULL;
7079 unsigned long augmentation_data_len = 0;
bf5117e3
NC
7080 unsigned int encoded_ptr_size = saved_eh_addr_size;
7081 unsigned int offset_size;
7082 unsigned int initial_length_size;
5b6312fd 7083 bfd_boolean all_nops;
19e6b90e
L
7084
7085 saved_start = start;
19e6b90e 7086
0c588247 7087 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
041830e0 7088
19e6b90e
L
7089 if (length == 0)
7090 {
7091 printf ("\n%08lx ZERO terminator\n\n",
7092 (unsigned long)(saved_start - section_start));
6937bb54
NC
7093 /* Skip any zero terminators that directly follow.
7094 A corrupt section size could have loaded a whole
7095 slew of zero filled memory bytes. eg
7096 PR 17512: file: 070-19381-0.004. */
7097 while (start < end && * start == 0)
7098 ++ start;
b758e50f 7099 continue;
19e6b90e
L
7100 }
7101
7102 if (length == 0xffffffff)
7103 {
0c588247 7104 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
19e6b90e
L
7105 offset_size = 8;
7106 initial_length_size = 12;
7107 }
7108 else
7109 {
7110 offset_size = 4;
7111 initial_length_size = 4;
7112 }
7113
7114 block_end = saved_start + length + initial_length_size;
041830e0 7115 if (block_end > end || block_end < start)
53b8873b 7116 {
bf5117e3
NC
7117 warn ("Invalid length 0x%s in FDE at %#08lx\n",
7118 dwarf_vmatoa_1 (NULL, length, offset_size),
7119 (unsigned long) (saved_start - section_start));
53b8873b
NC
7120 block_end = end;
7121 }
0c588247
NC
7122
7123 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
19e6b90e 7124
846a11e4
NC
7125 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
7126 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
19e6b90e
L
7127 {
7128 int version;
a1165289 7129 unsigned int mreg;
19e6b90e 7130
49727e46
AM
7131 start = read_cie (start, end, &cie, &version,
7132 &augmentation_data_len, &augmentation_data);
041830e0
NC
7133 /* PR 17512: file: 027-135133-0.005. */
7134 if (cie == NULL)
7135 break;
a1165289 7136
49727e46 7137 fc = cie;
19e6b90e
L
7138 fc->next = chunks;
7139 chunks = fc;
7140 fc->chunk_start = saved_start;
a1165289 7141 mreg = max_regs > 0 ? max_regs - 1 : 0;
49727e46
AM
7142 if (mreg < fc->ra)
7143 mreg = fc->ra;
06614111
NC
7144 if (frame_need_space (fc, mreg) < 0)
7145 break;
49727e46
AM
7146 if (fc->fde_encoding)
7147 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
19e6b90e 7148
bf5117e3
NC
7149 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
7150 print_dwarf_vma (length, fc->ptr_size);
9c41109d 7151 print_dwarf_vma (cie_id, offset_size);
bf5117e3 7152
19e6b90e 7153 if (do_debug_frames_interp)
bf5117e3
NC
7154 {
7155 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
7156 fc->code_factor, fc->data_factor, fc->ra);
7157 }
19e6b90e
L
7158 else
7159 {
bf5117e3 7160 printf ("CIE\n");
19e6b90e
L
7161 printf (" Version: %d\n", version);
7162 printf (" Augmentation: \"%s\"\n", fc->augmentation);
604282a7
JJ
7163 if (version >= 4)
7164 {
7165 printf (" Pointer Size: %u\n", fc->ptr_size);
7166 printf (" Segment Size: %u\n", fc->segment_size);
7167 }
19e6b90e
L
7168 printf (" Code alignment factor: %u\n", fc->code_factor);
7169 printf (" Data alignment factor: %d\n", fc->data_factor);
7170 printf (" Return address column: %d\n", fc->ra);
7171
7172 if (augmentation_data_len)
7173 {
7174 unsigned long i;
a1165289 7175
19e6b90e
L
7176 printf (" Augmentation data: ");
7177 for (i = 0; i < augmentation_data_len; ++i)
a1165289
NC
7178 /* FIXME: If do_wide is FALSE, then we should
7179 add carriage returns at 80 columns... */
19e6b90e
L
7180 printf (" %02x", augmentation_data[i]);
7181 putchar ('\n');
7182 }
7183 putchar ('\n');
7184 }
19e6b90e
L
7185 }
7186 else
7187 {
7188 unsigned char *look_for;
7189 static Frame_Chunk fde_fc;
604282a7 7190 unsigned long segment_selector;
19e6b90e 7191
49727e46
AM
7192 if (is_eh)
7193 {
7194 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
7195 look_for = start - 4 - ((cie_id ^ sign) - sign);
7196 }
7197 else
7198 look_for = section_start + cie_id;
19e6b90e 7199
49727e46
AM
7200 if (look_for <= saved_start)
7201 {
7202 for (cie = chunks; cie ; cie = cie->next)
7203 if (cie->chunk_start == look_for)
7204 break;
7205 }
7206 else
7207 {
7208 for (cie = forward_refs; cie ; cie = cie->next)
7209 if (cie->chunk_start == look_for)
7210 break;
7211 if (!cie)
7212 {
7213 unsigned int off_size;
7214 unsigned char *cie_scan;
19e6b90e 7215
49727e46
AM
7216 cie_scan = look_for;
7217 off_size = 4;
7218 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
7219 if (length == 0xffffffff)
7220 {
7221 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
7222 off_size = 8;
7223 }
7224 if (length != 0)
7225 {
7226 dwarf_vma c_id;
7227
7228 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
7229 if (is_eh
7230 ? c_id == 0
7231 : ((off_size == 4 && c_id == DW_CIE_ID)
7232 || (off_size == 8 && c_id == DW64_CIE_ID)))
7233 {
7234 int version;
a1165289 7235 unsigned int mreg;
49727e46
AM
7236
7237 read_cie (cie_scan, end, &cie, &version,
7238 &augmentation_data_len, &augmentation_data);
a1165289
NC
7239 /* PR 17512: file: 3450-2098-0.004. */
7240 if (cie == NULL)
7241 {
7242 warn (_("Failed to read CIE information\n"));
7243 break;
7244 }
49727e46
AM
7245 cie->next = forward_refs;
7246 forward_refs = cie;
7247 cie->chunk_start = look_for;
a1165289 7248 mreg = max_regs > 0 ? max_regs - 1 : 0;
49727e46
AM
7249 if (mreg < cie->ra)
7250 mreg = cie->ra;
06614111
NC
7251 if (frame_need_space (cie, mreg) < 0)
7252 {
7253 warn (_("Invalid max register\n"));
7254 break;
7255 }
49727e46
AM
7256 if (cie->fde_encoding)
7257 encoded_ptr_size
7258 = size_of_encoded_value (cie->fde_encoding);
7259 }
7260 }
7261 }
7262 }
7263
7264 fc = &fde_fc;
7265 memset (fc, 0, sizeof (Frame_Chunk));
19e6b90e
L
7266
7267 if (!cie)
7268 {
bf5117e3
NC
7269 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
7270 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
7271 (unsigned long) (saved_start - section_start));
19e6b90e 7272 fc->ncols = 0;
3f5e193b
NC
7273 fc->col_type = (short int *) xmalloc (sizeof (short int));
7274 fc->col_offset = (int *) xmalloc (sizeof (int));
06614111
NC
7275 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
7276 {
7277 warn (_("Invalid max register\n"));
7278 break;
7279 }
19e6b90e
L
7280 cie = fc;
7281 fc->augmentation = "";
7282 fc->fde_encoding = 0;
604282a7
JJ
7283 fc->ptr_size = eh_addr_size;
7284 fc->segment_size = 0;
19e6b90e
L
7285 }
7286 else
7287 {
7288 fc->ncols = cie->ncols;
3f5e193b
NC
7289 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
7290 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
19e6b90e
L
7291 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
7292 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
7293 fc->augmentation = cie->augmentation;
604282a7
JJ
7294 fc->ptr_size = cie->ptr_size;
7295 eh_addr_size = cie->ptr_size;
7296 fc->segment_size = cie->segment_size;
19e6b90e
L
7297 fc->code_factor = cie->code_factor;
7298 fc->data_factor = cie->data_factor;
7299 fc->cfa_reg = cie->cfa_reg;
7300 fc->cfa_offset = cie->cfa_offset;
7301 fc->ra = cie->ra;
06614111
NC
7302 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
7303 {
7304 warn (_("Invalid max register\n"));
7305 break;
7306 }
19e6b90e
L
7307 fc->fde_encoding = cie->fde_encoding;
7308 }
7309
7310 if (fc->fde_encoding)
7311 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7312
604282a7
JJ
7313 segment_selector = 0;
7314 if (fc->segment_size)
c8071705
NC
7315 {
7316 if (fc->segment_size > sizeof (segment_selector))
7317 {
7318 /* PR 17512: file: 9e196b3e. */
7319 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size);
7320 fc->segment_size = 4;
7321 }
7322 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
7323 }
041830e0
NC
7324
7325 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
19e6b90e 7326
0c588247
NC
7327 /* FIXME: It appears that sometimes the final pc_range value is
7328 encoded in less than encoded_ptr_size bytes. See the x86_64
7329 run of the "objcopy on compressed debug sections" test for an
7330 example of this. */
7331 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
bf5117e3 7332
19e6b90e
L
7333 if (cie->augmentation[0] == 'z')
7334 {
7f2c8a1d 7335 READ_ULEB (augmentation_data_len);
19e6b90e
L
7336 augmentation_data = start;
7337 start += augmentation_data_len;
0a9d414a 7338 /* PR 17512: file: 722-8446-0.004. */
53774b7e 7339 if (start >= end || ((signed long) augmentation_data_len) < 0)
0a9d414a
NC
7340 {
7341 warn (_("Corrupt augmentation data length: %lx\n"),
7342 augmentation_data_len);
7343 start = end;
7344 augmentation_data = NULL;
7345 augmentation_data_len = 0;
7346 }
19e6b90e
L
7347 }
7348
bf5117e3
NC
7349 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
7350 (unsigned long)(saved_start - section_start),
7351 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
9c41109d 7352 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
604282a7 7353 (unsigned long)(cie->chunk_start - section_start));
bf5117e3 7354
604282a7
JJ
7355 if (fc->segment_size)
7356 printf ("%04lx:", segment_selector);
bf5117e3
NC
7357
7358 printf ("%s..%s\n",
7359 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
7360 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
7361
19e6b90e
L
7362 if (! do_debug_frames_interp && augmentation_data_len)
7363 {
7364 unsigned long i;
7365
7366 printf (" Augmentation data: ");
7367 for (i = 0; i < augmentation_data_len; ++i)
7368 printf (" %02x", augmentation_data[i]);
7369 putchar ('\n');
7370 putchar ('\n');
7371 }
7372 }
7373
7374 /* At this point, fc is the current chunk, cie (if any) is set, and
7375 we're about to interpret instructions for the chunk. */
7376 /* ??? At present we need to do this always, since this sizes the
7377 fc->col_type and fc->col_offset arrays, which we write into always.
7378 We should probably split the interpreted and non-interpreted bits
7379 into two different routines, since there's so much that doesn't
7380 really overlap between them. */
7381 if (1 || do_debug_frames_interp)
7382 {
7383 /* Start by making a pass over the chunk, allocating storage
7384 and taking note of what registers are used. */
7385 unsigned char *tmp = start;
7386
7387 while (start < block_end)
7388 {
041830e0
NC
7389 unsigned int reg, op, opa;
7390 unsigned long temp;
5929c344 7391 unsigned char * new_start;
19e6b90e
L
7392
7393 op = *start++;
7394 opa = op & 0x3f;
7395 if (op & 0xc0)
7396 op &= 0xc0;
7397
7398 /* Warning: if you add any more cases to this switch, be
7399 sure to add them to the corresponding switch below. */
7400 switch (op)
7401 {
7402 case DW_CFA_advance_loc:
7403 break;
7404 case DW_CFA_offset:
7f2c8a1d 7405 SKIP_ULEB ();
665ce1f6
L
7406 if (frame_need_space (fc, opa) >= 0)
7407 fc->col_type[opa] = DW_CFA_undefined;
19e6b90e
L
7408 break;
7409 case DW_CFA_restore:
665ce1f6
L
7410 if (frame_need_space (fc, opa) >= 0)
7411 fc->col_type[opa] = DW_CFA_undefined;
19e6b90e
L
7412 break;
7413 case DW_CFA_set_loc:
7414 start += encoded_ptr_size;
7415 break;
7416 case DW_CFA_advance_loc1:
7417 start += 1;
7418 break;
7419 case DW_CFA_advance_loc2:
7420 start += 2;
7421 break;
7422 case DW_CFA_advance_loc4:
7423 start += 4;
7424 break;
7425 case DW_CFA_offset_extended:
12eae2d3 7426 case DW_CFA_val_offset:
7f2c8a1d
NC
7427 READ_ULEB (reg);
7428 SKIP_ULEB ();
665ce1f6
L
7429 if (frame_need_space (fc, reg) >= 0)
7430 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
7431 break;
7432 case DW_CFA_restore_extended:
7f2c8a1d 7433 READ_ULEB (reg);
665ce1f6
L
7434 if (frame_need_space (fc, reg) >= 0)
7435 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
7436 break;
7437 case DW_CFA_undefined:
7f2c8a1d 7438 READ_ULEB (reg);
665ce1f6
L
7439 if (frame_need_space (fc, reg) >= 0)
7440 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
7441 break;
7442 case DW_CFA_same_value:
7f2c8a1d 7443 READ_ULEB (reg);
665ce1f6
L
7444 if (frame_need_space (fc, reg) >= 0)
7445 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
7446 break;
7447 case DW_CFA_register:
7f2c8a1d
NC
7448 READ_ULEB (reg);
7449 SKIP_ULEB ();
665ce1f6
L
7450 if (frame_need_space (fc, reg) >= 0)
7451 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
7452 break;
7453 case DW_CFA_def_cfa:
7f2c8a1d
NC
7454 SKIP_ULEB ();
7455 SKIP_ULEB ();
19e6b90e
L
7456 break;
7457 case DW_CFA_def_cfa_register:
7f2c8a1d 7458 SKIP_ULEB ();
19e6b90e
L
7459 break;
7460 case DW_CFA_def_cfa_offset:
7f2c8a1d 7461 SKIP_ULEB ();
19e6b90e
L
7462 break;
7463 case DW_CFA_def_cfa_expression:
7f2c8a1d 7464 READ_ULEB (temp);
5929c344
NC
7465 new_start = start + temp;
7466 if (new_start < start)
041830e0
NC
7467 {
7468 warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
7469 start = block_end;
7470 }
7471 else
5929c344 7472 start = new_start;
19e6b90e
L
7473 break;
7474 case DW_CFA_expression:
12eae2d3 7475 case DW_CFA_val_expression:
7f2c8a1d
NC
7476 READ_ULEB (reg);
7477 READ_ULEB (temp);
5929c344
NC
7478 new_start = start + temp;
7479 if (new_start < start)
041830e0 7480 {
b4eb7656 7481 /* PR 17512: file:306-192417-0.005. */
041830e0
NC
7482 warn (_("Corrupt CFA expression value: %lu\n"), temp);
7483 start = block_end;
7484 }
7485 else
5929c344 7486 start = new_start;
665ce1f6
L
7487 if (frame_need_space (fc, reg) >= 0)
7488 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
7489 break;
7490 case DW_CFA_offset_extended_sf:
12eae2d3 7491 case DW_CFA_val_offset_sf:
7f2c8a1d
NC
7492 READ_ULEB (reg);
7493 SKIP_SLEB ();
665ce1f6
L
7494 if (frame_need_space (fc, reg) >= 0)
7495 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
7496 break;
7497 case DW_CFA_def_cfa_sf:
7f2c8a1d
NC
7498 SKIP_ULEB ();
7499 SKIP_SLEB ();
19e6b90e
L
7500 break;
7501 case DW_CFA_def_cfa_offset_sf:
7f2c8a1d 7502 SKIP_SLEB ();
19e6b90e
L
7503 break;
7504 case DW_CFA_MIPS_advance_loc8:
7505 start += 8;
7506 break;
7507 case DW_CFA_GNU_args_size:
7f2c8a1d 7508 SKIP_ULEB ();
19e6b90e
L
7509 break;
7510 case DW_CFA_GNU_negative_offset_extended:
7f2c8a1d
NC
7511 READ_ULEB (reg);
7512 SKIP_ULEB ();
665ce1f6
L
7513 if (frame_need_space (fc, reg) >= 0)
7514 fc->col_type[reg] = DW_CFA_undefined;
7515 break;
19e6b90e
L
7516 default:
7517 break;
7518 }
7519 }
7520 start = tmp;
7521 }
7522
5b6312fd
NC
7523 all_nops = TRUE;
7524
19e6b90e
L
7525 /* Now we know what registers are used, make a second pass over
7526 the chunk, this time actually printing out the info. */
7527
7528 while (start < block_end)
7529 {
362beea4 7530 unsigned char * tmp;
19e6b90e 7531 unsigned op, opa;
7f2c8a1d
NC
7532 unsigned long ul, roffs;
7533 /* Note: It is tempting to use an unsigned long for 'reg' but there
7534 are various functions, notably frame_space_needed() that assume that
7535 reg is an unsigned int. */
7536 unsigned int reg;
7537 dwarf_signed_vma l;
bf5117e3 7538 dwarf_vma ofs;
19e6b90e 7539 dwarf_vma vma;
665ce1f6 7540 const char *reg_prefix = "";
19e6b90e
L
7541
7542 op = *start++;
7543 opa = op & 0x3f;
7544 if (op & 0xc0)
7545 op &= 0xc0;
7546
5b6312fd
NC
7547 /* Make a note if something other than DW_CFA_nop happens. */
7548 if (op != DW_CFA_nop)
7549 all_nops = FALSE;
7550
19e6b90e
L
7551 /* Warning: if you add any more cases to this switch, be
7552 sure to add them to the corresponding switch above. */
7553 switch (op)
7554 {
7555 case DW_CFA_advance_loc:
7556 if (do_debug_frames_interp)
7557 frame_display_row (fc, &need_col_headers, &max_regs);
7558 else
bf5117e3 7559 printf (" DW_CFA_advance_loc: %d to %s\n",
19e6b90e 7560 opa * fc->code_factor,
b4eb7656 7561 dwarf_vmatoa_1 (NULL,
bf5117e3
NC
7562 fc->pc_begin + opa * fc->code_factor,
7563 fc->ptr_size));
19e6b90e
L
7564 fc->pc_begin += opa * fc->code_factor;
7565 break;
7566
7567 case DW_CFA_offset:
7f2c8a1d 7568 READ_ULEB (roffs);
665ce1f6
L
7569 if (opa >= (unsigned int) fc->ncols)
7570 reg_prefix = bad_reg;
7571 if (! do_debug_frames_interp || *reg_prefix != '\0')
7572 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
7573 reg_prefix, regname (opa, 0),
7574 roffs * fc->data_factor);
7575 if (*reg_prefix == '\0')
7576 {
7577 fc->col_type[opa] = DW_CFA_offset;
7578 fc->col_offset[opa] = roffs * fc->data_factor;
7579 }
19e6b90e
L
7580 break;
7581
7582 case DW_CFA_restore:
50751e18 7583 if (opa >= (unsigned int) fc->ncols)
665ce1f6
L
7584 reg_prefix = bad_reg;
7585 if (! do_debug_frames_interp || *reg_prefix != '\0')
7586 printf (" DW_CFA_restore: %s%s\n",
7587 reg_prefix, regname (opa, 0));
50751e18
AK
7588 if (*reg_prefix != '\0')
7589 break;
7590
7591 if (opa >= (unsigned int) cie->ncols
7592 || (do_debug_frames_interp
7593 && cie->col_type[opa] == DW_CFA_unreferenced))
7594 {
7595 fc->col_type[opa] = DW_CFA_undefined;
7596 fc->col_offset[opa] = 0;
7597 }
7598 else
665ce1f6
L
7599 {
7600 fc->col_type[opa] = cie->col_type[opa];
7601 fc->col_offset[opa] = cie->col_offset[opa];
7602 }
19e6b90e
L
7603 break;
7604
7605 case DW_CFA_set_loc:
6937bb54 7606 vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
19e6b90e
L
7607 if (do_debug_frames_interp)
7608 frame_display_row (fc, &need_col_headers, &max_regs);
7609 else
bf5117e3
NC
7610 printf (" DW_CFA_set_loc: %s\n",
7611 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
19e6b90e
L
7612 fc->pc_begin = vma;
7613 break;
7614
7615 case DW_CFA_advance_loc1:
0c588247 7616 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
19e6b90e
L
7617 if (do_debug_frames_interp)
7618 frame_display_row (fc, &need_col_headers, &max_regs);
7619 else
bf5117e3
NC
7620 printf (" DW_CFA_advance_loc1: %ld to %s\n",
7621 (unsigned long) (ofs * fc->code_factor),
7622 dwarf_vmatoa_1 (NULL,
7623 fc->pc_begin + ofs * fc->code_factor,
7624 fc->ptr_size));
19e6b90e
L
7625 fc->pc_begin += ofs * fc->code_factor;
7626 break;
7627
7628 case DW_CFA_advance_loc2:
6937bb54 7629 SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
19e6b90e
L
7630 if (do_debug_frames_interp)
7631 frame_display_row (fc, &need_col_headers, &max_regs);
7632 else
bf5117e3
NC
7633 printf (" DW_CFA_advance_loc2: %ld to %s\n",
7634 (unsigned long) (ofs * fc->code_factor),
7635 dwarf_vmatoa_1 (NULL,
7636 fc->pc_begin + ofs * fc->code_factor,
7637 fc->ptr_size));
19e6b90e
L
7638 fc->pc_begin += ofs * fc->code_factor;
7639 break;
7640
7641 case DW_CFA_advance_loc4:
6937bb54 7642 SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
19e6b90e
L
7643 if (do_debug_frames_interp)
7644 frame_display_row (fc, &need_col_headers, &max_regs);
7645 else
bf5117e3
NC
7646 printf (" DW_CFA_advance_loc4: %ld to %s\n",
7647 (unsigned long) (ofs * fc->code_factor),
7648 dwarf_vmatoa_1 (NULL,
7649 fc->pc_begin + ofs * fc->code_factor,
7650 fc->ptr_size));
19e6b90e
L
7651 fc->pc_begin += ofs * fc->code_factor;
7652 break;
7653
7654 case DW_CFA_offset_extended:
7f2c8a1d
NC
7655 READ_ULEB (reg);
7656 READ_ULEB (roffs);
665ce1f6
L
7657 if (reg >= (unsigned int) fc->ncols)
7658 reg_prefix = bad_reg;
7659 if (! do_debug_frames_interp || *reg_prefix != '\0')
7660 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
7661 reg_prefix, regname (reg, 0),
7662 roffs * fc->data_factor);
7663 if (*reg_prefix == '\0')
7664 {
7665 fc->col_type[reg] = DW_CFA_offset;
7666 fc->col_offset[reg] = roffs * fc->data_factor;
7667 }
19e6b90e
L
7668 break;
7669
12eae2d3 7670 case DW_CFA_val_offset:
7f2c8a1d
NC
7671 READ_ULEB (reg);
7672 READ_ULEB (roffs);
665ce1f6
L
7673 if (reg >= (unsigned int) fc->ncols)
7674 reg_prefix = bad_reg;
7675 if (! do_debug_frames_interp || *reg_prefix != '\0')
084303b8 7676 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
665ce1f6
L
7677 reg_prefix, regname (reg, 0),
7678 roffs * fc->data_factor);
7679 if (*reg_prefix == '\0')
7680 {
7681 fc->col_type[reg] = DW_CFA_val_offset;
7682 fc->col_offset[reg] = roffs * fc->data_factor;
7683 }
12eae2d3
JJ
7684 break;
7685
19e6b90e 7686 case DW_CFA_restore_extended:
7f2c8a1d 7687 READ_ULEB (reg);
50751e18 7688 if (reg >= (unsigned int) fc->ncols)
665ce1f6
L
7689 reg_prefix = bad_reg;
7690 if (! do_debug_frames_interp || *reg_prefix != '\0')
7691 printf (" DW_CFA_restore_extended: %s%s\n",
7692 reg_prefix, regname (reg, 0));
50751e18
AK
7693 if (*reg_prefix != '\0')
7694 break;
7695
7696 if (reg >= (unsigned int) cie->ncols)
7697 {
7698 fc->col_type[reg] = DW_CFA_undefined;
7699 fc->col_offset[reg] = 0;
7700 }
7701 else
665ce1f6
L
7702 {
7703 fc->col_type[reg] = cie->col_type[reg];
7704 fc->col_offset[reg] = cie->col_offset[reg];
7705 }
19e6b90e
L
7706 break;
7707
7708 case DW_CFA_undefined:
7f2c8a1d 7709 READ_ULEB (reg);
665ce1f6
L
7710 if (reg >= (unsigned int) fc->ncols)
7711 reg_prefix = bad_reg;
7712 if (! do_debug_frames_interp || *reg_prefix != '\0')
7713 printf (" DW_CFA_undefined: %s%s\n",
7714 reg_prefix, regname (reg, 0));
7715 if (*reg_prefix == '\0')
7716 {
7717 fc->col_type[reg] = DW_CFA_undefined;
7718 fc->col_offset[reg] = 0;
7719 }
19e6b90e
L
7720 break;
7721
7722 case DW_CFA_same_value:
7f2c8a1d 7723 READ_ULEB (reg);
665ce1f6
L
7724 if (reg >= (unsigned int) fc->ncols)
7725 reg_prefix = bad_reg;
7726 if (! do_debug_frames_interp || *reg_prefix != '\0')
7727 printf (" DW_CFA_same_value: %s%s\n",
7728 reg_prefix, regname (reg, 0));
7729 if (*reg_prefix == '\0')
7730 {
7731 fc->col_type[reg] = DW_CFA_same_value;
7732 fc->col_offset[reg] = 0;
7733 }
19e6b90e
L
7734 break;
7735
7736 case DW_CFA_register:
7f2c8a1d
NC
7737 READ_ULEB (reg);
7738 READ_ULEB (roffs);
665ce1f6
L
7739 if (reg >= (unsigned int) fc->ncols)
7740 reg_prefix = bad_reg;
7741 if (! do_debug_frames_interp || *reg_prefix != '\0')
2dc4cec1 7742 {
665ce1f6
L
7743 printf (" DW_CFA_register: %s%s in ",
7744 reg_prefix, regname (reg, 0));
2dc4cec1
L
7745 puts (regname (roffs, 0));
7746 }
665ce1f6
L
7747 if (*reg_prefix == '\0')
7748 {
7749 fc->col_type[reg] = DW_CFA_register;
7750 fc->col_offset[reg] = roffs;
7751 }
19e6b90e
L
7752 break;
7753
7754 case DW_CFA_remember_state:
7755 if (! do_debug_frames_interp)
7756 printf (" DW_CFA_remember_state\n");
3f5e193b 7757 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
b4eb7656 7758 rs->cfa_offset = fc->cfa_offset;
d71ad7fc
RC
7759 rs->cfa_reg = fc->cfa_reg;
7760 rs->ra = fc->ra;
7761 rs->cfa_exp = fc->cfa_exp;
19e6b90e 7762 rs->ncols = fc->ncols;
3f5e193b 7763 rs->col_type = (short int *) xcmalloc (rs->ncols,
b4eb7656 7764 sizeof (* rs->col_type));
d71ad7fc
RC
7765 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
7766 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
7767 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
19e6b90e
L
7768 rs->next = remembered_state;
7769 remembered_state = rs;
7770 break;
7771
7772 case DW_CFA_restore_state:
7773 if (! do_debug_frames_interp)
7774 printf (" DW_CFA_restore_state\n");
7775 rs = remembered_state;
7776 if (rs)
7777 {
7778 remembered_state = rs->next;
d71ad7fc
RC
7779 fc->cfa_offset = rs->cfa_offset;
7780 fc->cfa_reg = rs->cfa_reg;
b4eb7656
AM
7781 fc->ra = rs->ra;
7782 fc->cfa_exp = rs->cfa_exp;
06614111
NC
7783 if (frame_need_space (fc, rs->ncols - 1) < 0)
7784 {
1306a742 7785 warn (_("Invalid column number in saved frame state\n"));
06614111
NC
7786 fc->ncols = 0;
7787 break;
7788 }
d71ad7fc 7789 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
19e6b90e 7790 memcpy (fc->col_offset, rs->col_offset,
d71ad7fc 7791 rs->ncols * sizeof (* rs->col_offset));
19e6b90e
L
7792 free (rs->col_type);
7793 free (rs->col_offset);
7794 free (rs);
7795 }
7796 else if (do_debug_frames_interp)
7797 printf ("Mismatched DW_CFA_restore_state\n");
7798 break;
7799
7800 case DW_CFA_def_cfa:
7f2c8a1d
NC
7801 READ_SLEB (fc->cfa_reg);
7802 READ_ULEB (fc->cfa_offset);
19e6b90e
L
7803 fc->cfa_exp = 0;
7804 if (! do_debug_frames_interp)
2dc4cec1 7805 printf (" DW_CFA_def_cfa: %s ofs %d\n",
c8071705 7806 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
19e6b90e
L
7807 break;
7808
7809 case DW_CFA_def_cfa_register:
7f2c8a1d 7810 READ_SLEB (fc->cfa_reg);
19e6b90e
L
7811 fc->cfa_exp = 0;
7812 if (! do_debug_frames_interp)
2dc4cec1
L
7813 printf (" DW_CFA_def_cfa_register: %s\n",
7814 regname (fc->cfa_reg, 0));
19e6b90e
L
7815 break;
7816
7817 case DW_CFA_def_cfa_offset:
7f2c8a1d 7818 READ_ULEB (fc->cfa_offset);
19e6b90e 7819 if (! do_debug_frames_interp)
c8071705 7820 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset);
19e6b90e
L
7821 break;
7822
7823 case DW_CFA_nop:
7824 if (! do_debug_frames_interp)
7825 printf (" DW_CFA_nop\n");
7826 break;
7827
7828 case DW_CFA_def_cfa_expression:
7f2c8a1d 7829 READ_ULEB (ul);
7460c0ab 7830 if (start >= block_end || ul > (unsigned long) (block_end - start))
6937bb54 7831 {
a1165289 7832 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
6937bb54
NC
7833 break;
7834 }
19e6b90e
L
7835 if (! do_debug_frames_interp)
7836 {
7837 printf (" DW_CFA_def_cfa_expression (");
b7807392
JJ
7838 decode_location_expression (start, eh_addr_size, 0, -1,
7839 ul, 0, section);
19e6b90e
L
7840 printf (")\n");
7841 }
7842 fc->cfa_exp = 1;
7843 start += ul;
7844 break;
7845
7846 case DW_CFA_expression:
7f2c8a1d
NC
7847 READ_ULEB (reg);
7848 READ_ULEB (ul);
665ce1f6
L
7849 if (reg >= (unsigned int) fc->ncols)
7850 reg_prefix = bad_reg;
6937bb54 7851 /* PR 17512: file: 069-133014-0.006. */
06614111 7852 /* PR 17512: file: 98c02eb4. */
362beea4
NC
7853 tmp = start + ul;
7854 if (start >= block_end || tmp > block_end || tmp < start)
6937bb54 7855 {
a1165289 7856 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
6937bb54
NC
7857 break;
7858 }
665ce1f6 7859 if (! do_debug_frames_interp || *reg_prefix != '\0')
19e6b90e 7860 {
665ce1f6
L
7861 printf (" DW_CFA_expression: %s%s (",
7862 reg_prefix, regname (reg, 0));
b7807392 7863 decode_location_expression (start, eh_addr_size, 0, -1,
f1c4cc75 7864 ul, 0, section);
19e6b90e
L
7865 printf (")\n");
7866 }
665ce1f6
L
7867 if (*reg_prefix == '\0')
7868 fc->col_type[reg] = DW_CFA_expression;
362beea4 7869 start = tmp;
19e6b90e
L
7870 break;
7871
12eae2d3 7872 case DW_CFA_val_expression:
7f2c8a1d
NC
7873 READ_ULEB (reg);
7874 READ_ULEB (ul);
665ce1f6
L
7875 if (reg >= (unsigned int) fc->ncols)
7876 reg_prefix = bad_reg;
362beea4
NC
7877 tmp = start + ul;
7878 if (start >= block_end || tmp > block_end || tmp < start)
6937bb54 7879 {
a1165289 7880 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
6937bb54
NC
7881 break;
7882 }
665ce1f6 7883 if (! do_debug_frames_interp || *reg_prefix != '\0')
12eae2d3 7884 {
665ce1f6
L
7885 printf (" DW_CFA_val_expression: %s%s (",
7886 reg_prefix, regname (reg, 0));
b7807392
JJ
7887 decode_location_expression (start, eh_addr_size, 0, -1,
7888 ul, 0, section);
12eae2d3
JJ
7889 printf (")\n");
7890 }
665ce1f6
L
7891 if (*reg_prefix == '\0')
7892 fc->col_type[reg] = DW_CFA_val_expression;
362beea4 7893 start = tmp;
12eae2d3
JJ
7894 break;
7895
19e6b90e 7896 case DW_CFA_offset_extended_sf:
7f2c8a1d
NC
7897 READ_ULEB (reg);
7898 READ_SLEB (l);
665ce1f6
L
7899 if (frame_need_space (fc, reg) < 0)
7900 reg_prefix = bad_reg;
7901 if (! do_debug_frames_interp || *reg_prefix != '\0')
7902 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
7903 reg_prefix, regname (reg, 0),
c8071705 7904 (long)(l * fc->data_factor));
665ce1f6
L
7905 if (*reg_prefix == '\0')
7906 {
7907 fc->col_type[reg] = DW_CFA_offset;
7908 fc->col_offset[reg] = l * fc->data_factor;
7909 }
19e6b90e
L
7910 break;
7911
12eae2d3 7912 case DW_CFA_val_offset_sf:
7f2c8a1d
NC
7913 READ_ULEB (reg);
7914 READ_SLEB (l);
665ce1f6
L
7915 if (frame_need_space (fc, reg) < 0)
7916 reg_prefix = bad_reg;
7917 if (! do_debug_frames_interp || *reg_prefix != '\0')
084303b8 7918 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
665ce1f6 7919 reg_prefix, regname (reg, 0),
c8071705 7920 (long)(l * fc->data_factor));
665ce1f6
L
7921 if (*reg_prefix == '\0')
7922 {
7923 fc->col_type[reg] = DW_CFA_val_offset;
7924 fc->col_offset[reg] = l * fc->data_factor;
7925 }
12eae2d3
JJ
7926 break;
7927
19e6b90e 7928 case DW_CFA_def_cfa_sf:
7f2c8a1d
NC
7929 READ_SLEB (fc->cfa_reg);
7930 READ_ULEB (fc->cfa_offset);
19e6b90e
L
7931 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
7932 fc->cfa_exp = 0;
7933 if (! do_debug_frames_interp)
2dc4cec1 7934 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
c8071705 7935 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
19e6b90e
L
7936 break;
7937
7938 case DW_CFA_def_cfa_offset_sf:
7f2c8a1d 7939 READ_ULEB (fc->cfa_offset);
c8071705 7940 fc->cfa_offset *= fc->data_factor;
19e6b90e 7941 if (! do_debug_frames_interp)
c8071705 7942 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset);
19e6b90e
L
7943 break;
7944
7945 case DW_CFA_MIPS_advance_loc8:
6937bb54 7946 SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
19e6b90e
L
7947 if (do_debug_frames_interp)
7948 frame_display_row (fc, &need_col_headers, &max_regs);
7949 else
bf5117e3
NC
7950 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
7951 (unsigned long) (ofs * fc->code_factor),
7952 dwarf_vmatoa_1 (NULL,
7953 fc->pc_begin + ofs * fc->code_factor,
7954 fc->ptr_size));
19e6b90e
L
7955 fc->pc_begin += ofs * fc->code_factor;
7956 break;
7957
7958 case DW_CFA_GNU_window_save:
7959 if (! do_debug_frames_interp)
7960 printf (" DW_CFA_GNU_window_save\n");
7961 break;
7962
7963 case DW_CFA_GNU_args_size:
7f2c8a1d 7964 READ_ULEB (ul);
19e6b90e
L
7965 if (! do_debug_frames_interp)
7966 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
7967 break;
7968
7969 case DW_CFA_GNU_negative_offset_extended:
7f2c8a1d
NC
7970 READ_ULEB (reg);
7971 READ_SLEB (l);
7972 l = - l;
665ce1f6
L
7973 if (frame_need_space (fc, reg) < 0)
7974 reg_prefix = bad_reg;
7975 if (! do_debug_frames_interp || *reg_prefix != '\0')
7976 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
7977 reg_prefix, regname (reg, 0),
c8071705 7978 (long)(l * fc->data_factor));
665ce1f6
L
7979 if (*reg_prefix == '\0')
7980 {
7981 fc->col_type[reg] = DW_CFA_offset;
7982 fc->col_offset[reg] = l * fc->data_factor;
7983 }
19e6b90e
L
7984 break;
7985
7986 default:
53b8873b
NC
7987 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
7988 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
7989 else
f41e4712 7990 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
19e6b90e
L
7991 start = block_end;
7992 }
7993 }
7994
5b6312fd
NC
7995 /* Interpret the CFA - as long as it is not completely full of NOPs. */
7996 if (do_debug_frames_interp && ! all_nops)
19e6b90e
L
7997 frame_display_row (fc, &need_col_headers, &max_regs);
7998
7999 start = block_end;
604282a7 8000 eh_addr_size = saved_eh_addr_size;
19e6b90e
L
8001 }
8002
8003 printf ("\n");
8004
8005 return 1;
8006}
8007
8008#undef GET
19e6b90e 8009
61364358
JK
8010static int
8011display_debug_names (struct dwarf_section *section, void *file)
8012{
8013 unsigned char *hdrptr = section->start;
8014 dwarf_vma unit_length;
8015 unsigned char *unit_start;
8016 const unsigned char *const section_end = section->start + section->size;
8017 unsigned char *unit_end;
8018
8019 printf (_("Contents of the %s section:\n"), section->name);
8020
8021 load_debug_section (str, file);
8022
8023 for (; hdrptr < section_end; hdrptr = unit_end)
8024 {
8025 unsigned int offset_size;
8026 uint16_t dwarf_version, padding;
8027 uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count;
8028 uint32_t bucket_count, name_count, abbrev_table_size;
8029 uint32_t augmentation_string_size;
8030 unsigned int i;
8031
8032 unit_start = hdrptr;
8033
8034 /* Get and check the length of the block. */
8035 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end);
8036
8037 if (unit_length == 0xffffffff)
8038 {
8039 /* This section is 64-bit DWARF. */
8040 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end);
8041 offset_size = 8;
8042 }
8043 else
8044 offset_size = 4;
8045 unit_end = hdrptr + unit_length;
8046
8047 if ((hdrptr - section->start) + unit_length > section->size)
8048 {
8049 warn (_("The length field (0x%lx) for unit 0x%lx in the debug_names "
8050 "header is wrong - the section is too small\n"),
8051 (long) unit_length, (long) (unit_start - section->start));
8052 return 0;
8053 }
8054
8055 /* Get and check the version number. */
8056 SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end);
8057 printf (_("Version %ld\n"), (long) dwarf_version);
8058
8059 /* Prior versions did not exist, and future versions may not be
8060 backwards compatible. */
8061 if (dwarf_version != 5)
8062 {
8063 warn (_("Only DWARF version 5 .debug_names "
8064 "is currently supported.\n"));
8065 return 0;
8066 }
8067
8068 SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end);
8069 if (padding != 0)
8070 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
8071 padding);
8072
8073 SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end);
8074 if (comp_unit_count == 0)
8075 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
8076
8077 SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end);
8078 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end);
8079 SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end);
8080 SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end);
8081 SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end);
8082
8083 SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end);
8084 if (augmentation_string_size % 4 != 0)
8085 {
8086 warn (_("Augmentation string length %u must be rounded up "
8087 "to a multiple of 4 in .debug_names.\n"),
8088 augmentation_string_size);
8089 augmentation_string_size += (-augmentation_string_size) & 3;
8090 }
8091 printf (_("Augmentation string:"));
8092 for (i = 0; i < augmentation_string_size; i++)
8093 {
8094 unsigned char uc;
8095
8096 SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end);
8097 printf (" %02x", uc);
8098 }
8099 putchar ('\n');
8100 putchar ('\n');
8101
8102 printf (_("CU table:\n"));
8103 for (i = 0; i < comp_unit_count; i++)
8104 {
8105 uint64_t cu_offset;
8106
8107 SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end);
8108 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset);
8109 }
8110 putchar ('\n');
8111
8112 printf (_("TU table:\n"));
8113 for (i = 0; i < local_type_unit_count; i++)
8114 {
8115 uint64_t tu_offset;
8116
8117 SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end);
8118 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset);
8119 }
8120 putchar ('\n');
8121
8122 printf (_("Foreign TU table:\n"));
8123 for (i = 0; i < foreign_type_unit_count; i++)
8124 {
8125 uint64_t signature;
8126
8127 SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end);
8128 printf (_("[%3u] "), i);
8129 print_dwarf_vma (signature, 8);
8130 putchar ('\n');
8131 }
8132 putchar ('\n');
8133
8134 const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr;
8135 hdrptr += bucket_count * sizeof (uint32_t);
8136 const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr;
8137 hdrptr += name_count * sizeof (uint32_t);
8138 unsigned char *const name_table_string_offsets = hdrptr;
8139 hdrptr += name_count * offset_size;
8140 unsigned char *const name_table_entry_offsets = hdrptr;
8141 hdrptr += name_count * offset_size;
8142 unsigned char *const abbrev_table = hdrptr;
8143 hdrptr += abbrev_table_size;
8144 const unsigned char *const abbrev_table_end = hdrptr;
8145 unsigned char *const entry_pool = hdrptr;
8146 if (hdrptr > unit_end)
8147 {
8148 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
8149 "for unit 0x%lx in the debug_names\n"),
8150 (long) (hdrptr - section->start),
8151 (long) (unit_end - section->start),
8152 (long) (unit_start - section->start));
8153 return 0;
8154 }
8155
8156 size_t buckets_filled = 0;
8157 size_t bucketi;
8158 for (bucketi = 0; bucketi < bucket_count; bucketi++)
8159 {
8160 const uint32_t bucket = hash_table_buckets[bucketi];
8161
8162 if (bucket != 0)
8163 ++buckets_filled;
8164 }
8165 printf (_("Used %zu of %lu buckets.\n"), buckets_filled,
8166 (unsigned long) bucket_count);
8167
0a79bef4 8168 uint32_t hash_prev = 0;
61364358
JK
8169 size_t hash_clash_count = 0;
8170 size_t longest_clash = 0;
8171 size_t this_length = 0;
8172 size_t hashi;
8173 for (hashi = 0; hashi < name_count; hashi++)
8174 {
8175 const uint32_t hash_this = hash_table_hashes[hashi];
8176
8177 if (hashi > 0)
8178 {
8179 if (hash_prev % bucket_count == hash_this % bucket_count)
8180 {
8181 ++hash_clash_count;
8182 ++this_length;
8183 longest_clash = MAX (longest_clash, this_length);
8184 }
8185 else
8186 this_length = 0;
8187 }
8188 hash_prev = hash_this;
8189 }
8190 printf (_("Out of %lu items there are %zu bucket clashes"
8191 " (longest of %zu entries).\n"),
8192 (unsigned long) name_count, hash_clash_count, longest_clash);
8193 assert (name_count == buckets_filled + hash_clash_count);
8194
8195 struct abbrev_lookup_entry
8196 {
8197 dwarf_vma abbrev_tag;
8198 unsigned char *abbrev_lookup_ptr;
8199 };
8200 struct abbrev_lookup_entry *abbrev_lookup = NULL;
8201 size_t abbrev_lookup_used = 0;
8202 size_t abbrev_lookup_allocated = 0;
8203
8204 unsigned char *abbrevptr = abbrev_table;
8205 for (;;)
8206 {
8207 unsigned int bytes_read;
8208 const dwarf_vma abbrev_tag = read_uleb128 (abbrevptr, &bytes_read,
8209 abbrev_table_end);
8210 abbrevptr += bytes_read;
8211 if (abbrev_tag == 0)
8212 break;
8213 if (abbrev_lookup_used == abbrev_lookup_allocated)
8214 {
8215 abbrev_lookup_allocated = MAX (0x100,
8216 abbrev_lookup_allocated * 2);
8217 abbrev_lookup = xrealloc (abbrev_lookup,
8218 (abbrev_lookup_allocated
8219 * sizeof (*abbrev_lookup)));
8220 }
8221 assert (abbrev_lookup_used < abbrev_lookup_allocated);
8222 struct abbrev_lookup_entry *entry;
8223 for (entry = abbrev_lookup;
8224 entry < abbrev_lookup + abbrev_lookup_used;
8225 entry++)
8226 if (entry->abbrev_tag == abbrev_tag)
8227 {
8228 warn (_("Duplicate abbreviation tag %lu "
8229 "in unit 0x%lx in the debug_names\n"),
8230 (long) abbrev_tag, (long) (unit_start - section->start));
8231 break;
8232 }
8233 entry = &abbrev_lookup[abbrev_lookup_used++];
8234 entry->abbrev_tag = abbrev_tag;
8235 entry->abbrev_lookup_ptr = abbrevptr;
8236
8237 /* Skip DWARF tag. */
8238 read_uleb128 (abbrevptr, &bytes_read, abbrev_table_end);
8239 abbrevptr += bytes_read;
8240 for (;;)
8241 {
1d827a72
L
8242 const dwarf_vma xindex = read_uleb128 (abbrevptr,
8243 &bytes_read,
8244 abbrev_table_end);
61364358
JK
8245 abbrevptr += bytes_read;
8246 const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read,
8247 abbrev_table_end);
8248 abbrevptr += bytes_read;
1d827a72 8249 if (xindex == 0 && form == 0)
61364358
JK
8250 break;
8251 }
8252 }
8253
8254 printf (_("\nSymbol table:\n"));
8255 uint32_t namei;
8256 for (namei = 0; namei < name_count; ++namei)
8257 {
8258 uint64_t string_offset, entry_offset;
8259
8260 SAFE_BYTE_GET (string_offset,
8261 name_table_string_offsets + namei * offset_size,
8262 offset_size, unit_end);
8263 SAFE_BYTE_GET (entry_offset,
8264 name_table_entry_offsets + namei * offset_size,
8265 offset_size, unit_end);
8266
8267 printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei],
8268 fetch_indirect_string (string_offset));
8269
8270 unsigned char *entryptr = entry_pool + entry_offset;
8271
8272 // We need to scan first whether there is a single or multiple
8273 // entries. TAGNO is -2 for the first entry, it is -1 for the
8274 // initial tag read of the second entry, then it becomes 0 for the
8275 // first entry for real printing etc.
8276 int tagno = -2;
8277 /* Initialize it due to a false compiler warning. */
8278 dwarf_vma second_abbrev_tag = -1;
8279 for (;;)
8280 {
8281 unsigned int bytes_read;
8282 const dwarf_vma abbrev_tag = read_uleb128 (entryptr, &bytes_read,
8283 unit_end);
8284 entryptr += bytes_read;
8285 if (tagno == -1)
8286 {
8287 second_abbrev_tag = abbrev_tag;
8288 tagno = 0;
8289 entryptr = entry_pool + entry_offset;
8290 continue;
8291 }
8292 if (abbrev_tag == 0)
8293 break;
8294 if (tagno >= 0)
8295 printf ("%s<%lu>",
8296 (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"),
8297 (unsigned long) abbrev_tag);
8298
8299 const struct abbrev_lookup_entry *entry;
8300 for (entry = abbrev_lookup;
8301 entry < abbrev_lookup + abbrev_lookup_used;
8302 entry++)
8303 if (entry->abbrev_tag == abbrev_tag)
8304 break;
8305 if (entry >= abbrev_lookup + abbrev_lookup_used)
8306 {
8307 warn (_("Undefined abbreviation tag %lu "
8308 "in unit 0x%lx in the debug_names\n"),
8309 (long) abbrev_tag,
8310 (long) (unit_start - section->start));
8311 break;
8312 }
8313 abbrevptr = entry->abbrev_lookup_ptr;
8314 const dwarf_vma dwarf_tag = read_uleb128 (abbrevptr, &bytes_read,
8315 abbrev_table_end);
8316 abbrevptr += bytes_read;
8317 if (tagno >= 0)
8318 printf (" %s", get_TAG_name (dwarf_tag));
8319 for (;;)
8320 {
1d827a72
L
8321 const dwarf_vma xindex = read_uleb128 (abbrevptr,
8322 &bytes_read,
8323 abbrev_table_end);
61364358
JK
8324 abbrevptr += bytes_read;
8325 const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read,
8326 abbrev_table_end);
8327 abbrevptr += bytes_read;
1d827a72 8328 if (xindex == 0 && form == 0)
61364358
JK
8329 break;
8330
8331 if (tagno >= 0)
1d827a72 8332 printf (" %s", get_IDX_name (xindex));
61364358
JK
8333 entryptr = read_and_display_attr_value (0, form, 0, entryptr,
8334 unit_end, 0, 0,
8335 offset_size,
8336 dwarf_version, NULL,
8337 (tagno < 0), NULL,
8338 NULL, '=');
8339 }
8340 ++tagno;
8341 }
8342 if (tagno <= 0)
8343 printf (_(" <no entries>"));
8344 putchar ('\n');
8345 }
8346
8347 free (abbrev_lookup);
8348 }
8349
8350 return 1;
8351}
8352
5bbdf3d5
DE
8353static int
8354display_gdb_index (struct dwarf_section *section,
8355 void *file ATTRIBUTE_UNUSED)
8356{
8357 unsigned char *start = section->start;
8358 uint32_t version;
8359 uint32_t cu_list_offset, tu_list_offset;
8360 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
8361 unsigned int cu_list_elements, tu_list_elements;
8362 unsigned int address_table_size, symbol_table_slots;
8363 unsigned char *cu_list, *tu_list;
8364 unsigned char *address_table, *symbol_table, *constant_pool;
8365 unsigned int i;
8366
8367 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
8368
8369 printf (_("Contents of the %s section:\n"), section->name);
8370
8371 if (section->size < 6 * sizeof (uint32_t))
8372 {
8373 warn (_("Truncated header in the %s section.\n"), section->name);
8374 return 0;
8375 }
8376
8377 version = byte_get_little_endian (start, 4);
da88a764 8378 printf (_("Version %ld\n"), (long) version);
5bbdf3d5
DE
8379
8380 /* Prior versions are obsolete, and future versions may not be
8381 backwards compatible. */
aa170720 8382 if (version < 3 || version > 8)
5bbdf3d5 8383 {
da88a764 8384 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
5bbdf3d5
DE
8385 return 0;
8386 }
8d6eee87
TT
8387 if (version < 4)
8388 warn (_("The address table data in version 3 may be wrong.\n"));
8389 if (version < 5)
8390 warn (_("Version 4 does not support case insensitive lookups.\n"));
8391 if (version < 6)
8392 warn (_("Version 5 does not include inlined functions.\n"));
8393 if (version < 7)
8394 warn (_("Version 6 does not include symbol attributes.\n"));
aa170720
DE
8395 /* Version 7 indices generated by Gold have bad type unit references,
8396 PR binutils/15021. But we don't know if the index was generated by
8397 Gold or not, so to avoid worrying users with gdb-generated indices
8398 we say nothing for version 7 here. */
5bbdf3d5
DE
8399
8400 cu_list_offset = byte_get_little_endian (start + 4, 4);
8401 tu_list_offset = byte_get_little_endian (start + 8, 4);
8402 address_table_offset = byte_get_little_endian (start + 12, 4);
8403 symbol_table_offset = byte_get_little_endian (start + 16, 4);
8404 constant_pool_offset = byte_get_little_endian (start + 20, 4);
8405
8406 if (cu_list_offset > section->size
8407 || tu_list_offset > section->size
8408 || address_table_offset > section->size
8409 || symbol_table_offset > section->size
8410 || constant_pool_offset > section->size)
8411 {
8412 warn (_("Corrupt header in the %s section.\n"), section->name);
8413 return 0;
8414 }
8415
53774b7e
NC
8416 /* PR 17531: file: 418d0a8a. */
8417 if (tu_list_offset < cu_list_offset)
8418 {
8419 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
8420 tu_list_offset, cu_list_offset);
8421 return 0;
8422 }
8423
5bbdf3d5 8424 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
53774b7e
NC
8425
8426 if (address_table_offset < tu_list_offset)
8427 {
8428 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
8429 address_table_offset, tu_list_offset);
8430 return 0;
8431 }
8432
5bbdf3d5 8433 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
53774b7e
NC
8434
8435 /* PR 17531: file: 18a47d3d. */
8436 if (symbol_table_offset < address_table_offset)
8437 {
13bace4a 8438 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
53774b7e
NC
8439 symbol_table_offset, address_table_offset);
8440 return 0;
8441 }
8442
5bbdf3d5 8443 address_table_size = symbol_table_offset - address_table_offset;
53774b7e
NC
8444
8445 if (constant_pool_offset < symbol_table_offset)
8446 {
8447 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
8448 constant_pool_offset, symbol_table_offset);
8449 return 0;
8450 }
8451
5bbdf3d5
DE
8452 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
8453
8454 cu_list = start + cu_list_offset;
8455 tu_list = start + tu_list_offset;
8456 address_table = start + address_table_offset;
8457 symbol_table = start + symbol_table_offset;
8458 constant_pool = start + constant_pool_offset;
8459
28d909e5 8460 if (address_table + address_table_size > section->start + section->size)
acff9664 8461 {
1306a742 8462 warn (_("Address table extends beyond end of section.\n"));
acff9664
NC
8463 return 0;
8464 }
b4eb7656 8465
5bbdf3d5
DE
8466 printf (_("\nCU table:\n"));
8467 for (i = 0; i < cu_list_elements; i += 2)
8468 {
8469 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
8470 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
8471
8472 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
8473 (unsigned long) cu_offset,
8474 (unsigned long) (cu_offset + cu_length - 1));
8475 }
8476
8477 printf (_("\nTU table:\n"));
8478 for (i = 0; i < tu_list_elements; i += 3)
8479 {
8480 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
8481 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
8482 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
8483
8484 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
8485 (unsigned long) tu_offset,
8486 (unsigned long) type_offset);
8487 print_dwarf_vma (signature, 8);
8488 printf ("\n");
8489 }
8490
8491 printf (_("\nAddress table:\n"));
acff9664
NC
8492 for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
8493 i += 2 * 8 + 4)
5bbdf3d5
DE
8494 {
8495 uint64_t low = byte_get_little_endian (address_table + i, 8);
8496 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
8497 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
8498
8499 print_dwarf_vma (low, 8);
8500 print_dwarf_vma (high, 8);
da88a764 8501 printf (_("%lu\n"), (unsigned long) cu_index);
5bbdf3d5
DE
8502 }
8503
8504 printf (_("\nSymbol table:\n"));
8505 for (i = 0; i < symbol_table_slots; ++i)
8506 {
8507 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
8508 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
8509 uint32_t num_cus, cu;
8510
8511 if (name_offset != 0
8512 || cu_vector_offset != 0)
8513 {
8514 unsigned int j;
362beea4 8515 unsigned char * adr;
5bbdf3d5 8516
362beea4 8517 adr = constant_pool + name_offset;
53774b7e 8518 /* PR 17531: file: 5b7b07ad. */
362beea4 8519 if (adr < constant_pool || adr >= section->start + section->size)
53774b7e
NC
8520 {
8521 printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
8522 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
8523 name_offset, i);
8524 }
8525 else
acff9664
NC
8526 printf ("[%3u] %.*s:", i,
8527 (int) (section->size - (constant_pool_offset + name_offset)),
8528 constant_pool + name_offset);
53774b7e 8529
362beea4
NC
8530 adr = constant_pool + cu_vector_offset;
8531 if (adr < constant_pool || adr >= section->start + section->size - 3)
53774b7e
NC
8532 {
8533 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
8534 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
8535 cu_vector_offset, i);
8536 continue;
8537 }
57028622 8538
362beea4 8539 num_cus = byte_get_little_endian (adr, 4);
53774b7e 8540
362beea4 8541 adr = constant_pool + cu_vector_offset + 4 + num_cus * 4;
acff9664 8542 if (num_cus * 4 < num_cus
362beea4
NC
8543 || adr >= section->start + section->size
8544 || adr < constant_pool)
53774b7e
NC
8545 {
8546 printf ("<invalid number of CUs: %d>\n", num_cus);
acff9664 8547 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
53774b7e
NC
8548 num_cus, i);
8549 continue;
8550 }
8551
8d6eee87
TT
8552 if (num_cus > 1)
8553 printf ("\n");
f3853b34 8554
5bbdf3d5
DE
8555 for (j = 0; j < num_cus; ++j)
8556 {
7c1cef97 8557 int is_static;
8d6eee87
TT
8558 gdb_index_symbol_kind kind;
8559
5bbdf3d5 8560 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
7c1cef97 8561 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
8d6eee87
TT
8562 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
8563 cu = GDB_INDEX_CU_VALUE (cu);
5bbdf3d5 8564 /* Convert to TU number if it's for a type unit. */
ad6b52dd 8565 if (cu >= cu_list_elements / 2)
8d6eee87
TT
8566 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
8567 (unsigned long) (cu - cu_list_elements / 2));
5bbdf3d5 8568 else
8d6eee87
TT
8569 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
8570
459d52c8
DE
8571 printf (" [%s, %s]",
8572 is_static ? _("static") : _("global"),
8573 get_gdb_index_symbol_kind_name (kind));
8d6eee87
TT
8574 if (num_cus > 1)
8575 printf ("\n");
5bbdf3d5 8576 }
8d6eee87
TT
8577 if (num_cus <= 1)
8578 printf ("\n");
5bbdf3d5
DE
8579 }
8580 }
8581
8582 return 1;
8583}
8584
657d0d47
CC
8585/* Pre-allocate enough space for the CU/TU sets needed. */
8586
8587static void
8588prealloc_cu_tu_list (unsigned int nshndx)
8589{
8590 if (shndx_pool == NULL)
8591 {
8592 shndx_pool_size = nshndx;
8593 shndx_pool_used = 0;
8594 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
8595 sizeof (unsigned int));
8596 }
8597 else
8598 {
8599 shndx_pool_size = shndx_pool_used + nshndx;
8600 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
8601 sizeof (unsigned int));
8602 }
8603}
8604
8605static void
8606add_shndx_to_cu_tu_entry (unsigned int shndx)
8607{
8608 if (shndx_pool_used >= shndx_pool_size)
8609 {
8610 error (_("Internal error: out of space in the shndx pool.\n"));
8611 return;
8612 }
8613 shndx_pool [shndx_pool_used++] = shndx;
8614}
8615
8616static void
8617end_cu_tu_entry (void)
8618{
8619 if (shndx_pool_used >= shndx_pool_size)
8620 {
8621 error (_("Internal error: out of space in the shndx pool.\n"));
8622 return;
8623 }
8624 shndx_pool [shndx_pool_used++] = 0;
8625}
8626
341f9135
CC
8627/* Return the short name of a DWARF section given by a DW_SECT enumerator. */
8628
8629static const char *
8630get_DW_SECT_short_name (unsigned int dw_sect)
8631{
8632 static char buf[16];
8633
8634 switch (dw_sect)
8635 {
8636 case DW_SECT_INFO:
8637 return "info";
8638 case DW_SECT_TYPES:
8639 return "types";
8640 case DW_SECT_ABBREV:
8641 return "abbrev";
8642 case DW_SECT_LINE:
8643 return "line";
8644 case DW_SECT_LOC:
8645 return "loc";
8646 case DW_SECT_STR_OFFSETS:
8647 return "str_off";
8648 case DW_SECT_MACINFO:
8649 return "macinfo";
8650 case DW_SECT_MACRO:
8651 return "macro";
8652 default:
b4eb7656 8653 break;
341f9135
CC
8654 }
8655
8656 snprintf (buf, sizeof (buf), "%d", dw_sect);
8657 return buf;
8658}
8659
8660/* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
8661 These sections are extensions for Fission.
8662 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
657d0d47
CC
8663
8664static int
8665process_cu_tu_index (struct dwarf_section *section, int do_display)
8666{
8667 unsigned char *phdr = section->start;
8668 unsigned char *limit = phdr + section->size;
8669 unsigned char *phash;
8670 unsigned char *pindex;
8671 unsigned char *ppool;
8672 unsigned int version;
341f9135 8673 unsigned int ncols = 0;
657d0d47
CC
8674 unsigned int nused;
8675 unsigned int nslots;
8676 unsigned int i;
341f9135
CC
8677 unsigned int j;
8678 dwarf_vma signature_high;
8679 dwarf_vma signature_low;
8680 char buf[64];
657d0d47 8681
6937bb54
NC
8682 /* PR 17512: file: 002-168123-0.004. */
8683 if (phdr == NULL)
8684 {
8685 warn (_("Section %s is empty\n"), section->name);
8686 return 0;
8687 }
8688 /* PR 17512: file: 002-376-0.004. */
8689 if (section->size < 24)
8690 {
72c61a0d 8691 warn (_("Section %s is too small to contain a CU/TU header\n"),
6937bb54
NC
8692 section->name);
8693 return 0;
8694 }
8695
8696 SAFE_BYTE_GET (version, phdr, 4, limit);
341f9135 8697 if (version >= 2)
6937bb54
NC
8698 SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
8699 SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
8700 SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
8701
657d0d47
CC
8702 phash = phdr + 16;
8703 pindex = phash + nslots * 8;
8704 ppool = pindex + nslots * 4;
8705
57028622 8706 /* PR 17531: file: 45d69832. */
03a91817 8707 if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0))
57028622
NC
8708 {
8709 warn (_("Section %s is too small for %d slots\n"),
8710 section->name, nslots);
8711 return 0;
8712 }
8713
657d0d47
CC
8714 if (do_display)
8715 {
8716 printf (_("Contents of the %s section:\n\n"), section->name);
8717 printf (_(" Version: %d\n"), version);
341f9135
CC
8718 if (version >= 2)
8719 printf (_(" Number of columns: %d\n"), ncols);
657d0d47
CC
8720 printf (_(" Number of used entries: %d\n"), nused);
8721 printf (_(" Number of slots: %d\n\n"), nslots);
8722 }
8723
03a91817 8724 if (ppool > limit || ppool < phdr)
657d0d47
CC
8725 {
8726 warn (_("Section %s too small for %d hash table entries\n"),
8727 section->name, nslots);
8728 return 0;
8729 }
8730
341f9135 8731 if (version == 1)
657d0d47 8732 {
341f9135
CC
8733 if (!do_display)
8734 prealloc_cu_tu_list ((limit - ppool) / 4);
8735 for (i = 0; i < nslots; i++)
657d0d47 8736 {
341f9135
CC
8737 unsigned char *shndx_list;
8738 unsigned int shndx;
8739
6937bb54 8740 SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
341f9135 8741 if (signature_high != 0 || signature_low != 0)
657d0d47 8742 {
6937bb54 8743 SAFE_BYTE_GET (j, pindex, 4, limit);
341f9135 8744 shndx_list = ppool + j * 4;
f3853b34
NC
8745 /* PR 17531: file: 705e010d. */
8746 if (shndx_list < ppool)
8747 {
8748 warn (_("Section index pool located before start of section\n"));
8749 return 0;
8750 }
8751
341f9135
CC
8752 if (do_display)
8753 printf (_(" [%3d] Signature: 0x%s Sections: "),
8754 i, dwarf_vmatoa64 (signature_high, signature_low,
8755 buf, sizeof (buf)));
8756 for (;;)
657d0d47 8757 {
341f9135
CC
8758 if (shndx_list >= limit)
8759 {
8760 warn (_("Section %s too small for shndx pool\n"),
8761 section->name);
8762 return 0;
8763 }
6937bb54 8764 SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
341f9135
CC
8765 if (shndx == 0)
8766 break;
8767 if (do_display)
8768 printf (" %d", shndx);
8769 else
8770 add_shndx_to_cu_tu_entry (shndx);
8771 shndx_list += 4;
657d0d47 8772 }
657d0d47 8773 if (do_display)
341f9135 8774 printf ("\n");
657d0d47 8775 else
341f9135
CC
8776 end_cu_tu_entry ();
8777 }
8778 phash += 8;
8779 pindex += 4;
8780 }
8781 }
8782 else if (version == 2)
8783 {
8784 unsigned int val;
8785 unsigned int dw_sect;
8786 unsigned char *ph = phash;
8787 unsigned char *pi = pindex;
8788 unsigned char *poffsets = ppool + ncols * 4;
8789 unsigned char *psizes = poffsets + nused * ncols * 4;
8790 unsigned char *pend = psizes + nused * ncols * 4;
8791 bfd_boolean is_tu_index;
8792 struct cu_tu_set *this_set = NULL;
8793 unsigned int row;
8794 unsigned char *prow;
8795
8796 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
8797
362beea4 8798 /* PR 17531: file: 0dd159bf.
b4eb7656 8799 Check for wraparound with an overlarge ncols value. */
c8071705 8800 if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols)
362beea4
NC
8801 {
8802 warn (_("Overlarge number of columns: %x\n"), ncols);
8803 return 0;
8804 }
8805
341f9135
CC
8806 if (pend > limit)
8807 {
8808 warn (_("Section %s too small for offset and size tables\n"),
8809 section->name);
8810 return 0;
8811 }
8812
8813 if (do_display)
8814 {
8815 printf (_(" Offset table\n"));
8816 printf (" slot %-16s ",
8817 is_tu_index ? _("signature") : _("dwo_id"));
8818 }
8819 else
8820 {
8821 if (is_tu_index)
8822 {
8823 tu_count = nused;
72c61a0d 8824 tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
341f9135 8825 this_set = tu_sets;
657d0d47 8826 }
657d0d47 8827 else
341f9135
CC
8828 {
8829 cu_count = nused;
72c61a0d 8830 cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
341f9135
CC
8831 this_set = cu_sets;
8832 }
8833 }
6937bb54 8834
341f9135
CC
8835 if (do_display)
8836 {
8837 for (j = 0; j < ncols; j++)
8838 {
6937bb54 8839 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
341f9135
CC
8840 printf (" %8s", get_DW_SECT_short_name (dw_sect));
8841 }
8842 printf ("\n");
8843 }
6937bb54 8844
341f9135
CC
8845 for (i = 0; i < nslots; i++)
8846 {
6937bb54
NC
8847 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
8848
8849 SAFE_BYTE_GET (row, pi, 4, limit);
341f9135
CC
8850 if (row != 0)
8851 {
591f7597 8852 /* PR 17531: file: a05f6ab3. */
ef77750e 8853 if (row > nused)
591f7597
NC
8854 {
8855 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
8856 row, nused);
8857 return 0;
8858 }
8859
341f9135
CC
8860 if (!do_display)
8861 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
6937bb54 8862
341f9135 8863 prow = poffsets + (row - 1) * ncols * 4;
ffc0f143
NC
8864 /* PR 17531: file: b8ce60a8. */
8865 if (prow < poffsets || prow > limit)
8866 {
8867 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
8868 row, ncols);
8869 return 0;
8870 }
3aade688 8871
341f9135
CC
8872 if (do_display)
8873 printf (_(" [%3d] 0x%s"),
8874 i, dwarf_vmatoa64 (signature_high, signature_low,
8875 buf, sizeof (buf)));
8876 for (j = 0; j < ncols; j++)
8877 {
6937bb54 8878 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
341f9135
CC
8879 if (do_display)
8880 printf (" %8d", val);
8881 else
8882 {
6937bb54 8883 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
82b1b41b
NC
8884
8885 /* PR 17531: file: 10796eb3. */
8886 if (dw_sect >= DW_SECT_MAX)
8887 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
8888 else
8889 this_set [row - 1].section_offsets [dw_sect] = val;
341f9135
CC
8890 }
8891 }
6937bb54 8892
341f9135
CC
8893 if (do_display)
8894 printf ("\n");
8895 }
8896 ph += 8;
8897 pi += 4;
8898 }
8899
8900 ph = phash;
8901 pi = pindex;
8902 if (do_display)
b4eb7656 8903 {
341f9135
CC
8904 printf ("\n");
8905 printf (_(" Size table\n"));
8906 printf (" slot %-16s ",
8907 is_tu_index ? _("signature") : _("dwo_id"));
b4eb7656 8908 }
6937bb54 8909
341f9135
CC
8910 for (j = 0; j < ncols; j++)
8911 {
6937bb54 8912 SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
341f9135
CC
8913 if (do_display)
8914 printf (" %8s", get_DW_SECT_short_name (val));
8915 }
6937bb54 8916
341f9135
CC
8917 if (do_display)
8918 printf ("\n");
6937bb54 8919
341f9135
CC
8920 for (i = 0; i < nslots; i++)
8921 {
6937bb54
NC
8922 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
8923
8924 SAFE_BYTE_GET (row, pi, 4, limit);
341f9135
CC
8925 if (row != 0)
8926 {
8927 prow = psizes + (row - 1) * ncols * 4;
6937bb54 8928
341f9135
CC
8929 if (do_display)
8930 printf (_(" [%3d] 0x%s"),
8931 i, dwarf_vmatoa64 (signature_high, signature_low,
8932 buf, sizeof (buf)));
6937bb54 8933
341f9135
CC
8934 for (j = 0; j < ncols; j++)
8935 {
6937bb54 8936 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
341f9135
CC
8937 if (do_display)
8938 printf (" %8d", val);
8939 else
8940 {
6937bb54 8941 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
82b1b41b
NC
8942 if (dw_sect >= DW_SECT_MAX)
8943 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
8944 else
341f9135
CC
8945 this_set [row - 1].section_sizes [dw_sect] = val;
8946 }
8947 }
6937bb54 8948
341f9135
CC
8949 if (do_display)
8950 printf ("\n");
8951 }
6937bb54 8952
341f9135
CC
8953 ph += 8;
8954 pi += 4;
657d0d47 8955 }
657d0d47 8956 }
341f9135 8957 else if (do_display)
6937bb54 8958 printf (_(" Unsupported version (%d)\n"), version);
657d0d47
CC
8959
8960 if (do_display)
8961 printf ("\n");
8962
8963 return 1;
8964}
8965
8966/* Load the CU and TU indexes if present. This will build a list of
8967 section sets that we can use to associate a .debug_info.dwo section
8968 with its associated .debug_abbrev.dwo section in a .dwp file. */
8969
43a444f9 8970static bfd_boolean
657d0d47
CC
8971load_cu_tu_indexes (void *file)
8972{
43a444f9
NC
8973 static int cu_tu_indexes_read = -1; /* Tri-state variable. */
8974
657d0d47
CC
8975 /* If we have already loaded (or tried to load) the CU and TU indexes
8976 then do not bother to repeat the task. */
43a444f9
NC
8977 if (cu_tu_indexes_read == -1)
8978 {
8979 cu_tu_indexes_read = TRUE;
8980
8981 if (load_debug_section (dwp_cu_index, file))
8982 if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0))
8983 cu_tu_indexes_read = FALSE;
8984
8985 if (load_debug_section (dwp_tu_index, file))
8986 if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0))
8987 cu_tu_indexes_read = FALSE;
8988 }
657d0d47 8989
43a444f9 8990 return (bfd_boolean) cu_tu_indexes_read;
657d0d47
CC
8991}
8992
8993/* Find the set of sections that includes section SHNDX. */
8994
8995unsigned int *
8996find_cu_tu_set (void *file, unsigned int shndx)
8997{
8998 unsigned int i;
8999
43a444f9
NC
9000 if (! load_cu_tu_indexes (file))
9001 return NULL;
657d0d47
CC
9002
9003 /* Find SHNDX in the shndx pool. */
9004 for (i = 0; i < shndx_pool_used; i++)
9005 if (shndx_pool [i] == shndx)
9006 break;
9007
9008 if (i >= shndx_pool_used)
9009 return NULL;
9010
9011 /* Now backup to find the first entry in the set. */
9012 while (i > 0 && shndx_pool [i - 1] != 0)
9013 i--;
9014
9015 return shndx_pool + i;
9016}
9017
9018/* Display a .debug_cu_index or .debug_tu_index section. */
9019
9020static int
9021display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
9022{
9023 return process_cu_tu_index (section, 1);
9024}
9025
19e6b90e
L
9026static int
9027display_debug_not_supported (struct dwarf_section *section,
9028 void *file ATTRIBUTE_UNUSED)
9029{
9030 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9031 section->name);
9032
9033 return 1;
9034}
9035
1306a742
NC
9036/* Like malloc, but takes two parameters like calloc.
9037 Verifies that the first parameter is not too large.
82b1b41b 9038 Note: does *not* initialise the allocated memory to zero. */
19e6b90e
L
9039void *
9040cmalloc (size_t nmemb, size_t size)
9041{
9042 /* Check for overflow. */
9043 if (nmemb >= ~(size_t) 0 / size)
9044 return NULL;
82b1b41b
NC
9045
9046 return xmalloc (nmemb * size);
19e6b90e
L
9047}
9048
1306a742
NC
9049/* Like xmalloc, but takes two parameters like calloc.
9050 Verifies that the first parameter is not too large.
9051 Note: does *not* initialise the allocated memory to zero. */
72c61a0d 9052void *
1306a742 9053xcmalloc (size_t nmemb, size_t size)
72c61a0d
NC
9054{
9055 /* Check for overflow. */
9056 if (nmemb >= ~(size_t) 0 / size)
8490fb40
NC
9057 {
9058 fprintf (stderr,
9059 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
9060 (long) nmemb);
9061 xexit (1);
9062 }
72c61a0d 9063
1306a742 9064 return xmalloc (nmemb * size);
72c61a0d
NC
9065}
9066
1306a742
NC
9067/* Like xrealloc, but takes three parameters.
9068 Verifies that the second parameter is not too large.
9069 Note: does *not* initialise any new memory to zero. */
19e6b90e 9070void *
1306a742 9071xcrealloc (void *ptr, size_t nmemb, size_t size)
19e6b90e
L
9072{
9073 /* Check for overflow. */
9074 if (nmemb >= ~(size_t) 0 / size)
8490fb40
NC
9075 {
9076 fprintf (stderr,
9077 _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
9078 (long) nmemb);
9079 xexit (1);
9080 }
82b1b41b 9081
1306a742 9082 return xrealloc (ptr, nmemb * size);
19e6b90e
L
9083}
9084
1306a742 9085/* Like xcalloc, but verifies that the first parameter is not too large. */
19e6b90e 9086void *
1306a742 9087xcalloc2 (size_t nmemb, size_t size)
19e6b90e
L
9088{
9089 /* Check for overflow. */
9090 if (nmemb >= ~(size_t) 0 / size)
8490fb40
NC
9091 {
9092 fprintf (stderr,
9093 _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
9094 (long) nmemb);
9095 xexit (1);
9096 }
82b1b41b 9097
1306a742 9098 return xcalloc (nmemb, size);
19e6b90e
L
9099}
9100
19e6b90e
L
9101void
9102free_debug_memory (void)
9103{
3f5e193b 9104 unsigned int i;
19e6b90e
L
9105
9106 free_abbrevs ();
9107
9108 for (i = 0; i < max; i++)
3f5e193b 9109 free_debug_section ((enum dwarf_section_display_enum) i);
19e6b90e 9110
cc86f28f 9111 if (debug_information != NULL)
19e6b90e 9112 {
cc86f28f 9113 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
19e6b90e 9114 {
cc86f28f 9115 for (i = 0; i < num_debug_info_entries; i++)
19e6b90e 9116 {
cc86f28f
NC
9117 if (!debug_information [i].max_loc_offsets)
9118 {
9119 free (debug_information [i].loc_offsets);
9120 free (debug_information [i].have_frame_base);
9121 }
9122 if (!debug_information [i].max_range_lists)
9123 free (debug_information [i].range_lists);
19e6b90e 9124 }
19e6b90e
L
9125 }
9126 free (debug_information);
9127 debug_information = NULL;
82b1b41b 9128 alloc_num_debug_info_entries = num_debug_info_entries = 0;
19e6b90e 9129 }
19e6b90e
L
9130}
9131
4cb93e3b
TG
9132void
9133dwarf_select_sections_by_names (const char *names)
9134{
9135 typedef struct
9136 {
9137 const char * option;
9138 int * variable;
f9f0e732 9139 int val;
4cb93e3b
TG
9140 }
9141 debug_dump_long_opts;
9142
9143 static const debug_dump_long_opts opts_table [] =
9144 {
9145 /* Please keep this table alpha- sorted. */
9146 { "Ranges", & do_debug_ranges, 1 },
9147 { "abbrev", & do_debug_abbrevs, 1 },
657d0d47 9148 { "addr", & do_debug_addr, 1 },
4cb93e3b 9149 { "aranges", & do_debug_aranges, 1 },
657d0d47
CC
9150 { "cu_index", & do_debug_cu_index, 1 },
9151 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
4cb93e3b
TG
9152 { "frames", & do_debug_frames, 1 },
9153 { "frames-interp", & do_debug_frames_interp, 1 },
657d0d47
CC
9154 /* The special .gdb_index section. */
9155 { "gdb_index", & do_gdb_index, 1 },
4cb93e3b
TG
9156 { "info", & do_debug_info, 1 },
9157 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
4cb93e3b
TG
9158 { "loc", & do_debug_loc, 1 },
9159 { "macro", & do_debug_macinfo, 1 },
9160 { "pubnames", & do_debug_pubnames, 1 },
357da287 9161 { "pubtypes", & do_debug_pubtypes, 1 },
222c2bf0 9162 /* This entry is for compatibility
4cb93e3b
TG
9163 with earlier versions of readelf. */
9164 { "ranges", & do_debug_aranges, 1 },
657d0d47 9165 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
4cb93e3b 9166 { "str", & do_debug_str, 1 },
6f875884
TG
9167 /* These trace_* sections are used by Itanium VMS. */
9168 { "trace_abbrev", & do_trace_abbrevs, 1 },
9169 { "trace_aranges", & do_trace_aranges, 1 },
9170 { "trace_info", & do_trace_info, 1 },
4cb93e3b
TG
9171 { NULL, NULL, 0 }
9172 };
9173
9174 const char *p;
467c65bc 9175
4cb93e3b
TG
9176 p = names;
9177 while (*p)
9178 {
9179 const debug_dump_long_opts * entry;
467c65bc 9180
4cb93e3b
TG
9181 for (entry = opts_table; entry->option; entry++)
9182 {
9183 size_t len = strlen (entry->option);
467c65bc 9184
4cb93e3b
TG
9185 if (strncmp (p, entry->option, len) == 0
9186 && (p[len] == ',' || p[len] == '\0'))
9187 {
9188 * entry->variable |= entry->val;
467c65bc 9189
4cb93e3b
TG
9190 /* The --debug-dump=frames-interp option also
9191 enables the --debug-dump=frames option. */
9192 if (do_debug_frames_interp)
9193 do_debug_frames = 1;
9194
9195 p += len;
9196 break;
9197 }
9198 }
467c65bc 9199
4cb93e3b
TG
9200 if (entry->option == NULL)
9201 {
9202 warn (_("Unrecognized debug option '%s'\n"), p);
9203 p = strchr (p, ',');
9204 if (p == NULL)
9205 break;
9206 }
467c65bc 9207
4cb93e3b
TG
9208 if (*p == ',')
9209 p++;
9210 }
9211}
9212
9213void
9214dwarf_select_sections_by_letters (const char *letters)
9215{
91d6fa6a 9216 unsigned int lindex = 0;
4cb93e3b 9217
91d6fa6a
NC
9218 while (letters[lindex])
9219 switch (letters[lindex++])
4cb93e3b
TG
9220 {
9221 case 'i':
9222 do_debug_info = 1;
9223 break;
467c65bc 9224
4cb93e3b
TG
9225 case 'a':
9226 do_debug_abbrevs = 1;
9227 break;
467c65bc 9228
4cb93e3b
TG
9229 case 'l':
9230 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
9231 break;
467c65bc 9232
4cb93e3b
TG
9233 case 'L':
9234 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
9235 break;
467c65bc 9236
4cb93e3b
TG
9237 case 'p':
9238 do_debug_pubnames = 1;
9239 break;
467c65bc 9240
f9f0e732
NC
9241 case 't':
9242 do_debug_pubtypes = 1;
9243 break;
467c65bc 9244
4cb93e3b
TG
9245 case 'r':
9246 do_debug_aranges = 1;
9247 break;
467c65bc 9248
4cb93e3b
TG
9249 case 'R':
9250 do_debug_ranges = 1;
9251 break;
467c65bc 9252
4cb93e3b
TG
9253 case 'F':
9254 do_debug_frames_interp = 1;
1a0670f3 9255 /* Fall through. */
4cb93e3b
TG
9256 case 'f':
9257 do_debug_frames = 1;
9258 break;
467c65bc 9259
4cb93e3b
TG
9260 case 'm':
9261 do_debug_macinfo = 1;
9262 break;
467c65bc 9263
4cb93e3b
TG
9264 case 's':
9265 do_debug_str = 1;
9266 break;
467c65bc 9267
4cb93e3b
TG
9268 case 'o':
9269 do_debug_loc = 1;
9270 break;
467c65bc 9271
4cb93e3b 9272 default:
7cc78d07 9273 warn (_("Unrecognized debug option '%s'\n"), letters);
4cb93e3b
TG
9274 break;
9275 }
9276}
9277
9278void
9279dwarf_select_sections_all (void)
9280{
9281 do_debug_info = 1;
9282 do_debug_abbrevs = 1;
9283 do_debug_lines = FLAG_DEBUG_LINES_RAW;
9284 do_debug_pubnames = 1;
f9f0e732 9285 do_debug_pubtypes = 1;
4cb93e3b
TG
9286 do_debug_aranges = 1;
9287 do_debug_ranges = 1;
9288 do_debug_frames = 1;
9289 do_debug_macinfo = 1;
9290 do_debug_str = 1;
9291 do_debug_loc = 1;
5bbdf3d5 9292 do_gdb_index = 1;
6f875884
TG
9293 do_trace_info = 1;
9294 do_trace_abbrevs = 1;
9295 do_trace_aranges = 1;
657d0d47
CC
9296 do_debug_addr = 1;
9297 do_debug_cu_index = 1;
4cb93e3b
TG
9298}
9299
19e6b90e
L
9300struct dwarf_section_display debug_displays[] =
9301{
d1c4b12b
NC
9302 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9303 display_debug_abbrev, &do_debug_abbrevs, FALSE },
9304 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9305 display_debug_aranges, &do_debug_aranges, TRUE },
9306 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9307 display_debug_frames, &do_debug_frames, TRUE },
9308 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
9309 display_debug_info, &do_debug_info, TRUE },
9310 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9311 display_debug_lines, &do_debug_lines, TRUE },
9312 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9313 display_debug_pubnames, &do_debug_pubnames, FALSE },
9314 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9315 display_debug_gnu_pubnames, &do_debug_pubnames, FALSE },
9316 { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9317 display_debug_frames, &do_debug_frames, TRUE },
9318 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9319 display_debug_macinfo, &do_debug_macinfo, FALSE },
9320 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9321 display_debug_macro, &do_debug_macinfo, TRUE },
9322 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9323 display_debug_str, &do_debug_str, FALSE },
77145576
JK
9324 { { ".debug_line_str", ".zdebug_line_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9325 display_debug_str, &do_debug_str, FALSE },
d1c4b12b
NC
9326 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9327 display_debug_loc, &do_debug_loc, TRUE },
77145576
JK
9328 { { ".debug_loclists", ".zdebug_loclists", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9329 display_debug_loc, &do_debug_loc, TRUE },
d1c4b12b
NC
9330 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9331 display_debug_pubnames, &do_debug_pubtypes, FALSE },
9332 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9333 display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE },
9334 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9335 display_debug_ranges, &do_debug_ranges, TRUE },
77145576
JK
9336 { { ".debug_rnglists", ".zdebug_rnglists", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9337 display_debug_ranges, &do_debug_ranges, TRUE },
d1c4b12b
NC
9338 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9339 display_debug_not_supported, NULL, FALSE },
9340 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9341 display_debug_not_supported, NULL, FALSE },
9342 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
9343 display_debug_types, &do_debug_info, TRUE },
9344 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9345 display_debug_not_supported, NULL, FALSE },
9346 { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9347 display_gdb_index, &do_gdb_index, FALSE },
61364358
JK
9348 { { ".debug_names", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9349 display_debug_names, &do_gdb_index, FALSE },
d1c4b12b
NC
9350 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL, 0, NULL },
9351 display_trace_info, &do_trace_info, TRUE },
9352 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9353 display_debug_abbrev, &do_trace_abbrevs, FALSE },
9354 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9355 display_debug_aranges, &do_trace_aranges, FALSE },
9356 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
9357 display_debug_info, &do_debug_info, TRUE },
9358 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9359 display_debug_abbrev, &do_debug_abbrevs, FALSE },
9360 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
9361 display_debug_types, &do_debug_info, TRUE },
9362 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9363 display_debug_lines, &do_debug_lines, TRUE },
9364 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9365 display_debug_loc, &do_debug_loc, TRUE },
9366 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9367 display_debug_macro, &do_debug_macinfo, TRUE },
9368 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9369 display_debug_macinfo, &do_debug_macinfo, FALSE },
9370 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9371 display_debug_str, &do_debug_str, TRUE },
9372 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9373 display_debug_str_offsets, NULL, FALSE },
9374 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9375 display_debug_str_offsets, NULL, FALSE },
9376 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9377 display_debug_addr, &do_debug_addr, TRUE },
9378 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9379 display_cu_index, &do_debug_cu_index, FALSE },
9380 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
9381 display_cu_index, &do_debug_cu_index, FALSE },
19e6b90e 9382};
b451e98a
JK
9383
9384/* A static assertion. */
9385extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1];
This page took 1.103511 seconds and 4 git commands to generate.