Commit | Line | Data |
---|---|---|
19e6b90e | 1 | /* dwarf.c -- display DWARF contents of a BFD binary file |
250d07de | 2 | Copyright (C) 2005-2021 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" |
3dfb1b6d | 24 | #include <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" |
48467cb9 | 32 | #include "safe-ctype.h" |
61364358 JK |
33 | #include <assert.h> |
34 | ||
301a9420 AM |
35 | #ifdef HAVE_LIBDEBUGINFOD |
36 | #include <elfutils/debuginfod.h> | |
37 | #endif | |
38 | ||
b9b204b3 | 39 | #include <limits.h> |
b9b204b3 AM |
40 | #ifndef CHAR_BIT |
41 | #define CHAR_BIT 8 | |
42 | #endif | |
43 | ||
61364358 JK |
44 | #undef MAX |
45 | #undef MIN | |
46 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) | |
47 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | |
19e6b90e | 48 | |
18464d4d | 49 | static const char *regname (unsigned int regno, int row); |
1296bc99 | 50 | static const char *regname_internal_by_table_only (unsigned int regno); |
18464d4d | 51 | |
19e6b90e L |
52 | static int have_frame_base; |
53 | static int need_base_address; | |
54 | ||
19e6b90e | 55 | static unsigned int num_debug_info_entries = 0; |
82b1b41b | 56 | static unsigned int alloc_num_debug_info_entries = 0; |
19e6b90e | 57 | static debug_info *debug_information = NULL; |
cc86f28f NC |
58 | /* Special value for num_debug_info_entries to indicate |
59 | that the .debug_info section could not be loaded/parsed. */ | |
60 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 | |
19e6b90e | 61 | |
24841daa NC |
62 | /* A .debug_info section can contain multiple links to separate |
63 | DWO object files. We use these structures to record these links. */ | |
64 | typedef enum dwo_type | |
65 | { | |
66 | DWO_NAME, | |
67 | DWO_DIR, | |
68 | DWO_ID | |
69 | } dwo_type; | |
70 | ||
71 | typedef struct dwo_info | |
72 | { | |
73 | dwo_type type; | |
74 | const char * value; | |
50ea0877 | 75 | dwarf_vma cu_offset; |
24841daa NC |
76 | struct dwo_info * next; |
77 | } dwo_info; | |
78 | ||
015dc7e1 AM |
79 | static dwo_info *first_dwo_info = NULL; |
80 | static bool need_dwo_info; | |
24841daa NC |
81 | |
82 | separate_info * first_separate_info = NULL; | |
d85bf2ba | 83 | |
77ef8654 | 84 | unsigned int eh_addr_size; |
19e6b90e L |
85 | |
86 | int do_debug_info; | |
87 | int do_debug_abbrevs; | |
88 | int do_debug_lines; | |
89 | int do_debug_pubnames; | |
f9f0e732 | 90 | int do_debug_pubtypes; |
19e6b90e L |
91 | int do_debug_aranges; |
92 | int do_debug_ranges; | |
93 | int do_debug_frames; | |
94 | int do_debug_frames_interp; | |
95 | int do_debug_macinfo; | |
96 | int do_debug_str; | |
e4b7104b | 97 | int do_debug_str_offsets; |
19e6b90e | 98 | int do_debug_loc; |
5bbdf3d5 | 99 | int do_gdb_index; |
6f875884 TG |
100 | int do_trace_info; |
101 | int do_trace_abbrevs; | |
102 | int do_trace_aranges; | |
657d0d47 CC |
103 | int do_debug_addr; |
104 | int do_debug_cu_index; | |
a262ae96 | 105 | int do_wide; |
dda8d76d | 106 | int do_debug_links; |
c46b7066 | 107 | int do_follow_links = DEFAULT_FOR_FOLLOW_LINKS; |
015dc7e1 | 108 | bool do_checks; |
19e6b90e | 109 | |
fd2f0033 TT |
110 | int dwarf_cutoff_level = -1; |
111 | unsigned long dwarf_start_die; | |
112 | ||
4723351a CC |
113 | int dwarf_check = 0; |
114 | ||
9f272209 AO |
115 | /* Convenient constant, to avoid having to cast -1 to dwarf_vma when |
116 | testing whether e.g. a locview list is present. */ | |
117 | static const dwarf_vma vm1 = -1; | |
118 | ||
341f9135 CC |
119 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
120 | sections. For version 1 package files, each set is stored in SHNDX_POOL | |
121 | as a zero-terminated list of section indexes comprising one set of debug | |
122 | sections from a .dwo file. */ | |
123 | ||
341f9135 CC |
124 | static unsigned int *shndx_pool = NULL; |
125 | static unsigned int shndx_pool_size = 0; | |
126 | static unsigned int shndx_pool_used = 0; | |
127 | ||
128 | /* For version 2 package files, each set contains an array of section offsets | |
129 | and an array of section sizes, giving the offset and size of the | |
130 | contribution from a CU or TU within one of the debug sections. | |
131 | When displaying debug info from a package file, we need to use these | |
132 | tables to locate the corresponding contributions to each section. */ | |
133 | ||
134 | struct cu_tu_set | |
135 | { | |
ec1b0fbb NC |
136 | uint64_t signature; |
137 | dwarf_vma section_offsets[DW_SECT_MAX]; | |
138 | size_t section_sizes[DW_SECT_MAX]; | |
341f9135 CC |
139 | }; |
140 | ||
141 | static int cu_count = 0; | |
142 | static int tu_count = 0; | |
143 | static struct cu_tu_set *cu_sets = NULL; | |
144 | static struct cu_tu_set *tu_sets = NULL; | |
145 | ||
015dc7e1 | 146 | static bool load_cu_tu_indexes (void *); |
341f9135 | 147 | |
ec1b0fbb NC |
148 | /* An array that indicates for a given level of CU nesting whether |
149 | the latest DW_AT_type seen for that level was a signed type or | |
150 | an unsigned type. */ | |
151 | #define MAX_CU_NESTING (1 << 8) | |
015dc7e1 | 152 | static bool level_type_signed[MAX_CU_NESTING]; |
ec1b0fbb | 153 | |
4cb93e3b TG |
154 | /* Values for do_debug_lines. */ |
155 | #define FLAG_DEBUG_LINES_RAW 1 | |
156 | #define FLAG_DEBUG_LINES_DECODED 2 | |
157 | ||
77ef8654 | 158 | static unsigned int |
f1c4cc75 RH |
159 | size_of_encoded_value (int encoding) |
160 | { | |
161 | switch (encoding & 0x7) | |
162 | { | |
163 | default: /* ??? */ | |
164 | case 0: return eh_addr_size; | |
165 | case 2: return 2; | |
166 | case 3: return 4; | |
167 | case 4: return 8; | |
168 | } | |
169 | } | |
170 | ||
171 | static dwarf_vma | |
041830e0 | 172 | get_encoded_value (unsigned char **pdata, |
bad62cf5 | 173 | int encoding, |
041830e0 NC |
174 | struct dwarf_section *section, |
175 | unsigned char * end) | |
f1c4cc75 | 176 | { |
041830e0 | 177 | unsigned char * data = * pdata; |
6937bb54 | 178 | unsigned int size = size_of_encoded_value (encoding); |
bad62cf5 | 179 | dwarf_vma val; |
f1c4cc75 | 180 | |
041830e0 NC |
181 | if (data + size >= end) |
182 | { | |
183 | warn (_("Encoded value extends past end of section\n")); | |
184 | * pdata = end; | |
185 | return 0; | |
186 | } | |
187 | ||
6937bb54 NC |
188 | /* PR 17512: file: 002-829853-0.004. */ |
189 | if (size > 8) | |
190 | { | |
191 | warn (_("Encoded size of %d is too large to read\n"), size); | |
192 | * pdata = end; | |
193 | return 0; | |
194 | } | |
195 | ||
0a9d414a NC |
196 | /* PR 17512: file: 1085-5603-0.004. */ |
197 | if (size == 0) | |
198 | { | |
199 | warn (_("Encoded size of 0 is too small to read\n")); | |
200 | * pdata = end; | |
201 | return 0; | |
202 | } | |
203 | ||
f1c4cc75 | 204 | if (encoding & DW_EH_PE_signed) |
bad62cf5 | 205 | val = byte_get_signed (data, size); |
f1c4cc75 | 206 | else |
bad62cf5 AM |
207 | val = byte_get (data, size); |
208 | ||
209 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
210 | val += section->address + (data - section->start); | |
041830e0 NC |
211 | |
212 | * pdata = data + size; | |
bad62cf5 | 213 | return val; |
f1c4cc75 RH |
214 | } |
215 | ||
87b9f255 | 216 | #if SIZEOF_LONG_LONG > SIZEOF_LONG |
4c219c2e AM |
217 | # ifndef __MINGW32__ |
218 | # define DWARF_VMA_FMT "ll" | |
219 | # define DWARF_VMA_FMT_LONG "%16.16llx" | |
220 | # else | |
221 | # define DWARF_VMA_FMT "I64" | |
222 | # define DWARF_VMA_FMT_LONG "%016I64x" | |
223 | # endif | |
2e14fae2 | 224 | #else |
4c219c2e AM |
225 | # define DWARF_VMA_FMT "l" |
226 | # define DWARF_VMA_FMT_LONG "%16.16lx" | |
2d9472a2 NC |
227 | #endif |
228 | ||
bf5117e3 NC |
229 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
230 | buffer containing the converted VALUE. The value is converted according | |
231 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then | |
232 | it specifies the maximum number of bytes to be displayed in the converted | |
233 | value and FMTCH is ignored - hex is always used. */ | |
467c65bc | 234 | |
47704ddf | 235 | static const char * |
bf5117e3 | 236 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
47704ddf KT |
237 | { |
238 | /* As dwarf_vmatoa is used more then once in a printf call | |
239 | for output, we are cycling through an fixed array of pointers | |
240 | for return address. */ | |
241 | static int buf_pos = 0; | |
467c65bc NC |
242 | static struct dwarf_vmatoa_buf |
243 | { | |
47704ddf KT |
244 | char place[64]; |
245 | } buf[16]; | |
47704ddf KT |
246 | char *ret; |
247 | ||
47704ddf | 248 | ret = buf[buf_pos++].place; |
467c65bc | 249 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf | 250 | |
bf5117e3 NC |
251 | if (num_bytes) |
252 | { | |
222c2bf0 | 253 | /* Printf does not have a way of specifying a maximum field width for an |
bf5117e3 NC |
254 | integer value, so we print the full value into a buffer and then select |
255 | the precision we need. */ | |
256 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); | |
257 | if (num_bytes > 8) | |
258 | num_bytes = 8; | |
259 | return ret + (16 - 2 * num_bytes); | |
260 | } | |
261 | else | |
262 | { | |
263 | char fmt[32]; | |
264 | ||
0bae9e9e NC |
265 | if (fmtch) |
266 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); | |
267 | else | |
268 | sprintf (fmt, "%%%s", DWARF_VMA_FMT); | |
bf5117e3 NC |
269 | snprintf (ret, sizeof (buf[0].place), fmt, value); |
270 | return ret; | |
271 | } | |
272 | } | |
47704ddf | 273 | |
bf5117e3 NC |
274 | static inline const char * |
275 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) | |
276 | { | |
277 | return dwarf_vmatoa_1 (fmtch, value, 0); | |
278 | } | |
279 | ||
280 | /* Print a dwarf_vma value (typically an address, offset or length) in | |
281 | hexadecimal format, followed by a space. The length of the VALUE (and | |
282 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ | |
283 | ||
284 | static void | |
285 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) | |
286 | { | |
287 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); | |
47704ddf KT |
288 | } |
289 | ||
9f272209 AO |
290 | /* Print a view number in hexadecimal value, with the same width |
291 | print_dwarf_vma would have printed it with the same num_bytes. | |
292 | Print blanks for zero view, unless force is nonzero. */ | |
293 | ||
294 | static void | |
295 | print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force) | |
296 | { | |
297 | int len; | |
298 | if (!num_bytes) | |
299 | len = 4; | |
300 | else | |
301 | len = num_bytes * 2; | |
302 | ||
303 | assert (value == (unsigned long) value); | |
304 | if (value || force) | |
305 | printf ("v%0*lx ", len - 1, (unsigned long) value); | |
306 | else | |
307 | printf ("%*s", len + 1, ""); | |
308 | } | |
309 | ||
74bc6052 CC |
310 | /* Format a 64-bit value, given as two 32-bit values, in hex. |
311 | For reentrancy, this uses a buffer provided by the caller. */ | |
312 | ||
313 | static const char * | |
314 | dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, | |
315 | unsigned int buf_len) | |
316 | { | |
317 | int len = 0; | |
318 | ||
319 | if (hvalue == 0) | |
320 | snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); | |
321 | else | |
322 | { | |
323 | len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); | |
324 | snprintf (buf + len, buf_len - len, | |
325 | "%08" DWARF_VMA_FMT "x", lvalue); | |
326 | } | |
327 | ||
328 | return buf; | |
329 | } | |
330 | ||
f6f0e17b NC |
331 | /* Read in a LEB128 encoded value starting at address DATA. |
332 | If SIGN is true, return a signed LEB128 value. | |
333 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
b9b204b3 | 334 | If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the |
cd30bcef AM |
335 | terminating byte was not found and with bit 1 set if the value |
336 | overflows a dwarf_vma. | |
f6f0e17b NC |
337 | No bytes will be read at address END or beyond. */ |
338 | ||
467c65bc | 339 | dwarf_vma |
f6f0e17b | 340 | read_leb128 (unsigned char *data, |
cd30bcef | 341 | const unsigned char *const end, |
015dc7e1 | 342 | bool sign, |
cd30bcef AM |
343 | unsigned int *length_return, |
344 | int *status_return) | |
19e6b90e | 345 | { |
467c65bc | 346 | dwarf_vma result = 0; |
19e6b90e L |
347 | unsigned int num_read = 0; |
348 | unsigned int shift = 0; | |
cd30bcef | 349 | int status = 1; |
19e6b90e | 350 | |
f6f0e17b | 351 | while (data < end) |
19e6b90e | 352 | { |
cd30bcef | 353 | unsigned char byte = *data++; |
b9b204b3 | 354 | unsigned char lost, mask; |
08d7da7d | 355 | |
19e6b90e L |
356 | num_read++; |
357 | ||
b9b204b3 | 358 | if (shift < CHAR_BIT * sizeof (result)) |
cd30bcef | 359 | { |
b9b204b3 AM |
360 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; |
361 | /* These bits overflowed. */ | |
362 | lost = byte ^ (result >> shift); | |
363 | /* And this is the mask of possible overflow bits. */ | |
364 | mask = 0x7f ^ ((dwarf_vma) 0x7f << shift >> shift); | |
cd30bcef AM |
365 | shift += 7; |
366 | } | |
b9b204b3 | 367 | else |
08d7da7d | 368 | { |
b9b204b3 AM |
369 | lost = byte; |
370 | mask = 0x7f; | |
08d7da7d | 371 | } |
b9b204b3 AM |
372 | if ((lost & mask) != (sign && (dwarf_signed_vma) result < 0 ? mask : 0)) |
373 | status |= 2; | |
19e6b90e | 374 | |
b9b204b3 | 375 | if ((byte & 0x80) == 0) |
cd30bcef AM |
376 | { |
377 | status &= ~1; | |
b9b204b3 | 378 | if (sign && shift < CHAR_BIT * sizeof (result) && (byte & 0x40)) |
cd30bcef AM |
379 | result |= -((dwarf_vma) 1 << shift); |
380 | break; | |
381 | } | |
19e6b90e | 382 | } |
19e6b90e L |
383 | |
384 | if (length_return != NULL) | |
385 | *length_return = num_read; | |
cd30bcef AM |
386 | if (status_return != NULL) |
387 | *status_return = status; | |
19e6b90e L |
388 | |
389 | return result; | |
390 | } | |
391 | ||
d11ae95e NC |
392 | /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value. |
393 | Checks to make sure that the read will not reach or pass END | |
394 | and that VAL is big enough to hold AMOUNT bytes. */ | |
0c588247 NC |
395 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
396 | do \ | |
397 | { \ | |
398 | unsigned int amount = (AMOUNT); \ | |
34b9f729 NC |
399 | if (sizeof (VAL) < amount) \ |
400 | { \ | |
d3a49aa8 AM |
401 | error (ngettext ("internal error: attempt to read %d byte " \ |
402 | "of data in to %d sized variable", \ | |
403 | "internal error: attempt to read %d bytes " \ | |
404 | "of data in to %d sized variable", \ | |
405 | amount), \ | |
34b9f729 NC |
406 | amount, (int) sizeof (VAL)); \ |
407 | amount = sizeof (VAL); \ | |
408 | } \ | |
0c588247 NC |
409 | if (((PTR) + amount) >= (END)) \ |
410 | { \ | |
411 | if ((PTR) < (END)) \ | |
412 | amount = (END) - (PTR); \ | |
413 | else \ | |
414 | amount = 0; \ | |
415 | } \ | |
6937bb54 | 416 | if (amount == 0 || amount > 8) \ |
0c588247 | 417 | VAL = 0; \ |
6937bb54 NC |
418 | else \ |
419 | VAL = byte_get ((PTR), amount); \ | |
0c588247 NC |
420 | } \ |
421 | while (0) | |
422 | ||
d11ae95e | 423 | /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
424 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
425 | do \ | |
426 | { \ | |
427 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
428 | PTR += AMOUNT; \ | |
429 | } \ | |
430 | while (0) | |
431 | ||
d11ae95e | 432 | /* Like SAFE_BYTE_GET, but reads a signed value. */ |
0c588247 NC |
433 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
434 | do \ | |
435 | { \ | |
436 | unsigned int amount = (AMOUNT); \ | |
437 | if (((PTR) + amount) >= (END)) \ | |
438 | { \ | |
439 | if ((PTR) < (END)) \ | |
440 | amount = (END) - (PTR); \ | |
441 | else \ | |
442 | amount = 0; \ | |
443 | } \ | |
444 | if (amount) \ | |
445 | VAL = byte_get_signed ((PTR), amount); \ | |
446 | else \ | |
447 | VAL = 0; \ | |
448 | } \ | |
449 | while (0) | |
450 | ||
d11ae95e | 451 | /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
452 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
453 | do \ | |
454 | { \ | |
455 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
456 | PTR += AMOUNT; \ | |
457 | } \ | |
458 | while (0) | |
459 | ||
460 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ | |
461 | do \ | |
462 | { \ | |
87bc83b3 | 463 | if (((PTR) + 8) <= (END)) \ |
0c588247 NC |
464 | { \ |
465 | byte_get_64 ((PTR), (HIGH), (LOW)); \ | |
466 | } \ | |
467 | else \ | |
468 | { \ | |
0c588247 NC |
469 | * (LOW) = * (HIGH) = 0; \ |
470 | } \ | |
471 | } \ | |
472 | while (0) | |
473 | ||
19e6b90e L |
474 | typedef struct State_Machine_Registers |
475 | { | |
467c65bc | 476 | dwarf_vma address; |
ba8826a8 | 477 | unsigned int view; |
19e6b90e L |
478 | unsigned int file; |
479 | unsigned int line; | |
480 | unsigned int column; | |
481 | int is_stmt; | |
482 | int basic_block; | |
a233b20c JJ |
483 | unsigned char op_index; |
484 | unsigned char end_sequence; | |
ba8826a8 AO |
485 | /* This variable hold the number of the last entry seen |
486 | in the File Table. */ | |
19e6b90e L |
487 | unsigned int last_file_entry; |
488 | } SMR; | |
489 | ||
490 | static SMR state_machine_regs; | |
491 | ||
492 | static void | |
493 | reset_state_machine (int is_stmt) | |
494 | { | |
495 | state_machine_regs.address = 0; | |
ba8826a8 | 496 | state_machine_regs.view = 0; |
a233b20c | 497 | state_machine_regs.op_index = 0; |
19e6b90e L |
498 | state_machine_regs.file = 1; |
499 | state_machine_regs.line = 1; | |
500 | state_machine_regs.column = 0; | |
501 | state_machine_regs.is_stmt = is_stmt; | |
502 | state_machine_regs.basic_block = 0; | |
503 | state_machine_regs.end_sequence = 0; | |
504 | state_machine_regs.last_file_entry = 0; | |
505 | } | |
506 | ||
507 | /* Handled an extend line op. | |
508 | Returns the number of bytes read. */ | |
509 | ||
cd30bcef | 510 | static size_t |
f6f0e17b NC |
511 | process_extended_line_op (unsigned char * data, |
512 | int is_stmt, | |
513 | unsigned char * end) | |
19e6b90e L |
514 | { |
515 | unsigned char op_code; | |
cd30bcef | 516 | size_t len, header_len; |
19e6b90e | 517 | unsigned char *name; |
143a3db0 | 518 | unsigned char *orig_data = data; |
cd30bcef | 519 | dwarf_vma adr, val; |
19e6b90e | 520 | |
cd30bcef AM |
521 | READ_ULEB (len, data, end); |
522 | header_len = data - orig_data; | |
19e6b90e | 523 | |
cd30bcef | 524 | if (len == 0 || data == end || len > (size_t) (end - data)) |
19e6b90e | 525 | { |
f41e4712 | 526 | warn (_("Badly formed extended line op encountered!\n")); |
cd30bcef | 527 | return header_len; |
19e6b90e L |
528 | } |
529 | ||
19e6b90e L |
530 | op_code = *data++; |
531 | ||
532 | printf (_(" Extended opcode %d: "), op_code); | |
533 | ||
534 | switch (op_code) | |
535 | { | |
536 | case DW_LNE_end_sequence: | |
537 | printf (_("End of Sequence\n\n")); | |
538 | reset_state_machine (is_stmt); | |
539 | break; | |
540 | ||
541 | case DW_LNE_set_address: | |
6937bb54 | 542 | /* PR 17512: file: 002-100480-0.004. */ |
cd30bcef | 543 | if (len - 1 > 8) |
77ef8654 | 544 | { |
cd30bcef AM |
545 | warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"), |
546 | (unsigned long) len - 1); | |
77ef8654 NC |
547 | adr = 0; |
548 | } | |
549 | else | |
cd30bcef | 550 | SAFE_BYTE_GET (adr, data, len - 1, end); |
47704ddf | 551 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 552 | state_machine_regs.address = adr; |
ba8826a8 | 553 | state_machine_regs.view = 0; |
a233b20c | 554 | state_machine_regs.op_index = 0; |
19e6b90e L |
555 | break; |
556 | ||
557 | case DW_LNE_define_file: | |
143a3db0 | 558 | printf (_("define new File Table entry\n")); |
19e6b90e | 559 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 560 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 561 | |
d949ff56 NC |
562 | { |
563 | size_t l; | |
564 | ||
565 | name = data; | |
566 | l = strnlen ((char *) data, end - data); | |
cd30bcef AM |
567 | data += l + 1; |
568 | READ_ULEB (val, data, end); | |
569 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
570 | READ_ULEB (val, data, end); | |
571 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
572 | READ_ULEB (val, data, end); | |
573 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
d949ff56 NC |
574 | printf ("%.*s\n\n", (int) l, name); |
575 | } | |
f6f0e17b | 576 | |
cd30bcef | 577 | if (((size_t) (data - orig_data) != len + header_len) || data == end) |
b4eb7656 | 578 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
579 | break; |
580 | ||
ed4a4bdf | 581 | case DW_LNE_set_discriminator: |
cd30bcef AM |
582 | READ_ULEB (val, data, end); |
583 | printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val)); | |
ed4a4bdf CC |
584 | break; |
585 | ||
e2a0d921 NC |
586 | /* HP extensions. */ |
587 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 588 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
589 | break; |
590 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 591 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
592 | break; |
593 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 594 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
595 | break; |
596 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 597 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
598 | break; |
599 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 600 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
601 | break; |
602 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 603 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
604 | break; |
605 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 606 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
607 | break; |
608 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 609 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
610 | break; |
611 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 612 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
613 | break; |
614 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 615 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 616 | break; |
43294ab7 TG |
617 | case DW_LNE_HP_source_file_correlation: |
618 | { | |
cd30bcef | 619 | unsigned char *edata = data + len - 1; |
b4eb7656 AM |
620 | |
621 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
622 | ||
623 | while (data < edata) | |
624 | { | |
625 | unsigned int opc; | |
626 | ||
cd30bcef | 627 | READ_ULEB (opc, data, edata); |
b4eb7656 AM |
628 | |
629 | switch (opc) | |
630 | { | |
631 | case DW_LNE_HP_SFC_formfeed: | |
632 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
633 | break; | |
634 | case DW_LNE_HP_SFC_set_listing_line: | |
cd30bcef | 635 | READ_ULEB (val, data, edata); |
b4eb7656 | 636 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", |
cd30bcef | 637 | dwarf_vmatoa ("u", val)); |
b4eb7656 AM |
638 | break; |
639 | case DW_LNE_HP_SFC_associate: | |
640 | printf (" DW_LNE_HP_SFC_associate "); | |
cd30bcef AM |
641 | READ_ULEB (val, data, edata); |
642 | printf ("(%s", dwarf_vmatoa ("u", val)); | |
643 | READ_ULEB (val, data, edata); | |
644 | printf (",%s", dwarf_vmatoa ("u", val)); | |
645 | READ_ULEB (val, data, edata); | |
646 | printf (",%s)\n", dwarf_vmatoa ("u", val)); | |
b4eb7656 AM |
647 | break; |
648 | default: | |
649 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
650 | data = edata; | |
651 | break; | |
652 | } | |
653 | } | |
43294ab7 TG |
654 | } |
655 | break; | |
cecf136e | 656 | |
19e6b90e | 657 | default: |
7e665af3 | 658 | { |
cd30bcef | 659 | unsigned int rlen = len - 1; |
b4eb7656 AM |
660 | |
661 | if (op_code >= DW_LNE_lo_user | |
662 | /* The test against DW_LNW_hi_user is redundant due to | |
663 | the limited range of the unsigned char data type used | |
664 | for op_code. */ | |
665 | /*&& op_code <= DW_LNE_hi_user*/) | |
666 | printf (_("user defined: ")); | |
667 | else | |
668 | printf (_("UNKNOWN: ")); | |
669 | printf (_("length %d ["), rlen); | |
670 | for (; rlen; rlen--) | |
671 | printf (" %02x", *data++); | |
672 | printf ("]\n"); | |
7e665af3 | 673 | } |
19e6b90e L |
674 | break; |
675 | } | |
676 | ||
cd30bcef | 677 | return len + header_len; |
19e6b90e L |
678 | } |
679 | ||
0c588247 | 680 | static const unsigned char * |
467c65bc | 681 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
682 | { |
683 | struct dwarf_section *section = &debug_displays [str].section; | |
d949ff56 | 684 | const unsigned char * ret; |
19e6b90e L |
685 | |
686 | if (section->start == NULL) | |
0c588247 | 687 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e | 688 | |
d949ff56 | 689 | if (offset >= section->size) |
19e6b90e | 690 | { |
d296b736 | 691 | warn (_("DW_FORM_strp offset too big: 0x%s\n"), |
467c65bc | 692 | dwarf_vmatoa ("x", offset)); |
0c588247 | 693 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
694 | } |
695 | ||
d949ff56 NC |
696 | ret = section->start + offset; |
697 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
698 | NUL byte. Since our caller is expecting to receive a well formed C | |
699 | string we test for the lack of a terminating byte here. */ | |
700 | if (strnlen ((const char *) ret, section->size - offset) | |
701 | == section->size - offset) | |
702 | ret = (const unsigned char *) | |
703 | _("<no NUL byte at end of .debug_str section>"); | |
704 | ||
521d4b19 | 705 | return ret; |
19e6b90e L |
706 | } |
707 | ||
77145576 JK |
708 | static const unsigned char * |
709 | fetch_indirect_line_string (dwarf_vma offset) | |
710 | { | |
711 | struct dwarf_section *section = &debug_displays [line_str].section; | |
d949ff56 | 712 | const unsigned char * ret; |
77145576 JK |
713 | |
714 | if (section->start == NULL) | |
715 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
716 | ||
d949ff56 | 717 | if (offset >= section->size) |
77145576 | 718 | { |
d296b736 | 719 | warn (_("DW_FORM_line_strp offset too big: 0x%s\n"), |
77145576 JK |
720 | dwarf_vmatoa ("x", offset)); |
721 | return (const unsigned char *) _("<offset is too big>"); | |
722 | } | |
723 | ||
d949ff56 NC |
724 | ret = section->start + offset; |
725 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
726 | with a NUL byte. Since our caller is expecting to receive a well formed | |
727 | C string we test for the lack of a terminating byte here. */ | |
728 | if (strnlen ((const char *) ret, section->size - offset) | |
729 | == section->size - offset) | |
730 | ret = (const unsigned char *) | |
731 | _("<no NUL byte at end of .debug_line_str section>"); | |
732 | ||
733 | return ret; | |
77145576 JK |
734 | } |
735 | ||
4723351a | 736 | static const char * |
341f9135 | 737 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
015dc7e1 | 738 | dwarf_vma offset_size, bool dwo) |
4723351a CC |
739 | { |
740 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
741 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
742 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
743 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
e4b7104b | 744 | dwarf_vma index_offset; |
4723351a | 745 | dwarf_vma str_offset; |
d949ff56 | 746 | const char * ret; |
e4b7104b NC |
747 | unsigned char *curr = index_section->start; |
748 | const unsigned char *end = curr + index_section->size; | |
749 | dwarf_vma length; | |
4723351a CC |
750 | |
751 | if (index_section->start == NULL) | |
752 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
753 | : _("<no .debug_str_offsets section>")); | |
754 | ||
e4b7104b NC |
755 | if (str_section->start == NULL) |
756 | return (dwo ? _("<no .debug_str.dwo section>") | |
757 | : _("<no .debug_str section>")); | |
758 | ||
759 | /* FIXME: We should cache the length... */ | |
760 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); | |
761 | if (length == 0xffffffff) | |
762 | { | |
763 | if (offset_size != 8) | |
39f381cb | 764 | warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size)); |
e4b7104b NC |
765 | SAFE_BYTE_GET_AND_INC (length, curr, 8, end); |
766 | } | |
767 | else if (offset_size != 4) | |
768 | { | |
39f381cb | 769 | warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size)); |
e4b7104b NC |
770 | } |
771 | ||
39f381cb | 772 | if (length == 0) |
e4b7104b | 773 | { |
39f381cb NC |
774 | /* This is probably an old style .debug_str_offset section which |
775 | just contains offsets and no header (and the first offset is 0). */ | |
776 | curr = index_section->start; | |
777 | length = index_section->size; | |
778 | } | |
779 | else | |
780 | { | |
781 | /* Skip the version and padding bytes. | |
782 | We assume that they are correct. */ | |
783 | curr += 4; | |
784 | ||
785 | /* FIXME: The code below assumes that there is only one table | |
786 | in the .debug_str_offsets section, so check that now. */ | |
787 | if ((offset_size == 4 && curr + length < (end - 8)) | |
788 | || (offset_size == 8 && curr + length < (end - 16))) | |
789 | { | |
790 | warn (_("index table size is too small %s vs %s\n"), | |
791 | dwarf_vmatoa ("x", length), | |
792 | dwarf_vmatoa ("x", index_section->size)); | |
793 | return _("<table too small>"); | |
794 | } | |
e4b7104b NC |
795 | } |
796 | ||
797 | index_offset = idx * offset_size; | |
521d4b19 | 798 | |
341f9135 CC |
799 | if (this_set != NULL) |
800 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
e4b7104b NC |
801 | |
802 | if (index_offset >= length) | |
4723351a | 803 | { |
d296b736 | 804 | warn (_("DW_FORM_GNU_str_index offset too big: 0x%s vs 0x%s\n"), |
e4b7104b NC |
805 | dwarf_vmatoa ("x", index_offset), |
806 | dwarf_vmatoa ("x", length)); | |
4723351a CC |
807 | return _("<index offset is too big>"); |
808 | } | |
809 | ||
e4b7104b | 810 | str_offset = byte_get (curr + index_offset, offset_size); |
4723351a | 811 | str_offset -= str_section->address; |
d949ff56 | 812 | if (str_offset >= str_section->size) |
4723351a | 813 | { |
d296b736 | 814 | warn (_("DW_FORM_GNU_str_index indirect offset too big: 0x%s\n"), |
4723351a CC |
815 | dwarf_vmatoa ("x", str_offset)); |
816 | return _("<indirect index offset is too big>"); | |
817 | } | |
818 | ||
d949ff56 NC |
819 | ret = (const char *) str_section->start + str_offset; |
820 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. | |
821 | Since our caller is expecting to receive a well formed C string we test | |
822 | for the lack of a terminating byte here. */ | |
823 | if (strnlen (ret, str_section->size - str_offset) | |
824 | == str_section->size - str_offset) | |
825 | ret = (const char *) _("<no NUL byte at end of section>"); | |
826 | ||
827 | return ret; | |
4723351a CC |
828 | } |
829 | ||
830 | static const char * | |
831 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
832 | { | |
833 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
834 | ||
835 | if (section->start == NULL) | |
836 | return (_("<no .debug_addr section>")); | |
837 | ||
838 | if (offset + bytes > section->size) | |
839 | { | |
d296b736 | 840 | warn (_("Offset into section %s too big: 0x%s\n"), |
b4eb7656 | 841 | section->name, dwarf_vmatoa ("x", offset)); |
4723351a CC |
842 | return "<offset too big>"; |
843 | } | |
844 | ||
845 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
846 | } | |
847 | ||
848 | ||
19e6b90e L |
849 | /* FIXME: There are better and more efficient ways to handle |
850 | these structures. For now though, I just want something that | |
851 | is simple to implement. */ | |
bcd213b2 | 852 | /* Records a single attribute in an abbrev. */ |
19e6b90e L |
853 | typedef struct abbrev_attr |
854 | { | |
bcd213b2 NC |
855 | unsigned long attribute; |
856 | unsigned long form; | |
857 | bfd_signed_vma implicit_const; | |
858 | struct abbrev_attr * next; | |
19e6b90e L |
859 | } |
860 | abbrev_attr; | |
861 | ||
bcd213b2 | 862 | /* Records a single abbrev. */ |
19e6b90e L |
863 | typedef struct abbrev_entry |
864 | { | |
bcd213b2 NC |
865 | unsigned long number; |
866 | unsigned long tag; | |
867 | int children; | |
868 | struct abbrev_attr * first_attr; | |
869 | struct abbrev_attr * last_attr; | |
870 | struct abbrev_entry * next; | |
19e6b90e L |
871 | } |
872 | abbrev_entry; | |
873 | ||
bcd213b2 NC |
874 | /* Records a set of abbreviations. */ |
875 | typedef struct abbrev_list | |
876 | { | |
877 | abbrev_entry * first_abbrev; | |
878 | abbrev_entry * last_abbrev; | |
76868f36 | 879 | dwarf_vma abbrev_base; |
bcd213b2 NC |
880 | dwarf_vma abbrev_offset; |
881 | struct abbrev_list * next; | |
882 | unsigned char * start_of_next_abbrevs; | |
883 | } | |
884 | abbrev_list; | |
885 | ||
886 | /* Records all the abbrevs found so far. */ | |
887 | static struct abbrev_list * abbrev_lists = NULL; | |
888 | ||
889 | typedef struct abbrev_map | |
890 | { | |
891 | dwarf_vma start; | |
892 | dwarf_vma end; | |
893 | abbrev_list * list; | |
894 | } abbrev_map; | |
895 | ||
896 | /* Maps between CU offsets and abbrev sets. */ | |
897 | static abbrev_map * cu_abbrev_map = NULL; | |
898 | static unsigned long num_abbrev_map_entries = 0; | |
899 | static unsigned long next_free_abbrev_map_entry = 0; | |
900 | ||
901 | #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8 | |
902 | #define ABBREV_MAP_ENTRIES_INCREMENT 8 | |
903 | ||
904 | static void | |
905 | record_abbrev_list_for_cu (dwarf_vma start, dwarf_vma end, abbrev_list * list) | |
906 | { | |
907 | if (cu_abbrev_map == NULL) | |
908 | { | |
909 | num_abbrev_map_entries = INITIAL_NUM_ABBREV_MAP_ENTRIES; | |
910 | cu_abbrev_map = xmalloc (num_abbrev_map_entries * sizeof (* cu_abbrev_map)); | |
911 | } | |
912 | else if (next_free_abbrev_map_entry == num_abbrev_map_entries) | |
913 | { | |
914 | num_abbrev_map_entries += ABBREV_MAP_ENTRIES_INCREMENT; | |
915 | cu_abbrev_map = xrealloc (cu_abbrev_map, num_abbrev_map_entries * sizeof (* cu_abbrev_map)); | |
916 | } | |
917 | ||
918 | cu_abbrev_map[next_free_abbrev_map_entry].start = start; | |
919 | cu_abbrev_map[next_free_abbrev_map_entry].end = end; | |
920 | cu_abbrev_map[next_free_abbrev_map_entry].list = list; | |
921 | next_free_abbrev_map_entry ++; | |
922 | } | |
19e6b90e L |
923 | |
924 | static void | |
bcd213b2 | 925 | free_all_abbrevs (void) |
19e6b90e | 926 | { |
bcd213b2 | 927 | abbrev_list * list; |
19e6b90e | 928 | |
bcd213b2 | 929 | for (list = abbrev_lists; list != NULL;) |
19e6b90e | 930 | { |
bcd213b2 NC |
931 | abbrev_list * next = list->next; |
932 | abbrev_entry * abbrv; | |
19e6b90e | 933 | |
bcd213b2 | 934 | for (abbrv = list->first_abbrev; abbrv != NULL;) |
19e6b90e | 935 | { |
bcd213b2 NC |
936 | abbrev_entry * next_abbrev = abbrv->next; |
937 | abbrev_attr * attr; | |
938 | ||
939 | for (attr = abbrv->first_attr; attr;) | |
940 | { | |
941 | abbrev_attr *next_attr = attr->next; | |
19e6b90e | 942 | |
bcd213b2 NC |
943 | free (attr); |
944 | attr = next_attr; | |
945 | } | |
946 | ||
947 | free (abbrv); | |
948 | abbrv = next_abbrev; | |
19e6b90e L |
949 | } |
950 | ||
bcd213b2 NC |
951 | free (list); |
952 | list = next; | |
19e6b90e L |
953 | } |
954 | ||
bcd213b2 NC |
955 | abbrev_lists = NULL; |
956 | } | |
957 | ||
958 | static abbrev_list * | |
76868f36 | 959 | new_abbrev_list (dwarf_vma abbrev_base, dwarf_vma abbrev_offset) |
bcd213b2 NC |
960 | { |
961 | abbrev_list * list = (abbrev_list *) xcalloc (sizeof * list, 1); | |
962 | ||
76868f36 | 963 | list->abbrev_base = abbrev_base; |
bcd213b2 NC |
964 | list->abbrev_offset = abbrev_offset; |
965 | ||
966 | list->next = abbrev_lists; | |
967 | abbrev_lists = list; | |
968 | ||
969 | return list; | |
970 | } | |
971 | ||
972 | static abbrev_list * | |
76868f36 L |
973 | find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base, |
974 | dwarf_vma abbrev_offset) | |
bcd213b2 NC |
975 | { |
976 | abbrev_list * list; | |
977 | ||
978 | for (list = abbrev_lists; list != NULL; list = list->next) | |
76868f36 L |
979 | if (list->abbrev_base == abbrev_base |
980 | && list->abbrev_offset == abbrev_offset) | |
bcd213b2 NC |
981 | return list; |
982 | ||
983 | return NULL; | |
984 | } | |
985 | ||
986 | /* Find the abbreviation map for the CU that includes OFFSET. | |
987 | OFFSET is an absolute offset from the start of the .debug_info section. */ | |
988 | /* FIXME: This function is going to slow down readelf & objdump. | |
989 | Consider using a better algorithm to mitigate this effect. */ | |
990 | ||
991 | static abbrev_map * | |
992 | find_abbrev_map_by_offset (dwarf_vma offset) | |
993 | { | |
994 | unsigned long i; | |
995 | ||
996 | for (i = 0; i < next_free_abbrev_map_entry; i++) | |
997 | if (cu_abbrev_map[i].start <= offset | |
998 | && cu_abbrev_map[i].end > offset) | |
999 | return cu_abbrev_map + i; | |
1000 | ||
1001 | return NULL; | |
19e6b90e L |
1002 | } |
1003 | ||
1004 | static void | |
bcd213b2 NC |
1005 | add_abbrev (unsigned long number, |
1006 | unsigned long tag, | |
1007 | int children, | |
1008 | abbrev_list * list) | |
19e6b90e | 1009 | { |
bcd213b2 | 1010 | abbrev_entry * entry; |
19e6b90e | 1011 | |
bcd213b2 | 1012 | entry = (abbrev_entry *) xmalloc (sizeof (*entry)); |
19e6b90e | 1013 | |
bcd213b2 | 1014 | entry->number = number; |
19e6b90e L |
1015 | entry->tag = tag; |
1016 | entry->children = children; | |
1017 | entry->first_attr = NULL; | |
1018 | entry->last_attr = NULL; | |
1019 | entry->next = NULL; | |
1020 | ||
bcd213b2 NC |
1021 | assert (list != NULL); |
1022 | ||
1023 | if (list->first_abbrev == NULL) | |
1024 | list->first_abbrev = entry; | |
19e6b90e | 1025 | else |
bcd213b2 | 1026 | list->last_abbrev->next = entry; |
19e6b90e | 1027 | |
bcd213b2 | 1028 | list->last_abbrev = entry; |
19e6b90e L |
1029 | } |
1030 | ||
1031 | static void | |
bcd213b2 NC |
1032 | add_abbrev_attr (unsigned long attribute, |
1033 | unsigned long form, | |
1034 | bfd_signed_vma implicit_const, | |
1035 | abbrev_list * list) | |
19e6b90e L |
1036 | { |
1037 | abbrev_attr *attr; | |
1038 | ||
bcd213b2 | 1039 | attr = (abbrev_attr *) xmalloc (sizeof (*attr)); |
19e6b90e L |
1040 | |
1041 | attr->attribute = attribute; | |
1042 | attr->form = form; | |
77145576 | 1043 | attr->implicit_const = implicit_const; |
19e6b90e L |
1044 | attr->next = NULL; |
1045 | ||
bcd213b2 NC |
1046 | assert (list != NULL && list->last_abbrev != NULL); |
1047 | ||
1048 | if (list->last_abbrev->first_attr == NULL) | |
1049 | list->last_abbrev->first_attr = attr; | |
19e6b90e | 1050 | else |
bcd213b2 | 1051 | list->last_abbrev->last_attr->next = attr; |
19e6b90e | 1052 | |
bcd213b2 | 1053 | list->last_abbrev->last_attr = attr; |
19e6b90e L |
1054 | } |
1055 | ||
1056 | /* Processes the (partial) contents of a .debug_abbrev section. | |
1057 | Returns NULL if the end of the section was encountered. | |
1058 | Returns the address after the last byte read if the end of | |
1059 | an abbreviation set was found. */ | |
1060 | ||
1061 | static unsigned char * | |
bcd213b2 NC |
1062 | process_abbrev_set (unsigned char * start, |
1063 | const unsigned char * end, | |
1064 | abbrev_list * list) | |
19e6b90e | 1065 | { |
19e6b90e L |
1066 | while (start < end) |
1067 | { | |
19e6b90e L |
1068 | unsigned long entry; |
1069 | unsigned long tag; | |
1070 | unsigned long attribute; | |
1071 | int children; | |
1072 | ||
cd30bcef | 1073 | READ_ULEB (entry, start, end); |
19e6b90e | 1074 | |
bcd213b2 | 1075 | /* A single zero is supposed to end the set according |
19e6b90e L |
1076 | to the standard. If there's more, then signal that to |
1077 | the caller. */ | |
f6f0e17b NC |
1078 | if (start == end) |
1079 | return NULL; | |
19e6b90e | 1080 | if (entry == 0) |
f6f0e17b | 1081 | return start; |
19e6b90e | 1082 | |
cd30bcef | 1083 | READ_ULEB (tag, start, end); |
f6f0e17b NC |
1084 | if (start == end) |
1085 | return NULL; | |
19e6b90e L |
1086 | |
1087 | children = *start++; | |
1088 | ||
bcd213b2 | 1089 | add_abbrev (entry, tag, children, list); |
19e6b90e L |
1090 | |
1091 | do | |
1092 | { | |
1093 | unsigned long form; | |
77145576 JK |
1094 | /* Initialize it due to a false compiler warning. */ |
1095 | bfd_signed_vma implicit_const = -1; | |
19e6b90e | 1096 | |
cd30bcef | 1097 | READ_ULEB (attribute, start, end); |
f6f0e17b NC |
1098 | if (start == end) |
1099 | break; | |
19e6b90e | 1100 | |
cd30bcef | 1101 | READ_ULEB (form, start, end); |
f6f0e17b NC |
1102 | if (start == end) |
1103 | break; | |
19e6b90e | 1104 | |
77145576 JK |
1105 | if (form == DW_FORM_implicit_const) |
1106 | { | |
cd30bcef | 1107 | READ_SLEB (implicit_const, start, end); |
77145576 JK |
1108 | if (start == end) |
1109 | break; | |
1110 | } | |
1111 | ||
bcd213b2 | 1112 | add_abbrev_attr (attribute, form, implicit_const, list); |
19e6b90e L |
1113 | } |
1114 | while (attribute != 0); | |
1115 | } | |
1116 | ||
399c99f7 L |
1117 | /* Report the missing single zero which ends the section. */ |
1118 | error (_(".debug_abbrev section not zero terminated\n")); | |
1119 | ||
19e6b90e L |
1120 | return NULL; |
1121 | } | |
1122 | ||
a19c41a7 | 1123 | static const char * |
19e6b90e L |
1124 | get_TAG_name (unsigned long tag) |
1125 | { | |
04914e37 | 1126 | const char *name = get_DW_TAG_name ((unsigned int) tag); |
a19c41a7 TT |
1127 | |
1128 | if (name == NULL) | |
19e6b90e | 1129 | { |
a19c41a7 | 1130 | static char buffer[100]; |
19e6b90e | 1131 | |
04914e37 NC |
1132 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
1133 | snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag); | |
1134 | else | |
1135 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag); | |
a19c41a7 | 1136 | return buffer; |
19e6b90e | 1137 | } |
a19c41a7 TT |
1138 | |
1139 | return name; | |
19e6b90e L |
1140 | } |
1141 | ||
a19c41a7 | 1142 | static const char * |
19e6b90e L |
1143 | get_FORM_name (unsigned long form) |
1144 | { | |
399c99f7 | 1145 | const char *name; |
bf5117e3 | 1146 | |
399c99f7 L |
1147 | if (form == 0) |
1148 | return "DW_FORM value: 0"; | |
a19c41a7 | 1149 | |
399c99f7 | 1150 | name = get_DW_FORM_name (form); |
a19c41a7 | 1151 | if (name == NULL) |
19e6b90e | 1152 | { |
a19c41a7 | 1153 | static char buffer[100]; |
19e6b90e | 1154 | |
a19c41a7 TT |
1155 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
1156 | return buffer; | |
19e6b90e | 1157 | } |
a19c41a7 TT |
1158 | |
1159 | return name; | |
19e6b90e L |
1160 | } |
1161 | ||
61364358 JK |
1162 | static const char * |
1163 | get_IDX_name (unsigned long idx) | |
1164 | { | |
1165 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
1166 | ||
1167 | if (name == NULL) | |
1168 | { | |
1169 | static char buffer[100]; | |
1170 | ||
1171 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1172 | return buffer; | |
1173 | } | |
1174 | ||
1175 | return name; | |
1176 | } | |
1177 | ||
19e6b90e | 1178 | static unsigned char * |
0c588247 NC |
1179 | display_block (unsigned char *data, |
1180 | dwarf_vma length, | |
ef0b5f1c | 1181 | const unsigned char * const end, char delimiter) |
19e6b90e | 1182 | { |
0c588247 NC |
1183 | dwarf_vma maxlen; |
1184 | ||
ef0b5f1c | 1185 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
1186 | if (data > end) |
1187 | return (unsigned char *) end; | |
19e6b90e | 1188 | |
0c588247 NC |
1189 | maxlen = (dwarf_vma) (end - data); |
1190 | length = length > maxlen ? maxlen : length; | |
1191 | ||
19e6b90e L |
1192 | while (length --) |
1193 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1194 | ||
1195 | return data; | |
1196 | } | |
1197 | ||
1198 | static int | |
1199 | decode_location_expression (unsigned char * data, | |
1200 | unsigned int pointer_size, | |
b7807392 JJ |
1201 | unsigned int offset_size, |
1202 | int dwarf_version, | |
467c65bc NC |
1203 | dwarf_vma length, |
1204 | dwarf_vma cu_offset, | |
f1c4cc75 | 1205 | struct dwarf_section * section) |
19e6b90e L |
1206 | { |
1207 | unsigned op; | |
467c65bc | 1208 | dwarf_vma uvalue; |
0c588247 | 1209 | dwarf_signed_vma svalue; |
19e6b90e L |
1210 | unsigned char *end = data + length; |
1211 | int need_frame_base = 0; | |
1212 | ||
1213 | while (data < end) | |
1214 | { | |
1215 | op = *data++; | |
1216 | ||
1217 | switch (op) | |
1218 | { | |
1219 | case DW_OP_addr: | |
0c588247 NC |
1220 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1221 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1222 | break; |
1223 | case DW_OP_deref: | |
1224 | printf ("DW_OP_deref"); | |
1225 | break; | |
1226 | case DW_OP_const1u: | |
0c588247 NC |
1227 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1228 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1229 | break; |
1230 | case DW_OP_const1s: | |
0c588247 NC |
1231 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1232 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1233 | break; |
1234 | case DW_OP_const2u: | |
87bc83b3 | 1235 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1236 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1237 | break; |
1238 | case DW_OP_const2s: | |
0c588247 NC |
1239 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1240 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1241 | break; |
1242 | case DW_OP_const4u: | |
0c588247 NC |
1243 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1244 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1245 | break; |
1246 | case DW_OP_const4s: | |
0c588247 NC |
1247 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1248 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1249 | break; |
1250 | case DW_OP_const8u: | |
0c588247 NC |
1251 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1252 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1253 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1254 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1255 | break; |
1256 | case DW_OP_const8s: | |
0c588247 NC |
1257 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1258 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1259 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1260 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1261 | break; |
1262 | case DW_OP_constu: | |
cd30bcef AM |
1263 | READ_ULEB (uvalue, data, end); |
1264 | printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1265 | break; |
1266 | case DW_OP_consts: | |
cd30bcef AM |
1267 | READ_SLEB (svalue, data, end); |
1268 | printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1269 | break; |
1270 | case DW_OP_dup: | |
1271 | printf ("DW_OP_dup"); | |
1272 | break; | |
1273 | case DW_OP_drop: | |
1274 | printf ("DW_OP_drop"); | |
1275 | break; | |
1276 | case DW_OP_over: | |
1277 | printf ("DW_OP_over"); | |
1278 | break; | |
1279 | case DW_OP_pick: | |
0c588247 NC |
1280 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1281 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1282 | break; |
1283 | case DW_OP_swap: | |
1284 | printf ("DW_OP_swap"); | |
1285 | break; | |
1286 | case DW_OP_rot: | |
1287 | printf ("DW_OP_rot"); | |
1288 | break; | |
1289 | case DW_OP_xderef: | |
1290 | printf ("DW_OP_xderef"); | |
1291 | break; | |
1292 | case DW_OP_abs: | |
1293 | printf ("DW_OP_abs"); | |
1294 | break; | |
1295 | case DW_OP_and: | |
1296 | printf ("DW_OP_and"); | |
1297 | break; | |
1298 | case DW_OP_div: | |
1299 | printf ("DW_OP_div"); | |
1300 | break; | |
1301 | case DW_OP_minus: | |
1302 | printf ("DW_OP_minus"); | |
1303 | break; | |
1304 | case DW_OP_mod: | |
1305 | printf ("DW_OP_mod"); | |
1306 | break; | |
1307 | case DW_OP_mul: | |
1308 | printf ("DW_OP_mul"); | |
1309 | break; | |
1310 | case DW_OP_neg: | |
1311 | printf ("DW_OP_neg"); | |
1312 | break; | |
1313 | case DW_OP_not: | |
1314 | printf ("DW_OP_not"); | |
1315 | break; | |
1316 | case DW_OP_or: | |
1317 | printf ("DW_OP_or"); | |
1318 | break; | |
1319 | case DW_OP_plus: | |
1320 | printf ("DW_OP_plus"); | |
1321 | break; | |
1322 | case DW_OP_plus_uconst: | |
cd30bcef AM |
1323 | READ_ULEB (uvalue, data, end); |
1324 | printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1325 | break; |
1326 | case DW_OP_shl: | |
1327 | printf ("DW_OP_shl"); | |
1328 | break; | |
1329 | case DW_OP_shr: | |
1330 | printf ("DW_OP_shr"); | |
1331 | break; | |
1332 | case DW_OP_shra: | |
1333 | printf ("DW_OP_shra"); | |
1334 | break; | |
1335 | case DW_OP_xor: | |
1336 | printf ("DW_OP_xor"); | |
1337 | break; | |
1338 | case DW_OP_bra: | |
0c588247 NC |
1339 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1340 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1341 | break; |
1342 | case DW_OP_eq: | |
1343 | printf ("DW_OP_eq"); | |
1344 | break; | |
1345 | case DW_OP_ge: | |
1346 | printf ("DW_OP_ge"); | |
1347 | break; | |
1348 | case DW_OP_gt: | |
1349 | printf ("DW_OP_gt"); | |
1350 | break; | |
1351 | case DW_OP_le: | |
1352 | printf ("DW_OP_le"); | |
1353 | break; | |
1354 | case DW_OP_lt: | |
1355 | printf ("DW_OP_lt"); | |
1356 | break; | |
1357 | case DW_OP_ne: | |
1358 | printf ("DW_OP_ne"); | |
1359 | break; | |
1360 | case DW_OP_skip: | |
0c588247 NC |
1361 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1362 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1363 | break; |
1364 | ||
1365 | case DW_OP_lit0: | |
1366 | case DW_OP_lit1: | |
1367 | case DW_OP_lit2: | |
1368 | case DW_OP_lit3: | |
1369 | case DW_OP_lit4: | |
1370 | case DW_OP_lit5: | |
1371 | case DW_OP_lit6: | |
1372 | case DW_OP_lit7: | |
1373 | case DW_OP_lit8: | |
1374 | case DW_OP_lit9: | |
1375 | case DW_OP_lit10: | |
1376 | case DW_OP_lit11: | |
1377 | case DW_OP_lit12: | |
1378 | case DW_OP_lit13: | |
1379 | case DW_OP_lit14: | |
1380 | case DW_OP_lit15: | |
1381 | case DW_OP_lit16: | |
1382 | case DW_OP_lit17: | |
1383 | case DW_OP_lit18: | |
1384 | case DW_OP_lit19: | |
1385 | case DW_OP_lit20: | |
1386 | case DW_OP_lit21: | |
1387 | case DW_OP_lit22: | |
1388 | case DW_OP_lit23: | |
1389 | case DW_OP_lit24: | |
1390 | case DW_OP_lit25: | |
1391 | case DW_OP_lit26: | |
1392 | case DW_OP_lit27: | |
1393 | case DW_OP_lit28: | |
1394 | case DW_OP_lit29: | |
1395 | case DW_OP_lit30: | |
1396 | case DW_OP_lit31: | |
1397 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1398 | break; | |
1399 | ||
1400 | case DW_OP_reg0: | |
1401 | case DW_OP_reg1: | |
1402 | case DW_OP_reg2: | |
1403 | case DW_OP_reg3: | |
1404 | case DW_OP_reg4: | |
1405 | case DW_OP_reg5: | |
1406 | case DW_OP_reg6: | |
1407 | case DW_OP_reg7: | |
1408 | case DW_OP_reg8: | |
1409 | case DW_OP_reg9: | |
1410 | case DW_OP_reg10: | |
1411 | case DW_OP_reg11: | |
1412 | case DW_OP_reg12: | |
1413 | case DW_OP_reg13: | |
1414 | case DW_OP_reg14: | |
1415 | case DW_OP_reg15: | |
1416 | case DW_OP_reg16: | |
1417 | case DW_OP_reg17: | |
1418 | case DW_OP_reg18: | |
1419 | case DW_OP_reg19: | |
1420 | case DW_OP_reg20: | |
1421 | case DW_OP_reg21: | |
1422 | case DW_OP_reg22: | |
1423 | case DW_OP_reg23: | |
1424 | case DW_OP_reg24: | |
1425 | case DW_OP_reg25: | |
1426 | case DW_OP_reg26: | |
1427 | case DW_OP_reg27: | |
1428 | case DW_OP_reg28: | |
1429 | case DW_OP_reg29: | |
1430 | case DW_OP_reg30: | |
1431 | case DW_OP_reg31: | |
18464d4d JK |
1432 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1433 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1434 | break; |
1435 | ||
1436 | case DW_OP_breg0: | |
1437 | case DW_OP_breg1: | |
1438 | case DW_OP_breg2: | |
1439 | case DW_OP_breg3: | |
1440 | case DW_OP_breg4: | |
1441 | case DW_OP_breg5: | |
1442 | case DW_OP_breg6: | |
1443 | case DW_OP_breg7: | |
1444 | case DW_OP_breg8: | |
1445 | case DW_OP_breg9: | |
1446 | case DW_OP_breg10: | |
1447 | case DW_OP_breg11: | |
1448 | case DW_OP_breg12: | |
1449 | case DW_OP_breg13: | |
1450 | case DW_OP_breg14: | |
1451 | case DW_OP_breg15: | |
1452 | case DW_OP_breg16: | |
1453 | case DW_OP_breg17: | |
1454 | case DW_OP_breg18: | |
1455 | case DW_OP_breg19: | |
1456 | case DW_OP_breg20: | |
1457 | case DW_OP_breg21: | |
1458 | case DW_OP_breg22: | |
1459 | case DW_OP_breg23: | |
1460 | case DW_OP_breg24: | |
1461 | case DW_OP_breg25: | |
1462 | case DW_OP_breg26: | |
1463 | case DW_OP_breg27: | |
1464 | case DW_OP_breg28: | |
1465 | case DW_OP_breg29: | |
1466 | case DW_OP_breg30: | |
1467 | case DW_OP_breg31: | |
cd30bcef AM |
1468 | READ_SLEB (svalue, data, end); |
1469 | printf ("DW_OP_breg%d (%s): %s", op - DW_OP_breg0, | |
1470 | regname (op - DW_OP_breg0, 1), dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1471 | break; |
1472 | ||
1473 | case DW_OP_regx: | |
cd30bcef | 1474 | READ_ULEB (uvalue, data, end); |
467c65bc NC |
1475 | printf ("DW_OP_regx: %s (%s)", |
1476 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1477 | break; |
1478 | case DW_OP_fbreg: | |
1479 | need_frame_base = 1; | |
cd30bcef AM |
1480 | READ_SLEB (svalue, data, end); |
1481 | printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1482 | break; |
1483 | case DW_OP_bregx: | |
cd30bcef AM |
1484 | READ_ULEB (uvalue, data, end); |
1485 | READ_SLEB (svalue, data, end); | |
467c65bc NC |
1486 | printf ("DW_OP_bregx: %s (%s) %s", |
1487 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
cd30bcef | 1488 | dwarf_vmatoa ("d", svalue)); |
19e6b90e L |
1489 | break; |
1490 | case DW_OP_piece: | |
cd30bcef AM |
1491 | READ_ULEB (uvalue, data, end); |
1492 | printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1493 | break; |
1494 | case DW_OP_deref_size: | |
0c588247 NC |
1495 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1496 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1497 | break; |
1498 | case DW_OP_xderef_size: | |
0c588247 NC |
1499 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1500 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1501 | break; |
1502 | case DW_OP_nop: | |
1503 | printf ("DW_OP_nop"); | |
1504 | break; | |
1505 | ||
1506 | /* DWARF 3 extensions. */ | |
1507 | case DW_OP_push_object_address: | |
1508 | printf ("DW_OP_push_object_address"); | |
1509 | break; | |
1510 | case DW_OP_call2: | |
d85bf2ba | 1511 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1512 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1513 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1514 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1515 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1516 | break; |
1517 | case DW_OP_call4: | |
d85bf2ba | 1518 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1519 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1520 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1521 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1522 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1523 | break; |
1524 | case DW_OP_call_ref: | |
d85bf2ba | 1525 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
e2a0d921 | 1526 | this ought to be an 8-byte wide computation. */ |
b7807392 JJ |
1527 | if (dwarf_version == -1) |
1528 | { | |
1529 | printf (_("(DW_OP_call_ref in frame info)")); | |
1530 | /* No way to tell where the next op is, so just bail. */ | |
1531 | return need_frame_base; | |
1532 | } | |
1533 | if (dwarf_version == 2) | |
1534 | { | |
0c588247 | 1535 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1536 | } |
1537 | else | |
1538 | { | |
0c588247 | 1539 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1540 | } |
0c588247 | 1541 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1542 | break; |
a87b0a59 NS |
1543 | case DW_OP_form_tls_address: |
1544 | printf ("DW_OP_form_tls_address"); | |
1545 | break; | |
e2a0d921 NC |
1546 | case DW_OP_call_frame_cfa: |
1547 | printf ("DW_OP_call_frame_cfa"); | |
1548 | break; | |
1549 | case DW_OP_bit_piece: | |
1550 | printf ("DW_OP_bit_piece: "); | |
cd30bcef AM |
1551 | READ_ULEB (uvalue, data, end); |
1552 | printf (_("size: %s "), dwarf_vmatoa ("u", uvalue)); | |
1553 | READ_ULEB (uvalue, data, end); | |
1554 | printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue)); | |
e2a0d921 | 1555 | break; |
19e6b90e | 1556 | |
3244e8f5 JJ |
1557 | /* DWARF 4 extensions. */ |
1558 | case DW_OP_stack_value: | |
1559 | printf ("DW_OP_stack_value"); | |
1560 | break; | |
1561 | ||
1562 | case DW_OP_implicit_value: | |
1563 | printf ("DW_OP_implicit_value"); | |
cd30bcef | 1564 | READ_ULEB (uvalue, data, end); |
ef0b5f1c | 1565 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1566 | break; |
1567 | ||
19e6b90e L |
1568 | /* GNU extensions. */ |
1569 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1570 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1571 | break; |
1572 | case DW_OP_GNU_uninit: | |
1573 | printf ("DW_OP_GNU_uninit"); | |
1574 | /* FIXME: Is there data associated with this OP ? */ | |
1575 | break; | |
f1c4cc75 RH |
1576 | case DW_OP_GNU_encoded_addr: |
1577 | { | |
6937bb54 | 1578 | int encoding = 0; |
f1c4cc75 | 1579 | dwarf_vma addr; |
467c65bc | 1580 | |
6937bb54 NC |
1581 | if (data < end) |
1582 | encoding = *data++; | |
041830e0 | 1583 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1584 | |
1585 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1586 | print_dwarf_vma (addr, pointer_size); | |
1587 | } | |
1588 | break; | |
bc0a77d2 | 1589 | case DW_OP_implicit_pointer: |
b7807392 | 1590 | case DW_OP_GNU_implicit_pointer: |
d85bf2ba | 1591 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
b7807392 JJ |
1592 | this ought to be an 8-byte wide computation. */ |
1593 | if (dwarf_version == -1) | |
1594 | { | |
bc0a77d2 JK |
1595 | printf (_("(%s in frame info)"), |
1596 | (op == DW_OP_implicit_pointer | |
1597 | ? "DW_OP_implicit_pointer" | |
1598 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1599 | /* No way to tell where the next op is, so just bail. */ |
1600 | return need_frame_base; | |
1601 | } | |
1602 | if (dwarf_version == 2) | |
1603 | { | |
0c588247 | 1604 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1605 | } |
1606 | else | |
1607 | { | |
0c588247 | 1608 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1609 | } |
cd30bcef | 1610 | READ_SLEB (svalue, data, end); |
bc0a77d2 JK |
1611 | printf ("%s: <0x%s> %s", |
1612 | (op == DW_OP_implicit_pointer | |
1613 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 | 1614 | dwarf_vmatoa ("x", uvalue), |
cd30bcef | 1615 | dwarf_vmatoa ("d", svalue)); |
b7807392 | 1616 | break; |
77145576 | 1617 | case DW_OP_entry_value: |
0892011d | 1618 | case DW_OP_GNU_entry_value: |
cd30bcef | 1619 | READ_ULEB (uvalue, data, end); |
058037d3 NC |
1620 | /* PR 17531: file: 0cc9cd00. */ |
1621 | if (uvalue > (dwarf_vma) (end - data)) | |
1622 | uvalue = end - data; | |
77145576 JK |
1623 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1624 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1625 | if (decode_location_expression (data, pointer_size, offset_size, |
1626 | dwarf_version, uvalue, | |
1627 | cu_offset, section)) | |
1628 | need_frame_base = 1; | |
1629 | putchar (')'); | |
1630 | data += uvalue; | |
6937bb54 NC |
1631 | if (data > end) |
1632 | data = end; | |
0892011d | 1633 | break; |
bc0a77d2 | 1634 | case DW_OP_const_type: |
0892011d | 1635 | case DW_OP_GNU_const_type: |
cd30bcef | 1636 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1637 | printf ("%s: <0x%s> ", |
1638 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1639 | : "DW_OP_GNU_const_type"), | |
0892011d | 1640 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1641 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1642 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1643 | break; |
bc0a77d2 | 1644 | case DW_OP_regval_type: |
0892011d | 1645 | case DW_OP_GNU_regval_type: |
cd30bcef | 1646 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1647 | printf ("%s: %s (%s)", |
1648 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1649 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1650 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
cd30bcef | 1651 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1652 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1653 | break; | |
bc0a77d2 | 1654 | case DW_OP_deref_type: |
0892011d | 1655 | case DW_OP_GNU_deref_type: |
0c588247 | 1656 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1657 | printf ("%s: %ld", |
1658 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1659 | : "DW_OP_GNU_deref_type"), | |
1660 | (long) uvalue); | |
cd30bcef | 1661 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1662 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1663 | break; | |
bc0a77d2 | 1664 | case DW_OP_convert: |
0892011d | 1665 | case DW_OP_GNU_convert: |
cd30bcef | 1666 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1667 | printf ("%s <0x%s>", |
1668 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1669 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1670 | break; |
bc0a77d2 | 1671 | case DW_OP_reinterpret: |
0892011d | 1672 | case DW_OP_GNU_reinterpret: |
cd30bcef | 1673 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1674 | printf ("%s <0x%s>", |
1675 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1676 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1677 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1678 | break; | |
1679 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1680 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1681 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1682 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1683 | break; |
b4eb7656 | 1684 | case DW_OP_GNU_addr_index: |
cd30bcef | 1685 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1686 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1687 | break; | |
1688 | case DW_OP_GNU_const_index: | |
cd30bcef | 1689 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1690 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1691 | break; | |
f384a1f0 KB |
1692 | case DW_OP_GNU_variable_value: |
1693 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1694 | this ought to be an 8-byte wide computation. */ | |
1695 | if (dwarf_version == -1) | |
1696 | { | |
1697 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1698 | /* No way to tell where the next op is, so just bail. */ | |
1699 | return need_frame_base; | |
1700 | } | |
1701 | if (dwarf_version == 2) | |
1702 | { | |
1703 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1704 | } | |
1705 | else | |
1706 | { | |
1707 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1708 | } | |
1709 | printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1710 | break; | |
e2a0d921 NC |
1711 | |
1712 | /* HP extensions. */ | |
1713 | case DW_OP_HP_is_value: | |
1714 | printf ("DW_OP_HP_is_value"); | |
1715 | /* FIXME: Is there data associated with this OP ? */ | |
1716 | break; | |
1717 | case DW_OP_HP_fltconst4: | |
1718 | printf ("DW_OP_HP_fltconst4"); | |
1719 | /* FIXME: Is there data associated with this OP ? */ | |
1720 | break; | |
1721 | case DW_OP_HP_fltconst8: | |
1722 | printf ("DW_OP_HP_fltconst8"); | |
1723 | /* FIXME: Is there data associated with this OP ? */ | |
1724 | break; | |
1725 | case DW_OP_HP_mod_range: | |
1726 | printf ("DW_OP_HP_mod_range"); | |
1727 | /* FIXME: Is there data associated with this OP ? */ | |
1728 | break; | |
1729 | case DW_OP_HP_unmod_range: | |
1730 | printf ("DW_OP_HP_unmod_range"); | |
1731 | /* FIXME: Is there data associated with this OP ? */ | |
1732 | break; | |
1733 | case DW_OP_HP_tls: | |
1734 | printf ("DW_OP_HP_tls"); | |
1735 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1736 | break; |
1737 | ||
35d60fe4 NC |
1738 | /* PGI (STMicroelectronics) extensions. */ |
1739 | case DW_OP_PGI_omp_thread_num: | |
1740 | /* Pushes the thread number for the current thread as it would be | |
1741 | returned by the standard OpenMP library function: | |
1742 | omp_get_thread_num(). The "current thread" is the thread for | |
1743 | which the expression is being evaluated. */ | |
1744 | printf ("DW_OP_PGI_omp_thread_num"); | |
1745 | break; | |
1746 | ||
19e6b90e L |
1747 | default: |
1748 | if (op >= DW_OP_lo_user | |
1749 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1750 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1751 | else |
0502a2b4 | 1752 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1753 | /* No way to tell where the next op is, so just bail. */ |
1754 | return need_frame_base; | |
1755 | } | |
1756 | ||
1757 | /* Separate the ops. */ | |
1758 | if (data < end) | |
1759 | printf ("; "); | |
1760 | } | |
1761 | ||
1762 | return need_frame_base; | |
1763 | } | |
1764 | ||
341f9135 CC |
1765 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1766 | This is used for DWARF package files. */ | |
1767 | ||
1768 | static struct cu_tu_set * | |
1769 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1770 | { | |
1771 | struct cu_tu_set *p; | |
1772 | unsigned int nsets; | |
1773 | unsigned int dw_sect; | |
1774 | ||
1775 | if (do_types) | |
1776 | { | |
1777 | p = tu_sets; | |
1778 | nsets = tu_count; | |
1779 | dw_sect = DW_SECT_TYPES; | |
1780 | } | |
1781 | else | |
1782 | { | |
1783 | p = cu_sets; | |
1784 | nsets = cu_count; | |
1785 | dw_sect = DW_SECT_INFO; | |
1786 | } | |
1787 | while (nsets > 0) | |
1788 | { | |
1789 | if (p->section_offsets [dw_sect] == cu_offset) | |
1790 | return p; | |
1791 | p++; | |
1792 | nsets--; | |
1793 | } | |
1794 | return NULL; | |
1795 | } | |
1796 | ||
a69c4772 NC |
1797 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1798 | static void | |
1799 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1800 | { | |
1801 | dwarf_vma tmp = * low_bits; | |
1802 | ||
1803 | tmp += inc; | |
1804 | ||
1805 | /* FIXME: There is probably a better way of handling this: | |
1806 | ||
1807 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1808 | type. Plus regardless of its size LOW_BITS is meant to | |
1809 | only hold 32-bits, so if there is overflow or wrap around | |
1810 | we must propagate into HIGH_BITS. */ | |
1811 | if (tmp < * low_bits) | |
1812 | { | |
1813 | ++ * high_bits; | |
1814 | } | |
1815 | else if (sizeof (tmp) > 8 | |
1816 | && (tmp >> 31) > 1) | |
1817 | { | |
1818 | ++ * high_bits; | |
1819 | tmp &= 0xFFFFFFFF; | |
1820 | } | |
1821 | ||
1822 | * low_bits = tmp; | |
1823 | } | |
1824 | ||
dda8d76d NC |
1825 | static const char * |
1826 | fetch_alt_indirect_string (dwarf_vma offset) | |
1827 | { | |
24841daa | 1828 | separate_info * i; |
dda8d76d NC |
1829 | |
1830 | if (! do_follow_links) | |
1831 | return ""; | |
1832 | ||
24841daa NC |
1833 | if (first_separate_info == NULL) |
1834 | return _("<no links available>"); | |
dda8d76d | 1835 | |
24841daa NC |
1836 | for (i = first_separate_info; i != NULL; i = i->next) |
1837 | { | |
1838 | struct dwarf_section * section; | |
1839 | const char * ret; | |
dda8d76d | 1840 | |
24841daa NC |
1841 | if (! load_debug_section (separate_debug_str, i->handle)) |
1842 | continue; | |
dda8d76d | 1843 | |
24841daa | 1844 | section = &debug_displays [separate_debug_str].section; |
dda8d76d | 1845 | |
24841daa NC |
1846 | if (section->start == NULL) |
1847 | continue; | |
dda8d76d | 1848 | |
24841daa NC |
1849 | if (offset >= section->size) |
1850 | continue; | |
1851 | ||
1852 | ret = (const char *) (section->start + offset); | |
1853 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1854 | NUL byte. Since our caller is expecting to receive a well formed C | |
1855 | string we test for the lack of a terminating byte here. */ | |
1856 | if (strnlen ((const char *) ret, section->size - offset) | |
1857 | == section->size - offset) | |
1858 | return _("<no NUL byte at end of alt .debug_str section>"); | |
1859 | ||
1860 | return ret; | |
1861 | } | |
521d4b19 | 1862 | |
24841daa NC |
1863 | warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"), |
1864 | dwarf_vmatoa ("x", offset)); | |
1865 | return _("<offset is too big>"); | |
dda8d76d NC |
1866 | } |
1867 | ||
d85bf2ba NC |
1868 | static const char * |
1869 | get_AT_name (unsigned long attribute) | |
1870 | { | |
1871 | const char *name; | |
1872 | ||
1873 | if (attribute == 0) | |
1874 | return "DW_AT value: 0"; | |
1875 | ||
1876 | /* One value is shared by the MIPS and HP extensions: */ | |
1877 | if (attribute == DW_AT_MIPS_fde) | |
1878 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1879 | ||
1880 | name = get_DW_AT_name (attribute); | |
1881 | ||
1882 | if (name == NULL) | |
1883 | { | |
1884 | static char buffer[100]; | |
1885 | ||
1886 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1887 | attribute); | |
1888 | return buffer; | |
1889 | } | |
1890 | ||
1891 | return name; | |
1892 | } | |
1893 | ||
24841daa | 1894 | static void |
50ea0877 | 1895 | add_dwo_info (const char * value, dwarf_vma cu_offset, dwo_type type) |
24841daa NC |
1896 | { |
1897 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); | |
1898 | ||
50ea0877 NC |
1899 | dwinfo->type = type; |
1900 | dwinfo->value = value; | |
1901 | dwinfo->cu_offset = cu_offset; | |
1902 | dwinfo->next = first_dwo_info; | |
24841daa NC |
1903 | first_dwo_info = dwinfo; |
1904 | } | |
1905 | ||
1906 | static void | |
50ea0877 | 1907 | add_dwo_name (const char * name, dwarf_vma cu_offset) |
24841daa | 1908 | { |
50ea0877 | 1909 | add_dwo_info (name, cu_offset, DWO_NAME); |
24841daa NC |
1910 | } |
1911 | ||
1912 | static void | |
50ea0877 | 1913 | add_dwo_dir (const char * dir, dwarf_vma cu_offset) |
24841daa | 1914 | { |
50ea0877 | 1915 | add_dwo_info (dir, cu_offset, DWO_DIR); |
24841daa NC |
1916 | } |
1917 | ||
1918 | static void | |
50ea0877 | 1919 | add_dwo_id (const char * id, dwarf_vma cu_offset) |
24841daa | 1920 | { |
50ea0877 | 1921 | add_dwo_info (id, cu_offset, DWO_ID); |
24841daa NC |
1922 | } |
1923 | ||
1924 | static void | |
1925 | free_dwo_info (void) | |
1926 | { | |
1927 | dwo_info * dwinfo; | |
1928 | dwo_info * next; | |
1929 | ||
1930 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) | |
1931 | { | |
1932 | next = dwinfo->next; | |
1933 | free (dwinfo); | |
1934 | } | |
1935 | first_dwo_info = NULL; | |
1936 | } | |
1937 | ||
afc72f15 NC |
1938 | /* Ensure that START + UVALUE is less than END. |
1939 | Return an adjusted UVALUE if necessary to ensure this relationship. */ | |
1940 | ||
1941 | static inline dwarf_vma | |
1942 | check_uvalue (const unsigned char * start, | |
1943 | dwarf_vma uvalue, | |
1944 | const unsigned char * end) | |
1945 | { | |
1946 | dwarf_vma max_uvalue = end - start; | |
1947 | ||
afc72f15 NC |
1948 | /* See PR 17512: file: 008-103549-0.001:0.1. |
1949 | and PR 24829 for examples of where these tests are triggered. */ | |
a85eba51 | 1950 | if (uvalue > max_uvalue) |
afc72f15 NC |
1951 | { |
1952 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1953 | uvalue = max_uvalue; | |
1954 | } | |
1955 | ||
1956 | return uvalue; | |
1957 | } | |
1958 | ||
ec1b0fbb NC |
1959 | static unsigned char * |
1960 | skip_attr_bytes (unsigned long form, | |
1961 | unsigned char * data, | |
1962 | unsigned const char * end, | |
1963 | dwarf_vma pointer_size, | |
1964 | dwarf_vma offset_size, | |
1965 | int dwarf_version, | |
1966 | dwarf_vma * value_return) | |
1967 | { | |
cd30bcef AM |
1968 | dwarf_signed_vma svalue; |
1969 | dwarf_vma uvalue = 0; | |
ec1b0fbb NC |
1970 | |
1971 | * value_return = 0; | |
1972 | ||
1973 | switch (form) | |
1974 | { | |
1975 | case DW_FORM_ref_addr: | |
1976 | if (dwarf_version == 2) | |
1977 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
59624513 | 1978 | else if (dwarf_version > 2) |
ec1b0fbb NC |
1979 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1980 | else | |
1981 | return NULL; | |
1982 | break; | |
1983 | ||
1984 | case DW_FORM_addr: | |
1985 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1986 | break; | |
1987 | ||
1988 | case DW_FORM_strp: | |
1989 | case DW_FORM_line_strp: | |
1990 | case DW_FORM_sec_offset: | |
1991 | case DW_FORM_GNU_ref_alt: | |
1992 | case DW_FORM_GNU_strp_alt: | |
1993 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1994 | break; | |
1995 | ||
1996 | case DW_FORM_flag_present: | |
1997 | uvalue = 1; | |
1998 | break; | |
1999 | ||
2000 | case DW_FORM_ref1: | |
2001 | case DW_FORM_flag: | |
2002 | case DW_FORM_data1: | |
32e4f96c TV |
2003 | case DW_FORM_strx1: |
2004 | case DW_FORM_addrx1: | |
ec1b0fbb NC |
2005 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2006 | break; | |
2007 | ||
32e4f96c TV |
2008 | case DW_FORM_strx3: |
2009 | case DW_FORM_addrx3: | |
2010 | SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); | |
2011 | break; | |
2012 | ||
ec1b0fbb NC |
2013 | case DW_FORM_ref2: |
2014 | case DW_FORM_data2: | |
32e4f96c TV |
2015 | case DW_FORM_strx2: |
2016 | case DW_FORM_addrx2: | |
ec1b0fbb NC |
2017 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2018 | break; | |
2019 | ||
2020 | case DW_FORM_ref4: | |
2021 | case DW_FORM_data4: | |
32e4f96c TV |
2022 | case DW_FORM_strx4: |
2023 | case DW_FORM_addrx4: | |
ec1b0fbb NC |
2024 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2025 | break; | |
2026 | ||
2027 | case DW_FORM_sdata: | |
cd30bcef AM |
2028 | READ_SLEB (svalue, data, end); |
2029 | uvalue = svalue; | |
ec1b0fbb NC |
2030 | break; |
2031 | ||
2032 | case DW_FORM_ref_udata: | |
2033 | case DW_FORM_udata: | |
2034 | case DW_FORM_GNU_str_index: | |
32e4f96c | 2035 | case DW_FORM_strx: |
ec1b0fbb | 2036 | case DW_FORM_GNU_addr_index: |
32e4f96c | 2037 | case DW_FORM_addrx: |
cd30bcef | 2038 | READ_ULEB (uvalue, data, end); |
ec1b0fbb NC |
2039 | break; |
2040 | ||
2041 | case DW_FORM_ref8: | |
1f573141 NC |
2042 | { |
2043 | dwarf_vma high_bits; | |
2044 | ||
2045 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); | |
2046 | data += 8; | |
2047 | if (sizeof (uvalue) > 4) | |
2048 | uvalue += high_bits << 32; | |
2049 | else if (high_bits != 0) | |
2050 | { | |
2051 | /* FIXME: What to do ? */ | |
2052 | return NULL; | |
2053 | } | |
2054 | break; | |
2055 | } | |
2056 | ||
ec1b0fbb | 2057 | case DW_FORM_data8: |
59624513 | 2058 | case DW_FORM_ref_sig8: |
ec1b0fbb NC |
2059 | data += 8; |
2060 | break; | |
2061 | ||
2062 | case DW_FORM_data16: | |
2063 | data += 16; | |
2064 | break; | |
2065 | ||
2066 | case DW_FORM_string: | |
2067 | data += strnlen ((char *) data, end - data) + 1; | |
2068 | break; | |
2069 | ||
2070 | case DW_FORM_block: | |
2071 | case DW_FORM_exprloc: | |
cd30bcef | 2072 | READ_ULEB (uvalue, data, end); |
59624513 | 2073 | data += uvalue; |
ec1b0fbb NC |
2074 | break; |
2075 | ||
2076 | case DW_FORM_block1: | |
2077 | SAFE_BYTE_GET (uvalue, data, 1, end); | |
2078 | data += 1 + uvalue; | |
2079 | break; | |
2080 | ||
2081 | case DW_FORM_block2: | |
2082 | SAFE_BYTE_GET (uvalue, data, 2, end); | |
2083 | data += 2 + uvalue; | |
2084 | break; | |
2085 | ||
2086 | case DW_FORM_block4: | |
2087 | SAFE_BYTE_GET (uvalue, data, 4, end); | |
2088 | data += 4 + uvalue; | |
2089 | break; | |
2090 | ||
ec1b0fbb | 2091 | case DW_FORM_indirect: |
59624513 NC |
2092 | READ_ULEB (form, data, end); |
2093 | if (form == DW_FORM_implicit_const) | |
2094 | SKIP_ULEB (data, end); | |
2095 | return skip_attr_bytes (form, data, end, pointer_size, offset_size, dwarf_version, value_return); | |
2096 | ||
ec1b0fbb NC |
2097 | default: |
2098 | return NULL; | |
2099 | } | |
2100 | ||
2101 | * value_return = uvalue; | |
2102 | if (data > end) | |
2103 | data = (unsigned char *) end; | |
2104 | return data; | |
2105 | } | |
2106 | ||
bcd213b2 NC |
2107 | /* Given form FORM with value UVALUE, locate and return the abbreviation |
2108 | associated with it. */ | |
2109 | ||
2110 | static abbrev_entry * | |
2111 | get_type_abbrev_from_form (unsigned long form, | |
2112 | unsigned long uvalue, | |
2113 | dwarf_vma cu_offset, | |
2114 | const struct dwarf_section * section, | |
2115 | unsigned long * abbrev_num_return, | |
2116 | unsigned char ** data_return, | |
2117 | unsigned long * cu_offset_return) | |
2118 | { | |
2119 | unsigned long abbrev_number; | |
2120 | abbrev_map * map; | |
2121 | abbrev_entry * entry; | |
2122 | unsigned char * data; | |
2123 | ||
2124 | if (abbrev_num_return != NULL) | |
2125 | * abbrev_num_return = 0; | |
2126 | if (data_return != NULL) | |
2127 | * data_return = NULL; | |
2128 | ||
2129 | switch (form) | |
2130 | { | |
2131 | case DW_FORM_GNU_ref_alt: | |
5f128a25 | 2132 | case DW_FORM_ref_sig8: |
bcd213b2 NC |
2133 | /* FIXME: We are unable to handle this form at the moment. */ |
2134 | return NULL; | |
2135 | ||
2136 | case DW_FORM_ref_addr: | |
2137 | if (uvalue >= section->size) | |
2138 | { | |
2139 | warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"), | |
2140 | uvalue, (long) section->size, section->name); | |
2141 | return NULL; | |
2142 | } | |
2143 | break; | |
2144 | ||
e38332c2 NC |
2145 | case DW_FORM_ref_sup4: |
2146 | case DW_FORM_ref_sup8: | |
2147 | break; | |
2148 | ||
bcd213b2 NC |
2149 | case DW_FORM_ref1: |
2150 | case DW_FORM_ref2: | |
2151 | case DW_FORM_ref4: | |
1f573141 | 2152 | case DW_FORM_ref8: |
bcd213b2 NC |
2153 | case DW_FORM_ref_udata: |
2154 | if (uvalue + cu_offset > section->size) | |
2155 | { | |
2156 | warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > section size %lx\n"), | |
2157 | uvalue, (long) cu_offset, (long) section->size); | |
2158 | return NULL; | |
2159 | } | |
2160 | uvalue += cu_offset; | |
2161 | break; | |
2162 | ||
2163 | /* FIXME: Are there other DW_FORMs that can be used by types ? */ | |
2164 | ||
2165 | default: | |
2166 | warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form); | |
2167 | return NULL; | |
2168 | } | |
2169 | ||
2170 | data = (unsigned char *) section->start + uvalue; | |
2171 | map = find_abbrev_map_by_offset (uvalue); | |
521d4b19 | 2172 | |
bcd213b2 NC |
2173 | if (map == NULL) |
2174 | { | |
2175 | warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue); | |
2176 | return NULL; | |
2177 | } | |
2178 | if (map->list == NULL) | |
2179 | { | |
2180 | warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue); | |
2181 | return NULL; | |
2182 | } | |
2183 | ||
2184 | if (cu_offset_return != NULL) | |
2185 | { | |
2186 | if (form == DW_FORM_ref_addr) | |
2187 | * cu_offset_return = map->start; | |
2188 | else | |
2189 | * cu_offset_return = cu_offset; | |
2190 | } | |
2191 | ||
2192 | READ_ULEB (abbrev_number, data, section->start + section->size); | |
2193 | ||
2194 | for (entry = map->list->first_abbrev; entry != NULL; entry = entry->next) | |
2195 | if (entry->number == abbrev_number) | |
2196 | break; | |
521d4b19 | 2197 | |
bcd213b2 NC |
2198 | if (abbrev_num_return != NULL) |
2199 | * abbrev_num_return = abbrev_number; | |
2200 | ||
2201 | if (data_return != NULL) | |
2202 | * data_return = data; | |
2203 | ||
2204 | if (entry == NULL) | |
2205 | warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number); | |
2206 | ||
2207 | return entry; | |
2208 | } | |
2209 | ||
2210 | /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY | |
2211 | can be determined to be a signed type. The data for ENTRY can be | |
2212 | found starting at DATA. */ | |
ec1b0fbb NC |
2213 | |
2214 | static void | |
015dc7e1 AM |
2215 | get_type_signedness (abbrev_entry *entry, |
2216 | const struct dwarf_section *section, | |
2217 | unsigned char *data, | |
2218 | unsigned const char *end, | |
2219 | dwarf_vma cu_offset, | |
2220 | dwarf_vma pointer_size, | |
2221 | dwarf_vma offset_size, | |
2222 | int dwarf_version, | |
2223 | bool *is_signed, | |
2224 | unsigned int nesting) | |
ec1b0fbb | 2225 | { |
ec1b0fbb NC |
2226 | abbrev_attr * attr; |
2227 | ||
015dc7e1 | 2228 | * is_signed = false; |
ec1b0fbb | 2229 | |
59624513 NC |
2230 | #define MAX_NESTING 20 |
2231 | if (nesting > MAX_NESTING) | |
2232 | { | |
2233 | /* FIXME: Warn - or is this expected ? | |
2234 | NB/ We need to avoid infinite recursion. */ | |
2235 | return; | |
2236 | } | |
2237 | ||
ec1b0fbb NC |
2238 | for (attr = entry->first_attr; |
2239 | attr != NULL && attr->attribute; | |
2240 | attr = attr->next) | |
2241 | { | |
bcd213b2 | 2242 | unsigned char * orig_data = data; |
ec1b0fbb NC |
2243 | dwarf_vma uvalue = 0; |
2244 | ||
2245 | data = skip_attr_bytes (attr->form, data, end, pointer_size, | |
2246 | offset_size, dwarf_version, & uvalue); | |
2247 | if (data == NULL) | |
2248 | return; | |
2249 | ||
2250 | switch (attr->attribute) | |
2251 | { | |
bcd213b2 | 2252 | case DW_AT_linkage_name: |
ec1b0fbb | 2253 | case DW_AT_name: |
bcd213b2 NC |
2254 | if (do_wide) |
2255 | { | |
2256 | if (attr->form == DW_FORM_strp) | |
2257 | printf (", %s", fetch_indirect_string (uvalue)); | |
2258 | else if (attr->form == DW_FORM_string) | |
2259 | printf (", %s", orig_data); | |
2260 | } | |
ec1b0fbb | 2261 | break; |
bcd213b2 | 2262 | |
ec1b0fbb NC |
2263 | case DW_AT_type: |
2264 | /* Recurse. */ | |
bcd213b2 NC |
2265 | { |
2266 | abbrev_entry * type_abbrev; | |
2267 | unsigned char * type_data; | |
2268 | unsigned long type_cu_offset; | |
2269 | ||
2270 | type_abbrev = get_type_abbrev_from_form (attr->form, | |
2271 | uvalue, | |
2272 | cu_offset, | |
2273 | section, | |
2274 | NULL /* abbrev num return */, | |
2275 | & type_data, | |
2276 | & type_cu_offset); | |
2277 | if (type_abbrev == NULL) | |
2278 | break; | |
2279 | ||
2280 | get_type_signedness (type_abbrev, section, type_data, end, type_cu_offset, | |
2281 | pointer_size, offset_size, dwarf_version, | |
2282 | is_signed, nesting + 1); | |
2283 | } | |
ec1b0fbb NC |
2284 | break; |
2285 | ||
2286 | case DW_AT_encoding: | |
2287 | /* Determine signness. */ | |
2288 | switch (uvalue) | |
2289 | { | |
2290 | case DW_ATE_address: | |
2291 | /* FIXME - some architectures have signed addresses. */ | |
2292 | case DW_ATE_boolean: | |
2293 | case DW_ATE_unsigned: | |
2294 | case DW_ATE_unsigned_char: | |
2295 | case DW_ATE_unsigned_fixed: | |
015dc7e1 | 2296 | * is_signed = false; |
ec1b0fbb NC |
2297 | break; |
2298 | ||
2299 | default: | |
2300 | case DW_ATE_complex_float: | |
2301 | case DW_ATE_float: | |
2302 | case DW_ATE_signed: | |
2303 | case DW_ATE_signed_char: | |
2304 | case DW_ATE_imaginary_float: | |
2305 | case DW_ATE_decimal_float: | |
2306 | case DW_ATE_signed_fixed: | |
015dc7e1 | 2307 | * is_signed = true; |
ec1b0fbb NC |
2308 | break; |
2309 | } | |
2310 | break; | |
2311 | } | |
2312 | } | |
2313 | } | |
2314 | ||
2315 | static void | |
015dc7e1 AM |
2316 | read_and_print_leb128 (unsigned char *data, |
2317 | unsigned int *bytes_read, | |
2318 | unsigned const char *end, | |
2319 | bool is_signed) | |
ec1b0fbb | 2320 | { |
cd30bcef AM |
2321 | int status; |
2322 | dwarf_vma val = read_leb128 (data, end, is_signed, bytes_read, &status); | |
2323 | if (status != 0) | |
1b513401 | 2324 | report_leb_status (status, __FILE__, __LINE__); |
ec1b0fbb | 2325 | else |
cd30bcef | 2326 | printf ("%s", dwarf_vmatoa (is_signed ? "d" : "u", val)); |
ec1b0fbb NC |
2327 | } |
2328 | ||
2329 | static void | |
2330 | display_discr_list (unsigned long form, | |
2331 | dwarf_vma uvalue, | |
2332 | unsigned char * data, | |
2333 | unsigned const char * end, | |
2334 | int level) | |
2335 | { | |
2336 | if (uvalue == 0) | |
2337 | { | |
2338 | printf ("[default]"); | |
2339 | return; | |
2340 | } | |
521d4b19 | 2341 | |
ec1b0fbb NC |
2342 | switch (form) |
2343 | { | |
2344 | case DW_FORM_block: | |
2345 | case DW_FORM_block1: | |
2346 | case DW_FORM_block2: | |
2347 | case DW_FORM_block4: | |
2348 | /* Move data pointer back to the start of the byte array. */ | |
2349 | data -= uvalue; | |
2350 | break; | |
2351 | default: | |
2352 | printf ("<corrupt>\n"); | |
2353 | warn (_("corrupt discr_list - not using a block form\n")); | |
2354 | return; | |
2355 | } | |
2356 | ||
2357 | if (uvalue < 2) | |
2358 | { | |
2359 | printf ("<corrupt>\n"); | |
2360 | warn (_("corrupt discr_list - block not long enough\n")); | |
2361 | return; | |
2362 | } | |
2363 | ||
015dc7e1 | 2364 | bool is_signed = |
ec1b0fbb | 2365 | (level > 0 && level <= MAX_CU_NESTING) |
015dc7e1 | 2366 | ? level_type_signed [level - 1] : false; |
521d4b19 | 2367 | |
ec1b0fbb NC |
2368 | printf ("("); |
2369 | while (uvalue) | |
2370 | { | |
2371 | unsigned char discriminant; | |
2372 | unsigned int bytes_read; | |
2373 | ||
2374 | SAFE_BYTE_GET (discriminant, data, 1, end); | |
2375 | -- uvalue; | |
2376 | data ++; | |
2377 | ||
2378 | assert (uvalue > 0); | |
2379 | switch (discriminant) | |
2380 | { | |
2381 | case DW_DSC_label: | |
2382 | printf ("label "); | |
2383 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2384 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2385 | uvalue -= bytes_read; | |
2386 | data += bytes_read; | |
2387 | break; | |
2388 | ||
2389 | case DW_DSC_range: | |
2390 | printf ("range "); | |
2391 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2392 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2393 | uvalue -= bytes_read; | |
2394 | data += bytes_read; | |
2395 | ||
2396 | printf (".."); | |
2397 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2398 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2399 | uvalue -= bytes_read; | |
2400 | data += bytes_read; | |
2401 | break; | |
2402 | ||
2403 | default: | |
2404 | printf ("<corrupt>\n"); | |
e38332c2 | 2405 | warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"), |
ec1b0fbb NC |
2406 | discriminant); |
2407 | return; | |
2408 | } | |
2409 | ||
2410 | if (uvalue) | |
2411 | printf (", "); | |
2412 | } | |
2413 | ||
2414 | if (is_signed) | |
2415 | printf (")(signed)"); | |
2416 | else | |
2417 | printf (")(unsigned)"); | |
2418 | } | |
2419 | ||
19e6b90e | 2420 | static unsigned char * |
dda8d76d NC |
2421 | read_and_display_attr_value (unsigned long attribute, |
2422 | unsigned long form, | |
2423 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 2424 | unsigned char * start, |
dda8d76d NC |
2425 | unsigned char * data, |
2426 | unsigned char * end, | |
2427 | dwarf_vma cu_offset, | |
2428 | dwarf_vma pointer_size, | |
2429 | dwarf_vma offset_size, | |
2430 | int dwarf_version, | |
2431 | debug_info * debug_info_p, | |
2432 | int do_loc, | |
2433 | struct dwarf_section * section, | |
2434 | struct cu_tu_set * this_set, | |
ec1b0fbb NC |
2435 | char delimiter, |
2436 | int level) | |
19e6b90e | 2437 | { |
cd30bcef | 2438 | dwarf_signed_vma svalue; |
ec1b0fbb NC |
2439 | dwarf_vma uvalue = 0; |
2440 | unsigned char * block_start = NULL; | |
2441 | unsigned char * orig_data = data; | |
19e6b90e | 2442 | |
f41e4712 | 2443 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 2444 | { |
f41e4712 | 2445 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
2446 | return data; |
2447 | } | |
2448 | ||
521d4b19 NC |
2449 | if (do_wide && ! do_loc) |
2450 | { | |
2451 | /* PR 26847: Display the name of the form. */ | |
2452 | const char * name = get_FORM_name (form); | |
2453 | ||
2454 | /* For convenience we skip the DW_FORM_ prefix to the name. */ | |
2455 | if (name[0] == 'D') | |
2456 | name += 8; /* strlen ("DW_FORM_") */ | |
2457 | printf ("%c(%s)", delimiter, name); | |
2458 | } | |
2459 | ||
19e6b90e L |
2460 | switch (form) |
2461 | { | |
2462 | default: | |
2463 | break; | |
2464 | ||
2465 | case DW_FORM_ref_addr: | |
2466 | if (dwarf_version == 2) | |
0c588247 | 2467 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
ec47b32a | 2468 | else if (dwarf_version > 2) |
0c588247 | 2469 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 2470 | else |
ec47b32a | 2471 | error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n")); |
19e6b90e L |
2472 | break; |
2473 | ||
2474 | case DW_FORM_addr: | |
0c588247 | 2475 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
2476 | break; |
2477 | ||
e38332c2 | 2478 | case DW_FORM_strp_sup: |
19e6b90e | 2479 | case DW_FORM_strp: |
77145576 | 2480 | case DW_FORM_line_strp: |
932fd279 | 2481 | case DW_FORM_sec_offset: |
a081f3cd JJ |
2482 | case DW_FORM_GNU_ref_alt: |
2483 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 2484 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
2485 | break; |
2486 | ||
932fd279 JJ |
2487 | case DW_FORM_flag_present: |
2488 | uvalue = 1; | |
2489 | break; | |
2490 | ||
19e6b90e L |
2491 | case DW_FORM_ref1: |
2492 | case DW_FORM_flag: | |
2493 | case DW_FORM_data1: | |
32e4f96c TV |
2494 | case DW_FORM_strx1: |
2495 | case DW_FORM_addrx1: | |
0c588247 | 2496 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
2497 | break; |
2498 | ||
2499 | case DW_FORM_ref2: | |
2500 | case DW_FORM_data2: | |
32e4f96c TV |
2501 | case DW_FORM_strx2: |
2502 | case DW_FORM_addrx2: | |
0c588247 | 2503 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
2504 | break; |
2505 | ||
32e4f96c TV |
2506 | case DW_FORM_strx3: |
2507 | case DW_FORM_addrx3: | |
2508 | SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); | |
2509 | break; | |
2510 | ||
e38332c2 | 2511 | case DW_FORM_ref_sup4: |
19e6b90e L |
2512 | case DW_FORM_ref4: |
2513 | case DW_FORM_data4: | |
32e4f96c TV |
2514 | case DW_FORM_strx4: |
2515 | case DW_FORM_addrx4: | |
0c588247 | 2516 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
2517 | break; |
2518 | ||
2519 | case DW_FORM_sdata: | |
cd30bcef AM |
2520 | READ_SLEB (svalue, data, end); |
2521 | uvalue = svalue; | |
19e6b90e L |
2522 | break; |
2523 | ||
4723351a | 2524 | case DW_FORM_GNU_str_index: |
32e4f96c | 2525 | case DW_FORM_strx: |
19e6b90e L |
2526 | case DW_FORM_ref_udata: |
2527 | case DW_FORM_udata: | |
cd30bcef | 2528 | case DW_FORM_GNU_addr_index: |
32e4f96c | 2529 | case DW_FORM_addrx: |
cd30bcef | 2530 | READ_ULEB (uvalue, data, end); |
19e6b90e L |
2531 | break; |
2532 | ||
2533 | case DW_FORM_indirect: | |
cd30bcef | 2534 | READ_ULEB (form, data, end); |
19e6b90e | 2535 | if (!do_loc) |
ef0b5f1c | 2536 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 | 2537 | if (form == DW_FORM_implicit_const) |
cd30bcef | 2538 | READ_SLEB (implicit_const, data, end); |
ec1b0fbb NC |
2539 | return read_and_display_attr_value (attribute, form, implicit_const, |
2540 | start, data, end, | |
2541 | cu_offset, pointer_size, | |
19e6b90e | 2542 | offset_size, dwarf_version, |
ec4d4525 | 2543 | debug_info_p, do_loc, |
ec1b0fbb | 2544 | section, this_set, delimiter, level); |
19e6b90e L |
2545 | } |
2546 | ||
2547 | switch (form) | |
2548 | { | |
2549 | case DW_FORM_ref_addr: | |
2550 | if (!do_loc) | |
bcd213b2 | 2551 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2552 | break; |
2553 | ||
a081f3cd JJ |
2554 | case DW_FORM_GNU_ref_alt: |
2555 | if (!do_loc) | |
521d4b19 NC |
2556 | { |
2557 | if (do_wide) | |
2558 | /* We have already printed the form name. */ | |
2559 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); | |
2560 | else | |
2561 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); | |
2562 | } | |
dda8d76d | 2563 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
2564 | break; |
2565 | ||
19e6b90e L |
2566 | case DW_FORM_ref1: |
2567 | case DW_FORM_ref2: | |
2568 | case DW_FORM_ref4: | |
e38332c2 | 2569 | case DW_FORM_ref_sup4: |
19e6b90e L |
2570 | case DW_FORM_ref_udata: |
2571 | if (!do_loc) | |
ef0b5f1c | 2572 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
2573 | break; |
2574 | ||
2575 | case DW_FORM_data4: | |
2576 | case DW_FORM_addr: | |
932fd279 | 2577 | case DW_FORM_sec_offset: |
19e6b90e | 2578 | if (!do_loc) |
ef0b5f1c | 2579 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2580 | break; |
2581 | ||
932fd279 | 2582 | case DW_FORM_flag_present: |
19e6b90e L |
2583 | case DW_FORM_flag: |
2584 | case DW_FORM_data1: | |
2585 | case DW_FORM_data2: | |
2586 | case DW_FORM_sdata: | |
2587 | case DW_FORM_udata: | |
2588 | if (!do_loc) | |
ef0b5f1c | 2589 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
2590 | break; |
2591 | ||
77145576 JK |
2592 | case DW_FORM_implicit_const: |
2593 | if (!do_loc) | |
2594 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
2595 | break; | |
2596 | ||
e38332c2 | 2597 | case DW_FORM_ref_sup8: |
19e6b90e L |
2598 | case DW_FORM_ref8: |
2599 | case DW_FORM_data8: | |
2bc8690c | 2600 | if (!do_loc) |
19e6b90e | 2601 | { |
74bc6052 | 2602 | dwarf_vma high_bits; |
a69c4772 | 2603 | dwarf_vma utmp; |
74bc6052 CC |
2604 | char buf[64]; |
2605 | ||
0c588247 | 2606 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
2607 | utmp = uvalue; |
2608 | if (form == DW_FORM_ref8) | |
2609 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 2610 | printf ("%c0x%s", delimiter, |
a69c4772 | 2611 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 2612 | } |
0c588247 | 2613 | |
19e6b90e L |
2614 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2615 | && num_debug_info_entries == 0) | |
2616 | { | |
2617 | if (sizeof (uvalue) == 8) | |
0c588247 | 2618 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 2619 | else |
467c65bc | 2620 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 2621 | } |
0c588247 | 2622 | |
19e6b90e L |
2623 | data += 8; |
2624 | break; | |
2625 | ||
2f6cd591 JK |
2626 | case DW_FORM_data16: |
2627 | if (!do_loc) | |
2628 | { | |
2629 | dwarf_vma left_high_bits, left_low_bits; | |
2630 | dwarf_vma right_high_bits, right_low_bits; | |
2631 | ||
2632 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
2633 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
2634 | if (byte_get == byte_get_little_endian) | |
2635 | { | |
2636 | /* Swap them. */ | |
2637 | left_high_bits ^= right_high_bits; | |
2638 | right_high_bits ^= left_high_bits; | |
2639 | left_high_bits ^= right_high_bits; | |
2640 | left_low_bits ^= right_low_bits; | |
2641 | right_low_bits ^= left_low_bits; | |
2642 | left_low_bits ^= right_low_bits; | |
2643 | } | |
2644 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
2645 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
2646 | left_high_bits, left_low_bits, right_high_bits, | |
2647 | right_low_bits); | |
2648 | } | |
2649 | data += 16; | |
2650 | break; | |
2651 | ||
19e6b90e L |
2652 | case DW_FORM_string: |
2653 | if (!do_loc) | |
ef0b5f1c | 2654 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 2655 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
2656 | break; |
2657 | ||
2658 | case DW_FORM_block: | |
932fd279 | 2659 | case DW_FORM_exprloc: |
cd30bcef AM |
2660 | READ_ULEB (uvalue, data, end); |
2661 | do_block: | |
2662 | block_start = data; | |
a1165289 NC |
2663 | if (block_start >= end) |
2664 | { | |
2665 | warn (_("Block ends prematurely\n")); | |
2666 | uvalue = 0; | |
2667 | block_start = end; | |
2668 | } | |
afc72f15 NC |
2669 | |
2670 | uvalue = check_uvalue (block_start, uvalue, end); | |
2671 | ||
19e6b90e L |
2672 | if (do_loc) |
2673 | data = block_start + uvalue; | |
2674 | else | |
ef0b5f1c | 2675 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2676 | break; |
2677 | ||
2678 | case DW_FORM_block1: | |
cd30bcef AM |
2679 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2680 | goto do_block; | |
19e6b90e L |
2681 | |
2682 | case DW_FORM_block2: | |
cd30bcef AM |
2683 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2684 | goto do_block; | |
19e6b90e L |
2685 | |
2686 | case DW_FORM_block4: | |
cd30bcef AM |
2687 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2688 | goto do_block; | |
19e6b90e L |
2689 | |
2690 | case DW_FORM_strp: | |
2691 | if (!do_loc) | |
521d4b19 NC |
2692 | { |
2693 | if (do_wide) | |
2694 | /* We have already displayed the form name. */ | |
2695 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2696 | dwarf_vmatoa ("x", uvalue), | |
2697 | fetch_indirect_string (uvalue)); | |
2698 | else | |
2699 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, | |
2700 | dwarf_vmatoa ("x", uvalue), | |
2701 | fetch_indirect_string (uvalue)); | |
2702 | } | |
19e6b90e L |
2703 | break; |
2704 | ||
77145576 JK |
2705 | case DW_FORM_line_strp: |
2706 | if (!do_loc) | |
521d4b19 NC |
2707 | { |
2708 | if (do_wide) | |
2709 | /* We have already displayed the form name. */ | |
2710 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2711 | dwarf_vmatoa ("x", uvalue), | |
2712 | fetch_indirect_line_string (uvalue)); | |
2713 | else | |
2714 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2715 | dwarf_vmatoa ("x", uvalue), | |
2716 | fetch_indirect_line_string (uvalue)); | |
2717 | } | |
77145576 JK |
2718 | break; |
2719 | ||
4723351a | 2720 | case DW_FORM_GNU_str_index: |
32e4f96c TV |
2721 | case DW_FORM_strx: |
2722 | case DW_FORM_strx1: | |
2723 | case DW_FORM_strx2: | |
2724 | case DW_FORM_strx3: | |
2725 | case DW_FORM_strx4: | |
4723351a | 2726 | if (!do_loc) |
b4eb7656 | 2727 | { |
63b4cc53 | 2728 | const char *suffix = strrchr (section->name, '.'); |
015dc7e1 | 2729 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
b4eb7656 | 2730 | |
521d4b19 NC |
2731 | if (do_wide) |
2732 | /* We have already displayed the form name. */ | |
2733 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2734 | dwarf_vmatoa ("x", uvalue), | |
2735 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2736 | else | |
2737 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, | |
2738 | dwarf_vmatoa ("x", uvalue), | |
2739 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
b4eb7656 | 2740 | } |
4723351a CC |
2741 | break; |
2742 | ||
a081f3cd JJ |
2743 | case DW_FORM_GNU_strp_alt: |
2744 | if (!do_loc) | |
dda8d76d | 2745 | { |
521d4b19 NC |
2746 | if (do_wide) |
2747 | /* We have already displayed the form name. */ | |
2748 | printf (_("%c(offset: 0x%s) %s"), delimiter, | |
2749 | dwarf_vmatoa ("x", uvalue), | |
2750 | fetch_alt_indirect_string (uvalue)); | |
2751 | else | |
2752 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2753 | dwarf_vmatoa ("x", uvalue), | |
2754 | fetch_alt_indirect_string (uvalue)); | |
dda8d76d | 2755 | } |
a081f3cd JJ |
2756 | break; |
2757 | ||
19e6b90e L |
2758 | case DW_FORM_indirect: |
2759 | /* Handled above. */ | |
2760 | break; | |
2761 | ||
2b6f5997 CC |
2762 | case DW_FORM_ref_sig8: |
2763 | if (!do_loc) | |
2764 | { | |
74bc6052 CC |
2765 | dwarf_vma high_bits; |
2766 | char buf[64]; | |
2767 | ||
0c588247 | 2768 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
521d4b19 NC |
2769 | if (do_wide) |
2770 | /* We have already displayed the form name. */ | |
2771 | printf ("%c: 0x%s", delimiter, | |
2772 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); | |
2773 | else | |
2774 | printf ("%csignature: 0x%s", delimiter, | |
2775 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); | |
2b6f5997 | 2776 | } |
74bc6052 | 2777 | data += 8; |
2b6f5997 CC |
2778 | break; |
2779 | ||
4723351a | 2780 | case DW_FORM_GNU_addr_index: |
32e4f96c TV |
2781 | case DW_FORM_addrx: |
2782 | case DW_FORM_addrx1: | |
2783 | case DW_FORM_addrx2: | |
2784 | case DW_FORM_addrx3: | |
2785 | case DW_FORM_addrx4: | |
4723351a | 2786 | if (!do_loc) |
521d4b19 | 2787 | { |
32e4f96c TV |
2788 | dwarf_vma base; |
2789 | dwarf_vma offset; | |
2790 | ||
2791 | if (debug_info_p == NULL) | |
2792 | base = 0; | |
2793 | else if (debug_info_p->addr_base == DEBUG_INFO_UNAVAILABLE) | |
2794 | base = 0; | |
2795 | else | |
2796 | base = debug_info_p->addr_base; | |
2797 | ||
2798 | offset = base + uvalue * pointer_size; | |
2799 | ||
521d4b19 NC |
2800 | if (do_wide) |
2801 | /* We have already displayed the form name. */ | |
2802 | printf (_("%c(index: 0x%s): %s"), delimiter, | |
2803 | dwarf_vmatoa ("x", uvalue), | |
32e4f96c | 2804 | fetch_indexed_value (offset, pointer_size)); |
521d4b19 NC |
2805 | else |
2806 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, | |
2807 | dwarf_vmatoa ("x", uvalue), | |
32e4f96c | 2808 | fetch_indexed_value (offset, pointer_size)); |
521d4b19 | 2809 | } |
4723351a CC |
2810 | break; |
2811 | ||
e38332c2 NC |
2812 | case DW_FORM_strp_sup: |
2813 | if (!do_loc) | |
2814 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); | |
2815 | break; | |
2816 | ||
19e6b90e | 2817 | default: |
e38332c2 | 2818 | warn (_("Unrecognized form: 0x%lx\n"), form); |
19e6b90e L |
2819 | break; |
2820 | } | |
2821 | ||
19e6b90e | 2822 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2823 | && num_debug_info_entries == 0 |
2824 | && debug_info_p != NULL) | |
19e6b90e L |
2825 | { |
2826 | switch (attribute) | |
2827 | { | |
2828 | case DW_AT_frame_base: | |
2829 | have_frame_base = 1; | |
1a0670f3 | 2830 | /* Fall through. */ |
19e6b90e | 2831 | case DW_AT_location: |
9f272209 | 2832 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2833 | case DW_AT_string_length: |
2834 | case DW_AT_return_addr: | |
19e6b90e L |
2835 | case DW_AT_data_member_location: |
2836 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2837 | case DW_AT_segment: |
2838 | case DW_AT_static_link: | |
2839 | case DW_AT_use_location: | |
bc0a77d2 | 2840 | case DW_AT_call_value: |
629e7ca8 | 2841 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2842 | case DW_AT_call_data_value: |
629e7ca8 | 2843 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2844 | case DW_AT_call_target: |
629e7ca8 | 2845 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2846 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2847 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2848 | if ((dwarf_version < 4 |
212b6063 | 2849 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2850 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2851 | { |
2852 | /* Process location list. */ | |
91d6fa6a | 2853 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2854 | unsigned int num = debug_info_p->num_loc_offsets; |
2855 | ||
91d6fa6a | 2856 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2857 | { |
91d6fa6a | 2858 | lmax += 1024; |
467c65bc | 2859 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2860 | xcrealloc (debug_info_p->loc_offsets, |
2861 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2862 | debug_info_p->loc_views = (dwarf_vma *) |
2863 | xcrealloc (debug_info_p->loc_views, | |
2864 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2865 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2866 | xcrealloc (debug_info_p->have_frame_base, |
2867 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2868 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2869 | } |
341f9135 | 2870 | if (this_set != NULL) |
b4eb7656 | 2871 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2872 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2873 | if (attribute != DW_AT_GNU_locviews) |
2874 | { | |
a7504f87 NC |
2875 | /* Corrupt DWARF info can produce more offsets than views. |
2876 | See PR 23062 for an example. */ | |
2877 | if (debug_info_p->num_loc_offsets | |
2878 | > debug_info_p->num_loc_views) | |
2879 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2880 | else | |
2881 | { | |
2882 | debug_info_p->loc_offsets [num] = uvalue; | |
2883 | debug_info_p->num_loc_offsets++; | |
2884 | } | |
9f272209 AO |
2885 | } |
2886 | else | |
2887 | { | |
2888 | assert (debug_info_p->num_loc_views <= num); | |
2889 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2890 | if (num > debug_info_p->num_loc_offsets) |
2891 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2892 | else | |
2893 | { | |
2894 | debug_info_p->loc_views [num] = uvalue; | |
2895 | debug_info_p->num_loc_views++; | |
2896 | } | |
9f272209 | 2897 | } |
19e6b90e L |
2898 | } |
2899 | break; | |
e2a0d921 | 2900 | |
19e6b90e L |
2901 | case DW_AT_low_pc: |
2902 | if (need_base_address) | |
2903 | debug_info_p->base_address = uvalue; | |
2904 | break; | |
2905 | ||
4723351a | 2906 | case DW_AT_GNU_addr_base: |
32e4f96c | 2907 | case DW_AT_addr_base: |
b4eb7656 | 2908 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2909 | break; |
2910 | ||
2911 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2912 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2913 | break; |
2914 | ||
19e6b90e | 2915 | case DW_AT_ranges: |
b4eb7656 | 2916 | if ((dwarf_version < 4 |
212b6063 | 2917 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2918 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2919 | { |
2920 | /* Process range list. */ | |
91d6fa6a | 2921 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2922 | unsigned int num = debug_info_p->num_range_lists; |
2923 | ||
91d6fa6a | 2924 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2925 | { |
91d6fa6a | 2926 | lmax += 1024; |
467c65bc | 2927 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2928 | xcrealloc (debug_info_p->range_lists, |
2929 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2930 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2931 | } |
2932 | debug_info_p->range_lists [num] = uvalue; | |
2933 | debug_info_p->num_range_lists++; | |
2934 | } | |
2935 | break; | |
2936 | ||
d85bf2ba NC |
2937 | case DW_AT_GNU_dwo_name: |
2938 | case DW_AT_dwo_name: | |
2939 | if (need_dwo_info) | |
2940 | switch (form) | |
2941 | { | |
2942 | case DW_FORM_strp: | |
50ea0877 | 2943 | add_dwo_name ((const char *) fetch_indirect_string (uvalue), cu_offset); |
d85bf2ba | 2944 | break; |
5568cc9e | 2945 | case DW_FORM_GNU_strp_alt: |
50ea0877 | 2946 | add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue), cu_offset); |
5568cc9e | 2947 | break; |
d85bf2ba | 2948 | case DW_FORM_GNU_str_index: |
32e4f96c TV |
2949 | case DW_FORM_strx: |
2950 | case DW_FORM_strx1: | |
2951 | case DW_FORM_strx2: | |
2952 | case DW_FORM_strx3: | |
2953 | case DW_FORM_strx4: | |
015dc7e1 | 2954 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, false), cu_offset); |
d85bf2ba NC |
2955 | break; |
2956 | case DW_FORM_string: | |
50ea0877 | 2957 | add_dwo_name ((const char *) orig_data, cu_offset); |
d85bf2ba NC |
2958 | break; |
2959 | default: | |
2960 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2961 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2962 | break; |
2963 | } | |
2964 | break; | |
521d4b19 | 2965 | |
d85bf2ba NC |
2966 | case DW_AT_comp_dir: |
2967 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2968 | if (need_dwo_info) | |
2969 | switch (form) | |
2970 | { | |
2971 | case DW_FORM_strp: | |
50ea0877 | 2972 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue), cu_offset); |
d85bf2ba | 2973 | break; |
5568cc9e | 2974 | case DW_FORM_GNU_strp_alt: |
50ea0877 | 2975 | add_dwo_dir (fetch_alt_indirect_string (uvalue), cu_offset); |
5568cc9e | 2976 | break; |
d85bf2ba | 2977 | case DW_FORM_line_strp: |
50ea0877 | 2978 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue), cu_offset); |
d85bf2ba NC |
2979 | break; |
2980 | case DW_FORM_GNU_str_index: | |
32e4f96c TV |
2981 | case DW_FORM_strx: |
2982 | case DW_FORM_strx1: | |
2983 | case DW_FORM_strx2: | |
2984 | case DW_FORM_strx3: | |
2985 | case DW_FORM_strx4: | |
015dc7e1 | 2986 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, false), cu_offset); |
d85bf2ba NC |
2987 | break; |
2988 | case DW_FORM_string: | |
50ea0877 | 2989 | add_dwo_dir ((const char *) orig_data, cu_offset); |
d85bf2ba NC |
2990 | break; |
2991 | default: | |
2992 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2993 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2994 | break; |
2995 | } | |
2996 | break; | |
521d4b19 | 2997 | |
d85bf2ba NC |
2998 | case DW_AT_GNU_dwo_id: |
2999 | if (need_dwo_info) | |
3000 | switch (form) | |
3001 | { | |
3002 | case DW_FORM_data8: | |
24841daa | 3003 | /* FIXME: Record the length of the ID as well ? */ |
50ea0877 | 3004 | add_dwo_id ((const char *) (data - 8), cu_offset); |
d85bf2ba NC |
3005 | break; |
3006 | default: | |
3007 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
3008 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
3009 | break; |
3010 | } | |
3011 | break; | |
521d4b19 | 3012 | |
19e6b90e L |
3013 | default: |
3014 | break; | |
3015 | } | |
3016 | } | |
3017 | ||
4ccf1e31 | 3018 | if (do_loc || attribute == 0) |
19e6b90e L |
3019 | return data; |
3020 | ||
ec4d4525 | 3021 | /* For some attributes we can display further information. */ |
19e6b90e L |
3022 | switch (attribute) |
3023 | { | |
ec1b0fbb | 3024 | case DW_AT_type: |
b3fe587e AM |
3025 | if (level >= 0 && level < MAX_CU_NESTING |
3026 | && uvalue < (size_t) (end - start)) | |
ec1b0fbb | 3027 | { |
015dc7e1 AM |
3028 | bool is_signed = false; |
3029 | abbrev_entry *type_abbrev; | |
3030 | unsigned char *type_data; | |
3031 | unsigned long type_cu_offset; | |
521d4b19 | 3032 | |
bcd213b2 NC |
3033 | type_abbrev = get_type_abbrev_from_form (form, uvalue, cu_offset, |
3034 | section, NULL, & type_data, & type_cu_offset); | |
3035 | if (type_abbrev != NULL) | |
3036 | { | |
3037 | get_type_signedness (type_abbrev, section, type_data, end, type_cu_offset, | |
3038 | pointer_size, offset_size, dwarf_version, | |
3039 | & is_signed, 0); | |
3040 | } | |
ec1b0fbb NC |
3041 | level_type_signed[level] = is_signed; |
3042 | } | |
3043 | break; | |
521d4b19 | 3044 | |
19e6b90e | 3045 | case DW_AT_inline: |
2e9e81a8 | 3046 | printf ("\t"); |
19e6b90e L |
3047 | switch (uvalue) |
3048 | { | |
3049 | case DW_INL_not_inlined: | |
3050 | printf (_("(not inlined)")); | |
3051 | break; | |
3052 | case DW_INL_inlined: | |
3053 | printf (_("(inlined)")); | |
3054 | break; | |
3055 | case DW_INL_declared_not_inlined: | |
3056 | printf (_("(declared as inline but ignored)")); | |
3057 | break; | |
3058 | case DW_INL_declared_inlined: | |
3059 | printf (_("(declared as inline and inlined)")); | |
3060 | break; | |
3061 | default: | |
47704ddf KT |
3062 | printf (_(" (Unknown inline attribute value: %s)"), |
3063 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
3064 | break; |
3065 | } | |
3066 | break; | |
3067 | ||
3068 | case DW_AT_language: | |
2e9e81a8 | 3069 | printf ("\t"); |
19e6b90e L |
3070 | switch (uvalue) |
3071 | { | |
4b78141a | 3072 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 3073 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
3074 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
3075 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 3076 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
3077 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
3078 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
3079 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
3080 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 3081 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 3082 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 3083 | /* DWARF 2.1 values. */ |
4b78141a | 3084 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
3085 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
3086 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
3087 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
3088 | /* DWARF 3 values. */ |
3089 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
3090 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
3091 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
3092 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
3093 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
3094 | /* DWARF 4 values. */ |
3095 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 3096 | /* DWARF 5 values. */ |
2008a0db | 3097 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 3098 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
3099 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
3100 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
3101 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 3102 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
3103 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
3104 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 3105 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
3106 | case DW_LANG_Swift: printf ("(Swift)"); break; |
3107 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
3108 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 3109 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
3110 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
3111 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 3112 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
3113 | /* MIPS extension. */ |
3114 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
3115 | /* UPC extension. */ | |
3116 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
3117 | default: | |
4b78141a | 3118 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 3119 | printf (_("(implementation defined: %s)"), |
467c65bc | 3120 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 3121 | else |
9cf03b7e | 3122 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
3123 | break; |
3124 | } | |
3125 | break; | |
3126 | ||
3127 | case DW_AT_encoding: | |
2e9e81a8 | 3128 | printf ("\t"); |
19e6b90e L |
3129 | switch (uvalue) |
3130 | { | |
3131 | case DW_ATE_void: printf ("(void)"); break; | |
3132 | case DW_ATE_address: printf ("(machine address)"); break; | |
3133 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
3134 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
3135 | case DW_ATE_float: printf ("(float)"); break; | |
3136 | case DW_ATE_signed: printf ("(signed)"); break; | |
3137 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
3138 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
3139 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 3140 | /* DWARF 2.1 values: */ |
19e6b90e L |
3141 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
3142 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
3143 | /* DWARF 3 values: */ |
3144 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
3145 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
3146 | case DW_ATE_edited: printf ("(edited)"); break; | |
3147 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
3148 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
3149 | /* DWARF 4 values: */ |
3150 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
3151 | /* DWARF 5 values: */ | |
3152 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
3153 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
3154 | ||
e2a0d921 NC |
3155 | /* HP extensions: */ |
3156 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
3157 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
3158 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
3159 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
3160 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
3161 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
3162 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
3163 | ||
19e6b90e L |
3164 | default: |
3165 | if (uvalue >= DW_ATE_lo_user | |
3166 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 3167 | printf (_("(user defined type)")); |
19e6b90e | 3168 | else |
9cf03b7e | 3169 | printf (_("(unknown type)")); |
19e6b90e L |
3170 | break; |
3171 | } | |
3172 | break; | |
3173 | ||
3174 | case DW_AT_accessibility: | |
2e9e81a8 | 3175 | printf ("\t"); |
19e6b90e L |
3176 | switch (uvalue) |
3177 | { | |
3178 | case DW_ACCESS_public: printf ("(public)"); break; | |
3179 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
3180 | case DW_ACCESS_private: printf ("(private)"); break; | |
3181 | default: | |
9cf03b7e | 3182 | printf (_("(unknown accessibility)")); |
19e6b90e L |
3183 | break; |
3184 | } | |
3185 | break; | |
3186 | ||
3187 | case DW_AT_visibility: | |
2e9e81a8 | 3188 | printf ("\t"); |
19e6b90e L |
3189 | switch (uvalue) |
3190 | { | |
3191 | case DW_VIS_local: printf ("(local)"); break; | |
3192 | case DW_VIS_exported: printf ("(exported)"); break; | |
3193 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 3194 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
3195 | } |
3196 | break; | |
3197 | ||
04914e37 NC |
3198 | case DW_AT_endianity: |
3199 | printf ("\t"); | |
3200 | switch (uvalue) | |
3201 | { | |
3202 | case DW_END_default: printf ("(default)"); break; | |
3203 | case DW_END_big: printf ("(big)"); break; | |
3204 | case DW_END_little: printf ("(little)"); break; | |
3205 | default: | |
3206 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
3207 | printf (_("(user specified)")); | |
3208 | else | |
3209 | printf (_("(unknown endianity)")); | |
3210 | break; | |
3211 | } | |
3212 | break; | |
3213 | ||
19e6b90e | 3214 | case DW_AT_virtuality: |
2e9e81a8 | 3215 | printf ("\t"); |
19e6b90e L |
3216 | switch (uvalue) |
3217 | { | |
3218 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
3219 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
3220 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 3221 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
3222 | } |
3223 | break; | |
3224 | ||
3225 | case DW_AT_identifier_case: | |
2e9e81a8 | 3226 | printf ("\t"); |
19e6b90e L |
3227 | switch (uvalue) |
3228 | { | |
3229 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
3230 | case DW_ID_up_case: printf ("(up_case)"); break; | |
3231 | case DW_ID_down_case: printf ("(down_case)"); break; | |
3232 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 3233 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
3234 | } |
3235 | break; | |
3236 | ||
3237 | case DW_AT_calling_convention: | |
2e9e81a8 | 3238 | printf ("\t"); |
19e6b90e L |
3239 | switch (uvalue) |
3240 | { | |
3241 | case DW_CC_normal: printf ("(normal)"); break; | |
3242 | case DW_CC_program: printf ("(program)"); break; | |
3243 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
3244 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
3245 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
3246 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
3247 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
3248 | default: |
3249 | if (uvalue >= DW_CC_lo_user | |
3250 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 3251 | printf (_("(user defined)")); |
19e6b90e | 3252 | else |
9cf03b7e | 3253 | printf (_("(unknown convention)")); |
19e6b90e L |
3254 | } |
3255 | break; | |
3256 | ||
3257 | case DW_AT_ordering: | |
2e9e81a8 | 3258 | printf ("\t"); |
19e6b90e L |
3259 | switch (uvalue) |
3260 | { | |
04914e37 | 3261 | case 255: |
9cf03b7e | 3262 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
3263 | case 0: printf ("(row major)"); break; |
3264 | case 1: printf ("(column major)"); break; | |
3265 | } | |
3266 | break; | |
3267 | ||
04914e37 NC |
3268 | case DW_AT_decimal_sign: |
3269 | printf ("\t"); | |
3270 | switch (uvalue) | |
3271 | { | |
3272 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
3273 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
3274 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
3275 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
3276 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
3277 | default: printf (_("(unrecognised)")); break; | |
3278 | } | |
3279 | break; | |
3280 | ||
3281 | case DW_AT_defaulted: | |
3282 | printf ("\t"); | |
3283 | switch (uvalue) | |
3284 | { | |
3285 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
3286 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
3287 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
3288 | default: printf (_("(unrecognised)")); break; | |
3289 | } | |
3290 | break; | |
3291 | ||
3292 | case DW_AT_discr_list: | |
3293 | printf ("\t"); | |
ec1b0fbb | 3294 | display_discr_list (form, uvalue, data, end, level); |
04914e37 | 3295 | break; |
521d4b19 | 3296 | |
19e6b90e L |
3297 | case DW_AT_frame_base: |
3298 | have_frame_base = 1; | |
1a0670f3 | 3299 | /* Fall through. */ |
19e6b90e | 3300 | case DW_AT_location: |
e2a0d921 NC |
3301 | case DW_AT_string_length: |
3302 | case DW_AT_return_addr: | |
19e6b90e L |
3303 | case DW_AT_data_member_location: |
3304 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
3305 | case DW_AT_segment: |
3306 | case DW_AT_static_link: | |
3307 | case DW_AT_use_location: | |
bc0a77d2 | 3308 | case DW_AT_call_value: |
629e7ca8 | 3309 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 3310 | case DW_AT_call_data_value: |
629e7ca8 | 3311 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 3312 | case DW_AT_call_target: |
629e7ca8 | 3313 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 3314 | case DW_AT_call_target_clobbered: |
629e7ca8 | 3315 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 3316 | if ((dwarf_version < 4 |
b4eb7656 | 3317 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 3318 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 3319 | printf (_(" (location list)")); |
e2a0d921 | 3320 | /* Fall through. */ |
19e6b90e L |
3321 | case DW_AT_allocated: |
3322 | case DW_AT_associated: | |
3323 | case DW_AT_data_location: | |
3324 | case DW_AT_stride: | |
3325 | case DW_AT_upper_bound: | |
cecf136e | 3326 | case DW_AT_lower_bound: |
19e6b90e L |
3327 | if (block_start) |
3328 | { | |
3329 | int need_frame_base; | |
3330 | ||
2e9e81a8 | 3331 | printf ("\t("); |
19e6b90e L |
3332 | need_frame_base = decode_location_expression (block_start, |
3333 | pointer_size, | |
b7807392 JJ |
3334 | offset_size, |
3335 | dwarf_version, | |
19e6b90e | 3336 | uvalue, |
f1c4cc75 | 3337 | cu_offset, section); |
19e6b90e L |
3338 | printf (")"); |
3339 | if (need_frame_base && !have_frame_base) | |
3340 | printf (_(" [without DW_AT_frame_base]")); | |
3341 | } | |
19e6b90e L |
3342 | break; |
3343 | ||
c54207d3 NC |
3344 | case DW_AT_data_bit_offset: |
3345 | case DW_AT_byte_size: | |
3346 | case DW_AT_bit_size: | |
3347 | case DW_AT_string_length_byte_size: | |
3348 | case DW_AT_string_length_bit_size: | |
3349 | case DW_AT_bit_stride: | |
3350 | if (form == DW_FORM_exprloc) | |
3351 | { | |
3352 | printf ("\t("); | |
3353 | (void) decode_location_expression (block_start, pointer_size, | |
3354 | offset_size, dwarf_version, | |
3355 | uvalue, cu_offset, section); | |
3356 | printf (")"); | |
3357 | } | |
3358 | break; | |
3359 | ||
ec4d4525 NC |
3360 | case DW_AT_import: |
3361 | { | |
bcd213b2 NC |
3362 | unsigned long abbrev_number; |
3363 | abbrev_entry *entry; | |
2b6f5997 | 3364 | |
bcd213b2 NC |
3365 | entry = get_type_abbrev_from_form (form, uvalue, cu_offset, |
3366 | section, & abbrev_number, NULL, NULL); | |
3367 | if (entry == NULL) | |
3368 | { | |
3369 | if (form != DW_FORM_GNU_ref_alt) | |
3370 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), | |
3371 | dwarf_vmatoa ("x", uvalue), | |
3372 | (unsigned long) (orig_data - section->start)); | |
3373 | } | |
6e3d6dc1 NC |
3374 | else |
3375 | { | |
2e9e81a8 | 3376 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
bcd213b2 | 3377 | printf (" (%s)", get_TAG_name (entry->tag)); |
6e3d6dc1 NC |
3378 | printf ("]"); |
3379 | } | |
ec4d4525 NC |
3380 | } |
3381 | break; | |
3382 | ||
19e6b90e L |
3383 | default: |
3384 | break; | |
3385 | } | |
3386 | ||
3387 | return data; | |
3388 | } | |
3389 | ||
19e6b90e | 3390 | static unsigned char * |
dda8d76d NC |
3391 | read_and_display_attr (unsigned long attribute, |
3392 | unsigned long form, | |
3393 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 3394 | unsigned char * start, |
dda8d76d NC |
3395 | unsigned char * data, |
3396 | unsigned char * end, | |
3397 | dwarf_vma cu_offset, | |
3398 | dwarf_vma pointer_size, | |
3399 | dwarf_vma offset_size, | |
3400 | int dwarf_version, | |
3401 | debug_info * debug_info_p, | |
3402 | int do_loc, | |
3403 | struct dwarf_section * section, | |
ec1b0fbb NC |
3404 | struct cu_tu_set * this_set, |
3405 | int level) | |
19e6b90e L |
3406 | { |
3407 | if (!do_loc) | |
750f03b7 | 3408 | printf (" %-18s:", get_AT_name (attribute)); |
ec1b0fbb NC |
3409 | data = read_and_display_attr_value (attribute, form, implicit_const, |
3410 | start, data, end, | |
f6f0e17b | 3411 | cu_offset, pointer_size, offset_size, |
19e6b90e | 3412 | dwarf_version, debug_info_p, |
ec1b0fbb | 3413 | do_loc, section, this_set, ' ', level); |
19e6b90e L |
3414 | if (!do_loc) |
3415 | printf ("\n"); | |
3416 | return data; | |
3417 | } | |
3418 | ||
dda8d76d | 3419 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
3420 | following debug links, then attempt to load the requested section |
3421 | from one of the separate debug info files. */ | |
dda8d76d | 3422 | |
015dc7e1 | 3423 | static bool |
dda8d76d | 3424 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, |
24841daa | 3425 | void * handle) |
dda8d76d | 3426 | { |
24841daa | 3427 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 3428 | { |
24841daa NC |
3429 | if (debug_displays[sec_enum].section.filename == NULL) |
3430 | { | |
3431 | /* See if we can associate a filename with this section. */ | |
3432 | separate_info * i; | |
3433 | ||
3434 | for (i = first_separate_info; i != NULL; i = i->next) | |
3435 | if (i->handle == handle) | |
3436 | { | |
3437 | debug_displays[sec_enum].section.filename = i->filename; | |
3438 | break; | |
3439 | } | |
3440 | } | |
3441 | ||
015dc7e1 | 3442 | return true; |
dda8d76d NC |
3443 | } |
3444 | ||
24841daa NC |
3445 | if (do_follow_links) |
3446 | { | |
3447 | separate_info * i; | |
3448 | ||
3449 | for (i = first_separate_info; i != NULL; i = i->next) | |
3450 | { | |
3451 | if (load_debug_section (sec_enum, i->handle)) | |
3452 | { | |
3453 | debug_displays[sec_enum].section.filename = i->filename; | |
3454 | ||
3455 | /* FIXME: We should check to see if any of the remaining debug info | |
3456 | files also contain this section, and, umm, do something about it. */ | |
015dc7e1 | 3457 | return true; |
24841daa NC |
3458 | } |
3459 | } | |
3460 | } | |
dda8d76d | 3461 | |
015dc7e1 | 3462 | return false; |
dda8d76d NC |
3463 | } |
3464 | ||
3465 | static void | |
015dc7e1 | 3466 | introduce (struct dwarf_section * section, bool raw) |
dda8d76d NC |
3467 | { |
3468 | if (raw) | |
3469 | { | |
3470 | if (do_follow_links && section->filename) | |
3471 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
3472 | section->name, section->filename); | |
3473 | else | |
3474 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
3475 | } | |
3476 | else | |
3477 | { | |
3478 | if (do_follow_links && section->filename) | |
3479 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
3480 | section->name, section->filename); | |
3481 | else | |
3482 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3483 | } | |
3484 | } | |
521d4b19 | 3485 | |
d85bf2ba NC |
3486 | /* Process the contents of a .debug_info section. |
3487 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
3488 | and we do not want to display anything to the user. | |
3489 | If do_types is TRUE, we are processing a .debug_types section instead of | |
3490 | a .debug_info section. | |
3491 | The information displayed is restricted by the values in DWARF_START_DIE | |
3492 | and DWARF_CUTOFF_LEVEL. | |
3493 | Returns TRUE upon success. Otherwise an error or warning message is | |
3494 | printed and FALSE is returned. */ | |
19e6b90e | 3495 | |
015dc7e1 AM |
3496 | static bool |
3497 | process_debug_info (struct dwarf_section * section, | |
3498 | void *file, | |
3499 | enum dwarf_section_display_enum abbrev_sec, | |
3500 | bool do_loc, | |
3501 | bool do_types) | |
19e6b90e L |
3502 | { |
3503 | unsigned char *start = section->start; | |
3504 | unsigned char *end = start + section->size; | |
3505 | unsigned char *section_begin; | |
3506 | unsigned int unit; | |
3507 | unsigned int num_units = 0; | |
3508 | ||
3509 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3510 | && num_debug_info_entries == 0 |
3511 | && ! do_types) | |
19e6b90e | 3512 | { |
767221a9 | 3513 | dwarf_vma length; |
19e6b90e L |
3514 | |
3515 | /* First scan the section to get the number of comp units. */ | |
3516 | for (section_begin = start, num_units = 0; section_begin < end; | |
3517 | num_units ++) | |
3518 | { | |
3519 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
3520 | will be the length. For a 64-bit DWARF section, it'll be | |
3521 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 3522 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
3523 | |
3524 | if (length == 0xffffffff) | |
3525 | { | |
0c588247 | 3526 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
3527 | section_begin += length + 12; |
3528 | } | |
ec4d4525 NC |
3529 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
3530 | { | |
767221a9 NC |
3531 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
3532 | dwarf_vmatoa ("x", length), section->name); | |
015dc7e1 | 3533 | return false; |
ec4d4525 | 3534 | } |
19e6b90e L |
3535 | else |
3536 | section_begin += length + 4; | |
aca88567 NC |
3537 | |
3538 | /* Negative values are illegal, they may even cause infinite | |
3539 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
3540 | relocations to an object file, or if the file is corrupt. */ |
3541 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 3542 | { |
767221a9 NC |
3543 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
3544 | dwarf_vmatoa ("x", length), section->name); | |
015dc7e1 | 3545 | return false; |
aca88567 | 3546 | } |
19e6b90e L |
3547 | } |
3548 | ||
3549 | if (num_units == 0) | |
3550 | { | |
f41e4712 | 3551 | error (_("No comp units in %s section ?\n"), section->name); |
015dc7e1 | 3552 | return false; |
19e6b90e L |
3553 | } |
3554 | ||
3555 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 3556 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 3557 | sizeof (* debug_information)); |
19e6b90e L |
3558 | if (debug_information == NULL) |
3559 | { | |
f41e4712 | 3560 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 3561 | num_units); |
82b1b41b | 3562 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
015dc7e1 | 3563 | return false; |
19e6b90e | 3564 | } |
d85bf2ba | 3565 | |
03a91817 NC |
3566 | /* PR 17531: file: 92ca3797. |
3567 | We cannot rely upon the debug_information array being initialised | |
3568 | before it is used. A corrupt file could easily contain references | |
3569 | to a unit for which information has not been made available. So | |
3570 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
3571 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
3572 | ||
82b1b41b | 3573 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
3574 | } |
3575 | ||
3576 | if (!do_loc) | |
3577 | { | |
dda8d76d NC |
3578 | load_debug_section_with_follow (str, file); |
3579 | load_debug_section_with_follow (line_str, file); | |
3580 | load_debug_section_with_follow (str_dwo, file); | |
3581 | load_debug_section_with_follow (str_index, file); | |
3582 | load_debug_section_with_follow (str_index_dwo, file); | |
3583 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e | 3584 | } |
521d4b19 | 3585 | |
dda8d76d | 3586 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 3587 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
3588 | { |
3589 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 3590 | debug_displays [abbrev_sec].section.uncompressed_name); |
015dc7e1 | 3591 | return false; |
19e6b90e L |
3592 | } |
3593 | ||
dda8d76d | 3594 | if (!do_loc && dwarf_start_die == 0) |
015dc7e1 | 3595 | introduce (section, false); |
bcd213b2 NC |
3596 | |
3597 | free_all_abbrevs (); | |
3598 | free (cu_abbrev_map); | |
3599 | cu_abbrev_map = NULL; | |
3600 | next_free_abbrev_map_entry = 0; | |
521d4b19 | 3601 | |
bcd213b2 NC |
3602 | /* In order to be able to resolve DW_FORM_ref_attr forms we need |
3603 | to load *all* of the abbrevs for all CUs in this .debug_info | |
3604 | section. This does effectively mean that we (partially) read | |
3605 | every CU header twice. */ | |
3606 | for (section_begin = start; start < end;) | |
3607 | { | |
3608 | DWARF2_Internal_CompUnit compunit; | |
3609 | unsigned char * hdrptr; | |
76868f36 L |
3610 | dwarf_vma abbrev_base; |
3611 | size_t abbrev_size; | |
bcd213b2 NC |
3612 | dwarf_vma cu_offset; |
3613 | unsigned int offset_size; | |
3614 | unsigned int initial_length_size; | |
3615 | struct cu_tu_set * this_set; | |
3616 | abbrev_list * list; | |
3617 | ||
3618 | hdrptr = start; | |
3619 | ||
3620 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); | |
3621 | ||
3622 | if (compunit.cu_length == 0xffffffff) | |
3623 | { | |
3624 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); | |
3625 | offset_size = 8; | |
3626 | initial_length_size = 12; | |
3627 | } | |
3628 | else | |
3629 | { | |
3630 | offset_size = 4; | |
3631 | initial_length_size = 4; | |
3632 | } | |
3633 | ||
3634 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); | |
3635 | ||
3636 | cu_offset = start - section_begin; | |
3637 | ||
3638 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); | |
3639 | ||
3640 | if (compunit.cu_version < 5) | |
3641 | { | |
3642 | compunit.cu_unit_type = DW_UT_compile; | |
3643 | /* Initialize it due to a false compiler warning. */ | |
3644 | compunit.cu_pointer_size = -1; | |
3645 | } | |
3646 | else | |
3647 | { | |
3648 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3649 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3650 | ||
3651 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3652 | } | |
3653 | ||
3654 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); | |
3655 | ||
9b87f84a TV |
3656 | if (compunit.cu_unit_type == DW_UT_split_compile |
3657 | || compunit.cu_unit_type == DW_UT_skeleton) | |
3658 | { | |
3659 | uint64_t dwo_id; | |
3660 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end); | |
3661 | } | |
3662 | ||
76868f36 L |
3663 | if (this_set == NULL) |
3664 | { | |
3665 | abbrev_base = 0; | |
3666 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3667 | } | |
3668 | else | |
3669 | { | |
3670 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3671 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3672 | } | |
3673 | ||
3674 | list = find_abbrev_list_by_abbrev_offset (abbrev_base, | |
3675 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3676 | if (list == NULL) |
3677 | { | |
bcd213b2 NC |
3678 | unsigned char * next; |
3679 | ||
76868f36 L |
3680 | list = new_abbrev_list (abbrev_base, |
3681 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3682 | next = process_abbrev_set |
3683 | (((unsigned char *) debug_displays [abbrev_sec].section.start | |
3684 | + abbrev_base + compunit.cu_abbrev_offset), | |
3685 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3686 | + abbrev_base + abbrev_size), | |
3687 | list); | |
3688 | list->start_of_next_abbrevs = next; | |
3689 | } | |
521d4b19 | 3690 | |
bcd213b2 NC |
3691 | start = section_begin + cu_offset + compunit.cu_length |
3692 | + initial_length_size; | |
3693 | record_abbrev_list_for_cu (cu_offset, start - section_begin, list); | |
3694 | } | |
3695 | ||
3696 | for (start = section_begin, unit = 0; start < end; unit++) | |
19e6b90e L |
3697 | { |
3698 | DWARF2_Internal_CompUnit compunit; | |
3699 | unsigned char *hdrptr; | |
19e6b90e | 3700 | unsigned char *tags; |
fd2f0033 | 3701 | int level, last_level, saved_level; |
467c65bc | 3702 | dwarf_vma cu_offset; |
e98fdf1a | 3703 | unsigned long sec_off; |
bf5117e3 | 3704 | unsigned int offset_size; |
19485196 | 3705 | unsigned int initial_length_size; |
74bc6052 CC |
3706 | dwarf_vma signature_high = 0; |
3707 | dwarf_vma signature_low = 0; | |
767221a9 | 3708 | dwarf_vma type_offset = 0; |
341f9135 CC |
3709 | struct cu_tu_set *this_set; |
3710 | dwarf_vma abbrev_base; | |
3711 | size_t abbrev_size; | |
bcd213b2 | 3712 | abbrev_list * list = NULL; |
19e6b90e L |
3713 | |
3714 | hdrptr = start; | |
3715 | ||
0c588247 | 3716 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
3717 | |
3718 | if (compunit.cu_length == 0xffffffff) | |
3719 | { | |
0c588247 | 3720 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
3721 | offset_size = 8; |
3722 | initial_length_size = 12; | |
3723 | } | |
3724 | else | |
3725 | { | |
3726 | offset_size = 4; | |
3727 | initial_length_size = 4; | |
3728 | } | |
3729 | ||
0c588247 | 3730 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
3731 | |
3732 | cu_offset = start - section_begin; | |
19e6b90e | 3733 | |
341f9135 CC |
3734 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3735 | ||
77145576 JK |
3736 | if (compunit.cu_version < 5) |
3737 | { | |
3738 | compunit.cu_unit_type = DW_UT_compile; | |
3739 | /* Initialize it due to a false compiler warning. */ | |
3740 | compunit.cu_pointer_size = -1; | |
3741 | } | |
3742 | else | |
3743 | { | |
3744 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3745 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3746 | ||
3747 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3748 | } | |
3749 | ||
0c588247 | 3750 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 3751 | |
341f9135 CC |
3752 | if (this_set == NULL) |
3753 | { | |
3754 | abbrev_base = 0; | |
3755 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3756 | } | |
3757 | else | |
3758 | { | |
3759 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3760 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3761 | } | |
3762 | ||
77145576 JK |
3763 | if (compunit.cu_version < 5) |
3764 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3765 | ||
015dc7e1 | 3766 | bool do_dwo_id = false; |
e6ca1878 | 3767 | uint64_t dwo_id = 0; |
9b87f84a TV |
3768 | if (compunit.cu_unit_type == DW_UT_split_compile |
3769 | || compunit.cu_unit_type == DW_UT_skeleton) | |
3770 | { | |
9b87f84a | 3771 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end); |
015dc7e1 | 3772 | do_dwo_id = true; |
9b87f84a TV |
3773 | } |
3774 | ||
f41e4712 NC |
3775 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
3776 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
3777 | { | |
3778 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
3779 | compunit.cu_pointer_size, offset_size); | |
3780 | compunit.cu_pointer_size = offset_size; | |
3781 | } | |
2b6f5997 CC |
3782 | |
3783 | if (do_types) | |
b4eb7656 | 3784 | { |
0c588247 | 3785 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 3786 | hdrptr += 8; |
0c588247 | 3787 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 3788 | } |
2b6f5997 | 3789 | |
ae7e7825 NC |
3790 | if (dwarf_start_die > (cu_offset + compunit.cu_length |
3791 | + initial_length_size)) | |
3792 | { | |
3793 | start = section_begin + cu_offset + compunit.cu_length | |
3794 | + initial_length_size; | |
3795 | continue; | |
3796 | } | |
3797 | ||
19e6b90e | 3798 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 | 3799 | && num_debug_info_entries == 0 |
c4b2f181 | 3800 | && alloc_num_debug_info_entries > unit |
2b6f5997 | 3801 | && ! do_types) |
19e6b90e L |
3802 | { |
3803 | debug_information [unit].cu_offset = cu_offset; | |
3804 | debug_information [unit].pointer_size | |
3805 | = compunit.cu_pointer_size; | |
b7807392 JJ |
3806 | debug_information [unit].offset_size = offset_size; |
3807 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 3808 | debug_information [unit].base_address = 0; |
4723351a CC |
3809 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
3810 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
3811 | debug_information [unit].loc_offsets = NULL; |
3812 | debug_information [unit].have_frame_base = NULL; | |
3813 | debug_information [unit].max_loc_offsets = 0; | |
3814 | debug_information [unit].num_loc_offsets = 0; | |
3815 | debug_information [unit].range_lists = NULL; | |
3816 | debug_information [unit].max_range_lists= 0; | |
3817 | debug_information [unit].num_range_lists = 0; | |
3818 | } | |
3819 | ||
fd2f0033 | 3820 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 3821 | { |
47704ddf KT |
3822 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3823 | dwarf_vmatoa ("x", cu_offset)); | |
3824 | printf (_(" Length: 0x%s (%s)\n"), | |
3825 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3826 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3827 | printf (_(" Version: %d\n"), compunit.cu_version); |
debd1a62 MW |
3828 | if (compunit.cu_version >= 5) |
3829 | printf (_(" Unit Type: %s (%x)\n"), | |
3830 | get_DW_UT_name (compunit.cu_unit_type) ?: "???", | |
3831 | compunit.cu_unit_type); | |
7282333f AM |
3832 | printf (_(" Abbrev Offset: 0x%s\n"), |
3833 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3834 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3835 | if (do_types) |
3836 | { | |
74bc6052 CC |
3837 | char buf[64]; |
3838 | ||
3839 | printf (_(" Signature: 0x%s\n"), | |
3840 | dwarf_vmatoa64 (signature_high, signature_low, | |
3841 | buf, sizeof (buf))); | |
3842 | printf (_(" Type Offset: 0x%s\n"), | |
3843 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3844 | } |
d60f7998 TV |
3845 | if (do_dwo_id) |
3846 | printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id)); | |
341f9135 CC |
3847 | if (this_set != NULL) |
3848 | { | |
3849 | dwarf_vma *offsets = this_set->section_offsets; | |
3850 | size_t *sizes = this_set->section_sizes; | |
3851 | ||
3852 | printf (_(" Section contributions:\n")); | |
3853 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3854 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3855 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3856 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3857 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3858 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3859 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3860 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3861 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3862 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3863 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3864 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3865 | } | |
19e6b90e L |
3866 | } |
3867 | ||
e98fdf1a AM |
3868 | sec_off = cu_offset + initial_length_size; |
3869 | if (sec_off + compunit.cu_length < sec_off | |
3870 | || sec_off + compunit.cu_length > section->size) | |
460c89ff | 3871 | { |
e98fdf1a AM |
3872 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
3873 | section->name, | |
3874 | (unsigned long) cu_offset, | |
19485196 NC |
3875 | dwarf_vmatoa ("x", compunit.cu_length)); |
3876 | num_units = unit; | |
3877 | break; | |
3878 | } | |
3879 | ||
460c89ff NS |
3880 | tags = hdrptr; |
3881 | start += compunit.cu_length + initial_length_size; | |
3882 | ||
77145576 | 3883 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3884 | { |
47704ddf KT |
3885 | warn (_("CU at offset %s contains corrupt or " |
3886 | "unsupported version number: %d.\n"), | |
3887 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3888 | continue; |
3889 | } | |
3890 | ||
77145576 | 3891 | if (compunit.cu_unit_type != DW_UT_compile |
ec47b32a | 3892 | && compunit.cu_unit_type != DW_UT_partial |
9b87f84a TV |
3893 | && compunit.cu_unit_type != DW_UT_type |
3894 | && compunit.cu_unit_type != DW_UT_split_compile | |
3895 | && compunit.cu_unit_type != DW_UT_skeleton) | |
77145576 JK |
3896 | { |
3897 | warn (_("CU at offset %s contains corrupt or " | |
3898 | "unsupported unit type: %d.\n"), | |
3899 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3900 | continue; | |
3901 | } | |
3902 | ||
d493b283 | 3903 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 3904 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
3905 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
3906 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 3907 | (unsigned long) abbrev_size); |
b4eb7656 | 3908 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
3909 | else if ((abbrev_base + abbrev_size) |
3910 | > debug_displays [abbrev_sec].section.size) | |
3911 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
3912 | (unsigned long) abbrev_base + abbrev_size, | |
3913 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff | 3914 | else |
bcd213b2 | 3915 | { |
76868f36 L |
3916 | list = find_abbrev_list_by_abbrev_offset (abbrev_base, |
3917 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3918 | if (list == NULL) |
3919 | { | |
3920 | unsigned char * next; | |
3921 | ||
76868f36 L |
3922 | list = new_abbrev_list (abbrev_base, |
3923 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3924 | next = process_abbrev_set |
3925 | (((unsigned char *) debug_displays [abbrev_sec].section.start | |
3926 | + abbrev_base + compunit.cu_abbrev_offset), | |
3927 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3928 | + abbrev_base + abbrev_size), | |
3929 | list); | |
3930 | list->start_of_next_abbrevs = next; | |
3931 | } | |
3932 | } | |
19e6b90e L |
3933 | |
3934 | level = 0; | |
fd2f0033 TT |
3935 | last_level = level; |
3936 | saved_level = -1; | |
19e6b90e L |
3937 | while (tags < start) |
3938 | { | |
19e6b90e | 3939 | unsigned long abbrev_number; |
ec4d4525 | 3940 | unsigned long die_offset; |
19e6b90e L |
3941 | abbrev_entry *entry; |
3942 | abbrev_attr *attr; | |
fd2f0033 | 3943 | int do_printing = 1; |
19e6b90e | 3944 | |
ec4d4525 NC |
3945 | die_offset = tags - section_begin; |
3946 | ||
cd30bcef | 3947 | READ_ULEB (abbrev_number, tags, start); |
19e6b90e | 3948 | |
eb7cc021 JK |
3949 | /* A null DIE marks the end of a list of siblings or it may also be |
3950 | a section padding. */ | |
19e6b90e L |
3951 | if (abbrev_number == 0) |
3952 | { | |
eb7cc021 JK |
3953 | /* Check if it can be a section padding for the last CU. */ |
3954 | if (level == 0 && start == end) | |
3955 | { | |
3956 | unsigned char *chk; | |
3957 | ||
3958 | for (chk = tags; chk < start; chk++) | |
3959 | if (*chk != 0) | |
3960 | break; | |
3961 | if (chk == start) | |
3962 | break; | |
3963 | } | |
3964 | ||
4337774f TT |
3965 | if (!do_loc && die_offset >= dwarf_start_die |
3966 | && (dwarf_cutoff_level == -1 | |
3967 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3968 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3969 | level, die_offset); | |
3970 | ||
19e6b90e | 3971 | --level; |
ec4d4525 NC |
3972 | if (level < 0) |
3973 | { | |
3974 | static unsigned num_bogus_warns = 0; | |
3975 | ||
3976 | if (num_bogus_warns < 3) | |
3977 | { | |
4723351a CC |
3978 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3979 | die_offset, section->name); | |
ec4d4525 NC |
3980 | num_bogus_warns ++; |
3981 | if (num_bogus_warns == 3) | |
3982 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3983 | } | |
3984 | } | |
fd2f0033 | 3985 | if (dwarf_start_die != 0 && level < saved_level) |
015dc7e1 | 3986 | return true; |
19e6b90e L |
3987 | continue; |
3988 | } | |
3989 | ||
4b78141a | 3990 | if (!do_loc) |
fd2f0033 TT |
3991 | { |
3992 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
3993 | do_printing = 0; | |
3994 | else | |
3995 | { | |
3996 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
3997 | saved_level = level; | |
3998 | do_printing = (dwarf_cutoff_level == -1 | |
3999 | || level < dwarf_cutoff_level); | |
4000 | if (do_printing) | |
4001 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
4002 | level, die_offset, abbrev_number); | |
4003 | else if (dwarf_cutoff_level == -1 | |
4004 | || last_level < dwarf_cutoff_level) | |
4005 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
4006 | last_level = level; | |
4007 | } | |
4008 | } | |
cecf136e | 4009 | |
19e6b90e L |
4010 | /* Scan through the abbreviation list until we reach the |
4011 | correct entry. */ | |
bcd213b2 | 4012 | if (list == NULL) |
19e6b90e L |
4013 | continue; |
4014 | ||
bcd213b2 NC |
4015 | for (entry = list->first_abbrev; entry != NULL; entry = entry->next) |
4016 | if (entry->number == abbrev_number) | |
4017 | break; | |
4018 | ||
19e6b90e L |
4019 | if (entry == NULL) |
4020 | { | |
fd2f0033 | 4021 | if (!do_loc && do_printing) |
4b78141a NC |
4022 | { |
4023 | printf ("\n"); | |
4024 | fflush (stdout); | |
4025 | } | |
f3853b34 | 4026 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 4027 | die_offset, abbrev_number); |
015dc7e1 | 4028 | return false; |
19e6b90e L |
4029 | } |
4030 | ||
fd2f0033 | 4031 | if (!do_loc && do_printing) |
cc5914eb | 4032 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 4033 | |
19e6b90e L |
4034 | switch (entry->tag) |
4035 | { | |
4036 | default: | |
4037 | need_base_address = 0; | |
4038 | break; | |
4039 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
4040 | need_base_address = 1; |
4041 | need_dwo_info = do_loc; | |
19e6b90e L |
4042 | break; |
4043 | case DW_TAG_entry_point: | |
19e6b90e L |
4044 | case DW_TAG_subprogram: |
4045 | need_base_address = 0; | |
4046 | /* Assuming that there is no DW_AT_frame_base. */ | |
4047 | have_frame_base = 0; | |
4048 | break; | |
4049 | } | |
4050 | ||
9f272209 AO |
4051 | debug_info *debug_info_p = |
4052 | (debug_information && unit < alloc_num_debug_info_entries) | |
4053 | ? debug_information + unit : NULL; | |
4054 | ||
4055 | assert (!debug_info_p | |
4056 | || (debug_info_p->num_loc_offsets | |
4057 | == debug_info_p->num_loc_views)); | |
4058 | ||
399c99f7 L |
4059 | for (attr = entry->first_attr; |
4060 | attr && attr->attribute; | |
4061 | attr = attr->next) | |
4b78141a | 4062 | { |
fd2f0033 | 4063 | if (! do_loc && do_printing) |
4b78141a | 4064 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 | 4065 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
4066 | tags = read_and_display_attr (attr->attribute, |
4067 | attr->form, | |
77145576 | 4068 | attr->implicit_const, |
ec1b0fbb | 4069 | section_begin, |
341f9135 | 4070 | tags, |
f6f0e17b | 4071 | end, |
341f9135 | 4072 | cu_offset, |
4b78141a NC |
4073 | compunit.cu_pointer_size, |
4074 | offset_size, | |
4075 | compunit.cu_version, | |
9f272209 | 4076 | debug_info_p, |
341f9135 CC |
4077 | do_loc || ! do_printing, |
4078 | section, | |
ec1b0fbb NC |
4079 | this_set, |
4080 | level); | |
4b78141a | 4081 | } |
cecf136e | 4082 | |
9f272209 AO |
4083 | /* If a locview attribute appears before a location one, |
4084 | make sure we don't associate it with an earlier | |
4085 | loclist. */ | |
4086 | if (debug_info_p) | |
4087 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
4088 | { | |
4089 | case 1: | |
4090 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
4091 | debug_info_p->num_loc_views++; | |
4092 | assert (debug_info_p->num_loc_views | |
4093 | == debug_info_p->num_loc_offsets); | |
4094 | break; | |
4095 | ||
4096 | case 0: | |
4097 | break; | |
4098 | ||
4099 | case -1: | |
4100 | warn(_("DIE has locviews without loclist\n")); | |
4101 | debug_info_p->num_loc_views--; | |
4102 | break; | |
4103 | ||
4104 | default: | |
4105 | assert (0); | |
4106 | } | |
4107 | ||
b4eb7656 AM |
4108 | if (entry->children) |
4109 | ++level; | |
4110 | } | |
19e6b90e | 4111 | } |
cecf136e | 4112 | |
19e6b90e L |
4113 | /* Set num_debug_info_entries here so that it can be used to check if |
4114 | we need to process .debug_loc and .debug_ranges sections. */ | |
4115 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
4116 | && num_debug_info_entries == 0 |
4117 | && ! do_types) | |
82b1b41b | 4118 | { |
b4eb7656 | 4119 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
4120 | num_debug_info_entries = alloc_num_debug_info_entries; |
4121 | else | |
4122 | num_debug_info_entries = num_units; | |
4123 | } | |
cecf136e | 4124 | |
19e6b90e | 4125 | if (!do_loc) |
467c65bc | 4126 | printf ("\n"); |
cecf136e | 4127 | |
015dc7e1 | 4128 | return true; |
19e6b90e L |
4129 | } |
4130 | ||
4131 | /* Locate and scan the .debug_info section in the file and record the pointer | |
4132 | sizes and offsets for the compilation units in it. Usually an executable | |
4133 | will have just one pointer size, but this is not guaranteed, and so we try | |
4134 | not to make any assumptions. Returns zero upon failure, or the number of | |
4135 | compilation units upon success. */ | |
4136 | ||
4137 | static unsigned int | |
4138 | load_debug_info (void * file) | |
4139 | { | |
1febe64d | 4140 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 4141 | section then do not bother to repeat the task. */ |
cc86f28f | 4142 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
4143 | return 0; |
4144 | ||
19e6b90e L |
4145 | /* If we already have the information there is nothing else to do. */ |
4146 | if (num_debug_info_entries > 0) | |
4147 | return num_debug_info_entries; | |
4148 | ||
341f9135 | 4149 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 4150 | (void) load_cu_tu_indexes (file); |
341f9135 | 4151 | |
dda8d76d | 4152 | if (load_debug_section_with_follow (info, file) |
015dc7e1 | 4153 | && process_debug_info (&debug_displays [info].section, file, abbrev, true, false)) |
19e6b90e | 4154 | return num_debug_info_entries; |
82b1b41b | 4155 | |
dda8d76d | 4156 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 4157 | && process_debug_info (&debug_displays [info_dwo].section, file, |
015dc7e1 | 4158 | abbrev_dwo, true, false)) |
4723351a | 4159 | return num_debug_info_entries; |
1febe64d | 4160 | |
cc86f28f | 4161 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 4162 | return 0; |
19e6b90e L |
4163 | } |
4164 | ||
b40bf0a2 NC |
4165 | /* Read a DWARF .debug_line section header starting at DATA. |
4166 | Upon success returns an updated DATA pointer and the LINFO | |
4167 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
4168 | Otherwise returns NULL. */ | |
19e6b90e | 4169 | |
b40bf0a2 NC |
4170 | static unsigned char * |
4171 | read_debug_line_header (struct dwarf_section * section, | |
4172 | unsigned char * data, | |
4173 | unsigned char * end, | |
4174 | DWARF2_Internal_LineInfo * linfo, | |
4175 | unsigned char ** end_of_sequence) | |
4176 | { | |
4177 | unsigned char *hdrptr; | |
b40bf0a2 | 4178 | unsigned int initial_length_size; |
19e6b90e | 4179 | |
b40bf0a2 NC |
4180 | /* Extract information from the Line Number Program Header. |
4181 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 4182 | hdrptr = data; |
19e6b90e | 4183 | |
b40bf0a2 NC |
4184 | /* Get and check the length of the block. */ |
4185 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 4186 | |
b40bf0a2 | 4187 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
4188 | { |
4189 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 4190 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 4191 | linfo->li_offset_size = 8; |
f41e4712 NC |
4192 | initial_length_size = 12; |
4193 | } | |
4194 | else | |
4195 | { | |
77145576 | 4196 | linfo->li_offset_size = 4; |
f41e4712 NC |
4197 | initial_length_size = 4; |
4198 | } | |
19e6b90e | 4199 | |
b40bf0a2 | 4200 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 4201 | { |
8fcc61b4 NC |
4202 | /* If the length field has a relocation against it, then we should |
4203 | not complain if it is inaccurate (and probably negative). This | |
4204 | happens in object files when the .debug_line section is actually | |
4205 | comprised of several different .debug_line.* sections, (some of | |
4206 | which may be removed by linker garbage collection), and a relocation | |
4207 | is used to compute the correct length once that is done. */ | |
77145576 | 4208 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 4209 | { |
8fcc61b4 | 4210 | linfo->li_length = (end - data) - initial_length_size; |
b40bf0a2 NC |
4211 | } |
4212 | else | |
4213 | { | |
8fcc61b4 NC |
4214 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
4215 | (long) linfo->li_length); | |
b40bf0a2 NC |
4216 | return NULL; |
4217 | } | |
f41e4712 | 4218 | } |
19e6b90e | 4219 | |
b40bf0a2 NC |
4220 | /* Get and check the version number. */ |
4221 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
4222 | ||
4223 | if (linfo->li_version != 2 | |
4224 | && linfo->li_version != 3 | |
77145576 JK |
4225 | && linfo->li_version != 4 |
4226 | && linfo->li_version != 5) | |
f41e4712 | 4227 | { |
77145576 JK |
4228 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
4229 | "is currently supported.\n")); | |
b40bf0a2 | 4230 | return NULL; |
f41e4712 | 4231 | } |
19e6b90e | 4232 | |
77145576 JK |
4233 | if (linfo->li_version >= 5) |
4234 | { | |
5496f3c6 | 4235 | SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end); |
77145576 | 4236 | |
5496f3c6 NC |
4237 | SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end); |
4238 | if (linfo->li_segment_size != 0) | |
77145576 JK |
4239 | { |
4240 | warn (_("The %s section contains " | |
4241 | "unsupported segment selector size: %d.\n"), | |
5496f3c6 NC |
4242 | section->name, linfo->li_segment_size); |
4243 | return NULL; | |
77145576 JK |
4244 | } |
4245 | } | |
4246 | ||
4247 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
4248 | linfo->li_offset_size, end); | |
b40bf0a2 | 4249 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 4250 | |
b40bf0a2 | 4251 | if (linfo->li_version >= 4) |
f41e4712 | 4252 | { |
b40bf0a2 | 4253 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 4254 | |
b40bf0a2 | 4255 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
4256 | { |
4257 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 4258 | return NULL; |
a233b20c | 4259 | } |
f41e4712 NC |
4260 | } |
4261 | else | |
b40bf0a2 | 4262 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 4263 | |
b40bf0a2 | 4264 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 4265 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
4266 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
4267 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 4268 | |
b40bf0a2 | 4269 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 4270 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
4271 | if (* end_of_sequence > end) |
4272 | { | |
4c219c2e AM |
4273 | warn (_("Line length %s extends beyond end of section\n"), |
4274 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
4275 | * end_of_sequence = end; |
4276 | return NULL; | |
4277 | } | |
4278 | ||
b40bf0a2 NC |
4279 | return hdrptr; |
4280 | } | |
19e6b90e | 4281 | |
77145576 | 4282 | static unsigned char * |
015dc7e1 AM |
4283 | display_formatted_table (unsigned char *data, |
4284 | unsigned char *start, | |
4285 | unsigned char *end, | |
4286 | const DWARF2_Internal_LineInfo *linfo, | |
4287 | struct dwarf_section *section, | |
4288 | bool is_dir) | |
77145576 JK |
4289 | { |
4290 | unsigned char *format_start, format_count, *format, formati; | |
4291 | dwarf_vma data_count, datai; | |
cd30bcef | 4292 | unsigned int namepass, last_entry = 0; |
5496f3c6 | 4293 | const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table"); |
521d4b19 | 4294 | |
77145576 | 4295 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
546cb2d8 NC |
4296 | if (do_checks && format_count > 5) |
4297 | warn (_("Unexpectedly large number of columns in the %s (%u)\n"), | |
4298 | table_name, format_count); | |
4299 | ||
77145576 JK |
4300 | format_start = data; |
4301 | for (formati = 0; formati < format_count; formati++) | |
4302 | { | |
cd30bcef AM |
4303 | SKIP_ULEB (data, end); |
4304 | SKIP_ULEB (data, end); | |
77145576 JK |
4305 | if (data == end) |
4306 | { | |
5496f3c6 | 4307 | warn (_("%s: Corrupt format description entry\n"), table_name); |
77145576 JK |
4308 | return data; |
4309 | } | |
4310 | } | |
4311 | ||
cd30bcef | 4312 | READ_ULEB (data_count, data, end); |
546cb2d8 | 4313 | if (data_count == 0) |
77145576 | 4314 | { |
546cb2d8 | 4315 | printf (_("\n The %s is empty.\n"), table_name); |
77145576 JK |
4316 | return data; |
4317 | } | |
546cb2d8 | 4318 | else if (data == end) |
77145576 | 4319 | { |
546cb2d8 NC |
4320 | warn (_("%s: Corrupt entry count - expected %s but none found\n"), |
4321 | table_name, dwarf_vmatoa ("x", data_count)); | |
77145576 JK |
4322 | return data; |
4323 | } | |
546cb2d8 | 4324 | |
5496f3c6 NC |
4325 | else if (format_count == 0) |
4326 | { | |
4327 | warn (_("%s: format count is zero, but the table is not empty\n"), | |
4328 | table_name); | |
4329 | return end; | |
4330 | } | |
77145576 | 4331 | |
5496f3c6 NC |
4332 | printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"), |
4333 | table_name, (long) (data - start), dwarf_vmatoa ("u", data_count), | |
4334 | format_count); | |
77145576 JK |
4335 | |
4336 | printf (_(" Entry")); | |
521d4b19 | 4337 | /* Delay displaying name as the last entry for better screen layout. */ |
77145576 JK |
4338 | for (namepass = 0; namepass < 2; namepass++) |
4339 | { | |
4340 | format = format_start; | |
4341 | for (formati = 0; formati < format_count; formati++) | |
4342 | { | |
4343 | dwarf_vma content_type; | |
4344 | ||
cd30bcef | 4345 | READ_ULEB (content_type, format, end); |
77145576 JK |
4346 | if ((content_type == DW_LNCT_path) == (namepass == 1)) |
4347 | switch (content_type) | |
4348 | { | |
4349 | case DW_LNCT_path: | |
4350 | printf (_("\tName")); | |
4351 | break; | |
4352 | case DW_LNCT_directory_index: | |
4353 | printf (_("\tDir")); | |
4354 | break; | |
4355 | case DW_LNCT_timestamp: | |
4356 | printf (_("\tTime")); | |
4357 | break; | |
4358 | case DW_LNCT_size: | |
4359 | printf (_("\tSize")); | |
4360 | break; | |
4361 | case DW_LNCT_MD5: | |
5496f3c6 | 4362 | printf (_("\tMD5\t\t\t")); |
77145576 JK |
4363 | break; |
4364 | default: | |
4365 | printf (_("\t(Unknown format content type %s)"), | |
4366 | dwarf_vmatoa ("u", content_type)); | |
4367 | } | |
cd30bcef | 4368 | SKIP_ULEB (format, end); |
77145576 JK |
4369 | } |
4370 | } | |
4371 | putchar ('\n'); | |
4372 | ||
4373 | for (datai = 0; datai < data_count; datai++) | |
4374 | { | |
4375 | unsigned char *datapass = data; | |
4376 | ||
4377 | printf (" %d", last_entry++); | |
521d4b19 | 4378 | /* Delay displaying name as the last entry for better screen layout. */ |
77145576 JK |
4379 | for (namepass = 0; namepass < 2; namepass++) |
4380 | { | |
4381 | format = format_start; | |
4382 | data = datapass; | |
4383 | for (formati = 0; formati < format_count; formati++) | |
4384 | { | |
4385 | dwarf_vma content_type, form; | |
4386 | ||
cd30bcef AM |
4387 | READ_ULEB (content_type, format, end); |
4388 | READ_ULEB (form, format, end); | |
4389 | data = read_and_display_attr_value (0, form, 0, start, data, end, | |
4390 | 0, 0, linfo->li_offset_size, | |
77145576 JK |
4391 | linfo->li_version, NULL, |
4392 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
ec1b0fbb | 4393 | section, NULL, '\t', -1); |
77145576 JK |
4394 | } |
4395 | } | |
5496f3c6 NC |
4396 | |
4397 | if (data == end && (datai < data_count - 1)) | |
77145576 | 4398 | { |
5496f3c6 | 4399 | warn (_("\n%s: Corrupt entries list\n"), table_name); |
77145576 JK |
4400 | return data; |
4401 | } | |
4402 | putchar ('\n'); | |
4403 | } | |
4404 | return data; | |
4405 | } | |
4406 | ||
e38332c2 NC |
4407 | static int |
4408 | display_debug_sup (struct dwarf_section * section, | |
4409 | void * file ATTRIBUTE_UNUSED) | |
4410 | { | |
4411 | unsigned char * start = section->start; | |
4412 | unsigned char * end = section->start + section->size; | |
4413 | unsigned int version; | |
4414 | char is_supplementary; | |
4415 | const unsigned char * sup_filename; | |
4416 | size_t sup_filename_len; | |
4417 | unsigned int num_read; | |
4418 | int status; | |
4419 | dwarf_vma checksum_len; | |
4420 | ||
4421 | ||
015dc7e1 | 4422 | introduce (section, true); |
e38332c2 NC |
4423 | if (section->size < 4) |
4424 | { | |
4425 | error (_("corrupt .debug_sup section: size is too small\n")); | |
4426 | return 0; | |
4427 | } | |
4428 | ||
4429 | /* Read the data. */ | |
4430 | SAFE_BYTE_GET_AND_INC (version, start, 2, end); | |
4431 | if (version < 5) | |
4432 | warn (_("corrupt .debug_sup section: version < 5")); | |
4433 | ||
4434 | SAFE_BYTE_GET_AND_INC (is_supplementary, start, 1, end); | |
4435 | if (is_supplementary != 0 && is_supplementary != 1) | |
4436 | warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n")); | |
4437 | ||
4438 | sup_filename = start; | |
4439 | if (is_supplementary && sup_filename[0] != 0) | |
4440 | warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n")); | |
4441 | ||
4442 | sup_filename_len = strnlen ((const char *) start, end - start); | |
4443 | if (sup_filename_len == (size_t) (end - start)) | |
4444 | { | |
4445 | error (_("corrupt .debug_sup section: filename is not NUL terminated\n")); | |
4446 | return 0; | |
4447 | } | |
4448 | start += sup_filename_len + 1; | |
4449 | ||
015dc7e1 | 4450 | checksum_len = read_leb128 (start, end, false /* unsigned */, & num_read, & status); |
e38332c2 NC |
4451 | if (status) |
4452 | { | |
4453 | error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n")); | |
4454 | checksum_len = 0; | |
4455 | } | |
4456 | start += num_read; | |
4457 | if (checksum_len > (dwarf_vma) (end - start)) | |
4458 | { | |
4459 | error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n")); | |
4460 | checksum_len = end - start; | |
4461 | } | |
4462 | else if (checksum_len < (dwarf_vma) (end - start)) | |
4463 | { | |
4464 | warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"), | |
4465 | (long) ((end - start) - checksum_len)); | |
4466 | } | |
4467 | ||
4468 | printf (_(" Version: %u\n"), version); | |
4469 | printf (_(" Is Supp: %u\n"), is_supplementary); | |
4470 | printf (_(" Filename: %s\n"), sup_filename); | |
4471 | printf (_(" Checksum Len: %lu\n"), (long) checksum_len); | |
4472 | if (checksum_len > 0) | |
4473 | { | |
4474 | printf (_(" Checksum: ")); | |
4475 | while (checksum_len--) | |
4476 | printf ("0x%x ", * start++ ); | |
4477 | printf ("\n"); | |
4478 | } | |
4479 | return 1; | |
4480 | } | |
4481 | ||
b40bf0a2 | 4482 | static int |
dda8d76d NC |
4483 | display_debug_lines_raw (struct dwarf_section * section, |
4484 | unsigned char * data, | |
4485 | unsigned char * end, | |
4486 | void * file) | |
b40bf0a2 NC |
4487 | { |
4488 | unsigned char *start = section->start; | |
ba8826a8 | 4489 | int verbose_view = 0; |
19e6b90e | 4490 | |
015dc7e1 | 4491 | introduce (section, true); |
19e6b90e | 4492 | |
b40bf0a2 NC |
4493 | while (data < end) |
4494 | { | |
4495 | static DWARF2_Internal_LineInfo saved_linfo; | |
4496 | DWARF2_Internal_LineInfo linfo; | |
4497 | unsigned char *standard_opcodes; | |
4498 | unsigned char *end_of_sequence; | |
fe59e83d | 4499 | int i; |
19e6b90e | 4500 | |
24d127aa | 4501 | if (startswith (section->name, ".debug_line.") |
4925cdd7 NC |
4502 | /* Note: the following does not apply to .debug_line.dwo sections. |
4503 | These are full debug_line sections. */ | |
4504 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 4505 | { |
b40bf0a2 NC |
4506 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
4507 | section containing just the Line Number Statements. They are | |
4508 | created by the assembler and intended to be used alongside gcc's | |
4509 | -ffunction-sections command line option. When the linker's | |
4510 | garbage collection decides to discard a .text.<foo> section it | |
4511 | can then also discard the line number information in .debug_line.<foo>. | |
4512 | ||
4925cdd7 | 4513 | Since the section is a fragment it does not have the details |
b40bf0a2 | 4514 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 4515 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
4516 | end_of_sequence = end; |
4517 | standard_opcodes = NULL; | |
4518 | linfo = saved_linfo; | |
058037d3 NC |
4519 | /* PR 17531: file: 0522b371. */ |
4520 | if (linfo.li_line_range == 0) | |
4521 | { | |
1306a742 | 4522 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4523 | return 0; |
4524 | } | |
b40bf0a2 | 4525 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4526 | } |
19e6b90e L |
4527 | else |
4528 | { | |
b40bf0a2 | 4529 | unsigned char * hdrptr; |
19e6b90e | 4530 | |
b40bf0a2 NC |
4531 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4532 | & end_of_sequence)) == NULL) | |
4533 | return 0; | |
19e6b90e | 4534 | |
b40bf0a2 NC |
4535 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
4536 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
4537 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
5496f3c6 NC |
4538 | if (linfo.li_version >= 5) |
4539 | { | |
4540 | printf (_(" Address size (bytes): %d\n"), linfo.li_address_size); | |
4541 | printf (_(" Segment selector (bytes): %d\n"), linfo.li_segment_size); | |
4542 | } | |
77ef8654 | 4543 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
4544 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
4545 | if (linfo.li_version >= 4) | |
4546 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
4547 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
4548 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
4549 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
4550 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 4551 | |
0a9d414a NC |
4552 | /* PR 17512: file: 1665-6428-0.004. */ |
4553 | if (linfo.li_line_range == 0) | |
4554 | { | |
4555 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4556 | linfo.li_line_range = 1; | |
4557 | } | |
77ef8654 | 4558 | |
b40bf0a2 | 4559 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4560 | |
b40bf0a2 NC |
4561 | /* Display the contents of the Opcodes table. */ |
4562 | standard_opcodes = hdrptr; | |
19e6b90e | 4563 | |
6937bb54 NC |
4564 | /* PR 17512: file: 002-417945-0.004. */ |
4565 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
4566 | { | |
4567 | warn (_("Line Base extends beyond end of section\n")); | |
4568 | return 0; | |
4569 | } | |
4570 | ||
b40bf0a2 | 4571 | printf (_("\n Opcodes:\n")); |
19e6b90e | 4572 | |
b40bf0a2 | 4573 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
4574 | printf (ngettext (" Opcode %d has %d arg\n", |
4575 | " Opcode %d has %d args\n", | |
4576 | standard_opcodes[i - 1]), | |
4577 | i, standard_opcodes[i - 1]); | |
19e6b90e | 4578 | |
b40bf0a2 NC |
4579 | /* Display the contents of the Directory table. */ |
4580 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 4581 | |
77145576 | 4582 | if (linfo.li_version >= 5) |
b40bf0a2 | 4583 | { |
dda8d76d | 4584 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 4585 | |
77145576 | 4586 | data = display_formatted_table (data, start, end, &linfo, section, |
015dc7e1 | 4587 | true); |
77145576 | 4588 | data = display_formatted_table (data, start, end, &linfo, section, |
015dc7e1 | 4589 | false); |
77145576 JK |
4590 | } |
4591 | else | |
4592 | { | |
4593 | if (*data == 0) | |
4594 | printf (_("\n The Directory Table is empty.\n")); | |
4595 | else | |
a233b20c | 4596 | { |
77145576 | 4597 | unsigned int last_dir_entry = 0; |
6937bb54 | 4598 | |
77145576 JK |
4599 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
4600 | (long)(data - start)); | |
19e6b90e | 4601 | |
77145576 JK |
4602 | while (data < end && *data != 0) |
4603 | { | |
4604 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 4605 | |
77145576 JK |
4606 | data += strnlen ((char *) data, end - data) + 1; |
4607 | } | |
19e6b90e | 4608 | |
77145576 JK |
4609 | /* PR 17512: file: 002-132094-0.004. */ |
4610 | if (data >= end - 1) | |
4611 | break; | |
4612 | } | |
19e6b90e | 4613 | |
77145576 JK |
4614 | /* Skip the NUL at the end of the table. */ |
4615 | data++; | |
19e6b90e | 4616 | |
77145576 JK |
4617 | /* Display the contents of the File Name table. */ |
4618 | if (*data == 0) | |
4619 | printf (_("\n The File Name Table is empty.\n")); | |
4620 | else | |
4621 | { | |
4622 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
4623 | (long)(data - start)); | |
4624 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 4625 | |
77145576 | 4626 | while (data < end && *data != 0) |
b40bf0a2 | 4627 | { |
77145576 | 4628 | unsigned char *name; |
cd30bcef | 4629 | dwarf_vma val; |
77145576 JK |
4630 | |
4631 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
4632 | name = data; | |
4633 | data += strnlen ((char *) data, end - data) + 1; | |
4634 | ||
cd30bcef AM |
4635 | READ_ULEB (val, data, end); |
4636 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4637 | READ_ULEB (val, data, end); | |
4638 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4639 | READ_ULEB (val, data, end); | |
4640 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
77145576 JK |
4641 | printf ("%.*s\n", (int)(end - name), name); |
4642 | ||
4643 | if (data == end) | |
4644 | { | |
4645 | warn (_("Corrupt file name table entry\n")); | |
4646 | break; | |
4647 | } | |
b40bf0a2 | 4648 | } |
a233b20c | 4649 | } |
77145576 JK |
4650 | |
4651 | /* Skip the NUL at the end of the table. */ | |
4652 | data++; | |
b40bf0a2 | 4653 | } |
19e6b90e | 4654 | |
b40bf0a2 NC |
4655 | putchar ('\n'); |
4656 | saved_linfo = linfo; | |
4657 | } | |
19e6b90e | 4658 | |
b40bf0a2 NC |
4659 | /* Now display the statements. */ |
4660 | if (data >= end_of_sequence) | |
4661 | printf (_(" No Line Number Statements.\n")); | |
4662 | else | |
4663 | { | |
4664 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 4665 | |
b40bf0a2 NC |
4666 | while (data < end_of_sequence) |
4667 | { | |
4668 | unsigned char op_code; | |
4669 | dwarf_signed_vma adv; | |
4670 | dwarf_vma uladv; | |
19e6b90e | 4671 | |
fe59e83d CC |
4672 | printf (" [0x%08lx]", (long)(data - start)); |
4673 | ||
b40bf0a2 | 4674 | op_code = *data++; |
19e6b90e | 4675 | |
b40bf0a2 | 4676 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 4677 | { |
b40bf0a2 NC |
4678 | op_code -= linfo.li_opcode_base; |
4679 | uladv = (op_code / linfo.li_line_range); | |
4680 | if (linfo.li_max_ops_per_insn == 1) | |
4681 | { | |
4682 | uladv *= linfo.li_min_insn_length; | |
4683 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4684 | if (uladv) |
4685 | state_machine_regs.view = 0; | |
b40bf0a2 | 4686 | printf (_(" Special opcode %d: " |
ba8826a8 | 4687 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 4688 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4689 | dwarf_vmatoa ("x", state_machine_regs.address), |
4690 | verbose_view && uladv | |
4691 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4692 | } |
4693 | else | |
4694 | { | |
ba8826a8 AO |
4695 | unsigned addrdelta |
4696 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
4697 | / linfo.li_max_ops_per_insn) |
4698 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
4699 | |
4700 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
4701 | state_machine_regs.op_index |
4702 | = (state_machine_regs.op_index + uladv) | |
4703 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4704 | if (addrdelta) |
4705 | state_machine_regs.view = 0; | |
b40bf0a2 | 4706 | printf (_(" Special opcode %d: " |
ba8826a8 | 4707 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
4708 | op_code, dwarf_vmatoa ("u", uladv), |
4709 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4710 | state_machine_regs.op_index, |
4711 | verbose_view && addrdelta | |
4712 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4713 | } |
4714 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
4715 | state_machine_regs.line += adv; | |
ba8826a8 | 4716 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 4717 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
4718 | if (verbose_view || state_machine_regs.view) |
4719 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4720 | else | |
4721 | putchar ('\n'); | |
4722 | state_machine_regs.view++; | |
19e6b90e | 4723 | } |
cd30bcef AM |
4724 | else |
4725 | switch (op_code) | |
4726 | { | |
4727 | case DW_LNS_extended_op: | |
4728 | data += process_extended_line_op (data, | |
4729 | linfo.li_default_is_stmt, | |
4730 | end); | |
4731 | break; | |
4732 | ||
4733 | case DW_LNS_copy: | |
4734 | printf (_(" Copy")); | |
4735 | if (verbose_view || state_machine_regs.view) | |
4736 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4737 | else | |
4738 | putchar ('\n'); | |
4739 | state_machine_regs.view++; | |
4740 | break; | |
4741 | ||
4742 | case DW_LNS_advance_pc: | |
4743 | READ_ULEB (uladv, data, end); | |
4744 | if (linfo.li_max_ops_per_insn == 1) | |
4745 | { | |
4746 | uladv *= linfo.li_min_insn_length; | |
4747 | state_machine_regs.address += uladv; | |
4748 | if (uladv) | |
4749 | state_machine_regs.view = 0; | |
4750 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
4751 | dwarf_vmatoa ("u", uladv), | |
4752 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4753 | verbose_view && uladv | |
4754 | ? _(" (reset view)") : ""); | |
4755 | } | |
4756 | else | |
4757 | { | |
4758 | unsigned addrdelta | |
4759 | = ((state_machine_regs.op_index + uladv) | |
4760 | / linfo.li_max_ops_per_insn) | |
4761 | * linfo.li_min_insn_length; | |
4762 | state_machine_regs.address | |
4763 | += addrdelta; | |
4764 | state_machine_regs.op_index | |
4765 | = (state_machine_regs.op_index + uladv) | |
4766 | % linfo.li_max_ops_per_insn; | |
4767 | if (addrdelta) | |
4768 | state_machine_regs.view = 0; | |
4769 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
4770 | dwarf_vmatoa ("u", uladv), | |
4771 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4772 | state_machine_regs.op_index, | |
4773 | verbose_view && addrdelta | |
4774 | ? _(" (reset view)") : ""); | |
4775 | } | |
4776 | break; | |
4777 | ||
4778 | case DW_LNS_advance_line: | |
4779 | READ_SLEB (adv, data, end); | |
4780 | state_machine_regs.line += adv; | |
4781 | printf (_(" Advance Line by %s to %d\n"), | |
4782 | dwarf_vmatoa ("d", adv), | |
4783 | state_machine_regs.line); | |
4784 | break; | |
4785 | ||
4786 | case DW_LNS_set_file: | |
4787 | READ_ULEB (uladv, data, end); | |
4788 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
4789 | dwarf_vmatoa ("u", uladv)); | |
4790 | state_machine_regs.file = uladv; | |
4791 | break; | |
4792 | ||
4793 | case DW_LNS_set_column: | |
4794 | READ_ULEB (uladv, data, end); | |
4795 | printf (_(" Set column to %s\n"), | |
4796 | dwarf_vmatoa ("u", uladv)); | |
4797 | state_machine_regs.column = uladv; | |
4798 | break; | |
4799 | ||
4800 | case DW_LNS_negate_stmt: | |
4801 | adv = state_machine_regs.is_stmt; | |
4802 | adv = ! adv; | |
4803 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
4804 | state_machine_regs.is_stmt = adv; | |
4805 | break; | |
4806 | ||
4807 | case DW_LNS_set_basic_block: | |
4808 | printf (_(" Set basic block\n")); | |
4809 | state_machine_regs.basic_block = 1; | |
4810 | break; | |
4811 | ||
4812 | case DW_LNS_const_add_pc: | |
4813 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4814 | if (linfo.li_max_ops_per_insn) | |
4815 | { | |
4816 | uladv *= linfo.li_min_insn_length; | |
4817 | state_machine_regs.address += uladv; | |
4818 | if (uladv) | |
4819 | state_machine_regs.view = 0; | |
4820 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
4821 | dwarf_vmatoa ("u", uladv), | |
4822 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4823 | verbose_view && uladv | |
4824 | ? _(" (reset view)") : ""); | |
4825 | } | |
4826 | else | |
4827 | { | |
4828 | unsigned addrdelta | |
4829 | = ((state_machine_regs.op_index + uladv) | |
4830 | / linfo.li_max_ops_per_insn) | |
4831 | * linfo.li_min_insn_length; | |
4832 | state_machine_regs.address | |
4833 | += addrdelta; | |
4834 | state_machine_regs.op_index | |
4835 | = (state_machine_regs.op_index + uladv) | |
4836 | % linfo.li_max_ops_per_insn; | |
4837 | if (addrdelta) | |
4838 | state_machine_regs.view = 0; | |
4839 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
4840 | dwarf_vmatoa ("u", uladv), | |
4841 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4842 | state_machine_regs.op_index, | |
4843 | verbose_view && addrdelta | |
4844 | ? _(" (reset view)") : ""); | |
4845 | } | |
4846 | break; | |
4847 | ||
4848 | case DW_LNS_fixed_advance_pc: | |
4849 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4850 | state_machine_regs.address += uladv; | |
4851 | state_machine_regs.op_index = 0; | |
4852 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
4853 | dwarf_vmatoa ("u", uladv), | |
4854 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
4855 | /* Do NOT reset view. */ | |
4856 | break; | |
4857 | ||
4858 | case DW_LNS_set_prologue_end: | |
4859 | printf (_(" Set prologue_end to true\n")); | |
4860 | break; | |
4861 | ||
4862 | case DW_LNS_set_epilogue_begin: | |
4863 | printf (_(" Set epilogue_begin to true\n")); | |
4864 | break; | |
4865 | ||
4866 | case DW_LNS_set_isa: | |
4867 | READ_ULEB (uladv, data, end); | |
4868 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
4869 | break; | |
4870 | ||
4871 | default: | |
4872 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4873 | ||
4874 | if (standard_opcodes != NULL) | |
4875 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4876 | { | |
4877 | READ_ULEB (uladv, data, end); | |
4878 | printf ("0x%s%s", dwarf_vmatoa ("x", uladv), | |
4879 | i == 1 ? "" : ", "); | |
4880 | } | |
4881 | putchar ('\n'); | |
4882 | break; | |
4883 | } | |
19e6b90e | 4884 | } |
b40bf0a2 | 4885 | putchar ('\n'); |
19e6b90e | 4886 | } |
19e6b90e L |
4887 | } |
4888 | ||
4889 | return 1; | |
4890 | } | |
4891 | ||
a262ae96 NC |
4892 | typedef struct |
4893 | { | |
467c65bc NC |
4894 | unsigned char *name; |
4895 | unsigned int directory_index; | |
4896 | unsigned int modification_date; | |
4897 | unsigned int length; | |
a262ae96 NC |
4898 | } File_Entry; |
4899 | ||
4900 | /* Output a decoded representation of the .debug_line section. */ | |
4901 | ||
4902 | static int | |
dda8d76d | 4903 | display_debug_lines_decoded (struct dwarf_section * section, |
ec1b0fbb | 4904 | unsigned char * start, |
dda8d76d NC |
4905 | unsigned char * data, |
4906 | unsigned char * end, | |
4907 | void * fileptr) | |
a262ae96 | 4908 | { |
b40bf0a2 NC |
4909 | static DWARF2_Internal_LineInfo saved_linfo; |
4910 | ||
015dc7e1 | 4911 | introduce (section, false); |
a262ae96 NC |
4912 | |
4913 | while (data < end) | |
4914 | { | |
4915 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4916 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4917 | unsigned char *standard_opcodes; |
4918 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4919 | int i; |
4920 | File_Entry *file_table = NULL; | |
143a3db0 | 4921 | unsigned int n_files = 0; |
a262ae96 | 4922 | unsigned char **directory_table = NULL; |
77145576 | 4923 | dwarf_vma n_directories = 0; |
a262ae96 | 4924 | |
24d127aa | 4925 | if (startswith (section->name, ".debug_line.") |
4925cdd7 NC |
4926 | /* Note: the following does not apply to .debug_line.dwo sections. |
4927 | These are full debug_line sections. */ | |
4928 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4929 | { |
4925cdd7 | 4930 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4931 | end_of_sequence = end; |
4932 | standard_opcodes = NULL; | |
4933 | linfo = saved_linfo; | |
058037d3 NC |
4934 | /* PR 17531: file: 0522b371. */ |
4935 | if (linfo.li_line_range == 0) | |
4936 | { | |
1306a742 | 4937 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4938 | return 0; |
4939 | } | |
b40bf0a2 | 4940 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4941 | } |
a262ae96 | 4942 | else |
b4eb7656 | 4943 | { |
b40bf0a2 | 4944 | unsigned char *hdrptr; |
a262ae96 | 4945 | |
b40bf0a2 NC |
4946 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4947 | & end_of_sequence)) == NULL) | |
a233b20c | 4948 | return 0; |
0c588247 | 4949 | |
058037d3 NC |
4950 | /* PR 17531: file: 0522b371. */ |
4951 | if (linfo.li_line_range == 0) | |
4952 | { | |
4953 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4954 | linfo.li_line_range = 1; | |
4955 | } | |
b40bf0a2 | 4956 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4957 | |
b40bf0a2 NC |
4958 | /* Save a pointer to the contents of the Opcodes table. */ |
4959 | standard_opcodes = hdrptr; | |
a262ae96 | 4960 | |
b40bf0a2 NC |
4961 | /* Traverse the Directory table just to count entries. */ |
4962 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4963 | /* PR 20440 */ |
4964 | if (data >= end) | |
4965 | { | |
4966 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4967 | linfo.li_opcode_base); | |
4968 | return 0; | |
4969 | } | |
4970 | ||
77145576 | 4971 | if (linfo.li_version >= 5) |
b40bf0a2 | 4972 | { |
77145576 JK |
4973 | unsigned char *format_start, format_count, *format; |
4974 | dwarf_vma formati, entryi; | |
a262ae96 | 4975 | |
dda8d76d | 4976 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4977 | |
4978 | /* Skip directories format. */ | |
4979 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4980 | if (do_checks && format_count > 1) |
4981 | warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"), | |
4982 | format_count); | |
77145576 JK |
4983 | format_start = data; |
4984 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4985 | { |
cd30bcef AM |
4986 | SKIP_ULEB (data, end); |
4987 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4988 | } |
a262ae96 | 4989 | |
cd30bcef | 4990 | READ_ULEB (n_directories, data, end); |
77145576 | 4991 | if (data == end) |
d8024a91 | 4992 | { |
77145576 | 4993 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
4994 | break; |
4995 | } | |
4996 | ||
070b775f NC |
4997 | if (n_directories == 0) |
4998 | directory_table = NULL; | |
4999 | else | |
5000 | directory_table = (unsigned char **) | |
5001 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 5002 | |
77145576 | 5003 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 5004 | { |
77145576 | 5005 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 5006 | |
77145576 JK |
5007 | format = format_start; |
5008 | for (formati = 0; formati < format_count; formati++) | |
5009 | { | |
5010 | dwarf_vma content_type, form; | |
5011 | dwarf_vma uvalue; | |
5012 | ||
cd30bcef AM |
5013 | READ_ULEB (content_type, format, end); |
5014 | READ_ULEB (form, format, end); | |
77145576 JK |
5015 | if (data == end) |
5016 | { | |
5017 | warn (_("Corrupt directories list\n")); | |
5018 | break; | |
5019 | } | |
5020 | switch (content_type) | |
5021 | { | |
5022 | case DW_LNCT_path: | |
5023 | switch (form) | |
5024 | { | |
5025 | case DW_FORM_string: | |
5026 | *pathp = data; | |
5027 | break; | |
5028 | case DW_FORM_line_strp: | |
5029 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
5030 | end); | |
5031 | /* Remove const by the cast. */ | |
5032 | *pathp = (unsigned char *) | |
5033 | fetch_indirect_line_string (uvalue); | |
5034 | break; | |
5035 | } | |
5036 | break; | |
5037 | } | |
cd30bcef AM |
5038 | data = read_and_display_attr_value (0, form, 0, start, |
5039 | data, end, 0, 0, | |
77145576 JK |
5040 | linfo.li_offset_size, |
5041 | linfo.li_version, | |
5042 | NULL, 1, section, | |
ec1b0fbb | 5043 | NULL, '\t', -1); |
77145576 JK |
5044 | } |
5045 | if (data == end) | |
5046 | { | |
5047 | warn (_("Corrupt directories list\n")); | |
5048 | break; | |
5049 | } | |
5050 | } | |
a262ae96 | 5051 | |
77145576 JK |
5052 | /* Skip files format. */ |
5053 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
5054 | if (do_checks && format_count > 5) |
5055 | warn (_("Unexpectedly large number of columns in the file name table (%u)\n"), | |
5056 | format_count); | |
77145576 JK |
5057 | format_start = data; |
5058 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 5059 | { |
cd30bcef AM |
5060 | SKIP_ULEB (data, end); |
5061 | SKIP_ULEB (data, end); | |
b40bf0a2 | 5062 | } |
a262ae96 | 5063 | |
cd30bcef | 5064 | READ_ULEB (n_files, data, end); |
070b775f | 5065 | if (data == end && n_files > 0) |
d8024a91 | 5066 | { |
77145576 | 5067 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
5068 | break; |
5069 | } | |
5070 | ||
070b775f NC |
5071 | if (n_files == 0) |
5072 | file_table = NULL; | |
5073 | else | |
5074 | file_table = (File_Entry *) xcalloc (1, n_files | |
5075 | * sizeof (File_Entry)); | |
a262ae96 | 5076 | |
77145576 | 5077 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 5078 | { |
77145576 | 5079 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 5080 | |
77145576 JK |
5081 | format = format_start; |
5082 | for (formati = 0; formati < format_count; formati++) | |
5083 | { | |
5084 | dwarf_vma content_type, form; | |
5085 | dwarf_vma uvalue; | |
cd30bcef | 5086 | unsigned char *tmp; |
77145576 | 5087 | |
cd30bcef AM |
5088 | READ_ULEB (content_type, format, end); |
5089 | READ_ULEB (form, format, end); | |
77145576 JK |
5090 | if (data == end) |
5091 | { | |
5092 | warn (_("Corrupt file name list\n")); | |
5093 | break; | |
5094 | } | |
5095 | switch (content_type) | |
5096 | { | |
5097 | case DW_LNCT_path: | |
5098 | switch (form) | |
5099 | { | |
5100 | case DW_FORM_string: | |
5101 | file->name = data; | |
5102 | break; | |
5103 | case DW_FORM_line_strp: | |
5104 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
5105 | end); | |
5106 | /* Remove const by the cast. */ | |
5107 | file->name = (unsigned char *) | |
5108 | fetch_indirect_line_string (uvalue); | |
5109 | break; | |
5110 | } | |
5111 | break; | |
5112 | case DW_LNCT_directory_index: | |
5113 | switch (form) | |
5114 | { | |
5115 | case DW_FORM_data1: | |
5116 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
5117 | end); | |
5118 | break; | |
5119 | case DW_FORM_data2: | |
5120 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
5121 | end); | |
5122 | break; | |
5123 | case DW_FORM_udata: | |
cd30bcef AM |
5124 | tmp = data; |
5125 | READ_ULEB (file->directory_index, tmp, end); | |
77145576 JK |
5126 | break; |
5127 | } | |
5128 | break; | |
5129 | } | |
cd30bcef AM |
5130 | data = read_and_display_attr_value (0, form, 0, start, |
5131 | data, end, 0, 0, | |
77145576 JK |
5132 | linfo.li_offset_size, |
5133 | linfo.li_version, | |
5134 | NULL, 1, section, | |
ec1b0fbb | 5135 | NULL, '\t', -1); |
77145576 JK |
5136 | } |
5137 | if (data == end) | |
5138 | { | |
5139 | warn (_("Corrupt file name list\n")); | |
5140 | break; | |
5141 | } | |
5142 | } | |
5143 | } | |
5144 | else | |
5145 | { | |
5146 | if (*data != 0) | |
b40bf0a2 | 5147 | { |
77145576 JK |
5148 | unsigned char *ptr_directory_table = data; |
5149 | ||
5150 | while (data < end && *data != 0) | |
5151 | { | |
5152 | data += strnlen ((char *) data, end - data) + 1; | |
5153 | n_directories++; | |
5154 | } | |
5155 | ||
5156 | /* PR 20440 */ | |
5157 | if (data >= end) | |
5158 | { | |
5159 | warn (_("directory table ends unexpectedly\n")); | |
5160 | n_directories = 0; | |
5161 | break; | |
5162 | } | |
5163 | ||
5164 | /* Go through the directory table again to save the directories. */ | |
5165 | directory_table = (unsigned char **) | |
5166 | xmalloc (n_directories * sizeof (unsigned char *)); | |
5167 | ||
5168 | i = 0; | |
5169 | while (*ptr_directory_table != 0) | |
5170 | { | |
5171 | directory_table[i] = ptr_directory_table; | |
5172 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
5173 | ptr_directory_table - end) + 1; | |
5174 | i++; | |
5175 | } | |
b40bf0a2 | 5176 | } |
77145576 JK |
5177 | /* Skip the NUL at the end of the table. */ |
5178 | data++; | |
5179 | ||
5180 | /* Traverse the File Name table just to count the entries. */ | |
5181 | if (data < end && *data != 0) | |
b40bf0a2 | 5182 | { |
77145576 JK |
5183 | unsigned char *ptr_file_name_table = data; |
5184 | ||
5185 | while (data < end && *data != 0) | |
db9537d2 | 5186 | { |
cd30bcef AM |
5187 | /* Skip Name, directory index, last modification |
5188 | time and length of file. */ | |
77145576 | 5189 | data += strnlen ((char *) data, end - data) + 1; |
cd30bcef AM |
5190 | SKIP_ULEB (data, end); |
5191 | SKIP_ULEB (data, end); | |
5192 | SKIP_ULEB (data, end); | |
77145576 | 5193 | n_files++; |
db9537d2 | 5194 | } |
a262ae96 | 5195 | |
77145576 JK |
5196 | if (data >= end) |
5197 | { | |
5198 | warn (_("file table ends unexpectedly\n")); | |
5199 | n_files = 0; | |
5200 | break; | |
5201 | } | |
5202 | ||
5203 | /* Go through the file table again to save the strings. */ | |
5204 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 5205 | |
77145576 JK |
5206 | i = 0; |
5207 | while (*ptr_file_name_table != 0) | |
5208 | { | |
77145576 JK |
5209 | file_table[i].name = ptr_file_name_table; |
5210 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
5211 | end - ptr_file_name_table) + 1; | |
5212 | ||
5213 | /* We are not interested in directory, time or size. */ | |
cd30bcef AM |
5214 | READ_ULEB (file_table[i].directory_index, |
5215 | ptr_file_name_table, end); | |
5216 | READ_ULEB (file_table[i].modification_date, | |
5217 | ptr_file_name_table, end); | |
5218 | READ_ULEB (file_table[i].length, | |
5219 | ptr_file_name_table, end); | |
77145576 JK |
5220 | i++; |
5221 | } | |
5222 | i = 0; | |
b40bf0a2 | 5223 | } |
77145576 JK |
5224 | |
5225 | /* Skip the NUL at the end of the table. */ | |
5226 | data++; | |
b40bf0a2 | 5227 | } |
cc5914eb | 5228 | |
77145576 | 5229 | /* Print the Compilation Unit's name and a header. */ |
f082820d | 5230 | if (file_table == NULL) |
070b775f | 5231 | printf (_("CU: No directory table\n")); |
f082820d AM |
5232 | else if (directory_table == NULL) |
5233 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
5234 | else |
5235 | { | |
5236 | unsigned int ix = file_table[0].directory_index; | |
5237 | const char *directory; | |
5238 | ||
5239 | if (ix == 0) | |
5240 | directory = "."; | |
5241 | /* PR 20439 */ | |
5242 | else if (n_directories == 0) | |
5243 | directory = _("<unknown>"); | |
5244 | else if (ix > n_directories) | |
5245 | { | |
5246 | warn (_("directory index %u > number of directories %s\n"), | |
5247 | ix, dwarf_vmatoa ("u", n_directories)); | |
5248 | directory = _("<corrupt>"); | |
5249 | } | |
5250 | else | |
5251 | directory = (char *) directory_table[ix - 1]; | |
5252 | ||
5253 | if (do_wide || strlen (directory) < 76) | |
5254 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
5255 | else | |
5256 | printf ("%s:\n", file_table[0].name); | |
77145576 | 5257 | } |
a262ae96 | 5258 | |
070b775f NC |
5259 | if (n_files > 0) |
5260 | printf (_("File name Line number Starting address View Stmt\n")); | |
5261 | else | |
5262 | printf (_("CU: Empty file name table\n")); | |
b40bf0a2 NC |
5263 | saved_linfo = linfo; |
5264 | } | |
a262ae96 NC |
5265 | |
5266 | /* This loop iterates through the Dwarf Line Number Program. */ | |
5267 | while (data < end_of_sequence) | |
b4eb7656 | 5268 | { |
a262ae96 | 5269 | unsigned char op_code; |
ba8826a8 | 5270 | int xop; |
b4eb7656 AM |
5271 | int adv; |
5272 | unsigned long int uladv; | |
b4eb7656 | 5273 | int is_special_opcode = 0; |
a262ae96 | 5274 | |
b4eb7656 | 5275 | op_code = *data++; |
ba8826a8 | 5276 | xop = op_code; |
a262ae96 | 5277 | |
b4eb7656 | 5278 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 5279 | { |
91d6fa6a | 5280 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
5281 | uladv = (op_code / linfo.li_line_range); |
5282 | if (linfo.li_max_ops_per_insn == 1) | |
5283 | { | |
5284 | uladv *= linfo.li_min_insn_length; | |
5285 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
5286 | if (uladv) |
5287 | state_machine_regs.view = 0; | |
a233b20c JJ |
5288 | } |
5289 | else | |
5290 | { | |
ba8826a8 AO |
5291 | unsigned addrdelta |
5292 | = ((state_machine_regs.op_index + uladv) | |
5293 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 5294 | * linfo.li_min_insn_length; |
ba8826a8 AO |
5295 | state_machine_regs.address |
5296 | += addrdelta; | |
a233b20c JJ |
5297 | state_machine_regs.op_index |
5298 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 5299 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
5300 | if (addrdelta) |
5301 | state_machine_regs.view = 0; | |
a233b20c | 5302 | } |
a262ae96 | 5303 | |
b4eb7656 AM |
5304 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
5305 | state_machine_regs.line += adv; | |
5306 | is_special_opcode = 1; | |
ba8826a8 | 5307 | /* Increment view after printing this row. */ |
b4eb7656 | 5308 | } |
cd30bcef AM |
5309 | else |
5310 | switch (op_code) | |
5311 | { | |
5312 | case DW_LNS_extended_op: | |
5313 | { | |
5314 | unsigned int ext_op_code_len; | |
5315 | unsigned char ext_op_code; | |
5316 | unsigned char *op_code_end; | |
5317 | unsigned char *op_code_data = data; | |
5318 | ||
5319 | READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence); | |
5320 | op_code_end = op_code_data + ext_op_code_len; | |
5321 | if (ext_op_code_len == 0 || op_code_end > end_of_sequence) | |
5322 | { | |
5323 | warn (_("Badly formed extended line op encountered!\n")); | |
5324 | break; | |
5325 | } | |
5326 | ext_op_code = *op_code_data++; | |
5327 | xop = ext_op_code; | |
5328 | xop = -xop; | |
5329 | ||
5330 | switch (ext_op_code) | |
5331 | { | |
5332 | case DW_LNE_end_sequence: | |
5333 | /* Reset stuff after printing this row. */ | |
5334 | break; | |
5335 | case DW_LNE_set_address: | |
5336 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
5337 | op_code_data, | |
5338 | op_code_end - op_code_data, | |
5339 | op_code_end); | |
5340 | state_machine_regs.op_index = 0; | |
5341 | state_machine_regs.view = 0; | |
5342 | break; | |
5343 | case DW_LNE_define_file: | |
5344 | file_table = (File_Entry *) xrealloc | |
5345 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
5346 | ||
5347 | ++state_machine_regs.last_file_entry; | |
5348 | /* Source file name. */ | |
5349 | file_table[n_files].name = op_code_data; | |
5350 | op_code_data += strlen ((char *) op_code_data) + 1; | |
5351 | /* Directory index. */ | |
5352 | READ_ULEB (file_table[n_files].directory_index, | |
5353 | op_code_data, op_code_end); | |
5354 | /* Last modification time. */ | |
5355 | READ_ULEB (file_table[n_files].modification_date, | |
5356 | op_code_data, op_code_end); | |
5357 | /* File length. */ | |
5358 | READ_ULEB (file_table[n_files].length, | |
5359 | op_code_data, op_code_end); | |
5360 | n_files++; | |
5361 | break; | |
5362 | ||
5363 | case DW_LNE_set_discriminator: | |
5364 | case DW_LNE_HP_set_sequence: | |
5365 | /* Simply ignored. */ | |
5366 | break; | |
5367 | ||
5368 | default: | |
5369 | printf (_("UNKNOWN (%u): length %ld\n"), | |
27653fba | 5370 | ext_op_code, (long int) (op_code_data - data)); |
cd30bcef AM |
5371 | break; |
5372 | } | |
5373 | data = op_code_end; | |
5374 | break; | |
5375 | } | |
5376 | case DW_LNS_copy: | |
5377 | /* Increment view after printing this row. */ | |
5378 | break; | |
5379 | ||
5380 | case DW_LNS_advance_pc: | |
5381 | READ_ULEB (uladv, data, end); | |
5382 | if (linfo.li_max_ops_per_insn == 1) | |
5383 | { | |
5384 | uladv *= linfo.li_min_insn_length; | |
5385 | state_machine_regs.address += uladv; | |
5386 | if (uladv) | |
5387 | state_machine_regs.view = 0; | |
5388 | } | |
5389 | else | |
5390 | { | |
5391 | unsigned addrdelta | |
5392 | = ((state_machine_regs.op_index + uladv) | |
5393 | / linfo.li_max_ops_per_insn) | |
5394 | * linfo.li_min_insn_length; | |
5395 | state_machine_regs.address | |
5396 | += addrdelta; | |
5397 | state_machine_regs.op_index | |
5398 | = (state_machine_regs.op_index + uladv) | |
5399 | % linfo.li_max_ops_per_insn; | |
5400 | if (addrdelta) | |
5401 | state_machine_regs.view = 0; | |
5402 | } | |
5403 | break; | |
5404 | ||
5405 | case DW_LNS_advance_line: | |
5406 | READ_SLEB (adv, data, end); | |
5407 | state_machine_regs.line += adv; | |
5408 | break; | |
5409 | ||
5410 | case DW_LNS_set_file: | |
5411 | READ_ULEB (uladv, data, end); | |
5412 | state_machine_regs.file = uladv; | |
5413 | ||
5414 | { | |
5415 | unsigned file = state_machine_regs.file - 1; | |
5416 | unsigned dir; | |
5417 | ||
5418 | if (file_table == NULL || n_files == 0) | |
5419 | printf (_("\n [Use file table entry %d]\n"), file); | |
5420 | /* PR 20439 */ | |
5421 | else if (file >= n_files) | |
5422 | { | |
5423 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
5424 | printf (_("\n <over large file table index %u>"), file); | |
5425 | } | |
5426 | else if ((dir = file_table[file].directory_index) == 0) | |
5427 | /* If directory index is 0, that means current directory. */ | |
5428 | printf ("\n./%s:[++]\n", file_table[file].name); | |
5429 | else if (directory_table == NULL || n_directories == 0) | |
5430 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
5431 | file_table[file].name, dir); | |
5432 | /* PR 20439 */ | |
5433 | else if (dir > n_directories) | |
5434 | { | |
5435 | warn (_("directory index %u > number of directories %s\n"), | |
5436 | dir, dwarf_vmatoa ("u", n_directories)); | |
5437 | printf (_("\n <over large directory table entry %u>\n"), dir); | |
5438 | } | |
5439 | else | |
5440 | printf ("\n%s/%s:\n", | |
5441 | /* The directory index starts counting at 1. */ | |
5442 | directory_table[dir - 1], file_table[file].name); | |
5443 | } | |
5444 | break; | |
5445 | ||
5446 | case DW_LNS_set_column: | |
5447 | READ_ULEB (uladv, data, end); | |
5448 | state_machine_regs.column = uladv; | |
5449 | break; | |
5450 | ||
5451 | case DW_LNS_negate_stmt: | |
5452 | adv = state_machine_regs.is_stmt; | |
5453 | adv = ! adv; | |
5454 | state_machine_regs.is_stmt = adv; | |
5455 | break; | |
5456 | ||
5457 | case DW_LNS_set_basic_block: | |
5458 | state_machine_regs.basic_block = 1; | |
5459 | break; | |
5460 | ||
5461 | case DW_LNS_const_add_pc: | |
5462 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
5463 | if (linfo.li_max_ops_per_insn == 1) | |
5464 | { | |
5465 | uladv *= linfo.li_min_insn_length; | |
5466 | state_machine_regs.address += uladv; | |
5467 | if (uladv) | |
5468 | state_machine_regs.view = 0; | |
5469 | } | |
5470 | else | |
5471 | { | |
5472 | unsigned addrdelta | |
5473 | = ((state_machine_regs.op_index + uladv) | |
5474 | / linfo.li_max_ops_per_insn) | |
5475 | * linfo.li_min_insn_length; | |
5476 | state_machine_regs.address | |
5477 | += addrdelta; | |
5478 | state_machine_regs.op_index | |
5479 | = (state_machine_regs.op_index + uladv) | |
5480 | % linfo.li_max_ops_per_insn; | |
5481 | if (addrdelta) | |
5482 | state_machine_regs.view = 0; | |
5483 | } | |
5484 | break; | |
5485 | ||
5486 | case DW_LNS_fixed_advance_pc: | |
5487 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
5488 | state_machine_regs.address += uladv; | |
5489 | state_machine_regs.op_index = 0; | |
5490 | /* Do NOT reset view. */ | |
5491 | break; | |
5492 | ||
5493 | case DW_LNS_set_prologue_end: | |
5494 | break; | |
5495 | ||
5496 | case DW_LNS_set_epilogue_begin: | |
5497 | break; | |
5498 | ||
5499 | case DW_LNS_set_isa: | |
5500 | READ_ULEB (uladv, data, end); | |
5501 | printf (_(" Set ISA to %lu\n"), uladv); | |
5502 | break; | |
5503 | ||
5504 | default: | |
5505 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
5506 | ||
5507 | if (standard_opcodes != NULL) | |
5508 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
5509 | { | |
5510 | dwarf_vma val; | |
5511 | ||
5512 | READ_ULEB (val, data, end); | |
5513 | printf ("0x%s%s", dwarf_vmatoa ("x", val), | |
5514 | i == 1 ? "" : ", "); | |
5515 | } | |
5516 | putchar ('\n'); | |
5517 | break; | |
5518 | } | |
a262ae96 | 5519 | |
b4eb7656 AM |
5520 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
5521 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
5522 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
5523 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
5524 | { |
5525 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
5526 | char *fileName; | |
5527 | char *newFileName = NULL; | |
5528 | size_t fileNameLength; | |
b40bf0a2 NC |
5529 | |
5530 | if (file_table) | |
db9537d2 NC |
5531 | { |
5532 | unsigned indx = state_machine_regs.file - 1; | |
5533 | /* PR 20439 */ | |
5534 | if (indx >= n_files) | |
5535 | { | |
5536 | warn (_("corrupt file index %u encountered\n"), indx); | |
5537 | fileName = _("<corrupt>"); | |
5538 | } | |
5539 | else | |
5540 | fileName = (char *) file_table[indx].name; | |
5541 | } | |
b40bf0a2 | 5542 | else |
db9537d2 | 5543 | fileName = _("<unknown>"); |
b40bf0a2 NC |
5544 | |
5545 | fileNameLength = strlen (fileName); | |
a262ae96 | 5546 | |
b4eb7656 AM |
5547 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
5548 | { | |
5549 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
5550 | /* Truncate file name */ | |
5551 | strncpy (newFileName, | |
5552 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
5553 | MAX_FILENAME_LENGTH + 1); | |
e1104d08 NC |
5554 | /* FIXME: This is to pacify gcc-10 which can warn that the |
5555 | strncpy above might leave a non-NUL terminated string | |
5556 | in newFileName. It won't, but gcc's analysis doesn't | |
5557 | quite go far enough to discover this. */ | |
5558 | newFileName[MAX_FILENAME_LENGTH] = 0; | |
b4eb7656 AM |
5559 | } |
5560 | else | |
5561 | { | |
5562 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
5563 | strncpy (newFileName, fileName, fileNameLength + 1); | |
5564 | } | |
5565 | ||
af2b3186 TV |
5566 | /* A row with end_seq set to true has a meaningful address, but |
5567 | the other information in the same row is not significant. | |
5568 | In such a row, print line as "-", and don't print | |
5569 | view/is_stmt. */ | |
b4eb7656 AM |
5570 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) |
5571 | { | |
a233b20c | 5572 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5573 | { |
5574 | if (xop == -DW_LNE_end_sequence) | |
5575 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x", | |
5576 | newFileName, "-", | |
5577 | state_machine_regs.address); | |
5578 | else | |
5579 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", | |
5580 | newFileName, state_machine_regs.line, | |
5581 | state_machine_regs.address); | |
5582 | } | |
a233b20c | 5583 | else |
af2b3186 TV |
5584 | { |
5585 | if (xop == -DW_LNE_end_sequence) | |
5586 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5587 | newFileName, "-", | |
5588 | state_machine_regs.address, | |
5589 | state_machine_regs.op_index); | |
5590 | else | |
5591 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5592 | newFileName, state_machine_regs.line, | |
5593 | state_machine_regs.address, | |
5594 | state_machine_regs.op_index); | |
5595 | } | |
b4eb7656 AM |
5596 | } |
5597 | else | |
5598 | { | |
a233b20c | 5599 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5600 | { |
5601 | if (xop == -DW_LNE_end_sequence) | |
5602 | printf ("%s %11s %#18" DWARF_VMA_FMT "x", | |
5603 | newFileName, "-", | |
5604 | state_machine_regs.address); | |
5605 | else | |
5606 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", | |
5607 | newFileName, state_machine_regs.line, | |
5608 | state_machine_regs.address); | |
5609 | } | |
a233b20c | 5610 | else |
af2b3186 TV |
5611 | { |
5612 | if (xop == -DW_LNE_end_sequence) | |
5613 | printf ("%s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5614 | newFileName, "-", | |
5615 | state_machine_regs.address, | |
5616 | state_machine_regs.op_index); | |
5617 | else | |
5618 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5619 | newFileName, state_machine_regs.line, | |
5620 | state_machine_regs.address, | |
5621 | state_machine_regs.op_index); | |
5622 | } | |
b4eb7656 | 5623 | } |
a262ae96 | 5624 | |
af2b3186 TV |
5625 | if (xop != -DW_LNE_end_sequence) |
5626 | { | |
5627 | if (state_machine_regs.view) | |
5628 | printf (" %6u", state_machine_regs.view); | |
5629 | else | |
5630 | printf (" "); | |
17f6ade2 | 5631 | |
af2b3186 TV |
5632 | if (state_machine_regs.is_stmt) |
5633 | printf (" x"); | |
5634 | } | |
17f6ade2 JD |
5635 | |
5636 | putchar ('\n'); | |
ba8826a8 AO |
5637 | state_machine_regs.view++; |
5638 | ||
5639 | if (xop == -DW_LNE_end_sequence) | |
5640 | { | |
5641 | reset_state_machine (linfo.li_default_is_stmt); | |
5642 | putchar ('\n'); | |
5643 | } | |
a262ae96 | 5644 | |
b4eb7656 AM |
5645 | free (newFileName); |
5646 | } | |
5647 | } | |
b40bf0a2 NC |
5648 | |
5649 | if (file_table) | |
5650 | { | |
5651 | free (file_table); | |
5652 | file_table = NULL; | |
5653 | n_files = 0; | |
5654 | } | |
5655 | ||
5656 | if (directory_table) | |
5657 | { | |
5658 | free (directory_table); | |
5659 | directory_table = NULL; | |
5660 | n_directories = 0; | |
5661 | } | |
5662 | ||
a262ae96 NC |
5663 | putchar ('\n'); |
5664 | } | |
5665 | ||
5666 | return 1; | |
5667 | } | |
5668 | ||
5669 | static int | |
77145576 | 5670 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
5671 | { |
5672 | unsigned char *data = section->start; | |
5673 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
5674 | int retValRaw = 1; |
5675 | int retValDecoded = 1; | |
a262ae96 | 5676 | |
008f4c78 NC |
5677 | if (do_debug_lines == 0) |
5678 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
5679 | ||
4cb93e3b | 5680 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 5681 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 5682 | |
4cb93e3b | 5683 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
ec1b0fbb | 5684 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
a262ae96 | 5685 | |
4cb93e3b | 5686 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
5687 | return 0; |
5688 | ||
5689 | return 1; | |
5690 | } | |
5691 | ||
6e3d6dc1 NC |
5692 | static debug_info * |
5693 | find_debug_info_for_offset (unsigned long offset) | |
5694 | { | |
5695 | unsigned int i; | |
5696 | ||
5697 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
5698 | return NULL; | |
5699 | ||
5700 | for (i = 0; i < num_debug_info_entries; i++) | |
5701 | if (debug_information[i].cu_offset == offset) | |
5702 | return debug_information + i; | |
5703 | ||
5704 | return NULL; | |
5705 | } | |
5706 | ||
459d52c8 DE |
5707 | static const char * |
5708 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
5709 | { | |
5710 | /* See gdb/gdb-index.h. */ | |
5711 | static const char * const kinds[] = | |
5712 | { | |
5713 | N_ ("no info"), | |
5714 | N_ ("type"), | |
5715 | N_ ("variable"), | |
5716 | N_ ("function"), | |
5717 | N_ ("other"), | |
5718 | N_ ("unused5"), | |
5719 | N_ ("unused6"), | |
5720 | N_ ("unused7") | |
5721 | }; | |
5722 | ||
5723 | return _ (kinds[kind]); | |
5724 | } | |
5725 | ||
19e6b90e | 5726 | static int |
459d52c8 DE |
5727 | display_debug_pubnames_worker (struct dwarf_section *section, |
5728 | void *file ATTRIBUTE_UNUSED, | |
5729 | int is_gnu) | |
19e6b90e | 5730 | { |
91d6fa6a | 5731 | DWARF2_Internal_PubNames names; |
19e6b90e L |
5732 | unsigned char *start = section->start; |
5733 | unsigned char *end = start + section->size; | |
5734 | ||
6e3d6dc1 NC |
5735 | /* It does not matter if this load fails, |
5736 | we test for that later on. */ | |
5737 | load_debug_info (file); | |
5738 | ||
015dc7e1 | 5739 | introduce (section, false); |
19e6b90e L |
5740 | |
5741 | while (start < end) | |
5742 | { | |
5743 | unsigned char *data; | |
e98fdf1a | 5744 | unsigned long sec_off; |
bf5117e3 | 5745 | unsigned int offset_size, initial_length_size; |
19e6b90e | 5746 | |
e98fdf1a | 5747 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 5748 | if (names.pn_length == 0xffffffff) |
19e6b90e | 5749 | { |
e98fdf1a | 5750 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e L |
5751 | offset_size = 8; |
5752 | initial_length_size = 12; | |
5753 | } | |
5754 | else | |
5755 | { | |
5756 | offset_size = 4; | |
5757 | initial_length_size = 4; | |
5758 | } | |
5759 | ||
e98fdf1a AM |
5760 | sec_off = start - section->start; |
5761 | if (sec_off + names.pn_length < sec_off | |
5762 | || sec_off + names.pn_length > section->size) | |
5763 | { | |
5764 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
5765 | section->name, | |
5766 | sec_off - initial_length_size, | |
5767 | dwarf_vmatoa ("x", names.pn_length)); | |
5768 | break; | |
5769 | } | |
5770 | ||
5771 | data = start; | |
5772 | start += names.pn_length; | |
5773 | ||
0c588247 NC |
5774 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
5775 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
5776 | |
5777 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
5778 | && num_debug_info_entries > 0 | |
91d6fa6a | 5779 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 5780 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 5781 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 5782 | |
0c588247 | 5783 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 5784 | |
058037d3 NC |
5785 | printf (_(" Length: %ld\n"), |
5786 | (long) names.pn_length); | |
5787 | printf (_(" Version: %d\n"), | |
5788 | names.pn_version); | |
5789 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
5790 | (unsigned long) names.pn_offset); | |
5791 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
5792 | (long) names.pn_size); | |
19e6b90e | 5793 | |
91d6fa6a | 5794 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
5795 | { |
5796 | static int warned = 0; | |
5797 | ||
5798 | if (! warned) | |
5799 | { | |
5800 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
5801 | warned = 1; | |
5802 | } | |
5803 | ||
5804 | continue; | |
5805 | } | |
5806 | ||
459d52c8 DE |
5807 | if (is_gnu) |
5808 | printf (_("\n Offset Kind Name\n")); | |
5809 | else | |
5810 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 5811 | |
e98fdf1a | 5812 | while (1) |
19e6b90e | 5813 | { |
f41e4712 | 5814 | bfd_size_type maxprint; |
e98fdf1a | 5815 | dwarf_vma offset; |
f41e4712 | 5816 | |
0c588247 | 5817 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e | 5818 | |
e98fdf1a AM |
5819 | if (offset == 0) |
5820 | break; | |
b4eb7656 | 5821 | |
e98fdf1a AM |
5822 | data += offset_size; |
5823 | if (data >= end) | |
5824 | break; | |
5825 | maxprint = (end - data) - 1; | |
f41e4712 | 5826 | |
e98fdf1a AM |
5827 | if (is_gnu) |
5828 | { | |
5829 | unsigned int kind_data; | |
5830 | gdb_index_symbol_kind kind; | |
5831 | const char *kind_name; | |
5832 | int is_static; | |
5833 | ||
5834 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
5835 | data++; | |
5836 | maxprint --; | |
5837 | /* GCC computes the kind as the upper byte in the CU index | |
5838 | word, and then right shifts it by the CU index size. | |
5839 | Left shift KIND to where the gdb-index.h accessor macros | |
5840 | can use it. */ | |
5841 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
5842 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
5843 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
5844 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
5845 | printf (" %-6lx %s,%-10s %.*s\n", | |
5846 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
5847 | kind_name, (int) maxprint, data); | |
19e6b90e | 5848 | } |
e98fdf1a AM |
5849 | else |
5850 | printf (" %-6lx\t%.*s\n", | |
5851 | (unsigned long) offset, (int) maxprint, data); | |
5852 | ||
5853 | data += strnlen ((char *) data, maxprint) + 1; | |
5854 | if (data >= end) | |
5855 | break; | |
19e6b90e | 5856 | } |
19e6b90e L |
5857 | } |
5858 | ||
5859 | printf ("\n"); | |
5860 | return 1; | |
5861 | } | |
5862 | ||
459d52c8 DE |
5863 | static int |
5864 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
5865 | { | |
5866 | return display_debug_pubnames_worker (section, file, 0); | |
5867 | } | |
5868 | ||
5869 | static int | |
5870 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
5871 | { | |
5872 | return display_debug_pubnames_worker (section, file, 1); | |
5873 | } | |
5874 | ||
19e6b90e L |
5875 | static int |
5876 | display_debug_macinfo (struct dwarf_section *section, | |
5877 | void *file ATTRIBUTE_UNUSED) | |
5878 | { | |
5879 | unsigned char *start = section->start; | |
5880 | unsigned char *end = start + section->size; | |
5881 | unsigned char *curr = start; | |
19e6b90e L |
5882 | enum dwarf_macinfo_record_type op; |
5883 | ||
015dc7e1 | 5884 | introduce (section, false); |
19e6b90e L |
5885 | |
5886 | while (curr < end) | |
5887 | { | |
5888 | unsigned int lineno; | |
0c588247 | 5889 | const unsigned char *string; |
19e6b90e | 5890 | |
3f5e193b | 5891 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
5892 | curr++; |
5893 | ||
5894 | switch (op) | |
5895 | { | |
5896 | case DW_MACINFO_start_file: | |
5897 | { | |
5898 | unsigned int filenum; | |
5899 | ||
cd30bcef AM |
5900 | READ_ULEB (lineno, curr, end); |
5901 | READ_ULEB (filenum, curr, end); | |
19e6b90e L |
5902 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), |
5903 | lineno, filenum); | |
5904 | } | |
5905 | break; | |
5906 | ||
5907 | case DW_MACINFO_end_file: | |
5908 | printf (_(" DW_MACINFO_end_file\n")); | |
5909 | break; | |
5910 | ||
5911 | case DW_MACINFO_define: | |
cd30bcef | 5912 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5913 | string = curr; |
5914 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5915 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
5916 | lineno, string); | |
5917 | break; | |
5918 | ||
5919 | case DW_MACINFO_undef: | |
cd30bcef | 5920 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5921 | string = curr; |
5922 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5923 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
5924 | lineno, string); | |
5925 | break; | |
5926 | ||
5927 | case DW_MACINFO_vendor_ext: | |
5928 | { | |
5929 | unsigned int constant; | |
5930 | ||
cd30bcef | 5931 | READ_ULEB (constant, curr, end); |
0c588247 NC |
5932 | string = curr; |
5933 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5934 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
5935 | constant, string); | |
5936 | } | |
5937 | break; | |
5938 | } | |
5939 | } | |
5940 | ||
5941 | return 1; | |
5942 | } | |
5943 | ||
4ccf1e31 JJ |
5944 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5945 | filename and dirname corresponding to file name table entry with index | |
5946 | FILEIDX. Return NULL on failure. */ | |
5947 | ||
5948 | static unsigned char * | |
f6f0e17b NC |
5949 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5950 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5951 | unsigned char **dir_name) |
5952 | { | |
5953 | struct dwarf_section *section = &debug_displays [line].section; | |
5954 | unsigned char *hdrptr, *dirtable, *file_name; | |
5955 | unsigned int offset_size, initial_length_size; | |
cd30bcef | 5956 | unsigned int version, opcode_base; |
4ccf1e31 | 5957 | dwarf_vma length, diridx; |
f6f0e17b | 5958 | const unsigned char * end; |
4ccf1e31 JJ |
5959 | |
5960 | *dir_name = NULL; | |
5961 | if (section->start == NULL | |
5962 | || line_offset >= section->size | |
5963 | || fileidx == 0) | |
5964 | return NULL; | |
5965 | ||
5966 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5967 | end = section->start + section->size; |
0c588247 NC |
5968 | |
5969 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5970 | if (length == 0xffffffff) |
5971 | { | |
5972 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5973 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
5974 | offset_size = 8; |
5975 | initial_length_size = 12; | |
5976 | } | |
5977 | else | |
5978 | { | |
5979 | offset_size = 4; | |
5980 | initial_length_size = 4; | |
5981 | } | |
e98fdf1a AM |
5982 | if (length + initial_length_size < length |
5983 | || length + initial_length_size > section->size) | |
4ccf1e31 | 5984 | return NULL; |
0c588247 NC |
5985 | |
5986 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5987 | if (version != 2 && version != 3 && version != 4) |
5988 | return NULL; | |
5989 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5990 | if (version >= 4) | |
5991 | hdrptr++; /* Skip max_ops_per_insn. */ | |
5992 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
5993 | |
5994 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
5995 | if (opcode_base == 0) |
5996 | return NULL; | |
0c588247 | 5997 | |
4ccf1e31 | 5998 | hdrptr += opcode_base - 1; |
5c1c468d NC |
5999 | if (hdrptr >= end) |
6000 | return NULL; | |
6001 | ||
4ccf1e31 JJ |
6002 | dirtable = hdrptr; |
6003 | /* Skip over dirname table. */ | |
6004 | while (*hdrptr != '\0') | |
5c1c468d NC |
6005 | { |
6006 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; | |
6007 | if (hdrptr >= end) | |
6008 | return NULL; | |
6009 | } | |
4ccf1e31 | 6010 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 6011 | |
4ccf1e31 | 6012 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 6013 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 6014 | { |
0c588247 | 6015 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
cd30bcef AM |
6016 | SKIP_ULEB (hdrptr, end); |
6017 | SKIP_ULEB (hdrptr, end); | |
6018 | SKIP_ULEB (hdrptr, end); | |
4ccf1e31 | 6019 | } |
5c1c468d | 6020 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 6021 | return NULL; |
5c1c468d | 6022 | |
4ccf1e31 | 6023 | file_name = hdrptr; |
0c588247 | 6024 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
5c1c468d NC |
6025 | if (hdrptr >= end) |
6026 | return NULL; | |
cd30bcef | 6027 | READ_ULEB (diridx, hdrptr, end); |
4ccf1e31 JJ |
6028 | if (diridx == 0) |
6029 | return file_name; | |
5c1c468d | 6030 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
0c588247 | 6031 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
5c1c468d | 6032 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
6033 | return NULL; |
6034 | *dir_name = dirtable; | |
6035 | return file_name; | |
6036 | } | |
6037 | ||
6038 | static int | |
6039 | display_debug_macro (struct dwarf_section *section, | |
6040 | void *file) | |
6041 | { | |
6042 | unsigned char *start = section->start; | |
6043 | unsigned char *end = start + section->size; | |
6044 | unsigned char *curr = start; | |
6045 | unsigned char *extended_op_buf[256]; | |
015dc7e1 | 6046 | bool is_dwo = false; |
d296b736 NC |
6047 | const char *suffix = strrchr (section->name, '.'); |
6048 | ||
6049 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
015dc7e1 | 6050 | is_dwo = true; |
4ccf1e31 | 6051 | |
dda8d76d NC |
6052 | load_debug_section_with_follow (str, file); |
6053 | load_debug_section_with_follow (line, file); | |
e4b7104b | 6054 | load_debug_section_with_follow (str_index, file); |
d296b736 | 6055 | |
015dc7e1 | 6056 | introduce (section, false); |
4ccf1e31 JJ |
6057 | |
6058 | while (curr < end) | |
6059 | { | |
6060 | unsigned int lineno, version, flags; | |
d296b736 | 6061 | unsigned int offset_size; |
0c588247 | 6062 | const unsigned char *string; |
4ccf1e31 JJ |
6063 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
6064 | unsigned char **extended_ops = NULL; | |
6065 | ||
0c588247 | 6066 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 6067 | if (version != 4 && version != 5) |
4ccf1e31 | 6068 | { |
0e12f6c8 TV |
6069 | error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"), |
6070 | section->name, version); | |
4ccf1e31 JJ |
6071 | return 0; |
6072 | } | |
6073 | ||
0c588247 | 6074 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
d296b736 | 6075 | offset_size = (flags & 1) ? 8 : 4; |
4ccf1e31 JJ |
6076 | printf (_(" Offset: 0x%lx\n"), |
6077 | (unsigned long) sec_offset); | |
6078 | printf (_(" Version: %d\n"), version); | |
6079 | printf (_(" Offset size: %d\n"), offset_size); | |
6080 | if (flags & 2) | |
6081 | { | |
0c588247 | 6082 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
6083 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
6084 | (unsigned long) line_offset); | |
6085 | } | |
6086 | if (flags & 4) | |
6087 | { | |
0c588247 | 6088 | unsigned int i, count, op; |
4ccf1e31 | 6089 | dwarf_vma nargs, n; |
0c588247 NC |
6090 | |
6091 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 6092 | |
4ccf1e31 JJ |
6093 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
6094 | extended_ops = extended_op_buf; | |
6095 | if (count) | |
6096 | { | |
6097 | printf (_(" Extension opcode arguments:\n")); | |
6098 | for (i = 0; i < count; i++) | |
6099 | { | |
0c588247 | 6100 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 6101 | extended_ops[op] = curr; |
cd30bcef | 6102 | READ_ULEB (nargs, curr, end); |
4ccf1e31 | 6103 | if (nargs == 0) |
7a7e1061 | 6104 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
6105 | else |
6106 | { | |
7a7e1061 | 6107 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
6108 | for (n = 0; n < nargs; n++) |
6109 | { | |
0c588247 NC |
6110 | unsigned int form; |
6111 | ||
6112 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
6113 | printf ("%s%s", get_FORM_name (form), |
6114 | n == nargs - 1 ? "\n" : ", "); | |
6115 | switch (form) | |
6116 | { | |
6117 | case DW_FORM_data1: | |
6118 | case DW_FORM_data2: | |
6119 | case DW_FORM_data4: | |
6120 | case DW_FORM_data8: | |
6121 | case DW_FORM_sdata: | |
6122 | case DW_FORM_udata: | |
6123 | case DW_FORM_block: | |
6124 | case DW_FORM_block1: | |
6125 | case DW_FORM_block2: | |
6126 | case DW_FORM_block4: | |
6127 | case DW_FORM_flag: | |
6128 | case DW_FORM_string: | |
6129 | case DW_FORM_strp: | |
6130 | case DW_FORM_sec_offset: | |
6131 | break; | |
6132 | default: | |
6133 | error (_("Invalid extension opcode form %s\n"), | |
6134 | get_FORM_name (form)); | |
6135 | return 0; | |
6136 | } | |
6137 | } | |
6138 | } | |
6139 | } | |
6140 | } | |
6141 | } | |
6142 | printf ("\n"); | |
6143 | ||
6144 | while (1) | |
6145 | { | |
6146 | unsigned int op; | |
6147 | ||
6148 | if (curr >= end) | |
6149 | { | |
6150 | error (_(".debug_macro section not zero terminated\n")); | |
6151 | return 0; | |
6152 | } | |
6153 | ||
0c588247 | 6154 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
6155 | if (op == 0) |
6156 | break; | |
6157 | ||
6158 | switch (op) | |
6159 | { | |
e4b7104b NC |
6160 | case DW_MACRO_define: |
6161 | READ_ULEB (lineno, curr, end); | |
6162 | string = curr; | |
6163 | curr += strnlen ((char *) string, end - string) + 1; | |
6164 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), | |
6165 | lineno, string); | |
6166 | break; | |
6167 | ||
6168 | case DW_MACRO_undef: | |
6169 | READ_ULEB (lineno, curr, end); | |
6170 | string = curr; | |
6171 | curr += strnlen ((char *) string, end - string) + 1; | |
6172 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), | |
6173 | lineno, string); | |
6174 | break; | |
6175 | ||
7a7e1061 | 6176 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
6177 | { |
6178 | unsigned int filenum; | |
6179 | unsigned char *file_name = NULL, *dir_name = NULL; | |
6180 | ||
cd30bcef AM |
6181 | READ_ULEB (lineno, curr, end); |
6182 | READ_ULEB (filenum, curr, end); | |
4ccf1e31 JJ |
6183 | |
6184 | if ((flags & 2) == 0) | |
7a7e1061 | 6185 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
6186 | else |
6187 | file_name | |
6188 | = get_line_filename_and_dirname (line_offset, filenum, | |
6189 | &dir_name); | |
6190 | if (file_name == NULL) | |
7a7e1061 | 6191 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
6192 | lineno, filenum); |
6193 | else | |
7a7e1061 | 6194 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
6195 | lineno, filenum, |
6196 | dir_name != NULL ? (const char *) dir_name : "", | |
6197 | dir_name != NULL ? "/" : "", file_name); | |
6198 | } | |
6199 | break; | |
6200 | ||
7a7e1061 JK |
6201 | case DW_MACRO_end_file: |
6202 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
6203 | break; |
6204 | ||
7a7e1061 | 6205 | case DW_MACRO_define_strp: |
cd30bcef | 6206 | READ_ULEB (lineno, curr, end); |
d296b736 NC |
6207 | if (version == 4 && is_dwo) |
6208 | READ_ULEB (offset, curr, end); | |
6209 | else | |
6210 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
4ccf1e31 | 6211 | string = fetch_indirect_string (offset); |
7a7e1061 | 6212 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
6213 | lineno, string); |
6214 | break; | |
6215 | ||
7a7e1061 | 6216 | case DW_MACRO_undef_strp: |
cd30bcef | 6217 | READ_ULEB (lineno, curr, end); |
d296b736 NC |
6218 | if (version == 4 && is_dwo) |
6219 | READ_ULEB (offset, curr, end); | |
6220 | else | |
6221 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
4ccf1e31 | 6222 | string = fetch_indirect_string (offset); |
7a7e1061 | 6223 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
6224 | lineno, string); |
6225 | break; | |
6226 | ||
7a7e1061 | 6227 | case DW_MACRO_import: |
0c588247 | 6228 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6229 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
6230 | (unsigned long) offset); |
6231 | break; | |
6232 | ||
7a7e1061 | 6233 | case DW_MACRO_define_sup: |
cd30bcef | 6234 | READ_ULEB (lineno, curr, end); |
0c588247 | 6235 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6236 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
6237 | lineno, (unsigned long) offset); |
6238 | break; | |
6239 | ||
7a7e1061 | 6240 | case DW_MACRO_undef_sup: |
cd30bcef | 6241 | READ_ULEB (lineno, curr, end); |
0c588247 | 6242 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6243 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
6244 | lineno, (unsigned long) offset); |
6245 | break; | |
6246 | ||
7a7e1061 | 6247 | case DW_MACRO_import_sup: |
0c588247 | 6248 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6249 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
6250 | (unsigned long) offset); |
6251 | break; | |
6252 | ||
e4b7104b NC |
6253 | case DW_MACRO_define_strx: |
6254 | case DW_MACRO_undef_strx: | |
6255 | READ_ULEB (lineno, curr, end); | |
6256 | READ_ULEB (offset, curr, end); | |
6257 | string = (const unsigned char *) | |
015dc7e1 | 6258 | fetch_indexed_string (offset, NULL, offset_size, false); |
e4b7104b NC |
6259 | if (op == DW_MACRO_define_strx) |
6260 | printf (" DW_MACRO_define_strx "); | |
6261 | else | |
6262 | printf (" DW_MACRO_undef_strx "); | |
6263 | if (do_wide) | |
39f381cb | 6264 | printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset)); |
e4b7104b NC |
6265 | printf (_("lineno : %d macro : %s\n"), |
6266 | lineno, string); | |
6267 | break; | |
6268 | ||
4ccf1e31 | 6269 | default: |
e4b7104b NC |
6270 | if (op >= DW_MACRO_lo_user && op <= DW_MACRO_hi_user) |
6271 | { | |
6272 | printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op); | |
6273 | break; | |
6274 | } | |
6275 | ||
4ccf1e31 JJ |
6276 | if (extended_ops == NULL || extended_ops[op] == NULL) |
6277 | { | |
6278 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
6279 | return 0; | |
6280 | } | |
6281 | else | |
6282 | { | |
6283 | /* Skip over unhandled opcodes. */ | |
6284 | dwarf_vma nargs, n; | |
6285 | unsigned char *desc = extended_ops[op]; | |
cd30bcef | 6286 | READ_ULEB (nargs, desc, end); |
4ccf1e31 JJ |
6287 | if (nargs == 0) |
6288 | { | |
7a7e1061 | 6289 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
6290 | break; |
6291 | } | |
7a7e1061 | 6292 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
6293 | for (n = 0; n < nargs; n++) |
6294 | { | |
0c588247 NC |
6295 | int val; |
6296 | ||
77145576 | 6297 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 6298 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 6299 | curr |
77145576 | 6300 | = read_and_display_attr_value (0, val, 0, |
ec1b0fbb | 6301 | start, curr, end, 0, 0, offset_size, |
341f9135 | 6302 | version, NULL, 0, NULL, |
ec1b0fbb | 6303 | NULL, ' ', -1); |
4ccf1e31 JJ |
6304 | if (n != nargs - 1) |
6305 | printf (","); | |
6306 | } | |
6307 | printf ("\n"); | |
6308 | } | |
6309 | break; | |
6310 | } | |
6311 | } | |
6312 | ||
6313 | printf ("\n"); | |
b4eb7656 | 6314 | } |
4ccf1e31 JJ |
6315 | |
6316 | return 1; | |
6317 | } | |
6318 | ||
19e6b90e L |
6319 | static int |
6320 | display_debug_abbrev (struct dwarf_section *section, | |
6321 | void *file ATTRIBUTE_UNUSED) | |
6322 | { | |
6323 | abbrev_entry *entry; | |
6324 | unsigned char *start = section->start; | |
bcd213b2 | 6325 | const unsigned char *end = start + section->size; |
19e6b90e | 6326 | |
015dc7e1 | 6327 | introduce (section, false); |
19e6b90e L |
6328 | |
6329 | do | |
6330 | { | |
bcd213b2 NC |
6331 | abbrev_list * list; |
6332 | dwarf_vma offset; | |
7282333f | 6333 | |
bcd213b2 | 6334 | offset = start - section->start; |
76868f36 | 6335 | list = find_abbrev_list_by_abbrev_offset (0, offset); |
bcd213b2 NC |
6336 | if (list == NULL) |
6337 | { | |
76868f36 | 6338 | list = new_abbrev_list (0, offset); |
bcd213b2 NC |
6339 | start = process_abbrev_set (start, end, list); |
6340 | list->start_of_next_abbrevs = start; | |
6341 | } | |
6342 | else | |
6343 | start = list->start_of_next_abbrevs; | |
19e6b90e | 6344 | |
bcd213b2 | 6345 | if (list->first_abbrev == NULL) |
19e6b90e L |
6346 | continue; |
6347 | ||
bcd213b2 | 6348 | printf (_(" Number TAG (0x%lx)\n"), (long) offset); |
19e6b90e | 6349 | |
bcd213b2 | 6350 | for (entry = list->first_abbrev; entry; entry = entry->next) |
19e6b90e L |
6351 | { |
6352 | abbrev_attr *attr; | |
6353 | ||
cc5914eb | 6354 | printf (" %ld %s [%s]\n", |
bcd213b2 | 6355 | entry->number, |
19e6b90e L |
6356 | get_TAG_name (entry->tag), |
6357 | entry->children ? _("has children") : _("no children")); | |
6358 | ||
6359 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
6360 | { |
6361 | printf (" %-18s %s", | |
6362 | get_AT_name (attr->attribute), | |
6363 | get_FORM_name (attr->form)); | |
6364 | if (attr->form == DW_FORM_implicit_const) | |
6365 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
6366 | putchar ('\n'); | |
6367 | } | |
19e6b90e L |
6368 | } |
6369 | } | |
6370 | while (start); | |
6371 | ||
6372 | printf ("\n"); | |
6373 | ||
6374 | return 1; | |
6375 | } | |
6376 | ||
42bcef4a AB |
6377 | /* Return true when ADDR is the maximum address, when addresses are |
6378 | POINTER_SIZE bytes long. */ | |
6379 | ||
015dc7e1 | 6380 | static bool |
42bcef4a AB |
6381 | is_max_address (dwarf_vma addr, unsigned int pointer_size) |
6382 | { | |
6383 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
6384 | return ((addr & mask) == mask); | |
6385 | } | |
6386 | ||
9f272209 AO |
6387 | /* Display a view pair list starting at *VSTART_PTR and ending at |
6388 | VLISTEND within SECTION. */ | |
6389 | ||
6390 | static void | |
6391 | display_view_pair_list (struct dwarf_section *section, | |
6392 | unsigned char **vstart_ptr, | |
6393 | unsigned int debug_info_entry, | |
6394 | unsigned char *vlistend) | |
6395 | { | |
6396 | unsigned char *vstart = *vstart_ptr; | |
6397 | unsigned char *section_end = section->start + section->size; | |
6398 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
6399 | ||
6400 | if (vlistend < section_end) | |
6401 | section_end = vlistend; | |
6402 | ||
6403 | putchar ('\n'); | |
6404 | ||
6405 | while (vstart < section_end) | |
6406 | { | |
6407 | dwarf_vma off = vstart - section->start; | |
6408 | dwarf_vma vbegin, vend; | |
6409 | ||
cd30bcef | 6410 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 | 6411 | if (vstart == section_end) |
cd30bcef | 6412 | break; |
9f272209 | 6413 | |
cd30bcef | 6414 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6415 | printf (" %8.8lx ", (unsigned long) off); |
6416 | ||
6417 | print_dwarf_view (vbegin, pointer_size, 1); | |
6418 | print_dwarf_view (vend, pointer_size, 1); | |
6419 | printf (_("location view pair\n")); | |
6420 | } | |
6421 | ||
6422 | putchar ('\n'); | |
6423 | *vstart_ptr = vstart; | |
6424 | } | |
6425 | ||
4723351a CC |
6426 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
6427 | ||
6428 | static void | |
6429 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
6430 | unsigned char **start_ptr, |
6431 | unsigned int debug_info_entry, | |
359ca075 JK |
6432 | dwarf_vma offset, |
6433 | dwarf_vma base_address, | |
9f272209 | 6434 | unsigned char **vstart_ptr, |
b4eb7656 | 6435 | int has_frame_base) |
4723351a | 6436 | { |
9f272209 | 6437 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6438 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6439 | unsigned long cu_offset; |
6440 | unsigned int pointer_size; | |
6441 | unsigned int offset_size; | |
6442 | int dwarf_version; | |
4723351a CC |
6443 | |
6444 | dwarf_vma begin; | |
6445 | dwarf_vma end; | |
6446 | unsigned short length; | |
6447 | int need_frame_base; | |
6448 | ||
82b1b41b NC |
6449 | if (debug_info_entry >= num_debug_info_entries) |
6450 | { | |
6451 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
6452 | debug_info_entry); | |
6453 | return; | |
6454 | } | |
b4eb7656 | 6455 | |
82b1b41b NC |
6456 | cu_offset = debug_information [debug_info_entry].cu_offset; |
6457 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6458 | offset_size = debug_information [debug_info_entry].offset_size; | |
6459 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 6460 | |
f41e4712 NC |
6461 | if (pointer_size < 2 || pointer_size > 8) |
6462 | { | |
6463 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6464 | pointer_size, debug_info_entry); | |
6465 | return; | |
6466 | } | |
6467 | ||
4723351a CC |
6468 | while (1) |
6469 | { | |
359ca075 | 6470 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 6471 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 6472 | |
4723351a | 6473 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
6474 | { |
6475 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6476 | (unsigned long) offset); |
b4eb7656 AM |
6477 | break; |
6478 | } | |
4723351a | 6479 | |
359ca075 | 6480 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 6481 | |
0c588247 NC |
6482 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
6483 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 6484 | |
4723351a | 6485 | if (begin == 0 && end == 0) |
b4eb7656 | 6486 | { |
d1c4b12b NC |
6487 | /* PR 18374: In a object file we can have a location list that |
6488 | starts with a begin and end of 0 because there are relocations | |
6489 | that need to be applied to the addresses. Actually applying | |
6490 | the relocations now does not help as they will probably resolve | |
6491 | to 0, since the object file has not been fully linked. Real | |
6492 | end of list markers will not have any relocations against them. */ | |
6493 | if (! reloc_at (section, off) | |
6494 | && ! reloc_at (section, off + pointer_size)) | |
6495 | { | |
6496 | printf (_("<End of list>\n")); | |
6497 | break; | |
6498 | } | |
b4eb7656 | 6499 | } |
4723351a CC |
6500 | |
6501 | /* Check base address specifiers. */ | |
42bcef4a AB |
6502 | if (is_max_address (begin, pointer_size) |
6503 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
6504 | { |
6505 | base_address = end; | |
6506 | print_dwarf_vma (begin, pointer_size); | |
6507 | print_dwarf_vma (end, pointer_size); | |
6508 | printf (_("(base address)\n")); | |
6509 | continue; | |
6510 | } | |
4723351a | 6511 | |
9f272209 AO |
6512 | if (vstart) |
6513 | { | |
9f272209 AO |
6514 | off = offset + (vstart - *start_ptr); |
6515 | ||
cd30bcef | 6516 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
6517 | print_dwarf_view (vbegin, pointer_size, 1); |
6518 | ||
cd30bcef | 6519 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6520 | print_dwarf_view (vend, pointer_size, 1); |
6521 | ||
6522 | printf (_("views at %8.8lx for:\n %*s "), | |
6523 | (unsigned long) off, 8, ""); | |
6524 | } | |
6525 | ||
4723351a | 6526 | if (start + 2 > section_end) |
b4eb7656 AM |
6527 | { |
6528 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6529 | (unsigned long) offset); |
b4eb7656 AM |
6530 | break; |
6531 | } | |
4723351a | 6532 | |
0c588247 | 6533 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
6534 | |
6535 | if (start + length > section_end) | |
b4eb7656 AM |
6536 | { |
6537 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6538 | (unsigned long) offset); |
b4eb7656 AM |
6539 | break; |
6540 | } | |
4723351a CC |
6541 | |
6542 | print_dwarf_vma (begin + base_address, pointer_size); | |
6543 | print_dwarf_vma (end + base_address, pointer_size); | |
6544 | ||
6545 | putchar ('('); | |
6546 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6547 | pointer_size, |
6548 | offset_size, | |
6549 | dwarf_version, | |
6550 | length, | |
6551 | cu_offset, section); | |
4723351a CC |
6552 | putchar (')'); |
6553 | ||
6554 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6555 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 6556 | |
9f272209 | 6557 | if (begin == end && vbegin == vend) |
b4eb7656 | 6558 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6559 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 6560 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
6561 | |
6562 | putchar ('\n'); | |
6563 | ||
6564 | start += length; | |
6565 | } | |
6566 | ||
6567 | *start_ptr = start; | |
9f272209 | 6568 | *vstart_ptr = vstart; |
4723351a CC |
6569 | } |
6570 | ||
77145576 JK |
6571 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
6572 | ||
6573 | static void | |
6574 | display_loclists_list (struct dwarf_section *section, | |
6575 | unsigned char **start_ptr, | |
6576 | unsigned int debug_info_entry, | |
6577 | dwarf_vma offset, | |
6578 | dwarf_vma base_address, | |
9f272209 | 6579 | unsigned char **vstart_ptr, |
77145576 JK |
6580 | int has_frame_base) |
6581 | { | |
9f272209 | 6582 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
6583 | unsigned char *section_end = section->start + section->size; |
6584 | unsigned long cu_offset; | |
6585 | unsigned int pointer_size; | |
6586 | unsigned int offset_size; | |
6587 | int dwarf_version; | |
77145576 | 6588 | |
9dfd0db9 | 6589 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
6590 | dwarf_vma begin = -1, vbegin = -1; |
6591 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
6592 | dwarf_vma length; |
6593 | int need_frame_base; | |
6594 | ||
6595 | if (debug_info_entry >= num_debug_info_entries) | |
6596 | { | |
6597 | warn (_("No debug information available for " | |
6598 | "loclists lists of entry: %u\n"), | |
6599 | debug_info_entry); | |
6600 | return; | |
6601 | } | |
6602 | ||
6603 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6604 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6605 | offset_size = debug_information [debug_info_entry].offset_size; | |
6606 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6607 | ||
6608 | if (pointer_size < 2 || pointer_size > 8) | |
6609 | { | |
6610 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6611 | pointer_size, debug_info_entry); | |
6612 | return; | |
6613 | } | |
6614 | ||
6615 | while (1) | |
6616 | { | |
6617 | dwarf_vma off = offset + (start - *start_ptr); | |
6618 | enum dwarf_location_list_entry_type llet; | |
6619 | ||
6620 | if (start + 1 > section_end) | |
6621 | { | |
6622 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6623 | (unsigned long) offset); | |
6624 | break; | |
6625 | } | |
6626 | ||
6627 | printf (" %8.8lx ", (unsigned long) off); | |
6628 | ||
6629 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
6630 | ||
1c9f770d MW |
6631 | if (vstart && (llet == DW_LLE_offset_pair |
6632 | || llet == DW_LLE_start_end | |
6633 | || llet == DW_LLE_start_length)) | |
9f272209 AO |
6634 | { |
6635 | off = offset + (vstart - *start_ptr); | |
6636 | ||
cd30bcef | 6637 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
6638 | print_dwarf_view (vbegin, pointer_size, 1); |
6639 | ||
cd30bcef | 6640 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6641 | print_dwarf_view (vend, pointer_size, 1); |
6642 | ||
6643 | printf (_("views at %8.8lx for:\n %*s "), | |
6644 | (unsigned long) off, 8, ""); | |
6645 | } | |
6646 | ||
77145576 JK |
6647 | switch (llet) |
6648 | { | |
6649 | case DW_LLE_end_of_list: | |
6650 | printf (_("<End of list>\n")); | |
6651 | break; | |
6652 | case DW_LLE_offset_pair: | |
cd30bcef | 6653 | READ_ULEB (begin, start, section_end); |
1c9f770d | 6654 | begin += base_address; |
cd30bcef | 6655 | READ_ULEB (end, start, section_end); |
1c9f770d MW |
6656 | end += base_address; |
6657 | break; | |
6658 | case DW_LLE_start_end: | |
6659 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6660 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
6661 | break; | |
6662 | case DW_LLE_start_length: | |
6663 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6664 | READ_ULEB (end, start, section_end); | |
6665 | end += begin; | |
77145576 JK |
6666 | break; |
6667 | case DW_LLE_base_address: | |
6668 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
6669 | section_end); | |
6670 | print_dwarf_vma (base_address, pointer_size); | |
6671 | printf (_("(base address)\n")); | |
6672 | break; | |
9f272209 AO |
6673 | #ifdef DW_LLE_view_pair |
6674 | case DW_LLE_view_pair: | |
6675 | if (vstart) | |
6676 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
cd30bcef | 6677 | READ_ULEB (vbegin, start, section_end); |
9f272209 AO |
6678 | print_dwarf_view (vbegin, pointer_size, 1); |
6679 | ||
cd30bcef | 6680 | READ_ULEB (vend, start, section_end); |
9f272209 AO |
6681 | print_dwarf_view (vend, pointer_size, 1); |
6682 | ||
6683 | printf (_("views for:\n")); | |
6684 | continue; | |
6685 | #endif | |
77145576 JK |
6686 | default: |
6687 | error (_("Invalid location list entry type %d\n"), llet); | |
6688 | return; | |
6689 | } | |
6690 | if (llet == DW_LLE_end_of_list) | |
6691 | break; | |
1c9f770d MW |
6692 | if (llet != DW_LLE_offset_pair |
6693 | && llet != DW_LLE_start_end | |
6694 | && llet != DW_LLE_start_length) | |
77145576 JK |
6695 | continue; |
6696 | ||
6697 | if (start + 2 > section_end) | |
6698 | { | |
6699 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6700 | (unsigned long) offset); | |
6701 | break; | |
6702 | } | |
6703 | ||
cd30bcef | 6704 | READ_ULEB (length, start, section_end); |
77145576 | 6705 | |
1c9f770d MW |
6706 | print_dwarf_vma (begin, pointer_size); |
6707 | print_dwarf_vma (end, pointer_size); | |
77145576 JK |
6708 | |
6709 | putchar ('('); | |
6710 | need_frame_base = decode_location_expression (start, | |
6711 | pointer_size, | |
6712 | offset_size, | |
6713 | dwarf_version, | |
6714 | length, | |
6715 | cu_offset, section); | |
6716 | putchar (')'); | |
6717 | ||
6718 | if (need_frame_base && !has_frame_base) | |
6719 | printf (_(" [without DW_AT_frame_base]")); | |
6720 | ||
9f272209 | 6721 | if (begin == end && vbegin == vend) |
77145576 | 6722 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6723 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
6724 | fputs (_(" (start > end)"), stdout); |
6725 | ||
6726 | putchar ('\n'); | |
6727 | ||
6728 | start += length; | |
9f272209 | 6729 | vbegin = vend = -1; |
77145576 JK |
6730 | } |
6731 | ||
9f272209 AO |
6732 | if (vbegin != vm1 || vend != vm1) |
6733 | printf (_("Trailing view pair not used in a range")); | |
6734 | ||
77145576 | 6735 | *start_ptr = start; |
9f272209 | 6736 | *vstart_ptr = vstart; |
77145576 JK |
6737 | } |
6738 | ||
fab128ef CC |
6739 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
6740 | right-adjusted in a field of length LEN, and followed by a space. */ | |
6741 | ||
6742 | static void | |
6743 | print_addr_index (unsigned int idx, unsigned int len) | |
6744 | { | |
6745 | static char buf[15]; | |
6746 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 6747 | printf ("%*s ", len, buf); |
fab128ef CC |
6748 | } |
6749 | ||
4723351a CC |
6750 | /* Display a location list from a .dwo section. It uses address indexes rather |
6751 | than embedded addresses. This code closely follows display_loc_list, but the | |
6752 | two are sufficiently different that combining things is very ugly. */ | |
6753 | ||
6754 | static void | |
6755 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
6756 | unsigned char **start_ptr, |
6757 | unsigned int debug_info_entry, | |
359ca075 | 6758 | dwarf_vma offset, |
9f272209 | 6759 | unsigned char **vstart_ptr, |
b4eb7656 | 6760 | int has_frame_base) |
4723351a | 6761 | { |
9f272209 | 6762 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6763 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6764 | unsigned long cu_offset; |
6765 | unsigned int pointer_size; | |
6766 | unsigned int offset_size; | |
6767 | int dwarf_version; | |
4723351a CC |
6768 | int entry_type; |
6769 | unsigned short length; | |
6770 | int need_frame_base; | |
fab128ef | 6771 | unsigned int idx; |
4723351a | 6772 | |
82b1b41b NC |
6773 | if (debug_info_entry >= num_debug_info_entries) |
6774 | { | |
6775 | warn (_("No debug information for loc lists of entry: %u\n"), | |
6776 | debug_info_entry); | |
6777 | return; | |
6778 | } | |
6779 | ||
6780 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6781 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6782 | offset_size = debug_information [debug_info_entry].offset_size; | |
6783 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6784 | ||
f41e4712 NC |
6785 | if (pointer_size < 2 || pointer_size > 8) |
6786 | { | |
6787 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6788 | pointer_size, debug_info_entry); | |
6789 | return; | |
6790 | } | |
6791 | ||
4723351a CC |
6792 | while (1) |
6793 | { | |
359ca075 | 6794 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 6795 | |
fab128ef | 6796 | if (start >= section_end) |
b4eb7656 AM |
6797 | { |
6798 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6799 | (unsigned long) offset); |
b4eb7656 AM |
6800 | break; |
6801 | } | |
4723351a | 6802 | |
0c588247 | 6803 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
6804 | |
6805 | if (vstart) | |
6806 | switch (entry_type) | |
6807 | { | |
6808 | default: | |
6809 | break; | |
6810 | ||
6811 | case 2: | |
6812 | case 3: | |
6813 | case 4: | |
6814 | { | |
6815 | dwarf_vma view; | |
6816 | dwarf_vma off = offset + (vstart - *start_ptr); | |
6817 | ||
cd30bcef | 6818 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6819 | print_dwarf_view (view, 8, 1); |
6820 | ||
cd30bcef | 6821 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6822 | print_dwarf_view (view, 8, 1); |
6823 | ||
6824 | printf (_("views at %8.8lx for:\n %*s "), | |
6825 | (unsigned long) off, 8, ""); | |
6826 | ||
6827 | } | |
6828 | break; | |
6829 | } | |
6830 | ||
4723351a | 6831 | switch (entry_type) |
b4eb7656 AM |
6832 | { |
6833 | case 0: /* A terminating entry. */ | |
6834 | *start_ptr = start; | |
9f272209 | 6835 | *vstart_ptr = vstart; |
b4eb7656 AM |
6836 | printf (_("<End of list>\n")); |
6837 | return; | |
6838 | case 1: /* A base-address entry. */ | |
cd30bcef | 6839 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6840 | print_addr_index (idx, 8); |
9f272209 | 6841 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
6842 | printf (_("(base address selection entry)\n")); |
6843 | continue; | |
6844 | case 2: /* A start/end entry. */ | |
cd30bcef | 6845 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6846 | print_addr_index (idx, 8); |
cd30bcef | 6847 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6848 | print_addr_index (idx, 8); |
6849 | break; | |
6850 | case 3: /* A start/length entry. */ | |
cd30bcef | 6851 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6852 | print_addr_index (idx, 8); |
6853 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6854 | printf ("%08x ", idx); | |
6855 | break; | |
6856 | case 4: /* An offset pair entry. */ | |
6857 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6858 | printf ("%08x ", idx); | |
6859 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6860 | printf ("%08x ", idx); | |
6861 | break; | |
6862 | default: | |
6863 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
6864 | *start_ptr = start; | |
9f272209 | 6865 | *vstart_ptr = vstart; |
b4eb7656 AM |
6866 | return; |
6867 | } | |
4723351a CC |
6868 | |
6869 | if (start + 2 > section_end) | |
b4eb7656 AM |
6870 | { |
6871 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6872 | (unsigned long) offset); |
b4eb7656 AM |
6873 | break; |
6874 | } | |
4723351a | 6875 | |
0c588247 | 6876 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6877 | if (start + length > section_end) |
b4eb7656 AM |
6878 | { |
6879 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6880 | (unsigned long) offset); |
b4eb7656 AM |
6881 | break; |
6882 | } | |
4723351a CC |
6883 | |
6884 | putchar ('('); | |
6885 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6886 | pointer_size, |
6887 | offset_size, | |
6888 | dwarf_version, | |
6889 | length, | |
6890 | cu_offset, section); | |
4723351a CC |
6891 | putchar (')'); |
6892 | ||
6893 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6894 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
6895 | |
6896 | putchar ('\n'); | |
6897 | ||
6898 | start += length; | |
6899 | } | |
6900 | ||
6901 | *start_ptr = start; | |
9f272209 | 6902 | *vstart_ptr = vstart; |
4723351a CC |
6903 | } |
6904 | ||
9f272209 AO |
6905 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
6906 | loc_views. */ | |
51d0d03f | 6907 | |
9f272209 | 6908 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
6909 | |
6910 | static int | |
6911 | loc_offsets_compar (const void *ap, const void *bp) | |
6912 | { | |
6913 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
6914 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
6915 | ||
9f272209 AO |
6916 | int ret = (a > b) - (b > a); |
6917 | if (ret) | |
6918 | return ret; | |
6919 | ||
6920 | a = loc_views[*(const unsigned int *) ap]; | |
6921 | b = loc_views[*(const unsigned int *) bp]; | |
6922 | ||
6923 | ret = (a > b) - (b > a); | |
6924 | ||
6925 | return ret; | |
51d0d03f JJ |
6926 | } |
6927 | ||
19e6b90e L |
6928 | static int |
6929 | display_debug_loc (struct dwarf_section *section, void *file) | |
6930 | { | |
9f272209 | 6931 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
6932 | unsigned long bytes; |
6933 | unsigned char *section_begin = start; | |
6934 | unsigned int num_loc_list = 0; | |
6935 | unsigned long last_offset = 0; | |
9f272209 | 6936 | unsigned long last_view = 0; |
19e6b90e L |
6937 | unsigned int first = 0; |
6938 | unsigned int i; | |
6939 | unsigned int j; | |
6940 | int seen_first_offset = 0; | |
51d0d03f | 6941 | int locs_sorted = 1; |
9f272209 | 6942 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6943 | unsigned int *array = NULL; |
4723351a | 6944 | const char *suffix = strrchr (section->name, '.'); |
015dc7e1 | 6945 | bool is_dwo = false; |
77145576 JK |
6946 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6947 | dwarf_vma expected_start = 0; | |
4723351a CC |
6948 | |
6949 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
015dc7e1 | 6950 | is_dwo = true; |
19e6b90e L |
6951 | |
6952 | bytes = section->size; | |
19e6b90e L |
6953 | |
6954 | if (bytes == 0) | |
6955 | { | |
6956 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6957 | return 0; | |
6958 | } | |
6959 | ||
77145576 JK |
6960 | if (is_loclists) |
6961 | { | |
6962 | unsigned char *hdrptr = section_begin; | |
6963 | dwarf_vma ll_length; | |
6964 | unsigned short ll_version; | |
6965 | unsigned char *end = section_begin + section->size; | |
6966 | unsigned char address_size, segment_selector_size; | |
6967 | uint32_t offset_entry_count; | |
6968 | ||
6969 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6970 | if (ll_length == 0xffffffff) | |
6971 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6972 | ||
6973 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6974 | if (ll_version != 5) | |
6975 | { | |
6976 | warn (_("The %s section contains corrupt or " | |
6977 | "unsupported version number: %d.\n"), | |
6978 | section->name, ll_version); | |
6979 | return 0; | |
6980 | } | |
6981 | ||
6982 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6983 | ||
6984 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6985 | if (segment_selector_size != 0) | |
6986 | { | |
6987 | warn (_("The %s section contains " | |
6988 | "unsupported segment selector size: %d.\n"), | |
6989 | section->name, segment_selector_size); | |
6990 | return 0; | |
6991 | } | |
6992 | ||
6993 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
6994 | if (offset_entry_count != 0) | |
6995 | { | |
6996 | warn (_("The %s section contains " | |
6997 | "unsupported offset entry count: %d.\n"), | |
6998 | section->name, offset_entry_count); | |
6999 | return 0; | |
7000 | } | |
7001 | ||
7002 | expected_start = hdrptr - section_begin; | |
7003 | } | |
7004 | ||
1febe64d NC |
7005 | if (load_debug_info (file) == 0) |
7006 | { | |
7007 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7008 | section->name); | |
7009 | return 0; | |
7010 | } | |
19e6b90e L |
7011 | |
7012 | /* Check the order of location list in .debug_info section. If | |
7013 | offsets of location lists are in the ascending order, we can | |
7014 | use `debug_information' directly. */ | |
7015 | for (i = 0; i < num_debug_info_entries; i++) | |
7016 | { | |
7017 | unsigned int num; | |
7018 | ||
7019 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
7020 | if (num > num_loc_list) |
7021 | num_loc_list = num; | |
19e6b90e L |
7022 | |
7023 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 7024 | if (locs_sorted && num != 0) |
19e6b90e L |
7025 | { |
7026 | if (!seen_first_offset) | |
7027 | { | |
7028 | /* This is the first location list. */ | |
7029 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 7030 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
7031 | first = i; |
7032 | seen_first_offset = 1; | |
7033 | j = 1; | |
7034 | } | |
7035 | else | |
7036 | j = 0; | |
7037 | ||
7038 | for (; j < num; j++) | |
7039 | { | |
7040 | if (last_offset > | |
9f272209 AO |
7041 | debug_information [i].loc_offsets [j] |
7042 | || (last_offset == debug_information [i].loc_offsets [j] | |
7043 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 7044 | { |
51d0d03f | 7045 | locs_sorted = 0; |
19e6b90e L |
7046 | break; |
7047 | } | |
7048 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 7049 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
7050 | } |
7051 | } | |
7052 | } | |
7053 | ||
19e6b90e L |
7054 | if (!seen_first_offset) |
7055 | error (_("No location lists in .debug_info section!\n")); | |
7056 | ||
d4bfc77b | 7057 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
7058 | && debug_information [first].loc_offsets [0] != expected_start |
7059 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
7060 | warn (_("Location lists in %s section start at 0x%s\n"), |
7061 | section->name, | |
7062 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 7063 | |
51d0d03f JJ |
7064 | if (!locs_sorted) |
7065 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d | 7066 | |
015dc7e1 | 7067 | introduce (section, false); |
dda8d76d | 7068 | |
d1c4b12b NC |
7069 | if (reloc_at (section, 0)) |
7070 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 7071 | |
d1c4b12b | 7072 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
7073 | |
7074 | seen_first_offset = 0; | |
7075 | for (i = first; i < num_debug_info_entries; i++) | |
7076 | { | |
9f272209 | 7077 | dwarf_vma offset, voffset; |
359ca075 | 7078 | dwarf_vma base_address; |
d1c4b12b | 7079 | unsigned int k; |
19e6b90e L |
7080 | int has_frame_base; |
7081 | ||
51d0d03f JJ |
7082 | if (!locs_sorted) |
7083 | { | |
7084 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
7085 | array[k] = k; | |
7086 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 7087 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
7088 | qsort (array, debug_information [i].num_loc_offsets, |
7089 | sizeof (*array), loc_offsets_compar); | |
7090 | } | |
19e6b90e | 7091 | |
9f272209 | 7092 | int adjacent_view_loclists = 1; |
51d0d03f | 7093 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 7094 | { |
51d0d03f JJ |
7095 | j = locs_sorted ? k : array[k]; |
7096 | if (k | |
9f272209 | 7097 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 7098 | ? k - 1 : array [k - 1]] |
9f272209 AO |
7099 | == debug_information [i].loc_offsets [j]) |
7100 | && (debug_information [i].loc_views [locs_sorted | |
7101 | ? k - 1 : array [k - 1]] | |
7102 | == debug_information [i].loc_views [j])) | |
51d0d03f | 7103 | continue; |
19e6b90e | 7104 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 7105 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 7106 | next = section_begin + offset; |
9f272209 AO |
7107 | voffset = debug_information [i].loc_views [j]; |
7108 | if (voffset != vm1) | |
7109 | vnext = section_begin + voffset; | |
7110 | else | |
7111 | vnext = NULL; | |
19e6b90e L |
7112 | base_address = debug_information [i].base_address; |
7113 | ||
9f272209 AO |
7114 | if (vnext && vnext < next) |
7115 | { | |
7116 | vstart = vnext; | |
7117 | display_view_pair_list (section, &vstart, i, next); | |
7118 | if (start == vnext) | |
7119 | start = vstart; | |
7120 | } | |
7121 | ||
7122 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
7123 | seen_first_offset = 1; |
7124 | else | |
7125 | { | |
7126 | if (start < next) | |
7127 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 7128 | (unsigned long) (start - section_begin), |
c8071705 | 7129 | (unsigned long) offset); |
19e6b90e L |
7130 | else if (start > next) |
7131 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 7132 | (unsigned long) (start - section_begin), |
c8071705 | 7133 | (unsigned long) offset); |
19e6b90e L |
7134 | } |
7135 | start = next; | |
9f272209 | 7136 | vstart = vnext; |
19e6b90e L |
7137 | |
7138 | if (offset >= bytes) | |
7139 | { | |
7140 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 7141 | (unsigned long) offset); |
19e6b90e L |
7142 | continue; |
7143 | } | |
7144 | ||
9f272209 AO |
7145 | if (vnext && voffset >= bytes) |
7146 | { | |
7147 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
7148 | (unsigned long) voffset); | |
7149 | continue; | |
7150 | } | |
7151 | ||
77145576 JK |
7152 | if (!is_loclists) |
7153 | { | |
7154 | if (is_dwo) | |
7155 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 7156 | &vstart, has_frame_base); |
77145576 JK |
7157 | else |
7158 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 7159 | &vstart, has_frame_base); |
77145576 | 7160 | } |
b4eb7656 | 7161 | else |
77145576 JK |
7162 | { |
7163 | if (is_dwo) | |
7164 | warn (_("DWO is not yet supported.\n")); | |
7165 | else | |
7166 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
7167 | &vstart, has_frame_base); |
7168 | } | |
7169 | ||
7170 | /* FIXME: this arrangement is quite simplistic. Nothing | |
7171 | requires locview lists to be adjacent to corresponding | |
7172 | loclists, and a single loclist could be augmented by | |
7173 | different locview lists, and vice-versa, unlikely as it | |
7174 | is that it would make sense to do so. Hopefully we'll | |
7175 | have view pair support built into loclists before we ever | |
7176 | need to address all these possibilities. */ | |
7177 | if (adjacent_view_loclists && vnext | |
7178 | && vnext != start && vstart != next) | |
7179 | { | |
7180 | adjacent_view_loclists = 0; | |
7181 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 7182 | } |
9f272209 AO |
7183 | |
7184 | if (vnext && vnext == start) | |
7185 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
7186 | } |
7187 | } | |
031cd65f | 7188 | |
4723351a | 7189 | if (start < section->start + section->size) |
d3a49aa8 AM |
7190 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
7191 | "There are %ld unused bytes at the end of section %s\n", | |
7192 | (long) (section->start + section->size - start)), | |
4723351a | 7193 | (long) (section->start + section->size - start), section->name); |
98fb390a | 7194 | putchar ('\n'); |
51d0d03f | 7195 | free (array); |
19e6b90e L |
7196 | return 1; |
7197 | } | |
7198 | ||
7199 | static int | |
7200 | display_debug_str (struct dwarf_section *section, | |
7201 | void *file ATTRIBUTE_UNUSED) | |
7202 | { | |
7203 | unsigned char *start = section->start; | |
7204 | unsigned long bytes = section->size; | |
7205 | dwarf_vma addr = section->address; | |
7206 | ||
7207 | if (bytes == 0) | |
7208 | { | |
7209 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7210 | return 0; | |
7211 | } | |
7212 | ||
015dc7e1 | 7213 | introduce (section, false); |
19e6b90e L |
7214 | |
7215 | while (bytes) | |
7216 | { | |
7217 | int j; | |
7218 | int k; | |
7219 | int lbytes; | |
7220 | ||
7221 | lbytes = (bytes > 16 ? 16 : bytes); | |
7222 | ||
7223 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
7224 | ||
7225 | for (j = 0; j < 16; j++) | |
7226 | { | |
7227 | if (j < lbytes) | |
7228 | printf ("%2.2x", start[j]); | |
7229 | else | |
7230 | printf (" "); | |
7231 | ||
7232 | if ((j & 3) == 3) | |
7233 | printf (" "); | |
7234 | } | |
7235 | ||
7236 | for (j = 0; j < lbytes; j++) | |
7237 | { | |
7238 | k = start[j]; | |
7239 | if (k >= ' ' && k < 0x80) | |
7240 | printf ("%c", k); | |
7241 | else | |
7242 | printf ("."); | |
7243 | } | |
7244 | ||
7245 | putchar ('\n'); | |
7246 | ||
7247 | start += lbytes; | |
7248 | addr += lbytes; | |
7249 | bytes -= lbytes; | |
7250 | } | |
7251 | ||
7252 | putchar ('\n'); | |
7253 | ||
7254 | return 1; | |
7255 | } | |
7256 | ||
19e6b90e L |
7257 | static int |
7258 | display_debug_info (struct dwarf_section *section, void *file) | |
7259 | { | |
015dc7e1 | 7260 | return process_debug_info (section, file, section->abbrev_sec, false, false); |
19e6b90e L |
7261 | } |
7262 | ||
2b6f5997 CC |
7263 | static int |
7264 | display_debug_types (struct dwarf_section *section, void *file) | |
7265 | { | |
015dc7e1 | 7266 | return process_debug_info (section, file, section->abbrev_sec, false, true); |
6f875884 TG |
7267 | } |
7268 | ||
7269 | static int | |
7270 | display_trace_info (struct dwarf_section *section, void *file) | |
7271 | { | |
015dc7e1 | 7272 | return process_debug_info (section, file, section->abbrev_sec, false, true); |
2b6f5997 | 7273 | } |
19e6b90e L |
7274 | |
7275 | static int | |
7276 | display_debug_aranges (struct dwarf_section *section, | |
7277 | void *file ATTRIBUTE_UNUSED) | |
7278 | { | |
7279 | unsigned char *start = section->start; | |
7280 | unsigned char *end = start + section->size; | |
7281 | ||
015dc7e1 | 7282 | introduce (section, false); |
19e6b90e | 7283 | |
6e3d6dc1 NC |
7284 | /* It does not matter if this load fails, |
7285 | we test for that later on. */ | |
7286 | load_debug_info (file); | |
7287 | ||
19e6b90e L |
7288 | while (start < end) |
7289 | { | |
7290 | unsigned char *hdrptr; | |
7291 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 7292 | unsigned char *addr_ranges; |
2d9472a2 NC |
7293 | dwarf_vma length; |
7294 | dwarf_vma address; | |
e98fdf1a | 7295 | unsigned long sec_off; |
53b8873b | 7296 | unsigned char address_size; |
19e6b90e | 7297 | int excess; |
bf5117e3 NC |
7298 | unsigned int offset_size; |
7299 | unsigned int initial_length_size; | |
19e6b90e L |
7300 | |
7301 | hdrptr = start; | |
7302 | ||
0c588247 | 7303 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
7304 | if (arange.ar_length == 0xffffffff) |
7305 | { | |
0c588247 | 7306 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
7307 | offset_size = 8; |
7308 | initial_length_size = 12; | |
7309 | } | |
7310 | else | |
7311 | { | |
7312 | offset_size = 4; | |
7313 | initial_length_size = 4; | |
7314 | } | |
7315 | ||
e98fdf1a AM |
7316 | sec_off = hdrptr - section->start; |
7317 | if (sec_off + arange.ar_length < sec_off | |
7318 | || sec_off + arange.ar_length > section->size) | |
7319 | { | |
7320 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
7321 | section->name, | |
7322 | sec_off - initial_length_size, | |
7323 | dwarf_vmatoa ("x", arange.ar_length)); | |
7324 | break; | |
7325 | } | |
7326 | ||
0c588247 NC |
7327 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
7328 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 7329 | |
6e3d6dc1 NC |
7330 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
7331 | && num_debug_info_entries > 0 | |
7332 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
7333 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 7334 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 7335 | |
0c588247 NC |
7336 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
7337 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
7338 | |
7339 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
7340 | { | |
67f101ee NC |
7341 | /* PR 19872: A version number of 0 probably means that there is |
7342 | padding at the end of the .debug_aranges section. Gold puts | |
7343 | it there when performing an incremental link, for example. | |
7344 | So do not generate a warning in this case. */ | |
7345 | if (arange.ar_version) | |
7346 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
7347 | break; |
7348 | } | |
7349 | ||
47704ddf KT |
7350 | printf (_(" Length: %ld\n"), |
7351 | (long) arange.ar_length); | |
19e6b90e | 7352 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
7353 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
7354 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
7355 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
7356 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
7357 | ||
53b8873b NC |
7358 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
7359 | ||
f41e4712 NC |
7360 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
7361 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
7362 | { |
7363 | error (_("Invalid address size in %s section!\n"), | |
7364 | section->name); | |
7365 | break; | |
7366 | } | |
7367 | ||
53b8873b NC |
7368 | /* The DWARF spec does not require that the address size be a power |
7369 | of two, but we do. This will have to change if we ever encounter | |
7370 | an uneven architecture. */ | |
7371 | if ((address_size & (address_size - 1)) != 0) | |
7372 | { | |
7373 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
7374 | break; | |
7375 | } | |
cecf136e | 7376 | |
209c9a13 NC |
7377 | if (address_size > 4) |
7378 | printf (_("\n Address Length\n")); | |
7379 | else | |
7380 | printf (_("\n Address Length\n")); | |
19e6b90e | 7381 | |
91d6fa6a | 7382 | addr_ranges = hdrptr; |
19e6b90e | 7383 | |
53b8873b NC |
7384 | /* Must pad to an alignment boundary that is twice the address size. */ |
7385 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 7386 | if (excess) |
91d6fa6a | 7387 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 7388 | |
e98fdf1a | 7389 | start += arange.ar_length + initial_length_size; |
1617e571 | 7390 | |
91d6fa6a | 7391 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 7392 | { |
0c588247 NC |
7393 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
7394 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 7395 | |
80c35038 | 7396 | printf (" "); |
2d9472a2 NC |
7397 | print_dwarf_vma (address, address_size); |
7398 | print_dwarf_vma (length, address_size); | |
7399 | putchar ('\n'); | |
19e6b90e | 7400 | } |
19e6b90e L |
7401 | } |
7402 | ||
7403 | printf ("\n"); | |
7404 | ||
7405 | return 1; | |
7406 | } | |
7407 | ||
4723351a CC |
7408 | /* Comparison function for qsort. */ |
7409 | static int | |
7410 | comp_addr_base (const void * v0, const void * v1) | |
7411 | { | |
d367307b AM |
7412 | debug_info *info0 = *(debug_info **) v0; |
7413 | debug_info *info1 = *(debug_info **) v1; | |
4723351a CC |
7414 | return info0->addr_base - info1->addr_base; |
7415 | } | |
7416 | ||
7417 | /* Display the debug_addr section. */ | |
7418 | static int | |
7419 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 7420 | void *file) |
4723351a CC |
7421 | { |
7422 | debug_info **debug_addr_info; | |
7423 | unsigned char *entry; | |
7424 | unsigned char *end; | |
7425 | unsigned int i; | |
7426 | unsigned int count; | |
0e12f6c8 | 7427 | unsigned char * header; |
4723351a CC |
7428 | |
7429 | if (section->size == 0) | |
7430 | { | |
7431 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7432 | return 0; | |
7433 | } | |
7434 | ||
7435 | if (load_debug_info (file) == 0) | |
7436 | { | |
7437 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7438 | section->name); | |
7439 | return 0; | |
7440 | } | |
7441 | ||
015dc7e1 | 7442 | introduce (section, false); |
4723351a | 7443 | |
1306a742 NC |
7444 | /* PR 17531: file: cf38d01b. |
7445 | We use xcalloc because a corrupt file may not have initialised all of the | |
7446 | fields in the debug_info structure, which means that the sort below might | |
7447 | try to move uninitialised data. */ | |
7448 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 7449 | sizeof (debug_info *)); |
4723351a CC |
7450 | |
7451 | count = 0; | |
7452 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 7453 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
7454 | { |
7455 | /* PR 17531: file: cf38d01b. */ | |
7456 | if (debug_information[i].addr_base >= section->size) | |
7457 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
7458 | (unsigned long) debug_information[i].addr_base, i); | |
7459 | else | |
7460 | debug_addr_info [count++] = debug_information + i; | |
7461 | } | |
4723351a CC |
7462 | |
7463 | /* Add a sentinel to make iteration convenient. */ | |
7464 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
7465 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 7466 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 7467 | |
0e12f6c8 | 7468 | header = section->start; |
4723351a CC |
7469 | for (i = 0; i < count; i++) |
7470 | { | |
7471 | unsigned int idx; | |
fab128ef | 7472 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
7473 | |
7474 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 7475 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 7476 | |
fab128ef | 7477 | printf (_("\tIndex\tAddress\n")); |
4723351a | 7478 | entry = section->start + debug_addr_info [i]->addr_base; |
0e12f6c8 TV |
7479 | if (debug_addr_info [i]->dwarf_version >= 5) |
7480 | { | |
7481 | size_t header_size = entry - header; | |
7482 | unsigned char * curr_header = header; | |
7483 | dwarf_vma length; | |
7484 | int version; | |
7485 | int segment_selector_size; | |
7486 | ||
7487 | if (header_size != 8 && header_size != 16) | |
7488 | { | |
7489 | warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"), | |
7490 | section->name, (long) header_size); | |
7491 | return 0; | |
7492 | } | |
7493 | ||
7494 | SAFE_BYTE_GET_AND_INC (length, curr_header, 4, entry); | |
7495 | if (length == 0xffffffff) | |
7496 | SAFE_BYTE_GET (length, curr_header, 8, entry); | |
7497 | end = curr_header + length; | |
7498 | ||
7499 | SAFE_BYTE_GET_AND_INC (version, curr_header, 2, entry); | |
7500 | if (version != 5) | |
7501 | warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"), | |
7502 | section->name, version); | |
7503 | ||
7504 | SAFE_BYTE_GET_AND_INC (address_size, curr_header, 1, entry); | |
7505 | SAFE_BYTE_GET_AND_INC (segment_selector_size, curr_header, 1, entry); | |
7506 | address_size += segment_selector_size; | |
7507 | } | |
7508 | else | |
7509 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
7510 | header = end; | |
4723351a CC |
7511 | idx = 0; |
7512 | while (entry < end) | |
b4eb7656 AM |
7513 | { |
7514 | dwarf_vma base = byte_get (entry, address_size); | |
7515 | printf (_("\t%d:\t"), idx); | |
7516 | print_dwarf_vma (base, address_size); | |
7517 | printf ("\n"); | |
7518 | entry += address_size; | |
7519 | idx++; | |
7520 | } | |
4723351a CC |
7521 | } |
7522 | printf ("\n"); | |
7523 | ||
7524 | free (debug_addr_info); | |
7525 | return 1; | |
7526 | } | |
7527 | ||
7528 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 7529 | |
4723351a CC |
7530 | static int |
7531 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 7532 | void *file ATTRIBUTE_UNUSED) |
4723351a | 7533 | { |
9f27c364 HPN |
7534 | unsigned long idx; |
7535 | ||
4723351a CC |
7536 | if (section->size == 0) |
7537 | { | |
7538 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7539 | return 0; | |
7540 | } | |
e4b7104b NC |
7541 | |
7542 | unsigned char *start = section->start; | |
7543 | unsigned char *end = start + section->size; | |
7544 | unsigned char *curr = start; | |
7545 | ||
63b4cc53 | 7546 | const char *suffix = strrchr (section->name, '.'); |
015dc7e1 | 7547 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
39f381cb NC |
7548 | |
7549 | if (dwo) | |
7550 | load_debug_section_with_follow (str_dwo, file); | |
7551 | else | |
7552 | load_debug_section_with_follow (str, file); | |
e4b7104b | 7553 | |
015dc7e1 | 7554 | introduce (section, false); |
e4b7104b NC |
7555 | |
7556 | while (curr < end) | |
7557 | { | |
7558 | dwarf_vma length; | |
7559 | dwarf_vma entry_length; | |
7560 | ||
7561 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); | |
7562 | /* FIXME: We assume that this means 64-bit DWARF is being used. */ | |
7563 | if (length == 0xffffffff) | |
7564 | { | |
7565 | SAFE_BYTE_GET (length, curr, 8, end); | |
7566 | entry_length = 8; | |
7567 | } | |
7568 | else | |
7569 | entry_length = 4; | |
7570 | ||
95abb394 | 7571 | unsigned char *entries_end; |
39f381cb NC |
7572 | if (length == 0) |
7573 | { | |
7574 | /* This is probably an old style .debug_str_offset section which | |
7575 | just contains offsets and no header (and the first offset is 0). */ | |
7576 | length = section->size; | |
7577 | curr = section->start; | |
95abb394 | 7578 | entries_end = end; |
e4b7104b | 7579 | |
39f381cb NC |
7580 | printf (_(" Length: %#lx\n"), (unsigned long) length); |
7581 | printf (_(" Index Offset [String]\n")); | |
7582 | } | |
7583 | else | |
7584 | { | |
95abb394 TV |
7585 | entries_end = curr + length; |
7586 | ||
39f381cb NC |
7587 | int version; |
7588 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); | |
7589 | if (version != 5) | |
7590 | warn (_("Unexpected version number in str_offset header: %#x\n"), version); | |
7591 | ||
7592 | int padding; | |
7593 | SAFE_BYTE_GET_AND_INC (padding, curr, 2, end); | |
7594 | if (padding != 0) | |
7595 | warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding); | |
7596 | ||
7597 | printf (_(" Length: %#lx\n"), (unsigned long) length); | |
7598 | printf (_(" Version: %#lx\n"), (unsigned long) version); | |
7599 | printf (_(" Index Offset [String]\n")); | |
7600 | } | |
e4b7104b | 7601 | |
95abb394 | 7602 | for (idx = 0; curr < entries_end; idx++) |
e4b7104b NC |
7603 | { |
7604 | dwarf_vma offset; | |
7605 | const unsigned char * string; | |
7606 | ||
95abb394 TV |
7607 | if (curr + entry_length > entries_end) |
7608 | /* Not enough space to read one entry_length, give up. */ | |
7609 | return 0; | |
7610 | ||
e4b7104b | 7611 | SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, end); |
39f381cb NC |
7612 | if (dwo) |
7613 | string = (const unsigned char *) | |
9f27c364 | 7614 | fetch_indexed_string (idx, NULL, entry_length, dwo); |
39f381cb NC |
7615 | else |
7616 | string = fetch_indirect_string (offset); | |
7617 | ||
9f27c364 | 7618 | printf (" %8lu %8s %s\n", idx, dwarf_vmatoa ("x", offset), |
e4b7104b NC |
7619 | string); |
7620 | } | |
7621 | } | |
39f381cb | 7622 | |
4723351a CC |
7623 | return 1; |
7624 | } | |
7625 | ||
01a8f077 JK |
7626 | /* Each debug_information[x].range_lists[y] gets this representation for |
7627 | sorting purposes. */ | |
7628 | ||
7629 | struct range_entry | |
467c65bc NC |
7630 | { |
7631 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 7632 | dwarf_vma ranges_offset; |
01a8f077 | 7633 | |
467c65bc NC |
7634 | /* Original debug_information to find parameters of the data. */ |
7635 | debug_info *debug_info_p; | |
7636 | }; | |
01a8f077 JK |
7637 | |
7638 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
7639 | ||
7640 | static int | |
7641 | range_entry_compar (const void *ap, const void *bp) | |
7642 | { | |
3f5e193b NC |
7643 | const struct range_entry *a_re = (const struct range_entry *) ap; |
7644 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
7645 | const dwarf_vma a = a_re->ranges_offset; |
7646 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
7647 | |
7648 | return (a > b) - (b > a); | |
7649 | } | |
7650 | ||
77145576 JK |
7651 | static void |
7652 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
7653 | unsigned int pointer_size, unsigned long offset, | |
7654 | unsigned long base_address) | |
7655 | { | |
7656 | while (start < finish) | |
7657 | { | |
7658 | dwarf_vma begin; | |
7659 | dwarf_vma end; | |
7660 | ||
7661 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7662 | if (start >= finish) | |
7663 | break; | |
7664 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7665 | ||
7666 | printf (" %8.8lx ", offset); | |
7667 | ||
7668 | if (begin == 0 && end == 0) | |
7669 | { | |
7670 | printf (_("<End of list>\n")); | |
7671 | break; | |
7672 | } | |
7673 | ||
7674 | /* Check base address specifiers. */ | |
7675 | if (is_max_address (begin, pointer_size) | |
7676 | && !is_max_address (end, pointer_size)) | |
7677 | { | |
7678 | base_address = end; | |
7679 | print_dwarf_vma (begin, pointer_size); | |
7680 | print_dwarf_vma (end, pointer_size); | |
7681 | printf ("(base address)\n"); | |
7682 | continue; | |
7683 | } | |
7684 | ||
7685 | print_dwarf_vma (begin + base_address, pointer_size); | |
7686 | print_dwarf_vma (end + base_address, pointer_size); | |
7687 | ||
7688 | if (begin == end) | |
7689 | fputs (_("(start == end)"), stdout); | |
7690 | else if (begin > end) | |
7691 | fputs (_("(start > end)"), stdout); | |
7692 | ||
7693 | putchar ('\n'); | |
7694 | } | |
7695 | } | |
7696 | ||
7697 | static void | |
7698 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
7699 | unsigned int pointer_size, unsigned long offset, | |
7700 | unsigned long base_address) | |
7701 | { | |
7702 | unsigned char *next = start; | |
7703 | ||
7704 | while (1) | |
7705 | { | |
7706 | unsigned long off = offset + (start - next); | |
7707 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
7708 | /* Initialize it due to a false compiler warning. */ |
7709 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
7710 | |
7711 | if (start + 1 > finish) | |
7712 | { | |
7713 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
7714 | offset); | |
7715 | break; | |
7716 | } | |
7717 | ||
7718 | printf (" %8.8lx ", off); | |
7719 | ||
7720 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
7721 | ||
7722 | switch (rlet) | |
7723 | { | |
7724 | case DW_RLE_end_of_list: | |
7725 | printf (_("<End of list>\n")); | |
7726 | break; | |
7727 | case DW_RLE_base_address: | |
7728 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
7729 | print_dwarf_vma (base_address, pointer_size); | |
7730 | printf (_("(base address)\n")); | |
7731 | break; | |
7732 | case DW_RLE_start_length: | |
7733 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
cd30bcef | 7734 | READ_ULEB (length, start, finish); |
77145576 JK |
7735 | end = begin + length; |
7736 | break; | |
7737 | case DW_RLE_offset_pair: | |
cd30bcef AM |
7738 | READ_ULEB (begin, start, finish); |
7739 | READ_ULEB (end, start, finish); | |
77145576 JK |
7740 | break; |
7741 | case DW_RLE_start_end: | |
7742 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7743 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7744 | break; | |
7745 | default: | |
7746 | error (_("Invalid range list entry type %d\n"), rlet); | |
7747 | rlet = DW_RLE_end_of_list; | |
7748 | break; | |
7749 | } | |
7750 | if (rlet == DW_RLE_end_of_list) | |
7751 | break; | |
7752 | if (rlet == DW_RLE_base_address) | |
7753 | continue; | |
7754 | ||
4d932715 BE |
7755 | /* Only a DW_RLE_offset_pair needs the base address added. */ |
7756 | if (rlet == DW_RLE_offset_pair) | |
7757 | { | |
7758 | begin += base_address; | |
7759 | end += base_address; | |
7760 | } | |
7761 | ||
7762 | print_dwarf_vma (begin, pointer_size); | |
7763 | print_dwarf_vma (end, pointer_size); | |
77145576 JK |
7764 | |
7765 | if (begin == end) | |
7766 | fputs (_("(start == end)"), stdout); | |
7767 | else if (begin > end) | |
7768 | fputs (_("(start > end)"), stdout); | |
7769 | ||
7770 | putchar ('\n'); | |
7771 | } | |
7772 | } | |
7773 | ||
19e6b90e L |
7774 | static int |
7775 | display_debug_ranges (struct dwarf_section *section, | |
7776 | void *file ATTRIBUTE_UNUSED) | |
7777 | { | |
7778 | unsigned char *start = section->start; | |
a2ff7a4b | 7779 | unsigned char *last_start = start; |
f6f0e17b | 7780 | unsigned long bytes = section->size; |
19e6b90e | 7781 | unsigned char *section_begin = start; |
f6f0e17b | 7782 | unsigned char *finish = start + bytes; |
01a8f077 JK |
7783 | unsigned int num_range_list, i; |
7784 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
7785 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
7786 | /* Initialize it due to a false compiler warning. */ | |
7787 | unsigned char address_size = 0; | |
cb4c35cf | 7788 | dwarf_vma last_offset = 0; |
19e6b90e | 7789 | |
19e6b90e L |
7790 | if (bytes == 0) |
7791 | { | |
7792 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7793 | return 0; | |
7794 | } | |
7795 | ||
77145576 JK |
7796 | if (is_rnglists) |
7797 | { | |
7798 | dwarf_vma initial_length; | |
7799 | unsigned int initial_length_size; | |
7800 | unsigned char segment_selector_size; | |
7801 | unsigned int offset_size, offset_entry_count; | |
7802 | unsigned short version; | |
7803 | ||
7804 | /* Get and check the length of the block. */ | |
7805 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
7806 | ||
7807 | if (initial_length == 0xffffffff) | |
7808 | { | |
7809 | /* This section is 64-bit DWARF 3. */ | |
7810 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
7811 | offset_size = 8; | |
7812 | initial_length_size = 12; | |
7813 | } | |
7814 | else | |
7815 | { | |
7816 | offset_size = 4; | |
7817 | initial_length_size = 4; | |
7818 | } | |
7819 | ||
7820 | if (initial_length + initial_length_size > section->size) | |
7821 | { | |
7822 | /* If the length field has a relocation against it, then we should | |
7823 | not complain if it is inaccurate (and probably negative). | |
7824 | It is copied from .debug_line handling code. */ | |
7825 | if (reloc_at (section, (start - section->start) - offset_size)) | |
7826 | { | |
7827 | initial_length = (finish - start) - initial_length_size; | |
7828 | } | |
7829 | else | |
7830 | { | |
7831 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
7832 | (long) initial_length); | |
7833 | return 0; | |
7834 | } | |
7835 | } | |
7836 | ||
7837 | /* Get and check the version number. */ | |
7838 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
7839 | ||
7840 | if (version != 5) | |
7841 | { | |
7842 | warn (_("Only DWARF version 5 debug_rnglists info " | |
7843 | "is currently supported.\n")); | |
7844 | return 0; | |
7845 | } | |
7846 | ||
7847 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
7848 | ||
7849 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
7850 | if (segment_selector_size != 0) | |
7851 | { | |
7852 | warn (_("The %s section contains " | |
7853 | "unsupported segment selector size: %d.\n"), | |
7854 | section->name, segment_selector_size); | |
7855 | return 0; | |
7856 | } | |
7857 | ||
7858 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
7859 | if (offset_entry_count != 0) | |
7860 | { | |
7861 | warn (_("The %s section contains " | |
7862 | "unsupported offset entry count: %u.\n"), | |
7863 | section->name, offset_entry_count); | |
7864 | return 0; | |
7865 | } | |
7866 | } | |
7867 | ||
1febe64d NC |
7868 | if (load_debug_info (file) == 0) |
7869 | { | |
7870 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7871 | section->name); | |
7872 | return 0; | |
7873 | } | |
19e6b90e | 7874 | |
01a8f077 | 7875 | num_range_list = 0; |
19e6b90e | 7876 | for (i = 0; i < num_debug_info_entries; i++) |
52ff20fe TV |
7877 | { |
7878 | if (debug_information [i].dwarf_version < 5 && is_rnglists) | |
7879 | /* Skip .debug_rnglists reference. */ | |
7880 | continue; | |
7881 | if (debug_information [i].dwarf_version >= 5 && !is_rnglists) | |
7882 | /* Skip .debug_range reference. */ | |
7883 | continue; | |
7884 | num_range_list += debug_information [i].num_range_lists; | |
7885 | } | |
19e6b90e | 7886 | |
01a8f077 | 7887 | if (num_range_list == 0) |
4723351a CC |
7888 | { |
7889 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 7890 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
7891 | printf (_("No range lists in .debug_info section.\n")); |
7892 | return 1; | |
7893 | } | |
19e6b90e | 7894 | |
3f5e193b NC |
7895 | range_entries = (struct range_entry *) |
7896 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 7897 | range_entry_fill = range_entries; |
19e6b90e | 7898 | |
01a8f077 JK |
7899 | for (i = 0; i < num_debug_info_entries; i++) |
7900 | { | |
7901 | debug_info *debug_info_p = &debug_information[i]; | |
7902 | unsigned int j; | |
7903 | ||
52ff20fe TV |
7904 | if (debug_information [i].dwarf_version < 5 && is_rnglists) |
7905 | /* Skip .debug_rnglists reference. */ | |
7906 | continue; | |
7907 | if (debug_information [i].dwarf_version >= 5 && !is_rnglists) | |
7908 | /* Skip .debug_range reference. */ | |
7909 | continue; | |
7910 | ||
01a8f077 JK |
7911 | for (j = 0; j < debug_info_p->num_range_lists; j++) |
7912 | { | |
7913 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
7914 | range_entry_fill->debug_info_p = debug_info_p; | |
7915 | range_entry_fill++; | |
19e6b90e L |
7916 | } |
7917 | } | |
7918 | ||
01a8f077 JK |
7919 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
7920 | range_entry_compar); | |
19e6b90e | 7921 | |
d493b283 | 7922 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 7923 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 7924 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 7925 | |
015dc7e1 | 7926 | introduce (section, false); |
dda8d76d | 7927 | |
19e6b90e L |
7928 | printf (_(" Offset Begin End\n")); |
7929 | ||
01a8f077 | 7930 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 7931 | { |
01a8f077 JK |
7932 | struct range_entry *range_entry = &range_entries[i]; |
7933 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 7934 | unsigned int pointer_size; |
359ca075 | 7935 | dwarf_vma offset; |
01a8f077 | 7936 | unsigned char *next; |
359ca075 | 7937 | dwarf_vma base_address; |
19e6b90e | 7938 | |
77145576 | 7939 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 7940 | offset = range_entry->ranges_offset; |
01a8f077 JK |
7941 | next = section_begin + offset; |
7942 | base_address = debug_info_p->base_address; | |
cecf136e | 7943 | |
f41e4712 NC |
7944 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
7945 | if (pointer_size < 2 || pointer_size > 8) | |
7946 | { | |
7947 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 7948 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
7949 | continue; |
7950 | } | |
b4eb7656 | 7951 | |
d11ae95e NC |
7952 | if (next < section_begin || next >= finish) |
7953 | { | |
7954 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
7955 | (unsigned long) offset, i); | |
7956 | continue; | |
7957 | } | |
7958 | ||
cb4c35cf AB |
7959 | /* If multiple DWARF entities reference the same range then we will |
7960 | have multiple entries in the `range_entries' list for the same | |
7961 | offset. Thanks to the sort above these will all be consecutive in | |
7962 | the `range_entries' list, so we can easily ignore duplicates | |
7963 | here. */ | |
7964 | if (i > 0 && last_offset == offset) | |
7965 | continue; | |
7966 | last_offset = offset; | |
7967 | ||
4723351a | 7968 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 7969 | { |
01a8f077 JK |
7970 | if (start < next) |
7971 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
7972 | (unsigned long) (start - section_begin), | |
7973 | (unsigned long) (next - section_begin), section->name); | |
7974 | else if (start > next) | |
a2ff7a4b AM |
7975 | { |
7976 | if (next == last_start) | |
7977 | continue; | |
7978 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
7979 | (unsigned long) (start - section_begin), | |
7980 | (unsigned long) (next - section_begin), section->name); | |
7981 | } | |
01a8f077 | 7982 | } |
d11ae95e | 7983 | |
01a8f077 | 7984 | start = next; |
a2ff7a4b | 7985 | last_start = next; |
19e6b90e | 7986 | |
77145576 JK |
7987 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
7988 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
7989 | } |
7990 | putchar ('\n'); | |
01a8f077 JK |
7991 | |
7992 | free (range_entries); | |
7993 | ||
19e6b90e L |
7994 | return 1; |
7995 | } | |
7996 | ||
7997 | typedef struct Frame_Chunk | |
7998 | { | |
7999 | struct Frame_Chunk *next; | |
8000 | unsigned char *chunk_start; | |
a1165289 | 8001 | unsigned int ncols; |
19e6b90e L |
8002 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
8003 | short int *col_type; | |
8004 | int *col_offset; | |
8005 | char *augmentation; | |
8006 | unsigned int code_factor; | |
8007 | int data_factor; | |
bf5117e3 NC |
8008 | dwarf_vma pc_begin; |
8009 | dwarf_vma pc_range; | |
32ef3000 | 8010 | unsigned int cfa_reg; |
c8071705 | 8011 | dwarf_vma cfa_offset; |
a1165289 | 8012 | unsigned int ra; |
19e6b90e L |
8013 | unsigned char fde_encoding; |
8014 | unsigned char cfa_exp; | |
604282a7 JJ |
8015 | unsigned char ptr_size; |
8016 | unsigned char segment_size; | |
19e6b90e L |
8017 | } |
8018 | Frame_Chunk; | |
8019 | ||
1296bc99 AB |
8020 | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); |
8021 | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; | |
665ce1f6 L |
8022 | static const char *const *dwarf_regnames; |
8023 | static unsigned int dwarf_regnames_count; | |
8024 | ||
1296bc99 | 8025 | |
19e6b90e L |
8026 | /* A marker for a col_type that means this column was never referenced |
8027 | in the frame info. */ | |
8028 | #define DW_CFA_unreferenced (-1) | |
8029 | ||
a1165289 | 8030 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
8031 | -1 for invalid reg. */ |
8032 | ||
8033 | static int | |
8034 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 8035 | { |
a1165289 | 8036 | unsigned int prev = fc->ncols; |
19e6b90e | 8037 | |
665ce1f6 L |
8038 | if (reg < (unsigned int) fc->ncols) |
8039 | return 0; | |
8040 | ||
d9acf707 | 8041 | if (dwarf_regnames_count > 0 |
665ce1f6 L |
8042 | && reg > dwarf_regnames_count) |
8043 | return -1; | |
19e6b90e L |
8044 | |
8045 | fc->ncols = reg + 1; | |
a1165289 NC |
8046 | /* PR 17512: file: 10450-2643-0.004. |
8047 | If reg == -1 then this can happen... */ | |
8048 | if (fc->ncols == 0) | |
8049 | return -1; | |
8050 | ||
06614111 | 8051 | /* PR 17512: file: 2844a11d. */ |
d9acf707 | 8052 | if (fc->ncols > 1024 && dwarf_regnames_count == 0) |
06614111 NC |
8053 | { |
8054 | error (_("Unfeasibly large register number: %u\n"), reg); | |
8055 | fc->ncols = 0; | |
8056 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
8057 | we ever encounter a valid binary that exceeds it. */ | |
8058 | return -1; | |
8059 | } | |
8060 | ||
3f5e193b | 8061 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 8062 | sizeof (short int)); |
3f5e193b | 8063 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 8064 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
8065 | if (fc->col_type == NULL || fc->col_offset == NULL) |
8066 | { | |
8067 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
8068 | fc->ncols); | |
8069 | fc->ncols = 0; | |
8070 | return -1; | |
8071 | } | |
19e6b90e L |
8072 | |
8073 | while (prev < fc->ncols) | |
8074 | { | |
8075 | fc->col_type[prev] = DW_CFA_unreferenced; | |
8076 | fc->col_offset[prev] = 0; | |
8077 | prev++; | |
8078 | } | |
665ce1f6 | 8079 | return 1; |
19e6b90e L |
8080 | } |
8081 | ||
2dc4cec1 L |
8082 | static const char *const dwarf_regnames_i386[] = |
8083 | { | |
43234a1e L |
8084 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
8085 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
8086 | "eip", "eflags", NULL, /* 8 - 10 */ | |
8087 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
8088 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
8089 | NULL, NULL, /* 19 - 20 */ | |
8090 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
8091 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
8092 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
8093 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
8094 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
8095 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
8096 | "tr", "ldtr", /* 48 - 49 */ | |
8097 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
8098 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
8099 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
8100 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
8101 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
8102 | NULL, NULL, NULL, /* 90 - 92 */ | |
8103 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
8104 | }; |
8105 | ||
3d875af5 L |
8106 | static const char *const dwarf_regnames_iamcu[] = |
8107 | { | |
8108 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
8109 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
8110 | "eip", "eflags", NULL, /* 8 - 10 */ | |
8111 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
8112 | NULL, NULL, /* 19 - 20 */ | |
8113 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
8114 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
8115 | NULL, NULL, NULL, /* 37 - 39 */ | |
8116 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
8117 | "tr", "ldtr", /* 48 - 49 */ | |
8118 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
8119 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
8120 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
8121 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
8122 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
8123 | NULL, NULL, NULL, /* 90 - 92 */ | |
8124 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
8125 | }; | |
8126 | ||
99f6fdd9 | 8127 | static void |
b129eb0e RH |
8128 | init_dwarf_regnames_i386 (void) |
8129 | { | |
8130 | dwarf_regnames = dwarf_regnames_i386; | |
8131 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
1296bc99 | 8132 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
8133 | } |
8134 | ||
99f6fdd9 | 8135 | static void |
3d875af5 L |
8136 | init_dwarf_regnames_iamcu (void) |
8137 | { | |
8138 | dwarf_regnames = dwarf_regnames_iamcu; | |
8139 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
1296bc99 | 8140 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
3d875af5 L |
8141 | } |
8142 | ||
2dc4cec1 L |
8143 | static const char *const dwarf_regnames_x86_64[] = |
8144 | { | |
8145 | "rax", "rdx", "rcx", "rbx", | |
8146 | "rsi", "rdi", "rbp", "rsp", | |
8147 | "r8", "r9", "r10", "r11", | |
8148 | "r12", "r13", "r14", "r15", | |
8149 | "rip", | |
8150 | "xmm0", "xmm1", "xmm2", "xmm3", | |
8151 | "xmm4", "xmm5", "xmm6", "xmm7", | |
8152 | "xmm8", "xmm9", "xmm10", "xmm11", | |
8153 | "xmm12", "xmm13", "xmm14", "xmm15", | |
8154 | "st0", "st1", "st2", "st3", | |
8155 | "st4", "st5", "st6", "st7", | |
8156 | "mm0", "mm1", "mm2", "mm3", | |
8157 | "mm4", "mm5", "mm6", "mm7", | |
8158 | "rflags", | |
8159 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
8160 | "fs.base", "gs.base", NULL, NULL, | |
8161 | "tr", "ldtr", | |
43234a1e L |
8162 | "mxcsr", "fcw", "fsw", |
8163 | "xmm16", "xmm17", "xmm18", "xmm19", | |
8164 | "xmm20", "xmm21", "xmm22", "xmm23", | |
8165 | "xmm24", "xmm25", "xmm26", "xmm27", | |
8166 | "xmm28", "xmm29", "xmm30", "xmm31", | |
8167 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
8168 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
8169 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
8170 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
8171 | NULL, NULL, NULL, /* 115 - 117 */ | |
8172 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
8173 | }; |
8174 | ||
99f6fdd9 | 8175 | static void |
b129eb0e RH |
8176 | init_dwarf_regnames_x86_64 (void) |
8177 | { | |
8178 | dwarf_regnames = dwarf_regnames_x86_64; | |
8179 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
1296bc99 | 8180 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
8181 | } |
8182 | ||
4ee22035 RH |
8183 | static const char *const dwarf_regnames_aarch64[] = |
8184 | { | |
b4eb7656 AM |
8185 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
8186 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
8187 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
8188 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
8189 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
fab7c86e TC |
8190 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
8191 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", | |
8192 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", | |
b4eb7656 AM |
8193 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
8194 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
8195 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
8196 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
fab7c86e TC |
8197 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
8198 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", | |
8199 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", | |
8200 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", | |
4ee22035 RH |
8201 | }; |
8202 | ||
99f6fdd9 | 8203 | static void |
4ee22035 RH |
8204 | init_dwarf_regnames_aarch64 (void) |
8205 | { | |
8206 | dwarf_regnames = dwarf_regnames_aarch64; | |
8207 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
1296bc99 | 8208 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
4ee22035 RH |
8209 | } |
8210 | ||
d6bb17b0 AA |
8211 | static const char *const dwarf_regnames_s390[] = |
8212 | { | |
8213 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
8214 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
8215 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
8216 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
8217 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
8218 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
8219 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
8220 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
8221 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
8222 | "pswm", "pswa", | |
8223 | NULL, NULL, | |
8224 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
8225 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
8226 | }; | |
8227 | ||
99f6fdd9 | 8228 | static void |
d6bb17b0 AA |
8229 | init_dwarf_regnames_s390 (void) |
8230 | { | |
8231 | dwarf_regnames = dwarf_regnames_s390; | |
8232 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
1296bc99 | 8233 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
d6bb17b0 AA |
8234 | } |
8235 | ||
5bb0830d AB |
8236 | static const char *const dwarf_regnames_riscv[] = |
8237 | { | |
8238 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
8239 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
8240 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
8241 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
8242 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
8243 | "fs0", "fs1", /* 40 - 41 */ | |
8244 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
8245 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
8246 | "fs10", "fs11", /* 58 - 59 */ | |
8247 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
8248 | }; | |
8249 | ||
4762fe62 AB |
8250 | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles |
8251 | the large number of CSRs. */ | |
8252 | ||
8253 | static const char * | |
8254 | regname_internal_riscv (unsigned int regno) | |
8255 | { | |
8256 | const char *name = NULL; | |
8257 | ||
8258 | /* Lookup in the table first, this covers GPR and FPR. */ | |
8259 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) | |
8260 | name = dwarf_regnames_riscv [regno]; | |
8261 | else if (regno >= 4096 && regno <= 8191) | |
8262 | { | |
8263 | /* This might be a CSR, these live in a sparse number space from 4096 | |
8264 | to 8191 These numbers are defined in the RISC-V ELF ABI | |
8265 | document. */ | |
8266 | switch (regno) | |
8267 | { | |
8f595e9b NC |
8268 | #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \ |
8269 | case VALUE + 4096: name = #NAME; break; | |
4762fe62 AB |
8270 | #include "opcode/riscv-opc.h" |
8271 | #undef DECLARE_CSR | |
8272 | ||
8273 | default: | |
8274 | { | |
8275 | static char csr_name[10]; | |
8276 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); | |
8277 | name = csr_name; | |
8278 | } | |
8279 | break; | |
8280 | } | |
8281 | } | |
8282 | ||
8283 | return name; | |
8284 | } | |
8285 | ||
99f6fdd9 | 8286 | static void |
5bb0830d AB |
8287 | init_dwarf_regnames_riscv (void) |
8288 | { | |
4762fe62 AB |
8289 | dwarf_regnames = NULL; |
8290 | dwarf_regnames_count = 8192; | |
8291 | dwarf_regnames_lookup_func = regname_internal_riscv; | |
5bb0830d AB |
8292 | } |
8293 | ||
2dc4cec1 | 8294 | void |
955ff7fc | 8295 | init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) |
2dc4cec1 | 8296 | { |
1296bc99 AB |
8297 | dwarf_regnames_lookup_func = NULL; |
8298 | ||
2dc4cec1 L |
8299 | switch (e_machine) |
8300 | { | |
8301 | case EM_386: | |
b129eb0e | 8302 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
8303 | break; |
8304 | ||
3d875af5 L |
8305 | case EM_IAMCU: |
8306 | init_dwarf_regnames_iamcu (); | |
8307 | break; | |
8308 | ||
2dc4cec1 | 8309 | case EM_X86_64: |
7f502d6c | 8310 | case EM_L1OM: |
7a9068fe | 8311 | case EM_K1OM: |
b129eb0e | 8312 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
8313 | break; |
8314 | ||
4ee22035 RH |
8315 | case EM_AARCH64: |
8316 | init_dwarf_regnames_aarch64 (); | |
8317 | break; | |
8318 | ||
d6bb17b0 AA |
8319 | case EM_S390: |
8320 | init_dwarf_regnames_s390 (); | |
8321 | break; | |
8322 | ||
5bb0830d AB |
8323 | case EM_RISCV: |
8324 | init_dwarf_regnames_riscv (); | |
8325 | break; | |
8326 | ||
2dc4cec1 L |
8327 | default: |
8328 | break; | |
8329 | } | |
8330 | } | |
8331 | ||
229a22cf AB |
8332 | /* Initialize the DWARF register name lookup state based on the |
8333 | architecture and specific machine type of a BFD. */ | |
8334 | ||
8335 | void | |
8336 | init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, | |
8337 | unsigned long mach) | |
8338 | { | |
1296bc99 AB |
8339 | dwarf_regnames_lookup_func = NULL; |
8340 | ||
229a22cf AB |
8341 | switch (arch) |
8342 | { | |
8343 | case bfd_arch_i386: | |
8344 | switch (mach) | |
8345 | { | |
8346 | case bfd_mach_x86_64: | |
8347 | case bfd_mach_x86_64_intel_syntax: | |
229a22cf AB |
8348 | case bfd_mach_x64_32: |
8349 | case bfd_mach_x64_32_intel_syntax: | |
229a22cf AB |
8350 | init_dwarf_regnames_x86_64 (); |
8351 | break; | |
8352 | ||
8353 | default: | |
8354 | init_dwarf_regnames_i386 (); | |
8355 | break; | |
8356 | } | |
8357 | break; | |
8358 | ||
8359 | case bfd_arch_iamcu: | |
8360 | init_dwarf_regnames_iamcu (); | |
8361 | break; | |
8362 | ||
8363 | case bfd_arch_aarch64: | |
8364 | init_dwarf_regnames_aarch64(); | |
8365 | break; | |
8366 | ||
8367 | case bfd_arch_s390: | |
8368 | init_dwarf_regnames_s390 (); | |
8369 | break; | |
8370 | ||
8371 | case bfd_arch_riscv: | |
8372 | init_dwarf_regnames_riscv (); | |
8373 | break; | |
8374 | ||
8375 | default: | |
8376 | break; | |
8377 | } | |
8378 | } | |
8379 | ||
2dc4cec1 | 8380 | static const char * |
1296bc99 | 8381 | regname_internal_by_table_only (unsigned int regno) |
2dc4cec1 | 8382 | { |
1296bc99 | 8383 | if (dwarf_regnames != NULL |
2dc4cec1 L |
8384 | && regno < dwarf_regnames_count |
8385 | && dwarf_regnames [regno] != NULL) | |
1296bc99 AB |
8386 | return dwarf_regnames [regno]; |
8387 | ||
8388 | return NULL; | |
8389 | } | |
8390 | ||
8391 | static const char * | |
8392 | regname (unsigned int regno, int name_only_p) | |
8393 | { | |
8394 | static char reg[64]; | |
8395 | ||
8396 | const char *name = NULL; | |
8397 | ||
8398 | if (dwarf_regnames_lookup_func != NULL) | |
8399 | name = dwarf_regnames_lookup_func (regno); | |
8400 | ||
8401 | if (name != NULL) | |
2dc4cec1 | 8402 | { |
1296bc99 AB |
8403 | if (name_only_p) |
8404 | return name; | |
8405 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); | |
2dc4cec1 L |
8406 | } |
8407 | else | |
8408 | snprintf (reg, sizeof (reg), "r%d", regno); | |
8409 | return reg; | |
8410 | } | |
8411 | ||
19e6b90e | 8412 | static void |
a1165289 | 8413 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 8414 | { |
a1165289 | 8415 | unsigned int r; |
19e6b90e L |
8416 | char tmp[100]; |
8417 | ||
d8024a91 | 8418 | if (*max_regs != fc->ncols) |
19e6b90e L |
8419 | *max_regs = fc->ncols; |
8420 | ||
8421 | if (*need_col_headers) | |
8422 | { | |
8423 | *need_col_headers = 0; | |
8424 | ||
288f0ba2 | 8425 | printf ("%-*s CFA ", eh_addr_size * 2, " LOC"); |
19e6b90e L |
8426 | |
8427 | for (r = 0; r < *max_regs; r++) | |
8428 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
8429 | { | |
8430 | if (r == fc->ra) | |
50751e18 | 8431 | printf ("ra "); |
19e6b90e | 8432 | else |
2dc4cec1 | 8433 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
8434 | } |
8435 | ||
8436 | printf ("\n"); | |
8437 | } | |
8438 | ||
bf5117e3 | 8439 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
8440 | if (fc->cfa_exp) |
8441 | strcpy (tmp, "exp"); | |
8442 | else | |
c8071705 | 8443 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
8444 | printf ("%-8s ", tmp); |
8445 | ||
8446 | for (r = 0; r < fc->ncols; r++) | |
8447 | { | |
8448 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
8449 | { | |
8450 | switch (fc->col_type[r]) | |
8451 | { | |
8452 | case DW_CFA_undefined: | |
8453 | strcpy (tmp, "u"); | |
8454 | break; | |
8455 | case DW_CFA_same_value: | |
8456 | strcpy (tmp, "s"); | |
8457 | break; | |
8458 | case DW_CFA_offset: | |
8459 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
8460 | break; | |
12eae2d3 JJ |
8461 | case DW_CFA_val_offset: |
8462 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
8463 | break; | |
19e6b90e | 8464 | case DW_CFA_register: |
2dc4cec1 | 8465 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
8466 | break; |
8467 | case DW_CFA_expression: | |
8468 | strcpy (tmp, "exp"); | |
8469 | break; | |
12eae2d3 JJ |
8470 | case DW_CFA_val_expression: |
8471 | strcpy (tmp, "vexp"); | |
8472 | break; | |
19e6b90e L |
8473 | default: |
8474 | strcpy (tmp, "n/a"); | |
8475 | break; | |
8476 | } | |
2dc4cec1 | 8477 | printf ("%-5s ", tmp); |
19e6b90e L |
8478 | } |
8479 | } | |
8480 | printf ("\n"); | |
8481 | } | |
8482 | ||
49727e46 | 8483 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 8484 | |
49727e46 AM |
8485 | static unsigned char * |
8486 | read_cie (unsigned char *start, unsigned char *end, | |
8487 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 8488 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
8489 | { |
8490 | int version; | |
8491 | Frame_Chunk *fc; | |
49727e46 | 8492 | unsigned char *augmentation_data = NULL; |
bf59c5d5 | 8493 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 8494 | |
041830e0 | 8495 | * p_cie = NULL; |
f41e4712 NC |
8496 | /* PR 17512: file: 001-228113-0.004. */ |
8497 | if (start >= end) | |
8498 | return end; | |
8499 | ||
49727e46 AM |
8500 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
8501 | memset (fc, 0, sizeof (Frame_Chunk)); | |
8502 | ||
8503 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
8504 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
8505 | ||
8506 | version = *start++; | |
8507 | ||
8508 | fc->augmentation = (char *) start; | |
f41e4712 NC |
8509 | /* PR 17512: file: 001-228113-0.004. |
8510 | Skip past augmentation name, but avoid running off the end of the data. */ | |
8511 | while (start < end) | |
8512 | if (* start ++ == '\0') | |
8513 | break; | |
8514 | if (start == end) | |
8515 | { | |
8516 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 8517 | goto fail; |
f41e4712 | 8518 | } |
49727e46 AM |
8519 | |
8520 | if (strcmp (fc->augmentation, "eh") == 0) | |
8521 | start += eh_addr_size; | |
8522 | ||
8523 | if (version >= 4) | |
8524 | { | |
8525 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
8526 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
8527 | { | |
8528 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 8529 | goto fail; |
77ef8654 NC |
8530 | } |
8531 | ||
49727e46 | 8532 | GET (fc->segment_size, 1); |
77ef8654 NC |
8533 | /* PR 17512: file: e99d2804. */ |
8534 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
8535 | { | |
8536 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 8537 | goto fail; |
77ef8654 NC |
8538 | } |
8539 | ||
49727e46 AM |
8540 | eh_addr_size = fc->ptr_size; |
8541 | } | |
8542 | else | |
8543 | { | |
8544 | fc->ptr_size = eh_addr_size; | |
8545 | fc->segment_size = 0; | |
8546 | } | |
442a6ce8 | 8547 | |
cd30bcef AM |
8548 | READ_ULEB (fc->code_factor, start, end); |
8549 | READ_SLEB (fc->data_factor, start, end); | |
442a6ce8 | 8550 | |
49727e46 AM |
8551 | if (version == 1) |
8552 | { | |
8553 | GET (fc->ra, 1); | |
8554 | } | |
8555 | else | |
8556 | { | |
cd30bcef | 8557 | READ_ULEB (fc->ra, start, end); |
49727e46 AM |
8558 | } |
8559 | ||
8560 | if (fc->augmentation[0] == 'z') | |
8561 | { | |
cd30bcef | 8562 | READ_ULEB (augmentation_data_len, start, end); |
49727e46 | 8563 | augmentation_data = start; |
a1165289 | 8564 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 8565 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 8566 | { |
bf59c5d5 NC |
8567 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
8568 | dwarf_vmatoa ("x", augmentation_data_len), | |
8569 | (unsigned long) (end - start)); | |
442a6ce8 | 8570 | goto fail; |
a1165289 | 8571 | } |
9c0f3d3f | 8572 | start += augmentation_data_len; |
49727e46 AM |
8573 | } |
8574 | ||
8575 | if (augmentation_data_len) | |
8576 | { | |
058037d3 NC |
8577 | unsigned char *p; |
8578 | unsigned char *q; | |
8579 | unsigned char *qend; | |
b4eb7656 | 8580 | |
49727e46 AM |
8581 | p = (unsigned char *) fc->augmentation + 1; |
8582 | q = augmentation_data; | |
058037d3 NC |
8583 | qend = q + augmentation_data_len; |
8584 | ||
9c0f3d3f | 8585 | while (p < end && q < qend) |
49727e46 AM |
8586 | { |
8587 | if (*p == 'L') | |
8588 | q++; | |
8589 | else if (*p == 'P') | |
8590 | q += 1 + size_of_encoded_value (*q); | |
8591 | else if (*p == 'R') | |
8592 | fc->fde_encoding = *q++; | |
8593 | else if (*p == 'S') | |
8594 | ; | |
09038062 ST |
8595 | else if (*p == 'B') |
8596 | ; | |
49727e46 AM |
8597 | else |
8598 | break; | |
8599 | p++; | |
8600 | } | |
c361b9ac NC |
8601 | /* Note - it is OK if this loop terminates with q < qend. |
8602 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
8603 | } |
8604 | ||
8605 | *p_cie = fc; | |
8606 | if (p_version) | |
8607 | *p_version = version; | |
8608 | if (p_aug_len) | |
8609 | { | |
8610 | *p_aug_len = augmentation_data_len; | |
8611 | *p_aug = augmentation_data; | |
8612 | } | |
8613 | return start; | |
442a6ce8 NC |
8614 | |
8615 | fail: | |
8616 | free (fc->col_offset); | |
8617 | free (fc->col_type); | |
8618 | free (fc); | |
8619 | return end; | |
49727e46 AM |
8620 | } |
8621 | ||
d85bf2ba NC |
8622 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
8623 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
8624 | PRINTED contains the number of characters already written to the current | |
8625 | output line. */ | |
bf59c5d5 NC |
8626 | |
8627 | static void | |
d85bf2ba NC |
8628 | display_data (bfd_size_type printed, |
8629 | const unsigned char * data, | |
8630 | const bfd_size_type len) | |
bf59c5d5 | 8631 | { |
d85bf2ba NC |
8632 | if (do_wide || len < ((80 - printed) / 3)) |
8633 | for (printed = 0; printed < len; ++printed) | |
8634 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
8635 | else |
8636 | { | |
d85bf2ba | 8637 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 8638 | { |
d85bf2ba | 8639 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 8640 | putchar ('\n'); |
d85bf2ba | 8641 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
8642 | } |
8643 | } | |
d85bf2ba NC |
8644 | } |
8645 | ||
8646 | /* Prints out the contents on the augmentation data array. | |
8647 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
8648 | ||
8649 | static void | |
8650 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
8651 | { | |
8652 | bfd_size_type i; | |
8653 | ||
8654 | i = printf (_(" Augmentation data: ")); | |
8655 | display_data (i, data, len); | |
bf59c5d5 NC |
8656 | } |
8657 | ||
19e6b90e L |
8658 | static int |
8659 | display_debug_frames (struct dwarf_section *section, | |
8660 | void *file ATTRIBUTE_UNUSED) | |
8661 | { | |
8662 | unsigned char *start = section->start; | |
8663 | unsigned char *end = start + section->size; | |
8664 | unsigned char *section_start = start; | |
3391569f NC |
8665 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
8666 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 8667 | Frame_Chunk *rs; |
015dc7e1 | 8668 | bool is_eh = strcmp (section->name, ".eh_frame") == 0; |
a1165289 | 8669 | unsigned int max_regs = 0; |
665ce1f6 | 8670 | const char *bad_reg = _("bad register: "); |
77ef8654 | 8671 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 8672 | |
015dc7e1 | 8673 | introduce (section, false); |
19e6b90e L |
8674 | |
8675 | while (start < end) | |
8676 | { | |
8677 | unsigned char *saved_start; | |
8678 | unsigned char *block_end; | |
bf5117e3 NC |
8679 | dwarf_vma length; |
8680 | dwarf_vma cie_id; | |
19e6b90e L |
8681 | Frame_Chunk *fc; |
8682 | Frame_Chunk *cie; | |
8683 | int need_col_headers = 1; | |
8684 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 8685 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
8686 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
8687 | unsigned int offset_size; | |
8688 | unsigned int initial_length_size; | |
015dc7e1 | 8689 | bool all_nops; |
a788aedd | 8690 | static Frame_Chunk fde_fc; |
19e6b90e L |
8691 | |
8692 | saved_start = start; | |
19e6b90e | 8693 | |
0c588247 | 8694 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 8695 | |
19e6b90e L |
8696 | if (length == 0) |
8697 | { | |
8698 | printf ("\n%08lx ZERO terminator\n\n", | |
8699 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
8700 | /* Skip any zero terminators that directly follow. |
8701 | A corrupt section size could have loaded a whole | |
8702 | slew of zero filled memory bytes. eg | |
8703 | PR 17512: file: 070-19381-0.004. */ | |
8704 | while (start < end && * start == 0) | |
8705 | ++ start; | |
b758e50f | 8706 | continue; |
19e6b90e L |
8707 | } |
8708 | ||
8709 | if (length == 0xffffffff) | |
8710 | { | |
0c588247 | 8711 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
8712 | offset_size = 8; |
8713 | initial_length_size = 12; | |
8714 | } | |
8715 | else | |
8716 | { | |
8717 | offset_size = 4; | |
8718 | initial_length_size = 4; | |
8719 | } | |
8720 | ||
8721 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 8722 | if (block_end > end || block_end < start) |
53b8873b | 8723 | { |
bf5117e3 NC |
8724 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
8725 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
8726 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
8727 | block_end = end; |
8728 | } | |
0c588247 NC |
8729 | |
8730 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 8731 | |
846a11e4 NC |
8732 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
8733 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
8734 | { |
8735 | int version; | |
a1165289 | 8736 | unsigned int mreg; |
19e6b90e | 8737 | |
49727e46 AM |
8738 | start = read_cie (start, end, &cie, &version, |
8739 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
8740 | /* PR 17512: file: 027-135133-0.005. */ |
8741 | if (cie == NULL) | |
8742 | break; | |
a1165289 | 8743 | |
49727e46 | 8744 | fc = cie; |
19e6b90e L |
8745 | fc->next = chunks; |
8746 | chunks = fc; | |
8747 | fc->chunk_start = saved_start; | |
a1165289 | 8748 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8749 | if (mreg < fc->ra) |
8750 | mreg = fc->ra; | |
06614111 NC |
8751 | if (frame_need_space (fc, mreg) < 0) |
8752 | break; | |
49727e46 AM |
8753 | if (fc->fde_encoding) |
8754 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 8755 | |
bf5117e3 NC |
8756 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
8757 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 8758 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 8759 | |
19e6b90e | 8760 | if (do_debug_frames_interp) |
bf5117e3 NC |
8761 | { |
8762 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
8763 | fc->code_factor, fc->data_factor, fc->ra); | |
8764 | } | |
19e6b90e L |
8765 | else |
8766 | { | |
bf5117e3 | 8767 | printf ("CIE\n"); |
19e6b90e L |
8768 | printf (" Version: %d\n", version); |
8769 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
8770 | if (version >= 4) |
8771 | { | |
8772 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
8773 | printf (" Segment Size: %u\n", fc->segment_size); | |
8774 | } | |
19e6b90e L |
8775 | printf (" Code alignment factor: %u\n", fc->code_factor); |
8776 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
8777 | printf (" Return address column: %d\n", fc->ra); | |
8778 | ||
8779 | if (augmentation_data_len) | |
bf59c5d5 | 8780 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 8781 | |
19e6b90e L |
8782 | putchar ('\n'); |
8783 | } | |
19e6b90e L |
8784 | } |
8785 | else | |
8786 | { | |
8787 | unsigned char *look_for; | |
604282a7 | 8788 | unsigned long segment_selector; |
19e6b90e | 8789 | |
49727e46 AM |
8790 | if (is_eh) |
8791 | { | |
8792 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
8793 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
8794 | } | |
8795 | else | |
8796 | look_for = section_start + cie_id; | |
19e6b90e | 8797 | |
49727e46 AM |
8798 | if (look_for <= saved_start) |
8799 | { | |
8800 | for (cie = chunks; cie ; cie = cie->next) | |
8801 | if (cie->chunk_start == look_for) | |
8802 | break; | |
8803 | } | |
8804 | else | |
8805 | { | |
8806 | for (cie = forward_refs; cie ; cie = cie->next) | |
8807 | if (cie->chunk_start == look_for) | |
8808 | break; | |
8809 | if (!cie) | |
8810 | { | |
8811 | unsigned int off_size; | |
8812 | unsigned char *cie_scan; | |
19e6b90e | 8813 | |
49727e46 AM |
8814 | cie_scan = look_for; |
8815 | off_size = 4; | |
8816 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
8817 | if (length == 0xffffffff) | |
8818 | { | |
8819 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
8820 | off_size = 8; | |
8821 | } | |
8822 | if (length != 0) | |
8823 | { | |
8824 | dwarf_vma c_id; | |
8825 | ||
8826 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
8827 | if (is_eh | |
8828 | ? c_id == 0 | |
8829 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
8830 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
8831 | { | |
8832 | int version; | |
a1165289 | 8833 | unsigned int mreg; |
49727e46 AM |
8834 | |
8835 | read_cie (cie_scan, end, &cie, &version, | |
8836 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
8837 | /* PR 17512: file: 3450-2098-0.004. */ |
8838 | if (cie == NULL) | |
8839 | { | |
8840 | warn (_("Failed to read CIE information\n")); | |
8841 | break; | |
8842 | } | |
49727e46 AM |
8843 | cie->next = forward_refs; |
8844 | forward_refs = cie; | |
8845 | cie->chunk_start = look_for; | |
a1165289 | 8846 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8847 | if (mreg < cie->ra) |
8848 | mreg = cie->ra; | |
06614111 NC |
8849 | if (frame_need_space (cie, mreg) < 0) |
8850 | { | |
8851 | warn (_("Invalid max register\n")); | |
8852 | break; | |
8853 | } | |
49727e46 AM |
8854 | if (cie->fde_encoding) |
8855 | encoded_ptr_size | |
8856 | = size_of_encoded_value (cie->fde_encoding); | |
8857 | } | |
8858 | } | |
8859 | } | |
8860 | } | |
8861 | ||
8862 | fc = &fde_fc; | |
8863 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
8864 | |
8865 | if (!cie) | |
8866 | { | |
bf5117e3 NC |
8867 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
8868 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
8869 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 8870 | fc->ncols = 0; |
3f5e193b NC |
8871 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
8872 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
8873 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
8874 | { | |
8875 | warn (_("Invalid max register\n")); | |
8876 | break; | |
8877 | } | |
19e6b90e L |
8878 | cie = fc; |
8879 | fc->augmentation = ""; | |
8880 | fc->fde_encoding = 0; | |
604282a7 JJ |
8881 | fc->ptr_size = eh_addr_size; |
8882 | fc->segment_size = 0; | |
19e6b90e L |
8883 | } |
8884 | else | |
8885 | { | |
8886 | fc->ncols = cie->ncols; | |
3f5e193b NC |
8887 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
8888 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
8889 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
8890 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
8891 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
8892 | fc->ptr_size = cie->ptr_size; |
8893 | eh_addr_size = cie->ptr_size; | |
8894 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
8895 | fc->code_factor = cie->code_factor; |
8896 | fc->data_factor = cie->data_factor; | |
8897 | fc->cfa_reg = cie->cfa_reg; | |
8898 | fc->cfa_offset = cie->cfa_offset; | |
8899 | fc->ra = cie->ra; | |
06614111 NC |
8900 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
8901 | { | |
8902 | warn (_("Invalid max register\n")); | |
8903 | break; | |
8904 | } | |
19e6b90e L |
8905 | fc->fde_encoding = cie->fde_encoding; |
8906 | } | |
8907 | ||
8908 | if (fc->fde_encoding) | |
8909 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
8910 | ||
604282a7 JJ |
8911 | segment_selector = 0; |
8912 | if (fc->segment_size) | |
c8071705 NC |
8913 | { |
8914 | if (fc->segment_size > sizeof (segment_selector)) | |
8915 | { | |
8916 | /* PR 17512: file: 9e196b3e. */ | |
8917 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
8918 | fc->segment_size = 4; | |
8919 | } | |
8920 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
8921 | } | |
041830e0 NC |
8922 | |
8923 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 8924 | |
0c588247 NC |
8925 | /* FIXME: It appears that sometimes the final pc_range value is |
8926 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
8927 | run of the "objcopy on compressed debug sections" test for an | |
8928 | example of this. */ | |
8929 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 8930 | |
19e6b90e L |
8931 | if (cie->augmentation[0] == 'z') |
8932 | { | |
cd30bcef | 8933 | READ_ULEB (augmentation_data_len, start, end); |
19e6b90e | 8934 | augmentation_data = start; |
bf59c5d5 | 8935 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
d292364e | 8936 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
0a9d414a | 8937 | { |
d292364e AM |
8938 | warn (_("Augmentation data too long: 0x%s, " |
8939 | "expected at most %#lx\n"), | |
8940 | dwarf_vmatoa ("x", augmentation_data_len), | |
8941 | (unsigned long) (end - start)); | |
0a9d414a NC |
8942 | start = end; |
8943 | augmentation_data = NULL; | |
8944 | augmentation_data_len = 0; | |
8945 | } | |
d292364e | 8946 | start += augmentation_data_len; |
19e6b90e L |
8947 | } |
8948 | ||
bf5117e3 NC |
8949 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
8950 | (unsigned long)(saved_start - section_start), | |
8951 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 8952 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 8953 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 8954 | |
604282a7 JJ |
8955 | if (fc->segment_size) |
8956 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
8957 | |
8958 | printf ("%s..%s\n", | |
8959 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
8960 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
8961 | ||
19e6b90e L |
8962 | if (! do_debug_frames_interp && augmentation_data_len) |
8963 | { | |
bf59c5d5 | 8964 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
8965 | putchar ('\n'); |
8966 | } | |
8967 | } | |
8968 | ||
8969 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
8970 | we're about to interpret instructions for the chunk. */ | |
8971 | /* ??? At present we need to do this always, since this sizes the | |
8972 | fc->col_type and fc->col_offset arrays, which we write into always. | |
8973 | We should probably split the interpreted and non-interpreted bits | |
8974 | into two different routines, since there's so much that doesn't | |
8975 | really overlap between them. */ | |
8976 | if (1 || do_debug_frames_interp) | |
8977 | { | |
8978 | /* Start by making a pass over the chunk, allocating storage | |
8979 | and taking note of what registers are used. */ | |
8980 | unsigned char *tmp = start; | |
8981 | ||
8982 | while (start < block_end) | |
8983 | { | |
041830e0 NC |
8984 | unsigned int reg, op, opa; |
8985 | unsigned long temp; | |
5929c344 | 8986 | unsigned char * new_start; |
19e6b90e L |
8987 | |
8988 | op = *start++; | |
8989 | opa = op & 0x3f; | |
8990 | if (op & 0xc0) | |
8991 | op &= 0xc0; | |
8992 | ||
8993 | /* Warning: if you add any more cases to this switch, be | |
8994 | sure to add them to the corresponding switch below. */ | |
8995 | switch (op) | |
8996 | { | |
8997 | case DW_CFA_advance_loc: | |
8998 | break; | |
8999 | case DW_CFA_offset: | |
cd30bcef | 9000 | SKIP_ULEB (start, end); |
665ce1f6 L |
9001 | if (frame_need_space (fc, opa) >= 0) |
9002 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
9003 | break; |
9004 | case DW_CFA_restore: | |
665ce1f6 L |
9005 | if (frame_need_space (fc, opa) >= 0) |
9006 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
9007 | break; |
9008 | case DW_CFA_set_loc: | |
9009 | start += encoded_ptr_size; | |
9010 | break; | |
9011 | case DW_CFA_advance_loc1: | |
9012 | start += 1; | |
9013 | break; | |
9014 | case DW_CFA_advance_loc2: | |
9015 | start += 2; | |
9016 | break; | |
9017 | case DW_CFA_advance_loc4: | |
9018 | start += 4; | |
9019 | break; | |
9020 | case DW_CFA_offset_extended: | |
12eae2d3 | 9021 | case DW_CFA_val_offset: |
cd30bcef AM |
9022 | READ_ULEB (reg, start, end); |
9023 | SKIP_ULEB (start, end); | |
665ce1f6 L |
9024 | if (frame_need_space (fc, reg) >= 0) |
9025 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9026 | break; |
9027 | case DW_CFA_restore_extended: | |
cd30bcef | 9028 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9029 | if (frame_need_space (fc, reg) >= 0) |
9030 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9031 | break; |
9032 | case DW_CFA_undefined: | |
cd30bcef | 9033 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9034 | if (frame_need_space (fc, reg) >= 0) |
9035 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9036 | break; |
9037 | case DW_CFA_same_value: | |
cd30bcef | 9038 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9039 | if (frame_need_space (fc, reg) >= 0) |
9040 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9041 | break; |
9042 | case DW_CFA_register: | |
cd30bcef AM |
9043 | READ_ULEB (reg, start, end); |
9044 | SKIP_ULEB (start, end); | |
665ce1f6 L |
9045 | if (frame_need_space (fc, reg) >= 0) |
9046 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9047 | break; |
9048 | case DW_CFA_def_cfa: | |
cd30bcef AM |
9049 | SKIP_ULEB (start, end); |
9050 | SKIP_ULEB (start, end); | |
19e6b90e L |
9051 | break; |
9052 | case DW_CFA_def_cfa_register: | |
cd30bcef | 9053 | SKIP_ULEB (start, end); |
19e6b90e L |
9054 | break; |
9055 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 9056 | SKIP_ULEB (start, end); |
19e6b90e L |
9057 | break; |
9058 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 9059 | READ_ULEB (temp, start, end); |
5929c344 NC |
9060 | new_start = start + temp; |
9061 | if (new_start < start) | |
041830e0 NC |
9062 | { |
9063 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
9064 | start = block_end; | |
9065 | } | |
9066 | else | |
5929c344 | 9067 | start = new_start; |
19e6b90e L |
9068 | break; |
9069 | case DW_CFA_expression: | |
12eae2d3 | 9070 | case DW_CFA_val_expression: |
cd30bcef AM |
9071 | READ_ULEB (reg, start, end); |
9072 | READ_ULEB (temp, start, end); | |
5929c344 NC |
9073 | new_start = start + temp; |
9074 | if (new_start < start) | |
041830e0 | 9075 | { |
b4eb7656 | 9076 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
9077 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
9078 | start = block_end; | |
9079 | } | |
9080 | else | |
5929c344 | 9081 | start = new_start; |
665ce1f6 L |
9082 | if (frame_need_space (fc, reg) >= 0) |
9083 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9084 | break; |
9085 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 9086 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
9087 | READ_ULEB (reg, start, end); |
9088 | SKIP_SLEB (start, end); | |
665ce1f6 L |
9089 | if (frame_need_space (fc, reg) >= 0) |
9090 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9091 | break; |
9092 | case DW_CFA_def_cfa_sf: | |
cd30bcef AM |
9093 | SKIP_ULEB (start, end); |
9094 | SKIP_SLEB (start, end); | |
19e6b90e L |
9095 | break; |
9096 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 9097 | SKIP_SLEB (start, end); |
19e6b90e L |
9098 | break; |
9099 | case DW_CFA_MIPS_advance_loc8: | |
9100 | start += 8; | |
9101 | break; | |
9102 | case DW_CFA_GNU_args_size: | |
cd30bcef | 9103 | SKIP_ULEB (start, end); |
19e6b90e L |
9104 | break; |
9105 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
9106 | READ_ULEB (reg, start, end); |
9107 | SKIP_ULEB (start, end); | |
665ce1f6 L |
9108 | if (frame_need_space (fc, reg) >= 0) |
9109 | fc->col_type[reg] = DW_CFA_undefined; | |
9110 | break; | |
19e6b90e L |
9111 | default: |
9112 | break; | |
9113 | } | |
9114 | } | |
9115 | start = tmp; | |
9116 | } | |
9117 | ||
015dc7e1 | 9118 | all_nops = true; |
5b6312fd | 9119 | |
19e6b90e L |
9120 | /* Now we know what registers are used, make a second pass over |
9121 | the chunk, this time actually printing out the info. */ | |
9122 | ||
9123 | while (start < block_end) | |
9124 | { | |
362beea4 | 9125 | unsigned char * tmp; |
19e6b90e | 9126 | unsigned op, opa; |
7f2c8a1d NC |
9127 | unsigned long ul, roffs; |
9128 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
9129 | are various functions, notably frame_space_needed() that assume that | |
9130 | reg is an unsigned int. */ | |
9131 | unsigned int reg; | |
9132 | dwarf_signed_vma l; | |
bf5117e3 | 9133 | dwarf_vma ofs; |
19e6b90e | 9134 | dwarf_vma vma; |
665ce1f6 | 9135 | const char *reg_prefix = ""; |
19e6b90e L |
9136 | |
9137 | op = *start++; | |
9138 | opa = op & 0x3f; | |
9139 | if (op & 0xc0) | |
9140 | op &= 0xc0; | |
9141 | ||
5b6312fd NC |
9142 | /* Make a note if something other than DW_CFA_nop happens. */ |
9143 | if (op != DW_CFA_nop) | |
015dc7e1 | 9144 | all_nops = false; |
5b6312fd | 9145 | |
19e6b90e L |
9146 | /* Warning: if you add any more cases to this switch, be |
9147 | sure to add them to the corresponding switch above. */ | |
9148 | switch (op) | |
9149 | { | |
9150 | case DW_CFA_advance_loc: | |
9151 | if (do_debug_frames_interp) | |
9152 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9153 | else | |
bf5117e3 | 9154 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 9155 | opa * fc->code_factor, |
b4eb7656 | 9156 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
9157 | fc->pc_begin + opa * fc->code_factor, |
9158 | fc->ptr_size)); | |
19e6b90e L |
9159 | fc->pc_begin += opa * fc->code_factor; |
9160 | break; | |
9161 | ||
9162 | case DW_CFA_offset: | |
cd30bcef | 9163 | READ_ULEB (roffs, start, end); |
665ce1f6 L |
9164 | if (opa >= (unsigned int) fc->ncols) |
9165 | reg_prefix = bad_reg; | |
9166 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9167 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
9168 | reg_prefix, regname (opa, 0), | |
9169 | roffs * fc->data_factor); | |
9170 | if (*reg_prefix == '\0') | |
9171 | { | |
9172 | fc->col_type[opa] = DW_CFA_offset; | |
9173 | fc->col_offset[opa] = roffs * fc->data_factor; | |
9174 | } | |
19e6b90e L |
9175 | break; |
9176 | ||
9177 | case DW_CFA_restore: | |
50751e18 | 9178 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
9179 | reg_prefix = bad_reg; |
9180 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9181 | printf (" DW_CFA_restore: %s%s\n", | |
9182 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
9183 | if (*reg_prefix != '\0') |
9184 | break; | |
9185 | ||
9186 | if (opa >= (unsigned int) cie->ncols | |
9187 | || (do_debug_frames_interp | |
9188 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
9189 | { | |
9190 | fc->col_type[opa] = DW_CFA_undefined; | |
9191 | fc->col_offset[opa] = 0; | |
9192 | } | |
9193 | else | |
665ce1f6 L |
9194 | { |
9195 | fc->col_type[opa] = cie->col_type[opa]; | |
9196 | fc->col_offset[opa] = cie->col_offset[opa]; | |
9197 | } | |
19e6b90e L |
9198 | break; |
9199 | ||
9200 | case DW_CFA_set_loc: | |
6937bb54 | 9201 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
9202 | if (do_debug_frames_interp) |
9203 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9204 | else | |
bf5117e3 NC |
9205 | printf (" DW_CFA_set_loc: %s\n", |
9206 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
9207 | fc->pc_begin = vma; |
9208 | break; | |
9209 | ||
9210 | case DW_CFA_advance_loc1: | |
0c588247 | 9211 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
9212 | if (do_debug_frames_interp) |
9213 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9214 | else | |
bf5117e3 NC |
9215 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
9216 | (unsigned long) (ofs * fc->code_factor), | |
9217 | dwarf_vmatoa_1 (NULL, | |
9218 | fc->pc_begin + ofs * fc->code_factor, | |
9219 | fc->ptr_size)); | |
19e6b90e L |
9220 | fc->pc_begin += ofs * fc->code_factor; |
9221 | break; | |
9222 | ||
9223 | case DW_CFA_advance_loc2: | |
6937bb54 | 9224 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
9225 | if (do_debug_frames_interp) |
9226 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9227 | else | |
bf5117e3 NC |
9228 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
9229 | (unsigned long) (ofs * fc->code_factor), | |
9230 | dwarf_vmatoa_1 (NULL, | |
9231 | fc->pc_begin + ofs * fc->code_factor, | |
9232 | fc->ptr_size)); | |
19e6b90e L |
9233 | fc->pc_begin += ofs * fc->code_factor; |
9234 | break; | |
9235 | ||
9236 | case DW_CFA_advance_loc4: | |
6937bb54 | 9237 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
9238 | if (do_debug_frames_interp) |
9239 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9240 | else | |
bf5117e3 NC |
9241 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
9242 | (unsigned long) (ofs * fc->code_factor), | |
9243 | dwarf_vmatoa_1 (NULL, | |
9244 | fc->pc_begin + ofs * fc->code_factor, | |
9245 | fc->ptr_size)); | |
19e6b90e L |
9246 | fc->pc_begin += ofs * fc->code_factor; |
9247 | break; | |
9248 | ||
9249 | case DW_CFA_offset_extended: | |
cd30bcef AM |
9250 | READ_ULEB (reg, start, end); |
9251 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
9252 | if (reg >= (unsigned int) fc->ncols) |
9253 | reg_prefix = bad_reg; | |
9254 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9255 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
9256 | reg_prefix, regname (reg, 0), | |
9257 | roffs * fc->data_factor); | |
9258 | if (*reg_prefix == '\0') | |
9259 | { | |
9260 | fc->col_type[reg] = DW_CFA_offset; | |
9261 | fc->col_offset[reg] = roffs * fc->data_factor; | |
9262 | } | |
19e6b90e L |
9263 | break; |
9264 | ||
12eae2d3 | 9265 | case DW_CFA_val_offset: |
cd30bcef AM |
9266 | READ_ULEB (reg, start, end); |
9267 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
9268 | if (reg >= (unsigned int) fc->ncols) |
9269 | reg_prefix = bad_reg; | |
9270 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 9271 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
9272 | reg_prefix, regname (reg, 0), |
9273 | roffs * fc->data_factor); | |
9274 | if (*reg_prefix == '\0') | |
9275 | { | |
9276 | fc->col_type[reg] = DW_CFA_val_offset; | |
9277 | fc->col_offset[reg] = roffs * fc->data_factor; | |
9278 | } | |
12eae2d3 JJ |
9279 | break; |
9280 | ||
19e6b90e | 9281 | case DW_CFA_restore_extended: |
cd30bcef | 9282 | READ_ULEB (reg, start, end); |
50751e18 | 9283 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
9284 | reg_prefix = bad_reg; |
9285 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9286 | printf (" DW_CFA_restore_extended: %s%s\n", | |
9287 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
9288 | if (*reg_prefix != '\0') |
9289 | break; | |
9290 | ||
9291 | if (reg >= (unsigned int) cie->ncols) | |
9292 | { | |
9293 | fc->col_type[reg] = DW_CFA_undefined; | |
9294 | fc->col_offset[reg] = 0; | |
9295 | } | |
9296 | else | |
665ce1f6 L |
9297 | { |
9298 | fc->col_type[reg] = cie->col_type[reg]; | |
9299 | fc->col_offset[reg] = cie->col_offset[reg]; | |
9300 | } | |
19e6b90e L |
9301 | break; |
9302 | ||
9303 | case DW_CFA_undefined: | |
cd30bcef | 9304 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9305 | if (reg >= (unsigned int) fc->ncols) |
9306 | reg_prefix = bad_reg; | |
9307 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9308 | printf (" DW_CFA_undefined: %s%s\n", | |
9309 | reg_prefix, regname (reg, 0)); | |
9310 | if (*reg_prefix == '\0') | |
9311 | { | |
9312 | fc->col_type[reg] = DW_CFA_undefined; | |
9313 | fc->col_offset[reg] = 0; | |
9314 | } | |
19e6b90e L |
9315 | break; |
9316 | ||
9317 | case DW_CFA_same_value: | |
cd30bcef | 9318 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9319 | if (reg >= (unsigned int) fc->ncols) |
9320 | reg_prefix = bad_reg; | |
9321 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9322 | printf (" DW_CFA_same_value: %s%s\n", | |
9323 | reg_prefix, regname (reg, 0)); | |
9324 | if (*reg_prefix == '\0') | |
9325 | { | |
9326 | fc->col_type[reg] = DW_CFA_same_value; | |
9327 | fc->col_offset[reg] = 0; | |
9328 | } | |
19e6b90e L |
9329 | break; |
9330 | ||
9331 | case DW_CFA_register: | |
cd30bcef AM |
9332 | READ_ULEB (reg, start, end); |
9333 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
9334 | if (reg >= (unsigned int) fc->ncols) |
9335 | reg_prefix = bad_reg; | |
9336 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 9337 | { |
665ce1f6 L |
9338 | printf (" DW_CFA_register: %s%s in ", |
9339 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
9340 | puts (regname (roffs, 0)); |
9341 | } | |
665ce1f6 L |
9342 | if (*reg_prefix == '\0') |
9343 | { | |
9344 | fc->col_type[reg] = DW_CFA_register; | |
9345 | fc->col_offset[reg] = roffs; | |
9346 | } | |
19e6b90e L |
9347 | break; |
9348 | ||
9349 | case DW_CFA_remember_state: | |
9350 | if (! do_debug_frames_interp) | |
9351 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 9352 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 9353 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
9354 | rs->cfa_reg = fc->cfa_reg; |
9355 | rs->ra = fc->ra; | |
9356 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 9357 | rs->ncols = fc->ncols; |
3f5e193b | 9358 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 9359 | sizeof (* rs->col_type)); |
d71ad7fc RC |
9360 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
9361 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
9362 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
9363 | rs->next = remembered_state; |
9364 | remembered_state = rs; | |
9365 | break; | |
9366 | ||
9367 | case DW_CFA_restore_state: | |
9368 | if (! do_debug_frames_interp) | |
9369 | printf (" DW_CFA_restore_state\n"); | |
9370 | rs = remembered_state; | |
9371 | if (rs) | |
9372 | { | |
9373 | remembered_state = rs->next; | |
d71ad7fc RC |
9374 | fc->cfa_offset = rs->cfa_offset; |
9375 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
9376 | fc->ra = rs->ra; |
9377 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
9378 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
9379 | { | |
1306a742 | 9380 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
9381 | fc->ncols = 0; |
9382 | break; | |
9383 | } | |
d71ad7fc | 9384 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 9385 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 9386 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
9387 | free (rs->col_type); |
9388 | free (rs->col_offset); | |
9389 | free (rs); | |
9390 | } | |
9391 | else if (do_debug_frames_interp) | |
9392 | printf ("Mismatched DW_CFA_restore_state\n"); | |
9393 | break; | |
9394 | ||
9395 | case DW_CFA_def_cfa: | |
cd30bcef AM |
9396 | READ_ULEB (fc->cfa_reg, start, end); |
9397 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
9398 | fc->cfa_exp = 0; |
9399 | if (! do_debug_frames_interp) | |
2dc4cec1 | 9400 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 9401 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
9402 | break; |
9403 | ||
9404 | case DW_CFA_def_cfa_register: | |
cd30bcef | 9405 | READ_ULEB (fc->cfa_reg, start, end); |
19e6b90e L |
9406 | fc->cfa_exp = 0; |
9407 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
9408 | printf (" DW_CFA_def_cfa_register: %s\n", |
9409 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
9410 | break; |
9411 | ||
9412 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 9413 | READ_ULEB (fc->cfa_offset, start, end); |
19e6b90e | 9414 | if (! do_debug_frames_interp) |
c8071705 | 9415 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
9416 | break; |
9417 | ||
9418 | case DW_CFA_nop: | |
9419 | if (! do_debug_frames_interp) | |
9420 | printf (" DW_CFA_nop\n"); | |
9421 | break; | |
9422 | ||
9423 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 9424 | READ_ULEB (ul, start, end); |
7460c0ab | 9425 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 9426 | { |
a1165289 | 9427 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
9428 | break; |
9429 | } | |
19e6b90e L |
9430 | if (! do_debug_frames_interp) |
9431 | { | |
9432 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
9433 | decode_location_expression (start, eh_addr_size, 0, -1, |
9434 | ul, 0, section); | |
19e6b90e L |
9435 | printf (")\n"); |
9436 | } | |
9437 | fc->cfa_exp = 1; | |
9438 | start += ul; | |
9439 | break; | |
9440 | ||
9441 | case DW_CFA_expression: | |
cd30bcef AM |
9442 | READ_ULEB (reg, start, end); |
9443 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
9444 | if (reg >= (unsigned int) fc->ncols) |
9445 | reg_prefix = bad_reg; | |
6937bb54 | 9446 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 9447 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
9448 | tmp = start + ul; |
9449 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 9450 | { |
a1165289 | 9451 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
9452 | break; |
9453 | } | |
665ce1f6 | 9454 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 9455 | { |
665ce1f6 L |
9456 | printf (" DW_CFA_expression: %s%s (", |
9457 | reg_prefix, regname (reg, 0)); | |
b7807392 | 9458 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 9459 | ul, 0, section); |
19e6b90e L |
9460 | printf (")\n"); |
9461 | } | |
665ce1f6 L |
9462 | if (*reg_prefix == '\0') |
9463 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 9464 | start = tmp; |
19e6b90e L |
9465 | break; |
9466 | ||
12eae2d3 | 9467 | case DW_CFA_val_expression: |
cd30bcef AM |
9468 | READ_ULEB (reg, start, end); |
9469 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
9470 | if (reg >= (unsigned int) fc->ncols) |
9471 | reg_prefix = bad_reg; | |
362beea4 NC |
9472 | tmp = start + ul; |
9473 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 9474 | { |
a1165289 | 9475 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
9476 | break; |
9477 | } | |
665ce1f6 | 9478 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 9479 | { |
665ce1f6 L |
9480 | printf (" DW_CFA_val_expression: %s%s (", |
9481 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
9482 | decode_location_expression (start, eh_addr_size, 0, -1, |
9483 | ul, 0, section); | |
12eae2d3 JJ |
9484 | printf (")\n"); |
9485 | } | |
665ce1f6 L |
9486 | if (*reg_prefix == '\0') |
9487 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 9488 | start = tmp; |
12eae2d3 JJ |
9489 | break; |
9490 | ||
19e6b90e | 9491 | case DW_CFA_offset_extended_sf: |
cd30bcef AM |
9492 | READ_ULEB (reg, start, end); |
9493 | READ_SLEB (l, start, end); | |
665ce1f6 L |
9494 | if (frame_need_space (fc, reg) < 0) |
9495 | reg_prefix = bad_reg; | |
9496 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9497 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
9498 | reg_prefix, regname (reg, 0), | |
c8071705 | 9499 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9500 | if (*reg_prefix == '\0') |
9501 | { | |
9502 | fc->col_type[reg] = DW_CFA_offset; | |
9503 | fc->col_offset[reg] = l * fc->data_factor; | |
9504 | } | |
19e6b90e L |
9505 | break; |
9506 | ||
12eae2d3 | 9507 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
9508 | READ_ULEB (reg, start, end); |
9509 | READ_SLEB (l, start, end); | |
665ce1f6 L |
9510 | if (frame_need_space (fc, reg) < 0) |
9511 | reg_prefix = bad_reg; | |
9512 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 9513 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 9514 | reg_prefix, regname (reg, 0), |
c8071705 | 9515 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9516 | if (*reg_prefix == '\0') |
9517 | { | |
9518 | fc->col_type[reg] = DW_CFA_val_offset; | |
9519 | fc->col_offset[reg] = l * fc->data_factor; | |
9520 | } | |
12eae2d3 JJ |
9521 | break; |
9522 | ||
19e6b90e | 9523 | case DW_CFA_def_cfa_sf: |
cd30bcef AM |
9524 | READ_ULEB (fc->cfa_reg, start, end); |
9525 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
9526 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
9527 | fc->cfa_exp = 0; | |
9528 | if (! do_debug_frames_interp) | |
2dc4cec1 | 9529 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 9530 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
9531 | break; |
9532 | ||
9533 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 9534 | READ_ULEB (fc->cfa_offset, start, end); |
c8071705 | 9535 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 9536 | if (! do_debug_frames_interp) |
c8071705 | 9537 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
9538 | break; |
9539 | ||
9540 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 9541 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
9542 | if (do_debug_frames_interp) |
9543 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9544 | else | |
bf5117e3 NC |
9545 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
9546 | (unsigned long) (ofs * fc->code_factor), | |
9547 | dwarf_vmatoa_1 (NULL, | |
9548 | fc->pc_begin + ofs * fc->code_factor, | |
9549 | fc->ptr_size)); | |
19e6b90e L |
9550 | fc->pc_begin += ofs * fc->code_factor; |
9551 | break; | |
9552 | ||
9553 | case DW_CFA_GNU_window_save: | |
9554 | if (! do_debug_frames_interp) | |
9555 | printf (" DW_CFA_GNU_window_save\n"); | |
9556 | break; | |
9557 | ||
9558 | case DW_CFA_GNU_args_size: | |
cd30bcef | 9559 | READ_ULEB (ul, start, end); |
19e6b90e L |
9560 | if (! do_debug_frames_interp) |
9561 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
9562 | break; | |
9563 | ||
9564 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
9565 | READ_ULEB (reg, start, end); |
9566 | READ_SLEB (l, start, end); | |
7f2c8a1d | 9567 | l = - l; |
665ce1f6 L |
9568 | if (frame_need_space (fc, reg) < 0) |
9569 | reg_prefix = bad_reg; | |
9570 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9571 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
9572 | reg_prefix, regname (reg, 0), | |
c8071705 | 9573 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9574 | if (*reg_prefix == '\0') |
9575 | { | |
9576 | fc->col_type[reg] = DW_CFA_offset; | |
9577 | fc->col_offset[reg] = l * fc->data_factor; | |
9578 | } | |
19e6b90e L |
9579 | break; |
9580 | ||
9581 | default: | |
53b8873b NC |
9582 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
9583 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
9584 | else | |
f41e4712 | 9585 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
9586 | start = block_end; |
9587 | } | |
9588 | } | |
9589 | ||
5b6312fd NC |
9590 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
9591 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
9592 | frame_display_row (fc, &need_col_headers, &max_regs); |
9593 | ||
a788aedd AM |
9594 | if (fde_fc.col_type != NULL) |
9595 | { | |
9596 | free (fde_fc.col_type); | |
9597 | fde_fc.col_type = NULL; | |
9598 | } | |
9599 | if (fde_fc.col_offset != NULL) | |
9600 | { | |
9601 | free (fde_fc.col_offset); | |
9602 | fde_fc.col_offset = NULL; | |
9603 | } | |
9604 | ||
19e6b90e | 9605 | start = block_end; |
604282a7 | 9606 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
9607 | } |
9608 | ||
9609 | printf ("\n"); | |
9610 | ||
3391569f NC |
9611 | while (remembered_state != NULL) |
9612 | { | |
9613 | rs = remembered_state; | |
9614 | remembered_state = rs->next; | |
9615 | free (rs->col_type); | |
9616 | free (rs->col_offset); | |
9617 | rs->next = NULL; /* Paranoia. */ | |
9618 | free (rs); | |
9619 | } | |
9620 | ||
9621 | while (chunks != NULL) | |
9622 | { | |
9623 | rs = chunks; | |
9624 | chunks = rs->next; | |
9625 | free (rs->col_type); | |
9626 | free (rs->col_offset); | |
9627 | rs->next = NULL; /* Paranoia. */ | |
9628 | free (rs); | |
9629 | } | |
9630 | ||
9631 | while (forward_refs != NULL) | |
9632 | { | |
9633 | rs = forward_refs; | |
9634 | forward_refs = rs->next; | |
9635 | free (rs->col_type); | |
9636 | free (rs->col_offset); | |
9637 | rs->next = NULL; /* Paranoia. */ | |
9638 | free (rs); | |
9639 | } | |
9640 | ||
19e6b90e L |
9641 | return 1; |
9642 | } | |
9643 | ||
9644 | #undef GET | |
19e6b90e | 9645 | |
61364358 JK |
9646 | static int |
9647 | display_debug_names (struct dwarf_section *section, void *file) | |
9648 | { | |
9649 | unsigned char *hdrptr = section->start; | |
9650 | dwarf_vma unit_length; | |
9651 | unsigned char *unit_start; | |
9652 | const unsigned char *const section_end = section->start + section->size; | |
9653 | unsigned char *unit_end; | |
9654 | ||
015dc7e1 | 9655 | introduce (section, false); |
61364358 | 9656 | |
dda8d76d | 9657 | load_debug_section_with_follow (str, file); |
61364358 JK |
9658 | |
9659 | for (; hdrptr < section_end; hdrptr = unit_end) | |
9660 | { | |
9661 | unsigned int offset_size; | |
9662 | uint16_t dwarf_version, padding; | |
9663 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
9664 | uint32_t bucket_count, name_count, abbrev_table_size; | |
9665 | uint32_t augmentation_string_size; | |
9666 | unsigned int i; | |
e98fdf1a | 9667 | unsigned long sec_off; |
015dc7e1 | 9668 | bool augmentation_printable; |
48467cb9 | 9669 | const char *augmentation_string; |
61364358 JK |
9670 | |
9671 | unit_start = hdrptr; | |
9672 | ||
9673 | /* Get and check the length of the block. */ | |
9674 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
9675 | ||
9676 | if (unit_length == 0xffffffff) | |
9677 | { | |
9678 | /* This section is 64-bit DWARF. */ | |
9679 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
9680 | offset_size = 8; | |
9681 | } | |
9682 | else | |
9683 | offset_size = 4; | |
9684 | unit_end = hdrptr + unit_length; | |
9685 | ||
e98fdf1a AM |
9686 | sec_off = hdrptr - section->start; |
9687 | if (sec_off + unit_length < sec_off | |
9688 | || sec_off + unit_length > section->size) | |
61364358 | 9689 | { |
e98fdf1a AM |
9690 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
9691 | section->name, | |
9692 | (unsigned long) (unit_start - section->start), | |
9693 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
9694 | return 0; |
9695 | } | |
9696 | ||
9697 | /* Get and check the version number. */ | |
9698 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
9699 | printf (_("Version %ld\n"), (long) dwarf_version); | |
9700 | ||
9701 | /* Prior versions did not exist, and future versions may not be | |
9702 | backwards compatible. */ | |
9703 | if (dwarf_version != 5) | |
9704 | { | |
9705 | warn (_("Only DWARF version 5 .debug_names " | |
9706 | "is currently supported.\n")); | |
9707 | return 0; | |
9708 | } | |
9709 | ||
9710 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
9711 | if (padding != 0) | |
9712 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
9713 | padding); | |
9714 | ||
9715 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
9716 | if (comp_unit_count == 0) | |
9717 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
9718 | ||
9719 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
9720 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
9721 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
9722 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
9723 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
9724 | ||
9725 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
9726 | if (augmentation_string_size % 4 != 0) | |
9727 | { | |
9728 | warn (_("Augmentation string length %u must be rounded up " | |
9729 | "to a multiple of 4 in .debug_names.\n"), | |
9730 | augmentation_string_size); | |
9731 | augmentation_string_size += (-augmentation_string_size) & 3; | |
9732 | } | |
48467cb9 | 9733 | |
61364358 | 9734 | printf (_("Augmentation string:")); |
48467cb9 | 9735 | |
015dc7e1 | 9736 | augmentation_printable = true; |
48467cb9 TV |
9737 | augmentation_string = (const char *) hdrptr; |
9738 | ||
61364358 JK |
9739 | for (i = 0; i < augmentation_string_size; i++) |
9740 | { | |
9741 | unsigned char uc; | |
9742 | ||
9743 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
9744 | printf (" %02x", uc); | |
48467cb9 TV |
9745 | |
9746 | if (uc != 0 && !ISPRINT (uc)) | |
015dc7e1 | 9747 | augmentation_printable = false; |
48467cb9 TV |
9748 | } |
9749 | ||
9750 | if (augmentation_printable) | |
9751 | { | |
9752 | printf (" (\""); | |
9753 | for (i = 0; | |
9754 | i < augmentation_string_size && augmentation_string[i]; | |
9755 | ++i) | |
9756 | putchar (augmentation_string[i]); | |
9757 | printf ("\")"); | |
61364358 | 9758 | } |
61364358 JK |
9759 | putchar ('\n'); |
9760 | ||
9761 | printf (_("CU table:\n")); | |
9762 | for (i = 0; i < comp_unit_count; i++) | |
9763 | { | |
9764 | uint64_t cu_offset; | |
9765 | ||
9766 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
9767 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
9768 | } | |
9769 | putchar ('\n'); | |
9770 | ||
9771 | printf (_("TU table:\n")); | |
9772 | for (i = 0; i < local_type_unit_count; i++) | |
9773 | { | |
9774 | uint64_t tu_offset; | |
9775 | ||
9776 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
9777 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
9778 | } | |
9779 | putchar ('\n'); | |
9780 | ||
9781 | printf (_("Foreign TU table:\n")); | |
9782 | for (i = 0; i < foreign_type_unit_count; i++) | |
9783 | { | |
9784 | uint64_t signature; | |
9785 | ||
9786 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
9787 | printf (_("[%3u] "), i); | |
9788 | print_dwarf_vma (signature, 8); | |
9789 | putchar ('\n'); | |
9790 | } | |
9791 | putchar ('\n'); | |
9792 | ||
9793 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
9794 | hdrptr += bucket_count * sizeof (uint32_t); | |
9795 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
9796 | hdrptr += name_count * sizeof (uint32_t); | |
9797 | unsigned char *const name_table_string_offsets = hdrptr; | |
9798 | hdrptr += name_count * offset_size; | |
9799 | unsigned char *const name_table_entry_offsets = hdrptr; | |
9800 | hdrptr += name_count * offset_size; | |
9801 | unsigned char *const abbrev_table = hdrptr; | |
9802 | hdrptr += abbrev_table_size; | |
9803 | const unsigned char *const abbrev_table_end = hdrptr; | |
9804 | unsigned char *const entry_pool = hdrptr; | |
9805 | if (hdrptr > unit_end) | |
9806 | { | |
9807 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
9808 | "for unit 0x%lx in the debug_names\n"), | |
9809 | (long) (hdrptr - section->start), | |
9810 | (long) (unit_end - section->start), | |
9811 | (long) (unit_start - section->start)); | |
9812 | return 0; | |
9813 | } | |
9814 | ||
9815 | size_t buckets_filled = 0; | |
9816 | size_t bucketi; | |
9817 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
9818 | { | |
9819 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
9820 | ||
9821 | if (bucket != 0) | |
9822 | ++buckets_filled; | |
9823 | } | |
d3a49aa8 AM |
9824 | printf (ngettext ("Used %zu of %lu bucket.\n", |
9825 | "Used %zu of %lu buckets.\n", | |
9826 | bucket_count), | |
9827 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 9828 | |
0a79bef4 | 9829 | uint32_t hash_prev = 0; |
61364358 JK |
9830 | size_t hash_clash_count = 0; |
9831 | size_t longest_clash = 0; | |
9832 | size_t this_length = 0; | |
9833 | size_t hashi; | |
9834 | for (hashi = 0; hashi < name_count; hashi++) | |
9835 | { | |
9836 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
9837 | ||
9838 | if (hashi > 0) | |
9839 | { | |
9840 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
9841 | { | |
9842 | ++hash_clash_count; | |
9843 | ++this_length; | |
9844 | longest_clash = MAX (longest_clash, this_length); | |
9845 | } | |
9846 | else | |
9847 | this_length = 0; | |
9848 | } | |
9849 | hash_prev = hash_this; | |
9850 | } | |
9851 | printf (_("Out of %lu items there are %zu bucket clashes" | |
9852 | " (longest of %zu entries).\n"), | |
9853 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
9854 | assert (name_count == buckets_filled + hash_clash_count); | |
9855 | ||
9856 | struct abbrev_lookup_entry | |
9857 | { | |
9858 | dwarf_vma abbrev_tag; | |
9859 | unsigned char *abbrev_lookup_ptr; | |
9860 | }; | |
9861 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
9862 | size_t abbrev_lookup_used = 0; | |
9863 | size_t abbrev_lookup_allocated = 0; | |
9864 | ||
9865 | unsigned char *abbrevptr = abbrev_table; | |
9866 | for (;;) | |
9867 | { | |
cd30bcef AM |
9868 | dwarf_vma abbrev_tag; |
9869 | ||
9870 | READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end); | |
61364358 JK |
9871 | if (abbrev_tag == 0) |
9872 | break; | |
9873 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
9874 | { | |
9875 | abbrev_lookup_allocated = MAX (0x100, | |
9876 | abbrev_lookup_allocated * 2); | |
9877 | abbrev_lookup = xrealloc (abbrev_lookup, | |
9878 | (abbrev_lookup_allocated | |
9879 | * sizeof (*abbrev_lookup))); | |
9880 | } | |
9881 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
9882 | struct abbrev_lookup_entry *entry; | |
9883 | for (entry = abbrev_lookup; | |
9884 | entry < abbrev_lookup + abbrev_lookup_used; | |
9885 | entry++) | |
9886 | if (entry->abbrev_tag == abbrev_tag) | |
9887 | { | |
9888 | warn (_("Duplicate abbreviation tag %lu " | |
9889 | "in unit 0x%lx in the debug_names\n"), | |
9890 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
9891 | break; | |
9892 | } | |
9893 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
9894 | entry->abbrev_tag = abbrev_tag; | |
9895 | entry->abbrev_lookup_ptr = abbrevptr; | |
9896 | ||
9897 | /* Skip DWARF tag. */ | |
cd30bcef | 9898 | SKIP_ULEB (abbrevptr, abbrev_table_end); |
61364358 JK |
9899 | for (;;) |
9900 | { | |
cd30bcef AM |
9901 | dwarf_vma xindex, form; |
9902 | ||
9903 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9904 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9905 | if (xindex == 0 && form == 0) |
61364358 JK |
9906 | break; |
9907 | } | |
9908 | } | |
9909 | ||
9910 | printf (_("\nSymbol table:\n")); | |
9911 | uint32_t namei; | |
9912 | for (namei = 0; namei < name_count; ++namei) | |
9913 | { | |
9914 | uint64_t string_offset, entry_offset; | |
9915 | ||
9916 | SAFE_BYTE_GET (string_offset, | |
9917 | name_table_string_offsets + namei * offset_size, | |
9918 | offset_size, unit_end); | |
9919 | SAFE_BYTE_GET (entry_offset, | |
9920 | name_table_entry_offsets + namei * offset_size, | |
9921 | offset_size, unit_end); | |
9922 | ||
9923 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
9924 | fetch_indirect_string (string_offset)); | |
9925 | ||
9926 | unsigned char *entryptr = entry_pool + entry_offset; | |
9927 | ||
279edac5 AM |
9928 | /* We need to scan first whether there is a single or multiple |
9929 | entries. TAGNO is -2 for the first entry, it is -1 for the | |
9930 | initial tag read of the second entry, then it becomes 0 for the | |
9931 | first entry for real printing etc. */ | |
61364358 JK |
9932 | int tagno = -2; |
9933 | /* Initialize it due to a false compiler warning. */ | |
9934 | dwarf_vma second_abbrev_tag = -1; | |
9935 | for (;;) | |
9936 | { | |
cd30bcef AM |
9937 | dwarf_vma abbrev_tag; |
9938 | dwarf_vma dwarf_tag; | |
9939 | const struct abbrev_lookup_entry *entry; | |
9940 | ||
9941 | READ_ULEB (abbrev_tag, entryptr, unit_end); | |
61364358 JK |
9942 | if (tagno == -1) |
9943 | { | |
9944 | second_abbrev_tag = abbrev_tag; | |
9945 | tagno = 0; | |
9946 | entryptr = entry_pool + entry_offset; | |
9947 | continue; | |
9948 | } | |
9949 | if (abbrev_tag == 0) | |
9950 | break; | |
9951 | if (tagno >= 0) | |
9952 | printf ("%s<%lu>", | |
9953 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
9954 | (unsigned long) abbrev_tag); | |
9955 | ||
61364358 JK |
9956 | for (entry = abbrev_lookup; |
9957 | entry < abbrev_lookup + abbrev_lookup_used; | |
9958 | entry++) | |
9959 | if (entry->abbrev_tag == abbrev_tag) | |
9960 | break; | |
9961 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
9962 | { | |
9963 | warn (_("Undefined abbreviation tag %lu " | |
9964 | "in unit 0x%lx in the debug_names\n"), | |
9965 | (long) abbrev_tag, | |
9966 | (long) (unit_start - section->start)); | |
9967 | break; | |
9968 | } | |
9969 | abbrevptr = entry->abbrev_lookup_ptr; | |
cd30bcef | 9970 | READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end); |
61364358 JK |
9971 | if (tagno >= 0) |
9972 | printf (" %s", get_TAG_name (dwarf_tag)); | |
9973 | for (;;) | |
9974 | { | |
cd30bcef AM |
9975 | dwarf_vma xindex, form; |
9976 | ||
9977 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9978 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9979 | if (xindex == 0 && form == 0) |
61364358 JK |
9980 | break; |
9981 | ||
9982 | if (tagno >= 0) | |
1d827a72 | 9983 | printf (" %s", get_IDX_name (xindex)); |
ec1b0fbb NC |
9984 | entryptr = read_and_display_attr_value (0, form, 0, |
9985 | unit_start, entryptr, unit_end, | |
9986 | 0, 0, offset_size, | |
61364358 JK |
9987 | dwarf_version, NULL, |
9988 | (tagno < 0), NULL, | |
ec1b0fbb | 9989 | NULL, '=', -1); |
61364358 JK |
9990 | } |
9991 | ++tagno; | |
9992 | } | |
9993 | if (tagno <= 0) | |
9994 | printf (_(" <no entries>")); | |
9995 | putchar ('\n'); | |
9996 | } | |
9997 | ||
9998 | free (abbrev_lookup); | |
9999 | } | |
10000 | ||
10001 | return 1; | |
10002 | } | |
10003 | ||
dda8d76d | 10004 | static int |
d85bf2ba NC |
10005 | display_debug_links (struct dwarf_section * section, |
10006 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
10007 | { |
10008 | const unsigned char * filename; | |
10009 | unsigned int filelen; | |
10010 | ||
015dc7e1 | 10011 | introduce (section, false); |
dda8d76d NC |
10012 | |
10013 | /* The .gnu_debuglink section is formatted as: | |
10014 | (c-string) Filename. | |
10015 | (padding) If needed to reach a 4 byte boundary. | |
10016 | (uint32_t) CRC32 value. | |
10017 | ||
10018 | The .gun_debugaltlink section is formatted as: | |
10019 | (c-string) Filename. | |
10020 | (binary) Build-ID. */ | |
521d4b19 | 10021 | |
dda8d76d NC |
10022 | filename = section->start; |
10023 | filelen = strnlen ((const char *) filename, section->size); | |
10024 | if (filelen == section->size) | |
10025 | { | |
10026 | warn (_("The debuglink filename is corrupt/missing\n")); | |
10027 | return 0; | |
10028 | } | |
10029 | ||
10030 | printf (_(" Separate debug info file: %s\n"), filename); | |
10031 | ||
24d127aa | 10032 | if (startswith (section->name, ".gnu_debuglink")) |
dda8d76d NC |
10033 | { |
10034 | unsigned int crc32; | |
10035 | unsigned int crc_offset; | |
10036 | ||
10037 | crc_offset = filelen + 1; | |
10038 | crc_offset = (crc_offset + 3) & ~3; | |
10039 | if (crc_offset + 4 > section->size) | |
10040 | { | |
10041 | warn (_("CRC offset missing/truncated\n")); | |
10042 | return 0; | |
10043 | } | |
10044 | ||
10045 | crc32 = byte_get (filename + crc_offset, 4); | |
10046 | ||
10047 | printf (_(" CRC value: %#x\n"), crc32); | |
10048 | ||
10049 | if (crc_offset + 4 < section->size) | |
10050 | { | |
10051 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
10052 | (long)(section->size - (crc_offset + 4))); | |
10053 | return 0; | |
10054 | } | |
10055 | } | |
24d127aa | 10056 | else /* startswith (section->name, ".gnu_debugaltlink") */ |
dda8d76d NC |
10057 | { |
10058 | const unsigned char * build_id = section->start + filelen + 1; | |
10059 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
10060 | bfd_size_type printed; | |
10061 | ||
10062 | /* FIXME: Should we support smaller build-id notes ? */ | |
10063 | if (build_id_len < 0x14) | |
10064 | { | |
10065 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
10066 | return 0; | |
10067 | } | |
10068 | ||
10069 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 10070 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
10071 | putchar ('\n'); |
10072 | } | |
10073 | ||
10074 | putchar ('\n'); | |
10075 | return 1; | |
10076 | } | |
10077 | ||
5bbdf3d5 DE |
10078 | static int |
10079 | display_gdb_index (struct dwarf_section *section, | |
10080 | void *file ATTRIBUTE_UNUSED) | |
10081 | { | |
10082 | unsigned char *start = section->start; | |
10083 | uint32_t version; | |
10084 | uint32_t cu_list_offset, tu_list_offset; | |
10085 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
10086 | unsigned int cu_list_elements, tu_list_elements; | |
10087 | unsigned int address_table_size, symbol_table_slots; | |
10088 | unsigned char *cu_list, *tu_list; | |
10089 | unsigned char *address_table, *symbol_table, *constant_pool; | |
10090 | unsigned int i; | |
10091 | ||
10092 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
10093 | ||
015dc7e1 | 10094 | introduce (section, false); |
5bbdf3d5 DE |
10095 | |
10096 | if (section->size < 6 * sizeof (uint32_t)) | |
10097 | { | |
10098 | warn (_("Truncated header in the %s section.\n"), section->name); | |
10099 | return 0; | |
10100 | } | |
10101 | ||
10102 | version = byte_get_little_endian (start, 4); | |
da88a764 | 10103 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
10104 | |
10105 | /* Prior versions are obsolete, and future versions may not be | |
10106 | backwards compatible. */ | |
aa170720 | 10107 | if (version < 3 || version > 8) |
5bbdf3d5 | 10108 | { |
da88a764 | 10109 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
10110 | return 0; |
10111 | } | |
8d6eee87 TT |
10112 | if (version < 4) |
10113 | warn (_("The address table data in version 3 may be wrong.\n")); | |
10114 | if (version < 5) | |
10115 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
10116 | if (version < 6) | |
10117 | warn (_("Version 5 does not include inlined functions.\n")); | |
10118 | if (version < 7) | |
10119 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
10120 | /* Version 7 indices generated by Gold have bad type unit references, |
10121 | PR binutils/15021. But we don't know if the index was generated by | |
10122 | Gold or not, so to avoid worrying users with gdb-generated indices | |
10123 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
10124 | |
10125 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
10126 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
10127 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
10128 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
10129 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
10130 | ||
10131 | if (cu_list_offset > section->size | |
10132 | || tu_list_offset > section->size | |
10133 | || address_table_offset > section->size | |
10134 | || symbol_table_offset > section->size | |
10135 | || constant_pool_offset > section->size) | |
10136 | { | |
10137 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
10138 | return 0; | |
10139 | } | |
10140 | ||
53774b7e NC |
10141 | /* PR 17531: file: 418d0a8a. */ |
10142 | if (tu_list_offset < cu_list_offset) | |
10143 | { | |
10144 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
10145 | tu_list_offset, cu_list_offset); | |
10146 | return 0; | |
10147 | } | |
10148 | ||
5bbdf3d5 | 10149 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
10150 | |
10151 | if (address_table_offset < tu_list_offset) | |
10152 | { | |
10153 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
10154 | address_table_offset, tu_list_offset); | |
10155 | return 0; | |
10156 | } | |
10157 | ||
5bbdf3d5 | 10158 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
10159 | |
10160 | /* PR 17531: file: 18a47d3d. */ | |
10161 | if (symbol_table_offset < address_table_offset) | |
10162 | { | |
13bace4a | 10163 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
10164 | symbol_table_offset, address_table_offset); |
10165 | return 0; | |
10166 | } | |
10167 | ||
5bbdf3d5 | 10168 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
10169 | |
10170 | if (constant_pool_offset < symbol_table_offset) | |
10171 | { | |
10172 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
10173 | constant_pool_offset, symbol_table_offset); | |
10174 | return 0; | |
10175 | } | |
10176 | ||
5bbdf3d5 DE |
10177 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
10178 | ||
10179 | cu_list = start + cu_list_offset; | |
10180 | tu_list = start + tu_list_offset; | |
10181 | address_table = start + address_table_offset; | |
10182 | symbol_table = start + symbol_table_offset; | |
10183 | constant_pool = start + constant_pool_offset; | |
10184 | ||
28d909e5 | 10185 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 10186 | { |
1306a742 | 10187 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
10188 | return 0; |
10189 | } | |
b4eb7656 | 10190 | |
5bbdf3d5 DE |
10191 | printf (_("\nCU table:\n")); |
10192 | for (i = 0; i < cu_list_elements; i += 2) | |
10193 | { | |
10194 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
10195 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
10196 | ||
10197 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
10198 | (unsigned long) cu_offset, | |
10199 | (unsigned long) (cu_offset + cu_length - 1)); | |
10200 | } | |
10201 | ||
10202 | printf (_("\nTU table:\n")); | |
10203 | for (i = 0; i < tu_list_elements; i += 3) | |
10204 | { | |
10205 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
10206 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
10207 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
10208 | ||
10209 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
10210 | (unsigned long) tu_offset, | |
10211 | (unsigned long) type_offset); | |
10212 | print_dwarf_vma (signature, 8); | |
10213 | printf ("\n"); | |
10214 | } | |
10215 | ||
10216 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
10217 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
10218 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
10219 | { |
10220 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
10221 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
10222 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
10223 | ||
10224 | print_dwarf_vma (low, 8); | |
10225 | print_dwarf_vma (high, 8); | |
da88a764 | 10226 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
10227 | } |
10228 | ||
10229 | printf (_("\nSymbol table:\n")); | |
10230 | for (i = 0; i < symbol_table_slots; ++i) | |
10231 | { | |
10232 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
10233 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
10234 | uint32_t num_cus, cu; | |
10235 | ||
10236 | if (name_offset != 0 | |
10237 | || cu_vector_offset != 0) | |
10238 | { | |
10239 | unsigned int j; | |
362beea4 | 10240 | unsigned char * adr; |
5bbdf3d5 | 10241 | |
362beea4 | 10242 | adr = constant_pool + name_offset; |
53774b7e | 10243 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 10244 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
10245 | { |
10246 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
10247 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
10248 | name_offset, i); | |
10249 | } | |
10250 | else | |
acff9664 NC |
10251 | printf ("[%3u] %.*s:", i, |
10252 | (int) (section->size - (constant_pool_offset + name_offset)), | |
10253 | constant_pool + name_offset); | |
53774b7e | 10254 | |
362beea4 NC |
10255 | adr = constant_pool + cu_vector_offset; |
10256 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
10257 | { |
10258 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
10259 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
10260 | cu_vector_offset, i); | |
10261 | continue; | |
10262 | } | |
57028622 | 10263 | |
362beea4 | 10264 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 10265 | |
362beea4 | 10266 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 10267 | if (num_cus * 4 < num_cus |
362beea4 NC |
10268 | || adr >= section->start + section->size |
10269 | || adr < constant_pool) | |
53774b7e NC |
10270 | { |
10271 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 10272 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
10273 | num_cus, i); |
10274 | continue; | |
10275 | } | |
10276 | ||
8d6eee87 TT |
10277 | if (num_cus > 1) |
10278 | printf ("\n"); | |
f3853b34 | 10279 | |
5bbdf3d5 DE |
10280 | for (j = 0; j < num_cus; ++j) |
10281 | { | |
7c1cef97 | 10282 | int is_static; |
8d6eee87 TT |
10283 | gdb_index_symbol_kind kind; |
10284 | ||
5bbdf3d5 | 10285 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 10286 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
10287 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
10288 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 10289 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 10290 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
10291 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
10292 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 10293 | else |
8d6eee87 TT |
10294 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
10295 | ||
459d52c8 DE |
10296 | printf (" [%s, %s]", |
10297 | is_static ? _("static") : _("global"), | |
10298 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
10299 | if (num_cus > 1) |
10300 | printf ("\n"); | |
5bbdf3d5 | 10301 | } |
8d6eee87 TT |
10302 | if (num_cus <= 1) |
10303 | printf ("\n"); | |
5bbdf3d5 DE |
10304 | } |
10305 | } | |
10306 | ||
10307 | return 1; | |
10308 | } | |
10309 | ||
657d0d47 CC |
10310 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
10311 | ||
10312 | static void | |
10313 | prealloc_cu_tu_list (unsigned int nshndx) | |
10314 | { | |
10315 | if (shndx_pool == NULL) | |
10316 | { | |
10317 | shndx_pool_size = nshndx; | |
10318 | shndx_pool_used = 0; | |
10319 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
10320 | sizeof (unsigned int)); | |
10321 | } | |
10322 | else | |
10323 | { | |
10324 | shndx_pool_size = shndx_pool_used + nshndx; | |
10325 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
10326 | sizeof (unsigned int)); | |
10327 | } | |
10328 | } | |
10329 | ||
10330 | static void | |
10331 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
10332 | { | |
10333 | if (shndx_pool_used >= shndx_pool_size) | |
10334 | { | |
10335 | error (_("Internal error: out of space in the shndx pool.\n")); | |
10336 | return; | |
10337 | } | |
10338 | shndx_pool [shndx_pool_used++] = shndx; | |
10339 | } | |
10340 | ||
10341 | static void | |
10342 | end_cu_tu_entry (void) | |
10343 | { | |
10344 | if (shndx_pool_used >= shndx_pool_size) | |
10345 | { | |
10346 | error (_("Internal error: out of space in the shndx pool.\n")); | |
10347 | return; | |
10348 | } | |
10349 | shndx_pool [shndx_pool_used++] = 0; | |
10350 | } | |
10351 | ||
341f9135 CC |
10352 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
10353 | ||
10354 | static const char * | |
10355 | get_DW_SECT_short_name (unsigned int dw_sect) | |
10356 | { | |
10357 | static char buf[16]; | |
10358 | ||
10359 | switch (dw_sect) | |
10360 | { | |
10361 | case DW_SECT_INFO: | |
10362 | return "info"; | |
10363 | case DW_SECT_TYPES: | |
10364 | return "types"; | |
10365 | case DW_SECT_ABBREV: | |
10366 | return "abbrev"; | |
10367 | case DW_SECT_LINE: | |
10368 | return "line"; | |
10369 | case DW_SECT_LOC: | |
10370 | return "loc"; | |
10371 | case DW_SECT_STR_OFFSETS: | |
10372 | return "str_off"; | |
10373 | case DW_SECT_MACINFO: | |
10374 | return "macinfo"; | |
10375 | case DW_SECT_MACRO: | |
10376 | return "macro"; | |
10377 | default: | |
b4eb7656 | 10378 | break; |
341f9135 CC |
10379 | } |
10380 | ||
10381 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
10382 | return buf; | |
10383 | } | |
10384 | ||
10385 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
10386 | These sections are extensions for Fission. | |
10387 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
10388 | |
10389 | static int | |
10390 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
10391 | { | |
10392 | unsigned char *phdr = section->start; | |
10393 | unsigned char *limit = phdr + section->size; | |
10394 | unsigned char *phash; | |
10395 | unsigned char *pindex; | |
10396 | unsigned char *ppool; | |
10397 | unsigned int version; | |
341f9135 | 10398 | unsigned int ncols = 0; |
657d0d47 CC |
10399 | unsigned int nused; |
10400 | unsigned int nslots; | |
10401 | unsigned int i; | |
341f9135 CC |
10402 | unsigned int j; |
10403 | dwarf_vma signature_high; | |
10404 | dwarf_vma signature_low; | |
10405 | char buf[64]; | |
657d0d47 | 10406 | |
6937bb54 NC |
10407 | /* PR 17512: file: 002-168123-0.004. */ |
10408 | if (phdr == NULL) | |
10409 | { | |
10410 | warn (_("Section %s is empty\n"), section->name); | |
10411 | return 0; | |
10412 | } | |
10413 | /* PR 17512: file: 002-376-0.004. */ | |
10414 | if (section->size < 24) | |
10415 | { | |
72c61a0d | 10416 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
10417 | section->name); |
10418 | return 0; | |
10419 | } | |
10420 | ||
10421 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 10422 | if (version >= 2) |
6937bb54 NC |
10423 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
10424 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
10425 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
10426 | ||
657d0d47 | 10427 | phash = phdr + 16; |
8e2e3c6c AM |
10428 | pindex = phash + (size_t) nslots * 8; |
10429 | ppool = pindex + (size_t) nslots * 4; | |
57028622 | 10430 | |
657d0d47 CC |
10431 | if (do_display) |
10432 | { | |
015dc7e1 | 10433 | introduce (section, false); |
dda8d76d | 10434 | |
8e2e3c6c | 10435 | printf (_(" Version: %u\n"), version); |
341f9135 | 10436 | if (version >= 2) |
8e2e3c6c AM |
10437 | printf (_(" Number of columns: %u\n"), ncols); |
10438 | printf (_(" Number of used entries: %u\n"), nused); | |
10439 | printf (_(" Number of slots: %u\n\n"), nslots); | |
657d0d47 CC |
10440 | } |
10441 | ||
8e2e3c6c AM |
10442 | /* PR 17531: file: 45d69832. */ |
10443 | if ((size_t) nslots * 8 / 8 != nslots | |
10444 | || phash < phdr || phash > limit | |
10445 | || pindex < phash || pindex > limit | |
10446 | || ppool < pindex || ppool > limit) | |
657d0d47 | 10447 | { |
8e2e3c6c AM |
10448 | warn (ngettext ("Section %s is too small for %u slot\n", |
10449 | "Section %s is too small for %u slots\n", | |
10450 | nslots), | |
657d0d47 CC |
10451 | section->name, nslots); |
10452 | return 0; | |
10453 | } | |
10454 | ||
341f9135 | 10455 | if (version == 1) |
657d0d47 | 10456 | { |
341f9135 CC |
10457 | if (!do_display) |
10458 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
10459 | for (i = 0; i < nslots; i++) | |
657d0d47 | 10460 | { |
341f9135 CC |
10461 | unsigned char *shndx_list; |
10462 | unsigned int shndx; | |
10463 | ||
6937bb54 | 10464 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 10465 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 10466 | { |
6937bb54 | 10467 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 10468 | shndx_list = ppool + j * 4; |
f3853b34 NC |
10469 | /* PR 17531: file: 705e010d. */ |
10470 | if (shndx_list < ppool) | |
10471 | { | |
10472 | warn (_("Section index pool located before start of section\n")); | |
10473 | return 0; | |
10474 | } | |
10475 | ||
341f9135 CC |
10476 | if (do_display) |
10477 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
10478 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10479 | buf, sizeof (buf))); | |
10480 | for (;;) | |
657d0d47 | 10481 | { |
341f9135 CC |
10482 | if (shndx_list >= limit) |
10483 | { | |
10484 | warn (_("Section %s too small for shndx pool\n"), | |
10485 | section->name); | |
10486 | return 0; | |
10487 | } | |
6937bb54 | 10488 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
10489 | if (shndx == 0) |
10490 | break; | |
10491 | if (do_display) | |
10492 | printf (" %d", shndx); | |
10493 | else | |
10494 | add_shndx_to_cu_tu_entry (shndx); | |
10495 | shndx_list += 4; | |
657d0d47 | 10496 | } |
657d0d47 | 10497 | if (do_display) |
341f9135 | 10498 | printf ("\n"); |
657d0d47 | 10499 | else |
341f9135 CC |
10500 | end_cu_tu_entry (); |
10501 | } | |
10502 | phash += 8; | |
10503 | pindex += 4; | |
10504 | } | |
10505 | } | |
10506 | else if (version == 2) | |
10507 | { | |
10508 | unsigned int val; | |
10509 | unsigned int dw_sect; | |
10510 | unsigned char *ph = phash; | |
10511 | unsigned char *pi = pindex; | |
8e2e3c6c AM |
10512 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
10513 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
10514 | unsigned char *pend = psizes + (size_t) nused * ncols * 4; | |
015dc7e1 | 10515 | bool is_tu_index; |
341f9135 CC |
10516 | struct cu_tu_set *this_set = NULL; |
10517 | unsigned int row; | |
10518 | unsigned char *prow; | |
10519 | ||
10520 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
10521 | ||
362beea4 | 10522 | /* PR 17531: file: 0dd159bf. |
8e2e3c6c AM |
10523 | Check for integer overflow (can occur when size_t is 32-bit) |
10524 | with overlarge ncols or nused values. */ | |
4ac948a0 NC |
10525 | if (ncols > 0 |
10526 | && ((size_t) ncols * 4 / 4 != ncols | |
10527 | || (size_t) nused * ncols * 4 / ((size_t) ncols * 4) != nused | |
10528 | || poffsets < ppool || poffsets > limit | |
10529 | || psizes < poffsets || psizes > limit | |
10530 | || pend < psizes || pend > limit)) | |
341f9135 CC |
10531 | { |
10532 | warn (_("Section %s too small for offset and size tables\n"), | |
10533 | section->name); | |
10534 | return 0; | |
10535 | } | |
10536 | ||
10537 | if (do_display) | |
10538 | { | |
10539 | printf (_(" Offset table\n")); | |
10540 | printf (" slot %-16s ", | |
10541 | is_tu_index ? _("signature") : _("dwo_id")); | |
10542 | } | |
10543 | else | |
10544 | { | |
10545 | if (is_tu_index) | |
10546 | { | |
10547 | tu_count = nused; | |
72c61a0d | 10548 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 10549 | this_set = tu_sets; |
657d0d47 | 10550 | } |
657d0d47 | 10551 | else |
341f9135 CC |
10552 | { |
10553 | cu_count = nused; | |
72c61a0d | 10554 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
10555 | this_set = cu_sets; |
10556 | } | |
10557 | } | |
6937bb54 | 10558 | |
341f9135 CC |
10559 | if (do_display) |
10560 | { | |
10561 | for (j = 0; j < ncols; j++) | |
10562 | { | |
6937bb54 | 10563 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
10564 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
10565 | } | |
10566 | printf ("\n"); | |
10567 | } | |
6937bb54 | 10568 | |
341f9135 CC |
10569 | for (i = 0; i < nslots; i++) |
10570 | { | |
6937bb54 NC |
10571 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
10572 | ||
10573 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10574 | if (row != 0) |
10575 | { | |
591f7597 | 10576 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 10577 | if (row > nused) |
591f7597 NC |
10578 | { |
10579 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
10580 | row, nused); | |
10581 | return 0; | |
10582 | } | |
10583 | ||
341f9135 | 10584 | if (!do_display) |
6aea08d9 NC |
10585 | { |
10586 | size_t num_copy = sizeof (uint64_t); | |
10587 | ||
10588 | /* PR 23064: Beware of buffer overflow. */ | |
10589 | if (ph + num_copy < limit) | |
10590 | memcpy (&this_set[row - 1].signature, ph, num_copy); | |
10591 | else | |
10592 | { | |
10593 | warn (_("Signature (%p) extends beyond end of space in section\n"), ph); | |
10594 | return 0; | |
10595 | } | |
10596 | } | |
6937bb54 | 10597 | |
341f9135 | 10598 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
10599 | /* PR 17531: file: b8ce60a8. */ |
10600 | if (prow < poffsets || prow > limit) | |
10601 | { | |
10602 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
10603 | row, ncols); | |
10604 | return 0; | |
10605 | } | |
3aade688 | 10606 | |
341f9135 CC |
10607 | if (do_display) |
10608 | printf (_(" [%3d] 0x%s"), | |
10609 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10610 | buf, sizeof (buf))); | |
10611 | for (j = 0; j < ncols; j++) | |
10612 | { | |
6937bb54 | 10613 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
10614 | if (do_display) |
10615 | printf (" %8d", val); | |
10616 | else | |
10617 | { | |
6937bb54 | 10618 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
10619 | |
10620 | /* PR 17531: file: 10796eb3. */ | |
10621 | if (dw_sect >= DW_SECT_MAX) | |
10622 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10623 | else | |
10624 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
10625 | } |
10626 | } | |
6937bb54 | 10627 | |
341f9135 CC |
10628 | if (do_display) |
10629 | printf ("\n"); | |
10630 | } | |
10631 | ph += 8; | |
10632 | pi += 4; | |
10633 | } | |
10634 | ||
10635 | ph = phash; | |
10636 | pi = pindex; | |
10637 | if (do_display) | |
b4eb7656 | 10638 | { |
341f9135 CC |
10639 | printf ("\n"); |
10640 | printf (_(" Size table\n")); | |
10641 | printf (" slot %-16s ", | |
10642 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 10643 | } |
6937bb54 | 10644 | |
341f9135 CC |
10645 | for (j = 0; j < ncols; j++) |
10646 | { | |
6937bb54 | 10647 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
10648 | if (do_display) |
10649 | printf (" %8s", get_DW_SECT_short_name (val)); | |
10650 | } | |
6937bb54 | 10651 | |
341f9135 CC |
10652 | if (do_display) |
10653 | printf ("\n"); | |
6937bb54 | 10654 | |
341f9135 CC |
10655 | for (i = 0; i < nslots; i++) |
10656 | { | |
6937bb54 NC |
10657 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
10658 | ||
10659 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10660 | if (row != 0) |
10661 | { | |
10662 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 10663 | |
341f9135 CC |
10664 | if (do_display) |
10665 | printf (_(" [%3d] 0x%s"), | |
10666 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10667 | buf, sizeof (buf))); | |
6937bb54 | 10668 | |
341f9135 CC |
10669 | for (j = 0; j < ncols; j++) |
10670 | { | |
6937bb54 | 10671 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
10672 | if (do_display) |
10673 | printf (" %8d", val); | |
10674 | else | |
10675 | { | |
6937bb54 | 10676 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
10677 | if (dw_sect >= DW_SECT_MAX) |
10678 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10679 | else | |
341f9135 CC |
10680 | this_set [row - 1].section_sizes [dw_sect] = val; |
10681 | } | |
10682 | } | |
6937bb54 | 10683 | |
341f9135 CC |
10684 | if (do_display) |
10685 | printf ("\n"); | |
10686 | } | |
6937bb54 | 10687 | |
341f9135 CC |
10688 | ph += 8; |
10689 | pi += 4; | |
657d0d47 | 10690 | } |
657d0d47 | 10691 | } |
341f9135 | 10692 | else if (do_display) |
6937bb54 | 10693 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
10694 | |
10695 | if (do_display) | |
10696 | printf ("\n"); | |
10697 | ||
10698 | return 1; | |
10699 | } | |
10700 | ||
288f0ba2 AM |
10701 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
10702 | ||
657d0d47 CC |
10703 | /* Load the CU and TU indexes if present. This will build a list of |
10704 | section sets that we can use to associate a .debug_info.dwo section | |
10705 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
10706 | ||
015dc7e1 | 10707 | static bool |
657d0d47 CC |
10708 | load_cu_tu_indexes (void *file) |
10709 | { | |
10710 | /* If we have already loaded (or tried to load) the CU and TU indexes | |
10711 | then do not bother to repeat the task. */ | |
43a444f9 NC |
10712 | if (cu_tu_indexes_read == -1) |
10713 | { | |
015dc7e1 | 10714 | cu_tu_indexes_read = true; |
521d4b19 | 10715 | |
dda8d76d | 10716 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 | 10717 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
015dc7e1 | 10718 | cu_tu_indexes_read = false; |
43a444f9 | 10719 | |
dda8d76d | 10720 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 | 10721 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
015dc7e1 | 10722 | cu_tu_indexes_read = false; |
43a444f9 | 10723 | } |
657d0d47 | 10724 | |
015dc7e1 | 10725 | return (bool) cu_tu_indexes_read; |
657d0d47 CC |
10726 | } |
10727 | ||
10728 | /* Find the set of sections that includes section SHNDX. */ | |
10729 | ||
10730 | unsigned int * | |
10731 | find_cu_tu_set (void *file, unsigned int shndx) | |
10732 | { | |
10733 | unsigned int i; | |
10734 | ||
43a444f9 NC |
10735 | if (! load_cu_tu_indexes (file)) |
10736 | return NULL; | |
657d0d47 CC |
10737 | |
10738 | /* Find SHNDX in the shndx pool. */ | |
10739 | for (i = 0; i < shndx_pool_used; i++) | |
10740 | if (shndx_pool [i] == shndx) | |
10741 | break; | |
10742 | ||
10743 | if (i >= shndx_pool_used) | |
10744 | return NULL; | |
10745 | ||
10746 | /* Now backup to find the first entry in the set. */ | |
10747 | while (i > 0 && shndx_pool [i - 1] != 0) | |
10748 | i--; | |
10749 | ||
10750 | return shndx_pool + i; | |
10751 | } | |
10752 | ||
10753 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
10754 | ||
10755 | static int | |
10756 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
10757 | { | |
10758 | return process_cu_tu_index (section, 1); | |
10759 | } | |
10760 | ||
19e6b90e L |
10761 | static int |
10762 | display_debug_not_supported (struct dwarf_section *section, | |
10763 | void *file ATTRIBUTE_UNUSED) | |
10764 | { | |
10765 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
10766 | section->name); | |
10767 | ||
10768 | return 1; | |
10769 | } | |
10770 | ||
1306a742 NC |
10771 | /* Like malloc, but takes two parameters like calloc. |
10772 | Verifies that the first parameter is not too large. | |
82b1b41b | 10773 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 10774 | |
19e6b90e L |
10775 | void * |
10776 | cmalloc (size_t nmemb, size_t size) | |
10777 | { | |
10778 | /* Check for overflow. */ | |
10779 | if (nmemb >= ~(size_t) 0 / size) | |
10780 | return NULL; | |
82b1b41b NC |
10781 | |
10782 | return xmalloc (nmemb * size); | |
19e6b90e L |
10783 | } |
10784 | ||
1306a742 NC |
10785 | /* Like xmalloc, but takes two parameters like calloc. |
10786 | Verifies that the first parameter is not too large. | |
10787 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 10788 | |
72c61a0d | 10789 | void * |
1306a742 | 10790 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
10791 | { |
10792 | /* Check for overflow. */ | |
10793 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
10794 | { |
10795 | fprintf (stderr, | |
10796 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
10797 | (long) nmemb); | |
10798 | xexit (1); | |
10799 | } | |
72c61a0d | 10800 | |
1306a742 | 10801 | return xmalloc (nmemb * size); |
72c61a0d NC |
10802 | } |
10803 | ||
1306a742 NC |
10804 | /* Like xrealloc, but takes three parameters. |
10805 | Verifies that the second parameter is not too large. | |
10806 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 10807 | |
19e6b90e | 10808 | void * |
1306a742 | 10809 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
10810 | { |
10811 | /* Check for overflow. */ | |
10812 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10813 | { |
dda8d76d NC |
10814 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
10815 | (long) nmemb); | |
8490fb40 NC |
10816 | xexit (1); |
10817 | } | |
82b1b41b | 10818 | |
1306a742 | 10819 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
10820 | } |
10821 | ||
1306a742 | 10822 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 10823 | |
19e6b90e | 10824 | void * |
1306a742 | 10825 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
10826 | { |
10827 | /* Check for overflow. */ | |
10828 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10829 | { |
dda8d76d NC |
10830 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
10831 | (long) nmemb); | |
8490fb40 NC |
10832 | xexit (1); |
10833 | } | |
82b1b41b | 10834 | |
1306a742 | 10835 | return xcalloc (nmemb, size); |
19e6b90e L |
10836 | } |
10837 | ||
dda8d76d NC |
10838 | static unsigned long |
10839 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
10840 | const unsigned char * buf, | |
10841 | bfd_size_type len) | |
10842 | { | |
10843 | static const unsigned long crc32_table[256] = | |
10844 | { | |
10845 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
10846 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
10847 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
10848 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
10849 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
10850 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
10851 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
10852 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
10853 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
10854 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
10855 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
10856 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
10857 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
10858 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
10859 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
10860 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
10861 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
10862 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
10863 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
10864 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
10865 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
10866 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
10867 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
10868 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
10869 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
10870 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
10871 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
10872 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
10873 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
10874 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
10875 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
10876 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
10877 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
10878 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
10879 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
10880 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
10881 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
10882 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
10883 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
10884 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
10885 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
10886 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
10887 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
10888 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
10889 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
10890 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
10891 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
10892 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
10893 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
10894 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
10895 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
10896 | 0x2d02ef8d | |
10897 | }; | |
10898 | const unsigned char *end; | |
10899 | ||
10900 | crc = ~crc & 0xffffffff; | |
10901 | for (end = buf + len; buf < end; ++ buf) | |
10902 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
10903 | return ~crc & 0xffffffff; | |
10904 | } | |
10905 | ||
015dc7e1 AM |
10906 | typedef bool (*check_func_type) (const char *, void *); |
10907 | typedef const char *(* parse_func_type) (struct dwarf_section *, void *); | |
dda8d76d | 10908 | |
015dc7e1 | 10909 | static bool |
dda8d76d NC |
10910 | check_gnu_debuglink (const char * pathname, void * crc_pointer) |
10911 | { | |
10912 | static unsigned char buffer [8 * 1024]; | |
10913 | FILE * f; | |
10914 | bfd_size_type count; | |
10915 | unsigned long crc = 0; | |
10916 | void * sep_data; | |
10917 | ||
10918 | sep_data = open_debug_file (pathname); | |
10919 | if (sep_data == NULL) | |
015dc7e1 | 10920 | return false; |
dda8d76d NC |
10921 | |
10922 | /* Yes - we are opening the file twice... */ | |
10923 | f = fopen (pathname, "rb"); | |
10924 | if (f == NULL) | |
10925 | { | |
10926 | /* Paranoia: This should never happen. */ | |
10927 | close_debug_file (sep_data); | |
10928 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
015dc7e1 | 10929 | return false; |
dda8d76d NC |
10930 | } |
10931 | ||
10932 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
10933 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
10934 | ||
10935 | fclose (f); | |
10936 | ||
10937 | if (crc != * (unsigned long *) crc_pointer) | |
10938 | { | |
10939 | close_debug_file (sep_data); | |
10940 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
10941 | pathname); | |
015dc7e1 | 10942 | return false; |
dda8d76d NC |
10943 | } |
10944 | ||
015dc7e1 | 10945 | return true; |
dda8d76d NC |
10946 | } |
10947 | ||
10948 | static const char * | |
10949 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
10950 | { | |
10951 | const char * name; | |
10952 | unsigned int crc_offset; | |
10953 | unsigned long * crc32 = (unsigned long *) data; | |
10954 | ||
10955 | /* The name is first. | |
10956 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
10957 | name = (const char *) section->start; | |
10958 | ||
10959 | crc_offset = strnlen (name, section->size) + 1; | |
10960 | crc_offset = (crc_offset + 3) & ~3; | |
10961 | if (crc_offset + 4 > section->size) | |
10962 | return NULL; | |
10963 | ||
10964 | * crc32 = byte_get (section->start + crc_offset, 4); | |
10965 | return name; | |
10966 | } | |
10967 | ||
015dc7e1 | 10968 | static bool |
dda8d76d NC |
10969 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) |
10970 | { | |
10971 | void * sep_data = open_debug_file (filename); | |
10972 | ||
10973 | if (sep_data == NULL) | |
015dc7e1 | 10974 | return false; |
dda8d76d NC |
10975 | |
10976 | /* FIXME: We should now extract the build-id in the separate file | |
10977 | and check it... */ | |
10978 | ||
015dc7e1 | 10979 | return true; |
dda8d76d NC |
10980 | } |
10981 | ||
10982 | typedef struct build_id_data | |
10983 | { | |
10984 | bfd_size_type len; | |
10985 | const unsigned char * data; | |
10986 | } Build_id_data; | |
10987 | ||
10988 | static const char * | |
10989 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
10990 | { | |
10991 | const char * name; | |
10992 | bfd_size_type namelen; | |
10993 | bfd_size_type id_len; | |
10994 | Build_id_data * build_id_data; | |
10995 | ||
10996 | /* The name is first. | |
10997 | The build-id follows immediately, with no padding, up to the section's end. */ | |
10998 | ||
10999 | name = (const char *) section->start; | |
11000 | namelen = strnlen (name, section->size) + 1; | |
11001 | if (namelen >= section->size) | |
11002 | return NULL; | |
11003 | ||
11004 | id_len = section->size - namelen; | |
11005 | if (id_len < 0x14) | |
11006 | return NULL; | |
11007 | ||
dfbee680 | 11008 | build_id_data = (Build_id_data *) data; |
dda8d76d NC |
11009 | build_id_data->len = id_len; |
11010 | build_id_data->data = section->start + namelen; | |
11011 | ||
dda8d76d NC |
11012 | return name; |
11013 | } | |
11014 | ||
24841daa NC |
11015 | static void |
11016 | add_separate_debug_file (const char * filename, void * handle) | |
11017 | { | |
11018 | separate_info * i = xmalloc (sizeof * i); | |
11019 | ||
11020 | i->filename = filename; | |
11021 | i->handle = handle; | |
11022 | i->next = first_separate_info; | |
11023 | first_separate_info = i; | |
11024 | } | |
11025 | ||
301a9420 AM |
11026 | #if HAVE_LIBDEBUGINFOD |
11027 | /* Query debuginfod servers for the target debuglink or debugaltlink | |
11028 | file. If successful, store the path of the file in filename and | |
11029 | return TRUE, otherwise return FALSE. */ | |
11030 | ||
015dc7e1 | 11031 | static bool |
301a9420 AM |
11032 | debuginfod_fetch_separate_debug_info (struct dwarf_section * section, |
11033 | char ** filename, | |
11034 | void * file) | |
11035 | { | |
11036 | size_t build_id_len; | |
11037 | unsigned char * build_id; | |
11038 | ||
11039 | if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0) | |
11040 | { | |
11041 | /* Get the build-id of file. */ | |
11042 | build_id = get_build_id (file); | |
11043 | build_id_len = 0; | |
11044 | } | |
11045 | else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0) | |
11046 | { | |
11047 | /* Get the build-id of the debugaltlink file. */ | |
11048 | unsigned int filelen; | |
11049 | ||
11050 | filelen = strnlen ((const char *)section->start, section->size); | |
11051 | if (filelen == section->size) | |
11052 | /* Corrupt debugaltlink. */ | |
015dc7e1 | 11053 | return false; |
301a9420 AM |
11054 | |
11055 | build_id = section->start + filelen + 1; | |
11056 | build_id_len = section->size - (filelen + 1); | |
11057 | ||
11058 | if (build_id_len == 0) | |
015dc7e1 | 11059 | return false; |
301a9420 AM |
11060 | } |
11061 | else | |
015dc7e1 | 11062 | return false; |
301a9420 AM |
11063 | |
11064 | if (build_id) | |
11065 | { | |
11066 | int fd; | |
11067 | debuginfod_client * client; | |
11068 | ||
11069 | client = debuginfod_begin (); | |
11070 | if (client == NULL) | |
015dc7e1 | 11071 | return false; |
301a9420 AM |
11072 | |
11073 | /* Query debuginfod servers for the target file. If found its path | |
11074 | will be stored in filename. */ | |
11075 | fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename); | |
11076 | debuginfod_end (client); | |
11077 | ||
11078 | /* Only free build_id if we allocated space for a hex string | |
11079 | in get_build_id (). */ | |
11080 | if (build_id_len == 0) | |
11081 | free (build_id); | |
11082 | ||
11083 | if (fd >= 0) | |
11084 | { | |
11085 | /* File successfully retrieved. Close fd since we want to | |
11086 | use open_debug_file () on filename instead. */ | |
11087 | close (fd); | |
015dc7e1 | 11088 | return true; |
301a9420 AM |
11089 | } |
11090 | } | |
11091 | ||
015dc7e1 | 11092 | return false; |
301a9420 AM |
11093 | } |
11094 | #endif | |
11095 | ||
dda8d76d NC |
11096 | static void * |
11097 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 11098 | struct dwarf_section * xlink, |
dda8d76d NC |
11099 | parse_func_type parse_func, |
11100 | check_func_type check_func, | |
301a9420 AM |
11101 | void * func_data, |
11102 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
11103 | { |
11104 | const char * separate_filename; | |
24841daa | 11105 | char * debug_filename; |
dda8d76d NC |
11106 | char * canon_dir; |
11107 | size_t canon_dirlen; | |
11108 | size_t dirlen; | |
11109 | ||
2b63c337 | 11110 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
11111 | { |
11112 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 11113 | xlink->name ? xlink->name : xlink->uncompressed_name); |
ce139cd5 | 11114 | return NULL; |
dda8d76d | 11115 | } |
521d4b19 | 11116 | |
dda8d76d NC |
11117 | /* Attempt to locate the separate file. |
11118 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
11119 | ||
11120 | canon_dir = lrealpath (main_filename); | |
521d4b19 | 11121 | |
dda8d76d NC |
11122 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) |
11123 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
11124 | break; | |
11125 | canon_dir[canon_dirlen] = '\0'; | |
11126 | ||
11127 | #ifndef DEBUGDIR | |
11128 | #define DEBUGDIR "/lib/debug" | |
11129 | #endif | |
11130 | #ifndef EXTRA_DEBUG_ROOT1 | |
11131 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
11132 | #endif | |
11133 | #ifndef EXTRA_DEBUG_ROOT2 | |
11134 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
11135 | #endif | |
11136 | ||
24841daa NC |
11137 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
11138 | + canon_dirlen | |
11139 | + strlen (".debug/") | |
dda8d76d | 11140 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 11141 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
11142 | #endif |
11143 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 11144 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 11145 | #endif |
24841daa NC |
11146 | + strlen (separate_filename) |
11147 | + 1); | |
11148 | if (debug_filename == NULL) | |
dda8d76d NC |
11149 | { |
11150 | warn (_("Out of memory")); | |
3391569f | 11151 | free (canon_dir); |
dda8d76d NC |
11152 | return NULL; |
11153 | } | |
11154 | ||
11155 | /* First try in the current directory. */ | |
24841daa NC |
11156 | sprintf (debug_filename, "%s", separate_filename); |
11157 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11158 | goto found; |
11159 | ||
11160 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
11161 | sprintf (debug_filename, ".debug/%s", separate_filename); |
11162 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11163 | goto found; |
11164 | ||
11165 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
11166 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
11167 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11168 | goto found; |
11169 | ||
11170 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
11171 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
11172 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11173 | goto found; |
11174 | ||
11175 | #ifdef EXTRA_DEBUG_ROOT1 | |
11176 | /* Try the first extra debug file root. */ | |
24841daa NC |
11177 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
11178 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 11179 | goto found; |
39f0547e NC |
11180 | |
11181 | /* Try the first extra debug file root. */ | |
11182 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
11183 | if (check_func (debug_filename, func_data)) | |
11184 | goto found; | |
dda8d76d NC |
11185 | #endif |
11186 | ||
11187 | #ifdef EXTRA_DEBUG_ROOT2 | |
11188 | /* Try the second extra debug file root. */ | |
24841daa NC |
11189 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
11190 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11191 | goto found; |
11192 | #endif | |
11193 | ||
24841daa NC |
11194 | /* Then try in the global debug_filename directory. */ |
11195 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
11196 | dirlen = strlen (DEBUGDIR) - 1; |
11197 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
11198 | strcat (debug_filename, "/"); |
11199 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 11200 | |
24841daa | 11201 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
11202 | goto found; |
11203 | ||
301a9420 AM |
11204 | #if HAVE_LIBDEBUGINFOD |
11205 | { | |
11206 | char * tmp_filename; | |
11207 | ||
11208 | if (debuginfod_fetch_separate_debug_info (xlink, | |
11209 | & tmp_filename, | |
11210 | file)) | |
11211 | { | |
11212 | /* File successfully downloaded from server, replace | |
11213 | debug_filename with the file's path. */ | |
11214 | free (debug_filename); | |
11215 | debug_filename = tmp_filename; | |
11216 | goto found; | |
11217 | } | |
11218 | } | |
11219 | #endif | |
11220 | ||
ecd65684 L |
11221 | if (do_debug_links) |
11222 | { | |
11223 | /* Failed to find the file. */ | |
11224 | warn (_("could not find separate debug file '%s'\n"), | |
11225 | separate_filename); | |
11226 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
11227 | |
11228 | #ifdef EXTRA_DEBUG_ROOT2 | |
ecd65684 L |
11229 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, |
11230 | separate_filename); | |
11231 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
11232 | #endif |
11233 | ||
11234 | #ifdef EXTRA_DEBUG_ROOT1 | |
ecd65684 L |
11235 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, |
11236 | canon_dir, separate_filename); | |
11237 | warn (_("tried: %s\n"), debug_filename); | |
39f0547e | 11238 | |
ecd65684 L |
11239 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, |
11240 | separate_filename); | |
11241 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
11242 | #endif |
11243 | ||
ecd65684 L |
11244 | sprintf (debug_filename, "%s.debug/%s", canon_dir, |
11245 | separate_filename); | |
11246 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11247 | |
ecd65684 L |
11248 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
11249 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11250 | |
ecd65684 L |
11251 | sprintf (debug_filename, ".debug/%s", separate_filename); |
11252 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11253 | |
ecd65684 L |
11254 | sprintf (debug_filename, "%s", separate_filename); |
11255 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11256 | |
301a9420 | 11257 | #if HAVE_LIBDEBUGINFOD |
ecd65684 L |
11258 | { |
11259 | char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR); | |
11260 | if (urls == NULL) | |
11261 | urls = ""; | |
301a9420 | 11262 | |
ecd65684 L |
11263 | warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls); |
11264 | } | |
301a9420 | 11265 | #endif |
ecd65684 | 11266 | } |
301a9420 | 11267 | |
dda8d76d | 11268 | free (canon_dir); |
24841daa | 11269 | free (debug_filename); |
dda8d76d NC |
11270 | return NULL; |
11271 | ||
11272 | found: | |
11273 | free (canon_dir); | |
11274 | ||
24841daa NC |
11275 | void * debug_handle; |
11276 | ||
dda8d76d | 11277 | /* Now open the file.... */ |
24841daa | 11278 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 11279 | { |
24841daa NC |
11280 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
11281 | free (debug_filename); | |
ce139cd5 | 11282 | return NULL; |
dda8d76d NC |
11283 | } |
11284 | ||
11285 | /* FIXME: We do not check to see if there are any other separate debug info | |
11286 | files that would also match. */ | |
11287 | ||
ca0e11aa NC |
11288 | if (do_debug_links) |
11289 | printf (_("\n%s: Found separate debug info file: %s\n"), main_filename, debug_filename); | |
24841daa | 11290 | add_separate_debug_file (debug_filename, debug_handle); |
dda8d76d | 11291 | |
24841daa | 11292 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 11293 | the structure returned by open_debug_file(). */ |
24841daa | 11294 | return debug_handle; |
dda8d76d NC |
11295 | } |
11296 | ||
d85bf2ba NC |
11297 | /* Attempt to load a separate dwarf object file. */ |
11298 | ||
11299 | static void * | |
24841daa | 11300 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 11301 | { |
24841daa NC |
11302 | char * separate_filename; |
11303 | void * separate_handle; | |
d85bf2ba | 11304 | |
d9d9d8ef TV |
11305 | if (IS_ABSOLUTE_PATH (name)) |
11306 | separate_filename = strdup (name); | |
11307 | else | |
11308 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
11309 | separate_filename = concat (dir, "/", name, NULL); | |
24841daa | 11310 | if (separate_filename == NULL) |
d85bf2ba NC |
11311 | { |
11312 | warn (_("Out of memory allocating dwo filename\n")); | |
11313 | return NULL; | |
11314 | } | |
11315 | ||
24841daa | 11316 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 11317 | { |
24841daa NC |
11318 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
11319 | free (separate_filename); | |
d85bf2ba NC |
11320 | return NULL; |
11321 | } | |
11322 | ||
11323 | /* FIXME: We should check the dwo_id. */ | |
11324 | ||
24841daa NC |
11325 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
11326 | add_separate_debug_file (separate_filename, separate_handle); | |
11327 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
11328 | return separate_handle; | |
d85bf2ba NC |
11329 | } |
11330 | ||
e38332c2 NC |
11331 | static void |
11332 | load_debug_sup_file (const char * main_filename, void * file) | |
11333 | { | |
11334 | if (! load_debug_section (debug_sup, file)) | |
11335 | return; /* No .debug_sup section. */ | |
11336 | ||
11337 | struct dwarf_section * section; | |
11338 | section = & debug_displays [debug_sup].section; | |
11339 | assert (section != NULL); | |
11340 | ||
11341 | if (section->start == NULL || section->size < 5) | |
11342 | { | |
11343 | warn (_(".debug_sup section is corrupt/empty\n")); | |
11344 | return; | |
11345 | } | |
11346 | ||
11347 | if (section->start[2] != 0) | |
11348 | return; /* This is a supplementary file. */ | |
11349 | ||
11350 | const char * filename = (const char *) section->start + 3; | |
11351 | if (strnlen (filename, section->size - 3) == section->size - 3) | |
11352 | { | |
11353 | warn (_("filename in .debug_sup section is corrupt\n")); | |
11354 | return; | |
11355 | } | |
11356 | ||
11357 | if (filename[0] != '/' && strchr (main_filename, '/')) | |
11358 | { | |
11359 | char * new_name; | |
11360 | if (asprintf (& new_name, "%.*s/%s", | |
11361 | (int) (strrchr (main_filename, '/') - main_filename), | |
11362 | main_filename, | |
11363 | filename) < 3) | |
11364 | warn (_("unable to construct path for supplementary debug file")); | |
11365 | else | |
11366 | filename = new_name; | |
11367 | } | |
11368 | ||
11369 | void * handle; | |
11370 | handle = open_debug_file (filename); | |
11371 | if (handle == NULL) | |
11372 | { | |
11373 | warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename); | |
11374 | return; | |
11375 | } | |
11376 | ||
11377 | printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename, filename); | |
11378 | ||
11379 | /* FIXME: Compare the checksums, if present. */ | |
11380 | add_separate_debug_file (filename, handle); | |
11381 | } | |
11382 | ||
ce139cd5 NC |
11383 | /* Load a debuglink section and/or a debugaltlink section, if either are present. |
11384 | Recursively check the loaded files for more of these sections. | |
e38332c2 NC |
11385 | Also follow any links in .debug_sup sections. |
11386 | FIXME: Should also check for DWO_* entries in the newly loaded files. */ | |
ce139cd5 NC |
11387 | |
11388 | static void | |
11389 | check_for_and_load_links (void * file, const char * filename) | |
11390 | { | |
11391 | void * handle = NULL; | |
11392 | ||
11393 | if (load_debug_section (gnu_debugaltlink, file)) | |
11394 | { | |
11395 | Build_id_data build_id_data; | |
11396 | ||
11397 | handle = load_separate_debug_info (filename, | |
11398 | & debug_displays[gnu_debugaltlink].section, | |
11399 | parse_gnu_debugaltlink, | |
11400 | check_gnu_debugaltlink, | |
11401 | & build_id_data, | |
11402 | file); | |
11403 | if (handle) | |
11404 | { | |
11405 | assert (handle == first_separate_info->handle); | |
11406 | check_for_and_load_links (first_separate_info->handle, | |
11407 | first_separate_info->filename); | |
11408 | } | |
11409 | } | |
11410 | ||
11411 | if (load_debug_section (gnu_debuglink, file)) | |
11412 | { | |
11413 | unsigned long crc32; | |
11414 | ||
11415 | handle = load_separate_debug_info (filename, | |
11416 | & debug_displays[gnu_debuglink].section, | |
11417 | parse_gnu_debuglink, | |
11418 | check_gnu_debuglink, | |
11419 | & crc32, | |
11420 | file); | |
11421 | if (handle) | |
11422 | { | |
11423 | assert (handle == first_separate_info->handle); | |
11424 | check_for_and_load_links (first_separate_info->handle, | |
11425 | first_separate_info->filename); | |
11426 | } | |
11427 | } | |
e38332c2 NC |
11428 | |
11429 | load_debug_sup_file (filename, file); | |
ce139cd5 NC |
11430 | } |
11431 | ||
24841daa NC |
11432 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
11433 | Returns TRUE if any were found, FALSE otherwise. | |
11434 | If TRUE is returned then the linked list starting at first_separate_info | |
11435 | will be populated with open file handles. */ | |
dda8d76d | 11436 | |
015dc7e1 | 11437 | bool |
24841daa | 11438 | load_separate_debug_files (void * file, const char * filename) |
dda8d76d | 11439 | { |
8de3a6e2 NC |
11440 | /* Skip this operation if we are not interested in debug links. */ |
11441 | if (! do_follow_links && ! do_debug_links) | |
015dc7e1 | 11442 | return false; |
8de3a6e2 | 11443 | |
24841daa | 11444 | /* See if there are any dwo links. */ |
d85bf2ba NC |
11445 | if (load_debug_section (str, file) |
11446 | && load_debug_section (abbrev, file) | |
11447 | && load_debug_section (info, file)) | |
11448 | { | |
24841daa | 11449 | free_dwo_info (); |
d85bf2ba | 11450 | |
50ea0877 | 11451 | if (process_debug_info (& debug_displays[info].section, file, abbrev, |
015dc7e1 | 11452 | true, false)) |
d85bf2ba | 11453 | { |
015dc7e1 AM |
11454 | bool introduced = false; |
11455 | dwo_info *dwinfo; | |
11456 | const char *dir = NULL; | |
11457 | const char *id = NULL; | |
11458 | const char *name = NULL; | |
24841daa NC |
11459 | |
11460 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 11461 | { |
50ea0877 | 11462 | /* Accumulate NAME, DIR and ID fields. */ |
24841daa | 11463 | switch (dwinfo->type) |
d85bf2ba | 11464 | { |
24841daa | 11465 | case DWO_NAME: |
50ea0877 NC |
11466 | if (name != NULL) |
11467 | warn (_("Multiple DWO_NAMEs encountered for the same CU\n")); | |
11468 | name = dwinfo->value; | |
11469 | break; | |
11470 | ||
11471 | case DWO_DIR: | |
11472 | /* There can be multiple DW_AT_comp_dir entries in a CU, | |
11473 | so do not complain. */ | |
11474 | dir = dwinfo->value; | |
11475 | break; | |
11476 | ||
11477 | case DWO_ID: | |
11478 | if (id != NULL) | |
11479 | warn (_("multiple DWO_IDs encountered for the same CU\n")); | |
11480 | id = dwinfo->value; | |
11481 | break; | |
11482 | ||
11483 | default: | |
11484 | error (_("Unexpected DWO INFO type")); | |
11485 | break; | |
11486 | } | |
11487 | ||
11488 | /* If we have reached the end of our list, or we are changing | |
11489 | CUs, then display the information that we have accumulated | |
11490 | so far. */ | |
11491 | if (name != NULL | |
11492 | && (dwinfo->next == NULL | |
11493 | || dwinfo->next->cu_offset != dwinfo->cu_offset)) | |
11494 | { | |
24841daa NC |
11495 | if (do_debug_links) |
11496 | { | |
11497 | if (! introduced) | |
11498 | { | |
11499 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
11500 | debug_displays [info].section.uncompressed_name); | |
015dc7e1 | 11501 | introduced = true; |
24841daa | 11502 | } |
d85bf2ba | 11503 | |
50ea0877 | 11504 | printf (_(" Name: %s\n"), name); |
24841daa NC |
11505 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); |
11506 | if (id != NULL) | |
11507 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
11508 | else | |
50ea0877 | 11509 | printf (_(" ID: <not specified>\n")); |
24841daa NC |
11510 | printf ("\n\n"); |
11511 | } | |
11512 | ||
11513 | if (do_follow_links) | |
50ea0877 | 11514 | load_dwo_file (filename, name, dir, id); |
24841daa | 11515 | |
50ea0877 | 11516 | name = dir = id = NULL; |
24841daa | 11517 | } |
d85bf2ba NC |
11518 | } |
11519 | } | |
11520 | } | |
11521 | ||
dda8d76d | 11522 | if (! do_follow_links) |
8de3a6e2 NC |
11523 | /* The other debug links will be displayed by display_debug_links() |
11524 | so we do not need to do any further processing here. */ | |
015dc7e1 | 11525 | return false; |
dda8d76d NC |
11526 | |
11527 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
dda8d76d | 11528 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ |
d85bf2ba | 11529 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 11530 | |
ce139cd5 | 11531 | check_for_and_load_links (file, filename); |
24841daa | 11532 | if (first_separate_info != NULL) |
015dc7e1 | 11533 | return true; |
24841daa | 11534 | |
dda8d76d | 11535 | do_follow_links = 0; |
015dc7e1 | 11536 | return false; |
521d4b19 | 11537 | } |
dda8d76d | 11538 | |
19e6b90e L |
11539 | void |
11540 | free_debug_memory (void) | |
11541 | { | |
3f5e193b | 11542 | unsigned int i; |
19e6b90e | 11543 | |
bcd213b2 | 11544 | free_all_abbrevs (); |
19e6b90e | 11545 | |
bcd213b2 NC |
11546 | free (cu_abbrev_map); |
11547 | cu_abbrev_map = NULL; | |
11548 | next_free_abbrev_map_entry = 0; | |
521d4b19 | 11549 | |
288f0ba2 AM |
11550 | free (shndx_pool); |
11551 | shndx_pool = NULL; | |
11552 | shndx_pool_size = 0; | |
11553 | shndx_pool_used = 0; | |
11554 | free (cu_sets); | |
11555 | cu_sets = NULL; | |
11556 | cu_count = 0; | |
11557 | free (tu_sets); | |
11558 | tu_sets = NULL; | |
11559 | tu_count = 0; | |
11560 | ||
11561 | memset (level_type_signed, 0, sizeof level_type_signed); | |
11562 | cu_tu_indexes_read = -1; | |
11563 | ||
19e6b90e | 11564 | for (i = 0; i < max; i++) |
3f5e193b | 11565 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 11566 | |
cc86f28f | 11567 | if (debug_information != NULL) |
19e6b90e | 11568 | { |
82fcdb39 | 11569 | for (i = 0; i < alloc_num_debug_info_entries; i++) |
19e6b90e | 11570 | { |
82fcdb39 | 11571 | if (debug_information [i].max_loc_offsets) |
19e6b90e | 11572 | { |
82fcdb39 AM |
11573 | free (debug_information [i].loc_offsets); |
11574 | free (debug_information [i].have_frame_base); | |
19e6b90e | 11575 | } |
82fcdb39 AM |
11576 | if (debug_information [i].max_range_lists) |
11577 | free (debug_information [i].range_lists); | |
19e6b90e L |
11578 | } |
11579 | free (debug_information); | |
11580 | debug_information = NULL; | |
82b1b41b | 11581 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 11582 | } |
dda8d76d | 11583 | |
24841daa NC |
11584 | separate_info * d; |
11585 | separate_info * next; | |
dda8d76d | 11586 | |
24841daa NC |
11587 | for (d = first_separate_info; d != NULL; d = next) |
11588 | { | |
11589 | close_debug_file (d->handle); | |
11590 | free ((void *) d->filename); | |
11591 | next = d->next; | |
11592 | free ((void *) d); | |
dda8d76d | 11593 | } |
24841daa | 11594 | first_separate_info = NULL; |
521d4b19 | 11595 | |
24841daa | 11596 | free_dwo_info (); |
19e6b90e L |
11597 | } |
11598 | ||
4cb93e3b TG |
11599 | void |
11600 | dwarf_select_sections_by_names (const char *names) | |
11601 | { | |
11602 | typedef struct | |
11603 | { | |
11604 | const char * option; | |
11605 | int * variable; | |
f9f0e732 | 11606 | int val; |
4cb93e3b TG |
11607 | } |
11608 | debug_dump_long_opts; | |
11609 | ||
11610 | static const debug_dump_long_opts opts_table [] = | |
11611 | { | |
11612 | /* Please keep this table alpha- sorted. */ | |
11613 | { "Ranges", & do_debug_ranges, 1 }, | |
11614 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 11615 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 11616 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
11617 | { "cu_index", & do_debug_cu_index, 1 }, |
11618 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 11619 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
11620 | { "frames", & do_debug_frames, 1 }, |
11621 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
11622 | /* The special .gdb_index section. */ |
11623 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
11624 | { "info", & do_debug_info, 1 }, |
11625 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 11626 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
11627 | { "loc", & do_debug_loc, 1 }, |
11628 | { "macro", & do_debug_macinfo, 1 }, | |
c46b7066 | 11629 | { "no-follow-links", & do_follow_links, 0 }, |
4cb93e3b | 11630 | { "pubnames", & do_debug_pubnames, 1 }, |
357da287 | 11631 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 11632 | /* This entry is for compatibility |
4cb93e3b TG |
11633 | with earlier versions of readelf. */ |
11634 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 11635 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 11636 | { "str", & do_debug_str, 1 }, |
e4b7104b | 11637 | { "str-offsets", & do_debug_str_offsets, 1 }, |
6f875884 TG |
11638 | /* These trace_* sections are used by Itanium VMS. */ |
11639 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
11640 | { "trace_aranges", & do_trace_aranges, 1 }, | |
11641 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
11642 | { NULL, NULL, 0 } |
11643 | }; | |
11644 | ||
11645 | const char *p; | |
467c65bc | 11646 | |
4cb93e3b TG |
11647 | p = names; |
11648 | while (*p) | |
11649 | { | |
11650 | const debug_dump_long_opts * entry; | |
467c65bc | 11651 | |
4cb93e3b TG |
11652 | for (entry = opts_table; entry->option; entry++) |
11653 | { | |
11654 | size_t len = strlen (entry->option); | |
467c65bc | 11655 | |
4cb93e3b TG |
11656 | if (strncmp (p, entry->option, len) == 0 |
11657 | && (p[len] == ',' || p[len] == '\0')) | |
11658 | { | |
c46b7066 | 11659 | * entry->variable = entry->val; |
467c65bc | 11660 | |
4cb93e3b TG |
11661 | /* The --debug-dump=frames-interp option also |
11662 | enables the --debug-dump=frames option. */ | |
11663 | if (do_debug_frames_interp) | |
11664 | do_debug_frames = 1; | |
11665 | ||
11666 | p += len; | |
11667 | break; | |
11668 | } | |
11669 | } | |
467c65bc | 11670 | |
4cb93e3b TG |
11671 | if (entry->option == NULL) |
11672 | { | |
11673 | warn (_("Unrecognized debug option '%s'\n"), p); | |
11674 | p = strchr (p, ','); | |
11675 | if (p == NULL) | |
11676 | break; | |
11677 | } | |
467c65bc | 11678 | |
4cb93e3b TG |
11679 | if (*p == ',') |
11680 | p++; | |
11681 | } | |
11682 | } | |
11683 | ||
11684 | void | |
11685 | dwarf_select_sections_by_letters (const char *letters) | |
11686 | { | |
91d6fa6a | 11687 | unsigned int lindex = 0; |
4cb93e3b | 11688 | |
91d6fa6a NC |
11689 | while (letters[lindex]) |
11690 | switch (letters[lindex++]) | |
4cb93e3b | 11691 | { |
dda8d76d NC |
11692 | case 'A': do_debug_addr = 1; break; |
11693 | case 'a': do_debug_abbrevs = 1; break; | |
11694 | case 'c': do_debug_cu_index = 1; break; | |
11695 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
11696 | case 'f': do_debug_frames = 1; break; | |
11697 | case 'g': do_gdb_index = 1; break; | |
11698 | case 'i': do_debug_info = 1; break; | |
11699 | case 'K': do_follow_links = 1; break; | |
c46b7066 | 11700 | case 'N': do_follow_links = 0; break; |
dda8d76d NC |
11701 | case 'k': do_debug_links = 1; break; |
11702 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
11703 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
11704 | case 'm': do_debug_macinfo = 1; break; | |
e4b7104b | 11705 | case 'O': do_debug_str_offsets = 1; break; |
dda8d76d NC |
11706 | case 'o': do_debug_loc = 1; break; |
11707 | case 'p': do_debug_pubnames = 1; break; | |
11708 | case 'R': do_debug_ranges = 1; break; | |
11709 | case 'r': do_debug_aranges = 1; break; | |
11710 | case 's': do_debug_str = 1; break; | |
11711 | case 'T': do_trace_aranges = 1; break; | |
11712 | case 't': do_debug_pubtypes = 1; break; | |
11713 | case 'U': do_trace_info = 1; break; | |
11714 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 11715 | |
4cb93e3b | 11716 | default: |
7cc78d07 | 11717 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
11718 | break; |
11719 | } | |
11720 | } | |
11721 | ||
11722 | void | |
11723 | dwarf_select_sections_all (void) | |
11724 | { | |
11725 | do_debug_info = 1; | |
11726 | do_debug_abbrevs = 1; | |
11727 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
11728 | do_debug_pubnames = 1; | |
f9f0e732 | 11729 | do_debug_pubtypes = 1; |
4cb93e3b TG |
11730 | do_debug_aranges = 1; |
11731 | do_debug_ranges = 1; | |
11732 | do_debug_frames = 1; | |
11733 | do_debug_macinfo = 1; | |
11734 | do_debug_str = 1; | |
11735 | do_debug_loc = 1; | |
5bbdf3d5 | 11736 | do_gdb_index = 1; |
6f875884 TG |
11737 | do_trace_info = 1; |
11738 | do_trace_abbrevs = 1; | |
11739 | do_trace_aranges = 1; | |
657d0d47 CC |
11740 | do_debug_addr = 1; |
11741 | do_debug_cu_index = 1; | |
dda8d76d NC |
11742 | do_follow_links = 1; |
11743 | do_debug_links = 1; | |
e4b7104b | 11744 | do_debug_str_offsets = 1; |
4cb93e3b TG |
11745 | } |
11746 | ||
208599d9 AM |
11747 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0 |
11748 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0 | |
dda8d76d NC |
11749 | |
11750 | /* N.B. The order here must match the order in section_display_enum. */ | |
11751 | ||
19e6b90e L |
11752 | struct dwarf_section_display debug_displays[] = |
11753 | { | |
015dc7e1 AM |
11754 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false }, |
11755 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, true }, | |
11756 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true }, | |
11757 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, true }, | |
11758 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true }, | |
11759 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, false }, | |
11760 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, false }, | |
11761 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true }, | |
11762 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false }, | |
11763 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true }, | |
11764 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, | |
11765 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, | |
11766 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
11767 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
11768 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, false }, | |
11769 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, false }, | |
11770 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, | |
11771 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, | |
11772 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
11773 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
11774 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, true }, | |
11775 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
11776 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, false }, | |
11777 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, false }, | |
11778 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, true }, | |
11779 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, false }, | |
11780 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, false }, | |
11781 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, true }, | |
11782 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false }, | |
11783 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, true }, | |
11784 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true }, | |
11785 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
11786 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true }, | |
11787 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false }, | |
11788 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, true }, | |
11789 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true }, | |
11790 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true }, | |
11791 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, true }, | |
11792 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false }, | |
11793 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false }, | |
11794 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false }, | |
11795 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false }, | |
11796 | { { ".debug_sup", "", NO_ABBREVS }, display_debug_sup, &do_debug_links, false }, | |
dda8d76d NC |
11797 | /* Separate debug info files can containt their own .debug_str section, |
11798 | and this might be in *addition* to a .debug_str section already present | |
11799 | in the main file. Hence we need to have two entries for .debug_str. */ | |
015dc7e1 | 11800 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, |
19e6b90e | 11801 | }; |
b451e98a JK |
11802 | |
11803 | /* A static assertion. */ | |
11804 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |