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