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