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