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