mep: define gdbarch_pc_regnum instead of gdbarch_write_pc.
[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
19e6b90e 2549static int
a262ae96
NC
2550display_debug_lines_raw (struct dwarf_section *section,
2551 unsigned char *data,
2552 unsigned char *end)
19e6b90e
L
2553{
2554 unsigned char *start = section->start;
19e6b90e 2555
a262ae96
NC
2556 printf (_("Raw dump of debug contents of section %s:\n\n"),
2557 section->name);
19e6b90e
L
2558
2559 while (data < end)
2560 {
91d6fa6a 2561 DWARF2_Internal_LineInfo linfo;
19e6b90e
L
2562 unsigned char *standard_opcodes;
2563 unsigned char *end_of_sequence;
2564 unsigned char *hdrptr;
6523721c 2565 unsigned long hdroff;
19e6b90e
L
2566 int initial_length_size;
2567 int offset_size;
2568 int i;
2569
2570 hdrptr = data;
6523721c 2571 hdroff = hdrptr - start;
19e6b90e
L
2572
2573 /* Check the length of the block. */
0c588247 2574 SAFE_BYTE_GET_AND_INC (linfo.li_length, hdrptr, 4, end);
19e6b90e 2575
91d6fa6a 2576 if (linfo.li_length == 0xffffffff)
19e6b90e
L
2577 {
2578 /* This section is 64-bit DWARF 3. */
0c588247 2579 SAFE_BYTE_GET_AND_INC (linfo.li_length, hdrptr, 8, end);
19e6b90e
L
2580 offset_size = 8;
2581 initial_length_size = 12;
2582 }
2583 else
2584 {
2585 offset_size = 4;
2586 initial_length_size = 4;
2587 }
2588
91d6fa6a 2589 if (linfo.li_length + initial_length_size > section->size)
19e6b90e
L
2590 {
2591 warn
cf13d699
NC
2592 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2593 section->name);
19e6b90e
L
2594 return 0;
2595 }
2596
2597 /* Check its version number. */
0c588247 2598 SAFE_BYTE_GET_AND_INC (linfo.li_version, hdrptr, 2, end);
932fd279
JJ
2599 if (linfo.li_version != 2
2600 && linfo.li_version != 3
2601 && linfo.li_version != 4)
19e6b90e 2602 {
932fd279 2603 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
19e6b90e
L
2604 return 0;
2605 }
2606
0c588247
NC
2607 SAFE_BYTE_GET_AND_INC (linfo.li_prologue_length, hdrptr, offset_size, end);
2608 SAFE_BYTE_GET_AND_INC (linfo.li_min_insn_length, hdrptr, 1, end);
2609
a233b20c
JJ
2610 if (linfo.li_version >= 4)
2611 {
0c588247
NC
2612 SAFE_BYTE_GET_AND_INC (linfo.li_max_ops_per_insn, hdrptr, 1, end);
2613
a233b20c
JJ
2614 if (linfo.li_max_ops_per_insn == 0)
2615 {
2616 warn (_("Invalid maximum operations per insn.\n"));
2617 return 0;
2618 }
2619 }
2620 else
2621 linfo.li_max_ops_per_insn = 1;
0c588247
NC
2622
2623 SAFE_BYTE_GET_AND_INC (linfo.li_default_is_stmt, hdrptr, 1, end);
2624 SAFE_BYTE_GET_AND_INC (linfo.li_line_base, hdrptr, 1, end);
2625 SAFE_BYTE_GET_AND_INC (linfo.li_line_range, hdrptr, 1, end);
2626 SAFE_BYTE_GET_AND_INC (linfo.li_opcode_base, hdrptr, 1, end);
19e6b90e
L
2627
2628 /* Sign extend the line base field. */
91d6fa6a
NC
2629 linfo.li_line_base <<= 24;
2630 linfo.li_line_base >>= 24;
19e6b90e 2631
6523721c 2632 printf (_(" Offset: 0x%lx\n"), hdroff);
47704ddf 2633 printf (_(" Length: %ld\n"), (long) linfo.li_length);
91d6fa6a
NC
2634 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2635 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2636 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
a233b20c
JJ
2637 if (linfo.li_version >= 4)
2638 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
91d6fa6a
NC
2639 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2640 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2641 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2642 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
19e6b90e 2643
91d6fa6a 2644 end_of_sequence = data + linfo.li_length + initial_length_size;
19e6b90e 2645
91d6fa6a 2646 reset_state_machine (linfo.li_default_is_stmt);
19e6b90e
L
2647
2648 /* Display the contents of the Opcodes table. */
2649 standard_opcodes = hdrptr;
2650
2651 printf (_("\n Opcodes:\n"));
2652
91d6fa6a 2653 for (i = 1; i < linfo.li_opcode_base; i++)
19e6b90e
L
2654 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2655
2656 /* Display the contents of the Directory table. */
91d6fa6a 2657 data = standard_opcodes + linfo.li_opcode_base - 1;
19e6b90e
L
2658
2659 if (*data == 0)
2660 printf (_("\n The Directory Table is empty.\n"));
2661 else
2662 {
2663 printf (_("\n The Directory Table:\n"));
2664
2665 while (*data != 0)
2666 {
cc5914eb 2667 printf (" %s\n", data);
19e6b90e 2668
0c588247 2669 data += strnlen ((char *) data, end - data) + 1;
19e6b90e
L
2670 }
2671 }
2672
2673 /* Skip the NUL at the end of the table. */
2674 data++;
2675
2676 /* Display the contents of the File Name table. */
2677 if (*data == 0)
2678 printf (_("\n The File Name Table is empty.\n"));
2679 else
2680 {
2681 printf (_("\n The File Name Table:\n"));
2682 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2683
2684 while (*data != 0)
2685 {
2686 unsigned char *name;
2687 unsigned int bytes_read;
2688
cc5914eb 2689 printf (" %d\t", ++state_machine_regs.last_file_entry);
19e6b90e 2690 name = data;
0c588247 2691 data += strnlen ((char *) data, end - data) + 1;
19e6b90e 2692
467c65bc 2693 printf ("%s\t",
f6f0e17b 2694 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
19e6b90e 2695 data += bytes_read;
467c65bc 2696 printf ("%s\t",
f6f0e17b 2697 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
19e6b90e 2698 data += bytes_read;
467c65bc 2699 printf ("%s\t",
f6f0e17b 2700 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
19e6b90e 2701 data += bytes_read;
cc5914eb 2702 printf ("%s\n", name);
f6f0e17b
NC
2703
2704 if (data == end)
2705 {
2706 warn (_("Corrupt file name table entry\n"));
2707 break;
2708 }
19e6b90e
L
2709 }
2710 }
2711
2712 /* Skip the NUL at the end of the table. */
2713 data++;
2714
2715 /* Now display the statements. */
2716 printf (_("\n Line Number Statements:\n"));
2717
2718 while (data < end_of_sequence)
2719 {
2720 unsigned char op_code;
467c65bc
NC
2721 dwarf_signed_vma adv;
2722 dwarf_vma uladv;
19e6b90e
L
2723 unsigned int bytes_read;
2724
2725 op_code = *data++;
2726
91d6fa6a 2727 if (op_code >= linfo.li_opcode_base)
19e6b90e 2728 {
91d6fa6a 2729 op_code -= linfo.li_opcode_base;
a233b20c
JJ
2730 uladv = (op_code / linfo.li_line_range);
2731 if (linfo.li_max_ops_per_insn == 1)
2732 {
2733 uladv *= linfo.li_min_insn_length;
2734 state_machine_regs.address += uladv;
467c65bc
NC
2735 printf (_(" Special opcode %d: "
2736 "advance Address by %s to 0x%s"),
2737 op_code, dwarf_vmatoa ("u", uladv),
2738 dwarf_vmatoa ("x", state_machine_regs.address));
a233b20c
JJ
2739 }
2740 else
2741 {
2742 state_machine_regs.address
2743 += ((state_machine_regs.op_index + uladv)
2744 / linfo.li_max_ops_per_insn)
2745 * linfo.li_min_insn_length;
2746 state_machine_regs.op_index
2747 = (state_machine_regs.op_index + uladv)
2748 % linfo.li_max_ops_per_insn;
467c65bc
NC
2749 printf (_(" Special opcode %d: "
2750 "advance Address by %s to 0x%s[%d]"),
2751 op_code, dwarf_vmatoa ("u", uladv),
2752 dwarf_vmatoa ("x", state_machine_regs.address),
a233b20c
JJ
2753 state_machine_regs.op_index);
2754 }
91d6fa6a 2755 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
19e6b90e 2756 state_machine_regs.line += adv;
467c65bc
NC
2757 printf (_(" and Line by %s to %d\n"),
2758 dwarf_vmatoa ("d", adv), state_machine_regs.line);
19e6b90e
L
2759 }
2760 else switch (op_code)
2761 {
2762 case DW_LNS_extended_op:
f6f0e17b 2763 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
19e6b90e
L
2764 break;
2765
2766 case DW_LNS_copy:
2767 printf (_(" Copy\n"));
2768 break;
2769
2770 case DW_LNS_advance_pc:
f6f0e17b 2771 uladv = read_uleb128 (data, & bytes_read, end);
19e6b90e 2772 data += bytes_read;
a233b20c
JJ
2773 if (linfo.li_max_ops_per_insn == 1)
2774 {
2775 uladv *= linfo.li_min_insn_length;
2776 state_machine_regs.address += uladv;
467c65bc
NC
2777 printf (_(" Advance PC by %s to 0x%s\n"),
2778 dwarf_vmatoa ("u", uladv),
2779 dwarf_vmatoa ("x", state_machine_regs.address));
a233b20c
JJ
2780 }
2781 else
2782 {
2783 state_machine_regs.address
2784 += ((state_machine_regs.op_index + uladv)
2785 / linfo.li_max_ops_per_insn)
2786 * linfo.li_min_insn_length;
2787 state_machine_regs.op_index
2788 = (state_machine_regs.op_index + uladv)
2789 % linfo.li_max_ops_per_insn;
467c65bc
NC
2790 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2791 dwarf_vmatoa ("u", uladv),
2792 dwarf_vmatoa ("x", state_machine_regs.address),
a233b20c
JJ
2793 state_machine_regs.op_index);
2794 }
19e6b90e
L
2795 break;
2796
2797 case DW_LNS_advance_line:
f6f0e17b 2798 adv = read_sleb128 (data, & bytes_read, end);
19e6b90e
L
2799 data += bytes_read;
2800 state_machine_regs.line += adv;
467c65bc
NC
2801 printf (_(" Advance Line by %s to %d\n"),
2802 dwarf_vmatoa ("d", adv),
2803 state_machine_regs.line);
19e6b90e
L
2804 break;
2805
2806 case DW_LNS_set_file:
f6f0e17b 2807 adv = read_uleb128 (data, & bytes_read, end);
19e6b90e 2808 data += bytes_read;
467c65bc
NC
2809 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2810 dwarf_vmatoa ("d", adv));
19e6b90e
L
2811 state_machine_regs.file = adv;
2812 break;
2813
2814 case DW_LNS_set_column:
f6f0e17b 2815 uladv = read_uleb128 (data, & bytes_read, end);
19e6b90e 2816 data += bytes_read;
467c65bc
NC
2817 printf (_(" Set column to %s\n"),
2818 dwarf_vmatoa ("u", uladv));
19e6b90e
L
2819 state_machine_regs.column = uladv;
2820 break;
2821
2822 case DW_LNS_negate_stmt:
2823 adv = state_machine_regs.is_stmt;
2824 adv = ! adv;
467c65bc 2825 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
19e6b90e
L
2826 state_machine_regs.is_stmt = adv;
2827 break;
2828
2829 case DW_LNS_set_basic_block:
2830 printf (_(" Set basic block\n"));
2831 state_machine_regs.basic_block = 1;
2832 break;
2833
2834 case DW_LNS_const_add_pc:
a233b20c
JJ
2835 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2836 if (linfo.li_max_ops_per_insn)
2837 {
2838 uladv *= linfo.li_min_insn_length;
2839 state_machine_regs.address += uladv;
467c65bc
NC
2840 printf (_(" Advance PC by constant %s to 0x%s\n"),
2841 dwarf_vmatoa ("u", uladv),
2842 dwarf_vmatoa ("x", state_machine_regs.address));
a233b20c
JJ
2843 }
2844 else
2845 {
2846 state_machine_regs.address
2847 += ((state_machine_regs.op_index + uladv)
2848 / linfo.li_max_ops_per_insn)
2849 * linfo.li_min_insn_length;
2850 state_machine_regs.op_index
2851 = (state_machine_regs.op_index + uladv)
2852 % linfo.li_max_ops_per_insn;
467c65bc
NC
2853 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2854 dwarf_vmatoa ("u", uladv),
2855 dwarf_vmatoa ("x", state_machine_regs.address),
a233b20c
JJ
2856 state_machine_regs.op_index);
2857 }
19e6b90e
L
2858 break;
2859
2860 case DW_LNS_fixed_advance_pc:
0c588247 2861 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
19e6b90e 2862 state_machine_regs.address += uladv;
a233b20c 2863 state_machine_regs.op_index = 0;
467c65bc
NC
2864 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2865 dwarf_vmatoa ("u", uladv),
2866 dwarf_vmatoa ("x", state_machine_regs.address));
19e6b90e
L
2867 break;
2868
2869 case DW_LNS_set_prologue_end:
2870 printf (_(" Set prologue_end to true\n"));
2871 break;
2872
2873 case DW_LNS_set_epilogue_begin:
2874 printf (_(" Set epilogue_begin to true\n"));
2875 break;
2876
2877 case DW_LNS_set_isa:
f6f0e17b 2878 uladv = read_uleb128 (data, & bytes_read, end);
19e6b90e 2879 data += bytes_read;
467c65bc 2880 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
19e6b90e
L
2881 break;
2882
2883 default:
2884 printf (_(" Unknown opcode %d with operands: "), op_code);
2885
2886 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2887 {
f6f0e17b
NC
2888 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
2889 &bytes_read, end)),
19e6b90e
L
2890 i == 1 ? "" : ", ");
2891 data += bytes_read;
2892 }
2893 putchar ('\n');
2894 break;
2895 }
2896 }
2897 putchar ('\n');
2898 }
2899
2900 return 1;
2901}
2902
a262ae96
NC
2903typedef struct
2904{
467c65bc
NC
2905 unsigned char *name;
2906 unsigned int directory_index;
2907 unsigned int modification_date;
2908 unsigned int length;
a262ae96
NC
2909} File_Entry;
2910
2911/* Output a decoded representation of the .debug_line section. */
2912
2913static int
2914display_debug_lines_decoded (struct dwarf_section *section,
2915 unsigned char *data,
2916 unsigned char *end)
2917{
2918 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2919 section->name);
2920
2921 while (data < end)
2922 {
2923 /* This loop amounts to one iteration per compilation unit. */
91d6fa6a 2924 DWARF2_Internal_LineInfo linfo;
a262ae96
NC
2925 unsigned char *standard_opcodes;
2926 unsigned char *end_of_sequence;
2927 unsigned char *hdrptr;
2928 int initial_length_size;
2929 int offset_size;
2930 int i;
2931 File_Entry *file_table = NULL;
143a3db0 2932 unsigned int n_files = 0;
a262ae96 2933 unsigned char **directory_table = NULL;
143a3db0 2934 unsigned int n_directories = 0;
a262ae96
NC
2935
2936 hdrptr = data;
2937
2938 /* Extract information from the Line Number Program Header.
2939 (section 6.2.4 in the Dwarf3 doc). */
2940
2941 /* Get the length of this CU's line number information block. */
0c588247 2942 SAFE_BYTE_GET_AND_INC (linfo.li_length, hdrptr, 4, end);
a262ae96 2943
91d6fa6a 2944 if (linfo.li_length == 0xffffffff)
a262ae96
NC
2945 {
2946 /* This section is 64-bit DWARF 3. */
0c588247 2947 SAFE_BYTE_GET_AND_INC (linfo.li_length, hdrptr, 8, end);
a262ae96
NC
2948 offset_size = 8;
2949 initial_length_size = 12;
2950 }
2951 else
2952 {
2953 offset_size = 4;
2954 initial_length_size = 4;
2955 }
2956
91d6fa6a 2957 if (linfo.li_length + initial_length_size > section->size)
a262ae96
NC
2958 {
2959 warn (_("The line info appears to be corrupt - "
2960 "the section is too small\n"));
2961 return 0;
2962 }
2963
2964 /* Get this CU's Line Number Block version number. */
0c588247 2965 SAFE_BYTE_GET_AND_INC (linfo.li_version, hdrptr, 2, end);
932fd279
JJ
2966 if (linfo.li_version != 2
2967 && linfo.li_version != 3
2968 && linfo.li_version != 4)
a262ae96 2969 {
932fd279 2970 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
a262ae96
NC
2971 "supported.\n"));
2972 return 0;
2973 }
2974
0c588247
NC
2975 SAFE_BYTE_GET_AND_INC (linfo.li_prologue_length, hdrptr, offset_size, end);
2976 SAFE_BYTE_GET_AND_INC (linfo.li_min_insn_length, hdrptr, 1, end);
2977
a233b20c
JJ
2978 if (linfo.li_version >= 4)
2979 {
0c588247 2980 SAFE_BYTE_GET_AND_INC (linfo.li_max_ops_per_insn, hdrptr, 1, end);
a233b20c
JJ
2981 if (linfo.li_max_ops_per_insn == 0)
2982 {
2983 warn (_("Invalid maximum operations per insn.\n"));
2984 return 0;
2985 }
2986 }
2987 else
2988 linfo.li_max_ops_per_insn = 1;
0c588247
NC
2989
2990 SAFE_BYTE_GET_AND_INC (linfo.li_default_is_stmt, hdrptr, 1, end);
2991 SAFE_BYTE_GET_AND_INC (linfo.li_line_base, hdrptr, 1, end);
2992 SAFE_BYTE_GET_AND_INC (linfo.li_line_range, hdrptr, 1, end);
2993 SAFE_BYTE_GET_AND_INC (linfo.li_opcode_base, hdrptr, 1, end);
a262ae96
NC
2994
2995 /* Sign extend the line base field. */
91d6fa6a
NC
2996 linfo.li_line_base <<= 24;
2997 linfo.li_line_base >>= 24;
a262ae96
NC
2998
2999 /* Find the end of this CU's Line Number Information Block. */
91d6fa6a 3000 end_of_sequence = data + linfo.li_length + initial_length_size;
a262ae96 3001
91d6fa6a 3002 reset_state_machine (linfo.li_default_is_stmt);
a262ae96
NC
3003
3004 /* Save a pointer to the contents of the Opcodes table. */
3005 standard_opcodes = hdrptr;
3006
3007 /* Traverse the Directory table just to count entries. */
91d6fa6a 3008 data = standard_opcodes + linfo.li_opcode_base - 1;
a262ae96
NC
3009 if (*data != 0)
3010 {
a262ae96 3011 unsigned char *ptr_directory_table = data;
a262ae96
NC
3012
3013 while (*data != 0)
3014 {
0c588247 3015 data += strnlen ((char *) data, end - data) + 1;
a262ae96
NC
3016 n_directories++;
3017 }
3018
3019 /* Go through the directory table again to save the directories. */
3f5e193b
NC
3020 directory_table = (unsigned char **)
3021 xmalloc (n_directories * sizeof (unsigned char *));
a262ae96
NC
3022
3023 i = 0;
3024 while (*ptr_directory_table != 0)
3025 {
3026 directory_table[i] = ptr_directory_table;
0c588247
NC
3027 ptr_directory_table += strnlen ((char *) ptr_directory_table,
3028 ptr_directory_table - end) + 1;
a262ae96
NC
3029 i++;
3030 }
3031 }
3032 /* Skip the NUL at the end of the table. */
3033 data++;
3034
3035 /* Traverse the File Name table just to count the entries. */
3036 if (*data != 0)
3037 {
a262ae96 3038 unsigned char *ptr_file_name_table = data;
a262ae96
NC
3039
3040 while (*data != 0)
3041 {
3042 unsigned int bytes_read;
3043
3044 /* Skip Name, directory index, last modification time and length
3045 of file. */
0c588247 3046 data += strnlen ((char *) data, end - data) + 1;
f6f0e17b 3047 read_uleb128 (data, & bytes_read, end);
a262ae96 3048 data += bytes_read;
f6f0e17b 3049 read_uleb128 (data, & bytes_read, end);
a262ae96 3050 data += bytes_read;
f6f0e17b 3051 read_uleb128 (data, & bytes_read, end);
a262ae96
NC
3052 data += bytes_read;
3053
3054 n_files++;
3055 }
3056
3057 /* Go through the file table again to save the strings. */
3f5e193b 3058 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
a262ae96
NC
3059
3060 i = 0;
3061 while (*ptr_file_name_table != 0)
3062 {
3063 unsigned int bytes_read;
3064
3065 file_table[i].name = ptr_file_name_table;
0c588247
NC
3066 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
3067 end - ptr_file_name_table) + 1;
a262ae96
NC
3068
3069 /* We are not interested in directory, time or size. */
f6f0e17b
NC
3070 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
3071 & bytes_read, end);
a262ae96 3072 ptr_file_name_table += bytes_read;
f6f0e17b
NC
3073 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
3074 & bytes_read, end);
a262ae96 3075 ptr_file_name_table += bytes_read;
f6f0e17b 3076 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
a262ae96
NC
3077 ptr_file_name_table += bytes_read;
3078 i++;
3079 }
3080 i = 0;
3081
3082 /* Print the Compilation Unit's name and a header. */
3083 if (directory_table == NULL)
3084 {
3085 printf (_("CU: %s:\n"), file_table[0].name);
3086 printf (_("File name Line number Starting address\n"));
3087 }
3088 else
3089 {
4eee63bc
CD
3090 unsigned int ix = file_table[0].directory_index;
3091 const char *directory = ix ? (char *)directory_table[ix - 1] : ".";
0c588247 3092
4eee63bc
CD
3093 if (do_wide || strlen (directory) < 76)
3094 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
a262ae96 3095 else
cc5914eb
AM
3096 printf ("%s:\n", file_table[0].name);
3097
a262ae96
NC
3098 printf (_("File name Line number Starting address\n"));
3099 }
3100 }
3101
3102 /* Skip the NUL at the end of the table. */
3103 data++;
3104
3105 /* This loop iterates through the Dwarf Line Number Program. */
3106 while (data < end_of_sequence)
3107 {
3108 unsigned char op_code;
3109 int adv;
3110 unsigned long int uladv;
3111 unsigned int bytes_read;
3112 int is_special_opcode = 0;
3113
3114 op_code = *data++;
a262ae96 3115
91d6fa6a 3116 if (op_code >= linfo.li_opcode_base)
a262ae96 3117 {
91d6fa6a 3118 op_code -= linfo.li_opcode_base;
a233b20c
JJ
3119 uladv = (op_code / linfo.li_line_range);
3120 if (linfo.li_max_ops_per_insn == 1)
3121 {
3122 uladv *= linfo.li_min_insn_length;
3123 state_machine_regs.address += uladv;
3124 }
3125 else
3126 {
3127 state_machine_regs.address
3128 += ((state_machine_regs.op_index + uladv)
3129 / linfo.li_max_ops_per_insn)
3130 * linfo.li_min_insn_length;
3131 state_machine_regs.op_index
3132 = (state_machine_regs.op_index + uladv)
3133 % linfo.li_max_ops_per_insn;
3134 }
a262ae96 3135
91d6fa6a 3136 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
a262ae96
NC
3137 state_machine_regs.line += adv;
3138 is_special_opcode = 1;
3139 }
3140 else switch (op_code)
3141 {
3142 case DW_LNS_extended_op:
3143 {
3144 unsigned int ext_op_code_len;
a262ae96
NC
3145 unsigned char ext_op_code;
3146 unsigned char *op_code_data = data;
3147
f6f0e17b
NC
3148 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
3149 end_of_sequence);
a262ae96
NC
3150 op_code_data += bytes_read;
3151
3152 if (ext_op_code_len == 0)
3153 {
3154 warn (_("badly formed extended line op encountered!\n"));
3155 break;
3156 }
3157 ext_op_code_len += bytes_read;
3158 ext_op_code = *op_code_data++;
3159
3160 switch (ext_op_code)
3161 {
3162 case DW_LNE_end_sequence:
91d6fa6a 3163 reset_state_machine (linfo.li_default_is_stmt);
a262ae96
NC
3164 break;
3165 case DW_LNE_set_address:
0c588247
NC
3166 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
3167 op_code_data, ext_op_code_len - bytes_read - 1,
3168 end);
a233b20c 3169 state_machine_regs.op_index = 0;
a262ae96
NC
3170 break;
3171 case DW_LNE_define_file:
3172 {
143a3db0
TG
3173 file_table = (File_Entry *) xrealloc
3174 (file_table, (n_files + 1) * sizeof (File_Entry));
a262ae96
NC
3175
3176 ++state_machine_regs.last_file_entry;
143a3db0
TG
3177 /* Source file name. */
3178 file_table[n_files].name = op_code_data;
a262ae96 3179 op_code_data += strlen ((char *) op_code_data) + 1;
143a3db0
TG
3180 /* Directory index. */
3181 file_table[n_files].directory_index =
f6f0e17b
NC
3182 read_uleb128 (op_code_data, & bytes_read,
3183 end_of_sequence);
a262ae96 3184 op_code_data += bytes_read;
143a3db0
TG
3185 /* Last modification time. */
3186 file_table[n_files].modification_date =
f6f0e17b
NC
3187 read_uleb128 (op_code_data, & bytes_read,
3188 end_of_sequence);
a262ae96 3189 op_code_data += bytes_read;
143a3db0
TG
3190 /* File length. */
3191 file_table[n_files].length =
f6f0e17b
NC
3192 read_uleb128 (op_code_data, & bytes_read,
3193 end_of_sequence);
a262ae96 3194
143a3db0 3195 n_files++;
a262ae96
NC
3196 break;
3197 }
143a3db0
TG
3198 case DW_LNE_set_discriminator:
3199 case DW_LNE_HP_set_sequence:
3200 /* Simply ignored. */
3201 break;
3202
a262ae96 3203 default:
143a3db0
TG
3204 printf (_("UNKNOWN (%u): length %d\n"),
3205 ext_op_code, ext_op_code_len - bytes_read);
a262ae96
NC
3206 break;
3207 }
3208 data += ext_op_code_len;
3209 break;
3210 }
3211 case DW_LNS_copy:
3212 break;
3213
3214 case DW_LNS_advance_pc:
f6f0e17b 3215 uladv = read_uleb128 (data, & bytes_read, end);
a262ae96 3216 data += bytes_read;
a233b20c
JJ
3217 if (linfo.li_max_ops_per_insn == 1)
3218 {
3219 uladv *= linfo.li_min_insn_length;
3220 state_machine_regs.address += uladv;
3221 }
3222 else
3223 {
3224 state_machine_regs.address
3225 += ((state_machine_regs.op_index + uladv)
3226 / linfo.li_max_ops_per_insn)
3227 * linfo.li_min_insn_length;
3228 state_machine_regs.op_index
3229 = (state_machine_regs.op_index + uladv)
3230 % linfo.li_max_ops_per_insn;
3231 }
a262ae96
NC
3232 break;
3233
3234 case DW_LNS_advance_line:
f6f0e17b 3235 adv = read_sleb128 (data, & bytes_read, end);
a262ae96
NC
3236 data += bytes_read;
3237 state_machine_regs.line += adv;
3238 break;
3239
3240 case DW_LNS_set_file:
f6f0e17b 3241 adv = read_uleb128 (data, & bytes_read, end);
a262ae96
NC
3242 data += bytes_read;
3243 state_machine_regs.file = adv;
3244 if (file_table[state_machine_regs.file - 1].directory_index == 0)
3245 {
3246 /* If directory index is 0, that means current directory. */
cc5914eb 3247 printf ("\n./%s:[++]\n",
a262ae96
NC
3248 file_table[state_machine_regs.file - 1].name);
3249 }
3250 else
3251 {
3252 /* The directory index starts counting at 1. */
cc5914eb 3253 printf ("\n%s/%s:\n",
a262ae96
NC
3254 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
3255 file_table[state_machine_regs.file - 1].name);
3256 }
3257 break;
3258
3259 case DW_LNS_set_column:
f6f0e17b 3260 uladv = read_uleb128 (data, & bytes_read, end);
a262ae96
NC
3261 data += bytes_read;
3262 state_machine_regs.column = uladv;
3263 break;
3264
3265 case DW_LNS_negate_stmt:
3266 adv = state_machine_regs.is_stmt;
3267 adv = ! adv;
3268 state_machine_regs.is_stmt = adv;
3269 break;
3270
3271 case DW_LNS_set_basic_block:
3272 state_machine_regs.basic_block = 1;
3273 break;
3274
3275 case DW_LNS_const_add_pc:
a233b20c
JJ
3276 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3277 if (linfo.li_max_ops_per_insn == 1)
3278 {
3279 uladv *= linfo.li_min_insn_length;
3280 state_machine_regs.address += uladv;
3281 }
3282 else
3283 {
3284 state_machine_regs.address
3285 += ((state_machine_regs.op_index + uladv)
3286 / linfo.li_max_ops_per_insn)
3287 * linfo.li_min_insn_length;
3288 state_machine_regs.op_index
3289 = (state_machine_regs.op_index + uladv)
3290 % linfo.li_max_ops_per_insn;
3291 }
a262ae96
NC
3292 break;
3293
3294 case DW_LNS_fixed_advance_pc:
0c588247 3295 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
a262ae96 3296 state_machine_regs.address += uladv;
a233b20c 3297 state_machine_regs.op_index = 0;
a262ae96
NC
3298 break;
3299
3300 case DW_LNS_set_prologue_end:
3301 break;
3302
3303 case DW_LNS_set_epilogue_begin:
3304 break;
3305
3306 case DW_LNS_set_isa:
f6f0e17b 3307 uladv = read_uleb128 (data, & bytes_read, end);
a262ae96
NC
3308 data += bytes_read;
3309 printf (_(" Set ISA to %lu\n"), uladv);
3310 break;
3311
3312 default:
3313 printf (_(" Unknown opcode %d with operands: "), op_code);
3314
3315 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3316 {
f6f0e17b
NC
3317 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3318 &bytes_read, end)),
a262ae96
NC
3319 i == 1 ? "" : ", ");
3320 data += bytes_read;
3321 }
3322 putchar ('\n');
3323 break;
3324 }
3325
3326 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3327 to the DWARF address/line matrix. */
3328 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3329 || (op_code == DW_LNS_copy))
3330 {
3331 const unsigned int MAX_FILENAME_LENGTH = 35;
3332 char *fileName = (char *)file_table[state_machine_regs.file - 1].name;
3333 char *newFileName = NULL;
3334 size_t fileNameLength = strlen (fileName);
3335
3336 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3337 {
3f5e193b 3338 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
a262ae96
NC
3339 /* Truncate file name */
3340 strncpy (newFileName,
3341 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3342 MAX_FILENAME_LENGTH + 1);
3343 }
3344 else
3345 {
3f5e193b 3346 newFileName = (char *) xmalloc (fileNameLength + 1);
a262ae96
NC
3347 strncpy (newFileName, fileName, fileNameLength + 1);
3348 }
3349
3350 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3351 {
a233b20c 3352 if (linfo.li_max_ops_per_insn == 1)
467c65bc
NC
3353 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3354 newFileName, state_machine_regs.line,
a233b20c
JJ
3355 state_machine_regs.address);
3356 else
467c65bc
NC
3357 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3358 newFileName, state_machine_regs.line,
a233b20c
JJ
3359 state_machine_regs.address,
3360 state_machine_regs.op_index);
a262ae96
NC
3361 }
3362 else
3363 {
a233b20c 3364 if (linfo.li_max_ops_per_insn == 1)
467c65bc
NC
3365 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3366 newFileName, state_machine_regs.line,
a233b20c
JJ
3367 state_machine_regs.address);
3368 else
467c65bc
NC
3369 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3370 newFileName, state_machine_regs.line,
a233b20c
JJ
3371 state_machine_regs.address,
3372 state_machine_regs.op_index);
a262ae96
NC
3373 }
3374
3375 if (op_code == DW_LNE_end_sequence)
3376 printf ("\n");
3377
3378 free (newFileName);
3379 }
3380 }
3381 free (file_table);
3382 file_table = NULL;
3383 free (directory_table);
3384 directory_table = NULL;
3385 putchar ('\n');
3386 }
3387
3388 return 1;
3389}
3390
3391static int
1c4cc746 3392display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
a262ae96
NC
3393{
3394 unsigned char *data = section->start;
3395 unsigned char *end = data + section->size;
4cb93e3b
TG
3396 int retValRaw = 1;
3397 int retValDecoded = 1;
a262ae96 3398
008f4c78
NC
3399 if (do_debug_lines == 0)
3400 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3401
4cb93e3b 3402 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
a262ae96
NC
3403 retValRaw = display_debug_lines_raw (section, data, end);
3404
4cb93e3b 3405 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
a262ae96
NC
3406 retValDecoded = display_debug_lines_decoded (section, data, end);
3407
4cb93e3b 3408 if (!retValRaw || !retValDecoded)
a262ae96
NC
3409 return 0;
3410
3411 return 1;
3412}
3413
6e3d6dc1
NC
3414static debug_info *
3415find_debug_info_for_offset (unsigned long offset)
3416{
3417 unsigned int i;
3418
3419 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3420 return NULL;
3421
3422 for (i = 0; i < num_debug_info_entries; i++)
3423 if (debug_information[i].cu_offset == offset)
3424 return debug_information + i;
3425
3426 return NULL;
3427}
3428
19e6b90e
L
3429static int
3430display_debug_pubnames (struct dwarf_section *section,
3431 void *file ATTRIBUTE_UNUSED)
3432{
91d6fa6a 3433 DWARF2_Internal_PubNames names;
19e6b90e
L
3434 unsigned char *start = section->start;
3435 unsigned char *end = start + section->size;
3436
6e3d6dc1
NC
3437 /* It does not matter if this load fails,
3438 we test for that later on. */
3439 load_debug_info (file);
3440
19e6b90e
L
3441 printf (_("Contents of the %s section:\n\n"), section->name);
3442
3443 while (start < end)
3444 {
3445 unsigned char *data;
3446 unsigned long offset;
3447 int offset_size, initial_length_size;
3448
3449 data = start;
3450
0c588247 3451 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end);
91d6fa6a 3452 if (names.pn_length == 0xffffffff)
19e6b90e 3453 {
0c588247 3454 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end);
19e6b90e
L
3455 offset_size = 8;
3456 initial_length_size = 12;
3457 }
3458 else
3459 {
3460 offset_size = 4;
3461 initial_length_size = 4;
3462 }
3463
0c588247
NC
3464 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
3465 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
6e3d6dc1
NC
3466
3467 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3468 && num_debug_info_entries > 0
91d6fa6a 3469 && find_debug_info_for_offset (names.pn_offset) == NULL)
6e3d6dc1 3470 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
47704ddf 3471 (unsigned long) names.pn_offset, section->name);
cecf136e 3472
0c588247 3473 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
19e6b90e 3474
91d6fa6a 3475 start += names.pn_length + initial_length_size;
19e6b90e 3476
91d6fa6a 3477 if (names.pn_version != 2 && names.pn_version != 3)
19e6b90e
L
3478 {
3479 static int warned = 0;
3480
3481 if (! warned)
3482 {
3483 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3484 warned = 1;
3485 }
3486
3487 continue;
3488 }
3489
3490 printf (_(" Length: %ld\n"),
47704ddf 3491 (long) names.pn_length);
19e6b90e 3492 printf (_(" Version: %d\n"),
91d6fa6a 3493 names.pn_version);
6e3d6dc1 3494 printf (_(" Offset into .debug_info section: 0x%lx\n"),
47704ddf 3495 (unsigned long) names.pn_offset);
19e6b90e 3496 printf (_(" Size of area in .debug_info section: %ld\n"),
47704ddf 3497 (long) names.pn_size);
19e6b90e
L
3498
3499 printf (_("\n Offset\tName\n"));
3500
3501 do
3502 {
0c588247 3503 SAFE_BYTE_GET (offset, data, offset_size, end);
19e6b90e
L
3504
3505 if (offset != 0)
3506 {
3507 data += offset_size;
80c35038 3508 printf (" %-6lx\t%s\n", offset, data);
0c588247 3509 data += strnlen ((char *) data, end - data) + 1;
19e6b90e
L
3510 }
3511 }
3512 while (offset != 0);
3513 }
3514
3515 printf ("\n");
3516 return 1;
3517}
3518
3519static int
3520display_debug_macinfo (struct dwarf_section *section,
3521 void *file ATTRIBUTE_UNUSED)
3522{
3523 unsigned char *start = section->start;
3524 unsigned char *end = start + section->size;
3525 unsigned char *curr = start;
3526 unsigned int bytes_read;
3527 enum dwarf_macinfo_record_type op;
3528
3529 printf (_("Contents of the %s section:\n\n"), section->name);
3530
3531 while (curr < end)
3532 {
3533 unsigned int lineno;
0c588247 3534 const unsigned char *string;
19e6b90e 3535
3f5e193b 3536 op = (enum dwarf_macinfo_record_type) *curr;
19e6b90e
L
3537 curr++;
3538
3539 switch (op)
3540 {
3541 case DW_MACINFO_start_file:
3542 {
3543 unsigned int filenum;
3544
f6f0e17b 3545 lineno = read_uleb128 (curr, & bytes_read, end);
19e6b90e 3546 curr += bytes_read;
f6f0e17b 3547 filenum = read_uleb128 (curr, & bytes_read, end);
19e6b90e
L
3548 curr += bytes_read;
3549
3550 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3551 lineno, filenum);
3552 }
3553 break;
3554
3555 case DW_MACINFO_end_file:
3556 printf (_(" DW_MACINFO_end_file\n"));
3557 break;
3558
3559 case DW_MACINFO_define:
f6f0e17b 3560 lineno = read_uleb128 (curr, & bytes_read, end);
19e6b90e 3561 curr += bytes_read;
0c588247
NC
3562 string = curr;
3563 curr += strnlen ((char *) string, end - string) + 1;
19e6b90e
L
3564 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3565 lineno, string);
3566 break;
3567
3568 case DW_MACINFO_undef:
f6f0e17b 3569 lineno = read_uleb128 (curr, & bytes_read, end);
19e6b90e 3570 curr += bytes_read;
0c588247
NC
3571 string = curr;
3572 curr += strnlen ((char *) string, end - string) + 1;
19e6b90e
L
3573 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3574 lineno, string);
3575 break;
3576
3577 case DW_MACINFO_vendor_ext:
3578 {
3579 unsigned int constant;
3580
f6f0e17b 3581 constant = read_uleb128 (curr, & bytes_read, end);
19e6b90e 3582 curr += bytes_read;
0c588247
NC
3583 string = curr;
3584 curr += strnlen ((char *) string, end - string) + 1;
19e6b90e
L
3585 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3586 constant, string);
3587 }
3588 break;
3589 }
3590 }
3591
3592 return 1;
3593}
3594
4ccf1e31
JJ
3595/* Given LINE_OFFSET into the .debug_line section, attempt to return
3596 filename and dirname corresponding to file name table entry with index
3597 FILEIDX. Return NULL on failure. */
3598
3599static unsigned char *
f6f0e17b
NC
3600get_line_filename_and_dirname (dwarf_vma line_offset,
3601 dwarf_vma fileidx,
4ccf1e31
JJ
3602 unsigned char **dir_name)
3603{
3604 struct dwarf_section *section = &debug_displays [line].section;
3605 unsigned char *hdrptr, *dirtable, *file_name;
3606 unsigned int offset_size, initial_length_size;
3607 unsigned int version, opcode_base, bytes_read;
3608 dwarf_vma length, diridx;
f6f0e17b 3609 const unsigned char * end;
4ccf1e31
JJ
3610
3611 *dir_name = NULL;
3612 if (section->start == NULL
3613 || line_offset >= section->size
3614 || fileidx == 0)
3615 return NULL;
3616
3617 hdrptr = section->start + line_offset;
f6f0e17b 3618 end = section->start + section->size;
0c588247
NC
3619
3620 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
4ccf1e31
JJ
3621 if (length == 0xffffffff)
3622 {
3623 /* This section is 64-bit DWARF 3. */
0c588247 3624 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
4ccf1e31
JJ
3625 offset_size = 8;
3626 initial_length_size = 12;
3627 }
3628 else
3629 {
3630 offset_size = 4;
3631 initial_length_size = 4;
3632 }
3633 if (length + initial_length_size > section->size)
3634 return NULL;
0c588247
NC
3635
3636 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
4ccf1e31
JJ
3637 if (version != 2 && version != 3 && version != 4)
3638 return NULL;
3639 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
3640 if (version >= 4)
3641 hdrptr++; /* Skip max_ops_per_insn. */
3642 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
0c588247
NC
3643
3644 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
4ccf1e31
JJ
3645 if (opcode_base == 0)
3646 return NULL;
0c588247 3647
4ccf1e31
JJ
3648 hdrptr += opcode_base - 1;
3649 dirtable = hdrptr;
3650 /* Skip over dirname table. */
3651 while (*hdrptr != '\0')
0c588247 3652 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4ccf1e31
JJ
3653 hdrptr++; /* Skip the NUL at the end of the table. */
3654 /* Now skip over preceding filename table entries. */
3655 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
3656 {
0c588247 3657 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
f6f0e17b 3658 read_uleb128 (hdrptr, &bytes_read, end);
4ccf1e31 3659 hdrptr += bytes_read;
f6f0e17b 3660 read_uleb128 (hdrptr, &bytes_read, end);
4ccf1e31 3661 hdrptr += bytes_read;
f6f0e17b 3662 read_uleb128 (hdrptr, &bytes_read, end);
4ccf1e31
JJ
3663 hdrptr += bytes_read;
3664 }
f6f0e17b 3665 if (hdrptr == end || *hdrptr == '\0')
4ccf1e31
JJ
3666 return NULL;
3667 file_name = hdrptr;
0c588247 3668 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
f6f0e17b 3669 diridx = read_uleb128 (hdrptr, &bytes_read, end);
4ccf1e31
JJ
3670 if (diridx == 0)
3671 return file_name;
3672 for (; *dirtable != '\0' && diridx > 1; diridx--)
0c588247 3673 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
4ccf1e31
JJ
3674 if (*dirtable == '\0')
3675 return NULL;
3676 *dir_name = dirtable;
3677 return file_name;
3678}
3679
3680static int
3681display_debug_macro (struct dwarf_section *section,
3682 void *file)
3683{
3684 unsigned char *start = section->start;
3685 unsigned char *end = start + section->size;
3686 unsigned char *curr = start;
3687 unsigned char *extended_op_buf[256];
3688 unsigned int bytes_read;
3689
3690 load_debug_section (str, file);
3691 load_debug_section (line, file);
3692
3693 printf (_("Contents of the %s section:\n\n"), section->name);
3694
3695 while (curr < end)
3696 {
3697 unsigned int lineno, version, flags;
3698 unsigned int offset_size = 4;
0c588247 3699 const unsigned char *string;
4ccf1e31
JJ
3700 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
3701 unsigned char **extended_ops = NULL;
3702
0c588247 3703 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
4ccf1e31
JJ
3704 if (version != 4)
3705 {
3706 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3707 section->name);
3708 return 0;
3709 }
3710
0c588247 3711 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
4ccf1e31
JJ
3712 if (flags & 1)
3713 offset_size = 8;
3714 printf (_(" Offset: 0x%lx\n"),
3715 (unsigned long) sec_offset);
3716 printf (_(" Version: %d\n"), version);
3717 printf (_(" Offset size: %d\n"), offset_size);
3718 if (flags & 2)
3719 {
0c588247 3720 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
4ccf1e31
JJ
3721 printf (_(" Offset into .debug_line: 0x%lx\n"),
3722 (unsigned long) line_offset);
3723 }
3724 if (flags & 4)
3725 {
0c588247 3726 unsigned int i, count, op;
4ccf1e31 3727 dwarf_vma nargs, n;
0c588247
NC
3728
3729 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
3730
4ccf1e31
JJ
3731 memset (extended_op_buf, 0, sizeof (extended_op_buf));
3732 extended_ops = extended_op_buf;
3733 if (count)
3734 {
3735 printf (_(" Extension opcode arguments:\n"));
3736 for (i = 0; i < count; i++)
3737 {
0c588247 3738 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4ccf1e31 3739 extended_ops[op] = curr;
f6f0e17b 3740 nargs = read_uleb128 (curr, &bytes_read, end);
4ccf1e31
JJ
3741 curr += bytes_read;
3742 if (nargs == 0)
3743 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op);
3744 else
3745 {
3746 printf (_(" DW_MACRO_GNU_%02x arguments: "), op);
3747 for (n = 0; n < nargs; n++)
3748 {
0c588247
NC
3749 unsigned int form;
3750
3751 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
4ccf1e31
JJ
3752 printf ("%s%s", get_FORM_name (form),
3753 n == nargs - 1 ? "\n" : ", ");
3754 switch (form)
3755 {
3756 case DW_FORM_data1:
3757 case DW_FORM_data2:
3758 case DW_FORM_data4:
3759 case DW_FORM_data8:
3760 case DW_FORM_sdata:
3761 case DW_FORM_udata:
3762 case DW_FORM_block:
3763 case DW_FORM_block1:
3764 case DW_FORM_block2:
3765 case DW_FORM_block4:
3766 case DW_FORM_flag:
3767 case DW_FORM_string:
3768 case DW_FORM_strp:
3769 case DW_FORM_sec_offset:
3770 break;
3771 default:
3772 error (_("Invalid extension opcode form %s\n"),
3773 get_FORM_name (form));
3774 return 0;
3775 }
3776 }
3777 }
3778 }
3779 }
3780 }
3781 printf ("\n");
3782
3783 while (1)
3784 {
3785 unsigned int op;
3786
3787 if (curr >= end)
3788 {
3789 error (_(".debug_macro section not zero terminated\n"));
3790 return 0;
3791 }
3792
0c588247 3793 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4ccf1e31
JJ
3794 if (op == 0)
3795 break;
3796
3797 switch (op)
3798 {
3799 case DW_MACRO_GNU_start_file:
3800 {
3801 unsigned int filenum;
3802 unsigned char *file_name = NULL, *dir_name = NULL;
3803
f6f0e17b 3804 lineno = read_uleb128 (curr, &bytes_read, end);
4ccf1e31 3805 curr += bytes_read;
f6f0e17b 3806 filenum = read_uleb128 (curr, &bytes_read, end);
4ccf1e31
JJ
3807 curr += bytes_read;
3808
3809 if ((flags & 2) == 0)
3810 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
3811 else
3812 file_name
3813 = get_line_filename_and_dirname (line_offset, filenum,
3814 &dir_name);
3815 if (file_name == NULL)
3816 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
3817 lineno, filenum);
3818 else
3819 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
3820 lineno, filenum,
3821 dir_name != NULL ? (const char *) dir_name : "",
3822 dir_name != NULL ? "/" : "", file_name);
3823 }
3824 break;
3825
3826 case DW_MACRO_GNU_end_file:
3827 printf (_(" DW_MACRO_GNU_end_file\n"));
3828 break;
3829
3830 case DW_MACRO_GNU_define:
f6f0e17b 3831 lineno = read_uleb128 (curr, &bytes_read, end);
4ccf1e31 3832 curr += bytes_read;
0c588247
NC
3833 string = curr;
3834 curr += strnlen ((char *) string, end - string) + 1;
4ccf1e31
JJ
3835 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
3836 lineno, string);
3837 break;
3838
3839 case DW_MACRO_GNU_undef:
f6f0e17b 3840 lineno = read_uleb128 (curr, &bytes_read, end);
4ccf1e31 3841 curr += bytes_read;
0c588247
NC
3842 string = curr;
3843 curr += strnlen ((char *) string, end - string) + 1;
4ccf1e31
JJ
3844 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
3845 lineno, string);
3846 break;
3847
3848 case DW_MACRO_GNU_define_indirect:
f6f0e17b 3849 lineno = read_uleb128 (curr, &bytes_read, end);
4ccf1e31 3850 curr += bytes_read;
0c588247 3851 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4ccf1e31
JJ
3852 string = fetch_indirect_string (offset);
3853 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
3854 lineno, string);
3855 break;
3856
3857 case DW_MACRO_GNU_undef_indirect:
f6f0e17b 3858 lineno = read_uleb128 (curr, &bytes_read, end);
4ccf1e31 3859 curr += bytes_read;
0c588247 3860 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4ccf1e31
JJ
3861 string = fetch_indirect_string (offset);
3862 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
3863 lineno, string);
3864 break;
3865
3866 case DW_MACRO_GNU_transparent_include:
0c588247 3867 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4ccf1e31
JJ
3868 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
3869 (unsigned long) offset);
3870 break;
3871
a081f3cd 3872 case DW_MACRO_GNU_define_indirect_alt:
f6f0e17b 3873 lineno = read_uleb128 (curr, &bytes_read, end);
a081f3cd 3874 curr += bytes_read;
0c588247 3875 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
a081f3cd
JJ
3876 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
3877 lineno, (unsigned long) offset);
3878 break;
3879
3880 case DW_MACRO_GNU_undef_indirect_alt:
f6f0e17b 3881 lineno = read_uleb128 (curr, &bytes_read, end);
a081f3cd 3882 curr += bytes_read;
0c588247 3883 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
a081f3cd
JJ
3884 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
3885 lineno, (unsigned long) offset);
3886 break;
3887
3888 case DW_MACRO_GNU_transparent_include_alt:
0c588247 3889 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
a081f3cd
JJ
3890 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
3891 (unsigned long) offset);
3892 break;
3893
4ccf1e31
JJ
3894 default:
3895 if (extended_ops == NULL || extended_ops[op] == NULL)
3896 {
3897 error (_(" Unknown macro opcode %02x seen\n"), op);
3898 return 0;
3899 }
3900 else
3901 {
3902 /* Skip over unhandled opcodes. */
3903 dwarf_vma nargs, n;
3904 unsigned char *desc = extended_ops[op];
f6f0e17b 3905 nargs = read_uleb128 (desc, &bytes_read, end);
4ccf1e31
JJ
3906 desc += bytes_read;
3907 if (nargs == 0)
3908 {
3909 printf (_(" DW_MACRO_GNU_%02x\n"), op);
3910 break;
3911 }
3912 printf (_(" DW_MACRO_GNU_%02x -"), op);
3913 for (n = 0; n < nargs; n++)
3914 {
0c588247
NC
3915 int val;
3916
3917 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
4ccf1e31 3918 curr
0c588247 3919 = read_and_display_attr_value (0, val,
f6f0e17b 3920 curr, end, 0, 0, offset_size,
341f9135
CC
3921 version, NULL, 0, NULL,
3922 NULL);
4ccf1e31
JJ
3923 if (n != nargs - 1)
3924 printf (",");
3925 }
3926 printf ("\n");
3927 }
3928 break;
3929 }
3930 }
3931
3932 printf ("\n");
3933 }
3934
3935 return 1;
3936}
3937
19e6b90e
L
3938static int
3939display_debug_abbrev (struct dwarf_section *section,
3940 void *file ATTRIBUTE_UNUSED)
3941{
3942 abbrev_entry *entry;
3943 unsigned char *start = section->start;
3944 unsigned char *end = start + section->size;
3945
3946 printf (_("Contents of the %s section:\n\n"), section->name);
3947
3948 do
3949 {
7282333f
AM
3950 unsigned char *last;
3951
19e6b90e
L
3952 free_abbrevs ();
3953
7282333f 3954 last = start;
19e6b90e
L
3955 start = process_abbrev_section (start, end);
3956
3957 if (first_abbrev == NULL)
3958 continue;
3959
7282333f 3960 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
19e6b90e
L
3961
3962 for (entry = first_abbrev; entry; entry = entry->next)
3963 {
3964 abbrev_attr *attr;
3965
cc5914eb 3966 printf (" %ld %s [%s]\n",
19e6b90e
L
3967 entry->entry,
3968 get_TAG_name (entry->tag),
3969 entry->children ? _("has children") : _("no children"));
3970
3971 for (attr = entry->first_attr; attr; attr = attr->next)
cc5914eb 3972 printf (" %-18s %s\n",
19e6b90e
L
3973 get_AT_name (attr->attribute),
3974 get_FORM_name (attr->form));
3975 }
3976 }
3977 while (start);
3978
3979 printf ("\n");
3980
3981 return 1;
3982}
3983
4723351a
CC
3984/* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
3985
3986static void
3987display_loc_list (struct dwarf_section *section,
3988 unsigned char **start_ptr,
3989 int debug_info_entry,
3990 unsigned long offset,
3991 unsigned long base_address,
3992 int has_frame_base)
3993{
3994 unsigned char *start = *start_ptr;
3995 unsigned char *section_end = section->start + section->size;
3996 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
3997 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
3998 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
3999 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
4000
4001 dwarf_vma begin;
4002 dwarf_vma end;
4003 unsigned short length;
4004 int need_frame_base;
4005
4006 while (1)
4007 {
4008 if (start + 2 * pointer_size > section_end)
4009 {
4010 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4011 offset);
4012 break;
4013 }
4014
fab128ef
CC
4015 printf (" %8.8lx ", offset + (start - *start_ptr));
4016
4723351a
CC
4017 /* Note: we use sign extension here in order to be sure that we can detect
4018 the -1 escape value. Sign extension into the top 32 bits of a 32-bit
4019 address will not affect the values that we display since we always show
4020 hex values, and always the bottom 32-bits. */
0c588247
NC
4021 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
4022 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
4723351a 4023
4723351a
CC
4024 if (begin == 0 && end == 0)
4025 {
4026 printf (_("<End of list>\n"));
4027 break;
4028 }
4029
4030 /* Check base address specifiers. */
4031 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4032 {
4033 base_address = end;
4034 print_dwarf_vma (begin, pointer_size);
4035 print_dwarf_vma (end, pointer_size);
4036 printf (_("(base address)\n"));
4037 continue;
4038 }
4039
4040 if (start + 2 > section_end)
4041 {
4042 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4043 offset);
4044 break;
4045 }
4046
0c588247 4047 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4723351a
CC
4048
4049 if (start + length > section_end)
4050 {
4051 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4052 offset);
4053 break;
4054 }
4055
4056 print_dwarf_vma (begin + base_address, pointer_size);
4057 print_dwarf_vma (end + base_address, pointer_size);
4058
4059 putchar ('(');
4060 need_frame_base = decode_location_expression (start,
4061 pointer_size,
4062 offset_size,
4063 dwarf_version,
4064 length,
4065 cu_offset, section);
4066 putchar (')');
4067
4068 if (need_frame_base && !has_frame_base)
4069 printf (_(" [without DW_AT_frame_base]"));
4070
4071 if (begin == end)
4072 fputs (_(" (start == end)"), stdout);
4073 else if (begin > end)
4074 fputs (_(" (start > end)"), stdout);
4075
4076 putchar ('\n');
4077
4078 start += length;
4079 }
4080
4081 *start_ptr = start;
4082}
4083
fab128ef
CC
4084/* Print a .debug_addr table index in decimal, surrounded by square brackets,
4085 right-adjusted in a field of length LEN, and followed by a space. */
4086
4087static void
4088print_addr_index (unsigned int idx, unsigned int len)
4089{
4090 static char buf[15];
4091 snprintf (buf, sizeof (buf), "[%d]", idx);
341f9135 4092 printf ("%*s ", len, buf);
fab128ef
CC
4093}
4094
4723351a
CC
4095/* Display a location list from a .dwo section. It uses address indexes rather
4096 than embedded addresses. This code closely follows display_loc_list, but the
4097 two are sufficiently different that combining things is very ugly. */
4098
4099static void
4100display_loc_list_dwo (struct dwarf_section *section,
4101 unsigned char **start_ptr,
4102 int debug_info_entry,
4103 unsigned long offset,
4104 int has_frame_base)
4105{
4106 unsigned char *start = *start_ptr;
4107 unsigned char *section_end = section->start + section->size;
4108 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
4109 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
4110 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
4111 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
4112 int entry_type;
4113 unsigned short length;
4114 int need_frame_base;
fab128ef 4115 unsigned int idx;
4723351a
CC
4116 unsigned int bytes_read;
4117
4118 while (1)
4119 {
fab128ef 4120 printf (" %8.8lx ", offset + (start - *start_ptr));
4723351a 4121
fab128ef 4122 if (start >= section_end)
4723351a
CC
4123 {
4124 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4125 offset);
4126 break;
4127 }
4128
0c588247 4129 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
4723351a
CC
4130 switch (entry_type)
4131 {
4132 case 0: /* A terminating entry. */
4723351a 4133 *start_ptr = start;
fab128ef 4134 printf (_("<End of list>\n"));
4723351a
CC
4135 return;
4136 case 1: /* A base-address entry. */
f6f0e17b 4137 idx = read_uleb128 (start, &bytes_read, section_end);
4723351a 4138 start += bytes_read;
fab128ef
CC
4139 print_addr_index (idx, 8);
4140 printf (" ");
4141 printf (_("(base address selection entry)\n"));
4723351a 4142 continue;
fab128ef 4143 case 2: /* A start/end entry. */
f6f0e17b 4144 idx = read_uleb128 (start, &bytes_read, section_end);
fab128ef
CC
4145 start += bytes_read;
4146 print_addr_index (idx, 8);
f6f0e17b 4147 idx = read_uleb128 (start, &bytes_read, section_end);
4723351a 4148 start += bytes_read;
fab128ef
CC
4149 print_addr_index (idx, 8);
4150 break;
4151 case 3: /* A start/length entry. */
f6f0e17b 4152 idx = read_uleb128 (start, &bytes_read, section_end);
4723351a 4153 start += bytes_read;
fab128ef 4154 print_addr_index (idx, 8);
0c588247 4155 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
fab128ef
CC
4156 printf ("%08x ", idx);
4157 break;
4158 case 4: /* An offset pair entry. */
0c588247 4159 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
fab128ef 4160 printf ("%08x ", idx);
0c588247 4161 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
fab128ef 4162 printf ("%08x ", idx);
4723351a
CC
4163 break;
4164 default:
fab128ef 4165 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
4723351a
CC
4166 *start_ptr = start;
4167 return;
4168 }
4169
4170 if (start + 2 > section_end)
4171 {
4172 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4173 offset);
4174 break;
4175 }
4176
0c588247 4177 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4723351a
CC
4178 if (start + length > section_end)
4179 {
4180 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4181 offset);
4182 break;
4183 }
4184
4185 putchar ('(');
4186 need_frame_base = decode_location_expression (start,
4187 pointer_size,
4188 offset_size,
4189 dwarf_version,
4190 length,
4191 cu_offset, section);
4192 putchar (')');
4193
4194 if (need_frame_base && !has_frame_base)
4195 printf (_(" [without DW_AT_frame_base]"));
4196
4197 putchar ('\n');
4198
4199 start += length;
4200 }
4201
4202 *start_ptr = start;
4203}
4204
51d0d03f
JJ
4205/* Sort array of indexes in ascending order of loc_offsets[idx]. */
4206
4207static dwarf_vma *loc_offsets;
4208
4209static int
4210loc_offsets_compar (const void *ap, const void *bp)
4211{
4212 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
4213 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
4214
4215 return (a > b) - (b > a);
4216}
4217
19e6b90e
L
4218static int
4219display_debug_loc (struct dwarf_section *section, void *file)
4220{
4221 unsigned char *start = section->start;
19e6b90e
L
4222 unsigned long bytes;
4223 unsigned char *section_begin = start;
4224 unsigned int num_loc_list = 0;
4225 unsigned long last_offset = 0;
4226 unsigned int first = 0;
4227 unsigned int i;
4228 unsigned int j;
51d0d03f 4229 unsigned int k;
19e6b90e 4230 int seen_first_offset = 0;
51d0d03f 4231 int locs_sorted = 1;
19e6b90e 4232 unsigned char *next;
51d0d03f 4233 unsigned int *array = NULL;
4723351a
CC
4234 const char *suffix = strrchr (section->name, '.');
4235 int is_dwo = 0;
4236
4237 if (suffix && strcmp (suffix, ".dwo") == 0)
4238 is_dwo = 1;
19e6b90e
L
4239
4240 bytes = section->size;
19e6b90e
L
4241
4242 if (bytes == 0)
4243 {
4244 printf (_("\nThe %s section is empty.\n"), section->name);
4245 return 0;
4246 }
4247
1febe64d
NC
4248 if (load_debug_info (file) == 0)
4249 {
4250 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4251 section->name);
4252 return 0;
4253 }
19e6b90e
L
4254
4255 /* Check the order of location list in .debug_info section. If
4256 offsets of location lists are in the ascending order, we can
4257 use `debug_information' directly. */
4258 for (i = 0; i < num_debug_info_entries; i++)
4259 {
4260 unsigned int num;
4261
4262 num = debug_information [i].num_loc_offsets;
51d0d03f
JJ
4263 if (num > num_loc_list)
4264 num_loc_list = num;
19e6b90e
L
4265
4266 /* Check if we can use `debug_information' directly. */
51d0d03f 4267 if (locs_sorted && num != 0)
19e6b90e
L
4268 {
4269 if (!seen_first_offset)
4270 {
4271 /* This is the first location list. */
4272 last_offset = debug_information [i].loc_offsets [0];
4273 first = i;
4274 seen_first_offset = 1;
4275 j = 1;
4276 }
4277 else
4278 j = 0;
4279
4280 for (; j < num; j++)
4281 {
4282 if (last_offset >
4283 debug_information [i].loc_offsets [j])
4284 {
51d0d03f 4285 locs_sorted = 0;
19e6b90e
L
4286 break;
4287 }
4288 last_offset = debug_information [i].loc_offsets [j];
4289 }
4290 }
4291 }
4292
19e6b90e
L
4293 if (!seen_first_offset)
4294 error (_("No location lists in .debug_info section!\n"));
4295
bfe2612a 4296 /* DWARF sections under Mach-O have non-zero addresses. */
d4bfc77b
AS
4297 if (debug_information [first].num_loc_offsets > 0
4298 && debug_information [first].loc_offsets [0] != section->address)
47704ddf
KT
4299 warn (_("Location lists in %s section start at 0x%s\n"),
4300 section->name,
4301 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
19e6b90e 4302
51d0d03f
JJ
4303 if (!locs_sorted)
4304 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
19e6b90e 4305 printf (_("Contents of the %s section:\n\n"), section->name);
fab128ef 4306 printf (_(" Offset Begin End Expression\n"));
19e6b90e
L
4307
4308 seen_first_offset = 0;
4309 for (i = first; i < num_debug_info_entries; i++)
4310 {
19e6b90e 4311 unsigned long offset;
19e6b90e 4312 unsigned long base_address;
19e6b90e
L
4313 int has_frame_base;
4314
51d0d03f
JJ
4315 if (!locs_sorted)
4316 {
4317 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4318 array[k] = k;
4319 loc_offsets = debug_information [i].loc_offsets;
4320 qsort (array, debug_information [i].num_loc_offsets,
4321 sizeof (*array), loc_offsets_compar);
4322 }
19e6b90e 4323
51d0d03f 4324 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
19e6b90e 4325 {
51d0d03f
JJ
4326 j = locs_sorted ? k : array[k];
4327 if (k
4328 && debug_information [i].loc_offsets [locs_sorted
4329 ? k - 1 : array [k - 1]]
4330 == debug_information [i].loc_offsets [j])
4331 continue;
19e6b90e 4332 has_frame_base = debug_information [i].have_frame_base [j];
bfe2612a 4333 /* DWARF sections under Mach-O have non-zero addresses. */
cecf136e 4334 offset = debug_information [i].loc_offsets [j] - section->address;
19e6b90e
L
4335 next = section_begin + offset;
4336 base_address = debug_information [i].base_address;
4337
4338 if (!seen_first_offset)
4339 seen_first_offset = 1;
4340 else
4341 {
4342 if (start < next)
4343 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
0af1713e
AM
4344 (unsigned long) (start - section_begin),
4345 (unsigned long) (next - section_begin));
19e6b90e
L
4346 else if (start > next)
4347 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
0af1713e
AM
4348 (unsigned long) (start - section_begin),
4349 (unsigned long) (next - section_begin));
19e6b90e
L
4350 }
4351 start = next;
4352
4353 if (offset >= bytes)
4354 {
4355 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4356 offset);
4357 continue;
4358 }
4359
4723351a
CC
4360 if (is_dwo)
4361 display_loc_list_dwo (section, &start, i, offset, has_frame_base);
4362 else
4363 display_loc_list (section, &start, i, offset, base_address,
4364 has_frame_base);
19e6b90e
L
4365 }
4366 }
031cd65f 4367
4723351a 4368 if (start < section->start + section->size)
031cd65f 4369 warn (_("There are %ld unused bytes at the end of section %s\n"),
4723351a 4370 (long) (section->start + section->size - start), section->name);
98fb390a 4371 putchar ('\n');
51d0d03f 4372 free (array);
19e6b90e
L
4373 return 1;
4374}
4375
4376static int
4377display_debug_str (struct dwarf_section *section,
4378 void *file ATTRIBUTE_UNUSED)
4379{
4380 unsigned char *start = section->start;
4381 unsigned long bytes = section->size;
4382 dwarf_vma addr = section->address;
4383
4384 if (bytes == 0)
4385 {
4386 printf (_("\nThe %s section is empty.\n"), section->name);
4387 return 0;
4388 }
4389
4390 printf (_("Contents of the %s section:\n\n"), section->name);
4391
4392 while (bytes)
4393 {
4394 int j;
4395 int k;
4396 int lbytes;
4397
4398 lbytes = (bytes > 16 ? 16 : bytes);
4399
4400 printf (" 0x%8.8lx ", (unsigned long) addr);
4401
4402 for (j = 0; j < 16; j++)
4403 {
4404 if (j < lbytes)
4405 printf ("%2.2x", start[j]);
4406 else
4407 printf (" ");
4408
4409 if ((j & 3) == 3)
4410 printf (" ");
4411 }
4412
4413 for (j = 0; j < lbytes; j++)
4414 {
4415 k = start[j];
4416 if (k >= ' ' && k < 0x80)
4417 printf ("%c", k);
4418 else
4419 printf (".");
4420 }
4421
4422 putchar ('\n');
4423
4424 start += lbytes;
4425 addr += lbytes;
4426 bytes -= lbytes;
4427 }
4428
4429 putchar ('\n');
4430
4431 return 1;
4432}
4433
19e6b90e
L
4434static int
4435display_debug_info (struct dwarf_section *section, void *file)
4436{
4723351a 4437 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
19e6b90e
L
4438}
4439
2b6f5997
CC
4440static int
4441display_debug_types (struct dwarf_section *section, void *file)
4442{
4723351a 4443 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
6f875884
TG
4444}
4445
4446static int
4447display_trace_info (struct dwarf_section *section, void *file)
4448{
4723351a 4449 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
2b6f5997 4450}
19e6b90e
L
4451
4452static int
4453display_debug_aranges (struct dwarf_section *section,
4454 void *file ATTRIBUTE_UNUSED)
4455{
4456 unsigned char *start = section->start;
4457 unsigned char *end = start + section->size;
4458
80c35038 4459 printf (_("Contents of the %s section:\n\n"), section->name);
19e6b90e 4460
6e3d6dc1
NC
4461 /* It does not matter if this load fails,
4462 we test for that later on. */
4463 load_debug_info (file);
4464
19e6b90e
L
4465 while (start < end)
4466 {
4467 unsigned char *hdrptr;
4468 DWARF2_Internal_ARange arange;
91d6fa6a 4469 unsigned char *addr_ranges;
2d9472a2
NC
4470 dwarf_vma length;
4471 dwarf_vma address;
53b8873b 4472 unsigned char address_size;
19e6b90e
L
4473 int excess;
4474 int offset_size;
4475 int initial_length_size;
4476
4477 hdrptr = start;
4478
0c588247 4479 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
19e6b90e
L
4480 if (arange.ar_length == 0xffffffff)
4481 {
0c588247 4482 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
19e6b90e
L
4483 offset_size = 8;
4484 initial_length_size = 12;
4485 }
4486 else
4487 {
4488 offset_size = 4;
4489 initial_length_size = 4;
4490 }
4491
0c588247
NC
4492 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
4493 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
19e6b90e 4494
6e3d6dc1
NC
4495 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4496 && num_debug_info_entries > 0
4497 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
4498 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
47704ddf 4499 (unsigned long) arange.ar_info_offset, section->name);
6e3d6dc1 4500
0c588247
NC
4501 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
4502 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
19e6b90e
L
4503
4504 if (arange.ar_version != 2 && arange.ar_version != 3)
4505 {
4506 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4507 break;
4508 }
4509
47704ddf
KT
4510 printf (_(" Length: %ld\n"),
4511 (long) arange.ar_length);
19e6b90e 4512 printf (_(" Version: %d\n"), arange.ar_version);
47704ddf
KT
4513 printf (_(" Offset into .debug_info: 0x%lx\n"),
4514 (unsigned long) arange.ar_info_offset);
19e6b90e
L
4515 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
4516 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
4517
53b8873b
NC
4518 address_size = arange.ar_pointer_size + arange.ar_segment_size;
4519
b3681d67
L
4520 if (address_size == 0)
4521 {
4522 error (_("Invalid address size in %s section!\n"),
4523 section->name);
4524 break;
4525 }
4526
53b8873b
NC
4527 /* The DWARF spec does not require that the address size be a power
4528 of two, but we do. This will have to change if we ever encounter
4529 an uneven architecture. */
4530 if ((address_size & (address_size - 1)) != 0)
4531 {
4532 warn (_("Pointer size + Segment size is not a power of two.\n"));
4533 break;
4534 }
cecf136e 4535
209c9a13
NC
4536 if (address_size > 4)
4537 printf (_("\n Address Length\n"));
4538 else
4539 printf (_("\n Address Length\n"));
19e6b90e 4540
91d6fa6a 4541 addr_ranges = hdrptr;
19e6b90e 4542
53b8873b
NC
4543 /* Must pad to an alignment boundary that is twice the address size. */
4544 excess = (hdrptr - start) % (2 * address_size);
19e6b90e 4545 if (excess)
91d6fa6a 4546 addr_ranges += (2 * address_size) - excess;
19e6b90e 4547
1617e571
AM
4548 start += arange.ar_length + initial_length_size;
4549
91d6fa6a 4550 while (addr_ranges + 2 * address_size <= start)
19e6b90e 4551 {
0c588247
NC
4552 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
4553 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
19e6b90e 4554
80c35038 4555 printf (" ");
2d9472a2
NC
4556 print_dwarf_vma (address, address_size);
4557 print_dwarf_vma (length, address_size);
4558 putchar ('\n');
19e6b90e 4559 }
19e6b90e
L
4560 }
4561
4562 printf ("\n");
4563
4564 return 1;
4565}
4566
4723351a
CC
4567/* Comparison function for qsort. */
4568static int
4569comp_addr_base (const void * v0, const void * v1)
4570{
4571 debug_info * info0 = (debug_info *) v0;
4572 debug_info * info1 = (debug_info *) v1;
4573 return info0->addr_base - info1->addr_base;
4574}
4575
4576/* Display the debug_addr section. */
4577static int
4578display_debug_addr (struct dwarf_section *section,
4579 void *file)
4580{
4581 debug_info **debug_addr_info;
4582 unsigned char *entry;
4583 unsigned char *end;
4584 unsigned int i;
4585 unsigned int count;
4586
4587 if (section->size == 0)
4588 {
4589 printf (_("\nThe %s section is empty.\n"), section->name);
4590 return 0;
4591 }
4592
4593 if (load_debug_info (file) == 0)
4594 {
4595 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4596 section->name);
4597 return 0;
4598 }
4599
4600 printf (_("Contents of the %s section:\n\n"), section->name);
4601
90f9a987 4602 debug_addr_info = (debug_info **) xmalloc ((num_debug_info_entries + 1)
4723351a
CC
4603 * sizeof (debug_info *));
4604
4605 count = 0;
4606 for (i = 0; i < num_debug_info_entries; i++)
4607 {
4608 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
4609 debug_addr_info [count++] = &debug_information [i];
4610 }
4611
4612 /* Add a sentinel to make iteration convenient. */
4613 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
4614 debug_addr_info [count]->addr_base = section->size;
4615
4616 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
4617 for (i = 0; i < count; i++)
4618 {
4619 unsigned int idx;
fab128ef 4620 unsigned int address_size = debug_addr_info [i]->pointer_size;
4723351a
CC
4621
4622 printf (_(" For compilation unit at offset 0x%s:\n"),
4623 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
4624
fab128ef 4625 printf (_("\tIndex\tAddress\n"));
4723351a
CC
4626 entry = section->start + debug_addr_info [i]->addr_base;
4627 end = section->start + debug_addr_info [i + 1]->addr_base;
4628 idx = 0;
4629 while (entry < end)
4630 {
fab128ef
CC
4631 dwarf_vma base = byte_get (entry, address_size);
4632 printf (_("\t%d:\t"), idx);
4633 print_dwarf_vma (base, address_size);
4634 printf ("\n");
4635 entry += address_size;
4723351a
CC
4636 idx++;
4637 }
4638 }
4639 printf ("\n");
4640
4641 free (debug_addr_info);
4642 return 1;
4643}
4644
4645/* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
4646static int
4647display_debug_str_offsets (struct dwarf_section *section,
4648 void *file ATTRIBUTE_UNUSED)
4649{
4650 if (section->size == 0)
4651 {
4652 printf (_("\nThe %s section is empty.\n"), section->name);
4653 return 0;
4654 }
4655 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
4656 what the offset size is for this section. */
4657 return 1;
4658}
4659
01a8f077
JK
4660/* Each debug_information[x].range_lists[y] gets this representation for
4661 sorting purposes. */
4662
4663struct range_entry
467c65bc
NC
4664{
4665 /* The debug_information[x].range_lists[y] value. */
4666 unsigned long ranges_offset;
01a8f077 4667
467c65bc
NC
4668 /* Original debug_information to find parameters of the data. */
4669 debug_info *debug_info_p;
4670};
01a8f077
JK
4671
4672/* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4673
4674static int
4675range_entry_compar (const void *ap, const void *bp)
4676{
3f5e193b
NC
4677 const struct range_entry *a_re = (const struct range_entry *) ap;
4678 const struct range_entry *b_re = (const struct range_entry *) bp;
01a8f077
JK
4679 const unsigned long a = a_re->ranges_offset;
4680 const unsigned long b = b_re->ranges_offset;
4681
4682 return (a > b) - (b > a);
4683}
4684
19e6b90e
L
4685static int
4686display_debug_ranges (struct dwarf_section *section,
4687 void *file ATTRIBUTE_UNUSED)
4688{
4689 unsigned char *start = section->start;
a2ff7a4b 4690 unsigned char *last_start = start;
f6f0e17b 4691 unsigned long bytes = section->size;
19e6b90e 4692 unsigned char *section_begin = start;
f6f0e17b 4693 unsigned char *finish = start + bytes;
01a8f077
JK
4694 unsigned int num_range_list, i;
4695 struct range_entry *range_entries, *range_entry_fill;
19e6b90e 4696
19e6b90e
L
4697 if (bytes == 0)
4698 {
4699 printf (_("\nThe %s section is empty.\n"), section->name);
4700 return 0;
4701 }
4702
1febe64d
NC
4703 if (load_debug_info (file) == 0)
4704 {
4705 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4706 section->name);
4707 return 0;
4708 }
19e6b90e 4709
01a8f077 4710 num_range_list = 0;
19e6b90e 4711 for (i = 0; i < num_debug_info_entries; i++)
01a8f077 4712 num_range_list += debug_information [i].num_range_lists;
19e6b90e 4713
01a8f077 4714 if (num_range_list == 0)
4723351a
CC
4715 {
4716 /* This can happen when the file was compiled with -gsplit-debug
4717 which removes references to range lists from the primary .o file. */
4718 printf (_("No range lists in .debug_info section.\n"));
4719 return 1;
4720 }
19e6b90e 4721
3f5e193b
NC
4722 range_entries = (struct range_entry *)
4723 xmalloc (sizeof (*range_entries) * num_range_list);
01a8f077 4724 range_entry_fill = range_entries;
19e6b90e 4725
01a8f077
JK
4726 for (i = 0; i < num_debug_info_entries; i++)
4727 {
4728 debug_info *debug_info_p = &debug_information[i];
4729 unsigned int j;
4730
4731 for (j = 0; j < debug_info_p->num_range_lists; j++)
4732 {
4733 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
4734 range_entry_fill->debug_info_p = debug_info_p;
4735 range_entry_fill++;
19e6b90e
L
4736 }
4737 }
4738
01a8f077
JK
4739 qsort (range_entries, num_range_list, sizeof (*range_entries),
4740 range_entry_compar);
19e6b90e 4741
bfe2612a 4742 /* DWARF sections under Mach-O have non-zero addresses. */
4723351a 4743 if (dwarf_check != 0 && range_entries[0].ranges_offset != section->address)
19e6b90e 4744 warn (_("Range lists in %s section start at 0x%lx\n"),
01a8f077 4745 section->name, range_entries[0].ranges_offset);
19e6b90e
L
4746
4747 printf (_("Contents of the %s section:\n\n"), section->name);
4748 printf (_(" Offset Begin End\n"));
4749
01a8f077 4750 for (i = 0; i < num_range_list; i++)
19e6b90e 4751 {
01a8f077
JK
4752 struct range_entry *range_entry = &range_entries[i];
4753 debug_info *debug_info_p = range_entry->debug_info_p;
19e6b90e 4754 unsigned int pointer_size;
01a8f077
JK
4755 unsigned long offset;
4756 unsigned char *next;
19e6b90e
L
4757 unsigned long base_address;
4758
01a8f077
JK
4759 pointer_size = debug_info_p->pointer_size;
4760
4761 /* DWARF sections under Mach-O have non-zero addresses. */
4762 offset = range_entry->ranges_offset - section->address;
4763 next = section_begin + offset;
4764 base_address = debug_info_p->base_address;
cecf136e 4765
4723351a 4766 if (dwarf_check != 0 && i > 0)
19e6b90e 4767 {
01a8f077
JK
4768 if (start < next)
4769 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4770 (unsigned long) (start - section_begin),
4771 (unsigned long) (next - section_begin), section->name);
4772 else if (start > next)
a2ff7a4b
AM
4773 {
4774 if (next == last_start)
4775 continue;
4776 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4777 (unsigned long) (start - section_begin),
4778 (unsigned long) (next - section_begin), section->name);
4779 }
01a8f077
JK
4780 }
4781 start = next;
a2ff7a4b 4782 last_start = next;
19e6b90e 4783
f6f0e17b 4784 while (start < finish)
01a8f077
JK
4785 {
4786 dwarf_vma begin;
4787 dwarf_vma end;
4788
4789 /* Note: we use sign extension here in order to be sure that
4790 we can detect the -1 escape value. Sign extension into the
4791 top 32 bits of a 32-bit address will not affect the values
4792 that we display since we always show hex values, and always
4793 the bottom 32-bits. */
0c588247 4794 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
f6f0e17b
NC
4795 if (start >= finish)
4796 break;
0c588247 4797 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
01a8f077
JK
4798
4799 printf (" %8.8lx ", offset);
4800
4801 if (begin == 0 && end == 0)
19e6b90e 4802 {
01a8f077
JK
4803 printf (_("<End of list>\n"));
4804 break;
19e6b90e 4805 }
19e6b90e 4806
01a8f077
JK
4807 /* Check base address specifiers. */
4808 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
19e6b90e 4809 {
01a8f077
JK
4810 base_address = end;
4811 print_dwarf_vma (begin, pointer_size);
4812 print_dwarf_vma (end, pointer_size);
4813 printf ("(base address)\n");
4814 continue;
4815 }
19e6b90e 4816
01a8f077
JK
4817 print_dwarf_vma (begin + base_address, pointer_size);
4818 print_dwarf_vma (end + base_address, pointer_size);
4a149252 4819
01a8f077
JK
4820 if (begin == end)
4821 fputs (_("(start == end)"), stdout);
4822 else if (begin > end)
4823 fputs (_("(start > end)"), stdout);
19e6b90e 4824
01a8f077 4825 putchar ('\n');
19e6b90e
L
4826 }
4827 }
4828 putchar ('\n');
01a8f077
JK
4829
4830 free (range_entries);
4831
19e6b90e
L
4832 return 1;
4833}
4834
4835typedef struct Frame_Chunk
4836{
4837 struct Frame_Chunk *next;
4838 unsigned char *chunk_start;
4839 int ncols;
4840 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4841 short int *col_type;
4842 int *col_offset;
4843 char *augmentation;
4844 unsigned int code_factor;
4845 int data_factor;
4846 unsigned long pc_begin;
4847 unsigned long pc_range;
4848 int cfa_reg;
4849 int cfa_offset;
4850 int ra;
4851 unsigned char fde_encoding;
4852 unsigned char cfa_exp;
604282a7
JJ
4853 unsigned char ptr_size;
4854 unsigned char segment_size;
19e6b90e
L
4855}
4856Frame_Chunk;
4857
665ce1f6
L
4858static const char *const *dwarf_regnames;
4859static unsigned int dwarf_regnames_count;
4860
19e6b90e
L
4861/* A marker for a col_type that means this column was never referenced
4862 in the frame info. */
4863#define DW_CFA_unreferenced (-1)
4864
665ce1f6
L
4865/* Return 0 if not more space is needed, 1 if more space is needed,
4866 -1 for invalid reg. */
4867
4868static int
4869frame_need_space (Frame_Chunk *fc, unsigned int reg)
19e6b90e
L
4870{
4871 int prev = fc->ncols;
4872
665ce1f6
L
4873 if (reg < (unsigned int) fc->ncols)
4874 return 0;
4875
4876 if (dwarf_regnames_count
4877 && reg > dwarf_regnames_count)
4878 return -1;
19e6b90e
L
4879
4880 fc->ncols = reg + 1;
3f5e193b
NC
4881 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
4882 sizeof (short int));
4883 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
19e6b90e
L
4884
4885 while (prev < fc->ncols)
4886 {
4887 fc->col_type[prev] = DW_CFA_unreferenced;
4888 fc->col_offset[prev] = 0;
4889 prev++;
4890 }
665ce1f6 4891 return 1;
19e6b90e
L
4892}
4893
2dc4cec1
L
4894static const char *const dwarf_regnames_i386[] =
4895{
4896 "eax", "ecx", "edx", "ebx",
4897 "esp", "ebp", "esi", "edi",
4898 "eip", "eflags", NULL,
4899 "st0", "st1", "st2", "st3",
4900 "st4", "st5", "st6", "st7",
4901 NULL, NULL,
4902 "xmm0", "xmm1", "xmm2", "xmm3",
4903 "xmm4", "xmm5", "xmm6", "xmm7",
4904 "mm0", "mm1", "mm2", "mm3",
4905 "mm4", "mm5", "mm6", "mm7",
4906 "fcw", "fsw", "mxcsr",
4907 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
a656ed5b 4908 "tr", "ldtr"
2dc4cec1
L
4909};
4910
b129eb0e
RH
4911void
4912init_dwarf_regnames_i386 (void)
4913{
4914 dwarf_regnames = dwarf_regnames_i386;
4915 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
4916}
4917
2dc4cec1
L
4918static const char *const dwarf_regnames_x86_64[] =
4919{
4920 "rax", "rdx", "rcx", "rbx",
4921 "rsi", "rdi", "rbp", "rsp",
4922 "r8", "r9", "r10", "r11",
4923 "r12", "r13", "r14", "r15",
4924 "rip",
4925 "xmm0", "xmm1", "xmm2", "xmm3",
4926 "xmm4", "xmm5", "xmm6", "xmm7",
4927 "xmm8", "xmm9", "xmm10", "xmm11",
4928 "xmm12", "xmm13", "xmm14", "xmm15",
4929 "st0", "st1", "st2", "st3",
4930 "st4", "st5", "st6", "st7",
4931 "mm0", "mm1", "mm2", "mm3",
4932 "mm4", "mm5", "mm6", "mm7",
4933 "rflags",
4934 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4935 "fs.base", "gs.base", NULL, NULL,
4936 "tr", "ldtr",
a656ed5b 4937 "mxcsr", "fcw", "fsw"
2dc4cec1
L
4938};
4939
b129eb0e
RH
4940void
4941init_dwarf_regnames_x86_64 (void)
4942{
4943 dwarf_regnames = dwarf_regnames_x86_64;
4944 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
4945}
4946
2dc4cec1
L
4947void
4948init_dwarf_regnames (unsigned int e_machine)
4949{
4950 switch (e_machine)
4951 {
4952 case EM_386:
4953 case EM_486:
b129eb0e 4954 init_dwarf_regnames_i386 ();
2dc4cec1
L
4955 break;
4956
4957 case EM_X86_64:
7f502d6c 4958 case EM_L1OM:
7a9068fe 4959 case EM_K1OM:
b129eb0e 4960 init_dwarf_regnames_x86_64 ();
2dc4cec1
L
4961 break;
4962
4963 default:
4964 break;
4965 }
4966}
4967
4968static const char *
4969regname (unsigned int regno, int row)
4970{
4971 static char reg[64];
4972 if (dwarf_regnames
4973 && regno < dwarf_regnames_count
4974 && dwarf_regnames [regno] != NULL)
4975 {
4976 if (row)
4977 return dwarf_regnames [regno];
4978 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
4979 dwarf_regnames [regno]);
4980 }
4981 else
4982 snprintf (reg, sizeof (reg), "r%d", regno);
4983 return reg;
4984}
4985
19e6b90e
L
4986static void
4987frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
4988{
4989 int r;
4990 char tmp[100];
4991
4992 if (*max_regs < fc->ncols)
4993 *max_regs = fc->ncols;
4994
4995 if (*need_col_headers)
4996 {
91d6fa6a 4997 static const char *sloc = " LOC";
2dc4cec1 4998
19e6b90e
L
4999 *need_col_headers = 0;
5000
91d6fa6a 5001 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
19e6b90e
L
5002
5003 for (r = 0; r < *max_regs; r++)
5004 if (fc->col_type[r] != DW_CFA_unreferenced)
5005 {
5006 if (r == fc->ra)
2dc4cec1 5007 printf ("ra ");
19e6b90e 5008 else
2dc4cec1 5009 printf ("%-5s ", regname (r, 1));
19e6b90e
L
5010 }
5011
5012 printf ("\n");
5013 }
5014
2dc4cec1 5015 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
19e6b90e
L
5016 if (fc->cfa_exp)
5017 strcpy (tmp, "exp");
5018 else
2dc4cec1 5019 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
19e6b90e
L
5020 printf ("%-8s ", tmp);
5021
5022 for (r = 0; r < fc->ncols; r++)
5023 {
5024 if (fc->col_type[r] != DW_CFA_unreferenced)
5025 {
5026 switch (fc->col_type[r])
5027 {
5028 case DW_CFA_undefined:
5029 strcpy (tmp, "u");
5030 break;
5031 case DW_CFA_same_value:
5032 strcpy (tmp, "s");
5033 break;
5034 case DW_CFA_offset:
5035 sprintf (tmp, "c%+d", fc->col_offset[r]);
5036 break;
12eae2d3
JJ
5037 case DW_CFA_val_offset:
5038 sprintf (tmp, "v%+d", fc->col_offset[r]);
5039 break;
19e6b90e 5040 case DW_CFA_register:
2dc4cec1 5041 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
19e6b90e
L
5042 break;
5043 case DW_CFA_expression:
5044 strcpy (tmp, "exp");
5045 break;
12eae2d3
JJ
5046 case DW_CFA_val_expression:
5047 strcpy (tmp, "vexp");
5048 break;
19e6b90e
L
5049 default:
5050 strcpy (tmp, "n/a");
5051 break;
5052 }
2dc4cec1 5053 printf ("%-5s ", tmp);
19e6b90e
L
5054 }
5055 }
5056 printf ("\n");
5057}
5058
0c588247 5059#define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end);
f6f0e17b
NC
5060#define LEB() read_uleb128 (start, & length_return, end); start += length_return
5061#define SLEB() read_sleb128 (start, & length_return, end); start += length_return
19e6b90e
L
5062
5063static int
5064display_debug_frames (struct dwarf_section *section,
5065 void *file ATTRIBUTE_UNUSED)
5066{
5067 unsigned char *start = section->start;
5068 unsigned char *end = start + section->size;
5069 unsigned char *section_start = start;
5070 Frame_Chunk *chunks = 0;
5071 Frame_Chunk *remembered_state = 0;
5072 Frame_Chunk *rs;
5073 int is_eh = strcmp (section->name, ".eh_frame") == 0;
5074 unsigned int length_return;
5075 int max_regs = 0;
665ce1f6 5076 const char *bad_reg = _("bad register: ");
604282a7 5077 int saved_eh_addr_size = eh_addr_size;
19e6b90e 5078
80c35038 5079 printf (_("Contents of the %s section:\n"), section->name);
19e6b90e
L
5080
5081 while (start < end)
5082 {
5083 unsigned char *saved_start;
5084 unsigned char *block_end;
5085 unsigned long length;
5086 unsigned long cie_id;
5087 Frame_Chunk *fc;
5088 Frame_Chunk *cie;
5089 int need_col_headers = 1;
5090 unsigned char *augmentation_data = NULL;
5091 unsigned long augmentation_data_len = 0;
604282a7 5092 int encoded_ptr_size = saved_eh_addr_size;
19e6b90e
L
5093 int offset_size;
5094 int initial_length_size;
5095
5096 saved_start = start;
19e6b90e 5097
0c588247 5098 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
19e6b90e
L
5099 if (length == 0)
5100 {
5101 printf ("\n%08lx ZERO terminator\n\n",
5102 (unsigned long)(saved_start - section_start));
b758e50f 5103 continue;
19e6b90e
L
5104 }
5105
5106 if (length == 0xffffffff)
5107 {
0c588247 5108 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
19e6b90e
L
5109 offset_size = 8;
5110 initial_length_size = 12;
5111 }
5112 else
5113 {
5114 offset_size = 4;
5115 initial_length_size = 4;
5116 }
5117
5118 block_end = saved_start + length + initial_length_size;
53b8873b
NC
5119 if (block_end > end)
5120 {
5121 warn ("Invalid length %#08lx in FDE at %#08lx\n",
5122 length, (unsigned long)(saved_start - section_start));
5123 block_end = end;
5124 }
0c588247
NC
5125
5126 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
19e6b90e
L
5127
5128 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
5129 {
5130 int version;
5131
3f5e193b 5132 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
19e6b90e
L
5133 memset (fc, 0, sizeof (Frame_Chunk));
5134
5135 fc->next = chunks;
5136 chunks = fc;
5137 fc->chunk_start = saved_start;
5138 fc->ncols = 0;
3f5e193b
NC
5139 fc->col_type = (short int *) xmalloc (sizeof (short int));
5140 fc->col_offset = (int *) xmalloc (sizeof (int));
cc86f28f 5141 frame_need_space (fc, max_regs - 1);
19e6b90e
L
5142
5143 version = *start++;
5144
5145 fc->augmentation = (char *) start;
5146 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
5147
604282a7
JJ
5148 if (strcmp (fc->augmentation, "eh") == 0)
5149 start += eh_addr_size;
5150
5151 if (version >= 4)
19e6b90e 5152 {
0c588247
NC
5153 GET (fc->ptr_size, 1);
5154 GET (fc->segment_size, 1);
604282a7 5155 eh_addr_size = fc->ptr_size;
19e6b90e 5156 }
604282a7 5157 else
19e6b90e 5158 {
604282a7
JJ
5159 fc->ptr_size = eh_addr_size;
5160 fc->segment_size = 0;
5161 }
5162 fc->code_factor = LEB ();
5163 fc->data_factor = SLEB ();
5164 if (version == 1)
5165 {
0c588247 5166 GET (fc->ra, 1);
19e6b90e
L
5167 }
5168 else
5169 {
604282a7
JJ
5170 fc->ra = LEB ();
5171 }
5172
5173 if (fc->augmentation[0] == 'z')
5174 {
5175 augmentation_data_len = LEB ();
5176 augmentation_data = start;
5177 start += augmentation_data_len;
19e6b90e
L
5178 }
5179 cie = fc;
5180
5181 if (do_debug_frames_interp)
5182 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
5183 (unsigned long)(saved_start - section_start), length, cie_id,
5184 fc->augmentation, fc->code_factor, fc->data_factor,
5185 fc->ra);
5186 else
5187 {
5188 printf ("\n%08lx %08lx %08lx CIE\n",
5189 (unsigned long)(saved_start - section_start), length, cie_id);
5190 printf (" Version: %d\n", version);
5191 printf (" Augmentation: \"%s\"\n", fc->augmentation);
604282a7
JJ
5192 if (version >= 4)
5193 {
5194 printf (" Pointer Size: %u\n", fc->ptr_size);
5195 printf (" Segment Size: %u\n", fc->segment_size);
5196 }
19e6b90e
L
5197 printf (" Code alignment factor: %u\n", fc->code_factor);
5198 printf (" Data alignment factor: %d\n", fc->data_factor);
5199 printf (" Return address column: %d\n", fc->ra);
5200
5201 if (augmentation_data_len)
5202 {
5203 unsigned long i;
5204 printf (" Augmentation data: ");
5205 for (i = 0; i < augmentation_data_len; ++i)
5206 printf (" %02x", augmentation_data[i]);
5207 putchar ('\n');
5208 }
5209 putchar ('\n');
5210 }
5211
5212 if (augmentation_data_len)
5213 {
5214 unsigned char *p, *q;
5215 p = (unsigned char *) fc->augmentation + 1;
5216 q = augmentation_data;
5217
5218 while (1)
5219 {
5220 if (*p == 'L')
5221 q++;
5222 else if (*p == 'P')
5223 q += 1 + size_of_encoded_value (*q);
5224 else if (*p == 'R')
5225 fc->fde_encoding = *q++;
d80e8de2
JB
5226 else if (*p == 'S')
5227 ;
19e6b90e
L
5228 else
5229 break;
5230 p++;
5231 }
5232
5233 if (fc->fde_encoding)
5234 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5235 }
5236
5237 frame_need_space (fc, fc->ra);
5238 }
5239 else
5240 {
5241 unsigned char *look_for;
5242 static Frame_Chunk fde_fc;
604282a7 5243 unsigned long segment_selector;
19e6b90e
L
5244
5245 fc = & fde_fc;
5246 memset (fc, 0, sizeof (Frame_Chunk));
5247
5248 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
5249
5250 for (cie = chunks; cie ; cie = cie->next)
5251 if (cie->chunk_start == look_for)
5252 break;
5253
5254 if (!cie)
5255 {
53b8873b 5256 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
1617e571 5257 cie_id, (unsigned long)(saved_start - section_start));
19e6b90e 5258 fc->ncols = 0;
3f5e193b
NC
5259 fc->col_type = (short int *) xmalloc (sizeof (short int));
5260 fc->col_offset = (int *) xmalloc (sizeof (int));
19e6b90e
L
5261 frame_need_space (fc, max_regs - 1);
5262 cie = fc;
5263 fc->augmentation = "";
5264 fc->fde_encoding = 0;
604282a7
JJ
5265 fc->ptr_size = eh_addr_size;
5266 fc->segment_size = 0;
19e6b90e
L
5267 }
5268 else
5269 {
5270 fc->ncols = cie->ncols;
3f5e193b
NC
5271 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
5272 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
19e6b90e
L
5273 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
5274 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
5275 fc->augmentation = cie->augmentation;
604282a7
JJ
5276 fc->ptr_size = cie->ptr_size;
5277 eh_addr_size = cie->ptr_size;
5278 fc->segment_size = cie->segment_size;
19e6b90e
L
5279 fc->code_factor = cie->code_factor;
5280 fc->data_factor = cie->data_factor;
5281 fc->cfa_reg = cie->cfa_reg;
5282 fc->cfa_offset = cie->cfa_offset;
5283 fc->ra = cie->ra;
cc86f28f 5284 frame_need_space (fc, max_regs - 1);
19e6b90e
L
5285 fc->fde_encoding = cie->fde_encoding;
5286 }
5287
5288 if (fc->fde_encoding)
5289 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5290
604282a7
JJ
5291 segment_selector = 0;
5292 if (fc->segment_size)
5293 {
0c588247 5294 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
604282a7 5295 }
bad62cf5 5296 fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section);
19e6b90e 5297 start += encoded_ptr_size;
19e6b90e 5298
0c588247
NC
5299 /* FIXME: It appears that sometimes the final pc_range value is
5300 encoded in less than encoded_ptr_size bytes. See the x86_64
5301 run of the "objcopy on compressed debug sections" test for an
5302 example of this. */
5303 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
5304
19e6b90e
L
5305 if (cie->augmentation[0] == 'z')
5306 {
5307 augmentation_data_len = LEB ();
5308 augmentation_data = start;
5309 start += augmentation_data_len;
5310 }
5311
604282a7 5312 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
19e6b90e 5313 (unsigned long)(saved_start - section_start), length, cie_id,
604282a7
JJ
5314 (unsigned long)(cie->chunk_start - section_start));
5315 if (fc->segment_size)
5316 printf ("%04lx:", segment_selector);
5317 printf ("%08lx..%08lx\n", fc->pc_begin, fc->pc_begin + fc->pc_range);
19e6b90e
L
5318 if (! do_debug_frames_interp && augmentation_data_len)
5319 {
5320 unsigned long i;
5321
5322 printf (" Augmentation data: ");
5323 for (i = 0; i < augmentation_data_len; ++i)
5324 printf (" %02x", augmentation_data[i]);
5325 putchar ('\n');
5326 putchar ('\n');
5327 }
5328 }
5329
5330 /* At this point, fc is the current chunk, cie (if any) is set, and
5331 we're about to interpret instructions for the chunk. */
5332 /* ??? At present we need to do this always, since this sizes the
5333 fc->col_type and fc->col_offset arrays, which we write into always.
5334 We should probably split the interpreted and non-interpreted bits
5335 into two different routines, since there's so much that doesn't
5336 really overlap between them. */
5337 if (1 || do_debug_frames_interp)
5338 {
5339 /* Start by making a pass over the chunk, allocating storage
5340 and taking note of what registers are used. */
5341 unsigned char *tmp = start;
5342
5343 while (start < block_end)
5344 {
5345 unsigned op, opa;
91d6fa6a 5346 unsigned long reg, temp;
19e6b90e
L
5347
5348 op = *start++;
5349 opa = op & 0x3f;
5350 if (op & 0xc0)
5351 op &= 0xc0;
5352
5353 /* Warning: if you add any more cases to this switch, be
5354 sure to add them to the corresponding switch below. */
5355 switch (op)
5356 {
5357 case DW_CFA_advance_loc:
5358 break;
5359 case DW_CFA_offset:
5360 LEB ();
665ce1f6
L
5361 if (frame_need_space (fc, opa) >= 0)
5362 fc->col_type[opa] = DW_CFA_undefined;
19e6b90e
L
5363 break;
5364 case DW_CFA_restore:
665ce1f6
L
5365 if (frame_need_space (fc, opa) >= 0)
5366 fc->col_type[opa] = DW_CFA_undefined;
19e6b90e
L
5367 break;
5368 case DW_CFA_set_loc:
5369 start += encoded_ptr_size;
5370 break;
5371 case DW_CFA_advance_loc1:
5372 start += 1;
5373 break;
5374 case DW_CFA_advance_loc2:
5375 start += 2;
5376 break;
5377 case DW_CFA_advance_loc4:
5378 start += 4;
5379 break;
5380 case DW_CFA_offset_extended:
12eae2d3 5381 case DW_CFA_val_offset:
19e6b90e 5382 reg = LEB (); LEB ();
665ce1f6
L
5383 if (frame_need_space (fc, reg) >= 0)
5384 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
5385 break;
5386 case DW_CFA_restore_extended:
5387 reg = LEB ();
5388 frame_need_space (fc, reg);
665ce1f6
L
5389 if (frame_need_space (fc, reg) >= 0)
5390 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
5391 break;
5392 case DW_CFA_undefined:
5393 reg = LEB ();
665ce1f6
L
5394 if (frame_need_space (fc, reg) >= 0)
5395 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
5396 break;
5397 case DW_CFA_same_value:
5398 reg = LEB ();
665ce1f6
L
5399 if (frame_need_space (fc, reg) >= 0)
5400 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
5401 break;
5402 case DW_CFA_register:
5403 reg = LEB (); LEB ();
665ce1f6
L
5404 if (frame_need_space (fc, reg) >= 0)
5405 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
5406 break;
5407 case DW_CFA_def_cfa:
5408 LEB (); LEB ();
5409 break;
5410 case DW_CFA_def_cfa_register:
5411 LEB ();
5412 break;
5413 case DW_CFA_def_cfa_offset:
5414 LEB ();
5415 break;
5416 case DW_CFA_def_cfa_expression:
91d6fa6a
NC
5417 temp = LEB ();
5418 start += temp;
19e6b90e
L
5419 break;
5420 case DW_CFA_expression:
12eae2d3 5421 case DW_CFA_val_expression:
19e6b90e 5422 reg = LEB ();
91d6fa6a
NC
5423 temp = LEB ();
5424 start += temp;
665ce1f6
L
5425 if (frame_need_space (fc, reg) >= 0)
5426 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
5427 break;
5428 case DW_CFA_offset_extended_sf:
12eae2d3 5429 case DW_CFA_val_offset_sf:
19e6b90e 5430 reg = LEB (); SLEB ();
665ce1f6
L
5431 if (frame_need_space (fc, reg) >= 0)
5432 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
5433 break;
5434 case DW_CFA_def_cfa_sf:
5435 LEB (); SLEB ();
5436 break;
5437 case DW_CFA_def_cfa_offset_sf:
5438 SLEB ();
5439 break;
5440 case DW_CFA_MIPS_advance_loc8:
5441 start += 8;
5442 break;
5443 case DW_CFA_GNU_args_size:
5444 LEB ();
5445 break;
5446 case DW_CFA_GNU_negative_offset_extended:
5447 reg = LEB (); LEB ();
665ce1f6
L
5448 if (frame_need_space (fc, reg) >= 0)
5449 fc->col_type[reg] = DW_CFA_undefined;
5450 break;
19e6b90e
L
5451 default:
5452 break;
5453 }
5454 }
5455 start = tmp;
5456 }
5457
5458 /* Now we know what registers are used, make a second pass over
5459 the chunk, this time actually printing out the info. */
5460
5461 while (start < block_end)
5462 {
5463 unsigned op, opa;
5464 unsigned long ul, reg, roffs;
5465 long l, ofs;
5466 dwarf_vma vma;
665ce1f6 5467 const char *reg_prefix = "";
19e6b90e
L
5468
5469 op = *start++;
5470 opa = op & 0x3f;
5471 if (op & 0xc0)
5472 op &= 0xc0;
5473
5474 /* Warning: if you add any more cases to this switch, be
5475 sure to add them to the corresponding switch above. */
5476 switch (op)
5477 {
5478 case DW_CFA_advance_loc:
5479 if (do_debug_frames_interp)
5480 frame_display_row (fc, &need_col_headers, &max_regs);
5481 else
5482 printf (" DW_CFA_advance_loc: %d to %08lx\n",
5483 opa * fc->code_factor,
5484 fc->pc_begin + opa * fc->code_factor);
5485 fc->pc_begin += opa * fc->code_factor;
5486 break;
5487
5488 case DW_CFA_offset:
5489 roffs = LEB ();
665ce1f6
L
5490 if (opa >= (unsigned int) fc->ncols)
5491 reg_prefix = bad_reg;
5492 if (! do_debug_frames_interp || *reg_prefix != '\0')
5493 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
5494 reg_prefix, regname (opa, 0),
5495 roffs * fc->data_factor);
5496 if (*reg_prefix == '\0')
5497 {
5498 fc->col_type[opa] = DW_CFA_offset;
5499 fc->col_offset[opa] = roffs * fc->data_factor;
5500 }
19e6b90e
L
5501 break;
5502
5503 case DW_CFA_restore:
665ce1f6
L
5504 if (opa >= (unsigned int) cie->ncols
5505 || opa >= (unsigned int) fc->ncols)
5506 reg_prefix = bad_reg;
5507 if (! do_debug_frames_interp || *reg_prefix != '\0')
5508 printf (" DW_CFA_restore: %s%s\n",
5509 reg_prefix, regname (opa, 0));
5510 if (*reg_prefix == '\0')
5511 {
5512 fc->col_type[opa] = cie->col_type[opa];
5513 fc->col_offset[opa] = cie->col_offset[opa];
b3f5b73b
ILT
5514 if (do_debug_frames_interp
5515 && fc->col_type[opa] == DW_CFA_unreferenced)
5516 fc->col_type[opa] = DW_CFA_undefined;
665ce1f6 5517 }
19e6b90e
L
5518 break;
5519
5520 case DW_CFA_set_loc:
bad62cf5 5521 vma = get_encoded_value (start, fc->fde_encoding, section);
19e6b90e
L
5522 start += encoded_ptr_size;
5523 if (do_debug_frames_interp)
5524 frame_display_row (fc, &need_col_headers, &max_regs);
5525 else
5526 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
5527 fc->pc_begin = vma;
5528 break;
5529
5530 case DW_CFA_advance_loc1:
0c588247 5531 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
19e6b90e
L
5532 if (do_debug_frames_interp)
5533 frame_display_row (fc, &need_col_headers, &max_regs);
5534 else
5535 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
5536 ofs * fc->code_factor,
5537 fc->pc_begin + ofs * fc->code_factor);
5538 fc->pc_begin += ofs * fc->code_factor;
5539 break;
5540
5541 case DW_CFA_advance_loc2:
0c588247 5542 SAFE_BYTE_GET_AND_INC (ofs, start, 2, end);
19e6b90e
L
5543 if (do_debug_frames_interp)
5544 frame_display_row (fc, &need_col_headers, &max_regs);
5545 else
5546 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
5547 ofs * fc->code_factor,
5548 fc->pc_begin + ofs * fc->code_factor);
5549 fc->pc_begin += ofs * fc->code_factor;
5550 break;
5551
5552 case DW_CFA_advance_loc4:
0c588247 5553 SAFE_BYTE_GET_AND_INC (ofs, start, 4, end);
19e6b90e
L
5554 if (do_debug_frames_interp)
5555 frame_display_row (fc, &need_col_headers, &max_regs);
5556 else
5557 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
5558 ofs * fc->code_factor,
5559 fc->pc_begin + ofs * fc->code_factor);
5560 fc->pc_begin += ofs * fc->code_factor;
5561 break;
5562
5563 case DW_CFA_offset_extended:
5564 reg = LEB ();
5565 roffs = LEB ();
665ce1f6
L
5566 if (reg >= (unsigned int) fc->ncols)
5567 reg_prefix = bad_reg;
5568 if (! do_debug_frames_interp || *reg_prefix != '\0')
5569 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
5570 reg_prefix, regname (reg, 0),
5571 roffs * fc->data_factor);
5572 if (*reg_prefix == '\0')
5573 {
5574 fc->col_type[reg] = DW_CFA_offset;
5575 fc->col_offset[reg] = roffs * fc->data_factor;
5576 }
19e6b90e
L
5577 break;
5578
12eae2d3
JJ
5579 case DW_CFA_val_offset:
5580 reg = LEB ();
5581 roffs = LEB ();
665ce1f6
L
5582 if (reg >= (unsigned int) fc->ncols)
5583 reg_prefix = bad_reg;
5584 if (! do_debug_frames_interp || *reg_prefix != '\0')
5585 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
5586 reg_prefix, regname (reg, 0),
5587 roffs * fc->data_factor);
5588 if (*reg_prefix == '\0')
5589 {
5590 fc->col_type[reg] = DW_CFA_val_offset;
5591 fc->col_offset[reg] = roffs * fc->data_factor;
5592 }
12eae2d3
JJ
5593 break;
5594
19e6b90e
L
5595 case DW_CFA_restore_extended:
5596 reg = LEB ();
665ce1f6
L
5597 if (reg >= (unsigned int) cie->ncols
5598 || reg >= (unsigned int) fc->ncols)
5599 reg_prefix = bad_reg;
5600 if (! do_debug_frames_interp || *reg_prefix != '\0')
5601 printf (" DW_CFA_restore_extended: %s%s\n",
5602 reg_prefix, regname (reg, 0));
5603 if (*reg_prefix == '\0')
5604 {
5605 fc->col_type[reg] = cie->col_type[reg];
5606 fc->col_offset[reg] = cie->col_offset[reg];
5607 }
19e6b90e
L
5608 break;
5609
5610 case DW_CFA_undefined:
5611 reg = LEB ();
665ce1f6
L
5612 if (reg >= (unsigned int) fc->ncols)
5613 reg_prefix = bad_reg;
5614 if (! do_debug_frames_interp || *reg_prefix != '\0')
5615 printf (" DW_CFA_undefined: %s%s\n",
5616 reg_prefix, regname (reg, 0));
5617 if (*reg_prefix == '\0')
5618 {
5619 fc->col_type[reg] = DW_CFA_undefined;
5620 fc->col_offset[reg] = 0;
5621 }
19e6b90e
L
5622 break;
5623
5624 case DW_CFA_same_value:
5625 reg = 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_same_value: %s%s\n",
5630 reg_prefix, regname (reg, 0));
5631 if (*reg_prefix == '\0')
5632 {
5633 fc->col_type[reg] = DW_CFA_same_value;
5634 fc->col_offset[reg] = 0;
5635 }
19e6b90e
L
5636 break;
5637
5638 case DW_CFA_register:
5639 reg = LEB ();
5640 roffs = LEB ();
665ce1f6
L
5641 if (reg >= (unsigned int) fc->ncols)
5642 reg_prefix = bad_reg;
5643 if (! do_debug_frames_interp || *reg_prefix != '\0')
2dc4cec1 5644 {
665ce1f6
L
5645 printf (" DW_CFA_register: %s%s in ",
5646 reg_prefix, regname (reg, 0));
2dc4cec1
L
5647 puts (regname (roffs, 0));
5648 }
665ce1f6
L
5649 if (*reg_prefix == '\0')
5650 {
5651 fc->col_type[reg] = DW_CFA_register;
5652 fc->col_offset[reg] = roffs;
5653 }
19e6b90e
L
5654 break;
5655
5656 case DW_CFA_remember_state:
5657 if (! do_debug_frames_interp)
5658 printf (" DW_CFA_remember_state\n");
3f5e193b 5659 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
19e6b90e 5660 rs->ncols = fc->ncols;
3f5e193b
NC
5661 rs->col_type = (short int *) xcmalloc (rs->ncols,
5662 sizeof (short int));
5663 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int));
19e6b90e
L
5664 memcpy (rs->col_type, fc->col_type, rs->ncols);
5665 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
5666 rs->next = remembered_state;
5667 remembered_state = rs;
5668 break;
5669
5670 case DW_CFA_restore_state:
5671 if (! do_debug_frames_interp)
5672 printf (" DW_CFA_restore_state\n");
5673 rs = remembered_state;
5674 if (rs)
5675 {
5676 remembered_state = rs->next;
cc86f28f 5677 frame_need_space (fc, rs->ncols - 1);
19e6b90e
L
5678 memcpy (fc->col_type, rs->col_type, rs->ncols);
5679 memcpy (fc->col_offset, rs->col_offset,
5680 rs->ncols * sizeof (int));
5681 free (rs->col_type);
5682 free (rs->col_offset);
5683 free (rs);
5684 }
5685 else if (do_debug_frames_interp)
5686 printf ("Mismatched DW_CFA_restore_state\n");
5687 break;
5688
5689 case DW_CFA_def_cfa:
5690 fc->cfa_reg = LEB ();
5691 fc->cfa_offset = LEB ();
5692 fc->cfa_exp = 0;
5693 if (! do_debug_frames_interp)
2dc4cec1
L
5694 printf (" DW_CFA_def_cfa: %s ofs %d\n",
5695 regname (fc->cfa_reg, 0), fc->cfa_offset);
19e6b90e
L
5696 break;
5697
5698 case DW_CFA_def_cfa_register:
5699 fc->cfa_reg = LEB ();
5700 fc->cfa_exp = 0;
5701 if (! do_debug_frames_interp)
2dc4cec1
L
5702 printf (" DW_CFA_def_cfa_register: %s\n",
5703 regname (fc->cfa_reg, 0));
19e6b90e
L
5704 break;
5705
5706 case DW_CFA_def_cfa_offset:
5707 fc->cfa_offset = LEB ();
5708 if (! do_debug_frames_interp)
5709 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
5710 break;
5711
5712 case DW_CFA_nop:
5713 if (! do_debug_frames_interp)
5714 printf (" DW_CFA_nop\n");
5715 break;
5716
5717 case DW_CFA_def_cfa_expression:
5718 ul = LEB ();
5719 if (! do_debug_frames_interp)
5720 {
5721 printf (" DW_CFA_def_cfa_expression (");
b7807392
JJ
5722 decode_location_expression (start, eh_addr_size, 0, -1,
5723 ul, 0, section);
19e6b90e
L
5724 printf (")\n");
5725 }
5726 fc->cfa_exp = 1;
5727 start += ul;
5728 break;
5729
5730 case DW_CFA_expression:
5731 reg = LEB ();
5732 ul = LEB ();
665ce1f6
L
5733 if (reg >= (unsigned int) fc->ncols)
5734 reg_prefix = bad_reg;
5735 if (! do_debug_frames_interp || *reg_prefix != '\0')
19e6b90e 5736 {
665ce1f6
L
5737 printf (" DW_CFA_expression: %s%s (",
5738 reg_prefix, regname (reg, 0));
b7807392 5739 decode_location_expression (start, eh_addr_size, 0, -1,
f1c4cc75 5740 ul, 0, section);
19e6b90e
L
5741 printf (")\n");
5742 }
665ce1f6
L
5743 if (*reg_prefix == '\0')
5744 fc->col_type[reg] = DW_CFA_expression;
19e6b90e
L
5745 start += ul;
5746 break;
5747
12eae2d3
JJ
5748 case DW_CFA_val_expression:
5749 reg = LEB ();
5750 ul = LEB ();
665ce1f6
L
5751 if (reg >= (unsigned int) fc->ncols)
5752 reg_prefix = bad_reg;
5753 if (! do_debug_frames_interp || *reg_prefix != '\0')
12eae2d3 5754 {
665ce1f6
L
5755 printf (" DW_CFA_val_expression: %s%s (",
5756 reg_prefix, regname (reg, 0));
b7807392
JJ
5757 decode_location_expression (start, eh_addr_size, 0, -1,
5758 ul, 0, section);
12eae2d3
JJ
5759 printf (")\n");
5760 }
665ce1f6
L
5761 if (*reg_prefix == '\0')
5762 fc->col_type[reg] = DW_CFA_val_expression;
12eae2d3
JJ
5763 start += ul;
5764 break;
5765
19e6b90e
L
5766 case DW_CFA_offset_extended_sf:
5767 reg = LEB ();
5768 l = SLEB ();
665ce1f6
L
5769 if (frame_need_space (fc, reg) < 0)
5770 reg_prefix = bad_reg;
5771 if (! do_debug_frames_interp || *reg_prefix != '\0')
5772 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5773 reg_prefix, regname (reg, 0),
5774 l * fc->data_factor);
5775 if (*reg_prefix == '\0')
5776 {
5777 fc->col_type[reg] = DW_CFA_offset;
5778 fc->col_offset[reg] = l * fc->data_factor;
5779 }
19e6b90e
L
5780 break;
5781
12eae2d3
JJ
5782 case DW_CFA_val_offset_sf:
5783 reg = LEB ();
5784 l = SLEB ();
665ce1f6
L
5785 if (frame_need_space (fc, reg) < 0)
5786 reg_prefix = bad_reg;
5787 if (! do_debug_frames_interp || *reg_prefix != '\0')
5788 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5789 reg_prefix, regname (reg, 0),
5790 l * fc->data_factor);
5791 if (*reg_prefix == '\0')
5792 {
5793 fc->col_type[reg] = DW_CFA_val_offset;
5794 fc->col_offset[reg] = l * fc->data_factor;
5795 }
12eae2d3
JJ
5796 break;
5797
19e6b90e
L
5798 case DW_CFA_def_cfa_sf:
5799 fc->cfa_reg = LEB ();
5800 fc->cfa_offset = SLEB ();
5801 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5802 fc->cfa_exp = 0;
5803 if (! do_debug_frames_interp)
2dc4cec1
L
5804 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5805 regname (fc->cfa_reg, 0), fc->cfa_offset);
19e6b90e
L
5806 break;
5807
5808 case DW_CFA_def_cfa_offset_sf:
5809 fc->cfa_offset = SLEB ();
5810 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5811 if (! do_debug_frames_interp)
5812 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
5813 break;
5814
5815 case DW_CFA_MIPS_advance_loc8:
0c588247 5816 SAFE_BYTE_GET_AND_INC (ofs, start, 8, end);
19e6b90e
L
5817 if (do_debug_frames_interp)
5818 frame_display_row (fc, &need_col_headers, &max_regs);
5819 else
5820 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5821 ofs * fc->code_factor,
5822 fc->pc_begin + ofs * fc->code_factor);
5823 fc->pc_begin += ofs * fc->code_factor;
5824 break;
5825
5826 case DW_CFA_GNU_window_save:
5827 if (! do_debug_frames_interp)
5828 printf (" DW_CFA_GNU_window_save\n");
5829 break;
5830
5831 case DW_CFA_GNU_args_size:
5832 ul = LEB ();
5833 if (! do_debug_frames_interp)
5834 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
5835 break;
5836
5837 case DW_CFA_GNU_negative_offset_extended:
5838 reg = LEB ();
5839 l = - LEB ();
665ce1f6
L
5840 if (frame_need_space (fc, reg) < 0)
5841 reg_prefix = bad_reg;
5842 if (! do_debug_frames_interp || *reg_prefix != '\0')
5843 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5844 reg_prefix, regname (reg, 0),
5845 l * fc->data_factor);
5846 if (*reg_prefix == '\0')
5847 {
5848 fc->col_type[reg] = DW_CFA_offset;
5849 fc->col_offset[reg] = l * fc->data_factor;
5850 }
19e6b90e
L
5851 break;
5852
5853 default:
53b8873b
NC
5854 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
5855 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
5856 else
cecf136e 5857 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
19e6b90e
L
5858 start = block_end;
5859 }
5860 }
5861
5862 if (do_debug_frames_interp)
5863 frame_display_row (fc, &need_col_headers, &max_regs);
5864
5865 start = block_end;
604282a7 5866 eh_addr_size = saved_eh_addr_size;
19e6b90e
L
5867 }
5868
5869 printf ("\n");
5870
5871 return 1;
5872}
5873
5874#undef GET
5875#undef LEB
5876#undef SLEB
5877
5bbdf3d5
DE
5878static int
5879display_gdb_index (struct dwarf_section *section,
5880 void *file ATTRIBUTE_UNUSED)
5881{
5882 unsigned char *start = section->start;
5883 uint32_t version;
5884 uint32_t cu_list_offset, tu_list_offset;
5885 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
5886 unsigned int cu_list_elements, tu_list_elements;
5887 unsigned int address_table_size, symbol_table_slots;
5888 unsigned char *cu_list, *tu_list;
5889 unsigned char *address_table, *symbol_table, *constant_pool;
5890 unsigned int i;
5891
5892 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5893
5894 printf (_("Contents of the %s section:\n"), section->name);
5895
5896 if (section->size < 6 * sizeof (uint32_t))
5897 {
5898 warn (_("Truncated header in the %s section.\n"), section->name);
5899 return 0;
5900 }
5901
5902 version = byte_get_little_endian (start, 4);
da88a764 5903 printf (_("Version %ld\n"), (long) version);
5bbdf3d5
DE
5904
5905 /* Prior versions are obsolete, and future versions may not be
5906 backwards compatible. */
aa170720 5907 if (version < 3 || version > 8)
5bbdf3d5 5908 {
da88a764 5909 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
5bbdf3d5
DE
5910 return 0;
5911 }
8d6eee87
TT
5912 if (version < 4)
5913 warn (_("The address table data in version 3 may be wrong.\n"));
5914 if (version < 5)
5915 warn (_("Version 4 does not support case insensitive lookups.\n"));
5916 if (version < 6)
5917 warn (_("Version 5 does not include inlined functions.\n"));
5918 if (version < 7)
5919 warn (_("Version 6 does not include symbol attributes.\n"));
aa170720
DE
5920 /* Version 7 indices generated by Gold have bad type unit references,
5921 PR binutils/15021. But we don't know if the index was generated by
5922 Gold or not, so to avoid worrying users with gdb-generated indices
5923 we say nothing for version 7 here. */
5bbdf3d5
DE
5924
5925 cu_list_offset = byte_get_little_endian (start + 4, 4);
5926 tu_list_offset = byte_get_little_endian (start + 8, 4);
5927 address_table_offset = byte_get_little_endian (start + 12, 4);
5928 symbol_table_offset = byte_get_little_endian (start + 16, 4);
5929 constant_pool_offset = byte_get_little_endian (start + 20, 4);
5930
5931 if (cu_list_offset > section->size
5932 || tu_list_offset > section->size
5933 || address_table_offset > section->size
5934 || symbol_table_offset > section->size
5935 || constant_pool_offset > section->size)
5936 {
5937 warn (_("Corrupt header in the %s section.\n"), section->name);
5938 return 0;
5939 }
5940
5941 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
5942 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
5943 address_table_size = symbol_table_offset - address_table_offset;
5944 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
5945
5946 cu_list = start + cu_list_offset;
5947 tu_list = start + tu_list_offset;
5948 address_table = start + address_table_offset;
5949 symbol_table = start + symbol_table_offset;
5950 constant_pool = start + constant_pool_offset;
5951
5952 printf (_("\nCU table:\n"));
5953 for (i = 0; i < cu_list_elements; i += 2)
5954 {
5955 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
5956 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
5957
5958 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
5959 (unsigned long) cu_offset,
5960 (unsigned long) (cu_offset + cu_length - 1));
5961 }
5962
5963 printf (_("\nTU table:\n"));
5964 for (i = 0; i < tu_list_elements; i += 3)
5965 {
5966 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
5967 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
5968 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
5969
5970 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
5971 (unsigned long) tu_offset,
5972 (unsigned long) type_offset);
5973 print_dwarf_vma (signature, 8);
5974 printf ("\n");
5975 }
5976
5977 printf (_("\nAddress table:\n"));
5978 for (i = 0; i < address_table_size; i += 2 * 8 + 4)
5979 {
5980 uint64_t low = byte_get_little_endian (address_table + i, 8);
5981 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
5982 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
5983
5984 print_dwarf_vma (low, 8);
5985 print_dwarf_vma (high, 8);
da88a764 5986 printf (_("%lu\n"), (unsigned long) cu_index);
5bbdf3d5
DE
5987 }
5988
5989 printf (_("\nSymbol table:\n"));
5990 for (i = 0; i < symbol_table_slots; ++i)
5991 {
5992 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
5993 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
5994 uint32_t num_cus, cu;
5995
5996 if (name_offset != 0
5997 || cu_vector_offset != 0)
5998 {
5999 unsigned int j;
6000
6001 printf ("[%3u] %s:", i, constant_pool + name_offset);
6002 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
8d6eee87
TT
6003 if (num_cus > 1)
6004 printf ("\n");
5bbdf3d5
DE
6005 for (j = 0; j < num_cus; ++j)
6006 {
7c1cef97 6007 int is_static;
8d6eee87
TT
6008 gdb_index_symbol_kind kind;
6009
5bbdf3d5 6010 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
7c1cef97 6011 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
8d6eee87
TT
6012 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
6013 cu = GDB_INDEX_CU_VALUE (cu);
5bbdf3d5 6014 /* Convert to TU number if it's for a type unit. */
ad6b52dd 6015 if (cu >= cu_list_elements / 2)
8d6eee87
TT
6016 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
6017 (unsigned long) (cu - cu_list_elements / 2));
5bbdf3d5 6018 else
8d6eee87
TT
6019 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
6020
6021 switch (kind)
6022 {
6023 case GDB_INDEX_SYMBOL_KIND_NONE:
6024 printf (_(" [no symbol information]"));
6025 break;
6026 case GDB_INDEX_SYMBOL_KIND_TYPE:
7c1cef97
DE
6027 printf (is_static
6028 ? _(" [static type]")
6029 : _(" [global type]"));
8d6eee87
TT
6030 break;
6031 case GDB_INDEX_SYMBOL_KIND_VARIABLE:
7c1cef97
DE
6032 printf (is_static
6033 ? _(" [static variable]")
6034 : _(" [global variable]"));
8d6eee87
TT
6035 break;
6036 case GDB_INDEX_SYMBOL_KIND_FUNCTION:
7c1cef97
DE
6037 printf (is_static
6038 ? _(" [static function]")
6039 : _(" [global function]"));
8d6eee87
TT
6040 break;
6041 case GDB_INDEX_SYMBOL_KIND_OTHER:
7c1cef97
DE
6042 printf (is_static
6043 ? _(" [static other]")
6044 : _(" [global other]"));
8d6eee87
TT
6045 break;
6046 default:
7c1cef97
DE
6047 printf (is_static
6048 ? _(" [static unknown: %d]")
6049 : _(" [global unknown: %d]"),
6050 kind);
8d6eee87
TT
6051 break;
6052 }
6053 if (num_cus > 1)
6054 printf ("\n");
5bbdf3d5 6055 }
8d6eee87
TT
6056 if (num_cus <= 1)
6057 printf ("\n");
5bbdf3d5
DE
6058 }
6059 }
6060
6061 return 1;
6062}
6063
657d0d47
CC
6064/* Pre-allocate enough space for the CU/TU sets needed. */
6065
6066static void
6067prealloc_cu_tu_list (unsigned int nshndx)
6068{
6069 if (shndx_pool == NULL)
6070 {
6071 shndx_pool_size = nshndx;
6072 shndx_pool_used = 0;
6073 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
6074 sizeof (unsigned int));
6075 }
6076 else
6077 {
6078 shndx_pool_size = shndx_pool_used + nshndx;
6079 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
6080 sizeof (unsigned int));
6081 }
6082}
6083
6084static void
6085add_shndx_to_cu_tu_entry (unsigned int shndx)
6086{
6087 if (shndx_pool_used >= shndx_pool_size)
6088 {
6089 error (_("Internal error: out of space in the shndx pool.\n"));
6090 return;
6091 }
6092 shndx_pool [shndx_pool_used++] = shndx;
6093}
6094
6095static void
6096end_cu_tu_entry (void)
6097{
6098 if (shndx_pool_used >= shndx_pool_size)
6099 {
6100 error (_("Internal error: out of space in the shndx pool.\n"));
6101 return;
6102 }
6103 shndx_pool [shndx_pool_used++] = 0;
6104}
6105
341f9135
CC
6106/* Return the short name of a DWARF section given by a DW_SECT enumerator. */
6107
6108static const char *
6109get_DW_SECT_short_name (unsigned int dw_sect)
6110{
6111 static char buf[16];
6112
6113 switch (dw_sect)
6114 {
6115 case DW_SECT_INFO:
6116 return "info";
6117 case DW_SECT_TYPES:
6118 return "types";
6119 case DW_SECT_ABBREV:
6120 return "abbrev";
6121 case DW_SECT_LINE:
6122 return "line";
6123 case DW_SECT_LOC:
6124 return "loc";
6125 case DW_SECT_STR_OFFSETS:
6126 return "str_off";
6127 case DW_SECT_MACINFO:
6128 return "macinfo";
6129 case DW_SECT_MACRO:
6130 return "macro";
6131 default:
6132 break;
6133 }
6134
6135 snprintf (buf, sizeof (buf), "%d", dw_sect);
6136 return buf;
6137}
6138
6139/* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
6140 These sections are extensions for Fission.
6141 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
657d0d47
CC
6142
6143static int
6144process_cu_tu_index (struct dwarf_section *section, int do_display)
6145{
6146 unsigned char *phdr = section->start;
6147 unsigned char *limit = phdr + section->size;
6148 unsigned char *phash;
6149 unsigned char *pindex;
6150 unsigned char *ppool;
6151 unsigned int version;
341f9135 6152 unsigned int ncols = 0;
657d0d47
CC
6153 unsigned int nused;
6154 unsigned int nslots;
6155 unsigned int i;
341f9135
CC
6156 unsigned int j;
6157 dwarf_vma signature_high;
6158 dwarf_vma signature_low;
6159 char buf[64];
657d0d47
CC
6160
6161 version = byte_get (phdr, 4);
341f9135
CC
6162 if (version >= 2)
6163 ncols = byte_get (phdr + 4, 4);
657d0d47
CC
6164 nused = byte_get (phdr + 8, 4);
6165 nslots = byte_get (phdr + 12, 4);
6166 phash = phdr + 16;
6167 pindex = phash + nslots * 8;
6168 ppool = pindex + nslots * 4;
6169
657d0d47
CC
6170 if (do_display)
6171 {
6172 printf (_("Contents of the %s section:\n\n"), section->name);
6173 printf (_(" Version: %d\n"), version);
341f9135
CC
6174 if (version >= 2)
6175 printf (_(" Number of columns: %d\n"), ncols);
657d0d47
CC
6176 printf (_(" Number of used entries: %d\n"), nused);
6177 printf (_(" Number of slots: %d\n\n"), nslots);
6178 }
6179
6180 if (ppool > limit)
6181 {
6182 warn (_("Section %s too small for %d hash table entries\n"),
6183 section->name, nslots);
6184 return 0;
6185 }
6186
341f9135 6187 if (version == 1)
657d0d47 6188 {
341f9135
CC
6189 if (!do_display)
6190 prealloc_cu_tu_list ((limit - ppool) / 4);
6191 for (i = 0; i < nslots; i++)
657d0d47 6192 {
341f9135
CC
6193 unsigned char *shndx_list;
6194 unsigned int shndx;
6195
6196 byte_get_64 (phash, &signature_high, &signature_low);
6197 if (signature_high != 0 || signature_low != 0)
657d0d47 6198 {
341f9135
CC
6199 j = byte_get (pindex, 4);
6200 shndx_list = ppool + j * 4;
6201 if (do_display)
6202 printf (_(" [%3d] Signature: 0x%s Sections: "),
6203 i, dwarf_vmatoa64 (signature_high, signature_low,
6204 buf, sizeof (buf)));
6205 for (;;)
657d0d47 6206 {
341f9135
CC
6207 if (shndx_list >= limit)
6208 {
6209 warn (_("Section %s too small for shndx pool\n"),
6210 section->name);
6211 return 0;
6212 }
6213 shndx = byte_get (shndx_list, 4);
6214 if (shndx == 0)
6215 break;
6216 if (do_display)
6217 printf (" %d", shndx);
6218 else
6219 add_shndx_to_cu_tu_entry (shndx);
6220 shndx_list += 4;
657d0d47 6221 }
657d0d47 6222 if (do_display)
341f9135 6223 printf ("\n");
657d0d47 6224 else
341f9135
CC
6225 end_cu_tu_entry ();
6226 }
6227 phash += 8;
6228 pindex += 4;
6229 }
6230 }
6231 else if (version == 2)
6232 {
6233 unsigned int val;
6234 unsigned int dw_sect;
6235 unsigned char *ph = phash;
6236 unsigned char *pi = pindex;
6237 unsigned char *poffsets = ppool + ncols * 4;
6238 unsigned char *psizes = poffsets + nused * ncols * 4;
6239 unsigned char *pend = psizes + nused * ncols * 4;
6240 bfd_boolean is_tu_index;
6241 struct cu_tu_set *this_set = NULL;
6242 unsigned int row;
6243 unsigned char *prow;
6244
6245 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
6246
6247 if (pend > limit)
6248 {
6249 warn (_("Section %s too small for offset and size tables\n"),
6250 section->name);
6251 return 0;
6252 }
6253
6254 if (do_display)
6255 {
6256 printf (_(" Offset table\n"));
6257 printf (" slot %-16s ",
6258 is_tu_index ? _("signature") : _("dwo_id"));
6259 }
6260 else
6261 {
6262 if (is_tu_index)
6263 {
6264 tu_count = nused;
6265 tu_sets = xcmalloc (nused, sizeof (struct cu_tu_set));
6266 this_set = tu_sets;
657d0d47 6267 }
657d0d47 6268 else
341f9135
CC
6269 {
6270 cu_count = nused;
6271 cu_sets = xcmalloc (nused, sizeof (struct cu_tu_set));
6272 this_set = cu_sets;
6273 }
6274 }
6275 if (do_display)
6276 {
6277 for (j = 0; j < ncols; j++)
6278 {
6279 dw_sect = byte_get (ppool + j * 4, 4);
6280 printf (" %8s", get_DW_SECT_short_name (dw_sect));
6281 }
6282 printf ("\n");
6283 }
6284 for (i = 0; i < nslots; i++)
6285 {
6286 byte_get_64 (ph, &signature_high, &signature_low);
6287 row = byte_get (pi, 4);
6288 if (row != 0)
6289 {
6290 if (!do_display)
6291 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
6292 prow = poffsets + (row - 1) * ncols * 4;
6293 if (do_display)
6294 printf (_(" [%3d] 0x%s"),
6295 i, dwarf_vmatoa64 (signature_high, signature_low,
6296 buf, sizeof (buf)));
6297 for (j = 0; j < ncols; j++)
6298 {
6299 val = byte_get (prow + j * 4, 4);
6300 if (do_display)
6301 printf (" %8d", val);
6302 else
6303 {
6304 dw_sect = byte_get (ppool + j * 4, 4);
6305 this_set [row - 1].section_offsets [dw_sect] = val;
6306 }
6307 }
6308 if (do_display)
6309 printf ("\n");
6310 }
6311 ph += 8;
6312 pi += 4;
6313 }
6314
6315 ph = phash;
6316 pi = pindex;
6317 if (do_display)
6318 {
6319 printf ("\n");
6320 printf (_(" Size table\n"));
6321 printf (" slot %-16s ",
6322 is_tu_index ? _("signature") : _("dwo_id"));
6323 }
6324 for (j = 0; j < ncols; j++)
6325 {
6326 val = byte_get (ppool + j * 4, 4);
6327 if (do_display)
6328 printf (" %8s", get_DW_SECT_short_name (val));
6329 }
6330 if (do_display)
6331 printf ("\n");
6332 for (i = 0; i < nslots; i++)
6333 {
6334 byte_get_64 (ph, &signature_high, &signature_low);
6335 row = byte_get (pi, 4);
6336 if (row != 0)
6337 {
6338 prow = psizes + (row - 1) * ncols * 4;
6339 if (do_display)
6340 printf (_(" [%3d] 0x%s"),
6341 i, dwarf_vmatoa64 (signature_high, signature_low,
6342 buf, sizeof (buf)));
6343 for (j = 0; j < ncols; j++)
6344 {
6345 val = byte_get (prow + j * 4, 4);
6346 if (do_display)
6347 printf (" %8d", val);
6348 else
6349 {
6350 dw_sect = byte_get (ppool + j * 4, 4);
6351 this_set [row - 1].section_sizes [dw_sect] = val;
6352 }
6353 }
6354 if (do_display)
6355 printf ("\n");
6356 }
6357 ph += 8;
6358 pi += 4;
657d0d47 6359 }
657d0d47 6360 }
341f9135
CC
6361 else if (do_display)
6362 printf (_(" Unsupported version\n"));
657d0d47
CC
6363
6364 if (do_display)
6365 printf ("\n");
6366
6367 return 1;
6368}
6369
6370/* Load the CU and TU indexes if present. This will build a list of
6371 section sets that we can use to associate a .debug_info.dwo section
6372 with its associated .debug_abbrev.dwo section in a .dwp file. */
6373
6374static void
6375load_cu_tu_indexes (void *file)
6376{
6377 /* If we have already loaded (or tried to load) the CU and TU indexes
6378 then do not bother to repeat the task. */
6379 if (cu_tu_indexes_read)
6380 return;
6381
6382 if (load_debug_section (dwp_cu_index, file))
6383 process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0);
6384
6385 if (load_debug_section (dwp_tu_index, file))
6386 process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0);
6387
6388 cu_tu_indexes_read = 1;
6389}
6390
6391/* Find the set of sections that includes section SHNDX. */
6392
6393unsigned int *
6394find_cu_tu_set (void *file, unsigned int shndx)
6395{
6396 unsigned int i;
6397
6398 load_cu_tu_indexes (file);
6399
6400 /* Find SHNDX in the shndx pool. */
6401 for (i = 0; i < shndx_pool_used; i++)
6402 if (shndx_pool [i] == shndx)
6403 break;
6404
6405 if (i >= shndx_pool_used)
6406 return NULL;
6407
6408 /* Now backup to find the first entry in the set. */
6409 while (i > 0 && shndx_pool [i - 1] != 0)
6410 i--;
6411
6412 return shndx_pool + i;
6413}
6414
6415/* Display a .debug_cu_index or .debug_tu_index section. */
6416
6417static int
6418display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
6419{
6420 return process_cu_tu_index (section, 1);
6421}
6422
19e6b90e
L
6423static int
6424display_debug_not_supported (struct dwarf_section *section,
6425 void *file ATTRIBUTE_UNUSED)
6426{
6427 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
6428 section->name);
6429
6430 return 1;
6431}
6432
6433void *
6434cmalloc (size_t nmemb, size_t size)
6435{
6436 /* Check for overflow. */
6437 if (nmemb >= ~(size_t) 0 / size)
6438 return NULL;
6439 else
6440 return malloc (nmemb * size);
6441}
6442
6443void *
6444xcmalloc (size_t nmemb, size_t size)
6445{
6446 /* Check for overflow. */
6447 if (nmemb >= ~(size_t) 0 / size)
6448 return NULL;
6449 else
6450 return xmalloc (nmemb * size);
6451}
6452
6453void *
6454xcrealloc (void *ptr, size_t nmemb, size_t size)
6455{
6456 /* Check for overflow. */
6457 if (nmemb >= ~(size_t) 0 / size)
6458 return NULL;
6459 else
6460 return xrealloc (ptr, nmemb * size);
6461}
6462
19e6b90e
L
6463void
6464free_debug_memory (void)
6465{
3f5e193b 6466 unsigned int i;
19e6b90e
L
6467
6468 free_abbrevs ();
6469
6470 for (i = 0; i < max; i++)
3f5e193b 6471 free_debug_section ((enum dwarf_section_display_enum) i);
19e6b90e 6472
cc86f28f 6473 if (debug_information != NULL)
19e6b90e 6474 {
cc86f28f 6475 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
19e6b90e 6476 {
cc86f28f 6477 for (i = 0; i < num_debug_info_entries; i++)
19e6b90e 6478 {
cc86f28f
NC
6479 if (!debug_information [i].max_loc_offsets)
6480 {
6481 free (debug_information [i].loc_offsets);
6482 free (debug_information [i].have_frame_base);
6483 }
6484 if (!debug_information [i].max_range_lists)
6485 free (debug_information [i].range_lists);
19e6b90e 6486 }
19e6b90e 6487 }
cc86f28f 6488
19e6b90e
L
6489 free (debug_information);
6490 debug_information = NULL;
6491 num_debug_info_entries = 0;
6492 }
19e6b90e
L
6493}
6494
4cb93e3b
TG
6495void
6496dwarf_select_sections_by_names (const char *names)
6497{
6498 typedef struct
6499 {
6500 const char * option;
6501 int * variable;
f9f0e732 6502 int val;
4cb93e3b
TG
6503 }
6504 debug_dump_long_opts;
6505
6506 static const debug_dump_long_opts opts_table [] =
6507 {
6508 /* Please keep this table alpha- sorted. */
6509 { "Ranges", & do_debug_ranges, 1 },
6510 { "abbrev", & do_debug_abbrevs, 1 },
657d0d47 6511 { "addr", & do_debug_addr, 1 },
4cb93e3b 6512 { "aranges", & do_debug_aranges, 1 },
657d0d47
CC
6513 { "cu_index", & do_debug_cu_index, 1 },
6514 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
4cb93e3b
TG
6515 { "frames", & do_debug_frames, 1 },
6516 { "frames-interp", & do_debug_frames_interp, 1 },
657d0d47
CC
6517 /* The special .gdb_index section. */
6518 { "gdb_index", & do_gdb_index, 1 },
4cb93e3b
TG
6519 { "info", & do_debug_info, 1 },
6520 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
4cb93e3b
TG
6521 { "loc", & do_debug_loc, 1 },
6522 { "macro", & do_debug_macinfo, 1 },
6523 { "pubnames", & do_debug_pubnames, 1 },
357da287 6524 { "pubtypes", & do_debug_pubtypes, 1 },
4cb93e3b
TG
6525 /* This entry is for compatability
6526 with earlier versions of readelf. */
6527 { "ranges", & do_debug_aranges, 1 },
657d0d47 6528 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
4cb93e3b 6529 { "str", & do_debug_str, 1 },
6f875884
TG
6530 /* These trace_* sections are used by Itanium VMS. */
6531 { "trace_abbrev", & do_trace_abbrevs, 1 },
6532 { "trace_aranges", & do_trace_aranges, 1 },
6533 { "trace_info", & do_trace_info, 1 },
4cb93e3b
TG
6534 { NULL, NULL, 0 }
6535 };
6536
6537 const char *p;
467c65bc 6538
4cb93e3b
TG
6539 p = names;
6540 while (*p)
6541 {
6542 const debug_dump_long_opts * entry;
467c65bc 6543
4cb93e3b
TG
6544 for (entry = opts_table; entry->option; entry++)
6545 {
6546 size_t len = strlen (entry->option);
467c65bc 6547
4cb93e3b
TG
6548 if (strncmp (p, entry->option, len) == 0
6549 && (p[len] == ',' || p[len] == '\0'))
6550 {
6551 * entry->variable |= entry->val;
467c65bc 6552
4cb93e3b
TG
6553 /* The --debug-dump=frames-interp option also
6554 enables the --debug-dump=frames option. */
6555 if (do_debug_frames_interp)
6556 do_debug_frames = 1;
6557
6558 p += len;
6559 break;
6560 }
6561 }
467c65bc 6562
4cb93e3b
TG
6563 if (entry->option == NULL)
6564 {
6565 warn (_("Unrecognized debug option '%s'\n"), p);
6566 p = strchr (p, ',');
6567 if (p == NULL)
6568 break;
6569 }
467c65bc 6570
4cb93e3b
TG
6571 if (*p == ',')
6572 p++;
6573 }
6574}
6575
6576void
6577dwarf_select_sections_by_letters (const char *letters)
6578{
91d6fa6a 6579 unsigned int lindex = 0;
4cb93e3b 6580
91d6fa6a
NC
6581 while (letters[lindex])
6582 switch (letters[lindex++])
4cb93e3b
TG
6583 {
6584 case 'i':
6585 do_debug_info = 1;
6586 break;
467c65bc 6587
4cb93e3b
TG
6588 case 'a':
6589 do_debug_abbrevs = 1;
6590 break;
467c65bc 6591
4cb93e3b
TG
6592 case 'l':
6593 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
6594 break;
467c65bc 6595
4cb93e3b
TG
6596 case 'L':
6597 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
6598 break;
467c65bc 6599
4cb93e3b
TG
6600 case 'p':
6601 do_debug_pubnames = 1;
6602 break;
467c65bc 6603
f9f0e732
NC
6604 case 't':
6605 do_debug_pubtypes = 1;
6606 break;
467c65bc 6607
4cb93e3b
TG
6608 case 'r':
6609 do_debug_aranges = 1;
6610 break;
467c65bc 6611
4cb93e3b
TG
6612 case 'R':
6613 do_debug_ranges = 1;
6614 break;
467c65bc 6615
4cb93e3b
TG
6616 case 'F':
6617 do_debug_frames_interp = 1;
6618 case 'f':
6619 do_debug_frames = 1;
6620 break;
467c65bc 6621
4cb93e3b
TG
6622 case 'm':
6623 do_debug_macinfo = 1;
6624 break;
467c65bc 6625
4cb93e3b
TG
6626 case 's':
6627 do_debug_str = 1;
6628 break;
467c65bc 6629
4cb93e3b
TG
6630 case 'o':
6631 do_debug_loc = 1;
6632 break;
467c65bc 6633
4cb93e3b
TG
6634 default:
6635 warn (_("Unrecognized debug option '%s'\n"), optarg);
6636 break;
6637 }
6638}
6639
6640void
6641dwarf_select_sections_all (void)
6642{
6643 do_debug_info = 1;
6644 do_debug_abbrevs = 1;
6645 do_debug_lines = FLAG_DEBUG_LINES_RAW;
6646 do_debug_pubnames = 1;
f9f0e732 6647 do_debug_pubtypes = 1;
4cb93e3b
TG
6648 do_debug_aranges = 1;
6649 do_debug_ranges = 1;
6650 do_debug_frames = 1;
6651 do_debug_macinfo = 1;
6652 do_debug_str = 1;
6653 do_debug_loc = 1;
5bbdf3d5 6654 do_gdb_index = 1;
6f875884
TG
6655 do_trace_info = 1;
6656 do_trace_abbrevs = 1;
6657 do_trace_aranges = 1;
657d0d47
CC
6658 do_debug_addr = 1;
6659 do_debug_cu_index = 1;
4cb93e3b
TG
6660}
6661
19e6b90e
L
6662struct dwarf_section_display debug_displays[] =
6663{
657d0d47 6664 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0 },
4723351a 6665 display_debug_abbrev, &do_debug_abbrevs, 0 },
657d0d47 6666 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0 },
4723351a 6667 display_debug_aranges, &do_debug_aranges, 1 },
657d0d47 6668 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0 },
4723351a
CC
6669 display_debug_frames, &do_debug_frames, 1 },
6670 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev },
6671 display_debug_info, &do_debug_info, 1 },
657d0d47 6672 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0 },
4723351a 6673 display_debug_lines, &do_debug_lines, 1 },
657d0d47 6674 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0 },
4723351a 6675 display_debug_pubnames, &do_debug_pubnames, 0 },
657d0d47 6676 { { ".eh_frame", "", NULL, NULL, 0, 0, 0 },
4723351a 6677 display_debug_frames, &do_debug_frames, 1 },
657d0d47 6678 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0 },
4723351a 6679 display_debug_macinfo, &do_debug_macinfo, 0 },
657d0d47 6680 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0 },
4723351a 6681 display_debug_macro, &do_debug_macinfo, 1 },
657d0d47 6682 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0 },
4723351a 6683 display_debug_str, &do_debug_str, 0 },
657d0d47 6684 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0 },
4723351a 6685 display_debug_loc, &do_debug_loc, 1 },
657d0d47 6686 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0 },
4723351a 6687 display_debug_pubnames, &do_debug_pubtypes, 0 },
657d0d47 6688 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0 },
4723351a 6689 display_debug_ranges, &do_debug_ranges, 1 },
657d0d47 6690 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0 },
4723351a 6691 display_debug_not_supported, NULL, 0 },
657d0d47 6692 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0 },
4723351a
CC
6693 display_debug_not_supported, NULL, 0 },
6694 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev },
6695 display_debug_types, &do_debug_info, 1 },
657d0d47 6696 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0 },
4723351a 6697 display_debug_not_supported, NULL, 0 },
657d0d47
CC
6698 { { ".gdb_index", "", NULL, NULL, 0, 0, 0 },
6699 display_gdb_index, &do_gdb_index, 0 },
4723351a 6700 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev },
657d0d47
CC
6701 display_trace_info, &do_trace_info, 1 },
6702 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0 },
6703 display_debug_abbrev, &do_trace_abbrevs, 0 },
6704 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0 },
6705 display_debug_aranges, &do_trace_aranges, 0 },
4723351a 6706 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo },
657d0d47
CC
6707 display_debug_info, &do_debug_info, 1 },
6708 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0 },
6709 display_debug_abbrev, &do_debug_abbrevs, 0 },
4723351a 6710 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo },
657d0d47
CC
6711 display_debug_types, &do_debug_info, 1 },
6712 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0 },
6713 display_debug_lines, &do_debug_lines, 1 },
6714 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0 },
4723351a 6715 display_debug_loc, &do_debug_loc, 1 },
657d0d47 6716 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0 },
4723351a 6717 display_debug_macro, &do_debug_macinfo, 1 },
657d0d47 6718 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0 },
4723351a 6719 display_debug_macinfo, &do_debug_macinfo, 0 },
657d0d47
CC
6720 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0 },
6721 display_debug_str, &do_debug_str, 1 },
6722 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0 },
4723351a 6723 display_debug_str_offsets, NULL, 0 },
657d0d47 6724 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0 },
4723351a 6725 display_debug_str_offsets, NULL, 0 },
657d0d47
CC
6726 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0 },
6727 display_debug_addr, &do_debug_addr, 1 },
6728 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0 },
6729 display_cu_index, &do_debug_cu_index, 0 },
6730 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0 },
6731 display_cu_index, &do_debug_cu_index, 0 },
19e6b90e 6732};
This page took 0.696997 seconds and 4 git commands to generate.