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