Fix build failure in darwin-nat.c
[deliverable/binutils-gdb.git] / binutils / dwarf.c
CommitLineData
19e6b90e 1/* dwarf.c -- display DWARF contents of a BFD binary file
2571583a 2 Copyright (C) 2005-2017 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"
dda8d76d 31#include "filenames.h"
61364358
JK
32#include <assert.h>
33
34#undef MAX
35#undef MIN
36#define MAX(a, b) ((a) > (b) ? (a) : (b))
37#define MIN(a, b) ((a) < (b) ? (a) : (b))
19e6b90e 38
18464d4d
JK
39static const char *regname (unsigned int regno, int row);
40
19e6b90e
L
41static int have_frame_base;
42static int need_base_address;
43
19e6b90e 44static unsigned int num_debug_info_entries = 0;
82b1b41b 45static unsigned int alloc_num_debug_info_entries = 0;
19e6b90e 46static debug_info *debug_information = NULL;
cc86f28f
NC
47/* Special value for num_debug_info_entries to indicate
48 that the .debug_info section could not be loaded/parsed. */
49#define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
19e6b90e 50
77ef8654 51unsigned int eh_addr_size;
19e6b90e
L
52
53int do_debug_info;
54int do_debug_abbrevs;
55int do_debug_lines;
56int do_debug_pubnames;
f9f0e732 57int do_debug_pubtypes;
19e6b90e
L
58int do_debug_aranges;
59int do_debug_ranges;
60int do_debug_frames;
61int do_debug_frames_interp;
62int do_debug_macinfo;
63int do_debug_str;
64int do_debug_loc;
5bbdf3d5 65int do_gdb_index;
6f875884
TG
66int do_trace_info;
67int do_trace_abbrevs;
68int do_trace_aranges;
657d0d47
CC
69int do_debug_addr;
70int do_debug_cu_index;
a262ae96 71int do_wide;
dda8d76d
NC
72int do_debug_links;
73int do_follow_links;
19e6b90e 74
fd2f0033
TT
75int dwarf_cutoff_level = -1;
76unsigned long dwarf_start_die;
77
4723351a
CC
78int dwarf_check = 0;
79
9f272209
AO
80/* Convenient constant, to avoid having to cast -1 to dwarf_vma when
81 testing whether e.g. a locview list is present. */
82static const dwarf_vma vm1 = -1;
83
341f9135
CC
84/* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
85 sections. For version 1 package files, each set is stored in SHNDX_POOL
86 as a zero-terminated list of section indexes comprising one set of debug
87 sections from a .dwo file. */
88
341f9135
CC
89static unsigned int *shndx_pool = NULL;
90static unsigned int shndx_pool_size = 0;
91static unsigned int shndx_pool_used = 0;
92
dda8d76d
NC
93/* Pointer to a separate file containing extra debug information. */
94static void * separate_debug_file = NULL;
95static const char * separate_debug_filename = NULL;
96
341f9135
CC
97/* For version 2 package files, each set contains an array of section offsets
98 and an array of section sizes, giving the offset and size of the
99 contribution from a CU or TU within one of the debug sections.
100 When displaying debug info from a package file, we need to use these
101 tables to locate the corresponding contributions to each section. */
102
103struct cu_tu_set
104{
105 uint64_t signature;
106 dwarf_vma section_offsets[DW_SECT_MAX];
107 size_t section_sizes[DW_SECT_MAX];
108};
109
110static int cu_count = 0;
111static int tu_count = 0;
112static struct cu_tu_set *cu_sets = NULL;
113static struct cu_tu_set *tu_sets = NULL;
114
43a444f9 115static bfd_boolean load_cu_tu_indexes (void *);
341f9135 116
4cb93e3b
TG
117/* Values for do_debug_lines. */
118#define FLAG_DEBUG_LINES_RAW 1
119#define FLAG_DEBUG_LINES_DECODED 2
120
77ef8654 121static unsigned int
f1c4cc75
RH
122size_of_encoded_value (int encoding)
123{
124 switch (encoding & 0x7)
125 {
126 default: /* ??? */
127 case 0: return eh_addr_size;
128 case 2: return 2;
129 case 3: return 4;
130 case 4: return 8;
131 }
132}
133
134static dwarf_vma
041830e0 135get_encoded_value (unsigned char **pdata,
bad62cf5 136 int encoding,
041830e0
NC
137 struct dwarf_section *section,
138 unsigned char * end)
f1c4cc75 139{
041830e0 140 unsigned char * data = * pdata;
6937bb54 141 unsigned int size = size_of_encoded_value (encoding);
bad62cf5 142 dwarf_vma val;
f1c4cc75 143
041830e0
NC
144 if (data + size >= end)
145 {
146 warn (_("Encoded value extends past end of section\n"));
147 * pdata = end;
148 return 0;
149 }
150
6937bb54
NC
151 /* PR 17512: file: 002-829853-0.004. */
152 if (size > 8)
153 {
154 warn (_("Encoded size of %d is too large to read\n"), size);
155 * pdata = end;
156 return 0;
157 }
158
0a9d414a
NC
159 /* PR 17512: file: 1085-5603-0.004. */
160 if (size == 0)
161 {
162 warn (_("Encoded size of 0 is too small to read\n"));
163 * pdata = end;
164 return 0;
165 }
166
f1c4cc75 167 if (encoding & DW_EH_PE_signed)
bad62cf5 168 val = byte_get_signed (data, size);
f1c4cc75 169 else
bad62cf5
AM
170 val = byte_get (data, size);
171
172 if ((encoding & 0x70) == DW_EH_PE_pcrel)
173 val += section->address + (data - section->start);
041830e0
NC
174
175 * pdata = data + size;
bad62cf5 176 return val;
f1c4cc75
RH
177}
178
4c219c2e
AM
179#if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
180# ifndef __MINGW32__
181# define DWARF_VMA_FMT "ll"
182# define DWARF_VMA_FMT_LONG "%16.16llx"
183# else
184# define DWARF_VMA_FMT "I64"
185# define DWARF_VMA_FMT_LONG "%016I64x"
186# endif
2e14fae2 187#else
4c219c2e
AM
188# define DWARF_VMA_FMT "l"
189# define DWARF_VMA_FMT_LONG "%16.16lx"
2d9472a2
NC
190#endif
191
bf5117e3
NC
192/* Convert a dwarf vma value into a string. Returns a pointer to a static
193 buffer containing the converted VALUE. The value is converted according
194 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
195 it specifies the maximum number of bytes to be displayed in the converted
196 value and FMTCH is ignored - hex is always used. */
467c65bc 197
47704ddf 198static const char *
bf5117e3 199dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes)
47704ddf
KT
200{
201 /* As dwarf_vmatoa is used more then once in a printf call
202 for output, we are cycling through an fixed array of pointers
203 for return address. */
204 static int buf_pos = 0;
467c65bc
NC
205 static struct dwarf_vmatoa_buf
206 {
47704ddf
KT
207 char place[64];
208 } buf[16];
47704ddf
KT
209 char *ret;
210
47704ddf 211 ret = buf[buf_pos++].place;
467c65bc 212 buf_pos %= ARRAY_SIZE (buf);
47704ddf 213
bf5117e3
NC
214 if (num_bytes)
215 {
222c2bf0 216 /* Printf does not have a way of specifying a maximum field width for an
bf5117e3
NC
217 integer value, so we print the full value into a buffer and then select
218 the precision we need. */
219 snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value);
220 if (num_bytes > 8)
221 num_bytes = 8;
222 return ret + (16 - 2 * num_bytes);
223 }
224 else
225 {
226 char fmt[32];
227
0bae9e9e
NC
228 if (fmtch)
229 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
230 else
231 sprintf (fmt, "%%%s", DWARF_VMA_FMT);
bf5117e3
NC
232 snprintf (ret, sizeof (buf[0].place), fmt, value);
233 return ret;
234 }
235}
47704ddf 236
bf5117e3
NC
237static inline const char *
238dwarf_vmatoa (const char * fmtch, dwarf_vma value)
239{
240 return dwarf_vmatoa_1 (fmtch, value, 0);
241}
242
243/* Print a dwarf_vma value (typically an address, offset or length) in
244 hexadecimal format, followed by a space. The length of the VALUE (and
245 hence the precision displayed) is determined by the NUM_BYTES parameter. */
246
247static void
248print_dwarf_vma (dwarf_vma value, unsigned num_bytes)
249{
250 printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes));
47704ddf
KT
251}
252
9f272209
AO
253/* Print a view number in hexadecimal value, with the same width
254 print_dwarf_vma would have printed it with the same num_bytes.
255 Print blanks for zero view, unless force is nonzero. */
256
257static void
258print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force)
259{
260 int len;
261 if (!num_bytes)
262 len = 4;
263 else
264 len = num_bytes * 2;
265
266 assert (value == (unsigned long) value);
267 if (value || force)
268 printf ("v%0*lx ", len - 1, (unsigned long) value);
269 else
270 printf ("%*s", len + 1, "");
271}
272
74bc6052
CC
273/* Format a 64-bit value, given as two 32-bit values, in hex.
274 For reentrancy, this uses a buffer provided by the caller. */
275
276static const char *
277dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
278 unsigned int buf_len)
279{
280 int len = 0;
281
282 if (hvalue == 0)
283 snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
284 else
285 {
286 len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
287 snprintf (buf + len, buf_len - len,
288 "%08" DWARF_VMA_FMT "x", lvalue);
289 }
290
291 return buf;
292}
293
f6f0e17b
NC
294/* Read in a LEB128 encoded value starting at address DATA.
295 If SIGN is true, return a signed LEB128 value.
296 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
297 No bytes will be read at address END or beyond. */
298
467c65bc 299dwarf_vma
f6f0e17b
NC
300read_leb128 (unsigned char *data,
301 unsigned int *length_return,
302 bfd_boolean sign,
303 const unsigned char * const end)
19e6b90e 304{
467c65bc 305 dwarf_vma result = 0;
19e6b90e
L
306 unsigned int num_read = 0;
307 unsigned int shift = 0;
f6f0e17b 308 unsigned char byte = 0;
19e6b90e 309
f6f0e17b 310 while (data < end)
19e6b90e
L
311 {
312 byte = *data++;
313 num_read++;
314
467c65bc 315 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
19e6b90e
L
316
317 shift += 7;
f6f0e17b
NC
318 if ((byte & 0x80) == 0)
319 break;
77ef8654
NC
320
321 /* PR 17512: file: 0ca183b8.
322 FIXME: Should we signal this error somehow ? */
f641dd96 323 if (shift >= sizeof (result) * 8)
77ef8654 324 break;
19e6b90e 325 }
19e6b90e
L
326
327 if (length_return != NULL)
328 *length_return = num_read;
329
330 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
c4e0beac 331 result |= -((dwarf_vma) 1 << shift);
19e6b90e
L
332
333 return result;
334}
335
467c65bc 336/* Create a signed version to avoid painful typecasts. */
f6f0e17b
NC
337static inline dwarf_signed_vma
338read_sleb128 (unsigned char * data,
339 unsigned int * length_return,
340 const unsigned char * const end)
341{
342 return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end);
343}
344
345static inline dwarf_vma
346read_uleb128 (unsigned char * data,
347 unsigned int * length_return,
348 const unsigned char * const end)
467c65bc 349{
f6f0e17b 350 return read_leb128 (data, length_return, FALSE, end);
467c65bc
NC
351}
352
7f2c8a1d
NC
353#define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return
354#define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return
355
356#define READ_ULEB(var) \
357 do \
358 { \
359 dwarf_vma _val; \
360 \
361 (var) = _val = read_uleb128 (start, &length_return, end); \
362 if ((var) != _val) \
66cfc0fd
AM
363 error (_("Internal error: %s:%d: LEB value (%s) " \
364 "too large for containing variable\n"), \
365 __FILE__, __LINE__, dwarf_vmatoa ("u", _val)); \
7f2c8a1d
NC
366 start += length_return; \
367 } \
368 while (0)
369
370#define READ_SLEB(var) \
371 do \
372 { \
373 dwarf_signed_vma _val; \
374 \
375 (var) = _val = read_sleb128 (start, &length_return, end); \
376 if ((var) != _val) \
66cfc0fd
AM
377 error (_("Internal error: %s:%d: LEB value (%s) " \
378 "too large for containing variable\n"), \
379 __FILE__, __LINE__, dwarf_vmatoa ("d", _val)); \
7f2c8a1d
NC
380 start += length_return; \
381 } \
382 while (0)
383
0c588247
NC
384#define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
385 do \
386 { \
387 unsigned int amount = (AMOUNT); \
34b9f729
NC
388 if (sizeof (VAL) < amount) \
389 { \
d3a49aa8
AM
390 error (ngettext ("internal error: attempt to read %d byte " \
391 "of data in to %d sized variable", \
392 "internal error: attempt to read %d bytes " \
393 "of data in to %d sized variable", \
394 amount), \
34b9f729
NC
395 amount, (int) sizeof (VAL)); \
396 amount = sizeof (VAL); \
397 } \
0c588247
NC
398 if (((PTR) + amount) >= (END)) \
399 { \
400 if ((PTR) < (END)) \
401 amount = (END) - (PTR); \
402 else \
403 amount = 0; \
404 } \
6937bb54 405 if (amount == 0 || amount > 8) \
0c588247 406 VAL = 0; \
6937bb54
NC
407 else \
408 VAL = byte_get ((PTR), amount); \
0c588247
NC
409 } \
410 while (0)
411
412#define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
413 do \
414 { \
415 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
416 PTR += AMOUNT; \
417 } \
418 while (0)
419
420#define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
421 do \
422 { \
423 unsigned int amount = (AMOUNT); \
424 if (((PTR) + amount) >= (END)) \
425 { \
426 if ((PTR) < (END)) \
427 amount = (END) - (PTR); \
428 else \
429 amount = 0; \
430 } \
431 if (amount) \
432 VAL = byte_get_signed ((PTR), amount); \
433 else \
434 VAL = 0; \
435 } \
436 while (0)
437
438#define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
439 do \
440 { \
441 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
442 PTR += AMOUNT; \
443 } \
444 while (0)
445
446#define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
447 do \
448 { \
87bc83b3 449 if (((PTR) + 8) <= (END)) \
0c588247
NC
450 { \
451 byte_get_64 ((PTR), (HIGH), (LOW)); \
452 } \
453 else \
454 { \
0c588247
NC
455 * (LOW) = * (HIGH) = 0; \
456 } \
457 } \
458 while (0)
459
19e6b90e
L
460typedef struct State_Machine_Registers
461{
467c65bc 462 dwarf_vma address;
ba8826a8 463 unsigned int view;
19e6b90e
L
464 unsigned int file;
465 unsigned int line;
466 unsigned int column;
467 int is_stmt;
468 int basic_block;
a233b20c
JJ
469 unsigned char op_index;
470 unsigned char end_sequence;
ba8826a8
AO
471 /* This variable hold the number of the last entry seen
472 in the File Table. */
19e6b90e
L
473 unsigned int last_file_entry;
474} SMR;
475
476static SMR state_machine_regs;
477
478static void
479reset_state_machine (int is_stmt)
480{
481 state_machine_regs.address = 0;
ba8826a8 482 state_machine_regs.view = 0;
a233b20c 483 state_machine_regs.op_index = 0;
19e6b90e
L
484 state_machine_regs.file = 1;
485 state_machine_regs.line = 1;
486 state_machine_regs.column = 0;
487 state_machine_regs.is_stmt = is_stmt;
488 state_machine_regs.basic_block = 0;
489 state_machine_regs.end_sequence = 0;
490 state_machine_regs.last_file_entry = 0;
491}
492
493/* Handled an extend line op.
494 Returns the number of bytes read. */
495
496static int
f6f0e17b
NC
497process_extended_line_op (unsigned char * data,
498 int is_stmt,
499 unsigned char * end)
19e6b90e
L
500{
501 unsigned char op_code;
502 unsigned int bytes_read;
503 unsigned int len;
504 unsigned char *name;
143a3db0 505 unsigned char *orig_data = data;
f6f0e17b 506 dwarf_vma adr;
19e6b90e 507
f6f0e17b 508 len = read_uleb128 (data, & bytes_read, end);
19e6b90e
L
509 data += bytes_read;
510
e44c58ce 511 if (len == 0 || data == end || len > (uintptr_t) (end - data))
19e6b90e 512 {
f41e4712 513 warn (_("Badly formed extended line op encountered!\n"));
19e6b90e
L
514 return bytes_read;
515 }
516
517 len += bytes_read;
518 op_code = *data++;
519
520 printf (_(" Extended opcode %d: "), op_code);
521
522 switch (op_code)
523 {
524 case DW_LNE_end_sequence:
525 printf (_("End of Sequence\n\n"));
526 reset_state_machine (is_stmt);
527 break;
528
529 case DW_LNE_set_address:
6937bb54
NC
530 /* PR 17512: file: 002-100480-0.004. */
531 if (len - bytes_read - 1 > 8)
77ef8654
NC
532 {
533 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
534 len - bytes_read - 1);
535 adr = 0;
536 }
537 else
538 SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
47704ddf 539 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
19e6b90e 540 state_machine_regs.address = adr;
ba8826a8 541 state_machine_regs.view = 0;
a233b20c 542 state_machine_regs.op_index = 0;
19e6b90e
L
543 break;
544
545 case DW_LNE_define_file:
143a3db0 546 printf (_("define new File Table entry\n"));
19e6b90e 547 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
cc5914eb 548 printf (" %d\t", ++state_machine_regs.last_file_entry);
f6f0e17b 549
d949ff56
NC
550 {
551 size_t l;
552
553 name = data;
554 l = strnlen ((char *) data, end - data);
555 data += len + 1;
556 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
557 data += bytes_read;
558 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
559 data += bytes_read;
560 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
561 data += bytes_read;
562 printf ("%.*s\n\n", (int) l, name);
563 }
f6f0e17b
NC
564
565 if (((unsigned int) (data - orig_data) != len) || data == end)
b4eb7656 566 warn (_("DW_LNE_define_file: Bad opcode length\n"));
19e6b90e
L
567 break;
568
ed4a4bdf 569 case DW_LNE_set_discriminator:
47704ddf 570 printf (_("set Discriminator to %s\n"),
f6f0e17b 571 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
ed4a4bdf
CC
572 break;
573
e2a0d921
NC
574 /* HP extensions. */
575 case DW_LNE_HP_negate_is_UV_update:
ed4a4bdf 576 printf ("DW_LNE_HP_negate_is_UV_update\n");
e2a0d921
NC
577 break;
578 case DW_LNE_HP_push_context:
ed4a4bdf 579 printf ("DW_LNE_HP_push_context\n");
e2a0d921
NC
580 break;
581 case DW_LNE_HP_pop_context:
ed4a4bdf 582 printf ("DW_LNE_HP_pop_context\n");
e2a0d921
NC
583 break;
584 case DW_LNE_HP_set_file_line_column:
ed4a4bdf 585 printf ("DW_LNE_HP_set_file_line_column\n");
e2a0d921
NC
586 break;
587 case DW_LNE_HP_set_routine_name:
ed4a4bdf 588 printf ("DW_LNE_HP_set_routine_name\n");
e2a0d921
NC
589 break;
590 case DW_LNE_HP_set_sequence:
ed4a4bdf 591 printf ("DW_LNE_HP_set_sequence\n");
e2a0d921
NC
592 break;
593 case DW_LNE_HP_negate_post_semantics:
ed4a4bdf 594 printf ("DW_LNE_HP_negate_post_semantics\n");
e2a0d921
NC
595 break;
596 case DW_LNE_HP_negate_function_exit:
ed4a4bdf 597 printf ("DW_LNE_HP_negate_function_exit\n");
e2a0d921
NC
598 break;
599 case DW_LNE_HP_negate_front_end_logical:
ed4a4bdf 600 printf ("DW_LNE_HP_negate_front_end_logical\n");
e2a0d921
NC
601 break;
602 case DW_LNE_HP_define_proc:
ed4a4bdf 603 printf ("DW_LNE_HP_define_proc\n");
e2a0d921 604 break;
43294ab7
TG
605 case DW_LNE_HP_source_file_correlation:
606 {
b4eb7656
AM
607 unsigned char *edata = data + len - bytes_read - 1;
608
609 printf ("DW_LNE_HP_source_file_correlation\n");
610
611 while (data < edata)
612 {
613 unsigned int opc;
614
615 opc = read_uleb128 (data, & bytes_read, edata);
616 data += bytes_read;
617
618 switch (opc)
619 {
620 case DW_LNE_HP_SFC_formfeed:
621 printf (" DW_LNE_HP_SFC_formfeed\n");
622 break;
623 case DW_LNE_HP_SFC_set_listing_line:
624 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
625 dwarf_vmatoa ("u",
626 read_uleb128 (data, & bytes_read, edata)));
627 data += bytes_read;
628 break;
629 case DW_LNE_HP_SFC_associate:
630 printf (" DW_LNE_HP_SFC_associate ");
631 printf ("(%s",
632 dwarf_vmatoa ("u",
633 read_uleb128 (data, & bytes_read, edata)));
634 data += bytes_read;
635 printf (",%s",
636 dwarf_vmatoa ("u",
637 read_uleb128 (data, & bytes_read, edata)));
638 data += bytes_read;
639 printf (",%s)\n",
640 dwarf_vmatoa ("u",
641 read_uleb128 (data, & bytes_read, edata)));
642 data += bytes_read;
643 break;
644 default:
645 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
646 data = edata;
647 break;
648 }
649 }
43294ab7
TG
650 }
651 break;
cecf136e 652
19e6b90e 653 default:
7e665af3 654 {
b4eb7656
AM
655 unsigned int rlen = len - bytes_read - 1;
656
657 if (op_code >= DW_LNE_lo_user
658 /* The test against DW_LNW_hi_user is redundant due to
659 the limited range of the unsigned char data type used
660 for op_code. */
661 /*&& op_code <= DW_LNE_hi_user*/)
662 printf (_("user defined: "));
663 else
664 printf (_("UNKNOWN: "));
665 printf (_("length %d ["), rlen);
666 for (; rlen; rlen--)
667 printf (" %02x", *data++);
668 printf ("]\n");
7e665af3 669 }
19e6b90e
L
670 break;
671 }
672
673 return len;
674}
675
0c588247 676static const unsigned char *
467c65bc 677fetch_indirect_string (dwarf_vma offset)
19e6b90e
L
678{
679 struct dwarf_section *section = &debug_displays [str].section;
d949ff56 680 const unsigned char * ret;
19e6b90e
L
681
682 if (section->start == NULL)
0c588247 683 return (const unsigned char *) _("<no .debug_str section>");
19e6b90e 684
d949ff56 685 if (offset >= section->size)
19e6b90e 686 {
467c65bc
NC
687 warn (_("DW_FORM_strp offset too big: %s\n"),
688 dwarf_vmatoa ("x", offset));
0c588247 689 return (const unsigned char *) _("<offset is too big>");
19e6b90e
L
690 }
691
d949ff56
NC
692 ret = section->start + offset;
693 /* Unfortunately we cannot rely upon the .debug_str section ending with a
694 NUL byte. Since our caller is expecting to receive a well formed C
695 string we test for the lack of a terminating byte here. */
696 if (strnlen ((const char *) ret, section->size - offset)
697 == section->size - offset)
698 ret = (const unsigned char *)
699 _("<no NUL byte at end of .debug_str section>");
700
701 return ret;
19e6b90e
L
702}
703
77145576
JK
704static const unsigned char *
705fetch_indirect_line_string (dwarf_vma offset)
706{
707 struct dwarf_section *section = &debug_displays [line_str].section;
d949ff56 708 const unsigned char * ret;
77145576
JK
709
710 if (section->start == NULL)
711 return (const unsigned char *) _("<no .debug_line_str section>");
712
d949ff56 713 if (offset >= section->size)
77145576
JK
714 {
715 warn (_("DW_FORM_line_strp offset too big: %s\n"),
716 dwarf_vmatoa ("x", offset));
717 return (const unsigned char *) _("<offset is too big>");
718 }
719
d949ff56
NC
720 ret = section->start + offset;
721 /* Unfortunately we cannot rely upon the .debug_line_str section ending
722 with a NUL byte. Since our caller is expecting to receive a well formed
723 C string we test for the lack of a terminating byte here. */
724 if (strnlen ((const char *) ret, section->size - offset)
725 == section->size - offset)
726 ret = (const unsigned char *)
727 _("<no NUL byte at end of .debug_line_str section>");
728
729 return ret;
77145576
JK
730}
731
4723351a 732static const char *
341f9135
CC
733fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
734 dwarf_vma offset_size, int dwo)
4723351a
CC
735{
736 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
737 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
738 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
739 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
740 dwarf_vma index_offset = idx * offset_size;
741 dwarf_vma str_offset;
d949ff56 742 const char * ret;
4723351a
CC
743
744 if (index_section->start == NULL)
745 return (dwo ? _("<no .debug_str_offsets.dwo section>")
746 : _("<no .debug_str_offsets section>"));
747
341f9135
CC
748 if (this_set != NULL)
749 index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
d949ff56 750 if (index_offset >= index_section->size)
4723351a
CC
751 {
752 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
753 dwarf_vmatoa ("x", index_offset));
754 return _("<index offset is too big>");
755 }
756
757 if (str_section->start == NULL)
758 return (dwo ? _("<no .debug_str.dwo section>")
759 : _("<no .debug_str section>"));
760
761 str_offset = byte_get (index_section->start + index_offset, offset_size);
762 str_offset -= str_section->address;
d949ff56 763 if (str_offset >= str_section->size)
4723351a
CC
764 {
765 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
766 dwarf_vmatoa ("x", str_offset));
767 return _("<indirect index offset is too big>");
768 }
769
d949ff56
NC
770 ret = (const char *) str_section->start + str_offset;
771 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
772 Since our caller is expecting to receive a well formed C string we test
773 for the lack of a terminating byte here. */
774 if (strnlen (ret, str_section->size - str_offset)
775 == str_section->size - str_offset)
776 ret = (const char *) _("<no NUL byte at end of section>");
777
778 return ret;
4723351a
CC
779}
780
781static const char *
782fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
783{
784 struct dwarf_section *section = &debug_displays [debug_addr].section;
785
786 if (section->start == NULL)
787 return (_("<no .debug_addr section>"));
788
789 if (offset + bytes > section->size)
790 {
791 warn (_("Offset into section %s too big: %s\n"),
b4eb7656 792 section->name, dwarf_vmatoa ("x", offset));
4723351a
CC
793 return "<offset too big>";
794 }
795
796 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
797}
798
799
19e6b90e
L
800/* FIXME: There are better and more efficient ways to handle
801 these structures. For now though, I just want something that
802 is simple to implement. */
803typedef struct abbrev_attr
804{
805 unsigned long attribute;
806 unsigned long form;
77145576 807 bfd_signed_vma implicit_const;
19e6b90e
L
808 struct abbrev_attr *next;
809}
810abbrev_attr;
811
812typedef struct abbrev_entry
813{
814 unsigned long entry;
815 unsigned long tag;
816 int children;
817 struct abbrev_attr *first_attr;
818 struct abbrev_attr *last_attr;
819 struct abbrev_entry *next;
820}
821abbrev_entry;
822
823static abbrev_entry *first_abbrev = NULL;
824static abbrev_entry *last_abbrev = NULL;
825
826static void
827free_abbrevs (void)
828{
91d6fa6a 829 abbrev_entry *abbrv;
19e6b90e 830
91d6fa6a 831 for (abbrv = first_abbrev; abbrv;)
19e6b90e 832 {
91d6fa6a 833 abbrev_entry *next_abbrev = abbrv->next;
19e6b90e
L
834 abbrev_attr *attr;
835
91d6fa6a 836 for (attr = abbrv->first_attr; attr;)
19e6b90e 837 {
91d6fa6a 838 abbrev_attr *next_attr = attr->next;
19e6b90e
L
839
840 free (attr);
91d6fa6a 841 attr = next_attr;
19e6b90e
L
842 }
843
91d6fa6a
NC
844 free (abbrv);
845 abbrv = next_abbrev;
19e6b90e
L
846 }
847
848 last_abbrev = first_abbrev = NULL;
849}
850
851static void
852add_abbrev (unsigned long number, unsigned long tag, int children)
853{
854 abbrev_entry *entry;
855
3f5e193b 856 entry = (abbrev_entry *) malloc (sizeof (*entry));
19e6b90e
L
857 if (entry == NULL)
858 /* ugg */
859 return;
860
861 entry->entry = number;
862 entry->tag = tag;
863 entry->children = children;
864 entry->first_attr = NULL;
865 entry->last_attr = NULL;
866 entry->next = NULL;
867
868 if (first_abbrev == NULL)
869 first_abbrev = entry;
870 else
871 last_abbrev->next = entry;
872
873 last_abbrev = entry;
874}
875
876static void
77145576
JK
877add_abbrev_attr (unsigned long attribute, unsigned long form,
878 bfd_signed_vma implicit_const)
19e6b90e
L
879{
880 abbrev_attr *attr;
881
3f5e193b 882 attr = (abbrev_attr *) malloc (sizeof (*attr));
19e6b90e
L
883 if (attr == NULL)
884 /* ugg */
885 return;
886
887 attr->attribute = attribute;
888 attr->form = form;
77145576 889 attr->implicit_const = implicit_const;
19e6b90e
L
890 attr->next = NULL;
891
892 if (last_abbrev->first_attr == NULL)
893 last_abbrev->first_attr = attr;
894 else
895 last_abbrev->last_attr->next = attr;
896
897 last_abbrev->last_attr = attr;
898}
899
900/* Processes the (partial) contents of a .debug_abbrev section.
901 Returns NULL if the end of the section was encountered.
902 Returns the address after the last byte read if the end of
903 an abbreviation set was found. */
904
905static unsigned char *
906process_abbrev_section (unsigned char *start, unsigned char *end)
907{
908 if (first_abbrev != NULL)
909 return NULL;
910
911 while (start < end)
912 {
913 unsigned int bytes_read;
914 unsigned long entry;
915 unsigned long tag;
916 unsigned long attribute;
917 int children;
918
f6f0e17b 919 entry = read_uleb128 (start, & bytes_read, end);
19e6b90e
L
920 start += bytes_read;
921
922 /* A single zero is supposed to end the section according
923 to the standard. If there's more, then signal that to
924 the caller. */
f6f0e17b
NC
925 if (start == end)
926 return NULL;
19e6b90e 927 if (entry == 0)
f6f0e17b 928 return start;
19e6b90e 929
f6f0e17b 930 tag = read_uleb128 (start, & bytes_read, end);
19e6b90e 931 start += bytes_read;
f6f0e17b
NC
932 if (start == end)
933 return NULL;
19e6b90e
L
934
935 children = *start++;
936
937 add_abbrev (entry, tag, children);
938
939 do
940 {
941 unsigned long form;
77145576
JK
942 /* Initialize it due to a false compiler warning. */
943 bfd_signed_vma implicit_const = -1;
19e6b90e 944
f6f0e17b 945 attribute = read_uleb128 (start, & bytes_read, end);
19e6b90e 946 start += bytes_read;
f6f0e17b
NC
947 if (start == end)
948 break;
19e6b90e 949
f6f0e17b 950 form = read_uleb128 (start, & bytes_read, end);
19e6b90e 951 start += bytes_read;
f6f0e17b
NC
952 if (start == end)
953 break;
19e6b90e 954
77145576
JK
955 if (form == DW_FORM_implicit_const)
956 {
957 implicit_const = read_sleb128 (start, & bytes_read, end);
958 start += bytes_read;
959 if (start == end)
960 break;
961 }
962
963 add_abbrev_attr (attribute, form, implicit_const);
19e6b90e
L
964 }
965 while (attribute != 0);
966 }
967
399c99f7
L
968 /* Report the missing single zero which ends the section. */
969 error (_(".debug_abbrev section not zero terminated\n"));
970
19e6b90e
L
971 return NULL;
972}
973
a19c41a7 974static const char *
19e6b90e
L
975get_TAG_name (unsigned long tag)
976{
04914e37 977 const char *name = get_DW_TAG_name ((unsigned int) tag);
a19c41a7
TT
978
979 if (name == NULL)
19e6b90e 980 {
a19c41a7 981 static char buffer[100];
19e6b90e 982
04914e37
NC
983 if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user)
984 snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag);
985 else
986 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag);
a19c41a7 987 return buffer;
19e6b90e 988 }
a19c41a7
TT
989
990 return name;
19e6b90e
L
991}
992
a19c41a7 993static const char *
19e6b90e
L
994get_FORM_name (unsigned long form)
995{
399c99f7 996 const char *name;
bf5117e3 997
399c99f7
L
998 if (form == 0)
999 return "DW_FORM value: 0";
a19c41a7 1000
399c99f7 1001 name = get_DW_FORM_name (form);
a19c41a7 1002 if (name == NULL)
19e6b90e 1003 {
a19c41a7 1004 static char buffer[100];
19e6b90e 1005
a19c41a7
TT
1006 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
1007 return buffer;
19e6b90e 1008 }
a19c41a7
TT
1009
1010 return name;
19e6b90e
L
1011}
1012
61364358
JK
1013static const char *
1014get_IDX_name (unsigned long idx)
1015{
1016 const char *name = get_DW_IDX_name ((unsigned int) idx);
1017
1018 if (name == NULL)
1019 {
1020 static char buffer[100];
1021
1022 snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx);
1023 return buffer;
1024 }
1025
1026 return name;
1027}
1028
19e6b90e 1029static unsigned char *
0c588247
NC
1030display_block (unsigned char *data,
1031 dwarf_vma length,
ef0b5f1c 1032 const unsigned char * const end, char delimiter)
19e6b90e 1033{
0c588247
NC
1034 dwarf_vma maxlen;
1035
ef0b5f1c 1036 printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length));
a1165289
NC
1037 if (data > end)
1038 return (unsigned char *) end;
19e6b90e 1039
0c588247
NC
1040 maxlen = (dwarf_vma) (end - data);
1041 length = length > maxlen ? maxlen : length;
1042
19e6b90e
L
1043 while (length --)
1044 printf ("%lx ", (unsigned long) byte_get (data++, 1));
1045
1046 return data;
1047}
1048
1049static int
1050decode_location_expression (unsigned char * data,
1051 unsigned int pointer_size,
b7807392
JJ
1052 unsigned int offset_size,
1053 int dwarf_version,
467c65bc
NC
1054 dwarf_vma length,
1055 dwarf_vma cu_offset,
f1c4cc75 1056 struct dwarf_section * section)
19e6b90e
L
1057{
1058 unsigned op;
1059 unsigned int bytes_read;
467c65bc 1060 dwarf_vma uvalue;
0c588247 1061 dwarf_signed_vma svalue;
19e6b90e
L
1062 unsigned char *end = data + length;
1063 int need_frame_base = 0;
1064
1065 while (data < end)
1066 {
1067 op = *data++;
1068
1069 switch (op)
1070 {
1071 case DW_OP_addr:
0c588247
NC
1072 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
1073 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
19e6b90e
L
1074 break;
1075 case DW_OP_deref:
1076 printf ("DW_OP_deref");
1077 break;
1078 case DW_OP_const1u:
0c588247
NC
1079 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1080 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
19e6b90e
L
1081 break;
1082 case DW_OP_const1s:
0c588247
NC
1083 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
1084 printf ("DW_OP_const1s: %ld", (long) svalue);
19e6b90e
L
1085 break;
1086 case DW_OP_const2u:
87bc83b3 1087 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
0c588247 1088 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
19e6b90e
L
1089 break;
1090 case DW_OP_const2s:
0c588247
NC
1091 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1092 printf ("DW_OP_const2s: %ld", (long) svalue);
19e6b90e
L
1093 break;
1094 case DW_OP_const4u:
0c588247
NC
1095 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1096 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
19e6b90e
L
1097 break;
1098 case DW_OP_const4s:
0c588247
NC
1099 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1100 printf ("DW_OP_const4s: %ld", (long) svalue);
19e6b90e
L
1101 break;
1102 case DW_OP_const8u:
0c588247
NC
1103 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1104 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
1105 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
1106 printf ("%lu", (unsigned long) uvalue);
19e6b90e
L
1107 break;
1108 case DW_OP_const8s:
0c588247
NC
1109 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1110 printf ("DW_OP_const8s: %ld ", (long) svalue);
1111 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
1112 printf ("%ld", (long) svalue);
19e6b90e
L
1113 break;
1114 case DW_OP_constu:
467c65bc 1115 printf ("DW_OP_constu: %s",
f6f0e17b 1116 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
19e6b90e
L
1117 data += bytes_read;
1118 break;
1119 case DW_OP_consts:
467c65bc 1120 printf ("DW_OP_consts: %s",
f6f0e17b 1121 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
19e6b90e
L
1122 data += bytes_read;
1123 break;
1124 case DW_OP_dup:
1125 printf ("DW_OP_dup");
1126 break;
1127 case DW_OP_drop:
1128 printf ("DW_OP_drop");
1129 break;
1130 case DW_OP_over:
1131 printf ("DW_OP_over");
1132 break;
1133 case DW_OP_pick:
0c588247
NC
1134 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1135 printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
19e6b90e
L
1136 break;
1137 case DW_OP_swap:
1138 printf ("DW_OP_swap");
1139 break;
1140 case DW_OP_rot:
1141 printf ("DW_OP_rot");
1142 break;
1143 case DW_OP_xderef:
1144 printf ("DW_OP_xderef");
1145 break;
1146 case DW_OP_abs:
1147 printf ("DW_OP_abs");
1148 break;
1149 case DW_OP_and:
1150 printf ("DW_OP_and");
1151 break;
1152 case DW_OP_div:
1153 printf ("DW_OP_div");
1154 break;
1155 case DW_OP_minus:
1156 printf ("DW_OP_minus");
1157 break;
1158 case DW_OP_mod:
1159 printf ("DW_OP_mod");
1160 break;
1161 case DW_OP_mul:
1162 printf ("DW_OP_mul");
1163 break;
1164 case DW_OP_neg:
1165 printf ("DW_OP_neg");
1166 break;
1167 case DW_OP_not:
1168 printf ("DW_OP_not");
1169 break;
1170 case DW_OP_or:
1171 printf ("DW_OP_or");
1172 break;
1173 case DW_OP_plus:
1174 printf ("DW_OP_plus");
1175 break;
1176 case DW_OP_plus_uconst:
467c65bc 1177 printf ("DW_OP_plus_uconst: %s",
f6f0e17b 1178 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
19e6b90e
L
1179 data += bytes_read;
1180 break;
1181 case DW_OP_shl:
1182 printf ("DW_OP_shl");
1183 break;
1184 case DW_OP_shr:
1185 printf ("DW_OP_shr");
1186 break;
1187 case DW_OP_shra:
1188 printf ("DW_OP_shra");
1189 break;
1190 case DW_OP_xor:
1191 printf ("DW_OP_xor");
1192 break;
1193 case DW_OP_bra:
0c588247
NC
1194 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1195 printf ("DW_OP_bra: %ld", (long) svalue);
19e6b90e
L
1196 break;
1197 case DW_OP_eq:
1198 printf ("DW_OP_eq");
1199 break;
1200 case DW_OP_ge:
1201 printf ("DW_OP_ge");
1202 break;
1203 case DW_OP_gt:
1204 printf ("DW_OP_gt");
1205 break;
1206 case DW_OP_le:
1207 printf ("DW_OP_le");
1208 break;
1209 case DW_OP_lt:
1210 printf ("DW_OP_lt");
1211 break;
1212 case DW_OP_ne:
1213 printf ("DW_OP_ne");
1214 break;
1215 case DW_OP_skip:
0c588247
NC
1216 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
1217 printf ("DW_OP_skip: %ld", (long) svalue);
19e6b90e
L
1218 break;
1219
1220 case DW_OP_lit0:
1221 case DW_OP_lit1:
1222 case DW_OP_lit2:
1223 case DW_OP_lit3:
1224 case DW_OP_lit4:
1225 case DW_OP_lit5:
1226 case DW_OP_lit6:
1227 case DW_OP_lit7:
1228 case DW_OP_lit8:
1229 case DW_OP_lit9:
1230 case DW_OP_lit10:
1231 case DW_OP_lit11:
1232 case DW_OP_lit12:
1233 case DW_OP_lit13:
1234 case DW_OP_lit14:
1235 case DW_OP_lit15:
1236 case DW_OP_lit16:
1237 case DW_OP_lit17:
1238 case DW_OP_lit18:
1239 case DW_OP_lit19:
1240 case DW_OP_lit20:
1241 case DW_OP_lit21:
1242 case DW_OP_lit22:
1243 case DW_OP_lit23:
1244 case DW_OP_lit24:
1245 case DW_OP_lit25:
1246 case DW_OP_lit26:
1247 case DW_OP_lit27:
1248 case DW_OP_lit28:
1249 case DW_OP_lit29:
1250 case DW_OP_lit30:
1251 case DW_OP_lit31:
1252 printf ("DW_OP_lit%d", op - DW_OP_lit0);
1253 break;
1254
1255 case DW_OP_reg0:
1256 case DW_OP_reg1:
1257 case DW_OP_reg2:
1258 case DW_OP_reg3:
1259 case DW_OP_reg4:
1260 case DW_OP_reg5:
1261 case DW_OP_reg6:
1262 case DW_OP_reg7:
1263 case DW_OP_reg8:
1264 case DW_OP_reg9:
1265 case DW_OP_reg10:
1266 case DW_OP_reg11:
1267 case DW_OP_reg12:
1268 case DW_OP_reg13:
1269 case DW_OP_reg14:
1270 case DW_OP_reg15:
1271 case DW_OP_reg16:
1272 case DW_OP_reg17:
1273 case DW_OP_reg18:
1274 case DW_OP_reg19:
1275 case DW_OP_reg20:
1276 case DW_OP_reg21:
1277 case DW_OP_reg22:
1278 case DW_OP_reg23:
1279 case DW_OP_reg24:
1280 case DW_OP_reg25:
1281 case DW_OP_reg26:
1282 case DW_OP_reg27:
1283 case DW_OP_reg28:
1284 case DW_OP_reg29:
1285 case DW_OP_reg30:
1286 case DW_OP_reg31:
18464d4d
JK
1287 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
1288 regname (op - DW_OP_reg0, 1));
19e6b90e
L
1289 break;
1290
1291 case DW_OP_breg0:
1292 case DW_OP_breg1:
1293 case DW_OP_breg2:
1294 case DW_OP_breg3:
1295 case DW_OP_breg4:
1296 case DW_OP_breg5:
1297 case DW_OP_breg6:
1298 case DW_OP_breg7:
1299 case DW_OP_breg8:
1300 case DW_OP_breg9:
1301 case DW_OP_breg10:
1302 case DW_OP_breg11:
1303 case DW_OP_breg12:
1304 case DW_OP_breg13:
1305 case DW_OP_breg14:
1306 case DW_OP_breg15:
1307 case DW_OP_breg16:
1308 case DW_OP_breg17:
1309 case DW_OP_breg18:
1310 case DW_OP_breg19:
1311 case DW_OP_breg20:
1312 case DW_OP_breg21:
1313 case DW_OP_breg22:
1314 case DW_OP_breg23:
1315 case DW_OP_breg24:
1316 case DW_OP_breg25:
1317 case DW_OP_breg26:
1318 case DW_OP_breg27:
1319 case DW_OP_breg28:
1320 case DW_OP_breg29:
1321 case DW_OP_breg30:
1322 case DW_OP_breg31:
467c65bc 1323 printf ("DW_OP_breg%d (%s): %s",
47704ddf 1324 op - DW_OP_breg0,
18464d4d 1325 regname (op - DW_OP_breg0, 1),
f6f0e17b 1326 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
19e6b90e
L
1327 data += bytes_read;
1328 break;
1329
1330 case DW_OP_regx:
f6f0e17b 1331 uvalue = read_uleb128 (data, &bytes_read, end);
19e6b90e 1332 data += bytes_read;
467c65bc
NC
1333 printf ("DW_OP_regx: %s (%s)",
1334 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
19e6b90e
L
1335 break;
1336 case DW_OP_fbreg:
1337 need_frame_base = 1;
467c65bc 1338 printf ("DW_OP_fbreg: %s",
f6f0e17b 1339 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
19e6b90e
L
1340 data += bytes_read;
1341 break;
1342 case DW_OP_bregx:
f6f0e17b 1343 uvalue = read_uleb128 (data, &bytes_read, end);
19e6b90e 1344 data += bytes_read;
467c65bc
NC
1345 printf ("DW_OP_bregx: %s (%s) %s",
1346 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
f6f0e17b 1347 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
19e6b90e
L
1348 data += bytes_read;
1349 break;
1350 case DW_OP_piece:
467c65bc 1351 printf ("DW_OP_piece: %s",
f6f0e17b 1352 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
19e6b90e
L
1353 data += bytes_read;
1354 break;
1355 case DW_OP_deref_size:
0c588247
NC
1356 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1357 printf ("DW_OP_deref_size: %ld", (long) uvalue);
19e6b90e
L
1358 break;
1359 case DW_OP_xderef_size:
0c588247
NC
1360 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
1361 printf ("DW_OP_xderef_size: %ld", (long) uvalue);
19e6b90e
L
1362 break;
1363 case DW_OP_nop:
1364 printf ("DW_OP_nop");
1365 break;
1366
1367 /* DWARF 3 extensions. */
1368 case DW_OP_push_object_address:
1369 printf ("DW_OP_push_object_address");
1370 break;
1371 case DW_OP_call2:
1372 /* XXX: Strictly speaking for 64-bit DWARF3 files
1373 this ought to be an 8-byte wide computation. */
0c588247 1374 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
467c65bc 1375 printf ("DW_OP_call2: <0x%s>",
0c588247 1376 dwarf_vmatoa ("x", svalue + cu_offset));
19e6b90e
L
1377 break;
1378 case DW_OP_call4:
1379 /* XXX: Strictly speaking for 64-bit DWARF3 files
1380 this ought to be an 8-byte wide computation. */
0c588247 1381 SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
467c65bc 1382 printf ("DW_OP_call4: <0x%s>",
0c588247 1383 dwarf_vmatoa ("x", svalue + cu_offset));
19e6b90e
L
1384 break;
1385 case DW_OP_call_ref:
e2a0d921
NC
1386 /* XXX: Strictly speaking for 64-bit DWARF3 files
1387 this ought to be an 8-byte wide computation. */
b7807392
JJ
1388 if (dwarf_version == -1)
1389 {
1390 printf (_("(DW_OP_call_ref in frame info)"));
1391 /* No way to tell where the next op is, so just bail. */
1392 return need_frame_base;
1393 }
1394 if (dwarf_version == 2)
1395 {
0c588247 1396 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
b7807392
JJ
1397 }
1398 else
1399 {
0c588247 1400 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
b7807392 1401 }
0c588247 1402 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
19e6b90e 1403 break;
a87b0a59
NS
1404 case DW_OP_form_tls_address:
1405 printf ("DW_OP_form_tls_address");
1406 break;
e2a0d921
NC
1407 case DW_OP_call_frame_cfa:
1408 printf ("DW_OP_call_frame_cfa");
1409 break;
1410 case DW_OP_bit_piece:
1411 printf ("DW_OP_bit_piece: ");
9cf03b7e 1412 printf (_("size: %s "),
f6f0e17b 1413 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
e2a0d921 1414 data += bytes_read;
9cf03b7e 1415 printf (_("offset: %s "),
f6f0e17b 1416 dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
e2a0d921
NC
1417 data += bytes_read;
1418 break;
19e6b90e 1419
3244e8f5
JJ
1420 /* DWARF 4 extensions. */
1421 case DW_OP_stack_value:
1422 printf ("DW_OP_stack_value");
1423 break;
1424
1425 case DW_OP_implicit_value:
1426 printf ("DW_OP_implicit_value");
f6f0e17b 1427 uvalue = read_uleb128 (data, &bytes_read, end);
3244e8f5 1428 data += bytes_read;
ef0b5f1c 1429 data = display_block (data, uvalue, end, ' ');
3244e8f5
JJ
1430 break;
1431
19e6b90e
L
1432 /* GNU extensions. */
1433 case DW_OP_GNU_push_tls_address:
9cf03b7e 1434 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
e2a0d921
NC
1435 break;
1436 case DW_OP_GNU_uninit:
1437 printf ("DW_OP_GNU_uninit");
1438 /* FIXME: Is there data associated with this OP ? */
1439 break;
f1c4cc75
RH
1440 case DW_OP_GNU_encoded_addr:
1441 {
6937bb54 1442 int encoding = 0;
f1c4cc75 1443 dwarf_vma addr;
467c65bc 1444
6937bb54
NC
1445 if (data < end)
1446 encoding = *data++;
041830e0 1447 addr = get_encoded_value (&data, encoding, section, end);
f1c4cc75
RH
1448
1449 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1450 print_dwarf_vma (addr, pointer_size);
1451 }
1452 break;
bc0a77d2 1453 case DW_OP_implicit_pointer:
b7807392
JJ
1454 case DW_OP_GNU_implicit_pointer:
1455 /* XXX: Strictly speaking for 64-bit DWARF3 files
1456 this ought to be an 8-byte wide computation. */
1457 if (dwarf_version == -1)
1458 {
bc0a77d2
JK
1459 printf (_("(%s in frame info)"),
1460 (op == DW_OP_implicit_pointer
1461 ? "DW_OP_implicit_pointer"
1462 : "DW_OP_GNU_implicit_pointer"));
b7807392
JJ
1463 /* No way to tell where the next op is, so just bail. */
1464 return need_frame_base;
1465 }
1466 if (dwarf_version == 2)
1467 {
0c588247 1468 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
b7807392
JJ
1469 }
1470 else
1471 {
0c588247 1472 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
b7807392 1473 }
bc0a77d2
JK
1474 printf ("%s: <0x%s> %s",
1475 (op == DW_OP_implicit_pointer
1476 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
0c588247
NC
1477 dwarf_vmatoa ("x", uvalue),
1478 dwarf_vmatoa ("d", read_sleb128 (data,
1479 &bytes_read, end)));
1480 data += bytes_read;
b7807392 1481 break;
77145576 1482 case DW_OP_entry_value:
0892011d 1483 case DW_OP_GNU_entry_value:
f6f0e17b 1484 uvalue = read_uleb128 (data, &bytes_read, end);
0892011d 1485 data += bytes_read;
058037d3
NC
1486 /* PR 17531: file: 0cc9cd00. */
1487 if (uvalue > (dwarf_vma) (end - data))
1488 uvalue = end - data;
77145576
JK
1489 printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value"
1490 : "DW_OP_GNU_entry_value"));
0892011d
JJ
1491 if (decode_location_expression (data, pointer_size, offset_size,
1492 dwarf_version, uvalue,
1493 cu_offset, section))
1494 need_frame_base = 1;
1495 putchar (')');
1496 data += uvalue;
6937bb54
NC
1497 if (data > end)
1498 data = end;
0892011d 1499 break;
bc0a77d2 1500 case DW_OP_const_type:
0892011d 1501 case DW_OP_GNU_const_type:
f6f0e17b 1502 uvalue = read_uleb128 (data, &bytes_read, end);
0892011d 1503 data += bytes_read;
bc0a77d2
JK
1504 printf ("%s: <0x%s> ",
1505 (op == DW_OP_const_type ? "DW_OP_const_type"
1506 : "DW_OP_GNU_const_type"),
0892011d 1507 dwarf_vmatoa ("x", cu_offset + uvalue));
0c588247 1508 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
ef0b5f1c 1509 data = display_block (data, uvalue, end, ' ');
0892011d 1510 break;
bc0a77d2 1511 case DW_OP_regval_type:
0892011d 1512 case DW_OP_GNU_regval_type:
f6f0e17b 1513 uvalue = read_uleb128 (data, &bytes_read, end);
0892011d 1514 data += bytes_read;
bc0a77d2
JK
1515 printf ("%s: %s (%s)",
1516 (op == DW_OP_regval_type ? "DW_OP_regval_type"
1517 : "DW_OP_GNU_regval_type"),
0892011d 1518 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
f6f0e17b 1519 uvalue = read_uleb128 (data, &bytes_read, end);
0892011d
JJ
1520 data += bytes_read;
1521 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1522 break;
bc0a77d2 1523 case DW_OP_deref_type:
0892011d 1524 case DW_OP_GNU_deref_type:
0c588247 1525 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
bc0a77d2
JK
1526 printf ("%s: %ld",
1527 (op == DW_OP_deref_type ? "DW_OP_deref_type"
1528 : "DW_OP_GNU_deref_type"),
1529 (long) uvalue);
f6f0e17b 1530 uvalue = read_uleb128 (data, &bytes_read, end);
0892011d
JJ
1531 data += bytes_read;
1532 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1533 break;
bc0a77d2 1534 case DW_OP_convert:
0892011d 1535 case DW_OP_GNU_convert:
f6f0e17b 1536 uvalue = read_uleb128 (data, &bytes_read, end);
0892011d 1537 data += bytes_read;
bc0a77d2
JK
1538 printf ("%s <0x%s>",
1539 (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"),
f8b999f9 1540 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
0892011d 1541 break;
bc0a77d2 1542 case DW_OP_reinterpret:
0892011d 1543 case DW_OP_GNU_reinterpret:
f6f0e17b 1544 uvalue = read_uleb128 (data, &bytes_read, end);
0892011d 1545 data += bytes_read;
bc0a77d2
JK
1546 printf ("%s <0x%s>",
1547 (op == DW_OP_reinterpret ? "DW_OP_reinterpret"
1548 : "DW_OP_GNU_reinterpret"),
f8b999f9
JJ
1549 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1550 break;
1551 case DW_OP_GNU_parameter_ref:
0c588247 1552 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
f8b999f9 1553 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
0c588247 1554 dwarf_vmatoa ("x", cu_offset + uvalue));
0892011d 1555 break;
b4eb7656
AM
1556 case DW_OP_GNU_addr_index:
1557 uvalue = read_uleb128 (data, &bytes_read, end);
1558 data += bytes_read;
1559 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1560 break;
1561 case DW_OP_GNU_const_index:
1562 uvalue = read_uleb128 (data, &bytes_read, end);
1563 data += bytes_read;
1564 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1565 break;
e2a0d921
NC
1566
1567 /* HP extensions. */
1568 case DW_OP_HP_is_value:
1569 printf ("DW_OP_HP_is_value");
1570 /* FIXME: Is there data associated with this OP ? */
1571 break;
1572 case DW_OP_HP_fltconst4:
1573 printf ("DW_OP_HP_fltconst4");
1574 /* FIXME: Is there data associated with this OP ? */
1575 break;
1576 case DW_OP_HP_fltconst8:
1577 printf ("DW_OP_HP_fltconst8");
1578 /* FIXME: Is there data associated with this OP ? */
1579 break;
1580 case DW_OP_HP_mod_range:
1581 printf ("DW_OP_HP_mod_range");
1582 /* FIXME: Is there data associated with this OP ? */
1583 break;
1584 case DW_OP_HP_unmod_range:
1585 printf ("DW_OP_HP_unmod_range");
1586 /* FIXME: Is there data associated with this OP ? */
1587 break;
1588 case DW_OP_HP_tls:
1589 printf ("DW_OP_HP_tls");
1590 /* FIXME: Is there data associated with this OP ? */
19e6b90e
L
1591 break;
1592
35d60fe4
NC
1593 /* PGI (STMicroelectronics) extensions. */
1594 case DW_OP_PGI_omp_thread_num:
1595 /* Pushes the thread number for the current thread as it would be
1596 returned by the standard OpenMP library function:
1597 omp_get_thread_num(). The "current thread" is the thread for
1598 which the expression is being evaluated. */
1599 printf ("DW_OP_PGI_omp_thread_num");
1600 break;
1601
19e6b90e
L
1602 default:
1603 if (op >= DW_OP_lo_user
1604 && op <= DW_OP_hi_user)
0502a2b4 1605 printf (_("(User defined location op 0x%x)"), op);
19e6b90e 1606 else
0502a2b4 1607 printf (_("(Unknown location op 0x%x)"), op);
19e6b90e
L
1608 /* No way to tell where the next op is, so just bail. */
1609 return need_frame_base;
1610 }
1611
1612 /* Separate the ops. */
1613 if (data < end)
1614 printf ("; ");
1615 }
1616
1617 return need_frame_base;
1618}
1619
341f9135
CC
1620/* Find the CU or TU set corresponding to the given CU_OFFSET.
1621 This is used for DWARF package files. */
1622
1623static struct cu_tu_set *
1624find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
1625{
1626 struct cu_tu_set *p;
1627 unsigned int nsets;
1628 unsigned int dw_sect;
1629
1630 if (do_types)
1631 {
1632 p = tu_sets;
1633 nsets = tu_count;
1634 dw_sect = DW_SECT_TYPES;
1635 }
1636 else
1637 {
1638 p = cu_sets;
1639 nsets = cu_count;
1640 dw_sect = DW_SECT_INFO;
1641 }
1642 while (nsets > 0)
1643 {
1644 if (p->section_offsets [dw_sect] == cu_offset)
1645 return p;
1646 p++;
1647 nsets--;
1648 }
1649 return NULL;
1650}
1651
a69c4772
NC
1652/* Add INC to HIGH_BITS:LOW_BITS. */
1653static void
1654add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc)
1655{
1656 dwarf_vma tmp = * low_bits;
1657
1658 tmp += inc;
1659
1660 /* FIXME: There is probably a better way of handling this:
1661
1662 We need to cope with dwarf_vma being a 32-bit or 64-bit
1663 type. Plus regardless of its size LOW_BITS is meant to
1664 only hold 32-bits, so if there is overflow or wrap around
1665 we must propagate into HIGH_BITS. */
1666 if (tmp < * low_bits)
1667 {
1668 ++ * high_bits;
1669 }
1670 else if (sizeof (tmp) > 8
1671 && (tmp >> 31) > 1)
1672 {
1673 ++ * high_bits;
1674 tmp &= 0xFFFFFFFF;
1675 }
1676
1677 * low_bits = tmp;
1678}
1679
dda8d76d
NC
1680static const char *
1681fetch_alt_indirect_string (dwarf_vma offset)
1682{
1683 struct dwarf_section * section;
1684 const char * ret;
1685
1686 if (! do_follow_links)
1687 return "";
1688
1689 if (separate_debug_file == NULL)
1690 return _("<following link not possible>");
1691
1692 if (! load_debug_section (separate_debug_str, separate_debug_file))
1693 return _("<could not load separate string section>");
1694
1695 section = &debug_displays [separate_debug_str].section;
1696 if (section->start == NULL)
1697 return _("<no .debug_str section>");
1698
1699 if (offset >= section->size)
1700 {
1701 warn (_("DW_FORM_GNU_strp_alt offset too big: %s\n"), dwarf_vmatoa ("x", offset));
1702 return _("<offset is too big>");
1703 }
1704
1705 ret = (const char *) (section->start + offset);
1706 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1707 NUL byte. Since our caller is expecting to receive a well formed C
1708 string we test for the lack of a terminating byte here. */
1709 if (strnlen ((const char *) ret, section->size - offset)
1710 == section->size - offset)
1711 return _("<no NUL byte at end of .debug_str section>");
1712
1713 return ret;
1714}
1715
19e6b90e 1716static unsigned char *
dda8d76d
NC
1717read_and_display_attr_value (unsigned long attribute,
1718 unsigned long form,
1719 dwarf_signed_vma implicit_const,
1720 unsigned char * data,
1721 unsigned char * end,
1722 dwarf_vma cu_offset,
1723 dwarf_vma pointer_size,
1724 dwarf_vma offset_size,
1725 int dwarf_version,
1726 debug_info * debug_info_p,
1727 int do_loc,
1728 struct dwarf_section * section,
1729 struct cu_tu_set * this_set,
1730 char delimiter)
19e6b90e 1731{
467c65bc 1732 dwarf_vma uvalue = 0;
19e6b90e 1733 unsigned char *block_start = NULL;
6e3d6dc1 1734 unsigned char * orig_data = data;
19e6b90e
L
1735 unsigned int bytes_read;
1736
f41e4712 1737 if (data > end || (data == end && form != DW_FORM_flag_present))
0c588247 1738 {
f41e4712 1739 warn (_("Corrupt attribute\n"));
0c588247
NC
1740 return data;
1741 }
1742
19e6b90e
L
1743 switch (form)
1744 {
1745 default:
1746 break;
1747
1748 case DW_FORM_ref_addr:
1749 if (dwarf_version == 2)
0c588247 1750 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
932fd279 1751 else if (dwarf_version == 3 || dwarf_version == 4)
0c588247 1752 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
19e6b90e 1753 else
467c65bc
NC
1754 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1755
19e6b90e
L
1756 break;
1757
1758 case DW_FORM_addr:
0c588247 1759 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
19e6b90e
L
1760 break;
1761
1762 case DW_FORM_strp:
77145576 1763 case DW_FORM_line_strp:
932fd279 1764 case DW_FORM_sec_offset:
a081f3cd
JJ
1765 case DW_FORM_GNU_ref_alt:
1766 case DW_FORM_GNU_strp_alt:
0c588247 1767 SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
19e6b90e
L
1768 break;
1769
932fd279
JJ
1770 case DW_FORM_flag_present:
1771 uvalue = 1;
1772 break;
1773
19e6b90e
L
1774 case DW_FORM_ref1:
1775 case DW_FORM_flag:
1776 case DW_FORM_data1:
0c588247 1777 SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
19e6b90e
L
1778 break;
1779
1780 case DW_FORM_ref2:
1781 case DW_FORM_data2:
0c588247 1782 SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
19e6b90e
L
1783 break;
1784
1785 case DW_FORM_ref4:
1786 case DW_FORM_data4:
0c588247 1787 SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
19e6b90e
L
1788 break;
1789
1790 case DW_FORM_sdata:
f6f0e17b 1791 uvalue = read_sleb128 (data, & bytes_read, end);
19e6b90e
L
1792 data += bytes_read;
1793 break;
1794
4723351a 1795 case DW_FORM_GNU_str_index:
f6f0e17b 1796 uvalue = read_uleb128 (data, & bytes_read, end);
4723351a
CC
1797 data += bytes_read;
1798 break;
1799
19e6b90e
L
1800 case DW_FORM_ref_udata:
1801 case DW_FORM_udata:
f6f0e17b 1802 uvalue = read_uleb128 (data, & bytes_read, end);
19e6b90e
L
1803 data += bytes_read;
1804 break;
1805
1806 case DW_FORM_indirect:
f6f0e17b 1807 form = read_uleb128 (data, & bytes_read, end);
19e6b90e
L
1808 data += bytes_read;
1809 if (!do_loc)
ef0b5f1c 1810 printf ("%c%s", delimiter, get_FORM_name (form));
77145576
JK
1811 if (form == DW_FORM_implicit_const)
1812 {
1813 implicit_const = read_sleb128 (data, & bytes_read, end);
1814 data += bytes_read;
1815 }
1816 return read_and_display_attr_value (attribute, form, implicit_const, data,
1817 end, cu_offset, pointer_size,
19e6b90e 1818 offset_size, dwarf_version,
ec4d4525 1819 debug_info_p, do_loc,
ef0b5f1c 1820 section, this_set, delimiter);
4723351a 1821 case DW_FORM_GNU_addr_index:
f6f0e17b 1822 uvalue = read_uleb128 (data, & bytes_read, end);
4723351a
CC
1823 data += bytes_read;
1824 break;
19e6b90e
L
1825 }
1826
1827 switch (form)
1828 {
1829 case DW_FORM_ref_addr:
1830 if (!do_loc)
ef0b5f1c 1831 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
19e6b90e
L
1832 break;
1833
a081f3cd
JJ
1834 case DW_FORM_GNU_ref_alt:
1835 if (!do_loc)
ef0b5f1c 1836 printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
dda8d76d 1837 /* FIXME: Follow the reference... */
a081f3cd
JJ
1838 break;
1839
19e6b90e
L
1840 case DW_FORM_ref1:
1841 case DW_FORM_ref2:
1842 case DW_FORM_ref4:
1843 case DW_FORM_ref_udata:
1844 if (!do_loc)
ef0b5f1c 1845 printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset));
19e6b90e
L
1846 break;
1847
1848 case DW_FORM_data4:
1849 case DW_FORM_addr:
932fd279 1850 case DW_FORM_sec_offset:
19e6b90e 1851 if (!do_loc)
ef0b5f1c 1852 printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue));
19e6b90e
L
1853 break;
1854
932fd279 1855 case DW_FORM_flag_present:
19e6b90e
L
1856 case DW_FORM_flag:
1857 case DW_FORM_data1:
1858 case DW_FORM_data2:
1859 case DW_FORM_sdata:
1860 case DW_FORM_udata:
1861 if (!do_loc)
ef0b5f1c 1862 printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue));
19e6b90e
L
1863 break;
1864
77145576
JK
1865 case DW_FORM_implicit_const:
1866 if (!do_loc)
1867 printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const));
1868 break;
1869
19e6b90e
L
1870 case DW_FORM_ref8:
1871 case DW_FORM_data8:
2bc8690c 1872 if (!do_loc)
19e6b90e 1873 {
74bc6052 1874 dwarf_vma high_bits;
a69c4772 1875 dwarf_vma utmp;
74bc6052
CC
1876 char buf[64];
1877
0c588247 1878 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
a69c4772
NC
1879 utmp = uvalue;
1880 if (form == DW_FORM_ref8)
1881 add64 (& high_bits, & utmp, cu_offset);
ef0b5f1c 1882 printf ("%c0x%s", delimiter,
a69c4772 1883 dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf)));
19e6b90e 1884 }
0c588247 1885
19e6b90e
L
1886 if ((do_loc || do_debug_loc || do_debug_ranges)
1887 && num_debug_info_entries == 0)
1888 {
1889 if (sizeof (uvalue) == 8)
0c588247 1890 SAFE_BYTE_GET (uvalue, data, 8, end);
19e6b90e 1891 else
467c65bc 1892 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
19e6b90e 1893 }
0c588247 1894
19e6b90e
L
1895 data += 8;
1896 break;
1897
2f6cd591
JK
1898 case DW_FORM_data16:
1899 if (!do_loc)
1900 {
1901 dwarf_vma left_high_bits, left_low_bits;
1902 dwarf_vma right_high_bits, right_low_bits;
1903
1904 SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end);
1905 SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end);
1906 if (byte_get == byte_get_little_endian)
1907 {
1908 /* Swap them. */
1909 left_high_bits ^= right_high_bits;
1910 right_high_bits ^= left_high_bits;
1911 left_high_bits ^= right_high_bits;
1912 left_low_bits ^= right_low_bits;
1913 right_low_bits ^= left_low_bits;
1914 left_low_bits ^= right_low_bits;
1915 }
1916 printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x"
1917 "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x",
1918 left_high_bits, left_low_bits, right_high_bits,
1919 right_low_bits);
1920 }
1921 data += 16;
1922 break;
1923
19e6b90e
L
1924 case DW_FORM_string:
1925 if (!do_loc)
ef0b5f1c 1926 printf ("%c%.*s", delimiter, (int) (end - data), data);
0c588247 1927 data += strnlen ((char *) data, end - data) + 1;
19e6b90e
L
1928 break;
1929
1930 case DW_FORM_block:
932fd279 1931 case DW_FORM_exprloc:
f6f0e17b 1932 uvalue = read_uleb128 (data, & bytes_read, end);
19e6b90e 1933 block_start = data + bytes_read;
a1165289
NC
1934 if (block_start >= end)
1935 {
1936 warn (_("Block ends prematurely\n"));
1937 uvalue = 0;
1938 block_start = end;
1939 }
f3853b34
NC
1940 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1941 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1942 block_start + uvalue here. */
1943 data = block_start + uvalue;
f41e4712 1944 /* PR 17512: file: 008-103549-0.001:0.1. */
f3853b34 1945 if (block_start + uvalue > end || data < block_start)
f41e4712
NC
1946 {
1947 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1948 uvalue = end - block_start;
1949 }
19e6b90e
L
1950 if (do_loc)
1951 data = block_start + uvalue;
1952 else
ef0b5f1c 1953 data = display_block (block_start, uvalue, end, delimiter);
19e6b90e
L
1954 break;
1955
1956 case DW_FORM_block1:
0c588247 1957 SAFE_BYTE_GET (uvalue, data, 1, end);
19e6b90e 1958 block_start = data + 1;
a1165289
NC
1959 if (block_start >= end)
1960 {
1961 warn (_("Block ends prematurely\n"));
1962 uvalue = 0;
1963 block_start = end;
1964 }
f3853b34
NC
1965 data = block_start + uvalue;
1966 if (block_start + uvalue > end || data < block_start)
f41e4712
NC
1967 {
1968 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1969 uvalue = end - block_start;
1970 }
19e6b90e
L
1971 if (do_loc)
1972 data = block_start + uvalue;
1973 else
ef0b5f1c 1974 data = display_block (block_start, uvalue, end, delimiter);
19e6b90e
L
1975 break;
1976
1977 case DW_FORM_block2:
0c588247 1978 SAFE_BYTE_GET (uvalue, data, 2, end);
19e6b90e 1979 block_start = data + 2;
a1165289
NC
1980 if (block_start >= end)
1981 {
1982 warn (_("Block ends prematurely\n"));
1983 uvalue = 0;
1984 block_start = end;
1985 }
f3853b34
NC
1986 data = block_start + uvalue;
1987 if (block_start + uvalue > end || data < block_start)
f41e4712
NC
1988 {
1989 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
1990 uvalue = end - block_start;
1991 }
19e6b90e
L
1992 if (do_loc)
1993 data = block_start + uvalue;
1994 else
ef0b5f1c 1995 data = display_block (block_start, uvalue, end, delimiter);
19e6b90e
L
1996 break;
1997
1998 case DW_FORM_block4:
0c588247 1999 SAFE_BYTE_GET (uvalue, data, 4, end);
19e6b90e 2000 block_start = data + 4;
a1165289
NC
2001 /* PR 17512: file: 3371-3907-0.004. */
2002 if (block_start >= end)
2003 {
2004 warn (_("Block ends prematurely\n"));
2005 uvalue = 0;
2006 block_start = end;
2007 }
f3853b34
NC
2008 data = block_start + uvalue;
2009 if (block_start + uvalue > end
b4eb7656 2010 /* PR 17531: file: 5b5f0592. */
f3853b34 2011 || data < block_start)
f41e4712
NC
2012 {
2013 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
2014 uvalue = end - block_start;
2015 }
19e6b90e
L
2016 if (do_loc)
2017 data = block_start + uvalue;
2018 else
ef0b5f1c 2019 data = display_block (block_start, uvalue, end, delimiter);
19e6b90e
L
2020 break;
2021
2022 case DW_FORM_strp:
2023 if (!do_loc)
ef0b5f1c 2024 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter,
47704ddf
KT
2025 dwarf_vmatoa ("x", uvalue),
2026 fetch_indirect_string (uvalue));
19e6b90e
L
2027 break;
2028
77145576
JK
2029 case DW_FORM_line_strp:
2030 if (!do_loc)
2031 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter,
2032 dwarf_vmatoa ("x", uvalue),
2033 fetch_indirect_line_string (uvalue));
2034 break;
2035
4723351a
CC
2036 case DW_FORM_GNU_str_index:
2037 if (!do_loc)
b4eb7656
AM
2038 {
2039 const char *suffix = strrchr (section->name, '.');
2040 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
2041
ef0b5f1c 2042 printf (_("%c(indexed string: 0x%s): %s"), delimiter,
b4eb7656
AM
2043 dwarf_vmatoa ("x", uvalue),
2044 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
2045 }
4723351a
CC
2046 break;
2047
a081f3cd
JJ
2048 case DW_FORM_GNU_strp_alt:
2049 if (!do_loc)
dda8d76d
NC
2050 {
2051 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter,
2052 dwarf_vmatoa ("x", uvalue),
2053 fetch_alt_indirect_string (uvalue));
2054 }
a081f3cd
JJ
2055 break;
2056
19e6b90e
L
2057 case DW_FORM_indirect:
2058 /* Handled above. */
2059 break;
2060
2b6f5997
CC
2061 case DW_FORM_ref_sig8:
2062 if (!do_loc)
2063 {
74bc6052
CC
2064 dwarf_vma high_bits;
2065 char buf[64];
2066
0c588247 2067 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
ef0b5f1c 2068 printf ("%csignature: 0x%s", delimiter,
74bc6052 2069 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
2b6f5997 2070 }
74bc6052 2071 data += 8;
2b6f5997
CC
2072 break;
2073
4723351a
CC
2074 case DW_FORM_GNU_addr_index:
2075 if (!do_loc)
ef0b5f1c 2076 printf (_("%c(addr_index: 0x%s): %s"), delimiter,
b4eb7656
AM
2077 dwarf_vmatoa ("x", uvalue),
2078 fetch_indexed_value (uvalue * pointer_size, pointer_size));
4723351a
CC
2079 break;
2080
19e6b90e
L
2081 default:
2082 warn (_("Unrecognized form: %lu\n"), form);
2083 break;
2084 }
2085
19e6b90e 2086 if ((do_loc || do_debug_loc || do_debug_ranges)
fd2f0033
TT
2087 && num_debug_info_entries == 0
2088 && debug_info_p != NULL)
19e6b90e
L
2089 {
2090 switch (attribute)
2091 {
2092 case DW_AT_frame_base:
2093 have_frame_base = 1;
1a0670f3 2094 /* Fall through. */
19e6b90e 2095 case DW_AT_location:
9f272209 2096 case DW_AT_GNU_locviews:
e2a0d921
NC
2097 case DW_AT_string_length:
2098 case DW_AT_return_addr:
19e6b90e
L
2099 case DW_AT_data_member_location:
2100 case DW_AT_vtable_elem_location:
e2a0d921
NC
2101 case DW_AT_segment:
2102 case DW_AT_static_link:
2103 case DW_AT_use_location:
bc0a77d2 2104 case DW_AT_call_value:
629e7ca8 2105 case DW_AT_GNU_call_site_value:
bc0a77d2 2106 case DW_AT_call_data_value:
629e7ca8 2107 case DW_AT_GNU_call_site_data_value:
bc0a77d2 2108 case DW_AT_call_target:
629e7ca8 2109 case DW_AT_GNU_call_site_target:
bc0a77d2 2110 case DW_AT_call_target_clobbered:
629e7ca8 2111 case DW_AT_GNU_call_site_target_clobbered:
b4eb7656 2112 if ((dwarf_version < 4
212b6063 2113 && (form == DW_FORM_data4 || form == DW_FORM_data8))
932fd279 2114 || form == DW_FORM_sec_offset)
19e6b90e
L
2115 {
2116 /* Process location list. */
91d6fa6a 2117 unsigned int lmax = debug_info_p->max_loc_offsets;
19e6b90e
L
2118 unsigned int num = debug_info_p->num_loc_offsets;
2119
91d6fa6a 2120 if (lmax == 0 || num >= lmax)
19e6b90e 2121 {
91d6fa6a 2122 lmax += 1024;
467c65bc 2123 debug_info_p->loc_offsets = (dwarf_vma *)
b4eb7656
AM
2124 xcrealloc (debug_info_p->loc_offsets,
2125 lmax, sizeof (*debug_info_p->loc_offsets));
9f272209
AO
2126 debug_info_p->loc_views = (dwarf_vma *)
2127 xcrealloc (debug_info_p->loc_views,
2128 lmax, sizeof (*debug_info_p->loc_views));
3f5e193b 2129 debug_info_p->have_frame_base = (int *)
b4eb7656
AM
2130 xcrealloc (debug_info_p->have_frame_base,
2131 lmax, sizeof (*debug_info_p->have_frame_base));
91d6fa6a 2132 debug_info_p->max_loc_offsets = lmax;
19e6b90e 2133 }
341f9135 2134 if (this_set != NULL)
b4eb7656 2135 uvalue += this_set->section_offsets [DW_SECT_LOC];
19e6b90e 2136 debug_info_p->have_frame_base [num] = have_frame_base;
9f272209
AO
2137 if (attribute != DW_AT_GNU_locviews)
2138 {
2139 debug_info_p->loc_offsets [num] = uvalue;
2140 debug_info_p->num_loc_offsets++;
2141 assert (debug_info_p->num_loc_offsets
2142 - debug_info_p->num_loc_views <= 1);
2143 }
2144 else
2145 {
2146 assert (debug_info_p->num_loc_views <= num);
2147 num = debug_info_p->num_loc_views;
2148 debug_info_p->loc_views [num] = uvalue;
2149 debug_info_p->num_loc_views++;
2150 assert (debug_info_p->num_loc_views
2151 - debug_info_p->num_loc_offsets <= 1);
2152 }
19e6b90e
L
2153 }
2154 break;
e2a0d921 2155
19e6b90e
L
2156 case DW_AT_low_pc:
2157 if (need_base_address)
2158 debug_info_p->base_address = uvalue;
2159 break;
2160
4723351a 2161 case DW_AT_GNU_addr_base:
b4eb7656 2162 debug_info_p->addr_base = uvalue;
4723351a
CC
2163 break;
2164
2165 case DW_AT_GNU_ranges_base:
b4eb7656 2166 debug_info_p->ranges_base = uvalue;
4723351a
CC
2167 break;
2168
19e6b90e 2169 case DW_AT_ranges:
b4eb7656 2170 if ((dwarf_version < 4
212b6063 2171 && (form == DW_FORM_data4 || form == DW_FORM_data8))
932fd279 2172 || form == DW_FORM_sec_offset)
19e6b90e
L
2173 {
2174 /* Process range list. */
91d6fa6a 2175 unsigned int lmax = debug_info_p->max_range_lists;
19e6b90e
L
2176 unsigned int num = debug_info_p->num_range_lists;
2177
91d6fa6a 2178 if (lmax == 0 || num >= lmax)
19e6b90e 2179 {
91d6fa6a 2180 lmax += 1024;
467c65bc 2181 debug_info_p->range_lists = (dwarf_vma *)
b4eb7656
AM
2182 xcrealloc (debug_info_p->range_lists,
2183 lmax, sizeof (*debug_info_p->range_lists));
91d6fa6a 2184 debug_info_p->max_range_lists = lmax;
19e6b90e
L
2185 }
2186 debug_info_p->range_lists [num] = uvalue;
2187 debug_info_p->num_range_lists++;
2188 }
2189 break;
2190
2191 default:
2192 break;
2193 }
2194 }
2195
4ccf1e31 2196 if (do_loc || attribute == 0)
19e6b90e
L
2197 return data;
2198
ec4d4525 2199 /* For some attributes we can display further information. */
19e6b90e
L
2200 switch (attribute)
2201 {
2202 case DW_AT_inline:
2e9e81a8 2203 printf ("\t");
19e6b90e
L
2204 switch (uvalue)
2205 {
2206 case DW_INL_not_inlined:
2207 printf (_("(not inlined)"));
2208 break;
2209 case DW_INL_inlined:
2210 printf (_("(inlined)"));
2211 break;
2212 case DW_INL_declared_not_inlined:
2213 printf (_("(declared as inline but ignored)"));
2214 break;
2215 case DW_INL_declared_inlined:
2216 printf (_("(declared as inline and inlined)"));
2217 break;
2218 default:
47704ddf
KT
2219 printf (_(" (Unknown inline attribute value: %s)"),
2220 dwarf_vmatoa ("x", uvalue));
19e6b90e
L
2221 break;
2222 }
2223 break;
2224
2225 case DW_AT_language:
2e9e81a8 2226 printf ("\t");
19e6b90e
L
2227 switch (uvalue)
2228 {
4b78141a 2229 /* Ordered by the numeric value of these constants. */
19e6b90e 2230 case DW_LANG_C89: printf ("(ANSI C)"); break;
4b78141a
NC
2231 case DW_LANG_C: printf ("(non-ANSI C)"); break;
2232 case DW_LANG_Ada83: printf ("(Ada)"); break;
19e6b90e 2233 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
4b78141a
NC
2234 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
2235 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
19e6b90e
L
2236 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
2237 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
19e6b90e 2238 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
4b78141a 2239 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
19e6b90e 2240 /* DWARF 2.1 values. */
4b78141a 2241 case DW_LANG_Java: printf ("(Java)"); break;
19e6b90e
L
2242 case DW_LANG_C99: printf ("(ANSI C99)"); break;
2243 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
2244 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
4b78141a
NC
2245 /* DWARF 3 values. */
2246 case DW_LANG_PLI: printf ("(PLI)"); break;
2247 case DW_LANG_ObjC: printf ("(Objective C)"); break;
2248 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
2249 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
2250 case DW_LANG_D: printf ("(D)"); break;
2b6f5997
CC
2251 /* DWARF 4 values. */
2252 case DW_LANG_Python: printf ("(Python)"); break;
3362e0d9
ILT
2253 /* DWARF 5 values. */
2254 case DW_LANG_Go: printf ("(Go)"); break;
8bc10620 2255 case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break;
6ddfe5b4 2256 case DW_LANG_C11: printf ("(C11)"); break;
8bc10620 2257 case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break;
5a195044
MW
2258 case DW_LANG_Fortran03: printf ("(Fortran 03)"); break;
2259 case DW_LANG_Fortran08: printf ("(Fortran 08)"); break;
19e6b90e
L
2260 /* MIPS extension. */
2261 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
2262 /* UPC extension. */
2263 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
2264 default:
4b78141a 2265 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
9cf03b7e 2266 printf (_("(implementation defined: %s)"),
467c65bc 2267 dwarf_vmatoa ("x", uvalue));
4b78141a 2268 else
9cf03b7e 2269 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
19e6b90e
L
2270 break;
2271 }
2272 break;
2273
2274 case DW_AT_encoding:
2e9e81a8 2275 printf ("\t");
19e6b90e
L
2276 switch (uvalue)
2277 {
2278 case DW_ATE_void: printf ("(void)"); break;
2279 case DW_ATE_address: printf ("(machine address)"); break;
2280 case DW_ATE_boolean: printf ("(boolean)"); break;
2281 case DW_ATE_complex_float: printf ("(complex float)"); break;
2282 case DW_ATE_float: printf ("(float)"); break;
2283 case DW_ATE_signed: printf ("(signed)"); break;
2284 case DW_ATE_signed_char: printf ("(signed char)"); break;
2285 case DW_ATE_unsigned: printf ("(unsigned)"); break;
2286 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
e2a0d921 2287 /* DWARF 2.1 values: */
19e6b90e
L
2288 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
2289 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
e2a0d921
NC
2290 /* DWARF 3 values: */
2291 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
2292 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
2293 case DW_ATE_edited: printf ("(edited)"); break;
2294 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
2295 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
04914e37
NC
2296 /* DWARF 4 values: */
2297 case DW_ATE_UTF: printf ("(unicode string)"); break;
2298 /* DWARF 5 values: */
2299 case DW_ATE_UCS: printf ("(UCS)"); break;
2300 case DW_ATE_ASCII: printf ("(ASCII)"); break;
2301
e2a0d921
NC
2302 /* HP extensions: */
2303 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
2304 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
2305 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
2306 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
2307 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
2308 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
2309 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
2310
19e6b90e
L
2311 default:
2312 if (uvalue >= DW_ATE_lo_user
2313 && uvalue <= DW_ATE_hi_user)
9cf03b7e 2314 printf (_("(user defined type)"));
19e6b90e 2315 else
9cf03b7e 2316 printf (_("(unknown type)"));
19e6b90e
L
2317 break;
2318 }
2319 break;
2320
2321 case DW_AT_accessibility:
2e9e81a8 2322 printf ("\t");
19e6b90e
L
2323 switch (uvalue)
2324 {
2325 case DW_ACCESS_public: printf ("(public)"); break;
2326 case DW_ACCESS_protected: printf ("(protected)"); break;
2327 case DW_ACCESS_private: printf ("(private)"); break;
2328 default:
9cf03b7e 2329 printf (_("(unknown accessibility)"));
19e6b90e
L
2330 break;
2331 }
2332 break;
2333
2334 case DW_AT_visibility:
2e9e81a8 2335 printf ("\t");
19e6b90e
L
2336 switch (uvalue)
2337 {
2338 case DW_VIS_local: printf ("(local)"); break;
2339 case DW_VIS_exported: printf ("(exported)"); break;
2340 case DW_VIS_qualified: printf ("(qualified)"); break;
9cf03b7e 2341 default: printf (_("(unknown visibility)")); break;
19e6b90e
L
2342 }
2343 break;
2344
04914e37
NC
2345 case DW_AT_endianity:
2346 printf ("\t");
2347 switch (uvalue)
2348 {
2349 case DW_END_default: printf ("(default)"); break;
2350 case DW_END_big: printf ("(big)"); break;
2351 case DW_END_little: printf ("(little)"); break;
2352 default:
2353 if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user)
2354 printf (_("(user specified)"));
2355 else
2356 printf (_("(unknown endianity)"));
2357 break;
2358 }
2359 break;
2360
19e6b90e 2361 case DW_AT_virtuality:
2e9e81a8 2362 printf ("\t");
19e6b90e
L
2363 switch (uvalue)
2364 {
2365 case DW_VIRTUALITY_none: printf ("(none)"); break;
2366 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
2367 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
9cf03b7e 2368 default: printf (_("(unknown virtuality)")); break;
19e6b90e
L
2369 }
2370 break;
2371
2372 case DW_AT_identifier_case:
2e9e81a8 2373 printf ("\t");
19e6b90e
L
2374 switch (uvalue)
2375 {
2376 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
2377 case DW_ID_up_case: printf ("(up_case)"); break;
2378 case DW_ID_down_case: printf ("(down_case)"); break;
2379 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
9cf03b7e 2380 default: printf (_("(unknown case)")); break;
19e6b90e
L
2381 }
2382 break;
2383
2384 case DW_AT_calling_convention:
2e9e81a8 2385 printf ("\t");
19e6b90e
L
2386 switch (uvalue)
2387 {
2388 case DW_CC_normal: printf ("(normal)"); break;
2389 case DW_CC_program: printf ("(program)"); break;
2390 case DW_CC_nocall: printf ("(nocall)"); break;
04914e37
NC
2391 case DW_CC_pass_by_reference: printf ("(pass by ref)"); break;
2392 case DW_CC_pass_by_value: printf ("(pass by value)"); break;
2393 case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break;
2394 case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break;
19e6b90e
L
2395 default:
2396 if (uvalue >= DW_CC_lo_user
2397 && uvalue <= DW_CC_hi_user)
9cf03b7e 2398 printf (_("(user defined)"));
19e6b90e 2399 else
9cf03b7e 2400 printf (_("(unknown convention)"));
19e6b90e
L
2401 }
2402 break;
2403
2404 case DW_AT_ordering:
2e9e81a8 2405 printf ("\t");
19e6b90e
L
2406 switch (uvalue)
2407 {
04914e37 2408 case 255:
9cf03b7e 2409 case -1: printf (_("(undefined)")); break;
19e6b90e
L
2410 case 0: printf ("(row major)"); break;
2411 case 1: printf ("(column major)"); break;
2412 }
2413 break;
2414
04914e37
NC
2415 case DW_AT_decimal_sign:
2416 printf ("\t");
2417 switch (uvalue)
2418 {
2419 case DW_DS_unsigned: printf (_("(unsigned)")); break;
2420 case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break;
2421 case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break;
2422 case DW_DS_leading_separate: printf (_("(leading separate)")); break;
2423 case DW_DS_trailing_separate: printf (_("(trailing separate)")); break;
2424 default: printf (_("(unrecognised)")); break;
2425 }
2426 break;
2427
2428 case DW_AT_defaulted:
2429 printf ("\t");
2430 switch (uvalue)
2431 {
2432 case DW_DEFAULTED_no: printf (_("(no)")); break;
2433 case DW_DEFAULTED_in_class: printf (_("(in class)")); break;
2434 case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break;
2435 default: printf (_("(unrecognised)")); break;
2436 }
2437 break;
2438
2439 case DW_AT_discr_list:
2440 printf ("\t");
2441 switch (uvalue)
2442 {
2443 case DW_DSC_label: printf (_("(label)")); break;
2444 case DW_DSC_range: printf (_("(range)")); break;
2445 default: printf (_("(unrecognised)")); break;
2446 }
2447 break;
2448
19e6b90e
L
2449 case DW_AT_frame_base:
2450 have_frame_base = 1;
1a0670f3 2451 /* Fall through. */
19e6b90e 2452 case DW_AT_location:
e2a0d921
NC
2453 case DW_AT_string_length:
2454 case DW_AT_return_addr:
19e6b90e
L
2455 case DW_AT_data_member_location:
2456 case DW_AT_vtable_elem_location:
e2a0d921
NC
2457 case DW_AT_segment:
2458 case DW_AT_static_link:
2459 case DW_AT_use_location:
bc0a77d2 2460 case DW_AT_call_value:
629e7ca8 2461 case DW_AT_GNU_call_site_value:
bc0a77d2 2462 case DW_AT_call_data_value:
629e7ca8 2463 case DW_AT_GNU_call_site_data_value:
bc0a77d2 2464 case DW_AT_call_target:
629e7ca8 2465 case DW_AT_GNU_call_site_target:
bc0a77d2 2466 case DW_AT_call_target_clobbered:
629e7ca8 2467 case DW_AT_GNU_call_site_target_clobbered:
212b6063 2468 if ((dwarf_version < 4
b4eb7656 2469 && (form == DW_FORM_data4 || form == DW_FORM_data8))
932fd279 2470 || form == DW_FORM_sec_offset)
2e9e81a8 2471 printf (_(" (location list)"));
e2a0d921 2472 /* Fall through. */
19e6b90e
L
2473 case DW_AT_allocated:
2474 case DW_AT_associated:
2475 case DW_AT_data_location:
2476 case DW_AT_stride:
2477 case DW_AT_upper_bound:
cecf136e 2478 case DW_AT_lower_bound:
19e6b90e
L
2479 if (block_start)
2480 {
2481 int need_frame_base;
2482
2e9e81a8 2483 printf ("\t(");
19e6b90e
L
2484 need_frame_base = decode_location_expression (block_start,
2485 pointer_size,
b7807392
JJ
2486 offset_size,
2487 dwarf_version,
19e6b90e 2488 uvalue,
f1c4cc75 2489 cu_offset, section);
19e6b90e
L
2490 printf (")");
2491 if (need_frame_base && !have_frame_base)
2492 printf (_(" [without DW_AT_frame_base]"));
2493 }
19e6b90e
L
2494 break;
2495
ec4d4525
NC
2496 case DW_AT_import:
2497 {
a081f3cd
JJ
2498 if (form == DW_FORM_ref_sig8
2499 || form == DW_FORM_GNU_ref_alt)
b4eb7656 2500 break;
2b6f5997 2501
ec4d4525
NC
2502 if (form == DW_FORM_ref1
2503 || form == DW_FORM_ref2
a7a0b6a5
JK
2504 || form == DW_FORM_ref4
2505 || form == DW_FORM_ref_udata)
ec4d4525
NC
2506 uvalue += cu_offset;
2507
6e3d6dc1 2508 if (uvalue >= section->size)
f3853b34 2509 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
47704ddf
KT
2510 dwarf_vmatoa ("x", uvalue),
2511 (unsigned long) (orig_data - section->start));
6e3d6dc1
NC
2512 else
2513 {
2514 unsigned long abbrev_number;
2515 abbrev_entry * entry;
2516
f6f0e17b 2517 abbrev_number = read_uleb128 (section->start + uvalue, NULL, end);
cecf136e 2518
2e9e81a8 2519 printf (_("\t[Abbrev Number: %ld"), abbrev_number);
afd6e1ff
JJ
2520 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2521 use different abbrev table, and we don't track .debug_info chunks
2522 yet. */
2523 if (form != DW_FORM_ref_addr)
2524 {
2525 for (entry = first_abbrev; entry != NULL; entry = entry->next)
2526 if (entry->entry == abbrev_number)
2527 break;
2528 if (entry != NULL)
2529 printf (" (%s)", get_TAG_name (entry->tag));
2530 }
6e3d6dc1
NC
2531 printf ("]");
2532 }
ec4d4525
NC
2533 }
2534 break;
2535
19e6b90e
L
2536 default:
2537 break;
2538 }
2539
2540 return data;
2541}
2542
a19c41a7 2543static const char *
19e6b90e
L
2544get_AT_name (unsigned long attribute)
2545{
a19c41a7 2546 const char *name;
e2a0d921 2547
399c99f7
L
2548 if (attribute == 0)
2549 return "DW_AT value: 0";
2550
a19c41a7
TT
2551 /* One value is shared by the MIPS and HP extensions: */
2552 if (attribute == DW_AT_MIPS_fde)
2553 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
19e6b90e 2554
a19c41a7
TT
2555 name = get_DW_AT_name (attribute);
2556
2557 if (name == NULL)
2558 {
2559 static char buffer[100];
2560
2561 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
2562 attribute);
2563 return buffer;
19e6b90e 2564 }
a19c41a7
TT
2565
2566 return name;
19e6b90e
L
2567}
2568
2569static unsigned char *
dda8d76d
NC
2570read_and_display_attr (unsigned long attribute,
2571 unsigned long form,
2572 dwarf_signed_vma implicit_const,
2573 unsigned char * data,
2574 unsigned char * end,
2575 dwarf_vma cu_offset,
2576 dwarf_vma pointer_size,
2577 dwarf_vma offset_size,
2578 int dwarf_version,
2579 debug_info * debug_info_p,
2580 int do_loc,
2581 struct dwarf_section * section,
2582 struct cu_tu_set * this_set)
19e6b90e
L
2583{
2584 if (!do_loc)
750f03b7 2585 printf (" %-18s:", get_AT_name (attribute));
77145576 2586 data = read_and_display_attr_value (attribute, form, implicit_const, data, end,
f6f0e17b 2587 cu_offset, pointer_size, offset_size,
19e6b90e 2588 dwarf_version, debug_info_p,
ef0b5f1c 2589 do_loc, section, this_set, ' ');
19e6b90e
L
2590 if (!do_loc)
2591 printf ("\n");
2592 return data;
2593}
2594
dda8d76d
NC
2595/* Like load_debug_section, but if the ordinary call fails, and we are
2596 following debug links, and we have been able to load a separate debug
2597 info file, then attempt to load the requested section from the separate
2598 file. */
2599
2600static bfd_boolean
2601load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum,
2602 void * data)
2603{
2604 if (load_debug_section (sec_enum, data))
2605 {
2606 if (data == separate_debug_file)
2607 debug_displays[sec_enum].section.filename = separate_debug_filename;
2608
2609 /* FIXME: We should check to see if there is a separate debug info file
2610 that also contains this section, and if so, issue a warning. */
2611 return TRUE;
2612 }
2613
2614 if (do_follow_links && separate_debug_file != NULL)
2615 if (load_debug_section (sec_enum, separate_debug_file))
2616 {
2617 debug_displays[sec_enum].section.filename = separate_debug_filename;
2618 return TRUE;
2619 }
2620
2621 return FALSE;
2622}
2623
2624static void
2625introduce (struct dwarf_section * section, bfd_boolean raw)
2626{
2627 if (raw)
2628 {
2629 if (do_follow_links && section->filename)
2630 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
2631 section->name, section->filename);
2632 else
2633 printf (_("Raw dump of debug contents of section %s:\n\n"), section->name);
2634 }
2635 else
2636 {
2637 if (do_follow_links && section->filename)
2638 printf (_("Contents of the %s section (loaded from %s):\n\n"),
2639 section->name, section->filename);
2640 else
2641 printf (_("Contents of the %s section:\n\n"), section->name);
2642 }
2643}
2644
19e6b90e
L
2645/* Process the contents of a .debug_info section. If do_loc is non-zero
2646 then we are scanning for location lists and we do not want to display
2b6f5997
CC
2647 anything to the user. If do_types is non-zero, we are processing
2648 a .debug_types section instead of a .debug_info section. */
19e6b90e
L
2649
2650static int
6e3d6dc1
NC
2651process_debug_info (struct dwarf_section *section,
2652 void *file,
b4eb7656 2653 enum dwarf_section_display_enum abbrev_sec,
2b6f5997
CC
2654 int do_loc,
2655 int do_types)
19e6b90e
L
2656{
2657 unsigned char *start = section->start;
2658 unsigned char *end = start + section->size;
2659 unsigned char *section_begin;
2660 unsigned int unit;
2661 unsigned int num_units = 0;
2662
2663 if ((do_loc || do_debug_loc || do_debug_ranges)
2b6f5997
CC
2664 && num_debug_info_entries == 0
2665 && ! do_types)
19e6b90e 2666 {
767221a9 2667 dwarf_vma length;
19e6b90e
L
2668
2669 /* First scan the section to get the number of comp units. */
2670 for (section_begin = start, num_units = 0; section_begin < end;
2671 num_units ++)
2672 {
2673 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2674 will be the length. For a 64-bit DWARF section, it'll be
2675 the escape code 0xffffffff followed by an 8 byte length. */
0c588247 2676 SAFE_BYTE_GET (length, section_begin, 4, end);
19e6b90e
L
2677
2678 if (length == 0xffffffff)
2679 {
0c588247 2680 SAFE_BYTE_GET (length, section_begin + 4, 8, end);
19e6b90e
L
2681 section_begin += length + 12;
2682 }
ec4d4525
NC
2683 else if (length >= 0xfffffff0 && length < 0xffffffff)
2684 {
767221a9
NC
2685 warn (_("Reserved length value (0x%s) found in section %s\n"),
2686 dwarf_vmatoa ("x", length), section->name);
ec4d4525
NC
2687 return 0;
2688 }
19e6b90e
L
2689 else
2690 section_begin += length + 4;
aca88567
NC
2691
2692 /* Negative values are illegal, they may even cause infinite
2693 looping. This can happen if we can't accurately apply
f3853b34
NC
2694 relocations to an object file, or if the file is corrupt. */
2695 if ((signed long) length <= 0 || section_begin < start)
aca88567 2696 {
767221a9
NC
2697 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2698 dwarf_vmatoa ("x", length), section->name);
aca88567
NC
2699 return 0;
2700 }
19e6b90e
L
2701 }
2702
2703 if (num_units == 0)
2704 {
f41e4712 2705 error (_("No comp units in %s section ?\n"), section->name);
19e6b90e
L
2706 return 0;
2707 }
2708
2709 /* Then allocate an array to hold the information. */
3f5e193b 2710 debug_information = (debug_info *) cmalloc (num_units,
1306a742 2711 sizeof (* debug_information));
19e6b90e
L
2712 if (debug_information == NULL)
2713 {
f41e4712 2714 error (_("Not enough memory for a debug info array of %u entries\n"),
19e6b90e 2715 num_units);
82b1b41b 2716 alloc_num_debug_info_entries = num_debug_info_entries = 0;
19e6b90e
L
2717 return 0;
2718 }
03a91817
NC
2719 /* PR 17531: file: 92ca3797.
2720 We cannot rely upon the debug_information array being initialised
2721 before it is used. A corrupt file could easily contain references
2722 to a unit for which information has not been made available. So
2723 we ensure that the array is zeroed here. */
b4eb7656
AM
2724 memset (debug_information, 0, num_units * sizeof (*debug_information));
2725
82b1b41b 2726 alloc_num_debug_info_entries = num_units;
19e6b90e
L
2727 }
2728
2729 if (!do_loc)
2730 {
dda8d76d
NC
2731 load_debug_section_with_follow (str, file);
2732 load_debug_section_with_follow (line_str, file);
2733 load_debug_section_with_follow (str_dwo, file);
2734 load_debug_section_with_follow (str_index, file);
2735 load_debug_section_with_follow (str_index_dwo, file);
2736 load_debug_section_with_follow (debug_addr, file);
19e6b90e
L
2737 }
2738
dda8d76d 2739 load_debug_section_with_follow (abbrev_sec, file);
6f875884 2740 if (debug_displays [abbrev_sec].section.start == NULL)
19e6b90e
L
2741 {
2742 warn (_("Unable to locate %s section!\n"),
dda8d76d 2743 debug_displays [abbrev_sec].section.uncompressed_name);
19e6b90e
L
2744 return 0;
2745 }
2746
dda8d76d
NC
2747 if (!do_loc && dwarf_start_die == 0)
2748 introduce (section, FALSE);
2749
19e6b90e
L
2750 for (section_begin = start, unit = 0; start < end; unit++)
2751 {
2752 DWARF2_Internal_CompUnit compunit;
2753 unsigned char *hdrptr;
19e6b90e 2754 unsigned char *tags;
fd2f0033 2755 int level, last_level, saved_level;
467c65bc 2756 dwarf_vma cu_offset;
e98fdf1a 2757 unsigned long sec_off;
bf5117e3 2758 unsigned int offset_size;
19485196 2759 unsigned int initial_length_size;
74bc6052
CC
2760 dwarf_vma signature_high = 0;
2761 dwarf_vma signature_low = 0;
767221a9 2762 dwarf_vma type_offset = 0;
341f9135
CC
2763 struct cu_tu_set *this_set;
2764 dwarf_vma abbrev_base;
2765 size_t abbrev_size;
19e6b90e
L
2766
2767 hdrptr = start;
2768
0c588247 2769 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
19e6b90e
L
2770
2771 if (compunit.cu_length == 0xffffffff)
2772 {
0c588247 2773 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
19e6b90e
L
2774 offset_size = 8;
2775 initial_length_size = 12;
2776 }
2777 else
2778 {
2779 offset_size = 4;
2780 initial_length_size = 4;
2781 }
2782
0c588247 2783 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
19e6b90e
L
2784
2785 cu_offset = start - section_begin;
19e6b90e 2786
341f9135
CC
2787 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2788
77145576
JK
2789 if (compunit.cu_version < 5)
2790 {
2791 compunit.cu_unit_type = DW_UT_compile;
2792 /* Initialize it due to a false compiler warning. */
2793 compunit.cu_pointer_size = -1;
2794 }
2795 else
2796 {
2797 SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end);
2798 do_types = (compunit.cu_unit_type == DW_UT_type);
2799
2800 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2801 }
2802
0c588247 2803 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
19e6b90e 2804
341f9135
CC
2805 if (this_set == NULL)
2806 {
2807 abbrev_base = 0;
2808 abbrev_size = debug_displays [abbrev_sec].section.size;
2809 }
2810 else
2811 {
2812 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2813 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2814 }
2815
77145576
JK
2816 if (compunit.cu_version < 5)
2817 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2818
f41e4712
NC
2819 /* PR 17512: file: 001-108546-0.001:0.1. */
2820 if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
2821 {
2822 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2823 compunit.cu_pointer_size, offset_size);
2824 compunit.cu_pointer_size = offset_size;
2825 }
2b6f5997
CC
2826
2827 if (do_types)
b4eb7656 2828 {
0c588247 2829 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
f048b142 2830 hdrptr += 8;
0c588247 2831 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
b4eb7656 2832 }
2b6f5997 2833
ae7e7825
NC
2834 if (dwarf_start_die > (cu_offset + compunit.cu_length
2835 + initial_length_size))
2836 {
2837 start = section_begin + cu_offset + compunit.cu_length
2838 + initial_length_size;
2839 continue;
2840 }
2841
19e6b90e 2842 if ((do_loc || do_debug_loc || do_debug_ranges)
2b6f5997
CC
2843 && num_debug_info_entries == 0
2844 && ! do_types)
19e6b90e
L
2845 {
2846 debug_information [unit].cu_offset = cu_offset;
2847 debug_information [unit].pointer_size
2848 = compunit.cu_pointer_size;
b7807392
JJ
2849 debug_information [unit].offset_size = offset_size;
2850 debug_information [unit].dwarf_version = compunit.cu_version;
19e6b90e 2851 debug_information [unit].base_address = 0;
4723351a
CC
2852 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2853 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
19e6b90e
L
2854 debug_information [unit].loc_offsets = NULL;
2855 debug_information [unit].have_frame_base = NULL;
2856 debug_information [unit].max_loc_offsets = 0;
2857 debug_information [unit].num_loc_offsets = 0;
2858 debug_information [unit].range_lists = NULL;
2859 debug_information [unit].max_range_lists= 0;
2860 debug_information [unit].num_range_lists = 0;
2861 }
2862
fd2f0033 2863 if (!do_loc && dwarf_start_die == 0)
19e6b90e 2864 {
47704ddf
KT
2865 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2866 dwarf_vmatoa ("x", cu_offset));
2867 printf (_(" Length: 0x%s (%s)\n"),
2868 dwarf_vmatoa ("x", compunit.cu_length),
49e7b350 2869 offset_size == 8 ? "64-bit" : "32-bit");
19e6b90e 2870 printf (_(" Version: %d\n"), compunit.cu_version);
7282333f
AM
2871 printf (_(" Abbrev Offset: 0x%s\n"),
2872 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
19e6b90e 2873 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2b6f5997
CC
2874 if (do_types)
2875 {
74bc6052
CC
2876 char buf[64];
2877
2878 printf (_(" Signature: 0x%s\n"),
2879 dwarf_vmatoa64 (signature_high, signature_low,
2880 buf, sizeof (buf)));
2881 printf (_(" Type Offset: 0x%s\n"),
2882 dwarf_vmatoa ("x", type_offset));
2b6f5997 2883 }
341f9135
CC
2884 if (this_set != NULL)
2885 {
2886 dwarf_vma *offsets = this_set->section_offsets;
2887 size_t *sizes = this_set->section_sizes;
2888
2889 printf (_(" Section contributions:\n"));
2890 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2891 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2892 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2893 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2894 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2895 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2896 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2897 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2898 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2899 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2900 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2901 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2902 }
19e6b90e
L
2903 }
2904
e98fdf1a
AM
2905 sec_off = cu_offset + initial_length_size;
2906 if (sec_off + compunit.cu_length < sec_off
2907 || sec_off + compunit.cu_length > section->size)
460c89ff 2908 {
e98fdf1a
AM
2909 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
2910 section->name,
2911 (unsigned long) cu_offset,
19485196
NC
2912 dwarf_vmatoa ("x", compunit.cu_length));
2913 num_units = unit;
2914 break;
2915 }
2916
460c89ff
NS
2917 tags = hdrptr;
2918 start += compunit.cu_length + initial_length_size;
2919
77145576 2920 if (compunit.cu_version < 2 || compunit.cu_version > 5)
19e6b90e 2921 {
47704ddf
KT
2922 warn (_("CU at offset %s contains corrupt or "
2923 "unsupported version number: %d.\n"),
2924 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
19e6b90e
L
2925 continue;
2926 }
2927
77145576
JK
2928 if (compunit.cu_unit_type != DW_UT_compile
2929 && compunit.cu_unit_type != DW_UT_type)
2930 {
2931 warn (_("CU at offset %s contains corrupt or "
2932 "unsupported unit type: %d.\n"),
2933 dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type);
2934 continue;
2935 }
2936
19e6b90e
L
2937 free_abbrevs ();
2938
d493b283 2939 /* Process the abbrevs used by this compilation unit. */
341f9135 2940 if (compunit.cu_abbrev_offset >= abbrev_size)
ec4d4525
NC
2941 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2942 (unsigned long) compunit.cu_abbrev_offset,
341f9135 2943 (unsigned long) abbrev_size);
b4eb7656 2944 /* PR 17531: file:4bcd9ce9. */
a0a3b04c
L
2945 else if ((abbrev_base + abbrev_size)
2946 > debug_displays [abbrev_sec].section.size)
2947 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2948 (unsigned long) abbrev_base + abbrev_size,
2949 (unsigned long) debug_displays [abbrev_sec].section.size);
460c89ff
NS
2950 else
2951 process_abbrev_section
341f9135
CC
2952 (((unsigned char *) debug_displays [abbrev_sec].section.start
2953 + abbrev_base + compunit.cu_abbrev_offset),
2954 ((unsigned char *) debug_displays [abbrev_sec].section.start
2955 + abbrev_base + abbrev_size));
19e6b90e
L
2956
2957 level = 0;
fd2f0033
TT
2958 last_level = level;
2959 saved_level = -1;
19e6b90e
L
2960 while (tags < start)
2961 {
2962 unsigned int bytes_read;
2963 unsigned long abbrev_number;
ec4d4525 2964 unsigned long die_offset;
19e6b90e
L
2965 abbrev_entry *entry;
2966 abbrev_attr *attr;
fd2f0033 2967 int do_printing = 1;
19e6b90e 2968
ec4d4525
NC
2969 die_offset = tags - section_begin;
2970
f6f0e17b 2971 abbrev_number = read_uleb128 (tags, & bytes_read, start);
19e6b90e
L
2972 tags += bytes_read;
2973
eb7cc021
JK
2974 /* A null DIE marks the end of a list of siblings or it may also be
2975 a section padding. */
19e6b90e
L
2976 if (abbrev_number == 0)
2977 {
eb7cc021
JK
2978 /* Check if it can be a section padding for the last CU. */
2979 if (level == 0 && start == end)
2980 {
2981 unsigned char *chk;
2982
2983 for (chk = tags; chk < start; chk++)
2984 if (*chk != 0)
2985 break;
2986 if (chk == start)
2987 break;
2988 }
2989
4337774f
TT
2990 if (!do_loc && die_offset >= dwarf_start_die
2991 && (dwarf_cutoff_level == -1
2992 || level < dwarf_cutoff_level))
399c99f7
L
2993 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2994 level, die_offset);
2995
19e6b90e 2996 --level;
ec4d4525
NC
2997 if (level < 0)
2998 {
2999 static unsigned num_bogus_warns = 0;
3000
3001 if (num_bogus_warns < 3)
3002 {
4723351a
CC
3003 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3004 die_offset, section->name);
ec4d4525
NC
3005 num_bogus_warns ++;
3006 if (num_bogus_warns == 3)
3007 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3008 }
3009 }
fd2f0033
TT
3010 if (dwarf_start_die != 0 && level < saved_level)
3011 return 1;
19e6b90e
L
3012 continue;
3013 }
3014
4b78141a 3015 if (!do_loc)
fd2f0033
TT
3016 {
3017 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
3018 do_printing = 0;
3019 else
3020 {
3021 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
3022 saved_level = level;
3023 do_printing = (dwarf_cutoff_level == -1
3024 || level < dwarf_cutoff_level);
3025 if (do_printing)
3026 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3027 level, die_offset, abbrev_number);
3028 else if (dwarf_cutoff_level == -1
3029 || last_level < dwarf_cutoff_level)
3030 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
3031 last_level = level;
3032 }
3033 }
cecf136e 3034
19e6b90e
L
3035 /* Scan through the abbreviation list until we reach the
3036 correct entry. */
3037 for (entry = first_abbrev;
3038 entry && entry->entry != abbrev_number;
3039 entry = entry->next)
3040 continue;
3041
3042 if (entry == NULL)
3043 {
fd2f0033 3044 if (!do_loc && do_printing)
4b78141a
NC
3045 {
3046 printf ("\n");
3047 fflush (stdout);
3048 }
f3853b34 3049 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
cc86f28f 3050 die_offset, abbrev_number);
19e6b90e
L
3051 return 0;
3052 }
3053
fd2f0033 3054 if (!do_loc && do_printing)
cc5914eb 3055 printf (" (%s)\n", get_TAG_name (entry->tag));
cecf136e 3056
19e6b90e
L
3057 switch (entry->tag)
3058 {
3059 default:
3060 need_base_address = 0;
3061 break;
3062 case DW_TAG_compile_unit:
3063 need_base_address = 1;
3064 break;
3065 case DW_TAG_entry_point:
19e6b90e
L
3066 case DW_TAG_subprogram:
3067 need_base_address = 0;
3068 /* Assuming that there is no DW_AT_frame_base. */
3069 have_frame_base = 0;
3070 break;
3071 }
3072
9f272209
AO
3073 debug_info *debug_info_p =
3074 (debug_information && unit < alloc_num_debug_info_entries)
3075 ? debug_information + unit : NULL;
3076
3077 assert (!debug_info_p
3078 || (debug_info_p->num_loc_offsets
3079 == debug_info_p->num_loc_views));
3080
399c99f7
L
3081 for (attr = entry->first_attr;
3082 attr && attr->attribute;
3083 attr = attr->next)
4b78141a 3084 {
fd2f0033 3085 if (! do_loc && do_printing)
4b78141a 3086 /* Show the offset from where the tag was extracted. */
fd2f0033
TT
3087 printf (" <%lx>", (unsigned long)(tags - section_begin));
3088
4b78141a
NC
3089 tags = read_and_display_attr (attr->attribute,
3090 attr->form,
77145576 3091 attr->implicit_const,
341f9135 3092 tags,
f6f0e17b 3093 end,
341f9135 3094 cu_offset,
4b78141a
NC
3095 compunit.cu_pointer_size,
3096 offset_size,
3097 compunit.cu_version,
9f272209 3098 debug_info_p,
341f9135
CC
3099 do_loc || ! do_printing,
3100 section,
3101 this_set);
4b78141a 3102 }
cecf136e 3103
9f272209
AO
3104 /* If a locview attribute appears before a location one,
3105 make sure we don't associate it with an earlier
3106 loclist. */
3107 if (debug_info_p)
3108 switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views)
3109 {
3110 case 1:
3111 debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1;
3112 debug_info_p->num_loc_views++;
3113 assert (debug_info_p->num_loc_views
3114 == debug_info_p->num_loc_offsets);
3115 break;
3116
3117 case 0:
3118 break;
3119
3120 case -1:
3121 warn(_("DIE has locviews without loclist\n"));
3122 debug_info_p->num_loc_views--;
3123 break;
3124
3125 default:
3126 assert (0);
3127 }
3128
b4eb7656
AM
3129 if (entry->children)
3130 ++level;
3131 }
19e6b90e 3132 }
cecf136e 3133
19e6b90e
L
3134 /* Set num_debug_info_entries here so that it can be used to check if
3135 we need to process .debug_loc and .debug_ranges sections. */
3136 if ((do_loc || do_debug_loc || do_debug_ranges)
2b6f5997
CC
3137 && num_debug_info_entries == 0
3138 && ! do_types)
82b1b41b 3139 {
b4eb7656 3140 if (num_units > alloc_num_debug_info_entries)
82b1b41b
NC
3141 num_debug_info_entries = alloc_num_debug_info_entries;
3142 else
3143 num_debug_info_entries = num_units;
3144 }
cecf136e 3145
19e6b90e 3146 if (!do_loc)
467c65bc 3147 printf ("\n");
cecf136e 3148
19e6b90e
L
3149 return 1;
3150}
3151
3152/* Locate and scan the .debug_info section in the file and record the pointer
3153 sizes and offsets for the compilation units in it. Usually an executable
3154 will have just one pointer size, but this is not guaranteed, and so we try
3155 not to make any assumptions. Returns zero upon failure, or the number of
3156 compilation units upon success. */
3157
3158static unsigned int
3159load_debug_info (void * file)
3160{
1febe64d 3161 /* If we have already tried and failed to load the .debug_info
657d0d47 3162 section then do not bother to repeat the task. */
cc86f28f 3163 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
1febe64d
NC
3164 return 0;
3165
19e6b90e
L
3166 /* If we already have the information there is nothing else to do. */
3167 if (num_debug_info_entries > 0)
3168 return num_debug_info_entries;
3169
341f9135 3170 /* If this is a DWARF package file, load the CU and TU indexes. */
43a444f9 3171 (void) load_cu_tu_indexes (file);
341f9135 3172
dda8d76d 3173 if (load_debug_section_with_follow (info, file)
6f875884 3174 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
19e6b90e 3175 return num_debug_info_entries;
82b1b41b 3176
dda8d76d 3177 if (load_debug_section_with_follow (info_dwo, file)
82b1b41b
NC
3178 && process_debug_info (&debug_displays [info_dwo].section, file,
3179 abbrev_dwo, 1, 0))
4723351a 3180 return num_debug_info_entries;
1febe64d 3181
cc86f28f 3182 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
1febe64d 3183 return 0;
19e6b90e
L
3184}
3185
b40bf0a2
NC
3186/* Read a DWARF .debug_line section header starting at DATA.
3187 Upon success returns an updated DATA pointer and the LINFO
3188 structure and the END_OF_SEQUENCE pointer will be filled in.
3189 Otherwise returns NULL. */
19e6b90e 3190
b40bf0a2
NC
3191static unsigned char *
3192read_debug_line_header (struct dwarf_section * section,
3193 unsigned char * data,
3194 unsigned char * end,
3195 DWARF2_Internal_LineInfo * linfo,
3196 unsigned char ** end_of_sequence)
3197{
3198 unsigned char *hdrptr;
b40bf0a2 3199 unsigned int initial_length_size;
77145576 3200 unsigned char address_size, segment_selector_size;
19e6b90e 3201
b40bf0a2
NC
3202 /* Extract information from the Line Number Program Header.
3203 (section 6.2.4 in the Dwarf3 doc). */
6937bb54 3204 hdrptr = data;
19e6b90e 3205
b40bf0a2
NC
3206 /* Get and check the length of the block. */
3207 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
19e6b90e 3208
b40bf0a2 3209 if (linfo->li_length == 0xffffffff)
f41e4712
NC
3210 {
3211 /* This section is 64-bit DWARF 3. */
b40bf0a2 3212 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
77145576 3213 linfo->li_offset_size = 8;
f41e4712
NC
3214 initial_length_size = 12;
3215 }
3216 else
3217 {
77145576 3218 linfo->li_offset_size = 4;
f41e4712
NC
3219 initial_length_size = 4;
3220 }
19e6b90e 3221
b40bf0a2 3222 if (linfo->li_length + initial_length_size > section->size)
f41e4712 3223 {
8fcc61b4
NC
3224 /* If the length field has a relocation against it, then we should
3225 not complain if it is inaccurate (and probably negative). This
3226 happens in object files when the .debug_line section is actually
3227 comprised of several different .debug_line.* sections, (some of
3228 which may be removed by linker garbage collection), and a relocation
3229 is used to compute the correct length once that is done. */
77145576 3230 if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size))
b40bf0a2 3231 {
8fcc61b4 3232 linfo->li_length = (end - data) - initial_length_size;
b40bf0a2
NC
3233 }
3234 else
3235 {
8fcc61b4
NC
3236 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3237 (long) linfo->li_length);
b40bf0a2
NC
3238 return NULL;
3239 }
f41e4712 3240 }
19e6b90e 3241
b40bf0a2
NC
3242 /* Get and check the version number. */
3243 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
3244
3245 if (linfo->li_version != 2
3246 && linfo->li_version != 3
77145576
JK
3247 && linfo->li_version != 4
3248 && linfo->li_version != 5)
f41e4712 3249 {
77145576
JK
3250 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3251 "is currently supported.\n"));
b40bf0a2 3252 return NULL;
f41e4712 3253 }
19e6b90e 3254
77145576
JK
3255 if (linfo->li_version >= 5)
3256 {
3257 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
3258
3259 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
3260 if (segment_selector_size != 0)
3261 {
3262 warn (_("The %s section contains "
3263 "unsupported segment selector size: %d.\n"),
3264 section->name, segment_selector_size);
3265 return 0;
3266 }
3267 }
3268
3269 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr,
3270 linfo->li_offset_size, end);
b40bf0a2 3271 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
0c588247 3272
b40bf0a2 3273 if (linfo->li_version >= 4)
f41e4712 3274 {
b40bf0a2 3275 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
0c588247 3276
b40bf0a2 3277 if (linfo->li_max_ops_per_insn == 0)
f41e4712
NC
3278 {
3279 warn (_("Invalid maximum operations per insn.\n"));
b40bf0a2 3280 return NULL;
a233b20c 3281 }
f41e4712
NC
3282 }
3283 else
b40bf0a2 3284 linfo->li_max_ops_per_insn = 1;
0c588247 3285
b40bf0a2 3286 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
65879393 3287 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
b40bf0a2
NC
3288 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
3289 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
19e6b90e 3290
b40bf0a2 3291 * end_of_sequence = data + linfo->li_length + initial_length_size;
b4eb7656 3292 /* PR 17512: file:002-117414-0.004. */
6937bb54
NC
3293 if (* end_of_sequence > end)
3294 {
4c219c2e
AM
3295 warn (_("Line length %s extends beyond end of section\n"),
3296 dwarf_vmatoa ("u", linfo->li_length));
6937bb54
NC
3297 * end_of_sequence = end;
3298 return NULL;
3299 }
3300
b40bf0a2
NC
3301 return hdrptr;
3302}
19e6b90e 3303
77145576 3304static unsigned char *
dda8d76d
NC
3305display_formatted_table (unsigned char * data,
3306 unsigned char * start,
3307 unsigned char * end,
3308 const DWARF2_Internal_LineInfo * linfo,
3309 struct dwarf_section * section,
3310 const char * what)
77145576
JK
3311{
3312 unsigned char *format_start, format_count, *format, formati;
3313 dwarf_vma data_count, datai;
3314 unsigned int bytes_read, namepass, last_entry = 0;
3315
3316 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3317 format_start = data;
3318 for (formati = 0; formati < format_count; formati++)
3319 {
3320 read_uleb128 (data, & bytes_read, end);
3321 data += bytes_read;
3322 read_uleb128 (data, & bytes_read, end);
3323 data += bytes_read;
3324 if (data == end)
3325 {
14357de1 3326 warn (_("Corrupt %s format table entry\n"), what);
77145576
JK
3327 return data;
3328 }
3329 }
3330
3331 data_count = read_uleb128 (data, & bytes_read, end);
3332 data += bytes_read;
3333 if (data == end)
3334 {
3335 warn (_("Corrupt %s list\n"), what);
3336 return data;
3337 }
3338
3339 if (data_count == 0)
3340 {
3341 printf (_("\n The %s Table is empty.\n"), what);
3342 return data;
3343 }
3344
3345 printf (_("\n The %s Table (offset 0x%lx):\n"), what,
3346 (long)(data - start));
3347
3348 printf (_(" Entry"));
3349 /* Delay displaying name as the last entry for better screen layout. */
3350 for (namepass = 0; namepass < 2; namepass++)
3351 {
3352 format = format_start;
3353 for (formati = 0; formati < format_count; formati++)
3354 {
3355 dwarf_vma content_type;
3356
3357 content_type = read_uleb128 (format, & bytes_read, end);
3358 format += bytes_read;
3359 if ((content_type == DW_LNCT_path) == (namepass == 1))
3360 switch (content_type)
3361 {
3362 case DW_LNCT_path:
3363 printf (_("\tName"));
3364 break;
3365 case DW_LNCT_directory_index:
3366 printf (_("\tDir"));
3367 break;
3368 case DW_LNCT_timestamp:
3369 printf (_("\tTime"));
3370 break;
3371 case DW_LNCT_size:
3372 printf (_("\tSize"));
3373 break;
3374 case DW_LNCT_MD5:
3375 printf (_("\tMD5"));
3376 break;
3377 default:
3378 printf (_("\t(Unknown format content type %s)"),
3379 dwarf_vmatoa ("u", content_type));
3380 }
3381 read_uleb128 (format, & bytes_read, end);
3382 format += bytes_read;
3383 }
3384 }
3385 putchar ('\n');
3386
3387 for (datai = 0; datai < data_count; datai++)
3388 {
3389 unsigned char *datapass = data;
3390
3391 printf (" %d", last_entry++);
3392 /* Delay displaying name as the last entry for better screen layout. */
3393 for (namepass = 0; namepass < 2; namepass++)
3394 {
3395 format = format_start;
3396 data = datapass;
3397 for (formati = 0; formati < format_count; formati++)
3398 {
3399 dwarf_vma content_type, form;
3400
3401 content_type = read_uleb128 (format, & bytes_read, end);
3402 format += bytes_read;
3403 form = read_uleb128 (format, & bytes_read, end);
3404 format += bytes_read;
3405 data = read_and_display_attr_value (0, form, 0, data, end, 0, 0,
3406 linfo->li_offset_size,
3407 linfo->li_version, NULL,
3408 ((content_type == DW_LNCT_path) != (namepass == 1)),
3409 section, NULL, '\t');
3410 }
3411 }
3412 if (data == end)
3413 {
3414 warn (_("Corrupt %s entries list\n"), what);
3415 return data;
3416 }
3417 putchar ('\n');
3418 }
3419 return data;
3420}
3421
b40bf0a2 3422static int
dda8d76d
NC
3423display_debug_lines_raw (struct dwarf_section * section,
3424 unsigned char * data,
3425 unsigned char * end,
3426 void * file)
b40bf0a2
NC
3427{
3428 unsigned char *start = section->start;
ba8826a8 3429 int verbose_view = 0;
19e6b90e 3430
dda8d76d 3431 introduce (section, TRUE);
19e6b90e 3432
b40bf0a2
NC
3433 while (data < end)
3434 {
3435 static DWARF2_Internal_LineInfo saved_linfo;
3436 DWARF2_Internal_LineInfo linfo;
3437 unsigned char *standard_opcodes;
3438 unsigned char *end_of_sequence;
fe59e83d 3439 int i;
19e6b90e 3440
4925cdd7
NC
3441 if (const_strneq (section->name, ".debug_line.")
3442 /* Note: the following does not apply to .debug_line.dwo sections.
3443 These are full debug_line sections. */
3444 && strcmp (section->name, ".debug_line.dwo") != 0)
19e6b90e 3445 {
b40bf0a2
NC
3446 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3447 section containing just the Line Number Statements. They are
3448 created by the assembler and intended to be used alongside gcc's
3449 -ffunction-sections command line option. When the linker's
3450 garbage collection decides to discard a .text.<foo> section it
3451 can then also discard the line number information in .debug_line.<foo>.
3452
4925cdd7 3453 Since the section is a fragment it does not have the details
b40bf0a2 3454 needed to fill out a LineInfo structure, so instead we use the
4925cdd7 3455 details from the last full debug_line section that we processed. */
b40bf0a2
NC
3456 end_of_sequence = end;
3457 standard_opcodes = NULL;
3458 linfo = saved_linfo;
058037d3
NC
3459 /* PR 17531: file: 0522b371. */
3460 if (linfo.li_line_range == 0)
3461 {
1306a742 3462 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
058037d3
NC
3463 return 0;
3464 }
b40bf0a2 3465 reset_state_machine (linfo.li_default_is_stmt);
19e6b90e 3466 }
19e6b90e
L
3467 else
3468 {
b40bf0a2 3469 unsigned char * hdrptr;
19e6b90e 3470
b40bf0a2
NC
3471 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3472 & end_of_sequence)) == NULL)
3473 return 0;
19e6b90e 3474
b40bf0a2
NC
3475 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
3476 printf (_(" Length: %ld\n"), (long) linfo.li_length);
3477 printf (_(" DWARF Version: %d\n"), linfo.li_version);
77ef8654 3478 printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length);
b40bf0a2
NC
3479 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
3480 if (linfo.li_version >= 4)
3481 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
3482 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
3483 printf (_(" Line Base: %d\n"), linfo.li_line_base);
3484 printf (_(" Line Range: %d\n"), linfo.li_line_range);
3485 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
19e6b90e 3486
0a9d414a
NC
3487 /* PR 17512: file: 1665-6428-0.004. */
3488 if (linfo.li_line_range == 0)
3489 {
3490 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3491 linfo.li_line_range = 1;
3492 }
77ef8654 3493
b40bf0a2 3494 reset_state_machine (linfo.li_default_is_stmt);
19e6b90e 3495
b40bf0a2
NC
3496 /* Display the contents of the Opcodes table. */
3497 standard_opcodes = hdrptr;
19e6b90e 3498
6937bb54
NC
3499 /* PR 17512: file: 002-417945-0.004. */
3500 if (standard_opcodes + linfo.li_opcode_base >= end)
3501 {
3502 warn (_("Line Base extends beyond end of section\n"));
3503 return 0;
3504 }
3505
b40bf0a2 3506 printf (_("\n Opcodes:\n"));
19e6b90e 3507
b40bf0a2 3508 for (i = 1; i < linfo.li_opcode_base; i++)
d3a49aa8
AM
3509 printf (ngettext (" Opcode %d has %d arg\n",
3510 " Opcode %d has %d args\n",
3511 standard_opcodes[i - 1]),
3512 i, standard_opcodes[i - 1]);
19e6b90e 3513
b40bf0a2
NC
3514 /* Display the contents of the Directory table. */
3515 data = standard_opcodes + linfo.li_opcode_base - 1;
19e6b90e 3516
77145576 3517 if (linfo.li_version >= 5)
b40bf0a2 3518 {
dda8d76d 3519 load_debug_section_with_follow (line_str, file);
19e6b90e 3520
77145576
JK
3521 data = display_formatted_table (data, start, end, &linfo, section,
3522 _("Directory"));
3523 data = display_formatted_table (data, start, end, &linfo, section,
3524 _("File name"));
3525 }
3526 else
3527 {
3528 if (*data == 0)
3529 printf (_("\n The Directory Table is empty.\n"));
3530 else
a233b20c 3531 {
77145576 3532 unsigned int last_dir_entry = 0;
6937bb54 3533
77145576
JK
3534 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3535 (long)(data - start));
19e6b90e 3536
77145576
JK
3537 while (data < end && *data != 0)
3538 {
3539 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
19e6b90e 3540
77145576
JK
3541 data += strnlen ((char *) data, end - data) + 1;
3542 }
19e6b90e 3543
77145576
JK
3544 /* PR 17512: file: 002-132094-0.004. */
3545 if (data >= end - 1)
3546 break;
3547 }
19e6b90e 3548
77145576
JK
3549 /* Skip the NUL at the end of the table. */
3550 data++;
19e6b90e 3551
77145576
JK
3552 /* Display the contents of the File Name table. */
3553 if (*data == 0)
3554 printf (_("\n The File Name Table is empty.\n"));
3555 else
3556 {
3557 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3558 (long)(data - start));
3559 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
19e6b90e 3560
77145576 3561 while (data < end && *data != 0)
b40bf0a2 3562 {
77145576
JK
3563 unsigned char *name;
3564 unsigned int bytes_read;
3565
3566 printf (" %d\t", ++state_machine_regs.last_file_entry);
3567 name = data;
3568 data += strnlen ((char *) data, end - data) + 1;
3569
3570 printf ("%s\t",
3571 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3572 data += bytes_read;
3573 printf ("%s\t",
3574 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3575 data += bytes_read;
3576 printf ("%s\t",
3577 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
3578 data += bytes_read;
3579 printf ("%.*s\n", (int)(end - name), name);
3580
3581 if (data == end)
3582 {
3583 warn (_("Corrupt file name table entry\n"));
3584 break;
3585 }
b40bf0a2 3586 }
a233b20c 3587 }
77145576
JK
3588
3589 /* Skip the NUL at the end of the table. */
3590 data++;
b40bf0a2 3591 }
19e6b90e 3592
b40bf0a2
NC
3593 putchar ('\n');
3594 saved_linfo = linfo;
3595 }
19e6b90e 3596
b40bf0a2
NC
3597 /* Now display the statements. */
3598 if (data >= end_of_sequence)
3599 printf (_(" No Line Number Statements.\n"));
3600 else
3601 {
3602 printf (_(" Line Number Statements:\n"));
19e6b90e 3603
b40bf0a2
NC
3604 while (data < end_of_sequence)
3605 {
3606 unsigned char op_code;
3607 dwarf_signed_vma adv;
3608 dwarf_vma uladv;
3609 unsigned int bytes_read;
19e6b90e 3610
fe59e83d
CC
3611 printf (" [0x%08lx]", (long)(data - start));
3612
b40bf0a2 3613 op_code = *data++;
19e6b90e 3614
b40bf0a2 3615 if (op_code >= linfo.li_opcode_base)
19e6b90e 3616 {
b40bf0a2
NC
3617 op_code -= linfo.li_opcode_base;
3618 uladv = (op_code / linfo.li_line_range);
3619 if (linfo.li_max_ops_per_insn == 1)
3620 {
3621 uladv *= linfo.li_min_insn_length;
3622 state_machine_regs.address += uladv;
ba8826a8
AO
3623 if (uladv)
3624 state_machine_regs.view = 0;
b40bf0a2 3625 printf (_(" Special opcode %d: "
ba8826a8 3626 "advance Address by %s to 0x%s%s"),
b40bf0a2 3627 op_code, dwarf_vmatoa ("u", uladv),
ba8826a8
AO
3628 dwarf_vmatoa ("x", state_machine_regs.address),
3629 verbose_view && uladv
3630 ? _(" (reset view)") : "");
b40bf0a2
NC
3631 }
3632 else
3633 {
ba8826a8
AO
3634 unsigned addrdelta
3635 = ((state_machine_regs.op_index + uladv)
b40bf0a2
NC
3636 / linfo.li_max_ops_per_insn)
3637 * linfo.li_min_insn_length;
ba8826a8
AO
3638
3639 state_machine_regs.address += addrdelta;
b40bf0a2
NC
3640 state_machine_regs.op_index
3641 = (state_machine_regs.op_index + uladv)
3642 % linfo.li_max_ops_per_insn;
ba8826a8
AO
3643 if (addrdelta)
3644 state_machine_regs.view = 0;
b40bf0a2 3645 printf (_(" Special opcode %d: "
ba8826a8 3646 "advance Address by %s to 0x%s[%d]%s"),
b40bf0a2
NC
3647 op_code, dwarf_vmatoa ("u", uladv),
3648 dwarf_vmatoa ("x", state_machine_regs.address),
ba8826a8
AO
3649 state_machine_regs.op_index,
3650 verbose_view && addrdelta
3651 ? _(" (reset view)") : "");
b40bf0a2
NC
3652 }
3653 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3654 state_machine_regs.line += adv;
ba8826a8 3655 printf (_(" and Line by %s to %d"),
b40bf0a2 3656 dwarf_vmatoa ("d", adv), state_machine_regs.line);
ba8826a8
AO
3657 if (verbose_view || state_machine_regs.view)
3658 printf (_(" (view %u)\n"), state_machine_regs.view);
3659 else
3660 putchar ('\n');
3661 state_machine_regs.view++;
19e6b90e 3662 }
b40bf0a2
NC
3663 else switch (op_code)
3664 {
3665 case DW_LNS_extended_op:
3666 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
3667 break;
3668
3669 case DW_LNS_copy:
ba8826a8
AO
3670 printf (_(" Copy"));
3671 if (verbose_view || state_machine_regs.view)
3672 printf (_(" (view %u)\n"), state_machine_regs.view);
3673 else
3674 putchar ('\n');
3675 state_machine_regs.view++;
b40bf0a2
NC
3676 break;
3677
3678 case DW_LNS_advance_pc:
3679 uladv = read_uleb128 (data, & bytes_read, end);
3680 data += bytes_read;
3681 if (linfo.li_max_ops_per_insn == 1)
3682 {
3683 uladv *= linfo.li_min_insn_length;
3684 state_machine_regs.address += uladv;
ba8826a8
AO
3685 if (uladv)
3686 state_machine_regs.view = 0;
3687 printf (_(" Advance PC by %s to 0x%s%s\n"),
b40bf0a2 3688 dwarf_vmatoa ("u", uladv),
ba8826a8
AO
3689 dwarf_vmatoa ("x", state_machine_regs.address),
3690 verbose_view && uladv
3691 ? _(" (reset view)") : "");
b40bf0a2
NC
3692 }
3693 else
3694 {
ba8826a8
AO
3695 unsigned addrdelta
3696 = ((state_machine_regs.op_index + uladv)
3697 / linfo.li_max_ops_per_insn)
b40bf0a2 3698 * linfo.li_min_insn_length;
ba8826a8
AO
3699 state_machine_regs.address
3700 += addrdelta;
b40bf0a2
NC
3701 state_machine_regs.op_index
3702 = (state_machine_regs.op_index + uladv)
3703 % linfo.li_max_ops_per_insn;
ba8826a8
AO
3704 if (addrdelta)
3705 state_machine_regs.view = 0;
3706 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
b40bf0a2
NC
3707 dwarf_vmatoa ("u", uladv),
3708 dwarf_vmatoa ("x", state_machine_regs.address),
ba8826a8
AO
3709 state_machine_regs.op_index,
3710 verbose_view && addrdelta
3711 ? _(" (reset view)") : "");
b40bf0a2
NC
3712 }
3713 break;
3714
3715 case DW_LNS_advance_line:
3716 adv = read_sleb128 (data, & bytes_read, end);
3717 data += bytes_read;
3718 state_machine_regs.line += adv;
3719 printf (_(" Advance Line by %s to %d\n"),
3720 dwarf_vmatoa ("d", adv),
3721 state_machine_regs.line);
3722 break;
3723
3724 case DW_LNS_set_file:
3725 adv = read_uleb128 (data, & bytes_read, end);
3726 data += bytes_read;
3727 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3728 dwarf_vmatoa ("d", adv));
3729 state_machine_regs.file = adv;
3730 break;
3731
3732 case DW_LNS_set_column:
3733 uladv = read_uleb128 (data, & bytes_read, end);
3734 data += bytes_read;
3735 printf (_(" Set column to %s\n"),
3736 dwarf_vmatoa ("u", uladv));
3737 state_machine_regs.column = uladv;
3738 break;
3739
3740 case DW_LNS_negate_stmt:
3741 adv = state_machine_regs.is_stmt;
3742 adv = ! adv;
3743 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
3744 state_machine_regs.is_stmt = adv;
3745 break;
3746
3747 case DW_LNS_set_basic_block:
3748 printf (_(" Set basic block\n"));
3749 state_machine_regs.basic_block = 1;
3750 break;
3751
3752 case DW_LNS_const_add_pc:
3753 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3754 if (linfo.li_max_ops_per_insn)
3755 {
3756 uladv *= linfo.li_min_insn_length;
3757 state_machine_regs.address += uladv;
ba8826a8
AO
3758 if (uladv)
3759 state_machine_regs.view = 0;
3760 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
b40bf0a2 3761 dwarf_vmatoa ("u", uladv),
ba8826a8
AO
3762 dwarf_vmatoa ("x", state_machine_regs.address),
3763 verbose_view && uladv
3764 ? _(" (reset view)") : "");
b40bf0a2
NC
3765 }
3766 else
3767 {
ba8826a8
AO
3768 unsigned addrdelta
3769 = ((state_machine_regs.op_index + uladv)
3770 / linfo.li_max_ops_per_insn)
b40bf0a2 3771 * linfo.li_min_insn_length;
ba8826a8
AO
3772 state_machine_regs.address
3773 += addrdelta;
b40bf0a2
NC
3774 state_machine_regs.op_index
3775 = (state_machine_regs.op_index + uladv)
3776 % linfo.li_max_ops_per_insn;
ba8826a8
AO
3777 if (addrdelta)
3778 state_machine_regs.view = 0;
3779 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
b40bf0a2
NC
3780 dwarf_vmatoa ("u", uladv),
3781 dwarf_vmatoa ("x", state_machine_regs.address),
ba8826a8
AO
3782 state_machine_regs.op_index,
3783 verbose_view && addrdelta
3784 ? _(" (reset view)") : "");
b40bf0a2
NC
3785 }
3786 break;
3787
3788 case DW_LNS_fixed_advance_pc:
3789 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3790 state_machine_regs.address += uladv;
3791 state_machine_regs.op_index = 0;
3792 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3793 dwarf_vmatoa ("u", uladv),
3794 dwarf_vmatoa ("x", state_machine_regs.address));
ba8826a8 3795 /* Do NOT reset view. */
b40bf0a2
NC
3796 break;
3797
3798 case DW_LNS_set_prologue_end:
3799 printf (_(" Set prologue_end to true\n"));
3800 break;
3801
3802 case DW_LNS_set_epilogue_begin:
3803 printf (_(" Set epilogue_begin to true\n"));
3804 break;
3805
3806 case DW_LNS_set_isa:
3807 uladv = read_uleb128 (data, & bytes_read, end);
3808 data += bytes_read;
3809 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
3810 break;
3811
3812 default:
3813 printf (_(" Unknown opcode %d with operands: "), op_code);
3814
3815 if (standard_opcodes != NULL)
3816 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3817 {
3818 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3819 &bytes_read, end)),
3820 i == 1 ? "" : ", ");
3821 data += bytes_read;
3822 }
3823 putchar ('\n');
3824 break;
3825 }
19e6b90e 3826 }
b40bf0a2 3827 putchar ('\n');
19e6b90e 3828 }
19e6b90e
L
3829 }
3830
3831 return 1;
3832}
3833
a262ae96
NC
3834typedef struct
3835{
467c65bc
NC
3836 unsigned char *name;
3837 unsigned int directory_index;
3838 unsigned int modification_date;
3839 unsigned int length;
a262ae96
NC
3840} File_Entry;
3841
3842/* Output a decoded representation of the .debug_line section. */
3843
3844static int
dda8d76d
NC
3845display_debug_lines_decoded (struct dwarf_section * section,
3846 unsigned char * data,
3847 unsigned char * end,
3848 void * fileptr)
a262ae96 3849{
b40bf0a2
NC
3850 static DWARF2_Internal_LineInfo saved_linfo;
3851
dda8d76d 3852 introduce (section, FALSE);
a262ae96
NC
3853
3854 while (data < end)
3855 {
3856 /* This loop amounts to one iteration per compilation unit. */
91d6fa6a 3857 DWARF2_Internal_LineInfo linfo;
a262ae96
NC
3858 unsigned char *standard_opcodes;
3859 unsigned char *end_of_sequence;
a262ae96
NC
3860 int i;
3861 File_Entry *file_table = NULL;
143a3db0 3862 unsigned int n_files = 0;
a262ae96 3863 unsigned char **directory_table = NULL;
77145576 3864 dwarf_vma n_directories = 0;
a262ae96 3865
4925cdd7
NC
3866 if (const_strneq (section->name, ".debug_line.")
3867 /* Note: the following does not apply to .debug_line.dwo sections.
3868 These are full debug_line sections. */
3869 && strcmp (section->name, ".debug_line.dwo") != 0)
b4eb7656 3870 {
4925cdd7 3871 /* See comment in display_debug_lines_raw(). */
b40bf0a2
NC
3872 end_of_sequence = end;
3873 standard_opcodes = NULL;
3874 linfo = saved_linfo;
058037d3
NC
3875 /* PR 17531: file: 0522b371. */
3876 if (linfo.li_line_range == 0)
3877 {
1306a742 3878 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
058037d3
NC
3879 return 0;
3880 }
b40bf0a2 3881 reset_state_machine (linfo.li_default_is_stmt);
b4eb7656 3882 }
a262ae96 3883 else
b4eb7656 3884 {
b40bf0a2 3885 unsigned char *hdrptr;
a262ae96 3886
b40bf0a2
NC
3887 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3888 & end_of_sequence)) == NULL)
a233b20c 3889 return 0;
0c588247 3890
058037d3
NC
3891 /* PR 17531: file: 0522b371. */
3892 if (linfo.li_line_range == 0)
3893 {
3894 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3895 linfo.li_line_range = 1;
3896 }
b40bf0a2 3897 reset_state_machine (linfo.li_default_is_stmt);
a262ae96 3898
b40bf0a2
NC
3899 /* Save a pointer to the contents of the Opcodes table. */
3900 standard_opcodes = hdrptr;
a262ae96 3901
b40bf0a2
NC
3902 /* Traverse the Directory table just to count entries. */
3903 data = standard_opcodes + linfo.li_opcode_base - 1;
d8024a91
NC
3904 /* PR 20440 */
3905 if (data >= end)
3906 {
3907 warn (_("opcode base of %d extends beyond end of section\n"),
3908 linfo.li_opcode_base);
3909 return 0;
3910 }
3911
77145576 3912 if (linfo.li_version >= 5)
b40bf0a2 3913 {
77145576
JK
3914 unsigned char *format_start, format_count, *format;
3915 dwarf_vma formati, entryi;
3916 unsigned int bytes_read;
a262ae96 3917
dda8d76d 3918 load_debug_section_with_follow (line_str, fileptr);
77145576
JK
3919
3920 /* Skip directories format. */
3921 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3922 format_start = data;
3923 for (formati = 0; formati < format_count; formati++)
b40bf0a2 3924 {
77145576
JK
3925 read_uleb128 (data, & bytes_read, end);
3926 data += bytes_read;
3927 read_uleb128 (data, & bytes_read, end);
3928 data += bytes_read;
b40bf0a2 3929 }
a262ae96 3930
77145576
JK
3931 n_directories = read_uleb128 (data, & bytes_read, end);
3932 data += bytes_read;
3933 if (data == end)
d8024a91 3934 {
77145576 3935 warn (_("Corrupt directories list\n"));
d8024a91
NC
3936 break;
3937 }
3938
b40bf0a2
NC
3939 directory_table = (unsigned char **)
3940 xmalloc (n_directories * sizeof (unsigned char *));
a262ae96 3941
77145576 3942 for (entryi = 0; entryi < n_directories; entryi++)
b40bf0a2 3943 {
77145576 3944 unsigned char **pathp = &directory_table[entryi];
a262ae96 3945
77145576
JK
3946 format = format_start;
3947 for (formati = 0; formati < format_count; formati++)
3948 {
3949 dwarf_vma content_type, form;
3950 dwarf_vma uvalue;
3951
3952 content_type = read_uleb128 (format, & bytes_read, end);
3953 format += bytes_read;
3954 form = read_uleb128 (format, & bytes_read, end);
3955 format += bytes_read;
3956 if (data == end)
3957 {
3958 warn (_("Corrupt directories list\n"));
3959 break;
3960 }
3961 switch (content_type)
3962 {
3963 case DW_LNCT_path:
3964 switch (form)
3965 {
3966 case DW_FORM_string:
3967 *pathp = data;
3968 break;
3969 case DW_FORM_line_strp:
3970 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
3971 end);
3972 /* Remove const by the cast. */
3973 *pathp = (unsigned char *)
3974 fetch_indirect_line_string (uvalue);
3975 break;
3976 }
3977 break;
3978 }
3979 data = read_and_display_attr_value (0, form, 0, data, end,
3980 0, 0,
3981 linfo.li_offset_size,
3982 linfo.li_version,
3983 NULL, 1, section,
3984 NULL, '\t');
3985 }
3986 if (data == end)
3987 {
3988 warn (_("Corrupt directories list\n"));
3989 break;
3990 }
3991 }
a262ae96 3992
77145576
JK
3993 /* Skip files format. */
3994 SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
3995 format_start = data;
3996 for (formati = 0; formati < format_count; formati++)
b40bf0a2 3997 {
b40bf0a2
NC
3998 read_uleb128 (data, & bytes_read, end);
3999 data += bytes_read;
4000 read_uleb128 (data, & bytes_read, end);
4001 data += bytes_read;
b40bf0a2 4002 }
a262ae96 4003
77145576
JK
4004 n_files = read_uleb128 (data, & bytes_read, end);
4005 data += bytes_read;
4006 if (data == end)
d8024a91 4007 {
77145576 4008 warn (_("Corrupt file name list\n"));
d8024a91
NC
4009 break;
4010 }
4011
77145576
JK
4012 file_table = (File_Entry *) xcalloc (1, n_files
4013 * sizeof (File_Entry));
a262ae96 4014
77145576 4015 for (entryi = 0; entryi < n_files; entryi++)
b40bf0a2 4016 {
77145576 4017 File_Entry *file = &file_table[entryi];
a262ae96 4018
77145576
JK
4019 format = format_start;
4020 for (formati = 0; formati < format_count; formati++)
4021 {
4022 dwarf_vma content_type, form;
4023 dwarf_vma uvalue;
4024
4025 content_type = read_uleb128 (format, & bytes_read, end);
4026 format += bytes_read;
4027 form = read_uleb128 (format, & bytes_read, end);
4028 format += bytes_read;
4029 if (data == end)
4030 {
4031 warn (_("Corrupt file name list\n"));
4032 break;
4033 }
4034 switch (content_type)
4035 {
4036 case DW_LNCT_path:
4037 switch (form)
4038 {
4039 case DW_FORM_string:
4040 file->name = data;
4041 break;
4042 case DW_FORM_line_strp:
4043 SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
4044 end);
4045 /* Remove const by the cast. */
4046 file->name = (unsigned char *)
4047 fetch_indirect_line_string (uvalue);
4048 break;
4049 }
4050 break;
4051 case DW_LNCT_directory_index:
4052 switch (form)
4053 {
4054 case DW_FORM_data1:
4055 SAFE_BYTE_GET (file->directory_index, data, 1,
4056 end);
4057 break;
4058 case DW_FORM_data2:
4059 SAFE_BYTE_GET (file->directory_index, data, 2,
4060 end);
4061 break;
4062 case DW_FORM_udata:
4063 file->directory_index = read_uleb128 (data, NULL,
4064 end);
4065 break;
4066 }
4067 break;
4068 }
4069 data = read_and_display_attr_value (0, form, 0, data, end,
4070 0, 0,
4071 linfo.li_offset_size,
4072 linfo.li_version,
4073 NULL, 1, section,
4074 NULL, '\t');
4075 }
4076 if (data == end)
4077 {
4078 warn (_("Corrupt file name list\n"));
4079 break;
4080 }
4081 }
4082 }
4083 else
4084 {
4085 if (*data != 0)
b40bf0a2 4086 {
77145576
JK
4087 unsigned char *ptr_directory_table = data;
4088
4089 while (data < end && *data != 0)
4090 {
4091 data += strnlen ((char *) data, end - data) + 1;
4092 n_directories++;
4093 }
4094
4095 /* PR 20440 */
4096 if (data >= end)
4097 {
4098 warn (_("directory table ends unexpectedly\n"));
4099 n_directories = 0;
4100 break;
4101 }
4102
4103 /* Go through the directory table again to save the directories. */
4104 directory_table = (unsigned char **)
4105 xmalloc (n_directories * sizeof (unsigned char *));
4106
4107 i = 0;
4108 while (*ptr_directory_table != 0)
4109 {
4110 directory_table[i] = ptr_directory_table;
4111 ptr_directory_table += strnlen ((char *) ptr_directory_table,
4112 ptr_directory_table - end) + 1;
4113 i++;
4114 }
b40bf0a2 4115 }
77145576
JK
4116 /* Skip the NUL at the end of the table. */
4117 data++;
4118
4119 /* Traverse the File Name table just to count the entries. */
4120 if (data < end && *data != 0)
b40bf0a2 4121 {
77145576
JK
4122 unsigned char *ptr_file_name_table = data;
4123
4124 while (data < end && *data != 0)
db9537d2 4125 {
77145576
JK
4126 unsigned int bytes_read;
4127
4128 /* Skip Name, directory index, last modification time and length
4129 of file. */
4130 data += strnlen ((char *) data, end - data) + 1;
4131 read_uleb128 (data, & bytes_read, end);
4132 data += bytes_read;
4133 read_uleb128 (data, & bytes_read, end);
4134 data += bytes_read;
4135 read_uleb128 (data, & bytes_read, end);
4136 data += bytes_read;
4137
4138 n_files++;
db9537d2 4139 }
a262ae96 4140
77145576
JK
4141 if (data >= end)
4142 {
4143 warn (_("file table ends unexpectedly\n"));
4144 n_files = 0;
4145 break;
4146 }
4147
4148 /* Go through the file table again to save the strings. */
4149 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
0c588247 4150
77145576
JK
4151 i = 0;
4152 while (*ptr_file_name_table != 0)
4153 {
4154 unsigned int bytes_read;
4155
4156 file_table[i].name = ptr_file_name_table;
4157 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
4158 end - ptr_file_name_table) + 1;
4159
4160 /* We are not interested in directory, time or size. */
4161 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
4162 & bytes_read, end);
4163 ptr_file_name_table += bytes_read;
4164 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
4165 & bytes_read, end);
4166 ptr_file_name_table += bytes_read;
4167 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
4168 ptr_file_name_table += bytes_read;
4169 i++;
4170 }
4171 i = 0;
b40bf0a2 4172 }
77145576
JK
4173
4174 /* Skip the NUL at the end of the table. */
4175 data++;
b40bf0a2 4176 }
cc5914eb 4177
77145576 4178 /* Print the Compilation Unit's name and a header. */
f082820d
AM
4179 if (file_table == NULL)
4180 ;
4181 else if (directory_table == NULL)
4182 printf (_("CU: %s:\n"), file_table[0].name);
77145576
JK
4183 else
4184 {
4185 unsigned int ix = file_table[0].directory_index;
4186 const char *directory;
4187
4188 if (ix == 0)
4189 directory = ".";
4190 /* PR 20439 */
4191 else if (n_directories == 0)
4192 directory = _("<unknown>");
4193 else if (ix > n_directories)
4194 {
4195 warn (_("directory index %u > number of directories %s\n"),
4196 ix, dwarf_vmatoa ("u", n_directories));
4197 directory = _("<corrupt>");
4198 }
4199 else
4200 directory = (char *) directory_table[ix - 1];
4201
4202 if (do_wide || strlen (directory) < 76)
4203 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
4204 else
4205 printf ("%s:\n", file_table[0].name);
77145576 4206 }
a262ae96 4207
ba8826a8 4208 printf (_("File name Line number Starting address View\n"));
b40bf0a2
NC
4209 saved_linfo = linfo;
4210 }
a262ae96
NC
4211
4212 /* This loop iterates through the Dwarf Line Number Program. */
4213 while (data < end_of_sequence)
b4eb7656 4214 {
a262ae96 4215 unsigned char op_code;
ba8826a8 4216 int xop;
b4eb7656
AM
4217 int adv;
4218 unsigned long int uladv;
4219 unsigned int bytes_read;
4220 int is_special_opcode = 0;
a262ae96 4221
b4eb7656 4222 op_code = *data++;
ba8826a8 4223 xop = op_code;
a262ae96 4224
b4eb7656 4225 if (op_code >= linfo.li_opcode_base)
a262ae96 4226 {
91d6fa6a 4227 op_code -= linfo.li_opcode_base;
a233b20c
JJ
4228 uladv = (op_code / linfo.li_line_range);
4229 if (linfo.li_max_ops_per_insn == 1)
4230 {
4231 uladv *= linfo.li_min_insn_length;
4232 state_machine_regs.address += uladv;
ba8826a8
AO
4233 if (uladv)
4234 state_machine_regs.view = 0;
a233b20c
JJ
4235 }
4236 else
4237 {
ba8826a8
AO
4238 unsigned addrdelta
4239 = ((state_machine_regs.op_index + uladv)
4240 / linfo.li_max_ops_per_insn)
b40bf0a2 4241 * linfo.li_min_insn_length;
ba8826a8
AO
4242 state_machine_regs.address
4243 += addrdelta;
a233b20c
JJ
4244 state_machine_regs.op_index
4245 = (state_machine_regs.op_index + uladv)
b40bf0a2 4246 % linfo.li_max_ops_per_insn;
ba8826a8
AO
4247 if (addrdelta)
4248 state_machine_regs.view = 0;
a233b20c 4249 }
a262ae96 4250
b4eb7656
AM
4251 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
4252 state_machine_regs.line += adv;
4253 is_special_opcode = 1;
ba8826a8 4254 /* Increment view after printing this row. */
b4eb7656
AM
4255 }
4256 else switch (op_code)
b40bf0a2
NC
4257 {
4258 case DW_LNS_extended_op:
4259 {
4260 unsigned int ext_op_code_len;
4261 unsigned char ext_op_code;
4262 unsigned char *op_code_data = data;
4263
4264 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
4265 end_of_sequence);
4266 op_code_data += bytes_read;
4267
4268 if (ext_op_code_len == 0)
4269 {
f41e4712 4270 warn (_("Badly formed extended line op encountered!\n"));
b40bf0a2
NC
4271 break;
4272 }
4273 ext_op_code_len += bytes_read;
4274 ext_op_code = *op_code_data++;
ba8826a8
AO
4275 xop = ext_op_code;
4276 xop = -xop;
b40bf0a2
NC
4277
4278 switch (ext_op_code)
4279 {
4280 case DW_LNE_end_sequence:
ba8826a8 4281 /* Reset stuff after printing this row. */
b40bf0a2
NC
4282 break;
4283 case DW_LNE_set_address:
4284 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
87bc83b3
CC
4285 op_code_data,
4286 ext_op_code_len - bytes_read - 1,
b40bf0a2
NC
4287 end);
4288 state_machine_regs.op_index = 0;
ba8826a8 4289 state_machine_regs.view = 0;
b40bf0a2
NC
4290 break;
4291 case DW_LNE_define_file:
4292 {
4293 file_table = (File_Entry *) xrealloc
4294 (file_table, (n_files + 1) * sizeof (File_Entry));
4295
4296 ++state_machine_regs.last_file_entry;
4297 /* Source file name. */
4298 file_table[n_files].name = op_code_data;
4299 op_code_data += strlen ((char *) op_code_data) + 1;
4300 /* Directory index. */
4301 file_table[n_files].directory_index =
4302 read_uleb128 (op_code_data, & bytes_read,
4303 end_of_sequence);
4304 op_code_data += bytes_read;
4305 /* Last modification time. */
4306 file_table[n_files].modification_date =
4307 read_uleb128 (op_code_data, & bytes_read,
4308 end_of_sequence);
4309 op_code_data += bytes_read;
4310 /* File length. */
4311 file_table[n_files].length =
4312 read_uleb128 (op_code_data, & bytes_read,
4313 end_of_sequence);
4314
4315 n_files++;
4316 break;
4317 }
4318 case DW_LNE_set_discriminator:
4319 case DW_LNE_HP_set_sequence:
4320 /* Simply ignored. */
4321 break;
4322
4323 default:
4324 printf (_("UNKNOWN (%u): length %d\n"),
4325 ext_op_code, ext_op_code_len - bytes_read);
4326 break;
4327 }
4328 data += ext_op_code_len;
4329 break;
4330 }
4331 case DW_LNS_copy:
ba8826a8 4332 /* Increment view after printing this row. */
b40bf0a2
NC
4333 break;
4334
4335 case DW_LNS_advance_pc:
4336 uladv = read_uleb128 (data, & bytes_read, end);
4337 data += bytes_read;
4338 if (linfo.li_max_ops_per_insn == 1)
4339 {
4340 uladv *= linfo.li_min_insn_length;
4341 state_machine_regs.address += uladv;
ba8826a8
AO
4342 if (uladv)
4343 state_machine_regs.view = 0;
b40bf0a2
NC
4344 }
4345 else
4346 {
ba8826a8
AO
4347 unsigned addrdelta
4348 = ((state_machine_regs.op_index + uladv)
4349 / linfo.li_max_ops_per_insn)
b40bf0a2 4350 * linfo.li_min_insn_length;
ba8826a8
AO
4351 state_machine_regs.address
4352 += addrdelta;
b40bf0a2
NC
4353 state_machine_regs.op_index
4354 = (state_machine_regs.op_index + uladv)
4355 % linfo.li_max_ops_per_insn;
ba8826a8
AO
4356 if (addrdelta)
4357 state_machine_regs.view = 0;
b40bf0a2
NC
4358 }
4359 break;
4360
4361 case DW_LNS_advance_line:
4362 adv = read_sleb128 (data, & bytes_read, end);
4363 data += bytes_read;
4364 state_machine_regs.line += adv;
4365 break;
4366
4367 case DW_LNS_set_file:
4368 adv = read_uleb128 (data, & bytes_read, end);
4369 data += bytes_read;
4370 state_machine_regs.file = adv;
4371
db9537d2
NC
4372 {
4373 unsigned file = state_machine_regs.file - 1;
4374 unsigned dir;
4375
4376 if (file_table == NULL || n_files == 0)
4377 printf (_("\n [Use file table entry %d]\n"), file);
4378 /* PR 20439 */
4379 else if (file >= n_files)
4380 {
4381 warn (_("file index %u > number of files %u\n"), file + 1, n_files);
4382 printf (_("\n <over large file table index %u>"), file);
4383 }
4384 else if ((dir = file_table[file].directory_index) == 0)
4385 /* If directory index is 0, that means current directory. */
4386 printf ("\n./%s:[++]\n", file_table[file].name);
4387 else if (directory_table == NULL || n_directories == 0)
4388 printf (_("\n [Use file %s in directory table entry %d]\n"),
4389 file_table[file].name, dir);
4390 /* PR 20439 */
4391 else if (dir > n_directories)
4392 {
77145576
JK
4393 warn (_("directory index %u > number of directories %s\n"),
4394 dir, dwarf_vmatoa ("u", n_directories));
db9537d2
NC
4395 printf (_("\n <over large directory table entry %u>\n"), dir);
4396 }
4397 else
4398 printf ("\n%s/%s:\n",
4399 /* The directory index starts counting at 1. */
4400 directory_table[dir - 1], file_table[file].name);
4401 }
b40bf0a2
NC
4402 break;
4403
4404 case DW_LNS_set_column:
4405 uladv = read_uleb128 (data, & bytes_read, end);
4406 data += bytes_read;
4407 state_machine_regs.column = uladv;
4408 break;
4409
4410 case DW_LNS_negate_stmt:
4411 adv = state_machine_regs.is_stmt;
4412 adv = ! adv;
4413 state_machine_regs.is_stmt = adv;
4414 break;
4415
4416 case DW_LNS_set_basic_block:
4417 state_machine_regs.basic_block = 1;
4418 break;
4419
4420 case DW_LNS_const_add_pc:
4421 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
4422 if (linfo.li_max_ops_per_insn == 1)
4423 {
4424 uladv *= linfo.li_min_insn_length;
4425 state_machine_regs.address += uladv;
ba8826a8
AO
4426 if (uladv)
4427 state_machine_regs.view = 0;
b40bf0a2
NC
4428 }
4429 else
4430 {
ba8826a8
AO
4431 unsigned addrdelta
4432 = ((state_machine_regs.op_index + uladv)
4433 / linfo.li_max_ops_per_insn)
b40bf0a2 4434 * linfo.li_min_insn_length;
ba8826a8
AO
4435 state_machine_regs.address
4436 += addrdelta;
b40bf0a2
NC
4437 state_machine_regs.op_index
4438 = (state_machine_regs.op_index + uladv)
4439 % linfo.li_max_ops_per_insn;
ba8826a8
AO
4440 if (addrdelta)
4441 state_machine_regs.view = 0;
b40bf0a2
NC
4442 }
4443 break;
4444
4445 case DW_LNS_fixed_advance_pc:
4446 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
4447 state_machine_regs.address += uladv;
4448 state_machine_regs.op_index = 0;
ba8826a8 4449 /* Do NOT reset view. */
b40bf0a2
NC
4450 break;
4451
4452 case DW_LNS_set_prologue_end:
4453 break;
4454
4455 case DW_LNS_set_epilogue_begin:
4456 break;
4457
4458 case DW_LNS_set_isa:
4459 uladv = read_uleb128 (data, & bytes_read, end);
4460 data += bytes_read;
4461 printf (_(" Set ISA to %lu\n"), uladv);
4462 break;
4463
4464 default:
4465 printf (_(" Unknown opcode %d with operands: "), op_code);
4466
4467 if (standard_opcodes != NULL)
4468 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
4469 {
4470 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
4471 &bytes_read, end)),
4472 i == 1 ? "" : ", ");
4473 data += bytes_read;
4474 }
4475 putchar ('\n');
4476 break;
4477 }
a262ae96 4478
b4eb7656
AM
4479 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4480 to the DWARF address/line matrix. */
ba8826a8
AO
4481 if ((is_special_opcode) || (xop == -DW_LNE_end_sequence)
4482 || (xop == DW_LNS_copy))
b4eb7656
AM
4483 {
4484 const unsigned int MAX_FILENAME_LENGTH = 35;
4485 char *fileName;
4486 char *newFileName = NULL;
4487 size_t fileNameLength;
b40bf0a2
NC
4488
4489 if (file_table)
db9537d2
NC
4490 {
4491 unsigned indx = state_machine_regs.file - 1;
4492 /* PR 20439 */
4493 if (indx >= n_files)
4494 {
4495 warn (_("corrupt file index %u encountered\n"), indx);
4496 fileName = _("<corrupt>");
4497 }
4498 else
4499 fileName = (char *) file_table[indx].name;
4500 }
b40bf0a2 4501 else
db9537d2 4502 fileName = _("<unknown>");
b40bf0a2
NC
4503
4504 fileNameLength = strlen (fileName);
a262ae96 4505
b4eb7656
AM
4506 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
4507 {
4508 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
4509 /* Truncate file name */
4510 strncpy (newFileName,
4511 fileName + fileNameLength - MAX_FILENAME_LENGTH,
4512 MAX_FILENAME_LENGTH + 1);
4513 }
4514 else
4515 {
4516 newFileName = (char *) xmalloc (fileNameLength + 1);
4517 strncpy (newFileName, fileName, fileNameLength + 1);
4518 }
4519
4520 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
4521 {
a233b20c 4522 if (linfo.li_max_ops_per_insn == 1)
ba8826a8 4523 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x",
467c65bc 4524 newFileName, state_machine_regs.line,
a233b20c
JJ
4525 state_machine_regs.address);
4526 else
ba8826a8 4527 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]",
467c65bc 4528 newFileName, state_machine_regs.line,
a233b20c
JJ
4529 state_machine_regs.address,
4530 state_machine_regs.op_index);
b4eb7656
AM
4531 }
4532 else
4533 {
a233b20c 4534 if (linfo.li_max_ops_per_insn == 1)
ba8826a8 4535 printf ("%s %11d %#18" DWARF_VMA_FMT "x",
467c65bc 4536 newFileName, state_machine_regs.line,
a233b20c
JJ
4537 state_machine_regs.address);
4538 else
ba8826a8 4539 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]",
467c65bc 4540 newFileName, state_machine_regs.line,
a233b20c
JJ
4541 state_machine_regs.address,
4542 state_machine_regs.op_index);
b4eb7656 4543 }
a262ae96 4544
ba8826a8
AO
4545 if (state_machine_regs.view)
4546 printf (" %6u\n", state_machine_regs.view);
4547 else
4548 putchar ('\n');
4549 state_machine_regs.view++;
4550
4551 if (xop == -DW_LNE_end_sequence)
4552 {
4553 reset_state_machine (linfo.li_default_is_stmt);
4554 putchar ('\n');
4555 }
a262ae96 4556
b4eb7656
AM
4557 free (newFileName);
4558 }
4559 }
b40bf0a2
NC
4560
4561 if (file_table)
4562 {
4563 free (file_table);
4564 file_table = NULL;
4565 n_files = 0;
4566 }
4567
4568 if (directory_table)
4569 {
4570 free (directory_table);
4571 directory_table = NULL;
4572 n_directories = 0;
4573 }
4574
a262ae96
NC
4575 putchar ('\n');
4576 }
4577
4578 return 1;
4579}
4580
4581static int
77145576 4582display_debug_lines (struct dwarf_section *section, void *file)
a262ae96
NC
4583{
4584 unsigned char *data = section->start;
4585 unsigned char *end = data + section->size;
4cb93e3b
TG
4586 int retValRaw = 1;
4587 int retValDecoded = 1;
a262ae96 4588
008f4c78
NC
4589 if (do_debug_lines == 0)
4590 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
4591
4cb93e3b 4592 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
77145576 4593 retValRaw = display_debug_lines_raw (section, data, end, file);
a262ae96 4594
4cb93e3b 4595 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
77145576 4596 retValDecoded = display_debug_lines_decoded (section, data, end, file);
a262ae96 4597
4cb93e3b 4598 if (!retValRaw || !retValDecoded)
a262ae96
NC
4599 return 0;
4600
4601 return 1;
4602}
4603
6e3d6dc1
NC
4604static debug_info *
4605find_debug_info_for_offset (unsigned long offset)
4606{
4607 unsigned int i;
4608
4609 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
4610 return NULL;
4611
4612 for (i = 0; i < num_debug_info_entries; i++)
4613 if (debug_information[i].cu_offset == offset)
4614 return debug_information + i;
4615
4616 return NULL;
4617}
4618
459d52c8
DE
4619static const char *
4620get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
4621{
4622 /* See gdb/gdb-index.h. */
4623 static const char * const kinds[] =
4624 {
4625 N_ ("no info"),
4626 N_ ("type"),
4627 N_ ("variable"),
4628 N_ ("function"),
4629 N_ ("other"),
4630 N_ ("unused5"),
4631 N_ ("unused6"),
4632 N_ ("unused7")
4633 };
4634
4635 return _ (kinds[kind]);
4636}
4637
19e6b90e 4638static int
459d52c8
DE
4639display_debug_pubnames_worker (struct dwarf_section *section,
4640 void *file ATTRIBUTE_UNUSED,
4641 int is_gnu)
19e6b90e 4642{
91d6fa6a 4643 DWARF2_Internal_PubNames names;
19e6b90e
L
4644 unsigned char *start = section->start;
4645 unsigned char *end = start + section->size;
4646
6e3d6dc1
NC
4647 /* It does not matter if this load fails,
4648 we test for that later on. */
4649 load_debug_info (file);
4650
dda8d76d 4651 introduce (section, FALSE);
19e6b90e
L
4652
4653 while (start < end)
4654 {
4655 unsigned char *data;
e98fdf1a 4656 unsigned long sec_off;
bf5117e3 4657 unsigned int offset_size, initial_length_size;
19e6b90e 4658
e98fdf1a 4659 SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end);
91d6fa6a 4660 if (names.pn_length == 0xffffffff)
19e6b90e 4661 {
e98fdf1a 4662 SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end);
19e6b90e
L
4663 offset_size = 8;
4664 initial_length_size = 12;
4665 }
4666 else
4667 {
4668 offset_size = 4;
4669 initial_length_size = 4;
4670 }
4671
e98fdf1a
AM
4672 sec_off = start - section->start;
4673 if (sec_off + names.pn_length < sec_off
4674 || sec_off + names.pn_length > section->size)
4675 {
4676 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
4677 section->name,
4678 sec_off - initial_length_size,
4679 dwarf_vmatoa ("x", names.pn_length));
4680 break;
4681 }
4682
4683 data = start;
4684 start += names.pn_length;
4685
0c588247
NC
4686 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
4687 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
6e3d6dc1
NC
4688
4689 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4690 && num_debug_info_entries > 0
91d6fa6a 4691 && find_debug_info_for_offset (names.pn_offset) == NULL)
6e3d6dc1 4692 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
47704ddf 4693 (unsigned long) names.pn_offset, section->name);
cecf136e 4694
0c588247 4695 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
19e6b90e 4696
058037d3
NC
4697 printf (_(" Length: %ld\n"),
4698 (long) names.pn_length);
4699 printf (_(" Version: %d\n"),
4700 names.pn_version);
4701 printf (_(" Offset into .debug_info section: 0x%lx\n"),
4702 (unsigned long) names.pn_offset);
4703 printf (_(" Size of area in .debug_info section: %ld\n"),
4704 (long) names.pn_size);
19e6b90e 4705
91d6fa6a 4706 if (names.pn_version != 2 && names.pn_version != 3)
19e6b90e
L
4707 {
4708 static int warned = 0;
4709
4710 if (! warned)
4711 {
4712 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
4713 warned = 1;
4714 }
4715
4716 continue;
4717 }
4718
459d52c8
DE
4719 if (is_gnu)
4720 printf (_("\n Offset Kind Name\n"));
4721 else
4722 printf (_("\n Offset\tName\n"));
19e6b90e 4723
e98fdf1a 4724 while (1)
19e6b90e 4725 {
f41e4712 4726 bfd_size_type maxprint;
e98fdf1a 4727 dwarf_vma offset;
f41e4712 4728
0c588247 4729 SAFE_BYTE_GET (offset, data, offset_size, end);
19e6b90e 4730
e98fdf1a
AM
4731 if (offset == 0)
4732 break;
b4eb7656 4733
e98fdf1a
AM
4734 data += offset_size;
4735 if (data >= end)
4736 break;
4737 maxprint = (end - data) - 1;
f41e4712 4738
e98fdf1a
AM
4739 if (is_gnu)
4740 {
4741 unsigned int kind_data;
4742 gdb_index_symbol_kind kind;
4743 const char *kind_name;
4744 int is_static;
4745
4746 SAFE_BYTE_GET (kind_data, data, 1, end);
4747 data++;
4748 maxprint --;
4749 /* GCC computes the kind as the upper byte in the CU index
4750 word, and then right shifts it by the CU index size.
4751 Left shift KIND to where the gdb-index.h accessor macros
4752 can use it. */
4753 kind_data <<= GDB_INDEX_CU_BITSIZE;
4754 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
4755 kind_name = get_gdb_index_symbol_kind_name (kind);
4756 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
4757 printf (" %-6lx %s,%-10s %.*s\n",
4758 (unsigned long) offset, is_static ? _("s") : _("g"),
4759 kind_name, (int) maxprint, data);
19e6b90e 4760 }
e98fdf1a
AM
4761 else
4762 printf (" %-6lx\t%.*s\n",
4763 (unsigned long) offset, (int) maxprint, data);
4764
4765 data += strnlen ((char *) data, maxprint) + 1;
4766 if (data >= end)
4767 break;
19e6b90e 4768 }
19e6b90e
L
4769 }
4770
4771 printf ("\n");
4772 return 1;
4773}
4774
459d52c8
DE
4775static int
4776display_debug_pubnames (struct dwarf_section *section, void *file)
4777{
4778 return display_debug_pubnames_worker (section, file, 0);
4779}
4780
4781static int
4782display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
4783{
4784 return display_debug_pubnames_worker (section, file, 1);
4785}
4786
19e6b90e
L
4787static int
4788display_debug_macinfo (struct dwarf_section *section,
4789 void *file ATTRIBUTE_UNUSED)
4790{
4791 unsigned char *start = section->start;
4792 unsigned char *end = start + section->size;
4793 unsigned char *curr = start;
4794 unsigned int bytes_read;
4795 enum dwarf_macinfo_record_type op;
4796
dda8d76d 4797 introduce (section, FALSE);
19e6b90e
L
4798
4799 while (curr < end)
4800 {
4801 unsigned int lineno;
0c588247 4802 const unsigned char *string;
19e6b90e 4803
3f5e193b 4804 op = (enum dwarf_macinfo_record_type) *curr;
19e6b90e
L
4805 curr++;
4806
4807 switch (op)
4808 {
4809 case DW_MACINFO_start_file:
4810 {
4811 unsigned int filenum;
4812
f6f0e17b 4813 lineno = read_uleb128 (curr, & bytes_read, end);
19e6b90e 4814 curr += bytes_read;
f6f0e17b 4815 filenum = read_uleb128 (curr, & bytes_read, end);
19e6b90e
L
4816 curr += bytes_read;
4817
4818 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
4819 lineno, filenum);
4820 }
4821 break;
4822
4823 case DW_MACINFO_end_file:
4824 printf (_(" DW_MACINFO_end_file\n"));
4825 break;
4826
4827 case DW_MACINFO_define:
f6f0e17b 4828 lineno = read_uleb128 (curr, & bytes_read, end);
19e6b90e 4829 curr += bytes_read;
0c588247
NC
4830 string = curr;
4831 curr += strnlen ((char *) string, end - string) + 1;
19e6b90e
L
4832 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
4833 lineno, string);
4834 break;
4835
4836 case DW_MACINFO_undef:
f6f0e17b 4837 lineno = read_uleb128 (curr, & bytes_read, end);
19e6b90e 4838 curr += bytes_read;
0c588247
NC
4839 string = curr;
4840 curr += strnlen ((char *) string, end - string) + 1;
19e6b90e
L
4841 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
4842 lineno, string);
4843 break;
4844
4845 case DW_MACINFO_vendor_ext:
4846 {
4847 unsigned int constant;
4848
f6f0e17b 4849 constant = read_uleb128 (curr, & bytes_read, end);
19e6b90e 4850 curr += bytes_read;
0c588247
NC
4851 string = curr;
4852 curr += strnlen ((char *) string, end - string) + 1;
19e6b90e
L
4853 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4854 constant, string);
4855 }
4856 break;
4857 }
4858 }
4859
4860 return 1;
4861}
4862
4ccf1e31
JJ
4863/* Given LINE_OFFSET into the .debug_line section, attempt to return
4864 filename and dirname corresponding to file name table entry with index
4865 FILEIDX. Return NULL on failure. */
4866
4867static unsigned char *
f6f0e17b
NC
4868get_line_filename_and_dirname (dwarf_vma line_offset,
4869 dwarf_vma fileidx,
4ccf1e31
JJ
4870 unsigned char **dir_name)
4871{
4872 struct dwarf_section *section = &debug_displays [line].section;
4873 unsigned char *hdrptr, *dirtable, *file_name;
4874 unsigned int offset_size, initial_length_size;
4875 unsigned int version, opcode_base, bytes_read;
4876 dwarf_vma length, diridx;
f6f0e17b 4877 const unsigned char * end;
4ccf1e31
JJ
4878
4879 *dir_name = NULL;
4880 if (section->start == NULL
4881 || line_offset >= section->size
4882 || fileidx == 0)
4883 return NULL;
4884
4885 hdrptr = section->start + line_offset;
f6f0e17b 4886 end = section->start + section->size;
0c588247
NC
4887
4888 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
4ccf1e31
JJ
4889 if (length == 0xffffffff)
4890 {
4891 /* This section is 64-bit DWARF 3. */
0c588247 4892 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
4ccf1e31
JJ
4893 offset_size = 8;
4894 initial_length_size = 12;
4895 }
4896 else
4897 {
4898 offset_size = 4;
4899 initial_length_size = 4;
4900 }
e98fdf1a
AM
4901 if (length + initial_length_size < length
4902 || length + initial_length_size > section->size)
4ccf1e31 4903 return NULL;
0c588247
NC
4904
4905 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
4ccf1e31
JJ
4906 if (version != 2 && version != 3 && version != 4)
4907 return NULL;
4908 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
4909 if (version >= 4)
4910 hdrptr++; /* Skip max_ops_per_insn. */
4911 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
0c588247
NC
4912
4913 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
4ccf1e31
JJ
4914 if (opcode_base == 0)
4915 return NULL;
0c588247 4916
4ccf1e31 4917 hdrptr += opcode_base - 1;
5c1c468d
NC
4918 if (hdrptr >= end)
4919 return NULL;
4920
4ccf1e31
JJ
4921 dirtable = hdrptr;
4922 /* Skip over dirname table. */
4923 while (*hdrptr != '\0')
5c1c468d
NC
4924 {
4925 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4926 if (hdrptr >= end)
4927 return NULL;
4928 }
4ccf1e31 4929 hdrptr++; /* Skip the NUL at the end of the table. */
5c1c468d 4930
4ccf1e31 4931 /* Now skip over preceding filename table entries. */
5c1c468d 4932 for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--)
4ccf1e31 4933 {
0c588247 4934 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
f6f0e17b 4935 read_uleb128 (hdrptr, &bytes_read, end);
4ccf1e31 4936 hdrptr += bytes_read;
f6f0e17b 4937 read_uleb128 (hdrptr, &bytes_read, end);
4ccf1e31 4938 hdrptr += bytes_read;
f6f0e17b 4939 read_uleb128 (hdrptr, &bytes_read, end);
4ccf1e31
JJ
4940 hdrptr += bytes_read;
4941 }
5c1c468d 4942 if (hdrptr >= end || *hdrptr == '\0')
4ccf1e31 4943 return NULL;
5c1c468d 4944
4ccf1e31 4945 file_name = hdrptr;
0c588247 4946 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
5c1c468d
NC
4947 if (hdrptr >= end)
4948 return NULL;
f6f0e17b 4949 diridx = read_uleb128 (hdrptr, &bytes_read, end);
4ccf1e31
JJ
4950 if (diridx == 0)
4951 return file_name;
5c1c468d 4952 for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--)
0c588247 4953 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
5c1c468d 4954 if (dirtable >= end || *dirtable == '\0')
4ccf1e31
JJ
4955 return NULL;
4956 *dir_name = dirtable;
4957 return file_name;
4958}
4959
4960static int
4961display_debug_macro (struct dwarf_section *section,
4962 void *file)
4963{
4964 unsigned char *start = section->start;
4965 unsigned char *end = start + section->size;
4966 unsigned char *curr = start;
4967 unsigned char *extended_op_buf[256];
4968 unsigned int bytes_read;
4969
dda8d76d
NC
4970 load_debug_section_with_follow (str, file);
4971 load_debug_section_with_follow (line, file);
4ccf1e31 4972
dda8d76d 4973 introduce (section, FALSE);
4ccf1e31
JJ
4974
4975 while (curr < end)
4976 {
4977 unsigned int lineno, version, flags;
4978 unsigned int offset_size = 4;
0c588247 4979 const unsigned char *string;
4ccf1e31
JJ
4980 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
4981 unsigned char **extended_ops = NULL;
4982
0c588247 4983 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
7a7e1061 4984 if (version != 4 && version != 5)
4ccf1e31 4985 {
7a7e1061 4986 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
4ccf1e31
JJ
4987 section->name);
4988 return 0;
4989 }
4990
0c588247 4991 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
4ccf1e31
JJ
4992 if (flags & 1)
4993 offset_size = 8;
4994 printf (_(" Offset: 0x%lx\n"),
4995 (unsigned long) sec_offset);
4996 printf (_(" Version: %d\n"), version);
4997 printf (_(" Offset size: %d\n"), offset_size);
4998 if (flags & 2)
4999 {
0c588247 5000 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
4ccf1e31
JJ
5001 printf (_(" Offset into .debug_line: 0x%lx\n"),
5002 (unsigned long) line_offset);
5003 }
5004 if (flags & 4)
5005 {
0c588247 5006 unsigned int i, count, op;
4ccf1e31 5007 dwarf_vma nargs, n;
0c588247
NC
5008
5009 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
bf5117e3 5010
4ccf1e31
JJ
5011 memset (extended_op_buf, 0, sizeof (extended_op_buf));
5012 extended_ops = extended_op_buf;
5013 if (count)
5014 {
5015 printf (_(" Extension opcode arguments:\n"));
5016 for (i = 0; i < count; i++)
5017 {
0c588247 5018 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4ccf1e31 5019 extended_ops[op] = curr;
f6f0e17b 5020 nargs = read_uleb128 (curr, &bytes_read, end);
4ccf1e31
JJ
5021 curr += bytes_read;
5022 if (nargs == 0)
7a7e1061 5023 printf (_(" DW_MACRO_%02x has no arguments\n"), op);
4ccf1e31
JJ
5024 else
5025 {
7a7e1061 5026 printf (_(" DW_MACRO_%02x arguments: "), op);
4ccf1e31
JJ
5027 for (n = 0; n < nargs; n++)
5028 {
0c588247
NC
5029 unsigned int form;
5030
5031 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
4ccf1e31
JJ
5032 printf ("%s%s", get_FORM_name (form),
5033 n == nargs - 1 ? "\n" : ", ");
5034 switch (form)
5035 {
5036 case DW_FORM_data1:
5037 case DW_FORM_data2:
5038 case DW_FORM_data4:
5039 case DW_FORM_data8:
5040 case DW_FORM_sdata:
5041 case DW_FORM_udata:
5042 case DW_FORM_block:
5043 case DW_FORM_block1:
5044 case DW_FORM_block2:
5045 case DW_FORM_block4:
5046 case DW_FORM_flag:
5047 case DW_FORM_string:
5048 case DW_FORM_strp:
5049 case DW_FORM_sec_offset:
5050 break;
5051 default:
5052 error (_("Invalid extension opcode form %s\n"),
5053 get_FORM_name (form));
5054 return 0;
5055 }
5056 }
5057 }
5058 }
5059 }
5060 }
5061 printf ("\n");
5062
5063 while (1)
5064 {
5065 unsigned int op;
5066
5067 if (curr >= end)
5068 {
5069 error (_(".debug_macro section not zero terminated\n"));
5070 return 0;
5071 }
5072
0c588247 5073 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4ccf1e31
JJ
5074 if (op == 0)
5075 break;
5076
5077 switch (op)
5078 {
7a7e1061 5079 case DW_MACRO_start_file:
4ccf1e31
JJ
5080 {
5081 unsigned int filenum;
5082 unsigned char *file_name = NULL, *dir_name = NULL;
5083
f6f0e17b 5084 lineno = read_uleb128 (curr, &bytes_read, end);
4ccf1e31 5085 curr += bytes_read;
f6f0e17b 5086 filenum = read_uleb128 (curr, &bytes_read, end);
4ccf1e31
JJ
5087 curr += bytes_read;
5088
5089 if ((flags & 2) == 0)
7a7e1061 5090 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
4ccf1e31
JJ
5091 else
5092 file_name
5093 = get_line_filename_and_dirname (line_offset, filenum,
5094 &dir_name);
5095 if (file_name == NULL)
7a7e1061 5096 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
4ccf1e31
JJ
5097 lineno, filenum);
5098 else
7a7e1061 5099 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4ccf1e31
JJ
5100 lineno, filenum,
5101 dir_name != NULL ? (const char *) dir_name : "",
5102 dir_name != NULL ? "/" : "", file_name);
5103 }
5104 break;
5105
7a7e1061
JK
5106 case DW_MACRO_end_file:
5107 printf (_(" DW_MACRO_end_file\n"));
4ccf1e31
JJ
5108 break;
5109
7a7e1061 5110 case DW_MACRO_define:
f6f0e17b 5111 lineno = read_uleb128 (curr, &bytes_read, end);
4ccf1e31 5112 curr += bytes_read;
0c588247
NC
5113 string = curr;
5114 curr += strnlen ((char *) string, end - string) + 1;
7a7e1061 5115 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
4ccf1e31
JJ
5116 lineno, string);
5117 break;
5118
7a7e1061 5119 case DW_MACRO_undef:
f6f0e17b 5120 lineno = read_uleb128 (curr, &bytes_read, end);
4ccf1e31 5121 curr += bytes_read;
0c588247
NC
5122 string = curr;
5123 curr += strnlen ((char *) string, end - string) + 1;
7a7e1061 5124 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
4ccf1e31
JJ
5125 lineno, string);
5126 break;
5127
7a7e1061 5128 case DW_MACRO_define_strp:
f6f0e17b 5129 lineno = read_uleb128 (curr, &bytes_read, end);
4ccf1e31 5130 curr += bytes_read;
0c588247 5131 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4ccf1e31 5132 string = fetch_indirect_string (offset);
7a7e1061 5133 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
4ccf1e31
JJ
5134 lineno, string);
5135 break;
5136
7a7e1061 5137 case DW_MACRO_undef_strp:
f6f0e17b 5138 lineno = read_uleb128 (curr, &bytes_read, end);
4ccf1e31 5139 curr += bytes_read;
0c588247 5140 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4ccf1e31 5141 string = fetch_indirect_string (offset);
7a7e1061 5142 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
4ccf1e31
JJ
5143 lineno, string);
5144 break;
5145
7a7e1061 5146 case DW_MACRO_import:
0c588247 5147 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
7a7e1061 5148 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
4ccf1e31
JJ
5149 (unsigned long) offset);
5150 break;
5151
7a7e1061 5152 case DW_MACRO_define_sup:
f6f0e17b 5153 lineno = read_uleb128 (curr, &bytes_read, end);
a081f3cd 5154 curr += bytes_read;
0c588247 5155 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
7a7e1061 5156 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
a081f3cd
JJ
5157 lineno, (unsigned long) offset);
5158 break;
5159
7a7e1061 5160 case DW_MACRO_undef_sup:
f6f0e17b 5161 lineno = read_uleb128 (curr, &bytes_read, end);
a081f3cd 5162 curr += bytes_read;
0c588247 5163 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
7a7e1061 5164 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
a081f3cd
JJ
5165 lineno, (unsigned long) offset);
5166 break;
5167
7a7e1061 5168 case DW_MACRO_import_sup:
0c588247 5169 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
7a7e1061 5170 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
a081f3cd
JJ
5171 (unsigned long) offset);
5172 break;
5173
4ccf1e31
JJ
5174 default:
5175 if (extended_ops == NULL || extended_ops[op] == NULL)
5176 {
5177 error (_(" Unknown macro opcode %02x seen\n"), op);
5178 return 0;
5179 }
5180 else
5181 {
5182 /* Skip over unhandled opcodes. */
5183 dwarf_vma nargs, n;
5184 unsigned char *desc = extended_ops[op];
f6f0e17b 5185 nargs = read_uleb128 (desc, &bytes_read, end);
4ccf1e31
JJ
5186 desc += bytes_read;
5187 if (nargs == 0)
5188 {
7a7e1061 5189 printf (_(" DW_MACRO_%02x\n"), op);
4ccf1e31
JJ
5190 break;
5191 }
7a7e1061 5192 printf (_(" DW_MACRO_%02x -"), op);
4ccf1e31
JJ
5193 for (n = 0; n < nargs; n++)
5194 {
0c588247
NC
5195 int val;
5196
77145576 5197 /* DW_FORM_implicit_const is not expected here. */
0c588247 5198 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
4ccf1e31 5199 curr
77145576 5200 = read_and_display_attr_value (0, val, 0,
f6f0e17b 5201 curr, end, 0, 0, offset_size,
341f9135 5202 version, NULL, 0, NULL,
ef0b5f1c 5203 NULL, ' ');
4ccf1e31
JJ
5204 if (n != nargs - 1)
5205 printf (",");
5206 }
5207 printf ("\n");
5208 }
5209 break;
5210 }
5211 }
5212
5213 printf ("\n");
b4eb7656 5214 }
4ccf1e31
JJ
5215
5216 return 1;
5217}
5218
19e6b90e
L
5219static int
5220display_debug_abbrev (struct dwarf_section *section,
5221 void *file ATTRIBUTE_UNUSED)
5222{
5223 abbrev_entry *entry;
5224 unsigned char *start = section->start;
5225 unsigned char *end = start + section->size;
5226
dda8d76d 5227 introduce (section, FALSE);
19e6b90e
L
5228
5229 do
5230 {
7282333f
AM
5231 unsigned char *last;
5232
19e6b90e
L
5233 free_abbrevs ();
5234
7282333f 5235 last = start;
19e6b90e
L
5236 start = process_abbrev_section (start, end);
5237
5238 if (first_abbrev == NULL)
5239 continue;
5240
7282333f 5241 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
19e6b90e
L
5242
5243 for (entry = first_abbrev; entry; entry = entry->next)
5244 {
5245 abbrev_attr *attr;
5246
cc5914eb 5247 printf (" %ld %s [%s]\n",
19e6b90e
L
5248 entry->entry,
5249 get_TAG_name (entry->tag),
5250 entry->children ? _("has children") : _("no children"));
5251
5252 for (attr = entry->first_attr; attr; attr = attr->next)
77145576
JK
5253 {
5254 printf (" %-18s %s",
5255 get_AT_name (attr->attribute),
5256 get_FORM_name (attr->form));
5257 if (attr->form == DW_FORM_implicit_const)
5258 printf (": %" BFD_VMA_FMT "d", attr->implicit_const);
5259 putchar ('\n');
5260 }
19e6b90e
L
5261 }
5262 }
5263 while (start);
5264
5265 printf ("\n");
5266
5267 return 1;
5268}
5269
42bcef4a
AB
5270/* Return true when ADDR is the maximum address, when addresses are
5271 POINTER_SIZE bytes long. */
5272
5273static bfd_boolean
5274is_max_address (dwarf_vma addr, unsigned int pointer_size)
5275{
5276 dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1));
5277 return ((addr & mask) == mask);
5278}
5279
9f272209
AO
5280/* Display a view pair list starting at *VSTART_PTR and ending at
5281 VLISTEND within SECTION. */
5282
5283static void
5284display_view_pair_list (struct dwarf_section *section,
5285 unsigned char **vstart_ptr,
5286 unsigned int debug_info_entry,
5287 unsigned char *vlistend)
5288{
5289 unsigned char *vstart = *vstart_ptr;
5290 unsigned char *section_end = section->start + section->size;
5291 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
5292
5293 if (vlistend < section_end)
5294 section_end = vlistend;
5295
5296 putchar ('\n');
5297
5298 while (vstart < section_end)
5299 {
5300 dwarf_vma off = vstart - section->start;
5301 dwarf_vma vbegin, vend;
5302
5303 unsigned int bytes_read;
5304 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5305 vstart += bytes_read;
5306 if (vstart == section_end)
5307 {
5308 vstart -= bytes_read;
5309 break;
5310 }
5311
5312 vend = read_uleb128 (vstart, &bytes_read, section_end);
5313 vstart += bytes_read;
5314
5315 printf (" %8.8lx ", (unsigned long) off);
5316
5317 print_dwarf_view (vbegin, pointer_size, 1);
5318 print_dwarf_view (vend, pointer_size, 1);
5319 printf (_("location view pair\n"));
5320 }
5321
5322 putchar ('\n');
5323 *vstart_ptr = vstart;
5324}
5325
4723351a
CC
5326/* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
5327
5328static void
5329display_loc_list (struct dwarf_section *section,
b4eb7656
AM
5330 unsigned char **start_ptr,
5331 unsigned int debug_info_entry,
359ca075
JK
5332 dwarf_vma offset,
5333 dwarf_vma base_address,
9f272209 5334 unsigned char **vstart_ptr,
b4eb7656 5335 int has_frame_base)
4723351a 5336{
9f272209 5337 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
4723351a 5338 unsigned char *section_end = section->start + section->size;
82b1b41b
NC
5339 unsigned long cu_offset;
5340 unsigned int pointer_size;
5341 unsigned int offset_size;
5342 int dwarf_version;
4723351a
CC
5343
5344 dwarf_vma begin;
5345 dwarf_vma end;
5346 unsigned short length;
5347 int need_frame_base;
5348
82b1b41b
NC
5349 if (debug_info_entry >= num_debug_info_entries)
5350 {
5351 warn (_("No debug information available for loc lists of entry: %u\n"),
5352 debug_info_entry);
5353 return;
5354 }
b4eb7656 5355
82b1b41b
NC
5356 cu_offset = debug_information [debug_info_entry].cu_offset;
5357 pointer_size = debug_information [debug_info_entry].pointer_size;
5358 offset_size = debug_information [debug_info_entry].offset_size;
5359 dwarf_version = debug_information [debug_info_entry].dwarf_version;
b4eb7656 5360
f41e4712
NC
5361 if (pointer_size < 2 || pointer_size > 8)
5362 {
5363 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5364 pointer_size, debug_info_entry);
5365 return;
5366 }
5367
4723351a
CC
5368 while (1)
5369 {
359ca075 5370 dwarf_vma off = offset + (start - *start_ptr);
9f272209 5371 dwarf_vma vbegin = vm1, vend = vm1;
d1c4b12b 5372
4723351a 5373 if (start + 2 * pointer_size > section_end)
b4eb7656
AM
5374 {
5375 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 5376 (unsigned long) offset);
b4eb7656
AM
5377 break;
5378 }
4723351a 5379
359ca075 5380 printf (" %8.8lx ", (unsigned long) off);
fab128ef 5381
0c588247
NC
5382 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
5383 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
4723351a 5384
4723351a 5385 if (begin == 0 && end == 0)
b4eb7656 5386 {
d1c4b12b
NC
5387 /* PR 18374: In a object file we can have a location list that
5388 starts with a begin and end of 0 because there are relocations
5389 that need to be applied to the addresses. Actually applying
5390 the relocations now does not help as they will probably resolve
5391 to 0, since the object file has not been fully linked. Real
5392 end of list markers will not have any relocations against them. */
5393 if (! reloc_at (section, off)
5394 && ! reloc_at (section, off + pointer_size))
5395 {
5396 printf (_("<End of list>\n"));
5397 break;
5398 }
b4eb7656 5399 }
4723351a
CC
5400
5401 /* Check base address specifiers. */
42bcef4a
AB
5402 if (is_max_address (begin, pointer_size)
5403 && !is_max_address (end, pointer_size))
b4eb7656
AM
5404 {
5405 base_address = end;
5406 print_dwarf_vma (begin, pointer_size);
5407 print_dwarf_vma (end, pointer_size);
5408 printf (_("(base address)\n"));
5409 continue;
5410 }
4723351a 5411
9f272209
AO
5412 if (vstart)
5413 {
5414 unsigned int bytes_read;
5415
5416 off = offset + (vstart - *start_ptr);
5417
5418 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5419 vstart += bytes_read;
5420 print_dwarf_view (vbegin, pointer_size, 1);
5421
5422 vend = read_uleb128 (vstart, &bytes_read, section_end);
5423 vstart += bytes_read;
5424 print_dwarf_view (vend, pointer_size, 1);
5425
5426 printf (_("views at %8.8lx for:\n %*s "),
5427 (unsigned long) off, 8, "");
5428 }
5429
4723351a 5430 if (start + 2 > section_end)
b4eb7656
AM
5431 {
5432 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 5433 (unsigned long) offset);
b4eb7656
AM
5434 break;
5435 }
4723351a 5436
0c588247 5437 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4723351a
CC
5438
5439 if (start + length > section_end)
b4eb7656
AM
5440 {
5441 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 5442 (unsigned long) offset);
b4eb7656
AM
5443 break;
5444 }
4723351a
CC
5445
5446 print_dwarf_vma (begin + base_address, pointer_size);
5447 print_dwarf_vma (end + base_address, pointer_size);
5448
5449 putchar ('(');
5450 need_frame_base = decode_location_expression (start,
b4eb7656
AM
5451 pointer_size,
5452 offset_size,
5453 dwarf_version,
5454 length,
5455 cu_offset, section);
4723351a
CC
5456 putchar (')');
5457
5458 if (need_frame_base && !has_frame_base)
b4eb7656 5459 printf (_(" [without DW_AT_frame_base]"));
4723351a 5460
9f272209 5461 if (begin == end && vbegin == vend)
b4eb7656 5462 fputs (_(" (start == end)"), stdout);
9f272209 5463 else if (begin > end || (begin == end && vbegin > vend))
b4eb7656 5464 fputs (_(" (start > end)"), stdout);
4723351a
CC
5465
5466 putchar ('\n');
5467
5468 start += length;
5469 }
5470
5471 *start_ptr = start;
9f272209 5472 *vstart_ptr = vstart;
4723351a
CC
5473}
5474
77145576
JK
5475/* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5476
5477static void
5478display_loclists_list (struct dwarf_section *section,
5479 unsigned char **start_ptr,
5480 unsigned int debug_info_entry,
5481 dwarf_vma offset,
5482 dwarf_vma base_address,
9f272209 5483 unsigned char **vstart_ptr,
77145576
JK
5484 int has_frame_base)
5485{
9f272209 5486 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
77145576
JK
5487 unsigned char *section_end = section->start + section->size;
5488 unsigned long cu_offset;
5489 unsigned int pointer_size;
5490 unsigned int offset_size;
5491 int dwarf_version;
5492 unsigned int bytes_read;
5493
9dfd0db9 5494 /* Initialize it due to a false compiler warning. */
9f272209
AO
5495 dwarf_vma begin = -1, vbegin = -1;
5496 dwarf_vma end = -1, vend = -1;
77145576
JK
5497 dwarf_vma length;
5498 int need_frame_base;
5499
5500 if (debug_info_entry >= num_debug_info_entries)
5501 {
5502 warn (_("No debug information available for "
5503 "loclists lists of entry: %u\n"),
5504 debug_info_entry);
5505 return;
5506 }
5507
5508 cu_offset = debug_information [debug_info_entry].cu_offset;
5509 pointer_size = debug_information [debug_info_entry].pointer_size;
5510 offset_size = debug_information [debug_info_entry].offset_size;
5511 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5512
5513 if (pointer_size < 2 || pointer_size > 8)
5514 {
5515 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5516 pointer_size, debug_info_entry);
5517 return;
5518 }
5519
5520 while (1)
5521 {
5522 dwarf_vma off = offset + (start - *start_ptr);
5523 enum dwarf_location_list_entry_type llet;
5524
5525 if (start + 1 > section_end)
5526 {
5527 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5528 (unsigned long) offset);
5529 break;
5530 }
5531
5532 printf (" %8.8lx ", (unsigned long) off);
5533
5534 SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end);
5535
9f272209
AO
5536 if (vstart && llet == DW_LLE_offset_pair)
5537 {
5538 off = offset + (vstart - *start_ptr);
5539
5540 vbegin = read_uleb128 (vstart, &bytes_read, section_end);
5541 vstart += bytes_read;
5542 print_dwarf_view (vbegin, pointer_size, 1);
5543
5544 vend = read_uleb128 (vstart, &bytes_read, section_end);
5545 vstart += bytes_read;
5546 print_dwarf_view (vend, pointer_size, 1);
5547
5548 printf (_("views at %8.8lx for:\n %*s "),
5549 (unsigned long) off, 8, "");
5550 }
5551
77145576
JK
5552 switch (llet)
5553 {
5554 case DW_LLE_end_of_list:
5555 printf (_("<End of list>\n"));
5556 break;
5557 case DW_LLE_offset_pair:
5558 begin = read_uleb128 (start, &bytes_read, section_end);
5559 start += bytes_read;
5560 end = read_uleb128 (start, &bytes_read, section_end);
5561 start += bytes_read;
5562 break;
5563 case DW_LLE_base_address:
5564 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size,
5565 section_end);
5566 print_dwarf_vma (base_address, pointer_size);
5567 printf (_("(base address)\n"));
5568 break;
9f272209
AO
5569#ifdef DW_LLE_view_pair
5570 case DW_LLE_view_pair:
5571 if (vstart)
5572 printf (_("View pair entry in loclist with locviews attribute\n"));
5573 vbegin = read_uleb128 (start, &bytes_read, section_end);
5574 start += bytes_read;
5575 print_dwarf_view (vbegin, pointer_size, 1);
5576
5577 vend = read_uleb128 (start, &bytes_read, section_end);
5578 start += bytes_read;
5579 print_dwarf_view (vend, pointer_size, 1);
5580
5581 printf (_("views for:\n"));
5582 continue;
5583#endif
77145576
JK
5584 default:
5585 error (_("Invalid location list entry type %d\n"), llet);
5586 return;
5587 }
5588 if (llet == DW_LLE_end_of_list)
5589 break;
5590 if (llet != DW_LLE_offset_pair)
5591 continue;
5592
5593 if (start + 2 > section_end)
5594 {
5595 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5596 (unsigned long) offset);
5597 break;
5598 }
5599
5600 length = read_uleb128 (start, &bytes_read, section_end);
5601 start += bytes_read;
5602
5603 print_dwarf_vma (begin + base_address, pointer_size);
5604 print_dwarf_vma (end + base_address, pointer_size);
5605
5606 putchar ('(');
5607 need_frame_base = decode_location_expression (start,
5608 pointer_size,
5609 offset_size,
5610 dwarf_version,
5611 length,
5612 cu_offset, section);
5613 putchar (')');
5614
5615 if (need_frame_base && !has_frame_base)
5616 printf (_(" [without DW_AT_frame_base]"));
5617
9f272209 5618 if (begin == end && vbegin == vend)
77145576 5619 fputs (_(" (start == end)"), stdout);
9f272209 5620 else if (begin > end || (begin == end && vbegin > vend))
77145576
JK
5621 fputs (_(" (start > end)"), stdout);
5622
5623 putchar ('\n');
5624
5625 start += length;
9f272209 5626 vbegin = vend = -1;
77145576
JK
5627 }
5628
9f272209
AO
5629 if (vbegin != vm1 || vend != vm1)
5630 printf (_("Trailing view pair not used in a range"));
5631
77145576 5632 *start_ptr = start;
9f272209 5633 *vstart_ptr = vstart;
77145576
JK
5634}
5635
fab128ef
CC
5636/* Print a .debug_addr table index in decimal, surrounded by square brackets,
5637 right-adjusted in a field of length LEN, and followed by a space. */
5638
5639static void
5640print_addr_index (unsigned int idx, unsigned int len)
5641{
5642 static char buf[15];
5643 snprintf (buf, sizeof (buf), "[%d]", idx);
341f9135 5644 printf ("%*s ", len, buf);
fab128ef
CC
5645}
5646
4723351a
CC
5647/* Display a location list from a .dwo section. It uses address indexes rather
5648 than embedded addresses. This code closely follows display_loc_list, but the
5649 two are sufficiently different that combining things is very ugly. */
5650
5651static void
5652display_loc_list_dwo (struct dwarf_section *section,
b4eb7656
AM
5653 unsigned char **start_ptr,
5654 unsigned int debug_info_entry,
359ca075 5655 dwarf_vma offset,
9f272209 5656 unsigned char **vstart_ptr,
b4eb7656 5657 int has_frame_base)
4723351a 5658{
9f272209 5659 unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
4723351a 5660 unsigned char *section_end = section->start + section->size;
82b1b41b
NC
5661 unsigned long cu_offset;
5662 unsigned int pointer_size;
5663 unsigned int offset_size;
5664 int dwarf_version;
4723351a
CC
5665 int entry_type;
5666 unsigned short length;
5667 int need_frame_base;
fab128ef 5668 unsigned int idx;
4723351a
CC
5669 unsigned int bytes_read;
5670
82b1b41b
NC
5671 if (debug_info_entry >= num_debug_info_entries)
5672 {
5673 warn (_("No debug information for loc lists of entry: %u\n"),
5674 debug_info_entry);
5675 return;
5676 }
5677
5678 cu_offset = debug_information [debug_info_entry].cu_offset;
5679 pointer_size = debug_information [debug_info_entry].pointer_size;
5680 offset_size = debug_information [debug_info_entry].offset_size;
5681 dwarf_version = debug_information [debug_info_entry].dwarf_version;
5682
f41e4712
NC
5683 if (pointer_size < 2 || pointer_size > 8)
5684 {
5685 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5686 pointer_size, debug_info_entry);
5687 return;
5688 }
5689
4723351a
CC
5690 while (1)
5691 {
359ca075 5692 printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr)));
4723351a 5693
fab128ef 5694 if (start >= section_end)
b4eb7656
AM
5695 {
5696 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 5697 (unsigned long) offset);
b4eb7656
AM
5698 break;
5699 }
4723351a 5700
0c588247 5701 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
9f272209
AO
5702
5703 if (vstart)
5704 switch (entry_type)
5705 {
5706 default:
5707 break;
5708
5709 case 2:
5710 case 3:
5711 case 4:
5712 {
5713 dwarf_vma view;
5714 dwarf_vma off = offset + (vstart - *start_ptr);
5715
5716 view = read_uleb128 (vstart, &bytes_read, section_end);
5717 vstart += bytes_read;
5718 print_dwarf_view (view, 8, 1);
5719
5720 view = read_uleb128 (vstart, &bytes_read, section_end);
5721 vstart += bytes_read;
5722 print_dwarf_view (view, 8, 1);
5723
5724 printf (_("views at %8.8lx for:\n %*s "),
5725 (unsigned long) off, 8, "");
5726
5727 }
5728 break;
5729 }
5730
4723351a 5731 switch (entry_type)
b4eb7656
AM
5732 {
5733 case 0: /* A terminating entry. */
5734 *start_ptr = start;
9f272209 5735 *vstart_ptr = vstart;
b4eb7656
AM
5736 printf (_("<End of list>\n"));
5737 return;
5738 case 1: /* A base-address entry. */
5739 idx = read_uleb128 (start, &bytes_read, section_end);
5740 start += bytes_read;
5741 print_addr_index (idx, 8);
9f272209 5742 printf ("%*s", 9 + (vstart ? 2 * 6 : 0), "");
b4eb7656
AM
5743 printf (_("(base address selection entry)\n"));
5744 continue;
5745 case 2: /* A start/end entry. */
5746 idx = read_uleb128 (start, &bytes_read, section_end);
5747 start += bytes_read;
5748 print_addr_index (idx, 8);
5749 idx = read_uleb128 (start, &bytes_read, section_end);
5750 start += bytes_read;
5751 print_addr_index (idx, 8);
5752 break;
5753 case 3: /* A start/length entry. */
5754 idx = read_uleb128 (start, &bytes_read, section_end);
5755 start += bytes_read;
5756 print_addr_index (idx, 8);
5757 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5758 printf ("%08x ", idx);
5759 break;
5760 case 4: /* An offset pair entry. */
5761 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5762 printf ("%08x ", idx);
5763 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
5764 printf ("%08x ", idx);
5765 break;
5766 default:
5767 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
5768 *start_ptr = start;
9f272209 5769 *vstart_ptr = vstart;
b4eb7656
AM
5770 return;
5771 }
4723351a
CC
5772
5773 if (start + 2 > section_end)
b4eb7656
AM
5774 {
5775 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 5776 (unsigned long) offset);
b4eb7656
AM
5777 break;
5778 }
4723351a 5779
0c588247 5780 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4723351a 5781 if (start + length > section_end)
b4eb7656
AM
5782 {
5783 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
359ca075 5784 (unsigned long) offset);
b4eb7656
AM
5785 break;
5786 }
4723351a
CC
5787
5788 putchar ('(');
5789 need_frame_base = decode_location_expression (start,
b4eb7656
AM
5790 pointer_size,
5791 offset_size,
5792 dwarf_version,
5793 length,
5794 cu_offset, section);
4723351a
CC
5795 putchar (')');
5796
5797 if (need_frame_base && !has_frame_base)
b4eb7656 5798 printf (_(" [without DW_AT_frame_base]"));
4723351a
CC
5799
5800 putchar ('\n');
5801
5802 start += length;
5803 }
5804
5805 *start_ptr = start;
9f272209 5806 *vstart_ptr = vstart;
4723351a
CC
5807}
5808
9f272209
AO
5809/* Sort array of indexes in ascending order of loc_offsets[idx] and
5810 loc_views. */
51d0d03f 5811
9f272209 5812static dwarf_vma *loc_offsets, *loc_views;
51d0d03f
JJ
5813
5814static int
5815loc_offsets_compar (const void *ap, const void *bp)
5816{
5817 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
5818 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
5819
9f272209
AO
5820 int ret = (a > b) - (b > a);
5821 if (ret)
5822 return ret;
5823
5824 a = loc_views[*(const unsigned int *) ap];
5825 b = loc_views[*(const unsigned int *) bp];
5826
5827 ret = (a > b) - (b > a);
5828
5829 return ret;
51d0d03f
JJ
5830}
5831
19e6b90e
L
5832static int
5833display_debug_loc (struct dwarf_section *section, void *file)
5834{
9f272209 5835 unsigned char *start = section->start, *vstart = NULL;
19e6b90e
L
5836 unsigned long bytes;
5837 unsigned char *section_begin = start;
5838 unsigned int num_loc_list = 0;
5839 unsigned long last_offset = 0;
9f272209 5840 unsigned long last_view = 0;
19e6b90e
L
5841 unsigned int first = 0;
5842 unsigned int i;
5843 unsigned int j;
5844 int seen_first_offset = 0;
51d0d03f 5845 int locs_sorted = 1;
9f272209 5846 unsigned char *next = start, *vnext = vstart;
51d0d03f 5847 unsigned int *array = NULL;
4723351a
CC
5848 const char *suffix = strrchr (section->name, '.');
5849 int is_dwo = 0;
77145576
JK
5850 int is_loclists = strstr (section->name, "debug_loclists") != NULL;
5851 dwarf_vma expected_start = 0;
4723351a
CC
5852
5853 if (suffix && strcmp (suffix, ".dwo") == 0)
5854 is_dwo = 1;
19e6b90e
L
5855
5856 bytes = section->size;
19e6b90e
L
5857
5858 if (bytes == 0)
5859 {
5860 printf (_("\nThe %s section is empty.\n"), section->name);
5861 return 0;
5862 }
5863
77145576
JK
5864 if (is_loclists)
5865 {
5866 unsigned char *hdrptr = section_begin;
5867 dwarf_vma ll_length;
5868 unsigned short ll_version;
5869 unsigned char *end = section_begin + section->size;
5870 unsigned char address_size, segment_selector_size;
5871 uint32_t offset_entry_count;
5872
5873 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end);
5874 if (ll_length == 0xffffffff)
5875 SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end);
5876
5877 SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end);
5878 if (ll_version != 5)
5879 {
5880 warn (_("The %s section contains corrupt or "
5881 "unsupported version number: %d.\n"),
5882 section->name, ll_version);
5883 return 0;
5884 }
5885
5886 SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
5887
5888 SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
5889 if (segment_selector_size != 0)
5890 {
5891 warn (_("The %s section contains "
5892 "unsupported segment selector size: %d.\n"),
5893 section->name, segment_selector_size);
5894 return 0;
5895 }
5896
5897 SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end);
5898 if (offset_entry_count != 0)
5899 {
5900 warn (_("The %s section contains "
5901 "unsupported offset entry count: %d.\n"),
5902 section->name, offset_entry_count);
5903 return 0;
5904 }
5905
5906 expected_start = hdrptr - section_begin;
5907 }
5908
1febe64d
NC
5909 if (load_debug_info (file) == 0)
5910 {
5911 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5912 section->name);
5913 return 0;
5914 }
19e6b90e
L
5915
5916 /* Check the order of location list in .debug_info section. If
5917 offsets of location lists are in the ascending order, we can
5918 use `debug_information' directly. */
5919 for (i = 0; i < num_debug_info_entries; i++)
5920 {
5921 unsigned int num;
5922
5923 num = debug_information [i].num_loc_offsets;
51d0d03f
JJ
5924 if (num > num_loc_list)
5925 num_loc_list = num;
19e6b90e
L
5926
5927 /* Check if we can use `debug_information' directly. */
51d0d03f 5928 if (locs_sorted && num != 0)
19e6b90e
L
5929 {
5930 if (!seen_first_offset)
5931 {
5932 /* This is the first location list. */
5933 last_offset = debug_information [i].loc_offsets [0];
9f272209 5934 last_view = debug_information [i].loc_views [0];
19e6b90e
L
5935 first = i;
5936 seen_first_offset = 1;
5937 j = 1;
5938 }
5939 else
5940 j = 0;
5941
5942 for (; j < num; j++)
5943 {
5944 if (last_offset >
9f272209
AO
5945 debug_information [i].loc_offsets [j]
5946 || (last_offset == debug_information [i].loc_offsets [j]
5947 && last_view > debug_information [i].loc_views [j]))
19e6b90e 5948 {
51d0d03f 5949 locs_sorted = 0;
19e6b90e
L
5950 break;
5951 }
5952 last_offset = debug_information [i].loc_offsets [j];
9f272209 5953 last_view = debug_information [i].loc_views [j];
19e6b90e
L
5954 }
5955 }
5956 }
5957
19e6b90e
L
5958 if (!seen_first_offset)
5959 error (_("No location lists in .debug_info section!\n"));
5960
d4bfc77b 5961 if (debug_information [first].num_loc_offsets > 0
9f272209
AO
5962 && debug_information [first].loc_offsets [0] != expected_start
5963 && debug_information [first].loc_views [0] != expected_start)
47704ddf
KT
5964 warn (_("Location lists in %s section start at 0x%s\n"),
5965 section->name,
5966 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
19e6b90e 5967
51d0d03f
JJ
5968 if (!locs_sorted)
5969 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
dda8d76d
NC
5970
5971 introduce (section, FALSE);
5972
d1c4b12b
NC
5973 if (reloc_at (section, 0))
5974 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
dda8d76d 5975
d1c4b12b 5976 printf (_(" Offset Begin End Expression\n"));
19e6b90e
L
5977
5978 seen_first_offset = 0;
5979 for (i = first; i < num_debug_info_entries; i++)
5980 {
9f272209 5981 dwarf_vma offset, voffset;
359ca075 5982 dwarf_vma base_address;
d1c4b12b 5983 unsigned int k;
19e6b90e
L
5984 int has_frame_base;
5985
51d0d03f
JJ
5986 if (!locs_sorted)
5987 {
5988 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
5989 array[k] = k;
5990 loc_offsets = debug_information [i].loc_offsets;
9f272209 5991 loc_views = debug_information [i].loc_views;
51d0d03f
JJ
5992 qsort (array, debug_information [i].num_loc_offsets,
5993 sizeof (*array), loc_offsets_compar);
5994 }
19e6b90e 5995
9f272209 5996 int adjacent_view_loclists = 1;
51d0d03f 5997 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
19e6b90e 5998 {
51d0d03f
JJ
5999 j = locs_sorted ? k : array[k];
6000 if (k
9f272209 6001 && (debug_information [i].loc_offsets [locs_sorted
51d0d03f 6002 ? k - 1 : array [k - 1]]
9f272209
AO
6003 == debug_information [i].loc_offsets [j])
6004 && (debug_information [i].loc_views [locs_sorted
6005 ? k - 1 : array [k - 1]]
6006 == debug_information [i].loc_views [j]))
51d0d03f 6007 continue;
19e6b90e 6008 has_frame_base = debug_information [i].have_frame_base [j];
d493b283 6009 offset = debug_information [i].loc_offsets [j];
19e6b90e 6010 next = section_begin + offset;
9f272209
AO
6011 voffset = debug_information [i].loc_views [j];
6012 if (voffset != vm1)
6013 vnext = section_begin + voffset;
6014 else
6015 vnext = NULL;
19e6b90e
L
6016 base_address = debug_information [i].base_address;
6017
9f272209
AO
6018 if (vnext && vnext < next)
6019 {
6020 vstart = vnext;
6021 display_view_pair_list (section, &vstart, i, next);
6022 if (start == vnext)
6023 start = vstart;
6024 }
6025
6026 if (!seen_first_offset || !adjacent_view_loclists)
19e6b90e
L
6027 seen_first_offset = 1;
6028 else
6029 {
6030 if (start < next)
6031 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
0af1713e 6032 (unsigned long) (start - section_begin),
c8071705 6033 (unsigned long) offset);
19e6b90e
L
6034 else if (start > next)
6035 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
0af1713e 6036 (unsigned long) (start - section_begin),
c8071705 6037 (unsigned long) offset);
19e6b90e
L
6038 }
6039 start = next;
9f272209 6040 vstart = vnext;
19e6b90e
L
6041
6042 if (offset >= bytes)
6043 {
6044 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
359ca075 6045 (unsigned long) offset);
19e6b90e
L
6046 continue;
6047 }
6048
9f272209
AO
6049 if (vnext && voffset >= bytes)
6050 {
6051 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
6052 (unsigned long) voffset);
6053 continue;
6054 }
6055
77145576
JK
6056 if (!is_loclists)
6057 {
6058 if (is_dwo)
6059 display_loc_list_dwo (section, &start, i, offset,
9f272209 6060 &vstart, has_frame_base);
77145576
JK
6061 else
6062 display_loc_list (section, &start, i, offset, base_address,
9f272209 6063 &vstart, has_frame_base);
77145576 6064 }
b4eb7656 6065 else
77145576
JK
6066 {
6067 if (is_dwo)
6068 warn (_("DWO is not yet supported.\n"));
6069 else
6070 display_loclists_list (section, &start, i, offset, base_address,
9f272209
AO
6071 &vstart, has_frame_base);
6072 }
6073
6074 /* FIXME: this arrangement is quite simplistic. Nothing
6075 requires locview lists to be adjacent to corresponding
6076 loclists, and a single loclist could be augmented by
6077 different locview lists, and vice-versa, unlikely as it
6078 is that it would make sense to do so. Hopefully we'll
6079 have view pair support built into loclists before we ever
6080 need to address all these possibilities. */
6081 if (adjacent_view_loclists && vnext
6082 && vnext != start && vstart != next)
6083 {
6084 adjacent_view_loclists = 0;
6085 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
77145576 6086 }
9f272209
AO
6087
6088 if (vnext && vnext == start)
6089 display_view_pair_list (section, &start, i, vstart);
19e6b90e
L
6090 }
6091 }
031cd65f 6092
4723351a 6093 if (start < section->start + section->size)
d3a49aa8
AM
6094 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
6095 "There are %ld unused bytes at the end of section %s\n",
6096 (long) (section->start + section->size - start)),
4723351a 6097 (long) (section->start + section->size - start), section->name);
98fb390a 6098 putchar ('\n');
51d0d03f 6099 free (array);
19e6b90e
L
6100 return 1;
6101}
6102
6103static int
6104display_debug_str (struct dwarf_section *section,
6105 void *file ATTRIBUTE_UNUSED)
6106{
6107 unsigned char *start = section->start;
6108 unsigned long bytes = section->size;
6109 dwarf_vma addr = section->address;
6110
6111 if (bytes == 0)
6112 {
6113 printf (_("\nThe %s section is empty.\n"), section->name);
6114 return 0;
6115 }
6116
dda8d76d 6117 introduce (section, FALSE);
19e6b90e
L
6118
6119 while (bytes)
6120 {
6121 int j;
6122 int k;
6123 int lbytes;
6124
6125 lbytes = (bytes > 16 ? 16 : bytes);
6126
6127 printf (" 0x%8.8lx ", (unsigned long) addr);
6128
6129 for (j = 0; j < 16; j++)
6130 {
6131 if (j < lbytes)
6132 printf ("%2.2x", start[j]);
6133 else
6134 printf (" ");
6135
6136 if ((j & 3) == 3)
6137 printf (" ");
6138 }
6139
6140 for (j = 0; j < lbytes; j++)
6141 {
6142 k = start[j];
6143 if (k >= ' ' && k < 0x80)
6144 printf ("%c", k);
6145 else
6146 printf (".");
6147 }
6148
6149 putchar ('\n');
6150
6151 start += lbytes;
6152 addr += lbytes;
6153 bytes -= lbytes;
6154 }
6155
6156 putchar ('\n');
6157
6158 return 1;
6159}
6160
19e6b90e
L
6161static int
6162display_debug_info (struct dwarf_section *section, void *file)
6163{
4723351a 6164 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
19e6b90e
L
6165}
6166
2b6f5997
CC
6167static int
6168display_debug_types (struct dwarf_section *section, void *file)
6169{
4723351a 6170 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
6f875884
TG
6171}
6172
6173static int
6174display_trace_info (struct dwarf_section *section, void *file)
6175{
4723351a 6176 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
2b6f5997 6177}
19e6b90e
L
6178
6179static int
6180display_debug_aranges (struct dwarf_section *section,
6181 void *file ATTRIBUTE_UNUSED)
6182{
6183 unsigned char *start = section->start;
6184 unsigned char *end = start + section->size;
6185
dda8d76d 6186 introduce (section, FALSE);
19e6b90e 6187
6e3d6dc1
NC
6188 /* It does not matter if this load fails,
6189 we test for that later on. */
6190 load_debug_info (file);
6191
19e6b90e
L
6192 while (start < end)
6193 {
6194 unsigned char *hdrptr;
6195 DWARF2_Internal_ARange arange;
91d6fa6a 6196 unsigned char *addr_ranges;
2d9472a2
NC
6197 dwarf_vma length;
6198 dwarf_vma address;
e98fdf1a 6199 unsigned long sec_off;
53b8873b 6200 unsigned char address_size;
19e6b90e 6201 int excess;
bf5117e3
NC
6202 unsigned int offset_size;
6203 unsigned int initial_length_size;
19e6b90e
L
6204
6205 hdrptr = start;
6206
0c588247 6207 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
19e6b90e
L
6208 if (arange.ar_length == 0xffffffff)
6209 {
0c588247 6210 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
19e6b90e
L
6211 offset_size = 8;
6212 initial_length_size = 12;
6213 }
6214 else
6215 {
6216 offset_size = 4;
6217 initial_length_size = 4;
6218 }
6219
e98fdf1a
AM
6220 sec_off = hdrptr - section->start;
6221 if (sec_off + arange.ar_length < sec_off
6222 || sec_off + arange.ar_length > section->size)
6223 {
6224 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
6225 section->name,
6226 sec_off - initial_length_size,
6227 dwarf_vmatoa ("x", arange.ar_length));
6228 break;
6229 }
6230
0c588247
NC
6231 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
6232 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
19e6b90e 6233
6e3d6dc1
NC
6234 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
6235 && num_debug_info_entries > 0
6236 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
6237 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
47704ddf 6238 (unsigned long) arange.ar_info_offset, section->name);
6e3d6dc1 6239
0c588247
NC
6240 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
6241 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
19e6b90e
L
6242
6243 if (arange.ar_version != 2 && arange.ar_version != 3)
6244 {
67f101ee
NC
6245 /* PR 19872: A version number of 0 probably means that there is
6246 padding at the end of the .debug_aranges section. Gold puts
6247 it there when performing an incremental link, for example.
6248 So do not generate a warning in this case. */
6249 if (arange.ar_version)
6250 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
19e6b90e
L
6251 break;
6252 }
6253
47704ddf
KT
6254 printf (_(" Length: %ld\n"),
6255 (long) arange.ar_length);
19e6b90e 6256 printf (_(" Version: %d\n"), arange.ar_version);
47704ddf
KT
6257 printf (_(" Offset into .debug_info: 0x%lx\n"),
6258 (unsigned long) arange.ar_info_offset);
19e6b90e
L
6259 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
6260 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
6261
53b8873b
NC
6262 address_size = arange.ar_pointer_size + arange.ar_segment_size;
6263
f41e4712
NC
6264 /* PR 17512: file: 001-108546-0.001:0.1. */
6265 if (address_size == 0 || address_size > 8)
b3681d67
L
6266 {
6267 error (_("Invalid address size in %s section!\n"),
6268 section->name);
6269 break;
6270 }
6271
53b8873b
NC
6272 /* The DWARF spec does not require that the address size be a power
6273 of two, but we do. This will have to change if we ever encounter
6274 an uneven architecture. */
6275 if ((address_size & (address_size - 1)) != 0)
6276 {
6277 warn (_("Pointer size + Segment size is not a power of two.\n"));
6278 break;
6279 }
cecf136e 6280
209c9a13
NC
6281 if (address_size > 4)
6282 printf (_("\n Address Length\n"));
6283 else
6284 printf (_("\n Address Length\n"));
19e6b90e 6285
91d6fa6a 6286 addr_ranges = hdrptr;
19e6b90e 6287
53b8873b
NC
6288 /* Must pad to an alignment boundary that is twice the address size. */
6289 excess = (hdrptr - start) % (2 * address_size);
19e6b90e 6290 if (excess)
91d6fa6a 6291 addr_ranges += (2 * address_size) - excess;
19e6b90e 6292
e98fdf1a 6293 start += arange.ar_length + initial_length_size;
1617e571 6294
91d6fa6a 6295 while (addr_ranges + 2 * address_size <= start)
19e6b90e 6296 {
0c588247
NC
6297 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
6298 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
19e6b90e 6299
80c35038 6300 printf (" ");
2d9472a2
NC
6301 print_dwarf_vma (address, address_size);
6302 print_dwarf_vma (length, address_size);
6303 putchar ('\n');
19e6b90e 6304 }
19e6b90e
L
6305 }
6306
6307 printf ("\n");
6308
6309 return 1;
6310}
6311
4723351a
CC
6312/* Comparison function for qsort. */
6313static int
6314comp_addr_base (const void * v0, const void * v1)
6315{
6316 debug_info * info0 = (debug_info *) v0;
6317 debug_info * info1 = (debug_info *) v1;
6318 return info0->addr_base - info1->addr_base;
6319}
6320
6321/* Display the debug_addr section. */
6322static int
6323display_debug_addr (struct dwarf_section *section,
b4eb7656 6324 void *file)
4723351a
CC
6325{
6326 debug_info **debug_addr_info;
6327 unsigned char *entry;
6328 unsigned char *end;
6329 unsigned int i;
6330 unsigned int count;
6331
6332 if (section->size == 0)
6333 {
6334 printf (_("\nThe %s section is empty.\n"), section->name);
6335 return 0;
6336 }
6337
6338 if (load_debug_info (file) == 0)
6339 {
6340 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6341 section->name);
6342 return 0;
6343 }
6344
dda8d76d 6345 introduce (section, FALSE);
4723351a 6346
1306a742
NC
6347 /* PR 17531: file: cf38d01b.
6348 We use xcalloc because a corrupt file may not have initialised all of the
6349 fields in the debug_info structure, which means that the sort below might
6350 try to move uninitialised data. */
6351 debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
b4eb7656 6352 sizeof (debug_info *));
4723351a
CC
6353
6354 count = 0;
6355 for (i = 0; i < num_debug_info_entries; i++)
82b1b41b 6356 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
1306a742
NC
6357 {
6358 /* PR 17531: file: cf38d01b. */
6359 if (debug_information[i].addr_base >= section->size)
6360 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
6361 (unsigned long) debug_information[i].addr_base, i);
6362 else
6363 debug_addr_info [count++] = debug_information + i;
6364 }
4723351a
CC
6365
6366 /* Add a sentinel to make iteration convenient. */
6367 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
6368 debug_addr_info [count]->addr_base = section->size;
4723351a 6369 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
1306a742 6370
4723351a
CC
6371 for (i = 0; i < count; i++)
6372 {
6373 unsigned int idx;
fab128ef 6374 unsigned int address_size = debug_addr_info [i]->pointer_size;
4723351a
CC
6375
6376 printf (_(" For compilation unit at offset 0x%s:\n"),
b4eb7656 6377 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
4723351a 6378
fab128ef 6379 printf (_("\tIndex\tAddress\n"));
4723351a
CC
6380 entry = section->start + debug_addr_info [i]->addr_base;
6381 end = section->start + debug_addr_info [i + 1]->addr_base;
6382 idx = 0;
6383 while (entry < end)
b4eb7656
AM
6384 {
6385 dwarf_vma base = byte_get (entry, address_size);
6386 printf (_("\t%d:\t"), idx);
6387 print_dwarf_vma (base, address_size);
6388 printf ("\n");
6389 entry += address_size;
6390 idx++;
6391 }
4723351a
CC
6392 }
6393 printf ("\n");
6394
6395 free (debug_addr_info);
6396 return 1;
6397}
6398
6399/* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
6400static int
6401display_debug_str_offsets (struct dwarf_section *section,
b4eb7656 6402 void *file ATTRIBUTE_UNUSED)
4723351a
CC
6403{
6404 if (section->size == 0)
6405 {
6406 printf (_("\nThe %s section is empty.\n"), section->name);
6407 return 0;
6408 }
6409 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
6410 what the offset size is for this section. */
6411 return 1;
6412}
6413
01a8f077
JK
6414/* Each debug_information[x].range_lists[y] gets this representation for
6415 sorting purposes. */
6416
6417struct range_entry
467c65bc
NC
6418{
6419 /* The debug_information[x].range_lists[y] value. */
359ca075 6420 dwarf_vma ranges_offset;
01a8f077 6421
467c65bc
NC
6422 /* Original debug_information to find parameters of the data. */
6423 debug_info *debug_info_p;
6424};
01a8f077
JK
6425
6426/* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
6427
6428static int
6429range_entry_compar (const void *ap, const void *bp)
6430{
3f5e193b
NC
6431 const struct range_entry *a_re = (const struct range_entry *) ap;
6432 const struct range_entry *b_re = (const struct range_entry *) bp;
359ca075
JK
6433 const dwarf_vma a = a_re->ranges_offset;
6434 const dwarf_vma b = b_re->ranges_offset;
01a8f077
JK
6435
6436 return (a > b) - (b > a);
6437}
6438
77145576
JK
6439static void
6440display_debug_ranges_list (unsigned char *start, unsigned char *finish,
6441 unsigned int pointer_size, unsigned long offset,
6442 unsigned long base_address)
6443{
6444 while (start < finish)
6445 {
6446 dwarf_vma begin;
6447 dwarf_vma end;
6448
6449 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6450 if (start >= finish)
6451 break;
6452 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
6453
6454 printf (" %8.8lx ", offset);
6455
6456 if (begin == 0 && end == 0)
6457 {
6458 printf (_("<End of list>\n"));
6459 break;
6460 }
6461
6462 /* Check base address specifiers. */
6463 if (is_max_address (begin, pointer_size)
6464 && !is_max_address (end, pointer_size))
6465 {
6466 base_address = end;
6467 print_dwarf_vma (begin, pointer_size);
6468 print_dwarf_vma (end, pointer_size);
6469 printf ("(base address)\n");
6470 continue;
6471 }
6472
6473 print_dwarf_vma (begin + base_address, pointer_size);
6474 print_dwarf_vma (end + base_address, pointer_size);
6475
6476 if (begin == end)
6477 fputs (_("(start == end)"), stdout);
6478 else if (begin > end)
6479 fputs (_("(start > end)"), stdout);
6480
6481 putchar ('\n');
6482 }
6483}
6484
6485static void
6486display_debug_rnglists_list (unsigned char *start, unsigned char *finish,
6487 unsigned int pointer_size, unsigned long offset,
6488 unsigned long base_address)
6489{
6490 unsigned char *next = start;
6491
6492 while (1)
6493 {
6494 unsigned long off = offset + (start - next);
6495 enum dwarf_range_list_entry rlet;
9dfd0db9
JK
6496 /* Initialize it due to a false compiler warning. */
6497 dwarf_vma begin = -1, length, end = -1;
77145576
JK
6498 unsigned int bytes_read;
6499
6500 if (start + 1 > finish)
6501 {
6502 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
6503 offset);
6504 break;
6505 }
6506
6507 printf (" %8.8lx ", off);
6508
6509 SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish);
6510
6511 switch (rlet)
6512 {
6513 case DW_RLE_end_of_list:
6514 printf (_("<End of list>\n"));
6515 break;
6516 case DW_RLE_base_address:
6517 SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish);
6518 print_dwarf_vma (base_address, pointer_size);
6519 printf (_("(base address)\n"));
6520 break;
6521 case DW_RLE_start_length:
6522 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6523 length = read_uleb128 (start, &bytes_read, finish);
6524 start += bytes_read;
6525 end = begin + length;
6526 break;
6527 case DW_RLE_offset_pair:
6528 begin = read_uleb128 (start, &bytes_read, finish);
6529 start += bytes_read;
6530 end = read_uleb128 (start, &bytes_read, finish);
6531 start += bytes_read;
6532 break;
6533 case DW_RLE_start_end:
6534 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
6535 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish);
6536 break;
6537 default:
6538 error (_("Invalid range list entry type %d\n"), rlet);
6539 rlet = DW_RLE_end_of_list;
6540 break;
6541 }
6542 if (rlet == DW_RLE_end_of_list)
6543 break;
6544 if (rlet == DW_RLE_base_address)
6545 continue;
6546
6547 print_dwarf_vma (begin + base_address, pointer_size);
6548 print_dwarf_vma (end + base_address, pointer_size);
6549
6550 if (begin == end)
6551 fputs (_("(start == end)"), stdout);
6552 else if (begin > end)
6553 fputs (_("(start > end)"), stdout);
6554
6555 putchar ('\n');
6556 }
6557}
6558
19e6b90e
L
6559static int
6560display_debug_ranges (struct dwarf_section *section,
6561 void *file ATTRIBUTE_UNUSED)
6562{
6563 unsigned char *start = section->start;
a2ff7a4b 6564 unsigned char *last_start = start;
f6f0e17b 6565 unsigned long bytes = section->size;
19e6b90e 6566 unsigned char *section_begin = start;
f6f0e17b 6567 unsigned char *finish = start + bytes;
01a8f077
JK
6568 unsigned int num_range_list, i;
6569 struct range_entry *range_entries, *range_entry_fill;
77145576
JK
6570 int is_rnglists = strstr (section->name, "debug_rnglists") != NULL;
6571 /* Initialize it due to a false compiler warning. */
6572 unsigned char address_size = 0;
19e6b90e 6573
19e6b90e
L
6574 if (bytes == 0)
6575 {
6576 printf (_("\nThe %s section is empty.\n"), section->name);
6577 return 0;
6578 }
6579
77145576
JK
6580 if (is_rnglists)
6581 {
6582 dwarf_vma initial_length;
6583 unsigned int initial_length_size;
6584 unsigned char segment_selector_size;
6585 unsigned int offset_size, offset_entry_count;
6586 unsigned short version;
6587
6588 /* Get and check the length of the block. */
6589 SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish);
6590
6591 if (initial_length == 0xffffffff)
6592 {
6593 /* This section is 64-bit DWARF 3. */
6594 SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish);
6595 offset_size = 8;
6596 initial_length_size = 12;
6597 }
6598 else
6599 {
6600 offset_size = 4;
6601 initial_length_size = 4;
6602 }
6603
6604 if (initial_length + initial_length_size > section->size)
6605 {
6606 /* If the length field has a relocation against it, then we should
6607 not complain if it is inaccurate (and probably negative).
6608 It is copied from .debug_line handling code. */
6609 if (reloc_at (section, (start - section->start) - offset_size))
6610 {
6611 initial_length = (finish - start) - initial_length_size;
6612 }
6613 else
6614 {
6615 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
6616 (long) initial_length);
6617 return 0;
6618 }
6619 }
6620
6621 /* Get and check the version number. */
6622 SAFE_BYTE_GET_AND_INC (version, start, 2, finish);
6623
6624 if (version != 5)
6625 {
6626 warn (_("Only DWARF version 5 debug_rnglists info "
6627 "is currently supported.\n"));
6628 return 0;
6629 }
6630
6631 SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish);
6632
6633 SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish);
6634 if (segment_selector_size != 0)
6635 {
6636 warn (_("The %s section contains "
6637 "unsupported segment selector size: %d.\n"),
6638 section->name, segment_selector_size);
6639 return 0;
6640 }
6641
6642 SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish);
6643 if (offset_entry_count != 0)
6644 {
6645 warn (_("The %s section contains "
6646 "unsupported offset entry count: %u.\n"),
6647 section->name, offset_entry_count);
6648 return 0;
6649 }
6650 }
6651
1febe64d
NC
6652 if (load_debug_info (file) == 0)
6653 {
6654 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6655 section->name);
6656 return 0;
6657 }
19e6b90e 6658
01a8f077 6659 num_range_list = 0;
19e6b90e 6660 for (i = 0; i < num_debug_info_entries; i++)
01a8f077 6661 num_range_list += debug_information [i].num_range_lists;
19e6b90e 6662
01a8f077 6663 if (num_range_list == 0)
4723351a
CC
6664 {
6665 /* This can happen when the file was compiled with -gsplit-debug
b4eb7656 6666 which removes references to range lists from the primary .o file. */
4723351a
CC
6667 printf (_("No range lists in .debug_info section.\n"));
6668 return 1;
6669 }
19e6b90e 6670
3f5e193b
NC
6671 range_entries = (struct range_entry *)
6672 xmalloc (sizeof (*range_entries) * num_range_list);
01a8f077 6673 range_entry_fill = range_entries;
19e6b90e 6674
01a8f077
JK
6675 for (i = 0; i < num_debug_info_entries; i++)
6676 {
6677 debug_info *debug_info_p = &debug_information[i];
6678 unsigned int j;
6679
6680 for (j = 0; j < debug_info_p->num_range_lists; j++)
6681 {
6682 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
6683 range_entry_fill->debug_info_p = debug_info_p;
6684 range_entry_fill++;
19e6b90e
L
6685 }
6686 }
6687
01a8f077
JK
6688 qsort (range_entries, num_range_list, sizeof (*range_entries),
6689 range_entry_compar);
19e6b90e 6690
d493b283 6691 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
19e6b90e 6692 warn (_("Range lists in %s section start at 0x%lx\n"),
359ca075 6693 section->name, (unsigned long) range_entries[0].ranges_offset);
19e6b90e 6694
dda8d76d
NC
6695 introduce (section, FALSE);
6696
19e6b90e
L
6697 printf (_(" Offset Begin End\n"));
6698
01a8f077 6699 for (i = 0; i < num_range_list; i++)
19e6b90e 6700 {
01a8f077
JK
6701 struct range_entry *range_entry = &range_entries[i];
6702 debug_info *debug_info_p = range_entry->debug_info_p;
19e6b90e 6703 unsigned int pointer_size;
359ca075 6704 dwarf_vma offset;
01a8f077 6705 unsigned char *next;
359ca075 6706 dwarf_vma base_address;
19e6b90e 6707
77145576 6708 pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size);
d493b283 6709 offset = range_entry->ranges_offset;
01a8f077
JK
6710 next = section_begin + offset;
6711 base_address = debug_info_p->base_address;
cecf136e 6712
f41e4712
NC
6713 /* PR 17512: file: 001-101485-0.001:0.1. */
6714 if (pointer_size < 2 || pointer_size > 8)
6715 {
6716 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
359ca075 6717 pointer_size, (unsigned long) offset);
f41e4712
NC
6718 continue;
6719 }
b4eb7656 6720
4723351a 6721 if (dwarf_check != 0 && i > 0)
19e6b90e 6722 {
01a8f077
JK
6723 if (start < next)
6724 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
6725 (unsigned long) (start - section_begin),
6726 (unsigned long) (next - section_begin), section->name);
6727 else if (start > next)
a2ff7a4b
AM
6728 {
6729 if (next == last_start)
6730 continue;
6731 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
6732 (unsigned long) (start - section_begin),
6733 (unsigned long) (next - section_begin), section->name);
6734 }
01a8f077
JK
6735 }
6736 start = next;
a2ff7a4b 6737 last_start = next;
19e6b90e 6738
77145576
JK
6739 (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list)
6740 (start, finish, pointer_size, offset, base_address);
19e6b90e
L
6741 }
6742 putchar ('\n');
01a8f077
JK
6743
6744 free (range_entries);
6745
19e6b90e
L
6746 return 1;
6747}
6748
6749typedef struct Frame_Chunk
6750{
6751 struct Frame_Chunk *next;
6752 unsigned char *chunk_start;
a1165289 6753 unsigned int ncols;
19e6b90e
L
6754 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6755 short int *col_type;
6756 int *col_offset;
6757 char *augmentation;
6758 unsigned int code_factor;
6759 int data_factor;
bf5117e3
NC
6760 dwarf_vma pc_begin;
6761 dwarf_vma pc_range;
32ef3000 6762 unsigned int cfa_reg;
c8071705 6763 dwarf_vma cfa_offset;
a1165289 6764 unsigned int ra;
19e6b90e
L
6765 unsigned char fde_encoding;
6766 unsigned char cfa_exp;
604282a7
JJ
6767 unsigned char ptr_size;
6768 unsigned char segment_size;
19e6b90e
L
6769}
6770Frame_Chunk;
6771
665ce1f6
L
6772static const char *const *dwarf_regnames;
6773static unsigned int dwarf_regnames_count;
6774
19e6b90e
L
6775/* A marker for a col_type that means this column was never referenced
6776 in the frame info. */
6777#define DW_CFA_unreferenced (-1)
6778
a1165289 6779/* Return 0 if no more space is needed, 1 if more space is needed,
665ce1f6
L
6780 -1 for invalid reg. */
6781
6782static int
6783frame_need_space (Frame_Chunk *fc, unsigned int reg)
19e6b90e 6784{
a1165289 6785 unsigned int prev = fc->ncols;
19e6b90e 6786
665ce1f6
L
6787 if (reg < (unsigned int) fc->ncols)
6788 return 0;
6789
6790 if (dwarf_regnames_count
6791 && reg > dwarf_regnames_count)
6792 return -1;
19e6b90e
L
6793
6794 fc->ncols = reg + 1;
a1165289
NC
6795 /* PR 17512: file: 10450-2643-0.004.
6796 If reg == -1 then this can happen... */
6797 if (fc->ncols == 0)
6798 return -1;
6799
06614111
NC
6800 /* PR 17512: file: 2844a11d. */
6801 if (fc->ncols > 1024)
6802 {
6803 error (_("Unfeasibly large register number: %u\n"), reg);
6804 fc->ncols = 0;
6805 /* FIXME: 1024 is an arbitrary limit. Increase it if
6806 we ever encounter a valid binary that exceeds it. */
6807 return -1;
6808 }
6809
3f5e193b 6810 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
b4eb7656 6811 sizeof (short int));
3f5e193b 6812 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
b4eb7656 6813 /* PR 17512: file:002-10025-0.005. */
041830e0
NC
6814 if (fc->col_type == NULL || fc->col_offset == NULL)
6815 {
6816 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
6817 fc->ncols);
6818 fc->ncols = 0;
6819 return -1;
6820 }
19e6b90e
L
6821
6822 while (prev < fc->ncols)
6823 {
6824 fc->col_type[prev] = DW_CFA_unreferenced;
6825 fc->col_offset[prev] = 0;
6826 prev++;
6827 }
665ce1f6 6828 return 1;
19e6b90e
L
6829}
6830
2dc4cec1
L
6831static const char *const dwarf_regnames_i386[] =
6832{
43234a1e
L
6833 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6834 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6835 "eip", "eflags", NULL, /* 8 - 10 */
6836 "st0", "st1", "st2", "st3", /* 11 - 14 */
6837 "st4", "st5", "st6", "st7", /* 15 - 18 */
6838 NULL, NULL, /* 19 - 20 */
6839 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
6840 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
6841 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
6842 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
6843 "fcw", "fsw", "mxcsr", /* 37 - 39 */
6844 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6845 "tr", "ldtr", /* 48 - 49 */
6846 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6847 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6848 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6849 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6850 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6851 NULL, NULL, NULL, /* 90 - 92 */
6852 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
2dc4cec1
L
6853};
6854
3d875af5
L
6855static const char *const dwarf_regnames_iamcu[] =
6856{
6857 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6858 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6859 "eip", "eflags", NULL, /* 8 - 10 */
6860 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */
6861 NULL, NULL, /* 19 - 20 */
6862 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */
6863 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */
6864 NULL, NULL, NULL, /* 37 - 39 */
6865 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
6866 "tr", "ldtr", /* 48 - 49 */
6867 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
6868 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
6869 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
6870 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
6871 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
6872 NULL, NULL, NULL, /* 90 - 92 */
6873 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */
6874};
6875
b129eb0e
RH
6876void
6877init_dwarf_regnames_i386 (void)
6878{
6879 dwarf_regnames = dwarf_regnames_i386;
6880 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
6881}
6882
3d875af5
L
6883void
6884init_dwarf_regnames_iamcu (void)
6885{
6886 dwarf_regnames = dwarf_regnames_iamcu;
6887 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu);
6888}
6889
2dc4cec1
L
6890static const char *const dwarf_regnames_x86_64[] =
6891{
6892 "rax", "rdx", "rcx", "rbx",
6893 "rsi", "rdi", "rbp", "rsp",
6894 "r8", "r9", "r10", "r11",
6895 "r12", "r13", "r14", "r15",
6896 "rip",
6897 "xmm0", "xmm1", "xmm2", "xmm3",
6898 "xmm4", "xmm5", "xmm6", "xmm7",
6899 "xmm8", "xmm9", "xmm10", "xmm11",
6900 "xmm12", "xmm13", "xmm14", "xmm15",
6901 "st0", "st1", "st2", "st3",
6902 "st4", "st5", "st6", "st7",
6903 "mm0", "mm1", "mm2", "mm3",
6904 "mm4", "mm5", "mm6", "mm7",
6905 "rflags",
6906 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
6907 "fs.base", "gs.base", NULL, NULL,
6908 "tr", "ldtr",
43234a1e
L
6909 "mxcsr", "fcw", "fsw",
6910 "xmm16", "xmm17", "xmm18", "xmm19",
6911 "xmm20", "xmm21", "xmm22", "xmm23",
6912 "xmm24", "xmm25", "xmm26", "xmm27",
6913 "xmm28", "xmm29", "xmm30", "xmm31",
6914 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
6915 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
6916 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
6917 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
6918 NULL, NULL, NULL, /* 115 - 117 */
6919 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
2dc4cec1
L
6920};
6921
b129eb0e
RH
6922void
6923init_dwarf_regnames_x86_64 (void)
6924{
6925 dwarf_regnames = dwarf_regnames_x86_64;
6926 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
6927}
6928
4ee22035
RH
6929static const char *const dwarf_regnames_aarch64[] =
6930{
b4eb7656
AM
6931 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
6932 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
4ee22035
RH
6933 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
6934 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
6935 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
6936 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6937 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6938 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
b4eb7656
AM
6939 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
6940 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
4ee22035
RH
6941 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
6942 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
6943};
6944
6945void
6946init_dwarf_regnames_aarch64 (void)
6947{
6948 dwarf_regnames = dwarf_regnames_aarch64;
6949 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
6950}
6951
d6bb17b0
AA
6952static const char *const dwarf_regnames_s390[] =
6953{
6954 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
6955 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6956 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
6957 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
6958 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
6959 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
6960 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
6961 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
6962 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
6963 "pswm", "pswa",
6964 NULL, NULL,
6965 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
6966 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
6967};
6968
6969void
6970init_dwarf_regnames_s390 (void)
6971{
6972 dwarf_regnames = dwarf_regnames_s390;
6973 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390);
6974}
6975
2dc4cec1
L
6976void
6977init_dwarf_regnames (unsigned int e_machine)
6978{
6979 switch (e_machine)
6980 {
6981 case EM_386:
b129eb0e 6982 init_dwarf_regnames_i386 ();
2dc4cec1
L
6983 break;
6984
3d875af5
L
6985 case EM_IAMCU:
6986 init_dwarf_regnames_iamcu ();
6987 break;
6988
2dc4cec1 6989 case EM_X86_64:
7f502d6c 6990 case EM_L1OM:
7a9068fe 6991 case EM_K1OM:
b129eb0e 6992 init_dwarf_regnames_x86_64 ();
2dc4cec1
L
6993 break;
6994
4ee22035
RH
6995 case EM_AARCH64:
6996 init_dwarf_regnames_aarch64 ();
6997 break;
6998
d6bb17b0
AA
6999 case EM_S390:
7000 init_dwarf_regnames_s390 ();
7001 break;
7002
2dc4cec1
L
7003 default:
7004 break;
7005 }
7006}
7007
7008static const char *
7009regname (unsigned int regno, int row)
7010{
7011 static char reg[64];
7f2c8a1d 7012
2dc4cec1
L
7013 if (dwarf_regnames
7014 && regno < dwarf_regnames_count
7015 && dwarf_regnames [regno] != NULL)
7016 {
7017 if (row)
7018 return dwarf_regnames [regno];
7019 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
7020 dwarf_regnames [regno]);
7021 }
7022 else
7023 snprintf (reg, sizeof (reg), "r%d", regno);
7024 return reg;
7025}
7026
19e6b90e 7027static void
a1165289 7028frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
19e6b90e 7029{
a1165289 7030 unsigned int r;
19e6b90e
L
7031 char tmp[100];
7032
d8024a91 7033 if (*max_regs != fc->ncols)
19e6b90e
L
7034 *max_regs = fc->ncols;
7035
7036 if (*need_col_headers)
7037 {
91d6fa6a 7038 static const char *sloc = " LOC";
2dc4cec1 7039
19e6b90e
L
7040 *need_col_headers = 0;
7041
91d6fa6a 7042 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
19e6b90e
L
7043
7044 for (r = 0; r < *max_regs; r++)
7045 if (fc->col_type[r] != DW_CFA_unreferenced)
7046 {
7047 if (r == fc->ra)
50751e18 7048 printf ("ra ");
19e6b90e 7049 else
2dc4cec1 7050 printf ("%-5s ", regname (r, 1));
19e6b90e
L
7051 }
7052
7053 printf ("\n");
7054 }
7055
bf5117e3 7056 print_dwarf_vma (fc->pc_begin, eh_addr_size);
19e6b90e
L
7057 if (fc->cfa_exp)
7058 strcpy (tmp, "exp");
7059 else
c8071705 7060 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset);
19e6b90e
L
7061 printf ("%-8s ", tmp);
7062
7063 for (r = 0; r < fc->ncols; r++)
7064 {
7065 if (fc->col_type[r] != DW_CFA_unreferenced)
7066 {
7067 switch (fc->col_type[r])
7068 {
7069 case DW_CFA_undefined:
7070 strcpy (tmp, "u");
7071 break;
7072 case DW_CFA_same_value:
7073 strcpy (tmp, "s");
7074 break;
7075 case DW_CFA_offset:
7076 sprintf (tmp, "c%+d", fc->col_offset[r]);
7077 break;
12eae2d3
JJ
7078 case DW_CFA_val_offset:
7079 sprintf (tmp, "v%+d", fc->col_offset[r]);
7080 break;
19e6b90e 7081 case DW_CFA_register:
2dc4cec1 7082 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
19e6b90e
L
7083 break;
7084 case DW_CFA_expression:
7085 strcpy (tmp, "exp");
7086 break;
12eae2d3
JJ
7087 case DW_CFA_val_expression:
7088 strcpy (tmp, "vexp");
7089 break;
19e6b90e
L
7090 default:
7091 strcpy (tmp, "n/a");
7092 break;
7093 }
2dc4cec1 7094 printf ("%-5s ", tmp);
19e6b90e
L
7095 }
7096 }
7097 printf ("\n");
7098}
7099
49727e46 7100#define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
19e6b90e 7101
49727e46
AM
7102static unsigned char *
7103read_cie (unsigned char *start, unsigned char *end,
7104 Frame_Chunk **p_cie, int *p_version,
bf59c5d5 7105 bfd_size_type *p_aug_len, unsigned char **p_aug)
49727e46
AM
7106{
7107 int version;
7108 Frame_Chunk *fc;
7109 unsigned int length_return;
7110 unsigned char *augmentation_data = NULL;
bf59c5d5 7111 bfd_size_type augmentation_data_len = 0;
49727e46 7112
041830e0 7113 * p_cie = NULL;
f41e4712
NC
7114 /* PR 17512: file: 001-228113-0.004. */
7115 if (start >= end)
7116 return end;
7117
49727e46
AM
7118 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
7119 memset (fc, 0, sizeof (Frame_Chunk));
7120
7121 fc->col_type = (short int *) xmalloc (sizeof (short int));
7122 fc->col_offset = (int *) xmalloc (sizeof (int));
7123
7124 version = *start++;
7125
7126 fc->augmentation = (char *) start;
f41e4712
NC
7127 /* PR 17512: file: 001-228113-0.004.
7128 Skip past augmentation name, but avoid running off the end of the data. */
7129 while (start < end)
7130 if (* start ++ == '\0')
7131 break;
7132 if (start == end)
7133 {
7134 warn (_("No terminator for augmentation name\n"));
7135 return start;
7136 }
49727e46
AM
7137
7138 if (strcmp (fc->augmentation, "eh") == 0)
7139 start += eh_addr_size;
7140
7141 if (version >= 4)
7142 {
7143 GET (fc->ptr_size, 1);
77ef8654
NC
7144 if (fc->ptr_size < 1 || fc->ptr_size > 8)
7145 {
7146 warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size);
7147 return end;
7148 }
7149
49727e46 7150 GET (fc->segment_size, 1);
77ef8654
NC
7151 /* PR 17512: file: e99d2804. */
7152 if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8)
7153 {
7154 warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size);
7155 return end;
7156 }
7157
49727e46
AM
7158 eh_addr_size = fc->ptr_size;
7159 }
7160 else
7161 {
7162 fc->ptr_size = eh_addr_size;
7163 fc->segment_size = 0;
7164 }
7f2c8a1d
NC
7165 READ_ULEB (fc->code_factor);
7166 READ_SLEB (fc->data_factor);
49727e46
AM
7167 if (version == 1)
7168 {
7169 GET (fc->ra, 1);
7170 }
7171 else
7172 {
7f2c8a1d 7173 READ_ULEB (fc->ra);
49727e46
AM
7174 }
7175
7176 if (fc->augmentation[0] == 'z')
7177 {
7f2c8a1d 7178 READ_ULEB (augmentation_data_len);
49727e46 7179 augmentation_data = start;
a1165289 7180 /* PR 17512: file: 11042-2589-0.004. */
bf59c5d5 7181 if (augmentation_data_len > (bfd_size_type) (end - start))
a1165289 7182 {
bf59c5d5
NC
7183 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
7184 dwarf_vmatoa ("x", augmentation_data_len),
7185 (unsigned long) (end - start));
a1165289
NC
7186 return end;
7187 }
9c0f3d3f 7188 start += augmentation_data_len;
49727e46
AM
7189 }
7190
7191 if (augmentation_data_len)
7192 {
058037d3
NC
7193 unsigned char *p;
7194 unsigned char *q;
7195 unsigned char *qend;
b4eb7656 7196
49727e46
AM
7197 p = (unsigned char *) fc->augmentation + 1;
7198 q = augmentation_data;
058037d3
NC
7199 qend = q + augmentation_data_len;
7200
9c0f3d3f 7201 while (p < end && q < qend)
49727e46
AM
7202 {
7203 if (*p == 'L')
7204 q++;
7205 else if (*p == 'P')
7206 q += 1 + size_of_encoded_value (*q);
7207 else if (*p == 'R')
7208 fc->fde_encoding = *q++;
7209 else if (*p == 'S')
7210 ;
7211 else
7212 break;
7213 p++;
7214 }
c361b9ac
NC
7215 /* Note - it is OK if this loop terminates with q < qend.
7216 Padding may have been inserted to align the end of the CIE. */
49727e46
AM
7217 }
7218
7219 *p_cie = fc;
7220 if (p_version)
7221 *p_version = version;
7222 if (p_aug_len)
7223 {
7224 *p_aug_len = augmentation_data_len;
7225 *p_aug = augmentation_data;
7226 }
7227 return start;
7228}
7229
bf59c5d5
NC
7230/* Prints out the contents on the augmentation data array.
7231 If do_wide is not enabled, then formats the output to fit into 80 columns. */
7232
7233static void
7234display_augmentation_data (const unsigned char * data, const bfd_size_type len)
7235{
7236 bfd_size_type i;
7237
7238 i = printf (_(" Augmentation data: "));
7239
7240 if (do_wide || len < ((80 - i) / 3))
7241 for (i = 0; i < len; ++i)
7242 printf (" %02x", data[i]);
7243 else
7244 {
7245 for (i = 0; i < len; ++i)
7246 {
7247 if (i % (80 / 3) == 0)
7248 putchar ('\n');
7249 printf (" %02x", data[i]);
7250 }
7251 }
7252 putchar ('\n');
7253}
7254
19e6b90e
L
7255static int
7256display_debug_frames (struct dwarf_section *section,
7257 void *file ATTRIBUTE_UNUSED)
7258{
7259 unsigned char *start = section->start;
7260 unsigned char *end = start + section->size;
7261 unsigned char *section_start = start;
49727e46 7262 Frame_Chunk *chunks = 0, *forward_refs = 0;
19e6b90e
L
7263 Frame_Chunk *remembered_state = 0;
7264 Frame_Chunk *rs;
7265 int is_eh = strcmp (section->name, ".eh_frame") == 0;
7266 unsigned int length_return;
a1165289 7267 unsigned int max_regs = 0;
665ce1f6 7268 const char *bad_reg = _("bad register: ");
77ef8654 7269 unsigned int saved_eh_addr_size = eh_addr_size;
19e6b90e 7270
dda8d76d 7271 introduce (section, FALSE);
19e6b90e
L
7272
7273 while (start < end)
7274 {
7275 unsigned char *saved_start;
7276 unsigned char *block_end;
bf5117e3
NC
7277 dwarf_vma length;
7278 dwarf_vma cie_id;
19e6b90e
L
7279 Frame_Chunk *fc;
7280 Frame_Chunk *cie;
7281 int need_col_headers = 1;
7282 unsigned char *augmentation_data = NULL;
bf59c5d5 7283 bfd_size_type augmentation_data_len = 0;
bf5117e3
NC
7284 unsigned int encoded_ptr_size = saved_eh_addr_size;
7285 unsigned int offset_size;
7286 unsigned int initial_length_size;
5b6312fd 7287 bfd_boolean all_nops;
19e6b90e
L
7288
7289 saved_start = start;
19e6b90e 7290
0c588247 7291 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
041830e0 7292
19e6b90e
L
7293 if (length == 0)
7294 {
7295 printf ("\n%08lx ZERO terminator\n\n",
7296 (unsigned long)(saved_start - section_start));
6937bb54
NC
7297 /* Skip any zero terminators that directly follow.
7298 A corrupt section size could have loaded a whole
7299 slew of zero filled memory bytes. eg
7300 PR 17512: file: 070-19381-0.004. */
7301 while (start < end && * start == 0)
7302 ++ start;
b758e50f 7303 continue;
19e6b90e
L
7304 }
7305
7306 if (length == 0xffffffff)
7307 {
0c588247 7308 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
19e6b90e
L
7309 offset_size = 8;
7310 initial_length_size = 12;
7311 }
7312 else
7313 {
7314 offset_size = 4;
7315 initial_length_size = 4;
7316 }
7317
7318 block_end = saved_start + length + initial_length_size;
041830e0 7319 if (block_end > end || block_end < start)
53b8873b 7320 {
bf5117e3
NC
7321 warn ("Invalid length 0x%s in FDE at %#08lx\n",
7322 dwarf_vmatoa_1 (NULL, length, offset_size),
7323 (unsigned long) (saved_start - section_start));
53b8873b
NC
7324 block_end = end;
7325 }
0c588247
NC
7326
7327 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
19e6b90e 7328
846a11e4
NC
7329 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
7330 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
19e6b90e
L
7331 {
7332 int version;
a1165289 7333 unsigned int mreg;
19e6b90e 7334
49727e46
AM
7335 start = read_cie (start, end, &cie, &version,
7336 &augmentation_data_len, &augmentation_data);
041830e0
NC
7337 /* PR 17512: file: 027-135133-0.005. */
7338 if (cie == NULL)
7339 break;
a1165289 7340
49727e46 7341 fc = cie;
19e6b90e
L
7342 fc->next = chunks;
7343 chunks = fc;
7344 fc->chunk_start = saved_start;
a1165289 7345 mreg = max_regs > 0 ? max_regs - 1 : 0;
49727e46
AM
7346 if (mreg < fc->ra)
7347 mreg = fc->ra;
06614111
NC
7348 if (frame_need_space (fc, mreg) < 0)
7349 break;
49727e46
AM
7350 if (fc->fde_encoding)
7351 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
19e6b90e 7352
bf5117e3
NC
7353 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
7354 print_dwarf_vma (length, fc->ptr_size);
9c41109d 7355 print_dwarf_vma (cie_id, offset_size);
bf5117e3 7356
19e6b90e 7357 if (do_debug_frames_interp)
bf5117e3
NC
7358 {
7359 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
7360 fc->code_factor, fc->data_factor, fc->ra);
7361 }
19e6b90e
L
7362 else
7363 {
bf5117e3 7364 printf ("CIE\n");
19e6b90e
L
7365 printf (" Version: %d\n", version);
7366 printf (" Augmentation: \"%s\"\n", fc->augmentation);
604282a7
JJ
7367 if (version >= 4)
7368 {
7369 printf (" Pointer Size: %u\n", fc->ptr_size);
7370 printf (" Segment Size: %u\n", fc->segment_size);
7371 }
19e6b90e
L
7372 printf (" Code alignment factor: %u\n", fc->code_factor);
7373 printf (" Data alignment factor: %d\n", fc->data_factor);
7374 printf (" Return address column: %d\n", fc->ra);
7375
7376 if (augmentation_data_len)
bf59c5d5 7377 display_augmentation_data (augmentation_data, augmentation_data_len);
a1165289 7378
19e6b90e
L
7379 putchar ('\n');
7380 }
19e6b90e
L
7381 }
7382 else
7383 {
7384 unsigned char *look_for;
7385 static Frame_Chunk fde_fc;
604282a7 7386 unsigned long segment_selector;
19e6b90e 7387
49727e46
AM
7388 if (is_eh)
7389 {
7390 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
7391 look_for = start - 4 - ((cie_id ^ sign) - sign);
7392 }
7393 else
7394 look_for = section_start + cie_id;
19e6b90e 7395
49727e46
AM
7396 if (look_for <= saved_start)
7397 {
7398 for (cie = chunks; cie ; cie = cie->next)
7399 if (cie->chunk_start == look_for)
7400 break;
7401 }
7402 else
7403 {
7404 for (cie = forward_refs; cie ; cie = cie->next)
7405 if (cie->chunk_start == look_for)
7406 break;
7407 if (!cie)
7408 {
7409 unsigned int off_size;
7410 unsigned char *cie_scan;
19e6b90e 7411
49727e46
AM
7412 cie_scan = look_for;
7413 off_size = 4;
7414 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
7415 if (length == 0xffffffff)
7416 {
7417 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
7418 off_size = 8;
7419 }
7420 if (length != 0)
7421 {
7422 dwarf_vma c_id;
7423
7424 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
7425 if (is_eh
7426 ? c_id == 0
7427 : ((off_size == 4 && c_id == DW_CIE_ID)
7428 || (off_size == 8 && c_id == DW64_CIE_ID)))
7429 {
7430 int version;
a1165289 7431 unsigned int mreg;
49727e46
AM
7432
7433 read_cie (cie_scan, end, &cie, &version,
7434 &augmentation_data_len, &augmentation_data);
a1165289
NC
7435 /* PR 17512: file: 3450-2098-0.004. */
7436 if (cie == NULL)
7437 {
7438 warn (_("Failed to read CIE information\n"));
7439 break;
7440 }
49727e46
AM
7441 cie->next = forward_refs;
7442 forward_refs = cie;
7443 cie->chunk_start = look_for;
a1165289 7444 mreg = max_regs > 0 ? max_regs - 1 : 0;
49727e46
AM
7445 if (mreg < cie->ra)
7446 mreg = cie->ra;
06614111
NC
7447 if (frame_need_space (cie, mreg) < 0)
7448 {
7449 warn (_("Invalid max register\n"));
7450 break;
7451 }
49727e46
AM
7452 if (cie->fde_encoding)
7453 encoded_ptr_size
7454 = size_of_encoded_value (cie->fde_encoding);
7455 }
7456 }
7457 }
7458 }
7459
7460 fc = &fde_fc;
7461 memset (fc, 0, sizeof (Frame_Chunk));
19e6b90e
L
7462
7463 if (!cie)
7464 {
bf5117e3
NC
7465 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
7466 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
7467 (unsigned long) (saved_start - section_start));
19e6b90e 7468 fc->ncols = 0;
3f5e193b
NC
7469 fc->col_type = (short int *) xmalloc (sizeof (short int));
7470 fc->col_offset = (int *) xmalloc (sizeof (int));
06614111
NC
7471 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
7472 {
7473 warn (_("Invalid max register\n"));
7474 break;
7475 }
19e6b90e
L
7476 cie = fc;
7477 fc->augmentation = "";
7478 fc->fde_encoding = 0;
604282a7
JJ
7479 fc->ptr_size = eh_addr_size;
7480 fc->segment_size = 0;
19e6b90e
L
7481 }
7482 else
7483 {
7484 fc->ncols = cie->ncols;
3f5e193b
NC
7485 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
7486 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
19e6b90e
L
7487 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
7488 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
7489 fc->augmentation = cie->augmentation;
604282a7
JJ
7490 fc->ptr_size = cie->ptr_size;
7491 eh_addr_size = cie->ptr_size;
7492 fc->segment_size = cie->segment_size;
19e6b90e
L
7493 fc->code_factor = cie->code_factor;
7494 fc->data_factor = cie->data_factor;
7495 fc->cfa_reg = cie->cfa_reg;
7496 fc->cfa_offset = cie->cfa_offset;
7497 fc->ra = cie->ra;
06614111
NC
7498 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
7499 {
7500 warn (_("Invalid max register\n"));
7501 break;
7502 }
19e6b90e
L
7503 fc->fde_encoding = cie->fde_encoding;
7504 }
7505
7506 if (fc->fde_encoding)
7507 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
7508
604282a7
JJ
7509 segment_selector = 0;
7510 if (fc->segment_size)
c8071705
NC
7511 {
7512 if (fc->segment_size > sizeof (segment_selector))
7513 {
7514 /* PR 17512: file: 9e196b3e. */
7515 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size);
7516 fc->segment_size = 4;
7517 }
7518 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
7519 }
041830e0
NC
7520
7521 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
19e6b90e 7522
0c588247
NC
7523 /* FIXME: It appears that sometimes the final pc_range value is
7524 encoded in less than encoded_ptr_size bytes. See the x86_64
7525 run of the "objcopy on compressed debug sections" test for an
7526 example of this. */
7527 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
bf5117e3 7528
19e6b90e
L
7529 if (cie->augmentation[0] == 'z')
7530 {
7f2c8a1d 7531 READ_ULEB (augmentation_data_len);
19e6b90e
L
7532 augmentation_data = start;
7533 start += augmentation_data_len;
bf59c5d5
NC
7534 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
7535 if (start >= end
7536 || ((bfd_signed_vma) augmentation_data_len) < 0
7537 || augmentation_data > start)
0a9d414a 7538 {
bf59c5d5
NC
7539 warn (_("Corrupt augmentation data length: 0x%s\n"),
7540 dwarf_vmatoa ("x", augmentation_data_len));
0a9d414a
NC
7541 start = end;
7542 augmentation_data = NULL;
7543 augmentation_data_len = 0;
7544 }
19e6b90e
L
7545 }
7546
bf5117e3
NC
7547 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
7548 (unsigned long)(saved_start - section_start),
7549 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
9c41109d 7550 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
604282a7 7551 (unsigned long)(cie->chunk_start - section_start));
bf5117e3 7552
604282a7
JJ
7553 if (fc->segment_size)
7554 printf ("%04lx:", segment_selector);
bf5117e3
NC
7555
7556 printf ("%s..%s\n",
7557 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
7558 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
7559
19e6b90e
L
7560 if (! do_debug_frames_interp && augmentation_data_len)
7561 {
bf59c5d5 7562 display_augmentation_data (augmentation_data, augmentation_data_len);
19e6b90e
L
7563 putchar ('\n');
7564 }
7565 }
7566
7567 /* At this point, fc is the current chunk, cie (if any) is set, and
7568 we're about to interpret instructions for the chunk. */
7569 /* ??? At present we need to do this always, since this sizes the
7570 fc->col_type and fc->col_offset arrays, which we write into always.
7571 We should probably split the interpreted and non-interpreted bits
7572 into two different routines, since there's so much that doesn't
7573 really overlap between them. */
7574 if (1 || do_debug_frames_interp)
7575 {
7576 /* Start by making a pass over the chunk, allocating storage
7577 and taking note of what registers are used. */
7578 unsigned char *tmp = start;
7579
7580 while (start < block_end)
7581 {
041830e0
NC
7582 unsigned int reg, op, opa;
7583 unsigned long temp;
5929c344 7584 unsigned char * new_start;
19e6b90e
L
7585
7586 op = *start++;
7587 opa = op & 0x3f;
7588 if (op & 0xc0)
7589 op &= 0xc0;
7590
7591 /* Warning: if you add any more cases to this switch, be
7592 sure to add them to the corresponding switch below. */
7593 switch (op)
7594 {
7595 case DW_CFA_advance_loc:
7596 break;
7597 case DW_CFA_offset:
7f2c8a1d 7598 SKIP_ULEB ();
665ce1f6
L
7599 if (frame_need_space (fc, opa) >= 0)
7600 fc->col_type[opa] = DW_CFA_undefined;
19e6b90e
L
7601 break;
7602 case DW_CFA_restore:
665ce1f6
L
7603 if (frame_need_space (fc, opa) >= 0)
7604 fc->col_type[opa] = DW_CFA_undefined;
19e6b90e
L
7605 break;
7606 case DW_CFA_set_loc:
7607 start += encoded_ptr_size;
7608 break;
7609 case DW_CFA_advance_loc1:
7610 start += 1;
7611 break;
7612 case DW_CFA_advance_loc2:
7613 start += 2;
7614 break;
7615 case DW_CFA_advance_loc4:
7616 start += 4;
7617 break;
7618 case DW_CFA_offset_extended:
12eae2d3 7619 case DW_CFA_val_offset:
7f2c8a1d
NC
7620 READ_ULEB (reg);
7621 SKIP_ULEB ();
665ce1f6
L
7622 if (frame_need_space (fc, reg) >= 0)
7623 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
7624 break;
7625 case DW_CFA_restore_extended:
7f2c8a1d 7626 READ_ULEB (reg);
665ce1f6
L
7627 if (frame_need_space (fc, reg) >= 0)
7628 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
7629 break;
7630 case DW_CFA_undefined:
7f2c8a1d 7631 READ_ULEB (reg);
665ce1f6
L
7632 if (frame_need_space (fc, reg) >= 0)
7633 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
7634 break;
7635 case DW_CFA_same_value:
7f2c8a1d 7636 READ_ULEB (reg);
665ce1f6
L
7637 if (frame_need_space (fc, reg) >= 0)
7638 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
7639 break;
7640 case DW_CFA_register:
7f2c8a1d
NC
7641 READ_ULEB (reg);
7642 SKIP_ULEB ();
665ce1f6
L
7643 if (frame_need_space (fc, reg) >= 0)
7644 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
7645 break;
7646 case DW_CFA_def_cfa:
7f2c8a1d
NC
7647 SKIP_ULEB ();
7648 SKIP_ULEB ();
19e6b90e
L
7649 break;
7650 case DW_CFA_def_cfa_register:
7f2c8a1d 7651 SKIP_ULEB ();
19e6b90e
L
7652 break;
7653 case DW_CFA_def_cfa_offset:
7f2c8a1d 7654 SKIP_ULEB ();
19e6b90e
L
7655 break;
7656 case DW_CFA_def_cfa_expression:
7f2c8a1d 7657 READ_ULEB (temp);
5929c344
NC
7658 new_start = start + temp;
7659 if (new_start < start)
041830e0
NC
7660 {
7661 warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
7662 start = block_end;
7663 }
7664 else
5929c344 7665 start = new_start;
19e6b90e
L
7666 break;
7667 case DW_CFA_expression:
12eae2d3 7668 case DW_CFA_val_expression:
7f2c8a1d
NC
7669 READ_ULEB (reg);
7670 READ_ULEB (temp);
5929c344
NC
7671 new_start = start + temp;
7672 if (new_start < start)
041830e0 7673 {
b4eb7656 7674 /* PR 17512: file:306-192417-0.005. */
041830e0
NC
7675 warn (_("Corrupt CFA expression value: %lu\n"), temp);
7676 start = block_end;
7677 }
7678 else
5929c344 7679 start = new_start;
665ce1f6
L
7680 if (frame_need_space (fc, reg) >= 0)
7681 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
7682 break;
7683 case DW_CFA_offset_extended_sf:
12eae2d3 7684 case DW_CFA_val_offset_sf:
7f2c8a1d
NC
7685 READ_ULEB (reg);
7686 SKIP_SLEB ();
665ce1f6
L
7687 if (frame_need_space (fc, reg) >= 0)
7688 fc->col_type[reg] = DW_CFA_undefined;
19e6b90e
L
7689 break;
7690 case DW_CFA_def_cfa_sf:
7f2c8a1d
NC
7691 SKIP_ULEB ();
7692 SKIP_SLEB ();
19e6b90e
L
7693 break;
7694 case DW_CFA_def_cfa_offset_sf:
7f2c8a1d 7695 SKIP_SLEB ();
19e6b90e
L
7696 break;
7697 case DW_CFA_MIPS_advance_loc8:
7698 start += 8;
7699 break;
7700 case DW_CFA_GNU_args_size:
7f2c8a1d 7701 SKIP_ULEB ();
19e6b90e
L
7702 break;
7703 case DW_CFA_GNU_negative_offset_extended:
7f2c8a1d
NC
7704 READ_ULEB (reg);
7705 SKIP_ULEB ();
665ce1f6
L
7706 if (frame_need_space (fc, reg) >= 0)
7707 fc->col_type[reg] = DW_CFA_undefined;
7708 break;
19e6b90e
L
7709 default:
7710 break;
7711 }
7712 }
7713 start = tmp;
7714 }
7715
5b6312fd
NC
7716 all_nops = TRUE;
7717
19e6b90e
L
7718 /* Now we know what registers are used, make a second pass over
7719 the chunk, this time actually printing out the info. */
7720
7721 while (start < block_end)
7722 {
362beea4 7723 unsigned char * tmp;
19e6b90e 7724 unsigned op, opa;
7f2c8a1d
NC
7725 unsigned long ul, roffs;
7726 /* Note: It is tempting to use an unsigned long for 'reg' but there
7727 are various functions, notably frame_space_needed() that assume that
7728 reg is an unsigned int. */
7729 unsigned int reg;
7730 dwarf_signed_vma l;
bf5117e3 7731 dwarf_vma ofs;
19e6b90e 7732 dwarf_vma vma;
665ce1f6 7733 const char *reg_prefix = "";
19e6b90e
L
7734
7735 op = *start++;
7736 opa = op & 0x3f;
7737 if (op & 0xc0)
7738 op &= 0xc0;
7739
5b6312fd
NC
7740 /* Make a note if something other than DW_CFA_nop happens. */
7741 if (op != DW_CFA_nop)
7742 all_nops = FALSE;
7743
19e6b90e
L
7744 /* Warning: if you add any more cases to this switch, be
7745 sure to add them to the corresponding switch above. */
7746 switch (op)
7747 {
7748 case DW_CFA_advance_loc:
7749 if (do_debug_frames_interp)
7750 frame_display_row (fc, &need_col_headers, &max_regs);
7751 else
bf5117e3 7752 printf (" DW_CFA_advance_loc: %d to %s\n",
19e6b90e 7753 opa * fc->code_factor,
b4eb7656 7754 dwarf_vmatoa_1 (NULL,
bf5117e3
NC
7755 fc->pc_begin + opa * fc->code_factor,
7756 fc->ptr_size));
19e6b90e
L
7757 fc->pc_begin += opa * fc->code_factor;
7758 break;
7759
7760 case DW_CFA_offset:
7f2c8a1d 7761 READ_ULEB (roffs);
665ce1f6
L
7762 if (opa >= (unsigned int) fc->ncols)
7763 reg_prefix = bad_reg;
7764 if (! do_debug_frames_interp || *reg_prefix != '\0')
7765 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
7766 reg_prefix, regname (opa, 0),
7767 roffs * fc->data_factor);
7768 if (*reg_prefix == '\0')
7769 {
7770 fc->col_type[opa] = DW_CFA_offset;
7771 fc->col_offset[opa] = roffs * fc->data_factor;
7772 }
19e6b90e
L
7773 break;
7774
7775 case DW_CFA_restore:
50751e18 7776 if (opa >= (unsigned int) fc->ncols)
665ce1f6
L
7777 reg_prefix = bad_reg;
7778 if (! do_debug_frames_interp || *reg_prefix != '\0')
7779 printf (" DW_CFA_restore: %s%s\n",
7780 reg_prefix, regname (opa, 0));
50751e18
AK
7781 if (*reg_prefix != '\0')
7782 break;
7783
7784 if (opa >= (unsigned int) cie->ncols
7785 || (do_debug_frames_interp
7786 && cie->col_type[opa] == DW_CFA_unreferenced))
7787 {
7788 fc->col_type[opa] = DW_CFA_undefined;
7789 fc->col_offset[opa] = 0;
7790 }
7791 else
665ce1f6
L
7792 {
7793 fc->col_type[opa] = cie->col_type[opa];
7794 fc->col_offset[opa] = cie->col_offset[opa];
7795 }
19e6b90e
L
7796 break;
7797
7798 case DW_CFA_set_loc:
6937bb54 7799 vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
19e6b90e
L
7800 if (do_debug_frames_interp)
7801 frame_display_row (fc, &need_col_headers, &max_regs);
7802 else
bf5117e3
NC
7803 printf (" DW_CFA_set_loc: %s\n",
7804 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
19e6b90e
L
7805 fc->pc_begin = vma;
7806 break;
7807
7808 case DW_CFA_advance_loc1:
0c588247 7809 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
19e6b90e
L
7810 if (do_debug_frames_interp)
7811 frame_display_row (fc, &need_col_headers, &max_regs);
7812 else
bf5117e3
NC
7813 printf (" DW_CFA_advance_loc1: %ld to %s\n",
7814 (unsigned long) (ofs * fc->code_factor),
7815 dwarf_vmatoa_1 (NULL,
7816 fc->pc_begin + ofs * fc->code_factor,
7817 fc->ptr_size));
19e6b90e
L
7818 fc->pc_begin += ofs * fc->code_factor;
7819 break;
7820
7821 case DW_CFA_advance_loc2:
6937bb54 7822 SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
19e6b90e
L
7823 if (do_debug_frames_interp)
7824 frame_display_row (fc, &need_col_headers, &max_regs);
7825 else
bf5117e3
NC
7826 printf (" DW_CFA_advance_loc2: %ld to %s\n",
7827 (unsigned long) (ofs * fc->code_factor),
7828 dwarf_vmatoa_1 (NULL,
7829 fc->pc_begin + ofs * fc->code_factor,
7830 fc->ptr_size));
19e6b90e
L
7831 fc->pc_begin += ofs * fc->code_factor;
7832 break;
7833
7834 case DW_CFA_advance_loc4:
6937bb54 7835 SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
19e6b90e
L
7836 if (do_debug_frames_interp)
7837 frame_display_row (fc, &need_col_headers, &max_regs);
7838 else
bf5117e3
NC
7839 printf (" DW_CFA_advance_loc4: %ld to %s\n",
7840 (unsigned long) (ofs * fc->code_factor),
7841 dwarf_vmatoa_1 (NULL,
7842 fc->pc_begin + ofs * fc->code_factor,
7843 fc->ptr_size));
19e6b90e
L
7844 fc->pc_begin += ofs * fc->code_factor;
7845 break;
7846
7847 case DW_CFA_offset_extended:
7f2c8a1d
NC
7848 READ_ULEB (reg);
7849 READ_ULEB (roffs);
665ce1f6
L
7850 if (reg >= (unsigned int) fc->ncols)
7851 reg_prefix = bad_reg;
7852 if (! do_debug_frames_interp || *reg_prefix != '\0')
7853 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
7854 reg_prefix, regname (reg, 0),
7855 roffs * fc->data_factor);
7856 if (*reg_prefix == '\0')
7857 {
7858 fc->col_type[reg] = DW_CFA_offset;
7859 fc->col_offset[reg] = roffs * fc->data_factor;
7860 }
19e6b90e
L
7861 break;
7862
12eae2d3 7863 case DW_CFA_val_offset:
7f2c8a1d
NC
7864 READ_ULEB (reg);
7865 READ_ULEB (roffs);
665ce1f6
L
7866 if (reg >= (unsigned int) fc->ncols)
7867 reg_prefix = bad_reg;
7868 if (! do_debug_frames_interp || *reg_prefix != '\0')
084303b8 7869 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
665ce1f6
L
7870 reg_prefix, regname (reg, 0),
7871 roffs * fc->data_factor);
7872 if (*reg_prefix == '\0')
7873 {
7874 fc->col_type[reg] = DW_CFA_val_offset;
7875 fc->col_offset[reg] = roffs * fc->data_factor;
7876 }
12eae2d3
JJ
7877 break;
7878
19e6b90e 7879 case DW_CFA_restore_extended:
7f2c8a1d 7880 READ_ULEB (reg);
50751e18 7881 if (reg >= (unsigned int) fc->ncols)
665ce1f6
L
7882 reg_prefix = bad_reg;
7883 if (! do_debug_frames_interp || *reg_prefix != '\0')
7884 printf (" DW_CFA_restore_extended: %s%s\n",
7885 reg_prefix, regname (reg, 0));
50751e18
AK
7886 if (*reg_prefix != '\0')
7887 break;
7888
7889 if (reg >= (unsigned int) cie->ncols)
7890 {
7891 fc->col_type[reg] = DW_CFA_undefined;
7892 fc->col_offset[reg] = 0;
7893 }
7894 else
665ce1f6
L
7895 {
7896 fc->col_type[reg] = cie->col_type[reg];
7897 fc->col_offset[reg] = cie->col_offset[reg];
7898 }
19e6b90e
L
7899 break;
7900
7901 case DW_CFA_undefined:
7f2c8a1d 7902 READ_ULEB (reg);
665ce1f6
L
7903 if (reg >= (unsigned int) fc->ncols)
7904 reg_prefix = bad_reg;
7905 if (! do_debug_frames_interp || *reg_prefix != '\0')
7906 printf (" DW_CFA_undefined: %s%s\n",
7907 reg_prefix, regname (reg, 0));
7908 if (*reg_prefix == '\0')
7909 {
7910 fc->col_type[reg] = DW_CFA_undefined;
7911 fc->col_offset[reg] = 0;
7912 }
19e6b90e
L
7913 break;
7914
7915 case DW_CFA_same_value:
7f2c8a1d 7916 READ_ULEB (reg);
665ce1f6
L
7917 if (reg >= (unsigned int) fc->ncols)
7918 reg_prefix = bad_reg;
7919 if (! do_debug_frames_interp || *reg_prefix != '\0')
7920 printf (" DW_CFA_same_value: %s%s\n",
7921 reg_prefix, regname (reg, 0));
7922 if (*reg_prefix == '\0')
7923 {
7924 fc->col_type[reg] = DW_CFA_same_value;
7925 fc->col_offset[reg] = 0;
7926 }
19e6b90e
L
7927 break;
7928
7929 case DW_CFA_register:
7f2c8a1d
NC
7930 READ_ULEB (reg);
7931 READ_ULEB (roffs);
665ce1f6
L
7932 if (reg >= (unsigned int) fc->ncols)
7933 reg_prefix = bad_reg;
7934 if (! do_debug_frames_interp || *reg_prefix != '\0')
2dc4cec1 7935 {
665ce1f6
L
7936 printf (" DW_CFA_register: %s%s in ",
7937 reg_prefix, regname (reg, 0));
2dc4cec1
L
7938 puts (regname (roffs, 0));
7939 }
665ce1f6
L
7940 if (*reg_prefix == '\0')
7941 {
7942 fc->col_type[reg] = DW_CFA_register;
7943 fc->col_offset[reg] = roffs;
7944 }
19e6b90e
L
7945 break;
7946
7947 case DW_CFA_remember_state:
7948 if (! do_debug_frames_interp)
7949 printf (" DW_CFA_remember_state\n");
3f5e193b 7950 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
b4eb7656 7951 rs->cfa_offset = fc->cfa_offset;
d71ad7fc
RC
7952 rs->cfa_reg = fc->cfa_reg;
7953 rs->ra = fc->ra;
7954 rs->cfa_exp = fc->cfa_exp;
19e6b90e 7955 rs->ncols = fc->ncols;
3f5e193b 7956 rs->col_type = (short int *) xcmalloc (rs->ncols,
b4eb7656 7957 sizeof (* rs->col_type));
d71ad7fc
RC
7958 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
7959 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
7960 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
19e6b90e
L
7961 rs->next = remembered_state;
7962 remembered_state = rs;
7963 break;
7964
7965 case DW_CFA_restore_state:
7966 if (! do_debug_frames_interp)
7967 printf (" DW_CFA_restore_state\n");
7968 rs = remembered_state;
7969 if (rs)
7970 {
7971 remembered_state = rs->next;
d71ad7fc
RC
7972 fc->cfa_offset = rs->cfa_offset;
7973 fc->cfa_reg = rs->cfa_reg;
b4eb7656
AM
7974 fc->ra = rs->ra;
7975 fc->cfa_exp = rs->cfa_exp;
06614111
NC
7976 if (frame_need_space (fc, rs->ncols - 1) < 0)
7977 {
1306a742 7978 warn (_("Invalid column number in saved frame state\n"));
06614111
NC
7979 fc->ncols = 0;
7980 break;
7981 }
d71ad7fc 7982 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
19e6b90e 7983 memcpy (fc->col_offset, rs->col_offset,
d71ad7fc 7984 rs->ncols * sizeof (* rs->col_offset));
19e6b90e
L
7985 free (rs->col_type);
7986 free (rs->col_offset);
7987 free (rs);
7988 }
7989 else if (do_debug_frames_interp)
7990 printf ("Mismatched DW_CFA_restore_state\n");
7991 break;
7992
7993 case DW_CFA_def_cfa:
32ef3000 7994 READ_ULEB (fc->cfa_reg);
7f2c8a1d 7995 READ_ULEB (fc->cfa_offset);
19e6b90e
L
7996 fc->cfa_exp = 0;
7997 if (! do_debug_frames_interp)
2dc4cec1 7998 printf (" DW_CFA_def_cfa: %s ofs %d\n",
c8071705 7999 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
19e6b90e
L
8000 break;
8001
8002 case DW_CFA_def_cfa_register:
32ef3000 8003 READ_ULEB (fc->cfa_reg);
19e6b90e
L
8004 fc->cfa_exp = 0;
8005 if (! do_debug_frames_interp)
2dc4cec1
L
8006 printf (" DW_CFA_def_cfa_register: %s\n",
8007 regname (fc->cfa_reg, 0));
19e6b90e
L
8008 break;
8009
8010 case DW_CFA_def_cfa_offset:
7f2c8a1d 8011 READ_ULEB (fc->cfa_offset);
19e6b90e 8012 if (! do_debug_frames_interp)
c8071705 8013 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset);
19e6b90e
L
8014 break;
8015
8016 case DW_CFA_nop:
8017 if (! do_debug_frames_interp)
8018 printf (" DW_CFA_nop\n");
8019 break;
8020
8021 case DW_CFA_def_cfa_expression:
7f2c8a1d 8022 READ_ULEB (ul);
7460c0ab 8023 if (start >= block_end || ul > (unsigned long) (block_end - start))
6937bb54 8024 {
a1165289 8025 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
6937bb54
NC
8026 break;
8027 }
19e6b90e
L
8028 if (! do_debug_frames_interp)
8029 {
8030 printf (" DW_CFA_def_cfa_expression (");
b7807392
JJ
8031 decode_location_expression (start, eh_addr_size, 0, -1,
8032 ul, 0, section);
19e6b90e
L
8033 printf (")\n");
8034 }
8035 fc->cfa_exp = 1;
8036 start += ul;
8037 break;
8038
8039 case DW_CFA_expression:
7f2c8a1d
NC
8040 READ_ULEB (reg);
8041 READ_ULEB (ul);
665ce1f6
L
8042 if (reg >= (unsigned int) fc->ncols)
8043 reg_prefix = bad_reg;
6937bb54 8044 /* PR 17512: file: 069-133014-0.006. */
06614111 8045 /* PR 17512: file: 98c02eb4. */
362beea4
NC
8046 tmp = start + ul;
8047 if (start >= block_end || tmp > block_end || tmp < start)
6937bb54 8048 {
a1165289 8049 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
6937bb54
NC
8050 break;
8051 }
665ce1f6 8052 if (! do_debug_frames_interp || *reg_prefix != '\0')
19e6b90e 8053 {
665ce1f6
L
8054 printf (" DW_CFA_expression: %s%s (",
8055 reg_prefix, regname (reg, 0));
b7807392 8056 decode_location_expression (start, eh_addr_size, 0, -1,
f1c4cc75 8057 ul, 0, section);
19e6b90e
L
8058 printf (")\n");
8059 }
665ce1f6
L
8060 if (*reg_prefix == '\0')
8061 fc->col_type[reg] = DW_CFA_expression;
362beea4 8062 start = tmp;
19e6b90e
L
8063 break;
8064
12eae2d3 8065 case DW_CFA_val_expression:
7f2c8a1d
NC
8066 READ_ULEB (reg);
8067 READ_ULEB (ul);
665ce1f6
L
8068 if (reg >= (unsigned int) fc->ncols)
8069 reg_prefix = bad_reg;
362beea4
NC
8070 tmp = start + ul;
8071 if (start >= block_end || tmp > block_end || tmp < start)
6937bb54 8072 {
a1165289 8073 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
6937bb54
NC
8074 break;
8075 }
665ce1f6 8076 if (! do_debug_frames_interp || *reg_prefix != '\0')
12eae2d3 8077 {
665ce1f6
L
8078 printf (" DW_CFA_val_expression: %s%s (",
8079 reg_prefix, regname (reg, 0));
b7807392
JJ
8080 decode_location_expression (start, eh_addr_size, 0, -1,
8081 ul, 0, section);
12eae2d3
JJ
8082 printf (")\n");
8083 }
665ce1f6
L
8084 if (*reg_prefix == '\0')
8085 fc->col_type[reg] = DW_CFA_val_expression;
362beea4 8086 start = tmp;
12eae2d3
JJ
8087 break;
8088
19e6b90e 8089 case DW_CFA_offset_extended_sf:
7f2c8a1d
NC
8090 READ_ULEB (reg);
8091 READ_SLEB (l);
665ce1f6
L
8092 if (frame_need_space (fc, reg) < 0)
8093 reg_prefix = bad_reg;
8094 if (! do_debug_frames_interp || *reg_prefix != '\0')
8095 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
8096 reg_prefix, regname (reg, 0),
c8071705 8097 (long)(l * fc->data_factor));
665ce1f6
L
8098 if (*reg_prefix == '\0')
8099 {
8100 fc->col_type[reg] = DW_CFA_offset;
8101 fc->col_offset[reg] = l * fc->data_factor;
8102 }
19e6b90e
L
8103 break;
8104
12eae2d3 8105 case DW_CFA_val_offset_sf:
7f2c8a1d
NC
8106 READ_ULEB (reg);
8107 READ_SLEB (l);
665ce1f6
L
8108 if (frame_need_space (fc, reg) < 0)
8109 reg_prefix = bad_reg;
8110 if (! do_debug_frames_interp || *reg_prefix != '\0')
084303b8 8111 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
665ce1f6 8112 reg_prefix, regname (reg, 0),
c8071705 8113 (long)(l * fc->data_factor));
665ce1f6
L
8114 if (*reg_prefix == '\0')
8115 {
8116 fc->col_type[reg] = DW_CFA_val_offset;
8117 fc->col_offset[reg] = l * fc->data_factor;
8118 }
12eae2d3
JJ
8119 break;
8120
19e6b90e 8121 case DW_CFA_def_cfa_sf:
32ef3000 8122 READ_ULEB (fc->cfa_reg);
7f2c8a1d 8123 READ_ULEB (fc->cfa_offset);
19e6b90e
L
8124 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
8125 fc->cfa_exp = 0;
8126 if (! do_debug_frames_interp)
2dc4cec1 8127 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
c8071705 8128 regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
19e6b90e
L
8129 break;
8130
8131 case DW_CFA_def_cfa_offset_sf:
7f2c8a1d 8132 READ_ULEB (fc->cfa_offset);
c8071705 8133 fc->cfa_offset *= fc->data_factor;
19e6b90e 8134 if (! do_debug_frames_interp)
c8071705 8135 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset);
19e6b90e
L
8136 break;
8137
8138 case DW_CFA_MIPS_advance_loc8:
6937bb54 8139 SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
19e6b90e
L
8140 if (do_debug_frames_interp)
8141 frame_display_row (fc, &need_col_headers, &max_regs);
8142 else
bf5117e3
NC
8143 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
8144 (unsigned long) (ofs * fc->code_factor),
8145 dwarf_vmatoa_1 (NULL,
8146 fc->pc_begin + ofs * fc->code_factor,
8147 fc->ptr_size));
19e6b90e
L
8148 fc->pc_begin += ofs * fc->code_factor;
8149 break;
8150
8151 case DW_CFA_GNU_window_save:
8152 if (! do_debug_frames_interp)
8153 printf (" DW_CFA_GNU_window_save\n");
8154 break;
8155
8156 case DW_CFA_GNU_args_size:
7f2c8a1d 8157 READ_ULEB (ul);
19e6b90e
L
8158 if (! do_debug_frames_interp)
8159 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
8160 break;
8161
8162 case DW_CFA_GNU_negative_offset_extended:
7f2c8a1d
NC
8163 READ_ULEB (reg);
8164 READ_SLEB (l);
8165 l = - l;
665ce1f6
L
8166 if (frame_need_space (fc, reg) < 0)
8167 reg_prefix = bad_reg;
8168 if (! do_debug_frames_interp || *reg_prefix != '\0')
8169 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
8170 reg_prefix, regname (reg, 0),
c8071705 8171 (long)(l * fc->data_factor));
665ce1f6
L
8172 if (*reg_prefix == '\0')
8173 {
8174 fc->col_type[reg] = DW_CFA_offset;
8175 fc->col_offset[reg] = l * fc->data_factor;
8176 }
19e6b90e
L
8177 break;
8178
8179 default:
53b8873b
NC
8180 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
8181 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
8182 else
f41e4712 8183 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
19e6b90e
L
8184 start = block_end;
8185 }
8186 }
8187
5b6312fd
NC
8188 /* Interpret the CFA - as long as it is not completely full of NOPs. */
8189 if (do_debug_frames_interp && ! all_nops)
19e6b90e
L
8190 frame_display_row (fc, &need_col_headers, &max_regs);
8191
8192 start = block_end;
604282a7 8193 eh_addr_size = saved_eh_addr_size;
19e6b90e
L
8194 }
8195
8196 printf ("\n");
8197
8198 return 1;
8199}
8200
8201#undef GET
19e6b90e 8202
61364358
JK
8203static int
8204display_debug_names (struct dwarf_section *section, void *file)
8205{
8206 unsigned char *hdrptr = section->start;
8207 dwarf_vma unit_length;
8208 unsigned char *unit_start;
8209 const unsigned char *const section_end = section->start + section->size;
8210 unsigned char *unit_end;
8211
dda8d76d 8212 introduce (section, FALSE);
61364358 8213
dda8d76d 8214 load_debug_section_with_follow (str, file);
61364358
JK
8215
8216 for (; hdrptr < section_end; hdrptr = unit_end)
8217 {
8218 unsigned int offset_size;
8219 uint16_t dwarf_version, padding;
8220 uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count;
8221 uint32_t bucket_count, name_count, abbrev_table_size;
8222 uint32_t augmentation_string_size;
8223 unsigned int i;
e98fdf1a 8224 unsigned long sec_off;
61364358
JK
8225
8226 unit_start = hdrptr;
8227
8228 /* Get and check the length of the block. */
8229 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end);
8230
8231 if (unit_length == 0xffffffff)
8232 {
8233 /* This section is 64-bit DWARF. */
8234 SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end);
8235 offset_size = 8;
8236 }
8237 else
8238 offset_size = 4;
8239 unit_end = hdrptr + unit_length;
8240
e98fdf1a
AM
8241 sec_off = hdrptr - section->start;
8242 if (sec_off + unit_length < sec_off
8243 || sec_off + unit_length > section->size)
61364358 8244 {
e98fdf1a
AM
8245 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
8246 section->name,
8247 (unsigned long) (unit_start - section->start),
8248 dwarf_vmatoa ("x", unit_length));
61364358
JK
8249 return 0;
8250 }
8251
8252 /* Get and check the version number. */
8253 SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end);
8254 printf (_("Version %ld\n"), (long) dwarf_version);
8255
8256 /* Prior versions did not exist, and future versions may not be
8257 backwards compatible. */
8258 if (dwarf_version != 5)
8259 {
8260 warn (_("Only DWARF version 5 .debug_names "
8261 "is currently supported.\n"));
8262 return 0;
8263 }
8264
8265 SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end);
8266 if (padding != 0)
8267 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
8268 padding);
8269
8270 SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end);
8271 if (comp_unit_count == 0)
8272 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
8273
8274 SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end);
8275 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end);
8276 SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end);
8277 SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end);
8278 SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end);
8279
8280 SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end);
8281 if (augmentation_string_size % 4 != 0)
8282 {
8283 warn (_("Augmentation string length %u must be rounded up "
8284 "to a multiple of 4 in .debug_names.\n"),
8285 augmentation_string_size);
8286 augmentation_string_size += (-augmentation_string_size) & 3;
8287 }
8288 printf (_("Augmentation string:"));
8289 for (i = 0; i < augmentation_string_size; i++)
8290 {
8291 unsigned char uc;
8292
8293 SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end);
8294 printf (" %02x", uc);
8295 }
8296 putchar ('\n');
8297 putchar ('\n');
8298
8299 printf (_("CU table:\n"));
8300 for (i = 0; i < comp_unit_count; i++)
8301 {
8302 uint64_t cu_offset;
8303
8304 SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end);
8305 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset);
8306 }
8307 putchar ('\n');
8308
8309 printf (_("TU table:\n"));
8310 for (i = 0; i < local_type_unit_count; i++)
8311 {
8312 uint64_t tu_offset;
8313
8314 SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end);
8315 printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset);
8316 }
8317 putchar ('\n');
8318
8319 printf (_("Foreign TU table:\n"));
8320 for (i = 0; i < foreign_type_unit_count; i++)
8321 {
8322 uint64_t signature;
8323
8324 SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end);
8325 printf (_("[%3u] "), i);
8326 print_dwarf_vma (signature, 8);
8327 putchar ('\n');
8328 }
8329 putchar ('\n');
8330
8331 const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr;
8332 hdrptr += bucket_count * sizeof (uint32_t);
8333 const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr;
8334 hdrptr += name_count * sizeof (uint32_t);
8335 unsigned char *const name_table_string_offsets = hdrptr;
8336 hdrptr += name_count * offset_size;
8337 unsigned char *const name_table_entry_offsets = hdrptr;
8338 hdrptr += name_count * offset_size;
8339 unsigned char *const abbrev_table = hdrptr;
8340 hdrptr += abbrev_table_size;
8341 const unsigned char *const abbrev_table_end = hdrptr;
8342 unsigned char *const entry_pool = hdrptr;
8343 if (hdrptr > unit_end)
8344 {
8345 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
8346 "for unit 0x%lx in the debug_names\n"),
8347 (long) (hdrptr - section->start),
8348 (long) (unit_end - section->start),
8349 (long) (unit_start - section->start));
8350 return 0;
8351 }
8352
8353 size_t buckets_filled = 0;
8354 size_t bucketi;
8355 for (bucketi = 0; bucketi < bucket_count; bucketi++)
8356 {
8357 const uint32_t bucket = hash_table_buckets[bucketi];
8358
8359 if (bucket != 0)
8360 ++buckets_filled;
8361 }
d3a49aa8
AM
8362 printf (ngettext ("Used %zu of %lu bucket.\n",
8363 "Used %zu of %lu buckets.\n",
8364 bucket_count),
8365 buckets_filled, (unsigned long) bucket_count);
61364358 8366
0a79bef4 8367 uint32_t hash_prev = 0;
61364358
JK
8368 size_t hash_clash_count = 0;
8369 size_t longest_clash = 0;
8370 size_t this_length = 0;
8371 size_t hashi;
8372 for (hashi = 0; hashi < name_count; hashi++)
8373 {
8374 const uint32_t hash_this = hash_table_hashes[hashi];
8375
8376 if (hashi > 0)
8377 {
8378 if (hash_prev % bucket_count == hash_this % bucket_count)
8379 {
8380 ++hash_clash_count;
8381 ++this_length;
8382 longest_clash = MAX (longest_clash, this_length);
8383 }
8384 else
8385 this_length = 0;
8386 }
8387 hash_prev = hash_this;
8388 }
8389 printf (_("Out of %lu items there are %zu bucket clashes"
8390 " (longest of %zu entries).\n"),
8391 (unsigned long) name_count, hash_clash_count, longest_clash);
8392 assert (name_count == buckets_filled + hash_clash_count);
8393
8394 struct abbrev_lookup_entry
8395 {
8396 dwarf_vma abbrev_tag;
8397 unsigned char *abbrev_lookup_ptr;
8398 };
8399 struct abbrev_lookup_entry *abbrev_lookup = NULL;
8400 size_t abbrev_lookup_used = 0;
8401 size_t abbrev_lookup_allocated = 0;
8402
8403 unsigned char *abbrevptr = abbrev_table;
8404 for (;;)
8405 {
8406 unsigned int bytes_read;
8407 const dwarf_vma abbrev_tag = read_uleb128 (abbrevptr, &bytes_read,
8408 abbrev_table_end);
8409 abbrevptr += bytes_read;
8410 if (abbrev_tag == 0)
8411 break;
8412 if (abbrev_lookup_used == abbrev_lookup_allocated)
8413 {
8414 abbrev_lookup_allocated = MAX (0x100,
8415 abbrev_lookup_allocated * 2);
8416 abbrev_lookup = xrealloc (abbrev_lookup,
8417 (abbrev_lookup_allocated
8418 * sizeof (*abbrev_lookup)));
8419 }
8420 assert (abbrev_lookup_used < abbrev_lookup_allocated);
8421 struct abbrev_lookup_entry *entry;
8422 for (entry = abbrev_lookup;
8423 entry < abbrev_lookup + abbrev_lookup_used;
8424 entry++)
8425 if (entry->abbrev_tag == abbrev_tag)
8426 {
8427 warn (_("Duplicate abbreviation tag %lu "
8428 "in unit 0x%lx in the debug_names\n"),
8429 (long) abbrev_tag, (long) (unit_start - section->start));
8430 break;
8431 }
8432 entry = &abbrev_lookup[abbrev_lookup_used++];
8433 entry->abbrev_tag = abbrev_tag;
8434 entry->abbrev_lookup_ptr = abbrevptr;
8435
8436 /* Skip DWARF tag. */
8437 read_uleb128 (abbrevptr, &bytes_read, abbrev_table_end);
8438 abbrevptr += bytes_read;
8439 for (;;)
8440 {
1d827a72
L
8441 const dwarf_vma xindex = read_uleb128 (abbrevptr,
8442 &bytes_read,
8443 abbrev_table_end);
61364358
JK
8444 abbrevptr += bytes_read;
8445 const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read,
8446 abbrev_table_end);
8447 abbrevptr += bytes_read;
1d827a72 8448 if (xindex == 0 && form == 0)
61364358
JK
8449 break;
8450 }
8451 }
8452
8453 printf (_("\nSymbol table:\n"));
8454 uint32_t namei;
8455 for (namei = 0; namei < name_count; ++namei)
8456 {
8457 uint64_t string_offset, entry_offset;
8458
8459 SAFE_BYTE_GET (string_offset,
8460 name_table_string_offsets + namei * offset_size,
8461 offset_size, unit_end);
8462 SAFE_BYTE_GET (entry_offset,
8463 name_table_entry_offsets + namei * offset_size,
8464 offset_size, unit_end);
8465
8466 printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei],
8467 fetch_indirect_string (string_offset));
8468
8469 unsigned char *entryptr = entry_pool + entry_offset;
8470
8471 // We need to scan first whether there is a single or multiple
8472 // entries. TAGNO is -2 for the first entry, it is -1 for the
8473 // initial tag read of the second entry, then it becomes 0 for the
8474 // first entry for real printing etc.
8475 int tagno = -2;
8476 /* Initialize it due to a false compiler warning. */
8477 dwarf_vma second_abbrev_tag = -1;
8478 for (;;)
8479 {
8480 unsigned int bytes_read;
8481 const dwarf_vma abbrev_tag = read_uleb128 (entryptr, &bytes_read,
8482 unit_end);
8483 entryptr += bytes_read;
8484 if (tagno == -1)
8485 {
8486 second_abbrev_tag = abbrev_tag;
8487 tagno = 0;
8488 entryptr = entry_pool + entry_offset;
8489 continue;
8490 }
8491 if (abbrev_tag == 0)
8492 break;
8493 if (tagno >= 0)
8494 printf ("%s<%lu>",
8495 (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"),
8496 (unsigned long) abbrev_tag);
8497
8498 const struct abbrev_lookup_entry *entry;
8499 for (entry = abbrev_lookup;
8500 entry < abbrev_lookup + abbrev_lookup_used;
8501 entry++)
8502 if (entry->abbrev_tag == abbrev_tag)
8503 break;
8504 if (entry >= abbrev_lookup + abbrev_lookup_used)
8505 {
8506 warn (_("Undefined abbreviation tag %lu "
8507 "in unit 0x%lx in the debug_names\n"),
8508 (long) abbrev_tag,
8509 (long) (unit_start - section->start));
8510 break;
8511 }
8512 abbrevptr = entry->abbrev_lookup_ptr;
8513 const dwarf_vma dwarf_tag = read_uleb128 (abbrevptr, &bytes_read,
8514 abbrev_table_end);
8515 abbrevptr += bytes_read;
8516 if (tagno >= 0)
8517 printf (" %s", get_TAG_name (dwarf_tag));
8518 for (;;)
8519 {
1d827a72
L
8520 const dwarf_vma xindex = read_uleb128 (abbrevptr,
8521 &bytes_read,
8522 abbrev_table_end);
61364358
JK
8523 abbrevptr += bytes_read;
8524 const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read,
8525 abbrev_table_end);
8526 abbrevptr += bytes_read;
1d827a72 8527 if (xindex == 0 && form == 0)
61364358
JK
8528 break;
8529
8530 if (tagno >= 0)
1d827a72 8531 printf (" %s", get_IDX_name (xindex));
61364358
JK
8532 entryptr = read_and_display_attr_value (0, form, 0, entryptr,
8533 unit_end, 0, 0,
8534 offset_size,
8535 dwarf_version, NULL,
8536 (tagno < 0), NULL,
8537 NULL, '=');
8538 }
8539 ++tagno;
8540 }
8541 if (tagno <= 0)
8542 printf (_(" <no entries>"));
8543 putchar ('\n');
8544 }
8545
8546 free (abbrev_lookup);
8547 }
8548
8549 return 1;
8550}
8551
dda8d76d
NC
8552static int
8553display_debug_links (struct dwarf_section * section,
8554 void * file ATTRIBUTE_UNUSED)
8555{
8556 const unsigned char * filename;
8557 unsigned int filelen;
8558
8559 introduce (section, FALSE);
8560
8561 /* The .gnu_debuglink section is formatted as:
8562 (c-string) Filename.
8563 (padding) If needed to reach a 4 byte boundary.
8564 (uint32_t) CRC32 value.
8565
8566 The .gun_debugaltlink section is formatted as:
8567 (c-string) Filename.
8568 (binary) Build-ID. */
8569
8570 filename = section->start;
8571 filelen = strnlen ((const char *) filename, section->size);
8572 if (filelen == section->size)
8573 {
8574 warn (_("The debuglink filename is corrupt/missing\n"));
8575 return 0;
8576 }
8577
8578 printf (_(" Separate debug info file: %s\n"), filename);
8579
8580 if (const_strneq (section->name, ".gnu_debuglink"))
8581 {
8582 unsigned int crc32;
8583 unsigned int crc_offset;
8584
8585 crc_offset = filelen + 1;
8586 crc_offset = (crc_offset + 3) & ~3;
8587 if (crc_offset + 4 > section->size)
8588 {
8589 warn (_("CRC offset missing/truncated\n"));
8590 return 0;
8591 }
8592
8593 crc32 = byte_get (filename + crc_offset, 4);
8594
8595 printf (_(" CRC value: %#x\n"), crc32);
8596
8597 if (crc_offset + 4 < section->size)
8598 {
8599 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
8600 (long)(section->size - (crc_offset + 4)));
8601 return 0;
8602 }
8603 }
8604 else /* const_strneq (section->name, ".gnu_debugaltlink") */
8605 {
8606 const unsigned char * build_id = section->start + filelen + 1;
8607 bfd_size_type build_id_len = section->size - (filelen + 1);
8608 bfd_size_type printed;
8609
8610 /* FIXME: Should we support smaller build-id notes ? */
8611 if (build_id_len < 0x14)
8612 {
8613 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len);
8614 return 0;
8615 }
8616
8617 printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len);
8618
8619 if (do_wide || build_id_len < ((80 - printed) / 3))
8620 for (printed = 0; printed < build_id_len; ++printed)
8621 printf (" %02x", build_id[printed]);
8622 else
8623 {
8624 for (printed = 0; printed < build_id_len; ++printed)
8625 {
8626 if (printed % (80 / 3) == 0)
8627 putchar ('\n');
8628 printf (" %02x", build_id[printed]);
8629 }
8630 }
8631 putchar ('\n');
8632 }
8633
8634 putchar ('\n');
8635 return 1;
8636}
8637
5bbdf3d5
DE
8638static int
8639display_gdb_index (struct dwarf_section *section,
8640 void *file ATTRIBUTE_UNUSED)
8641{
8642 unsigned char *start = section->start;
8643 uint32_t version;
8644 uint32_t cu_list_offset, tu_list_offset;
8645 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
8646 unsigned int cu_list_elements, tu_list_elements;
8647 unsigned int address_table_size, symbol_table_slots;
8648 unsigned char *cu_list, *tu_list;
8649 unsigned char *address_table, *symbol_table, *constant_pool;
8650 unsigned int i;
8651
8652 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
8653
dda8d76d 8654 introduce (section, FALSE);
5bbdf3d5
DE
8655
8656 if (section->size < 6 * sizeof (uint32_t))
8657 {
8658 warn (_("Truncated header in the %s section.\n"), section->name);
8659 return 0;
8660 }
8661
8662 version = byte_get_little_endian (start, 4);
da88a764 8663 printf (_("Version %ld\n"), (long) version);
5bbdf3d5
DE
8664
8665 /* Prior versions are obsolete, and future versions may not be
8666 backwards compatible. */
aa170720 8667 if (version < 3 || version > 8)
5bbdf3d5 8668 {
da88a764 8669 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
5bbdf3d5
DE
8670 return 0;
8671 }
8d6eee87
TT
8672 if (version < 4)
8673 warn (_("The address table data in version 3 may be wrong.\n"));
8674 if (version < 5)
8675 warn (_("Version 4 does not support case insensitive lookups.\n"));
8676 if (version < 6)
8677 warn (_("Version 5 does not include inlined functions.\n"));
8678 if (version < 7)
8679 warn (_("Version 6 does not include symbol attributes.\n"));
aa170720
DE
8680 /* Version 7 indices generated by Gold have bad type unit references,
8681 PR binutils/15021. But we don't know if the index was generated by
8682 Gold or not, so to avoid worrying users with gdb-generated indices
8683 we say nothing for version 7 here. */
5bbdf3d5
DE
8684
8685 cu_list_offset = byte_get_little_endian (start + 4, 4);
8686 tu_list_offset = byte_get_little_endian (start + 8, 4);
8687 address_table_offset = byte_get_little_endian (start + 12, 4);
8688 symbol_table_offset = byte_get_little_endian (start + 16, 4);
8689 constant_pool_offset = byte_get_little_endian (start + 20, 4);
8690
8691 if (cu_list_offset > section->size
8692 || tu_list_offset > section->size
8693 || address_table_offset > section->size
8694 || symbol_table_offset > section->size
8695 || constant_pool_offset > section->size)
8696 {
8697 warn (_("Corrupt header in the %s section.\n"), section->name);
8698 return 0;
8699 }
8700
53774b7e
NC
8701 /* PR 17531: file: 418d0a8a. */
8702 if (tu_list_offset < cu_list_offset)
8703 {
8704 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
8705 tu_list_offset, cu_list_offset);
8706 return 0;
8707 }
8708
5bbdf3d5 8709 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
53774b7e
NC
8710
8711 if (address_table_offset < tu_list_offset)
8712 {
8713 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
8714 address_table_offset, tu_list_offset);
8715 return 0;
8716 }
8717
5bbdf3d5 8718 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
53774b7e
NC
8719
8720 /* PR 17531: file: 18a47d3d. */
8721 if (symbol_table_offset < address_table_offset)
8722 {
13bace4a 8723 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
53774b7e
NC
8724 symbol_table_offset, address_table_offset);
8725 return 0;
8726 }
8727
5bbdf3d5 8728 address_table_size = symbol_table_offset - address_table_offset;
53774b7e
NC
8729
8730 if (constant_pool_offset < symbol_table_offset)
8731 {
8732 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
8733 constant_pool_offset, symbol_table_offset);
8734 return 0;
8735 }
8736
5bbdf3d5
DE
8737 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
8738
8739 cu_list = start + cu_list_offset;
8740 tu_list = start + tu_list_offset;
8741 address_table = start + address_table_offset;
8742 symbol_table = start + symbol_table_offset;
8743 constant_pool = start + constant_pool_offset;
8744
28d909e5 8745 if (address_table + address_table_size > section->start + section->size)
acff9664 8746 {
1306a742 8747 warn (_("Address table extends beyond end of section.\n"));
acff9664
NC
8748 return 0;
8749 }
b4eb7656 8750
5bbdf3d5
DE
8751 printf (_("\nCU table:\n"));
8752 for (i = 0; i < cu_list_elements; i += 2)
8753 {
8754 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
8755 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
8756
8757 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
8758 (unsigned long) cu_offset,
8759 (unsigned long) (cu_offset + cu_length - 1));
8760 }
8761
8762 printf (_("\nTU table:\n"));
8763 for (i = 0; i < tu_list_elements; i += 3)
8764 {
8765 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
8766 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
8767 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
8768
8769 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
8770 (unsigned long) tu_offset,
8771 (unsigned long) type_offset);
8772 print_dwarf_vma (signature, 8);
8773 printf ("\n");
8774 }
8775
8776 printf (_("\nAddress table:\n"));
acff9664
NC
8777 for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
8778 i += 2 * 8 + 4)
5bbdf3d5
DE
8779 {
8780 uint64_t low = byte_get_little_endian (address_table + i, 8);
8781 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
8782 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
8783
8784 print_dwarf_vma (low, 8);
8785 print_dwarf_vma (high, 8);
da88a764 8786 printf (_("%lu\n"), (unsigned long) cu_index);
5bbdf3d5
DE
8787 }
8788
8789 printf (_("\nSymbol table:\n"));
8790 for (i = 0; i < symbol_table_slots; ++i)
8791 {
8792 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
8793 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
8794 uint32_t num_cus, cu;
8795
8796 if (name_offset != 0
8797 || cu_vector_offset != 0)
8798 {
8799 unsigned int j;
362beea4 8800 unsigned char * adr;
5bbdf3d5 8801
362beea4 8802 adr = constant_pool + name_offset;
53774b7e 8803 /* PR 17531: file: 5b7b07ad. */
362beea4 8804 if (adr < constant_pool || adr >= section->start + section->size)
53774b7e
NC
8805 {
8806 printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
8807 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
8808 name_offset, i);
8809 }
8810 else
acff9664
NC
8811 printf ("[%3u] %.*s:", i,
8812 (int) (section->size - (constant_pool_offset + name_offset)),
8813 constant_pool + name_offset);
53774b7e 8814
362beea4
NC
8815 adr = constant_pool + cu_vector_offset;
8816 if (adr < constant_pool || adr >= section->start + section->size - 3)
53774b7e
NC
8817 {
8818 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
8819 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
8820 cu_vector_offset, i);
8821 continue;
8822 }
57028622 8823
362beea4 8824 num_cus = byte_get_little_endian (adr, 4);
53774b7e 8825
362beea4 8826 adr = constant_pool + cu_vector_offset + 4 + num_cus * 4;
acff9664 8827 if (num_cus * 4 < num_cus
362beea4
NC
8828 || adr >= section->start + section->size
8829 || adr < constant_pool)
53774b7e
NC
8830 {
8831 printf ("<invalid number of CUs: %d>\n", num_cus);
acff9664 8832 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
53774b7e
NC
8833 num_cus, i);
8834 continue;
8835 }
8836
8d6eee87
TT
8837 if (num_cus > 1)
8838 printf ("\n");
f3853b34 8839
5bbdf3d5
DE
8840 for (j = 0; j < num_cus; ++j)
8841 {
7c1cef97 8842 int is_static;
8d6eee87
TT
8843 gdb_index_symbol_kind kind;
8844
5bbdf3d5 8845 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
7c1cef97 8846 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
8d6eee87
TT
8847 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
8848 cu = GDB_INDEX_CU_VALUE (cu);
5bbdf3d5 8849 /* Convert to TU number if it's for a type unit. */
ad6b52dd 8850 if (cu >= cu_list_elements / 2)
8d6eee87
TT
8851 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
8852 (unsigned long) (cu - cu_list_elements / 2));
5bbdf3d5 8853 else
8d6eee87
TT
8854 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
8855
459d52c8
DE
8856 printf (" [%s, %s]",
8857 is_static ? _("static") : _("global"),
8858 get_gdb_index_symbol_kind_name (kind));
8d6eee87
TT
8859 if (num_cus > 1)
8860 printf ("\n");
5bbdf3d5 8861 }
8d6eee87
TT
8862 if (num_cus <= 1)
8863 printf ("\n");
5bbdf3d5
DE
8864 }
8865 }
8866
8867 return 1;
8868}
8869
657d0d47
CC
8870/* Pre-allocate enough space for the CU/TU sets needed. */
8871
8872static void
8873prealloc_cu_tu_list (unsigned int nshndx)
8874{
8875 if (shndx_pool == NULL)
8876 {
8877 shndx_pool_size = nshndx;
8878 shndx_pool_used = 0;
8879 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
8880 sizeof (unsigned int));
8881 }
8882 else
8883 {
8884 shndx_pool_size = shndx_pool_used + nshndx;
8885 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
8886 sizeof (unsigned int));
8887 }
8888}
8889
8890static void
8891add_shndx_to_cu_tu_entry (unsigned int shndx)
8892{
8893 if (shndx_pool_used >= shndx_pool_size)
8894 {
8895 error (_("Internal error: out of space in the shndx pool.\n"));
8896 return;
8897 }
8898 shndx_pool [shndx_pool_used++] = shndx;
8899}
8900
8901static void
8902end_cu_tu_entry (void)
8903{
8904 if (shndx_pool_used >= shndx_pool_size)
8905 {
8906 error (_("Internal error: out of space in the shndx pool.\n"));
8907 return;
8908 }
8909 shndx_pool [shndx_pool_used++] = 0;
8910}
8911
341f9135
CC
8912/* Return the short name of a DWARF section given by a DW_SECT enumerator. */
8913
8914static const char *
8915get_DW_SECT_short_name (unsigned int dw_sect)
8916{
8917 static char buf[16];
8918
8919 switch (dw_sect)
8920 {
8921 case DW_SECT_INFO:
8922 return "info";
8923 case DW_SECT_TYPES:
8924 return "types";
8925 case DW_SECT_ABBREV:
8926 return "abbrev";
8927 case DW_SECT_LINE:
8928 return "line";
8929 case DW_SECT_LOC:
8930 return "loc";
8931 case DW_SECT_STR_OFFSETS:
8932 return "str_off";
8933 case DW_SECT_MACINFO:
8934 return "macinfo";
8935 case DW_SECT_MACRO:
8936 return "macro";
8937 default:
b4eb7656 8938 break;
341f9135
CC
8939 }
8940
8941 snprintf (buf, sizeof (buf), "%d", dw_sect);
8942 return buf;
8943}
8944
8945/* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
8946 These sections are extensions for Fission.
8947 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
657d0d47
CC
8948
8949static int
8950process_cu_tu_index (struct dwarf_section *section, int do_display)
8951{
8952 unsigned char *phdr = section->start;
8953 unsigned char *limit = phdr + section->size;
8954 unsigned char *phash;
8955 unsigned char *pindex;
8956 unsigned char *ppool;
8957 unsigned int version;
341f9135 8958 unsigned int ncols = 0;
657d0d47
CC
8959 unsigned int nused;
8960 unsigned int nslots;
8961 unsigned int i;
341f9135
CC
8962 unsigned int j;
8963 dwarf_vma signature_high;
8964 dwarf_vma signature_low;
8965 char buf[64];
657d0d47 8966
6937bb54
NC
8967 /* PR 17512: file: 002-168123-0.004. */
8968 if (phdr == NULL)
8969 {
8970 warn (_("Section %s is empty\n"), section->name);
8971 return 0;
8972 }
8973 /* PR 17512: file: 002-376-0.004. */
8974 if (section->size < 24)
8975 {
72c61a0d 8976 warn (_("Section %s is too small to contain a CU/TU header\n"),
6937bb54
NC
8977 section->name);
8978 return 0;
8979 }
8980
8981 SAFE_BYTE_GET (version, phdr, 4, limit);
341f9135 8982 if (version >= 2)
6937bb54
NC
8983 SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
8984 SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
8985 SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
8986
657d0d47
CC
8987 phash = phdr + 16;
8988 pindex = phash + nslots * 8;
8989 ppool = pindex + nslots * 4;
8990
57028622 8991 /* PR 17531: file: 45d69832. */
03a91817 8992 if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0))
57028622 8993 {
d3a49aa8
AM
8994 warn (ngettext ("Section %s is too small for %d slot\n",
8995 "Section %s is too small for %d slots\n",
8996 nslots),
57028622
NC
8997 section->name, nslots);
8998 return 0;
8999 }
9000
657d0d47
CC
9001 if (do_display)
9002 {
dda8d76d
NC
9003 introduce (section, FALSE);
9004
657d0d47 9005 printf (_(" Version: %d\n"), version);
341f9135
CC
9006 if (version >= 2)
9007 printf (_(" Number of columns: %d\n"), ncols);
657d0d47
CC
9008 printf (_(" Number of used entries: %d\n"), nused);
9009 printf (_(" Number of slots: %d\n\n"), nslots);
9010 }
9011
03a91817 9012 if (ppool > limit || ppool < phdr)
657d0d47
CC
9013 {
9014 warn (_("Section %s too small for %d hash table entries\n"),
9015 section->name, nslots);
9016 return 0;
9017 }
9018
341f9135 9019 if (version == 1)
657d0d47 9020 {
341f9135
CC
9021 if (!do_display)
9022 prealloc_cu_tu_list ((limit - ppool) / 4);
9023 for (i = 0; i < nslots; i++)
657d0d47 9024 {
341f9135
CC
9025 unsigned char *shndx_list;
9026 unsigned int shndx;
9027
6937bb54 9028 SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
341f9135 9029 if (signature_high != 0 || signature_low != 0)
657d0d47 9030 {
6937bb54 9031 SAFE_BYTE_GET (j, pindex, 4, limit);
341f9135 9032 shndx_list = ppool + j * 4;
f3853b34
NC
9033 /* PR 17531: file: 705e010d. */
9034 if (shndx_list < ppool)
9035 {
9036 warn (_("Section index pool located before start of section\n"));
9037 return 0;
9038 }
9039
341f9135
CC
9040 if (do_display)
9041 printf (_(" [%3d] Signature: 0x%s Sections: "),
9042 i, dwarf_vmatoa64 (signature_high, signature_low,
9043 buf, sizeof (buf)));
9044 for (;;)
657d0d47 9045 {
341f9135
CC
9046 if (shndx_list >= limit)
9047 {
9048 warn (_("Section %s too small for shndx pool\n"),
9049 section->name);
9050 return 0;
9051 }
6937bb54 9052 SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
341f9135
CC
9053 if (shndx == 0)
9054 break;
9055 if (do_display)
9056 printf (" %d", shndx);
9057 else
9058 add_shndx_to_cu_tu_entry (shndx);
9059 shndx_list += 4;
657d0d47 9060 }
657d0d47 9061 if (do_display)
341f9135 9062 printf ("\n");
657d0d47 9063 else
341f9135
CC
9064 end_cu_tu_entry ();
9065 }
9066 phash += 8;
9067 pindex += 4;
9068 }
9069 }
9070 else if (version == 2)
9071 {
9072 unsigned int val;
9073 unsigned int dw_sect;
9074 unsigned char *ph = phash;
9075 unsigned char *pi = pindex;
9076 unsigned char *poffsets = ppool + ncols * 4;
9077 unsigned char *psizes = poffsets + nused * ncols * 4;
9078 unsigned char *pend = psizes + nused * ncols * 4;
9079 bfd_boolean is_tu_index;
9080 struct cu_tu_set *this_set = NULL;
9081 unsigned int row;
9082 unsigned char *prow;
9083
9084 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
9085
362beea4 9086 /* PR 17531: file: 0dd159bf.
b4eb7656 9087 Check for wraparound with an overlarge ncols value. */
c8071705 9088 if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols)
362beea4
NC
9089 {
9090 warn (_("Overlarge number of columns: %x\n"), ncols);
9091 return 0;
9092 }
9093
341f9135
CC
9094 if (pend > limit)
9095 {
9096 warn (_("Section %s too small for offset and size tables\n"),
9097 section->name);
9098 return 0;
9099 }
9100
9101 if (do_display)
9102 {
9103 printf (_(" Offset table\n"));
9104 printf (" slot %-16s ",
9105 is_tu_index ? _("signature") : _("dwo_id"));
9106 }
9107 else
9108 {
9109 if (is_tu_index)
9110 {
9111 tu_count = nused;
72c61a0d 9112 tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
341f9135 9113 this_set = tu_sets;
657d0d47 9114 }
657d0d47 9115 else
341f9135
CC
9116 {
9117 cu_count = nused;
72c61a0d 9118 cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
341f9135
CC
9119 this_set = cu_sets;
9120 }
9121 }
6937bb54 9122
341f9135
CC
9123 if (do_display)
9124 {
9125 for (j = 0; j < ncols; j++)
9126 {
6937bb54 9127 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
341f9135
CC
9128 printf (" %8s", get_DW_SECT_short_name (dw_sect));
9129 }
9130 printf ("\n");
9131 }
6937bb54 9132
341f9135
CC
9133 for (i = 0; i < nslots; i++)
9134 {
6937bb54
NC
9135 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
9136
9137 SAFE_BYTE_GET (row, pi, 4, limit);
341f9135
CC
9138 if (row != 0)
9139 {
591f7597 9140 /* PR 17531: file: a05f6ab3. */
ef77750e 9141 if (row > nused)
591f7597
NC
9142 {
9143 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
9144 row, nused);
9145 return 0;
9146 }
9147
341f9135
CC
9148 if (!do_display)
9149 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
6937bb54 9150
341f9135 9151 prow = poffsets + (row - 1) * ncols * 4;
ffc0f143
NC
9152 /* PR 17531: file: b8ce60a8. */
9153 if (prow < poffsets || prow > limit)
9154 {
9155 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
9156 row, ncols);
9157 return 0;
9158 }
3aade688 9159
341f9135
CC
9160 if (do_display)
9161 printf (_(" [%3d] 0x%s"),
9162 i, dwarf_vmatoa64 (signature_high, signature_low,
9163 buf, sizeof (buf)));
9164 for (j = 0; j < ncols; j++)
9165 {
6937bb54 9166 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
341f9135
CC
9167 if (do_display)
9168 printf (" %8d", val);
9169 else
9170 {
6937bb54 9171 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
82b1b41b
NC
9172
9173 /* PR 17531: file: 10796eb3. */
9174 if (dw_sect >= DW_SECT_MAX)
9175 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
9176 else
9177 this_set [row - 1].section_offsets [dw_sect] = val;
341f9135
CC
9178 }
9179 }
6937bb54 9180
341f9135
CC
9181 if (do_display)
9182 printf ("\n");
9183 }
9184 ph += 8;
9185 pi += 4;
9186 }
9187
9188 ph = phash;
9189 pi = pindex;
9190 if (do_display)
b4eb7656 9191 {
341f9135
CC
9192 printf ("\n");
9193 printf (_(" Size table\n"));
9194 printf (" slot %-16s ",
9195 is_tu_index ? _("signature") : _("dwo_id"));
b4eb7656 9196 }
6937bb54 9197
341f9135
CC
9198 for (j = 0; j < ncols; j++)
9199 {
6937bb54 9200 SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
341f9135
CC
9201 if (do_display)
9202 printf (" %8s", get_DW_SECT_short_name (val));
9203 }
6937bb54 9204
341f9135
CC
9205 if (do_display)
9206 printf ("\n");
6937bb54 9207
341f9135
CC
9208 for (i = 0; i < nslots; i++)
9209 {
6937bb54
NC
9210 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
9211
9212 SAFE_BYTE_GET (row, pi, 4, limit);
341f9135
CC
9213 if (row != 0)
9214 {
9215 prow = psizes + (row - 1) * ncols * 4;
6937bb54 9216
341f9135
CC
9217 if (do_display)
9218 printf (_(" [%3d] 0x%s"),
9219 i, dwarf_vmatoa64 (signature_high, signature_low,
9220 buf, sizeof (buf)));
6937bb54 9221
341f9135
CC
9222 for (j = 0; j < ncols; j++)
9223 {
6937bb54 9224 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
341f9135
CC
9225 if (do_display)
9226 printf (" %8d", val);
9227 else
9228 {
6937bb54 9229 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
82b1b41b
NC
9230 if (dw_sect >= DW_SECT_MAX)
9231 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
9232 else
341f9135
CC
9233 this_set [row - 1].section_sizes [dw_sect] = val;
9234 }
9235 }
6937bb54 9236
341f9135
CC
9237 if (do_display)
9238 printf ("\n");
9239 }
6937bb54 9240
341f9135
CC
9241 ph += 8;
9242 pi += 4;
657d0d47 9243 }
657d0d47 9244 }
341f9135 9245 else if (do_display)
6937bb54 9246 printf (_(" Unsupported version (%d)\n"), version);
657d0d47
CC
9247
9248 if (do_display)
9249 printf ("\n");
9250
9251 return 1;
9252}
9253
9254/* Load the CU and TU indexes if present. This will build a list of
9255 section sets that we can use to associate a .debug_info.dwo section
9256 with its associated .debug_abbrev.dwo section in a .dwp file. */
9257
43a444f9 9258static bfd_boolean
657d0d47
CC
9259load_cu_tu_indexes (void *file)
9260{
43a444f9
NC
9261 static int cu_tu_indexes_read = -1; /* Tri-state variable. */
9262
657d0d47
CC
9263 /* If we have already loaded (or tried to load) the CU and TU indexes
9264 then do not bother to repeat the task. */
43a444f9
NC
9265 if (cu_tu_indexes_read == -1)
9266 {
9267 cu_tu_indexes_read = TRUE;
9268
dda8d76d 9269 if (load_debug_section_with_follow (dwp_cu_index, file))
43a444f9
NC
9270 if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0))
9271 cu_tu_indexes_read = FALSE;
9272
dda8d76d 9273 if (load_debug_section_with_follow (dwp_tu_index, file))
43a444f9
NC
9274 if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0))
9275 cu_tu_indexes_read = FALSE;
9276 }
657d0d47 9277
43a444f9 9278 return (bfd_boolean) cu_tu_indexes_read;
657d0d47
CC
9279}
9280
9281/* Find the set of sections that includes section SHNDX. */
9282
9283unsigned int *
9284find_cu_tu_set (void *file, unsigned int shndx)
9285{
9286 unsigned int i;
9287
43a444f9
NC
9288 if (! load_cu_tu_indexes (file))
9289 return NULL;
657d0d47
CC
9290
9291 /* Find SHNDX in the shndx pool. */
9292 for (i = 0; i < shndx_pool_used; i++)
9293 if (shndx_pool [i] == shndx)
9294 break;
9295
9296 if (i >= shndx_pool_used)
9297 return NULL;
9298
9299 /* Now backup to find the first entry in the set. */
9300 while (i > 0 && shndx_pool [i - 1] != 0)
9301 i--;
9302
9303 return shndx_pool + i;
9304}
9305
9306/* Display a .debug_cu_index or .debug_tu_index section. */
9307
9308static int
9309display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
9310{
9311 return process_cu_tu_index (section, 1);
9312}
9313
19e6b90e
L
9314static int
9315display_debug_not_supported (struct dwarf_section *section,
9316 void *file ATTRIBUTE_UNUSED)
9317{
9318 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9319 section->name);
9320
9321 return 1;
9322}
9323
1306a742
NC
9324/* Like malloc, but takes two parameters like calloc.
9325 Verifies that the first parameter is not too large.
82b1b41b 9326 Note: does *not* initialise the allocated memory to zero. */
dda8d76d 9327
19e6b90e
L
9328void *
9329cmalloc (size_t nmemb, size_t size)
9330{
9331 /* Check for overflow. */
9332 if (nmemb >= ~(size_t) 0 / size)
9333 return NULL;
82b1b41b
NC
9334
9335 return xmalloc (nmemb * size);
19e6b90e
L
9336}
9337
1306a742
NC
9338/* Like xmalloc, but takes two parameters like calloc.
9339 Verifies that the first parameter is not too large.
9340 Note: does *not* initialise the allocated memory to zero. */
dda8d76d 9341
72c61a0d 9342void *
1306a742 9343xcmalloc (size_t nmemb, size_t size)
72c61a0d
NC
9344{
9345 /* Check for overflow. */
9346 if (nmemb >= ~(size_t) 0 / size)
8490fb40
NC
9347 {
9348 fprintf (stderr,
9349 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
9350 (long) nmemb);
9351 xexit (1);
9352 }
72c61a0d 9353
1306a742 9354 return xmalloc (nmemb * size);
72c61a0d
NC
9355}
9356
1306a742
NC
9357/* Like xrealloc, but takes three parameters.
9358 Verifies that the second parameter is not too large.
9359 Note: does *not* initialise any new memory to zero. */
dda8d76d 9360
19e6b90e 9361void *
1306a742 9362xcrealloc (void *ptr, size_t nmemb, size_t size)
19e6b90e
L
9363{
9364 /* Check for overflow. */
9365 if (nmemb >= ~(size_t) 0 / size)
8490fb40 9366 {
dda8d76d
NC
9367 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
9368 (long) nmemb);
8490fb40
NC
9369 xexit (1);
9370 }
82b1b41b 9371
1306a742 9372 return xrealloc (ptr, nmemb * size);
19e6b90e
L
9373}
9374
1306a742 9375/* Like xcalloc, but verifies that the first parameter is not too large. */
dda8d76d 9376
19e6b90e 9377void *
1306a742 9378xcalloc2 (size_t nmemb, size_t size)
19e6b90e
L
9379{
9380 /* Check for overflow. */
9381 if (nmemb >= ~(size_t) 0 / size)
8490fb40 9382 {
dda8d76d
NC
9383 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
9384 (long) nmemb);
8490fb40
NC
9385 xexit (1);
9386 }
82b1b41b 9387
1306a742 9388 return xcalloc (nmemb, size);
19e6b90e
L
9389}
9390
dda8d76d
NC
9391static unsigned long
9392calc_gnu_debuglink_crc32 (unsigned long crc,
9393 const unsigned char * buf,
9394 bfd_size_type len)
9395{
9396 static const unsigned long crc32_table[256] =
9397 {
9398 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
9399 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
9400 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
9401 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
9402 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
9403 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
9404 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
9405 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
9406 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
9407 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
9408 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
9409 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
9410 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
9411 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
9412 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
9413 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
9414 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
9415 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
9416 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
9417 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
9418 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
9419 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
9420 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
9421 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
9422 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
9423 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
9424 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
9425 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
9426 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
9427 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
9428 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
9429 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
9430 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
9431 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
9432 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
9433 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
9434 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
9435 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
9436 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
9437 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
9438 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
9439 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
9440 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
9441 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
9442 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
9443 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
9444 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
9445 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
9446 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
9447 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
9448 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
9449 0x2d02ef8d
9450 };
9451 const unsigned char *end;
9452
9453 crc = ~crc & 0xffffffff;
9454 for (end = buf + len; buf < end; ++ buf)
9455 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
9456 return ~crc & 0xffffffff;
9457}
9458
9459typedef bfd_boolean (* check_func_type) (const char *, void *);
9460typedef const char * (* parse_func_type) (struct dwarf_section *, void *);
9461
9462static bfd_boolean
9463check_gnu_debuglink (const char * pathname, void * crc_pointer)
9464{
9465 static unsigned char buffer [8 * 1024];
9466 FILE * f;
9467 bfd_size_type count;
9468 unsigned long crc = 0;
9469 void * sep_data;
9470
9471 sep_data = open_debug_file (pathname);
9472 if (sep_data == NULL)
9473 return FALSE;
9474
9475 /* Yes - we are opening the file twice... */
9476 f = fopen (pathname, "rb");
9477 if (f == NULL)
9478 {
9479 /* Paranoia: This should never happen. */
9480 close_debug_file (sep_data);
9481 warn (_("Unable to reopen separate debug info file: %s\n"), pathname);
9482 return FALSE;
9483 }
9484
9485 while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0)
9486 crc = calc_gnu_debuglink_crc32 (crc, buffer, count);
9487
9488 fclose (f);
9489
9490 if (crc != * (unsigned long *) crc_pointer)
9491 {
9492 close_debug_file (sep_data);
9493 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
9494 pathname);
9495 return FALSE;
9496 }
9497
9498 return TRUE;
9499}
9500
9501static const char *
9502parse_gnu_debuglink (struct dwarf_section * section, void * data)
9503{
9504 const char * name;
9505 unsigned int crc_offset;
9506 unsigned long * crc32 = (unsigned long *) data;
9507
9508 /* The name is first.
9509 The CRC value is stored after the filename, aligned up to 4 bytes. */
9510 name = (const char *) section->start;
9511
9512 crc_offset = strnlen (name, section->size) + 1;
9513 crc_offset = (crc_offset + 3) & ~3;
9514 if (crc_offset + 4 > section->size)
9515 return NULL;
9516
9517 * crc32 = byte_get (section->start + crc_offset, 4);
9518 return name;
9519}
9520
9521static bfd_boolean
9522check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED)
9523{
9524 void * sep_data = open_debug_file (filename);
9525
9526 if (sep_data == NULL)
9527 return FALSE;
9528
9529 /* FIXME: We should now extract the build-id in the separate file
9530 and check it... */
9531
9532 return TRUE;
9533}
9534
9535typedef struct build_id_data
9536{
9537 bfd_size_type len;
9538 const unsigned char * data;
9539} Build_id_data;
9540
9541static const char *
9542parse_gnu_debugaltlink (struct dwarf_section * section, void * data)
9543{
9544 const char * name;
9545 bfd_size_type namelen;
9546 bfd_size_type id_len;
9547 Build_id_data * build_id_data;
9548
9549 /* The name is first.
9550 The build-id follows immediately, with no padding, up to the section's end. */
9551
9552 name = (const char *) section->start;
9553 namelen = strnlen (name, section->size) + 1;
9554 if (namelen >= section->size)
9555 return NULL;
9556
9557 id_len = section->size - namelen;
9558 if (id_len < 0x14)
9559 return NULL;
9560
9561 build_id_data = calloc (1, sizeof * build_id_data);
9562 if (build_id_data == NULL)
9563 return NULL;
9564
9565 build_id_data->len = id_len;
9566 build_id_data->data = section->start + namelen;
9567
9568 * (Build_id_data **) data = build_id_data;
9569
9570 return name;
9571}
9572
9573static void *
9574load_separate_debug_info (const char * main_filename,
9575 struct dwarf_section * link,
9576 parse_func_type parse_func,
9577 check_func_type check_func,
9578 void * func_data)
9579{
9580 const char * separate_filename;
9581 char * debugfile;
9582 char * canon_dir;
9583 size_t canon_dirlen;
9584 size_t dirlen;
9585
9586 if ((separate_filename = parse_func (link, func_data)) == NULL)
9587 {
9588 warn (_("Corrupt debuglink section: %s\n"),
9589 link->name ? link->name : link->uncompressed_name);
9590 return FALSE;
9591 }
9592
9593 /* Attempt to locate the separate file.
9594 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
9595
9596 canon_dir = lrealpath (main_filename);
9597
9598 for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--)
9599 if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1]))
9600 break;
9601 canon_dir[canon_dirlen] = '\0';
9602
9603#ifndef DEBUGDIR
9604#define DEBUGDIR "/lib/debug"
9605#endif
9606#ifndef EXTRA_DEBUG_ROOT1
9607#define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
9608#endif
9609#ifndef EXTRA_DEBUG_ROOT2
9610#define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
9611#endif
9612
9613 debugfile = (char *) malloc (strlen (DEBUGDIR) + 1
9614 + canon_dirlen
9615 + strlen (".debug/")
9616#ifdef EXTRA_DEBUG_ROOT1
9617 + strlen (EXTRA_DEBUG_ROOT1)
9618#endif
9619#ifdef EXTRA_DEBUG_ROOT2
9620 + strlen (EXTRA_DEBUG_ROOT2)
9621#endif
9622 + strlen (separate_filename)
9623 + 1);
9624 if (debugfile == NULL)
9625 {
9626 warn (_("Out of memory"));
9627 return NULL;
9628 }
9629
9630 /* First try in the current directory. */
9631 sprintf (debugfile, "%s", separate_filename);
9632 if (check_func (debugfile, func_data))
9633 goto found;
9634
9635 /* Then try in a subdirectory called .debug. */
9636 sprintf (debugfile, ".debug/%s", separate_filename);
9637 if (check_func (debugfile, func_data))
9638 goto found;
9639
9640 /* Then try in the same directory as the original file. */
9641 sprintf (debugfile, "%s%s", canon_dir, separate_filename);
9642 if (check_func (debugfile, func_data))
9643 goto found;
9644
9645 /* And the .debug subdirectory of that directory. */
9646 sprintf (debugfile, "%s.debug/%s", canon_dir, separate_filename);
9647 if (check_func (debugfile, func_data))
9648 goto found;
9649
9650#ifdef EXTRA_DEBUG_ROOT1
9651 /* Try the first extra debug file root. */
9652 sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename);
9653 if (check_func (debugfile, func_data))
9654 goto found;
9655#endif
9656
9657#ifdef EXTRA_DEBUG_ROOT2
9658 /* Try the second extra debug file root. */
9659 sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename);
9660 if (check_func (debugfile, func_data))
9661 goto found;
9662#endif
9663
9664 /* Then try in the global debugfile directory. */
9665 strcpy (debugfile, DEBUGDIR);
9666 dirlen = strlen (DEBUGDIR) - 1;
9667 if (dirlen > 0 && DEBUGDIR[dirlen] != '/')
9668 strcat (debugfile, "/");
9669 strcat (debugfile, (const char *) separate_filename);
9670
9671 if (check_func (debugfile, func_data))
9672 goto found;
9673
9674 /* Failed to find the file. */
9675 warn (_("could not find separate debug file '%s'\n"), separate_filename);
9676 warn (_("tried: %s\n"), debugfile);
9677
9678#ifdef EXTRA_DEBUG_ROOT2
9679 sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename);
9680 warn (_("tried: %s\n"), debugfile);
9681#endif
9682
9683#ifdef EXTRA_DEBUG_ROOT1
9684 sprintf (debugfile, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename);
9685 warn (_("tried: %s\n"), debugfile);
9686#endif
9687
9688 sprintf (debugfile, "%s.debug/%s", canon_dir, separate_filename);
9689 warn (_("tried: %s\n"), debugfile);
9690
9691 sprintf (debugfile, "%s%s", canon_dir, separate_filename);
9692 warn (_("tried: %s\n"), debugfile);
9693
9694 sprintf (debugfile, ".debug/%s", separate_filename);
9695 warn (_("tried: %s\n"), debugfile);
9696
9697 sprintf (debugfile, "%s", separate_filename);
9698 warn (_("tried: %s\n"), debugfile);
9699
9700 free (canon_dir);
9701 free (debugfile);
9702 return NULL;
9703
9704 found:
9705 free (canon_dir);
9706
9707 /* Now open the file.... */
9708 if ((separate_debug_file = open_debug_file (debugfile)) == NULL)
9709 {
9710 warn (_("failed to open separate debug file: %s\n"), debugfile);
9711 free (debugfile);
9712 return FALSE;
9713 }
9714
9715 /* FIXME: We do not check to see if there are any other separate debug info
9716 files that would also match. */
9717
9718 printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debugfile);
9719 separate_debug_filename = debugfile;
9720
9721 /* Do not free debugfile - it might be referenced inside
9722 the structure returned by open_debug_file(). */
9723 return separate_debug_file;
9724}
9725
9726/* Load a separate debug info file, if it exists.
9727 Returns the data pointer that is the result of calling open_debug_file
9728 on the separate debug info file. */
9729
9730void *
9731load_separate_debug_file (void * file, const char * filename)
9732{
9733 if (! do_follow_links)
9734 return NULL;
9735
9736 /* FIXME: We do not check for the presence of both link sections in the same file. */
9737 /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */
9738 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
9739
9740 /* We try the alt version first as that is blessed by the DWARF5 standard. */
9741 if (load_debug_section (gnu_debugaltlink, file))
9742 {
9743 Build_id_data * build_id_data;
9744
9745 return load_separate_debug_info (filename,
9746 & debug_displays[gnu_debugaltlink].section,
9747 parse_gnu_debugaltlink,
9748 check_gnu_debugaltlink,
9749 & build_id_data);
9750 }
9751
9752 if (load_debug_section (gnu_debuglink, file))
9753 {
9754 unsigned long crc32;
9755
9756 return load_separate_debug_info (filename,
9757 & debug_displays[gnu_debuglink].section,
9758 parse_gnu_debuglink,
9759 check_gnu_debuglink,
9760 & crc32);
9761 }
9762
9763 do_follow_links = 0;
9764 return NULL;
9765}
9766
19e6b90e
L
9767void
9768free_debug_memory (void)
9769{
3f5e193b 9770 unsigned int i;
19e6b90e
L
9771
9772 free_abbrevs ();
9773
9774 for (i = 0; i < max; i++)
3f5e193b 9775 free_debug_section ((enum dwarf_section_display_enum) i);
19e6b90e 9776
cc86f28f 9777 if (debug_information != NULL)
19e6b90e 9778 {
cc86f28f 9779 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
19e6b90e 9780 {
cc86f28f 9781 for (i = 0; i < num_debug_info_entries; i++)
19e6b90e 9782 {
cc86f28f
NC
9783 if (!debug_information [i].max_loc_offsets)
9784 {
9785 free (debug_information [i].loc_offsets);
9786 free (debug_information [i].have_frame_base);
9787 }
9788 if (!debug_information [i].max_range_lists)
9789 free (debug_information [i].range_lists);
19e6b90e 9790 }
19e6b90e
L
9791 }
9792 free (debug_information);
9793 debug_information = NULL;
82b1b41b 9794 alloc_num_debug_info_entries = num_debug_info_entries = 0;
19e6b90e 9795 }
dda8d76d
NC
9796
9797 if (separate_debug_file != NULL)
9798 {
9799 close_debug_file (separate_debug_file);
9800 separate_debug_file = NULL;
9801
9802 free ((void *) separate_debug_filename);
9803 separate_debug_filename = NULL;
9804 }
19e6b90e
L
9805}
9806
4cb93e3b
TG
9807void
9808dwarf_select_sections_by_names (const char *names)
9809{
9810 typedef struct
9811 {
9812 const char * option;
9813 int * variable;
f9f0e732 9814 int val;
4cb93e3b
TG
9815 }
9816 debug_dump_long_opts;
9817
9818 static const debug_dump_long_opts opts_table [] =
9819 {
9820 /* Please keep this table alpha- sorted. */
9821 { "Ranges", & do_debug_ranges, 1 },
9822 { "abbrev", & do_debug_abbrevs, 1 },
657d0d47 9823 { "addr", & do_debug_addr, 1 },
4cb93e3b 9824 { "aranges", & do_debug_aranges, 1 },
657d0d47
CC
9825 { "cu_index", & do_debug_cu_index, 1 },
9826 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
dda8d76d 9827 { "follow-links", & do_follow_links, 1 },
4cb93e3b
TG
9828 { "frames", & do_debug_frames, 1 },
9829 { "frames-interp", & do_debug_frames_interp, 1 },
657d0d47
CC
9830 /* The special .gdb_index section. */
9831 { "gdb_index", & do_gdb_index, 1 },
4cb93e3b
TG
9832 { "info", & do_debug_info, 1 },
9833 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
dda8d76d 9834 { "links", & do_debug_links, 1 },
4cb93e3b
TG
9835 { "loc", & do_debug_loc, 1 },
9836 { "macro", & do_debug_macinfo, 1 },
9837 { "pubnames", & do_debug_pubnames, 1 },
357da287 9838 { "pubtypes", & do_debug_pubtypes, 1 },
222c2bf0 9839 /* This entry is for compatibility
4cb93e3b
TG
9840 with earlier versions of readelf. */
9841 { "ranges", & do_debug_aranges, 1 },
657d0d47 9842 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
4cb93e3b 9843 { "str", & do_debug_str, 1 },
6f875884
TG
9844 /* These trace_* sections are used by Itanium VMS. */
9845 { "trace_abbrev", & do_trace_abbrevs, 1 },
9846 { "trace_aranges", & do_trace_aranges, 1 },
9847 { "trace_info", & do_trace_info, 1 },
4cb93e3b
TG
9848 { NULL, NULL, 0 }
9849 };
9850
9851 const char *p;
467c65bc 9852
4cb93e3b
TG
9853 p = names;
9854 while (*p)
9855 {
9856 const debug_dump_long_opts * entry;
467c65bc 9857
4cb93e3b
TG
9858 for (entry = opts_table; entry->option; entry++)
9859 {
9860 size_t len = strlen (entry->option);
467c65bc 9861
4cb93e3b
TG
9862 if (strncmp (p, entry->option, len) == 0
9863 && (p[len] == ',' || p[len] == '\0'))
9864 {
9865 * entry->variable |= entry->val;
467c65bc 9866
4cb93e3b
TG
9867 /* The --debug-dump=frames-interp option also
9868 enables the --debug-dump=frames option. */
9869 if (do_debug_frames_interp)
9870 do_debug_frames = 1;
9871
9872 p += len;
9873 break;
9874 }
9875 }
467c65bc 9876
4cb93e3b
TG
9877 if (entry->option == NULL)
9878 {
9879 warn (_("Unrecognized debug option '%s'\n"), p);
9880 p = strchr (p, ',');
9881 if (p == NULL)
9882 break;
9883 }
467c65bc 9884
4cb93e3b
TG
9885 if (*p == ',')
9886 p++;
9887 }
9888}
9889
9890void
9891dwarf_select_sections_by_letters (const char *letters)
9892{
91d6fa6a 9893 unsigned int lindex = 0;
4cb93e3b 9894
91d6fa6a
NC
9895 while (letters[lindex])
9896 switch (letters[lindex++])
4cb93e3b 9897 {
dda8d76d
NC
9898 case 'A': do_debug_addr = 1; break;
9899 case 'a': do_debug_abbrevs = 1; break;
9900 case 'c': do_debug_cu_index = 1; break;
9901 case 'F': do_debug_frames_interp = 1; /* Fall through. */
9902 case 'f': do_debug_frames = 1; break;
9903 case 'g': do_gdb_index = 1; break;
9904 case 'i': do_debug_info = 1; break;
9905 case 'K': do_follow_links = 1; break;
9906 case 'k': do_debug_links = 1; break;
9907 case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break;
9908 case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break;
9909 case 'm': do_debug_macinfo = 1; break;
9910 case 'o': do_debug_loc = 1; break;
9911 case 'p': do_debug_pubnames = 1; break;
9912 case 'R': do_debug_ranges = 1; break;
9913 case 'r': do_debug_aranges = 1; break;
9914 case 's': do_debug_str = 1; break;
9915 case 'T': do_trace_aranges = 1; break;
9916 case 't': do_debug_pubtypes = 1; break;
9917 case 'U': do_trace_info = 1; break;
9918 case 'u': do_trace_abbrevs = 1; break;
467c65bc 9919
4cb93e3b 9920 default:
7cc78d07 9921 warn (_("Unrecognized debug option '%s'\n"), letters);
4cb93e3b
TG
9922 break;
9923 }
9924}
9925
9926void
9927dwarf_select_sections_all (void)
9928{
9929 do_debug_info = 1;
9930 do_debug_abbrevs = 1;
9931 do_debug_lines = FLAG_DEBUG_LINES_RAW;
9932 do_debug_pubnames = 1;
f9f0e732 9933 do_debug_pubtypes = 1;
4cb93e3b
TG
9934 do_debug_aranges = 1;
9935 do_debug_ranges = 1;
9936 do_debug_frames = 1;
9937 do_debug_macinfo = 1;
9938 do_debug_str = 1;
9939 do_debug_loc = 1;
5bbdf3d5 9940 do_gdb_index = 1;
6f875884
TG
9941 do_trace_info = 1;
9942 do_trace_abbrevs = 1;
9943 do_trace_aranges = 1;
657d0d47
CC
9944 do_debug_addr = 1;
9945 do_debug_cu_index = 1;
dda8d76d
NC
9946 do_follow_links = 1;
9947 do_debug_links = 1;
4cb93e3b
TG
9948}
9949
dda8d76d
NC
9950#define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL
9951#define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL
9952
9953/* N.B. The order here must match the order in section_display_enum. */
9954
19e6b90e
L
9955struct dwarf_section_display debug_displays[] =
9956{
dda8d76d
NC
9957 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE },
9958 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE },
9959 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE },
9960 { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE },
9961 { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE },
9962 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE },
9963 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE },
9964 { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE },
9965 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE },
9966 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE },
9967 { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE },
9968 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE },
9969 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE },
9970 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE },
9971 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE },
9972 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE },
9973 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE },
9974 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE },
9975 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE },
9976 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE },
9977 { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE },
9978 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE },
9979 { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE },
9980 { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE },
9981 { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE },
9982 { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE },
9983 { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE },
9984 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE },
9985 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE },
9986 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE },
9987 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE },
9988 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE },
9989 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE },
9990 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE },
9991 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE },
9992 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE },
9993 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE },
9994 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE },
9995 { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE },
9996 { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE },
9997 { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE },
9998 { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE },
9999 /* Separate debug info files can containt their own .debug_str section,
10000 and this might be in *addition* to a .debug_str section already present
10001 in the main file. Hence we need to have two entries for .debug_str. */
10002 { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE },
19e6b90e 10003};
b451e98a
JK
10004
10005/* A static assertion. */
10006extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1];
This page took 1.215913 seconds and 4 git commands to generate.