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 | } \ | |
2d4b4986 | 409 | if ((PTR) >= (END) - amount) \ |
0c588247 NC |
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); \ | |
2d4b4986 | 437 | if ((PTR) >= (END) - amount) \ |
0c588247 NC |
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 | { \ | |
2d4b4986 | 463 | if ((PTR) <= (END) - 8) \ |
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 * | |
f2f9554b AM |
1062 | process_abbrev_set (struct dwarf_section *section, |
1063 | dwarf_vma abbrev_base, | |
1064 | dwarf_vma abbrev_size, | |
1065 | dwarf_vma abbrev_offset, | |
1066 | abbrev_list *list) | |
19e6b90e | 1067 | { |
f2f9554b AM |
1068 | if (abbrev_base >= section->size |
1069 | || abbrev_size > section->size - abbrev_base) | |
1070 | { | |
1071 | /* PR 17531: file:4bcd9ce9. */ | |
1072 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than " | |
1073 | "abbrev section size (%lx)\n"), | |
d30182b5 | 1074 | (unsigned long) (abbrev_base + abbrev_size), |
f2f9554b AM |
1075 | (unsigned long) section->size); |
1076 | return NULL; | |
1077 | } | |
1078 | if (abbrev_offset >= abbrev_size) | |
1079 | { | |
1080 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than " | |
1081 | "abbrev section size (%lx)\n"), | |
1082 | (unsigned long) abbrev_offset, | |
1083 | (unsigned long) abbrev_size); | |
1084 | return NULL; | |
1085 | } | |
1086 | ||
1087 | unsigned char *start = section->start + abbrev_base; | |
1088 | unsigned char *end = start + abbrev_size; | |
1089 | start += abbrev_offset; | |
19e6b90e L |
1090 | while (start < end) |
1091 | { | |
19e6b90e L |
1092 | unsigned long entry; |
1093 | unsigned long tag; | |
1094 | unsigned long attribute; | |
1095 | int children; | |
1096 | ||
cd30bcef | 1097 | READ_ULEB (entry, start, end); |
19e6b90e | 1098 | |
bcd213b2 | 1099 | /* A single zero is supposed to end the set according |
19e6b90e L |
1100 | to the standard. If there's more, then signal that to |
1101 | the caller. */ | |
f6f0e17b NC |
1102 | if (start == end) |
1103 | return NULL; | |
19e6b90e | 1104 | if (entry == 0) |
f6f0e17b | 1105 | return start; |
19e6b90e | 1106 | |
cd30bcef | 1107 | READ_ULEB (tag, start, end); |
f6f0e17b NC |
1108 | if (start == end) |
1109 | return NULL; | |
19e6b90e L |
1110 | |
1111 | children = *start++; | |
1112 | ||
bcd213b2 | 1113 | add_abbrev (entry, tag, children, list); |
19e6b90e L |
1114 | |
1115 | do | |
1116 | { | |
1117 | unsigned long form; | |
77145576 JK |
1118 | /* Initialize it due to a false compiler warning. */ |
1119 | bfd_signed_vma implicit_const = -1; | |
19e6b90e | 1120 | |
cd30bcef | 1121 | READ_ULEB (attribute, start, end); |
f6f0e17b NC |
1122 | if (start == end) |
1123 | break; | |
19e6b90e | 1124 | |
cd30bcef | 1125 | READ_ULEB (form, start, end); |
f6f0e17b NC |
1126 | if (start == end) |
1127 | break; | |
19e6b90e | 1128 | |
77145576 JK |
1129 | if (form == DW_FORM_implicit_const) |
1130 | { | |
cd30bcef | 1131 | READ_SLEB (implicit_const, start, end); |
77145576 JK |
1132 | if (start == end) |
1133 | break; | |
1134 | } | |
1135 | ||
bcd213b2 | 1136 | add_abbrev_attr (attribute, form, implicit_const, list); |
19e6b90e L |
1137 | } |
1138 | while (attribute != 0); | |
1139 | } | |
1140 | ||
399c99f7 L |
1141 | /* Report the missing single zero which ends the section. */ |
1142 | error (_(".debug_abbrev section not zero terminated\n")); | |
1143 | ||
19e6b90e L |
1144 | return NULL; |
1145 | } | |
1146 | ||
a19c41a7 | 1147 | static const char * |
19e6b90e L |
1148 | get_TAG_name (unsigned long tag) |
1149 | { | |
04914e37 | 1150 | const char *name = get_DW_TAG_name ((unsigned int) tag); |
a19c41a7 TT |
1151 | |
1152 | if (name == NULL) | |
19e6b90e | 1153 | { |
a19c41a7 | 1154 | static char buffer[100]; |
19e6b90e | 1155 | |
04914e37 NC |
1156 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
1157 | snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag); | |
1158 | else | |
1159 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag); | |
a19c41a7 | 1160 | return buffer; |
19e6b90e | 1161 | } |
a19c41a7 TT |
1162 | |
1163 | return name; | |
19e6b90e L |
1164 | } |
1165 | ||
a19c41a7 | 1166 | static const char * |
19e6b90e L |
1167 | get_FORM_name (unsigned long form) |
1168 | { | |
399c99f7 | 1169 | const char *name; |
bf5117e3 | 1170 | |
399c99f7 L |
1171 | if (form == 0) |
1172 | return "DW_FORM value: 0"; | |
a19c41a7 | 1173 | |
399c99f7 | 1174 | name = get_DW_FORM_name (form); |
a19c41a7 | 1175 | if (name == NULL) |
19e6b90e | 1176 | { |
a19c41a7 | 1177 | static char buffer[100]; |
19e6b90e | 1178 | |
a19c41a7 TT |
1179 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
1180 | return buffer; | |
19e6b90e | 1181 | } |
a19c41a7 TT |
1182 | |
1183 | return name; | |
19e6b90e L |
1184 | } |
1185 | ||
61364358 JK |
1186 | static const char * |
1187 | get_IDX_name (unsigned long idx) | |
1188 | { | |
1189 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
1190 | ||
1191 | if (name == NULL) | |
1192 | { | |
1193 | static char buffer[100]; | |
1194 | ||
1195 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1196 | return buffer; | |
1197 | } | |
1198 | ||
1199 | return name; | |
1200 | } | |
1201 | ||
19e6b90e | 1202 | static unsigned char * |
0c588247 NC |
1203 | display_block (unsigned char *data, |
1204 | dwarf_vma length, | |
ef0b5f1c | 1205 | const unsigned char * const end, char delimiter) |
19e6b90e | 1206 | { |
0c588247 NC |
1207 | dwarf_vma maxlen; |
1208 | ||
ef0b5f1c | 1209 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
1210 | if (data > end) |
1211 | return (unsigned char *) end; | |
19e6b90e | 1212 | |
0c588247 NC |
1213 | maxlen = (dwarf_vma) (end - data); |
1214 | length = length > maxlen ? maxlen : length; | |
1215 | ||
19e6b90e L |
1216 | while (length --) |
1217 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1218 | ||
1219 | return data; | |
1220 | } | |
1221 | ||
1222 | static int | |
1223 | decode_location_expression (unsigned char * data, | |
1224 | unsigned int pointer_size, | |
b7807392 JJ |
1225 | unsigned int offset_size, |
1226 | int dwarf_version, | |
467c65bc NC |
1227 | dwarf_vma length, |
1228 | dwarf_vma cu_offset, | |
f1c4cc75 | 1229 | struct dwarf_section * section) |
19e6b90e L |
1230 | { |
1231 | unsigned op; | |
467c65bc | 1232 | dwarf_vma uvalue; |
0c588247 | 1233 | dwarf_signed_vma svalue; |
19e6b90e L |
1234 | unsigned char *end = data + length; |
1235 | int need_frame_base = 0; | |
1236 | ||
1237 | while (data < end) | |
1238 | { | |
1239 | op = *data++; | |
1240 | ||
1241 | switch (op) | |
1242 | { | |
1243 | case DW_OP_addr: | |
0c588247 NC |
1244 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1245 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1246 | break; |
1247 | case DW_OP_deref: | |
1248 | printf ("DW_OP_deref"); | |
1249 | break; | |
1250 | case DW_OP_const1u: | |
0c588247 NC |
1251 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1252 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1253 | break; |
1254 | case DW_OP_const1s: | |
0c588247 NC |
1255 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1256 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1257 | break; |
1258 | case DW_OP_const2u: | |
87bc83b3 | 1259 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1260 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1261 | break; |
1262 | case DW_OP_const2s: | |
0c588247 NC |
1263 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1264 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1265 | break; |
1266 | case DW_OP_const4u: | |
0c588247 NC |
1267 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1268 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1269 | break; |
1270 | case DW_OP_const4s: | |
0c588247 NC |
1271 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1272 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1273 | break; |
1274 | case DW_OP_const8u: | |
0c588247 NC |
1275 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1276 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1277 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1278 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1279 | break; |
1280 | case DW_OP_const8s: | |
0c588247 NC |
1281 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1282 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1283 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1284 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1285 | break; |
1286 | case DW_OP_constu: | |
cd30bcef AM |
1287 | READ_ULEB (uvalue, data, end); |
1288 | printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1289 | break; |
1290 | case DW_OP_consts: | |
cd30bcef AM |
1291 | READ_SLEB (svalue, data, end); |
1292 | printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1293 | break; |
1294 | case DW_OP_dup: | |
1295 | printf ("DW_OP_dup"); | |
1296 | break; | |
1297 | case DW_OP_drop: | |
1298 | printf ("DW_OP_drop"); | |
1299 | break; | |
1300 | case DW_OP_over: | |
1301 | printf ("DW_OP_over"); | |
1302 | break; | |
1303 | case DW_OP_pick: | |
0c588247 NC |
1304 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1305 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1306 | break; |
1307 | case DW_OP_swap: | |
1308 | printf ("DW_OP_swap"); | |
1309 | break; | |
1310 | case DW_OP_rot: | |
1311 | printf ("DW_OP_rot"); | |
1312 | break; | |
1313 | case DW_OP_xderef: | |
1314 | printf ("DW_OP_xderef"); | |
1315 | break; | |
1316 | case DW_OP_abs: | |
1317 | printf ("DW_OP_abs"); | |
1318 | break; | |
1319 | case DW_OP_and: | |
1320 | printf ("DW_OP_and"); | |
1321 | break; | |
1322 | case DW_OP_div: | |
1323 | printf ("DW_OP_div"); | |
1324 | break; | |
1325 | case DW_OP_minus: | |
1326 | printf ("DW_OP_minus"); | |
1327 | break; | |
1328 | case DW_OP_mod: | |
1329 | printf ("DW_OP_mod"); | |
1330 | break; | |
1331 | case DW_OP_mul: | |
1332 | printf ("DW_OP_mul"); | |
1333 | break; | |
1334 | case DW_OP_neg: | |
1335 | printf ("DW_OP_neg"); | |
1336 | break; | |
1337 | case DW_OP_not: | |
1338 | printf ("DW_OP_not"); | |
1339 | break; | |
1340 | case DW_OP_or: | |
1341 | printf ("DW_OP_or"); | |
1342 | break; | |
1343 | case DW_OP_plus: | |
1344 | printf ("DW_OP_plus"); | |
1345 | break; | |
1346 | case DW_OP_plus_uconst: | |
cd30bcef AM |
1347 | READ_ULEB (uvalue, data, end); |
1348 | printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1349 | break; |
1350 | case DW_OP_shl: | |
1351 | printf ("DW_OP_shl"); | |
1352 | break; | |
1353 | case DW_OP_shr: | |
1354 | printf ("DW_OP_shr"); | |
1355 | break; | |
1356 | case DW_OP_shra: | |
1357 | printf ("DW_OP_shra"); | |
1358 | break; | |
1359 | case DW_OP_xor: | |
1360 | printf ("DW_OP_xor"); | |
1361 | break; | |
1362 | case DW_OP_bra: | |
0c588247 NC |
1363 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1364 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1365 | break; |
1366 | case DW_OP_eq: | |
1367 | printf ("DW_OP_eq"); | |
1368 | break; | |
1369 | case DW_OP_ge: | |
1370 | printf ("DW_OP_ge"); | |
1371 | break; | |
1372 | case DW_OP_gt: | |
1373 | printf ("DW_OP_gt"); | |
1374 | break; | |
1375 | case DW_OP_le: | |
1376 | printf ("DW_OP_le"); | |
1377 | break; | |
1378 | case DW_OP_lt: | |
1379 | printf ("DW_OP_lt"); | |
1380 | break; | |
1381 | case DW_OP_ne: | |
1382 | printf ("DW_OP_ne"); | |
1383 | break; | |
1384 | case DW_OP_skip: | |
0c588247 NC |
1385 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1386 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1387 | break; |
1388 | ||
1389 | case DW_OP_lit0: | |
1390 | case DW_OP_lit1: | |
1391 | case DW_OP_lit2: | |
1392 | case DW_OP_lit3: | |
1393 | case DW_OP_lit4: | |
1394 | case DW_OP_lit5: | |
1395 | case DW_OP_lit6: | |
1396 | case DW_OP_lit7: | |
1397 | case DW_OP_lit8: | |
1398 | case DW_OP_lit9: | |
1399 | case DW_OP_lit10: | |
1400 | case DW_OP_lit11: | |
1401 | case DW_OP_lit12: | |
1402 | case DW_OP_lit13: | |
1403 | case DW_OP_lit14: | |
1404 | case DW_OP_lit15: | |
1405 | case DW_OP_lit16: | |
1406 | case DW_OP_lit17: | |
1407 | case DW_OP_lit18: | |
1408 | case DW_OP_lit19: | |
1409 | case DW_OP_lit20: | |
1410 | case DW_OP_lit21: | |
1411 | case DW_OP_lit22: | |
1412 | case DW_OP_lit23: | |
1413 | case DW_OP_lit24: | |
1414 | case DW_OP_lit25: | |
1415 | case DW_OP_lit26: | |
1416 | case DW_OP_lit27: | |
1417 | case DW_OP_lit28: | |
1418 | case DW_OP_lit29: | |
1419 | case DW_OP_lit30: | |
1420 | case DW_OP_lit31: | |
1421 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1422 | break; | |
1423 | ||
1424 | case DW_OP_reg0: | |
1425 | case DW_OP_reg1: | |
1426 | case DW_OP_reg2: | |
1427 | case DW_OP_reg3: | |
1428 | case DW_OP_reg4: | |
1429 | case DW_OP_reg5: | |
1430 | case DW_OP_reg6: | |
1431 | case DW_OP_reg7: | |
1432 | case DW_OP_reg8: | |
1433 | case DW_OP_reg9: | |
1434 | case DW_OP_reg10: | |
1435 | case DW_OP_reg11: | |
1436 | case DW_OP_reg12: | |
1437 | case DW_OP_reg13: | |
1438 | case DW_OP_reg14: | |
1439 | case DW_OP_reg15: | |
1440 | case DW_OP_reg16: | |
1441 | case DW_OP_reg17: | |
1442 | case DW_OP_reg18: | |
1443 | case DW_OP_reg19: | |
1444 | case DW_OP_reg20: | |
1445 | case DW_OP_reg21: | |
1446 | case DW_OP_reg22: | |
1447 | case DW_OP_reg23: | |
1448 | case DW_OP_reg24: | |
1449 | case DW_OP_reg25: | |
1450 | case DW_OP_reg26: | |
1451 | case DW_OP_reg27: | |
1452 | case DW_OP_reg28: | |
1453 | case DW_OP_reg29: | |
1454 | case DW_OP_reg30: | |
1455 | case DW_OP_reg31: | |
18464d4d JK |
1456 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1457 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1458 | break; |
1459 | ||
1460 | case DW_OP_breg0: | |
1461 | case DW_OP_breg1: | |
1462 | case DW_OP_breg2: | |
1463 | case DW_OP_breg3: | |
1464 | case DW_OP_breg4: | |
1465 | case DW_OP_breg5: | |
1466 | case DW_OP_breg6: | |
1467 | case DW_OP_breg7: | |
1468 | case DW_OP_breg8: | |
1469 | case DW_OP_breg9: | |
1470 | case DW_OP_breg10: | |
1471 | case DW_OP_breg11: | |
1472 | case DW_OP_breg12: | |
1473 | case DW_OP_breg13: | |
1474 | case DW_OP_breg14: | |
1475 | case DW_OP_breg15: | |
1476 | case DW_OP_breg16: | |
1477 | case DW_OP_breg17: | |
1478 | case DW_OP_breg18: | |
1479 | case DW_OP_breg19: | |
1480 | case DW_OP_breg20: | |
1481 | case DW_OP_breg21: | |
1482 | case DW_OP_breg22: | |
1483 | case DW_OP_breg23: | |
1484 | case DW_OP_breg24: | |
1485 | case DW_OP_breg25: | |
1486 | case DW_OP_breg26: | |
1487 | case DW_OP_breg27: | |
1488 | case DW_OP_breg28: | |
1489 | case DW_OP_breg29: | |
1490 | case DW_OP_breg30: | |
1491 | case DW_OP_breg31: | |
cd30bcef AM |
1492 | READ_SLEB (svalue, data, end); |
1493 | printf ("DW_OP_breg%d (%s): %s", op - DW_OP_breg0, | |
1494 | regname (op - DW_OP_breg0, 1), dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1495 | break; |
1496 | ||
1497 | case DW_OP_regx: | |
cd30bcef | 1498 | READ_ULEB (uvalue, data, end); |
467c65bc NC |
1499 | printf ("DW_OP_regx: %s (%s)", |
1500 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1501 | break; |
1502 | case DW_OP_fbreg: | |
1503 | need_frame_base = 1; | |
cd30bcef AM |
1504 | READ_SLEB (svalue, data, end); |
1505 | printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1506 | break; |
1507 | case DW_OP_bregx: | |
cd30bcef AM |
1508 | READ_ULEB (uvalue, data, end); |
1509 | READ_SLEB (svalue, data, end); | |
467c65bc NC |
1510 | printf ("DW_OP_bregx: %s (%s) %s", |
1511 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
cd30bcef | 1512 | dwarf_vmatoa ("d", svalue)); |
19e6b90e L |
1513 | break; |
1514 | case DW_OP_piece: | |
cd30bcef AM |
1515 | READ_ULEB (uvalue, data, end); |
1516 | printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1517 | break; |
1518 | case DW_OP_deref_size: | |
0c588247 NC |
1519 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1520 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1521 | break; |
1522 | case DW_OP_xderef_size: | |
0c588247 NC |
1523 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1524 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1525 | break; |
1526 | case DW_OP_nop: | |
1527 | printf ("DW_OP_nop"); | |
1528 | break; | |
1529 | ||
1530 | /* DWARF 3 extensions. */ | |
1531 | case DW_OP_push_object_address: | |
1532 | printf ("DW_OP_push_object_address"); | |
1533 | break; | |
1534 | case DW_OP_call2: | |
d85bf2ba | 1535 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1536 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1537 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1538 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1539 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1540 | break; |
1541 | case DW_OP_call4: | |
d85bf2ba | 1542 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1543 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1544 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1545 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1546 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1547 | break; |
1548 | case DW_OP_call_ref: | |
d85bf2ba | 1549 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
e2a0d921 | 1550 | this ought to be an 8-byte wide computation. */ |
b7807392 JJ |
1551 | if (dwarf_version == -1) |
1552 | { | |
1553 | printf (_("(DW_OP_call_ref in frame info)")); | |
1554 | /* No way to tell where the next op is, so just bail. */ | |
1555 | return need_frame_base; | |
1556 | } | |
1557 | if (dwarf_version == 2) | |
1558 | { | |
0c588247 | 1559 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1560 | } |
1561 | else | |
1562 | { | |
0c588247 | 1563 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1564 | } |
0c588247 | 1565 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1566 | break; |
a87b0a59 NS |
1567 | case DW_OP_form_tls_address: |
1568 | printf ("DW_OP_form_tls_address"); | |
1569 | break; | |
e2a0d921 NC |
1570 | case DW_OP_call_frame_cfa: |
1571 | printf ("DW_OP_call_frame_cfa"); | |
1572 | break; | |
1573 | case DW_OP_bit_piece: | |
1574 | printf ("DW_OP_bit_piece: "); | |
cd30bcef AM |
1575 | READ_ULEB (uvalue, data, end); |
1576 | printf (_("size: %s "), dwarf_vmatoa ("u", uvalue)); | |
1577 | READ_ULEB (uvalue, data, end); | |
1578 | printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue)); | |
e2a0d921 | 1579 | break; |
19e6b90e | 1580 | |
3244e8f5 JJ |
1581 | /* DWARF 4 extensions. */ |
1582 | case DW_OP_stack_value: | |
1583 | printf ("DW_OP_stack_value"); | |
1584 | break; | |
1585 | ||
1586 | case DW_OP_implicit_value: | |
1587 | printf ("DW_OP_implicit_value"); | |
cd30bcef | 1588 | READ_ULEB (uvalue, data, end); |
ef0b5f1c | 1589 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1590 | break; |
1591 | ||
19e6b90e L |
1592 | /* GNU extensions. */ |
1593 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1594 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1595 | break; |
1596 | case DW_OP_GNU_uninit: | |
1597 | printf ("DW_OP_GNU_uninit"); | |
1598 | /* FIXME: Is there data associated with this OP ? */ | |
1599 | break; | |
f1c4cc75 RH |
1600 | case DW_OP_GNU_encoded_addr: |
1601 | { | |
6937bb54 | 1602 | int encoding = 0; |
f1c4cc75 | 1603 | dwarf_vma addr; |
467c65bc | 1604 | |
6937bb54 NC |
1605 | if (data < end) |
1606 | encoding = *data++; | |
041830e0 | 1607 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1608 | |
1609 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1610 | print_dwarf_vma (addr, pointer_size); | |
1611 | } | |
1612 | break; | |
bc0a77d2 | 1613 | case DW_OP_implicit_pointer: |
b7807392 | 1614 | case DW_OP_GNU_implicit_pointer: |
d85bf2ba | 1615 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
b7807392 JJ |
1616 | this ought to be an 8-byte wide computation. */ |
1617 | if (dwarf_version == -1) | |
1618 | { | |
bc0a77d2 JK |
1619 | printf (_("(%s in frame info)"), |
1620 | (op == DW_OP_implicit_pointer | |
1621 | ? "DW_OP_implicit_pointer" | |
1622 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1623 | /* No way to tell where the next op is, so just bail. */ |
1624 | return need_frame_base; | |
1625 | } | |
1626 | if (dwarf_version == 2) | |
1627 | { | |
0c588247 | 1628 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1629 | } |
1630 | else | |
1631 | { | |
0c588247 | 1632 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1633 | } |
cd30bcef | 1634 | READ_SLEB (svalue, data, end); |
bc0a77d2 JK |
1635 | printf ("%s: <0x%s> %s", |
1636 | (op == DW_OP_implicit_pointer | |
1637 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 | 1638 | dwarf_vmatoa ("x", uvalue), |
cd30bcef | 1639 | dwarf_vmatoa ("d", svalue)); |
b7807392 | 1640 | break; |
77145576 | 1641 | case DW_OP_entry_value: |
0892011d | 1642 | case DW_OP_GNU_entry_value: |
cd30bcef | 1643 | READ_ULEB (uvalue, data, end); |
058037d3 NC |
1644 | /* PR 17531: file: 0cc9cd00. */ |
1645 | if (uvalue > (dwarf_vma) (end - data)) | |
1646 | uvalue = end - data; | |
77145576 JK |
1647 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1648 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1649 | if (decode_location_expression (data, pointer_size, offset_size, |
1650 | dwarf_version, uvalue, | |
1651 | cu_offset, section)) | |
1652 | need_frame_base = 1; | |
1653 | putchar (')'); | |
1654 | data += uvalue; | |
6937bb54 NC |
1655 | if (data > end) |
1656 | data = end; | |
0892011d | 1657 | break; |
bc0a77d2 | 1658 | case DW_OP_const_type: |
0892011d | 1659 | case DW_OP_GNU_const_type: |
cd30bcef | 1660 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1661 | printf ("%s: <0x%s> ", |
1662 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1663 | : "DW_OP_GNU_const_type"), | |
0892011d | 1664 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1665 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1666 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1667 | break; |
bc0a77d2 | 1668 | case DW_OP_regval_type: |
0892011d | 1669 | case DW_OP_GNU_regval_type: |
cd30bcef | 1670 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1671 | printf ("%s: %s (%s)", |
1672 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1673 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1674 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
cd30bcef | 1675 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1676 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1677 | break; | |
bc0a77d2 | 1678 | case DW_OP_deref_type: |
0892011d | 1679 | case DW_OP_GNU_deref_type: |
0c588247 | 1680 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1681 | printf ("%s: %ld", |
1682 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1683 | : "DW_OP_GNU_deref_type"), | |
1684 | (long) uvalue); | |
cd30bcef | 1685 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1686 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1687 | break; | |
bc0a77d2 | 1688 | case DW_OP_convert: |
0892011d | 1689 | case DW_OP_GNU_convert: |
cd30bcef | 1690 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1691 | printf ("%s <0x%s>", |
1692 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1693 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1694 | break; |
bc0a77d2 | 1695 | case DW_OP_reinterpret: |
0892011d | 1696 | case DW_OP_GNU_reinterpret: |
cd30bcef | 1697 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1698 | printf ("%s <0x%s>", |
1699 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1700 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1701 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1702 | break; | |
1703 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1704 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1705 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1706 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1707 | break; |
b4eb7656 | 1708 | case DW_OP_GNU_addr_index: |
cd30bcef | 1709 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1710 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1711 | break; | |
1712 | case DW_OP_GNU_const_index: | |
cd30bcef | 1713 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1714 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1715 | break; | |
f384a1f0 KB |
1716 | case DW_OP_GNU_variable_value: |
1717 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1718 | this ought to be an 8-byte wide computation. */ | |
1719 | if (dwarf_version == -1) | |
1720 | { | |
1721 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1722 | /* No way to tell where the next op is, so just bail. */ | |
1723 | return need_frame_base; | |
1724 | } | |
1725 | if (dwarf_version == 2) | |
1726 | { | |
1727 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1728 | } | |
1729 | else | |
1730 | { | |
1731 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1732 | } | |
1733 | printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1734 | break; | |
e2a0d921 NC |
1735 | |
1736 | /* HP extensions. */ | |
1737 | case DW_OP_HP_is_value: | |
1738 | printf ("DW_OP_HP_is_value"); | |
1739 | /* FIXME: Is there data associated with this OP ? */ | |
1740 | break; | |
1741 | case DW_OP_HP_fltconst4: | |
1742 | printf ("DW_OP_HP_fltconst4"); | |
1743 | /* FIXME: Is there data associated with this OP ? */ | |
1744 | break; | |
1745 | case DW_OP_HP_fltconst8: | |
1746 | printf ("DW_OP_HP_fltconst8"); | |
1747 | /* FIXME: Is there data associated with this OP ? */ | |
1748 | break; | |
1749 | case DW_OP_HP_mod_range: | |
1750 | printf ("DW_OP_HP_mod_range"); | |
1751 | /* FIXME: Is there data associated with this OP ? */ | |
1752 | break; | |
1753 | case DW_OP_HP_unmod_range: | |
1754 | printf ("DW_OP_HP_unmod_range"); | |
1755 | /* FIXME: Is there data associated with this OP ? */ | |
1756 | break; | |
1757 | case DW_OP_HP_tls: | |
1758 | printf ("DW_OP_HP_tls"); | |
1759 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1760 | break; |
1761 | ||
35d60fe4 NC |
1762 | /* PGI (STMicroelectronics) extensions. */ |
1763 | case DW_OP_PGI_omp_thread_num: | |
1764 | /* Pushes the thread number for the current thread as it would be | |
1765 | returned by the standard OpenMP library function: | |
1766 | omp_get_thread_num(). The "current thread" is the thread for | |
1767 | which the expression is being evaluated. */ | |
1768 | printf ("DW_OP_PGI_omp_thread_num"); | |
1769 | break; | |
1770 | ||
19e6b90e L |
1771 | default: |
1772 | if (op >= DW_OP_lo_user | |
1773 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1774 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1775 | else |
0502a2b4 | 1776 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1777 | /* No way to tell where the next op is, so just bail. */ |
1778 | return need_frame_base; | |
1779 | } | |
1780 | ||
1781 | /* Separate the ops. */ | |
1782 | if (data < end) | |
1783 | printf ("; "); | |
1784 | } | |
1785 | ||
1786 | return need_frame_base; | |
1787 | } | |
1788 | ||
341f9135 CC |
1789 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1790 | This is used for DWARF package files. */ | |
1791 | ||
1792 | static struct cu_tu_set * | |
1793 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1794 | { | |
1795 | struct cu_tu_set *p; | |
1796 | unsigned int nsets; | |
1797 | unsigned int dw_sect; | |
1798 | ||
1799 | if (do_types) | |
1800 | { | |
1801 | p = tu_sets; | |
1802 | nsets = tu_count; | |
1803 | dw_sect = DW_SECT_TYPES; | |
1804 | } | |
1805 | else | |
1806 | { | |
1807 | p = cu_sets; | |
1808 | nsets = cu_count; | |
1809 | dw_sect = DW_SECT_INFO; | |
1810 | } | |
1811 | while (nsets > 0) | |
1812 | { | |
1813 | if (p->section_offsets [dw_sect] == cu_offset) | |
1814 | return p; | |
1815 | p++; | |
1816 | nsets--; | |
1817 | } | |
1818 | return NULL; | |
1819 | } | |
1820 | ||
a69c4772 NC |
1821 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1822 | static void | |
1823 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1824 | { | |
1825 | dwarf_vma tmp = * low_bits; | |
1826 | ||
1827 | tmp += inc; | |
1828 | ||
1829 | /* FIXME: There is probably a better way of handling this: | |
1830 | ||
1831 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1832 | type. Plus regardless of its size LOW_BITS is meant to | |
1833 | only hold 32-bits, so if there is overflow or wrap around | |
1834 | we must propagate into HIGH_BITS. */ | |
1835 | if (tmp < * low_bits) | |
1836 | { | |
1837 | ++ * high_bits; | |
1838 | } | |
1839 | else if (sizeof (tmp) > 8 | |
1840 | && (tmp >> 31) > 1) | |
1841 | { | |
1842 | ++ * high_bits; | |
1843 | tmp &= 0xFFFFFFFF; | |
1844 | } | |
1845 | ||
1846 | * low_bits = tmp; | |
1847 | } | |
1848 | ||
dda8d76d NC |
1849 | static const char * |
1850 | fetch_alt_indirect_string (dwarf_vma offset) | |
1851 | { | |
24841daa | 1852 | separate_info * i; |
dda8d76d NC |
1853 | |
1854 | if (! do_follow_links) | |
1855 | return ""; | |
1856 | ||
24841daa NC |
1857 | if (first_separate_info == NULL) |
1858 | return _("<no links available>"); | |
dda8d76d | 1859 | |
24841daa NC |
1860 | for (i = first_separate_info; i != NULL; i = i->next) |
1861 | { | |
1862 | struct dwarf_section * section; | |
1863 | const char * ret; | |
dda8d76d | 1864 | |
24841daa NC |
1865 | if (! load_debug_section (separate_debug_str, i->handle)) |
1866 | continue; | |
dda8d76d | 1867 | |
24841daa | 1868 | section = &debug_displays [separate_debug_str].section; |
dda8d76d | 1869 | |
24841daa NC |
1870 | if (section->start == NULL) |
1871 | continue; | |
dda8d76d | 1872 | |
24841daa NC |
1873 | if (offset >= section->size) |
1874 | continue; | |
1875 | ||
1876 | ret = (const char *) (section->start + offset); | |
1877 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1878 | NUL byte. Since our caller is expecting to receive a well formed C | |
1879 | string we test for the lack of a terminating byte here. */ | |
1880 | if (strnlen ((const char *) ret, section->size - offset) | |
1881 | == section->size - offset) | |
1882 | return _("<no NUL byte at end of alt .debug_str section>"); | |
1883 | ||
1884 | return ret; | |
1885 | } | |
521d4b19 | 1886 | |
24841daa NC |
1887 | warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"), |
1888 | dwarf_vmatoa ("x", offset)); | |
1889 | return _("<offset is too big>"); | |
dda8d76d NC |
1890 | } |
1891 | ||
d85bf2ba NC |
1892 | static const char * |
1893 | get_AT_name (unsigned long attribute) | |
1894 | { | |
1895 | const char *name; | |
1896 | ||
1897 | if (attribute == 0) | |
1898 | return "DW_AT value: 0"; | |
1899 | ||
1900 | /* One value is shared by the MIPS and HP extensions: */ | |
1901 | if (attribute == DW_AT_MIPS_fde) | |
1902 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1903 | ||
1904 | name = get_DW_AT_name (attribute); | |
1905 | ||
1906 | if (name == NULL) | |
1907 | { | |
1908 | static char buffer[100]; | |
1909 | ||
1910 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1911 | attribute); | |
1912 | return buffer; | |
1913 | } | |
1914 | ||
1915 | return name; | |
1916 | } | |
1917 | ||
24841daa | 1918 | static void |
50ea0877 | 1919 | add_dwo_info (const char * value, dwarf_vma cu_offset, dwo_type type) |
24841daa NC |
1920 | { |
1921 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); | |
1922 | ||
50ea0877 NC |
1923 | dwinfo->type = type; |
1924 | dwinfo->value = value; | |
1925 | dwinfo->cu_offset = cu_offset; | |
1926 | dwinfo->next = first_dwo_info; | |
24841daa NC |
1927 | first_dwo_info = dwinfo; |
1928 | } | |
1929 | ||
1930 | static void | |
50ea0877 | 1931 | add_dwo_name (const char * name, dwarf_vma cu_offset) |
24841daa | 1932 | { |
50ea0877 | 1933 | add_dwo_info (name, cu_offset, DWO_NAME); |
24841daa NC |
1934 | } |
1935 | ||
1936 | static void | |
50ea0877 | 1937 | add_dwo_dir (const char * dir, dwarf_vma cu_offset) |
24841daa | 1938 | { |
50ea0877 | 1939 | add_dwo_info (dir, cu_offset, DWO_DIR); |
24841daa NC |
1940 | } |
1941 | ||
1942 | static void | |
50ea0877 | 1943 | add_dwo_id (const char * id, dwarf_vma cu_offset) |
24841daa | 1944 | { |
50ea0877 | 1945 | add_dwo_info (id, cu_offset, DWO_ID); |
24841daa NC |
1946 | } |
1947 | ||
1948 | static void | |
1949 | free_dwo_info (void) | |
1950 | { | |
1951 | dwo_info * dwinfo; | |
1952 | dwo_info * next; | |
1953 | ||
1954 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) | |
1955 | { | |
1956 | next = dwinfo->next; | |
1957 | free (dwinfo); | |
1958 | } | |
1959 | first_dwo_info = NULL; | |
1960 | } | |
1961 | ||
afc72f15 NC |
1962 | /* Ensure that START + UVALUE is less than END. |
1963 | Return an adjusted UVALUE if necessary to ensure this relationship. */ | |
1964 | ||
1965 | static inline dwarf_vma | |
1966 | check_uvalue (const unsigned char * start, | |
1967 | dwarf_vma uvalue, | |
1968 | const unsigned char * end) | |
1969 | { | |
1970 | dwarf_vma max_uvalue = end - start; | |
1971 | ||
afc72f15 NC |
1972 | /* See PR 17512: file: 008-103549-0.001:0.1. |
1973 | and PR 24829 for examples of where these tests are triggered. */ | |
a85eba51 | 1974 | if (uvalue > max_uvalue) |
afc72f15 NC |
1975 | { |
1976 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1977 | uvalue = max_uvalue; | |
1978 | } | |
1979 | ||
1980 | return uvalue; | |
1981 | } | |
1982 | ||
ec1b0fbb NC |
1983 | static unsigned char * |
1984 | skip_attr_bytes (unsigned long form, | |
1985 | unsigned char * data, | |
1986 | unsigned const char * end, | |
1987 | dwarf_vma pointer_size, | |
1988 | dwarf_vma offset_size, | |
1989 | int dwarf_version, | |
1990 | dwarf_vma * value_return) | |
1991 | { | |
cd30bcef AM |
1992 | dwarf_signed_vma svalue; |
1993 | dwarf_vma uvalue = 0; | |
ec1b0fbb NC |
1994 | |
1995 | * value_return = 0; | |
1996 | ||
1997 | switch (form) | |
1998 | { | |
1999 | case DW_FORM_ref_addr: | |
2000 | if (dwarf_version == 2) | |
2001 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
59624513 | 2002 | else if (dwarf_version > 2) |
ec1b0fbb NC |
2003 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
2004 | else | |
2005 | return NULL; | |
2006 | break; | |
2007 | ||
2008 | case DW_FORM_addr: | |
2009 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
2010 | break; | |
2011 | ||
2012 | case DW_FORM_strp: | |
2013 | case DW_FORM_line_strp: | |
2014 | case DW_FORM_sec_offset: | |
2015 | case DW_FORM_GNU_ref_alt: | |
2016 | case DW_FORM_GNU_strp_alt: | |
2017 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
2018 | break; | |
2019 | ||
2020 | case DW_FORM_flag_present: | |
2021 | uvalue = 1; | |
2022 | break; | |
2023 | ||
2024 | case DW_FORM_ref1: | |
2025 | case DW_FORM_flag: | |
2026 | case DW_FORM_data1: | |
32e4f96c TV |
2027 | case DW_FORM_strx1: |
2028 | case DW_FORM_addrx1: | |
ec1b0fbb NC |
2029 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2030 | break; | |
2031 | ||
32e4f96c TV |
2032 | case DW_FORM_strx3: |
2033 | case DW_FORM_addrx3: | |
2034 | SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); | |
2035 | break; | |
2036 | ||
ec1b0fbb NC |
2037 | case DW_FORM_ref2: |
2038 | case DW_FORM_data2: | |
32e4f96c TV |
2039 | case DW_FORM_strx2: |
2040 | case DW_FORM_addrx2: | |
ec1b0fbb NC |
2041 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2042 | break; | |
2043 | ||
2044 | case DW_FORM_ref4: | |
2045 | case DW_FORM_data4: | |
32e4f96c TV |
2046 | case DW_FORM_strx4: |
2047 | case DW_FORM_addrx4: | |
ec1b0fbb NC |
2048 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2049 | break; | |
2050 | ||
2051 | case DW_FORM_sdata: | |
cd30bcef AM |
2052 | READ_SLEB (svalue, data, end); |
2053 | uvalue = svalue; | |
ec1b0fbb NC |
2054 | break; |
2055 | ||
2056 | case DW_FORM_ref_udata: | |
2057 | case DW_FORM_udata: | |
2058 | case DW_FORM_GNU_str_index: | |
32e4f96c | 2059 | case DW_FORM_strx: |
ec1b0fbb | 2060 | case DW_FORM_GNU_addr_index: |
32e4f96c | 2061 | case DW_FORM_addrx: |
cd30bcef | 2062 | READ_ULEB (uvalue, data, end); |
ec1b0fbb NC |
2063 | break; |
2064 | ||
2065 | case DW_FORM_ref8: | |
1f573141 NC |
2066 | { |
2067 | dwarf_vma high_bits; | |
2068 | ||
2069 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); | |
2070 | data += 8; | |
2071 | if (sizeof (uvalue) > 4) | |
2072 | uvalue += high_bits << 32; | |
2073 | else if (high_bits != 0) | |
2074 | { | |
2075 | /* FIXME: What to do ? */ | |
2076 | return NULL; | |
2077 | } | |
2078 | break; | |
2079 | } | |
2080 | ||
ec1b0fbb | 2081 | case DW_FORM_data8: |
59624513 | 2082 | case DW_FORM_ref_sig8: |
ec1b0fbb NC |
2083 | data += 8; |
2084 | break; | |
2085 | ||
2086 | case DW_FORM_data16: | |
2087 | data += 16; | |
2088 | break; | |
2089 | ||
2090 | case DW_FORM_string: | |
2091 | data += strnlen ((char *) data, end - data) + 1; | |
2092 | break; | |
2093 | ||
2094 | case DW_FORM_block: | |
2095 | case DW_FORM_exprloc: | |
cd30bcef | 2096 | READ_ULEB (uvalue, data, end); |
59624513 | 2097 | data += uvalue; |
ec1b0fbb NC |
2098 | break; |
2099 | ||
2100 | case DW_FORM_block1: | |
2101 | SAFE_BYTE_GET (uvalue, data, 1, end); | |
2102 | data += 1 + uvalue; | |
2103 | break; | |
2104 | ||
2105 | case DW_FORM_block2: | |
2106 | SAFE_BYTE_GET (uvalue, data, 2, end); | |
2107 | data += 2 + uvalue; | |
2108 | break; | |
2109 | ||
2110 | case DW_FORM_block4: | |
2111 | SAFE_BYTE_GET (uvalue, data, 4, end); | |
2112 | data += 4 + uvalue; | |
2113 | break; | |
2114 | ||
ec1b0fbb | 2115 | case DW_FORM_indirect: |
59624513 NC |
2116 | READ_ULEB (form, data, end); |
2117 | if (form == DW_FORM_implicit_const) | |
2118 | SKIP_ULEB (data, end); | |
2119 | return skip_attr_bytes (form, data, end, pointer_size, offset_size, dwarf_version, value_return); | |
2120 | ||
ec1b0fbb NC |
2121 | default: |
2122 | return NULL; | |
2123 | } | |
2124 | ||
2125 | * value_return = uvalue; | |
2126 | if (data > end) | |
2127 | data = (unsigned char *) end; | |
2128 | return data; | |
2129 | } | |
2130 | ||
bcd213b2 NC |
2131 | /* Given form FORM with value UVALUE, locate and return the abbreviation |
2132 | associated with it. */ | |
2133 | ||
2134 | static abbrev_entry * | |
2135 | get_type_abbrev_from_form (unsigned long form, | |
2136 | unsigned long uvalue, | |
2137 | dwarf_vma cu_offset, | |
2138 | const struct dwarf_section * section, | |
2139 | unsigned long * abbrev_num_return, | |
2140 | unsigned char ** data_return, | |
2141 | unsigned long * cu_offset_return) | |
2142 | { | |
2143 | unsigned long abbrev_number; | |
2144 | abbrev_map * map; | |
2145 | abbrev_entry * entry; | |
2146 | unsigned char * data; | |
2147 | ||
2148 | if (abbrev_num_return != NULL) | |
2149 | * abbrev_num_return = 0; | |
2150 | if (data_return != NULL) | |
2151 | * data_return = NULL; | |
2152 | ||
2153 | switch (form) | |
2154 | { | |
2155 | case DW_FORM_GNU_ref_alt: | |
5f128a25 | 2156 | case DW_FORM_ref_sig8: |
bcd213b2 NC |
2157 | /* FIXME: We are unable to handle this form at the moment. */ |
2158 | return NULL; | |
2159 | ||
2160 | case DW_FORM_ref_addr: | |
2161 | if (uvalue >= section->size) | |
2162 | { | |
2163 | warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"), | |
2164 | uvalue, (long) section->size, section->name); | |
2165 | return NULL; | |
2166 | } | |
2167 | break; | |
2168 | ||
e38332c2 NC |
2169 | case DW_FORM_ref_sup4: |
2170 | case DW_FORM_ref_sup8: | |
2171 | break; | |
2172 | ||
bcd213b2 NC |
2173 | case DW_FORM_ref1: |
2174 | case DW_FORM_ref2: | |
2175 | case DW_FORM_ref4: | |
1f573141 | 2176 | case DW_FORM_ref8: |
bcd213b2 NC |
2177 | case DW_FORM_ref_udata: |
2178 | if (uvalue + cu_offset > section->size) | |
2179 | { | |
2180 | warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > section size %lx\n"), | |
2181 | uvalue, (long) cu_offset, (long) section->size); | |
2182 | return NULL; | |
2183 | } | |
2184 | uvalue += cu_offset; | |
2185 | break; | |
2186 | ||
2187 | /* FIXME: Are there other DW_FORMs that can be used by types ? */ | |
2188 | ||
2189 | default: | |
2190 | warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form); | |
2191 | return NULL; | |
2192 | } | |
2193 | ||
2194 | data = (unsigned char *) section->start + uvalue; | |
2195 | map = find_abbrev_map_by_offset (uvalue); | |
521d4b19 | 2196 | |
bcd213b2 NC |
2197 | if (map == NULL) |
2198 | { | |
2199 | warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue); | |
2200 | return NULL; | |
2201 | } | |
2202 | if (map->list == NULL) | |
2203 | { | |
2204 | warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue); | |
2205 | return NULL; | |
2206 | } | |
2207 | ||
2208 | if (cu_offset_return != NULL) | |
2209 | { | |
2210 | if (form == DW_FORM_ref_addr) | |
2211 | * cu_offset_return = map->start; | |
2212 | else | |
2213 | * cu_offset_return = cu_offset; | |
2214 | } | |
2215 | ||
2216 | READ_ULEB (abbrev_number, data, section->start + section->size); | |
2217 | ||
2218 | for (entry = map->list->first_abbrev; entry != NULL; entry = entry->next) | |
2219 | if (entry->number == abbrev_number) | |
2220 | break; | |
521d4b19 | 2221 | |
bcd213b2 NC |
2222 | if (abbrev_num_return != NULL) |
2223 | * abbrev_num_return = abbrev_number; | |
2224 | ||
2225 | if (data_return != NULL) | |
2226 | * data_return = data; | |
2227 | ||
2228 | if (entry == NULL) | |
2229 | warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number); | |
2230 | ||
2231 | return entry; | |
2232 | } | |
2233 | ||
2234 | /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY | |
2235 | can be determined to be a signed type. The data for ENTRY can be | |
2236 | found starting at DATA. */ | |
ec1b0fbb NC |
2237 | |
2238 | static void | |
015dc7e1 AM |
2239 | get_type_signedness (abbrev_entry *entry, |
2240 | const struct dwarf_section *section, | |
2241 | unsigned char *data, | |
2242 | unsigned const char *end, | |
2243 | dwarf_vma cu_offset, | |
2244 | dwarf_vma pointer_size, | |
2245 | dwarf_vma offset_size, | |
2246 | int dwarf_version, | |
2247 | bool *is_signed, | |
2248 | unsigned int nesting) | |
ec1b0fbb | 2249 | { |
ec1b0fbb NC |
2250 | abbrev_attr * attr; |
2251 | ||
015dc7e1 | 2252 | * is_signed = false; |
ec1b0fbb | 2253 | |
59624513 NC |
2254 | #define MAX_NESTING 20 |
2255 | if (nesting > MAX_NESTING) | |
2256 | { | |
2257 | /* FIXME: Warn - or is this expected ? | |
2258 | NB/ We need to avoid infinite recursion. */ | |
2259 | return; | |
2260 | } | |
2261 | ||
ec1b0fbb NC |
2262 | for (attr = entry->first_attr; |
2263 | attr != NULL && attr->attribute; | |
2264 | attr = attr->next) | |
2265 | { | |
bcd213b2 | 2266 | unsigned char * orig_data = data; |
ec1b0fbb NC |
2267 | dwarf_vma uvalue = 0; |
2268 | ||
2269 | data = skip_attr_bytes (attr->form, data, end, pointer_size, | |
2270 | offset_size, dwarf_version, & uvalue); | |
2271 | if (data == NULL) | |
2272 | return; | |
2273 | ||
2274 | switch (attr->attribute) | |
2275 | { | |
bcd213b2 | 2276 | case DW_AT_linkage_name: |
ec1b0fbb | 2277 | case DW_AT_name: |
bcd213b2 NC |
2278 | if (do_wide) |
2279 | { | |
2280 | if (attr->form == DW_FORM_strp) | |
2281 | printf (", %s", fetch_indirect_string (uvalue)); | |
2282 | else if (attr->form == DW_FORM_string) | |
2283 | printf (", %s", orig_data); | |
2284 | } | |
ec1b0fbb | 2285 | break; |
bcd213b2 | 2286 | |
ec1b0fbb NC |
2287 | case DW_AT_type: |
2288 | /* Recurse. */ | |
bcd213b2 NC |
2289 | { |
2290 | abbrev_entry * type_abbrev; | |
2291 | unsigned char * type_data; | |
2292 | unsigned long type_cu_offset; | |
2293 | ||
2294 | type_abbrev = get_type_abbrev_from_form (attr->form, | |
2295 | uvalue, | |
2296 | cu_offset, | |
2297 | section, | |
2298 | NULL /* abbrev num return */, | |
2299 | & type_data, | |
2300 | & type_cu_offset); | |
2301 | if (type_abbrev == NULL) | |
2302 | break; | |
2303 | ||
2304 | get_type_signedness (type_abbrev, section, type_data, end, type_cu_offset, | |
2305 | pointer_size, offset_size, dwarf_version, | |
2306 | is_signed, nesting + 1); | |
2307 | } | |
ec1b0fbb NC |
2308 | break; |
2309 | ||
2310 | case DW_AT_encoding: | |
2311 | /* Determine signness. */ | |
2312 | switch (uvalue) | |
2313 | { | |
2314 | case DW_ATE_address: | |
2315 | /* FIXME - some architectures have signed addresses. */ | |
2316 | case DW_ATE_boolean: | |
2317 | case DW_ATE_unsigned: | |
2318 | case DW_ATE_unsigned_char: | |
2319 | case DW_ATE_unsigned_fixed: | |
015dc7e1 | 2320 | * is_signed = false; |
ec1b0fbb NC |
2321 | break; |
2322 | ||
2323 | default: | |
2324 | case DW_ATE_complex_float: | |
2325 | case DW_ATE_float: | |
2326 | case DW_ATE_signed: | |
2327 | case DW_ATE_signed_char: | |
2328 | case DW_ATE_imaginary_float: | |
2329 | case DW_ATE_decimal_float: | |
2330 | case DW_ATE_signed_fixed: | |
015dc7e1 | 2331 | * is_signed = true; |
ec1b0fbb NC |
2332 | break; |
2333 | } | |
2334 | break; | |
2335 | } | |
2336 | } | |
2337 | } | |
2338 | ||
2339 | static void | |
015dc7e1 AM |
2340 | read_and_print_leb128 (unsigned char *data, |
2341 | unsigned int *bytes_read, | |
2342 | unsigned const char *end, | |
2343 | bool is_signed) | |
ec1b0fbb | 2344 | { |
cd30bcef AM |
2345 | int status; |
2346 | dwarf_vma val = read_leb128 (data, end, is_signed, bytes_read, &status); | |
2347 | if (status != 0) | |
1b513401 | 2348 | report_leb_status (status, __FILE__, __LINE__); |
ec1b0fbb | 2349 | else |
cd30bcef | 2350 | printf ("%s", dwarf_vmatoa (is_signed ? "d" : "u", val)); |
ec1b0fbb NC |
2351 | } |
2352 | ||
2353 | static void | |
2354 | display_discr_list (unsigned long form, | |
2355 | dwarf_vma uvalue, | |
2356 | unsigned char * data, | |
2357 | unsigned const char * end, | |
2358 | int level) | |
2359 | { | |
2360 | if (uvalue == 0) | |
2361 | { | |
2362 | printf ("[default]"); | |
2363 | return; | |
2364 | } | |
521d4b19 | 2365 | |
ec1b0fbb NC |
2366 | switch (form) |
2367 | { | |
2368 | case DW_FORM_block: | |
2369 | case DW_FORM_block1: | |
2370 | case DW_FORM_block2: | |
2371 | case DW_FORM_block4: | |
2372 | /* Move data pointer back to the start of the byte array. */ | |
2373 | data -= uvalue; | |
2374 | break; | |
2375 | default: | |
2376 | printf ("<corrupt>\n"); | |
2377 | warn (_("corrupt discr_list - not using a block form\n")); | |
2378 | return; | |
2379 | } | |
2380 | ||
2381 | if (uvalue < 2) | |
2382 | { | |
2383 | printf ("<corrupt>\n"); | |
2384 | warn (_("corrupt discr_list - block not long enough\n")); | |
2385 | return; | |
2386 | } | |
2387 | ||
015dc7e1 | 2388 | bool is_signed = |
ec1b0fbb | 2389 | (level > 0 && level <= MAX_CU_NESTING) |
015dc7e1 | 2390 | ? level_type_signed [level - 1] : false; |
521d4b19 | 2391 | |
ec1b0fbb NC |
2392 | printf ("("); |
2393 | while (uvalue) | |
2394 | { | |
2395 | unsigned char discriminant; | |
2396 | unsigned int bytes_read; | |
2397 | ||
2398 | SAFE_BYTE_GET (discriminant, data, 1, end); | |
2399 | -- uvalue; | |
2400 | data ++; | |
2401 | ||
2402 | assert (uvalue > 0); | |
2403 | switch (discriminant) | |
2404 | { | |
2405 | case DW_DSC_label: | |
2406 | printf ("label "); | |
2407 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2408 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2409 | uvalue -= bytes_read; | |
2410 | data += bytes_read; | |
2411 | break; | |
2412 | ||
2413 | case DW_DSC_range: | |
2414 | printf ("range "); | |
2415 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2416 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2417 | uvalue -= bytes_read; | |
2418 | data += bytes_read; | |
2419 | ||
2420 | printf (".."); | |
2421 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2422 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2423 | uvalue -= bytes_read; | |
2424 | data += bytes_read; | |
2425 | break; | |
2426 | ||
2427 | default: | |
2428 | printf ("<corrupt>\n"); | |
e38332c2 | 2429 | warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"), |
ec1b0fbb NC |
2430 | discriminant); |
2431 | return; | |
2432 | } | |
2433 | ||
2434 | if (uvalue) | |
2435 | printf (", "); | |
2436 | } | |
2437 | ||
2438 | if (is_signed) | |
2439 | printf (")(signed)"); | |
2440 | else | |
2441 | printf (")(unsigned)"); | |
2442 | } | |
2443 | ||
19e6b90e | 2444 | static unsigned char * |
dda8d76d NC |
2445 | read_and_display_attr_value (unsigned long attribute, |
2446 | unsigned long form, | |
2447 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 2448 | unsigned char * start, |
dda8d76d NC |
2449 | unsigned char * data, |
2450 | unsigned char * end, | |
2451 | dwarf_vma cu_offset, | |
2452 | dwarf_vma pointer_size, | |
2453 | dwarf_vma offset_size, | |
2454 | int dwarf_version, | |
2455 | debug_info * debug_info_p, | |
2456 | int do_loc, | |
2457 | struct dwarf_section * section, | |
2458 | struct cu_tu_set * this_set, | |
ec1b0fbb NC |
2459 | char delimiter, |
2460 | int level) | |
19e6b90e | 2461 | { |
cd30bcef | 2462 | dwarf_signed_vma svalue; |
ec1b0fbb NC |
2463 | dwarf_vma uvalue = 0; |
2464 | unsigned char * block_start = NULL; | |
2465 | unsigned char * orig_data = data; | |
19e6b90e | 2466 | |
f41e4712 | 2467 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 2468 | { |
f41e4712 | 2469 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
2470 | return data; |
2471 | } | |
2472 | ||
521d4b19 NC |
2473 | if (do_wide && ! do_loc) |
2474 | { | |
2475 | /* PR 26847: Display the name of the form. */ | |
2476 | const char * name = get_FORM_name (form); | |
2477 | ||
2478 | /* For convenience we skip the DW_FORM_ prefix to the name. */ | |
2479 | if (name[0] == 'D') | |
2480 | name += 8; /* strlen ("DW_FORM_") */ | |
2481 | printf ("%c(%s)", delimiter, name); | |
2482 | } | |
2483 | ||
19e6b90e L |
2484 | switch (form) |
2485 | { | |
2486 | default: | |
2487 | break; | |
2488 | ||
2489 | case DW_FORM_ref_addr: | |
2490 | if (dwarf_version == 2) | |
0c588247 | 2491 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
ec47b32a | 2492 | else if (dwarf_version > 2) |
0c588247 | 2493 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 2494 | else |
ec47b32a | 2495 | error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n")); |
19e6b90e L |
2496 | break; |
2497 | ||
2498 | case DW_FORM_addr: | |
0c588247 | 2499 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
2500 | break; |
2501 | ||
e38332c2 | 2502 | case DW_FORM_strp_sup: |
19e6b90e | 2503 | case DW_FORM_strp: |
77145576 | 2504 | case DW_FORM_line_strp: |
932fd279 | 2505 | case DW_FORM_sec_offset: |
a081f3cd JJ |
2506 | case DW_FORM_GNU_ref_alt: |
2507 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 2508 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
2509 | break; |
2510 | ||
932fd279 JJ |
2511 | case DW_FORM_flag_present: |
2512 | uvalue = 1; | |
2513 | break; | |
2514 | ||
19e6b90e L |
2515 | case DW_FORM_ref1: |
2516 | case DW_FORM_flag: | |
2517 | case DW_FORM_data1: | |
32e4f96c TV |
2518 | case DW_FORM_strx1: |
2519 | case DW_FORM_addrx1: | |
0c588247 | 2520 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
2521 | break; |
2522 | ||
2523 | case DW_FORM_ref2: | |
2524 | case DW_FORM_data2: | |
32e4f96c TV |
2525 | case DW_FORM_strx2: |
2526 | case DW_FORM_addrx2: | |
0c588247 | 2527 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
2528 | break; |
2529 | ||
32e4f96c TV |
2530 | case DW_FORM_strx3: |
2531 | case DW_FORM_addrx3: | |
2532 | SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); | |
2533 | break; | |
2534 | ||
e38332c2 | 2535 | case DW_FORM_ref_sup4: |
19e6b90e L |
2536 | case DW_FORM_ref4: |
2537 | case DW_FORM_data4: | |
32e4f96c TV |
2538 | case DW_FORM_strx4: |
2539 | case DW_FORM_addrx4: | |
0c588247 | 2540 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
2541 | break; |
2542 | ||
2543 | case DW_FORM_sdata: | |
cd30bcef AM |
2544 | READ_SLEB (svalue, data, end); |
2545 | uvalue = svalue; | |
19e6b90e L |
2546 | break; |
2547 | ||
4723351a | 2548 | case DW_FORM_GNU_str_index: |
32e4f96c | 2549 | case DW_FORM_strx: |
19e6b90e L |
2550 | case DW_FORM_ref_udata: |
2551 | case DW_FORM_udata: | |
cd30bcef | 2552 | case DW_FORM_GNU_addr_index: |
32e4f96c | 2553 | case DW_FORM_addrx: |
cd30bcef | 2554 | READ_ULEB (uvalue, data, end); |
19e6b90e L |
2555 | break; |
2556 | ||
2557 | case DW_FORM_indirect: | |
cd30bcef | 2558 | READ_ULEB (form, data, end); |
19e6b90e | 2559 | if (!do_loc) |
ef0b5f1c | 2560 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 | 2561 | if (form == DW_FORM_implicit_const) |
cd30bcef | 2562 | READ_SLEB (implicit_const, data, end); |
ec1b0fbb NC |
2563 | return read_and_display_attr_value (attribute, form, implicit_const, |
2564 | start, data, end, | |
2565 | cu_offset, pointer_size, | |
19e6b90e | 2566 | offset_size, dwarf_version, |
ec4d4525 | 2567 | debug_info_p, do_loc, |
ec1b0fbb | 2568 | section, this_set, delimiter, level); |
19e6b90e L |
2569 | } |
2570 | ||
2571 | switch (form) | |
2572 | { | |
2573 | case DW_FORM_ref_addr: | |
2574 | if (!do_loc) | |
bcd213b2 | 2575 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2576 | break; |
2577 | ||
a081f3cd JJ |
2578 | case DW_FORM_GNU_ref_alt: |
2579 | if (!do_loc) | |
521d4b19 NC |
2580 | { |
2581 | if (do_wide) | |
2582 | /* We have already printed the form name. */ | |
2583 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); | |
2584 | else | |
2585 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); | |
2586 | } | |
dda8d76d | 2587 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
2588 | break; |
2589 | ||
19e6b90e L |
2590 | case DW_FORM_ref1: |
2591 | case DW_FORM_ref2: | |
2592 | case DW_FORM_ref4: | |
e38332c2 | 2593 | case DW_FORM_ref_sup4: |
19e6b90e L |
2594 | case DW_FORM_ref_udata: |
2595 | if (!do_loc) | |
ef0b5f1c | 2596 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
2597 | break; |
2598 | ||
2599 | case DW_FORM_data4: | |
2600 | case DW_FORM_addr: | |
932fd279 | 2601 | case DW_FORM_sec_offset: |
19e6b90e | 2602 | if (!do_loc) |
ef0b5f1c | 2603 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2604 | break; |
2605 | ||
932fd279 | 2606 | case DW_FORM_flag_present: |
19e6b90e L |
2607 | case DW_FORM_flag: |
2608 | case DW_FORM_data1: | |
2609 | case DW_FORM_data2: | |
2610 | case DW_FORM_sdata: | |
2611 | case DW_FORM_udata: | |
2612 | if (!do_loc) | |
ef0b5f1c | 2613 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
2614 | break; |
2615 | ||
77145576 JK |
2616 | case DW_FORM_implicit_const: |
2617 | if (!do_loc) | |
2618 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
2619 | break; | |
2620 | ||
e38332c2 | 2621 | case DW_FORM_ref_sup8: |
19e6b90e L |
2622 | case DW_FORM_ref8: |
2623 | case DW_FORM_data8: | |
2bc8690c | 2624 | if (!do_loc) |
19e6b90e | 2625 | { |
74bc6052 | 2626 | dwarf_vma high_bits; |
a69c4772 | 2627 | dwarf_vma utmp; |
74bc6052 CC |
2628 | char buf[64]; |
2629 | ||
0c588247 | 2630 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
2631 | utmp = uvalue; |
2632 | if (form == DW_FORM_ref8) | |
2633 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 2634 | printf ("%c0x%s", delimiter, |
a69c4772 | 2635 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 2636 | } |
0c588247 | 2637 | |
19e6b90e L |
2638 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2639 | && num_debug_info_entries == 0) | |
2640 | { | |
2641 | if (sizeof (uvalue) == 8) | |
0c588247 | 2642 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 2643 | else |
467c65bc | 2644 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 2645 | } |
0c588247 | 2646 | |
19e6b90e L |
2647 | data += 8; |
2648 | break; | |
2649 | ||
2f6cd591 JK |
2650 | case DW_FORM_data16: |
2651 | if (!do_loc) | |
2652 | { | |
2653 | dwarf_vma left_high_bits, left_low_bits; | |
2654 | dwarf_vma right_high_bits, right_low_bits; | |
2655 | ||
2656 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
2657 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
2658 | if (byte_get == byte_get_little_endian) | |
2659 | { | |
2660 | /* Swap them. */ | |
2661 | left_high_bits ^= right_high_bits; | |
2662 | right_high_bits ^= left_high_bits; | |
2663 | left_high_bits ^= right_high_bits; | |
2664 | left_low_bits ^= right_low_bits; | |
2665 | right_low_bits ^= left_low_bits; | |
2666 | left_low_bits ^= right_low_bits; | |
2667 | } | |
2668 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
2669 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
2670 | left_high_bits, left_low_bits, right_high_bits, | |
2671 | right_low_bits); | |
2672 | } | |
2673 | data += 16; | |
2674 | break; | |
2675 | ||
19e6b90e L |
2676 | case DW_FORM_string: |
2677 | if (!do_loc) | |
ef0b5f1c | 2678 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 2679 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
2680 | break; |
2681 | ||
2682 | case DW_FORM_block: | |
932fd279 | 2683 | case DW_FORM_exprloc: |
cd30bcef AM |
2684 | READ_ULEB (uvalue, data, end); |
2685 | do_block: | |
2686 | block_start = data; | |
a1165289 NC |
2687 | if (block_start >= end) |
2688 | { | |
2689 | warn (_("Block ends prematurely\n")); | |
2690 | uvalue = 0; | |
2691 | block_start = end; | |
2692 | } | |
afc72f15 NC |
2693 | |
2694 | uvalue = check_uvalue (block_start, uvalue, end); | |
2695 | ||
19e6b90e L |
2696 | if (do_loc) |
2697 | data = block_start + uvalue; | |
2698 | else | |
ef0b5f1c | 2699 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2700 | break; |
2701 | ||
2702 | case DW_FORM_block1: | |
cd30bcef AM |
2703 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2704 | goto do_block; | |
19e6b90e L |
2705 | |
2706 | case DW_FORM_block2: | |
cd30bcef AM |
2707 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2708 | goto do_block; | |
19e6b90e L |
2709 | |
2710 | case DW_FORM_block4: | |
cd30bcef AM |
2711 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2712 | goto do_block; | |
19e6b90e L |
2713 | |
2714 | case DW_FORM_strp: | |
2715 | if (!do_loc) | |
521d4b19 NC |
2716 | { |
2717 | if (do_wide) | |
2718 | /* We have already displayed the form name. */ | |
2719 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2720 | dwarf_vmatoa ("x", uvalue), | |
2721 | fetch_indirect_string (uvalue)); | |
2722 | else | |
2723 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, | |
2724 | dwarf_vmatoa ("x", uvalue), | |
2725 | fetch_indirect_string (uvalue)); | |
2726 | } | |
19e6b90e L |
2727 | break; |
2728 | ||
77145576 JK |
2729 | case DW_FORM_line_strp: |
2730 | if (!do_loc) | |
521d4b19 NC |
2731 | { |
2732 | if (do_wide) | |
2733 | /* We have already displayed the form name. */ | |
2734 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2735 | dwarf_vmatoa ("x", uvalue), | |
2736 | fetch_indirect_line_string (uvalue)); | |
2737 | else | |
2738 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2739 | dwarf_vmatoa ("x", uvalue), | |
2740 | fetch_indirect_line_string (uvalue)); | |
2741 | } | |
77145576 JK |
2742 | break; |
2743 | ||
4723351a | 2744 | case DW_FORM_GNU_str_index: |
32e4f96c TV |
2745 | case DW_FORM_strx: |
2746 | case DW_FORM_strx1: | |
2747 | case DW_FORM_strx2: | |
2748 | case DW_FORM_strx3: | |
2749 | case DW_FORM_strx4: | |
4723351a | 2750 | if (!do_loc) |
b4eb7656 | 2751 | { |
63b4cc53 | 2752 | const char *suffix = strrchr (section->name, '.'); |
015dc7e1 | 2753 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
b4eb7656 | 2754 | |
521d4b19 NC |
2755 | if (do_wide) |
2756 | /* We have already displayed the form name. */ | |
2757 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2758 | dwarf_vmatoa ("x", uvalue), | |
2759 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2760 | else | |
2761 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, | |
2762 | dwarf_vmatoa ("x", uvalue), | |
2763 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
b4eb7656 | 2764 | } |
4723351a CC |
2765 | break; |
2766 | ||
a081f3cd JJ |
2767 | case DW_FORM_GNU_strp_alt: |
2768 | if (!do_loc) | |
dda8d76d | 2769 | { |
521d4b19 NC |
2770 | if (do_wide) |
2771 | /* We have already displayed the form name. */ | |
2772 | printf (_("%c(offset: 0x%s) %s"), delimiter, | |
2773 | dwarf_vmatoa ("x", uvalue), | |
2774 | fetch_alt_indirect_string (uvalue)); | |
2775 | else | |
2776 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2777 | dwarf_vmatoa ("x", uvalue), | |
2778 | fetch_alt_indirect_string (uvalue)); | |
dda8d76d | 2779 | } |
a081f3cd JJ |
2780 | break; |
2781 | ||
19e6b90e L |
2782 | case DW_FORM_indirect: |
2783 | /* Handled above. */ | |
2784 | break; | |
2785 | ||
2b6f5997 CC |
2786 | case DW_FORM_ref_sig8: |
2787 | if (!do_loc) | |
2788 | { | |
74bc6052 CC |
2789 | dwarf_vma high_bits; |
2790 | char buf[64]; | |
2791 | ||
0c588247 | 2792 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
521d4b19 NC |
2793 | if (do_wide) |
2794 | /* We have already displayed the form name. */ | |
2795 | printf ("%c: 0x%s", delimiter, | |
2796 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); | |
2797 | else | |
2798 | printf ("%csignature: 0x%s", delimiter, | |
2799 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); | |
2b6f5997 | 2800 | } |
74bc6052 | 2801 | data += 8; |
2b6f5997 CC |
2802 | break; |
2803 | ||
4723351a | 2804 | case DW_FORM_GNU_addr_index: |
32e4f96c TV |
2805 | case DW_FORM_addrx: |
2806 | case DW_FORM_addrx1: | |
2807 | case DW_FORM_addrx2: | |
2808 | case DW_FORM_addrx3: | |
2809 | case DW_FORM_addrx4: | |
4723351a | 2810 | if (!do_loc) |
521d4b19 | 2811 | { |
32e4f96c TV |
2812 | dwarf_vma base; |
2813 | dwarf_vma offset; | |
2814 | ||
2815 | if (debug_info_p == NULL) | |
2816 | base = 0; | |
2817 | else if (debug_info_p->addr_base == DEBUG_INFO_UNAVAILABLE) | |
2818 | base = 0; | |
2819 | else | |
2820 | base = debug_info_p->addr_base; | |
2821 | ||
2822 | offset = base + uvalue * pointer_size; | |
2823 | ||
521d4b19 NC |
2824 | if (do_wide) |
2825 | /* We have already displayed the form name. */ | |
2826 | printf (_("%c(index: 0x%s): %s"), delimiter, | |
2827 | dwarf_vmatoa ("x", uvalue), | |
32e4f96c | 2828 | fetch_indexed_value (offset, pointer_size)); |
521d4b19 NC |
2829 | else |
2830 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, | |
2831 | dwarf_vmatoa ("x", uvalue), | |
32e4f96c | 2832 | fetch_indexed_value (offset, pointer_size)); |
521d4b19 | 2833 | } |
4723351a CC |
2834 | break; |
2835 | ||
e38332c2 NC |
2836 | case DW_FORM_strp_sup: |
2837 | if (!do_loc) | |
2838 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); | |
2839 | break; | |
2840 | ||
19e6b90e | 2841 | default: |
e38332c2 | 2842 | warn (_("Unrecognized form: 0x%lx\n"), form); |
19e6b90e L |
2843 | break; |
2844 | } | |
2845 | ||
19e6b90e | 2846 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2847 | && num_debug_info_entries == 0 |
2848 | && debug_info_p != NULL) | |
19e6b90e L |
2849 | { |
2850 | switch (attribute) | |
2851 | { | |
2852 | case DW_AT_frame_base: | |
2853 | have_frame_base = 1; | |
1a0670f3 | 2854 | /* Fall through. */ |
19e6b90e | 2855 | case DW_AT_location: |
9f272209 | 2856 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2857 | case DW_AT_string_length: |
2858 | case DW_AT_return_addr: | |
19e6b90e L |
2859 | case DW_AT_data_member_location: |
2860 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2861 | case DW_AT_segment: |
2862 | case DW_AT_static_link: | |
2863 | case DW_AT_use_location: | |
bc0a77d2 | 2864 | case DW_AT_call_value: |
629e7ca8 | 2865 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2866 | case DW_AT_call_data_value: |
629e7ca8 | 2867 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2868 | case DW_AT_call_target: |
629e7ca8 | 2869 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2870 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2871 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2872 | if ((dwarf_version < 4 |
212b6063 | 2873 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2874 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2875 | { |
2876 | /* Process location list. */ | |
91d6fa6a | 2877 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2878 | unsigned int num = debug_info_p->num_loc_offsets; |
2879 | ||
91d6fa6a | 2880 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2881 | { |
91d6fa6a | 2882 | lmax += 1024; |
467c65bc | 2883 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2884 | xcrealloc (debug_info_p->loc_offsets, |
2885 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2886 | debug_info_p->loc_views = (dwarf_vma *) |
2887 | xcrealloc (debug_info_p->loc_views, | |
2888 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2889 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2890 | xcrealloc (debug_info_p->have_frame_base, |
2891 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2892 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2893 | } |
341f9135 | 2894 | if (this_set != NULL) |
b4eb7656 | 2895 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2896 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2897 | if (attribute != DW_AT_GNU_locviews) |
2898 | { | |
a7504f87 NC |
2899 | /* Corrupt DWARF info can produce more offsets than views. |
2900 | See PR 23062 for an example. */ | |
2901 | if (debug_info_p->num_loc_offsets | |
2902 | > debug_info_p->num_loc_views) | |
2903 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2904 | else | |
2905 | { | |
2906 | debug_info_p->loc_offsets [num] = uvalue; | |
2907 | debug_info_p->num_loc_offsets++; | |
2908 | } | |
9f272209 AO |
2909 | } |
2910 | else | |
2911 | { | |
2912 | assert (debug_info_p->num_loc_views <= num); | |
2913 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2914 | if (num > debug_info_p->num_loc_offsets) |
2915 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2916 | else | |
2917 | { | |
2918 | debug_info_p->loc_views [num] = uvalue; | |
2919 | debug_info_p->num_loc_views++; | |
2920 | } | |
9f272209 | 2921 | } |
19e6b90e L |
2922 | } |
2923 | break; | |
e2a0d921 | 2924 | |
19e6b90e L |
2925 | case DW_AT_low_pc: |
2926 | if (need_base_address) | |
2927 | debug_info_p->base_address = uvalue; | |
2928 | break; | |
2929 | ||
4723351a | 2930 | case DW_AT_GNU_addr_base: |
32e4f96c | 2931 | case DW_AT_addr_base: |
b4eb7656 | 2932 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2933 | break; |
2934 | ||
2935 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2936 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2937 | break; |
2938 | ||
19e6b90e | 2939 | case DW_AT_ranges: |
b4eb7656 | 2940 | if ((dwarf_version < 4 |
212b6063 | 2941 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2942 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2943 | { |
2944 | /* Process range list. */ | |
91d6fa6a | 2945 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2946 | unsigned int num = debug_info_p->num_range_lists; |
2947 | ||
91d6fa6a | 2948 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2949 | { |
91d6fa6a | 2950 | lmax += 1024; |
467c65bc | 2951 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2952 | xcrealloc (debug_info_p->range_lists, |
2953 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2954 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2955 | } |
2956 | debug_info_p->range_lists [num] = uvalue; | |
2957 | debug_info_p->num_range_lists++; | |
2958 | } | |
2959 | break; | |
2960 | ||
d85bf2ba NC |
2961 | case DW_AT_GNU_dwo_name: |
2962 | case DW_AT_dwo_name: | |
2963 | if (need_dwo_info) | |
2964 | switch (form) | |
2965 | { | |
2966 | case DW_FORM_strp: | |
50ea0877 | 2967 | add_dwo_name ((const char *) fetch_indirect_string (uvalue), cu_offset); |
d85bf2ba | 2968 | break; |
5568cc9e | 2969 | case DW_FORM_GNU_strp_alt: |
50ea0877 | 2970 | add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue), cu_offset); |
5568cc9e | 2971 | break; |
d85bf2ba | 2972 | case DW_FORM_GNU_str_index: |
32e4f96c TV |
2973 | case DW_FORM_strx: |
2974 | case DW_FORM_strx1: | |
2975 | case DW_FORM_strx2: | |
2976 | case DW_FORM_strx3: | |
2977 | case DW_FORM_strx4: | |
015dc7e1 | 2978 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, false), cu_offset); |
d85bf2ba NC |
2979 | break; |
2980 | case DW_FORM_string: | |
50ea0877 | 2981 | add_dwo_name ((const char *) orig_data, cu_offset); |
d85bf2ba NC |
2982 | break; |
2983 | default: | |
2984 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2985 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2986 | break; |
2987 | } | |
2988 | break; | |
521d4b19 | 2989 | |
d85bf2ba NC |
2990 | case DW_AT_comp_dir: |
2991 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2992 | if (need_dwo_info) | |
2993 | switch (form) | |
2994 | { | |
2995 | case DW_FORM_strp: | |
50ea0877 | 2996 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue), cu_offset); |
d85bf2ba | 2997 | break; |
5568cc9e | 2998 | case DW_FORM_GNU_strp_alt: |
50ea0877 | 2999 | add_dwo_dir (fetch_alt_indirect_string (uvalue), cu_offset); |
5568cc9e | 3000 | break; |
d85bf2ba | 3001 | case DW_FORM_line_strp: |
50ea0877 | 3002 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue), cu_offset); |
d85bf2ba NC |
3003 | break; |
3004 | case DW_FORM_GNU_str_index: | |
32e4f96c TV |
3005 | case DW_FORM_strx: |
3006 | case DW_FORM_strx1: | |
3007 | case DW_FORM_strx2: | |
3008 | case DW_FORM_strx3: | |
3009 | case DW_FORM_strx4: | |
015dc7e1 | 3010 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, false), cu_offset); |
d85bf2ba NC |
3011 | break; |
3012 | case DW_FORM_string: | |
50ea0877 | 3013 | add_dwo_dir ((const char *) orig_data, cu_offset); |
d85bf2ba NC |
3014 | break; |
3015 | default: | |
3016 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
3017 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
3018 | break; |
3019 | } | |
3020 | break; | |
521d4b19 | 3021 | |
d85bf2ba NC |
3022 | case DW_AT_GNU_dwo_id: |
3023 | if (need_dwo_info) | |
3024 | switch (form) | |
3025 | { | |
3026 | case DW_FORM_data8: | |
24841daa | 3027 | /* FIXME: Record the length of the ID as well ? */ |
50ea0877 | 3028 | add_dwo_id ((const char *) (data - 8), cu_offset); |
d85bf2ba NC |
3029 | break; |
3030 | default: | |
3031 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
3032 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
3033 | break; |
3034 | } | |
3035 | break; | |
521d4b19 | 3036 | |
19e6b90e L |
3037 | default: |
3038 | break; | |
3039 | } | |
3040 | } | |
3041 | ||
4ccf1e31 | 3042 | if (do_loc || attribute == 0) |
19e6b90e L |
3043 | return data; |
3044 | ||
ec4d4525 | 3045 | /* For some attributes we can display further information. */ |
19e6b90e L |
3046 | switch (attribute) |
3047 | { | |
ec1b0fbb | 3048 | case DW_AT_type: |
b3fe587e AM |
3049 | if (level >= 0 && level < MAX_CU_NESTING |
3050 | && uvalue < (size_t) (end - start)) | |
ec1b0fbb | 3051 | { |
015dc7e1 AM |
3052 | bool is_signed = false; |
3053 | abbrev_entry *type_abbrev; | |
3054 | unsigned char *type_data; | |
3055 | unsigned long type_cu_offset; | |
521d4b19 | 3056 | |
bcd213b2 NC |
3057 | type_abbrev = get_type_abbrev_from_form (form, uvalue, cu_offset, |
3058 | section, NULL, & type_data, & type_cu_offset); | |
3059 | if (type_abbrev != NULL) | |
3060 | { | |
3061 | get_type_signedness (type_abbrev, section, type_data, end, type_cu_offset, | |
3062 | pointer_size, offset_size, dwarf_version, | |
3063 | & is_signed, 0); | |
3064 | } | |
ec1b0fbb NC |
3065 | level_type_signed[level] = is_signed; |
3066 | } | |
3067 | break; | |
521d4b19 | 3068 | |
19e6b90e | 3069 | case DW_AT_inline: |
2e9e81a8 | 3070 | printf ("\t"); |
19e6b90e L |
3071 | switch (uvalue) |
3072 | { | |
3073 | case DW_INL_not_inlined: | |
3074 | printf (_("(not inlined)")); | |
3075 | break; | |
3076 | case DW_INL_inlined: | |
3077 | printf (_("(inlined)")); | |
3078 | break; | |
3079 | case DW_INL_declared_not_inlined: | |
3080 | printf (_("(declared as inline but ignored)")); | |
3081 | break; | |
3082 | case DW_INL_declared_inlined: | |
3083 | printf (_("(declared as inline and inlined)")); | |
3084 | break; | |
3085 | default: | |
47704ddf KT |
3086 | printf (_(" (Unknown inline attribute value: %s)"), |
3087 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
3088 | break; |
3089 | } | |
3090 | break; | |
3091 | ||
3092 | case DW_AT_language: | |
2e9e81a8 | 3093 | printf ("\t"); |
19e6b90e L |
3094 | switch (uvalue) |
3095 | { | |
4b78141a | 3096 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 3097 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
3098 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
3099 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 3100 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
3101 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
3102 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
3103 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
3104 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 3105 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 3106 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 3107 | /* DWARF 2.1 values. */ |
4b78141a | 3108 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
3109 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
3110 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
3111 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
3112 | /* DWARF 3 values. */ |
3113 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
3114 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
3115 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
3116 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
3117 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
3118 | /* DWARF 4 values. */ |
3119 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 3120 | /* DWARF 5 values. */ |
2008a0db | 3121 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 3122 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
3123 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
3124 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
3125 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 3126 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
3127 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
3128 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 3129 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
3130 | case DW_LANG_Swift: printf ("(Swift)"); break; |
3131 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
3132 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 3133 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
3134 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
3135 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 3136 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
3137 | /* MIPS extension. */ |
3138 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
3139 | /* UPC extension. */ | |
3140 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
3141 | default: | |
4b78141a | 3142 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 3143 | printf (_("(implementation defined: %s)"), |
467c65bc | 3144 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 3145 | else |
9cf03b7e | 3146 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
3147 | break; |
3148 | } | |
3149 | break; | |
3150 | ||
3151 | case DW_AT_encoding: | |
2e9e81a8 | 3152 | printf ("\t"); |
19e6b90e L |
3153 | switch (uvalue) |
3154 | { | |
3155 | case DW_ATE_void: printf ("(void)"); break; | |
3156 | case DW_ATE_address: printf ("(machine address)"); break; | |
3157 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
3158 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
3159 | case DW_ATE_float: printf ("(float)"); break; | |
3160 | case DW_ATE_signed: printf ("(signed)"); break; | |
3161 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
3162 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
3163 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 3164 | /* DWARF 2.1 values: */ |
19e6b90e L |
3165 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
3166 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
3167 | /* DWARF 3 values: */ |
3168 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
3169 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
3170 | case DW_ATE_edited: printf ("(edited)"); break; | |
3171 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
3172 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
3173 | /* DWARF 4 values: */ |
3174 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
3175 | /* DWARF 5 values: */ | |
3176 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
3177 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
3178 | ||
e2a0d921 NC |
3179 | /* HP extensions: */ |
3180 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
3181 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
3182 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
3183 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
3184 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
3185 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
3186 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
3187 | ||
19e6b90e L |
3188 | default: |
3189 | if (uvalue >= DW_ATE_lo_user | |
3190 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 3191 | printf (_("(user defined type)")); |
19e6b90e | 3192 | else |
9cf03b7e | 3193 | printf (_("(unknown type)")); |
19e6b90e L |
3194 | break; |
3195 | } | |
3196 | break; | |
3197 | ||
3198 | case DW_AT_accessibility: | |
2e9e81a8 | 3199 | printf ("\t"); |
19e6b90e L |
3200 | switch (uvalue) |
3201 | { | |
3202 | case DW_ACCESS_public: printf ("(public)"); break; | |
3203 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
3204 | case DW_ACCESS_private: printf ("(private)"); break; | |
3205 | default: | |
9cf03b7e | 3206 | printf (_("(unknown accessibility)")); |
19e6b90e L |
3207 | break; |
3208 | } | |
3209 | break; | |
3210 | ||
3211 | case DW_AT_visibility: | |
2e9e81a8 | 3212 | printf ("\t"); |
19e6b90e L |
3213 | switch (uvalue) |
3214 | { | |
3215 | case DW_VIS_local: printf ("(local)"); break; | |
3216 | case DW_VIS_exported: printf ("(exported)"); break; | |
3217 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 3218 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
3219 | } |
3220 | break; | |
3221 | ||
04914e37 NC |
3222 | case DW_AT_endianity: |
3223 | printf ("\t"); | |
3224 | switch (uvalue) | |
3225 | { | |
3226 | case DW_END_default: printf ("(default)"); break; | |
3227 | case DW_END_big: printf ("(big)"); break; | |
3228 | case DW_END_little: printf ("(little)"); break; | |
3229 | default: | |
3230 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
3231 | printf (_("(user specified)")); | |
3232 | else | |
3233 | printf (_("(unknown endianity)")); | |
3234 | break; | |
3235 | } | |
3236 | break; | |
3237 | ||
19e6b90e | 3238 | case DW_AT_virtuality: |
2e9e81a8 | 3239 | printf ("\t"); |
19e6b90e L |
3240 | switch (uvalue) |
3241 | { | |
3242 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
3243 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
3244 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 3245 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
3246 | } |
3247 | break; | |
3248 | ||
3249 | case DW_AT_identifier_case: | |
2e9e81a8 | 3250 | printf ("\t"); |
19e6b90e L |
3251 | switch (uvalue) |
3252 | { | |
3253 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
3254 | case DW_ID_up_case: printf ("(up_case)"); break; | |
3255 | case DW_ID_down_case: printf ("(down_case)"); break; | |
3256 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 3257 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
3258 | } |
3259 | break; | |
3260 | ||
3261 | case DW_AT_calling_convention: | |
2e9e81a8 | 3262 | printf ("\t"); |
19e6b90e L |
3263 | switch (uvalue) |
3264 | { | |
3265 | case DW_CC_normal: printf ("(normal)"); break; | |
3266 | case DW_CC_program: printf ("(program)"); break; | |
3267 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
3268 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
3269 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
3270 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
3271 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
3272 | default: |
3273 | if (uvalue >= DW_CC_lo_user | |
3274 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 3275 | printf (_("(user defined)")); |
19e6b90e | 3276 | else |
9cf03b7e | 3277 | printf (_("(unknown convention)")); |
19e6b90e L |
3278 | } |
3279 | break; | |
3280 | ||
3281 | case DW_AT_ordering: | |
2e9e81a8 | 3282 | printf ("\t"); |
19e6b90e L |
3283 | switch (uvalue) |
3284 | { | |
04914e37 | 3285 | case 255: |
9cf03b7e | 3286 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
3287 | case 0: printf ("(row major)"); break; |
3288 | case 1: printf ("(column major)"); break; | |
3289 | } | |
3290 | break; | |
3291 | ||
04914e37 NC |
3292 | case DW_AT_decimal_sign: |
3293 | printf ("\t"); | |
3294 | switch (uvalue) | |
3295 | { | |
3296 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
3297 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
3298 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
3299 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
3300 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
3301 | default: printf (_("(unrecognised)")); break; | |
3302 | } | |
3303 | break; | |
3304 | ||
3305 | case DW_AT_defaulted: | |
3306 | printf ("\t"); | |
3307 | switch (uvalue) | |
3308 | { | |
3309 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
3310 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
3311 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
3312 | default: printf (_("(unrecognised)")); break; | |
3313 | } | |
3314 | break; | |
3315 | ||
3316 | case DW_AT_discr_list: | |
3317 | printf ("\t"); | |
ec1b0fbb | 3318 | display_discr_list (form, uvalue, data, end, level); |
04914e37 | 3319 | break; |
521d4b19 | 3320 | |
19e6b90e L |
3321 | case DW_AT_frame_base: |
3322 | have_frame_base = 1; | |
1a0670f3 | 3323 | /* Fall through. */ |
19e6b90e | 3324 | case DW_AT_location: |
e2a0d921 NC |
3325 | case DW_AT_string_length: |
3326 | case DW_AT_return_addr: | |
19e6b90e L |
3327 | case DW_AT_data_member_location: |
3328 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
3329 | case DW_AT_segment: |
3330 | case DW_AT_static_link: | |
3331 | case DW_AT_use_location: | |
bc0a77d2 | 3332 | case DW_AT_call_value: |
629e7ca8 | 3333 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 3334 | case DW_AT_call_data_value: |
629e7ca8 | 3335 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 3336 | case DW_AT_call_target: |
629e7ca8 | 3337 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 3338 | case DW_AT_call_target_clobbered: |
629e7ca8 | 3339 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 3340 | if ((dwarf_version < 4 |
b4eb7656 | 3341 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 3342 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 3343 | printf (_(" (location list)")); |
e2a0d921 | 3344 | /* Fall through. */ |
19e6b90e L |
3345 | case DW_AT_allocated: |
3346 | case DW_AT_associated: | |
3347 | case DW_AT_data_location: | |
3348 | case DW_AT_stride: | |
3349 | case DW_AT_upper_bound: | |
cecf136e | 3350 | case DW_AT_lower_bound: |
19e6b90e L |
3351 | if (block_start) |
3352 | { | |
3353 | int need_frame_base; | |
3354 | ||
2e9e81a8 | 3355 | printf ("\t("); |
19e6b90e L |
3356 | need_frame_base = decode_location_expression (block_start, |
3357 | pointer_size, | |
b7807392 JJ |
3358 | offset_size, |
3359 | dwarf_version, | |
19e6b90e | 3360 | uvalue, |
f1c4cc75 | 3361 | cu_offset, section); |
19e6b90e L |
3362 | printf (")"); |
3363 | if (need_frame_base && !have_frame_base) | |
3364 | printf (_(" [without DW_AT_frame_base]")); | |
3365 | } | |
19e6b90e L |
3366 | break; |
3367 | ||
c54207d3 NC |
3368 | case DW_AT_data_bit_offset: |
3369 | case DW_AT_byte_size: | |
3370 | case DW_AT_bit_size: | |
3371 | case DW_AT_string_length_byte_size: | |
3372 | case DW_AT_string_length_bit_size: | |
3373 | case DW_AT_bit_stride: | |
3374 | if (form == DW_FORM_exprloc) | |
3375 | { | |
3376 | printf ("\t("); | |
3377 | (void) decode_location_expression (block_start, pointer_size, | |
3378 | offset_size, dwarf_version, | |
3379 | uvalue, cu_offset, section); | |
3380 | printf (")"); | |
3381 | } | |
3382 | break; | |
3383 | ||
ec4d4525 NC |
3384 | case DW_AT_import: |
3385 | { | |
bcd213b2 NC |
3386 | unsigned long abbrev_number; |
3387 | abbrev_entry *entry; | |
2b6f5997 | 3388 | |
bcd213b2 NC |
3389 | entry = get_type_abbrev_from_form (form, uvalue, cu_offset, |
3390 | section, & abbrev_number, NULL, NULL); | |
3391 | if (entry == NULL) | |
3392 | { | |
3393 | if (form != DW_FORM_GNU_ref_alt) | |
3394 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), | |
3395 | dwarf_vmatoa ("x", uvalue), | |
3396 | (unsigned long) (orig_data - section->start)); | |
3397 | } | |
6e3d6dc1 NC |
3398 | else |
3399 | { | |
2e9e81a8 | 3400 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
bcd213b2 | 3401 | printf (" (%s)", get_TAG_name (entry->tag)); |
6e3d6dc1 NC |
3402 | printf ("]"); |
3403 | } | |
ec4d4525 NC |
3404 | } |
3405 | break; | |
3406 | ||
19e6b90e L |
3407 | default: |
3408 | break; | |
3409 | } | |
3410 | ||
3411 | return data; | |
3412 | } | |
3413 | ||
19e6b90e | 3414 | static unsigned char * |
dda8d76d NC |
3415 | read_and_display_attr (unsigned long attribute, |
3416 | unsigned long form, | |
3417 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 3418 | unsigned char * start, |
dda8d76d NC |
3419 | unsigned char * data, |
3420 | unsigned char * end, | |
3421 | dwarf_vma cu_offset, | |
3422 | dwarf_vma pointer_size, | |
3423 | dwarf_vma offset_size, | |
3424 | int dwarf_version, | |
3425 | debug_info * debug_info_p, | |
3426 | int do_loc, | |
3427 | struct dwarf_section * section, | |
ec1b0fbb NC |
3428 | struct cu_tu_set * this_set, |
3429 | int level) | |
19e6b90e L |
3430 | { |
3431 | if (!do_loc) | |
750f03b7 | 3432 | printf (" %-18s:", get_AT_name (attribute)); |
ec1b0fbb NC |
3433 | data = read_and_display_attr_value (attribute, form, implicit_const, |
3434 | start, data, end, | |
f6f0e17b | 3435 | cu_offset, pointer_size, offset_size, |
19e6b90e | 3436 | dwarf_version, debug_info_p, |
ec1b0fbb | 3437 | do_loc, section, this_set, ' ', level); |
19e6b90e L |
3438 | if (!do_loc) |
3439 | printf ("\n"); | |
3440 | return data; | |
3441 | } | |
3442 | ||
dda8d76d | 3443 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
3444 | following debug links, then attempt to load the requested section |
3445 | from one of the separate debug info files. */ | |
dda8d76d | 3446 | |
015dc7e1 | 3447 | static bool |
dda8d76d | 3448 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, |
24841daa | 3449 | void * handle) |
dda8d76d | 3450 | { |
24841daa | 3451 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 3452 | { |
24841daa NC |
3453 | if (debug_displays[sec_enum].section.filename == NULL) |
3454 | { | |
3455 | /* See if we can associate a filename with this section. */ | |
3456 | separate_info * i; | |
3457 | ||
3458 | for (i = first_separate_info; i != NULL; i = i->next) | |
3459 | if (i->handle == handle) | |
3460 | { | |
3461 | debug_displays[sec_enum].section.filename = i->filename; | |
3462 | break; | |
3463 | } | |
3464 | } | |
3465 | ||
015dc7e1 | 3466 | return true; |
dda8d76d NC |
3467 | } |
3468 | ||
24841daa NC |
3469 | if (do_follow_links) |
3470 | { | |
3471 | separate_info * i; | |
3472 | ||
3473 | for (i = first_separate_info; i != NULL; i = i->next) | |
3474 | { | |
3475 | if (load_debug_section (sec_enum, i->handle)) | |
3476 | { | |
3477 | debug_displays[sec_enum].section.filename = i->filename; | |
3478 | ||
3479 | /* FIXME: We should check to see if any of the remaining debug info | |
3480 | files also contain this section, and, umm, do something about it. */ | |
015dc7e1 | 3481 | return true; |
24841daa NC |
3482 | } |
3483 | } | |
3484 | } | |
dda8d76d | 3485 | |
015dc7e1 | 3486 | return false; |
dda8d76d NC |
3487 | } |
3488 | ||
3489 | static void | |
015dc7e1 | 3490 | introduce (struct dwarf_section * section, bool raw) |
dda8d76d NC |
3491 | { |
3492 | if (raw) | |
3493 | { | |
3494 | if (do_follow_links && section->filename) | |
3495 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
3496 | section->name, section->filename); | |
3497 | else | |
3498 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
3499 | } | |
3500 | else | |
3501 | { | |
3502 | if (do_follow_links && section->filename) | |
3503 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
3504 | section->name, section->filename); | |
3505 | else | |
3506 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3507 | } | |
3508 | } | |
521d4b19 | 3509 | |
d85bf2ba NC |
3510 | /* Process the contents of a .debug_info section. |
3511 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
3512 | and we do not want to display anything to the user. | |
3513 | If do_types is TRUE, we are processing a .debug_types section instead of | |
3514 | a .debug_info section. | |
3515 | The information displayed is restricted by the values in DWARF_START_DIE | |
3516 | and DWARF_CUTOFF_LEVEL. | |
3517 | Returns TRUE upon success. Otherwise an error or warning message is | |
3518 | printed and FALSE is returned. */ | |
19e6b90e | 3519 | |
015dc7e1 AM |
3520 | static bool |
3521 | process_debug_info (struct dwarf_section * section, | |
3522 | void *file, | |
3523 | enum dwarf_section_display_enum abbrev_sec, | |
3524 | bool do_loc, | |
3525 | bool do_types) | |
19e6b90e L |
3526 | { |
3527 | unsigned char *start = section->start; | |
3528 | unsigned char *end = start + section->size; | |
3529 | unsigned char *section_begin; | |
3530 | unsigned int unit; | |
3531 | unsigned int num_units = 0; | |
3532 | ||
3533 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3534 | && num_debug_info_entries == 0 |
3535 | && ! do_types) | |
19e6b90e | 3536 | { |
767221a9 | 3537 | dwarf_vma length; |
19e6b90e L |
3538 | |
3539 | /* First scan the section to get the number of comp units. */ | |
3540 | for (section_begin = start, num_units = 0; section_begin < end; | |
3541 | num_units ++) | |
3542 | { | |
3543 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
3544 | will be the length. For a 64-bit DWARF section, it'll be | |
3545 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 3546 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
3547 | |
3548 | if (length == 0xffffffff) | |
3549 | { | |
0c588247 | 3550 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
3551 | section_begin += length + 12; |
3552 | } | |
ec4d4525 NC |
3553 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
3554 | { | |
767221a9 NC |
3555 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
3556 | dwarf_vmatoa ("x", length), section->name); | |
015dc7e1 | 3557 | return false; |
ec4d4525 | 3558 | } |
19e6b90e L |
3559 | else |
3560 | section_begin += length + 4; | |
aca88567 NC |
3561 | |
3562 | /* Negative values are illegal, they may even cause infinite | |
3563 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
3564 | relocations to an object file, or if the file is corrupt. */ |
3565 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 3566 | { |
767221a9 NC |
3567 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
3568 | dwarf_vmatoa ("x", length), section->name); | |
015dc7e1 | 3569 | return false; |
aca88567 | 3570 | } |
19e6b90e L |
3571 | } |
3572 | ||
3573 | if (num_units == 0) | |
3574 | { | |
f41e4712 | 3575 | error (_("No comp units in %s section ?\n"), section->name); |
015dc7e1 | 3576 | return false; |
19e6b90e L |
3577 | } |
3578 | ||
3579 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 3580 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 3581 | sizeof (* debug_information)); |
19e6b90e L |
3582 | if (debug_information == NULL) |
3583 | { | |
f41e4712 | 3584 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 3585 | num_units); |
82b1b41b | 3586 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
015dc7e1 | 3587 | return false; |
19e6b90e | 3588 | } |
d85bf2ba | 3589 | |
03a91817 NC |
3590 | /* PR 17531: file: 92ca3797. |
3591 | We cannot rely upon the debug_information array being initialised | |
3592 | before it is used. A corrupt file could easily contain references | |
3593 | to a unit for which information has not been made available. So | |
3594 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
3595 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
3596 | ||
82b1b41b | 3597 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
3598 | } |
3599 | ||
3600 | if (!do_loc) | |
3601 | { | |
dda8d76d NC |
3602 | load_debug_section_with_follow (str, file); |
3603 | load_debug_section_with_follow (line_str, file); | |
3604 | load_debug_section_with_follow (str_dwo, file); | |
3605 | load_debug_section_with_follow (str_index, file); | |
3606 | load_debug_section_with_follow (str_index_dwo, file); | |
3607 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e | 3608 | } |
521d4b19 | 3609 | |
dda8d76d | 3610 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 3611 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
3612 | { |
3613 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 3614 | debug_displays [abbrev_sec].section.uncompressed_name); |
015dc7e1 | 3615 | return false; |
19e6b90e L |
3616 | } |
3617 | ||
dda8d76d | 3618 | if (!do_loc && dwarf_start_die == 0) |
015dc7e1 | 3619 | introduce (section, false); |
bcd213b2 NC |
3620 | |
3621 | free_all_abbrevs (); | |
3622 | free (cu_abbrev_map); | |
3623 | cu_abbrev_map = NULL; | |
3624 | next_free_abbrev_map_entry = 0; | |
521d4b19 | 3625 | |
bcd213b2 NC |
3626 | /* In order to be able to resolve DW_FORM_ref_attr forms we need |
3627 | to load *all* of the abbrevs for all CUs in this .debug_info | |
3628 | section. This does effectively mean that we (partially) read | |
3629 | every CU header twice. */ | |
3630 | for (section_begin = start; start < end;) | |
3631 | { | |
3632 | DWARF2_Internal_CompUnit compunit; | |
3633 | unsigned char * hdrptr; | |
76868f36 L |
3634 | dwarf_vma abbrev_base; |
3635 | size_t abbrev_size; | |
bcd213b2 NC |
3636 | dwarf_vma cu_offset; |
3637 | unsigned int offset_size; | |
3638 | unsigned int initial_length_size; | |
3639 | struct cu_tu_set * this_set; | |
3640 | abbrev_list * list; | |
3641 | ||
3642 | hdrptr = start; | |
3643 | ||
3644 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); | |
3645 | ||
3646 | if (compunit.cu_length == 0xffffffff) | |
3647 | { | |
3648 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); | |
3649 | offset_size = 8; | |
3650 | initial_length_size = 12; | |
3651 | } | |
3652 | else | |
3653 | { | |
3654 | offset_size = 4; | |
3655 | initial_length_size = 4; | |
3656 | } | |
3657 | ||
3658 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); | |
3659 | ||
3660 | cu_offset = start - section_begin; | |
3661 | ||
3662 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); | |
3663 | ||
3664 | if (compunit.cu_version < 5) | |
3665 | { | |
3666 | compunit.cu_unit_type = DW_UT_compile; | |
3667 | /* Initialize it due to a false compiler warning. */ | |
3668 | compunit.cu_pointer_size = -1; | |
3669 | } | |
3670 | else | |
3671 | { | |
3672 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3673 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3674 | ||
3675 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3676 | } | |
3677 | ||
3678 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); | |
3679 | ||
9b87f84a TV |
3680 | if (compunit.cu_unit_type == DW_UT_split_compile |
3681 | || compunit.cu_unit_type == DW_UT_skeleton) | |
3682 | { | |
3683 | uint64_t dwo_id; | |
3684 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end); | |
3685 | } | |
3686 | ||
76868f36 L |
3687 | if (this_set == NULL) |
3688 | { | |
3689 | abbrev_base = 0; | |
3690 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3691 | } | |
3692 | else | |
3693 | { | |
3694 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3695 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3696 | } | |
3697 | ||
3698 | list = find_abbrev_list_by_abbrev_offset (abbrev_base, | |
3699 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3700 | if (list == NULL) |
3701 | { | |
bcd213b2 NC |
3702 | unsigned char * next; |
3703 | ||
76868f36 L |
3704 | list = new_abbrev_list (abbrev_base, |
3705 | compunit.cu_abbrev_offset); | |
f2f9554b AM |
3706 | next = process_abbrev_set (&debug_displays[abbrev_sec].section, |
3707 | abbrev_base, abbrev_size, | |
3708 | compunit.cu_abbrev_offset, list); | |
bcd213b2 NC |
3709 | list->start_of_next_abbrevs = next; |
3710 | } | |
521d4b19 | 3711 | |
bcd213b2 NC |
3712 | start = section_begin + cu_offset + compunit.cu_length |
3713 | + initial_length_size; | |
3714 | record_abbrev_list_for_cu (cu_offset, start - section_begin, list); | |
3715 | } | |
3716 | ||
3717 | for (start = section_begin, unit = 0; start < end; unit++) | |
19e6b90e L |
3718 | { |
3719 | DWARF2_Internal_CompUnit compunit; | |
3720 | unsigned char *hdrptr; | |
19e6b90e | 3721 | unsigned char *tags; |
fd2f0033 | 3722 | int level, last_level, saved_level; |
467c65bc | 3723 | dwarf_vma cu_offset; |
e98fdf1a | 3724 | unsigned long sec_off; |
bf5117e3 | 3725 | unsigned int offset_size; |
19485196 | 3726 | unsigned int initial_length_size; |
74bc6052 CC |
3727 | dwarf_vma signature_high = 0; |
3728 | dwarf_vma signature_low = 0; | |
767221a9 | 3729 | dwarf_vma type_offset = 0; |
341f9135 CC |
3730 | struct cu_tu_set *this_set; |
3731 | dwarf_vma abbrev_base; | |
3732 | size_t abbrev_size; | |
bcd213b2 | 3733 | abbrev_list * list = NULL; |
19e6b90e L |
3734 | |
3735 | hdrptr = start; | |
3736 | ||
0c588247 | 3737 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
3738 | |
3739 | if (compunit.cu_length == 0xffffffff) | |
3740 | { | |
0c588247 | 3741 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
3742 | offset_size = 8; |
3743 | initial_length_size = 12; | |
3744 | } | |
3745 | else | |
3746 | { | |
3747 | offset_size = 4; | |
3748 | initial_length_size = 4; | |
3749 | } | |
3750 | ||
0c588247 | 3751 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
3752 | |
3753 | cu_offset = start - section_begin; | |
19e6b90e | 3754 | |
341f9135 CC |
3755 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3756 | ||
77145576 JK |
3757 | if (compunit.cu_version < 5) |
3758 | { | |
3759 | compunit.cu_unit_type = DW_UT_compile; | |
3760 | /* Initialize it due to a false compiler warning. */ | |
3761 | compunit.cu_pointer_size = -1; | |
3762 | } | |
3763 | else | |
3764 | { | |
3765 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3766 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3767 | ||
3768 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3769 | } | |
3770 | ||
0c588247 | 3771 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 3772 | |
341f9135 CC |
3773 | if (this_set == NULL) |
3774 | { | |
3775 | abbrev_base = 0; | |
3776 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3777 | } | |
3778 | else | |
3779 | { | |
3780 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3781 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3782 | } | |
3783 | ||
77145576 JK |
3784 | if (compunit.cu_version < 5) |
3785 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3786 | ||
015dc7e1 | 3787 | bool do_dwo_id = false; |
e6ca1878 | 3788 | uint64_t dwo_id = 0; |
9b87f84a TV |
3789 | if (compunit.cu_unit_type == DW_UT_split_compile |
3790 | || compunit.cu_unit_type == DW_UT_skeleton) | |
3791 | { | |
9b87f84a | 3792 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end); |
015dc7e1 | 3793 | do_dwo_id = true; |
9b87f84a TV |
3794 | } |
3795 | ||
f41e4712 NC |
3796 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
3797 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
3798 | { | |
3799 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
3800 | compunit.cu_pointer_size, offset_size); | |
3801 | compunit.cu_pointer_size = offset_size; | |
3802 | } | |
2b6f5997 CC |
3803 | |
3804 | if (do_types) | |
b4eb7656 | 3805 | { |
0c588247 | 3806 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 3807 | hdrptr += 8; |
0c588247 | 3808 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 3809 | } |
2b6f5997 | 3810 | |
ae7e7825 NC |
3811 | if (dwarf_start_die > (cu_offset + compunit.cu_length |
3812 | + initial_length_size)) | |
3813 | { | |
3814 | start = section_begin + cu_offset + compunit.cu_length | |
3815 | + initial_length_size; | |
3816 | continue; | |
3817 | } | |
3818 | ||
19e6b90e | 3819 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 | 3820 | && num_debug_info_entries == 0 |
c4b2f181 | 3821 | && alloc_num_debug_info_entries > unit |
2b6f5997 | 3822 | && ! do_types) |
19e6b90e L |
3823 | { |
3824 | debug_information [unit].cu_offset = cu_offset; | |
3825 | debug_information [unit].pointer_size | |
3826 | = compunit.cu_pointer_size; | |
b7807392 JJ |
3827 | debug_information [unit].offset_size = offset_size; |
3828 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 3829 | debug_information [unit].base_address = 0; |
4723351a CC |
3830 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
3831 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
3832 | debug_information [unit].loc_offsets = NULL; |
3833 | debug_information [unit].have_frame_base = NULL; | |
3834 | debug_information [unit].max_loc_offsets = 0; | |
3835 | debug_information [unit].num_loc_offsets = 0; | |
3836 | debug_information [unit].range_lists = NULL; | |
3837 | debug_information [unit].max_range_lists= 0; | |
3838 | debug_information [unit].num_range_lists = 0; | |
3839 | } | |
3840 | ||
fd2f0033 | 3841 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 3842 | { |
47704ddf KT |
3843 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3844 | dwarf_vmatoa ("x", cu_offset)); | |
3845 | printf (_(" Length: 0x%s (%s)\n"), | |
3846 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3847 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3848 | printf (_(" Version: %d\n"), compunit.cu_version); |
debd1a62 | 3849 | if (compunit.cu_version >= 5) |
4896932e MF |
3850 | { |
3851 | const char *name = get_DW_UT_name (compunit.cu_unit_type); | |
3852 | ||
3853 | printf (_(" Unit Type: %s (%x)\n"), | |
3854 | name ? name : "???", | |
3855 | compunit.cu_unit_type); | |
3856 | } | |
7282333f AM |
3857 | printf (_(" Abbrev Offset: 0x%s\n"), |
3858 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3859 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3860 | if (do_types) |
3861 | { | |
74bc6052 CC |
3862 | char buf[64]; |
3863 | ||
3864 | printf (_(" Signature: 0x%s\n"), | |
3865 | dwarf_vmatoa64 (signature_high, signature_low, | |
3866 | buf, sizeof (buf))); | |
3867 | printf (_(" Type Offset: 0x%s\n"), | |
3868 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3869 | } |
d60f7998 TV |
3870 | if (do_dwo_id) |
3871 | printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id)); | |
341f9135 CC |
3872 | if (this_set != NULL) |
3873 | { | |
3874 | dwarf_vma *offsets = this_set->section_offsets; | |
3875 | size_t *sizes = this_set->section_sizes; | |
3876 | ||
3877 | printf (_(" Section contributions:\n")); | |
3878 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3879 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3880 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3881 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3882 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3883 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3884 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3885 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3886 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3887 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3888 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3889 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3890 | } | |
19e6b90e L |
3891 | } |
3892 | ||
e98fdf1a AM |
3893 | sec_off = cu_offset + initial_length_size; |
3894 | if (sec_off + compunit.cu_length < sec_off | |
3895 | || sec_off + compunit.cu_length > section->size) | |
460c89ff | 3896 | { |
e98fdf1a AM |
3897 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
3898 | section->name, | |
3899 | (unsigned long) cu_offset, | |
19485196 NC |
3900 | dwarf_vmatoa ("x", compunit.cu_length)); |
3901 | num_units = unit; | |
3902 | break; | |
3903 | } | |
3904 | ||
460c89ff NS |
3905 | tags = hdrptr; |
3906 | start += compunit.cu_length + initial_length_size; | |
3907 | ||
77145576 | 3908 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3909 | { |
47704ddf KT |
3910 | warn (_("CU at offset %s contains corrupt or " |
3911 | "unsupported version number: %d.\n"), | |
3912 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3913 | continue; |
3914 | } | |
3915 | ||
77145576 | 3916 | if (compunit.cu_unit_type != DW_UT_compile |
ec47b32a | 3917 | && compunit.cu_unit_type != DW_UT_partial |
9b87f84a TV |
3918 | && compunit.cu_unit_type != DW_UT_type |
3919 | && compunit.cu_unit_type != DW_UT_split_compile | |
3920 | && compunit.cu_unit_type != DW_UT_skeleton) | |
77145576 JK |
3921 | { |
3922 | warn (_("CU at offset %s contains corrupt or " | |
3923 | "unsupported unit type: %d.\n"), | |
3924 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3925 | continue; | |
3926 | } | |
3927 | ||
d493b283 | 3928 | /* Process the abbrevs used by this compilation unit. */ |
f2f9554b AM |
3929 | list = find_abbrev_list_by_abbrev_offset (abbrev_base, |
3930 | compunit.cu_abbrev_offset); | |
3931 | if (list == NULL) | |
bcd213b2 | 3932 | { |
f2f9554b AM |
3933 | unsigned char *next; |
3934 | ||
3935 | list = new_abbrev_list (abbrev_base, | |
3936 | compunit.cu_abbrev_offset); | |
3937 | next = process_abbrev_set (&debug_displays[abbrev_sec].section, | |
3938 | abbrev_base, abbrev_size, | |
3939 | compunit.cu_abbrev_offset, list); | |
3940 | list->start_of_next_abbrevs = next; | |
bcd213b2 | 3941 | } |
19e6b90e L |
3942 | |
3943 | level = 0; | |
fd2f0033 TT |
3944 | last_level = level; |
3945 | saved_level = -1; | |
19e6b90e L |
3946 | while (tags < start) |
3947 | { | |
19e6b90e | 3948 | unsigned long abbrev_number; |
ec4d4525 | 3949 | unsigned long die_offset; |
19e6b90e L |
3950 | abbrev_entry *entry; |
3951 | abbrev_attr *attr; | |
fd2f0033 | 3952 | int do_printing = 1; |
19e6b90e | 3953 | |
ec4d4525 NC |
3954 | die_offset = tags - section_begin; |
3955 | ||
cd30bcef | 3956 | READ_ULEB (abbrev_number, tags, start); |
19e6b90e | 3957 | |
eb7cc021 JK |
3958 | /* A null DIE marks the end of a list of siblings or it may also be |
3959 | a section padding. */ | |
19e6b90e L |
3960 | if (abbrev_number == 0) |
3961 | { | |
eb7cc021 JK |
3962 | /* Check if it can be a section padding for the last CU. */ |
3963 | if (level == 0 && start == end) | |
3964 | { | |
3965 | unsigned char *chk; | |
3966 | ||
3967 | for (chk = tags; chk < start; chk++) | |
3968 | if (*chk != 0) | |
3969 | break; | |
3970 | if (chk == start) | |
3971 | break; | |
3972 | } | |
3973 | ||
4337774f TT |
3974 | if (!do_loc && die_offset >= dwarf_start_die |
3975 | && (dwarf_cutoff_level == -1 | |
3976 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3977 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3978 | level, die_offset); | |
3979 | ||
19e6b90e | 3980 | --level; |
ec4d4525 NC |
3981 | if (level < 0) |
3982 | { | |
3983 | static unsigned num_bogus_warns = 0; | |
3984 | ||
3985 | if (num_bogus_warns < 3) | |
3986 | { | |
4723351a CC |
3987 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3988 | die_offset, section->name); | |
ec4d4525 NC |
3989 | num_bogus_warns ++; |
3990 | if (num_bogus_warns == 3) | |
3991 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3992 | } | |
3993 | } | |
fd2f0033 | 3994 | if (dwarf_start_die != 0 && level < saved_level) |
015dc7e1 | 3995 | return true; |
19e6b90e L |
3996 | continue; |
3997 | } | |
3998 | ||
4b78141a | 3999 | if (!do_loc) |
fd2f0033 TT |
4000 | { |
4001 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
4002 | do_printing = 0; | |
4003 | else | |
4004 | { | |
4005 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
4006 | saved_level = level; | |
4007 | do_printing = (dwarf_cutoff_level == -1 | |
4008 | || level < dwarf_cutoff_level); | |
4009 | if (do_printing) | |
4010 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
4011 | level, die_offset, abbrev_number); | |
4012 | else if (dwarf_cutoff_level == -1 | |
4013 | || last_level < dwarf_cutoff_level) | |
4014 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
4015 | last_level = level; | |
4016 | } | |
4017 | } | |
cecf136e | 4018 | |
19e6b90e L |
4019 | /* Scan through the abbreviation list until we reach the |
4020 | correct entry. */ | |
bcd213b2 | 4021 | if (list == NULL) |
19e6b90e L |
4022 | continue; |
4023 | ||
bcd213b2 NC |
4024 | for (entry = list->first_abbrev; entry != NULL; entry = entry->next) |
4025 | if (entry->number == abbrev_number) | |
4026 | break; | |
4027 | ||
19e6b90e L |
4028 | if (entry == NULL) |
4029 | { | |
fd2f0033 | 4030 | if (!do_loc && do_printing) |
4b78141a NC |
4031 | { |
4032 | printf ("\n"); | |
4033 | fflush (stdout); | |
4034 | } | |
f3853b34 | 4035 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 4036 | die_offset, abbrev_number); |
015dc7e1 | 4037 | return false; |
19e6b90e L |
4038 | } |
4039 | ||
fd2f0033 | 4040 | if (!do_loc && do_printing) |
cc5914eb | 4041 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 4042 | |
19e6b90e L |
4043 | switch (entry->tag) |
4044 | { | |
4045 | default: | |
4046 | need_base_address = 0; | |
4047 | break; | |
4048 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
4049 | need_base_address = 1; |
4050 | need_dwo_info = do_loc; | |
19e6b90e L |
4051 | break; |
4052 | case DW_TAG_entry_point: | |
19e6b90e L |
4053 | case DW_TAG_subprogram: |
4054 | need_base_address = 0; | |
4055 | /* Assuming that there is no DW_AT_frame_base. */ | |
4056 | have_frame_base = 0; | |
4057 | break; | |
4058 | } | |
4059 | ||
9f272209 AO |
4060 | debug_info *debug_info_p = |
4061 | (debug_information && unit < alloc_num_debug_info_entries) | |
4062 | ? debug_information + unit : NULL; | |
4063 | ||
4064 | assert (!debug_info_p | |
4065 | || (debug_info_p->num_loc_offsets | |
4066 | == debug_info_p->num_loc_views)); | |
4067 | ||
399c99f7 L |
4068 | for (attr = entry->first_attr; |
4069 | attr && attr->attribute; | |
4070 | attr = attr->next) | |
4b78141a | 4071 | { |
fd2f0033 | 4072 | if (! do_loc && do_printing) |
4b78141a | 4073 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 | 4074 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
4075 | tags = read_and_display_attr (attr->attribute, |
4076 | attr->form, | |
77145576 | 4077 | attr->implicit_const, |
ec1b0fbb | 4078 | section_begin, |
341f9135 | 4079 | tags, |
f6f0e17b | 4080 | end, |
341f9135 | 4081 | cu_offset, |
4b78141a NC |
4082 | compunit.cu_pointer_size, |
4083 | offset_size, | |
4084 | compunit.cu_version, | |
9f272209 | 4085 | debug_info_p, |
341f9135 CC |
4086 | do_loc || ! do_printing, |
4087 | section, | |
ec1b0fbb NC |
4088 | this_set, |
4089 | level); | |
4b78141a | 4090 | } |
cecf136e | 4091 | |
9f272209 AO |
4092 | /* If a locview attribute appears before a location one, |
4093 | make sure we don't associate it with an earlier | |
4094 | loclist. */ | |
4095 | if (debug_info_p) | |
4096 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
4097 | { | |
4098 | case 1: | |
4099 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
4100 | debug_info_p->num_loc_views++; | |
4101 | assert (debug_info_p->num_loc_views | |
4102 | == debug_info_p->num_loc_offsets); | |
4103 | break; | |
4104 | ||
4105 | case 0: | |
4106 | break; | |
4107 | ||
4108 | case -1: | |
4109 | warn(_("DIE has locviews without loclist\n")); | |
4110 | debug_info_p->num_loc_views--; | |
4111 | break; | |
4112 | ||
4113 | default: | |
4114 | assert (0); | |
4115 | } | |
4116 | ||
b4eb7656 AM |
4117 | if (entry->children) |
4118 | ++level; | |
4119 | } | |
19e6b90e | 4120 | } |
cecf136e | 4121 | |
19e6b90e L |
4122 | /* Set num_debug_info_entries here so that it can be used to check if |
4123 | we need to process .debug_loc and .debug_ranges sections. */ | |
4124 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
4125 | && num_debug_info_entries == 0 |
4126 | && ! do_types) | |
82b1b41b | 4127 | { |
b4eb7656 | 4128 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
4129 | num_debug_info_entries = alloc_num_debug_info_entries; |
4130 | else | |
4131 | num_debug_info_entries = num_units; | |
4132 | } | |
cecf136e | 4133 | |
19e6b90e | 4134 | if (!do_loc) |
467c65bc | 4135 | printf ("\n"); |
cecf136e | 4136 | |
015dc7e1 | 4137 | return true; |
19e6b90e L |
4138 | } |
4139 | ||
4140 | /* Locate and scan the .debug_info section in the file and record the pointer | |
4141 | sizes and offsets for the compilation units in it. Usually an executable | |
4142 | will have just one pointer size, but this is not guaranteed, and so we try | |
4143 | not to make any assumptions. Returns zero upon failure, or the number of | |
4144 | compilation units upon success. */ | |
4145 | ||
4146 | static unsigned int | |
4147 | load_debug_info (void * file) | |
4148 | { | |
1febe64d | 4149 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 4150 | section then do not bother to repeat the task. */ |
cc86f28f | 4151 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
4152 | return 0; |
4153 | ||
19e6b90e L |
4154 | /* If we already have the information there is nothing else to do. */ |
4155 | if (num_debug_info_entries > 0) | |
4156 | return num_debug_info_entries; | |
4157 | ||
341f9135 | 4158 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 4159 | (void) load_cu_tu_indexes (file); |
341f9135 | 4160 | |
dda8d76d | 4161 | if (load_debug_section_with_follow (info, file) |
015dc7e1 | 4162 | && process_debug_info (&debug_displays [info].section, file, abbrev, true, false)) |
19e6b90e | 4163 | return num_debug_info_entries; |
82b1b41b | 4164 | |
dda8d76d | 4165 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 4166 | && process_debug_info (&debug_displays [info_dwo].section, file, |
015dc7e1 | 4167 | abbrev_dwo, true, false)) |
4723351a | 4168 | return num_debug_info_entries; |
1febe64d | 4169 | |
cc86f28f | 4170 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 4171 | return 0; |
19e6b90e L |
4172 | } |
4173 | ||
b40bf0a2 NC |
4174 | /* Read a DWARF .debug_line section header starting at DATA. |
4175 | Upon success returns an updated DATA pointer and the LINFO | |
4176 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
4177 | Otherwise returns NULL. */ | |
19e6b90e | 4178 | |
b40bf0a2 NC |
4179 | static unsigned char * |
4180 | read_debug_line_header (struct dwarf_section * section, | |
4181 | unsigned char * data, | |
4182 | unsigned char * end, | |
4183 | DWARF2_Internal_LineInfo * linfo, | |
4184 | unsigned char ** end_of_sequence) | |
4185 | { | |
4186 | unsigned char *hdrptr; | |
b40bf0a2 | 4187 | unsigned int initial_length_size; |
19e6b90e | 4188 | |
b40bf0a2 NC |
4189 | /* Extract information from the Line Number Program Header. |
4190 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 4191 | hdrptr = data; |
19e6b90e | 4192 | |
b40bf0a2 NC |
4193 | /* Get and check the length of the block. */ |
4194 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 4195 | |
b40bf0a2 | 4196 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
4197 | { |
4198 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 4199 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 4200 | linfo->li_offset_size = 8; |
f41e4712 NC |
4201 | initial_length_size = 12; |
4202 | } | |
4203 | else | |
4204 | { | |
77145576 | 4205 | linfo->li_offset_size = 4; |
f41e4712 NC |
4206 | initial_length_size = 4; |
4207 | } | |
19e6b90e | 4208 | |
b40bf0a2 | 4209 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 4210 | { |
8fcc61b4 NC |
4211 | /* If the length field has a relocation against it, then we should |
4212 | not complain if it is inaccurate (and probably negative). This | |
4213 | happens in object files when the .debug_line section is actually | |
4214 | comprised of several different .debug_line.* sections, (some of | |
4215 | which may be removed by linker garbage collection), and a relocation | |
4216 | is used to compute the correct length once that is done. */ | |
77145576 | 4217 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 4218 | { |
8fcc61b4 | 4219 | linfo->li_length = (end - data) - initial_length_size; |
b40bf0a2 NC |
4220 | } |
4221 | else | |
4222 | { | |
8fcc61b4 NC |
4223 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
4224 | (long) linfo->li_length); | |
b40bf0a2 NC |
4225 | return NULL; |
4226 | } | |
f41e4712 | 4227 | } |
19e6b90e | 4228 | |
b40bf0a2 NC |
4229 | /* Get and check the version number. */ |
4230 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
4231 | ||
4232 | if (linfo->li_version != 2 | |
4233 | && linfo->li_version != 3 | |
77145576 JK |
4234 | && linfo->li_version != 4 |
4235 | && linfo->li_version != 5) | |
f41e4712 | 4236 | { |
77145576 JK |
4237 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
4238 | "is currently supported.\n")); | |
b40bf0a2 | 4239 | return NULL; |
f41e4712 | 4240 | } |
19e6b90e | 4241 | |
77145576 JK |
4242 | if (linfo->li_version >= 5) |
4243 | { | |
5496f3c6 | 4244 | SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end); |
77145576 | 4245 | |
5496f3c6 NC |
4246 | SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end); |
4247 | if (linfo->li_segment_size != 0) | |
77145576 JK |
4248 | { |
4249 | warn (_("The %s section contains " | |
4250 | "unsupported segment selector size: %d.\n"), | |
5496f3c6 NC |
4251 | section->name, linfo->li_segment_size); |
4252 | return NULL; | |
77145576 JK |
4253 | } |
4254 | } | |
4255 | ||
4256 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
4257 | linfo->li_offset_size, end); | |
b40bf0a2 | 4258 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 4259 | |
b40bf0a2 | 4260 | if (linfo->li_version >= 4) |
f41e4712 | 4261 | { |
b40bf0a2 | 4262 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 4263 | |
b40bf0a2 | 4264 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
4265 | { |
4266 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 4267 | return NULL; |
a233b20c | 4268 | } |
f41e4712 NC |
4269 | } |
4270 | else | |
b40bf0a2 | 4271 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 4272 | |
b40bf0a2 | 4273 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 4274 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
4275 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
4276 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 4277 | |
b40bf0a2 | 4278 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 4279 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
4280 | if (* end_of_sequence > end) |
4281 | { | |
4c219c2e AM |
4282 | warn (_("Line length %s extends beyond end of section\n"), |
4283 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
4284 | * end_of_sequence = end; |
4285 | return NULL; | |
4286 | } | |
4287 | ||
b40bf0a2 NC |
4288 | return hdrptr; |
4289 | } | |
19e6b90e | 4290 | |
77145576 | 4291 | static unsigned char * |
015dc7e1 AM |
4292 | display_formatted_table (unsigned char *data, |
4293 | unsigned char *start, | |
4294 | unsigned char *end, | |
4295 | const DWARF2_Internal_LineInfo *linfo, | |
4296 | struct dwarf_section *section, | |
4297 | bool is_dir) | |
77145576 JK |
4298 | { |
4299 | unsigned char *format_start, format_count, *format, formati; | |
4300 | dwarf_vma data_count, datai; | |
cd30bcef | 4301 | unsigned int namepass, last_entry = 0; |
5496f3c6 | 4302 | const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table"); |
521d4b19 | 4303 | |
77145576 | 4304 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
546cb2d8 NC |
4305 | if (do_checks && format_count > 5) |
4306 | warn (_("Unexpectedly large number of columns in the %s (%u)\n"), | |
4307 | table_name, format_count); | |
4308 | ||
77145576 JK |
4309 | format_start = data; |
4310 | for (formati = 0; formati < format_count; formati++) | |
4311 | { | |
cd30bcef AM |
4312 | SKIP_ULEB (data, end); |
4313 | SKIP_ULEB (data, end); | |
77145576 JK |
4314 | if (data == end) |
4315 | { | |
5496f3c6 | 4316 | warn (_("%s: Corrupt format description entry\n"), table_name); |
77145576 JK |
4317 | return data; |
4318 | } | |
4319 | } | |
4320 | ||
cd30bcef | 4321 | READ_ULEB (data_count, data, end); |
546cb2d8 | 4322 | if (data_count == 0) |
77145576 | 4323 | { |
546cb2d8 | 4324 | printf (_("\n The %s is empty.\n"), table_name); |
77145576 JK |
4325 | return data; |
4326 | } | |
546cb2d8 | 4327 | else if (data == end) |
77145576 | 4328 | { |
546cb2d8 NC |
4329 | warn (_("%s: Corrupt entry count - expected %s but none found\n"), |
4330 | table_name, dwarf_vmatoa ("x", data_count)); | |
77145576 JK |
4331 | return data; |
4332 | } | |
546cb2d8 | 4333 | |
5496f3c6 NC |
4334 | else if (format_count == 0) |
4335 | { | |
4336 | warn (_("%s: format count is zero, but the table is not empty\n"), | |
4337 | table_name); | |
4338 | return end; | |
4339 | } | |
77145576 | 4340 | |
5496f3c6 NC |
4341 | printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"), |
4342 | table_name, (long) (data - start), dwarf_vmatoa ("u", data_count), | |
4343 | format_count); | |
77145576 JK |
4344 | |
4345 | printf (_(" Entry")); | |
521d4b19 | 4346 | /* Delay displaying name as the last entry for better screen layout. */ |
77145576 JK |
4347 | for (namepass = 0; namepass < 2; namepass++) |
4348 | { | |
4349 | format = format_start; | |
4350 | for (formati = 0; formati < format_count; formati++) | |
4351 | { | |
4352 | dwarf_vma content_type; | |
4353 | ||
cd30bcef | 4354 | READ_ULEB (content_type, format, end); |
77145576 JK |
4355 | if ((content_type == DW_LNCT_path) == (namepass == 1)) |
4356 | switch (content_type) | |
4357 | { | |
4358 | case DW_LNCT_path: | |
4359 | printf (_("\tName")); | |
4360 | break; | |
4361 | case DW_LNCT_directory_index: | |
4362 | printf (_("\tDir")); | |
4363 | break; | |
4364 | case DW_LNCT_timestamp: | |
4365 | printf (_("\tTime")); | |
4366 | break; | |
4367 | case DW_LNCT_size: | |
4368 | printf (_("\tSize")); | |
4369 | break; | |
4370 | case DW_LNCT_MD5: | |
5496f3c6 | 4371 | printf (_("\tMD5\t\t\t")); |
77145576 JK |
4372 | break; |
4373 | default: | |
4374 | printf (_("\t(Unknown format content type %s)"), | |
4375 | dwarf_vmatoa ("u", content_type)); | |
4376 | } | |
cd30bcef | 4377 | SKIP_ULEB (format, end); |
77145576 JK |
4378 | } |
4379 | } | |
4380 | putchar ('\n'); | |
4381 | ||
4382 | for (datai = 0; datai < data_count; datai++) | |
4383 | { | |
4384 | unsigned char *datapass = data; | |
4385 | ||
4386 | printf (" %d", last_entry++); | |
521d4b19 | 4387 | /* Delay displaying name as the last entry for better screen layout. */ |
77145576 JK |
4388 | for (namepass = 0; namepass < 2; namepass++) |
4389 | { | |
4390 | format = format_start; | |
4391 | data = datapass; | |
4392 | for (formati = 0; formati < format_count; formati++) | |
4393 | { | |
4394 | dwarf_vma content_type, form; | |
4395 | ||
cd30bcef AM |
4396 | READ_ULEB (content_type, format, end); |
4397 | READ_ULEB (form, format, end); | |
4398 | data = read_and_display_attr_value (0, form, 0, start, data, end, | |
4399 | 0, 0, linfo->li_offset_size, | |
77145576 JK |
4400 | linfo->li_version, NULL, |
4401 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
ec1b0fbb | 4402 | section, NULL, '\t', -1); |
77145576 JK |
4403 | } |
4404 | } | |
5496f3c6 NC |
4405 | |
4406 | if (data == end && (datai < data_count - 1)) | |
77145576 | 4407 | { |
5496f3c6 | 4408 | warn (_("\n%s: Corrupt entries list\n"), table_name); |
77145576 JK |
4409 | return data; |
4410 | } | |
4411 | putchar ('\n'); | |
4412 | } | |
4413 | return data; | |
4414 | } | |
4415 | ||
e38332c2 NC |
4416 | static int |
4417 | display_debug_sup (struct dwarf_section * section, | |
4418 | void * file ATTRIBUTE_UNUSED) | |
4419 | { | |
4420 | unsigned char * start = section->start; | |
4421 | unsigned char * end = section->start + section->size; | |
4422 | unsigned int version; | |
4423 | char is_supplementary; | |
4424 | const unsigned char * sup_filename; | |
4425 | size_t sup_filename_len; | |
4426 | unsigned int num_read; | |
4427 | int status; | |
4428 | dwarf_vma checksum_len; | |
4429 | ||
4430 | ||
015dc7e1 | 4431 | introduce (section, true); |
e38332c2 NC |
4432 | if (section->size < 4) |
4433 | { | |
4434 | error (_("corrupt .debug_sup section: size is too small\n")); | |
4435 | return 0; | |
4436 | } | |
4437 | ||
4438 | /* Read the data. */ | |
4439 | SAFE_BYTE_GET_AND_INC (version, start, 2, end); | |
4440 | if (version < 5) | |
4441 | warn (_("corrupt .debug_sup section: version < 5")); | |
4442 | ||
4443 | SAFE_BYTE_GET_AND_INC (is_supplementary, start, 1, end); | |
4444 | if (is_supplementary != 0 && is_supplementary != 1) | |
4445 | warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n")); | |
4446 | ||
4447 | sup_filename = start; | |
4448 | if (is_supplementary && sup_filename[0] != 0) | |
4449 | warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n")); | |
4450 | ||
4451 | sup_filename_len = strnlen ((const char *) start, end - start); | |
4452 | if (sup_filename_len == (size_t) (end - start)) | |
4453 | { | |
4454 | error (_("corrupt .debug_sup section: filename is not NUL terminated\n")); | |
4455 | return 0; | |
4456 | } | |
4457 | start += sup_filename_len + 1; | |
4458 | ||
015dc7e1 | 4459 | checksum_len = read_leb128 (start, end, false /* unsigned */, & num_read, & status); |
e38332c2 NC |
4460 | if (status) |
4461 | { | |
4462 | error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n")); | |
4463 | checksum_len = 0; | |
4464 | } | |
4465 | start += num_read; | |
4466 | if (checksum_len > (dwarf_vma) (end - start)) | |
4467 | { | |
4468 | error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n")); | |
4469 | checksum_len = end - start; | |
4470 | } | |
4471 | else if (checksum_len < (dwarf_vma) (end - start)) | |
4472 | { | |
4473 | warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"), | |
4474 | (long) ((end - start) - checksum_len)); | |
4475 | } | |
4476 | ||
4477 | printf (_(" Version: %u\n"), version); | |
4478 | printf (_(" Is Supp: %u\n"), is_supplementary); | |
4479 | printf (_(" Filename: %s\n"), sup_filename); | |
4480 | printf (_(" Checksum Len: %lu\n"), (long) checksum_len); | |
4481 | if (checksum_len > 0) | |
4482 | { | |
4483 | printf (_(" Checksum: ")); | |
4484 | while (checksum_len--) | |
4485 | printf ("0x%x ", * start++ ); | |
4486 | printf ("\n"); | |
4487 | } | |
4488 | return 1; | |
4489 | } | |
4490 | ||
b40bf0a2 | 4491 | static int |
dda8d76d NC |
4492 | display_debug_lines_raw (struct dwarf_section * section, |
4493 | unsigned char * data, | |
4494 | unsigned char * end, | |
4495 | void * file) | |
b40bf0a2 NC |
4496 | { |
4497 | unsigned char *start = section->start; | |
ba8826a8 | 4498 | int verbose_view = 0; |
19e6b90e | 4499 | |
015dc7e1 | 4500 | introduce (section, true); |
19e6b90e | 4501 | |
b40bf0a2 NC |
4502 | while (data < end) |
4503 | { | |
4504 | static DWARF2_Internal_LineInfo saved_linfo; | |
4505 | DWARF2_Internal_LineInfo linfo; | |
4506 | unsigned char *standard_opcodes; | |
4507 | unsigned char *end_of_sequence; | |
fe59e83d | 4508 | int i; |
19e6b90e | 4509 | |
24d127aa | 4510 | if (startswith (section->name, ".debug_line.") |
4925cdd7 NC |
4511 | /* Note: the following does not apply to .debug_line.dwo sections. |
4512 | These are full debug_line sections. */ | |
4513 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 4514 | { |
b40bf0a2 NC |
4515 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
4516 | section containing just the Line Number Statements. They are | |
4517 | created by the assembler and intended to be used alongside gcc's | |
4518 | -ffunction-sections command line option. When the linker's | |
4519 | garbage collection decides to discard a .text.<foo> section it | |
4520 | can then also discard the line number information in .debug_line.<foo>. | |
4521 | ||
4925cdd7 | 4522 | Since the section is a fragment it does not have the details |
b40bf0a2 | 4523 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 4524 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
4525 | end_of_sequence = end; |
4526 | standard_opcodes = NULL; | |
4527 | linfo = saved_linfo; | |
058037d3 NC |
4528 | /* PR 17531: file: 0522b371. */ |
4529 | if (linfo.li_line_range == 0) | |
4530 | { | |
1306a742 | 4531 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4532 | return 0; |
4533 | } | |
b40bf0a2 | 4534 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4535 | } |
19e6b90e L |
4536 | else |
4537 | { | |
b40bf0a2 | 4538 | unsigned char * hdrptr; |
19e6b90e | 4539 | |
b40bf0a2 NC |
4540 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4541 | & end_of_sequence)) == NULL) | |
4542 | return 0; | |
19e6b90e | 4543 | |
b40bf0a2 NC |
4544 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
4545 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
4546 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
5496f3c6 NC |
4547 | if (linfo.li_version >= 5) |
4548 | { | |
4549 | printf (_(" Address size (bytes): %d\n"), linfo.li_address_size); | |
4550 | printf (_(" Segment selector (bytes): %d\n"), linfo.li_segment_size); | |
4551 | } | |
77ef8654 | 4552 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
4553 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
4554 | if (linfo.li_version >= 4) | |
4555 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
4556 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
4557 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
4558 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
4559 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 4560 | |
0a9d414a NC |
4561 | /* PR 17512: file: 1665-6428-0.004. */ |
4562 | if (linfo.li_line_range == 0) | |
4563 | { | |
4564 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4565 | linfo.li_line_range = 1; | |
4566 | } | |
77ef8654 | 4567 | |
b40bf0a2 | 4568 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4569 | |
b40bf0a2 NC |
4570 | /* Display the contents of the Opcodes table. */ |
4571 | standard_opcodes = hdrptr; | |
19e6b90e | 4572 | |
6937bb54 NC |
4573 | /* PR 17512: file: 002-417945-0.004. */ |
4574 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
4575 | { | |
4576 | warn (_("Line Base extends beyond end of section\n")); | |
4577 | return 0; | |
4578 | } | |
4579 | ||
b40bf0a2 | 4580 | printf (_("\n Opcodes:\n")); |
19e6b90e | 4581 | |
b40bf0a2 | 4582 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
4583 | printf (ngettext (" Opcode %d has %d arg\n", |
4584 | " Opcode %d has %d args\n", | |
4585 | standard_opcodes[i - 1]), | |
4586 | i, standard_opcodes[i - 1]); | |
19e6b90e | 4587 | |
b40bf0a2 NC |
4588 | /* Display the contents of the Directory table. */ |
4589 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 4590 | |
77145576 | 4591 | if (linfo.li_version >= 5) |
b40bf0a2 | 4592 | { |
dda8d76d | 4593 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 4594 | |
77145576 | 4595 | data = display_formatted_table (data, start, end, &linfo, section, |
015dc7e1 | 4596 | true); |
77145576 | 4597 | data = display_formatted_table (data, start, end, &linfo, section, |
015dc7e1 | 4598 | false); |
77145576 JK |
4599 | } |
4600 | else | |
4601 | { | |
4602 | if (*data == 0) | |
4603 | printf (_("\n The Directory Table is empty.\n")); | |
4604 | else | |
a233b20c | 4605 | { |
77145576 | 4606 | unsigned int last_dir_entry = 0; |
6937bb54 | 4607 | |
77145576 JK |
4608 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
4609 | (long)(data - start)); | |
19e6b90e | 4610 | |
77145576 JK |
4611 | while (data < end && *data != 0) |
4612 | { | |
4613 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 4614 | |
77145576 JK |
4615 | data += strnlen ((char *) data, end - data) + 1; |
4616 | } | |
19e6b90e | 4617 | |
77145576 JK |
4618 | /* PR 17512: file: 002-132094-0.004. */ |
4619 | if (data >= end - 1) | |
4620 | break; | |
4621 | } | |
19e6b90e | 4622 | |
77145576 JK |
4623 | /* Skip the NUL at the end of the table. */ |
4624 | data++; | |
19e6b90e | 4625 | |
77145576 JK |
4626 | /* Display the contents of the File Name table. */ |
4627 | if (*data == 0) | |
4628 | printf (_("\n The File Name Table is empty.\n")); | |
4629 | else | |
4630 | { | |
4631 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
4632 | (long)(data - start)); | |
4633 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 4634 | |
77145576 | 4635 | while (data < end && *data != 0) |
b40bf0a2 | 4636 | { |
77145576 | 4637 | unsigned char *name; |
cd30bcef | 4638 | dwarf_vma val; |
77145576 JK |
4639 | |
4640 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
4641 | name = data; | |
4642 | data += strnlen ((char *) data, end - data) + 1; | |
4643 | ||
cd30bcef AM |
4644 | READ_ULEB (val, data, end); |
4645 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4646 | READ_ULEB (val, data, end); | |
4647 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4648 | READ_ULEB (val, data, end); | |
4649 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
77145576 JK |
4650 | printf ("%.*s\n", (int)(end - name), name); |
4651 | ||
4652 | if (data == end) | |
4653 | { | |
4654 | warn (_("Corrupt file name table entry\n")); | |
4655 | break; | |
4656 | } | |
b40bf0a2 | 4657 | } |
a233b20c | 4658 | } |
77145576 JK |
4659 | |
4660 | /* Skip the NUL at the end of the table. */ | |
4661 | data++; | |
b40bf0a2 | 4662 | } |
19e6b90e | 4663 | |
b40bf0a2 NC |
4664 | putchar ('\n'); |
4665 | saved_linfo = linfo; | |
4666 | } | |
19e6b90e | 4667 | |
b40bf0a2 NC |
4668 | /* Now display the statements. */ |
4669 | if (data >= end_of_sequence) | |
4670 | printf (_(" No Line Number Statements.\n")); | |
4671 | else | |
4672 | { | |
4673 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 4674 | |
b40bf0a2 NC |
4675 | while (data < end_of_sequence) |
4676 | { | |
4677 | unsigned char op_code; | |
4678 | dwarf_signed_vma adv; | |
4679 | dwarf_vma uladv; | |
19e6b90e | 4680 | |
fe59e83d CC |
4681 | printf (" [0x%08lx]", (long)(data - start)); |
4682 | ||
b40bf0a2 | 4683 | op_code = *data++; |
19e6b90e | 4684 | |
b40bf0a2 | 4685 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 4686 | { |
b40bf0a2 NC |
4687 | op_code -= linfo.li_opcode_base; |
4688 | uladv = (op_code / linfo.li_line_range); | |
4689 | if (linfo.li_max_ops_per_insn == 1) | |
4690 | { | |
4691 | uladv *= linfo.li_min_insn_length; | |
4692 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4693 | if (uladv) |
4694 | state_machine_regs.view = 0; | |
b40bf0a2 | 4695 | printf (_(" Special opcode %d: " |
ba8826a8 | 4696 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 4697 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4698 | dwarf_vmatoa ("x", state_machine_regs.address), |
4699 | verbose_view && uladv | |
4700 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4701 | } |
4702 | else | |
4703 | { | |
ba8826a8 AO |
4704 | unsigned addrdelta |
4705 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
4706 | / linfo.li_max_ops_per_insn) |
4707 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
4708 | |
4709 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
4710 | state_machine_regs.op_index |
4711 | = (state_machine_regs.op_index + uladv) | |
4712 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4713 | if (addrdelta) |
4714 | state_machine_regs.view = 0; | |
b40bf0a2 | 4715 | printf (_(" Special opcode %d: " |
ba8826a8 | 4716 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
4717 | op_code, dwarf_vmatoa ("u", uladv), |
4718 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4719 | state_machine_regs.op_index, |
4720 | verbose_view && addrdelta | |
4721 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4722 | } |
4723 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
4724 | state_machine_regs.line += adv; | |
ba8826a8 | 4725 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 4726 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
4727 | if (verbose_view || state_machine_regs.view) |
4728 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4729 | else | |
4730 | putchar ('\n'); | |
4731 | state_machine_regs.view++; | |
19e6b90e | 4732 | } |
cd30bcef AM |
4733 | else |
4734 | switch (op_code) | |
4735 | { | |
4736 | case DW_LNS_extended_op: | |
4737 | data += process_extended_line_op (data, | |
4738 | linfo.li_default_is_stmt, | |
4739 | end); | |
4740 | break; | |
4741 | ||
4742 | case DW_LNS_copy: | |
4743 | printf (_(" Copy")); | |
4744 | if (verbose_view || state_machine_regs.view) | |
4745 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4746 | else | |
4747 | putchar ('\n'); | |
4748 | state_machine_regs.view++; | |
4749 | break; | |
4750 | ||
4751 | case DW_LNS_advance_pc: | |
4752 | READ_ULEB (uladv, data, end); | |
4753 | if (linfo.li_max_ops_per_insn == 1) | |
4754 | { | |
4755 | uladv *= linfo.li_min_insn_length; | |
4756 | state_machine_regs.address += uladv; | |
4757 | if (uladv) | |
4758 | state_machine_regs.view = 0; | |
4759 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
4760 | dwarf_vmatoa ("u", uladv), | |
4761 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4762 | verbose_view && uladv | |
4763 | ? _(" (reset view)") : ""); | |
4764 | } | |
4765 | else | |
4766 | { | |
4767 | unsigned addrdelta | |
4768 | = ((state_machine_regs.op_index + uladv) | |
4769 | / linfo.li_max_ops_per_insn) | |
4770 | * linfo.li_min_insn_length; | |
4771 | state_machine_regs.address | |
4772 | += addrdelta; | |
4773 | state_machine_regs.op_index | |
4774 | = (state_machine_regs.op_index + uladv) | |
4775 | % linfo.li_max_ops_per_insn; | |
4776 | if (addrdelta) | |
4777 | state_machine_regs.view = 0; | |
4778 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
4779 | dwarf_vmatoa ("u", uladv), | |
4780 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4781 | state_machine_regs.op_index, | |
4782 | verbose_view && addrdelta | |
4783 | ? _(" (reset view)") : ""); | |
4784 | } | |
4785 | break; | |
4786 | ||
4787 | case DW_LNS_advance_line: | |
4788 | READ_SLEB (adv, data, end); | |
4789 | state_machine_regs.line += adv; | |
4790 | printf (_(" Advance Line by %s to %d\n"), | |
4791 | dwarf_vmatoa ("d", adv), | |
4792 | state_machine_regs.line); | |
4793 | break; | |
4794 | ||
4795 | case DW_LNS_set_file: | |
4796 | READ_ULEB (uladv, data, end); | |
4797 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
4798 | dwarf_vmatoa ("u", uladv)); | |
4799 | state_machine_regs.file = uladv; | |
4800 | break; | |
4801 | ||
4802 | case DW_LNS_set_column: | |
4803 | READ_ULEB (uladv, data, end); | |
4804 | printf (_(" Set column to %s\n"), | |
4805 | dwarf_vmatoa ("u", uladv)); | |
4806 | state_machine_regs.column = uladv; | |
4807 | break; | |
4808 | ||
4809 | case DW_LNS_negate_stmt: | |
4810 | adv = state_machine_regs.is_stmt; | |
4811 | adv = ! adv; | |
4812 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
4813 | state_machine_regs.is_stmt = adv; | |
4814 | break; | |
4815 | ||
4816 | case DW_LNS_set_basic_block: | |
4817 | printf (_(" Set basic block\n")); | |
4818 | state_machine_regs.basic_block = 1; | |
4819 | break; | |
4820 | ||
4821 | case DW_LNS_const_add_pc: | |
4822 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4823 | if (linfo.li_max_ops_per_insn) | |
4824 | { | |
4825 | uladv *= linfo.li_min_insn_length; | |
4826 | state_machine_regs.address += uladv; | |
4827 | if (uladv) | |
4828 | state_machine_regs.view = 0; | |
4829 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
4830 | dwarf_vmatoa ("u", uladv), | |
4831 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4832 | verbose_view && uladv | |
4833 | ? _(" (reset view)") : ""); | |
4834 | } | |
4835 | else | |
4836 | { | |
4837 | unsigned addrdelta | |
4838 | = ((state_machine_regs.op_index + uladv) | |
4839 | / linfo.li_max_ops_per_insn) | |
4840 | * linfo.li_min_insn_length; | |
4841 | state_machine_regs.address | |
4842 | += addrdelta; | |
4843 | state_machine_regs.op_index | |
4844 | = (state_machine_regs.op_index + uladv) | |
4845 | % linfo.li_max_ops_per_insn; | |
4846 | if (addrdelta) | |
4847 | state_machine_regs.view = 0; | |
4848 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
4849 | dwarf_vmatoa ("u", uladv), | |
4850 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4851 | state_machine_regs.op_index, | |
4852 | verbose_view && addrdelta | |
4853 | ? _(" (reset view)") : ""); | |
4854 | } | |
4855 | break; | |
4856 | ||
4857 | case DW_LNS_fixed_advance_pc: | |
4858 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4859 | state_machine_regs.address += uladv; | |
4860 | state_machine_regs.op_index = 0; | |
4861 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
4862 | dwarf_vmatoa ("u", uladv), | |
4863 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
4864 | /* Do NOT reset view. */ | |
4865 | break; | |
4866 | ||
4867 | case DW_LNS_set_prologue_end: | |
4868 | printf (_(" Set prologue_end to true\n")); | |
4869 | break; | |
4870 | ||
4871 | case DW_LNS_set_epilogue_begin: | |
4872 | printf (_(" Set epilogue_begin to true\n")); | |
4873 | break; | |
4874 | ||
4875 | case DW_LNS_set_isa: | |
4876 | READ_ULEB (uladv, data, end); | |
4877 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
4878 | break; | |
4879 | ||
4880 | default: | |
4881 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4882 | ||
4883 | if (standard_opcodes != NULL) | |
4884 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4885 | { | |
4886 | READ_ULEB (uladv, data, end); | |
4887 | printf ("0x%s%s", dwarf_vmatoa ("x", uladv), | |
4888 | i == 1 ? "" : ", "); | |
4889 | } | |
4890 | putchar ('\n'); | |
4891 | break; | |
4892 | } | |
19e6b90e | 4893 | } |
b40bf0a2 | 4894 | putchar ('\n'); |
19e6b90e | 4895 | } |
19e6b90e L |
4896 | } |
4897 | ||
4898 | return 1; | |
4899 | } | |
4900 | ||
a262ae96 NC |
4901 | typedef struct |
4902 | { | |
467c65bc NC |
4903 | unsigned char *name; |
4904 | unsigned int directory_index; | |
4905 | unsigned int modification_date; | |
4906 | unsigned int length; | |
a262ae96 NC |
4907 | } File_Entry; |
4908 | ||
4909 | /* Output a decoded representation of the .debug_line section. */ | |
4910 | ||
4911 | static int | |
dda8d76d | 4912 | display_debug_lines_decoded (struct dwarf_section * section, |
ec1b0fbb | 4913 | unsigned char * start, |
dda8d76d NC |
4914 | unsigned char * data, |
4915 | unsigned char * end, | |
4916 | void * fileptr) | |
a262ae96 | 4917 | { |
b40bf0a2 NC |
4918 | static DWARF2_Internal_LineInfo saved_linfo; |
4919 | ||
015dc7e1 | 4920 | introduce (section, false); |
a262ae96 NC |
4921 | |
4922 | while (data < end) | |
4923 | { | |
4924 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4925 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4926 | unsigned char *standard_opcodes; |
4927 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4928 | int i; |
4929 | File_Entry *file_table = NULL; | |
143a3db0 | 4930 | unsigned int n_files = 0; |
a262ae96 | 4931 | unsigned char **directory_table = NULL; |
77145576 | 4932 | dwarf_vma n_directories = 0; |
a262ae96 | 4933 | |
24d127aa | 4934 | if (startswith (section->name, ".debug_line.") |
4925cdd7 NC |
4935 | /* Note: the following does not apply to .debug_line.dwo sections. |
4936 | These are full debug_line sections. */ | |
4937 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4938 | { |
4925cdd7 | 4939 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4940 | end_of_sequence = end; |
4941 | standard_opcodes = NULL; | |
4942 | linfo = saved_linfo; | |
058037d3 NC |
4943 | /* PR 17531: file: 0522b371. */ |
4944 | if (linfo.li_line_range == 0) | |
4945 | { | |
1306a742 | 4946 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4947 | return 0; |
4948 | } | |
b40bf0a2 | 4949 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4950 | } |
a262ae96 | 4951 | else |
b4eb7656 | 4952 | { |
b40bf0a2 | 4953 | unsigned char *hdrptr; |
a262ae96 | 4954 | |
b40bf0a2 NC |
4955 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4956 | & end_of_sequence)) == NULL) | |
a233b20c | 4957 | return 0; |
0c588247 | 4958 | |
058037d3 NC |
4959 | /* PR 17531: file: 0522b371. */ |
4960 | if (linfo.li_line_range == 0) | |
4961 | { | |
4962 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4963 | linfo.li_line_range = 1; | |
4964 | } | |
b40bf0a2 | 4965 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4966 | |
b40bf0a2 NC |
4967 | /* Save a pointer to the contents of the Opcodes table. */ |
4968 | standard_opcodes = hdrptr; | |
a262ae96 | 4969 | |
b40bf0a2 NC |
4970 | /* Traverse the Directory table just to count entries. */ |
4971 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4972 | /* PR 20440 */ |
4973 | if (data >= end) | |
4974 | { | |
4975 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4976 | linfo.li_opcode_base); | |
4977 | return 0; | |
4978 | } | |
4979 | ||
77145576 | 4980 | if (linfo.li_version >= 5) |
b40bf0a2 | 4981 | { |
77145576 JK |
4982 | unsigned char *format_start, format_count, *format; |
4983 | dwarf_vma formati, entryi; | |
a262ae96 | 4984 | |
dda8d76d | 4985 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4986 | |
4987 | /* Skip directories format. */ | |
4988 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4989 | if (do_checks && format_count > 1) |
4990 | warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"), | |
4991 | format_count); | |
77145576 JK |
4992 | format_start = data; |
4993 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4994 | { |
cd30bcef AM |
4995 | SKIP_ULEB (data, end); |
4996 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4997 | } |
a262ae96 | 4998 | |
cd30bcef | 4999 | READ_ULEB (n_directories, data, end); |
77145576 | 5000 | if (data == end) |
d8024a91 | 5001 | { |
77145576 | 5002 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
5003 | break; |
5004 | } | |
5005 | ||
070b775f NC |
5006 | if (n_directories == 0) |
5007 | directory_table = NULL; | |
5008 | else | |
5009 | directory_table = (unsigned char **) | |
5010 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 5011 | |
77145576 | 5012 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 5013 | { |
77145576 | 5014 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 5015 | |
77145576 JK |
5016 | format = format_start; |
5017 | for (formati = 0; formati < format_count; formati++) | |
5018 | { | |
5019 | dwarf_vma content_type, form; | |
5020 | dwarf_vma uvalue; | |
5021 | ||
cd30bcef AM |
5022 | READ_ULEB (content_type, format, end); |
5023 | READ_ULEB (form, format, end); | |
77145576 JK |
5024 | if (data == end) |
5025 | { | |
5026 | warn (_("Corrupt directories list\n")); | |
5027 | break; | |
5028 | } | |
5029 | switch (content_type) | |
5030 | { | |
5031 | case DW_LNCT_path: | |
5032 | switch (form) | |
5033 | { | |
5034 | case DW_FORM_string: | |
5035 | *pathp = data; | |
5036 | break; | |
5037 | case DW_FORM_line_strp: | |
5038 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
5039 | end); | |
5040 | /* Remove const by the cast. */ | |
5041 | *pathp = (unsigned char *) | |
5042 | fetch_indirect_line_string (uvalue); | |
5043 | break; | |
5044 | } | |
5045 | break; | |
5046 | } | |
cd30bcef AM |
5047 | data = read_and_display_attr_value (0, form, 0, start, |
5048 | data, end, 0, 0, | |
77145576 JK |
5049 | linfo.li_offset_size, |
5050 | linfo.li_version, | |
5051 | NULL, 1, section, | |
ec1b0fbb | 5052 | NULL, '\t', -1); |
77145576 JK |
5053 | } |
5054 | if (data == end) | |
5055 | { | |
5056 | warn (_("Corrupt directories list\n")); | |
5057 | break; | |
5058 | } | |
5059 | } | |
a262ae96 | 5060 | |
77145576 JK |
5061 | /* Skip files format. */ |
5062 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
5063 | if (do_checks && format_count > 5) |
5064 | warn (_("Unexpectedly large number of columns in the file name table (%u)\n"), | |
5065 | format_count); | |
77145576 JK |
5066 | format_start = data; |
5067 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 5068 | { |
cd30bcef AM |
5069 | SKIP_ULEB (data, end); |
5070 | SKIP_ULEB (data, end); | |
b40bf0a2 | 5071 | } |
a262ae96 | 5072 | |
cd30bcef | 5073 | READ_ULEB (n_files, data, end); |
070b775f | 5074 | if (data == end && n_files > 0) |
d8024a91 | 5075 | { |
77145576 | 5076 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
5077 | break; |
5078 | } | |
5079 | ||
070b775f NC |
5080 | if (n_files == 0) |
5081 | file_table = NULL; | |
5082 | else | |
5083 | file_table = (File_Entry *) xcalloc (1, n_files | |
5084 | * sizeof (File_Entry)); | |
a262ae96 | 5085 | |
77145576 | 5086 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 5087 | { |
77145576 | 5088 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 5089 | |
77145576 JK |
5090 | format = format_start; |
5091 | for (formati = 0; formati < format_count; formati++) | |
5092 | { | |
5093 | dwarf_vma content_type, form; | |
5094 | dwarf_vma uvalue; | |
cd30bcef | 5095 | unsigned char *tmp; |
77145576 | 5096 | |
cd30bcef AM |
5097 | READ_ULEB (content_type, format, end); |
5098 | READ_ULEB (form, format, end); | |
77145576 JK |
5099 | if (data == end) |
5100 | { | |
5101 | warn (_("Corrupt file name list\n")); | |
5102 | break; | |
5103 | } | |
5104 | switch (content_type) | |
5105 | { | |
5106 | case DW_LNCT_path: | |
5107 | switch (form) | |
5108 | { | |
5109 | case DW_FORM_string: | |
5110 | file->name = data; | |
5111 | break; | |
5112 | case DW_FORM_line_strp: | |
5113 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
5114 | end); | |
5115 | /* Remove const by the cast. */ | |
5116 | file->name = (unsigned char *) | |
5117 | fetch_indirect_line_string (uvalue); | |
5118 | break; | |
5119 | } | |
5120 | break; | |
5121 | case DW_LNCT_directory_index: | |
5122 | switch (form) | |
5123 | { | |
5124 | case DW_FORM_data1: | |
5125 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
5126 | end); | |
5127 | break; | |
5128 | case DW_FORM_data2: | |
5129 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
5130 | end); | |
5131 | break; | |
5132 | case DW_FORM_udata: | |
cd30bcef AM |
5133 | tmp = data; |
5134 | READ_ULEB (file->directory_index, tmp, end); | |
77145576 JK |
5135 | break; |
5136 | } | |
5137 | break; | |
5138 | } | |
cd30bcef AM |
5139 | data = read_and_display_attr_value (0, form, 0, start, |
5140 | data, end, 0, 0, | |
77145576 JK |
5141 | linfo.li_offset_size, |
5142 | linfo.li_version, | |
5143 | NULL, 1, section, | |
ec1b0fbb | 5144 | NULL, '\t', -1); |
77145576 JK |
5145 | } |
5146 | if (data == end) | |
5147 | { | |
5148 | warn (_("Corrupt file name list\n")); | |
5149 | break; | |
5150 | } | |
5151 | } | |
5152 | } | |
5153 | else | |
5154 | { | |
5155 | if (*data != 0) | |
b40bf0a2 | 5156 | { |
77145576 JK |
5157 | unsigned char *ptr_directory_table = data; |
5158 | ||
5159 | while (data < end && *data != 0) | |
5160 | { | |
5161 | data += strnlen ((char *) data, end - data) + 1; | |
5162 | n_directories++; | |
5163 | } | |
5164 | ||
5165 | /* PR 20440 */ | |
5166 | if (data >= end) | |
5167 | { | |
5168 | warn (_("directory table ends unexpectedly\n")); | |
5169 | n_directories = 0; | |
5170 | break; | |
5171 | } | |
5172 | ||
5173 | /* Go through the directory table again to save the directories. */ | |
5174 | directory_table = (unsigned char **) | |
5175 | xmalloc (n_directories * sizeof (unsigned char *)); | |
5176 | ||
5177 | i = 0; | |
5178 | while (*ptr_directory_table != 0) | |
5179 | { | |
5180 | directory_table[i] = ptr_directory_table; | |
5181 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
5182 | ptr_directory_table - end) + 1; | |
5183 | i++; | |
5184 | } | |
b40bf0a2 | 5185 | } |
77145576 JK |
5186 | /* Skip the NUL at the end of the table. */ |
5187 | data++; | |
5188 | ||
5189 | /* Traverse the File Name table just to count the entries. */ | |
5190 | if (data < end && *data != 0) | |
b40bf0a2 | 5191 | { |
77145576 JK |
5192 | unsigned char *ptr_file_name_table = data; |
5193 | ||
5194 | while (data < end && *data != 0) | |
db9537d2 | 5195 | { |
cd30bcef AM |
5196 | /* Skip Name, directory index, last modification |
5197 | time and length of file. */ | |
77145576 | 5198 | data += strnlen ((char *) data, end - data) + 1; |
cd30bcef AM |
5199 | SKIP_ULEB (data, end); |
5200 | SKIP_ULEB (data, end); | |
5201 | SKIP_ULEB (data, end); | |
77145576 | 5202 | n_files++; |
db9537d2 | 5203 | } |
a262ae96 | 5204 | |
77145576 JK |
5205 | if (data >= end) |
5206 | { | |
5207 | warn (_("file table ends unexpectedly\n")); | |
5208 | n_files = 0; | |
5209 | break; | |
5210 | } | |
5211 | ||
5212 | /* Go through the file table again to save the strings. */ | |
5213 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 5214 | |
77145576 JK |
5215 | i = 0; |
5216 | while (*ptr_file_name_table != 0) | |
5217 | { | |
77145576 JK |
5218 | file_table[i].name = ptr_file_name_table; |
5219 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
5220 | end - ptr_file_name_table) + 1; | |
5221 | ||
5222 | /* We are not interested in directory, time or size. */ | |
cd30bcef AM |
5223 | READ_ULEB (file_table[i].directory_index, |
5224 | ptr_file_name_table, end); | |
5225 | READ_ULEB (file_table[i].modification_date, | |
5226 | ptr_file_name_table, end); | |
5227 | READ_ULEB (file_table[i].length, | |
5228 | ptr_file_name_table, end); | |
77145576 JK |
5229 | i++; |
5230 | } | |
5231 | i = 0; | |
b40bf0a2 | 5232 | } |
77145576 JK |
5233 | |
5234 | /* Skip the NUL at the end of the table. */ | |
5235 | data++; | |
b40bf0a2 | 5236 | } |
cc5914eb | 5237 | |
77145576 | 5238 | /* Print the Compilation Unit's name and a header. */ |
f082820d | 5239 | if (file_table == NULL) |
070b775f | 5240 | printf (_("CU: No directory table\n")); |
f082820d AM |
5241 | else if (directory_table == NULL) |
5242 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
5243 | else |
5244 | { | |
5245 | unsigned int ix = file_table[0].directory_index; | |
5246 | const char *directory; | |
5247 | ||
5248 | if (ix == 0) | |
5249 | directory = "."; | |
5250 | /* PR 20439 */ | |
5251 | else if (n_directories == 0) | |
5252 | directory = _("<unknown>"); | |
5253 | else if (ix > n_directories) | |
5254 | { | |
5255 | warn (_("directory index %u > number of directories %s\n"), | |
5256 | ix, dwarf_vmatoa ("u", n_directories)); | |
5257 | directory = _("<corrupt>"); | |
5258 | } | |
5259 | else | |
5260 | directory = (char *) directory_table[ix - 1]; | |
5261 | ||
5262 | if (do_wide || strlen (directory) < 76) | |
5263 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
5264 | else | |
5265 | printf ("%s:\n", file_table[0].name); | |
77145576 | 5266 | } |
a262ae96 | 5267 | |
070b775f NC |
5268 | if (n_files > 0) |
5269 | printf (_("File name Line number Starting address View Stmt\n")); | |
5270 | else | |
5271 | printf (_("CU: Empty file name table\n")); | |
b40bf0a2 NC |
5272 | saved_linfo = linfo; |
5273 | } | |
a262ae96 NC |
5274 | |
5275 | /* This loop iterates through the Dwarf Line Number Program. */ | |
5276 | while (data < end_of_sequence) | |
b4eb7656 | 5277 | { |
a262ae96 | 5278 | unsigned char op_code; |
ba8826a8 | 5279 | int xop; |
b4eb7656 AM |
5280 | int adv; |
5281 | unsigned long int uladv; | |
b4eb7656 | 5282 | int is_special_opcode = 0; |
a262ae96 | 5283 | |
b4eb7656 | 5284 | op_code = *data++; |
ba8826a8 | 5285 | xop = op_code; |
a262ae96 | 5286 | |
b4eb7656 | 5287 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 5288 | { |
91d6fa6a | 5289 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
5290 | uladv = (op_code / linfo.li_line_range); |
5291 | if (linfo.li_max_ops_per_insn == 1) | |
5292 | { | |
5293 | uladv *= linfo.li_min_insn_length; | |
5294 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
5295 | if (uladv) |
5296 | state_machine_regs.view = 0; | |
a233b20c JJ |
5297 | } |
5298 | else | |
5299 | { | |
ba8826a8 AO |
5300 | unsigned addrdelta |
5301 | = ((state_machine_regs.op_index + uladv) | |
5302 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 5303 | * linfo.li_min_insn_length; |
ba8826a8 AO |
5304 | state_machine_regs.address |
5305 | += addrdelta; | |
a233b20c JJ |
5306 | state_machine_regs.op_index |
5307 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 5308 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
5309 | if (addrdelta) |
5310 | state_machine_regs.view = 0; | |
a233b20c | 5311 | } |
a262ae96 | 5312 | |
b4eb7656 AM |
5313 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
5314 | state_machine_regs.line += adv; | |
5315 | is_special_opcode = 1; | |
ba8826a8 | 5316 | /* Increment view after printing this row. */ |
b4eb7656 | 5317 | } |
cd30bcef AM |
5318 | else |
5319 | switch (op_code) | |
5320 | { | |
5321 | case DW_LNS_extended_op: | |
5322 | { | |
5323 | unsigned int ext_op_code_len; | |
5324 | unsigned char ext_op_code; | |
5325 | unsigned char *op_code_end; | |
5326 | unsigned char *op_code_data = data; | |
5327 | ||
5328 | READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence); | |
5329 | op_code_end = op_code_data + ext_op_code_len; | |
5330 | if (ext_op_code_len == 0 || op_code_end > end_of_sequence) | |
5331 | { | |
5332 | warn (_("Badly formed extended line op encountered!\n")); | |
5333 | break; | |
5334 | } | |
5335 | ext_op_code = *op_code_data++; | |
5336 | xop = ext_op_code; | |
5337 | xop = -xop; | |
5338 | ||
5339 | switch (ext_op_code) | |
5340 | { | |
5341 | case DW_LNE_end_sequence: | |
5342 | /* Reset stuff after printing this row. */ | |
5343 | break; | |
5344 | case DW_LNE_set_address: | |
5345 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
5346 | op_code_data, | |
5347 | op_code_end - op_code_data, | |
5348 | op_code_end); | |
5349 | state_machine_regs.op_index = 0; | |
5350 | state_machine_regs.view = 0; | |
5351 | break; | |
5352 | case DW_LNE_define_file: | |
5353 | file_table = (File_Entry *) xrealloc | |
5354 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
5355 | ||
5356 | ++state_machine_regs.last_file_entry; | |
5357 | /* Source file name. */ | |
5358 | file_table[n_files].name = op_code_data; | |
5359 | op_code_data += strlen ((char *) op_code_data) + 1; | |
5360 | /* Directory index. */ | |
5361 | READ_ULEB (file_table[n_files].directory_index, | |
5362 | op_code_data, op_code_end); | |
5363 | /* Last modification time. */ | |
5364 | READ_ULEB (file_table[n_files].modification_date, | |
5365 | op_code_data, op_code_end); | |
5366 | /* File length. */ | |
5367 | READ_ULEB (file_table[n_files].length, | |
5368 | op_code_data, op_code_end); | |
5369 | n_files++; | |
5370 | break; | |
5371 | ||
5372 | case DW_LNE_set_discriminator: | |
5373 | case DW_LNE_HP_set_sequence: | |
5374 | /* Simply ignored. */ | |
5375 | break; | |
5376 | ||
5377 | default: | |
5378 | printf (_("UNKNOWN (%u): length %ld\n"), | |
27653fba | 5379 | ext_op_code, (long int) (op_code_data - data)); |
cd30bcef AM |
5380 | break; |
5381 | } | |
5382 | data = op_code_end; | |
5383 | break; | |
5384 | } | |
5385 | case DW_LNS_copy: | |
5386 | /* Increment view after printing this row. */ | |
5387 | break; | |
5388 | ||
5389 | case DW_LNS_advance_pc: | |
5390 | READ_ULEB (uladv, data, end); | |
5391 | if (linfo.li_max_ops_per_insn == 1) | |
5392 | { | |
5393 | uladv *= linfo.li_min_insn_length; | |
5394 | state_machine_regs.address += uladv; | |
5395 | if (uladv) | |
5396 | state_machine_regs.view = 0; | |
5397 | } | |
5398 | else | |
5399 | { | |
5400 | unsigned addrdelta | |
5401 | = ((state_machine_regs.op_index + uladv) | |
5402 | / linfo.li_max_ops_per_insn) | |
5403 | * linfo.li_min_insn_length; | |
5404 | state_machine_regs.address | |
5405 | += addrdelta; | |
5406 | state_machine_regs.op_index | |
5407 | = (state_machine_regs.op_index + uladv) | |
5408 | % linfo.li_max_ops_per_insn; | |
5409 | if (addrdelta) | |
5410 | state_machine_regs.view = 0; | |
5411 | } | |
5412 | break; | |
5413 | ||
5414 | case DW_LNS_advance_line: | |
5415 | READ_SLEB (adv, data, end); | |
5416 | state_machine_regs.line += adv; | |
5417 | break; | |
5418 | ||
5419 | case DW_LNS_set_file: | |
5420 | READ_ULEB (uladv, data, end); | |
5421 | state_machine_regs.file = uladv; | |
5422 | ||
5423 | { | |
5424 | unsigned file = state_machine_regs.file - 1; | |
5425 | unsigned dir; | |
5426 | ||
5427 | if (file_table == NULL || n_files == 0) | |
5428 | printf (_("\n [Use file table entry %d]\n"), file); | |
5429 | /* PR 20439 */ | |
5430 | else if (file >= n_files) | |
5431 | { | |
5432 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
5433 | printf (_("\n <over large file table index %u>"), file); | |
5434 | } | |
5435 | else if ((dir = file_table[file].directory_index) == 0) | |
5436 | /* If directory index is 0, that means current directory. */ | |
5437 | printf ("\n./%s:[++]\n", file_table[file].name); | |
5438 | else if (directory_table == NULL || n_directories == 0) | |
5439 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
5440 | file_table[file].name, dir); | |
5441 | /* PR 20439 */ | |
5442 | else if (dir > n_directories) | |
5443 | { | |
5444 | warn (_("directory index %u > number of directories %s\n"), | |
5445 | dir, dwarf_vmatoa ("u", n_directories)); | |
5446 | printf (_("\n <over large directory table entry %u>\n"), dir); | |
5447 | } | |
5448 | else | |
5449 | printf ("\n%s/%s:\n", | |
5450 | /* The directory index starts counting at 1. */ | |
5451 | directory_table[dir - 1], file_table[file].name); | |
5452 | } | |
5453 | break; | |
5454 | ||
5455 | case DW_LNS_set_column: | |
5456 | READ_ULEB (uladv, data, end); | |
5457 | state_machine_regs.column = uladv; | |
5458 | break; | |
5459 | ||
5460 | case DW_LNS_negate_stmt: | |
5461 | adv = state_machine_regs.is_stmt; | |
5462 | adv = ! adv; | |
5463 | state_machine_regs.is_stmt = adv; | |
5464 | break; | |
5465 | ||
5466 | case DW_LNS_set_basic_block: | |
5467 | state_machine_regs.basic_block = 1; | |
5468 | break; | |
5469 | ||
5470 | case DW_LNS_const_add_pc: | |
5471 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
5472 | if (linfo.li_max_ops_per_insn == 1) | |
5473 | { | |
5474 | uladv *= linfo.li_min_insn_length; | |
5475 | state_machine_regs.address += uladv; | |
5476 | if (uladv) | |
5477 | state_machine_regs.view = 0; | |
5478 | } | |
5479 | else | |
5480 | { | |
5481 | unsigned addrdelta | |
5482 | = ((state_machine_regs.op_index + uladv) | |
5483 | / linfo.li_max_ops_per_insn) | |
5484 | * linfo.li_min_insn_length; | |
5485 | state_machine_regs.address | |
5486 | += addrdelta; | |
5487 | state_machine_regs.op_index | |
5488 | = (state_machine_regs.op_index + uladv) | |
5489 | % linfo.li_max_ops_per_insn; | |
5490 | if (addrdelta) | |
5491 | state_machine_regs.view = 0; | |
5492 | } | |
5493 | break; | |
5494 | ||
5495 | case DW_LNS_fixed_advance_pc: | |
5496 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
5497 | state_machine_regs.address += uladv; | |
5498 | state_machine_regs.op_index = 0; | |
5499 | /* Do NOT reset view. */ | |
5500 | break; | |
5501 | ||
5502 | case DW_LNS_set_prologue_end: | |
5503 | break; | |
5504 | ||
5505 | case DW_LNS_set_epilogue_begin: | |
5506 | break; | |
5507 | ||
5508 | case DW_LNS_set_isa: | |
5509 | READ_ULEB (uladv, data, end); | |
5510 | printf (_(" Set ISA to %lu\n"), uladv); | |
5511 | break; | |
5512 | ||
5513 | default: | |
5514 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
5515 | ||
5516 | if (standard_opcodes != NULL) | |
5517 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
5518 | { | |
5519 | dwarf_vma val; | |
5520 | ||
5521 | READ_ULEB (val, data, end); | |
5522 | printf ("0x%s%s", dwarf_vmatoa ("x", val), | |
5523 | i == 1 ? "" : ", "); | |
5524 | } | |
5525 | putchar ('\n'); | |
5526 | break; | |
5527 | } | |
a262ae96 | 5528 | |
b4eb7656 AM |
5529 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
5530 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
5531 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
5532 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
5533 | { |
5534 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
5535 | char *fileName; | |
5536 | char *newFileName = NULL; | |
5537 | size_t fileNameLength; | |
b40bf0a2 NC |
5538 | |
5539 | if (file_table) | |
db9537d2 NC |
5540 | { |
5541 | unsigned indx = state_machine_regs.file - 1; | |
5542 | /* PR 20439 */ | |
5543 | if (indx >= n_files) | |
5544 | { | |
5545 | warn (_("corrupt file index %u encountered\n"), indx); | |
5546 | fileName = _("<corrupt>"); | |
5547 | } | |
5548 | else | |
5549 | fileName = (char *) file_table[indx].name; | |
5550 | } | |
b40bf0a2 | 5551 | else |
db9537d2 | 5552 | fileName = _("<unknown>"); |
b40bf0a2 NC |
5553 | |
5554 | fileNameLength = strlen (fileName); | |
a262ae96 | 5555 | |
b4eb7656 AM |
5556 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
5557 | { | |
5558 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
5559 | /* Truncate file name */ | |
5560 | strncpy (newFileName, | |
5561 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
5562 | MAX_FILENAME_LENGTH + 1); | |
e1104d08 NC |
5563 | /* FIXME: This is to pacify gcc-10 which can warn that the |
5564 | strncpy above might leave a non-NUL terminated string | |
5565 | in newFileName. It won't, but gcc's analysis doesn't | |
5566 | quite go far enough to discover this. */ | |
5567 | newFileName[MAX_FILENAME_LENGTH] = 0; | |
b4eb7656 AM |
5568 | } |
5569 | else | |
5570 | { | |
5571 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
5572 | strncpy (newFileName, fileName, fileNameLength + 1); | |
5573 | } | |
5574 | ||
af2b3186 TV |
5575 | /* A row with end_seq set to true has a meaningful address, but |
5576 | the other information in the same row is not significant. | |
5577 | In such a row, print line as "-", and don't print | |
5578 | view/is_stmt. */ | |
b4eb7656 AM |
5579 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) |
5580 | { | |
a233b20c | 5581 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5582 | { |
5583 | if (xop == -DW_LNE_end_sequence) | |
5584 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x", | |
5585 | newFileName, "-", | |
5586 | state_machine_regs.address); | |
5587 | else | |
5588 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", | |
5589 | newFileName, state_machine_regs.line, | |
5590 | state_machine_regs.address); | |
5591 | } | |
a233b20c | 5592 | else |
af2b3186 TV |
5593 | { |
5594 | if (xop == -DW_LNE_end_sequence) | |
5595 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5596 | newFileName, "-", | |
5597 | state_machine_regs.address, | |
5598 | state_machine_regs.op_index); | |
5599 | else | |
5600 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5601 | newFileName, state_machine_regs.line, | |
5602 | state_machine_regs.address, | |
5603 | state_machine_regs.op_index); | |
5604 | } | |
b4eb7656 AM |
5605 | } |
5606 | else | |
5607 | { | |
a233b20c | 5608 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5609 | { |
5610 | if (xop == -DW_LNE_end_sequence) | |
5611 | printf ("%s %11s %#18" DWARF_VMA_FMT "x", | |
5612 | newFileName, "-", | |
5613 | state_machine_regs.address); | |
5614 | else | |
5615 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", | |
5616 | newFileName, state_machine_regs.line, | |
5617 | state_machine_regs.address); | |
5618 | } | |
a233b20c | 5619 | else |
af2b3186 TV |
5620 | { |
5621 | if (xop == -DW_LNE_end_sequence) | |
5622 | printf ("%s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5623 | newFileName, "-", | |
5624 | state_machine_regs.address, | |
5625 | state_machine_regs.op_index); | |
5626 | else | |
5627 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5628 | newFileName, state_machine_regs.line, | |
5629 | state_machine_regs.address, | |
5630 | state_machine_regs.op_index); | |
5631 | } | |
b4eb7656 | 5632 | } |
a262ae96 | 5633 | |
af2b3186 TV |
5634 | if (xop != -DW_LNE_end_sequence) |
5635 | { | |
5636 | if (state_machine_regs.view) | |
5637 | printf (" %6u", state_machine_regs.view); | |
5638 | else | |
5639 | printf (" "); | |
17f6ade2 | 5640 | |
af2b3186 TV |
5641 | if (state_machine_regs.is_stmt) |
5642 | printf (" x"); | |
5643 | } | |
17f6ade2 JD |
5644 | |
5645 | putchar ('\n'); | |
ba8826a8 AO |
5646 | state_machine_regs.view++; |
5647 | ||
5648 | if (xop == -DW_LNE_end_sequence) | |
5649 | { | |
5650 | reset_state_machine (linfo.li_default_is_stmt); | |
5651 | putchar ('\n'); | |
5652 | } | |
a262ae96 | 5653 | |
b4eb7656 AM |
5654 | free (newFileName); |
5655 | } | |
5656 | } | |
b40bf0a2 NC |
5657 | |
5658 | if (file_table) | |
5659 | { | |
5660 | free (file_table); | |
5661 | file_table = NULL; | |
5662 | n_files = 0; | |
5663 | } | |
5664 | ||
5665 | if (directory_table) | |
5666 | { | |
5667 | free (directory_table); | |
5668 | directory_table = NULL; | |
5669 | n_directories = 0; | |
5670 | } | |
5671 | ||
a262ae96 NC |
5672 | putchar ('\n'); |
5673 | } | |
5674 | ||
5675 | return 1; | |
5676 | } | |
5677 | ||
5678 | static int | |
77145576 | 5679 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
5680 | { |
5681 | unsigned char *data = section->start; | |
5682 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
5683 | int retValRaw = 1; |
5684 | int retValDecoded = 1; | |
a262ae96 | 5685 | |
008f4c78 NC |
5686 | if (do_debug_lines == 0) |
5687 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
5688 | ||
4cb93e3b | 5689 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 5690 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 5691 | |
4cb93e3b | 5692 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
ec1b0fbb | 5693 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
a262ae96 | 5694 | |
4cb93e3b | 5695 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
5696 | return 0; |
5697 | ||
5698 | return 1; | |
5699 | } | |
5700 | ||
6e3d6dc1 NC |
5701 | static debug_info * |
5702 | find_debug_info_for_offset (unsigned long offset) | |
5703 | { | |
5704 | unsigned int i; | |
5705 | ||
5706 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
5707 | return NULL; | |
5708 | ||
5709 | for (i = 0; i < num_debug_info_entries; i++) | |
5710 | if (debug_information[i].cu_offset == offset) | |
5711 | return debug_information + i; | |
5712 | ||
5713 | return NULL; | |
5714 | } | |
5715 | ||
459d52c8 DE |
5716 | static const char * |
5717 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
5718 | { | |
5719 | /* See gdb/gdb-index.h. */ | |
5720 | static const char * const kinds[] = | |
5721 | { | |
5722 | N_ ("no info"), | |
5723 | N_ ("type"), | |
5724 | N_ ("variable"), | |
5725 | N_ ("function"), | |
5726 | N_ ("other"), | |
5727 | N_ ("unused5"), | |
5728 | N_ ("unused6"), | |
5729 | N_ ("unused7") | |
5730 | }; | |
5731 | ||
5732 | return _ (kinds[kind]); | |
5733 | } | |
5734 | ||
19e6b90e | 5735 | static int |
459d52c8 DE |
5736 | display_debug_pubnames_worker (struct dwarf_section *section, |
5737 | void *file ATTRIBUTE_UNUSED, | |
5738 | int is_gnu) | |
19e6b90e | 5739 | { |
91d6fa6a | 5740 | DWARF2_Internal_PubNames names; |
19e6b90e L |
5741 | unsigned char *start = section->start; |
5742 | unsigned char *end = start + section->size; | |
5743 | ||
6e3d6dc1 NC |
5744 | /* It does not matter if this load fails, |
5745 | we test for that later on. */ | |
5746 | load_debug_info (file); | |
5747 | ||
015dc7e1 | 5748 | introduce (section, false); |
19e6b90e L |
5749 | |
5750 | while (start < end) | |
5751 | { | |
5752 | unsigned char *data; | |
e98fdf1a | 5753 | unsigned long sec_off; |
bf5117e3 | 5754 | unsigned int offset_size, initial_length_size; |
19e6b90e | 5755 | |
e98fdf1a | 5756 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 5757 | if (names.pn_length == 0xffffffff) |
19e6b90e | 5758 | { |
e98fdf1a | 5759 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e L |
5760 | offset_size = 8; |
5761 | initial_length_size = 12; | |
5762 | } | |
5763 | else | |
5764 | { | |
5765 | offset_size = 4; | |
5766 | initial_length_size = 4; | |
5767 | } | |
5768 | ||
e98fdf1a AM |
5769 | sec_off = start - section->start; |
5770 | if (sec_off + names.pn_length < sec_off | |
5771 | || sec_off + names.pn_length > section->size) | |
5772 | { | |
5773 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
5774 | section->name, | |
5775 | sec_off - initial_length_size, | |
5776 | dwarf_vmatoa ("x", names.pn_length)); | |
5777 | break; | |
5778 | } | |
5779 | ||
5780 | data = start; | |
5781 | start += names.pn_length; | |
5782 | ||
0c588247 NC |
5783 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
5784 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
5785 | |
5786 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
5787 | && num_debug_info_entries > 0 | |
91d6fa6a | 5788 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 5789 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 5790 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 5791 | |
0c588247 | 5792 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 5793 | |
058037d3 NC |
5794 | printf (_(" Length: %ld\n"), |
5795 | (long) names.pn_length); | |
5796 | printf (_(" Version: %d\n"), | |
5797 | names.pn_version); | |
5798 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
5799 | (unsigned long) names.pn_offset); | |
5800 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
5801 | (long) names.pn_size); | |
19e6b90e | 5802 | |
91d6fa6a | 5803 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
5804 | { |
5805 | static int warned = 0; | |
5806 | ||
5807 | if (! warned) | |
5808 | { | |
5809 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
5810 | warned = 1; | |
5811 | } | |
5812 | ||
5813 | continue; | |
5814 | } | |
5815 | ||
459d52c8 DE |
5816 | if (is_gnu) |
5817 | printf (_("\n Offset Kind Name\n")); | |
5818 | else | |
5819 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 5820 | |
e98fdf1a | 5821 | while (1) |
19e6b90e | 5822 | { |
f41e4712 | 5823 | bfd_size_type maxprint; |
e98fdf1a | 5824 | dwarf_vma offset; |
f41e4712 | 5825 | |
0c588247 | 5826 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e | 5827 | |
e98fdf1a AM |
5828 | if (offset == 0) |
5829 | break; | |
b4eb7656 | 5830 | |
e98fdf1a AM |
5831 | data += offset_size; |
5832 | if (data >= end) | |
5833 | break; | |
5834 | maxprint = (end - data) - 1; | |
f41e4712 | 5835 | |
e98fdf1a AM |
5836 | if (is_gnu) |
5837 | { | |
5838 | unsigned int kind_data; | |
5839 | gdb_index_symbol_kind kind; | |
5840 | const char *kind_name; | |
5841 | int is_static; | |
5842 | ||
5843 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
5844 | data++; | |
5845 | maxprint --; | |
5846 | /* GCC computes the kind as the upper byte in the CU index | |
5847 | word, and then right shifts it by the CU index size. | |
5848 | Left shift KIND to where the gdb-index.h accessor macros | |
5849 | can use it. */ | |
5850 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
5851 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
5852 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
5853 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
5854 | printf (" %-6lx %s,%-10s %.*s\n", | |
5855 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
5856 | kind_name, (int) maxprint, data); | |
19e6b90e | 5857 | } |
e98fdf1a AM |
5858 | else |
5859 | printf (" %-6lx\t%.*s\n", | |
5860 | (unsigned long) offset, (int) maxprint, data); | |
5861 | ||
5862 | data += strnlen ((char *) data, maxprint) + 1; | |
5863 | if (data >= end) | |
5864 | break; | |
19e6b90e | 5865 | } |
19e6b90e L |
5866 | } |
5867 | ||
5868 | printf ("\n"); | |
5869 | return 1; | |
5870 | } | |
5871 | ||
459d52c8 DE |
5872 | static int |
5873 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
5874 | { | |
5875 | return display_debug_pubnames_worker (section, file, 0); | |
5876 | } | |
5877 | ||
5878 | static int | |
5879 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
5880 | { | |
5881 | return display_debug_pubnames_worker (section, file, 1); | |
5882 | } | |
5883 | ||
19e6b90e L |
5884 | static int |
5885 | display_debug_macinfo (struct dwarf_section *section, | |
5886 | void *file ATTRIBUTE_UNUSED) | |
5887 | { | |
5888 | unsigned char *start = section->start; | |
5889 | unsigned char *end = start + section->size; | |
5890 | unsigned char *curr = start; | |
19e6b90e L |
5891 | enum dwarf_macinfo_record_type op; |
5892 | ||
015dc7e1 | 5893 | introduce (section, false); |
19e6b90e L |
5894 | |
5895 | while (curr < end) | |
5896 | { | |
5897 | unsigned int lineno; | |
0c588247 | 5898 | const unsigned char *string; |
19e6b90e | 5899 | |
3f5e193b | 5900 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
5901 | curr++; |
5902 | ||
5903 | switch (op) | |
5904 | { | |
5905 | case DW_MACINFO_start_file: | |
5906 | { | |
5907 | unsigned int filenum; | |
5908 | ||
cd30bcef AM |
5909 | READ_ULEB (lineno, curr, end); |
5910 | READ_ULEB (filenum, curr, end); | |
19e6b90e L |
5911 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), |
5912 | lineno, filenum); | |
5913 | } | |
5914 | break; | |
5915 | ||
5916 | case DW_MACINFO_end_file: | |
5917 | printf (_(" DW_MACINFO_end_file\n")); | |
5918 | break; | |
5919 | ||
5920 | case DW_MACINFO_define: | |
cd30bcef | 5921 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5922 | string = curr; |
5923 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5924 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
5925 | lineno, string); | |
5926 | break; | |
5927 | ||
5928 | case DW_MACINFO_undef: | |
cd30bcef | 5929 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5930 | string = curr; |
5931 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5932 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
5933 | lineno, string); | |
5934 | break; | |
5935 | ||
5936 | case DW_MACINFO_vendor_ext: | |
5937 | { | |
5938 | unsigned int constant; | |
5939 | ||
cd30bcef | 5940 | READ_ULEB (constant, curr, end); |
0c588247 NC |
5941 | string = curr; |
5942 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5943 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
5944 | constant, string); | |
5945 | } | |
5946 | break; | |
5947 | } | |
5948 | } | |
5949 | ||
5950 | return 1; | |
5951 | } | |
5952 | ||
4ccf1e31 JJ |
5953 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5954 | filename and dirname corresponding to file name table entry with index | |
5955 | FILEIDX. Return NULL on failure. */ | |
5956 | ||
5957 | static unsigned char * | |
f6f0e17b NC |
5958 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5959 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5960 | unsigned char **dir_name) |
5961 | { | |
5962 | struct dwarf_section *section = &debug_displays [line].section; | |
5963 | unsigned char *hdrptr, *dirtable, *file_name; | |
5964 | unsigned int offset_size, initial_length_size; | |
cd30bcef | 5965 | unsigned int version, opcode_base; |
4ccf1e31 | 5966 | dwarf_vma length, diridx; |
f6f0e17b | 5967 | const unsigned char * end; |
4ccf1e31 JJ |
5968 | |
5969 | *dir_name = NULL; | |
5970 | if (section->start == NULL | |
5971 | || line_offset >= section->size | |
5972 | || fileidx == 0) | |
5973 | return NULL; | |
5974 | ||
5975 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5976 | end = section->start + section->size; |
0c588247 NC |
5977 | |
5978 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5979 | if (length == 0xffffffff) |
5980 | { | |
5981 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5982 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
5983 | offset_size = 8; |
5984 | initial_length_size = 12; | |
5985 | } | |
5986 | else | |
5987 | { | |
5988 | offset_size = 4; | |
5989 | initial_length_size = 4; | |
5990 | } | |
e98fdf1a AM |
5991 | if (length + initial_length_size < length |
5992 | || length + initial_length_size > section->size) | |
4ccf1e31 | 5993 | return NULL; |
0c588247 NC |
5994 | |
5995 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5996 | if (version != 2 && version != 3 && version != 4) |
5997 | return NULL; | |
5998 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5999 | if (version >= 4) | |
6000 | hdrptr++; /* Skip max_ops_per_insn. */ | |
6001 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
6002 | |
6003 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
6004 | if (opcode_base == 0) |
6005 | return NULL; | |
0c588247 | 6006 | |
4ccf1e31 | 6007 | hdrptr += opcode_base - 1; |
5c1c468d NC |
6008 | if (hdrptr >= end) |
6009 | return NULL; | |
6010 | ||
4ccf1e31 JJ |
6011 | dirtable = hdrptr; |
6012 | /* Skip over dirname table. */ | |
6013 | while (*hdrptr != '\0') | |
5c1c468d NC |
6014 | { |
6015 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; | |
6016 | if (hdrptr >= end) | |
6017 | return NULL; | |
6018 | } | |
4ccf1e31 | 6019 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 6020 | |
4ccf1e31 | 6021 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 6022 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 6023 | { |
0c588247 | 6024 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
cd30bcef AM |
6025 | SKIP_ULEB (hdrptr, end); |
6026 | SKIP_ULEB (hdrptr, end); | |
6027 | SKIP_ULEB (hdrptr, end); | |
4ccf1e31 | 6028 | } |
5c1c468d | 6029 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 6030 | return NULL; |
5c1c468d | 6031 | |
4ccf1e31 | 6032 | file_name = hdrptr; |
0c588247 | 6033 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
5c1c468d NC |
6034 | if (hdrptr >= end) |
6035 | return NULL; | |
cd30bcef | 6036 | READ_ULEB (diridx, hdrptr, end); |
4ccf1e31 JJ |
6037 | if (diridx == 0) |
6038 | return file_name; | |
5c1c468d | 6039 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
0c588247 | 6040 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
5c1c468d | 6041 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
6042 | return NULL; |
6043 | *dir_name = dirtable; | |
6044 | return file_name; | |
6045 | } | |
6046 | ||
6047 | static int | |
6048 | display_debug_macro (struct dwarf_section *section, | |
6049 | void *file) | |
6050 | { | |
6051 | unsigned char *start = section->start; | |
6052 | unsigned char *end = start + section->size; | |
6053 | unsigned char *curr = start; | |
6054 | unsigned char *extended_op_buf[256]; | |
015dc7e1 | 6055 | bool is_dwo = false; |
d296b736 NC |
6056 | const char *suffix = strrchr (section->name, '.'); |
6057 | ||
6058 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
015dc7e1 | 6059 | is_dwo = true; |
4ccf1e31 | 6060 | |
dda8d76d NC |
6061 | load_debug_section_with_follow (str, file); |
6062 | load_debug_section_with_follow (line, file); | |
e4b7104b | 6063 | load_debug_section_with_follow (str_index, file); |
d296b736 | 6064 | |
015dc7e1 | 6065 | introduce (section, false); |
4ccf1e31 JJ |
6066 | |
6067 | while (curr < end) | |
6068 | { | |
6069 | unsigned int lineno, version, flags; | |
d296b736 | 6070 | unsigned int offset_size; |
0c588247 | 6071 | const unsigned char *string; |
4ccf1e31 JJ |
6072 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
6073 | unsigned char **extended_ops = NULL; | |
6074 | ||
0c588247 | 6075 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 6076 | if (version != 4 && version != 5) |
4ccf1e31 | 6077 | { |
0e12f6c8 TV |
6078 | error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"), |
6079 | section->name, version); | |
4ccf1e31 JJ |
6080 | return 0; |
6081 | } | |
6082 | ||
0c588247 | 6083 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
d296b736 | 6084 | offset_size = (flags & 1) ? 8 : 4; |
4ccf1e31 JJ |
6085 | printf (_(" Offset: 0x%lx\n"), |
6086 | (unsigned long) sec_offset); | |
6087 | printf (_(" Version: %d\n"), version); | |
6088 | printf (_(" Offset size: %d\n"), offset_size); | |
6089 | if (flags & 2) | |
6090 | { | |
0c588247 | 6091 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
6092 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
6093 | (unsigned long) line_offset); | |
6094 | } | |
6095 | if (flags & 4) | |
6096 | { | |
0c588247 | 6097 | unsigned int i, count, op; |
4ccf1e31 | 6098 | dwarf_vma nargs, n; |
0c588247 NC |
6099 | |
6100 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 6101 | |
4ccf1e31 JJ |
6102 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
6103 | extended_ops = extended_op_buf; | |
6104 | if (count) | |
6105 | { | |
6106 | printf (_(" Extension opcode arguments:\n")); | |
6107 | for (i = 0; i < count; i++) | |
6108 | { | |
0c588247 | 6109 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 6110 | extended_ops[op] = curr; |
cd30bcef | 6111 | READ_ULEB (nargs, curr, end); |
4ccf1e31 | 6112 | if (nargs == 0) |
7a7e1061 | 6113 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
6114 | else |
6115 | { | |
7a7e1061 | 6116 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
6117 | for (n = 0; n < nargs; n++) |
6118 | { | |
0c588247 NC |
6119 | unsigned int form; |
6120 | ||
6121 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
6122 | printf ("%s%s", get_FORM_name (form), |
6123 | n == nargs - 1 ? "\n" : ", "); | |
6124 | switch (form) | |
6125 | { | |
6126 | case DW_FORM_data1: | |
6127 | case DW_FORM_data2: | |
6128 | case DW_FORM_data4: | |
6129 | case DW_FORM_data8: | |
6130 | case DW_FORM_sdata: | |
6131 | case DW_FORM_udata: | |
6132 | case DW_FORM_block: | |
6133 | case DW_FORM_block1: | |
6134 | case DW_FORM_block2: | |
6135 | case DW_FORM_block4: | |
6136 | case DW_FORM_flag: | |
6137 | case DW_FORM_string: | |
6138 | case DW_FORM_strp: | |
6139 | case DW_FORM_sec_offset: | |
6140 | break; | |
6141 | default: | |
6142 | error (_("Invalid extension opcode form %s\n"), | |
6143 | get_FORM_name (form)); | |
6144 | return 0; | |
6145 | } | |
6146 | } | |
6147 | } | |
6148 | } | |
6149 | } | |
6150 | } | |
6151 | printf ("\n"); | |
6152 | ||
6153 | while (1) | |
6154 | { | |
6155 | unsigned int op; | |
6156 | ||
6157 | if (curr >= end) | |
6158 | { | |
6159 | error (_(".debug_macro section not zero terminated\n")); | |
6160 | return 0; | |
6161 | } | |
6162 | ||
0c588247 | 6163 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
6164 | if (op == 0) |
6165 | break; | |
6166 | ||
6167 | switch (op) | |
6168 | { | |
e4b7104b NC |
6169 | case DW_MACRO_define: |
6170 | READ_ULEB (lineno, curr, end); | |
6171 | string = curr; | |
6172 | curr += strnlen ((char *) string, end - string) + 1; | |
6173 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), | |
6174 | lineno, string); | |
6175 | break; | |
6176 | ||
6177 | case DW_MACRO_undef: | |
6178 | READ_ULEB (lineno, curr, end); | |
6179 | string = curr; | |
6180 | curr += strnlen ((char *) string, end - string) + 1; | |
6181 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), | |
6182 | lineno, string); | |
6183 | break; | |
6184 | ||
7a7e1061 | 6185 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
6186 | { |
6187 | unsigned int filenum; | |
6188 | unsigned char *file_name = NULL, *dir_name = NULL; | |
6189 | ||
cd30bcef AM |
6190 | READ_ULEB (lineno, curr, end); |
6191 | READ_ULEB (filenum, curr, end); | |
4ccf1e31 JJ |
6192 | |
6193 | if ((flags & 2) == 0) | |
7a7e1061 | 6194 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
6195 | else |
6196 | file_name | |
6197 | = get_line_filename_and_dirname (line_offset, filenum, | |
6198 | &dir_name); | |
6199 | if (file_name == NULL) | |
7a7e1061 | 6200 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
6201 | lineno, filenum); |
6202 | else | |
7a7e1061 | 6203 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
6204 | lineno, filenum, |
6205 | dir_name != NULL ? (const char *) dir_name : "", | |
6206 | dir_name != NULL ? "/" : "", file_name); | |
6207 | } | |
6208 | break; | |
6209 | ||
7a7e1061 JK |
6210 | case DW_MACRO_end_file: |
6211 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
6212 | break; |
6213 | ||
7a7e1061 | 6214 | case DW_MACRO_define_strp: |
cd30bcef | 6215 | READ_ULEB (lineno, curr, end); |
d296b736 NC |
6216 | if (version == 4 && is_dwo) |
6217 | READ_ULEB (offset, curr, end); | |
6218 | else | |
6219 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
4ccf1e31 | 6220 | string = fetch_indirect_string (offset); |
7a7e1061 | 6221 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
6222 | lineno, string); |
6223 | break; | |
6224 | ||
7a7e1061 | 6225 | case DW_MACRO_undef_strp: |
cd30bcef | 6226 | READ_ULEB (lineno, curr, end); |
d296b736 NC |
6227 | if (version == 4 && is_dwo) |
6228 | READ_ULEB (offset, curr, end); | |
6229 | else | |
6230 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
4ccf1e31 | 6231 | string = fetch_indirect_string (offset); |
7a7e1061 | 6232 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
6233 | lineno, string); |
6234 | break; | |
6235 | ||
7a7e1061 | 6236 | case DW_MACRO_import: |
0c588247 | 6237 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6238 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
6239 | (unsigned long) offset); |
6240 | break; | |
6241 | ||
7a7e1061 | 6242 | case DW_MACRO_define_sup: |
cd30bcef | 6243 | READ_ULEB (lineno, curr, end); |
0c588247 | 6244 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6245 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
6246 | lineno, (unsigned long) offset); |
6247 | break; | |
6248 | ||
7a7e1061 | 6249 | case DW_MACRO_undef_sup: |
cd30bcef | 6250 | READ_ULEB (lineno, curr, end); |
0c588247 | 6251 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6252 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
6253 | lineno, (unsigned long) offset); |
6254 | break; | |
6255 | ||
7a7e1061 | 6256 | case DW_MACRO_import_sup: |
0c588247 | 6257 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6258 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
6259 | (unsigned long) offset); |
6260 | break; | |
6261 | ||
e4b7104b NC |
6262 | case DW_MACRO_define_strx: |
6263 | case DW_MACRO_undef_strx: | |
6264 | READ_ULEB (lineno, curr, end); | |
6265 | READ_ULEB (offset, curr, end); | |
6266 | string = (const unsigned char *) | |
015dc7e1 | 6267 | fetch_indexed_string (offset, NULL, offset_size, false); |
e4b7104b NC |
6268 | if (op == DW_MACRO_define_strx) |
6269 | printf (" DW_MACRO_define_strx "); | |
6270 | else | |
6271 | printf (" DW_MACRO_undef_strx "); | |
6272 | if (do_wide) | |
39f381cb | 6273 | printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset)); |
e4b7104b NC |
6274 | printf (_("lineno : %d macro : %s\n"), |
6275 | lineno, string); | |
6276 | break; | |
6277 | ||
4ccf1e31 | 6278 | default: |
e4b7104b NC |
6279 | if (op >= DW_MACRO_lo_user && op <= DW_MACRO_hi_user) |
6280 | { | |
6281 | printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op); | |
6282 | break; | |
6283 | } | |
6284 | ||
4ccf1e31 JJ |
6285 | if (extended_ops == NULL || extended_ops[op] == NULL) |
6286 | { | |
6287 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
6288 | return 0; | |
6289 | } | |
6290 | else | |
6291 | { | |
6292 | /* Skip over unhandled opcodes. */ | |
6293 | dwarf_vma nargs, n; | |
6294 | unsigned char *desc = extended_ops[op]; | |
cd30bcef | 6295 | READ_ULEB (nargs, desc, end); |
4ccf1e31 JJ |
6296 | if (nargs == 0) |
6297 | { | |
7a7e1061 | 6298 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
6299 | break; |
6300 | } | |
7a7e1061 | 6301 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
6302 | for (n = 0; n < nargs; n++) |
6303 | { | |
0c588247 NC |
6304 | int val; |
6305 | ||
77145576 | 6306 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 6307 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 6308 | curr |
77145576 | 6309 | = read_and_display_attr_value (0, val, 0, |
ec1b0fbb | 6310 | start, curr, end, 0, 0, offset_size, |
341f9135 | 6311 | version, NULL, 0, NULL, |
ec1b0fbb | 6312 | NULL, ' ', -1); |
4ccf1e31 JJ |
6313 | if (n != nargs - 1) |
6314 | printf (","); | |
6315 | } | |
6316 | printf ("\n"); | |
6317 | } | |
6318 | break; | |
6319 | } | |
6320 | } | |
6321 | ||
6322 | printf ("\n"); | |
b4eb7656 | 6323 | } |
4ccf1e31 JJ |
6324 | |
6325 | return 1; | |
6326 | } | |
6327 | ||
19e6b90e L |
6328 | static int |
6329 | display_debug_abbrev (struct dwarf_section *section, | |
6330 | void *file ATTRIBUTE_UNUSED) | |
6331 | { | |
6332 | abbrev_entry *entry; | |
6333 | unsigned char *start = section->start; | |
19e6b90e | 6334 | |
015dc7e1 | 6335 | introduce (section, false); |
19e6b90e L |
6336 | |
6337 | do | |
6338 | { | |
bcd213b2 NC |
6339 | abbrev_list * list; |
6340 | dwarf_vma offset; | |
7282333f | 6341 | |
bcd213b2 | 6342 | offset = start - section->start; |
76868f36 | 6343 | list = find_abbrev_list_by_abbrev_offset (0, offset); |
bcd213b2 NC |
6344 | if (list == NULL) |
6345 | { | |
76868f36 | 6346 | list = new_abbrev_list (0, offset); |
f2f9554b | 6347 | start = process_abbrev_set (section, 0, section->size, offset, list); |
bcd213b2 NC |
6348 | list->start_of_next_abbrevs = start; |
6349 | } | |
6350 | else | |
6351 | start = list->start_of_next_abbrevs; | |
19e6b90e | 6352 | |
bcd213b2 | 6353 | if (list->first_abbrev == NULL) |
19e6b90e L |
6354 | continue; |
6355 | ||
bcd213b2 | 6356 | printf (_(" Number TAG (0x%lx)\n"), (long) offset); |
19e6b90e | 6357 | |
bcd213b2 | 6358 | for (entry = list->first_abbrev; entry; entry = entry->next) |
19e6b90e L |
6359 | { |
6360 | abbrev_attr *attr; | |
6361 | ||
cc5914eb | 6362 | printf (" %ld %s [%s]\n", |
bcd213b2 | 6363 | entry->number, |
19e6b90e L |
6364 | get_TAG_name (entry->tag), |
6365 | entry->children ? _("has children") : _("no children")); | |
6366 | ||
6367 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
6368 | { |
6369 | printf (" %-18s %s", | |
6370 | get_AT_name (attr->attribute), | |
6371 | get_FORM_name (attr->form)); | |
6372 | if (attr->form == DW_FORM_implicit_const) | |
6373 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
6374 | putchar ('\n'); | |
6375 | } | |
19e6b90e L |
6376 | } |
6377 | } | |
6378 | while (start); | |
6379 | ||
6380 | printf ("\n"); | |
6381 | ||
6382 | return 1; | |
6383 | } | |
6384 | ||
42bcef4a AB |
6385 | /* Return true when ADDR is the maximum address, when addresses are |
6386 | POINTER_SIZE bytes long. */ | |
6387 | ||
015dc7e1 | 6388 | static bool |
42bcef4a AB |
6389 | is_max_address (dwarf_vma addr, unsigned int pointer_size) |
6390 | { | |
6391 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
6392 | return ((addr & mask) == mask); | |
6393 | } | |
6394 | ||
9f272209 AO |
6395 | /* Display a view pair list starting at *VSTART_PTR and ending at |
6396 | VLISTEND within SECTION. */ | |
6397 | ||
6398 | static void | |
6399 | display_view_pair_list (struct dwarf_section *section, | |
6400 | unsigned char **vstart_ptr, | |
6401 | unsigned int debug_info_entry, | |
6402 | unsigned char *vlistend) | |
6403 | { | |
6404 | unsigned char *vstart = *vstart_ptr; | |
6405 | unsigned char *section_end = section->start + section->size; | |
6406 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
6407 | ||
6408 | if (vlistend < section_end) | |
6409 | section_end = vlistend; | |
6410 | ||
6411 | putchar ('\n'); | |
6412 | ||
6413 | while (vstart < section_end) | |
6414 | { | |
6415 | dwarf_vma off = vstart - section->start; | |
6416 | dwarf_vma vbegin, vend; | |
6417 | ||
cd30bcef | 6418 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 | 6419 | if (vstart == section_end) |
cd30bcef | 6420 | break; |
9f272209 | 6421 | |
cd30bcef | 6422 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6423 | printf (" %8.8lx ", (unsigned long) off); |
6424 | ||
6425 | print_dwarf_view (vbegin, pointer_size, 1); | |
6426 | print_dwarf_view (vend, pointer_size, 1); | |
6427 | printf (_("location view pair\n")); | |
6428 | } | |
6429 | ||
6430 | putchar ('\n'); | |
6431 | *vstart_ptr = vstart; | |
6432 | } | |
6433 | ||
4723351a CC |
6434 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
6435 | ||
6436 | static void | |
6437 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
6438 | unsigned char **start_ptr, |
6439 | unsigned int debug_info_entry, | |
359ca075 JK |
6440 | dwarf_vma offset, |
6441 | dwarf_vma base_address, | |
9f272209 | 6442 | unsigned char **vstart_ptr, |
b4eb7656 | 6443 | int has_frame_base) |
4723351a | 6444 | { |
9f272209 | 6445 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6446 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6447 | unsigned long cu_offset; |
6448 | unsigned int pointer_size; | |
6449 | unsigned int offset_size; | |
6450 | int dwarf_version; | |
4723351a CC |
6451 | |
6452 | dwarf_vma begin; | |
6453 | dwarf_vma end; | |
6454 | unsigned short length; | |
6455 | int need_frame_base; | |
6456 | ||
82b1b41b NC |
6457 | if (debug_info_entry >= num_debug_info_entries) |
6458 | { | |
6459 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
6460 | debug_info_entry); | |
6461 | return; | |
6462 | } | |
b4eb7656 | 6463 | |
82b1b41b NC |
6464 | cu_offset = debug_information [debug_info_entry].cu_offset; |
6465 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6466 | offset_size = debug_information [debug_info_entry].offset_size; | |
6467 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 6468 | |
f41e4712 NC |
6469 | if (pointer_size < 2 || pointer_size > 8) |
6470 | { | |
6471 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6472 | pointer_size, debug_info_entry); | |
6473 | return; | |
6474 | } | |
6475 | ||
4723351a CC |
6476 | while (1) |
6477 | { | |
359ca075 | 6478 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 6479 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 6480 | |
4723351a | 6481 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
6482 | { |
6483 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6484 | (unsigned long) offset); |
b4eb7656 AM |
6485 | break; |
6486 | } | |
4723351a | 6487 | |
359ca075 | 6488 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 6489 | |
0c588247 NC |
6490 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
6491 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 6492 | |
4723351a | 6493 | if (begin == 0 && end == 0) |
b4eb7656 | 6494 | { |
d1c4b12b NC |
6495 | /* PR 18374: In a object file we can have a location list that |
6496 | starts with a begin and end of 0 because there are relocations | |
6497 | that need to be applied to the addresses. Actually applying | |
6498 | the relocations now does not help as they will probably resolve | |
6499 | to 0, since the object file has not been fully linked. Real | |
6500 | end of list markers will not have any relocations against them. */ | |
6501 | if (! reloc_at (section, off) | |
6502 | && ! reloc_at (section, off + pointer_size)) | |
6503 | { | |
6504 | printf (_("<End of list>\n")); | |
6505 | break; | |
6506 | } | |
b4eb7656 | 6507 | } |
4723351a CC |
6508 | |
6509 | /* Check base address specifiers. */ | |
42bcef4a AB |
6510 | if (is_max_address (begin, pointer_size) |
6511 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
6512 | { |
6513 | base_address = end; | |
6514 | print_dwarf_vma (begin, pointer_size); | |
6515 | print_dwarf_vma (end, pointer_size); | |
6516 | printf (_("(base address)\n")); | |
6517 | continue; | |
6518 | } | |
4723351a | 6519 | |
9f272209 AO |
6520 | if (vstart) |
6521 | { | |
9f272209 AO |
6522 | off = offset + (vstart - *start_ptr); |
6523 | ||
cd30bcef | 6524 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
6525 | print_dwarf_view (vbegin, pointer_size, 1); |
6526 | ||
cd30bcef | 6527 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6528 | print_dwarf_view (vend, pointer_size, 1); |
6529 | ||
6530 | printf (_("views at %8.8lx for:\n %*s "), | |
6531 | (unsigned long) off, 8, ""); | |
6532 | } | |
6533 | ||
4723351a | 6534 | if (start + 2 > section_end) |
b4eb7656 AM |
6535 | { |
6536 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6537 | (unsigned long) offset); |
b4eb7656 AM |
6538 | break; |
6539 | } | |
4723351a | 6540 | |
0c588247 | 6541 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
6542 | |
6543 | if (start + length > section_end) | |
b4eb7656 AM |
6544 | { |
6545 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6546 | (unsigned long) offset); |
b4eb7656 AM |
6547 | break; |
6548 | } | |
4723351a CC |
6549 | |
6550 | print_dwarf_vma (begin + base_address, pointer_size); | |
6551 | print_dwarf_vma (end + base_address, pointer_size); | |
6552 | ||
6553 | putchar ('('); | |
6554 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6555 | pointer_size, |
6556 | offset_size, | |
6557 | dwarf_version, | |
6558 | length, | |
6559 | cu_offset, section); | |
4723351a CC |
6560 | putchar (')'); |
6561 | ||
6562 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6563 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 6564 | |
9f272209 | 6565 | if (begin == end && vbegin == vend) |
b4eb7656 | 6566 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6567 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 6568 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
6569 | |
6570 | putchar ('\n'); | |
6571 | ||
6572 | start += length; | |
6573 | } | |
6574 | ||
6575 | *start_ptr = start; | |
9f272209 | 6576 | *vstart_ptr = vstart; |
4723351a CC |
6577 | } |
6578 | ||
77145576 JK |
6579 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
6580 | ||
6581 | static void | |
6582 | display_loclists_list (struct dwarf_section *section, | |
6583 | unsigned char **start_ptr, | |
6584 | unsigned int debug_info_entry, | |
6585 | dwarf_vma offset, | |
6586 | dwarf_vma base_address, | |
9f272209 | 6587 | unsigned char **vstart_ptr, |
77145576 JK |
6588 | int has_frame_base) |
6589 | { | |
9f272209 | 6590 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
6591 | unsigned char *section_end = section->start + section->size; |
6592 | unsigned long cu_offset; | |
6593 | unsigned int pointer_size; | |
6594 | unsigned int offset_size; | |
6595 | int dwarf_version; | |
77145576 | 6596 | |
9dfd0db9 | 6597 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
6598 | dwarf_vma begin = -1, vbegin = -1; |
6599 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
6600 | dwarf_vma length; |
6601 | int need_frame_base; | |
6602 | ||
6603 | if (debug_info_entry >= num_debug_info_entries) | |
6604 | { | |
6605 | warn (_("No debug information available for " | |
6606 | "loclists lists of entry: %u\n"), | |
6607 | debug_info_entry); | |
6608 | return; | |
6609 | } | |
6610 | ||
6611 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6612 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6613 | offset_size = debug_information [debug_info_entry].offset_size; | |
6614 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6615 | ||
6616 | if (pointer_size < 2 || pointer_size > 8) | |
6617 | { | |
6618 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6619 | pointer_size, debug_info_entry); | |
6620 | return; | |
6621 | } | |
6622 | ||
6623 | while (1) | |
6624 | { | |
6625 | dwarf_vma off = offset + (start - *start_ptr); | |
6626 | enum dwarf_location_list_entry_type llet; | |
6627 | ||
6628 | if (start + 1 > section_end) | |
6629 | { | |
6630 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6631 | (unsigned long) offset); | |
6632 | break; | |
6633 | } | |
6634 | ||
6635 | printf (" %8.8lx ", (unsigned long) off); | |
6636 | ||
6637 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
6638 | ||
1c9f770d MW |
6639 | if (vstart && (llet == DW_LLE_offset_pair |
6640 | || llet == DW_LLE_start_end | |
6641 | || llet == DW_LLE_start_length)) | |
9f272209 AO |
6642 | { |
6643 | off = offset + (vstart - *start_ptr); | |
6644 | ||
cd30bcef | 6645 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
6646 | print_dwarf_view (vbegin, pointer_size, 1); |
6647 | ||
cd30bcef | 6648 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6649 | print_dwarf_view (vend, pointer_size, 1); |
6650 | ||
6651 | printf (_("views at %8.8lx for:\n %*s "), | |
6652 | (unsigned long) off, 8, ""); | |
6653 | } | |
6654 | ||
77145576 JK |
6655 | switch (llet) |
6656 | { | |
6657 | case DW_LLE_end_of_list: | |
6658 | printf (_("<End of list>\n")); | |
6659 | break; | |
6660 | case DW_LLE_offset_pair: | |
cd30bcef | 6661 | READ_ULEB (begin, start, section_end); |
1c9f770d | 6662 | begin += base_address; |
cd30bcef | 6663 | READ_ULEB (end, start, section_end); |
1c9f770d MW |
6664 | end += base_address; |
6665 | break; | |
6666 | case DW_LLE_start_end: | |
6667 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6668 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
6669 | break; | |
6670 | case DW_LLE_start_length: | |
6671 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6672 | READ_ULEB (end, start, section_end); | |
6673 | end += begin; | |
77145576 JK |
6674 | break; |
6675 | case DW_LLE_base_address: | |
6676 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
6677 | section_end); | |
6678 | print_dwarf_vma (base_address, pointer_size); | |
6679 | printf (_("(base address)\n")); | |
6680 | break; | |
9f272209 AO |
6681 | #ifdef DW_LLE_view_pair |
6682 | case DW_LLE_view_pair: | |
6683 | if (vstart) | |
6684 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
cd30bcef | 6685 | READ_ULEB (vbegin, start, section_end); |
9f272209 AO |
6686 | print_dwarf_view (vbegin, pointer_size, 1); |
6687 | ||
cd30bcef | 6688 | READ_ULEB (vend, start, section_end); |
9f272209 AO |
6689 | print_dwarf_view (vend, pointer_size, 1); |
6690 | ||
6691 | printf (_("views for:\n")); | |
6692 | continue; | |
6693 | #endif | |
77145576 JK |
6694 | default: |
6695 | error (_("Invalid location list entry type %d\n"), llet); | |
6696 | return; | |
6697 | } | |
6698 | if (llet == DW_LLE_end_of_list) | |
6699 | break; | |
1c9f770d MW |
6700 | if (llet != DW_LLE_offset_pair |
6701 | && llet != DW_LLE_start_end | |
6702 | && llet != DW_LLE_start_length) | |
77145576 JK |
6703 | continue; |
6704 | ||
6705 | if (start + 2 > section_end) | |
6706 | { | |
6707 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6708 | (unsigned long) offset); | |
6709 | break; | |
6710 | } | |
6711 | ||
cd30bcef | 6712 | READ_ULEB (length, start, section_end); |
77145576 | 6713 | |
1c9f770d MW |
6714 | print_dwarf_vma (begin, pointer_size); |
6715 | print_dwarf_vma (end, pointer_size); | |
77145576 JK |
6716 | |
6717 | putchar ('('); | |
6718 | need_frame_base = decode_location_expression (start, | |
6719 | pointer_size, | |
6720 | offset_size, | |
6721 | dwarf_version, | |
6722 | length, | |
6723 | cu_offset, section); | |
6724 | putchar (')'); | |
6725 | ||
6726 | if (need_frame_base && !has_frame_base) | |
6727 | printf (_(" [without DW_AT_frame_base]")); | |
6728 | ||
9f272209 | 6729 | if (begin == end && vbegin == vend) |
77145576 | 6730 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6731 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
6732 | fputs (_(" (start > end)"), stdout); |
6733 | ||
6734 | putchar ('\n'); | |
6735 | ||
6736 | start += length; | |
9f272209 | 6737 | vbegin = vend = -1; |
77145576 JK |
6738 | } |
6739 | ||
9f272209 AO |
6740 | if (vbegin != vm1 || vend != vm1) |
6741 | printf (_("Trailing view pair not used in a range")); | |
6742 | ||
77145576 | 6743 | *start_ptr = start; |
9f272209 | 6744 | *vstart_ptr = vstart; |
77145576 JK |
6745 | } |
6746 | ||
fab128ef CC |
6747 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
6748 | right-adjusted in a field of length LEN, and followed by a space. */ | |
6749 | ||
6750 | static void | |
6751 | print_addr_index (unsigned int idx, unsigned int len) | |
6752 | { | |
6753 | static char buf[15]; | |
6754 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 6755 | printf ("%*s ", len, buf); |
fab128ef CC |
6756 | } |
6757 | ||
4723351a CC |
6758 | /* Display a location list from a .dwo section. It uses address indexes rather |
6759 | than embedded addresses. This code closely follows display_loc_list, but the | |
6760 | two are sufficiently different that combining things is very ugly. */ | |
6761 | ||
6762 | static void | |
6763 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
6764 | unsigned char **start_ptr, |
6765 | unsigned int debug_info_entry, | |
359ca075 | 6766 | dwarf_vma offset, |
9f272209 | 6767 | unsigned char **vstart_ptr, |
b4eb7656 | 6768 | int has_frame_base) |
4723351a | 6769 | { |
9f272209 | 6770 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6771 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6772 | unsigned long cu_offset; |
6773 | unsigned int pointer_size; | |
6774 | unsigned int offset_size; | |
6775 | int dwarf_version; | |
4723351a CC |
6776 | int entry_type; |
6777 | unsigned short length; | |
6778 | int need_frame_base; | |
fab128ef | 6779 | unsigned int idx; |
4723351a | 6780 | |
82b1b41b NC |
6781 | if (debug_info_entry >= num_debug_info_entries) |
6782 | { | |
6783 | warn (_("No debug information for loc lists of entry: %u\n"), | |
6784 | debug_info_entry); | |
6785 | return; | |
6786 | } | |
6787 | ||
6788 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6789 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6790 | offset_size = debug_information [debug_info_entry].offset_size; | |
6791 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6792 | ||
f41e4712 NC |
6793 | if (pointer_size < 2 || pointer_size > 8) |
6794 | { | |
6795 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6796 | pointer_size, debug_info_entry); | |
6797 | return; | |
6798 | } | |
6799 | ||
4723351a CC |
6800 | while (1) |
6801 | { | |
359ca075 | 6802 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 6803 | |
fab128ef | 6804 | if (start >= section_end) |
b4eb7656 AM |
6805 | { |
6806 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6807 | (unsigned long) offset); |
b4eb7656 AM |
6808 | break; |
6809 | } | |
4723351a | 6810 | |
0c588247 | 6811 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
6812 | |
6813 | if (vstart) | |
6814 | switch (entry_type) | |
6815 | { | |
6816 | default: | |
6817 | break; | |
6818 | ||
6819 | case 2: | |
6820 | case 3: | |
6821 | case 4: | |
6822 | { | |
6823 | dwarf_vma view; | |
6824 | dwarf_vma off = offset + (vstart - *start_ptr); | |
6825 | ||
cd30bcef | 6826 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6827 | print_dwarf_view (view, 8, 1); |
6828 | ||
cd30bcef | 6829 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6830 | print_dwarf_view (view, 8, 1); |
6831 | ||
6832 | printf (_("views at %8.8lx for:\n %*s "), | |
6833 | (unsigned long) off, 8, ""); | |
6834 | ||
6835 | } | |
6836 | break; | |
6837 | } | |
6838 | ||
4723351a | 6839 | switch (entry_type) |
b4eb7656 AM |
6840 | { |
6841 | case 0: /* A terminating entry. */ | |
6842 | *start_ptr = start; | |
9f272209 | 6843 | *vstart_ptr = vstart; |
b4eb7656 AM |
6844 | printf (_("<End of list>\n")); |
6845 | return; | |
6846 | case 1: /* A base-address entry. */ | |
cd30bcef | 6847 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6848 | print_addr_index (idx, 8); |
9f272209 | 6849 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
6850 | printf (_("(base address selection entry)\n")); |
6851 | continue; | |
6852 | case 2: /* A start/end entry. */ | |
cd30bcef | 6853 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6854 | print_addr_index (idx, 8); |
cd30bcef | 6855 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6856 | print_addr_index (idx, 8); |
6857 | break; | |
6858 | case 3: /* A start/length entry. */ | |
cd30bcef | 6859 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6860 | print_addr_index (idx, 8); |
6861 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6862 | printf ("%08x ", idx); | |
6863 | break; | |
6864 | case 4: /* An offset pair entry. */ | |
6865 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6866 | printf ("%08x ", idx); | |
6867 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6868 | printf ("%08x ", idx); | |
6869 | break; | |
6870 | default: | |
6871 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
6872 | *start_ptr = start; | |
9f272209 | 6873 | *vstart_ptr = vstart; |
b4eb7656 AM |
6874 | return; |
6875 | } | |
4723351a CC |
6876 | |
6877 | if (start + 2 > 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 | 6883 | |
0c588247 | 6884 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6885 | if (start + length > section_end) |
b4eb7656 AM |
6886 | { |
6887 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6888 | (unsigned long) offset); |
b4eb7656 AM |
6889 | break; |
6890 | } | |
4723351a CC |
6891 | |
6892 | putchar ('('); | |
6893 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6894 | pointer_size, |
6895 | offset_size, | |
6896 | dwarf_version, | |
6897 | length, | |
6898 | cu_offset, section); | |
4723351a CC |
6899 | putchar (')'); |
6900 | ||
6901 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6902 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
6903 | |
6904 | putchar ('\n'); | |
6905 | ||
6906 | start += length; | |
6907 | } | |
6908 | ||
6909 | *start_ptr = start; | |
9f272209 | 6910 | *vstart_ptr = vstart; |
4723351a CC |
6911 | } |
6912 | ||
9f272209 AO |
6913 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
6914 | loc_views. */ | |
51d0d03f | 6915 | |
9f272209 | 6916 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
6917 | |
6918 | static int | |
6919 | loc_offsets_compar (const void *ap, const void *bp) | |
6920 | { | |
6921 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
6922 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
6923 | ||
9f272209 AO |
6924 | int ret = (a > b) - (b > a); |
6925 | if (ret) | |
6926 | return ret; | |
6927 | ||
6928 | a = loc_views[*(const unsigned int *) ap]; | |
6929 | b = loc_views[*(const unsigned int *) bp]; | |
6930 | ||
6931 | ret = (a > b) - (b > a); | |
6932 | ||
6933 | return ret; | |
51d0d03f JJ |
6934 | } |
6935 | ||
19e6b90e L |
6936 | static int |
6937 | display_debug_loc (struct dwarf_section *section, void *file) | |
6938 | { | |
9f272209 | 6939 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
6940 | unsigned long bytes; |
6941 | unsigned char *section_begin = start; | |
6942 | unsigned int num_loc_list = 0; | |
6943 | unsigned long last_offset = 0; | |
9f272209 | 6944 | unsigned long last_view = 0; |
19e6b90e L |
6945 | unsigned int first = 0; |
6946 | unsigned int i; | |
6947 | unsigned int j; | |
6948 | int seen_first_offset = 0; | |
51d0d03f | 6949 | int locs_sorted = 1; |
9f272209 | 6950 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6951 | unsigned int *array = NULL; |
4723351a | 6952 | const char *suffix = strrchr (section->name, '.'); |
015dc7e1 | 6953 | bool is_dwo = false; |
77145576 JK |
6954 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6955 | dwarf_vma expected_start = 0; | |
4723351a CC |
6956 | |
6957 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
015dc7e1 | 6958 | is_dwo = true; |
19e6b90e L |
6959 | |
6960 | bytes = section->size; | |
19e6b90e L |
6961 | |
6962 | if (bytes == 0) | |
6963 | { | |
6964 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6965 | return 0; | |
6966 | } | |
6967 | ||
77145576 JK |
6968 | if (is_loclists) |
6969 | { | |
6970 | unsigned char *hdrptr = section_begin; | |
6971 | dwarf_vma ll_length; | |
6972 | unsigned short ll_version; | |
6973 | unsigned char *end = section_begin + section->size; | |
6974 | unsigned char address_size, segment_selector_size; | |
6975 | uint32_t offset_entry_count; | |
6976 | ||
6977 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6978 | if (ll_length == 0xffffffff) | |
6979 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6980 | ||
6981 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6982 | if (ll_version != 5) | |
6983 | { | |
6984 | warn (_("The %s section contains corrupt or " | |
6985 | "unsupported version number: %d.\n"), | |
6986 | section->name, ll_version); | |
6987 | return 0; | |
6988 | } | |
6989 | ||
6990 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6991 | ||
6992 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6993 | if (segment_selector_size != 0) | |
6994 | { | |
6995 | warn (_("The %s section contains " | |
6996 | "unsupported segment selector size: %d.\n"), | |
6997 | section->name, segment_selector_size); | |
6998 | return 0; | |
6999 | } | |
7000 | ||
7001 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
7002 | if (offset_entry_count != 0) | |
7003 | { | |
7004 | warn (_("The %s section contains " | |
7005 | "unsupported offset entry count: %d.\n"), | |
7006 | section->name, offset_entry_count); | |
7007 | return 0; | |
7008 | } | |
7009 | ||
7010 | expected_start = hdrptr - section_begin; | |
7011 | } | |
7012 | ||
1febe64d NC |
7013 | if (load_debug_info (file) == 0) |
7014 | { | |
7015 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7016 | section->name); | |
7017 | return 0; | |
7018 | } | |
19e6b90e L |
7019 | |
7020 | /* Check the order of location list in .debug_info section. If | |
7021 | offsets of location lists are in the ascending order, we can | |
7022 | use `debug_information' directly. */ | |
7023 | for (i = 0; i < num_debug_info_entries; i++) | |
7024 | { | |
7025 | unsigned int num; | |
7026 | ||
7027 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
7028 | if (num > num_loc_list) |
7029 | num_loc_list = num; | |
19e6b90e L |
7030 | |
7031 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 7032 | if (locs_sorted && num != 0) |
19e6b90e L |
7033 | { |
7034 | if (!seen_first_offset) | |
7035 | { | |
7036 | /* This is the first location list. */ | |
7037 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 7038 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
7039 | first = i; |
7040 | seen_first_offset = 1; | |
7041 | j = 1; | |
7042 | } | |
7043 | else | |
7044 | j = 0; | |
7045 | ||
7046 | for (; j < num; j++) | |
7047 | { | |
7048 | if (last_offset > | |
9f272209 AO |
7049 | debug_information [i].loc_offsets [j] |
7050 | || (last_offset == debug_information [i].loc_offsets [j] | |
7051 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 7052 | { |
51d0d03f | 7053 | locs_sorted = 0; |
19e6b90e L |
7054 | break; |
7055 | } | |
7056 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 7057 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
7058 | } |
7059 | } | |
7060 | } | |
7061 | ||
19e6b90e L |
7062 | if (!seen_first_offset) |
7063 | error (_("No location lists in .debug_info section!\n")); | |
7064 | ||
d4bfc77b | 7065 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
7066 | && debug_information [first].loc_offsets [0] != expected_start |
7067 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
7068 | warn (_("Location lists in %s section start at 0x%s\n"), |
7069 | section->name, | |
7070 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 7071 | |
51d0d03f JJ |
7072 | if (!locs_sorted) |
7073 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d | 7074 | |
015dc7e1 | 7075 | introduce (section, false); |
dda8d76d | 7076 | |
d1c4b12b NC |
7077 | if (reloc_at (section, 0)) |
7078 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 7079 | |
d1c4b12b | 7080 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
7081 | |
7082 | seen_first_offset = 0; | |
7083 | for (i = first; i < num_debug_info_entries; i++) | |
7084 | { | |
9f272209 | 7085 | dwarf_vma offset, voffset; |
359ca075 | 7086 | dwarf_vma base_address; |
d1c4b12b | 7087 | unsigned int k; |
19e6b90e L |
7088 | int has_frame_base; |
7089 | ||
51d0d03f JJ |
7090 | if (!locs_sorted) |
7091 | { | |
7092 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
7093 | array[k] = k; | |
7094 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 7095 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
7096 | qsort (array, debug_information [i].num_loc_offsets, |
7097 | sizeof (*array), loc_offsets_compar); | |
7098 | } | |
19e6b90e | 7099 | |
9f272209 | 7100 | int adjacent_view_loclists = 1; |
51d0d03f | 7101 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 7102 | { |
51d0d03f JJ |
7103 | j = locs_sorted ? k : array[k]; |
7104 | if (k | |
9f272209 | 7105 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 7106 | ? k - 1 : array [k - 1]] |
9f272209 AO |
7107 | == debug_information [i].loc_offsets [j]) |
7108 | && (debug_information [i].loc_views [locs_sorted | |
7109 | ? k - 1 : array [k - 1]] | |
7110 | == debug_information [i].loc_views [j])) | |
51d0d03f | 7111 | continue; |
19e6b90e | 7112 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 7113 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 7114 | next = section_begin + offset; |
9f272209 AO |
7115 | voffset = debug_information [i].loc_views [j]; |
7116 | if (voffset != vm1) | |
7117 | vnext = section_begin + voffset; | |
7118 | else | |
7119 | vnext = NULL; | |
19e6b90e L |
7120 | base_address = debug_information [i].base_address; |
7121 | ||
9f272209 AO |
7122 | if (vnext && vnext < next) |
7123 | { | |
7124 | vstart = vnext; | |
7125 | display_view_pair_list (section, &vstart, i, next); | |
7126 | if (start == vnext) | |
7127 | start = vstart; | |
7128 | } | |
7129 | ||
7130 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
7131 | seen_first_offset = 1; |
7132 | else | |
7133 | { | |
7134 | if (start < next) | |
7135 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 7136 | (unsigned long) (start - section_begin), |
c8071705 | 7137 | (unsigned long) offset); |
19e6b90e L |
7138 | else if (start > next) |
7139 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 7140 | (unsigned long) (start - section_begin), |
c8071705 | 7141 | (unsigned long) offset); |
19e6b90e L |
7142 | } |
7143 | start = next; | |
9f272209 | 7144 | vstart = vnext; |
19e6b90e L |
7145 | |
7146 | if (offset >= bytes) | |
7147 | { | |
7148 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 7149 | (unsigned long) offset); |
19e6b90e L |
7150 | continue; |
7151 | } | |
7152 | ||
9f272209 AO |
7153 | if (vnext && voffset >= bytes) |
7154 | { | |
7155 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
7156 | (unsigned long) voffset); | |
7157 | continue; | |
7158 | } | |
7159 | ||
77145576 JK |
7160 | if (!is_loclists) |
7161 | { | |
7162 | if (is_dwo) | |
7163 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 7164 | &vstart, has_frame_base); |
77145576 JK |
7165 | else |
7166 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 7167 | &vstart, has_frame_base); |
77145576 | 7168 | } |
b4eb7656 | 7169 | else |
77145576 JK |
7170 | { |
7171 | if (is_dwo) | |
7172 | warn (_("DWO is not yet supported.\n")); | |
7173 | else | |
7174 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
7175 | &vstart, has_frame_base); |
7176 | } | |
7177 | ||
7178 | /* FIXME: this arrangement is quite simplistic. Nothing | |
7179 | requires locview lists to be adjacent to corresponding | |
7180 | loclists, and a single loclist could be augmented by | |
7181 | different locview lists, and vice-versa, unlikely as it | |
7182 | is that it would make sense to do so. Hopefully we'll | |
7183 | have view pair support built into loclists before we ever | |
7184 | need to address all these possibilities. */ | |
7185 | if (adjacent_view_loclists && vnext | |
7186 | && vnext != start && vstart != next) | |
7187 | { | |
7188 | adjacent_view_loclists = 0; | |
7189 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 7190 | } |
9f272209 AO |
7191 | |
7192 | if (vnext && vnext == start) | |
7193 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
7194 | } |
7195 | } | |
031cd65f | 7196 | |
4723351a | 7197 | if (start < section->start + section->size) |
d3a49aa8 AM |
7198 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
7199 | "There are %ld unused bytes at the end of section %s\n", | |
7200 | (long) (section->start + section->size - start)), | |
4723351a | 7201 | (long) (section->start + section->size - start), section->name); |
98fb390a | 7202 | putchar ('\n'); |
51d0d03f | 7203 | free (array); |
19e6b90e L |
7204 | return 1; |
7205 | } | |
7206 | ||
7207 | static int | |
7208 | display_debug_str (struct dwarf_section *section, | |
7209 | void *file ATTRIBUTE_UNUSED) | |
7210 | { | |
7211 | unsigned char *start = section->start; | |
7212 | unsigned long bytes = section->size; | |
7213 | dwarf_vma addr = section->address; | |
7214 | ||
7215 | if (bytes == 0) | |
7216 | { | |
7217 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7218 | return 0; | |
7219 | } | |
7220 | ||
015dc7e1 | 7221 | introduce (section, false); |
19e6b90e L |
7222 | |
7223 | while (bytes) | |
7224 | { | |
7225 | int j; | |
7226 | int k; | |
7227 | int lbytes; | |
7228 | ||
7229 | lbytes = (bytes > 16 ? 16 : bytes); | |
7230 | ||
7231 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
7232 | ||
7233 | for (j = 0; j < 16; j++) | |
7234 | { | |
7235 | if (j < lbytes) | |
7236 | printf ("%2.2x", start[j]); | |
7237 | else | |
7238 | printf (" "); | |
7239 | ||
7240 | if ((j & 3) == 3) | |
7241 | printf (" "); | |
7242 | } | |
7243 | ||
7244 | for (j = 0; j < lbytes; j++) | |
7245 | { | |
7246 | k = start[j]; | |
7247 | if (k >= ' ' && k < 0x80) | |
7248 | printf ("%c", k); | |
7249 | else | |
7250 | printf ("."); | |
7251 | } | |
7252 | ||
7253 | putchar ('\n'); | |
7254 | ||
7255 | start += lbytes; | |
7256 | addr += lbytes; | |
7257 | bytes -= lbytes; | |
7258 | } | |
7259 | ||
7260 | putchar ('\n'); | |
7261 | ||
7262 | return 1; | |
7263 | } | |
7264 | ||
19e6b90e L |
7265 | static int |
7266 | display_debug_info (struct dwarf_section *section, void *file) | |
7267 | { | |
015dc7e1 | 7268 | return process_debug_info (section, file, section->abbrev_sec, false, false); |
19e6b90e L |
7269 | } |
7270 | ||
2b6f5997 CC |
7271 | static int |
7272 | display_debug_types (struct dwarf_section *section, void *file) | |
7273 | { | |
015dc7e1 | 7274 | return process_debug_info (section, file, section->abbrev_sec, false, true); |
6f875884 TG |
7275 | } |
7276 | ||
7277 | static int | |
7278 | display_trace_info (struct dwarf_section *section, void *file) | |
7279 | { | |
015dc7e1 | 7280 | return process_debug_info (section, file, section->abbrev_sec, false, true); |
2b6f5997 | 7281 | } |
19e6b90e L |
7282 | |
7283 | static int | |
7284 | display_debug_aranges (struct dwarf_section *section, | |
7285 | void *file ATTRIBUTE_UNUSED) | |
7286 | { | |
7287 | unsigned char *start = section->start; | |
7288 | unsigned char *end = start + section->size; | |
7289 | ||
015dc7e1 | 7290 | introduce (section, false); |
19e6b90e | 7291 | |
6e3d6dc1 NC |
7292 | /* It does not matter if this load fails, |
7293 | we test for that later on. */ | |
7294 | load_debug_info (file); | |
7295 | ||
19e6b90e L |
7296 | while (start < end) |
7297 | { | |
7298 | unsigned char *hdrptr; | |
7299 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 7300 | unsigned char *addr_ranges; |
2d9472a2 NC |
7301 | dwarf_vma length; |
7302 | dwarf_vma address; | |
e98fdf1a | 7303 | unsigned long sec_off; |
53b8873b | 7304 | unsigned char address_size; |
19e6b90e | 7305 | int excess; |
bf5117e3 NC |
7306 | unsigned int offset_size; |
7307 | unsigned int initial_length_size; | |
19e6b90e L |
7308 | |
7309 | hdrptr = start; | |
7310 | ||
0c588247 | 7311 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
7312 | if (arange.ar_length == 0xffffffff) |
7313 | { | |
0c588247 | 7314 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
7315 | offset_size = 8; |
7316 | initial_length_size = 12; | |
7317 | } | |
7318 | else | |
7319 | { | |
7320 | offset_size = 4; | |
7321 | initial_length_size = 4; | |
7322 | } | |
7323 | ||
e98fdf1a AM |
7324 | sec_off = hdrptr - section->start; |
7325 | if (sec_off + arange.ar_length < sec_off | |
7326 | || sec_off + arange.ar_length > section->size) | |
7327 | { | |
7328 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
7329 | section->name, | |
7330 | sec_off - initial_length_size, | |
7331 | dwarf_vmatoa ("x", arange.ar_length)); | |
7332 | break; | |
7333 | } | |
7334 | ||
0c588247 NC |
7335 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
7336 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 7337 | |
6e3d6dc1 NC |
7338 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
7339 | && num_debug_info_entries > 0 | |
7340 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
7341 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 7342 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 7343 | |
0c588247 NC |
7344 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
7345 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
7346 | |
7347 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
7348 | { | |
67f101ee NC |
7349 | /* PR 19872: A version number of 0 probably means that there is |
7350 | padding at the end of the .debug_aranges section. Gold puts | |
7351 | it there when performing an incremental link, for example. | |
7352 | So do not generate a warning in this case. */ | |
7353 | if (arange.ar_version) | |
7354 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
7355 | break; |
7356 | } | |
7357 | ||
47704ddf KT |
7358 | printf (_(" Length: %ld\n"), |
7359 | (long) arange.ar_length); | |
19e6b90e | 7360 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
7361 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
7362 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
7363 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
7364 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
7365 | ||
53b8873b NC |
7366 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
7367 | ||
f41e4712 NC |
7368 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
7369 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
7370 | { |
7371 | error (_("Invalid address size in %s section!\n"), | |
7372 | section->name); | |
7373 | break; | |
7374 | } | |
7375 | ||
53b8873b NC |
7376 | /* The DWARF spec does not require that the address size be a power |
7377 | of two, but we do. This will have to change if we ever encounter | |
7378 | an uneven architecture. */ | |
7379 | if ((address_size & (address_size - 1)) != 0) | |
7380 | { | |
7381 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
7382 | break; | |
7383 | } | |
cecf136e | 7384 | |
209c9a13 NC |
7385 | if (address_size > 4) |
7386 | printf (_("\n Address Length\n")); | |
7387 | else | |
7388 | printf (_("\n Address Length\n")); | |
19e6b90e | 7389 | |
91d6fa6a | 7390 | addr_ranges = hdrptr; |
19e6b90e | 7391 | |
53b8873b NC |
7392 | /* Must pad to an alignment boundary that is twice the address size. */ |
7393 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 7394 | if (excess) |
91d6fa6a | 7395 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 7396 | |
e98fdf1a | 7397 | start += arange.ar_length + initial_length_size; |
1617e571 | 7398 | |
91d6fa6a | 7399 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 7400 | { |
0c588247 NC |
7401 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
7402 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 7403 | |
80c35038 | 7404 | printf (" "); |
2d9472a2 NC |
7405 | print_dwarf_vma (address, address_size); |
7406 | print_dwarf_vma (length, address_size); | |
7407 | putchar ('\n'); | |
19e6b90e | 7408 | } |
19e6b90e L |
7409 | } |
7410 | ||
7411 | printf ("\n"); | |
7412 | ||
7413 | return 1; | |
7414 | } | |
7415 | ||
4723351a CC |
7416 | /* Comparison function for qsort. */ |
7417 | static int | |
7418 | comp_addr_base (const void * v0, const void * v1) | |
7419 | { | |
d367307b AM |
7420 | debug_info *info0 = *(debug_info **) v0; |
7421 | debug_info *info1 = *(debug_info **) v1; | |
4723351a CC |
7422 | return info0->addr_base - info1->addr_base; |
7423 | } | |
7424 | ||
7425 | /* Display the debug_addr section. */ | |
7426 | static int | |
7427 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 7428 | void *file) |
4723351a CC |
7429 | { |
7430 | debug_info **debug_addr_info; | |
7431 | unsigned char *entry; | |
7432 | unsigned char *end; | |
7433 | unsigned int i; | |
7434 | unsigned int count; | |
0e12f6c8 | 7435 | unsigned char * header; |
4723351a CC |
7436 | |
7437 | if (section->size == 0) | |
7438 | { | |
7439 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7440 | return 0; | |
7441 | } | |
7442 | ||
7443 | if (load_debug_info (file) == 0) | |
7444 | { | |
7445 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7446 | section->name); | |
7447 | return 0; | |
7448 | } | |
7449 | ||
015dc7e1 | 7450 | introduce (section, false); |
4723351a | 7451 | |
1306a742 NC |
7452 | /* PR 17531: file: cf38d01b. |
7453 | We use xcalloc because a corrupt file may not have initialised all of the | |
7454 | fields in the debug_info structure, which means that the sort below might | |
7455 | try to move uninitialised data. */ | |
7456 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 7457 | sizeof (debug_info *)); |
4723351a CC |
7458 | |
7459 | count = 0; | |
7460 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 7461 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
7462 | { |
7463 | /* PR 17531: file: cf38d01b. */ | |
7464 | if (debug_information[i].addr_base >= section->size) | |
7465 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
7466 | (unsigned long) debug_information[i].addr_base, i); | |
7467 | else | |
7468 | debug_addr_info [count++] = debug_information + i; | |
7469 | } | |
4723351a CC |
7470 | |
7471 | /* Add a sentinel to make iteration convenient. */ | |
7472 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
7473 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 7474 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 7475 | |
0e12f6c8 | 7476 | header = section->start; |
4723351a CC |
7477 | for (i = 0; i < count; i++) |
7478 | { | |
7479 | unsigned int idx; | |
fab128ef | 7480 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
7481 | |
7482 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 7483 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 7484 | |
fab128ef | 7485 | printf (_("\tIndex\tAddress\n")); |
4723351a | 7486 | entry = section->start + debug_addr_info [i]->addr_base; |
0e12f6c8 TV |
7487 | if (debug_addr_info [i]->dwarf_version >= 5) |
7488 | { | |
7489 | size_t header_size = entry - header; | |
7490 | unsigned char * curr_header = header; | |
7491 | dwarf_vma length; | |
7492 | int version; | |
7493 | int segment_selector_size; | |
7494 | ||
7495 | if (header_size != 8 && header_size != 16) | |
7496 | { | |
7497 | warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"), | |
7498 | section->name, (long) header_size); | |
7499 | return 0; | |
7500 | } | |
7501 | ||
7502 | SAFE_BYTE_GET_AND_INC (length, curr_header, 4, entry); | |
7503 | if (length == 0xffffffff) | |
7504 | SAFE_BYTE_GET (length, curr_header, 8, entry); | |
7505 | end = curr_header + length; | |
7506 | ||
7507 | SAFE_BYTE_GET_AND_INC (version, curr_header, 2, entry); | |
7508 | if (version != 5) | |
7509 | warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"), | |
7510 | section->name, version); | |
7511 | ||
7512 | SAFE_BYTE_GET_AND_INC (address_size, curr_header, 1, entry); | |
7513 | SAFE_BYTE_GET_AND_INC (segment_selector_size, curr_header, 1, entry); | |
7514 | address_size += segment_selector_size; | |
7515 | } | |
7516 | else | |
7517 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
7518 | header = end; | |
4723351a CC |
7519 | idx = 0; |
7520 | while (entry < end) | |
b4eb7656 AM |
7521 | { |
7522 | dwarf_vma base = byte_get (entry, address_size); | |
7523 | printf (_("\t%d:\t"), idx); | |
7524 | print_dwarf_vma (base, address_size); | |
7525 | printf ("\n"); | |
7526 | entry += address_size; | |
7527 | idx++; | |
7528 | } | |
4723351a CC |
7529 | } |
7530 | printf ("\n"); | |
7531 | ||
7532 | free (debug_addr_info); | |
7533 | return 1; | |
7534 | } | |
7535 | ||
7536 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 7537 | |
4723351a CC |
7538 | static int |
7539 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 7540 | void *file ATTRIBUTE_UNUSED) |
4723351a | 7541 | { |
9f27c364 HPN |
7542 | unsigned long idx; |
7543 | ||
4723351a CC |
7544 | if (section->size == 0) |
7545 | { | |
7546 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7547 | return 0; | |
7548 | } | |
e4b7104b NC |
7549 | |
7550 | unsigned char *start = section->start; | |
7551 | unsigned char *end = start + section->size; | |
7552 | unsigned char *curr = start; | |
7553 | ||
63b4cc53 | 7554 | const char *suffix = strrchr (section->name, '.'); |
015dc7e1 | 7555 | bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
39f381cb NC |
7556 | |
7557 | if (dwo) | |
7558 | load_debug_section_with_follow (str_dwo, file); | |
7559 | else | |
7560 | load_debug_section_with_follow (str, file); | |
e4b7104b | 7561 | |
015dc7e1 | 7562 | introduce (section, false); |
e4b7104b NC |
7563 | |
7564 | while (curr < end) | |
7565 | { | |
7566 | dwarf_vma length; | |
7567 | dwarf_vma entry_length; | |
7568 | ||
7569 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); | |
7570 | /* FIXME: We assume that this means 64-bit DWARF is being used. */ | |
7571 | if (length == 0xffffffff) | |
7572 | { | |
7573 | SAFE_BYTE_GET (length, curr, 8, end); | |
7574 | entry_length = 8; | |
7575 | } | |
7576 | else | |
7577 | entry_length = 4; | |
7578 | ||
95abb394 | 7579 | unsigned char *entries_end; |
39f381cb NC |
7580 | if (length == 0) |
7581 | { | |
7582 | /* This is probably an old style .debug_str_offset section which | |
7583 | just contains offsets and no header (and the first offset is 0). */ | |
7584 | length = section->size; | |
7585 | curr = section->start; | |
95abb394 | 7586 | entries_end = end; |
e4b7104b | 7587 | |
39f381cb NC |
7588 | printf (_(" Length: %#lx\n"), (unsigned long) length); |
7589 | printf (_(" Index Offset [String]\n")); | |
7590 | } | |
7591 | else | |
7592 | { | |
95abb394 TV |
7593 | entries_end = curr + length; |
7594 | ||
39f381cb NC |
7595 | int version; |
7596 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); | |
7597 | if (version != 5) | |
7598 | warn (_("Unexpected version number in str_offset header: %#x\n"), version); | |
7599 | ||
7600 | int padding; | |
7601 | SAFE_BYTE_GET_AND_INC (padding, curr, 2, end); | |
7602 | if (padding != 0) | |
7603 | warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding); | |
7604 | ||
7605 | printf (_(" Length: %#lx\n"), (unsigned long) length); | |
7606 | printf (_(" Version: %#lx\n"), (unsigned long) version); | |
7607 | printf (_(" Index Offset [String]\n")); | |
7608 | } | |
e4b7104b | 7609 | |
95abb394 | 7610 | for (idx = 0; curr < entries_end; idx++) |
e4b7104b NC |
7611 | { |
7612 | dwarf_vma offset; | |
7613 | const unsigned char * string; | |
7614 | ||
95abb394 TV |
7615 | if (curr + entry_length > entries_end) |
7616 | /* Not enough space to read one entry_length, give up. */ | |
7617 | return 0; | |
7618 | ||
e4b7104b | 7619 | SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, end); |
39f381cb NC |
7620 | if (dwo) |
7621 | string = (const unsigned char *) | |
9f27c364 | 7622 | fetch_indexed_string (idx, NULL, entry_length, dwo); |
39f381cb NC |
7623 | else |
7624 | string = fetch_indirect_string (offset); | |
7625 | ||
9f27c364 | 7626 | printf (" %8lu %8s %s\n", idx, dwarf_vmatoa ("x", offset), |
e4b7104b NC |
7627 | string); |
7628 | } | |
7629 | } | |
39f381cb | 7630 | |
4723351a CC |
7631 | return 1; |
7632 | } | |
7633 | ||
01a8f077 JK |
7634 | /* Each debug_information[x].range_lists[y] gets this representation for |
7635 | sorting purposes. */ | |
7636 | ||
7637 | struct range_entry | |
467c65bc NC |
7638 | { |
7639 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 7640 | dwarf_vma ranges_offset; |
01a8f077 | 7641 | |
467c65bc NC |
7642 | /* Original debug_information to find parameters of the data. */ |
7643 | debug_info *debug_info_p; | |
7644 | }; | |
01a8f077 JK |
7645 | |
7646 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
7647 | ||
7648 | static int | |
7649 | range_entry_compar (const void *ap, const void *bp) | |
7650 | { | |
3f5e193b NC |
7651 | const struct range_entry *a_re = (const struct range_entry *) ap; |
7652 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
7653 | const dwarf_vma a = a_re->ranges_offset; |
7654 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
7655 | |
7656 | return (a > b) - (b > a); | |
7657 | } | |
7658 | ||
77145576 JK |
7659 | static void |
7660 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
7661 | unsigned int pointer_size, unsigned long offset, | |
7662 | unsigned long base_address) | |
7663 | { | |
7664 | while (start < finish) | |
7665 | { | |
7666 | dwarf_vma begin; | |
7667 | dwarf_vma end; | |
7668 | ||
7669 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7670 | if (start >= finish) | |
7671 | break; | |
7672 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7673 | ||
7674 | printf (" %8.8lx ", offset); | |
7675 | ||
7676 | if (begin == 0 && end == 0) | |
7677 | { | |
7678 | printf (_("<End of list>\n")); | |
7679 | break; | |
7680 | } | |
7681 | ||
7682 | /* Check base address specifiers. */ | |
7683 | if (is_max_address (begin, pointer_size) | |
7684 | && !is_max_address (end, pointer_size)) | |
7685 | { | |
7686 | base_address = end; | |
7687 | print_dwarf_vma (begin, pointer_size); | |
7688 | print_dwarf_vma (end, pointer_size); | |
7689 | printf ("(base address)\n"); | |
7690 | continue; | |
7691 | } | |
7692 | ||
7693 | print_dwarf_vma (begin + base_address, pointer_size); | |
7694 | print_dwarf_vma (end + base_address, pointer_size); | |
7695 | ||
7696 | if (begin == end) | |
7697 | fputs (_("(start == end)"), stdout); | |
7698 | else if (begin > end) | |
7699 | fputs (_("(start > end)"), stdout); | |
7700 | ||
7701 | putchar ('\n'); | |
7702 | } | |
7703 | } | |
7704 | ||
7705 | static void | |
7706 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
7707 | unsigned int pointer_size, unsigned long offset, | |
7708 | unsigned long base_address) | |
7709 | { | |
7710 | unsigned char *next = start; | |
7711 | ||
7712 | while (1) | |
7713 | { | |
7714 | unsigned long off = offset + (start - next); | |
7715 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
7716 | /* Initialize it due to a false compiler warning. */ |
7717 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
7718 | |
7719 | if (start + 1 > finish) | |
7720 | { | |
7721 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
7722 | offset); | |
7723 | break; | |
7724 | } | |
7725 | ||
7726 | printf (" %8.8lx ", off); | |
7727 | ||
7728 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
7729 | ||
7730 | switch (rlet) | |
7731 | { | |
7732 | case DW_RLE_end_of_list: | |
7733 | printf (_("<End of list>\n")); | |
7734 | break; | |
7735 | case DW_RLE_base_address: | |
7736 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
7737 | print_dwarf_vma (base_address, pointer_size); | |
7738 | printf (_("(base address)\n")); | |
7739 | break; | |
7740 | case DW_RLE_start_length: | |
7741 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
cd30bcef | 7742 | READ_ULEB (length, start, finish); |
77145576 JK |
7743 | end = begin + length; |
7744 | break; | |
7745 | case DW_RLE_offset_pair: | |
cd30bcef AM |
7746 | READ_ULEB (begin, start, finish); |
7747 | READ_ULEB (end, start, finish); | |
77145576 JK |
7748 | break; |
7749 | case DW_RLE_start_end: | |
7750 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7751 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7752 | break; | |
7753 | default: | |
7754 | error (_("Invalid range list entry type %d\n"), rlet); | |
7755 | rlet = DW_RLE_end_of_list; | |
7756 | break; | |
7757 | } | |
7758 | if (rlet == DW_RLE_end_of_list) | |
7759 | break; | |
7760 | if (rlet == DW_RLE_base_address) | |
7761 | continue; | |
7762 | ||
4d932715 BE |
7763 | /* Only a DW_RLE_offset_pair needs the base address added. */ |
7764 | if (rlet == DW_RLE_offset_pair) | |
7765 | { | |
7766 | begin += base_address; | |
7767 | end += base_address; | |
7768 | } | |
7769 | ||
7770 | print_dwarf_vma (begin, pointer_size); | |
7771 | print_dwarf_vma (end, pointer_size); | |
77145576 JK |
7772 | |
7773 | if (begin == end) | |
7774 | fputs (_("(start == end)"), stdout); | |
7775 | else if (begin > end) | |
7776 | fputs (_("(start > end)"), stdout); | |
7777 | ||
7778 | putchar ('\n'); | |
7779 | } | |
7780 | } | |
7781 | ||
19e6b90e L |
7782 | static int |
7783 | display_debug_ranges (struct dwarf_section *section, | |
7784 | void *file ATTRIBUTE_UNUSED) | |
7785 | { | |
7786 | unsigned char *start = section->start; | |
a2ff7a4b | 7787 | unsigned char *last_start = start; |
f6f0e17b | 7788 | unsigned long bytes = section->size; |
19e6b90e | 7789 | unsigned char *section_begin = start; |
f6f0e17b | 7790 | unsigned char *finish = start + bytes; |
01a8f077 JK |
7791 | unsigned int num_range_list, i; |
7792 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
7793 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
7794 | /* Initialize it due to a false compiler warning. */ | |
7795 | unsigned char address_size = 0; | |
cb4c35cf | 7796 | dwarf_vma last_offset = 0; |
19e6b90e | 7797 | |
19e6b90e L |
7798 | if (bytes == 0) |
7799 | { | |
7800 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7801 | return 0; | |
7802 | } | |
7803 | ||
77145576 JK |
7804 | if (is_rnglists) |
7805 | { | |
7806 | dwarf_vma initial_length; | |
7807 | unsigned int initial_length_size; | |
7808 | unsigned char segment_selector_size; | |
7809 | unsigned int offset_size, offset_entry_count; | |
7810 | unsigned short version; | |
7811 | ||
7812 | /* Get and check the length of the block. */ | |
7813 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
7814 | ||
7815 | if (initial_length == 0xffffffff) | |
7816 | { | |
7817 | /* This section is 64-bit DWARF 3. */ | |
7818 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
7819 | offset_size = 8; | |
7820 | initial_length_size = 12; | |
7821 | } | |
7822 | else | |
7823 | { | |
7824 | offset_size = 4; | |
7825 | initial_length_size = 4; | |
7826 | } | |
7827 | ||
7828 | if (initial_length + initial_length_size > section->size) | |
7829 | { | |
7830 | /* If the length field has a relocation against it, then we should | |
7831 | not complain if it is inaccurate (and probably negative). | |
7832 | It is copied from .debug_line handling code. */ | |
7833 | if (reloc_at (section, (start - section->start) - offset_size)) | |
7834 | { | |
7835 | initial_length = (finish - start) - initial_length_size; | |
7836 | } | |
7837 | else | |
7838 | { | |
7839 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
7840 | (long) initial_length); | |
7841 | return 0; | |
7842 | } | |
7843 | } | |
7844 | ||
7845 | /* Get and check the version number. */ | |
7846 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
7847 | ||
7848 | if (version != 5) | |
7849 | { | |
7850 | warn (_("Only DWARF version 5 debug_rnglists info " | |
7851 | "is currently supported.\n")); | |
7852 | return 0; | |
7853 | } | |
7854 | ||
7855 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
7856 | ||
7857 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
7858 | if (segment_selector_size != 0) | |
7859 | { | |
7860 | warn (_("The %s section contains " | |
7861 | "unsupported segment selector size: %d.\n"), | |
7862 | section->name, segment_selector_size); | |
7863 | return 0; | |
7864 | } | |
7865 | ||
7866 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
7867 | if (offset_entry_count != 0) | |
7868 | { | |
7869 | warn (_("The %s section contains " | |
7870 | "unsupported offset entry count: %u.\n"), | |
7871 | section->name, offset_entry_count); | |
7872 | return 0; | |
7873 | } | |
7874 | } | |
7875 | ||
1febe64d NC |
7876 | if (load_debug_info (file) == 0) |
7877 | { | |
7878 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7879 | section->name); | |
7880 | return 0; | |
7881 | } | |
19e6b90e | 7882 | |
01a8f077 | 7883 | num_range_list = 0; |
19e6b90e | 7884 | for (i = 0; i < num_debug_info_entries; i++) |
52ff20fe TV |
7885 | { |
7886 | if (debug_information [i].dwarf_version < 5 && is_rnglists) | |
7887 | /* Skip .debug_rnglists reference. */ | |
7888 | continue; | |
7889 | if (debug_information [i].dwarf_version >= 5 && !is_rnglists) | |
7890 | /* Skip .debug_range reference. */ | |
7891 | continue; | |
7892 | num_range_list += debug_information [i].num_range_lists; | |
7893 | } | |
19e6b90e | 7894 | |
01a8f077 | 7895 | if (num_range_list == 0) |
4723351a CC |
7896 | { |
7897 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 7898 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
7899 | printf (_("No range lists in .debug_info section.\n")); |
7900 | return 1; | |
7901 | } | |
19e6b90e | 7902 | |
3f5e193b NC |
7903 | range_entries = (struct range_entry *) |
7904 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 7905 | range_entry_fill = range_entries; |
19e6b90e | 7906 | |
01a8f077 JK |
7907 | for (i = 0; i < num_debug_info_entries; i++) |
7908 | { | |
7909 | debug_info *debug_info_p = &debug_information[i]; | |
7910 | unsigned int j; | |
7911 | ||
52ff20fe TV |
7912 | if (debug_information [i].dwarf_version < 5 && is_rnglists) |
7913 | /* Skip .debug_rnglists reference. */ | |
7914 | continue; | |
7915 | if (debug_information [i].dwarf_version >= 5 && !is_rnglists) | |
7916 | /* Skip .debug_range reference. */ | |
7917 | continue; | |
7918 | ||
01a8f077 JK |
7919 | for (j = 0; j < debug_info_p->num_range_lists; j++) |
7920 | { | |
7921 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
7922 | range_entry_fill->debug_info_p = debug_info_p; | |
7923 | range_entry_fill++; | |
19e6b90e L |
7924 | } |
7925 | } | |
7926 | ||
01a8f077 JK |
7927 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
7928 | range_entry_compar); | |
19e6b90e | 7929 | |
d493b283 | 7930 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 7931 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 7932 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 7933 | |
015dc7e1 | 7934 | introduce (section, false); |
dda8d76d | 7935 | |
19e6b90e L |
7936 | printf (_(" Offset Begin End\n")); |
7937 | ||
01a8f077 | 7938 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 7939 | { |
01a8f077 JK |
7940 | struct range_entry *range_entry = &range_entries[i]; |
7941 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 7942 | unsigned int pointer_size; |
359ca075 | 7943 | dwarf_vma offset; |
01a8f077 | 7944 | unsigned char *next; |
359ca075 | 7945 | dwarf_vma base_address; |
19e6b90e | 7946 | |
77145576 | 7947 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 7948 | offset = range_entry->ranges_offset; |
01a8f077 JK |
7949 | next = section_begin + offset; |
7950 | base_address = debug_info_p->base_address; | |
cecf136e | 7951 | |
f41e4712 NC |
7952 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
7953 | if (pointer_size < 2 || pointer_size > 8) | |
7954 | { | |
7955 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 7956 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
7957 | continue; |
7958 | } | |
b4eb7656 | 7959 | |
d11ae95e NC |
7960 | if (next < section_begin || next >= finish) |
7961 | { | |
7962 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
7963 | (unsigned long) offset, i); | |
7964 | continue; | |
7965 | } | |
7966 | ||
cb4c35cf AB |
7967 | /* If multiple DWARF entities reference the same range then we will |
7968 | have multiple entries in the `range_entries' list for the same | |
7969 | offset. Thanks to the sort above these will all be consecutive in | |
7970 | the `range_entries' list, so we can easily ignore duplicates | |
7971 | here. */ | |
7972 | if (i > 0 && last_offset == offset) | |
7973 | continue; | |
7974 | last_offset = offset; | |
7975 | ||
4723351a | 7976 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 7977 | { |
01a8f077 JK |
7978 | if (start < next) |
7979 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
7980 | (unsigned long) (start - section_begin), | |
7981 | (unsigned long) (next - section_begin), section->name); | |
7982 | else if (start > next) | |
a2ff7a4b AM |
7983 | { |
7984 | if (next == last_start) | |
7985 | continue; | |
7986 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
7987 | (unsigned long) (start - section_begin), | |
7988 | (unsigned long) (next - section_begin), section->name); | |
7989 | } | |
01a8f077 | 7990 | } |
d11ae95e | 7991 | |
01a8f077 | 7992 | start = next; |
a2ff7a4b | 7993 | last_start = next; |
19e6b90e | 7994 | |
77145576 JK |
7995 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
7996 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
7997 | } |
7998 | putchar ('\n'); | |
01a8f077 JK |
7999 | |
8000 | free (range_entries); | |
8001 | ||
19e6b90e L |
8002 | return 1; |
8003 | } | |
8004 | ||
8005 | typedef struct Frame_Chunk | |
8006 | { | |
8007 | struct Frame_Chunk *next; | |
8008 | unsigned char *chunk_start; | |
a1165289 | 8009 | unsigned int ncols; |
19e6b90e L |
8010 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
8011 | short int *col_type; | |
8012 | int *col_offset; | |
8013 | char *augmentation; | |
8014 | unsigned int code_factor; | |
8015 | int data_factor; | |
bf5117e3 NC |
8016 | dwarf_vma pc_begin; |
8017 | dwarf_vma pc_range; | |
32ef3000 | 8018 | unsigned int cfa_reg; |
c8071705 | 8019 | dwarf_vma cfa_offset; |
a1165289 | 8020 | unsigned int ra; |
19e6b90e L |
8021 | unsigned char fde_encoding; |
8022 | unsigned char cfa_exp; | |
604282a7 JJ |
8023 | unsigned char ptr_size; |
8024 | unsigned char segment_size; | |
19e6b90e L |
8025 | } |
8026 | Frame_Chunk; | |
8027 | ||
1296bc99 AB |
8028 | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); |
8029 | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; | |
665ce1f6 L |
8030 | static const char *const *dwarf_regnames; |
8031 | static unsigned int dwarf_regnames_count; | |
8032 | ||
1296bc99 | 8033 | |
19e6b90e L |
8034 | /* A marker for a col_type that means this column was never referenced |
8035 | in the frame info. */ | |
8036 | #define DW_CFA_unreferenced (-1) | |
8037 | ||
a1165289 | 8038 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
8039 | -1 for invalid reg. */ |
8040 | ||
8041 | static int | |
8042 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 8043 | { |
a1165289 | 8044 | unsigned int prev = fc->ncols; |
19e6b90e | 8045 | |
665ce1f6 L |
8046 | if (reg < (unsigned int) fc->ncols) |
8047 | return 0; | |
8048 | ||
d9acf707 | 8049 | if (dwarf_regnames_count > 0 |
665ce1f6 L |
8050 | && reg > dwarf_regnames_count) |
8051 | return -1; | |
19e6b90e L |
8052 | |
8053 | fc->ncols = reg + 1; | |
a1165289 NC |
8054 | /* PR 17512: file: 10450-2643-0.004. |
8055 | If reg == -1 then this can happen... */ | |
8056 | if (fc->ncols == 0) | |
8057 | return -1; | |
8058 | ||
06614111 | 8059 | /* PR 17512: file: 2844a11d. */ |
d9acf707 | 8060 | if (fc->ncols > 1024 && dwarf_regnames_count == 0) |
06614111 NC |
8061 | { |
8062 | error (_("Unfeasibly large register number: %u\n"), reg); | |
8063 | fc->ncols = 0; | |
8064 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
8065 | we ever encounter a valid binary that exceeds it. */ | |
8066 | return -1; | |
8067 | } | |
8068 | ||
3f5e193b | 8069 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 8070 | sizeof (short int)); |
3f5e193b | 8071 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 8072 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
8073 | if (fc->col_type == NULL || fc->col_offset == NULL) |
8074 | { | |
8075 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
8076 | fc->ncols); | |
8077 | fc->ncols = 0; | |
8078 | return -1; | |
8079 | } | |
19e6b90e L |
8080 | |
8081 | while (prev < fc->ncols) | |
8082 | { | |
8083 | fc->col_type[prev] = DW_CFA_unreferenced; | |
8084 | fc->col_offset[prev] = 0; | |
8085 | prev++; | |
8086 | } | |
665ce1f6 | 8087 | return 1; |
19e6b90e L |
8088 | } |
8089 | ||
2dc4cec1 L |
8090 | static const char *const dwarf_regnames_i386[] = |
8091 | { | |
43234a1e L |
8092 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
8093 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
8094 | "eip", "eflags", NULL, /* 8 - 10 */ | |
8095 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
8096 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
8097 | NULL, NULL, /* 19 - 20 */ | |
8098 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
8099 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
8100 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
8101 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
8102 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
8103 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
8104 | "tr", "ldtr", /* 48 - 49 */ | |
8105 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
8106 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
8107 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
8108 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
8109 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
8110 | NULL, NULL, NULL, /* 90 - 92 */ | |
8111 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
8112 | }; |
8113 | ||
3d875af5 L |
8114 | static const char *const dwarf_regnames_iamcu[] = |
8115 | { | |
8116 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
8117 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
8118 | "eip", "eflags", NULL, /* 8 - 10 */ | |
8119 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
8120 | NULL, NULL, /* 19 - 20 */ | |
8121 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
8122 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
8123 | NULL, NULL, NULL, /* 37 - 39 */ | |
8124 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
8125 | "tr", "ldtr", /* 48 - 49 */ | |
8126 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
8127 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
8128 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
8129 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
8130 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
8131 | NULL, NULL, NULL, /* 90 - 92 */ | |
8132 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
8133 | }; | |
8134 | ||
99f6fdd9 | 8135 | static void |
b129eb0e RH |
8136 | init_dwarf_regnames_i386 (void) |
8137 | { | |
8138 | dwarf_regnames = dwarf_regnames_i386; | |
8139 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
1296bc99 | 8140 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
8141 | } |
8142 | ||
99f6fdd9 | 8143 | static void |
3d875af5 L |
8144 | init_dwarf_regnames_iamcu (void) |
8145 | { | |
8146 | dwarf_regnames = dwarf_regnames_iamcu; | |
8147 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
1296bc99 | 8148 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
3d875af5 L |
8149 | } |
8150 | ||
2dc4cec1 L |
8151 | static const char *const dwarf_regnames_x86_64[] = |
8152 | { | |
8153 | "rax", "rdx", "rcx", "rbx", | |
8154 | "rsi", "rdi", "rbp", "rsp", | |
8155 | "r8", "r9", "r10", "r11", | |
8156 | "r12", "r13", "r14", "r15", | |
8157 | "rip", | |
8158 | "xmm0", "xmm1", "xmm2", "xmm3", | |
8159 | "xmm4", "xmm5", "xmm6", "xmm7", | |
8160 | "xmm8", "xmm9", "xmm10", "xmm11", | |
8161 | "xmm12", "xmm13", "xmm14", "xmm15", | |
8162 | "st0", "st1", "st2", "st3", | |
8163 | "st4", "st5", "st6", "st7", | |
8164 | "mm0", "mm1", "mm2", "mm3", | |
8165 | "mm4", "mm5", "mm6", "mm7", | |
8166 | "rflags", | |
8167 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
8168 | "fs.base", "gs.base", NULL, NULL, | |
8169 | "tr", "ldtr", | |
43234a1e L |
8170 | "mxcsr", "fcw", "fsw", |
8171 | "xmm16", "xmm17", "xmm18", "xmm19", | |
8172 | "xmm20", "xmm21", "xmm22", "xmm23", | |
8173 | "xmm24", "xmm25", "xmm26", "xmm27", | |
8174 | "xmm28", "xmm29", "xmm30", "xmm31", | |
8175 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
8176 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
8177 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
8178 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
8179 | NULL, NULL, NULL, /* 115 - 117 */ | |
8180 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
8181 | }; |
8182 | ||
99f6fdd9 | 8183 | static void |
b129eb0e RH |
8184 | init_dwarf_regnames_x86_64 (void) |
8185 | { | |
8186 | dwarf_regnames = dwarf_regnames_x86_64; | |
8187 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
1296bc99 | 8188 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
8189 | } |
8190 | ||
4ee22035 RH |
8191 | static const char *const dwarf_regnames_aarch64[] = |
8192 | { | |
b4eb7656 AM |
8193 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
8194 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
8195 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
8196 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
8197 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
fab7c86e TC |
8198 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
8199 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", | |
8200 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", | |
b4eb7656 AM |
8201 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
8202 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
8203 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
8204 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
fab7c86e TC |
8205 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
8206 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", | |
8207 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", | |
8208 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", | |
4ee22035 RH |
8209 | }; |
8210 | ||
99f6fdd9 | 8211 | static void |
4ee22035 RH |
8212 | init_dwarf_regnames_aarch64 (void) |
8213 | { | |
8214 | dwarf_regnames = dwarf_regnames_aarch64; | |
8215 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
1296bc99 | 8216 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
4ee22035 RH |
8217 | } |
8218 | ||
d6bb17b0 AA |
8219 | static const char *const dwarf_regnames_s390[] = |
8220 | { | |
8221 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
8222 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
8223 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
8224 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
8225 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
8226 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
8227 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
8228 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
8229 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
8230 | "pswm", "pswa", | |
8231 | NULL, NULL, | |
8232 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
8233 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
8234 | }; | |
8235 | ||
99f6fdd9 | 8236 | static void |
d6bb17b0 AA |
8237 | init_dwarf_regnames_s390 (void) |
8238 | { | |
8239 | dwarf_regnames = dwarf_regnames_s390; | |
8240 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
1296bc99 | 8241 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
d6bb17b0 AA |
8242 | } |
8243 | ||
5bb0830d AB |
8244 | static const char *const dwarf_regnames_riscv[] = |
8245 | { | |
8246 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
8247 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
8248 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
8249 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
8250 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
8251 | "fs0", "fs1", /* 40 - 41 */ | |
8252 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
8253 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
8254 | "fs10", "fs11", /* 58 - 59 */ | |
8255 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
8256 | }; | |
8257 | ||
4762fe62 AB |
8258 | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles |
8259 | the large number of CSRs. */ | |
8260 | ||
8261 | static const char * | |
8262 | regname_internal_riscv (unsigned int regno) | |
8263 | { | |
8264 | const char *name = NULL; | |
8265 | ||
8266 | /* Lookup in the table first, this covers GPR and FPR. */ | |
8267 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) | |
8268 | name = dwarf_regnames_riscv [regno]; | |
8269 | else if (regno >= 4096 && regno <= 8191) | |
8270 | { | |
8271 | /* This might be a CSR, these live in a sparse number space from 4096 | |
8272 | to 8191 These numbers are defined in the RISC-V ELF ABI | |
8273 | document. */ | |
8274 | switch (regno) | |
8275 | { | |
8f595e9b NC |
8276 | #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \ |
8277 | case VALUE + 4096: name = #NAME; break; | |
4762fe62 AB |
8278 | #include "opcode/riscv-opc.h" |
8279 | #undef DECLARE_CSR | |
8280 | ||
8281 | default: | |
8282 | { | |
8283 | static char csr_name[10]; | |
8284 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); | |
8285 | name = csr_name; | |
8286 | } | |
8287 | break; | |
8288 | } | |
8289 | } | |
8290 | ||
8291 | return name; | |
8292 | } | |
8293 | ||
99f6fdd9 | 8294 | static void |
5bb0830d AB |
8295 | init_dwarf_regnames_riscv (void) |
8296 | { | |
4762fe62 AB |
8297 | dwarf_regnames = NULL; |
8298 | dwarf_regnames_count = 8192; | |
8299 | dwarf_regnames_lookup_func = regname_internal_riscv; | |
5bb0830d AB |
8300 | } |
8301 | ||
2dc4cec1 | 8302 | void |
955ff7fc | 8303 | init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) |
2dc4cec1 | 8304 | { |
1296bc99 AB |
8305 | dwarf_regnames_lookup_func = NULL; |
8306 | ||
2dc4cec1 L |
8307 | switch (e_machine) |
8308 | { | |
8309 | case EM_386: | |
b129eb0e | 8310 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
8311 | break; |
8312 | ||
3d875af5 L |
8313 | case EM_IAMCU: |
8314 | init_dwarf_regnames_iamcu (); | |
8315 | break; | |
8316 | ||
2dc4cec1 | 8317 | case EM_X86_64: |
7f502d6c | 8318 | case EM_L1OM: |
7a9068fe | 8319 | case EM_K1OM: |
b129eb0e | 8320 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
8321 | break; |
8322 | ||
4ee22035 RH |
8323 | case EM_AARCH64: |
8324 | init_dwarf_regnames_aarch64 (); | |
8325 | break; | |
8326 | ||
d6bb17b0 AA |
8327 | case EM_S390: |
8328 | init_dwarf_regnames_s390 (); | |
8329 | break; | |
8330 | ||
5bb0830d AB |
8331 | case EM_RISCV: |
8332 | init_dwarf_regnames_riscv (); | |
8333 | break; | |
8334 | ||
2dc4cec1 L |
8335 | default: |
8336 | break; | |
8337 | } | |
8338 | } | |
8339 | ||
229a22cf AB |
8340 | /* Initialize the DWARF register name lookup state based on the |
8341 | architecture and specific machine type of a BFD. */ | |
8342 | ||
8343 | void | |
8344 | init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, | |
8345 | unsigned long mach) | |
8346 | { | |
1296bc99 AB |
8347 | dwarf_regnames_lookup_func = NULL; |
8348 | ||
229a22cf AB |
8349 | switch (arch) |
8350 | { | |
8351 | case bfd_arch_i386: | |
8352 | switch (mach) | |
8353 | { | |
8354 | case bfd_mach_x86_64: | |
8355 | case bfd_mach_x86_64_intel_syntax: | |
229a22cf AB |
8356 | case bfd_mach_x64_32: |
8357 | case bfd_mach_x64_32_intel_syntax: | |
229a22cf AB |
8358 | init_dwarf_regnames_x86_64 (); |
8359 | break; | |
8360 | ||
8361 | default: | |
8362 | init_dwarf_regnames_i386 (); | |
8363 | break; | |
8364 | } | |
8365 | break; | |
8366 | ||
8367 | case bfd_arch_iamcu: | |
8368 | init_dwarf_regnames_iamcu (); | |
8369 | break; | |
8370 | ||
8371 | case bfd_arch_aarch64: | |
8372 | init_dwarf_regnames_aarch64(); | |
8373 | break; | |
8374 | ||
8375 | case bfd_arch_s390: | |
8376 | init_dwarf_regnames_s390 (); | |
8377 | break; | |
8378 | ||
8379 | case bfd_arch_riscv: | |
8380 | init_dwarf_regnames_riscv (); | |
8381 | break; | |
8382 | ||
8383 | default: | |
8384 | break; | |
8385 | } | |
8386 | } | |
8387 | ||
2dc4cec1 | 8388 | static const char * |
1296bc99 | 8389 | regname_internal_by_table_only (unsigned int regno) |
2dc4cec1 | 8390 | { |
1296bc99 | 8391 | if (dwarf_regnames != NULL |
2dc4cec1 L |
8392 | && regno < dwarf_regnames_count |
8393 | && dwarf_regnames [regno] != NULL) | |
1296bc99 AB |
8394 | return dwarf_regnames [regno]; |
8395 | ||
8396 | return NULL; | |
8397 | } | |
8398 | ||
8399 | static const char * | |
8400 | regname (unsigned int regno, int name_only_p) | |
8401 | { | |
8402 | static char reg[64]; | |
8403 | ||
8404 | const char *name = NULL; | |
8405 | ||
8406 | if (dwarf_regnames_lookup_func != NULL) | |
8407 | name = dwarf_regnames_lookup_func (regno); | |
8408 | ||
8409 | if (name != NULL) | |
2dc4cec1 | 8410 | { |
1296bc99 AB |
8411 | if (name_only_p) |
8412 | return name; | |
8413 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); | |
2dc4cec1 L |
8414 | } |
8415 | else | |
8416 | snprintf (reg, sizeof (reg), "r%d", regno); | |
8417 | return reg; | |
8418 | } | |
8419 | ||
19e6b90e | 8420 | static void |
a1165289 | 8421 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 8422 | { |
a1165289 | 8423 | unsigned int r; |
19e6b90e L |
8424 | char tmp[100]; |
8425 | ||
d8024a91 | 8426 | if (*max_regs != fc->ncols) |
19e6b90e L |
8427 | *max_regs = fc->ncols; |
8428 | ||
8429 | if (*need_col_headers) | |
8430 | { | |
8431 | *need_col_headers = 0; | |
8432 | ||
288f0ba2 | 8433 | printf ("%-*s CFA ", eh_addr_size * 2, " LOC"); |
19e6b90e L |
8434 | |
8435 | for (r = 0; r < *max_regs; r++) | |
8436 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
8437 | { | |
8438 | if (r == fc->ra) | |
50751e18 | 8439 | printf ("ra "); |
19e6b90e | 8440 | else |
2dc4cec1 | 8441 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
8442 | } |
8443 | ||
8444 | printf ("\n"); | |
8445 | } | |
8446 | ||
bf5117e3 | 8447 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
8448 | if (fc->cfa_exp) |
8449 | strcpy (tmp, "exp"); | |
8450 | else | |
c8071705 | 8451 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
8452 | printf ("%-8s ", tmp); |
8453 | ||
8454 | for (r = 0; r < fc->ncols; r++) | |
8455 | { | |
8456 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
8457 | { | |
8458 | switch (fc->col_type[r]) | |
8459 | { | |
8460 | case DW_CFA_undefined: | |
8461 | strcpy (tmp, "u"); | |
8462 | break; | |
8463 | case DW_CFA_same_value: | |
8464 | strcpy (tmp, "s"); | |
8465 | break; | |
8466 | case DW_CFA_offset: | |
8467 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
8468 | break; | |
12eae2d3 JJ |
8469 | case DW_CFA_val_offset: |
8470 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
8471 | break; | |
19e6b90e | 8472 | case DW_CFA_register: |
2dc4cec1 | 8473 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
8474 | break; |
8475 | case DW_CFA_expression: | |
8476 | strcpy (tmp, "exp"); | |
8477 | break; | |
12eae2d3 JJ |
8478 | case DW_CFA_val_expression: |
8479 | strcpy (tmp, "vexp"); | |
8480 | break; | |
19e6b90e L |
8481 | default: |
8482 | strcpy (tmp, "n/a"); | |
8483 | break; | |
8484 | } | |
2dc4cec1 | 8485 | printf ("%-5s ", tmp); |
19e6b90e L |
8486 | } |
8487 | } | |
8488 | printf ("\n"); | |
8489 | } | |
8490 | ||
49727e46 | 8491 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 8492 | |
49727e46 AM |
8493 | static unsigned char * |
8494 | read_cie (unsigned char *start, unsigned char *end, | |
8495 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 8496 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
8497 | { |
8498 | int version; | |
8499 | Frame_Chunk *fc; | |
49727e46 | 8500 | unsigned char *augmentation_data = NULL; |
bf59c5d5 | 8501 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 8502 | |
041830e0 | 8503 | * p_cie = NULL; |
f41e4712 NC |
8504 | /* PR 17512: file: 001-228113-0.004. */ |
8505 | if (start >= end) | |
8506 | return end; | |
8507 | ||
49727e46 AM |
8508 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
8509 | memset (fc, 0, sizeof (Frame_Chunk)); | |
8510 | ||
8511 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
8512 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
8513 | ||
8514 | version = *start++; | |
8515 | ||
8516 | fc->augmentation = (char *) start; | |
f41e4712 NC |
8517 | /* PR 17512: file: 001-228113-0.004. |
8518 | Skip past augmentation name, but avoid running off the end of the data. */ | |
8519 | while (start < end) | |
8520 | if (* start ++ == '\0') | |
8521 | break; | |
8522 | if (start == end) | |
8523 | { | |
8524 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 8525 | goto fail; |
f41e4712 | 8526 | } |
49727e46 AM |
8527 | |
8528 | if (strcmp (fc->augmentation, "eh") == 0) | |
8529 | start += eh_addr_size; | |
8530 | ||
8531 | if (version >= 4) | |
8532 | { | |
8533 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
8534 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
8535 | { | |
8536 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 8537 | goto fail; |
77ef8654 NC |
8538 | } |
8539 | ||
49727e46 | 8540 | GET (fc->segment_size, 1); |
77ef8654 NC |
8541 | /* PR 17512: file: e99d2804. */ |
8542 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
8543 | { | |
8544 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 8545 | goto fail; |
77ef8654 NC |
8546 | } |
8547 | ||
49727e46 AM |
8548 | eh_addr_size = fc->ptr_size; |
8549 | } | |
8550 | else | |
8551 | { | |
8552 | fc->ptr_size = eh_addr_size; | |
8553 | fc->segment_size = 0; | |
8554 | } | |
442a6ce8 | 8555 | |
cd30bcef AM |
8556 | READ_ULEB (fc->code_factor, start, end); |
8557 | READ_SLEB (fc->data_factor, start, end); | |
442a6ce8 | 8558 | |
49727e46 AM |
8559 | if (version == 1) |
8560 | { | |
8561 | GET (fc->ra, 1); | |
8562 | } | |
8563 | else | |
8564 | { | |
cd30bcef | 8565 | READ_ULEB (fc->ra, start, end); |
49727e46 AM |
8566 | } |
8567 | ||
8568 | if (fc->augmentation[0] == 'z') | |
8569 | { | |
cd30bcef | 8570 | READ_ULEB (augmentation_data_len, start, end); |
49727e46 | 8571 | augmentation_data = start; |
a1165289 | 8572 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 8573 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 8574 | { |
bf59c5d5 NC |
8575 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
8576 | dwarf_vmatoa ("x", augmentation_data_len), | |
8577 | (unsigned long) (end - start)); | |
442a6ce8 | 8578 | goto fail; |
a1165289 | 8579 | } |
9c0f3d3f | 8580 | start += augmentation_data_len; |
49727e46 AM |
8581 | } |
8582 | ||
8583 | if (augmentation_data_len) | |
8584 | { | |
058037d3 NC |
8585 | unsigned char *p; |
8586 | unsigned char *q; | |
8587 | unsigned char *qend; | |
b4eb7656 | 8588 | |
49727e46 AM |
8589 | p = (unsigned char *) fc->augmentation + 1; |
8590 | q = augmentation_data; | |
058037d3 NC |
8591 | qend = q + augmentation_data_len; |
8592 | ||
9c0f3d3f | 8593 | while (p < end && q < qend) |
49727e46 AM |
8594 | { |
8595 | if (*p == 'L') | |
8596 | q++; | |
8597 | else if (*p == 'P') | |
8598 | q += 1 + size_of_encoded_value (*q); | |
8599 | else if (*p == 'R') | |
8600 | fc->fde_encoding = *q++; | |
8601 | else if (*p == 'S') | |
8602 | ; | |
09038062 ST |
8603 | else if (*p == 'B') |
8604 | ; | |
49727e46 AM |
8605 | else |
8606 | break; | |
8607 | p++; | |
8608 | } | |
c361b9ac NC |
8609 | /* Note - it is OK if this loop terminates with q < qend. |
8610 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
8611 | } |
8612 | ||
8613 | *p_cie = fc; | |
8614 | if (p_version) | |
8615 | *p_version = version; | |
8616 | if (p_aug_len) | |
8617 | { | |
8618 | *p_aug_len = augmentation_data_len; | |
8619 | *p_aug = augmentation_data; | |
8620 | } | |
8621 | return start; | |
442a6ce8 NC |
8622 | |
8623 | fail: | |
8624 | free (fc->col_offset); | |
8625 | free (fc->col_type); | |
8626 | free (fc); | |
8627 | return end; | |
49727e46 AM |
8628 | } |
8629 | ||
d85bf2ba NC |
8630 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
8631 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
8632 | PRINTED contains the number of characters already written to the current | |
8633 | output line. */ | |
bf59c5d5 NC |
8634 | |
8635 | static void | |
d85bf2ba NC |
8636 | display_data (bfd_size_type printed, |
8637 | const unsigned char * data, | |
8638 | const bfd_size_type len) | |
bf59c5d5 | 8639 | { |
d85bf2ba NC |
8640 | if (do_wide || len < ((80 - printed) / 3)) |
8641 | for (printed = 0; printed < len; ++printed) | |
8642 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
8643 | else |
8644 | { | |
d85bf2ba | 8645 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 8646 | { |
d85bf2ba | 8647 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 8648 | putchar ('\n'); |
d85bf2ba | 8649 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
8650 | } |
8651 | } | |
d85bf2ba NC |
8652 | } |
8653 | ||
8654 | /* Prints out the contents on the augmentation data array. | |
8655 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
8656 | ||
8657 | static void | |
8658 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
8659 | { | |
8660 | bfd_size_type i; | |
8661 | ||
8662 | i = printf (_(" Augmentation data: ")); | |
8663 | display_data (i, data, len); | |
bf59c5d5 NC |
8664 | } |
8665 | ||
19e6b90e L |
8666 | static int |
8667 | display_debug_frames (struct dwarf_section *section, | |
8668 | void *file ATTRIBUTE_UNUSED) | |
8669 | { | |
8670 | unsigned char *start = section->start; | |
8671 | unsigned char *end = start + section->size; | |
8672 | unsigned char *section_start = start; | |
3391569f NC |
8673 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
8674 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 8675 | Frame_Chunk *rs; |
015dc7e1 | 8676 | bool is_eh = strcmp (section->name, ".eh_frame") == 0; |
a1165289 | 8677 | unsigned int max_regs = 0; |
665ce1f6 | 8678 | const char *bad_reg = _("bad register: "); |
77ef8654 | 8679 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 8680 | |
015dc7e1 | 8681 | introduce (section, false); |
19e6b90e L |
8682 | |
8683 | while (start < end) | |
8684 | { | |
8685 | unsigned char *saved_start; | |
8686 | unsigned char *block_end; | |
bf5117e3 NC |
8687 | dwarf_vma length; |
8688 | dwarf_vma cie_id; | |
19e6b90e L |
8689 | Frame_Chunk *fc; |
8690 | Frame_Chunk *cie; | |
8691 | int need_col_headers = 1; | |
8692 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 8693 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
8694 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
8695 | unsigned int offset_size; | |
8696 | unsigned int initial_length_size; | |
015dc7e1 | 8697 | bool all_nops; |
a788aedd | 8698 | static Frame_Chunk fde_fc; |
19e6b90e L |
8699 | |
8700 | saved_start = start; | |
19e6b90e | 8701 | |
0c588247 | 8702 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 8703 | |
19e6b90e L |
8704 | if (length == 0) |
8705 | { | |
8706 | printf ("\n%08lx ZERO terminator\n\n", | |
8707 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
8708 | /* Skip any zero terminators that directly follow. |
8709 | A corrupt section size could have loaded a whole | |
8710 | slew of zero filled memory bytes. eg | |
8711 | PR 17512: file: 070-19381-0.004. */ | |
8712 | while (start < end && * start == 0) | |
8713 | ++ start; | |
b758e50f | 8714 | continue; |
19e6b90e L |
8715 | } |
8716 | ||
8717 | if (length == 0xffffffff) | |
8718 | { | |
0c588247 | 8719 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
8720 | offset_size = 8; |
8721 | initial_length_size = 12; | |
8722 | } | |
8723 | else | |
8724 | { | |
8725 | offset_size = 4; | |
8726 | initial_length_size = 4; | |
8727 | } | |
8728 | ||
8729 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 8730 | if (block_end > end || block_end < start) |
53b8873b | 8731 | { |
bf5117e3 NC |
8732 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
8733 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
8734 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
8735 | block_end = end; |
8736 | } | |
0c588247 NC |
8737 | |
8738 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 8739 | |
846a11e4 NC |
8740 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
8741 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
8742 | { |
8743 | int version; | |
a1165289 | 8744 | unsigned int mreg; |
19e6b90e | 8745 | |
49727e46 AM |
8746 | start = read_cie (start, end, &cie, &version, |
8747 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
8748 | /* PR 17512: file: 027-135133-0.005. */ |
8749 | if (cie == NULL) | |
8750 | break; | |
a1165289 | 8751 | |
49727e46 | 8752 | fc = cie; |
19e6b90e L |
8753 | fc->next = chunks; |
8754 | chunks = fc; | |
8755 | fc->chunk_start = saved_start; | |
a1165289 | 8756 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8757 | if (mreg < fc->ra) |
8758 | mreg = fc->ra; | |
06614111 NC |
8759 | if (frame_need_space (fc, mreg) < 0) |
8760 | break; | |
49727e46 AM |
8761 | if (fc->fde_encoding) |
8762 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 8763 | |
bf5117e3 NC |
8764 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
8765 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 8766 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 8767 | |
19e6b90e | 8768 | if (do_debug_frames_interp) |
bf5117e3 NC |
8769 | { |
8770 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
8771 | fc->code_factor, fc->data_factor, fc->ra); | |
8772 | } | |
19e6b90e L |
8773 | else |
8774 | { | |
bf5117e3 | 8775 | printf ("CIE\n"); |
19e6b90e L |
8776 | printf (" Version: %d\n", version); |
8777 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
8778 | if (version >= 4) |
8779 | { | |
8780 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
8781 | printf (" Segment Size: %u\n", fc->segment_size); | |
8782 | } | |
19e6b90e L |
8783 | printf (" Code alignment factor: %u\n", fc->code_factor); |
8784 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
8785 | printf (" Return address column: %d\n", fc->ra); | |
8786 | ||
8787 | if (augmentation_data_len) | |
bf59c5d5 | 8788 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 8789 | |
19e6b90e L |
8790 | putchar ('\n'); |
8791 | } | |
19e6b90e L |
8792 | } |
8793 | else | |
8794 | { | |
8795 | unsigned char *look_for; | |
604282a7 | 8796 | unsigned long segment_selector; |
19e6b90e | 8797 | |
49727e46 AM |
8798 | if (is_eh) |
8799 | { | |
8800 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
8801 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
8802 | } | |
8803 | else | |
8804 | look_for = section_start + cie_id; | |
19e6b90e | 8805 | |
49727e46 AM |
8806 | if (look_for <= saved_start) |
8807 | { | |
8808 | for (cie = chunks; cie ; cie = cie->next) | |
8809 | if (cie->chunk_start == look_for) | |
8810 | break; | |
8811 | } | |
8812 | else | |
8813 | { | |
8814 | for (cie = forward_refs; cie ; cie = cie->next) | |
8815 | if (cie->chunk_start == look_for) | |
8816 | break; | |
8817 | if (!cie) | |
8818 | { | |
8819 | unsigned int off_size; | |
8820 | unsigned char *cie_scan; | |
19e6b90e | 8821 | |
49727e46 AM |
8822 | cie_scan = look_for; |
8823 | off_size = 4; | |
8824 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
8825 | if (length == 0xffffffff) | |
8826 | { | |
8827 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
8828 | off_size = 8; | |
8829 | } | |
8830 | if (length != 0) | |
8831 | { | |
8832 | dwarf_vma c_id; | |
8833 | ||
8834 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
8835 | if (is_eh | |
8836 | ? c_id == 0 | |
8837 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
8838 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
8839 | { | |
8840 | int version; | |
a1165289 | 8841 | unsigned int mreg; |
49727e46 AM |
8842 | |
8843 | read_cie (cie_scan, end, &cie, &version, | |
8844 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
8845 | /* PR 17512: file: 3450-2098-0.004. */ |
8846 | if (cie == NULL) | |
8847 | { | |
8848 | warn (_("Failed to read CIE information\n")); | |
8849 | break; | |
8850 | } | |
49727e46 AM |
8851 | cie->next = forward_refs; |
8852 | forward_refs = cie; | |
8853 | cie->chunk_start = look_for; | |
a1165289 | 8854 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8855 | if (mreg < cie->ra) |
8856 | mreg = cie->ra; | |
06614111 NC |
8857 | if (frame_need_space (cie, mreg) < 0) |
8858 | { | |
8859 | warn (_("Invalid max register\n")); | |
8860 | break; | |
8861 | } | |
49727e46 AM |
8862 | if (cie->fde_encoding) |
8863 | encoded_ptr_size | |
8864 | = size_of_encoded_value (cie->fde_encoding); | |
8865 | } | |
8866 | } | |
8867 | } | |
8868 | } | |
8869 | ||
8870 | fc = &fde_fc; | |
8871 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
8872 | |
8873 | if (!cie) | |
8874 | { | |
bf5117e3 NC |
8875 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
8876 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
8877 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 8878 | fc->ncols = 0; |
3f5e193b NC |
8879 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
8880 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
8881 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
8882 | { | |
8883 | warn (_("Invalid max register\n")); | |
8884 | break; | |
8885 | } | |
19e6b90e L |
8886 | cie = fc; |
8887 | fc->augmentation = ""; | |
8888 | fc->fde_encoding = 0; | |
604282a7 JJ |
8889 | fc->ptr_size = eh_addr_size; |
8890 | fc->segment_size = 0; | |
19e6b90e L |
8891 | } |
8892 | else | |
8893 | { | |
8894 | fc->ncols = cie->ncols; | |
3f5e193b NC |
8895 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
8896 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
8897 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
8898 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
8899 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
8900 | fc->ptr_size = cie->ptr_size; |
8901 | eh_addr_size = cie->ptr_size; | |
8902 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
8903 | fc->code_factor = cie->code_factor; |
8904 | fc->data_factor = cie->data_factor; | |
8905 | fc->cfa_reg = cie->cfa_reg; | |
8906 | fc->cfa_offset = cie->cfa_offset; | |
8907 | fc->ra = cie->ra; | |
06614111 NC |
8908 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
8909 | { | |
8910 | warn (_("Invalid max register\n")); | |
8911 | break; | |
8912 | } | |
19e6b90e L |
8913 | fc->fde_encoding = cie->fde_encoding; |
8914 | } | |
8915 | ||
8916 | if (fc->fde_encoding) | |
8917 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
8918 | ||
604282a7 JJ |
8919 | segment_selector = 0; |
8920 | if (fc->segment_size) | |
c8071705 NC |
8921 | { |
8922 | if (fc->segment_size > sizeof (segment_selector)) | |
8923 | { | |
8924 | /* PR 17512: file: 9e196b3e. */ | |
8925 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
8926 | fc->segment_size = 4; | |
8927 | } | |
8928 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
8929 | } | |
041830e0 NC |
8930 | |
8931 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 8932 | |
0c588247 NC |
8933 | /* FIXME: It appears that sometimes the final pc_range value is |
8934 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
8935 | run of the "objcopy on compressed debug sections" test for an | |
8936 | example of this. */ | |
8937 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 8938 | |
19e6b90e L |
8939 | if (cie->augmentation[0] == 'z') |
8940 | { | |
cd30bcef | 8941 | READ_ULEB (augmentation_data_len, start, end); |
19e6b90e | 8942 | augmentation_data = start; |
bf59c5d5 | 8943 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
d292364e | 8944 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
0a9d414a | 8945 | { |
d292364e AM |
8946 | warn (_("Augmentation data too long: 0x%s, " |
8947 | "expected at most %#lx\n"), | |
8948 | dwarf_vmatoa ("x", augmentation_data_len), | |
8949 | (unsigned long) (end - start)); | |
0a9d414a NC |
8950 | start = end; |
8951 | augmentation_data = NULL; | |
8952 | augmentation_data_len = 0; | |
8953 | } | |
d292364e | 8954 | start += augmentation_data_len; |
19e6b90e L |
8955 | } |
8956 | ||
bf5117e3 NC |
8957 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
8958 | (unsigned long)(saved_start - section_start), | |
8959 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 8960 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 8961 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 8962 | |
604282a7 JJ |
8963 | if (fc->segment_size) |
8964 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
8965 | |
8966 | printf ("%s..%s\n", | |
8967 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
8968 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
8969 | ||
19e6b90e L |
8970 | if (! do_debug_frames_interp && augmentation_data_len) |
8971 | { | |
bf59c5d5 | 8972 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
8973 | putchar ('\n'); |
8974 | } | |
8975 | } | |
8976 | ||
8977 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
8978 | we're about to interpret instructions for the chunk. */ | |
8979 | /* ??? At present we need to do this always, since this sizes the | |
8980 | fc->col_type and fc->col_offset arrays, which we write into always. | |
8981 | We should probably split the interpreted and non-interpreted bits | |
8982 | into two different routines, since there's so much that doesn't | |
8983 | really overlap between them. */ | |
8984 | if (1 || do_debug_frames_interp) | |
8985 | { | |
8986 | /* Start by making a pass over the chunk, allocating storage | |
8987 | and taking note of what registers are used. */ | |
8988 | unsigned char *tmp = start; | |
8989 | ||
8990 | while (start < block_end) | |
8991 | { | |
041830e0 NC |
8992 | unsigned int reg, op, opa; |
8993 | unsigned long temp; | |
5929c344 | 8994 | unsigned char * new_start; |
19e6b90e L |
8995 | |
8996 | op = *start++; | |
8997 | opa = op & 0x3f; | |
8998 | if (op & 0xc0) | |
8999 | op &= 0xc0; | |
9000 | ||
9001 | /* Warning: if you add any more cases to this switch, be | |
9002 | sure to add them to the corresponding switch below. */ | |
9003 | switch (op) | |
9004 | { | |
9005 | case DW_CFA_advance_loc: | |
9006 | break; | |
9007 | case DW_CFA_offset: | |
cd30bcef | 9008 | SKIP_ULEB (start, end); |
665ce1f6 L |
9009 | if (frame_need_space (fc, opa) >= 0) |
9010 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
9011 | break; |
9012 | case DW_CFA_restore: | |
665ce1f6 L |
9013 | if (frame_need_space (fc, opa) >= 0) |
9014 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
9015 | break; |
9016 | case DW_CFA_set_loc: | |
9017 | start += encoded_ptr_size; | |
9018 | break; | |
9019 | case DW_CFA_advance_loc1: | |
9020 | start += 1; | |
9021 | break; | |
9022 | case DW_CFA_advance_loc2: | |
9023 | start += 2; | |
9024 | break; | |
9025 | case DW_CFA_advance_loc4: | |
9026 | start += 4; | |
9027 | break; | |
9028 | case DW_CFA_offset_extended: | |
12eae2d3 | 9029 | case DW_CFA_val_offset: |
cd30bcef AM |
9030 | READ_ULEB (reg, start, end); |
9031 | SKIP_ULEB (start, end); | |
665ce1f6 L |
9032 | if (frame_need_space (fc, reg) >= 0) |
9033 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9034 | break; |
9035 | case DW_CFA_restore_extended: | |
cd30bcef | 9036 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9037 | if (frame_need_space (fc, reg) >= 0) |
9038 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9039 | break; |
9040 | case DW_CFA_undefined: | |
cd30bcef | 9041 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9042 | if (frame_need_space (fc, reg) >= 0) |
9043 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9044 | break; |
9045 | case DW_CFA_same_value: | |
cd30bcef | 9046 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9047 | if (frame_need_space (fc, reg) >= 0) |
9048 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9049 | break; |
9050 | case DW_CFA_register: | |
cd30bcef AM |
9051 | READ_ULEB (reg, start, end); |
9052 | SKIP_ULEB (start, end); | |
665ce1f6 L |
9053 | if (frame_need_space (fc, reg) >= 0) |
9054 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9055 | break; |
9056 | case DW_CFA_def_cfa: | |
cd30bcef AM |
9057 | SKIP_ULEB (start, end); |
9058 | SKIP_ULEB (start, end); | |
19e6b90e L |
9059 | break; |
9060 | case DW_CFA_def_cfa_register: | |
cd30bcef | 9061 | SKIP_ULEB (start, end); |
19e6b90e L |
9062 | break; |
9063 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 9064 | SKIP_ULEB (start, end); |
19e6b90e L |
9065 | break; |
9066 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 9067 | READ_ULEB (temp, start, end); |
5929c344 NC |
9068 | new_start = start + temp; |
9069 | if (new_start < start) | |
041830e0 NC |
9070 | { |
9071 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
9072 | start = block_end; | |
9073 | } | |
9074 | else | |
5929c344 | 9075 | start = new_start; |
19e6b90e L |
9076 | break; |
9077 | case DW_CFA_expression: | |
12eae2d3 | 9078 | case DW_CFA_val_expression: |
cd30bcef AM |
9079 | READ_ULEB (reg, start, end); |
9080 | READ_ULEB (temp, start, end); | |
5929c344 NC |
9081 | new_start = start + temp; |
9082 | if (new_start < start) | |
041830e0 | 9083 | { |
b4eb7656 | 9084 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
9085 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
9086 | start = block_end; | |
9087 | } | |
9088 | else | |
5929c344 | 9089 | start = new_start; |
665ce1f6 L |
9090 | if (frame_need_space (fc, reg) >= 0) |
9091 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9092 | break; |
9093 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 9094 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
9095 | READ_ULEB (reg, start, end); |
9096 | SKIP_SLEB (start, end); | |
665ce1f6 L |
9097 | if (frame_need_space (fc, reg) >= 0) |
9098 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9099 | break; |
9100 | case DW_CFA_def_cfa_sf: | |
cd30bcef AM |
9101 | SKIP_ULEB (start, end); |
9102 | SKIP_SLEB (start, end); | |
19e6b90e L |
9103 | break; |
9104 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 9105 | SKIP_SLEB (start, end); |
19e6b90e L |
9106 | break; |
9107 | case DW_CFA_MIPS_advance_loc8: | |
9108 | start += 8; | |
9109 | break; | |
9110 | case DW_CFA_GNU_args_size: | |
cd30bcef | 9111 | SKIP_ULEB (start, end); |
19e6b90e L |
9112 | break; |
9113 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
9114 | READ_ULEB (reg, start, end); |
9115 | SKIP_ULEB (start, end); | |
665ce1f6 L |
9116 | if (frame_need_space (fc, reg) >= 0) |
9117 | fc->col_type[reg] = DW_CFA_undefined; | |
9118 | break; | |
19e6b90e L |
9119 | default: |
9120 | break; | |
9121 | } | |
9122 | } | |
9123 | start = tmp; | |
9124 | } | |
9125 | ||
015dc7e1 | 9126 | all_nops = true; |
5b6312fd | 9127 | |
19e6b90e L |
9128 | /* Now we know what registers are used, make a second pass over |
9129 | the chunk, this time actually printing out the info. */ | |
9130 | ||
9131 | while (start < block_end) | |
9132 | { | |
362beea4 | 9133 | unsigned char * tmp; |
19e6b90e | 9134 | unsigned op, opa; |
7f2c8a1d NC |
9135 | unsigned long ul, roffs; |
9136 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
9137 | are various functions, notably frame_space_needed() that assume that | |
9138 | reg is an unsigned int. */ | |
9139 | unsigned int reg; | |
9140 | dwarf_signed_vma l; | |
bf5117e3 | 9141 | dwarf_vma ofs; |
19e6b90e | 9142 | dwarf_vma vma; |
665ce1f6 | 9143 | const char *reg_prefix = ""; |
19e6b90e L |
9144 | |
9145 | op = *start++; | |
9146 | opa = op & 0x3f; | |
9147 | if (op & 0xc0) | |
9148 | op &= 0xc0; | |
9149 | ||
5b6312fd NC |
9150 | /* Make a note if something other than DW_CFA_nop happens. */ |
9151 | if (op != DW_CFA_nop) | |
015dc7e1 | 9152 | all_nops = false; |
5b6312fd | 9153 | |
19e6b90e L |
9154 | /* Warning: if you add any more cases to this switch, be |
9155 | sure to add them to the corresponding switch above. */ | |
9156 | switch (op) | |
9157 | { | |
9158 | case DW_CFA_advance_loc: | |
9159 | if (do_debug_frames_interp) | |
9160 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9161 | else | |
bf5117e3 | 9162 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 9163 | opa * fc->code_factor, |
b4eb7656 | 9164 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
9165 | fc->pc_begin + opa * fc->code_factor, |
9166 | fc->ptr_size)); | |
19e6b90e L |
9167 | fc->pc_begin += opa * fc->code_factor; |
9168 | break; | |
9169 | ||
9170 | case DW_CFA_offset: | |
cd30bcef | 9171 | READ_ULEB (roffs, start, end); |
665ce1f6 L |
9172 | if (opa >= (unsigned int) fc->ncols) |
9173 | reg_prefix = bad_reg; | |
9174 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9175 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
9176 | reg_prefix, regname (opa, 0), | |
9177 | roffs * fc->data_factor); | |
9178 | if (*reg_prefix == '\0') | |
9179 | { | |
9180 | fc->col_type[opa] = DW_CFA_offset; | |
9181 | fc->col_offset[opa] = roffs * fc->data_factor; | |
9182 | } | |
19e6b90e L |
9183 | break; |
9184 | ||
9185 | case DW_CFA_restore: | |
50751e18 | 9186 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
9187 | reg_prefix = bad_reg; |
9188 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9189 | printf (" DW_CFA_restore: %s%s\n", | |
9190 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
9191 | if (*reg_prefix != '\0') |
9192 | break; | |
9193 | ||
9194 | if (opa >= (unsigned int) cie->ncols | |
9195 | || (do_debug_frames_interp | |
9196 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
9197 | { | |
9198 | fc->col_type[opa] = DW_CFA_undefined; | |
9199 | fc->col_offset[opa] = 0; | |
9200 | } | |
9201 | else | |
665ce1f6 L |
9202 | { |
9203 | fc->col_type[opa] = cie->col_type[opa]; | |
9204 | fc->col_offset[opa] = cie->col_offset[opa]; | |
9205 | } | |
19e6b90e L |
9206 | break; |
9207 | ||
9208 | case DW_CFA_set_loc: | |
6937bb54 | 9209 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
9210 | if (do_debug_frames_interp) |
9211 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9212 | else | |
bf5117e3 NC |
9213 | printf (" DW_CFA_set_loc: %s\n", |
9214 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
9215 | fc->pc_begin = vma; |
9216 | break; | |
9217 | ||
9218 | case DW_CFA_advance_loc1: | |
0c588247 | 9219 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
9220 | if (do_debug_frames_interp) |
9221 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9222 | else | |
bf5117e3 NC |
9223 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
9224 | (unsigned long) (ofs * fc->code_factor), | |
9225 | dwarf_vmatoa_1 (NULL, | |
9226 | fc->pc_begin + ofs * fc->code_factor, | |
9227 | fc->ptr_size)); | |
19e6b90e L |
9228 | fc->pc_begin += ofs * fc->code_factor; |
9229 | break; | |
9230 | ||
9231 | case DW_CFA_advance_loc2: | |
6937bb54 | 9232 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
9233 | if (do_debug_frames_interp) |
9234 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9235 | else | |
bf5117e3 NC |
9236 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
9237 | (unsigned long) (ofs * fc->code_factor), | |
9238 | dwarf_vmatoa_1 (NULL, | |
9239 | fc->pc_begin + ofs * fc->code_factor, | |
9240 | fc->ptr_size)); | |
19e6b90e L |
9241 | fc->pc_begin += ofs * fc->code_factor; |
9242 | break; | |
9243 | ||
9244 | case DW_CFA_advance_loc4: | |
6937bb54 | 9245 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
9246 | if (do_debug_frames_interp) |
9247 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9248 | else | |
bf5117e3 NC |
9249 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
9250 | (unsigned long) (ofs * fc->code_factor), | |
9251 | dwarf_vmatoa_1 (NULL, | |
9252 | fc->pc_begin + ofs * fc->code_factor, | |
9253 | fc->ptr_size)); | |
19e6b90e L |
9254 | fc->pc_begin += ofs * fc->code_factor; |
9255 | break; | |
9256 | ||
9257 | case DW_CFA_offset_extended: | |
cd30bcef AM |
9258 | READ_ULEB (reg, start, end); |
9259 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
9260 | if (reg >= (unsigned int) fc->ncols) |
9261 | reg_prefix = bad_reg; | |
9262 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9263 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
9264 | reg_prefix, regname (reg, 0), | |
9265 | roffs * fc->data_factor); | |
9266 | if (*reg_prefix == '\0') | |
9267 | { | |
9268 | fc->col_type[reg] = DW_CFA_offset; | |
9269 | fc->col_offset[reg] = roffs * fc->data_factor; | |
9270 | } | |
19e6b90e L |
9271 | break; |
9272 | ||
12eae2d3 | 9273 | case DW_CFA_val_offset: |
cd30bcef AM |
9274 | READ_ULEB (reg, start, end); |
9275 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
9276 | if (reg >= (unsigned int) fc->ncols) |
9277 | reg_prefix = bad_reg; | |
9278 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 9279 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
9280 | reg_prefix, regname (reg, 0), |
9281 | roffs * fc->data_factor); | |
9282 | if (*reg_prefix == '\0') | |
9283 | { | |
9284 | fc->col_type[reg] = DW_CFA_val_offset; | |
9285 | fc->col_offset[reg] = roffs * fc->data_factor; | |
9286 | } | |
12eae2d3 JJ |
9287 | break; |
9288 | ||
19e6b90e | 9289 | case DW_CFA_restore_extended: |
cd30bcef | 9290 | READ_ULEB (reg, start, end); |
50751e18 | 9291 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
9292 | reg_prefix = bad_reg; |
9293 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9294 | printf (" DW_CFA_restore_extended: %s%s\n", | |
9295 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
9296 | if (*reg_prefix != '\0') |
9297 | break; | |
9298 | ||
9299 | if (reg >= (unsigned int) cie->ncols) | |
9300 | { | |
9301 | fc->col_type[reg] = DW_CFA_undefined; | |
9302 | fc->col_offset[reg] = 0; | |
9303 | } | |
9304 | else | |
665ce1f6 L |
9305 | { |
9306 | fc->col_type[reg] = cie->col_type[reg]; | |
9307 | fc->col_offset[reg] = cie->col_offset[reg]; | |
9308 | } | |
19e6b90e L |
9309 | break; |
9310 | ||
9311 | case DW_CFA_undefined: | |
cd30bcef | 9312 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9313 | if (reg >= (unsigned int) fc->ncols) |
9314 | reg_prefix = bad_reg; | |
9315 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9316 | printf (" DW_CFA_undefined: %s%s\n", | |
9317 | reg_prefix, regname (reg, 0)); | |
9318 | if (*reg_prefix == '\0') | |
9319 | { | |
9320 | fc->col_type[reg] = DW_CFA_undefined; | |
9321 | fc->col_offset[reg] = 0; | |
9322 | } | |
19e6b90e L |
9323 | break; |
9324 | ||
9325 | case DW_CFA_same_value: | |
cd30bcef | 9326 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9327 | if (reg >= (unsigned int) fc->ncols) |
9328 | reg_prefix = bad_reg; | |
9329 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9330 | printf (" DW_CFA_same_value: %s%s\n", | |
9331 | reg_prefix, regname (reg, 0)); | |
9332 | if (*reg_prefix == '\0') | |
9333 | { | |
9334 | fc->col_type[reg] = DW_CFA_same_value; | |
9335 | fc->col_offset[reg] = 0; | |
9336 | } | |
19e6b90e L |
9337 | break; |
9338 | ||
9339 | case DW_CFA_register: | |
cd30bcef AM |
9340 | READ_ULEB (reg, start, end); |
9341 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
9342 | if (reg >= (unsigned int) fc->ncols) |
9343 | reg_prefix = bad_reg; | |
9344 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 9345 | { |
665ce1f6 L |
9346 | printf (" DW_CFA_register: %s%s in ", |
9347 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
9348 | puts (regname (roffs, 0)); |
9349 | } | |
665ce1f6 L |
9350 | if (*reg_prefix == '\0') |
9351 | { | |
9352 | fc->col_type[reg] = DW_CFA_register; | |
9353 | fc->col_offset[reg] = roffs; | |
9354 | } | |
19e6b90e L |
9355 | break; |
9356 | ||
9357 | case DW_CFA_remember_state: | |
9358 | if (! do_debug_frames_interp) | |
9359 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 9360 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 9361 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
9362 | rs->cfa_reg = fc->cfa_reg; |
9363 | rs->ra = fc->ra; | |
9364 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 9365 | rs->ncols = fc->ncols; |
3f5e193b | 9366 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 9367 | sizeof (* rs->col_type)); |
d71ad7fc RC |
9368 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
9369 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
9370 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
9371 | rs->next = remembered_state; |
9372 | remembered_state = rs; | |
9373 | break; | |
9374 | ||
9375 | case DW_CFA_restore_state: | |
9376 | if (! do_debug_frames_interp) | |
9377 | printf (" DW_CFA_restore_state\n"); | |
9378 | rs = remembered_state; | |
9379 | if (rs) | |
9380 | { | |
9381 | remembered_state = rs->next; | |
d71ad7fc RC |
9382 | fc->cfa_offset = rs->cfa_offset; |
9383 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
9384 | fc->ra = rs->ra; |
9385 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
9386 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
9387 | { | |
1306a742 | 9388 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
9389 | fc->ncols = 0; |
9390 | break; | |
9391 | } | |
d71ad7fc | 9392 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 9393 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 9394 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
9395 | free (rs->col_type); |
9396 | free (rs->col_offset); | |
9397 | free (rs); | |
9398 | } | |
9399 | else if (do_debug_frames_interp) | |
9400 | printf ("Mismatched DW_CFA_restore_state\n"); | |
9401 | break; | |
9402 | ||
9403 | case DW_CFA_def_cfa: | |
cd30bcef AM |
9404 | READ_ULEB (fc->cfa_reg, start, end); |
9405 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
9406 | fc->cfa_exp = 0; |
9407 | if (! do_debug_frames_interp) | |
2dc4cec1 | 9408 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 9409 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
9410 | break; |
9411 | ||
9412 | case DW_CFA_def_cfa_register: | |
cd30bcef | 9413 | READ_ULEB (fc->cfa_reg, start, end); |
19e6b90e L |
9414 | fc->cfa_exp = 0; |
9415 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
9416 | printf (" DW_CFA_def_cfa_register: %s\n", |
9417 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
9418 | break; |
9419 | ||
9420 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 9421 | READ_ULEB (fc->cfa_offset, start, end); |
19e6b90e | 9422 | if (! do_debug_frames_interp) |
c8071705 | 9423 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
9424 | break; |
9425 | ||
9426 | case DW_CFA_nop: | |
9427 | if (! do_debug_frames_interp) | |
9428 | printf (" DW_CFA_nop\n"); | |
9429 | break; | |
9430 | ||
9431 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 9432 | READ_ULEB (ul, start, end); |
7460c0ab | 9433 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 9434 | { |
a1165289 | 9435 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
9436 | break; |
9437 | } | |
19e6b90e L |
9438 | if (! do_debug_frames_interp) |
9439 | { | |
9440 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
9441 | decode_location_expression (start, eh_addr_size, 0, -1, |
9442 | ul, 0, section); | |
19e6b90e L |
9443 | printf (")\n"); |
9444 | } | |
9445 | fc->cfa_exp = 1; | |
9446 | start += ul; | |
9447 | break; | |
9448 | ||
9449 | case DW_CFA_expression: | |
cd30bcef AM |
9450 | READ_ULEB (reg, start, end); |
9451 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
9452 | if (reg >= (unsigned int) fc->ncols) |
9453 | reg_prefix = bad_reg; | |
6937bb54 | 9454 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 9455 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
9456 | tmp = start + ul; |
9457 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 9458 | { |
a1165289 | 9459 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
9460 | break; |
9461 | } | |
665ce1f6 | 9462 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 9463 | { |
665ce1f6 L |
9464 | printf (" DW_CFA_expression: %s%s (", |
9465 | reg_prefix, regname (reg, 0)); | |
b7807392 | 9466 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 9467 | ul, 0, section); |
19e6b90e L |
9468 | printf (")\n"); |
9469 | } | |
665ce1f6 L |
9470 | if (*reg_prefix == '\0') |
9471 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 9472 | start = tmp; |
19e6b90e L |
9473 | break; |
9474 | ||
12eae2d3 | 9475 | case DW_CFA_val_expression: |
cd30bcef AM |
9476 | READ_ULEB (reg, start, end); |
9477 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
9478 | if (reg >= (unsigned int) fc->ncols) |
9479 | reg_prefix = bad_reg; | |
362beea4 NC |
9480 | tmp = start + ul; |
9481 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 9482 | { |
a1165289 | 9483 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
9484 | break; |
9485 | } | |
665ce1f6 | 9486 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 9487 | { |
665ce1f6 L |
9488 | printf (" DW_CFA_val_expression: %s%s (", |
9489 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
9490 | decode_location_expression (start, eh_addr_size, 0, -1, |
9491 | ul, 0, section); | |
12eae2d3 JJ |
9492 | printf (")\n"); |
9493 | } | |
665ce1f6 L |
9494 | if (*reg_prefix == '\0') |
9495 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 9496 | start = tmp; |
12eae2d3 JJ |
9497 | break; |
9498 | ||
19e6b90e | 9499 | case DW_CFA_offset_extended_sf: |
cd30bcef AM |
9500 | READ_ULEB (reg, start, end); |
9501 | READ_SLEB (l, start, end); | |
665ce1f6 L |
9502 | if (frame_need_space (fc, reg) < 0) |
9503 | reg_prefix = bad_reg; | |
9504 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9505 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
9506 | reg_prefix, regname (reg, 0), | |
c8071705 | 9507 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9508 | if (*reg_prefix == '\0') |
9509 | { | |
9510 | fc->col_type[reg] = DW_CFA_offset; | |
9511 | fc->col_offset[reg] = l * fc->data_factor; | |
9512 | } | |
19e6b90e L |
9513 | break; |
9514 | ||
12eae2d3 | 9515 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
9516 | READ_ULEB (reg, start, end); |
9517 | READ_SLEB (l, start, end); | |
665ce1f6 L |
9518 | if (frame_need_space (fc, reg) < 0) |
9519 | reg_prefix = bad_reg; | |
9520 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 9521 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 9522 | reg_prefix, regname (reg, 0), |
c8071705 | 9523 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9524 | if (*reg_prefix == '\0') |
9525 | { | |
9526 | fc->col_type[reg] = DW_CFA_val_offset; | |
9527 | fc->col_offset[reg] = l * fc->data_factor; | |
9528 | } | |
12eae2d3 JJ |
9529 | break; |
9530 | ||
19e6b90e | 9531 | case DW_CFA_def_cfa_sf: |
cd30bcef AM |
9532 | READ_ULEB (fc->cfa_reg, start, end); |
9533 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
9534 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
9535 | fc->cfa_exp = 0; | |
9536 | if (! do_debug_frames_interp) | |
2dc4cec1 | 9537 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 9538 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
9539 | break; |
9540 | ||
9541 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 9542 | READ_ULEB (fc->cfa_offset, start, end); |
c8071705 | 9543 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 9544 | if (! do_debug_frames_interp) |
c8071705 | 9545 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
9546 | break; |
9547 | ||
9548 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 9549 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
9550 | if (do_debug_frames_interp) |
9551 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9552 | else | |
bf5117e3 NC |
9553 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
9554 | (unsigned long) (ofs * fc->code_factor), | |
9555 | dwarf_vmatoa_1 (NULL, | |
9556 | fc->pc_begin + ofs * fc->code_factor, | |
9557 | fc->ptr_size)); | |
19e6b90e L |
9558 | fc->pc_begin += ofs * fc->code_factor; |
9559 | break; | |
9560 | ||
9561 | case DW_CFA_GNU_window_save: | |
9562 | if (! do_debug_frames_interp) | |
9563 | printf (" DW_CFA_GNU_window_save\n"); | |
9564 | break; | |
9565 | ||
9566 | case DW_CFA_GNU_args_size: | |
cd30bcef | 9567 | READ_ULEB (ul, start, end); |
19e6b90e L |
9568 | if (! do_debug_frames_interp) |
9569 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
9570 | break; | |
9571 | ||
9572 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
9573 | READ_ULEB (reg, start, end); |
9574 | READ_SLEB (l, start, end); | |
7f2c8a1d | 9575 | l = - l; |
665ce1f6 L |
9576 | if (frame_need_space (fc, reg) < 0) |
9577 | reg_prefix = bad_reg; | |
9578 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9579 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
9580 | reg_prefix, regname (reg, 0), | |
c8071705 | 9581 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9582 | if (*reg_prefix == '\0') |
9583 | { | |
9584 | fc->col_type[reg] = DW_CFA_offset; | |
9585 | fc->col_offset[reg] = l * fc->data_factor; | |
9586 | } | |
19e6b90e L |
9587 | break; |
9588 | ||
9589 | default: | |
53b8873b NC |
9590 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
9591 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
9592 | else | |
f41e4712 | 9593 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
9594 | start = block_end; |
9595 | } | |
9596 | } | |
9597 | ||
5b6312fd NC |
9598 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
9599 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
9600 | frame_display_row (fc, &need_col_headers, &max_regs); |
9601 | ||
a788aedd AM |
9602 | if (fde_fc.col_type != NULL) |
9603 | { | |
9604 | free (fde_fc.col_type); | |
9605 | fde_fc.col_type = NULL; | |
9606 | } | |
9607 | if (fde_fc.col_offset != NULL) | |
9608 | { | |
9609 | free (fde_fc.col_offset); | |
9610 | fde_fc.col_offset = NULL; | |
9611 | } | |
9612 | ||
19e6b90e | 9613 | start = block_end; |
604282a7 | 9614 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
9615 | } |
9616 | ||
9617 | printf ("\n"); | |
9618 | ||
3391569f NC |
9619 | while (remembered_state != NULL) |
9620 | { | |
9621 | rs = remembered_state; | |
9622 | remembered_state = rs->next; | |
9623 | free (rs->col_type); | |
9624 | free (rs->col_offset); | |
9625 | rs->next = NULL; /* Paranoia. */ | |
9626 | free (rs); | |
9627 | } | |
9628 | ||
9629 | while (chunks != NULL) | |
9630 | { | |
9631 | rs = chunks; | |
9632 | chunks = rs->next; | |
9633 | free (rs->col_type); | |
9634 | free (rs->col_offset); | |
9635 | rs->next = NULL; /* Paranoia. */ | |
9636 | free (rs); | |
9637 | } | |
9638 | ||
9639 | while (forward_refs != NULL) | |
9640 | { | |
9641 | rs = forward_refs; | |
9642 | forward_refs = rs->next; | |
9643 | free (rs->col_type); | |
9644 | free (rs->col_offset); | |
9645 | rs->next = NULL; /* Paranoia. */ | |
9646 | free (rs); | |
9647 | } | |
9648 | ||
19e6b90e L |
9649 | return 1; |
9650 | } | |
9651 | ||
9652 | #undef GET | |
19e6b90e | 9653 | |
61364358 JK |
9654 | static int |
9655 | display_debug_names (struct dwarf_section *section, void *file) | |
9656 | { | |
9657 | unsigned char *hdrptr = section->start; | |
9658 | dwarf_vma unit_length; | |
9659 | unsigned char *unit_start; | |
9660 | const unsigned char *const section_end = section->start + section->size; | |
9661 | unsigned char *unit_end; | |
9662 | ||
015dc7e1 | 9663 | introduce (section, false); |
61364358 | 9664 | |
dda8d76d | 9665 | load_debug_section_with_follow (str, file); |
61364358 JK |
9666 | |
9667 | for (; hdrptr < section_end; hdrptr = unit_end) | |
9668 | { | |
9669 | unsigned int offset_size; | |
9670 | uint16_t dwarf_version, padding; | |
9671 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
9672 | uint32_t bucket_count, name_count, abbrev_table_size; | |
9673 | uint32_t augmentation_string_size; | |
9674 | unsigned int i; | |
e98fdf1a | 9675 | unsigned long sec_off; |
015dc7e1 | 9676 | bool augmentation_printable; |
48467cb9 | 9677 | const char *augmentation_string; |
61364358 JK |
9678 | |
9679 | unit_start = hdrptr; | |
9680 | ||
9681 | /* Get and check the length of the block. */ | |
9682 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
9683 | ||
9684 | if (unit_length == 0xffffffff) | |
9685 | { | |
9686 | /* This section is 64-bit DWARF. */ | |
9687 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
9688 | offset_size = 8; | |
9689 | } | |
9690 | else | |
9691 | offset_size = 4; | |
9692 | unit_end = hdrptr + unit_length; | |
9693 | ||
e98fdf1a AM |
9694 | sec_off = hdrptr - section->start; |
9695 | if (sec_off + unit_length < sec_off | |
9696 | || sec_off + unit_length > section->size) | |
61364358 | 9697 | { |
e98fdf1a AM |
9698 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
9699 | section->name, | |
9700 | (unsigned long) (unit_start - section->start), | |
9701 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
9702 | return 0; |
9703 | } | |
9704 | ||
9705 | /* Get and check the version number. */ | |
9706 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
9707 | printf (_("Version %ld\n"), (long) dwarf_version); | |
9708 | ||
9709 | /* Prior versions did not exist, and future versions may not be | |
9710 | backwards compatible. */ | |
9711 | if (dwarf_version != 5) | |
9712 | { | |
9713 | warn (_("Only DWARF version 5 .debug_names " | |
9714 | "is currently supported.\n")); | |
9715 | return 0; | |
9716 | } | |
9717 | ||
9718 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
9719 | if (padding != 0) | |
9720 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
9721 | padding); | |
9722 | ||
9723 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
9724 | if (comp_unit_count == 0) | |
9725 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
9726 | ||
9727 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
9728 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
9729 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
9730 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
9731 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
9732 | ||
9733 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
9734 | if (augmentation_string_size % 4 != 0) | |
9735 | { | |
9736 | warn (_("Augmentation string length %u must be rounded up " | |
9737 | "to a multiple of 4 in .debug_names.\n"), | |
9738 | augmentation_string_size); | |
9739 | augmentation_string_size += (-augmentation_string_size) & 3; | |
9740 | } | |
48467cb9 | 9741 | |
61364358 | 9742 | printf (_("Augmentation string:")); |
48467cb9 | 9743 | |
015dc7e1 | 9744 | augmentation_printable = true; |
48467cb9 TV |
9745 | augmentation_string = (const char *) hdrptr; |
9746 | ||
61364358 JK |
9747 | for (i = 0; i < augmentation_string_size; i++) |
9748 | { | |
9749 | unsigned char uc; | |
9750 | ||
9751 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
9752 | printf (" %02x", uc); | |
48467cb9 TV |
9753 | |
9754 | if (uc != 0 && !ISPRINT (uc)) | |
015dc7e1 | 9755 | augmentation_printable = false; |
48467cb9 TV |
9756 | } |
9757 | ||
9758 | if (augmentation_printable) | |
9759 | { | |
9760 | printf (" (\""); | |
9761 | for (i = 0; | |
9762 | i < augmentation_string_size && augmentation_string[i]; | |
9763 | ++i) | |
9764 | putchar (augmentation_string[i]); | |
9765 | printf ("\")"); | |
61364358 | 9766 | } |
61364358 JK |
9767 | putchar ('\n'); |
9768 | ||
9769 | printf (_("CU table:\n")); | |
9770 | for (i = 0; i < comp_unit_count; i++) | |
9771 | { | |
9772 | uint64_t cu_offset; | |
9773 | ||
9774 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
9775 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
9776 | } | |
9777 | putchar ('\n'); | |
9778 | ||
9779 | printf (_("TU table:\n")); | |
9780 | for (i = 0; i < local_type_unit_count; i++) | |
9781 | { | |
9782 | uint64_t tu_offset; | |
9783 | ||
9784 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
9785 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
9786 | } | |
9787 | putchar ('\n'); | |
9788 | ||
9789 | printf (_("Foreign TU table:\n")); | |
9790 | for (i = 0; i < foreign_type_unit_count; i++) | |
9791 | { | |
9792 | uint64_t signature; | |
9793 | ||
9794 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
9795 | printf (_("[%3u] "), i); | |
9796 | print_dwarf_vma (signature, 8); | |
9797 | putchar ('\n'); | |
9798 | } | |
9799 | putchar ('\n'); | |
9800 | ||
9801 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
9802 | hdrptr += bucket_count * sizeof (uint32_t); | |
9803 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
9804 | hdrptr += name_count * sizeof (uint32_t); | |
9805 | unsigned char *const name_table_string_offsets = hdrptr; | |
9806 | hdrptr += name_count * offset_size; | |
9807 | unsigned char *const name_table_entry_offsets = hdrptr; | |
9808 | hdrptr += name_count * offset_size; | |
9809 | unsigned char *const abbrev_table = hdrptr; | |
9810 | hdrptr += abbrev_table_size; | |
9811 | const unsigned char *const abbrev_table_end = hdrptr; | |
9812 | unsigned char *const entry_pool = hdrptr; | |
9813 | if (hdrptr > unit_end) | |
9814 | { | |
9815 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
9816 | "for unit 0x%lx in the debug_names\n"), | |
9817 | (long) (hdrptr - section->start), | |
9818 | (long) (unit_end - section->start), | |
9819 | (long) (unit_start - section->start)); | |
9820 | return 0; | |
9821 | } | |
9822 | ||
9823 | size_t buckets_filled = 0; | |
9824 | size_t bucketi; | |
9825 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
9826 | { | |
9827 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
9828 | ||
9829 | if (bucket != 0) | |
9830 | ++buckets_filled; | |
9831 | } | |
d3a49aa8 AM |
9832 | printf (ngettext ("Used %zu of %lu bucket.\n", |
9833 | "Used %zu of %lu buckets.\n", | |
9834 | bucket_count), | |
9835 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 9836 | |
0a79bef4 | 9837 | uint32_t hash_prev = 0; |
61364358 JK |
9838 | size_t hash_clash_count = 0; |
9839 | size_t longest_clash = 0; | |
9840 | size_t this_length = 0; | |
9841 | size_t hashi; | |
9842 | for (hashi = 0; hashi < name_count; hashi++) | |
9843 | { | |
9844 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
9845 | ||
9846 | if (hashi > 0) | |
9847 | { | |
9848 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
9849 | { | |
9850 | ++hash_clash_count; | |
9851 | ++this_length; | |
9852 | longest_clash = MAX (longest_clash, this_length); | |
9853 | } | |
9854 | else | |
9855 | this_length = 0; | |
9856 | } | |
9857 | hash_prev = hash_this; | |
9858 | } | |
9859 | printf (_("Out of %lu items there are %zu bucket clashes" | |
9860 | " (longest of %zu entries).\n"), | |
9861 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
9862 | assert (name_count == buckets_filled + hash_clash_count); | |
9863 | ||
9864 | struct abbrev_lookup_entry | |
9865 | { | |
9866 | dwarf_vma abbrev_tag; | |
9867 | unsigned char *abbrev_lookup_ptr; | |
9868 | }; | |
9869 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
9870 | size_t abbrev_lookup_used = 0; | |
9871 | size_t abbrev_lookup_allocated = 0; | |
9872 | ||
9873 | unsigned char *abbrevptr = abbrev_table; | |
9874 | for (;;) | |
9875 | { | |
cd30bcef AM |
9876 | dwarf_vma abbrev_tag; |
9877 | ||
9878 | READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end); | |
61364358 JK |
9879 | if (abbrev_tag == 0) |
9880 | break; | |
9881 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
9882 | { | |
9883 | abbrev_lookup_allocated = MAX (0x100, | |
9884 | abbrev_lookup_allocated * 2); | |
9885 | abbrev_lookup = xrealloc (abbrev_lookup, | |
9886 | (abbrev_lookup_allocated | |
9887 | * sizeof (*abbrev_lookup))); | |
9888 | } | |
9889 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
9890 | struct abbrev_lookup_entry *entry; | |
9891 | for (entry = abbrev_lookup; | |
9892 | entry < abbrev_lookup + abbrev_lookup_used; | |
9893 | entry++) | |
9894 | if (entry->abbrev_tag == abbrev_tag) | |
9895 | { | |
9896 | warn (_("Duplicate abbreviation tag %lu " | |
9897 | "in unit 0x%lx in the debug_names\n"), | |
9898 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
9899 | break; | |
9900 | } | |
9901 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
9902 | entry->abbrev_tag = abbrev_tag; | |
9903 | entry->abbrev_lookup_ptr = abbrevptr; | |
9904 | ||
9905 | /* Skip DWARF tag. */ | |
cd30bcef | 9906 | SKIP_ULEB (abbrevptr, abbrev_table_end); |
61364358 JK |
9907 | for (;;) |
9908 | { | |
cd30bcef AM |
9909 | dwarf_vma xindex, form; |
9910 | ||
9911 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9912 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9913 | if (xindex == 0 && form == 0) |
61364358 JK |
9914 | break; |
9915 | } | |
9916 | } | |
9917 | ||
9918 | printf (_("\nSymbol table:\n")); | |
9919 | uint32_t namei; | |
9920 | for (namei = 0; namei < name_count; ++namei) | |
9921 | { | |
9922 | uint64_t string_offset, entry_offset; | |
9923 | ||
9924 | SAFE_BYTE_GET (string_offset, | |
9925 | name_table_string_offsets + namei * offset_size, | |
9926 | offset_size, unit_end); | |
9927 | SAFE_BYTE_GET (entry_offset, | |
9928 | name_table_entry_offsets + namei * offset_size, | |
9929 | offset_size, unit_end); | |
9930 | ||
9931 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
9932 | fetch_indirect_string (string_offset)); | |
9933 | ||
9934 | unsigned char *entryptr = entry_pool + entry_offset; | |
9935 | ||
279edac5 AM |
9936 | /* We need to scan first whether there is a single or multiple |
9937 | entries. TAGNO is -2 for the first entry, it is -1 for the | |
9938 | initial tag read of the second entry, then it becomes 0 for the | |
9939 | first entry for real printing etc. */ | |
61364358 JK |
9940 | int tagno = -2; |
9941 | /* Initialize it due to a false compiler warning. */ | |
9942 | dwarf_vma second_abbrev_tag = -1; | |
9943 | for (;;) | |
9944 | { | |
cd30bcef AM |
9945 | dwarf_vma abbrev_tag; |
9946 | dwarf_vma dwarf_tag; | |
9947 | const struct abbrev_lookup_entry *entry; | |
9948 | ||
9949 | READ_ULEB (abbrev_tag, entryptr, unit_end); | |
61364358 JK |
9950 | if (tagno == -1) |
9951 | { | |
9952 | second_abbrev_tag = abbrev_tag; | |
9953 | tagno = 0; | |
9954 | entryptr = entry_pool + entry_offset; | |
9955 | continue; | |
9956 | } | |
9957 | if (abbrev_tag == 0) | |
9958 | break; | |
9959 | if (tagno >= 0) | |
9960 | printf ("%s<%lu>", | |
9961 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
9962 | (unsigned long) abbrev_tag); | |
9963 | ||
61364358 JK |
9964 | for (entry = abbrev_lookup; |
9965 | entry < abbrev_lookup + abbrev_lookup_used; | |
9966 | entry++) | |
9967 | if (entry->abbrev_tag == abbrev_tag) | |
9968 | break; | |
9969 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
9970 | { | |
9971 | warn (_("Undefined abbreviation tag %lu " | |
9972 | "in unit 0x%lx in the debug_names\n"), | |
9973 | (long) abbrev_tag, | |
9974 | (long) (unit_start - section->start)); | |
9975 | break; | |
9976 | } | |
9977 | abbrevptr = entry->abbrev_lookup_ptr; | |
cd30bcef | 9978 | READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end); |
61364358 JK |
9979 | if (tagno >= 0) |
9980 | printf (" %s", get_TAG_name (dwarf_tag)); | |
9981 | for (;;) | |
9982 | { | |
cd30bcef AM |
9983 | dwarf_vma xindex, form; |
9984 | ||
9985 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9986 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9987 | if (xindex == 0 && form == 0) |
61364358 JK |
9988 | break; |
9989 | ||
9990 | if (tagno >= 0) | |
1d827a72 | 9991 | printf (" %s", get_IDX_name (xindex)); |
ec1b0fbb NC |
9992 | entryptr = read_and_display_attr_value (0, form, 0, |
9993 | unit_start, entryptr, unit_end, | |
9994 | 0, 0, offset_size, | |
61364358 JK |
9995 | dwarf_version, NULL, |
9996 | (tagno < 0), NULL, | |
ec1b0fbb | 9997 | NULL, '=', -1); |
61364358 JK |
9998 | } |
9999 | ++tagno; | |
10000 | } | |
10001 | if (tagno <= 0) | |
10002 | printf (_(" <no entries>")); | |
10003 | putchar ('\n'); | |
10004 | } | |
10005 | ||
10006 | free (abbrev_lookup); | |
10007 | } | |
10008 | ||
10009 | return 1; | |
10010 | } | |
10011 | ||
dda8d76d | 10012 | static int |
d85bf2ba NC |
10013 | display_debug_links (struct dwarf_section * section, |
10014 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
10015 | { |
10016 | const unsigned char * filename; | |
10017 | unsigned int filelen; | |
10018 | ||
015dc7e1 | 10019 | introduce (section, false); |
dda8d76d NC |
10020 | |
10021 | /* The .gnu_debuglink section is formatted as: | |
10022 | (c-string) Filename. | |
10023 | (padding) If needed to reach a 4 byte boundary. | |
10024 | (uint32_t) CRC32 value. | |
10025 | ||
10026 | The .gun_debugaltlink section is formatted as: | |
10027 | (c-string) Filename. | |
10028 | (binary) Build-ID. */ | |
521d4b19 | 10029 | |
dda8d76d NC |
10030 | filename = section->start; |
10031 | filelen = strnlen ((const char *) filename, section->size); | |
10032 | if (filelen == section->size) | |
10033 | { | |
10034 | warn (_("The debuglink filename is corrupt/missing\n")); | |
10035 | return 0; | |
10036 | } | |
10037 | ||
10038 | printf (_(" Separate debug info file: %s\n"), filename); | |
10039 | ||
24d127aa | 10040 | if (startswith (section->name, ".gnu_debuglink")) |
dda8d76d NC |
10041 | { |
10042 | unsigned int crc32; | |
10043 | unsigned int crc_offset; | |
10044 | ||
10045 | crc_offset = filelen + 1; | |
10046 | crc_offset = (crc_offset + 3) & ~3; | |
10047 | if (crc_offset + 4 > section->size) | |
10048 | { | |
10049 | warn (_("CRC offset missing/truncated\n")); | |
10050 | return 0; | |
10051 | } | |
10052 | ||
10053 | crc32 = byte_get (filename + crc_offset, 4); | |
10054 | ||
10055 | printf (_(" CRC value: %#x\n"), crc32); | |
10056 | ||
10057 | if (crc_offset + 4 < section->size) | |
10058 | { | |
10059 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
10060 | (long)(section->size - (crc_offset + 4))); | |
10061 | return 0; | |
10062 | } | |
10063 | } | |
24d127aa | 10064 | else /* startswith (section->name, ".gnu_debugaltlink") */ |
dda8d76d NC |
10065 | { |
10066 | const unsigned char * build_id = section->start + filelen + 1; | |
10067 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
10068 | bfd_size_type printed; | |
10069 | ||
10070 | /* FIXME: Should we support smaller build-id notes ? */ | |
10071 | if (build_id_len < 0x14) | |
10072 | { | |
10073 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
10074 | return 0; | |
10075 | } | |
10076 | ||
10077 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 10078 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
10079 | putchar ('\n'); |
10080 | } | |
10081 | ||
10082 | putchar ('\n'); | |
10083 | return 1; | |
10084 | } | |
10085 | ||
5bbdf3d5 DE |
10086 | static int |
10087 | display_gdb_index (struct dwarf_section *section, | |
10088 | void *file ATTRIBUTE_UNUSED) | |
10089 | { | |
10090 | unsigned char *start = section->start; | |
10091 | uint32_t version; | |
10092 | uint32_t cu_list_offset, tu_list_offset; | |
10093 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
10094 | unsigned int cu_list_elements, tu_list_elements; | |
10095 | unsigned int address_table_size, symbol_table_slots; | |
10096 | unsigned char *cu_list, *tu_list; | |
10097 | unsigned char *address_table, *symbol_table, *constant_pool; | |
10098 | unsigned int i; | |
10099 | ||
10100 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
10101 | ||
015dc7e1 | 10102 | introduce (section, false); |
5bbdf3d5 DE |
10103 | |
10104 | if (section->size < 6 * sizeof (uint32_t)) | |
10105 | { | |
10106 | warn (_("Truncated header in the %s section.\n"), section->name); | |
10107 | return 0; | |
10108 | } | |
10109 | ||
10110 | version = byte_get_little_endian (start, 4); | |
da88a764 | 10111 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
10112 | |
10113 | /* Prior versions are obsolete, and future versions may not be | |
10114 | backwards compatible. */ | |
aa170720 | 10115 | if (version < 3 || version > 8) |
5bbdf3d5 | 10116 | { |
da88a764 | 10117 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
10118 | return 0; |
10119 | } | |
8d6eee87 TT |
10120 | if (version < 4) |
10121 | warn (_("The address table data in version 3 may be wrong.\n")); | |
10122 | if (version < 5) | |
10123 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
10124 | if (version < 6) | |
10125 | warn (_("Version 5 does not include inlined functions.\n")); | |
10126 | if (version < 7) | |
10127 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
10128 | /* Version 7 indices generated by Gold have bad type unit references, |
10129 | PR binutils/15021. But we don't know if the index was generated by | |
10130 | Gold or not, so to avoid worrying users with gdb-generated indices | |
10131 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
10132 | |
10133 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
10134 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
10135 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
10136 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
10137 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
10138 | ||
10139 | if (cu_list_offset > section->size | |
10140 | || tu_list_offset > section->size | |
10141 | || address_table_offset > section->size | |
10142 | || symbol_table_offset > section->size | |
10143 | || constant_pool_offset > section->size) | |
10144 | { | |
10145 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
10146 | return 0; | |
10147 | } | |
10148 | ||
53774b7e NC |
10149 | /* PR 17531: file: 418d0a8a. */ |
10150 | if (tu_list_offset < cu_list_offset) | |
10151 | { | |
10152 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
10153 | tu_list_offset, cu_list_offset); | |
10154 | return 0; | |
10155 | } | |
10156 | ||
5bbdf3d5 | 10157 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
10158 | |
10159 | if (address_table_offset < tu_list_offset) | |
10160 | { | |
10161 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
10162 | address_table_offset, tu_list_offset); | |
10163 | return 0; | |
10164 | } | |
10165 | ||
5bbdf3d5 | 10166 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
10167 | |
10168 | /* PR 17531: file: 18a47d3d. */ | |
10169 | if (symbol_table_offset < address_table_offset) | |
10170 | { | |
13bace4a | 10171 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
10172 | symbol_table_offset, address_table_offset); |
10173 | return 0; | |
10174 | } | |
10175 | ||
5bbdf3d5 | 10176 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
10177 | |
10178 | if (constant_pool_offset < symbol_table_offset) | |
10179 | { | |
10180 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
10181 | constant_pool_offset, symbol_table_offset); | |
10182 | return 0; | |
10183 | } | |
10184 | ||
5bbdf3d5 DE |
10185 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
10186 | ||
10187 | cu_list = start + cu_list_offset; | |
10188 | tu_list = start + tu_list_offset; | |
10189 | address_table = start + address_table_offset; | |
10190 | symbol_table = start + symbol_table_offset; | |
10191 | constant_pool = start + constant_pool_offset; | |
10192 | ||
28d909e5 | 10193 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 10194 | { |
1306a742 | 10195 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
10196 | return 0; |
10197 | } | |
b4eb7656 | 10198 | |
5bbdf3d5 DE |
10199 | printf (_("\nCU table:\n")); |
10200 | for (i = 0; i < cu_list_elements; i += 2) | |
10201 | { | |
10202 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
10203 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
10204 | ||
10205 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
10206 | (unsigned long) cu_offset, | |
10207 | (unsigned long) (cu_offset + cu_length - 1)); | |
10208 | } | |
10209 | ||
10210 | printf (_("\nTU table:\n")); | |
10211 | for (i = 0; i < tu_list_elements; i += 3) | |
10212 | { | |
10213 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
10214 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
10215 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
10216 | ||
10217 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
10218 | (unsigned long) tu_offset, | |
10219 | (unsigned long) type_offset); | |
10220 | print_dwarf_vma (signature, 8); | |
10221 | printf ("\n"); | |
10222 | } | |
10223 | ||
10224 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
10225 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
10226 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
10227 | { |
10228 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
10229 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
10230 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
10231 | ||
10232 | print_dwarf_vma (low, 8); | |
10233 | print_dwarf_vma (high, 8); | |
da88a764 | 10234 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
10235 | } |
10236 | ||
10237 | printf (_("\nSymbol table:\n")); | |
10238 | for (i = 0; i < symbol_table_slots; ++i) | |
10239 | { | |
10240 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
10241 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
10242 | uint32_t num_cus, cu; | |
10243 | ||
10244 | if (name_offset != 0 | |
10245 | || cu_vector_offset != 0) | |
10246 | { | |
10247 | unsigned int j; | |
362beea4 | 10248 | unsigned char * adr; |
5bbdf3d5 | 10249 | |
362beea4 | 10250 | adr = constant_pool + name_offset; |
53774b7e | 10251 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 10252 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
10253 | { |
10254 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
10255 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
10256 | name_offset, i); | |
10257 | } | |
10258 | else | |
acff9664 NC |
10259 | printf ("[%3u] %.*s:", i, |
10260 | (int) (section->size - (constant_pool_offset + name_offset)), | |
10261 | constant_pool + name_offset); | |
53774b7e | 10262 | |
362beea4 NC |
10263 | adr = constant_pool + cu_vector_offset; |
10264 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
10265 | { |
10266 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
10267 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
10268 | cu_vector_offset, i); | |
10269 | continue; | |
10270 | } | |
57028622 | 10271 | |
362beea4 | 10272 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 10273 | |
362beea4 | 10274 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 10275 | if (num_cus * 4 < num_cus |
362beea4 NC |
10276 | || adr >= section->start + section->size |
10277 | || adr < constant_pool) | |
53774b7e NC |
10278 | { |
10279 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 10280 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
10281 | num_cus, i); |
10282 | continue; | |
10283 | } | |
10284 | ||
8d6eee87 TT |
10285 | if (num_cus > 1) |
10286 | printf ("\n"); | |
f3853b34 | 10287 | |
5bbdf3d5 DE |
10288 | for (j = 0; j < num_cus; ++j) |
10289 | { | |
7c1cef97 | 10290 | int is_static; |
8d6eee87 TT |
10291 | gdb_index_symbol_kind kind; |
10292 | ||
5bbdf3d5 | 10293 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 10294 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
10295 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
10296 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 10297 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 10298 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
10299 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
10300 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 10301 | else |
8d6eee87 TT |
10302 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
10303 | ||
459d52c8 DE |
10304 | printf (" [%s, %s]", |
10305 | is_static ? _("static") : _("global"), | |
10306 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
10307 | if (num_cus > 1) |
10308 | printf ("\n"); | |
5bbdf3d5 | 10309 | } |
8d6eee87 TT |
10310 | if (num_cus <= 1) |
10311 | printf ("\n"); | |
5bbdf3d5 DE |
10312 | } |
10313 | } | |
10314 | ||
10315 | return 1; | |
10316 | } | |
10317 | ||
657d0d47 CC |
10318 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
10319 | ||
10320 | static void | |
10321 | prealloc_cu_tu_list (unsigned int nshndx) | |
10322 | { | |
10323 | if (shndx_pool == NULL) | |
10324 | { | |
10325 | shndx_pool_size = nshndx; | |
10326 | shndx_pool_used = 0; | |
10327 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
10328 | sizeof (unsigned int)); | |
10329 | } | |
10330 | else | |
10331 | { | |
10332 | shndx_pool_size = shndx_pool_used + nshndx; | |
10333 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
10334 | sizeof (unsigned int)); | |
10335 | } | |
10336 | } | |
10337 | ||
10338 | static void | |
10339 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
10340 | { | |
10341 | if (shndx_pool_used >= shndx_pool_size) | |
10342 | { | |
10343 | error (_("Internal error: out of space in the shndx pool.\n")); | |
10344 | return; | |
10345 | } | |
10346 | shndx_pool [shndx_pool_used++] = shndx; | |
10347 | } | |
10348 | ||
10349 | static void | |
10350 | end_cu_tu_entry (void) | |
10351 | { | |
10352 | if (shndx_pool_used >= shndx_pool_size) | |
10353 | { | |
10354 | error (_("Internal error: out of space in the shndx pool.\n")); | |
10355 | return; | |
10356 | } | |
10357 | shndx_pool [shndx_pool_used++] = 0; | |
10358 | } | |
10359 | ||
341f9135 CC |
10360 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
10361 | ||
10362 | static const char * | |
10363 | get_DW_SECT_short_name (unsigned int dw_sect) | |
10364 | { | |
10365 | static char buf[16]; | |
10366 | ||
10367 | switch (dw_sect) | |
10368 | { | |
10369 | case DW_SECT_INFO: | |
10370 | return "info"; | |
10371 | case DW_SECT_TYPES: | |
10372 | return "types"; | |
10373 | case DW_SECT_ABBREV: | |
10374 | return "abbrev"; | |
10375 | case DW_SECT_LINE: | |
10376 | return "line"; | |
10377 | case DW_SECT_LOC: | |
10378 | return "loc"; | |
10379 | case DW_SECT_STR_OFFSETS: | |
10380 | return "str_off"; | |
10381 | case DW_SECT_MACINFO: | |
10382 | return "macinfo"; | |
10383 | case DW_SECT_MACRO: | |
10384 | return "macro"; | |
10385 | default: | |
b4eb7656 | 10386 | break; |
341f9135 CC |
10387 | } |
10388 | ||
10389 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
10390 | return buf; | |
10391 | } | |
10392 | ||
10393 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
10394 | These sections are extensions for Fission. | |
10395 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
10396 | |
10397 | static int | |
10398 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
10399 | { | |
10400 | unsigned char *phdr = section->start; | |
10401 | unsigned char *limit = phdr + section->size; | |
10402 | unsigned char *phash; | |
10403 | unsigned char *pindex; | |
10404 | unsigned char *ppool; | |
10405 | unsigned int version; | |
341f9135 | 10406 | unsigned int ncols = 0; |
657d0d47 CC |
10407 | unsigned int nused; |
10408 | unsigned int nslots; | |
10409 | unsigned int i; | |
341f9135 CC |
10410 | unsigned int j; |
10411 | dwarf_vma signature_high; | |
10412 | dwarf_vma signature_low; | |
10413 | char buf[64]; | |
657d0d47 | 10414 | |
6937bb54 NC |
10415 | /* PR 17512: file: 002-168123-0.004. */ |
10416 | if (phdr == NULL) | |
10417 | { | |
10418 | warn (_("Section %s is empty\n"), section->name); | |
10419 | return 0; | |
10420 | } | |
10421 | /* PR 17512: file: 002-376-0.004. */ | |
10422 | if (section->size < 24) | |
10423 | { | |
72c61a0d | 10424 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
10425 | section->name); |
10426 | return 0; | |
10427 | } | |
10428 | ||
10429 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 10430 | if (version >= 2) |
6937bb54 NC |
10431 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
10432 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
10433 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
10434 | ||
657d0d47 | 10435 | phash = phdr + 16; |
8e2e3c6c AM |
10436 | pindex = phash + (size_t) nslots * 8; |
10437 | ppool = pindex + (size_t) nslots * 4; | |
57028622 | 10438 | |
657d0d47 CC |
10439 | if (do_display) |
10440 | { | |
015dc7e1 | 10441 | introduce (section, false); |
dda8d76d | 10442 | |
8e2e3c6c | 10443 | printf (_(" Version: %u\n"), version); |
341f9135 | 10444 | if (version >= 2) |
8e2e3c6c AM |
10445 | printf (_(" Number of columns: %u\n"), ncols); |
10446 | printf (_(" Number of used entries: %u\n"), nused); | |
10447 | printf (_(" Number of slots: %u\n\n"), nslots); | |
657d0d47 CC |
10448 | } |
10449 | ||
8e2e3c6c AM |
10450 | /* PR 17531: file: 45d69832. */ |
10451 | if ((size_t) nslots * 8 / 8 != nslots | |
10452 | || phash < phdr || phash > limit | |
10453 | || pindex < phash || pindex > limit | |
10454 | || ppool < pindex || ppool > limit) | |
657d0d47 | 10455 | { |
8e2e3c6c AM |
10456 | warn (ngettext ("Section %s is too small for %u slot\n", |
10457 | "Section %s is too small for %u slots\n", | |
10458 | nslots), | |
657d0d47 CC |
10459 | section->name, nslots); |
10460 | return 0; | |
10461 | } | |
10462 | ||
341f9135 | 10463 | if (version == 1) |
657d0d47 | 10464 | { |
341f9135 CC |
10465 | if (!do_display) |
10466 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
10467 | for (i = 0; i < nslots; i++) | |
657d0d47 | 10468 | { |
341f9135 CC |
10469 | unsigned char *shndx_list; |
10470 | unsigned int shndx; | |
10471 | ||
6937bb54 | 10472 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 10473 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 10474 | { |
6937bb54 | 10475 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 10476 | shndx_list = ppool + j * 4; |
f3853b34 NC |
10477 | /* PR 17531: file: 705e010d. */ |
10478 | if (shndx_list < ppool) | |
10479 | { | |
10480 | warn (_("Section index pool located before start of section\n")); | |
10481 | return 0; | |
10482 | } | |
10483 | ||
341f9135 CC |
10484 | if (do_display) |
10485 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
10486 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10487 | buf, sizeof (buf))); | |
10488 | for (;;) | |
657d0d47 | 10489 | { |
341f9135 CC |
10490 | if (shndx_list >= limit) |
10491 | { | |
10492 | warn (_("Section %s too small for shndx pool\n"), | |
10493 | section->name); | |
10494 | return 0; | |
10495 | } | |
6937bb54 | 10496 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
10497 | if (shndx == 0) |
10498 | break; | |
10499 | if (do_display) | |
10500 | printf (" %d", shndx); | |
10501 | else | |
10502 | add_shndx_to_cu_tu_entry (shndx); | |
10503 | shndx_list += 4; | |
657d0d47 | 10504 | } |
657d0d47 | 10505 | if (do_display) |
341f9135 | 10506 | printf ("\n"); |
657d0d47 | 10507 | else |
341f9135 CC |
10508 | end_cu_tu_entry (); |
10509 | } | |
10510 | phash += 8; | |
10511 | pindex += 4; | |
10512 | } | |
10513 | } | |
10514 | else if (version == 2) | |
10515 | { | |
10516 | unsigned int val; | |
10517 | unsigned int dw_sect; | |
10518 | unsigned char *ph = phash; | |
10519 | unsigned char *pi = pindex; | |
8e2e3c6c AM |
10520 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
10521 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
10522 | unsigned char *pend = psizes + (size_t) nused * ncols * 4; | |
015dc7e1 | 10523 | bool is_tu_index; |
341f9135 CC |
10524 | struct cu_tu_set *this_set = NULL; |
10525 | unsigned int row; | |
10526 | unsigned char *prow; | |
10527 | ||
10528 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
10529 | ||
362beea4 | 10530 | /* PR 17531: file: 0dd159bf. |
8e2e3c6c AM |
10531 | Check for integer overflow (can occur when size_t is 32-bit) |
10532 | with overlarge ncols or nused values. */ | |
4ac948a0 NC |
10533 | if (ncols > 0 |
10534 | && ((size_t) ncols * 4 / 4 != ncols | |
10535 | || (size_t) nused * ncols * 4 / ((size_t) ncols * 4) != nused | |
10536 | || poffsets < ppool || poffsets > limit | |
10537 | || psizes < poffsets || psizes > limit | |
10538 | || pend < psizes || pend > limit)) | |
341f9135 CC |
10539 | { |
10540 | warn (_("Section %s too small for offset and size tables\n"), | |
10541 | section->name); | |
10542 | return 0; | |
10543 | } | |
10544 | ||
10545 | if (do_display) | |
10546 | { | |
10547 | printf (_(" Offset table\n")); | |
10548 | printf (" slot %-16s ", | |
10549 | is_tu_index ? _("signature") : _("dwo_id")); | |
10550 | } | |
10551 | else | |
10552 | { | |
10553 | if (is_tu_index) | |
10554 | { | |
10555 | tu_count = nused; | |
72c61a0d | 10556 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 10557 | this_set = tu_sets; |
657d0d47 | 10558 | } |
657d0d47 | 10559 | else |
341f9135 CC |
10560 | { |
10561 | cu_count = nused; | |
72c61a0d | 10562 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
10563 | this_set = cu_sets; |
10564 | } | |
10565 | } | |
6937bb54 | 10566 | |
341f9135 CC |
10567 | if (do_display) |
10568 | { | |
10569 | for (j = 0; j < ncols; j++) | |
10570 | { | |
6937bb54 | 10571 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
10572 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
10573 | } | |
10574 | printf ("\n"); | |
10575 | } | |
6937bb54 | 10576 | |
341f9135 CC |
10577 | for (i = 0; i < nslots; i++) |
10578 | { | |
6937bb54 NC |
10579 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
10580 | ||
10581 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10582 | if (row != 0) |
10583 | { | |
591f7597 | 10584 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 10585 | if (row > nused) |
591f7597 NC |
10586 | { |
10587 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
10588 | row, nused); | |
10589 | return 0; | |
10590 | } | |
10591 | ||
341f9135 | 10592 | if (!do_display) |
6aea08d9 NC |
10593 | { |
10594 | size_t num_copy = sizeof (uint64_t); | |
10595 | ||
10596 | /* PR 23064: Beware of buffer overflow. */ | |
10597 | if (ph + num_copy < limit) | |
10598 | memcpy (&this_set[row - 1].signature, ph, num_copy); | |
10599 | else | |
10600 | { | |
10601 | warn (_("Signature (%p) extends beyond end of space in section\n"), ph); | |
10602 | return 0; | |
10603 | } | |
10604 | } | |
6937bb54 | 10605 | |
341f9135 | 10606 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
10607 | /* PR 17531: file: b8ce60a8. */ |
10608 | if (prow < poffsets || prow > limit) | |
10609 | { | |
10610 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
10611 | row, ncols); | |
10612 | return 0; | |
10613 | } | |
3aade688 | 10614 | |
341f9135 CC |
10615 | if (do_display) |
10616 | printf (_(" [%3d] 0x%s"), | |
10617 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10618 | buf, sizeof (buf))); | |
10619 | for (j = 0; j < ncols; j++) | |
10620 | { | |
6937bb54 | 10621 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
10622 | if (do_display) |
10623 | printf (" %8d", val); | |
10624 | else | |
10625 | { | |
6937bb54 | 10626 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
10627 | |
10628 | /* PR 17531: file: 10796eb3. */ | |
10629 | if (dw_sect >= DW_SECT_MAX) | |
10630 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10631 | else | |
10632 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
10633 | } |
10634 | } | |
6937bb54 | 10635 | |
341f9135 CC |
10636 | if (do_display) |
10637 | printf ("\n"); | |
10638 | } | |
10639 | ph += 8; | |
10640 | pi += 4; | |
10641 | } | |
10642 | ||
10643 | ph = phash; | |
10644 | pi = pindex; | |
10645 | if (do_display) | |
b4eb7656 | 10646 | { |
341f9135 CC |
10647 | printf ("\n"); |
10648 | printf (_(" Size table\n")); | |
10649 | printf (" slot %-16s ", | |
10650 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 10651 | } |
6937bb54 | 10652 | |
341f9135 CC |
10653 | for (j = 0; j < ncols; j++) |
10654 | { | |
6937bb54 | 10655 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
10656 | if (do_display) |
10657 | printf (" %8s", get_DW_SECT_short_name (val)); | |
10658 | } | |
6937bb54 | 10659 | |
341f9135 CC |
10660 | if (do_display) |
10661 | printf ("\n"); | |
6937bb54 | 10662 | |
341f9135 CC |
10663 | for (i = 0; i < nslots; i++) |
10664 | { | |
6937bb54 NC |
10665 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
10666 | ||
10667 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10668 | if (row != 0) |
10669 | { | |
10670 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 10671 | |
341f9135 CC |
10672 | if (do_display) |
10673 | printf (_(" [%3d] 0x%s"), | |
10674 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10675 | buf, sizeof (buf))); | |
6937bb54 | 10676 | |
341f9135 CC |
10677 | for (j = 0; j < ncols; j++) |
10678 | { | |
6937bb54 | 10679 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
10680 | if (do_display) |
10681 | printf (" %8d", val); | |
10682 | else | |
10683 | { | |
6937bb54 | 10684 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
10685 | if (dw_sect >= DW_SECT_MAX) |
10686 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10687 | else | |
341f9135 CC |
10688 | this_set [row - 1].section_sizes [dw_sect] = val; |
10689 | } | |
10690 | } | |
6937bb54 | 10691 | |
341f9135 CC |
10692 | if (do_display) |
10693 | printf ("\n"); | |
10694 | } | |
6937bb54 | 10695 | |
341f9135 CC |
10696 | ph += 8; |
10697 | pi += 4; | |
657d0d47 | 10698 | } |
657d0d47 | 10699 | } |
341f9135 | 10700 | else if (do_display) |
6937bb54 | 10701 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
10702 | |
10703 | if (do_display) | |
10704 | printf ("\n"); | |
10705 | ||
10706 | return 1; | |
10707 | } | |
10708 | ||
288f0ba2 AM |
10709 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
10710 | ||
657d0d47 CC |
10711 | /* Load the CU and TU indexes if present. This will build a list of |
10712 | section sets that we can use to associate a .debug_info.dwo section | |
10713 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
10714 | ||
015dc7e1 | 10715 | static bool |
657d0d47 CC |
10716 | load_cu_tu_indexes (void *file) |
10717 | { | |
10718 | /* If we have already loaded (or tried to load) the CU and TU indexes | |
10719 | then do not bother to repeat the task. */ | |
43a444f9 NC |
10720 | if (cu_tu_indexes_read == -1) |
10721 | { | |
015dc7e1 | 10722 | cu_tu_indexes_read = true; |
521d4b19 | 10723 | |
dda8d76d | 10724 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 | 10725 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
015dc7e1 | 10726 | cu_tu_indexes_read = false; |
43a444f9 | 10727 | |
dda8d76d | 10728 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 | 10729 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
015dc7e1 | 10730 | cu_tu_indexes_read = false; |
43a444f9 | 10731 | } |
657d0d47 | 10732 | |
015dc7e1 | 10733 | return (bool) cu_tu_indexes_read; |
657d0d47 CC |
10734 | } |
10735 | ||
10736 | /* Find the set of sections that includes section SHNDX. */ | |
10737 | ||
10738 | unsigned int * | |
10739 | find_cu_tu_set (void *file, unsigned int shndx) | |
10740 | { | |
10741 | unsigned int i; | |
10742 | ||
43a444f9 NC |
10743 | if (! load_cu_tu_indexes (file)) |
10744 | return NULL; | |
657d0d47 CC |
10745 | |
10746 | /* Find SHNDX in the shndx pool. */ | |
10747 | for (i = 0; i < shndx_pool_used; i++) | |
10748 | if (shndx_pool [i] == shndx) | |
10749 | break; | |
10750 | ||
10751 | if (i >= shndx_pool_used) | |
10752 | return NULL; | |
10753 | ||
10754 | /* Now backup to find the first entry in the set. */ | |
10755 | while (i > 0 && shndx_pool [i - 1] != 0) | |
10756 | i--; | |
10757 | ||
10758 | return shndx_pool + i; | |
10759 | } | |
10760 | ||
10761 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
10762 | ||
10763 | static int | |
10764 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
10765 | { | |
10766 | return process_cu_tu_index (section, 1); | |
10767 | } | |
10768 | ||
19e6b90e L |
10769 | static int |
10770 | display_debug_not_supported (struct dwarf_section *section, | |
10771 | void *file ATTRIBUTE_UNUSED) | |
10772 | { | |
10773 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
10774 | section->name); | |
10775 | ||
10776 | return 1; | |
10777 | } | |
10778 | ||
1306a742 NC |
10779 | /* Like malloc, but takes two parameters like calloc. |
10780 | Verifies that the first parameter is not too large. | |
82b1b41b | 10781 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 10782 | |
19e6b90e L |
10783 | void * |
10784 | cmalloc (size_t nmemb, size_t size) | |
10785 | { | |
10786 | /* Check for overflow. */ | |
10787 | if (nmemb >= ~(size_t) 0 / size) | |
10788 | return NULL; | |
82b1b41b NC |
10789 | |
10790 | return xmalloc (nmemb * size); | |
19e6b90e L |
10791 | } |
10792 | ||
1306a742 NC |
10793 | /* Like xmalloc, but takes two parameters like calloc. |
10794 | Verifies that the first parameter is not too large. | |
10795 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 10796 | |
72c61a0d | 10797 | void * |
1306a742 | 10798 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
10799 | { |
10800 | /* Check for overflow. */ | |
10801 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
10802 | { |
10803 | fprintf (stderr, | |
10804 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
10805 | (long) nmemb); | |
10806 | xexit (1); | |
10807 | } | |
72c61a0d | 10808 | |
1306a742 | 10809 | return xmalloc (nmemb * size); |
72c61a0d NC |
10810 | } |
10811 | ||
1306a742 NC |
10812 | /* Like xrealloc, but takes three parameters. |
10813 | Verifies that the second parameter is not too large. | |
10814 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 10815 | |
19e6b90e | 10816 | void * |
1306a742 | 10817 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
10818 | { |
10819 | /* Check for overflow. */ | |
10820 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10821 | { |
dda8d76d NC |
10822 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
10823 | (long) nmemb); | |
8490fb40 NC |
10824 | xexit (1); |
10825 | } | |
82b1b41b | 10826 | |
1306a742 | 10827 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
10828 | } |
10829 | ||
1306a742 | 10830 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 10831 | |
19e6b90e | 10832 | void * |
1306a742 | 10833 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
10834 | { |
10835 | /* Check for overflow. */ | |
10836 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10837 | { |
dda8d76d NC |
10838 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
10839 | (long) nmemb); | |
8490fb40 NC |
10840 | xexit (1); |
10841 | } | |
82b1b41b | 10842 | |
1306a742 | 10843 | return xcalloc (nmemb, size); |
19e6b90e L |
10844 | } |
10845 | ||
dda8d76d NC |
10846 | static unsigned long |
10847 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
10848 | const unsigned char * buf, | |
10849 | bfd_size_type len) | |
10850 | { | |
10851 | static const unsigned long crc32_table[256] = | |
10852 | { | |
10853 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
10854 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
10855 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
10856 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
10857 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
10858 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
10859 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
10860 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
10861 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
10862 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
10863 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
10864 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
10865 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
10866 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
10867 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
10868 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
10869 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
10870 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
10871 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
10872 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
10873 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
10874 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
10875 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
10876 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
10877 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
10878 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
10879 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
10880 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
10881 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
10882 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
10883 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
10884 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
10885 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
10886 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
10887 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
10888 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
10889 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
10890 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
10891 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
10892 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
10893 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
10894 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
10895 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
10896 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
10897 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
10898 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
10899 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
10900 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
10901 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
10902 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
10903 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
10904 | 0x2d02ef8d | |
10905 | }; | |
10906 | const unsigned char *end; | |
10907 | ||
10908 | crc = ~crc & 0xffffffff; | |
10909 | for (end = buf + len; buf < end; ++ buf) | |
10910 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
10911 | return ~crc & 0xffffffff; | |
10912 | } | |
10913 | ||
015dc7e1 AM |
10914 | typedef bool (*check_func_type) (const char *, void *); |
10915 | typedef const char *(* parse_func_type) (struct dwarf_section *, void *); | |
dda8d76d | 10916 | |
015dc7e1 | 10917 | static bool |
dda8d76d NC |
10918 | check_gnu_debuglink (const char * pathname, void * crc_pointer) |
10919 | { | |
10920 | static unsigned char buffer [8 * 1024]; | |
10921 | FILE * f; | |
10922 | bfd_size_type count; | |
10923 | unsigned long crc = 0; | |
10924 | void * sep_data; | |
10925 | ||
10926 | sep_data = open_debug_file (pathname); | |
10927 | if (sep_data == NULL) | |
015dc7e1 | 10928 | return false; |
dda8d76d NC |
10929 | |
10930 | /* Yes - we are opening the file twice... */ | |
10931 | f = fopen (pathname, "rb"); | |
10932 | if (f == NULL) | |
10933 | { | |
10934 | /* Paranoia: This should never happen. */ | |
10935 | close_debug_file (sep_data); | |
10936 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
015dc7e1 | 10937 | return false; |
dda8d76d NC |
10938 | } |
10939 | ||
10940 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
10941 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
10942 | ||
10943 | fclose (f); | |
10944 | ||
10945 | if (crc != * (unsigned long *) crc_pointer) | |
10946 | { | |
10947 | close_debug_file (sep_data); | |
10948 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
10949 | pathname); | |
015dc7e1 | 10950 | return false; |
dda8d76d NC |
10951 | } |
10952 | ||
015dc7e1 | 10953 | return true; |
dda8d76d NC |
10954 | } |
10955 | ||
10956 | static const char * | |
10957 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
10958 | { | |
10959 | const char * name; | |
10960 | unsigned int crc_offset; | |
10961 | unsigned long * crc32 = (unsigned long *) data; | |
10962 | ||
10963 | /* The name is first. | |
10964 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
10965 | name = (const char *) section->start; | |
10966 | ||
10967 | crc_offset = strnlen (name, section->size) + 1; | |
3d64c987 NC |
10968 | if (crc_offset == 1) |
10969 | return NULL; | |
dda8d76d NC |
10970 | crc_offset = (crc_offset + 3) & ~3; |
10971 | if (crc_offset + 4 > section->size) | |
10972 | return NULL; | |
10973 | ||
10974 | * crc32 = byte_get (section->start + crc_offset, 4); | |
10975 | return name; | |
10976 | } | |
10977 | ||
015dc7e1 | 10978 | static bool |
dda8d76d NC |
10979 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) |
10980 | { | |
10981 | void * sep_data = open_debug_file (filename); | |
10982 | ||
10983 | if (sep_data == NULL) | |
015dc7e1 | 10984 | return false; |
dda8d76d NC |
10985 | |
10986 | /* FIXME: We should now extract the build-id in the separate file | |
10987 | and check it... */ | |
10988 | ||
015dc7e1 | 10989 | return true; |
dda8d76d NC |
10990 | } |
10991 | ||
10992 | typedef struct build_id_data | |
10993 | { | |
10994 | bfd_size_type len; | |
10995 | const unsigned char * data; | |
10996 | } Build_id_data; | |
10997 | ||
10998 | static const char * | |
10999 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
11000 | { | |
11001 | const char * name; | |
11002 | bfd_size_type namelen; | |
11003 | bfd_size_type id_len; | |
11004 | Build_id_data * build_id_data; | |
11005 | ||
11006 | /* The name is first. | |
11007 | The build-id follows immediately, with no padding, up to the section's end. */ | |
11008 | ||
11009 | name = (const char *) section->start; | |
11010 | namelen = strnlen (name, section->size) + 1; | |
3d64c987 NC |
11011 | if (namelen == 1) |
11012 | return NULL; | |
dda8d76d NC |
11013 | if (namelen >= section->size) |
11014 | return NULL; | |
11015 | ||
11016 | id_len = section->size - namelen; | |
11017 | if (id_len < 0x14) | |
11018 | return NULL; | |
11019 | ||
dfbee680 | 11020 | build_id_data = (Build_id_data *) data; |
dda8d76d NC |
11021 | build_id_data->len = id_len; |
11022 | build_id_data->data = section->start + namelen; | |
11023 | ||
dda8d76d NC |
11024 | return name; |
11025 | } | |
11026 | ||
24841daa NC |
11027 | static void |
11028 | add_separate_debug_file (const char * filename, void * handle) | |
11029 | { | |
11030 | separate_info * i = xmalloc (sizeof * i); | |
11031 | ||
11032 | i->filename = filename; | |
11033 | i->handle = handle; | |
11034 | i->next = first_separate_info; | |
11035 | first_separate_info = i; | |
11036 | } | |
11037 | ||
301a9420 AM |
11038 | #if HAVE_LIBDEBUGINFOD |
11039 | /* Query debuginfod servers for the target debuglink or debugaltlink | |
11040 | file. If successful, store the path of the file in filename and | |
11041 | return TRUE, otherwise return FALSE. */ | |
11042 | ||
015dc7e1 | 11043 | static bool |
301a9420 AM |
11044 | debuginfod_fetch_separate_debug_info (struct dwarf_section * section, |
11045 | char ** filename, | |
11046 | void * file) | |
11047 | { | |
11048 | size_t build_id_len; | |
11049 | unsigned char * build_id; | |
11050 | ||
11051 | if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0) | |
11052 | { | |
11053 | /* Get the build-id of file. */ | |
11054 | build_id = get_build_id (file); | |
11055 | build_id_len = 0; | |
11056 | } | |
11057 | else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0) | |
11058 | { | |
11059 | /* Get the build-id of the debugaltlink file. */ | |
11060 | unsigned int filelen; | |
11061 | ||
11062 | filelen = strnlen ((const char *)section->start, section->size); | |
11063 | if (filelen == section->size) | |
11064 | /* Corrupt debugaltlink. */ | |
015dc7e1 | 11065 | return false; |
301a9420 AM |
11066 | |
11067 | build_id = section->start + filelen + 1; | |
11068 | build_id_len = section->size - (filelen + 1); | |
11069 | ||
11070 | if (build_id_len == 0) | |
015dc7e1 | 11071 | return false; |
301a9420 AM |
11072 | } |
11073 | else | |
015dc7e1 | 11074 | return false; |
301a9420 AM |
11075 | |
11076 | if (build_id) | |
11077 | { | |
11078 | int fd; | |
11079 | debuginfod_client * client; | |
11080 | ||
11081 | client = debuginfod_begin (); | |
11082 | if (client == NULL) | |
015dc7e1 | 11083 | return false; |
301a9420 AM |
11084 | |
11085 | /* Query debuginfod servers for the target file. If found its path | |
11086 | will be stored in filename. */ | |
11087 | fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename); | |
11088 | debuginfod_end (client); | |
11089 | ||
11090 | /* Only free build_id if we allocated space for a hex string | |
11091 | in get_build_id (). */ | |
11092 | if (build_id_len == 0) | |
11093 | free (build_id); | |
11094 | ||
11095 | if (fd >= 0) | |
11096 | { | |
11097 | /* File successfully retrieved. Close fd since we want to | |
11098 | use open_debug_file () on filename instead. */ | |
11099 | close (fd); | |
015dc7e1 | 11100 | return true; |
301a9420 AM |
11101 | } |
11102 | } | |
11103 | ||
015dc7e1 | 11104 | return false; |
301a9420 AM |
11105 | } |
11106 | #endif | |
11107 | ||
dda8d76d NC |
11108 | static void * |
11109 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 11110 | struct dwarf_section * xlink, |
dda8d76d NC |
11111 | parse_func_type parse_func, |
11112 | check_func_type check_func, | |
301a9420 AM |
11113 | void * func_data, |
11114 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
11115 | { |
11116 | const char * separate_filename; | |
24841daa | 11117 | char * debug_filename; |
dda8d76d NC |
11118 | char * canon_dir; |
11119 | size_t canon_dirlen; | |
11120 | size_t dirlen; | |
11121 | ||
2b63c337 | 11122 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
11123 | { |
11124 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 11125 | xlink->name ? xlink->name : xlink->uncompressed_name); |
ce139cd5 | 11126 | return NULL; |
dda8d76d | 11127 | } |
521d4b19 | 11128 | |
dda8d76d NC |
11129 | /* Attempt to locate the separate file. |
11130 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
11131 | ||
11132 | canon_dir = lrealpath (main_filename); | |
521d4b19 | 11133 | |
dda8d76d NC |
11134 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) |
11135 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
11136 | break; | |
11137 | canon_dir[canon_dirlen] = '\0'; | |
11138 | ||
11139 | #ifndef DEBUGDIR | |
11140 | #define DEBUGDIR "/lib/debug" | |
11141 | #endif | |
11142 | #ifndef EXTRA_DEBUG_ROOT1 | |
11143 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
11144 | #endif | |
11145 | #ifndef EXTRA_DEBUG_ROOT2 | |
11146 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
11147 | #endif | |
11148 | ||
24841daa NC |
11149 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
11150 | + canon_dirlen | |
11151 | + strlen (".debug/") | |
dda8d76d | 11152 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 11153 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
11154 | #endif |
11155 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 11156 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 11157 | #endif |
24841daa NC |
11158 | + strlen (separate_filename) |
11159 | + 1); | |
11160 | if (debug_filename == NULL) | |
dda8d76d NC |
11161 | { |
11162 | warn (_("Out of memory")); | |
3391569f | 11163 | free (canon_dir); |
dda8d76d NC |
11164 | return NULL; |
11165 | } | |
11166 | ||
11167 | /* First try in the current directory. */ | |
24841daa NC |
11168 | sprintf (debug_filename, "%s", separate_filename); |
11169 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11170 | goto found; |
11171 | ||
11172 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
11173 | sprintf (debug_filename, ".debug/%s", separate_filename); |
11174 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11175 | goto found; |
11176 | ||
11177 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
11178 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
11179 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11180 | goto found; |
11181 | ||
11182 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
11183 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
11184 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11185 | goto found; |
11186 | ||
11187 | #ifdef EXTRA_DEBUG_ROOT1 | |
11188 | /* Try the first extra debug file root. */ | |
24841daa NC |
11189 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
11190 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 11191 | goto found; |
39f0547e NC |
11192 | |
11193 | /* Try the first extra debug file root. */ | |
11194 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
11195 | if (check_func (debug_filename, func_data)) | |
11196 | goto found; | |
dda8d76d NC |
11197 | #endif |
11198 | ||
11199 | #ifdef EXTRA_DEBUG_ROOT2 | |
11200 | /* Try the second extra debug file root. */ | |
24841daa NC |
11201 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
11202 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11203 | goto found; |
11204 | #endif | |
11205 | ||
24841daa NC |
11206 | /* Then try in the global debug_filename directory. */ |
11207 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
11208 | dirlen = strlen (DEBUGDIR) - 1; |
11209 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
11210 | strcat (debug_filename, "/"); |
11211 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 11212 | |
24841daa | 11213 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
11214 | goto found; |
11215 | ||
301a9420 AM |
11216 | #if HAVE_LIBDEBUGINFOD |
11217 | { | |
11218 | char * tmp_filename; | |
11219 | ||
11220 | if (debuginfod_fetch_separate_debug_info (xlink, | |
11221 | & tmp_filename, | |
11222 | file)) | |
11223 | { | |
11224 | /* File successfully downloaded from server, replace | |
11225 | debug_filename with the file's path. */ | |
11226 | free (debug_filename); | |
11227 | debug_filename = tmp_filename; | |
11228 | goto found; | |
11229 | } | |
11230 | } | |
11231 | #endif | |
11232 | ||
ecd65684 L |
11233 | if (do_debug_links) |
11234 | { | |
11235 | /* Failed to find the file. */ | |
11236 | warn (_("could not find separate debug file '%s'\n"), | |
11237 | separate_filename); | |
11238 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
11239 | |
11240 | #ifdef EXTRA_DEBUG_ROOT2 | |
ecd65684 L |
11241 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, |
11242 | separate_filename); | |
11243 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
11244 | #endif |
11245 | ||
11246 | #ifdef EXTRA_DEBUG_ROOT1 | |
ecd65684 L |
11247 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, |
11248 | canon_dir, separate_filename); | |
11249 | warn (_("tried: %s\n"), debug_filename); | |
39f0547e | 11250 | |
ecd65684 L |
11251 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, |
11252 | separate_filename); | |
11253 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
11254 | #endif |
11255 | ||
ecd65684 L |
11256 | sprintf (debug_filename, "%s.debug/%s", canon_dir, |
11257 | separate_filename); | |
11258 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11259 | |
ecd65684 L |
11260 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
11261 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11262 | |
ecd65684 L |
11263 | sprintf (debug_filename, ".debug/%s", separate_filename); |
11264 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11265 | |
ecd65684 L |
11266 | sprintf (debug_filename, "%s", separate_filename); |
11267 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11268 | |
301a9420 | 11269 | #if HAVE_LIBDEBUGINFOD |
ecd65684 L |
11270 | { |
11271 | char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR); | |
11272 | if (urls == NULL) | |
11273 | urls = ""; | |
301a9420 | 11274 | |
ecd65684 L |
11275 | warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls); |
11276 | } | |
301a9420 | 11277 | #endif |
ecd65684 | 11278 | } |
301a9420 | 11279 | |
dda8d76d | 11280 | free (canon_dir); |
24841daa | 11281 | free (debug_filename); |
dda8d76d NC |
11282 | return NULL; |
11283 | ||
11284 | found: | |
11285 | free (canon_dir); | |
11286 | ||
24841daa NC |
11287 | void * debug_handle; |
11288 | ||
dda8d76d | 11289 | /* Now open the file.... */ |
24841daa | 11290 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 11291 | { |
24841daa NC |
11292 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
11293 | free (debug_filename); | |
ce139cd5 | 11294 | return NULL; |
dda8d76d NC |
11295 | } |
11296 | ||
11297 | /* FIXME: We do not check to see if there are any other separate debug info | |
11298 | files that would also match. */ | |
11299 | ||
ca0e11aa NC |
11300 | if (do_debug_links) |
11301 | printf (_("\n%s: Found separate debug info file: %s\n"), main_filename, debug_filename); | |
24841daa | 11302 | add_separate_debug_file (debug_filename, debug_handle); |
dda8d76d | 11303 | |
24841daa | 11304 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 11305 | the structure returned by open_debug_file(). */ |
24841daa | 11306 | return debug_handle; |
dda8d76d NC |
11307 | } |
11308 | ||
d85bf2ba NC |
11309 | /* Attempt to load a separate dwarf object file. */ |
11310 | ||
11311 | static void * | |
24841daa | 11312 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 11313 | { |
24841daa NC |
11314 | char * separate_filename; |
11315 | void * separate_handle; | |
d85bf2ba | 11316 | |
d9d9d8ef TV |
11317 | if (IS_ABSOLUTE_PATH (name)) |
11318 | separate_filename = strdup (name); | |
11319 | else | |
11320 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
11321 | separate_filename = concat (dir, "/", name, NULL); | |
24841daa | 11322 | if (separate_filename == NULL) |
d85bf2ba NC |
11323 | { |
11324 | warn (_("Out of memory allocating dwo filename\n")); | |
11325 | return NULL; | |
11326 | } | |
11327 | ||
24841daa | 11328 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 11329 | { |
24841daa NC |
11330 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
11331 | free (separate_filename); | |
d85bf2ba NC |
11332 | return NULL; |
11333 | } | |
11334 | ||
11335 | /* FIXME: We should check the dwo_id. */ | |
11336 | ||
24841daa | 11337 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
bfbfa6e7 | 11338 | |
24841daa NC |
11339 | add_separate_debug_file (separate_filename, separate_handle); |
11340 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
11341 | return separate_handle; | |
d85bf2ba NC |
11342 | } |
11343 | ||
e38332c2 NC |
11344 | static void |
11345 | load_debug_sup_file (const char * main_filename, void * file) | |
11346 | { | |
11347 | if (! load_debug_section (debug_sup, file)) | |
11348 | return; /* No .debug_sup section. */ | |
11349 | ||
11350 | struct dwarf_section * section; | |
11351 | section = & debug_displays [debug_sup].section; | |
11352 | assert (section != NULL); | |
11353 | ||
11354 | if (section->start == NULL || section->size < 5) | |
11355 | { | |
11356 | warn (_(".debug_sup section is corrupt/empty\n")); | |
11357 | return; | |
11358 | } | |
11359 | ||
11360 | if (section->start[2] != 0) | |
11361 | return; /* This is a supplementary file. */ | |
11362 | ||
11363 | const char * filename = (const char *) section->start + 3; | |
11364 | if (strnlen (filename, section->size - 3) == section->size - 3) | |
11365 | { | |
11366 | warn (_("filename in .debug_sup section is corrupt\n")); | |
11367 | return; | |
11368 | } | |
11369 | ||
11370 | if (filename[0] != '/' && strchr (main_filename, '/')) | |
11371 | { | |
11372 | char * new_name; | |
bfbfa6e7 NC |
11373 | int new_len; |
11374 | ||
11375 | new_len = asprintf (& new_name, "%.*s/%s", | |
11376 | (int) (strrchr (main_filename, '/') - main_filename), | |
11377 | main_filename, | |
11378 | filename); | |
11379 | if (new_len < 3) | |
11380 | { | |
11381 | warn (_("unable to construct path for supplementary debug file")); | |
11382 | if (new_len > -1) | |
11383 | free (new_name); | |
11384 | return; | |
11385 | } | |
11386 | filename = new_name; | |
11387 | } | |
11388 | else | |
11389 | { | |
11390 | /* PR 27796: Make sure that we pass a filename that can be free'd to | |
11391 | add_separate_debug_file(). */ | |
11392 | filename = strdup (filename); | |
11393 | if (filename == NULL) | |
11394 | { | |
11395 | warn (_("out of memory constructing filename for .debug_sup link\n")); | |
11396 | return; | |
11397 | } | |
e38332c2 NC |
11398 | } |
11399 | ||
bfbfa6e7 | 11400 | void * handle = open_debug_file (filename); |
e38332c2 NC |
11401 | if (handle == NULL) |
11402 | { | |
11403 | warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename); | |
bfbfa6e7 | 11404 | free ((void *) filename); |
e38332c2 NC |
11405 | return; |
11406 | } | |
11407 | ||
11408 | printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename, filename); | |
11409 | ||
11410 | /* FIXME: Compare the checksums, if present. */ | |
11411 | add_separate_debug_file (filename, handle); | |
11412 | } | |
11413 | ||
ce139cd5 NC |
11414 | /* Load a debuglink section and/or a debugaltlink section, if either are present. |
11415 | Recursively check the loaded files for more of these sections. | |
e38332c2 NC |
11416 | Also follow any links in .debug_sup sections. |
11417 | FIXME: Should also check for DWO_* entries in the newly loaded files. */ | |
ce139cd5 NC |
11418 | |
11419 | static void | |
11420 | check_for_and_load_links (void * file, const char * filename) | |
11421 | { | |
11422 | void * handle = NULL; | |
11423 | ||
11424 | if (load_debug_section (gnu_debugaltlink, file)) | |
11425 | { | |
11426 | Build_id_data build_id_data; | |
11427 | ||
11428 | handle = load_separate_debug_info (filename, | |
11429 | & debug_displays[gnu_debugaltlink].section, | |
11430 | parse_gnu_debugaltlink, | |
11431 | check_gnu_debugaltlink, | |
11432 | & build_id_data, | |
11433 | file); | |
11434 | if (handle) | |
11435 | { | |
11436 | assert (handle == first_separate_info->handle); | |
11437 | check_for_and_load_links (first_separate_info->handle, | |
11438 | first_separate_info->filename); | |
11439 | } | |
11440 | } | |
11441 | ||
11442 | if (load_debug_section (gnu_debuglink, file)) | |
11443 | { | |
11444 | unsigned long crc32; | |
11445 | ||
11446 | handle = load_separate_debug_info (filename, | |
11447 | & debug_displays[gnu_debuglink].section, | |
11448 | parse_gnu_debuglink, | |
11449 | check_gnu_debuglink, | |
11450 | & crc32, | |
11451 | file); | |
11452 | if (handle) | |
11453 | { | |
11454 | assert (handle == first_separate_info->handle); | |
11455 | check_for_and_load_links (first_separate_info->handle, | |
11456 | first_separate_info->filename); | |
11457 | } | |
11458 | } | |
e38332c2 NC |
11459 | |
11460 | load_debug_sup_file (filename, file); | |
ce139cd5 NC |
11461 | } |
11462 | ||
24841daa NC |
11463 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
11464 | Returns TRUE if any were found, FALSE otherwise. | |
11465 | If TRUE is returned then the linked list starting at first_separate_info | |
11466 | will be populated with open file handles. */ | |
dda8d76d | 11467 | |
015dc7e1 | 11468 | bool |
24841daa | 11469 | load_separate_debug_files (void * file, const char * filename) |
dda8d76d | 11470 | { |
8de3a6e2 NC |
11471 | /* Skip this operation if we are not interested in debug links. */ |
11472 | if (! do_follow_links && ! do_debug_links) | |
015dc7e1 | 11473 | return false; |
8de3a6e2 | 11474 | |
24841daa | 11475 | /* See if there are any dwo links. */ |
d85bf2ba NC |
11476 | if (load_debug_section (str, file) |
11477 | && load_debug_section (abbrev, file) | |
11478 | && load_debug_section (info, file)) | |
11479 | { | |
24841daa | 11480 | free_dwo_info (); |
d85bf2ba | 11481 | |
50ea0877 | 11482 | if (process_debug_info (& debug_displays[info].section, file, abbrev, |
015dc7e1 | 11483 | true, false)) |
d85bf2ba | 11484 | { |
015dc7e1 AM |
11485 | bool introduced = false; |
11486 | dwo_info *dwinfo; | |
11487 | const char *dir = NULL; | |
11488 | const char *id = NULL; | |
11489 | const char *name = NULL; | |
24841daa NC |
11490 | |
11491 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 11492 | { |
50ea0877 | 11493 | /* Accumulate NAME, DIR and ID fields. */ |
24841daa | 11494 | switch (dwinfo->type) |
d85bf2ba | 11495 | { |
24841daa | 11496 | case DWO_NAME: |
50ea0877 NC |
11497 | if (name != NULL) |
11498 | warn (_("Multiple DWO_NAMEs encountered for the same CU\n")); | |
11499 | name = dwinfo->value; | |
11500 | break; | |
11501 | ||
11502 | case DWO_DIR: | |
11503 | /* There can be multiple DW_AT_comp_dir entries in a CU, | |
11504 | so do not complain. */ | |
11505 | dir = dwinfo->value; | |
11506 | break; | |
11507 | ||
11508 | case DWO_ID: | |
11509 | if (id != NULL) | |
11510 | warn (_("multiple DWO_IDs encountered for the same CU\n")); | |
11511 | id = dwinfo->value; | |
11512 | break; | |
11513 | ||
11514 | default: | |
11515 | error (_("Unexpected DWO INFO type")); | |
11516 | break; | |
11517 | } | |
11518 | ||
11519 | /* If we have reached the end of our list, or we are changing | |
11520 | CUs, then display the information that we have accumulated | |
11521 | so far. */ | |
11522 | if (name != NULL | |
11523 | && (dwinfo->next == NULL | |
11524 | || dwinfo->next->cu_offset != dwinfo->cu_offset)) | |
11525 | { | |
24841daa NC |
11526 | if (do_debug_links) |
11527 | { | |
11528 | if (! introduced) | |
11529 | { | |
11530 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
11531 | debug_displays [info].section.uncompressed_name); | |
015dc7e1 | 11532 | introduced = true; |
24841daa | 11533 | } |
d85bf2ba | 11534 | |
50ea0877 | 11535 | printf (_(" Name: %s\n"), name); |
24841daa NC |
11536 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); |
11537 | if (id != NULL) | |
11538 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
11539 | else | |
50ea0877 | 11540 | printf (_(" ID: <not specified>\n")); |
24841daa NC |
11541 | printf ("\n\n"); |
11542 | } | |
11543 | ||
11544 | if (do_follow_links) | |
50ea0877 | 11545 | load_dwo_file (filename, name, dir, id); |
24841daa | 11546 | |
50ea0877 | 11547 | name = dir = id = NULL; |
24841daa | 11548 | } |
d85bf2ba NC |
11549 | } |
11550 | } | |
11551 | } | |
11552 | ||
dda8d76d | 11553 | if (! do_follow_links) |
8de3a6e2 NC |
11554 | /* The other debug links will be displayed by display_debug_links() |
11555 | so we do not need to do any further processing here. */ | |
015dc7e1 | 11556 | return false; |
dda8d76d NC |
11557 | |
11558 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
dda8d76d | 11559 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ |
d85bf2ba | 11560 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 11561 | |
ce139cd5 | 11562 | check_for_and_load_links (file, filename); |
24841daa | 11563 | if (first_separate_info != NULL) |
015dc7e1 | 11564 | return true; |
24841daa | 11565 | |
dda8d76d | 11566 | do_follow_links = 0; |
015dc7e1 | 11567 | return false; |
521d4b19 | 11568 | } |
dda8d76d | 11569 | |
19e6b90e L |
11570 | void |
11571 | free_debug_memory (void) | |
11572 | { | |
3f5e193b | 11573 | unsigned int i; |
19e6b90e | 11574 | |
bcd213b2 | 11575 | free_all_abbrevs (); |
19e6b90e | 11576 | |
bcd213b2 NC |
11577 | free (cu_abbrev_map); |
11578 | cu_abbrev_map = NULL; | |
11579 | next_free_abbrev_map_entry = 0; | |
521d4b19 | 11580 | |
288f0ba2 AM |
11581 | free (shndx_pool); |
11582 | shndx_pool = NULL; | |
11583 | shndx_pool_size = 0; | |
11584 | shndx_pool_used = 0; | |
11585 | free (cu_sets); | |
11586 | cu_sets = NULL; | |
11587 | cu_count = 0; | |
11588 | free (tu_sets); | |
11589 | tu_sets = NULL; | |
11590 | tu_count = 0; | |
11591 | ||
11592 | memset (level_type_signed, 0, sizeof level_type_signed); | |
11593 | cu_tu_indexes_read = -1; | |
11594 | ||
19e6b90e | 11595 | for (i = 0; i < max; i++) |
3f5e193b | 11596 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 11597 | |
cc86f28f | 11598 | if (debug_information != NULL) |
19e6b90e | 11599 | { |
82fcdb39 | 11600 | for (i = 0; i < alloc_num_debug_info_entries; i++) |
19e6b90e | 11601 | { |
82fcdb39 | 11602 | if (debug_information [i].max_loc_offsets) |
19e6b90e | 11603 | { |
82fcdb39 AM |
11604 | free (debug_information [i].loc_offsets); |
11605 | free (debug_information [i].have_frame_base); | |
19e6b90e | 11606 | } |
82fcdb39 AM |
11607 | if (debug_information [i].max_range_lists) |
11608 | free (debug_information [i].range_lists); | |
19e6b90e L |
11609 | } |
11610 | free (debug_information); | |
11611 | debug_information = NULL; | |
82b1b41b | 11612 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 11613 | } |
dda8d76d | 11614 | |
24841daa NC |
11615 | separate_info * d; |
11616 | separate_info * next; | |
dda8d76d | 11617 | |
24841daa NC |
11618 | for (d = first_separate_info; d != NULL; d = next) |
11619 | { | |
11620 | close_debug_file (d->handle); | |
11621 | free ((void *) d->filename); | |
11622 | next = d->next; | |
11623 | free ((void *) d); | |
dda8d76d | 11624 | } |
24841daa | 11625 | first_separate_info = NULL; |
521d4b19 | 11626 | |
24841daa | 11627 | free_dwo_info (); |
19e6b90e L |
11628 | } |
11629 | ||
4cb93e3b TG |
11630 | void |
11631 | dwarf_select_sections_by_names (const char *names) | |
11632 | { | |
11633 | typedef struct | |
11634 | { | |
11635 | const char * option; | |
11636 | int * variable; | |
f9f0e732 | 11637 | int val; |
4cb93e3b TG |
11638 | } |
11639 | debug_dump_long_opts; | |
11640 | ||
11641 | static const debug_dump_long_opts opts_table [] = | |
11642 | { | |
11643 | /* Please keep this table alpha- sorted. */ | |
11644 | { "Ranges", & do_debug_ranges, 1 }, | |
11645 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 11646 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 11647 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
11648 | { "cu_index", & do_debug_cu_index, 1 }, |
11649 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 11650 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
11651 | { "frames", & do_debug_frames, 1 }, |
11652 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
11653 | /* The special .gdb_index section. */ |
11654 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
11655 | { "info", & do_debug_info, 1 }, |
11656 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 11657 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
11658 | { "loc", & do_debug_loc, 1 }, |
11659 | { "macro", & do_debug_macinfo, 1 }, | |
c46b7066 | 11660 | { "no-follow-links", & do_follow_links, 0 }, |
4cb93e3b | 11661 | { "pubnames", & do_debug_pubnames, 1 }, |
357da287 | 11662 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 11663 | /* This entry is for compatibility |
4cb93e3b TG |
11664 | with earlier versions of readelf. */ |
11665 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 11666 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 11667 | { "str", & do_debug_str, 1 }, |
e4b7104b | 11668 | { "str-offsets", & do_debug_str_offsets, 1 }, |
6f875884 TG |
11669 | /* These trace_* sections are used by Itanium VMS. */ |
11670 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
11671 | { "trace_aranges", & do_trace_aranges, 1 }, | |
11672 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
11673 | { NULL, NULL, 0 } |
11674 | }; | |
11675 | ||
11676 | const char *p; | |
467c65bc | 11677 | |
4cb93e3b TG |
11678 | p = names; |
11679 | while (*p) | |
11680 | { | |
11681 | const debug_dump_long_opts * entry; | |
467c65bc | 11682 | |
4cb93e3b TG |
11683 | for (entry = opts_table; entry->option; entry++) |
11684 | { | |
11685 | size_t len = strlen (entry->option); | |
467c65bc | 11686 | |
4cb93e3b TG |
11687 | if (strncmp (p, entry->option, len) == 0 |
11688 | && (p[len] == ',' || p[len] == '\0')) | |
11689 | { | |
c46b7066 | 11690 | * entry->variable = entry->val; |
467c65bc | 11691 | |
4cb93e3b TG |
11692 | /* The --debug-dump=frames-interp option also |
11693 | enables the --debug-dump=frames option. */ | |
11694 | if (do_debug_frames_interp) | |
11695 | do_debug_frames = 1; | |
11696 | ||
11697 | p += len; | |
11698 | break; | |
11699 | } | |
11700 | } | |
467c65bc | 11701 | |
4cb93e3b TG |
11702 | if (entry->option == NULL) |
11703 | { | |
11704 | warn (_("Unrecognized debug option '%s'\n"), p); | |
11705 | p = strchr (p, ','); | |
11706 | if (p == NULL) | |
11707 | break; | |
11708 | } | |
467c65bc | 11709 | |
4cb93e3b TG |
11710 | if (*p == ',') |
11711 | p++; | |
11712 | } | |
11713 | } | |
11714 | ||
11715 | void | |
11716 | dwarf_select_sections_by_letters (const char *letters) | |
11717 | { | |
91d6fa6a | 11718 | unsigned int lindex = 0; |
4cb93e3b | 11719 | |
91d6fa6a NC |
11720 | while (letters[lindex]) |
11721 | switch (letters[lindex++]) | |
4cb93e3b | 11722 | { |
dda8d76d NC |
11723 | case 'A': do_debug_addr = 1; break; |
11724 | case 'a': do_debug_abbrevs = 1; break; | |
11725 | case 'c': do_debug_cu_index = 1; break; | |
11726 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
11727 | case 'f': do_debug_frames = 1; break; | |
11728 | case 'g': do_gdb_index = 1; break; | |
11729 | case 'i': do_debug_info = 1; break; | |
11730 | case 'K': do_follow_links = 1; break; | |
c46b7066 | 11731 | case 'N': do_follow_links = 0; break; |
dda8d76d NC |
11732 | case 'k': do_debug_links = 1; break; |
11733 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
11734 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
11735 | case 'm': do_debug_macinfo = 1; break; | |
e4b7104b | 11736 | case 'O': do_debug_str_offsets = 1; break; |
dda8d76d NC |
11737 | case 'o': do_debug_loc = 1; break; |
11738 | case 'p': do_debug_pubnames = 1; break; | |
11739 | case 'R': do_debug_ranges = 1; break; | |
11740 | case 'r': do_debug_aranges = 1; break; | |
11741 | case 's': do_debug_str = 1; break; | |
11742 | case 'T': do_trace_aranges = 1; break; | |
11743 | case 't': do_debug_pubtypes = 1; break; | |
11744 | case 'U': do_trace_info = 1; break; | |
11745 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 11746 | |
4cb93e3b | 11747 | default: |
7cc78d07 | 11748 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
11749 | break; |
11750 | } | |
11751 | } | |
11752 | ||
11753 | void | |
11754 | dwarf_select_sections_all (void) | |
11755 | { | |
11756 | do_debug_info = 1; | |
11757 | do_debug_abbrevs = 1; | |
11758 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
11759 | do_debug_pubnames = 1; | |
f9f0e732 | 11760 | do_debug_pubtypes = 1; |
4cb93e3b TG |
11761 | do_debug_aranges = 1; |
11762 | do_debug_ranges = 1; | |
11763 | do_debug_frames = 1; | |
11764 | do_debug_macinfo = 1; | |
11765 | do_debug_str = 1; | |
11766 | do_debug_loc = 1; | |
5bbdf3d5 | 11767 | do_gdb_index = 1; |
6f875884 TG |
11768 | do_trace_info = 1; |
11769 | do_trace_abbrevs = 1; | |
11770 | do_trace_aranges = 1; | |
657d0d47 CC |
11771 | do_debug_addr = 1; |
11772 | do_debug_cu_index = 1; | |
dda8d76d NC |
11773 | do_follow_links = 1; |
11774 | do_debug_links = 1; | |
e4b7104b | 11775 | do_debug_str_offsets = 1; |
4cb93e3b TG |
11776 | } |
11777 | ||
208599d9 AM |
11778 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0 |
11779 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0 | |
dda8d76d NC |
11780 | |
11781 | /* N.B. The order here must match the order in section_display_enum. */ | |
11782 | ||
19e6b90e L |
11783 | struct dwarf_section_display debug_displays[] = |
11784 | { | |
015dc7e1 AM |
11785 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false }, |
11786 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, true }, | |
11787 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true }, | |
11788 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, true }, | |
11789 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true }, | |
11790 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, false }, | |
11791 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, false }, | |
11792 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true }, | |
11793 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false }, | |
11794 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true }, | |
11795 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, | |
11796 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, | |
11797 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
11798 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
11799 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, false }, | |
11800 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, false }, | |
11801 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, | |
11802 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true }, | |
11803 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
11804 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
11805 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, true }, | |
11806 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, false }, | |
11807 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, false }, | |
11808 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, false }, | |
11809 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, true }, | |
11810 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, false }, | |
11811 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, false }, | |
11812 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, true }, | |
11813 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false }, | |
11814 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, true }, | |
11815 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true }, | |
11816 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true }, | |
11817 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true }, | |
11818 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false }, | |
11819 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, true }, | |
11820 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true }, | |
11821 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true }, | |
11822 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, true }, | |
11823 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false }, | |
11824 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false }, | |
11825 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false }, | |
11826 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false }, | |
11827 | { { ".debug_sup", "", NO_ABBREVS }, display_debug_sup, &do_debug_links, false }, | |
dda8d76d NC |
11828 | /* Separate debug info files can containt their own .debug_str section, |
11829 | and this might be in *addition* to a .debug_str section already present | |
11830 | in the main file. Hence we need to have two entries for .debug_str. */ | |
015dc7e1 | 11831 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, false }, |
19e6b90e | 11832 | }; |
b451e98a JK |
11833 | |
11834 | /* A static assertion. */ | |
11835 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |