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