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