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