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" |
5bbdf3d5 | 24 | #include "bfd_stdint.h" |
3db64b00 | 25 | #include "bucomm.h" |
3284fe0c | 26 | #include "elfcomm.h" |
2dc4cec1 | 27 | #include "elf/common.h" |
fa8f86ff | 28 | #include "dwarf2.h" |
3db64b00 | 29 | #include "dwarf.h" |
8d6eee87 | 30 | #include "gdb/gdb-index.h" |
dda8d76d | 31 | #include "filenames.h" |
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 AM |
39 | #ifdef HAVE_LIMITS_H |
40 | #include <limits.h> | |
41 | #endif | |
42 | #ifndef CHAR_BIT | |
43 | #define CHAR_BIT 8 | |
44 | #endif | |
45 | ||
61364358 JK |
46 | #undef MAX |
47 | #undef MIN | |
48 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) | |
49 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | |
19e6b90e | 50 | |
18464d4d | 51 | static const char *regname (unsigned int regno, int row); |
1296bc99 | 52 | static const char *regname_internal_by_table_only (unsigned int regno); |
18464d4d | 53 | |
19e6b90e L |
54 | static int have_frame_base; |
55 | static int need_base_address; | |
56 | ||
19e6b90e | 57 | static unsigned int num_debug_info_entries = 0; |
82b1b41b | 58 | static unsigned int alloc_num_debug_info_entries = 0; |
19e6b90e | 59 | static debug_info *debug_information = NULL; |
cc86f28f NC |
60 | /* Special value for num_debug_info_entries to indicate |
61 | that the .debug_info section could not be loaded/parsed. */ | |
62 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 | |
19e6b90e | 63 | |
24841daa NC |
64 | /* A .debug_info section can contain multiple links to separate |
65 | DWO object files. We use these structures to record these links. */ | |
66 | typedef enum dwo_type | |
67 | { | |
68 | DWO_NAME, | |
69 | DWO_DIR, | |
70 | DWO_ID | |
71 | } dwo_type; | |
72 | ||
73 | typedef struct dwo_info | |
74 | { | |
75 | dwo_type type; | |
76 | const char * value; | |
50ea0877 | 77 | dwarf_vma cu_offset; |
24841daa NC |
78 | struct dwo_info * next; |
79 | } dwo_info; | |
80 | ||
81 | static dwo_info * first_dwo_info = NULL; | |
82 | static bfd_boolean need_dwo_info; | |
83 | ||
84 | separate_info * first_separate_info = NULL; | |
d85bf2ba | 85 | |
77ef8654 | 86 | unsigned int eh_addr_size; |
19e6b90e L |
87 | |
88 | int do_debug_info; | |
89 | int do_debug_abbrevs; | |
90 | int do_debug_lines; | |
91 | int do_debug_pubnames; | |
f9f0e732 | 92 | int do_debug_pubtypes; |
19e6b90e L |
93 | int do_debug_aranges; |
94 | int do_debug_ranges; | |
95 | int do_debug_frames; | |
96 | int do_debug_frames_interp; | |
97 | int do_debug_macinfo; | |
98 | int do_debug_str; | |
e4b7104b | 99 | int do_debug_str_offsets; |
19e6b90e | 100 | int do_debug_loc; |
5bbdf3d5 | 101 | int do_gdb_index; |
6f875884 TG |
102 | int do_trace_info; |
103 | int do_trace_abbrevs; | |
104 | int do_trace_aranges; | |
657d0d47 CC |
105 | int do_debug_addr; |
106 | int do_debug_cu_index; | |
a262ae96 | 107 | int do_wide; |
dda8d76d | 108 | int do_debug_links; |
c46b7066 | 109 | int do_follow_links = DEFAULT_FOR_FOLLOW_LINKS; |
546cb2d8 | 110 | bfd_boolean do_checks; |
19e6b90e | 111 | |
fd2f0033 TT |
112 | int dwarf_cutoff_level = -1; |
113 | unsigned long dwarf_start_die; | |
114 | ||
4723351a CC |
115 | int dwarf_check = 0; |
116 | ||
9f272209 AO |
117 | /* Convenient constant, to avoid having to cast -1 to dwarf_vma when |
118 | testing whether e.g. a locview list is present. */ | |
119 | static const dwarf_vma vm1 = -1; | |
120 | ||
341f9135 CC |
121 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
122 | sections. For version 1 package files, each set is stored in SHNDX_POOL | |
123 | as a zero-terminated list of section indexes comprising one set of debug | |
124 | sections from a .dwo file. */ | |
125 | ||
341f9135 CC |
126 | static unsigned int *shndx_pool = NULL; |
127 | static unsigned int shndx_pool_size = 0; | |
128 | static unsigned int shndx_pool_used = 0; | |
129 | ||
130 | /* For version 2 package files, each set contains an array of section offsets | |
131 | and an array of section sizes, giving the offset and size of the | |
132 | contribution from a CU or TU within one of the debug sections. | |
133 | When displaying debug info from a package file, we need to use these | |
134 | tables to locate the corresponding contributions to each section. */ | |
135 | ||
136 | struct cu_tu_set | |
137 | { | |
ec1b0fbb NC |
138 | uint64_t signature; |
139 | dwarf_vma section_offsets[DW_SECT_MAX]; | |
140 | size_t section_sizes[DW_SECT_MAX]; | |
341f9135 CC |
141 | }; |
142 | ||
143 | static int cu_count = 0; | |
144 | static int tu_count = 0; | |
145 | static struct cu_tu_set *cu_sets = NULL; | |
146 | static struct cu_tu_set *tu_sets = NULL; | |
147 | ||
43a444f9 | 148 | static bfd_boolean load_cu_tu_indexes (void *); |
341f9135 | 149 | |
ec1b0fbb NC |
150 | /* An array that indicates for a given level of CU nesting whether |
151 | the latest DW_AT_type seen for that level was a signed type or | |
152 | an unsigned type. */ | |
153 | #define MAX_CU_NESTING (1 << 8) | |
154 | static bfd_boolean level_type_signed[MAX_CU_NESTING]; | |
155 | ||
4cb93e3b TG |
156 | /* Values for do_debug_lines. */ |
157 | #define FLAG_DEBUG_LINES_RAW 1 | |
158 | #define FLAG_DEBUG_LINES_DECODED 2 | |
159 | ||
77ef8654 | 160 | static unsigned int |
f1c4cc75 RH |
161 | size_of_encoded_value (int encoding) |
162 | { | |
163 | switch (encoding & 0x7) | |
164 | { | |
165 | default: /* ??? */ | |
166 | case 0: return eh_addr_size; | |
167 | case 2: return 2; | |
168 | case 3: return 4; | |
169 | case 4: return 8; | |
170 | } | |
171 | } | |
172 | ||
173 | static dwarf_vma | |
041830e0 | 174 | get_encoded_value (unsigned char **pdata, |
bad62cf5 | 175 | int encoding, |
041830e0 NC |
176 | struct dwarf_section *section, |
177 | unsigned char * end) | |
f1c4cc75 | 178 | { |
041830e0 | 179 | unsigned char * data = * pdata; |
6937bb54 | 180 | unsigned int size = size_of_encoded_value (encoding); |
bad62cf5 | 181 | dwarf_vma val; |
f1c4cc75 | 182 | |
041830e0 NC |
183 | if (data + size >= end) |
184 | { | |
185 | warn (_("Encoded value extends past end of section\n")); | |
186 | * pdata = end; | |
187 | return 0; | |
188 | } | |
189 | ||
6937bb54 NC |
190 | /* PR 17512: file: 002-829853-0.004. */ |
191 | if (size > 8) | |
192 | { | |
193 | warn (_("Encoded size of %d is too large to read\n"), size); | |
194 | * pdata = end; | |
195 | return 0; | |
196 | } | |
197 | ||
0a9d414a NC |
198 | /* PR 17512: file: 1085-5603-0.004. */ |
199 | if (size == 0) | |
200 | { | |
201 | warn (_("Encoded size of 0 is too small to read\n")); | |
202 | * pdata = end; | |
203 | return 0; | |
204 | } | |
205 | ||
f1c4cc75 | 206 | if (encoding & DW_EH_PE_signed) |
bad62cf5 | 207 | val = byte_get_signed (data, size); |
f1c4cc75 | 208 | else |
bad62cf5 AM |
209 | val = byte_get (data, size); |
210 | ||
211 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
212 | val += section->address + (data - section->start); | |
041830e0 NC |
213 | |
214 | * pdata = data + size; | |
bad62cf5 | 215 | return val; |
f1c4cc75 RH |
216 | } |
217 | ||
4c219c2e AM |
218 | #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG |
219 | # ifndef __MINGW32__ | |
220 | # define DWARF_VMA_FMT "ll" | |
221 | # define DWARF_VMA_FMT_LONG "%16.16llx" | |
222 | # else | |
223 | # define DWARF_VMA_FMT "I64" | |
224 | # define DWARF_VMA_FMT_LONG "%016I64x" | |
225 | # endif | |
2e14fae2 | 226 | #else |
4c219c2e AM |
227 | # define DWARF_VMA_FMT "l" |
228 | # define DWARF_VMA_FMT_LONG "%16.16lx" | |
2d9472a2 NC |
229 | #endif |
230 | ||
bf5117e3 NC |
231 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
232 | buffer containing the converted VALUE. The value is converted according | |
233 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then | |
234 | it specifies the maximum number of bytes to be displayed in the converted | |
235 | value and FMTCH is ignored - hex is always used. */ | |
467c65bc | 236 | |
47704ddf | 237 | static const char * |
bf5117e3 | 238 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
47704ddf KT |
239 | { |
240 | /* As dwarf_vmatoa is used more then once in a printf call | |
241 | for output, we are cycling through an fixed array of pointers | |
242 | for return address. */ | |
243 | static int buf_pos = 0; | |
467c65bc NC |
244 | static struct dwarf_vmatoa_buf |
245 | { | |
47704ddf KT |
246 | char place[64]; |
247 | } buf[16]; | |
47704ddf KT |
248 | char *ret; |
249 | ||
47704ddf | 250 | ret = buf[buf_pos++].place; |
467c65bc | 251 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf | 252 | |
bf5117e3 NC |
253 | if (num_bytes) |
254 | { | |
222c2bf0 | 255 | /* Printf does not have a way of specifying a maximum field width for an |
bf5117e3 NC |
256 | integer value, so we print the full value into a buffer and then select |
257 | the precision we need. */ | |
258 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); | |
259 | if (num_bytes > 8) | |
260 | num_bytes = 8; | |
261 | return ret + (16 - 2 * num_bytes); | |
262 | } | |
263 | else | |
264 | { | |
265 | char fmt[32]; | |
266 | ||
0bae9e9e NC |
267 | if (fmtch) |
268 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); | |
269 | else | |
270 | sprintf (fmt, "%%%s", DWARF_VMA_FMT); | |
bf5117e3 NC |
271 | snprintf (ret, sizeof (buf[0].place), fmt, value); |
272 | return ret; | |
273 | } | |
274 | } | |
47704ddf | 275 | |
bf5117e3 NC |
276 | static inline const char * |
277 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) | |
278 | { | |
279 | return dwarf_vmatoa_1 (fmtch, value, 0); | |
280 | } | |
281 | ||
282 | /* Print a dwarf_vma value (typically an address, offset or length) in | |
283 | hexadecimal format, followed by a space. The length of the VALUE (and | |
284 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ | |
285 | ||
286 | static void | |
287 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) | |
288 | { | |
289 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); | |
47704ddf KT |
290 | } |
291 | ||
9f272209 AO |
292 | /* Print a view number in hexadecimal value, with the same width |
293 | print_dwarf_vma would have printed it with the same num_bytes. | |
294 | Print blanks for zero view, unless force is nonzero. */ | |
295 | ||
296 | static void | |
297 | print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force) | |
298 | { | |
299 | int len; | |
300 | if (!num_bytes) | |
301 | len = 4; | |
302 | else | |
303 | len = num_bytes * 2; | |
304 | ||
305 | assert (value == (unsigned long) value); | |
306 | if (value || force) | |
307 | printf ("v%0*lx ", len - 1, (unsigned long) value); | |
308 | else | |
309 | printf ("%*s", len + 1, ""); | |
310 | } | |
311 | ||
74bc6052 CC |
312 | /* Format a 64-bit value, given as two 32-bit values, in hex. |
313 | For reentrancy, this uses a buffer provided by the caller. */ | |
314 | ||
315 | static const char * | |
316 | dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, | |
317 | unsigned int buf_len) | |
318 | { | |
319 | int len = 0; | |
320 | ||
321 | if (hvalue == 0) | |
322 | snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); | |
323 | else | |
324 | { | |
325 | len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); | |
326 | snprintf (buf + len, buf_len - len, | |
327 | "%08" DWARF_VMA_FMT "x", lvalue); | |
328 | } | |
329 | ||
330 | return buf; | |
331 | } | |
332 | ||
f6f0e17b NC |
333 | /* Read in a LEB128 encoded value starting at address DATA. |
334 | If SIGN is true, return a signed LEB128 value. | |
335 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
b9b204b3 | 336 | If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the |
cd30bcef AM |
337 | terminating byte was not found and with bit 1 set if the value |
338 | overflows a dwarf_vma. | |
f6f0e17b NC |
339 | No bytes will be read at address END or beyond. */ |
340 | ||
467c65bc | 341 | dwarf_vma |
f6f0e17b | 342 | read_leb128 (unsigned char *data, |
cd30bcef | 343 | const unsigned char *const end, |
f6f0e17b | 344 | bfd_boolean sign, |
cd30bcef AM |
345 | unsigned int *length_return, |
346 | int *status_return) | |
19e6b90e | 347 | { |
467c65bc | 348 | dwarf_vma result = 0; |
19e6b90e L |
349 | unsigned int num_read = 0; |
350 | unsigned int shift = 0; | |
cd30bcef | 351 | int status = 1; |
19e6b90e | 352 | |
f6f0e17b | 353 | while (data < end) |
19e6b90e | 354 | { |
cd30bcef | 355 | unsigned char byte = *data++; |
b9b204b3 | 356 | unsigned char lost, mask; |
08d7da7d | 357 | |
19e6b90e L |
358 | num_read++; |
359 | ||
b9b204b3 | 360 | if (shift < CHAR_BIT * sizeof (result)) |
cd30bcef | 361 | { |
b9b204b3 AM |
362 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; |
363 | /* These bits overflowed. */ | |
364 | lost = byte ^ (result >> shift); | |
365 | /* And this is the mask of possible overflow bits. */ | |
366 | mask = 0x7f ^ ((dwarf_vma) 0x7f << shift >> shift); | |
cd30bcef AM |
367 | shift += 7; |
368 | } | |
b9b204b3 | 369 | else |
08d7da7d | 370 | { |
b9b204b3 AM |
371 | lost = byte; |
372 | mask = 0x7f; | |
08d7da7d | 373 | } |
b9b204b3 AM |
374 | if ((lost & mask) != (sign && (dwarf_signed_vma) result < 0 ? mask : 0)) |
375 | status |= 2; | |
19e6b90e | 376 | |
b9b204b3 | 377 | if ((byte & 0x80) == 0) |
cd30bcef AM |
378 | { |
379 | status &= ~1; | |
b9b204b3 | 380 | if (sign && shift < CHAR_BIT * sizeof (result) && (byte & 0x40)) |
cd30bcef AM |
381 | result |= -((dwarf_vma) 1 << shift); |
382 | break; | |
383 | } | |
19e6b90e | 384 | } |
19e6b90e L |
385 | |
386 | if (length_return != NULL) | |
387 | *length_return = num_read; | |
cd30bcef AM |
388 | if (status_return != NULL) |
389 | *status_return = status; | |
19e6b90e L |
390 | |
391 | return result; | |
392 | } | |
393 | ||
d11ae95e NC |
394 | /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value. |
395 | Checks to make sure that the read will not reach or pass END | |
396 | and that VAL is big enough to hold AMOUNT bytes. */ | |
0c588247 NC |
397 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
398 | do \ | |
399 | { \ | |
400 | unsigned int amount = (AMOUNT); \ | |
34b9f729 NC |
401 | if (sizeof (VAL) < amount) \ |
402 | { \ | |
d3a49aa8 AM |
403 | error (ngettext ("internal error: attempt to read %d byte " \ |
404 | "of data in to %d sized variable", \ | |
405 | "internal error: attempt to read %d bytes " \ | |
406 | "of data in to %d sized variable", \ | |
407 | amount), \ | |
34b9f729 NC |
408 | amount, (int) sizeof (VAL)); \ |
409 | amount = sizeof (VAL); \ | |
410 | } \ | |
0c588247 NC |
411 | if (((PTR) + amount) >= (END)) \ |
412 | { \ | |
413 | if ((PTR) < (END)) \ | |
414 | amount = (END) - (PTR); \ | |
415 | else \ | |
416 | amount = 0; \ | |
417 | } \ | |
6937bb54 | 418 | if (amount == 0 || amount > 8) \ |
0c588247 | 419 | VAL = 0; \ |
6937bb54 NC |
420 | else \ |
421 | VAL = byte_get ((PTR), amount); \ | |
0c588247 NC |
422 | } \ |
423 | while (0) | |
424 | ||
d11ae95e | 425 | /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
426 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
427 | do \ | |
428 | { \ | |
429 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
430 | PTR += AMOUNT; \ | |
431 | } \ | |
432 | while (0) | |
433 | ||
d11ae95e | 434 | /* Like SAFE_BYTE_GET, but reads a signed value. */ |
0c588247 NC |
435 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
436 | do \ | |
437 | { \ | |
438 | unsigned int amount = (AMOUNT); \ | |
439 | if (((PTR) + amount) >= (END)) \ | |
440 | { \ | |
441 | if ((PTR) < (END)) \ | |
442 | amount = (END) - (PTR); \ | |
443 | else \ | |
444 | amount = 0; \ | |
445 | } \ | |
446 | if (amount) \ | |
447 | VAL = byte_get_signed ((PTR), amount); \ | |
448 | else \ | |
449 | VAL = 0; \ | |
450 | } \ | |
451 | while (0) | |
452 | ||
d11ae95e | 453 | /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
454 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
455 | do \ | |
456 | { \ | |
457 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
458 | PTR += AMOUNT; \ | |
459 | } \ | |
460 | while (0) | |
461 | ||
462 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ | |
463 | do \ | |
464 | { \ | |
87bc83b3 | 465 | if (((PTR) + 8) <= (END)) \ |
0c588247 NC |
466 | { \ |
467 | byte_get_64 ((PTR), (HIGH), (LOW)); \ | |
468 | } \ | |
469 | else \ | |
470 | { \ | |
0c588247 NC |
471 | * (LOW) = * (HIGH) = 0; \ |
472 | } \ | |
473 | } \ | |
474 | while (0) | |
475 | ||
19e6b90e L |
476 | typedef struct State_Machine_Registers |
477 | { | |
467c65bc | 478 | dwarf_vma address; |
ba8826a8 | 479 | unsigned int view; |
19e6b90e L |
480 | unsigned int file; |
481 | unsigned int line; | |
482 | unsigned int column; | |
483 | int is_stmt; | |
484 | int basic_block; | |
a233b20c JJ |
485 | unsigned char op_index; |
486 | unsigned char end_sequence; | |
ba8826a8 AO |
487 | /* This variable hold the number of the last entry seen |
488 | in the File Table. */ | |
19e6b90e L |
489 | unsigned int last_file_entry; |
490 | } SMR; | |
491 | ||
492 | static SMR state_machine_regs; | |
493 | ||
494 | static void | |
495 | reset_state_machine (int is_stmt) | |
496 | { | |
497 | state_machine_regs.address = 0; | |
ba8826a8 | 498 | state_machine_regs.view = 0; |
a233b20c | 499 | state_machine_regs.op_index = 0; |
19e6b90e L |
500 | state_machine_regs.file = 1; |
501 | state_machine_regs.line = 1; | |
502 | state_machine_regs.column = 0; | |
503 | state_machine_regs.is_stmt = is_stmt; | |
504 | state_machine_regs.basic_block = 0; | |
505 | state_machine_regs.end_sequence = 0; | |
506 | state_machine_regs.last_file_entry = 0; | |
507 | } | |
508 | ||
509 | /* Handled an extend line op. | |
510 | Returns the number of bytes read. */ | |
511 | ||
cd30bcef | 512 | static size_t |
f6f0e17b NC |
513 | process_extended_line_op (unsigned char * data, |
514 | int is_stmt, | |
515 | unsigned char * end) | |
19e6b90e L |
516 | { |
517 | unsigned char op_code; | |
cd30bcef | 518 | size_t len, header_len; |
19e6b90e | 519 | unsigned char *name; |
143a3db0 | 520 | unsigned char *orig_data = data; |
cd30bcef | 521 | dwarf_vma adr, val; |
19e6b90e | 522 | |
cd30bcef AM |
523 | READ_ULEB (len, data, end); |
524 | header_len = data - orig_data; | |
19e6b90e | 525 | |
cd30bcef | 526 | if (len == 0 || data == end || len > (size_t) (end - data)) |
19e6b90e | 527 | { |
f41e4712 | 528 | warn (_("Badly formed extended line op encountered!\n")); |
cd30bcef | 529 | return header_len; |
19e6b90e L |
530 | } |
531 | ||
19e6b90e L |
532 | op_code = *data++; |
533 | ||
534 | printf (_(" Extended opcode %d: "), op_code); | |
535 | ||
536 | switch (op_code) | |
537 | { | |
538 | case DW_LNE_end_sequence: | |
539 | printf (_("End of Sequence\n\n")); | |
540 | reset_state_machine (is_stmt); | |
541 | break; | |
542 | ||
543 | case DW_LNE_set_address: | |
6937bb54 | 544 | /* PR 17512: file: 002-100480-0.004. */ |
cd30bcef | 545 | if (len - 1 > 8) |
77ef8654 | 546 | { |
cd30bcef AM |
547 | warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"), |
548 | (unsigned long) len - 1); | |
77ef8654 NC |
549 | adr = 0; |
550 | } | |
551 | else | |
cd30bcef | 552 | SAFE_BYTE_GET (adr, data, len - 1, end); |
47704ddf | 553 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 554 | state_machine_regs.address = adr; |
ba8826a8 | 555 | state_machine_regs.view = 0; |
a233b20c | 556 | state_machine_regs.op_index = 0; |
19e6b90e L |
557 | break; |
558 | ||
559 | case DW_LNE_define_file: | |
143a3db0 | 560 | printf (_("define new File Table entry\n")); |
19e6b90e | 561 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 562 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 563 | |
d949ff56 NC |
564 | { |
565 | size_t l; | |
566 | ||
567 | name = data; | |
568 | l = strnlen ((char *) data, end - data); | |
cd30bcef AM |
569 | data += l + 1; |
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)); | |
574 | READ_ULEB (val, data, end); | |
575 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
d949ff56 NC |
576 | printf ("%.*s\n\n", (int) l, name); |
577 | } | |
f6f0e17b | 578 | |
cd30bcef | 579 | if (((size_t) (data - orig_data) != len + header_len) || data == end) |
b4eb7656 | 580 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
581 | break; |
582 | ||
ed4a4bdf | 583 | case DW_LNE_set_discriminator: |
cd30bcef AM |
584 | READ_ULEB (val, data, end); |
585 | printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val)); | |
ed4a4bdf CC |
586 | break; |
587 | ||
e2a0d921 NC |
588 | /* HP extensions. */ |
589 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 590 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
591 | break; |
592 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 593 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
594 | break; |
595 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 596 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
597 | break; |
598 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 599 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
600 | break; |
601 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 602 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
603 | break; |
604 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 605 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
606 | break; |
607 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 608 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
609 | break; |
610 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 611 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
612 | break; |
613 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 614 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
615 | break; |
616 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 617 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 618 | break; |
43294ab7 TG |
619 | case DW_LNE_HP_source_file_correlation: |
620 | { | |
cd30bcef | 621 | unsigned char *edata = data + len - 1; |
b4eb7656 AM |
622 | |
623 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
624 | ||
625 | while (data < edata) | |
626 | { | |
627 | unsigned int opc; | |
628 | ||
cd30bcef | 629 | READ_ULEB (opc, data, edata); |
b4eb7656 AM |
630 | |
631 | switch (opc) | |
632 | { | |
633 | case DW_LNE_HP_SFC_formfeed: | |
634 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
635 | break; | |
636 | case DW_LNE_HP_SFC_set_listing_line: | |
cd30bcef | 637 | READ_ULEB (val, data, edata); |
b4eb7656 | 638 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", |
cd30bcef | 639 | dwarf_vmatoa ("u", val)); |
b4eb7656 AM |
640 | break; |
641 | case DW_LNE_HP_SFC_associate: | |
642 | printf (" DW_LNE_HP_SFC_associate "); | |
cd30bcef AM |
643 | READ_ULEB (val, data, edata); |
644 | printf ("(%s", dwarf_vmatoa ("u", val)); | |
645 | READ_ULEB (val, data, edata); | |
646 | printf (",%s", dwarf_vmatoa ("u", val)); | |
647 | READ_ULEB (val, data, edata); | |
648 | printf (",%s)\n", dwarf_vmatoa ("u", val)); | |
b4eb7656 AM |
649 | break; |
650 | default: | |
651 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
652 | data = edata; | |
653 | break; | |
654 | } | |
655 | } | |
43294ab7 TG |
656 | } |
657 | break; | |
cecf136e | 658 | |
19e6b90e | 659 | default: |
7e665af3 | 660 | { |
cd30bcef | 661 | unsigned int rlen = len - 1; |
b4eb7656 AM |
662 | |
663 | if (op_code >= DW_LNE_lo_user | |
664 | /* The test against DW_LNW_hi_user is redundant due to | |
665 | the limited range of the unsigned char data type used | |
666 | for op_code. */ | |
667 | /*&& op_code <= DW_LNE_hi_user*/) | |
668 | printf (_("user defined: ")); | |
669 | else | |
670 | printf (_("UNKNOWN: ")); | |
671 | printf (_("length %d ["), rlen); | |
672 | for (; rlen; rlen--) | |
673 | printf (" %02x", *data++); | |
674 | printf ("]\n"); | |
7e665af3 | 675 | } |
19e6b90e L |
676 | break; |
677 | } | |
678 | ||
cd30bcef | 679 | return len + header_len; |
19e6b90e L |
680 | } |
681 | ||
0c588247 | 682 | static const unsigned char * |
467c65bc | 683 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
684 | { |
685 | struct dwarf_section *section = &debug_displays [str].section; | |
d949ff56 | 686 | const unsigned char * ret; |
19e6b90e L |
687 | |
688 | if (section->start == NULL) | |
0c588247 | 689 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e | 690 | |
d949ff56 | 691 | if (offset >= section->size) |
19e6b90e | 692 | { |
d296b736 | 693 | warn (_("DW_FORM_strp offset too big: 0x%s\n"), |
467c65bc | 694 | dwarf_vmatoa ("x", offset)); |
0c588247 | 695 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
696 | } |
697 | ||
d949ff56 NC |
698 | ret = section->start + offset; |
699 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
700 | NUL byte. Since our caller is expecting to receive a well formed C | |
701 | string we test for the lack of a terminating byte here. */ | |
702 | if (strnlen ((const char *) ret, section->size - offset) | |
703 | == section->size - offset) | |
704 | ret = (const unsigned char *) | |
705 | _("<no NUL byte at end of .debug_str section>"); | |
706 | ||
521d4b19 | 707 | return ret; |
19e6b90e L |
708 | } |
709 | ||
77145576 JK |
710 | static const unsigned char * |
711 | fetch_indirect_line_string (dwarf_vma offset) | |
712 | { | |
713 | struct dwarf_section *section = &debug_displays [line_str].section; | |
d949ff56 | 714 | const unsigned char * ret; |
77145576 JK |
715 | |
716 | if (section->start == NULL) | |
717 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
718 | ||
d949ff56 | 719 | if (offset >= section->size) |
77145576 | 720 | { |
d296b736 | 721 | warn (_("DW_FORM_line_strp offset too big: 0x%s\n"), |
77145576 JK |
722 | dwarf_vmatoa ("x", offset)); |
723 | return (const unsigned char *) _("<offset is too big>"); | |
724 | } | |
725 | ||
d949ff56 NC |
726 | ret = section->start + offset; |
727 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
728 | with a NUL byte. Since our caller is expecting to receive a well formed | |
729 | C string we test for the lack of a terminating byte here. */ | |
730 | if (strnlen ((const char *) ret, section->size - offset) | |
731 | == section->size - offset) | |
732 | ret = (const unsigned char *) | |
733 | _("<no NUL byte at end of .debug_line_str section>"); | |
734 | ||
735 | return ret; | |
77145576 JK |
736 | } |
737 | ||
4723351a | 738 | static const char * |
341f9135 | 739 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
d85bf2ba | 740 | dwarf_vma offset_size, bfd_boolean dwo) |
4723351a CC |
741 | { |
742 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
743 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
744 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
745 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
e4b7104b | 746 | dwarf_vma index_offset; |
4723351a | 747 | dwarf_vma str_offset; |
d949ff56 | 748 | const char * ret; |
e4b7104b NC |
749 | unsigned char *curr = index_section->start; |
750 | const unsigned char *end = curr + index_section->size; | |
751 | dwarf_vma length; | |
4723351a CC |
752 | |
753 | if (index_section->start == NULL) | |
754 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
755 | : _("<no .debug_str_offsets section>")); | |
756 | ||
e4b7104b NC |
757 | if (str_section->start == NULL) |
758 | return (dwo ? _("<no .debug_str.dwo section>") | |
759 | : _("<no .debug_str section>")); | |
760 | ||
761 | /* FIXME: We should cache the length... */ | |
762 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); | |
763 | if (length == 0xffffffff) | |
764 | { | |
765 | if (offset_size != 8) | |
39f381cb | 766 | warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size)); |
e4b7104b NC |
767 | SAFE_BYTE_GET_AND_INC (length, curr, 8, end); |
768 | } | |
769 | else if (offset_size != 4) | |
770 | { | |
39f381cb | 771 | warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size)); |
e4b7104b NC |
772 | } |
773 | ||
39f381cb | 774 | if (length == 0) |
e4b7104b | 775 | { |
39f381cb NC |
776 | /* This is probably an old style .debug_str_offset section which |
777 | just contains offsets and no header (and the first offset is 0). */ | |
778 | curr = index_section->start; | |
779 | length = index_section->size; | |
780 | } | |
781 | else | |
782 | { | |
783 | /* Skip the version and padding bytes. | |
784 | We assume that they are correct. */ | |
785 | curr += 4; | |
786 | ||
787 | /* FIXME: The code below assumes that there is only one table | |
788 | in the .debug_str_offsets section, so check that now. */ | |
789 | if ((offset_size == 4 && curr + length < (end - 8)) | |
790 | || (offset_size == 8 && curr + length < (end - 16))) | |
791 | { | |
792 | warn (_("index table size is too small %s vs %s\n"), | |
793 | dwarf_vmatoa ("x", length), | |
794 | dwarf_vmatoa ("x", index_section->size)); | |
795 | return _("<table too small>"); | |
796 | } | |
e4b7104b NC |
797 | } |
798 | ||
799 | index_offset = idx * offset_size; | |
521d4b19 | 800 | |
341f9135 CC |
801 | if (this_set != NULL) |
802 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
e4b7104b NC |
803 | |
804 | if (index_offset >= length) | |
4723351a | 805 | { |
d296b736 | 806 | warn (_("DW_FORM_GNU_str_index offset too big: 0x%s vs 0x%s\n"), |
e4b7104b NC |
807 | dwarf_vmatoa ("x", index_offset), |
808 | dwarf_vmatoa ("x", length)); | |
4723351a CC |
809 | return _("<index offset is too big>"); |
810 | } | |
811 | ||
e4b7104b | 812 | str_offset = byte_get (curr + index_offset, offset_size); |
4723351a | 813 | str_offset -= str_section->address; |
d949ff56 | 814 | if (str_offset >= str_section->size) |
4723351a | 815 | { |
d296b736 | 816 | warn (_("DW_FORM_GNU_str_index indirect offset too big: 0x%s\n"), |
4723351a CC |
817 | dwarf_vmatoa ("x", str_offset)); |
818 | return _("<indirect index offset is too big>"); | |
819 | } | |
820 | ||
d949ff56 NC |
821 | ret = (const char *) str_section->start + str_offset; |
822 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. | |
823 | Since our caller is expecting to receive a well formed C string we test | |
824 | for the lack of a terminating byte here. */ | |
825 | if (strnlen (ret, str_section->size - str_offset) | |
826 | == str_section->size - str_offset) | |
827 | ret = (const char *) _("<no NUL byte at end of section>"); | |
828 | ||
829 | return ret; | |
4723351a CC |
830 | } |
831 | ||
832 | static const char * | |
833 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
834 | { | |
835 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
836 | ||
837 | if (section->start == NULL) | |
838 | return (_("<no .debug_addr section>")); | |
839 | ||
840 | if (offset + bytes > section->size) | |
841 | { | |
d296b736 | 842 | warn (_("Offset into section %s too big: 0x%s\n"), |
b4eb7656 | 843 | section->name, dwarf_vmatoa ("x", offset)); |
4723351a CC |
844 | return "<offset too big>"; |
845 | } | |
846 | ||
847 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
848 | } | |
849 | ||
850 | ||
19e6b90e L |
851 | /* FIXME: There are better and more efficient ways to handle |
852 | these structures. For now though, I just want something that | |
853 | is simple to implement. */ | |
bcd213b2 | 854 | /* Records a single attribute in an abbrev. */ |
19e6b90e L |
855 | typedef struct abbrev_attr |
856 | { | |
bcd213b2 NC |
857 | unsigned long attribute; |
858 | unsigned long form; | |
859 | bfd_signed_vma implicit_const; | |
860 | struct abbrev_attr * next; | |
19e6b90e L |
861 | } |
862 | abbrev_attr; | |
863 | ||
bcd213b2 | 864 | /* Records a single abbrev. */ |
19e6b90e L |
865 | typedef struct abbrev_entry |
866 | { | |
bcd213b2 NC |
867 | unsigned long number; |
868 | unsigned long tag; | |
869 | int children; | |
870 | struct abbrev_attr * first_attr; | |
871 | struct abbrev_attr * last_attr; | |
872 | struct abbrev_entry * next; | |
19e6b90e L |
873 | } |
874 | abbrev_entry; | |
875 | ||
bcd213b2 NC |
876 | /* Records a set of abbreviations. */ |
877 | typedef struct abbrev_list | |
878 | { | |
879 | abbrev_entry * first_abbrev; | |
880 | abbrev_entry * last_abbrev; | |
76868f36 | 881 | dwarf_vma abbrev_base; |
bcd213b2 NC |
882 | dwarf_vma abbrev_offset; |
883 | struct abbrev_list * next; | |
884 | unsigned char * start_of_next_abbrevs; | |
885 | } | |
886 | abbrev_list; | |
887 | ||
888 | /* Records all the abbrevs found so far. */ | |
889 | static struct abbrev_list * abbrev_lists = NULL; | |
890 | ||
891 | typedef struct abbrev_map | |
892 | { | |
893 | dwarf_vma start; | |
894 | dwarf_vma end; | |
895 | abbrev_list * list; | |
896 | } abbrev_map; | |
897 | ||
898 | /* Maps between CU offsets and abbrev sets. */ | |
899 | static abbrev_map * cu_abbrev_map = NULL; | |
900 | static unsigned long num_abbrev_map_entries = 0; | |
901 | static unsigned long next_free_abbrev_map_entry = 0; | |
902 | ||
903 | #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8 | |
904 | #define ABBREV_MAP_ENTRIES_INCREMENT 8 | |
905 | ||
906 | static void | |
907 | record_abbrev_list_for_cu (dwarf_vma start, dwarf_vma end, abbrev_list * list) | |
908 | { | |
909 | if (cu_abbrev_map == NULL) | |
910 | { | |
911 | num_abbrev_map_entries = INITIAL_NUM_ABBREV_MAP_ENTRIES; | |
912 | cu_abbrev_map = xmalloc (num_abbrev_map_entries * sizeof (* cu_abbrev_map)); | |
913 | } | |
914 | else if (next_free_abbrev_map_entry == num_abbrev_map_entries) | |
915 | { | |
916 | num_abbrev_map_entries += ABBREV_MAP_ENTRIES_INCREMENT; | |
917 | cu_abbrev_map = xrealloc (cu_abbrev_map, num_abbrev_map_entries * sizeof (* cu_abbrev_map)); | |
918 | } | |
919 | ||
920 | cu_abbrev_map[next_free_abbrev_map_entry].start = start; | |
921 | cu_abbrev_map[next_free_abbrev_map_entry].end = end; | |
922 | cu_abbrev_map[next_free_abbrev_map_entry].list = list; | |
923 | next_free_abbrev_map_entry ++; | |
924 | } | |
19e6b90e L |
925 | |
926 | static void | |
bcd213b2 | 927 | free_all_abbrevs (void) |
19e6b90e | 928 | { |
bcd213b2 | 929 | abbrev_list * list; |
19e6b90e | 930 | |
bcd213b2 | 931 | for (list = abbrev_lists; list != NULL;) |
19e6b90e | 932 | { |
bcd213b2 NC |
933 | abbrev_list * next = list->next; |
934 | abbrev_entry * abbrv; | |
19e6b90e | 935 | |
bcd213b2 | 936 | for (abbrv = list->first_abbrev; abbrv != NULL;) |
19e6b90e | 937 | { |
bcd213b2 NC |
938 | abbrev_entry * next_abbrev = abbrv->next; |
939 | abbrev_attr * attr; | |
940 | ||
941 | for (attr = abbrv->first_attr; attr;) | |
942 | { | |
943 | abbrev_attr *next_attr = attr->next; | |
19e6b90e | 944 | |
bcd213b2 NC |
945 | free (attr); |
946 | attr = next_attr; | |
947 | } | |
948 | ||
949 | free (abbrv); | |
950 | abbrv = next_abbrev; | |
19e6b90e L |
951 | } |
952 | ||
bcd213b2 NC |
953 | free (list); |
954 | list = next; | |
19e6b90e L |
955 | } |
956 | ||
bcd213b2 NC |
957 | abbrev_lists = NULL; |
958 | } | |
959 | ||
960 | static abbrev_list * | |
76868f36 | 961 | new_abbrev_list (dwarf_vma abbrev_base, dwarf_vma abbrev_offset) |
bcd213b2 NC |
962 | { |
963 | abbrev_list * list = (abbrev_list *) xcalloc (sizeof * list, 1); | |
964 | ||
76868f36 | 965 | list->abbrev_base = abbrev_base; |
bcd213b2 NC |
966 | list->abbrev_offset = abbrev_offset; |
967 | ||
968 | list->next = abbrev_lists; | |
969 | abbrev_lists = list; | |
970 | ||
971 | return list; | |
972 | } | |
973 | ||
974 | static abbrev_list * | |
76868f36 L |
975 | find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base, |
976 | dwarf_vma abbrev_offset) | |
bcd213b2 NC |
977 | { |
978 | abbrev_list * list; | |
979 | ||
980 | for (list = abbrev_lists; list != NULL; list = list->next) | |
76868f36 L |
981 | if (list->abbrev_base == abbrev_base |
982 | && list->abbrev_offset == abbrev_offset) | |
bcd213b2 NC |
983 | return list; |
984 | ||
985 | return NULL; | |
986 | } | |
987 | ||
988 | /* Find the abbreviation map for the CU that includes OFFSET. | |
989 | OFFSET is an absolute offset from the start of the .debug_info section. */ | |
990 | /* FIXME: This function is going to slow down readelf & objdump. | |
991 | Consider using a better algorithm to mitigate this effect. */ | |
992 | ||
993 | static abbrev_map * | |
994 | find_abbrev_map_by_offset (dwarf_vma offset) | |
995 | { | |
996 | unsigned long i; | |
997 | ||
998 | for (i = 0; i < next_free_abbrev_map_entry; i++) | |
999 | if (cu_abbrev_map[i].start <= offset | |
1000 | && cu_abbrev_map[i].end > offset) | |
1001 | return cu_abbrev_map + i; | |
1002 | ||
1003 | return NULL; | |
19e6b90e L |
1004 | } |
1005 | ||
1006 | static void | |
bcd213b2 NC |
1007 | add_abbrev (unsigned long number, |
1008 | unsigned long tag, | |
1009 | int children, | |
1010 | abbrev_list * list) | |
19e6b90e | 1011 | { |
bcd213b2 | 1012 | abbrev_entry * entry; |
19e6b90e | 1013 | |
bcd213b2 | 1014 | entry = (abbrev_entry *) xmalloc (sizeof (*entry)); |
19e6b90e | 1015 | |
bcd213b2 | 1016 | entry->number = number; |
19e6b90e L |
1017 | entry->tag = tag; |
1018 | entry->children = children; | |
1019 | entry->first_attr = NULL; | |
1020 | entry->last_attr = NULL; | |
1021 | entry->next = NULL; | |
1022 | ||
bcd213b2 NC |
1023 | assert (list != NULL); |
1024 | ||
1025 | if (list->first_abbrev == NULL) | |
1026 | list->first_abbrev = entry; | |
19e6b90e | 1027 | else |
bcd213b2 | 1028 | list->last_abbrev->next = entry; |
19e6b90e | 1029 | |
bcd213b2 | 1030 | list->last_abbrev = entry; |
19e6b90e L |
1031 | } |
1032 | ||
1033 | static void | |
bcd213b2 NC |
1034 | add_abbrev_attr (unsigned long attribute, |
1035 | unsigned long form, | |
1036 | bfd_signed_vma implicit_const, | |
1037 | abbrev_list * list) | |
19e6b90e L |
1038 | { |
1039 | abbrev_attr *attr; | |
1040 | ||
bcd213b2 | 1041 | attr = (abbrev_attr *) xmalloc (sizeof (*attr)); |
19e6b90e L |
1042 | |
1043 | attr->attribute = attribute; | |
1044 | attr->form = form; | |
77145576 | 1045 | attr->implicit_const = implicit_const; |
19e6b90e L |
1046 | attr->next = NULL; |
1047 | ||
bcd213b2 NC |
1048 | assert (list != NULL && list->last_abbrev != NULL); |
1049 | ||
1050 | if (list->last_abbrev->first_attr == NULL) | |
1051 | list->last_abbrev->first_attr = attr; | |
19e6b90e | 1052 | else |
bcd213b2 | 1053 | list->last_abbrev->last_attr->next = attr; |
19e6b90e | 1054 | |
bcd213b2 | 1055 | list->last_abbrev->last_attr = attr; |
19e6b90e L |
1056 | } |
1057 | ||
1058 | /* Processes the (partial) contents of a .debug_abbrev section. | |
1059 | Returns NULL if the end of the section was encountered. | |
1060 | Returns the address after the last byte read if the end of | |
1061 | an abbreviation set was found. */ | |
1062 | ||
1063 | static unsigned char * | |
bcd213b2 NC |
1064 | process_abbrev_set (unsigned char * start, |
1065 | const unsigned char * end, | |
1066 | abbrev_list * list) | |
19e6b90e | 1067 | { |
19e6b90e L |
1068 | while (start < end) |
1069 | { | |
19e6b90e L |
1070 | unsigned long entry; |
1071 | unsigned long tag; | |
1072 | unsigned long attribute; | |
1073 | int children; | |
1074 | ||
cd30bcef | 1075 | READ_ULEB (entry, start, end); |
19e6b90e | 1076 | |
bcd213b2 | 1077 | /* A single zero is supposed to end the set according |
19e6b90e L |
1078 | to the standard. If there's more, then signal that to |
1079 | the caller. */ | |
f6f0e17b NC |
1080 | if (start == end) |
1081 | return NULL; | |
19e6b90e | 1082 | if (entry == 0) |
f6f0e17b | 1083 | return start; |
19e6b90e | 1084 | |
cd30bcef | 1085 | READ_ULEB (tag, start, end); |
f6f0e17b NC |
1086 | if (start == end) |
1087 | return NULL; | |
19e6b90e L |
1088 | |
1089 | children = *start++; | |
1090 | ||
bcd213b2 | 1091 | add_abbrev (entry, tag, children, list); |
19e6b90e L |
1092 | |
1093 | do | |
1094 | { | |
1095 | unsigned long form; | |
77145576 JK |
1096 | /* Initialize it due to a false compiler warning. */ |
1097 | bfd_signed_vma implicit_const = -1; | |
19e6b90e | 1098 | |
cd30bcef | 1099 | READ_ULEB (attribute, start, end); |
f6f0e17b NC |
1100 | if (start == end) |
1101 | break; | |
19e6b90e | 1102 | |
cd30bcef | 1103 | READ_ULEB (form, start, end); |
f6f0e17b NC |
1104 | if (start == end) |
1105 | break; | |
19e6b90e | 1106 | |
77145576 JK |
1107 | if (form == DW_FORM_implicit_const) |
1108 | { | |
cd30bcef | 1109 | READ_SLEB (implicit_const, start, end); |
77145576 JK |
1110 | if (start == end) |
1111 | break; | |
1112 | } | |
1113 | ||
bcd213b2 | 1114 | add_abbrev_attr (attribute, form, implicit_const, list); |
19e6b90e L |
1115 | } |
1116 | while (attribute != 0); | |
1117 | } | |
1118 | ||
399c99f7 L |
1119 | /* Report the missing single zero which ends the section. */ |
1120 | error (_(".debug_abbrev section not zero terminated\n")); | |
1121 | ||
19e6b90e L |
1122 | return NULL; |
1123 | } | |
1124 | ||
a19c41a7 | 1125 | static const char * |
19e6b90e L |
1126 | get_TAG_name (unsigned long tag) |
1127 | { | |
04914e37 | 1128 | const char *name = get_DW_TAG_name ((unsigned int) tag); |
a19c41a7 TT |
1129 | |
1130 | if (name == NULL) | |
19e6b90e | 1131 | { |
a19c41a7 | 1132 | static char buffer[100]; |
19e6b90e | 1133 | |
04914e37 NC |
1134 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
1135 | snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag); | |
1136 | else | |
1137 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag); | |
a19c41a7 | 1138 | return buffer; |
19e6b90e | 1139 | } |
a19c41a7 TT |
1140 | |
1141 | return name; | |
19e6b90e L |
1142 | } |
1143 | ||
a19c41a7 | 1144 | static const char * |
19e6b90e L |
1145 | get_FORM_name (unsigned long form) |
1146 | { | |
399c99f7 | 1147 | const char *name; |
bf5117e3 | 1148 | |
399c99f7 L |
1149 | if (form == 0) |
1150 | return "DW_FORM value: 0"; | |
a19c41a7 | 1151 | |
399c99f7 | 1152 | name = get_DW_FORM_name (form); |
a19c41a7 | 1153 | if (name == NULL) |
19e6b90e | 1154 | { |
a19c41a7 | 1155 | static char buffer[100]; |
19e6b90e | 1156 | |
a19c41a7 TT |
1157 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
1158 | return buffer; | |
19e6b90e | 1159 | } |
a19c41a7 TT |
1160 | |
1161 | return name; | |
19e6b90e L |
1162 | } |
1163 | ||
61364358 JK |
1164 | static const char * |
1165 | get_IDX_name (unsigned long idx) | |
1166 | { | |
1167 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
1168 | ||
1169 | if (name == NULL) | |
1170 | { | |
1171 | static char buffer[100]; | |
1172 | ||
1173 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1174 | return buffer; | |
1175 | } | |
1176 | ||
1177 | return name; | |
1178 | } | |
1179 | ||
19e6b90e | 1180 | static unsigned char * |
0c588247 NC |
1181 | display_block (unsigned char *data, |
1182 | dwarf_vma length, | |
ef0b5f1c | 1183 | const unsigned char * const end, char delimiter) |
19e6b90e | 1184 | { |
0c588247 NC |
1185 | dwarf_vma maxlen; |
1186 | ||
ef0b5f1c | 1187 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
1188 | if (data > end) |
1189 | return (unsigned char *) end; | |
19e6b90e | 1190 | |
0c588247 NC |
1191 | maxlen = (dwarf_vma) (end - data); |
1192 | length = length > maxlen ? maxlen : length; | |
1193 | ||
19e6b90e L |
1194 | while (length --) |
1195 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1196 | ||
1197 | return data; | |
1198 | } | |
1199 | ||
1200 | static int | |
1201 | decode_location_expression (unsigned char * data, | |
1202 | unsigned int pointer_size, | |
b7807392 JJ |
1203 | unsigned int offset_size, |
1204 | int dwarf_version, | |
467c65bc NC |
1205 | dwarf_vma length, |
1206 | dwarf_vma cu_offset, | |
f1c4cc75 | 1207 | struct dwarf_section * section) |
19e6b90e L |
1208 | { |
1209 | unsigned op; | |
467c65bc | 1210 | dwarf_vma uvalue; |
0c588247 | 1211 | dwarf_signed_vma svalue; |
19e6b90e L |
1212 | unsigned char *end = data + length; |
1213 | int need_frame_base = 0; | |
1214 | ||
1215 | while (data < end) | |
1216 | { | |
1217 | op = *data++; | |
1218 | ||
1219 | switch (op) | |
1220 | { | |
1221 | case DW_OP_addr: | |
0c588247 NC |
1222 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1223 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1224 | break; |
1225 | case DW_OP_deref: | |
1226 | printf ("DW_OP_deref"); | |
1227 | break; | |
1228 | case DW_OP_const1u: | |
0c588247 NC |
1229 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1230 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1231 | break; |
1232 | case DW_OP_const1s: | |
0c588247 NC |
1233 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1234 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1235 | break; |
1236 | case DW_OP_const2u: | |
87bc83b3 | 1237 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1238 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1239 | break; |
1240 | case DW_OP_const2s: | |
0c588247 NC |
1241 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1242 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1243 | break; |
1244 | case DW_OP_const4u: | |
0c588247 NC |
1245 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1246 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1247 | break; |
1248 | case DW_OP_const4s: | |
0c588247 NC |
1249 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1250 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1251 | break; |
1252 | case DW_OP_const8u: | |
0c588247 NC |
1253 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1254 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1255 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1256 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1257 | break; |
1258 | case DW_OP_const8s: | |
0c588247 NC |
1259 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1260 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1261 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1262 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1263 | break; |
1264 | case DW_OP_constu: | |
cd30bcef AM |
1265 | READ_ULEB (uvalue, data, end); |
1266 | printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1267 | break; |
1268 | case DW_OP_consts: | |
cd30bcef AM |
1269 | READ_SLEB (svalue, data, end); |
1270 | printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1271 | break; |
1272 | case DW_OP_dup: | |
1273 | printf ("DW_OP_dup"); | |
1274 | break; | |
1275 | case DW_OP_drop: | |
1276 | printf ("DW_OP_drop"); | |
1277 | break; | |
1278 | case DW_OP_over: | |
1279 | printf ("DW_OP_over"); | |
1280 | break; | |
1281 | case DW_OP_pick: | |
0c588247 NC |
1282 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1283 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1284 | break; |
1285 | case DW_OP_swap: | |
1286 | printf ("DW_OP_swap"); | |
1287 | break; | |
1288 | case DW_OP_rot: | |
1289 | printf ("DW_OP_rot"); | |
1290 | break; | |
1291 | case DW_OP_xderef: | |
1292 | printf ("DW_OP_xderef"); | |
1293 | break; | |
1294 | case DW_OP_abs: | |
1295 | printf ("DW_OP_abs"); | |
1296 | break; | |
1297 | case DW_OP_and: | |
1298 | printf ("DW_OP_and"); | |
1299 | break; | |
1300 | case DW_OP_div: | |
1301 | printf ("DW_OP_div"); | |
1302 | break; | |
1303 | case DW_OP_minus: | |
1304 | printf ("DW_OP_minus"); | |
1305 | break; | |
1306 | case DW_OP_mod: | |
1307 | printf ("DW_OP_mod"); | |
1308 | break; | |
1309 | case DW_OP_mul: | |
1310 | printf ("DW_OP_mul"); | |
1311 | break; | |
1312 | case DW_OP_neg: | |
1313 | printf ("DW_OP_neg"); | |
1314 | break; | |
1315 | case DW_OP_not: | |
1316 | printf ("DW_OP_not"); | |
1317 | break; | |
1318 | case DW_OP_or: | |
1319 | printf ("DW_OP_or"); | |
1320 | break; | |
1321 | case DW_OP_plus: | |
1322 | printf ("DW_OP_plus"); | |
1323 | break; | |
1324 | case DW_OP_plus_uconst: | |
cd30bcef AM |
1325 | READ_ULEB (uvalue, data, end); |
1326 | printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1327 | break; |
1328 | case DW_OP_shl: | |
1329 | printf ("DW_OP_shl"); | |
1330 | break; | |
1331 | case DW_OP_shr: | |
1332 | printf ("DW_OP_shr"); | |
1333 | break; | |
1334 | case DW_OP_shra: | |
1335 | printf ("DW_OP_shra"); | |
1336 | break; | |
1337 | case DW_OP_xor: | |
1338 | printf ("DW_OP_xor"); | |
1339 | break; | |
1340 | case DW_OP_bra: | |
0c588247 NC |
1341 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1342 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1343 | break; |
1344 | case DW_OP_eq: | |
1345 | printf ("DW_OP_eq"); | |
1346 | break; | |
1347 | case DW_OP_ge: | |
1348 | printf ("DW_OP_ge"); | |
1349 | break; | |
1350 | case DW_OP_gt: | |
1351 | printf ("DW_OP_gt"); | |
1352 | break; | |
1353 | case DW_OP_le: | |
1354 | printf ("DW_OP_le"); | |
1355 | break; | |
1356 | case DW_OP_lt: | |
1357 | printf ("DW_OP_lt"); | |
1358 | break; | |
1359 | case DW_OP_ne: | |
1360 | printf ("DW_OP_ne"); | |
1361 | break; | |
1362 | case DW_OP_skip: | |
0c588247 NC |
1363 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1364 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1365 | break; |
1366 | ||
1367 | case DW_OP_lit0: | |
1368 | case DW_OP_lit1: | |
1369 | case DW_OP_lit2: | |
1370 | case DW_OP_lit3: | |
1371 | case DW_OP_lit4: | |
1372 | case DW_OP_lit5: | |
1373 | case DW_OP_lit6: | |
1374 | case DW_OP_lit7: | |
1375 | case DW_OP_lit8: | |
1376 | case DW_OP_lit9: | |
1377 | case DW_OP_lit10: | |
1378 | case DW_OP_lit11: | |
1379 | case DW_OP_lit12: | |
1380 | case DW_OP_lit13: | |
1381 | case DW_OP_lit14: | |
1382 | case DW_OP_lit15: | |
1383 | case DW_OP_lit16: | |
1384 | case DW_OP_lit17: | |
1385 | case DW_OP_lit18: | |
1386 | case DW_OP_lit19: | |
1387 | case DW_OP_lit20: | |
1388 | case DW_OP_lit21: | |
1389 | case DW_OP_lit22: | |
1390 | case DW_OP_lit23: | |
1391 | case DW_OP_lit24: | |
1392 | case DW_OP_lit25: | |
1393 | case DW_OP_lit26: | |
1394 | case DW_OP_lit27: | |
1395 | case DW_OP_lit28: | |
1396 | case DW_OP_lit29: | |
1397 | case DW_OP_lit30: | |
1398 | case DW_OP_lit31: | |
1399 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1400 | break; | |
1401 | ||
1402 | case DW_OP_reg0: | |
1403 | case DW_OP_reg1: | |
1404 | case DW_OP_reg2: | |
1405 | case DW_OP_reg3: | |
1406 | case DW_OP_reg4: | |
1407 | case DW_OP_reg5: | |
1408 | case DW_OP_reg6: | |
1409 | case DW_OP_reg7: | |
1410 | case DW_OP_reg8: | |
1411 | case DW_OP_reg9: | |
1412 | case DW_OP_reg10: | |
1413 | case DW_OP_reg11: | |
1414 | case DW_OP_reg12: | |
1415 | case DW_OP_reg13: | |
1416 | case DW_OP_reg14: | |
1417 | case DW_OP_reg15: | |
1418 | case DW_OP_reg16: | |
1419 | case DW_OP_reg17: | |
1420 | case DW_OP_reg18: | |
1421 | case DW_OP_reg19: | |
1422 | case DW_OP_reg20: | |
1423 | case DW_OP_reg21: | |
1424 | case DW_OP_reg22: | |
1425 | case DW_OP_reg23: | |
1426 | case DW_OP_reg24: | |
1427 | case DW_OP_reg25: | |
1428 | case DW_OP_reg26: | |
1429 | case DW_OP_reg27: | |
1430 | case DW_OP_reg28: | |
1431 | case DW_OP_reg29: | |
1432 | case DW_OP_reg30: | |
1433 | case DW_OP_reg31: | |
18464d4d JK |
1434 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1435 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1436 | break; |
1437 | ||
1438 | case DW_OP_breg0: | |
1439 | case DW_OP_breg1: | |
1440 | case DW_OP_breg2: | |
1441 | case DW_OP_breg3: | |
1442 | case DW_OP_breg4: | |
1443 | case DW_OP_breg5: | |
1444 | case DW_OP_breg6: | |
1445 | case DW_OP_breg7: | |
1446 | case DW_OP_breg8: | |
1447 | case DW_OP_breg9: | |
1448 | case DW_OP_breg10: | |
1449 | case DW_OP_breg11: | |
1450 | case DW_OP_breg12: | |
1451 | case DW_OP_breg13: | |
1452 | case DW_OP_breg14: | |
1453 | case DW_OP_breg15: | |
1454 | case DW_OP_breg16: | |
1455 | case DW_OP_breg17: | |
1456 | case DW_OP_breg18: | |
1457 | case DW_OP_breg19: | |
1458 | case DW_OP_breg20: | |
1459 | case DW_OP_breg21: | |
1460 | case DW_OP_breg22: | |
1461 | case DW_OP_breg23: | |
1462 | case DW_OP_breg24: | |
1463 | case DW_OP_breg25: | |
1464 | case DW_OP_breg26: | |
1465 | case DW_OP_breg27: | |
1466 | case DW_OP_breg28: | |
1467 | case DW_OP_breg29: | |
1468 | case DW_OP_breg30: | |
1469 | case DW_OP_breg31: | |
cd30bcef AM |
1470 | READ_SLEB (svalue, data, end); |
1471 | printf ("DW_OP_breg%d (%s): %s", op - DW_OP_breg0, | |
1472 | regname (op - DW_OP_breg0, 1), dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1473 | break; |
1474 | ||
1475 | case DW_OP_regx: | |
cd30bcef | 1476 | READ_ULEB (uvalue, data, end); |
467c65bc NC |
1477 | printf ("DW_OP_regx: %s (%s)", |
1478 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1479 | break; |
1480 | case DW_OP_fbreg: | |
1481 | need_frame_base = 1; | |
cd30bcef AM |
1482 | READ_SLEB (svalue, data, end); |
1483 | printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1484 | break; |
1485 | case DW_OP_bregx: | |
cd30bcef AM |
1486 | READ_ULEB (uvalue, data, end); |
1487 | READ_SLEB (svalue, data, end); | |
467c65bc NC |
1488 | printf ("DW_OP_bregx: %s (%s) %s", |
1489 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
cd30bcef | 1490 | dwarf_vmatoa ("d", svalue)); |
19e6b90e L |
1491 | break; |
1492 | case DW_OP_piece: | |
cd30bcef AM |
1493 | READ_ULEB (uvalue, data, end); |
1494 | printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1495 | break; |
1496 | case DW_OP_deref_size: | |
0c588247 NC |
1497 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1498 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1499 | break; |
1500 | case DW_OP_xderef_size: | |
0c588247 NC |
1501 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1502 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1503 | break; |
1504 | case DW_OP_nop: | |
1505 | printf ("DW_OP_nop"); | |
1506 | break; | |
1507 | ||
1508 | /* DWARF 3 extensions. */ | |
1509 | case DW_OP_push_object_address: | |
1510 | printf ("DW_OP_push_object_address"); | |
1511 | break; | |
1512 | case DW_OP_call2: | |
d85bf2ba | 1513 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1514 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1515 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1516 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1517 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1518 | break; |
1519 | case DW_OP_call4: | |
d85bf2ba | 1520 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1521 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1522 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1523 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1524 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1525 | break; |
1526 | case DW_OP_call_ref: | |
d85bf2ba | 1527 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
e2a0d921 | 1528 | this ought to be an 8-byte wide computation. */ |
b7807392 JJ |
1529 | if (dwarf_version == -1) |
1530 | { | |
1531 | printf (_("(DW_OP_call_ref in frame info)")); | |
1532 | /* No way to tell where the next op is, so just bail. */ | |
1533 | return need_frame_base; | |
1534 | } | |
1535 | if (dwarf_version == 2) | |
1536 | { | |
0c588247 | 1537 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1538 | } |
1539 | else | |
1540 | { | |
0c588247 | 1541 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1542 | } |
0c588247 | 1543 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1544 | break; |
a87b0a59 NS |
1545 | case DW_OP_form_tls_address: |
1546 | printf ("DW_OP_form_tls_address"); | |
1547 | break; | |
e2a0d921 NC |
1548 | case DW_OP_call_frame_cfa: |
1549 | printf ("DW_OP_call_frame_cfa"); | |
1550 | break; | |
1551 | case DW_OP_bit_piece: | |
1552 | printf ("DW_OP_bit_piece: "); | |
cd30bcef AM |
1553 | READ_ULEB (uvalue, data, end); |
1554 | printf (_("size: %s "), dwarf_vmatoa ("u", uvalue)); | |
1555 | READ_ULEB (uvalue, data, end); | |
1556 | printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue)); | |
e2a0d921 | 1557 | break; |
19e6b90e | 1558 | |
3244e8f5 JJ |
1559 | /* DWARF 4 extensions. */ |
1560 | case DW_OP_stack_value: | |
1561 | printf ("DW_OP_stack_value"); | |
1562 | break; | |
1563 | ||
1564 | case DW_OP_implicit_value: | |
1565 | printf ("DW_OP_implicit_value"); | |
cd30bcef | 1566 | READ_ULEB (uvalue, data, end); |
ef0b5f1c | 1567 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1568 | break; |
1569 | ||
19e6b90e L |
1570 | /* GNU extensions. */ |
1571 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1572 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1573 | break; |
1574 | case DW_OP_GNU_uninit: | |
1575 | printf ("DW_OP_GNU_uninit"); | |
1576 | /* FIXME: Is there data associated with this OP ? */ | |
1577 | break; | |
f1c4cc75 RH |
1578 | case DW_OP_GNU_encoded_addr: |
1579 | { | |
6937bb54 | 1580 | int encoding = 0; |
f1c4cc75 | 1581 | dwarf_vma addr; |
467c65bc | 1582 | |
6937bb54 NC |
1583 | if (data < end) |
1584 | encoding = *data++; | |
041830e0 | 1585 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1586 | |
1587 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1588 | print_dwarf_vma (addr, pointer_size); | |
1589 | } | |
1590 | break; | |
bc0a77d2 | 1591 | case DW_OP_implicit_pointer: |
b7807392 | 1592 | case DW_OP_GNU_implicit_pointer: |
d85bf2ba | 1593 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
b7807392 JJ |
1594 | this ought to be an 8-byte wide computation. */ |
1595 | if (dwarf_version == -1) | |
1596 | { | |
bc0a77d2 JK |
1597 | printf (_("(%s in frame info)"), |
1598 | (op == DW_OP_implicit_pointer | |
1599 | ? "DW_OP_implicit_pointer" | |
1600 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1601 | /* No way to tell where the next op is, so just bail. */ |
1602 | return need_frame_base; | |
1603 | } | |
1604 | if (dwarf_version == 2) | |
1605 | { | |
0c588247 | 1606 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1607 | } |
1608 | else | |
1609 | { | |
0c588247 | 1610 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1611 | } |
cd30bcef | 1612 | READ_SLEB (svalue, data, end); |
bc0a77d2 JK |
1613 | printf ("%s: <0x%s> %s", |
1614 | (op == DW_OP_implicit_pointer | |
1615 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 | 1616 | dwarf_vmatoa ("x", uvalue), |
cd30bcef | 1617 | dwarf_vmatoa ("d", svalue)); |
b7807392 | 1618 | break; |
77145576 | 1619 | case DW_OP_entry_value: |
0892011d | 1620 | case DW_OP_GNU_entry_value: |
cd30bcef | 1621 | READ_ULEB (uvalue, data, end); |
058037d3 NC |
1622 | /* PR 17531: file: 0cc9cd00. */ |
1623 | if (uvalue > (dwarf_vma) (end - data)) | |
1624 | uvalue = end - data; | |
77145576 JK |
1625 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1626 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1627 | if (decode_location_expression (data, pointer_size, offset_size, |
1628 | dwarf_version, uvalue, | |
1629 | cu_offset, section)) | |
1630 | need_frame_base = 1; | |
1631 | putchar (')'); | |
1632 | data += uvalue; | |
6937bb54 NC |
1633 | if (data > end) |
1634 | data = end; | |
0892011d | 1635 | break; |
bc0a77d2 | 1636 | case DW_OP_const_type: |
0892011d | 1637 | case DW_OP_GNU_const_type: |
cd30bcef | 1638 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1639 | printf ("%s: <0x%s> ", |
1640 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1641 | : "DW_OP_GNU_const_type"), | |
0892011d | 1642 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1643 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1644 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1645 | break; |
bc0a77d2 | 1646 | case DW_OP_regval_type: |
0892011d | 1647 | case DW_OP_GNU_regval_type: |
cd30bcef | 1648 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1649 | printf ("%s: %s (%s)", |
1650 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1651 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1652 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
cd30bcef | 1653 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1654 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1655 | break; | |
bc0a77d2 | 1656 | case DW_OP_deref_type: |
0892011d | 1657 | case DW_OP_GNU_deref_type: |
0c588247 | 1658 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1659 | printf ("%s: %ld", |
1660 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1661 | : "DW_OP_GNU_deref_type"), | |
1662 | (long) uvalue); | |
cd30bcef | 1663 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1664 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1665 | break; | |
bc0a77d2 | 1666 | case DW_OP_convert: |
0892011d | 1667 | case DW_OP_GNU_convert: |
cd30bcef | 1668 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1669 | printf ("%s <0x%s>", |
1670 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1671 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1672 | break; |
bc0a77d2 | 1673 | case DW_OP_reinterpret: |
0892011d | 1674 | case DW_OP_GNU_reinterpret: |
cd30bcef | 1675 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1676 | printf ("%s <0x%s>", |
1677 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1678 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1679 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1680 | break; | |
1681 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1682 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1683 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1684 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1685 | break; |
b4eb7656 | 1686 | case DW_OP_GNU_addr_index: |
cd30bcef | 1687 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1688 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1689 | break; | |
1690 | case DW_OP_GNU_const_index: | |
cd30bcef | 1691 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1692 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1693 | break; | |
f384a1f0 KB |
1694 | case DW_OP_GNU_variable_value: |
1695 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1696 | this ought to be an 8-byte wide computation. */ | |
1697 | if (dwarf_version == -1) | |
1698 | { | |
1699 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1700 | /* No way to tell where the next op is, so just bail. */ | |
1701 | return need_frame_base; | |
1702 | } | |
1703 | if (dwarf_version == 2) | |
1704 | { | |
1705 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1706 | } | |
1707 | else | |
1708 | { | |
1709 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1710 | } | |
1711 | printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1712 | break; | |
e2a0d921 NC |
1713 | |
1714 | /* HP extensions. */ | |
1715 | case DW_OP_HP_is_value: | |
1716 | printf ("DW_OP_HP_is_value"); | |
1717 | /* FIXME: Is there data associated with this OP ? */ | |
1718 | break; | |
1719 | case DW_OP_HP_fltconst4: | |
1720 | printf ("DW_OP_HP_fltconst4"); | |
1721 | /* FIXME: Is there data associated with this OP ? */ | |
1722 | break; | |
1723 | case DW_OP_HP_fltconst8: | |
1724 | printf ("DW_OP_HP_fltconst8"); | |
1725 | /* FIXME: Is there data associated with this OP ? */ | |
1726 | break; | |
1727 | case DW_OP_HP_mod_range: | |
1728 | printf ("DW_OP_HP_mod_range"); | |
1729 | /* FIXME: Is there data associated with this OP ? */ | |
1730 | break; | |
1731 | case DW_OP_HP_unmod_range: | |
1732 | printf ("DW_OP_HP_unmod_range"); | |
1733 | /* FIXME: Is there data associated with this OP ? */ | |
1734 | break; | |
1735 | case DW_OP_HP_tls: | |
1736 | printf ("DW_OP_HP_tls"); | |
1737 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1738 | break; |
1739 | ||
35d60fe4 NC |
1740 | /* PGI (STMicroelectronics) extensions. */ |
1741 | case DW_OP_PGI_omp_thread_num: | |
1742 | /* Pushes the thread number for the current thread as it would be | |
1743 | returned by the standard OpenMP library function: | |
1744 | omp_get_thread_num(). The "current thread" is the thread for | |
1745 | which the expression is being evaluated. */ | |
1746 | printf ("DW_OP_PGI_omp_thread_num"); | |
1747 | break; | |
1748 | ||
19e6b90e L |
1749 | default: |
1750 | if (op >= DW_OP_lo_user | |
1751 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1752 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1753 | else |
0502a2b4 | 1754 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1755 | /* No way to tell where the next op is, so just bail. */ |
1756 | return need_frame_base; | |
1757 | } | |
1758 | ||
1759 | /* Separate the ops. */ | |
1760 | if (data < end) | |
1761 | printf ("; "); | |
1762 | } | |
1763 | ||
1764 | return need_frame_base; | |
1765 | } | |
1766 | ||
341f9135 CC |
1767 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1768 | This is used for DWARF package files. */ | |
1769 | ||
1770 | static struct cu_tu_set * | |
1771 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1772 | { | |
1773 | struct cu_tu_set *p; | |
1774 | unsigned int nsets; | |
1775 | unsigned int dw_sect; | |
1776 | ||
1777 | if (do_types) | |
1778 | { | |
1779 | p = tu_sets; | |
1780 | nsets = tu_count; | |
1781 | dw_sect = DW_SECT_TYPES; | |
1782 | } | |
1783 | else | |
1784 | { | |
1785 | p = cu_sets; | |
1786 | nsets = cu_count; | |
1787 | dw_sect = DW_SECT_INFO; | |
1788 | } | |
1789 | while (nsets > 0) | |
1790 | { | |
1791 | if (p->section_offsets [dw_sect] == cu_offset) | |
1792 | return p; | |
1793 | p++; | |
1794 | nsets--; | |
1795 | } | |
1796 | return NULL; | |
1797 | } | |
1798 | ||
a69c4772 NC |
1799 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1800 | static void | |
1801 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1802 | { | |
1803 | dwarf_vma tmp = * low_bits; | |
1804 | ||
1805 | tmp += inc; | |
1806 | ||
1807 | /* FIXME: There is probably a better way of handling this: | |
1808 | ||
1809 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1810 | type. Plus regardless of its size LOW_BITS is meant to | |
1811 | only hold 32-bits, so if there is overflow or wrap around | |
1812 | we must propagate into HIGH_BITS. */ | |
1813 | if (tmp < * low_bits) | |
1814 | { | |
1815 | ++ * high_bits; | |
1816 | } | |
1817 | else if (sizeof (tmp) > 8 | |
1818 | && (tmp >> 31) > 1) | |
1819 | { | |
1820 | ++ * high_bits; | |
1821 | tmp &= 0xFFFFFFFF; | |
1822 | } | |
1823 | ||
1824 | * low_bits = tmp; | |
1825 | } | |
1826 | ||
dda8d76d NC |
1827 | static const char * |
1828 | fetch_alt_indirect_string (dwarf_vma offset) | |
1829 | { | |
24841daa | 1830 | separate_info * i; |
dda8d76d NC |
1831 | |
1832 | if (! do_follow_links) | |
1833 | return ""; | |
1834 | ||
24841daa NC |
1835 | if (first_separate_info == NULL) |
1836 | return _("<no links available>"); | |
dda8d76d | 1837 | |
24841daa NC |
1838 | for (i = first_separate_info; i != NULL; i = i->next) |
1839 | { | |
1840 | struct dwarf_section * section; | |
1841 | const char * ret; | |
dda8d76d | 1842 | |
24841daa NC |
1843 | if (! load_debug_section (separate_debug_str, i->handle)) |
1844 | continue; | |
dda8d76d | 1845 | |
24841daa | 1846 | section = &debug_displays [separate_debug_str].section; |
dda8d76d | 1847 | |
24841daa NC |
1848 | if (section->start == NULL) |
1849 | continue; | |
dda8d76d | 1850 | |
24841daa NC |
1851 | if (offset >= section->size) |
1852 | continue; | |
1853 | ||
1854 | ret = (const char *) (section->start + offset); | |
1855 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1856 | NUL byte. Since our caller is expecting to receive a well formed C | |
1857 | string we test for the lack of a terminating byte here. */ | |
1858 | if (strnlen ((const char *) ret, section->size - offset) | |
1859 | == section->size - offset) | |
1860 | return _("<no NUL byte at end of alt .debug_str section>"); | |
1861 | ||
1862 | return ret; | |
1863 | } | |
521d4b19 | 1864 | |
24841daa NC |
1865 | warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"), |
1866 | dwarf_vmatoa ("x", offset)); | |
1867 | return _("<offset is too big>"); | |
dda8d76d NC |
1868 | } |
1869 | ||
d85bf2ba NC |
1870 | static const char * |
1871 | get_AT_name (unsigned long attribute) | |
1872 | { | |
1873 | const char *name; | |
1874 | ||
1875 | if (attribute == 0) | |
1876 | return "DW_AT value: 0"; | |
1877 | ||
1878 | /* One value is shared by the MIPS and HP extensions: */ | |
1879 | if (attribute == DW_AT_MIPS_fde) | |
1880 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1881 | ||
1882 | name = get_DW_AT_name (attribute); | |
1883 | ||
1884 | if (name == NULL) | |
1885 | { | |
1886 | static char buffer[100]; | |
1887 | ||
1888 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1889 | attribute); | |
1890 | return buffer; | |
1891 | } | |
1892 | ||
1893 | return name; | |
1894 | } | |
1895 | ||
24841daa | 1896 | static void |
50ea0877 | 1897 | add_dwo_info (const char * value, dwarf_vma cu_offset, dwo_type type) |
24841daa NC |
1898 | { |
1899 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); | |
1900 | ||
50ea0877 NC |
1901 | dwinfo->type = type; |
1902 | dwinfo->value = value; | |
1903 | dwinfo->cu_offset = cu_offset; | |
1904 | dwinfo->next = first_dwo_info; | |
24841daa NC |
1905 | first_dwo_info = dwinfo; |
1906 | } | |
1907 | ||
1908 | static void | |
50ea0877 | 1909 | add_dwo_name (const char * name, dwarf_vma cu_offset) |
24841daa | 1910 | { |
50ea0877 | 1911 | add_dwo_info (name, cu_offset, DWO_NAME); |
24841daa NC |
1912 | } |
1913 | ||
1914 | static void | |
50ea0877 | 1915 | add_dwo_dir (const char * dir, dwarf_vma cu_offset) |
24841daa | 1916 | { |
50ea0877 | 1917 | add_dwo_info (dir, cu_offset, DWO_DIR); |
24841daa NC |
1918 | } |
1919 | ||
1920 | static void | |
50ea0877 | 1921 | add_dwo_id (const char * id, dwarf_vma cu_offset) |
24841daa | 1922 | { |
50ea0877 | 1923 | add_dwo_info (id, cu_offset, DWO_ID); |
24841daa NC |
1924 | } |
1925 | ||
1926 | static void | |
1927 | free_dwo_info (void) | |
1928 | { | |
1929 | dwo_info * dwinfo; | |
1930 | dwo_info * next; | |
1931 | ||
1932 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) | |
1933 | { | |
1934 | next = dwinfo->next; | |
1935 | free (dwinfo); | |
1936 | } | |
1937 | first_dwo_info = NULL; | |
1938 | } | |
1939 | ||
afc72f15 NC |
1940 | /* Ensure that START + UVALUE is less than END. |
1941 | Return an adjusted UVALUE if necessary to ensure this relationship. */ | |
1942 | ||
1943 | static inline dwarf_vma | |
1944 | check_uvalue (const unsigned char * start, | |
1945 | dwarf_vma uvalue, | |
1946 | const unsigned char * end) | |
1947 | { | |
1948 | dwarf_vma max_uvalue = end - start; | |
1949 | ||
afc72f15 NC |
1950 | /* See PR 17512: file: 008-103549-0.001:0.1. |
1951 | and PR 24829 for examples of where these tests are triggered. */ | |
a85eba51 | 1952 | if (uvalue > max_uvalue) |
afc72f15 NC |
1953 | { |
1954 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1955 | uvalue = max_uvalue; | |
1956 | } | |
1957 | ||
1958 | return uvalue; | |
1959 | } | |
1960 | ||
ec1b0fbb NC |
1961 | static unsigned char * |
1962 | skip_attr_bytes (unsigned long form, | |
1963 | unsigned char * data, | |
1964 | unsigned const char * end, | |
1965 | dwarf_vma pointer_size, | |
1966 | dwarf_vma offset_size, | |
1967 | int dwarf_version, | |
1968 | dwarf_vma * value_return) | |
1969 | { | |
cd30bcef AM |
1970 | dwarf_signed_vma svalue; |
1971 | dwarf_vma uvalue = 0; | |
ec1b0fbb NC |
1972 | |
1973 | * value_return = 0; | |
1974 | ||
1975 | switch (form) | |
1976 | { | |
1977 | case DW_FORM_ref_addr: | |
1978 | if (dwarf_version == 2) | |
1979 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
59624513 | 1980 | else if (dwarf_version > 2) |
ec1b0fbb NC |
1981 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1982 | else | |
1983 | return NULL; | |
1984 | break; | |
1985 | ||
1986 | case DW_FORM_addr: | |
1987 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1988 | break; | |
1989 | ||
1990 | case DW_FORM_strp: | |
1991 | case DW_FORM_line_strp: | |
1992 | case DW_FORM_sec_offset: | |
1993 | case DW_FORM_GNU_ref_alt: | |
1994 | case DW_FORM_GNU_strp_alt: | |
1995 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1996 | break; | |
1997 | ||
1998 | case DW_FORM_flag_present: | |
1999 | uvalue = 1; | |
2000 | break; | |
2001 | ||
2002 | case DW_FORM_ref1: | |
2003 | case DW_FORM_flag: | |
2004 | case DW_FORM_data1: | |
32e4f96c TV |
2005 | case DW_FORM_strx1: |
2006 | case DW_FORM_addrx1: | |
ec1b0fbb NC |
2007 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2008 | break; | |
2009 | ||
32e4f96c TV |
2010 | case DW_FORM_strx3: |
2011 | case DW_FORM_addrx3: | |
2012 | SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); | |
2013 | break; | |
2014 | ||
ec1b0fbb NC |
2015 | case DW_FORM_ref2: |
2016 | case DW_FORM_data2: | |
32e4f96c TV |
2017 | case DW_FORM_strx2: |
2018 | case DW_FORM_addrx2: | |
ec1b0fbb NC |
2019 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2020 | break; | |
2021 | ||
2022 | case DW_FORM_ref4: | |
2023 | case DW_FORM_data4: | |
32e4f96c TV |
2024 | case DW_FORM_strx4: |
2025 | case DW_FORM_addrx4: | |
ec1b0fbb NC |
2026 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2027 | break; | |
2028 | ||
2029 | case DW_FORM_sdata: | |
cd30bcef AM |
2030 | READ_SLEB (svalue, data, end); |
2031 | uvalue = svalue; | |
ec1b0fbb NC |
2032 | break; |
2033 | ||
2034 | case DW_FORM_ref_udata: | |
2035 | case DW_FORM_udata: | |
2036 | case DW_FORM_GNU_str_index: | |
32e4f96c | 2037 | case DW_FORM_strx: |
ec1b0fbb | 2038 | case DW_FORM_GNU_addr_index: |
32e4f96c | 2039 | case DW_FORM_addrx: |
cd30bcef | 2040 | READ_ULEB (uvalue, data, end); |
ec1b0fbb NC |
2041 | break; |
2042 | ||
2043 | case DW_FORM_ref8: | |
1f573141 NC |
2044 | { |
2045 | dwarf_vma high_bits; | |
2046 | ||
2047 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); | |
2048 | data += 8; | |
2049 | if (sizeof (uvalue) > 4) | |
2050 | uvalue += high_bits << 32; | |
2051 | else if (high_bits != 0) | |
2052 | { | |
2053 | /* FIXME: What to do ? */ | |
2054 | return NULL; | |
2055 | } | |
2056 | break; | |
2057 | } | |
2058 | ||
ec1b0fbb | 2059 | case DW_FORM_data8: |
59624513 | 2060 | case DW_FORM_ref_sig8: |
ec1b0fbb NC |
2061 | data += 8; |
2062 | break; | |
2063 | ||
2064 | case DW_FORM_data16: | |
2065 | data += 16; | |
2066 | break; | |
2067 | ||
2068 | case DW_FORM_string: | |
2069 | data += strnlen ((char *) data, end - data) + 1; | |
2070 | break; | |
2071 | ||
2072 | case DW_FORM_block: | |
2073 | case DW_FORM_exprloc: | |
cd30bcef | 2074 | READ_ULEB (uvalue, data, end); |
59624513 | 2075 | data += uvalue; |
ec1b0fbb NC |
2076 | break; |
2077 | ||
2078 | case DW_FORM_block1: | |
2079 | SAFE_BYTE_GET (uvalue, data, 1, end); | |
2080 | data += 1 + uvalue; | |
2081 | break; | |
2082 | ||
2083 | case DW_FORM_block2: | |
2084 | SAFE_BYTE_GET (uvalue, data, 2, end); | |
2085 | data += 2 + uvalue; | |
2086 | break; | |
2087 | ||
2088 | case DW_FORM_block4: | |
2089 | SAFE_BYTE_GET (uvalue, data, 4, end); | |
2090 | data += 4 + uvalue; | |
2091 | break; | |
2092 | ||
ec1b0fbb | 2093 | case DW_FORM_indirect: |
59624513 NC |
2094 | READ_ULEB (form, data, end); |
2095 | if (form == DW_FORM_implicit_const) | |
2096 | SKIP_ULEB (data, end); | |
2097 | return skip_attr_bytes (form, data, end, pointer_size, offset_size, dwarf_version, value_return); | |
2098 | ||
ec1b0fbb NC |
2099 | default: |
2100 | return NULL; | |
2101 | } | |
2102 | ||
2103 | * value_return = uvalue; | |
2104 | if (data > end) | |
2105 | data = (unsigned char *) end; | |
2106 | return data; | |
2107 | } | |
2108 | ||
bcd213b2 NC |
2109 | /* Given form FORM with value UVALUE, locate and return the abbreviation |
2110 | associated with it. */ | |
2111 | ||
2112 | static abbrev_entry * | |
2113 | get_type_abbrev_from_form (unsigned long form, | |
2114 | unsigned long uvalue, | |
2115 | dwarf_vma cu_offset, | |
2116 | const struct dwarf_section * section, | |
2117 | unsigned long * abbrev_num_return, | |
2118 | unsigned char ** data_return, | |
2119 | unsigned long * cu_offset_return) | |
2120 | { | |
2121 | unsigned long abbrev_number; | |
2122 | abbrev_map * map; | |
2123 | abbrev_entry * entry; | |
2124 | unsigned char * data; | |
2125 | ||
2126 | if (abbrev_num_return != NULL) | |
2127 | * abbrev_num_return = 0; | |
2128 | if (data_return != NULL) | |
2129 | * data_return = NULL; | |
2130 | ||
2131 | switch (form) | |
2132 | { | |
2133 | case DW_FORM_GNU_ref_alt: | |
5f128a25 | 2134 | case DW_FORM_ref_sig8: |
bcd213b2 NC |
2135 | /* FIXME: We are unable to handle this form at the moment. */ |
2136 | return NULL; | |
2137 | ||
2138 | case DW_FORM_ref_addr: | |
2139 | if (uvalue >= section->size) | |
2140 | { | |
2141 | warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"), | |
2142 | uvalue, (long) section->size, section->name); | |
2143 | return NULL; | |
2144 | } | |
2145 | break; | |
2146 | ||
e38332c2 NC |
2147 | case DW_FORM_ref_sup4: |
2148 | case DW_FORM_ref_sup8: | |
2149 | break; | |
2150 | ||
bcd213b2 NC |
2151 | case DW_FORM_ref1: |
2152 | case DW_FORM_ref2: | |
2153 | case DW_FORM_ref4: | |
1f573141 | 2154 | case DW_FORM_ref8: |
bcd213b2 NC |
2155 | case DW_FORM_ref_udata: |
2156 | if (uvalue + cu_offset > section->size) | |
2157 | { | |
2158 | warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > section size %lx\n"), | |
2159 | uvalue, (long) cu_offset, (long) section->size); | |
2160 | return NULL; | |
2161 | } | |
2162 | uvalue += cu_offset; | |
2163 | break; | |
2164 | ||
2165 | /* FIXME: Are there other DW_FORMs that can be used by types ? */ | |
2166 | ||
2167 | default: | |
2168 | warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form); | |
2169 | return NULL; | |
2170 | } | |
2171 | ||
2172 | data = (unsigned char *) section->start + uvalue; | |
2173 | map = find_abbrev_map_by_offset (uvalue); | |
521d4b19 | 2174 | |
bcd213b2 NC |
2175 | if (map == NULL) |
2176 | { | |
2177 | warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue); | |
2178 | return NULL; | |
2179 | } | |
2180 | if (map->list == NULL) | |
2181 | { | |
2182 | warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue); | |
2183 | return NULL; | |
2184 | } | |
2185 | ||
2186 | if (cu_offset_return != NULL) | |
2187 | { | |
2188 | if (form == DW_FORM_ref_addr) | |
2189 | * cu_offset_return = map->start; | |
2190 | else | |
2191 | * cu_offset_return = cu_offset; | |
2192 | } | |
2193 | ||
2194 | READ_ULEB (abbrev_number, data, section->start + section->size); | |
2195 | ||
2196 | for (entry = map->list->first_abbrev; entry != NULL; entry = entry->next) | |
2197 | if (entry->number == abbrev_number) | |
2198 | break; | |
521d4b19 | 2199 | |
bcd213b2 NC |
2200 | if (abbrev_num_return != NULL) |
2201 | * abbrev_num_return = abbrev_number; | |
2202 | ||
2203 | if (data_return != NULL) | |
2204 | * data_return = data; | |
2205 | ||
2206 | if (entry == NULL) | |
2207 | warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number); | |
2208 | ||
2209 | return entry; | |
2210 | } | |
2211 | ||
2212 | /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY | |
2213 | can be determined to be a signed type. The data for ENTRY can be | |
2214 | found starting at DATA. */ | |
ec1b0fbb NC |
2215 | |
2216 | static void | |
bcd213b2 NC |
2217 | get_type_signedness (abbrev_entry * entry, |
2218 | const struct dwarf_section * section, | |
ec1b0fbb NC |
2219 | unsigned char * data, |
2220 | unsigned const char * end, | |
bcd213b2 | 2221 | dwarf_vma cu_offset, |
ec1b0fbb NC |
2222 | dwarf_vma pointer_size, |
2223 | dwarf_vma offset_size, | |
2224 | int dwarf_version, | |
2225 | bfd_boolean * is_signed, | |
59624513 | 2226 | unsigned int nesting) |
ec1b0fbb | 2227 | { |
ec1b0fbb NC |
2228 | abbrev_attr * attr; |
2229 | ||
2230 | * is_signed = FALSE; | |
2231 | ||
59624513 NC |
2232 | #define MAX_NESTING 20 |
2233 | if (nesting > MAX_NESTING) | |
2234 | { | |
2235 | /* FIXME: Warn - or is this expected ? | |
2236 | NB/ We need to avoid infinite recursion. */ | |
2237 | return; | |
2238 | } | |
2239 | ||
ec1b0fbb NC |
2240 | for (attr = entry->first_attr; |
2241 | attr != NULL && attr->attribute; | |
2242 | attr = attr->next) | |
2243 | { | |
bcd213b2 | 2244 | unsigned char * orig_data = data; |
ec1b0fbb NC |
2245 | dwarf_vma uvalue = 0; |
2246 | ||
2247 | data = skip_attr_bytes (attr->form, data, end, pointer_size, | |
2248 | offset_size, dwarf_version, & uvalue); | |
2249 | if (data == NULL) | |
2250 | return; | |
2251 | ||
2252 | switch (attr->attribute) | |
2253 | { | |
bcd213b2 | 2254 | case DW_AT_linkage_name: |
ec1b0fbb | 2255 | case DW_AT_name: |
bcd213b2 NC |
2256 | if (do_wide) |
2257 | { | |
2258 | if (attr->form == DW_FORM_strp) | |
2259 | printf (", %s", fetch_indirect_string (uvalue)); | |
2260 | else if (attr->form == DW_FORM_string) | |
2261 | printf (", %s", orig_data); | |
2262 | } | |
ec1b0fbb | 2263 | break; |
bcd213b2 | 2264 | |
ec1b0fbb NC |
2265 | case DW_AT_type: |
2266 | /* Recurse. */ | |
bcd213b2 NC |
2267 | { |
2268 | abbrev_entry * type_abbrev; | |
2269 | unsigned char * type_data; | |
2270 | unsigned long type_cu_offset; | |
2271 | ||
2272 | type_abbrev = get_type_abbrev_from_form (attr->form, | |
2273 | uvalue, | |
2274 | cu_offset, | |
2275 | section, | |
2276 | NULL /* abbrev num return */, | |
2277 | & type_data, | |
2278 | & type_cu_offset); | |
2279 | if (type_abbrev == NULL) | |
2280 | break; | |
2281 | ||
2282 | get_type_signedness (type_abbrev, section, type_data, end, type_cu_offset, | |
2283 | pointer_size, offset_size, dwarf_version, | |
2284 | is_signed, nesting + 1); | |
2285 | } | |
ec1b0fbb NC |
2286 | break; |
2287 | ||
2288 | case DW_AT_encoding: | |
2289 | /* Determine signness. */ | |
2290 | switch (uvalue) | |
2291 | { | |
2292 | case DW_ATE_address: | |
2293 | /* FIXME - some architectures have signed addresses. */ | |
2294 | case DW_ATE_boolean: | |
2295 | case DW_ATE_unsigned: | |
2296 | case DW_ATE_unsigned_char: | |
2297 | case DW_ATE_unsigned_fixed: | |
2298 | * is_signed = FALSE; | |
2299 | break; | |
2300 | ||
2301 | default: | |
2302 | case DW_ATE_complex_float: | |
2303 | case DW_ATE_float: | |
2304 | case DW_ATE_signed: | |
2305 | case DW_ATE_signed_char: | |
2306 | case DW_ATE_imaginary_float: | |
2307 | case DW_ATE_decimal_float: | |
2308 | case DW_ATE_signed_fixed: | |
2309 | * is_signed = TRUE; | |
2310 | break; | |
2311 | } | |
2312 | break; | |
2313 | } | |
2314 | } | |
2315 | } | |
2316 | ||
2317 | static void | |
2318 | read_and_print_leb128 (unsigned char * data, | |
2319 | unsigned int * bytes_read, | |
2320 | unsigned const char * end, | |
2321 | bfd_boolean is_signed) | |
2322 | { | |
cd30bcef AM |
2323 | int status; |
2324 | dwarf_vma val = read_leb128 (data, end, is_signed, bytes_read, &status); | |
2325 | if (status != 0) | |
1b513401 | 2326 | report_leb_status (status, __FILE__, __LINE__); |
ec1b0fbb | 2327 | else |
cd30bcef | 2328 | printf ("%s", dwarf_vmatoa (is_signed ? "d" : "u", val)); |
ec1b0fbb NC |
2329 | } |
2330 | ||
2331 | static void | |
2332 | display_discr_list (unsigned long form, | |
2333 | dwarf_vma uvalue, | |
2334 | unsigned char * data, | |
2335 | unsigned const char * end, | |
2336 | int level) | |
2337 | { | |
2338 | if (uvalue == 0) | |
2339 | { | |
2340 | printf ("[default]"); | |
2341 | return; | |
2342 | } | |
521d4b19 | 2343 | |
ec1b0fbb NC |
2344 | switch (form) |
2345 | { | |
2346 | case DW_FORM_block: | |
2347 | case DW_FORM_block1: | |
2348 | case DW_FORM_block2: | |
2349 | case DW_FORM_block4: | |
2350 | /* Move data pointer back to the start of the byte array. */ | |
2351 | data -= uvalue; | |
2352 | break; | |
2353 | default: | |
2354 | printf ("<corrupt>\n"); | |
2355 | warn (_("corrupt discr_list - not using a block form\n")); | |
2356 | return; | |
2357 | } | |
2358 | ||
2359 | if (uvalue < 2) | |
2360 | { | |
2361 | printf ("<corrupt>\n"); | |
2362 | warn (_("corrupt discr_list - block not long enough\n")); | |
2363 | return; | |
2364 | } | |
2365 | ||
2366 | bfd_boolean is_signed = | |
2367 | (level > 0 && level <= MAX_CU_NESTING) | |
2368 | ? level_type_signed [level - 1] : FALSE; | |
521d4b19 | 2369 | |
ec1b0fbb NC |
2370 | printf ("("); |
2371 | while (uvalue) | |
2372 | { | |
2373 | unsigned char discriminant; | |
2374 | unsigned int bytes_read; | |
2375 | ||
2376 | SAFE_BYTE_GET (discriminant, data, 1, end); | |
2377 | -- uvalue; | |
2378 | data ++; | |
2379 | ||
2380 | assert (uvalue > 0); | |
2381 | switch (discriminant) | |
2382 | { | |
2383 | case DW_DSC_label: | |
2384 | printf ("label "); | |
2385 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2386 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2387 | uvalue -= bytes_read; | |
2388 | data += bytes_read; | |
2389 | break; | |
2390 | ||
2391 | case DW_DSC_range: | |
2392 | printf ("range "); | |
2393 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2394 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2395 | uvalue -= bytes_read; | |
2396 | data += bytes_read; | |
2397 | ||
2398 | printf (".."); | |
2399 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2400 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2401 | uvalue -= bytes_read; | |
2402 | data += bytes_read; | |
2403 | break; | |
2404 | ||
2405 | default: | |
2406 | printf ("<corrupt>\n"); | |
e38332c2 | 2407 | warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"), |
ec1b0fbb NC |
2408 | discriminant); |
2409 | return; | |
2410 | } | |
2411 | ||
2412 | if (uvalue) | |
2413 | printf (", "); | |
2414 | } | |
2415 | ||
2416 | if (is_signed) | |
2417 | printf (")(signed)"); | |
2418 | else | |
2419 | printf (")(unsigned)"); | |
2420 | } | |
2421 | ||
19e6b90e | 2422 | static unsigned char * |
dda8d76d NC |
2423 | read_and_display_attr_value (unsigned long attribute, |
2424 | unsigned long form, | |
2425 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 2426 | unsigned char * start, |
dda8d76d NC |
2427 | unsigned char * data, |
2428 | unsigned char * end, | |
2429 | dwarf_vma cu_offset, | |
2430 | dwarf_vma pointer_size, | |
2431 | dwarf_vma offset_size, | |
2432 | int dwarf_version, | |
2433 | debug_info * debug_info_p, | |
2434 | int do_loc, | |
2435 | struct dwarf_section * section, | |
2436 | struct cu_tu_set * this_set, | |
ec1b0fbb NC |
2437 | char delimiter, |
2438 | int level) | |
19e6b90e | 2439 | { |
cd30bcef | 2440 | dwarf_signed_vma svalue; |
ec1b0fbb NC |
2441 | dwarf_vma uvalue = 0; |
2442 | unsigned char * block_start = NULL; | |
2443 | unsigned char * orig_data = data; | |
19e6b90e | 2444 | |
f41e4712 | 2445 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 2446 | { |
f41e4712 | 2447 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
2448 | return data; |
2449 | } | |
2450 | ||
521d4b19 NC |
2451 | if (do_wide && ! do_loc) |
2452 | { | |
2453 | /* PR 26847: Display the name of the form. */ | |
2454 | const char * name = get_FORM_name (form); | |
2455 | ||
2456 | /* For convenience we skip the DW_FORM_ prefix to the name. */ | |
2457 | if (name[0] == 'D') | |
2458 | name += 8; /* strlen ("DW_FORM_") */ | |
2459 | printf ("%c(%s)", delimiter, name); | |
2460 | } | |
2461 | ||
19e6b90e L |
2462 | switch (form) |
2463 | { | |
2464 | default: | |
2465 | break; | |
2466 | ||
2467 | case DW_FORM_ref_addr: | |
2468 | if (dwarf_version == 2) | |
0c588247 | 2469 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
ec47b32a | 2470 | else if (dwarf_version > 2) |
0c588247 | 2471 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 2472 | else |
ec47b32a | 2473 | error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n")); |
19e6b90e L |
2474 | break; |
2475 | ||
2476 | case DW_FORM_addr: | |
0c588247 | 2477 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
2478 | break; |
2479 | ||
e38332c2 | 2480 | case DW_FORM_strp_sup: |
19e6b90e | 2481 | case DW_FORM_strp: |
77145576 | 2482 | case DW_FORM_line_strp: |
932fd279 | 2483 | case DW_FORM_sec_offset: |
a081f3cd JJ |
2484 | case DW_FORM_GNU_ref_alt: |
2485 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 2486 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
2487 | break; |
2488 | ||
932fd279 JJ |
2489 | case DW_FORM_flag_present: |
2490 | uvalue = 1; | |
2491 | break; | |
2492 | ||
19e6b90e L |
2493 | case DW_FORM_ref1: |
2494 | case DW_FORM_flag: | |
2495 | case DW_FORM_data1: | |
32e4f96c TV |
2496 | case DW_FORM_strx1: |
2497 | case DW_FORM_addrx1: | |
0c588247 | 2498 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
2499 | break; |
2500 | ||
2501 | case DW_FORM_ref2: | |
2502 | case DW_FORM_data2: | |
32e4f96c TV |
2503 | case DW_FORM_strx2: |
2504 | case DW_FORM_addrx2: | |
0c588247 | 2505 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
2506 | break; |
2507 | ||
32e4f96c TV |
2508 | case DW_FORM_strx3: |
2509 | case DW_FORM_addrx3: | |
2510 | SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); | |
2511 | break; | |
2512 | ||
e38332c2 | 2513 | case DW_FORM_ref_sup4: |
19e6b90e L |
2514 | case DW_FORM_ref4: |
2515 | case DW_FORM_data4: | |
32e4f96c TV |
2516 | case DW_FORM_strx4: |
2517 | case DW_FORM_addrx4: | |
0c588247 | 2518 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
2519 | break; |
2520 | ||
2521 | case DW_FORM_sdata: | |
cd30bcef AM |
2522 | READ_SLEB (svalue, data, end); |
2523 | uvalue = svalue; | |
19e6b90e L |
2524 | break; |
2525 | ||
4723351a | 2526 | case DW_FORM_GNU_str_index: |
32e4f96c | 2527 | case DW_FORM_strx: |
19e6b90e L |
2528 | case DW_FORM_ref_udata: |
2529 | case DW_FORM_udata: | |
cd30bcef | 2530 | case DW_FORM_GNU_addr_index: |
32e4f96c | 2531 | case DW_FORM_addrx: |
cd30bcef | 2532 | READ_ULEB (uvalue, data, end); |
19e6b90e L |
2533 | break; |
2534 | ||
2535 | case DW_FORM_indirect: | |
cd30bcef | 2536 | READ_ULEB (form, data, end); |
19e6b90e | 2537 | if (!do_loc) |
ef0b5f1c | 2538 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 | 2539 | if (form == DW_FORM_implicit_const) |
cd30bcef | 2540 | READ_SLEB (implicit_const, data, end); |
ec1b0fbb NC |
2541 | return read_and_display_attr_value (attribute, form, implicit_const, |
2542 | start, data, end, | |
2543 | cu_offset, pointer_size, | |
19e6b90e | 2544 | offset_size, dwarf_version, |
ec4d4525 | 2545 | debug_info_p, do_loc, |
ec1b0fbb | 2546 | section, this_set, delimiter, level); |
19e6b90e L |
2547 | } |
2548 | ||
2549 | switch (form) | |
2550 | { | |
2551 | case DW_FORM_ref_addr: | |
2552 | if (!do_loc) | |
bcd213b2 | 2553 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2554 | break; |
2555 | ||
a081f3cd JJ |
2556 | case DW_FORM_GNU_ref_alt: |
2557 | if (!do_loc) | |
521d4b19 NC |
2558 | { |
2559 | if (do_wide) | |
2560 | /* We have already printed the form name. */ | |
2561 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); | |
2562 | else | |
2563 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); | |
2564 | } | |
dda8d76d | 2565 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
2566 | break; |
2567 | ||
19e6b90e L |
2568 | case DW_FORM_ref1: |
2569 | case DW_FORM_ref2: | |
2570 | case DW_FORM_ref4: | |
e38332c2 | 2571 | case DW_FORM_ref_sup4: |
19e6b90e L |
2572 | case DW_FORM_ref_udata: |
2573 | if (!do_loc) | |
ef0b5f1c | 2574 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
2575 | break; |
2576 | ||
2577 | case DW_FORM_data4: | |
2578 | case DW_FORM_addr: | |
932fd279 | 2579 | case DW_FORM_sec_offset: |
19e6b90e | 2580 | if (!do_loc) |
ef0b5f1c | 2581 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2582 | break; |
2583 | ||
932fd279 | 2584 | case DW_FORM_flag_present: |
19e6b90e L |
2585 | case DW_FORM_flag: |
2586 | case DW_FORM_data1: | |
2587 | case DW_FORM_data2: | |
2588 | case DW_FORM_sdata: | |
2589 | case DW_FORM_udata: | |
2590 | if (!do_loc) | |
ef0b5f1c | 2591 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
2592 | break; |
2593 | ||
77145576 JK |
2594 | case DW_FORM_implicit_const: |
2595 | if (!do_loc) | |
2596 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
2597 | break; | |
2598 | ||
e38332c2 | 2599 | case DW_FORM_ref_sup8: |
19e6b90e L |
2600 | case DW_FORM_ref8: |
2601 | case DW_FORM_data8: | |
2bc8690c | 2602 | if (!do_loc) |
19e6b90e | 2603 | { |
74bc6052 | 2604 | dwarf_vma high_bits; |
a69c4772 | 2605 | dwarf_vma utmp; |
74bc6052 CC |
2606 | char buf[64]; |
2607 | ||
0c588247 | 2608 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
2609 | utmp = uvalue; |
2610 | if (form == DW_FORM_ref8) | |
2611 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 2612 | printf ("%c0x%s", delimiter, |
a69c4772 | 2613 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 2614 | } |
0c588247 | 2615 | |
19e6b90e L |
2616 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2617 | && num_debug_info_entries == 0) | |
2618 | { | |
2619 | if (sizeof (uvalue) == 8) | |
0c588247 | 2620 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 2621 | else |
467c65bc | 2622 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 2623 | } |
0c588247 | 2624 | |
19e6b90e L |
2625 | data += 8; |
2626 | break; | |
2627 | ||
2f6cd591 JK |
2628 | case DW_FORM_data16: |
2629 | if (!do_loc) | |
2630 | { | |
2631 | dwarf_vma left_high_bits, left_low_bits; | |
2632 | dwarf_vma right_high_bits, right_low_bits; | |
2633 | ||
2634 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
2635 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
2636 | if (byte_get == byte_get_little_endian) | |
2637 | { | |
2638 | /* Swap them. */ | |
2639 | left_high_bits ^= right_high_bits; | |
2640 | right_high_bits ^= left_high_bits; | |
2641 | left_high_bits ^= right_high_bits; | |
2642 | left_low_bits ^= right_low_bits; | |
2643 | right_low_bits ^= left_low_bits; | |
2644 | left_low_bits ^= right_low_bits; | |
2645 | } | |
2646 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
2647 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
2648 | left_high_bits, left_low_bits, right_high_bits, | |
2649 | right_low_bits); | |
2650 | } | |
2651 | data += 16; | |
2652 | break; | |
2653 | ||
19e6b90e L |
2654 | case DW_FORM_string: |
2655 | if (!do_loc) | |
ef0b5f1c | 2656 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 2657 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
2658 | break; |
2659 | ||
2660 | case DW_FORM_block: | |
932fd279 | 2661 | case DW_FORM_exprloc: |
cd30bcef AM |
2662 | READ_ULEB (uvalue, data, end); |
2663 | do_block: | |
2664 | block_start = data; | |
a1165289 NC |
2665 | if (block_start >= end) |
2666 | { | |
2667 | warn (_("Block ends prematurely\n")); | |
2668 | uvalue = 0; | |
2669 | block_start = end; | |
2670 | } | |
afc72f15 NC |
2671 | |
2672 | uvalue = check_uvalue (block_start, uvalue, end); | |
2673 | ||
19e6b90e L |
2674 | if (do_loc) |
2675 | data = block_start + uvalue; | |
2676 | else | |
ef0b5f1c | 2677 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2678 | break; |
2679 | ||
2680 | case DW_FORM_block1: | |
cd30bcef AM |
2681 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2682 | goto do_block; | |
19e6b90e L |
2683 | |
2684 | case DW_FORM_block2: | |
cd30bcef AM |
2685 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2686 | goto do_block; | |
19e6b90e L |
2687 | |
2688 | case DW_FORM_block4: | |
cd30bcef AM |
2689 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2690 | goto do_block; | |
19e6b90e L |
2691 | |
2692 | case DW_FORM_strp: | |
2693 | if (!do_loc) | |
521d4b19 NC |
2694 | { |
2695 | if (do_wide) | |
2696 | /* We have already displayed the form name. */ | |
2697 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2698 | dwarf_vmatoa ("x", uvalue), | |
2699 | fetch_indirect_string (uvalue)); | |
2700 | else | |
2701 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, | |
2702 | dwarf_vmatoa ("x", uvalue), | |
2703 | fetch_indirect_string (uvalue)); | |
2704 | } | |
19e6b90e L |
2705 | break; |
2706 | ||
77145576 JK |
2707 | case DW_FORM_line_strp: |
2708 | if (!do_loc) | |
521d4b19 NC |
2709 | { |
2710 | if (do_wide) | |
2711 | /* We have already displayed the form name. */ | |
2712 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2713 | dwarf_vmatoa ("x", uvalue), | |
2714 | fetch_indirect_line_string (uvalue)); | |
2715 | else | |
2716 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2717 | dwarf_vmatoa ("x", uvalue), | |
2718 | fetch_indirect_line_string (uvalue)); | |
2719 | } | |
77145576 JK |
2720 | break; |
2721 | ||
4723351a | 2722 | case DW_FORM_GNU_str_index: |
32e4f96c TV |
2723 | case DW_FORM_strx: |
2724 | case DW_FORM_strx1: | |
2725 | case DW_FORM_strx2: | |
2726 | case DW_FORM_strx3: | |
2727 | case DW_FORM_strx4: | |
4723351a | 2728 | if (!do_loc) |
b4eb7656 | 2729 | { |
d85bf2ba NC |
2730 | const char * suffix = strrchr (section->name, '.'); |
2731 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
b4eb7656 | 2732 | |
521d4b19 NC |
2733 | if (do_wide) |
2734 | /* We have already displayed the form name. */ | |
2735 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2736 | dwarf_vmatoa ("x", uvalue), | |
2737 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2738 | else | |
2739 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, | |
2740 | dwarf_vmatoa ("x", uvalue), | |
2741 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
b4eb7656 | 2742 | } |
4723351a CC |
2743 | break; |
2744 | ||
a081f3cd JJ |
2745 | case DW_FORM_GNU_strp_alt: |
2746 | if (!do_loc) | |
dda8d76d | 2747 | { |
521d4b19 NC |
2748 | if (do_wide) |
2749 | /* We have already displayed the form name. */ | |
2750 | printf (_("%c(offset: 0x%s) %s"), delimiter, | |
2751 | dwarf_vmatoa ("x", uvalue), | |
2752 | fetch_alt_indirect_string (uvalue)); | |
2753 | else | |
2754 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2755 | dwarf_vmatoa ("x", uvalue), | |
2756 | fetch_alt_indirect_string (uvalue)); | |
dda8d76d | 2757 | } |
a081f3cd JJ |
2758 | break; |
2759 | ||
19e6b90e L |
2760 | case DW_FORM_indirect: |
2761 | /* Handled above. */ | |
2762 | break; | |
2763 | ||
2b6f5997 CC |
2764 | case DW_FORM_ref_sig8: |
2765 | if (!do_loc) | |
2766 | { | |
74bc6052 CC |
2767 | dwarf_vma high_bits; |
2768 | char buf[64]; | |
2769 | ||
0c588247 | 2770 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
521d4b19 NC |
2771 | if (do_wide) |
2772 | /* We have already displayed the form name. */ | |
2773 | printf ("%c: 0x%s", delimiter, | |
2774 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); | |
2775 | else | |
2776 | printf ("%csignature: 0x%s", delimiter, | |
2777 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); | |
2b6f5997 | 2778 | } |
74bc6052 | 2779 | data += 8; |
2b6f5997 CC |
2780 | break; |
2781 | ||
4723351a | 2782 | case DW_FORM_GNU_addr_index: |
32e4f96c TV |
2783 | case DW_FORM_addrx: |
2784 | case DW_FORM_addrx1: | |
2785 | case DW_FORM_addrx2: | |
2786 | case DW_FORM_addrx3: | |
2787 | case DW_FORM_addrx4: | |
4723351a | 2788 | if (!do_loc) |
521d4b19 | 2789 | { |
32e4f96c TV |
2790 | dwarf_vma base; |
2791 | dwarf_vma offset; | |
2792 | ||
2793 | if (debug_info_p == NULL) | |
2794 | base = 0; | |
2795 | else if (debug_info_p->addr_base == DEBUG_INFO_UNAVAILABLE) | |
2796 | base = 0; | |
2797 | else | |
2798 | base = debug_info_p->addr_base; | |
2799 | ||
2800 | offset = base + uvalue * pointer_size; | |
2801 | ||
521d4b19 NC |
2802 | if (do_wide) |
2803 | /* We have already displayed the form name. */ | |
2804 | printf (_("%c(index: 0x%s): %s"), delimiter, | |
2805 | dwarf_vmatoa ("x", uvalue), | |
32e4f96c | 2806 | fetch_indexed_value (offset, pointer_size)); |
521d4b19 NC |
2807 | else |
2808 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, | |
2809 | dwarf_vmatoa ("x", uvalue), | |
32e4f96c | 2810 | fetch_indexed_value (offset, pointer_size)); |
521d4b19 | 2811 | } |
4723351a CC |
2812 | break; |
2813 | ||
e38332c2 NC |
2814 | case DW_FORM_strp_sup: |
2815 | if (!do_loc) | |
2816 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); | |
2817 | break; | |
2818 | ||
19e6b90e | 2819 | default: |
e38332c2 | 2820 | warn (_("Unrecognized form: 0x%lx\n"), form); |
19e6b90e L |
2821 | break; |
2822 | } | |
2823 | ||
19e6b90e | 2824 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2825 | && num_debug_info_entries == 0 |
2826 | && debug_info_p != NULL) | |
19e6b90e L |
2827 | { |
2828 | switch (attribute) | |
2829 | { | |
2830 | case DW_AT_frame_base: | |
2831 | have_frame_base = 1; | |
1a0670f3 | 2832 | /* Fall through. */ |
19e6b90e | 2833 | case DW_AT_location: |
9f272209 | 2834 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2835 | case DW_AT_string_length: |
2836 | case DW_AT_return_addr: | |
19e6b90e L |
2837 | case DW_AT_data_member_location: |
2838 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2839 | case DW_AT_segment: |
2840 | case DW_AT_static_link: | |
2841 | case DW_AT_use_location: | |
bc0a77d2 | 2842 | case DW_AT_call_value: |
629e7ca8 | 2843 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2844 | case DW_AT_call_data_value: |
629e7ca8 | 2845 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2846 | case DW_AT_call_target: |
629e7ca8 | 2847 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2848 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2849 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2850 | if ((dwarf_version < 4 |
212b6063 | 2851 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2852 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2853 | { |
2854 | /* Process location list. */ | |
91d6fa6a | 2855 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2856 | unsigned int num = debug_info_p->num_loc_offsets; |
2857 | ||
91d6fa6a | 2858 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2859 | { |
91d6fa6a | 2860 | lmax += 1024; |
467c65bc | 2861 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2862 | xcrealloc (debug_info_p->loc_offsets, |
2863 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2864 | debug_info_p->loc_views = (dwarf_vma *) |
2865 | xcrealloc (debug_info_p->loc_views, | |
2866 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2867 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2868 | xcrealloc (debug_info_p->have_frame_base, |
2869 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2870 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2871 | } |
341f9135 | 2872 | if (this_set != NULL) |
b4eb7656 | 2873 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2874 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2875 | if (attribute != DW_AT_GNU_locviews) |
2876 | { | |
a7504f87 NC |
2877 | /* Corrupt DWARF info can produce more offsets than views. |
2878 | See PR 23062 for an example. */ | |
2879 | if (debug_info_p->num_loc_offsets | |
2880 | > debug_info_p->num_loc_views) | |
2881 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2882 | else | |
2883 | { | |
2884 | debug_info_p->loc_offsets [num] = uvalue; | |
2885 | debug_info_p->num_loc_offsets++; | |
2886 | } | |
9f272209 AO |
2887 | } |
2888 | else | |
2889 | { | |
2890 | assert (debug_info_p->num_loc_views <= num); | |
2891 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2892 | if (num > debug_info_p->num_loc_offsets) |
2893 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2894 | else | |
2895 | { | |
2896 | debug_info_p->loc_views [num] = uvalue; | |
2897 | debug_info_p->num_loc_views++; | |
2898 | } | |
9f272209 | 2899 | } |
19e6b90e L |
2900 | } |
2901 | break; | |
e2a0d921 | 2902 | |
19e6b90e L |
2903 | case DW_AT_low_pc: |
2904 | if (need_base_address) | |
2905 | debug_info_p->base_address = uvalue; | |
2906 | break; | |
2907 | ||
4723351a | 2908 | case DW_AT_GNU_addr_base: |
32e4f96c | 2909 | case DW_AT_addr_base: |
b4eb7656 | 2910 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2911 | break; |
2912 | ||
2913 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2914 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2915 | break; |
2916 | ||
19e6b90e | 2917 | case DW_AT_ranges: |
b4eb7656 | 2918 | if ((dwarf_version < 4 |
212b6063 | 2919 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2920 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2921 | { |
2922 | /* Process range list. */ | |
91d6fa6a | 2923 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2924 | unsigned int num = debug_info_p->num_range_lists; |
2925 | ||
91d6fa6a | 2926 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2927 | { |
91d6fa6a | 2928 | lmax += 1024; |
467c65bc | 2929 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2930 | xcrealloc (debug_info_p->range_lists, |
2931 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2932 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2933 | } |
2934 | debug_info_p->range_lists [num] = uvalue; | |
2935 | debug_info_p->num_range_lists++; | |
2936 | } | |
2937 | break; | |
2938 | ||
d85bf2ba NC |
2939 | case DW_AT_GNU_dwo_name: |
2940 | case DW_AT_dwo_name: | |
2941 | if (need_dwo_info) | |
2942 | switch (form) | |
2943 | { | |
2944 | case DW_FORM_strp: | |
50ea0877 | 2945 | add_dwo_name ((const char *) fetch_indirect_string (uvalue), cu_offset); |
d85bf2ba | 2946 | break; |
5568cc9e | 2947 | case DW_FORM_GNU_strp_alt: |
50ea0877 | 2948 | add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue), cu_offset); |
5568cc9e | 2949 | break; |
d85bf2ba | 2950 | case DW_FORM_GNU_str_index: |
32e4f96c TV |
2951 | case DW_FORM_strx: |
2952 | case DW_FORM_strx1: | |
2953 | case DW_FORM_strx2: | |
2954 | case DW_FORM_strx3: | |
2955 | case DW_FORM_strx4: | |
50ea0877 | 2956 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, FALSE), cu_offset); |
d85bf2ba NC |
2957 | break; |
2958 | case DW_FORM_string: | |
50ea0877 | 2959 | add_dwo_name ((const char *) orig_data, cu_offset); |
d85bf2ba NC |
2960 | break; |
2961 | default: | |
2962 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2963 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2964 | break; |
2965 | } | |
2966 | break; | |
521d4b19 | 2967 | |
d85bf2ba NC |
2968 | case DW_AT_comp_dir: |
2969 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2970 | if (need_dwo_info) | |
2971 | switch (form) | |
2972 | { | |
2973 | case DW_FORM_strp: | |
50ea0877 | 2974 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue), cu_offset); |
d85bf2ba | 2975 | break; |
5568cc9e | 2976 | case DW_FORM_GNU_strp_alt: |
50ea0877 | 2977 | add_dwo_dir (fetch_alt_indirect_string (uvalue), cu_offset); |
5568cc9e | 2978 | break; |
d85bf2ba | 2979 | case DW_FORM_line_strp: |
50ea0877 | 2980 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue), cu_offset); |
d85bf2ba NC |
2981 | break; |
2982 | case DW_FORM_GNU_str_index: | |
32e4f96c TV |
2983 | case DW_FORM_strx: |
2984 | case DW_FORM_strx1: | |
2985 | case DW_FORM_strx2: | |
2986 | case DW_FORM_strx3: | |
2987 | case DW_FORM_strx4: | |
50ea0877 | 2988 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, FALSE), cu_offset); |
d85bf2ba NC |
2989 | break; |
2990 | case DW_FORM_string: | |
50ea0877 | 2991 | add_dwo_dir ((const char *) orig_data, cu_offset); |
d85bf2ba NC |
2992 | break; |
2993 | default: | |
2994 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2995 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2996 | break; |
2997 | } | |
2998 | break; | |
521d4b19 | 2999 | |
d85bf2ba NC |
3000 | case DW_AT_GNU_dwo_id: |
3001 | if (need_dwo_info) | |
3002 | switch (form) | |
3003 | { | |
3004 | case DW_FORM_data8: | |
24841daa | 3005 | /* FIXME: Record the length of the ID as well ? */ |
50ea0877 | 3006 | add_dwo_id ((const char *) (data - 8), cu_offset); |
d85bf2ba NC |
3007 | break; |
3008 | default: | |
3009 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
3010 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
3011 | break; |
3012 | } | |
3013 | break; | |
521d4b19 | 3014 | |
19e6b90e L |
3015 | default: |
3016 | break; | |
3017 | } | |
3018 | } | |
3019 | ||
4ccf1e31 | 3020 | if (do_loc || attribute == 0) |
19e6b90e L |
3021 | return data; |
3022 | ||
ec4d4525 | 3023 | /* For some attributes we can display further information. */ |
19e6b90e L |
3024 | switch (attribute) |
3025 | { | |
ec1b0fbb | 3026 | case DW_AT_type: |
b3fe587e AM |
3027 | if (level >= 0 && level < MAX_CU_NESTING |
3028 | && uvalue < (size_t) (end - start)) | |
ec1b0fbb NC |
3029 | { |
3030 | bfd_boolean is_signed = FALSE; | |
bcd213b2 NC |
3031 | abbrev_entry * type_abbrev; |
3032 | unsigned char * type_data; | |
3033 | unsigned long type_cu_offset; | |
521d4b19 | 3034 | |
bcd213b2 NC |
3035 | type_abbrev = get_type_abbrev_from_form (form, uvalue, cu_offset, |
3036 | section, NULL, & type_data, & type_cu_offset); | |
3037 | if (type_abbrev != NULL) | |
3038 | { | |
3039 | get_type_signedness (type_abbrev, section, type_data, end, type_cu_offset, | |
3040 | pointer_size, offset_size, dwarf_version, | |
3041 | & is_signed, 0); | |
3042 | } | |
ec1b0fbb NC |
3043 | level_type_signed[level] = is_signed; |
3044 | } | |
3045 | break; | |
521d4b19 | 3046 | |
19e6b90e | 3047 | case DW_AT_inline: |
2e9e81a8 | 3048 | printf ("\t"); |
19e6b90e L |
3049 | switch (uvalue) |
3050 | { | |
3051 | case DW_INL_not_inlined: | |
3052 | printf (_("(not inlined)")); | |
3053 | break; | |
3054 | case DW_INL_inlined: | |
3055 | printf (_("(inlined)")); | |
3056 | break; | |
3057 | case DW_INL_declared_not_inlined: | |
3058 | printf (_("(declared as inline but ignored)")); | |
3059 | break; | |
3060 | case DW_INL_declared_inlined: | |
3061 | printf (_("(declared as inline and inlined)")); | |
3062 | break; | |
3063 | default: | |
47704ddf KT |
3064 | printf (_(" (Unknown inline attribute value: %s)"), |
3065 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
3066 | break; |
3067 | } | |
3068 | break; | |
3069 | ||
3070 | case DW_AT_language: | |
2e9e81a8 | 3071 | printf ("\t"); |
19e6b90e L |
3072 | switch (uvalue) |
3073 | { | |
4b78141a | 3074 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 3075 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
3076 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
3077 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 3078 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
3079 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
3080 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
3081 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
3082 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 3083 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 3084 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 3085 | /* DWARF 2.1 values. */ |
4b78141a | 3086 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
3087 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
3088 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
3089 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
3090 | /* DWARF 3 values. */ |
3091 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
3092 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
3093 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
3094 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
3095 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
3096 | /* DWARF 4 values. */ |
3097 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 3098 | /* DWARF 5 values. */ |
2008a0db | 3099 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 3100 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
3101 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
3102 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
3103 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 3104 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
3105 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
3106 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 3107 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
3108 | case DW_LANG_Swift: printf ("(Swift)"); break; |
3109 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
3110 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 3111 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
3112 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
3113 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 3114 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
3115 | /* MIPS extension. */ |
3116 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
3117 | /* UPC extension. */ | |
3118 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
3119 | default: | |
4b78141a | 3120 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 3121 | printf (_("(implementation defined: %s)"), |
467c65bc | 3122 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 3123 | else |
9cf03b7e | 3124 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
3125 | break; |
3126 | } | |
3127 | break; | |
3128 | ||
3129 | case DW_AT_encoding: | |
2e9e81a8 | 3130 | printf ("\t"); |
19e6b90e L |
3131 | switch (uvalue) |
3132 | { | |
3133 | case DW_ATE_void: printf ("(void)"); break; | |
3134 | case DW_ATE_address: printf ("(machine address)"); break; | |
3135 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
3136 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
3137 | case DW_ATE_float: printf ("(float)"); break; | |
3138 | case DW_ATE_signed: printf ("(signed)"); break; | |
3139 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
3140 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
3141 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 3142 | /* DWARF 2.1 values: */ |
19e6b90e L |
3143 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
3144 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
3145 | /* DWARF 3 values: */ |
3146 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
3147 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
3148 | case DW_ATE_edited: printf ("(edited)"); break; | |
3149 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
3150 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
3151 | /* DWARF 4 values: */ |
3152 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
3153 | /* DWARF 5 values: */ | |
3154 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
3155 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
3156 | ||
e2a0d921 NC |
3157 | /* HP extensions: */ |
3158 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
3159 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
3160 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
3161 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
3162 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
3163 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
3164 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
3165 | ||
19e6b90e L |
3166 | default: |
3167 | if (uvalue >= DW_ATE_lo_user | |
3168 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 3169 | printf (_("(user defined type)")); |
19e6b90e | 3170 | else |
9cf03b7e | 3171 | printf (_("(unknown type)")); |
19e6b90e L |
3172 | break; |
3173 | } | |
3174 | break; | |
3175 | ||
3176 | case DW_AT_accessibility: | |
2e9e81a8 | 3177 | printf ("\t"); |
19e6b90e L |
3178 | switch (uvalue) |
3179 | { | |
3180 | case DW_ACCESS_public: printf ("(public)"); break; | |
3181 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
3182 | case DW_ACCESS_private: printf ("(private)"); break; | |
3183 | default: | |
9cf03b7e | 3184 | printf (_("(unknown accessibility)")); |
19e6b90e L |
3185 | break; |
3186 | } | |
3187 | break; | |
3188 | ||
3189 | case DW_AT_visibility: | |
2e9e81a8 | 3190 | printf ("\t"); |
19e6b90e L |
3191 | switch (uvalue) |
3192 | { | |
3193 | case DW_VIS_local: printf ("(local)"); break; | |
3194 | case DW_VIS_exported: printf ("(exported)"); break; | |
3195 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 3196 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
3197 | } |
3198 | break; | |
3199 | ||
04914e37 NC |
3200 | case DW_AT_endianity: |
3201 | printf ("\t"); | |
3202 | switch (uvalue) | |
3203 | { | |
3204 | case DW_END_default: printf ("(default)"); break; | |
3205 | case DW_END_big: printf ("(big)"); break; | |
3206 | case DW_END_little: printf ("(little)"); break; | |
3207 | default: | |
3208 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
3209 | printf (_("(user specified)")); | |
3210 | else | |
3211 | printf (_("(unknown endianity)")); | |
3212 | break; | |
3213 | } | |
3214 | break; | |
3215 | ||
19e6b90e | 3216 | case DW_AT_virtuality: |
2e9e81a8 | 3217 | printf ("\t"); |
19e6b90e L |
3218 | switch (uvalue) |
3219 | { | |
3220 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
3221 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
3222 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 3223 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
3224 | } |
3225 | break; | |
3226 | ||
3227 | case DW_AT_identifier_case: | |
2e9e81a8 | 3228 | printf ("\t"); |
19e6b90e L |
3229 | switch (uvalue) |
3230 | { | |
3231 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
3232 | case DW_ID_up_case: printf ("(up_case)"); break; | |
3233 | case DW_ID_down_case: printf ("(down_case)"); break; | |
3234 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 3235 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
3236 | } |
3237 | break; | |
3238 | ||
3239 | case DW_AT_calling_convention: | |
2e9e81a8 | 3240 | printf ("\t"); |
19e6b90e L |
3241 | switch (uvalue) |
3242 | { | |
3243 | case DW_CC_normal: printf ("(normal)"); break; | |
3244 | case DW_CC_program: printf ("(program)"); break; | |
3245 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
3246 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
3247 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
3248 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
3249 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
3250 | default: |
3251 | if (uvalue >= DW_CC_lo_user | |
3252 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 3253 | printf (_("(user defined)")); |
19e6b90e | 3254 | else |
9cf03b7e | 3255 | printf (_("(unknown convention)")); |
19e6b90e L |
3256 | } |
3257 | break; | |
3258 | ||
3259 | case DW_AT_ordering: | |
2e9e81a8 | 3260 | printf ("\t"); |
19e6b90e L |
3261 | switch (uvalue) |
3262 | { | |
04914e37 | 3263 | case 255: |
9cf03b7e | 3264 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
3265 | case 0: printf ("(row major)"); break; |
3266 | case 1: printf ("(column major)"); break; | |
3267 | } | |
3268 | break; | |
3269 | ||
04914e37 NC |
3270 | case DW_AT_decimal_sign: |
3271 | printf ("\t"); | |
3272 | switch (uvalue) | |
3273 | { | |
3274 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
3275 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
3276 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
3277 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
3278 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
3279 | default: printf (_("(unrecognised)")); break; | |
3280 | } | |
3281 | break; | |
3282 | ||
3283 | case DW_AT_defaulted: | |
3284 | printf ("\t"); | |
3285 | switch (uvalue) | |
3286 | { | |
3287 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
3288 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
3289 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
3290 | default: printf (_("(unrecognised)")); break; | |
3291 | } | |
3292 | break; | |
3293 | ||
3294 | case DW_AT_discr_list: | |
3295 | printf ("\t"); | |
ec1b0fbb | 3296 | display_discr_list (form, uvalue, data, end, level); |
04914e37 | 3297 | break; |
521d4b19 | 3298 | |
19e6b90e L |
3299 | case DW_AT_frame_base: |
3300 | have_frame_base = 1; | |
1a0670f3 | 3301 | /* Fall through. */ |
19e6b90e | 3302 | case DW_AT_location: |
e2a0d921 NC |
3303 | case DW_AT_string_length: |
3304 | case DW_AT_return_addr: | |
19e6b90e L |
3305 | case DW_AT_data_member_location: |
3306 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
3307 | case DW_AT_segment: |
3308 | case DW_AT_static_link: | |
3309 | case DW_AT_use_location: | |
bc0a77d2 | 3310 | case DW_AT_call_value: |
629e7ca8 | 3311 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 3312 | case DW_AT_call_data_value: |
629e7ca8 | 3313 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 3314 | case DW_AT_call_target: |
629e7ca8 | 3315 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 3316 | case DW_AT_call_target_clobbered: |
629e7ca8 | 3317 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 3318 | if ((dwarf_version < 4 |
b4eb7656 | 3319 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 3320 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 3321 | printf (_(" (location list)")); |
e2a0d921 | 3322 | /* Fall through. */ |
19e6b90e L |
3323 | case DW_AT_allocated: |
3324 | case DW_AT_associated: | |
3325 | case DW_AT_data_location: | |
3326 | case DW_AT_stride: | |
3327 | case DW_AT_upper_bound: | |
cecf136e | 3328 | case DW_AT_lower_bound: |
19e6b90e L |
3329 | if (block_start) |
3330 | { | |
3331 | int need_frame_base; | |
3332 | ||
2e9e81a8 | 3333 | printf ("\t("); |
19e6b90e L |
3334 | need_frame_base = decode_location_expression (block_start, |
3335 | pointer_size, | |
b7807392 JJ |
3336 | offset_size, |
3337 | dwarf_version, | |
19e6b90e | 3338 | uvalue, |
f1c4cc75 | 3339 | cu_offset, section); |
19e6b90e L |
3340 | printf (")"); |
3341 | if (need_frame_base && !have_frame_base) | |
3342 | printf (_(" [without DW_AT_frame_base]")); | |
3343 | } | |
19e6b90e L |
3344 | break; |
3345 | ||
c54207d3 NC |
3346 | case DW_AT_data_bit_offset: |
3347 | case DW_AT_byte_size: | |
3348 | case DW_AT_bit_size: | |
3349 | case DW_AT_string_length_byte_size: | |
3350 | case DW_AT_string_length_bit_size: | |
3351 | case DW_AT_bit_stride: | |
3352 | if (form == DW_FORM_exprloc) | |
3353 | { | |
3354 | printf ("\t("); | |
3355 | (void) decode_location_expression (block_start, pointer_size, | |
3356 | offset_size, dwarf_version, | |
3357 | uvalue, cu_offset, section); | |
3358 | printf (")"); | |
3359 | } | |
3360 | break; | |
3361 | ||
ec4d4525 NC |
3362 | case DW_AT_import: |
3363 | { | |
bcd213b2 NC |
3364 | unsigned long abbrev_number; |
3365 | abbrev_entry *entry; | |
2b6f5997 | 3366 | |
bcd213b2 NC |
3367 | entry = get_type_abbrev_from_form (form, uvalue, cu_offset, |
3368 | section, & abbrev_number, NULL, NULL); | |
3369 | if (entry == NULL) | |
3370 | { | |
3371 | if (form != DW_FORM_GNU_ref_alt) | |
3372 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), | |
3373 | dwarf_vmatoa ("x", uvalue), | |
3374 | (unsigned long) (orig_data - section->start)); | |
3375 | } | |
6e3d6dc1 NC |
3376 | else |
3377 | { | |
2e9e81a8 | 3378 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
bcd213b2 | 3379 | printf (" (%s)", get_TAG_name (entry->tag)); |
6e3d6dc1 NC |
3380 | printf ("]"); |
3381 | } | |
ec4d4525 NC |
3382 | } |
3383 | break; | |
3384 | ||
19e6b90e L |
3385 | default: |
3386 | break; | |
3387 | } | |
3388 | ||
3389 | return data; | |
3390 | } | |
3391 | ||
19e6b90e | 3392 | static unsigned char * |
dda8d76d NC |
3393 | read_and_display_attr (unsigned long attribute, |
3394 | unsigned long form, | |
3395 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 3396 | unsigned char * start, |
dda8d76d NC |
3397 | unsigned char * data, |
3398 | unsigned char * end, | |
3399 | dwarf_vma cu_offset, | |
3400 | dwarf_vma pointer_size, | |
3401 | dwarf_vma offset_size, | |
3402 | int dwarf_version, | |
3403 | debug_info * debug_info_p, | |
3404 | int do_loc, | |
3405 | struct dwarf_section * section, | |
ec1b0fbb NC |
3406 | struct cu_tu_set * this_set, |
3407 | int level) | |
19e6b90e L |
3408 | { |
3409 | if (!do_loc) | |
750f03b7 | 3410 | printf (" %-18s:", get_AT_name (attribute)); |
ec1b0fbb NC |
3411 | data = read_and_display_attr_value (attribute, form, implicit_const, |
3412 | start, data, end, | |
f6f0e17b | 3413 | cu_offset, pointer_size, offset_size, |
19e6b90e | 3414 | dwarf_version, debug_info_p, |
ec1b0fbb | 3415 | do_loc, section, this_set, ' ', level); |
19e6b90e L |
3416 | if (!do_loc) |
3417 | printf ("\n"); | |
3418 | return data; | |
3419 | } | |
3420 | ||
dda8d76d | 3421 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
3422 | following debug links, then attempt to load the requested section |
3423 | from one of the separate debug info files. */ | |
dda8d76d NC |
3424 | |
3425 | static bfd_boolean | |
3426 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, | |
24841daa | 3427 | void * handle) |
dda8d76d | 3428 | { |
24841daa | 3429 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 3430 | { |
24841daa NC |
3431 | if (debug_displays[sec_enum].section.filename == NULL) |
3432 | { | |
3433 | /* See if we can associate a filename with this section. */ | |
3434 | separate_info * i; | |
3435 | ||
3436 | for (i = first_separate_info; i != NULL; i = i->next) | |
3437 | if (i->handle == handle) | |
3438 | { | |
3439 | debug_displays[sec_enum].section.filename = i->filename; | |
3440 | break; | |
3441 | } | |
3442 | } | |
3443 | ||
dda8d76d NC |
3444 | return TRUE; |
3445 | } | |
3446 | ||
24841daa NC |
3447 | if (do_follow_links) |
3448 | { | |
3449 | separate_info * i; | |
3450 | ||
3451 | for (i = first_separate_info; i != NULL; i = i->next) | |
3452 | { | |
3453 | if (load_debug_section (sec_enum, i->handle)) | |
3454 | { | |
3455 | debug_displays[sec_enum].section.filename = i->filename; | |
3456 | ||
3457 | /* FIXME: We should check to see if any of the remaining debug info | |
3458 | files also contain this section, and, umm, do something about it. */ | |
3459 | return TRUE; | |
3460 | } | |
3461 | } | |
3462 | } | |
dda8d76d NC |
3463 | |
3464 | return FALSE; | |
3465 | } | |
3466 | ||
3467 | static void | |
3468 | introduce (struct dwarf_section * section, bfd_boolean raw) | |
3469 | { | |
3470 | if (raw) | |
3471 | { | |
3472 | if (do_follow_links && section->filename) | |
3473 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
3474 | section->name, section->filename); | |
3475 | else | |
3476 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
3477 | } | |
3478 | else | |
3479 | { | |
3480 | if (do_follow_links && section->filename) | |
3481 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
3482 | section->name, section->filename); | |
3483 | else | |
3484 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3485 | } | |
3486 | } | |
521d4b19 | 3487 | |
d85bf2ba NC |
3488 | /* Process the contents of a .debug_info section. |
3489 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
3490 | and we do not want to display anything to the user. | |
3491 | If do_types is TRUE, we are processing a .debug_types section instead of | |
3492 | a .debug_info section. | |
3493 | The information displayed is restricted by the values in DWARF_START_DIE | |
3494 | and DWARF_CUTOFF_LEVEL. | |
3495 | Returns TRUE upon success. Otherwise an error or warning message is | |
3496 | printed and FALSE is returned. */ | |
19e6b90e | 3497 | |
d85bf2ba NC |
3498 | static bfd_boolean |
3499 | process_debug_info (struct dwarf_section * section, | |
3500 | void * file, | |
3501 | enum dwarf_section_display_enum abbrev_sec, | |
3502 | bfd_boolean do_loc, | |
3503 | bfd_boolean do_types) | |
19e6b90e L |
3504 | { |
3505 | unsigned char *start = section->start; | |
3506 | unsigned char *end = start + section->size; | |
3507 | unsigned char *section_begin; | |
3508 | unsigned int unit; | |
3509 | unsigned int num_units = 0; | |
3510 | ||
3511 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3512 | && num_debug_info_entries == 0 |
3513 | && ! do_types) | |
19e6b90e | 3514 | { |
767221a9 | 3515 | dwarf_vma length; |
19e6b90e L |
3516 | |
3517 | /* First scan the section to get the number of comp units. */ | |
3518 | for (section_begin = start, num_units = 0; section_begin < end; | |
3519 | num_units ++) | |
3520 | { | |
3521 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
3522 | will be the length. For a 64-bit DWARF section, it'll be | |
3523 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 3524 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
3525 | |
3526 | if (length == 0xffffffff) | |
3527 | { | |
0c588247 | 3528 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
3529 | section_begin += length + 12; |
3530 | } | |
ec4d4525 NC |
3531 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
3532 | { | |
767221a9 NC |
3533 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
3534 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3535 | return FALSE; |
ec4d4525 | 3536 | } |
19e6b90e L |
3537 | else |
3538 | section_begin += length + 4; | |
aca88567 NC |
3539 | |
3540 | /* Negative values are illegal, they may even cause infinite | |
3541 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
3542 | relocations to an object file, or if the file is corrupt. */ |
3543 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 3544 | { |
767221a9 NC |
3545 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
3546 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3547 | return FALSE; |
aca88567 | 3548 | } |
19e6b90e L |
3549 | } |
3550 | ||
3551 | if (num_units == 0) | |
3552 | { | |
f41e4712 | 3553 | error (_("No comp units in %s section ?\n"), section->name); |
d85bf2ba | 3554 | return FALSE; |
19e6b90e L |
3555 | } |
3556 | ||
3557 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 3558 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 3559 | sizeof (* debug_information)); |
19e6b90e L |
3560 | if (debug_information == NULL) |
3561 | { | |
f41e4712 | 3562 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 3563 | num_units); |
82b1b41b | 3564 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
d85bf2ba | 3565 | return FALSE; |
19e6b90e | 3566 | } |
d85bf2ba | 3567 | |
03a91817 NC |
3568 | /* PR 17531: file: 92ca3797. |
3569 | We cannot rely upon the debug_information array being initialised | |
3570 | before it is used. A corrupt file could easily contain references | |
3571 | to a unit for which information has not been made available. So | |
3572 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
3573 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
3574 | ||
82b1b41b | 3575 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
3576 | } |
3577 | ||
3578 | if (!do_loc) | |
3579 | { | |
dda8d76d NC |
3580 | load_debug_section_with_follow (str, file); |
3581 | load_debug_section_with_follow (line_str, file); | |
3582 | load_debug_section_with_follow (str_dwo, file); | |
3583 | load_debug_section_with_follow (str_index, file); | |
3584 | load_debug_section_with_follow (str_index_dwo, file); | |
3585 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e | 3586 | } |
521d4b19 | 3587 | |
dda8d76d | 3588 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 3589 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
3590 | { |
3591 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 3592 | debug_displays [abbrev_sec].section.uncompressed_name); |
d85bf2ba | 3593 | return FALSE; |
19e6b90e L |
3594 | } |
3595 | ||
dda8d76d NC |
3596 | if (!do_loc && dwarf_start_die == 0) |
3597 | introduce (section, FALSE); | |
bcd213b2 NC |
3598 | |
3599 | free_all_abbrevs (); | |
3600 | free (cu_abbrev_map); | |
3601 | cu_abbrev_map = NULL; | |
3602 | next_free_abbrev_map_entry = 0; | |
521d4b19 | 3603 | |
bcd213b2 NC |
3604 | /* In order to be able to resolve DW_FORM_ref_attr forms we need |
3605 | to load *all* of the abbrevs for all CUs in this .debug_info | |
3606 | section. This does effectively mean that we (partially) read | |
3607 | every CU header twice. */ | |
3608 | for (section_begin = start; start < end;) | |
3609 | { | |
3610 | DWARF2_Internal_CompUnit compunit; | |
3611 | unsigned char * hdrptr; | |
76868f36 L |
3612 | dwarf_vma abbrev_base; |
3613 | size_t abbrev_size; | |
bcd213b2 NC |
3614 | dwarf_vma cu_offset; |
3615 | unsigned int offset_size; | |
3616 | unsigned int initial_length_size; | |
3617 | struct cu_tu_set * this_set; | |
3618 | abbrev_list * list; | |
3619 | ||
3620 | hdrptr = start; | |
3621 | ||
3622 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); | |
3623 | ||
3624 | if (compunit.cu_length == 0xffffffff) | |
3625 | { | |
3626 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); | |
3627 | offset_size = 8; | |
3628 | initial_length_size = 12; | |
3629 | } | |
3630 | else | |
3631 | { | |
3632 | offset_size = 4; | |
3633 | initial_length_size = 4; | |
3634 | } | |
3635 | ||
3636 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); | |
3637 | ||
3638 | cu_offset = start - section_begin; | |
3639 | ||
3640 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); | |
3641 | ||
3642 | if (compunit.cu_version < 5) | |
3643 | { | |
3644 | compunit.cu_unit_type = DW_UT_compile; | |
3645 | /* Initialize it due to a false compiler warning. */ | |
3646 | compunit.cu_pointer_size = -1; | |
3647 | } | |
3648 | else | |
3649 | { | |
3650 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3651 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3652 | ||
3653 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3654 | } | |
3655 | ||
3656 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); | |
3657 | ||
9b87f84a TV |
3658 | if (compunit.cu_unit_type == DW_UT_split_compile |
3659 | || compunit.cu_unit_type == DW_UT_skeleton) | |
3660 | { | |
3661 | uint64_t dwo_id; | |
3662 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end); | |
3663 | } | |
3664 | ||
76868f36 L |
3665 | if (this_set == NULL) |
3666 | { | |
3667 | abbrev_base = 0; | |
3668 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3669 | } | |
3670 | else | |
3671 | { | |
3672 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3673 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3674 | } | |
3675 | ||
3676 | list = find_abbrev_list_by_abbrev_offset (abbrev_base, | |
3677 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3678 | if (list == NULL) |
3679 | { | |
bcd213b2 NC |
3680 | unsigned char * next; |
3681 | ||
76868f36 L |
3682 | list = new_abbrev_list (abbrev_base, |
3683 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3684 | next = process_abbrev_set |
3685 | (((unsigned char *) debug_displays [abbrev_sec].section.start | |
3686 | + abbrev_base + compunit.cu_abbrev_offset), | |
3687 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3688 | + abbrev_base + abbrev_size), | |
3689 | list); | |
3690 | list->start_of_next_abbrevs = next; | |
3691 | } | |
521d4b19 | 3692 | |
bcd213b2 NC |
3693 | start = section_begin + cu_offset + compunit.cu_length |
3694 | + initial_length_size; | |
3695 | record_abbrev_list_for_cu (cu_offset, start - section_begin, list); | |
3696 | } | |
3697 | ||
3698 | for (start = section_begin, unit = 0; start < end; unit++) | |
19e6b90e L |
3699 | { |
3700 | DWARF2_Internal_CompUnit compunit; | |
3701 | unsigned char *hdrptr; | |
19e6b90e | 3702 | unsigned char *tags; |
fd2f0033 | 3703 | int level, last_level, saved_level; |
467c65bc | 3704 | dwarf_vma cu_offset; |
e98fdf1a | 3705 | unsigned long sec_off; |
bf5117e3 | 3706 | unsigned int offset_size; |
19485196 | 3707 | unsigned int initial_length_size; |
74bc6052 CC |
3708 | dwarf_vma signature_high = 0; |
3709 | dwarf_vma signature_low = 0; | |
767221a9 | 3710 | dwarf_vma type_offset = 0; |
341f9135 CC |
3711 | struct cu_tu_set *this_set; |
3712 | dwarf_vma abbrev_base; | |
3713 | size_t abbrev_size; | |
bcd213b2 | 3714 | abbrev_list * list = NULL; |
19e6b90e L |
3715 | |
3716 | hdrptr = start; | |
3717 | ||
0c588247 | 3718 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
3719 | |
3720 | if (compunit.cu_length == 0xffffffff) | |
3721 | { | |
0c588247 | 3722 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
3723 | offset_size = 8; |
3724 | initial_length_size = 12; | |
3725 | } | |
3726 | else | |
3727 | { | |
3728 | offset_size = 4; | |
3729 | initial_length_size = 4; | |
3730 | } | |
3731 | ||
0c588247 | 3732 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
3733 | |
3734 | cu_offset = start - section_begin; | |
19e6b90e | 3735 | |
341f9135 CC |
3736 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3737 | ||
77145576 JK |
3738 | if (compunit.cu_version < 5) |
3739 | { | |
3740 | compunit.cu_unit_type = DW_UT_compile; | |
3741 | /* Initialize it due to a false compiler warning. */ | |
3742 | compunit.cu_pointer_size = -1; | |
3743 | } | |
3744 | else | |
3745 | { | |
3746 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3747 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3748 | ||
3749 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3750 | } | |
3751 | ||
0c588247 | 3752 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 3753 | |
341f9135 CC |
3754 | if (this_set == NULL) |
3755 | { | |
3756 | abbrev_base = 0; | |
3757 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3758 | } | |
3759 | else | |
3760 | { | |
3761 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3762 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3763 | } | |
3764 | ||
77145576 JK |
3765 | if (compunit.cu_version < 5) |
3766 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3767 | ||
d60f7998 | 3768 | bfd_boolean do_dwo_id = FALSE; |
e6ca1878 | 3769 | uint64_t dwo_id = 0; |
9b87f84a TV |
3770 | if (compunit.cu_unit_type == DW_UT_split_compile |
3771 | || compunit.cu_unit_type == DW_UT_skeleton) | |
3772 | { | |
9b87f84a | 3773 | SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end); |
d60f7998 | 3774 | do_dwo_id = TRUE; |
9b87f84a TV |
3775 | } |
3776 | ||
f41e4712 NC |
3777 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
3778 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
3779 | { | |
3780 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
3781 | compunit.cu_pointer_size, offset_size); | |
3782 | compunit.cu_pointer_size = offset_size; | |
3783 | } | |
2b6f5997 CC |
3784 | |
3785 | if (do_types) | |
b4eb7656 | 3786 | { |
0c588247 | 3787 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 3788 | hdrptr += 8; |
0c588247 | 3789 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 3790 | } |
2b6f5997 | 3791 | |
ae7e7825 NC |
3792 | if (dwarf_start_die > (cu_offset + compunit.cu_length |
3793 | + initial_length_size)) | |
3794 | { | |
3795 | start = section_begin + cu_offset + compunit.cu_length | |
3796 | + initial_length_size; | |
3797 | continue; | |
3798 | } | |
3799 | ||
19e6b90e | 3800 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 | 3801 | && num_debug_info_entries == 0 |
c4b2f181 | 3802 | && alloc_num_debug_info_entries > unit |
2b6f5997 | 3803 | && ! do_types) |
19e6b90e L |
3804 | { |
3805 | debug_information [unit].cu_offset = cu_offset; | |
3806 | debug_information [unit].pointer_size | |
3807 | = compunit.cu_pointer_size; | |
b7807392 JJ |
3808 | debug_information [unit].offset_size = offset_size; |
3809 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 3810 | debug_information [unit].base_address = 0; |
4723351a CC |
3811 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
3812 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
3813 | debug_information [unit].loc_offsets = NULL; |
3814 | debug_information [unit].have_frame_base = NULL; | |
3815 | debug_information [unit].max_loc_offsets = 0; | |
3816 | debug_information [unit].num_loc_offsets = 0; | |
3817 | debug_information [unit].range_lists = NULL; | |
3818 | debug_information [unit].max_range_lists= 0; | |
3819 | debug_information [unit].num_range_lists = 0; | |
3820 | } | |
3821 | ||
fd2f0033 | 3822 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 3823 | { |
47704ddf KT |
3824 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3825 | dwarf_vmatoa ("x", cu_offset)); | |
3826 | printf (_(" Length: 0x%s (%s)\n"), | |
3827 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3828 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3829 | printf (_(" Version: %d\n"), compunit.cu_version); |
debd1a62 MW |
3830 | if (compunit.cu_version >= 5) |
3831 | printf (_(" Unit Type: %s (%x)\n"), | |
3832 | get_DW_UT_name (compunit.cu_unit_type) ?: "???", | |
3833 | compunit.cu_unit_type); | |
7282333f AM |
3834 | printf (_(" Abbrev Offset: 0x%s\n"), |
3835 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3836 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3837 | if (do_types) |
3838 | { | |
74bc6052 CC |
3839 | char buf[64]; |
3840 | ||
3841 | printf (_(" Signature: 0x%s\n"), | |
3842 | dwarf_vmatoa64 (signature_high, signature_low, | |
3843 | buf, sizeof (buf))); | |
3844 | printf (_(" Type Offset: 0x%s\n"), | |
3845 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3846 | } |
d60f7998 TV |
3847 | if (do_dwo_id) |
3848 | printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id)); | |
341f9135 CC |
3849 | if (this_set != NULL) |
3850 | { | |
3851 | dwarf_vma *offsets = this_set->section_offsets; | |
3852 | size_t *sizes = this_set->section_sizes; | |
3853 | ||
3854 | printf (_(" Section contributions:\n")); | |
3855 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3856 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3857 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3858 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3859 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3860 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3861 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3862 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3863 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3864 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3865 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3866 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3867 | } | |
19e6b90e L |
3868 | } |
3869 | ||
e98fdf1a AM |
3870 | sec_off = cu_offset + initial_length_size; |
3871 | if (sec_off + compunit.cu_length < sec_off | |
3872 | || sec_off + compunit.cu_length > section->size) | |
460c89ff | 3873 | { |
e98fdf1a AM |
3874 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
3875 | section->name, | |
3876 | (unsigned long) cu_offset, | |
19485196 NC |
3877 | dwarf_vmatoa ("x", compunit.cu_length)); |
3878 | num_units = unit; | |
3879 | break; | |
3880 | } | |
3881 | ||
460c89ff NS |
3882 | tags = hdrptr; |
3883 | start += compunit.cu_length + initial_length_size; | |
3884 | ||
77145576 | 3885 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3886 | { |
47704ddf KT |
3887 | warn (_("CU at offset %s contains corrupt or " |
3888 | "unsupported version number: %d.\n"), | |
3889 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3890 | continue; |
3891 | } | |
3892 | ||
77145576 | 3893 | if (compunit.cu_unit_type != DW_UT_compile |
ec47b32a | 3894 | && compunit.cu_unit_type != DW_UT_partial |
9b87f84a TV |
3895 | && compunit.cu_unit_type != DW_UT_type |
3896 | && compunit.cu_unit_type != DW_UT_split_compile | |
3897 | && compunit.cu_unit_type != DW_UT_skeleton) | |
77145576 JK |
3898 | { |
3899 | warn (_("CU at offset %s contains corrupt or " | |
3900 | "unsupported unit type: %d.\n"), | |
3901 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3902 | continue; | |
3903 | } | |
3904 | ||
d493b283 | 3905 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 3906 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
3907 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
3908 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 3909 | (unsigned long) abbrev_size); |
b4eb7656 | 3910 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
3911 | else if ((abbrev_base + abbrev_size) |
3912 | > debug_displays [abbrev_sec].section.size) | |
3913 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
3914 | (unsigned long) abbrev_base + abbrev_size, | |
3915 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff | 3916 | else |
bcd213b2 | 3917 | { |
76868f36 L |
3918 | list = find_abbrev_list_by_abbrev_offset (abbrev_base, |
3919 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3920 | if (list == NULL) |
3921 | { | |
3922 | unsigned char * next; | |
3923 | ||
76868f36 L |
3924 | list = new_abbrev_list (abbrev_base, |
3925 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3926 | next = process_abbrev_set |
3927 | (((unsigned char *) debug_displays [abbrev_sec].section.start | |
3928 | + abbrev_base + compunit.cu_abbrev_offset), | |
3929 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3930 | + abbrev_base + abbrev_size), | |
3931 | list); | |
3932 | list->start_of_next_abbrevs = next; | |
3933 | } | |
3934 | } | |
19e6b90e L |
3935 | |
3936 | level = 0; | |
fd2f0033 TT |
3937 | last_level = level; |
3938 | saved_level = -1; | |
19e6b90e L |
3939 | while (tags < start) |
3940 | { | |
19e6b90e | 3941 | unsigned long abbrev_number; |
ec4d4525 | 3942 | unsigned long die_offset; |
19e6b90e L |
3943 | abbrev_entry *entry; |
3944 | abbrev_attr *attr; | |
fd2f0033 | 3945 | int do_printing = 1; |
19e6b90e | 3946 | |
ec4d4525 NC |
3947 | die_offset = tags - section_begin; |
3948 | ||
cd30bcef | 3949 | READ_ULEB (abbrev_number, tags, start); |
19e6b90e | 3950 | |
eb7cc021 JK |
3951 | /* A null DIE marks the end of a list of siblings or it may also be |
3952 | a section padding. */ | |
19e6b90e L |
3953 | if (abbrev_number == 0) |
3954 | { | |
eb7cc021 JK |
3955 | /* Check if it can be a section padding for the last CU. */ |
3956 | if (level == 0 && start == end) | |
3957 | { | |
3958 | unsigned char *chk; | |
3959 | ||
3960 | for (chk = tags; chk < start; chk++) | |
3961 | if (*chk != 0) | |
3962 | break; | |
3963 | if (chk == start) | |
3964 | break; | |
3965 | } | |
3966 | ||
4337774f TT |
3967 | if (!do_loc && die_offset >= dwarf_start_die |
3968 | && (dwarf_cutoff_level == -1 | |
3969 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3970 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3971 | level, die_offset); | |
3972 | ||
19e6b90e | 3973 | --level; |
ec4d4525 NC |
3974 | if (level < 0) |
3975 | { | |
3976 | static unsigned num_bogus_warns = 0; | |
3977 | ||
3978 | if (num_bogus_warns < 3) | |
3979 | { | |
4723351a CC |
3980 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3981 | die_offset, section->name); | |
ec4d4525 NC |
3982 | num_bogus_warns ++; |
3983 | if (num_bogus_warns == 3) | |
3984 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3985 | } | |
3986 | } | |
fd2f0033 | 3987 | if (dwarf_start_die != 0 && level < saved_level) |
d85bf2ba | 3988 | return TRUE; |
19e6b90e L |
3989 | continue; |
3990 | } | |
3991 | ||
4b78141a | 3992 | if (!do_loc) |
fd2f0033 TT |
3993 | { |
3994 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
3995 | do_printing = 0; | |
3996 | else | |
3997 | { | |
3998 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
3999 | saved_level = level; | |
4000 | do_printing = (dwarf_cutoff_level == -1 | |
4001 | || level < dwarf_cutoff_level); | |
4002 | if (do_printing) | |
4003 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
4004 | level, die_offset, abbrev_number); | |
4005 | else if (dwarf_cutoff_level == -1 | |
4006 | || last_level < dwarf_cutoff_level) | |
4007 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
4008 | last_level = level; | |
4009 | } | |
4010 | } | |
cecf136e | 4011 | |
19e6b90e L |
4012 | /* Scan through the abbreviation list until we reach the |
4013 | correct entry. */ | |
bcd213b2 | 4014 | if (list == NULL) |
19e6b90e L |
4015 | continue; |
4016 | ||
bcd213b2 NC |
4017 | for (entry = list->first_abbrev; entry != NULL; entry = entry->next) |
4018 | if (entry->number == abbrev_number) | |
4019 | break; | |
4020 | ||
19e6b90e L |
4021 | if (entry == NULL) |
4022 | { | |
fd2f0033 | 4023 | if (!do_loc && do_printing) |
4b78141a NC |
4024 | { |
4025 | printf ("\n"); | |
4026 | fflush (stdout); | |
4027 | } | |
f3853b34 | 4028 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 4029 | die_offset, abbrev_number); |
d85bf2ba | 4030 | return FALSE; |
19e6b90e L |
4031 | } |
4032 | ||
fd2f0033 | 4033 | if (!do_loc && do_printing) |
cc5914eb | 4034 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 4035 | |
19e6b90e L |
4036 | switch (entry->tag) |
4037 | { | |
4038 | default: | |
4039 | need_base_address = 0; | |
4040 | break; | |
4041 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
4042 | need_base_address = 1; |
4043 | need_dwo_info = do_loc; | |
19e6b90e L |
4044 | break; |
4045 | case DW_TAG_entry_point: | |
19e6b90e L |
4046 | case DW_TAG_subprogram: |
4047 | need_base_address = 0; | |
4048 | /* Assuming that there is no DW_AT_frame_base. */ | |
4049 | have_frame_base = 0; | |
4050 | break; | |
4051 | } | |
4052 | ||
9f272209 AO |
4053 | debug_info *debug_info_p = |
4054 | (debug_information && unit < alloc_num_debug_info_entries) | |
4055 | ? debug_information + unit : NULL; | |
4056 | ||
4057 | assert (!debug_info_p | |
4058 | || (debug_info_p->num_loc_offsets | |
4059 | == debug_info_p->num_loc_views)); | |
4060 | ||
399c99f7 L |
4061 | for (attr = entry->first_attr; |
4062 | attr && attr->attribute; | |
4063 | attr = attr->next) | |
4b78141a | 4064 | { |
fd2f0033 | 4065 | if (! do_loc && do_printing) |
4b78141a | 4066 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 | 4067 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
4068 | tags = read_and_display_attr (attr->attribute, |
4069 | attr->form, | |
77145576 | 4070 | attr->implicit_const, |
ec1b0fbb | 4071 | section_begin, |
341f9135 | 4072 | tags, |
f6f0e17b | 4073 | end, |
341f9135 | 4074 | cu_offset, |
4b78141a NC |
4075 | compunit.cu_pointer_size, |
4076 | offset_size, | |
4077 | compunit.cu_version, | |
9f272209 | 4078 | debug_info_p, |
341f9135 CC |
4079 | do_loc || ! do_printing, |
4080 | section, | |
ec1b0fbb NC |
4081 | this_set, |
4082 | level); | |
4b78141a | 4083 | } |
cecf136e | 4084 | |
9f272209 AO |
4085 | /* If a locview attribute appears before a location one, |
4086 | make sure we don't associate it with an earlier | |
4087 | loclist. */ | |
4088 | if (debug_info_p) | |
4089 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
4090 | { | |
4091 | case 1: | |
4092 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
4093 | debug_info_p->num_loc_views++; | |
4094 | assert (debug_info_p->num_loc_views | |
4095 | == debug_info_p->num_loc_offsets); | |
4096 | break; | |
4097 | ||
4098 | case 0: | |
4099 | break; | |
4100 | ||
4101 | case -1: | |
4102 | warn(_("DIE has locviews without loclist\n")); | |
4103 | debug_info_p->num_loc_views--; | |
4104 | break; | |
4105 | ||
4106 | default: | |
4107 | assert (0); | |
4108 | } | |
4109 | ||
b4eb7656 AM |
4110 | if (entry->children) |
4111 | ++level; | |
4112 | } | |
19e6b90e | 4113 | } |
cecf136e | 4114 | |
19e6b90e L |
4115 | /* Set num_debug_info_entries here so that it can be used to check if |
4116 | we need to process .debug_loc and .debug_ranges sections. */ | |
4117 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
4118 | && num_debug_info_entries == 0 |
4119 | && ! do_types) | |
82b1b41b | 4120 | { |
b4eb7656 | 4121 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
4122 | num_debug_info_entries = alloc_num_debug_info_entries; |
4123 | else | |
4124 | num_debug_info_entries = num_units; | |
4125 | } | |
cecf136e | 4126 | |
19e6b90e | 4127 | if (!do_loc) |
467c65bc | 4128 | printf ("\n"); |
cecf136e | 4129 | |
d85bf2ba | 4130 | return TRUE; |
19e6b90e L |
4131 | } |
4132 | ||
4133 | /* Locate and scan the .debug_info section in the file and record the pointer | |
4134 | sizes and offsets for the compilation units in it. Usually an executable | |
4135 | will have just one pointer size, but this is not guaranteed, and so we try | |
4136 | not to make any assumptions. Returns zero upon failure, or the number of | |
4137 | compilation units upon success. */ | |
4138 | ||
4139 | static unsigned int | |
4140 | load_debug_info (void * file) | |
4141 | { | |
1febe64d | 4142 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 4143 | section then do not bother to repeat the task. */ |
cc86f28f | 4144 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
4145 | return 0; |
4146 | ||
19e6b90e L |
4147 | /* If we already have the information there is nothing else to do. */ |
4148 | if (num_debug_info_entries > 0) | |
4149 | return num_debug_info_entries; | |
4150 | ||
341f9135 | 4151 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 4152 | (void) load_cu_tu_indexes (file); |
341f9135 | 4153 | |
dda8d76d | 4154 | if (load_debug_section_with_follow (info, file) |
d85bf2ba | 4155 | && process_debug_info (&debug_displays [info].section, file, abbrev, TRUE, FALSE)) |
19e6b90e | 4156 | return num_debug_info_entries; |
82b1b41b | 4157 | |
dda8d76d | 4158 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 4159 | && process_debug_info (&debug_displays [info_dwo].section, file, |
d85bf2ba | 4160 | abbrev_dwo, TRUE, FALSE)) |
4723351a | 4161 | return num_debug_info_entries; |
1febe64d | 4162 | |
cc86f28f | 4163 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 4164 | return 0; |
19e6b90e L |
4165 | } |
4166 | ||
b40bf0a2 NC |
4167 | /* Read a DWARF .debug_line section header starting at DATA. |
4168 | Upon success returns an updated DATA pointer and the LINFO | |
4169 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
4170 | Otherwise returns NULL. */ | |
19e6b90e | 4171 | |
b40bf0a2 NC |
4172 | static unsigned char * |
4173 | read_debug_line_header (struct dwarf_section * section, | |
4174 | unsigned char * data, | |
4175 | unsigned char * end, | |
4176 | DWARF2_Internal_LineInfo * linfo, | |
4177 | unsigned char ** end_of_sequence) | |
4178 | { | |
4179 | unsigned char *hdrptr; | |
b40bf0a2 | 4180 | unsigned int initial_length_size; |
19e6b90e | 4181 | |
b40bf0a2 NC |
4182 | /* Extract information from the Line Number Program Header. |
4183 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 4184 | hdrptr = data; |
19e6b90e | 4185 | |
b40bf0a2 NC |
4186 | /* Get and check the length of the block. */ |
4187 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 4188 | |
b40bf0a2 | 4189 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
4190 | { |
4191 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 4192 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 4193 | linfo->li_offset_size = 8; |
f41e4712 NC |
4194 | initial_length_size = 12; |
4195 | } | |
4196 | else | |
4197 | { | |
77145576 | 4198 | linfo->li_offset_size = 4; |
f41e4712 NC |
4199 | initial_length_size = 4; |
4200 | } | |
19e6b90e | 4201 | |
b40bf0a2 | 4202 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 4203 | { |
8fcc61b4 NC |
4204 | /* If the length field has a relocation against it, then we should |
4205 | not complain if it is inaccurate (and probably negative). This | |
4206 | happens in object files when the .debug_line section is actually | |
4207 | comprised of several different .debug_line.* sections, (some of | |
4208 | which may be removed by linker garbage collection), and a relocation | |
4209 | is used to compute the correct length once that is done. */ | |
77145576 | 4210 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 4211 | { |
8fcc61b4 | 4212 | linfo->li_length = (end - data) - initial_length_size; |
b40bf0a2 NC |
4213 | } |
4214 | else | |
4215 | { | |
8fcc61b4 NC |
4216 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
4217 | (long) linfo->li_length); | |
b40bf0a2 NC |
4218 | return NULL; |
4219 | } | |
f41e4712 | 4220 | } |
19e6b90e | 4221 | |
b40bf0a2 NC |
4222 | /* Get and check the version number. */ |
4223 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
4224 | ||
4225 | if (linfo->li_version != 2 | |
4226 | && linfo->li_version != 3 | |
77145576 JK |
4227 | && linfo->li_version != 4 |
4228 | && linfo->li_version != 5) | |
f41e4712 | 4229 | { |
77145576 JK |
4230 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
4231 | "is currently supported.\n")); | |
b40bf0a2 | 4232 | return NULL; |
f41e4712 | 4233 | } |
19e6b90e | 4234 | |
77145576 JK |
4235 | if (linfo->li_version >= 5) |
4236 | { | |
5496f3c6 | 4237 | SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end); |
77145576 | 4238 | |
5496f3c6 NC |
4239 | SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end); |
4240 | if (linfo->li_segment_size != 0) | |
77145576 JK |
4241 | { |
4242 | warn (_("The %s section contains " | |
4243 | "unsupported segment selector size: %d.\n"), | |
5496f3c6 NC |
4244 | section->name, linfo->li_segment_size); |
4245 | return NULL; | |
77145576 JK |
4246 | } |
4247 | } | |
4248 | ||
4249 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
4250 | linfo->li_offset_size, end); | |
b40bf0a2 | 4251 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 4252 | |
b40bf0a2 | 4253 | if (linfo->li_version >= 4) |
f41e4712 | 4254 | { |
b40bf0a2 | 4255 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 4256 | |
b40bf0a2 | 4257 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
4258 | { |
4259 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 4260 | return NULL; |
a233b20c | 4261 | } |
f41e4712 NC |
4262 | } |
4263 | else | |
b40bf0a2 | 4264 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 4265 | |
b40bf0a2 | 4266 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 4267 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
4268 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
4269 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 4270 | |
b40bf0a2 | 4271 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 4272 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
4273 | if (* end_of_sequence > end) |
4274 | { | |
4c219c2e AM |
4275 | warn (_("Line length %s extends beyond end of section\n"), |
4276 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
4277 | * end_of_sequence = end; |
4278 | return NULL; | |
4279 | } | |
4280 | ||
b40bf0a2 NC |
4281 | return hdrptr; |
4282 | } | |
19e6b90e | 4283 | |
77145576 | 4284 | static unsigned char * |
dda8d76d NC |
4285 | display_formatted_table (unsigned char * data, |
4286 | unsigned char * start, | |
4287 | unsigned char * end, | |
4288 | const DWARF2_Internal_LineInfo * linfo, | |
4289 | struct dwarf_section * section, | |
7b8d9e8c | 4290 | bfd_boolean is_dir) |
77145576 JK |
4291 | { |
4292 | unsigned char *format_start, format_count, *format, formati; | |
4293 | dwarf_vma data_count, datai; | |
cd30bcef | 4294 | unsigned int namepass, last_entry = 0; |
5496f3c6 | 4295 | const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table"); |
521d4b19 | 4296 | |
77145576 | 4297 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
546cb2d8 NC |
4298 | if (do_checks && format_count > 5) |
4299 | warn (_("Unexpectedly large number of columns in the %s (%u)\n"), | |
4300 | table_name, format_count); | |
4301 | ||
77145576 JK |
4302 | format_start = data; |
4303 | for (formati = 0; formati < format_count; formati++) | |
4304 | { | |
cd30bcef AM |
4305 | SKIP_ULEB (data, end); |
4306 | SKIP_ULEB (data, end); | |
77145576 JK |
4307 | if (data == end) |
4308 | { | |
5496f3c6 | 4309 | warn (_("%s: Corrupt format description entry\n"), table_name); |
77145576 JK |
4310 | return data; |
4311 | } | |
4312 | } | |
4313 | ||
cd30bcef | 4314 | READ_ULEB (data_count, data, end); |
546cb2d8 | 4315 | if (data_count == 0) |
77145576 | 4316 | { |
546cb2d8 | 4317 | printf (_("\n The %s is empty.\n"), table_name); |
77145576 JK |
4318 | return data; |
4319 | } | |
546cb2d8 | 4320 | else if (data == end) |
77145576 | 4321 | { |
546cb2d8 NC |
4322 | warn (_("%s: Corrupt entry count - expected %s but none found\n"), |
4323 | table_name, dwarf_vmatoa ("x", data_count)); | |
77145576 JK |
4324 | return data; |
4325 | } | |
546cb2d8 | 4326 | |
5496f3c6 NC |
4327 | else if (format_count == 0) |
4328 | { | |
4329 | warn (_("%s: format count is zero, but the table is not empty\n"), | |
4330 | table_name); | |
4331 | return end; | |
4332 | } | |
77145576 | 4333 | |
5496f3c6 NC |
4334 | printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"), |
4335 | table_name, (long) (data - start), dwarf_vmatoa ("u", data_count), | |
4336 | format_count); | |
77145576 JK |
4337 | |
4338 | printf (_(" Entry")); | |
521d4b19 | 4339 | /* Delay displaying name as the last entry for better screen layout. */ |
77145576 JK |
4340 | for (namepass = 0; namepass < 2; namepass++) |
4341 | { | |
4342 | format = format_start; | |
4343 | for (formati = 0; formati < format_count; formati++) | |
4344 | { | |
4345 | dwarf_vma content_type; | |
4346 | ||
cd30bcef | 4347 | READ_ULEB (content_type, format, end); |
77145576 JK |
4348 | if ((content_type == DW_LNCT_path) == (namepass == 1)) |
4349 | switch (content_type) | |
4350 | { | |
4351 | case DW_LNCT_path: | |
4352 | printf (_("\tName")); | |
4353 | break; | |
4354 | case DW_LNCT_directory_index: | |
4355 | printf (_("\tDir")); | |
4356 | break; | |
4357 | case DW_LNCT_timestamp: | |
4358 | printf (_("\tTime")); | |
4359 | break; | |
4360 | case DW_LNCT_size: | |
4361 | printf (_("\tSize")); | |
4362 | break; | |
4363 | case DW_LNCT_MD5: | |
5496f3c6 | 4364 | printf (_("\tMD5\t\t\t")); |
77145576 JK |
4365 | break; |
4366 | default: | |
4367 | printf (_("\t(Unknown format content type %s)"), | |
4368 | dwarf_vmatoa ("u", content_type)); | |
4369 | } | |
cd30bcef | 4370 | SKIP_ULEB (format, end); |
77145576 JK |
4371 | } |
4372 | } | |
4373 | putchar ('\n'); | |
4374 | ||
4375 | for (datai = 0; datai < data_count; datai++) | |
4376 | { | |
4377 | unsigned char *datapass = data; | |
4378 | ||
4379 | printf (" %d", last_entry++); | |
521d4b19 | 4380 | /* Delay displaying name as the last entry for better screen layout. */ |
77145576 JK |
4381 | for (namepass = 0; namepass < 2; namepass++) |
4382 | { | |
4383 | format = format_start; | |
4384 | data = datapass; | |
4385 | for (formati = 0; formati < format_count; formati++) | |
4386 | { | |
4387 | dwarf_vma content_type, form; | |
4388 | ||
cd30bcef AM |
4389 | READ_ULEB (content_type, format, end); |
4390 | READ_ULEB (form, format, end); | |
4391 | data = read_and_display_attr_value (0, form, 0, start, data, end, | |
4392 | 0, 0, linfo->li_offset_size, | |
77145576 JK |
4393 | linfo->li_version, NULL, |
4394 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
ec1b0fbb | 4395 | section, NULL, '\t', -1); |
77145576 JK |
4396 | } |
4397 | } | |
5496f3c6 NC |
4398 | |
4399 | if (data == end && (datai < data_count - 1)) | |
77145576 | 4400 | { |
5496f3c6 | 4401 | warn (_("\n%s: Corrupt entries list\n"), table_name); |
77145576 JK |
4402 | return data; |
4403 | } | |
4404 | putchar ('\n'); | |
4405 | } | |
4406 | return data; | |
4407 | } | |
4408 | ||
e38332c2 NC |
4409 | static int |
4410 | display_debug_sup (struct dwarf_section * section, | |
4411 | void * file ATTRIBUTE_UNUSED) | |
4412 | { | |
4413 | unsigned char * start = section->start; | |
4414 | unsigned char * end = section->start + section->size; | |
4415 | unsigned int version; | |
4416 | char is_supplementary; | |
4417 | const unsigned char * sup_filename; | |
4418 | size_t sup_filename_len; | |
4419 | unsigned int num_read; | |
4420 | int status; | |
4421 | dwarf_vma checksum_len; | |
4422 | ||
4423 | ||
4424 | introduce (section, TRUE); | |
4425 | if (section->size < 4) | |
4426 | { | |
4427 | error (_("corrupt .debug_sup section: size is too small\n")); | |
4428 | return 0; | |
4429 | } | |
4430 | ||
4431 | /* Read the data. */ | |
4432 | SAFE_BYTE_GET_AND_INC (version, start, 2, end); | |
4433 | if (version < 5) | |
4434 | warn (_("corrupt .debug_sup section: version < 5")); | |
4435 | ||
4436 | SAFE_BYTE_GET_AND_INC (is_supplementary, start, 1, end); | |
4437 | if (is_supplementary != 0 && is_supplementary != 1) | |
4438 | warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n")); | |
4439 | ||
4440 | sup_filename = start; | |
4441 | if (is_supplementary && sup_filename[0] != 0) | |
4442 | warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n")); | |
4443 | ||
4444 | sup_filename_len = strnlen ((const char *) start, end - start); | |
4445 | if (sup_filename_len == (size_t) (end - start)) | |
4446 | { | |
4447 | error (_("corrupt .debug_sup section: filename is not NUL terminated\n")); | |
4448 | return 0; | |
4449 | } | |
4450 | start += sup_filename_len + 1; | |
4451 | ||
4452 | checksum_len = read_leb128 (start, end, FALSE /* unsigned */, & num_read, & status); | |
4453 | if (status) | |
4454 | { | |
4455 | error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n")); | |
4456 | checksum_len = 0; | |
4457 | } | |
4458 | start += num_read; | |
4459 | if (checksum_len > (dwarf_vma) (end - start)) | |
4460 | { | |
4461 | error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n")); | |
4462 | checksum_len = end - start; | |
4463 | } | |
4464 | else if (checksum_len < (dwarf_vma) (end - start)) | |
4465 | { | |
4466 | warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"), | |
4467 | (long) ((end - start) - checksum_len)); | |
4468 | } | |
4469 | ||
4470 | printf (_(" Version: %u\n"), version); | |
4471 | printf (_(" Is Supp: %u\n"), is_supplementary); | |
4472 | printf (_(" Filename: %s\n"), sup_filename); | |
4473 | printf (_(" Checksum Len: %lu\n"), (long) checksum_len); | |
4474 | if (checksum_len > 0) | |
4475 | { | |
4476 | printf (_(" Checksum: ")); | |
4477 | while (checksum_len--) | |
4478 | printf ("0x%x ", * start++ ); | |
4479 | printf ("\n"); | |
4480 | } | |
4481 | return 1; | |
4482 | } | |
4483 | ||
b40bf0a2 | 4484 | static int |
dda8d76d NC |
4485 | display_debug_lines_raw (struct dwarf_section * section, |
4486 | unsigned char * data, | |
4487 | unsigned char * end, | |
4488 | void * file) | |
b40bf0a2 NC |
4489 | { |
4490 | unsigned char *start = section->start; | |
ba8826a8 | 4491 | int verbose_view = 0; |
19e6b90e | 4492 | |
dda8d76d | 4493 | introduce (section, TRUE); |
19e6b90e | 4494 | |
b40bf0a2 NC |
4495 | while (data < end) |
4496 | { | |
4497 | static DWARF2_Internal_LineInfo saved_linfo; | |
4498 | DWARF2_Internal_LineInfo linfo; | |
4499 | unsigned char *standard_opcodes; | |
4500 | unsigned char *end_of_sequence; | |
fe59e83d | 4501 | int i; |
19e6b90e | 4502 | |
4925cdd7 NC |
4503 | if (const_strneq (section->name, ".debug_line.") |
4504 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4505 | These are full debug_line sections. */ | |
4506 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 4507 | { |
b40bf0a2 NC |
4508 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
4509 | section containing just the Line Number Statements. They are | |
4510 | created by the assembler and intended to be used alongside gcc's | |
4511 | -ffunction-sections command line option. When the linker's | |
4512 | garbage collection decides to discard a .text.<foo> section it | |
4513 | can then also discard the line number information in .debug_line.<foo>. | |
4514 | ||
4925cdd7 | 4515 | Since the section is a fragment it does not have the details |
b40bf0a2 | 4516 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 4517 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
4518 | end_of_sequence = end; |
4519 | standard_opcodes = NULL; | |
4520 | linfo = saved_linfo; | |
058037d3 NC |
4521 | /* PR 17531: file: 0522b371. */ |
4522 | if (linfo.li_line_range == 0) | |
4523 | { | |
1306a742 | 4524 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4525 | return 0; |
4526 | } | |
b40bf0a2 | 4527 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4528 | } |
19e6b90e L |
4529 | else |
4530 | { | |
b40bf0a2 | 4531 | unsigned char * hdrptr; |
19e6b90e | 4532 | |
b40bf0a2 NC |
4533 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4534 | & end_of_sequence)) == NULL) | |
4535 | return 0; | |
19e6b90e | 4536 | |
b40bf0a2 NC |
4537 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
4538 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
4539 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
5496f3c6 NC |
4540 | if (linfo.li_version >= 5) |
4541 | { | |
4542 | printf (_(" Address size (bytes): %d\n"), linfo.li_address_size); | |
4543 | printf (_(" Segment selector (bytes): %d\n"), linfo.li_segment_size); | |
4544 | } | |
77ef8654 | 4545 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
4546 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
4547 | if (linfo.li_version >= 4) | |
4548 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
4549 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
4550 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
4551 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
4552 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 4553 | |
0a9d414a NC |
4554 | /* PR 17512: file: 1665-6428-0.004. */ |
4555 | if (linfo.li_line_range == 0) | |
4556 | { | |
4557 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4558 | linfo.li_line_range = 1; | |
4559 | } | |
77ef8654 | 4560 | |
b40bf0a2 | 4561 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4562 | |
b40bf0a2 NC |
4563 | /* Display the contents of the Opcodes table. */ |
4564 | standard_opcodes = hdrptr; | |
19e6b90e | 4565 | |
6937bb54 NC |
4566 | /* PR 17512: file: 002-417945-0.004. */ |
4567 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
4568 | { | |
4569 | warn (_("Line Base extends beyond end of section\n")); | |
4570 | return 0; | |
4571 | } | |
4572 | ||
b40bf0a2 | 4573 | printf (_("\n Opcodes:\n")); |
19e6b90e | 4574 | |
b40bf0a2 | 4575 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
4576 | printf (ngettext (" Opcode %d has %d arg\n", |
4577 | " Opcode %d has %d args\n", | |
4578 | standard_opcodes[i - 1]), | |
4579 | i, standard_opcodes[i - 1]); | |
19e6b90e | 4580 | |
b40bf0a2 NC |
4581 | /* Display the contents of the Directory table. */ |
4582 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 4583 | |
77145576 | 4584 | if (linfo.li_version >= 5) |
b40bf0a2 | 4585 | { |
dda8d76d | 4586 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 4587 | |
77145576 | 4588 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 4589 | TRUE); |
77145576 | 4590 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 4591 | FALSE); |
77145576 JK |
4592 | } |
4593 | else | |
4594 | { | |
4595 | if (*data == 0) | |
4596 | printf (_("\n The Directory Table is empty.\n")); | |
4597 | else | |
a233b20c | 4598 | { |
77145576 | 4599 | unsigned int last_dir_entry = 0; |
6937bb54 | 4600 | |
77145576 JK |
4601 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
4602 | (long)(data - start)); | |
19e6b90e | 4603 | |
77145576 JK |
4604 | while (data < end && *data != 0) |
4605 | { | |
4606 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 4607 | |
77145576 JK |
4608 | data += strnlen ((char *) data, end - data) + 1; |
4609 | } | |
19e6b90e | 4610 | |
77145576 JK |
4611 | /* PR 17512: file: 002-132094-0.004. */ |
4612 | if (data >= end - 1) | |
4613 | break; | |
4614 | } | |
19e6b90e | 4615 | |
77145576 JK |
4616 | /* Skip the NUL at the end of the table. */ |
4617 | data++; | |
19e6b90e | 4618 | |
77145576 JK |
4619 | /* Display the contents of the File Name table. */ |
4620 | if (*data == 0) | |
4621 | printf (_("\n The File Name Table is empty.\n")); | |
4622 | else | |
4623 | { | |
4624 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
4625 | (long)(data - start)); | |
4626 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 4627 | |
77145576 | 4628 | while (data < end && *data != 0) |
b40bf0a2 | 4629 | { |
77145576 | 4630 | unsigned char *name; |
cd30bcef | 4631 | dwarf_vma val; |
77145576 JK |
4632 | |
4633 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
4634 | name = data; | |
4635 | data += strnlen ((char *) data, end - data) + 1; | |
4636 | ||
cd30bcef AM |
4637 | READ_ULEB (val, data, end); |
4638 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4639 | READ_ULEB (val, data, end); | |
4640 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4641 | READ_ULEB (val, data, end); | |
4642 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
77145576 JK |
4643 | printf ("%.*s\n", (int)(end - name), name); |
4644 | ||
4645 | if (data == end) | |
4646 | { | |
4647 | warn (_("Corrupt file name table entry\n")); | |
4648 | break; | |
4649 | } | |
b40bf0a2 | 4650 | } |
a233b20c | 4651 | } |
77145576 JK |
4652 | |
4653 | /* Skip the NUL at the end of the table. */ | |
4654 | data++; | |
b40bf0a2 | 4655 | } |
19e6b90e | 4656 | |
b40bf0a2 NC |
4657 | putchar ('\n'); |
4658 | saved_linfo = linfo; | |
4659 | } | |
19e6b90e | 4660 | |
b40bf0a2 NC |
4661 | /* Now display the statements. */ |
4662 | if (data >= end_of_sequence) | |
4663 | printf (_(" No Line Number Statements.\n")); | |
4664 | else | |
4665 | { | |
4666 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 4667 | |
b40bf0a2 NC |
4668 | while (data < end_of_sequence) |
4669 | { | |
4670 | unsigned char op_code; | |
4671 | dwarf_signed_vma adv; | |
4672 | dwarf_vma uladv; | |
19e6b90e | 4673 | |
fe59e83d CC |
4674 | printf (" [0x%08lx]", (long)(data - start)); |
4675 | ||
b40bf0a2 | 4676 | op_code = *data++; |
19e6b90e | 4677 | |
b40bf0a2 | 4678 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 4679 | { |
b40bf0a2 NC |
4680 | op_code -= linfo.li_opcode_base; |
4681 | uladv = (op_code / linfo.li_line_range); | |
4682 | if (linfo.li_max_ops_per_insn == 1) | |
4683 | { | |
4684 | uladv *= linfo.li_min_insn_length; | |
4685 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4686 | if (uladv) |
4687 | state_machine_regs.view = 0; | |
b40bf0a2 | 4688 | printf (_(" Special opcode %d: " |
ba8826a8 | 4689 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 4690 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4691 | dwarf_vmatoa ("x", state_machine_regs.address), |
4692 | verbose_view && uladv | |
4693 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4694 | } |
4695 | else | |
4696 | { | |
ba8826a8 AO |
4697 | unsigned addrdelta |
4698 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
4699 | / linfo.li_max_ops_per_insn) |
4700 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
4701 | |
4702 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
4703 | state_machine_regs.op_index |
4704 | = (state_machine_regs.op_index + uladv) | |
4705 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4706 | if (addrdelta) |
4707 | state_machine_regs.view = 0; | |
b40bf0a2 | 4708 | printf (_(" Special opcode %d: " |
ba8826a8 | 4709 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
4710 | op_code, dwarf_vmatoa ("u", uladv), |
4711 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4712 | state_machine_regs.op_index, |
4713 | verbose_view && addrdelta | |
4714 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4715 | } |
4716 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
4717 | state_machine_regs.line += adv; | |
ba8826a8 | 4718 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 4719 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
4720 | if (verbose_view || state_machine_regs.view) |
4721 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4722 | else | |
4723 | putchar ('\n'); | |
4724 | state_machine_regs.view++; | |
19e6b90e | 4725 | } |
cd30bcef AM |
4726 | else |
4727 | switch (op_code) | |
4728 | { | |
4729 | case DW_LNS_extended_op: | |
4730 | data += process_extended_line_op (data, | |
4731 | linfo.li_default_is_stmt, | |
4732 | end); | |
4733 | break; | |
4734 | ||
4735 | case DW_LNS_copy: | |
4736 | printf (_(" Copy")); | |
4737 | if (verbose_view || state_machine_regs.view) | |
4738 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4739 | else | |
4740 | putchar ('\n'); | |
4741 | state_machine_regs.view++; | |
4742 | break; | |
4743 | ||
4744 | case DW_LNS_advance_pc: | |
4745 | READ_ULEB (uladv, data, end); | |
4746 | if (linfo.li_max_ops_per_insn == 1) | |
4747 | { | |
4748 | uladv *= linfo.li_min_insn_length; | |
4749 | state_machine_regs.address += uladv; | |
4750 | if (uladv) | |
4751 | state_machine_regs.view = 0; | |
4752 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
4753 | dwarf_vmatoa ("u", uladv), | |
4754 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4755 | verbose_view && uladv | |
4756 | ? _(" (reset view)") : ""); | |
4757 | } | |
4758 | else | |
4759 | { | |
4760 | unsigned addrdelta | |
4761 | = ((state_machine_regs.op_index + uladv) | |
4762 | / linfo.li_max_ops_per_insn) | |
4763 | * linfo.li_min_insn_length; | |
4764 | state_machine_regs.address | |
4765 | += addrdelta; | |
4766 | state_machine_regs.op_index | |
4767 | = (state_machine_regs.op_index + uladv) | |
4768 | % linfo.li_max_ops_per_insn; | |
4769 | if (addrdelta) | |
4770 | state_machine_regs.view = 0; | |
4771 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
4772 | dwarf_vmatoa ("u", uladv), | |
4773 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4774 | state_machine_regs.op_index, | |
4775 | verbose_view && addrdelta | |
4776 | ? _(" (reset view)") : ""); | |
4777 | } | |
4778 | break; | |
4779 | ||
4780 | case DW_LNS_advance_line: | |
4781 | READ_SLEB (adv, data, end); | |
4782 | state_machine_regs.line += adv; | |
4783 | printf (_(" Advance Line by %s to %d\n"), | |
4784 | dwarf_vmatoa ("d", adv), | |
4785 | state_machine_regs.line); | |
4786 | break; | |
4787 | ||
4788 | case DW_LNS_set_file: | |
4789 | READ_ULEB (uladv, data, end); | |
4790 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
4791 | dwarf_vmatoa ("u", uladv)); | |
4792 | state_machine_regs.file = uladv; | |
4793 | break; | |
4794 | ||
4795 | case DW_LNS_set_column: | |
4796 | READ_ULEB (uladv, data, end); | |
4797 | printf (_(" Set column to %s\n"), | |
4798 | dwarf_vmatoa ("u", uladv)); | |
4799 | state_machine_regs.column = uladv; | |
4800 | break; | |
4801 | ||
4802 | case DW_LNS_negate_stmt: | |
4803 | adv = state_machine_regs.is_stmt; | |
4804 | adv = ! adv; | |
4805 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
4806 | state_machine_regs.is_stmt = adv; | |
4807 | break; | |
4808 | ||
4809 | case DW_LNS_set_basic_block: | |
4810 | printf (_(" Set basic block\n")); | |
4811 | state_machine_regs.basic_block = 1; | |
4812 | break; | |
4813 | ||
4814 | case DW_LNS_const_add_pc: | |
4815 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4816 | if (linfo.li_max_ops_per_insn) | |
4817 | { | |
4818 | uladv *= linfo.li_min_insn_length; | |
4819 | state_machine_regs.address += uladv; | |
4820 | if (uladv) | |
4821 | state_machine_regs.view = 0; | |
4822 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
4823 | dwarf_vmatoa ("u", uladv), | |
4824 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4825 | verbose_view && uladv | |
4826 | ? _(" (reset view)") : ""); | |
4827 | } | |
4828 | else | |
4829 | { | |
4830 | unsigned addrdelta | |
4831 | = ((state_machine_regs.op_index + uladv) | |
4832 | / linfo.li_max_ops_per_insn) | |
4833 | * linfo.li_min_insn_length; | |
4834 | state_machine_regs.address | |
4835 | += addrdelta; | |
4836 | state_machine_regs.op_index | |
4837 | = (state_machine_regs.op_index + uladv) | |
4838 | % linfo.li_max_ops_per_insn; | |
4839 | if (addrdelta) | |
4840 | state_machine_regs.view = 0; | |
4841 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
4842 | dwarf_vmatoa ("u", uladv), | |
4843 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4844 | state_machine_regs.op_index, | |
4845 | verbose_view && addrdelta | |
4846 | ? _(" (reset view)") : ""); | |
4847 | } | |
4848 | break; | |
4849 | ||
4850 | case DW_LNS_fixed_advance_pc: | |
4851 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4852 | state_machine_regs.address += uladv; | |
4853 | state_machine_regs.op_index = 0; | |
4854 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
4855 | dwarf_vmatoa ("u", uladv), | |
4856 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
4857 | /* Do NOT reset view. */ | |
4858 | break; | |
4859 | ||
4860 | case DW_LNS_set_prologue_end: | |
4861 | printf (_(" Set prologue_end to true\n")); | |
4862 | break; | |
4863 | ||
4864 | case DW_LNS_set_epilogue_begin: | |
4865 | printf (_(" Set epilogue_begin to true\n")); | |
4866 | break; | |
4867 | ||
4868 | case DW_LNS_set_isa: | |
4869 | READ_ULEB (uladv, data, end); | |
4870 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
4871 | break; | |
4872 | ||
4873 | default: | |
4874 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4875 | ||
4876 | if (standard_opcodes != NULL) | |
4877 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4878 | { | |
4879 | READ_ULEB (uladv, data, end); | |
4880 | printf ("0x%s%s", dwarf_vmatoa ("x", uladv), | |
4881 | i == 1 ? "" : ", "); | |
4882 | } | |
4883 | putchar ('\n'); | |
4884 | break; | |
4885 | } | |
19e6b90e | 4886 | } |
b40bf0a2 | 4887 | putchar ('\n'); |
19e6b90e | 4888 | } |
19e6b90e L |
4889 | } |
4890 | ||
4891 | return 1; | |
4892 | } | |
4893 | ||
a262ae96 NC |
4894 | typedef struct |
4895 | { | |
467c65bc NC |
4896 | unsigned char *name; |
4897 | unsigned int directory_index; | |
4898 | unsigned int modification_date; | |
4899 | unsigned int length; | |
a262ae96 NC |
4900 | } File_Entry; |
4901 | ||
4902 | /* Output a decoded representation of the .debug_line section. */ | |
4903 | ||
4904 | static int | |
dda8d76d | 4905 | display_debug_lines_decoded (struct dwarf_section * section, |
ec1b0fbb | 4906 | unsigned char * start, |
dda8d76d NC |
4907 | unsigned char * data, |
4908 | unsigned char * end, | |
4909 | void * fileptr) | |
a262ae96 | 4910 | { |
b40bf0a2 NC |
4911 | static DWARF2_Internal_LineInfo saved_linfo; |
4912 | ||
dda8d76d | 4913 | introduce (section, FALSE); |
a262ae96 NC |
4914 | |
4915 | while (data < end) | |
4916 | { | |
4917 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4918 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4919 | unsigned char *standard_opcodes; |
4920 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4921 | int i; |
4922 | File_Entry *file_table = NULL; | |
143a3db0 | 4923 | unsigned int n_files = 0; |
a262ae96 | 4924 | unsigned char **directory_table = NULL; |
77145576 | 4925 | dwarf_vma n_directories = 0; |
a262ae96 | 4926 | |
4925cdd7 NC |
4927 | if (const_strneq (section->name, ".debug_line.") |
4928 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4929 | These are full debug_line sections. */ | |
4930 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4931 | { |
4925cdd7 | 4932 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4933 | end_of_sequence = end; |
4934 | standard_opcodes = NULL; | |
4935 | linfo = saved_linfo; | |
058037d3 NC |
4936 | /* PR 17531: file: 0522b371. */ |
4937 | if (linfo.li_line_range == 0) | |
4938 | { | |
1306a742 | 4939 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4940 | return 0; |
4941 | } | |
b40bf0a2 | 4942 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4943 | } |
a262ae96 | 4944 | else |
b4eb7656 | 4945 | { |
b40bf0a2 | 4946 | unsigned char *hdrptr; |
a262ae96 | 4947 | |
b40bf0a2 NC |
4948 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4949 | & end_of_sequence)) == NULL) | |
a233b20c | 4950 | return 0; |
0c588247 | 4951 | |
058037d3 NC |
4952 | /* PR 17531: file: 0522b371. */ |
4953 | if (linfo.li_line_range == 0) | |
4954 | { | |
4955 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4956 | linfo.li_line_range = 1; | |
4957 | } | |
b40bf0a2 | 4958 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4959 | |
b40bf0a2 NC |
4960 | /* Save a pointer to the contents of the Opcodes table. */ |
4961 | standard_opcodes = hdrptr; | |
a262ae96 | 4962 | |
b40bf0a2 NC |
4963 | /* Traverse the Directory table just to count entries. */ |
4964 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4965 | /* PR 20440 */ |
4966 | if (data >= end) | |
4967 | { | |
4968 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4969 | linfo.li_opcode_base); | |
4970 | return 0; | |
4971 | } | |
4972 | ||
77145576 | 4973 | if (linfo.li_version >= 5) |
b40bf0a2 | 4974 | { |
77145576 JK |
4975 | unsigned char *format_start, format_count, *format; |
4976 | dwarf_vma formati, entryi; | |
a262ae96 | 4977 | |
dda8d76d | 4978 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4979 | |
4980 | /* Skip directories format. */ | |
4981 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4982 | if (do_checks && format_count > 1) |
4983 | warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"), | |
4984 | format_count); | |
77145576 JK |
4985 | format_start = data; |
4986 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4987 | { |
cd30bcef AM |
4988 | SKIP_ULEB (data, end); |
4989 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4990 | } |
a262ae96 | 4991 | |
cd30bcef | 4992 | READ_ULEB (n_directories, data, end); |
77145576 | 4993 | if (data == end) |
d8024a91 | 4994 | { |
77145576 | 4995 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
4996 | break; |
4997 | } | |
4998 | ||
070b775f NC |
4999 | if (n_directories == 0) |
5000 | directory_table = NULL; | |
5001 | else | |
5002 | directory_table = (unsigned char **) | |
5003 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 5004 | |
77145576 | 5005 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 5006 | { |
77145576 | 5007 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 5008 | |
77145576 JK |
5009 | format = format_start; |
5010 | for (formati = 0; formati < format_count; formati++) | |
5011 | { | |
5012 | dwarf_vma content_type, form; | |
5013 | dwarf_vma uvalue; | |
5014 | ||
cd30bcef AM |
5015 | READ_ULEB (content_type, format, end); |
5016 | READ_ULEB (form, format, end); | |
77145576 JK |
5017 | if (data == end) |
5018 | { | |
5019 | warn (_("Corrupt directories list\n")); | |
5020 | break; | |
5021 | } | |
5022 | switch (content_type) | |
5023 | { | |
5024 | case DW_LNCT_path: | |
5025 | switch (form) | |
5026 | { | |
5027 | case DW_FORM_string: | |
5028 | *pathp = data; | |
5029 | break; | |
5030 | case DW_FORM_line_strp: | |
5031 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
5032 | end); | |
5033 | /* Remove const by the cast. */ | |
5034 | *pathp = (unsigned char *) | |
5035 | fetch_indirect_line_string (uvalue); | |
5036 | break; | |
5037 | } | |
5038 | break; | |
5039 | } | |
cd30bcef AM |
5040 | data = read_and_display_attr_value (0, form, 0, start, |
5041 | data, end, 0, 0, | |
77145576 JK |
5042 | linfo.li_offset_size, |
5043 | linfo.li_version, | |
5044 | NULL, 1, section, | |
ec1b0fbb | 5045 | NULL, '\t', -1); |
77145576 JK |
5046 | } |
5047 | if (data == end) | |
5048 | { | |
5049 | warn (_("Corrupt directories list\n")); | |
5050 | break; | |
5051 | } | |
5052 | } | |
a262ae96 | 5053 | |
77145576 JK |
5054 | /* Skip files format. */ |
5055 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
5056 | if (do_checks && format_count > 5) |
5057 | warn (_("Unexpectedly large number of columns in the file name table (%u)\n"), | |
5058 | format_count); | |
77145576 JK |
5059 | format_start = data; |
5060 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 5061 | { |
cd30bcef AM |
5062 | SKIP_ULEB (data, end); |
5063 | SKIP_ULEB (data, end); | |
b40bf0a2 | 5064 | } |
a262ae96 | 5065 | |
cd30bcef | 5066 | READ_ULEB (n_files, data, end); |
070b775f | 5067 | if (data == end && n_files > 0) |
d8024a91 | 5068 | { |
77145576 | 5069 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
5070 | break; |
5071 | } | |
5072 | ||
070b775f NC |
5073 | if (n_files == 0) |
5074 | file_table = NULL; | |
5075 | else | |
5076 | file_table = (File_Entry *) xcalloc (1, n_files | |
5077 | * sizeof (File_Entry)); | |
a262ae96 | 5078 | |
77145576 | 5079 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 5080 | { |
77145576 | 5081 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 5082 | |
77145576 JK |
5083 | format = format_start; |
5084 | for (formati = 0; formati < format_count; formati++) | |
5085 | { | |
5086 | dwarf_vma content_type, form; | |
5087 | dwarf_vma uvalue; | |
cd30bcef | 5088 | unsigned char *tmp; |
77145576 | 5089 | |
cd30bcef AM |
5090 | READ_ULEB (content_type, format, end); |
5091 | READ_ULEB (form, format, end); | |
77145576 JK |
5092 | if (data == end) |
5093 | { | |
5094 | warn (_("Corrupt file name list\n")); | |
5095 | break; | |
5096 | } | |
5097 | switch (content_type) | |
5098 | { | |
5099 | case DW_LNCT_path: | |
5100 | switch (form) | |
5101 | { | |
5102 | case DW_FORM_string: | |
5103 | file->name = data; | |
5104 | break; | |
5105 | case DW_FORM_line_strp: | |
5106 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
5107 | end); | |
5108 | /* Remove const by the cast. */ | |
5109 | file->name = (unsigned char *) | |
5110 | fetch_indirect_line_string (uvalue); | |
5111 | break; | |
5112 | } | |
5113 | break; | |
5114 | case DW_LNCT_directory_index: | |
5115 | switch (form) | |
5116 | { | |
5117 | case DW_FORM_data1: | |
5118 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
5119 | end); | |
5120 | break; | |
5121 | case DW_FORM_data2: | |
5122 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
5123 | end); | |
5124 | break; | |
5125 | case DW_FORM_udata: | |
cd30bcef AM |
5126 | tmp = data; |
5127 | READ_ULEB (file->directory_index, tmp, end); | |
77145576 JK |
5128 | break; |
5129 | } | |
5130 | break; | |
5131 | } | |
cd30bcef AM |
5132 | data = read_and_display_attr_value (0, form, 0, start, |
5133 | data, end, 0, 0, | |
77145576 JK |
5134 | linfo.li_offset_size, |
5135 | linfo.li_version, | |
5136 | NULL, 1, section, | |
ec1b0fbb | 5137 | NULL, '\t', -1); |
77145576 JK |
5138 | } |
5139 | if (data == end) | |
5140 | { | |
5141 | warn (_("Corrupt file name list\n")); | |
5142 | break; | |
5143 | } | |
5144 | } | |
5145 | } | |
5146 | else | |
5147 | { | |
5148 | if (*data != 0) | |
b40bf0a2 | 5149 | { |
77145576 JK |
5150 | unsigned char *ptr_directory_table = data; |
5151 | ||
5152 | while (data < end && *data != 0) | |
5153 | { | |
5154 | data += strnlen ((char *) data, end - data) + 1; | |
5155 | n_directories++; | |
5156 | } | |
5157 | ||
5158 | /* PR 20440 */ | |
5159 | if (data >= end) | |
5160 | { | |
5161 | warn (_("directory table ends unexpectedly\n")); | |
5162 | n_directories = 0; | |
5163 | break; | |
5164 | } | |
5165 | ||
5166 | /* Go through the directory table again to save the directories. */ | |
5167 | directory_table = (unsigned char **) | |
5168 | xmalloc (n_directories * sizeof (unsigned char *)); | |
5169 | ||
5170 | i = 0; | |
5171 | while (*ptr_directory_table != 0) | |
5172 | { | |
5173 | directory_table[i] = ptr_directory_table; | |
5174 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
5175 | ptr_directory_table - end) + 1; | |
5176 | i++; | |
5177 | } | |
b40bf0a2 | 5178 | } |
77145576 JK |
5179 | /* Skip the NUL at the end of the table. */ |
5180 | data++; | |
5181 | ||
5182 | /* Traverse the File Name table just to count the entries. */ | |
5183 | if (data < end && *data != 0) | |
b40bf0a2 | 5184 | { |
77145576 JK |
5185 | unsigned char *ptr_file_name_table = data; |
5186 | ||
5187 | while (data < end && *data != 0) | |
db9537d2 | 5188 | { |
cd30bcef AM |
5189 | /* Skip Name, directory index, last modification |
5190 | time and length of file. */ | |
77145576 | 5191 | data += strnlen ((char *) data, end - data) + 1; |
cd30bcef AM |
5192 | SKIP_ULEB (data, end); |
5193 | SKIP_ULEB (data, end); | |
5194 | SKIP_ULEB (data, end); | |
77145576 | 5195 | n_files++; |
db9537d2 | 5196 | } |
a262ae96 | 5197 | |
77145576 JK |
5198 | if (data >= end) |
5199 | { | |
5200 | warn (_("file table ends unexpectedly\n")); | |
5201 | n_files = 0; | |
5202 | break; | |
5203 | } | |
5204 | ||
5205 | /* Go through the file table again to save the strings. */ | |
5206 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 5207 | |
77145576 JK |
5208 | i = 0; |
5209 | while (*ptr_file_name_table != 0) | |
5210 | { | |
77145576 JK |
5211 | file_table[i].name = ptr_file_name_table; |
5212 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
5213 | end - ptr_file_name_table) + 1; | |
5214 | ||
5215 | /* We are not interested in directory, time or size. */ | |
cd30bcef AM |
5216 | READ_ULEB (file_table[i].directory_index, |
5217 | ptr_file_name_table, end); | |
5218 | READ_ULEB (file_table[i].modification_date, | |
5219 | ptr_file_name_table, end); | |
5220 | READ_ULEB (file_table[i].length, | |
5221 | ptr_file_name_table, end); | |
77145576 JK |
5222 | i++; |
5223 | } | |
5224 | i = 0; | |
b40bf0a2 | 5225 | } |
77145576 JK |
5226 | |
5227 | /* Skip the NUL at the end of the table. */ | |
5228 | data++; | |
b40bf0a2 | 5229 | } |
cc5914eb | 5230 | |
77145576 | 5231 | /* Print the Compilation Unit's name and a header. */ |
f082820d | 5232 | if (file_table == NULL) |
070b775f | 5233 | printf (_("CU: No directory table\n")); |
f082820d AM |
5234 | else if (directory_table == NULL) |
5235 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
5236 | else |
5237 | { | |
5238 | unsigned int ix = file_table[0].directory_index; | |
5239 | const char *directory; | |
5240 | ||
5241 | if (ix == 0) | |
5242 | directory = "."; | |
5243 | /* PR 20439 */ | |
5244 | else if (n_directories == 0) | |
5245 | directory = _("<unknown>"); | |
5246 | else if (ix > n_directories) | |
5247 | { | |
5248 | warn (_("directory index %u > number of directories %s\n"), | |
5249 | ix, dwarf_vmatoa ("u", n_directories)); | |
5250 | directory = _("<corrupt>"); | |
5251 | } | |
5252 | else | |
5253 | directory = (char *) directory_table[ix - 1]; | |
5254 | ||
5255 | if (do_wide || strlen (directory) < 76) | |
5256 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
5257 | else | |
5258 | printf ("%s:\n", file_table[0].name); | |
77145576 | 5259 | } |
a262ae96 | 5260 | |
070b775f NC |
5261 | if (n_files > 0) |
5262 | printf (_("File name Line number Starting address View Stmt\n")); | |
5263 | else | |
5264 | printf (_("CU: Empty file name table\n")); | |
b40bf0a2 NC |
5265 | saved_linfo = linfo; |
5266 | } | |
a262ae96 NC |
5267 | |
5268 | /* This loop iterates through the Dwarf Line Number Program. */ | |
5269 | while (data < end_of_sequence) | |
b4eb7656 | 5270 | { |
a262ae96 | 5271 | unsigned char op_code; |
ba8826a8 | 5272 | int xop; |
b4eb7656 AM |
5273 | int adv; |
5274 | unsigned long int uladv; | |
b4eb7656 | 5275 | int is_special_opcode = 0; |
a262ae96 | 5276 | |
b4eb7656 | 5277 | op_code = *data++; |
ba8826a8 | 5278 | xop = op_code; |
a262ae96 | 5279 | |
b4eb7656 | 5280 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 5281 | { |
91d6fa6a | 5282 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
5283 | uladv = (op_code / linfo.li_line_range); |
5284 | if (linfo.li_max_ops_per_insn == 1) | |
5285 | { | |
5286 | uladv *= linfo.li_min_insn_length; | |
5287 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
5288 | if (uladv) |
5289 | state_machine_regs.view = 0; | |
a233b20c JJ |
5290 | } |
5291 | else | |
5292 | { | |
ba8826a8 AO |
5293 | unsigned addrdelta |
5294 | = ((state_machine_regs.op_index + uladv) | |
5295 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 5296 | * linfo.li_min_insn_length; |
ba8826a8 AO |
5297 | state_machine_regs.address |
5298 | += addrdelta; | |
a233b20c JJ |
5299 | state_machine_regs.op_index |
5300 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 5301 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
5302 | if (addrdelta) |
5303 | state_machine_regs.view = 0; | |
a233b20c | 5304 | } |
a262ae96 | 5305 | |
b4eb7656 AM |
5306 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
5307 | state_machine_regs.line += adv; | |
5308 | is_special_opcode = 1; | |
ba8826a8 | 5309 | /* Increment view after printing this row. */ |
b4eb7656 | 5310 | } |
cd30bcef AM |
5311 | else |
5312 | switch (op_code) | |
5313 | { | |
5314 | case DW_LNS_extended_op: | |
5315 | { | |
5316 | unsigned int ext_op_code_len; | |
5317 | unsigned char ext_op_code; | |
5318 | unsigned char *op_code_end; | |
5319 | unsigned char *op_code_data = data; | |
5320 | ||
5321 | READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence); | |
5322 | op_code_end = op_code_data + ext_op_code_len; | |
5323 | if (ext_op_code_len == 0 || op_code_end > end_of_sequence) | |
5324 | { | |
5325 | warn (_("Badly formed extended line op encountered!\n")); | |
5326 | break; | |
5327 | } | |
5328 | ext_op_code = *op_code_data++; | |
5329 | xop = ext_op_code; | |
5330 | xop = -xop; | |
5331 | ||
5332 | switch (ext_op_code) | |
5333 | { | |
5334 | case DW_LNE_end_sequence: | |
5335 | /* Reset stuff after printing this row. */ | |
5336 | break; | |
5337 | case DW_LNE_set_address: | |
5338 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
5339 | op_code_data, | |
5340 | op_code_end - op_code_data, | |
5341 | op_code_end); | |
5342 | state_machine_regs.op_index = 0; | |
5343 | state_machine_regs.view = 0; | |
5344 | break; | |
5345 | case DW_LNE_define_file: | |
5346 | file_table = (File_Entry *) xrealloc | |
5347 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
5348 | ||
5349 | ++state_machine_regs.last_file_entry; | |
5350 | /* Source file name. */ | |
5351 | file_table[n_files].name = op_code_data; | |
5352 | op_code_data += strlen ((char *) op_code_data) + 1; | |
5353 | /* Directory index. */ | |
5354 | READ_ULEB (file_table[n_files].directory_index, | |
5355 | op_code_data, op_code_end); | |
5356 | /* Last modification time. */ | |
5357 | READ_ULEB (file_table[n_files].modification_date, | |
5358 | op_code_data, op_code_end); | |
5359 | /* File length. */ | |
5360 | READ_ULEB (file_table[n_files].length, | |
5361 | op_code_data, op_code_end); | |
5362 | n_files++; | |
5363 | break; | |
5364 | ||
5365 | case DW_LNE_set_discriminator: | |
5366 | case DW_LNE_HP_set_sequence: | |
5367 | /* Simply ignored. */ | |
5368 | break; | |
5369 | ||
5370 | default: | |
5371 | printf (_("UNKNOWN (%u): length %ld\n"), | |
27653fba | 5372 | ext_op_code, (long int) (op_code_data - data)); |
cd30bcef AM |
5373 | break; |
5374 | } | |
5375 | data = op_code_end; | |
5376 | break; | |
5377 | } | |
5378 | case DW_LNS_copy: | |
5379 | /* Increment view after printing this row. */ | |
5380 | break; | |
5381 | ||
5382 | case DW_LNS_advance_pc: | |
5383 | READ_ULEB (uladv, data, end); | |
5384 | if (linfo.li_max_ops_per_insn == 1) | |
5385 | { | |
5386 | uladv *= linfo.li_min_insn_length; | |
5387 | state_machine_regs.address += uladv; | |
5388 | if (uladv) | |
5389 | state_machine_regs.view = 0; | |
5390 | } | |
5391 | else | |
5392 | { | |
5393 | unsigned addrdelta | |
5394 | = ((state_machine_regs.op_index + uladv) | |
5395 | / linfo.li_max_ops_per_insn) | |
5396 | * linfo.li_min_insn_length; | |
5397 | state_machine_regs.address | |
5398 | += addrdelta; | |
5399 | state_machine_regs.op_index | |
5400 | = (state_machine_regs.op_index + uladv) | |
5401 | % linfo.li_max_ops_per_insn; | |
5402 | if (addrdelta) | |
5403 | state_machine_regs.view = 0; | |
5404 | } | |
5405 | break; | |
5406 | ||
5407 | case DW_LNS_advance_line: | |
5408 | READ_SLEB (adv, data, end); | |
5409 | state_machine_regs.line += adv; | |
5410 | break; | |
5411 | ||
5412 | case DW_LNS_set_file: | |
5413 | READ_ULEB (uladv, data, end); | |
5414 | state_machine_regs.file = uladv; | |
5415 | ||
5416 | { | |
5417 | unsigned file = state_machine_regs.file - 1; | |
5418 | unsigned dir; | |
5419 | ||
5420 | if (file_table == NULL || n_files == 0) | |
5421 | printf (_("\n [Use file table entry %d]\n"), file); | |
5422 | /* PR 20439 */ | |
5423 | else if (file >= n_files) | |
5424 | { | |
5425 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
5426 | printf (_("\n <over large file table index %u>"), file); | |
5427 | } | |
5428 | else if ((dir = file_table[file].directory_index) == 0) | |
5429 | /* If directory index is 0, that means current directory. */ | |
5430 | printf ("\n./%s:[++]\n", file_table[file].name); | |
5431 | else if (directory_table == NULL || n_directories == 0) | |
5432 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
5433 | file_table[file].name, dir); | |
5434 | /* PR 20439 */ | |
5435 | else if (dir > n_directories) | |
5436 | { | |
5437 | warn (_("directory index %u > number of directories %s\n"), | |
5438 | dir, dwarf_vmatoa ("u", n_directories)); | |
5439 | printf (_("\n <over large directory table entry %u>\n"), dir); | |
5440 | } | |
5441 | else | |
5442 | printf ("\n%s/%s:\n", | |
5443 | /* The directory index starts counting at 1. */ | |
5444 | directory_table[dir - 1], file_table[file].name); | |
5445 | } | |
5446 | break; | |
5447 | ||
5448 | case DW_LNS_set_column: | |
5449 | READ_ULEB (uladv, data, end); | |
5450 | state_machine_regs.column = uladv; | |
5451 | break; | |
5452 | ||
5453 | case DW_LNS_negate_stmt: | |
5454 | adv = state_machine_regs.is_stmt; | |
5455 | adv = ! adv; | |
5456 | state_machine_regs.is_stmt = adv; | |
5457 | break; | |
5458 | ||
5459 | case DW_LNS_set_basic_block: | |
5460 | state_machine_regs.basic_block = 1; | |
5461 | break; | |
5462 | ||
5463 | case DW_LNS_const_add_pc: | |
5464 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
5465 | if (linfo.li_max_ops_per_insn == 1) | |
5466 | { | |
5467 | uladv *= linfo.li_min_insn_length; | |
5468 | state_machine_regs.address += uladv; | |
5469 | if (uladv) | |
5470 | state_machine_regs.view = 0; | |
5471 | } | |
5472 | else | |
5473 | { | |
5474 | unsigned addrdelta | |
5475 | = ((state_machine_regs.op_index + uladv) | |
5476 | / linfo.li_max_ops_per_insn) | |
5477 | * linfo.li_min_insn_length; | |
5478 | state_machine_regs.address | |
5479 | += addrdelta; | |
5480 | state_machine_regs.op_index | |
5481 | = (state_machine_regs.op_index + uladv) | |
5482 | % linfo.li_max_ops_per_insn; | |
5483 | if (addrdelta) | |
5484 | state_machine_regs.view = 0; | |
5485 | } | |
5486 | break; | |
5487 | ||
5488 | case DW_LNS_fixed_advance_pc: | |
5489 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
5490 | state_machine_regs.address += uladv; | |
5491 | state_machine_regs.op_index = 0; | |
5492 | /* Do NOT reset view. */ | |
5493 | break; | |
5494 | ||
5495 | case DW_LNS_set_prologue_end: | |
5496 | break; | |
5497 | ||
5498 | case DW_LNS_set_epilogue_begin: | |
5499 | break; | |
5500 | ||
5501 | case DW_LNS_set_isa: | |
5502 | READ_ULEB (uladv, data, end); | |
5503 | printf (_(" Set ISA to %lu\n"), uladv); | |
5504 | break; | |
5505 | ||
5506 | default: | |
5507 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
5508 | ||
5509 | if (standard_opcodes != NULL) | |
5510 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
5511 | { | |
5512 | dwarf_vma val; | |
5513 | ||
5514 | READ_ULEB (val, data, end); | |
5515 | printf ("0x%s%s", dwarf_vmatoa ("x", val), | |
5516 | i == 1 ? "" : ", "); | |
5517 | } | |
5518 | putchar ('\n'); | |
5519 | break; | |
5520 | } | |
a262ae96 | 5521 | |
b4eb7656 AM |
5522 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
5523 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
5524 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
5525 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
5526 | { |
5527 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
5528 | char *fileName; | |
5529 | char *newFileName = NULL; | |
5530 | size_t fileNameLength; | |
b40bf0a2 NC |
5531 | |
5532 | if (file_table) | |
db9537d2 NC |
5533 | { |
5534 | unsigned indx = state_machine_regs.file - 1; | |
5535 | /* PR 20439 */ | |
5536 | if (indx >= n_files) | |
5537 | { | |
5538 | warn (_("corrupt file index %u encountered\n"), indx); | |
5539 | fileName = _("<corrupt>"); | |
5540 | } | |
5541 | else | |
5542 | fileName = (char *) file_table[indx].name; | |
5543 | } | |
b40bf0a2 | 5544 | else |
db9537d2 | 5545 | fileName = _("<unknown>"); |
b40bf0a2 NC |
5546 | |
5547 | fileNameLength = strlen (fileName); | |
a262ae96 | 5548 | |
b4eb7656 AM |
5549 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
5550 | { | |
5551 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
5552 | /* Truncate file name */ | |
5553 | strncpy (newFileName, | |
5554 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
5555 | MAX_FILENAME_LENGTH + 1); | |
e1104d08 NC |
5556 | /* FIXME: This is to pacify gcc-10 which can warn that the |
5557 | strncpy above might leave a non-NUL terminated string | |
5558 | in newFileName. It won't, but gcc's analysis doesn't | |
5559 | quite go far enough to discover this. */ | |
5560 | newFileName[MAX_FILENAME_LENGTH] = 0; | |
b4eb7656 AM |
5561 | } |
5562 | else | |
5563 | { | |
5564 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
5565 | strncpy (newFileName, fileName, fileNameLength + 1); | |
5566 | } | |
5567 | ||
af2b3186 TV |
5568 | /* A row with end_seq set to true has a meaningful address, but |
5569 | the other information in the same row is not significant. | |
5570 | In such a row, print line as "-", and don't print | |
5571 | view/is_stmt. */ | |
b4eb7656 AM |
5572 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) |
5573 | { | |
a233b20c | 5574 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5575 | { |
5576 | if (xop == -DW_LNE_end_sequence) | |
5577 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x", | |
5578 | newFileName, "-", | |
5579 | state_machine_regs.address); | |
5580 | else | |
5581 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", | |
5582 | newFileName, state_machine_regs.line, | |
5583 | state_machine_regs.address); | |
5584 | } | |
a233b20c | 5585 | else |
af2b3186 TV |
5586 | { |
5587 | if (xop == -DW_LNE_end_sequence) | |
5588 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5589 | newFileName, "-", | |
5590 | state_machine_regs.address, | |
5591 | state_machine_regs.op_index); | |
5592 | else | |
5593 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5594 | newFileName, state_machine_regs.line, | |
5595 | state_machine_regs.address, | |
5596 | state_machine_regs.op_index); | |
5597 | } | |
b4eb7656 AM |
5598 | } |
5599 | else | |
5600 | { | |
a233b20c | 5601 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5602 | { |
5603 | if (xop == -DW_LNE_end_sequence) | |
5604 | printf ("%s %11s %#18" DWARF_VMA_FMT "x", | |
5605 | newFileName, "-", | |
5606 | state_machine_regs.address); | |
5607 | else | |
5608 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", | |
5609 | newFileName, state_machine_regs.line, | |
5610 | state_machine_regs.address); | |
5611 | } | |
a233b20c | 5612 | else |
af2b3186 TV |
5613 | { |
5614 | if (xop == -DW_LNE_end_sequence) | |
5615 | printf ("%s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5616 | newFileName, "-", | |
5617 | state_machine_regs.address, | |
5618 | state_machine_regs.op_index); | |
5619 | else | |
5620 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5621 | newFileName, state_machine_regs.line, | |
5622 | state_machine_regs.address, | |
5623 | state_machine_regs.op_index); | |
5624 | } | |
b4eb7656 | 5625 | } |
a262ae96 | 5626 | |
af2b3186 TV |
5627 | if (xop != -DW_LNE_end_sequence) |
5628 | { | |
5629 | if (state_machine_regs.view) | |
5630 | printf (" %6u", state_machine_regs.view); | |
5631 | else | |
5632 | printf (" "); | |
17f6ade2 | 5633 | |
af2b3186 TV |
5634 | if (state_machine_regs.is_stmt) |
5635 | printf (" x"); | |
5636 | } | |
17f6ade2 JD |
5637 | |
5638 | putchar ('\n'); | |
ba8826a8 AO |
5639 | state_machine_regs.view++; |
5640 | ||
5641 | if (xop == -DW_LNE_end_sequence) | |
5642 | { | |
5643 | reset_state_machine (linfo.li_default_is_stmt); | |
5644 | putchar ('\n'); | |
5645 | } | |
a262ae96 | 5646 | |
b4eb7656 AM |
5647 | free (newFileName); |
5648 | } | |
5649 | } | |
b40bf0a2 NC |
5650 | |
5651 | if (file_table) | |
5652 | { | |
5653 | free (file_table); | |
5654 | file_table = NULL; | |
5655 | n_files = 0; | |
5656 | } | |
5657 | ||
5658 | if (directory_table) | |
5659 | { | |
5660 | free (directory_table); | |
5661 | directory_table = NULL; | |
5662 | n_directories = 0; | |
5663 | } | |
5664 | ||
a262ae96 NC |
5665 | putchar ('\n'); |
5666 | } | |
5667 | ||
5668 | return 1; | |
5669 | } | |
5670 | ||
5671 | static int | |
77145576 | 5672 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
5673 | { |
5674 | unsigned char *data = section->start; | |
5675 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
5676 | int retValRaw = 1; |
5677 | int retValDecoded = 1; | |
a262ae96 | 5678 | |
008f4c78 NC |
5679 | if (do_debug_lines == 0) |
5680 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
5681 | ||
4cb93e3b | 5682 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 5683 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 5684 | |
4cb93e3b | 5685 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
ec1b0fbb | 5686 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
a262ae96 | 5687 | |
4cb93e3b | 5688 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
5689 | return 0; |
5690 | ||
5691 | return 1; | |
5692 | } | |
5693 | ||
6e3d6dc1 NC |
5694 | static debug_info * |
5695 | find_debug_info_for_offset (unsigned long offset) | |
5696 | { | |
5697 | unsigned int i; | |
5698 | ||
5699 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
5700 | return NULL; | |
5701 | ||
5702 | for (i = 0; i < num_debug_info_entries; i++) | |
5703 | if (debug_information[i].cu_offset == offset) | |
5704 | return debug_information + i; | |
5705 | ||
5706 | return NULL; | |
5707 | } | |
5708 | ||
459d52c8 DE |
5709 | static const char * |
5710 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
5711 | { | |
5712 | /* See gdb/gdb-index.h. */ | |
5713 | static const char * const kinds[] = | |
5714 | { | |
5715 | N_ ("no info"), | |
5716 | N_ ("type"), | |
5717 | N_ ("variable"), | |
5718 | N_ ("function"), | |
5719 | N_ ("other"), | |
5720 | N_ ("unused5"), | |
5721 | N_ ("unused6"), | |
5722 | N_ ("unused7") | |
5723 | }; | |
5724 | ||
5725 | return _ (kinds[kind]); | |
5726 | } | |
5727 | ||
19e6b90e | 5728 | static int |
459d52c8 DE |
5729 | display_debug_pubnames_worker (struct dwarf_section *section, |
5730 | void *file ATTRIBUTE_UNUSED, | |
5731 | int is_gnu) | |
19e6b90e | 5732 | { |
91d6fa6a | 5733 | DWARF2_Internal_PubNames names; |
19e6b90e L |
5734 | unsigned char *start = section->start; |
5735 | unsigned char *end = start + section->size; | |
5736 | ||
6e3d6dc1 NC |
5737 | /* It does not matter if this load fails, |
5738 | we test for that later on. */ | |
5739 | load_debug_info (file); | |
5740 | ||
dda8d76d | 5741 | introduce (section, FALSE); |
19e6b90e L |
5742 | |
5743 | while (start < end) | |
5744 | { | |
5745 | unsigned char *data; | |
e98fdf1a | 5746 | unsigned long sec_off; |
bf5117e3 | 5747 | unsigned int offset_size, initial_length_size; |
19e6b90e | 5748 | |
e98fdf1a | 5749 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 5750 | if (names.pn_length == 0xffffffff) |
19e6b90e | 5751 | { |
e98fdf1a | 5752 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e L |
5753 | offset_size = 8; |
5754 | initial_length_size = 12; | |
5755 | } | |
5756 | else | |
5757 | { | |
5758 | offset_size = 4; | |
5759 | initial_length_size = 4; | |
5760 | } | |
5761 | ||
e98fdf1a AM |
5762 | sec_off = start - section->start; |
5763 | if (sec_off + names.pn_length < sec_off | |
5764 | || sec_off + names.pn_length > section->size) | |
5765 | { | |
5766 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
5767 | section->name, | |
5768 | sec_off - initial_length_size, | |
5769 | dwarf_vmatoa ("x", names.pn_length)); | |
5770 | break; | |
5771 | } | |
5772 | ||
5773 | data = start; | |
5774 | start += names.pn_length; | |
5775 | ||
0c588247 NC |
5776 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
5777 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
5778 | |
5779 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
5780 | && num_debug_info_entries > 0 | |
91d6fa6a | 5781 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 5782 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 5783 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 5784 | |
0c588247 | 5785 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 5786 | |
058037d3 NC |
5787 | printf (_(" Length: %ld\n"), |
5788 | (long) names.pn_length); | |
5789 | printf (_(" Version: %d\n"), | |
5790 | names.pn_version); | |
5791 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
5792 | (unsigned long) names.pn_offset); | |
5793 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
5794 | (long) names.pn_size); | |
19e6b90e | 5795 | |
91d6fa6a | 5796 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
5797 | { |
5798 | static int warned = 0; | |
5799 | ||
5800 | if (! warned) | |
5801 | { | |
5802 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
5803 | warned = 1; | |
5804 | } | |
5805 | ||
5806 | continue; | |
5807 | } | |
5808 | ||
459d52c8 DE |
5809 | if (is_gnu) |
5810 | printf (_("\n Offset Kind Name\n")); | |
5811 | else | |
5812 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 5813 | |
e98fdf1a | 5814 | while (1) |
19e6b90e | 5815 | { |
f41e4712 | 5816 | bfd_size_type maxprint; |
e98fdf1a | 5817 | dwarf_vma offset; |
f41e4712 | 5818 | |
0c588247 | 5819 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e | 5820 | |
e98fdf1a AM |
5821 | if (offset == 0) |
5822 | break; | |
b4eb7656 | 5823 | |
e98fdf1a AM |
5824 | data += offset_size; |
5825 | if (data >= end) | |
5826 | break; | |
5827 | maxprint = (end - data) - 1; | |
f41e4712 | 5828 | |
e98fdf1a AM |
5829 | if (is_gnu) |
5830 | { | |
5831 | unsigned int kind_data; | |
5832 | gdb_index_symbol_kind kind; | |
5833 | const char *kind_name; | |
5834 | int is_static; | |
5835 | ||
5836 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
5837 | data++; | |
5838 | maxprint --; | |
5839 | /* GCC computes the kind as the upper byte in the CU index | |
5840 | word, and then right shifts it by the CU index size. | |
5841 | Left shift KIND to where the gdb-index.h accessor macros | |
5842 | can use it. */ | |
5843 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
5844 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
5845 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
5846 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
5847 | printf (" %-6lx %s,%-10s %.*s\n", | |
5848 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
5849 | kind_name, (int) maxprint, data); | |
19e6b90e | 5850 | } |
e98fdf1a AM |
5851 | else |
5852 | printf (" %-6lx\t%.*s\n", | |
5853 | (unsigned long) offset, (int) maxprint, data); | |
5854 | ||
5855 | data += strnlen ((char *) data, maxprint) + 1; | |
5856 | if (data >= end) | |
5857 | break; | |
19e6b90e | 5858 | } |
19e6b90e L |
5859 | } |
5860 | ||
5861 | printf ("\n"); | |
5862 | return 1; | |
5863 | } | |
5864 | ||
459d52c8 DE |
5865 | static int |
5866 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
5867 | { | |
5868 | return display_debug_pubnames_worker (section, file, 0); | |
5869 | } | |
5870 | ||
5871 | static int | |
5872 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
5873 | { | |
5874 | return display_debug_pubnames_worker (section, file, 1); | |
5875 | } | |
5876 | ||
19e6b90e L |
5877 | static int |
5878 | display_debug_macinfo (struct dwarf_section *section, | |
5879 | void *file ATTRIBUTE_UNUSED) | |
5880 | { | |
5881 | unsigned char *start = section->start; | |
5882 | unsigned char *end = start + section->size; | |
5883 | unsigned char *curr = start; | |
19e6b90e L |
5884 | enum dwarf_macinfo_record_type op; |
5885 | ||
dda8d76d | 5886 | introduce (section, FALSE); |
19e6b90e L |
5887 | |
5888 | while (curr < end) | |
5889 | { | |
5890 | unsigned int lineno; | |
0c588247 | 5891 | const unsigned char *string; |
19e6b90e | 5892 | |
3f5e193b | 5893 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
5894 | curr++; |
5895 | ||
5896 | switch (op) | |
5897 | { | |
5898 | case DW_MACINFO_start_file: | |
5899 | { | |
5900 | unsigned int filenum; | |
5901 | ||
cd30bcef AM |
5902 | READ_ULEB (lineno, curr, end); |
5903 | READ_ULEB (filenum, curr, end); | |
19e6b90e L |
5904 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), |
5905 | lineno, filenum); | |
5906 | } | |
5907 | break; | |
5908 | ||
5909 | case DW_MACINFO_end_file: | |
5910 | printf (_(" DW_MACINFO_end_file\n")); | |
5911 | break; | |
5912 | ||
5913 | case DW_MACINFO_define: | |
cd30bcef | 5914 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5915 | string = curr; |
5916 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5917 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
5918 | lineno, string); | |
5919 | break; | |
5920 | ||
5921 | case DW_MACINFO_undef: | |
cd30bcef | 5922 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5923 | string = curr; |
5924 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5925 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
5926 | lineno, string); | |
5927 | break; | |
5928 | ||
5929 | case DW_MACINFO_vendor_ext: | |
5930 | { | |
5931 | unsigned int constant; | |
5932 | ||
cd30bcef | 5933 | READ_ULEB (constant, curr, end); |
0c588247 NC |
5934 | string = curr; |
5935 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5936 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
5937 | constant, string); | |
5938 | } | |
5939 | break; | |
5940 | } | |
5941 | } | |
5942 | ||
5943 | return 1; | |
5944 | } | |
5945 | ||
4ccf1e31 JJ |
5946 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5947 | filename and dirname corresponding to file name table entry with index | |
5948 | FILEIDX. Return NULL on failure. */ | |
5949 | ||
5950 | static unsigned char * | |
f6f0e17b NC |
5951 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5952 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5953 | unsigned char **dir_name) |
5954 | { | |
5955 | struct dwarf_section *section = &debug_displays [line].section; | |
5956 | unsigned char *hdrptr, *dirtable, *file_name; | |
5957 | unsigned int offset_size, initial_length_size; | |
cd30bcef | 5958 | unsigned int version, opcode_base; |
4ccf1e31 | 5959 | dwarf_vma length, diridx; |
f6f0e17b | 5960 | const unsigned char * end; |
4ccf1e31 JJ |
5961 | |
5962 | *dir_name = NULL; | |
5963 | if (section->start == NULL | |
5964 | || line_offset >= section->size | |
5965 | || fileidx == 0) | |
5966 | return NULL; | |
5967 | ||
5968 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5969 | end = section->start + section->size; |
0c588247 NC |
5970 | |
5971 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5972 | if (length == 0xffffffff) |
5973 | { | |
5974 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5975 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
5976 | offset_size = 8; |
5977 | initial_length_size = 12; | |
5978 | } | |
5979 | else | |
5980 | { | |
5981 | offset_size = 4; | |
5982 | initial_length_size = 4; | |
5983 | } | |
e98fdf1a AM |
5984 | if (length + initial_length_size < length |
5985 | || length + initial_length_size > section->size) | |
4ccf1e31 | 5986 | return NULL; |
0c588247 NC |
5987 | |
5988 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5989 | if (version != 2 && version != 3 && version != 4) |
5990 | return NULL; | |
5991 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5992 | if (version >= 4) | |
5993 | hdrptr++; /* Skip max_ops_per_insn. */ | |
5994 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
5995 | |
5996 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
5997 | if (opcode_base == 0) |
5998 | return NULL; | |
0c588247 | 5999 | |
4ccf1e31 | 6000 | hdrptr += opcode_base - 1; |
5c1c468d NC |
6001 | if (hdrptr >= end) |
6002 | return NULL; | |
6003 | ||
4ccf1e31 JJ |
6004 | dirtable = hdrptr; |
6005 | /* Skip over dirname table. */ | |
6006 | while (*hdrptr != '\0') | |
5c1c468d NC |
6007 | { |
6008 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; | |
6009 | if (hdrptr >= end) | |
6010 | return NULL; | |
6011 | } | |
4ccf1e31 | 6012 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 6013 | |
4ccf1e31 | 6014 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 6015 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 6016 | { |
0c588247 | 6017 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
cd30bcef AM |
6018 | SKIP_ULEB (hdrptr, end); |
6019 | SKIP_ULEB (hdrptr, end); | |
6020 | SKIP_ULEB (hdrptr, end); | |
4ccf1e31 | 6021 | } |
5c1c468d | 6022 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 6023 | return NULL; |
5c1c468d | 6024 | |
4ccf1e31 | 6025 | file_name = hdrptr; |
0c588247 | 6026 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
5c1c468d NC |
6027 | if (hdrptr >= end) |
6028 | return NULL; | |
cd30bcef | 6029 | READ_ULEB (diridx, hdrptr, end); |
4ccf1e31 JJ |
6030 | if (diridx == 0) |
6031 | return file_name; | |
5c1c468d | 6032 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
0c588247 | 6033 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
5c1c468d | 6034 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
6035 | return NULL; |
6036 | *dir_name = dirtable; | |
6037 | return file_name; | |
6038 | } | |
6039 | ||
6040 | static int | |
6041 | display_debug_macro (struct dwarf_section *section, | |
6042 | void *file) | |
6043 | { | |
6044 | unsigned char *start = section->start; | |
6045 | unsigned char *end = start + section->size; | |
6046 | unsigned char *curr = start; | |
6047 | unsigned char *extended_op_buf[256]; | |
d296b736 NC |
6048 | bfd_boolean is_dwo = FALSE; |
6049 | const char *suffix = strrchr (section->name, '.'); | |
6050 | ||
6051 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
6052 | is_dwo = TRUE; | |
4ccf1e31 | 6053 | |
dda8d76d NC |
6054 | load_debug_section_with_follow (str, file); |
6055 | load_debug_section_with_follow (line, file); | |
e4b7104b | 6056 | load_debug_section_with_follow (str_index, file); |
d296b736 | 6057 | |
dda8d76d | 6058 | introduce (section, FALSE); |
4ccf1e31 JJ |
6059 | |
6060 | while (curr < end) | |
6061 | { | |
6062 | unsigned int lineno, version, flags; | |
d296b736 | 6063 | unsigned int offset_size; |
0c588247 | 6064 | const unsigned char *string; |
4ccf1e31 JJ |
6065 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
6066 | unsigned char **extended_ops = NULL; | |
6067 | ||
0c588247 | 6068 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 6069 | if (version != 4 && version != 5) |
4ccf1e31 | 6070 | { |
0e12f6c8 TV |
6071 | error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"), |
6072 | section->name, version); | |
4ccf1e31 JJ |
6073 | return 0; |
6074 | } | |
6075 | ||
0c588247 | 6076 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
d296b736 | 6077 | offset_size = (flags & 1) ? 8 : 4; |
4ccf1e31 JJ |
6078 | printf (_(" Offset: 0x%lx\n"), |
6079 | (unsigned long) sec_offset); | |
6080 | printf (_(" Version: %d\n"), version); | |
6081 | printf (_(" Offset size: %d\n"), offset_size); | |
6082 | if (flags & 2) | |
6083 | { | |
0c588247 | 6084 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
6085 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
6086 | (unsigned long) line_offset); | |
6087 | } | |
6088 | if (flags & 4) | |
6089 | { | |
0c588247 | 6090 | unsigned int i, count, op; |
4ccf1e31 | 6091 | dwarf_vma nargs, n; |
0c588247 NC |
6092 | |
6093 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 6094 | |
4ccf1e31 JJ |
6095 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
6096 | extended_ops = extended_op_buf; | |
6097 | if (count) | |
6098 | { | |
6099 | printf (_(" Extension opcode arguments:\n")); | |
6100 | for (i = 0; i < count; i++) | |
6101 | { | |
0c588247 | 6102 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 6103 | extended_ops[op] = curr; |
cd30bcef | 6104 | READ_ULEB (nargs, curr, end); |
4ccf1e31 | 6105 | if (nargs == 0) |
7a7e1061 | 6106 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
6107 | else |
6108 | { | |
7a7e1061 | 6109 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
6110 | for (n = 0; n < nargs; n++) |
6111 | { | |
0c588247 NC |
6112 | unsigned int form; |
6113 | ||
6114 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
6115 | printf ("%s%s", get_FORM_name (form), |
6116 | n == nargs - 1 ? "\n" : ", "); | |
6117 | switch (form) | |
6118 | { | |
6119 | case DW_FORM_data1: | |
6120 | case DW_FORM_data2: | |
6121 | case DW_FORM_data4: | |
6122 | case DW_FORM_data8: | |
6123 | case DW_FORM_sdata: | |
6124 | case DW_FORM_udata: | |
6125 | case DW_FORM_block: | |
6126 | case DW_FORM_block1: | |
6127 | case DW_FORM_block2: | |
6128 | case DW_FORM_block4: | |
6129 | case DW_FORM_flag: | |
6130 | case DW_FORM_string: | |
6131 | case DW_FORM_strp: | |
6132 | case DW_FORM_sec_offset: | |
6133 | break; | |
6134 | default: | |
6135 | error (_("Invalid extension opcode form %s\n"), | |
6136 | get_FORM_name (form)); | |
6137 | return 0; | |
6138 | } | |
6139 | } | |
6140 | } | |
6141 | } | |
6142 | } | |
6143 | } | |
6144 | printf ("\n"); | |
6145 | ||
6146 | while (1) | |
6147 | { | |
6148 | unsigned int op; | |
6149 | ||
6150 | if (curr >= end) | |
6151 | { | |
6152 | error (_(".debug_macro section not zero terminated\n")); | |
6153 | return 0; | |
6154 | } | |
6155 | ||
0c588247 | 6156 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
6157 | if (op == 0) |
6158 | break; | |
6159 | ||
6160 | switch (op) | |
6161 | { | |
e4b7104b NC |
6162 | case DW_MACRO_define: |
6163 | READ_ULEB (lineno, curr, end); | |
6164 | string = curr; | |
6165 | curr += strnlen ((char *) string, end - string) + 1; | |
6166 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), | |
6167 | lineno, string); | |
6168 | break; | |
6169 | ||
6170 | case DW_MACRO_undef: | |
6171 | READ_ULEB (lineno, curr, end); | |
6172 | string = curr; | |
6173 | curr += strnlen ((char *) string, end - string) + 1; | |
6174 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), | |
6175 | lineno, string); | |
6176 | break; | |
6177 | ||
7a7e1061 | 6178 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
6179 | { |
6180 | unsigned int filenum; | |
6181 | unsigned char *file_name = NULL, *dir_name = NULL; | |
6182 | ||
cd30bcef AM |
6183 | READ_ULEB (lineno, curr, end); |
6184 | READ_ULEB (filenum, curr, end); | |
4ccf1e31 JJ |
6185 | |
6186 | if ((flags & 2) == 0) | |
7a7e1061 | 6187 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
6188 | else |
6189 | file_name | |
6190 | = get_line_filename_and_dirname (line_offset, filenum, | |
6191 | &dir_name); | |
6192 | if (file_name == NULL) | |
7a7e1061 | 6193 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
6194 | lineno, filenum); |
6195 | else | |
7a7e1061 | 6196 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
6197 | lineno, filenum, |
6198 | dir_name != NULL ? (const char *) dir_name : "", | |
6199 | dir_name != NULL ? "/" : "", file_name); | |
6200 | } | |
6201 | break; | |
6202 | ||
7a7e1061 JK |
6203 | case DW_MACRO_end_file: |
6204 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
6205 | break; |
6206 | ||
7a7e1061 | 6207 | case DW_MACRO_define_strp: |
cd30bcef | 6208 | READ_ULEB (lineno, curr, end); |
d296b736 NC |
6209 | if (version == 4 && is_dwo) |
6210 | READ_ULEB (offset, curr, end); | |
6211 | else | |
6212 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
4ccf1e31 | 6213 | string = fetch_indirect_string (offset); |
7a7e1061 | 6214 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
6215 | lineno, string); |
6216 | break; | |
6217 | ||
7a7e1061 | 6218 | case DW_MACRO_undef_strp: |
cd30bcef | 6219 | READ_ULEB (lineno, curr, end); |
d296b736 NC |
6220 | if (version == 4 && is_dwo) |
6221 | READ_ULEB (offset, curr, end); | |
6222 | else | |
6223 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); | |
4ccf1e31 | 6224 | string = fetch_indirect_string (offset); |
7a7e1061 | 6225 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
6226 | lineno, string); |
6227 | break; | |
6228 | ||
7a7e1061 | 6229 | case DW_MACRO_import: |
0c588247 | 6230 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6231 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
6232 | (unsigned long) offset); |
6233 | break; | |
6234 | ||
7a7e1061 | 6235 | case DW_MACRO_define_sup: |
cd30bcef | 6236 | READ_ULEB (lineno, curr, end); |
0c588247 | 6237 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6238 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
6239 | lineno, (unsigned long) offset); |
6240 | break; | |
6241 | ||
7a7e1061 | 6242 | case DW_MACRO_undef_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_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
6246 | lineno, (unsigned long) offset); |
6247 | break; | |
6248 | ||
7a7e1061 | 6249 | case DW_MACRO_import_sup: |
0c588247 | 6250 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6251 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
6252 | (unsigned long) offset); |
6253 | break; | |
6254 | ||
e4b7104b NC |
6255 | case DW_MACRO_define_strx: |
6256 | case DW_MACRO_undef_strx: | |
6257 | READ_ULEB (lineno, curr, end); | |
6258 | READ_ULEB (offset, curr, end); | |
6259 | string = (const unsigned char *) | |
6260 | fetch_indexed_string (offset, NULL, offset_size, FALSE); | |
6261 | if (op == DW_MACRO_define_strx) | |
6262 | printf (" DW_MACRO_define_strx "); | |
6263 | else | |
6264 | printf (" DW_MACRO_undef_strx "); | |
6265 | if (do_wide) | |
39f381cb | 6266 | printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset)); |
e4b7104b NC |
6267 | printf (_("lineno : %d macro : %s\n"), |
6268 | lineno, string); | |
6269 | break; | |
6270 | ||
4ccf1e31 | 6271 | default: |
e4b7104b NC |
6272 | if (op >= DW_MACRO_lo_user && op <= DW_MACRO_hi_user) |
6273 | { | |
6274 | printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op); | |
6275 | break; | |
6276 | } | |
6277 | ||
4ccf1e31 JJ |
6278 | if (extended_ops == NULL || extended_ops[op] == NULL) |
6279 | { | |
6280 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
6281 | return 0; | |
6282 | } | |
6283 | else | |
6284 | { | |
6285 | /* Skip over unhandled opcodes. */ | |
6286 | dwarf_vma nargs, n; | |
6287 | unsigned char *desc = extended_ops[op]; | |
cd30bcef | 6288 | READ_ULEB (nargs, desc, end); |
4ccf1e31 JJ |
6289 | if (nargs == 0) |
6290 | { | |
7a7e1061 | 6291 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
6292 | break; |
6293 | } | |
7a7e1061 | 6294 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
6295 | for (n = 0; n < nargs; n++) |
6296 | { | |
0c588247 NC |
6297 | int val; |
6298 | ||
77145576 | 6299 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 6300 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 6301 | curr |
77145576 | 6302 | = read_and_display_attr_value (0, val, 0, |
ec1b0fbb | 6303 | start, curr, end, 0, 0, offset_size, |
341f9135 | 6304 | version, NULL, 0, NULL, |
ec1b0fbb | 6305 | NULL, ' ', -1); |
4ccf1e31 JJ |
6306 | if (n != nargs - 1) |
6307 | printf (","); | |
6308 | } | |
6309 | printf ("\n"); | |
6310 | } | |
6311 | break; | |
6312 | } | |
6313 | } | |
6314 | ||
6315 | printf ("\n"); | |
b4eb7656 | 6316 | } |
4ccf1e31 JJ |
6317 | |
6318 | return 1; | |
6319 | } | |
6320 | ||
19e6b90e L |
6321 | static int |
6322 | display_debug_abbrev (struct dwarf_section *section, | |
6323 | void *file ATTRIBUTE_UNUSED) | |
6324 | { | |
6325 | abbrev_entry *entry; | |
6326 | unsigned char *start = section->start; | |
bcd213b2 | 6327 | const unsigned char *end = start + section->size; |
19e6b90e | 6328 | |
dda8d76d | 6329 | introduce (section, FALSE); |
19e6b90e L |
6330 | |
6331 | do | |
6332 | { | |
bcd213b2 NC |
6333 | abbrev_list * list; |
6334 | dwarf_vma offset; | |
7282333f | 6335 | |
bcd213b2 | 6336 | offset = start - section->start; |
76868f36 | 6337 | list = find_abbrev_list_by_abbrev_offset (0, offset); |
bcd213b2 NC |
6338 | if (list == NULL) |
6339 | { | |
76868f36 | 6340 | list = new_abbrev_list (0, offset); |
bcd213b2 NC |
6341 | start = process_abbrev_set (start, end, list); |
6342 | list->start_of_next_abbrevs = start; | |
6343 | } | |
6344 | else | |
6345 | start = list->start_of_next_abbrevs; | |
19e6b90e | 6346 | |
bcd213b2 | 6347 | if (list->first_abbrev == NULL) |
19e6b90e L |
6348 | continue; |
6349 | ||
bcd213b2 | 6350 | printf (_(" Number TAG (0x%lx)\n"), (long) offset); |
19e6b90e | 6351 | |
bcd213b2 | 6352 | for (entry = list->first_abbrev; entry; entry = entry->next) |
19e6b90e L |
6353 | { |
6354 | abbrev_attr *attr; | |
6355 | ||
cc5914eb | 6356 | printf (" %ld %s [%s]\n", |
bcd213b2 | 6357 | entry->number, |
19e6b90e L |
6358 | get_TAG_name (entry->tag), |
6359 | entry->children ? _("has children") : _("no children")); | |
6360 | ||
6361 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
6362 | { |
6363 | printf (" %-18s %s", | |
6364 | get_AT_name (attr->attribute), | |
6365 | get_FORM_name (attr->form)); | |
6366 | if (attr->form == DW_FORM_implicit_const) | |
6367 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
6368 | putchar ('\n'); | |
6369 | } | |
19e6b90e L |
6370 | } |
6371 | } | |
6372 | while (start); | |
6373 | ||
6374 | printf ("\n"); | |
6375 | ||
6376 | return 1; | |
6377 | } | |
6378 | ||
42bcef4a AB |
6379 | /* Return true when ADDR is the maximum address, when addresses are |
6380 | POINTER_SIZE bytes long. */ | |
6381 | ||
6382 | static bfd_boolean | |
6383 | is_max_address (dwarf_vma addr, unsigned int pointer_size) | |
6384 | { | |
6385 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
6386 | return ((addr & mask) == mask); | |
6387 | } | |
6388 | ||
9f272209 AO |
6389 | /* Display a view pair list starting at *VSTART_PTR and ending at |
6390 | VLISTEND within SECTION. */ | |
6391 | ||
6392 | static void | |
6393 | display_view_pair_list (struct dwarf_section *section, | |
6394 | unsigned char **vstart_ptr, | |
6395 | unsigned int debug_info_entry, | |
6396 | unsigned char *vlistend) | |
6397 | { | |
6398 | unsigned char *vstart = *vstart_ptr; | |
6399 | unsigned char *section_end = section->start + section->size; | |
6400 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
6401 | ||
6402 | if (vlistend < section_end) | |
6403 | section_end = vlistend; | |
6404 | ||
6405 | putchar ('\n'); | |
6406 | ||
6407 | while (vstart < section_end) | |
6408 | { | |
6409 | dwarf_vma off = vstart - section->start; | |
6410 | dwarf_vma vbegin, vend; | |
6411 | ||
cd30bcef | 6412 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 | 6413 | if (vstart == section_end) |
cd30bcef | 6414 | break; |
9f272209 | 6415 | |
cd30bcef | 6416 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6417 | printf (" %8.8lx ", (unsigned long) off); |
6418 | ||
6419 | print_dwarf_view (vbegin, pointer_size, 1); | |
6420 | print_dwarf_view (vend, pointer_size, 1); | |
6421 | printf (_("location view pair\n")); | |
6422 | } | |
6423 | ||
6424 | putchar ('\n'); | |
6425 | *vstart_ptr = vstart; | |
6426 | } | |
6427 | ||
4723351a CC |
6428 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
6429 | ||
6430 | static void | |
6431 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
6432 | unsigned char **start_ptr, |
6433 | unsigned int debug_info_entry, | |
359ca075 JK |
6434 | dwarf_vma offset, |
6435 | dwarf_vma base_address, | |
9f272209 | 6436 | unsigned char **vstart_ptr, |
b4eb7656 | 6437 | int has_frame_base) |
4723351a | 6438 | { |
9f272209 | 6439 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6440 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6441 | unsigned long cu_offset; |
6442 | unsigned int pointer_size; | |
6443 | unsigned int offset_size; | |
6444 | int dwarf_version; | |
4723351a CC |
6445 | |
6446 | dwarf_vma begin; | |
6447 | dwarf_vma end; | |
6448 | unsigned short length; | |
6449 | int need_frame_base; | |
6450 | ||
82b1b41b NC |
6451 | if (debug_info_entry >= num_debug_info_entries) |
6452 | { | |
6453 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
6454 | debug_info_entry); | |
6455 | return; | |
6456 | } | |
b4eb7656 | 6457 | |
82b1b41b NC |
6458 | cu_offset = debug_information [debug_info_entry].cu_offset; |
6459 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6460 | offset_size = debug_information [debug_info_entry].offset_size; | |
6461 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 6462 | |
f41e4712 NC |
6463 | if (pointer_size < 2 || pointer_size > 8) |
6464 | { | |
6465 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6466 | pointer_size, debug_info_entry); | |
6467 | return; | |
6468 | } | |
6469 | ||
4723351a CC |
6470 | while (1) |
6471 | { | |
359ca075 | 6472 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 6473 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 6474 | |
4723351a | 6475 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
6476 | { |
6477 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6478 | (unsigned long) offset); |
b4eb7656 AM |
6479 | break; |
6480 | } | |
4723351a | 6481 | |
359ca075 | 6482 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 6483 | |
0c588247 NC |
6484 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
6485 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 6486 | |
4723351a | 6487 | if (begin == 0 && end == 0) |
b4eb7656 | 6488 | { |
d1c4b12b NC |
6489 | /* PR 18374: In a object file we can have a location list that |
6490 | starts with a begin and end of 0 because there are relocations | |
6491 | that need to be applied to the addresses. Actually applying | |
6492 | the relocations now does not help as they will probably resolve | |
6493 | to 0, since the object file has not been fully linked. Real | |
6494 | end of list markers will not have any relocations against them. */ | |
6495 | if (! reloc_at (section, off) | |
6496 | && ! reloc_at (section, off + pointer_size)) | |
6497 | { | |
6498 | printf (_("<End of list>\n")); | |
6499 | break; | |
6500 | } | |
b4eb7656 | 6501 | } |
4723351a CC |
6502 | |
6503 | /* Check base address specifiers. */ | |
42bcef4a AB |
6504 | if (is_max_address (begin, pointer_size) |
6505 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
6506 | { |
6507 | base_address = end; | |
6508 | print_dwarf_vma (begin, pointer_size); | |
6509 | print_dwarf_vma (end, pointer_size); | |
6510 | printf (_("(base address)\n")); | |
6511 | continue; | |
6512 | } | |
4723351a | 6513 | |
9f272209 AO |
6514 | if (vstart) |
6515 | { | |
9f272209 AO |
6516 | off = offset + (vstart - *start_ptr); |
6517 | ||
cd30bcef | 6518 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
6519 | print_dwarf_view (vbegin, pointer_size, 1); |
6520 | ||
cd30bcef | 6521 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6522 | print_dwarf_view (vend, pointer_size, 1); |
6523 | ||
6524 | printf (_("views at %8.8lx for:\n %*s "), | |
6525 | (unsigned long) off, 8, ""); | |
6526 | } | |
6527 | ||
4723351a | 6528 | if (start + 2 > section_end) |
b4eb7656 AM |
6529 | { |
6530 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6531 | (unsigned long) offset); |
b4eb7656 AM |
6532 | break; |
6533 | } | |
4723351a | 6534 | |
0c588247 | 6535 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
6536 | |
6537 | if (start + length > section_end) | |
b4eb7656 AM |
6538 | { |
6539 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6540 | (unsigned long) offset); |
b4eb7656 AM |
6541 | break; |
6542 | } | |
4723351a CC |
6543 | |
6544 | print_dwarf_vma (begin + base_address, pointer_size); | |
6545 | print_dwarf_vma (end + base_address, pointer_size); | |
6546 | ||
6547 | putchar ('('); | |
6548 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6549 | pointer_size, |
6550 | offset_size, | |
6551 | dwarf_version, | |
6552 | length, | |
6553 | cu_offset, section); | |
4723351a CC |
6554 | putchar (')'); |
6555 | ||
6556 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6557 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 6558 | |
9f272209 | 6559 | if (begin == end && vbegin == vend) |
b4eb7656 | 6560 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6561 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 6562 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
6563 | |
6564 | putchar ('\n'); | |
6565 | ||
6566 | start += length; | |
6567 | } | |
6568 | ||
6569 | *start_ptr = start; | |
9f272209 | 6570 | *vstart_ptr = vstart; |
4723351a CC |
6571 | } |
6572 | ||
77145576 JK |
6573 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
6574 | ||
6575 | static void | |
6576 | display_loclists_list (struct dwarf_section *section, | |
6577 | unsigned char **start_ptr, | |
6578 | unsigned int debug_info_entry, | |
6579 | dwarf_vma offset, | |
6580 | dwarf_vma base_address, | |
9f272209 | 6581 | unsigned char **vstart_ptr, |
77145576 JK |
6582 | int has_frame_base) |
6583 | { | |
9f272209 | 6584 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
6585 | unsigned char *section_end = section->start + section->size; |
6586 | unsigned long cu_offset; | |
6587 | unsigned int pointer_size; | |
6588 | unsigned int offset_size; | |
6589 | int dwarf_version; | |
77145576 | 6590 | |
9dfd0db9 | 6591 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
6592 | dwarf_vma begin = -1, vbegin = -1; |
6593 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
6594 | dwarf_vma length; |
6595 | int need_frame_base; | |
6596 | ||
6597 | if (debug_info_entry >= num_debug_info_entries) | |
6598 | { | |
6599 | warn (_("No debug information available for " | |
6600 | "loclists lists of entry: %u\n"), | |
6601 | debug_info_entry); | |
6602 | return; | |
6603 | } | |
6604 | ||
6605 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6606 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6607 | offset_size = debug_information [debug_info_entry].offset_size; | |
6608 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6609 | ||
6610 | if (pointer_size < 2 || pointer_size > 8) | |
6611 | { | |
6612 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6613 | pointer_size, debug_info_entry); | |
6614 | return; | |
6615 | } | |
6616 | ||
6617 | while (1) | |
6618 | { | |
6619 | dwarf_vma off = offset + (start - *start_ptr); | |
6620 | enum dwarf_location_list_entry_type llet; | |
6621 | ||
6622 | if (start + 1 > section_end) | |
6623 | { | |
6624 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6625 | (unsigned long) offset); | |
6626 | break; | |
6627 | } | |
6628 | ||
6629 | printf (" %8.8lx ", (unsigned long) off); | |
6630 | ||
6631 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
6632 | ||
1c9f770d MW |
6633 | if (vstart && (llet == DW_LLE_offset_pair |
6634 | || llet == DW_LLE_start_end | |
6635 | || llet == DW_LLE_start_length)) | |
9f272209 AO |
6636 | { |
6637 | off = offset + (vstart - *start_ptr); | |
6638 | ||
cd30bcef | 6639 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
6640 | print_dwarf_view (vbegin, pointer_size, 1); |
6641 | ||
cd30bcef | 6642 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6643 | print_dwarf_view (vend, pointer_size, 1); |
6644 | ||
6645 | printf (_("views at %8.8lx for:\n %*s "), | |
6646 | (unsigned long) off, 8, ""); | |
6647 | } | |
6648 | ||
77145576 JK |
6649 | switch (llet) |
6650 | { | |
6651 | case DW_LLE_end_of_list: | |
6652 | printf (_("<End of list>\n")); | |
6653 | break; | |
6654 | case DW_LLE_offset_pair: | |
cd30bcef | 6655 | READ_ULEB (begin, start, section_end); |
1c9f770d | 6656 | begin += base_address; |
cd30bcef | 6657 | READ_ULEB (end, start, section_end); |
1c9f770d MW |
6658 | end += base_address; |
6659 | break; | |
6660 | case DW_LLE_start_end: | |
6661 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6662 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
6663 | break; | |
6664 | case DW_LLE_start_length: | |
6665 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6666 | READ_ULEB (end, start, section_end); | |
6667 | end += begin; | |
77145576 JK |
6668 | break; |
6669 | case DW_LLE_base_address: | |
6670 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
6671 | section_end); | |
6672 | print_dwarf_vma (base_address, pointer_size); | |
6673 | printf (_("(base address)\n")); | |
6674 | break; | |
9f272209 AO |
6675 | #ifdef DW_LLE_view_pair |
6676 | case DW_LLE_view_pair: | |
6677 | if (vstart) | |
6678 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
cd30bcef | 6679 | READ_ULEB (vbegin, start, section_end); |
9f272209 AO |
6680 | print_dwarf_view (vbegin, pointer_size, 1); |
6681 | ||
cd30bcef | 6682 | READ_ULEB (vend, start, section_end); |
9f272209 AO |
6683 | print_dwarf_view (vend, pointer_size, 1); |
6684 | ||
6685 | printf (_("views for:\n")); | |
6686 | continue; | |
6687 | #endif | |
77145576 JK |
6688 | default: |
6689 | error (_("Invalid location list entry type %d\n"), llet); | |
6690 | return; | |
6691 | } | |
6692 | if (llet == DW_LLE_end_of_list) | |
6693 | break; | |
1c9f770d MW |
6694 | if (llet != DW_LLE_offset_pair |
6695 | && llet != DW_LLE_start_end | |
6696 | && llet != DW_LLE_start_length) | |
77145576 JK |
6697 | continue; |
6698 | ||
6699 | if (start + 2 > section_end) | |
6700 | { | |
6701 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6702 | (unsigned long) offset); | |
6703 | break; | |
6704 | } | |
6705 | ||
cd30bcef | 6706 | READ_ULEB (length, start, section_end); |
77145576 | 6707 | |
1c9f770d MW |
6708 | print_dwarf_vma (begin, pointer_size); |
6709 | print_dwarf_vma (end, pointer_size); | |
77145576 JK |
6710 | |
6711 | putchar ('('); | |
6712 | need_frame_base = decode_location_expression (start, | |
6713 | pointer_size, | |
6714 | offset_size, | |
6715 | dwarf_version, | |
6716 | length, | |
6717 | cu_offset, section); | |
6718 | putchar (')'); | |
6719 | ||
6720 | if (need_frame_base && !has_frame_base) | |
6721 | printf (_(" [without DW_AT_frame_base]")); | |
6722 | ||
9f272209 | 6723 | if (begin == end && vbegin == vend) |
77145576 | 6724 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6725 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
6726 | fputs (_(" (start > end)"), stdout); |
6727 | ||
6728 | putchar ('\n'); | |
6729 | ||
6730 | start += length; | |
9f272209 | 6731 | vbegin = vend = -1; |
77145576 JK |
6732 | } |
6733 | ||
9f272209 AO |
6734 | if (vbegin != vm1 || vend != vm1) |
6735 | printf (_("Trailing view pair not used in a range")); | |
6736 | ||
77145576 | 6737 | *start_ptr = start; |
9f272209 | 6738 | *vstart_ptr = vstart; |
77145576 JK |
6739 | } |
6740 | ||
fab128ef CC |
6741 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
6742 | right-adjusted in a field of length LEN, and followed by a space. */ | |
6743 | ||
6744 | static void | |
6745 | print_addr_index (unsigned int idx, unsigned int len) | |
6746 | { | |
6747 | static char buf[15]; | |
6748 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 6749 | printf ("%*s ", len, buf); |
fab128ef CC |
6750 | } |
6751 | ||
4723351a CC |
6752 | /* Display a location list from a .dwo section. It uses address indexes rather |
6753 | than embedded addresses. This code closely follows display_loc_list, but the | |
6754 | two are sufficiently different that combining things is very ugly. */ | |
6755 | ||
6756 | static void | |
6757 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
6758 | unsigned char **start_ptr, |
6759 | unsigned int debug_info_entry, | |
359ca075 | 6760 | dwarf_vma offset, |
9f272209 | 6761 | unsigned char **vstart_ptr, |
b4eb7656 | 6762 | int has_frame_base) |
4723351a | 6763 | { |
9f272209 | 6764 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6765 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6766 | unsigned long cu_offset; |
6767 | unsigned int pointer_size; | |
6768 | unsigned int offset_size; | |
6769 | int dwarf_version; | |
4723351a CC |
6770 | int entry_type; |
6771 | unsigned short length; | |
6772 | int need_frame_base; | |
fab128ef | 6773 | unsigned int idx; |
4723351a | 6774 | |
82b1b41b NC |
6775 | if (debug_info_entry >= num_debug_info_entries) |
6776 | { | |
6777 | warn (_("No debug information for loc lists of entry: %u\n"), | |
6778 | debug_info_entry); | |
6779 | return; | |
6780 | } | |
6781 | ||
6782 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6783 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6784 | offset_size = debug_information [debug_info_entry].offset_size; | |
6785 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6786 | ||
f41e4712 NC |
6787 | if (pointer_size < 2 || pointer_size > 8) |
6788 | { | |
6789 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6790 | pointer_size, debug_info_entry); | |
6791 | return; | |
6792 | } | |
6793 | ||
4723351a CC |
6794 | while (1) |
6795 | { | |
359ca075 | 6796 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 6797 | |
fab128ef | 6798 | if (start >= section_end) |
b4eb7656 AM |
6799 | { |
6800 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6801 | (unsigned long) offset); |
b4eb7656 AM |
6802 | break; |
6803 | } | |
4723351a | 6804 | |
0c588247 | 6805 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
6806 | |
6807 | if (vstart) | |
6808 | switch (entry_type) | |
6809 | { | |
6810 | default: | |
6811 | break; | |
6812 | ||
6813 | case 2: | |
6814 | case 3: | |
6815 | case 4: | |
6816 | { | |
6817 | dwarf_vma view; | |
6818 | dwarf_vma off = offset + (vstart - *start_ptr); | |
6819 | ||
cd30bcef | 6820 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6821 | print_dwarf_view (view, 8, 1); |
6822 | ||
cd30bcef | 6823 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6824 | print_dwarf_view (view, 8, 1); |
6825 | ||
6826 | printf (_("views at %8.8lx for:\n %*s "), | |
6827 | (unsigned long) off, 8, ""); | |
6828 | ||
6829 | } | |
6830 | break; | |
6831 | } | |
6832 | ||
4723351a | 6833 | switch (entry_type) |
b4eb7656 AM |
6834 | { |
6835 | case 0: /* A terminating entry. */ | |
6836 | *start_ptr = start; | |
9f272209 | 6837 | *vstart_ptr = vstart; |
b4eb7656 AM |
6838 | printf (_("<End of list>\n")); |
6839 | return; | |
6840 | case 1: /* A base-address entry. */ | |
cd30bcef | 6841 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6842 | print_addr_index (idx, 8); |
9f272209 | 6843 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
6844 | printf (_("(base address selection entry)\n")); |
6845 | continue; | |
6846 | case 2: /* A start/end entry. */ | |
cd30bcef | 6847 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6848 | print_addr_index (idx, 8); |
cd30bcef | 6849 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6850 | print_addr_index (idx, 8); |
6851 | break; | |
6852 | case 3: /* A start/length entry. */ | |
cd30bcef | 6853 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6854 | print_addr_index (idx, 8); |
6855 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6856 | printf ("%08x ", idx); | |
6857 | break; | |
6858 | case 4: /* An offset pair entry. */ | |
6859 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6860 | printf ("%08x ", idx); | |
6861 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6862 | printf ("%08x ", idx); | |
6863 | break; | |
6864 | default: | |
6865 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
6866 | *start_ptr = start; | |
9f272209 | 6867 | *vstart_ptr = vstart; |
b4eb7656 AM |
6868 | return; |
6869 | } | |
4723351a CC |
6870 | |
6871 | if (start + 2 > section_end) | |
b4eb7656 AM |
6872 | { |
6873 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6874 | (unsigned long) offset); |
b4eb7656 AM |
6875 | break; |
6876 | } | |
4723351a | 6877 | |
0c588247 | 6878 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6879 | if (start + length > section_end) |
b4eb7656 AM |
6880 | { |
6881 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6882 | (unsigned long) offset); |
b4eb7656 AM |
6883 | break; |
6884 | } | |
4723351a CC |
6885 | |
6886 | putchar ('('); | |
6887 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6888 | pointer_size, |
6889 | offset_size, | |
6890 | dwarf_version, | |
6891 | length, | |
6892 | cu_offset, section); | |
4723351a CC |
6893 | putchar (')'); |
6894 | ||
6895 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6896 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
6897 | |
6898 | putchar ('\n'); | |
6899 | ||
6900 | start += length; | |
6901 | } | |
6902 | ||
6903 | *start_ptr = start; | |
9f272209 | 6904 | *vstart_ptr = vstart; |
4723351a CC |
6905 | } |
6906 | ||
9f272209 AO |
6907 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
6908 | loc_views. */ | |
51d0d03f | 6909 | |
9f272209 | 6910 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
6911 | |
6912 | static int | |
6913 | loc_offsets_compar (const void *ap, const void *bp) | |
6914 | { | |
6915 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
6916 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
6917 | ||
9f272209 AO |
6918 | int ret = (a > b) - (b > a); |
6919 | if (ret) | |
6920 | return ret; | |
6921 | ||
6922 | a = loc_views[*(const unsigned int *) ap]; | |
6923 | b = loc_views[*(const unsigned int *) bp]; | |
6924 | ||
6925 | ret = (a > b) - (b > a); | |
6926 | ||
6927 | return ret; | |
51d0d03f JJ |
6928 | } |
6929 | ||
19e6b90e L |
6930 | static int |
6931 | display_debug_loc (struct dwarf_section *section, void *file) | |
6932 | { | |
9f272209 | 6933 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
6934 | unsigned long bytes; |
6935 | unsigned char *section_begin = start; | |
6936 | unsigned int num_loc_list = 0; | |
6937 | unsigned long last_offset = 0; | |
9f272209 | 6938 | unsigned long last_view = 0; |
19e6b90e L |
6939 | unsigned int first = 0; |
6940 | unsigned int i; | |
6941 | unsigned int j; | |
6942 | int seen_first_offset = 0; | |
51d0d03f | 6943 | int locs_sorted = 1; |
9f272209 | 6944 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6945 | unsigned int *array = NULL; |
4723351a | 6946 | const char *suffix = strrchr (section->name, '.'); |
24841daa | 6947 | bfd_boolean is_dwo = FALSE; |
77145576 JK |
6948 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6949 | dwarf_vma expected_start = 0; | |
4723351a CC |
6950 | |
6951 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
24841daa | 6952 | is_dwo = TRUE; |
19e6b90e L |
6953 | |
6954 | bytes = section->size; | |
19e6b90e L |
6955 | |
6956 | if (bytes == 0) | |
6957 | { | |
6958 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6959 | return 0; | |
6960 | } | |
6961 | ||
77145576 JK |
6962 | if (is_loclists) |
6963 | { | |
6964 | unsigned char *hdrptr = section_begin; | |
6965 | dwarf_vma ll_length; | |
6966 | unsigned short ll_version; | |
6967 | unsigned char *end = section_begin + section->size; | |
6968 | unsigned char address_size, segment_selector_size; | |
6969 | uint32_t offset_entry_count; | |
6970 | ||
6971 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6972 | if (ll_length == 0xffffffff) | |
6973 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6974 | ||
6975 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6976 | if (ll_version != 5) | |
6977 | { | |
6978 | warn (_("The %s section contains corrupt or " | |
6979 | "unsupported version number: %d.\n"), | |
6980 | section->name, ll_version); | |
6981 | return 0; | |
6982 | } | |
6983 | ||
6984 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6985 | ||
6986 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6987 | if (segment_selector_size != 0) | |
6988 | { | |
6989 | warn (_("The %s section contains " | |
6990 | "unsupported segment selector size: %d.\n"), | |
6991 | section->name, segment_selector_size); | |
6992 | return 0; | |
6993 | } | |
6994 | ||
6995 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
6996 | if (offset_entry_count != 0) | |
6997 | { | |
6998 | warn (_("The %s section contains " | |
6999 | "unsupported offset entry count: %d.\n"), | |
7000 | section->name, offset_entry_count); | |
7001 | return 0; | |
7002 | } | |
7003 | ||
7004 | expected_start = hdrptr - section_begin; | |
7005 | } | |
7006 | ||
1febe64d NC |
7007 | if (load_debug_info (file) == 0) |
7008 | { | |
7009 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7010 | section->name); | |
7011 | return 0; | |
7012 | } | |
19e6b90e L |
7013 | |
7014 | /* Check the order of location list in .debug_info section. If | |
7015 | offsets of location lists are in the ascending order, we can | |
7016 | use `debug_information' directly. */ | |
7017 | for (i = 0; i < num_debug_info_entries; i++) | |
7018 | { | |
7019 | unsigned int num; | |
7020 | ||
7021 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
7022 | if (num > num_loc_list) |
7023 | num_loc_list = num; | |
19e6b90e L |
7024 | |
7025 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 7026 | if (locs_sorted && num != 0) |
19e6b90e L |
7027 | { |
7028 | if (!seen_first_offset) | |
7029 | { | |
7030 | /* This is the first location list. */ | |
7031 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 7032 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
7033 | first = i; |
7034 | seen_first_offset = 1; | |
7035 | j = 1; | |
7036 | } | |
7037 | else | |
7038 | j = 0; | |
7039 | ||
7040 | for (; j < num; j++) | |
7041 | { | |
7042 | if (last_offset > | |
9f272209 AO |
7043 | debug_information [i].loc_offsets [j] |
7044 | || (last_offset == debug_information [i].loc_offsets [j] | |
7045 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 7046 | { |
51d0d03f | 7047 | locs_sorted = 0; |
19e6b90e L |
7048 | break; |
7049 | } | |
7050 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 7051 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
7052 | } |
7053 | } | |
7054 | } | |
7055 | ||
19e6b90e L |
7056 | if (!seen_first_offset) |
7057 | error (_("No location lists in .debug_info section!\n")); | |
7058 | ||
d4bfc77b | 7059 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
7060 | && debug_information [first].loc_offsets [0] != expected_start |
7061 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
7062 | warn (_("Location lists in %s section start at 0x%s\n"), |
7063 | section->name, | |
7064 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 7065 | |
51d0d03f JJ |
7066 | if (!locs_sorted) |
7067 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d NC |
7068 | |
7069 | introduce (section, FALSE); | |
7070 | ||
d1c4b12b NC |
7071 | if (reloc_at (section, 0)) |
7072 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 7073 | |
d1c4b12b | 7074 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
7075 | |
7076 | seen_first_offset = 0; | |
7077 | for (i = first; i < num_debug_info_entries; i++) | |
7078 | { | |
9f272209 | 7079 | dwarf_vma offset, voffset; |
359ca075 | 7080 | dwarf_vma base_address; |
d1c4b12b | 7081 | unsigned int k; |
19e6b90e L |
7082 | int has_frame_base; |
7083 | ||
51d0d03f JJ |
7084 | if (!locs_sorted) |
7085 | { | |
7086 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
7087 | array[k] = k; | |
7088 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 7089 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
7090 | qsort (array, debug_information [i].num_loc_offsets, |
7091 | sizeof (*array), loc_offsets_compar); | |
7092 | } | |
19e6b90e | 7093 | |
9f272209 | 7094 | int adjacent_view_loclists = 1; |
51d0d03f | 7095 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 7096 | { |
51d0d03f JJ |
7097 | j = locs_sorted ? k : array[k]; |
7098 | if (k | |
9f272209 | 7099 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 7100 | ? k - 1 : array [k - 1]] |
9f272209 AO |
7101 | == debug_information [i].loc_offsets [j]) |
7102 | && (debug_information [i].loc_views [locs_sorted | |
7103 | ? k - 1 : array [k - 1]] | |
7104 | == debug_information [i].loc_views [j])) | |
51d0d03f | 7105 | continue; |
19e6b90e | 7106 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 7107 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 7108 | next = section_begin + offset; |
9f272209 AO |
7109 | voffset = debug_information [i].loc_views [j]; |
7110 | if (voffset != vm1) | |
7111 | vnext = section_begin + voffset; | |
7112 | else | |
7113 | vnext = NULL; | |
19e6b90e L |
7114 | base_address = debug_information [i].base_address; |
7115 | ||
9f272209 AO |
7116 | if (vnext && vnext < next) |
7117 | { | |
7118 | vstart = vnext; | |
7119 | display_view_pair_list (section, &vstart, i, next); | |
7120 | if (start == vnext) | |
7121 | start = vstart; | |
7122 | } | |
7123 | ||
7124 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
7125 | seen_first_offset = 1; |
7126 | else | |
7127 | { | |
7128 | if (start < next) | |
7129 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 7130 | (unsigned long) (start - section_begin), |
c8071705 | 7131 | (unsigned long) offset); |
19e6b90e L |
7132 | else if (start > next) |
7133 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 7134 | (unsigned long) (start - section_begin), |
c8071705 | 7135 | (unsigned long) offset); |
19e6b90e L |
7136 | } |
7137 | start = next; | |
9f272209 | 7138 | vstart = vnext; |
19e6b90e L |
7139 | |
7140 | if (offset >= bytes) | |
7141 | { | |
7142 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 7143 | (unsigned long) offset); |
19e6b90e L |
7144 | continue; |
7145 | } | |
7146 | ||
9f272209 AO |
7147 | if (vnext && voffset >= bytes) |
7148 | { | |
7149 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
7150 | (unsigned long) voffset); | |
7151 | continue; | |
7152 | } | |
7153 | ||
77145576 JK |
7154 | if (!is_loclists) |
7155 | { | |
7156 | if (is_dwo) | |
7157 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 7158 | &vstart, has_frame_base); |
77145576 JK |
7159 | else |
7160 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 7161 | &vstart, has_frame_base); |
77145576 | 7162 | } |
b4eb7656 | 7163 | else |
77145576 JK |
7164 | { |
7165 | if (is_dwo) | |
7166 | warn (_("DWO is not yet supported.\n")); | |
7167 | else | |
7168 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
7169 | &vstart, has_frame_base); |
7170 | } | |
7171 | ||
7172 | /* FIXME: this arrangement is quite simplistic. Nothing | |
7173 | requires locview lists to be adjacent to corresponding | |
7174 | loclists, and a single loclist could be augmented by | |
7175 | different locview lists, and vice-versa, unlikely as it | |
7176 | is that it would make sense to do so. Hopefully we'll | |
7177 | have view pair support built into loclists before we ever | |
7178 | need to address all these possibilities. */ | |
7179 | if (adjacent_view_loclists && vnext | |
7180 | && vnext != start && vstart != next) | |
7181 | { | |
7182 | adjacent_view_loclists = 0; | |
7183 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 7184 | } |
9f272209 AO |
7185 | |
7186 | if (vnext && vnext == start) | |
7187 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
7188 | } |
7189 | } | |
031cd65f | 7190 | |
4723351a | 7191 | if (start < section->start + section->size) |
d3a49aa8 AM |
7192 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
7193 | "There are %ld unused bytes at the end of section %s\n", | |
7194 | (long) (section->start + section->size - start)), | |
4723351a | 7195 | (long) (section->start + section->size - start), section->name); |
98fb390a | 7196 | putchar ('\n'); |
51d0d03f | 7197 | free (array); |
19e6b90e L |
7198 | return 1; |
7199 | } | |
7200 | ||
7201 | static int | |
7202 | display_debug_str (struct dwarf_section *section, | |
7203 | void *file ATTRIBUTE_UNUSED) | |
7204 | { | |
7205 | unsigned char *start = section->start; | |
7206 | unsigned long bytes = section->size; | |
7207 | dwarf_vma addr = section->address; | |
7208 | ||
7209 | if (bytes == 0) | |
7210 | { | |
7211 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7212 | return 0; | |
7213 | } | |
7214 | ||
dda8d76d | 7215 | introduce (section, FALSE); |
19e6b90e L |
7216 | |
7217 | while (bytes) | |
7218 | { | |
7219 | int j; | |
7220 | int k; | |
7221 | int lbytes; | |
7222 | ||
7223 | lbytes = (bytes > 16 ? 16 : bytes); | |
7224 | ||
7225 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
7226 | ||
7227 | for (j = 0; j < 16; j++) | |
7228 | { | |
7229 | if (j < lbytes) | |
7230 | printf ("%2.2x", start[j]); | |
7231 | else | |
7232 | printf (" "); | |
7233 | ||
7234 | if ((j & 3) == 3) | |
7235 | printf (" "); | |
7236 | } | |
7237 | ||
7238 | for (j = 0; j < lbytes; j++) | |
7239 | { | |
7240 | k = start[j]; | |
7241 | if (k >= ' ' && k < 0x80) | |
7242 | printf ("%c", k); | |
7243 | else | |
7244 | printf ("."); | |
7245 | } | |
7246 | ||
7247 | putchar ('\n'); | |
7248 | ||
7249 | start += lbytes; | |
7250 | addr += lbytes; | |
7251 | bytes -= lbytes; | |
7252 | } | |
7253 | ||
7254 | putchar ('\n'); | |
7255 | ||
7256 | return 1; | |
7257 | } | |
7258 | ||
19e6b90e L |
7259 | static int |
7260 | display_debug_info (struct dwarf_section *section, void *file) | |
7261 | { | |
d85bf2ba | 7262 | return process_debug_info (section, file, section->abbrev_sec, FALSE, FALSE); |
19e6b90e L |
7263 | } |
7264 | ||
2b6f5997 CC |
7265 | static int |
7266 | display_debug_types (struct dwarf_section *section, void *file) | |
7267 | { | |
d85bf2ba | 7268 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
6f875884 TG |
7269 | } |
7270 | ||
7271 | static int | |
7272 | display_trace_info (struct dwarf_section *section, void *file) | |
7273 | { | |
d85bf2ba | 7274 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
2b6f5997 | 7275 | } |
19e6b90e L |
7276 | |
7277 | static int | |
7278 | display_debug_aranges (struct dwarf_section *section, | |
7279 | void *file ATTRIBUTE_UNUSED) | |
7280 | { | |
7281 | unsigned char *start = section->start; | |
7282 | unsigned char *end = start + section->size; | |
7283 | ||
dda8d76d | 7284 | introduce (section, FALSE); |
19e6b90e | 7285 | |
6e3d6dc1 NC |
7286 | /* It does not matter if this load fails, |
7287 | we test for that later on. */ | |
7288 | load_debug_info (file); | |
7289 | ||
19e6b90e L |
7290 | while (start < end) |
7291 | { | |
7292 | unsigned char *hdrptr; | |
7293 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 7294 | unsigned char *addr_ranges; |
2d9472a2 NC |
7295 | dwarf_vma length; |
7296 | dwarf_vma address; | |
e98fdf1a | 7297 | unsigned long sec_off; |
53b8873b | 7298 | unsigned char address_size; |
19e6b90e | 7299 | int excess; |
bf5117e3 NC |
7300 | unsigned int offset_size; |
7301 | unsigned int initial_length_size; | |
19e6b90e L |
7302 | |
7303 | hdrptr = start; | |
7304 | ||
0c588247 | 7305 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
7306 | if (arange.ar_length == 0xffffffff) |
7307 | { | |
0c588247 | 7308 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
7309 | offset_size = 8; |
7310 | initial_length_size = 12; | |
7311 | } | |
7312 | else | |
7313 | { | |
7314 | offset_size = 4; | |
7315 | initial_length_size = 4; | |
7316 | } | |
7317 | ||
e98fdf1a AM |
7318 | sec_off = hdrptr - section->start; |
7319 | if (sec_off + arange.ar_length < sec_off | |
7320 | || sec_off + arange.ar_length > section->size) | |
7321 | { | |
7322 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
7323 | section->name, | |
7324 | sec_off - initial_length_size, | |
7325 | dwarf_vmatoa ("x", arange.ar_length)); | |
7326 | break; | |
7327 | } | |
7328 | ||
0c588247 NC |
7329 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
7330 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 7331 | |
6e3d6dc1 NC |
7332 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
7333 | && num_debug_info_entries > 0 | |
7334 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
7335 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 7336 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 7337 | |
0c588247 NC |
7338 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
7339 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
7340 | |
7341 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
7342 | { | |
67f101ee NC |
7343 | /* PR 19872: A version number of 0 probably means that there is |
7344 | padding at the end of the .debug_aranges section. Gold puts | |
7345 | it there when performing an incremental link, for example. | |
7346 | So do not generate a warning in this case. */ | |
7347 | if (arange.ar_version) | |
7348 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
7349 | break; |
7350 | } | |
7351 | ||
47704ddf KT |
7352 | printf (_(" Length: %ld\n"), |
7353 | (long) arange.ar_length); | |
19e6b90e | 7354 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
7355 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
7356 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
7357 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
7358 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
7359 | ||
53b8873b NC |
7360 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
7361 | ||
f41e4712 NC |
7362 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
7363 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
7364 | { |
7365 | error (_("Invalid address size in %s section!\n"), | |
7366 | section->name); | |
7367 | break; | |
7368 | } | |
7369 | ||
53b8873b NC |
7370 | /* The DWARF spec does not require that the address size be a power |
7371 | of two, but we do. This will have to change if we ever encounter | |
7372 | an uneven architecture. */ | |
7373 | if ((address_size & (address_size - 1)) != 0) | |
7374 | { | |
7375 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
7376 | break; | |
7377 | } | |
cecf136e | 7378 | |
209c9a13 NC |
7379 | if (address_size > 4) |
7380 | printf (_("\n Address Length\n")); | |
7381 | else | |
7382 | printf (_("\n Address Length\n")); | |
19e6b90e | 7383 | |
91d6fa6a | 7384 | addr_ranges = hdrptr; |
19e6b90e | 7385 | |
53b8873b NC |
7386 | /* Must pad to an alignment boundary that is twice the address size. */ |
7387 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 7388 | if (excess) |
91d6fa6a | 7389 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 7390 | |
e98fdf1a | 7391 | start += arange.ar_length + initial_length_size; |
1617e571 | 7392 | |
91d6fa6a | 7393 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 7394 | { |
0c588247 NC |
7395 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
7396 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 7397 | |
80c35038 | 7398 | printf (" "); |
2d9472a2 NC |
7399 | print_dwarf_vma (address, address_size); |
7400 | print_dwarf_vma (length, address_size); | |
7401 | putchar ('\n'); | |
19e6b90e | 7402 | } |
19e6b90e L |
7403 | } |
7404 | ||
7405 | printf ("\n"); | |
7406 | ||
7407 | return 1; | |
7408 | } | |
7409 | ||
4723351a CC |
7410 | /* Comparison function for qsort. */ |
7411 | static int | |
7412 | comp_addr_base (const void * v0, const void * v1) | |
7413 | { | |
d367307b AM |
7414 | debug_info *info0 = *(debug_info **) v0; |
7415 | debug_info *info1 = *(debug_info **) v1; | |
4723351a CC |
7416 | return info0->addr_base - info1->addr_base; |
7417 | } | |
7418 | ||
7419 | /* Display the debug_addr section. */ | |
7420 | static int | |
7421 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 7422 | void *file) |
4723351a CC |
7423 | { |
7424 | debug_info **debug_addr_info; | |
7425 | unsigned char *entry; | |
7426 | unsigned char *end; | |
7427 | unsigned int i; | |
7428 | unsigned int count; | |
0e12f6c8 | 7429 | unsigned char * header; |
4723351a CC |
7430 | |
7431 | if (section->size == 0) | |
7432 | { | |
7433 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7434 | return 0; | |
7435 | } | |
7436 | ||
7437 | if (load_debug_info (file) == 0) | |
7438 | { | |
7439 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7440 | section->name); | |
7441 | return 0; | |
7442 | } | |
7443 | ||
dda8d76d | 7444 | introduce (section, FALSE); |
4723351a | 7445 | |
1306a742 NC |
7446 | /* PR 17531: file: cf38d01b. |
7447 | We use xcalloc because a corrupt file may not have initialised all of the | |
7448 | fields in the debug_info structure, which means that the sort below might | |
7449 | try to move uninitialised data. */ | |
7450 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 7451 | sizeof (debug_info *)); |
4723351a CC |
7452 | |
7453 | count = 0; | |
7454 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 7455 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
7456 | { |
7457 | /* PR 17531: file: cf38d01b. */ | |
7458 | if (debug_information[i].addr_base >= section->size) | |
7459 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
7460 | (unsigned long) debug_information[i].addr_base, i); | |
7461 | else | |
7462 | debug_addr_info [count++] = debug_information + i; | |
7463 | } | |
4723351a CC |
7464 | |
7465 | /* Add a sentinel to make iteration convenient. */ | |
7466 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
7467 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 7468 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 7469 | |
0e12f6c8 | 7470 | header = section->start; |
4723351a CC |
7471 | for (i = 0; i < count; i++) |
7472 | { | |
7473 | unsigned int idx; | |
fab128ef | 7474 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
7475 | |
7476 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 7477 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 7478 | |
fab128ef | 7479 | printf (_("\tIndex\tAddress\n")); |
4723351a | 7480 | entry = section->start + debug_addr_info [i]->addr_base; |
0e12f6c8 TV |
7481 | if (debug_addr_info [i]->dwarf_version >= 5) |
7482 | { | |
7483 | size_t header_size = entry - header; | |
7484 | unsigned char * curr_header = header; | |
7485 | dwarf_vma length; | |
7486 | int version; | |
7487 | int segment_selector_size; | |
7488 | ||
7489 | if (header_size != 8 && header_size != 16) | |
7490 | { | |
7491 | warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"), | |
7492 | section->name, (long) header_size); | |
7493 | return 0; | |
7494 | } | |
7495 | ||
7496 | SAFE_BYTE_GET_AND_INC (length, curr_header, 4, entry); | |
7497 | if (length == 0xffffffff) | |
7498 | SAFE_BYTE_GET (length, curr_header, 8, entry); | |
7499 | end = curr_header + length; | |
7500 | ||
7501 | SAFE_BYTE_GET_AND_INC (version, curr_header, 2, entry); | |
7502 | if (version != 5) | |
7503 | warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"), | |
7504 | section->name, version); | |
7505 | ||
7506 | SAFE_BYTE_GET_AND_INC (address_size, curr_header, 1, entry); | |
7507 | SAFE_BYTE_GET_AND_INC (segment_selector_size, curr_header, 1, entry); | |
7508 | address_size += segment_selector_size; | |
7509 | } | |
7510 | else | |
7511 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
7512 | header = end; | |
4723351a CC |
7513 | idx = 0; |
7514 | while (entry < end) | |
b4eb7656 AM |
7515 | { |
7516 | dwarf_vma base = byte_get (entry, address_size); | |
7517 | printf (_("\t%d:\t"), idx); | |
7518 | print_dwarf_vma (base, address_size); | |
7519 | printf ("\n"); | |
7520 | entry += address_size; | |
7521 | idx++; | |
7522 | } | |
4723351a CC |
7523 | } |
7524 | printf ("\n"); | |
7525 | ||
7526 | free (debug_addr_info); | |
7527 | return 1; | |
7528 | } | |
7529 | ||
7530 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 7531 | |
4723351a CC |
7532 | static int |
7533 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 7534 | void *file ATTRIBUTE_UNUSED) |
4723351a | 7535 | { |
9f27c364 HPN |
7536 | unsigned long idx; |
7537 | ||
4723351a CC |
7538 | if (section->size == 0) |
7539 | { | |
7540 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7541 | return 0; | |
7542 | } | |
e4b7104b NC |
7543 | |
7544 | unsigned char *start = section->start; | |
7545 | unsigned char *end = start + section->size; | |
7546 | unsigned char *curr = start; | |
7547 | ||
39f381cb NC |
7548 | const char * suffix = strrchr (section->name, '.'); |
7549 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
7550 | ||
7551 | if (dwo) | |
7552 | load_debug_section_with_follow (str_dwo, file); | |
7553 | else | |
7554 | load_debug_section_with_follow (str, file); | |
e4b7104b NC |
7555 | |
7556 | introduce (section, FALSE); | |
7557 | ||
7558 | while (curr < end) | |
7559 | { | |
7560 | dwarf_vma length; | |
7561 | dwarf_vma entry_length; | |
7562 | ||
7563 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); | |
7564 | /* FIXME: We assume that this means 64-bit DWARF is being used. */ | |
7565 | if (length == 0xffffffff) | |
7566 | { | |
7567 | SAFE_BYTE_GET (length, curr, 8, end); | |
7568 | entry_length = 8; | |
7569 | } | |
7570 | else | |
7571 | entry_length = 4; | |
7572 | ||
95abb394 | 7573 | unsigned char *entries_end; |
39f381cb NC |
7574 | if (length == 0) |
7575 | { | |
7576 | /* This is probably an old style .debug_str_offset section which | |
7577 | just contains offsets and no header (and the first offset is 0). */ | |
7578 | length = section->size; | |
7579 | curr = section->start; | |
95abb394 | 7580 | entries_end = end; |
e4b7104b | 7581 | |
39f381cb NC |
7582 | printf (_(" Length: %#lx\n"), (unsigned long) length); |
7583 | printf (_(" Index Offset [String]\n")); | |
7584 | } | |
7585 | else | |
7586 | { | |
95abb394 TV |
7587 | entries_end = curr + length; |
7588 | ||
39f381cb NC |
7589 | int version; |
7590 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); | |
7591 | if (version != 5) | |
7592 | warn (_("Unexpected version number in str_offset header: %#x\n"), version); | |
7593 | ||
7594 | int padding; | |
7595 | SAFE_BYTE_GET_AND_INC (padding, curr, 2, end); | |
7596 | if (padding != 0) | |
7597 | warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding); | |
7598 | ||
7599 | printf (_(" Length: %#lx\n"), (unsigned long) length); | |
7600 | printf (_(" Version: %#lx\n"), (unsigned long) version); | |
7601 | printf (_(" Index Offset [String]\n")); | |
7602 | } | |
e4b7104b | 7603 | |
95abb394 | 7604 | for (idx = 0; curr < entries_end; idx++) |
e4b7104b NC |
7605 | { |
7606 | dwarf_vma offset; | |
7607 | const unsigned char * string; | |
7608 | ||
95abb394 TV |
7609 | if (curr + entry_length > entries_end) |
7610 | /* Not enough space to read one entry_length, give up. */ | |
7611 | return 0; | |
7612 | ||
e4b7104b | 7613 | SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, end); |
39f381cb NC |
7614 | if (dwo) |
7615 | string = (const unsigned char *) | |
9f27c364 | 7616 | fetch_indexed_string (idx, NULL, entry_length, dwo); |
39f381cb NC |
7617 | else |
7618 | string = fetch_indirect_string (offset); | |
7619 | ||
9f27c364 | 7620 | printf (" %8lu %8s %s\n", idx, dwarf_vmatoa ("x", offset), |
e4b7104b NC |
7621 | string); |
7622 | } | |
7623 | } | |
39f381cb | 7624 | |
4723351a CC |
7625 | return 1; |
7626 | } | |
7627 | ||
01a8f077 JK |
7628 | /* Each debug_information[x].range_lists[y] gets this representation for |
7629 | sorting purposes. */ | |
7630 | ||
7631 | struct range_entry | |
467c65bc NC |
7632 | { |
7633 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 7634 | dwarf_vma ranges_offset; |
01a8f077 | 7635 | |
467c65bc NC |
7636 | /* Original debug_information to find parameters of the data. */ |
7637 | debug_info *debug_info_p; | |
7638 | }; | |
01a8f077 JK |
7639 | |
7640 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
7641 | ||
7642 | static int | |
7643 | range_entry_compar (const void *ap, const void *bp) | |
7644 | { | |
3f5e193b NC |
7645 | const struct range_entry *a_re = (const struct range_entry *) ap; |
7646 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
7647 | const dwarf_vma a = a_re->ranges_offset; |
7648 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
7649 | |
7650 | return (a > b) - (b > a); | |
7651 | } | |
7652 | ||
77145576 JK |
7653 | static void |
7654 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
7655 | unsigned int pointer_size, unsigned long offset, | |
7656 | unsigned long base_address) | |
7657 | { | |
7658 | while (start < finish) | |
7659 | { | |
7660 | dwarf_vma begin; | |
7661 | dwarf_vma end; | |
7662 | ||
7663 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7664 | if (start >= finish) | |
7665 | break; | |
7666 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7667 | ||
7668 | printf (" %8.8lx ", offset); | |
7669 | ||
7670 | if (begin == 0 && end == 0) | |
7671 | { | |
7672 | printf (_("<End of list>\n")); | |
7673 | break; | |
7674 | } | |
7675 | ||
7676 | /* Check base address specifiers. */ | |
7677 | if (is_max_address (begin, pointer_size) | |
7678 | && !is_max_address (end, pointer_size)) | |
7679 | { | |
7680 | base_address = end; | |
7681 | print_dwarf_vma (begin, pointer_size); | |
7682 | print_dwarf_vma (end, pointer_size); | |
7683 | printf ("(base address)\n"); | |
7684 | continue; | |
7685 | } | |
7686 | ||
7687 | print_dwarf_vma (begin + base_address, pointer_size); | |
7688 | print_dwarf_vma (end + base_address, pointer_size); | |
7689 | ||
7690 | if (begin == end) | |
7691 | fputs (_("(start == end)"), stdout); | |
7692 | else if (begin > end) | |
7693 | fputs (_("(start > end)"), stdout); | |
7694 | ||
7695 | putchar ('\n'); | |
7696 | } | |
7697 | } | |
7698 | ||
7699 | static void | |
7700 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
7701 | unsigned int pointer_size, unsigned long offset, | |
7702 | unsigned long base_address) | |
7703 | { | |
7704 | unsigned char *next = start; | |
7705 | ||
7706 | while (1) | |
7707 | { | |
7708 | unsigned long off = offset + (start - next); | |
7709 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
7710 | /* Initialize it due to a false compiler warning. */ |
7711 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
7712 | |
7713 | if (start + 1 > finish) | |
7714 | { | |
7715 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
7716 | offset); | |
7717 | break; | |
7718 | } | |
7719 | ||
7720 | printf (" %8.8lx ", off); | |
7721 | ||
7722 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
7723 | ||
7724 | switch (rlet) | |
7725 | { | |
7726 | case DW_RLE_end_of_list: | |
7727 | printf (_("<End of list>\n")); | |
7728 | break; | |
7729 | case DW_RLE_base_address: | |
7730 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
7731 | print_dwarf_vma (base_address, pointer_size); | |
7732 | printf (_("(base address)\n")); | |
7733 | break; | |
7734 | case DW_RLE_start_length: | |
7735 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
cd30bcef | 7736 | READ_ULEB (length, start, finish); |
77145576 JK |
7737 | end = begin + length; |
7738 | break; | |
7739 | case DW_RLE_offset_pair: | |
cd30bcef AM |
7740 | READ_ULEB (begin, start, finish); |
7741 | READ_ULEB (end, start, finish); | |
77145576 JK |
7742 | break; |
7743 | case DW_RLE_start_end: | |
7744 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7745 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7746 | break; | |
7747 | default: | |
7748 | error (_("Invalid range list entry type %d\n"), rlet); | |
7749 | rlet = DW_RLE_end_of_list; | |
7750 | break; | |
7751 | } | |
7752 | if (rlet == DW_RLE_end_of_list) | |
7753 | break; | |
7754 | if (rlet == DW_RLE_base_address) | |
7755 | continue; | |
7756 | ||
4d932715 BE |
7757 | /* Only a DW_RLE_offset_pair needs the base address added. */ |
7758 | if (rlet == DW_RLE_offset_pair) | |
7759 | { | |
7760 | begin += base_address; | |
7761 | end += base_address; | |
7762 | } | |
7763 | ||
7764 | print_dwarf_vma (begin, pointer_size); | |
7765 | print_dwarf_vma (end, pointer_size); | |
77145576 JK |
7766 | |
7767 | if (begin == end) | |
7768 | fputs (_("(start == end)"), stdout); | |
7769 | else if (begin > end) | |
7770 | fputs (_("(start > end)"), stdout); | |
7771 | ||
7772 | putchar ('\n'); | |
7773 | } | |
7774 | } | |
7775 | ||
19e6b90e L |
7776 | static int |
7777 | display_debug_ranges (struct dwarf_section *section, | |
7778 | void *file ATTRIBUTE_UNUSED) | |
7779 | { | |
7780 | unsigned char *start = section->start; | |
a2ff7a4b | 7781 | unsigned char *last_start = start; |
f6f0e17b | 7782 | unsigned long bytes = section->size; |
19e6b90e | 7783 | unsigned char *section_begin = start; |
f6f0e17b | 7784 | unsigned char *finish = start + bytes; |
01a8f077 JK |
7785 | unsigned int num_range_list, i; |
7786 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
7787 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
7788 | /* Initialize it due to a false compiler warning. */ | |
7789 | unsigned char address_size = 0; | |
cb4c35cf | 7790 | dwarf_vma last_offset = 0; |
19e6b90e | 7791 | |
19e6b90e L |
7792 | if (bytes == 0) |
7793 | { | |
7794 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7795 | return 0; | |
7796 | } | |
7797 | ||
77145576 JK |
7798 | if (is_rnglists) |
7799 | { | |
7800 | dwarf_vma initial_length; | |
7801 | unsigned int initial_length_size; | |
7802 | unsigned char segment_selector_size; | |
7803 | unsigned int offset_size, offset_entry_count; | |
7804 | unsigned short version; | |
7805 | ||
7806 | /* Get and check the length of the block. */ | |
7807 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
7808 | ||
7809 | if (initial_length == 0xffffffff) | |
7810 | { | |
7811 | /* This section is 64-bit DWARF 3. */ | |
7812 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
7813 | offset_size = 8; | |
7814 | initial_length_size = 12; | |
7815 | } | |
7816 | else | |
7817 | { | |
7818 | offset_size = 4; | |
7819 | initial_length_size = 4; | |
7820 | } | |
7821 | ||
7822 | if (initial_length + initial_length_size > section->size) | |
7823 | { | |
7824 | /* If the length field has a relocation against it, then we should | |
7825 | not complain if it is inaccurate (and probably negative). | |
7826 | It is copied from .debug_line handling code. */ | |
7827 | if (reloc_at (section, (start - section->start) - offset_size)) | |
7828 | { | |
7829 | initial_length = (finish - start) - initial_length_size; | |
7830 | } | |
7831 | else | |
7832 | { | |
7833 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
7834 | (long) initial_length); | |
7835 | return 0; | |
7836 | } | |
7837 | } | |
7838 | ||
7839 | /* Get and check the version number. */ | |
7840 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
7841 | ||
7842 | if (version != 5) | |
7843 | { | |
7844 | warn (_("Only DWARF version 5 debug_rnglists info " | |
7845 | "is currently supported.\n")); | |
7846 | return 0; | |
7847 | } | |
7848 | ||
7849 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
7850 | ||
7851 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
7852 | if (segment_selector_size != 0) | |
7853 | { | |
7854 | warn (_("The %s section contains " | |
7855 | "unsupported segment selector size: %d.\n"), | |
7856 | section->name, segment_selector_size); | |
7857 | return 0; | |
7858 | } | |
7859 | ||
7860 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
7861 | if (offset_entry_count != 0) | |
7862 | { | |
7863 | warn (_("The %s section contains " | |
7864 | "unsupported offset entry count: %u.\n"), | |
7865 | section->name, offset_entry_count); | |
7866 | return 0; | |
7867 | } | |
7868 | } | |
7869 | ||
1febe64d NC |
7870 | if (load_debug_info (file) == 0) |
7871 | { | |
7872 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7873 | section->name); | |
7874 | return 0; | |
7875 | } | |
19e6b90e | 7876 | |
01a8f077 | 7877 | num_range_list = 0; |
19e6b90e | 7878 | for (i = 0; i < num_debug_info_entries; i++) |
52ff20fe TV |
7879 | { |
7880 | if (debug_information [i].dwarf_version < 5 && is_rnglists) | |
7881 | /* Skip .debug_rnglists reference. */ | |
7882 | continue; | |
7883 | if (debug_information [i].dwarf_version >= 5 && !is_rnglists) | |
7884 | /* Skip .debug_range reference. */ | |
7885 | continue; | |
7886 | num_range_list += debug_information [i].num_range_lists; | |
7887 | } | |
19e6b90e | 7888 | |
01a8f077 | 7889 | if (num_range_list == 0) |
4723351a CC |
7890 | { |
7891 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 7892 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
7893 | printf (_("No range lists in .debug_info section.\n")); |
7894 | return 1; | |
7895 | } | |
19e6b90e | 7896 | |
3f5e193b NC |
7897 | range_entries = (struct range_entry *) |
7898 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 7899 | range_entry_fill = range_entries; |
19e6b90e | 7900 | |
01a8f077 JK |
7901 | for (i = 0; i < num_debug_info_entries; i++) |
7902 | { | |
7903 | debug_info *debug_info_p = &debug_information[i]; | |
7904 | unsigned int j; | |
7905 | ||
52ff20fe TV |
7906 | if (debug_information [i].dwarf_version < 5 && is_rnglists) |
7907 | /* Skip .debug_rnglists reference. */ | |
7908 | continue; | |
7909 | if (debug_information [i].dwarf_version >= 5 && !is_rnglists) | |
7910 | /* Skip .debug_range reference. */ | |
7911 | continue; | |
7912 | ||
01a8f077 JK |
7913 | for (j = 0; j < debug_info_p->num_range_lists; j++) |
7914 | { | |
7915 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
7916 | range_entry_fill->debug_info_p = debug_info_p; | |
7917 | range_entry_fill++; | |
19e6b90e L |
7918 | } |
7919 | } | |
7920 | ||
01a8f077 JK |
7921 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
7922 | range_entry_compar); | |
19e6b90e | 7923 | |
d493b283 | 7924 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 7925 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 7926 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 7927 | |
dda8d76d NC |
7928 | introduce (section, FALSE); |
7929 | ||
19e6b90e L |
7930 | printf (_(" Offset Begin End\n")); |
7931 | ||
01a8f077 | 7932 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 7933 | { |
01a8f077 JK |
7934 | struct range_entry *range_entry = &range_entries[i]; |
7935 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 7936 | unsigned int pointer_size; |
359ca075 | 7937 | dwarf_vma offset; |
01a8f077 | 7938 | unsigned char *next; |
359ca075 | 7939 | dwarf_vma base_address; |
19e6b90e | 7940 | |
77145576 | 7941 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 7942 | offset = range_entry->ranges_offset; |
01a8f077 JK |
7943 | next = section_begin + offset; |
7944 | base_address = debug_info_p->base_address; | |
cecf136e | 7945 | |
f41e4712 NC |
7946 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
7947 | if (pointer_size < 2 || pointer_size > 8) | |
7948 | { | |
7949 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 7950 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
7951 | continue; |
7952 | } | |
b4eb7656 | 7953 | |
d11ae95e NC |
7954 | if (next < section_begin || next >= finish) |
7955 | { | |
7956 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
7957 | (unsigned long) offset, i); | |
7958 | continue; | |
7959 | } | |
7960 | ||
cb4c35cf AB |
7961 | /* If multiple DWARF entities reference the same range then we will |
7962 | have multiple entries in the `range_entries' list for the same | |
7963 | offset. Thanks to the sort above these will all be consecutive in | |
7964 | the `range_entries' list, so we can easily ignore duplicates | |
7965 | here. */ | |
7966 | if (i > 0 && last_offset == offset) | |
7967 | continue; | |
7968 | last_offset = offset; | |
7969 | ||
4723351a | 7970 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 7971 | { |
01a8f077 JK |
7972 | if (start < next) |
7973 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
7974 | (unsigned long) (start - section_begin), | |
7975 | (unsigned long) (next - section_begin), section->name); | |
7976 | else if (start > next) | |
a2ff7a4b AM |
7977 | { |
7978 | if (next == last_start) | |
7979 | continue; | |
7980 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
7981 | (unsigned long) (start - section_begin), | |
7982 | (unsigned long) (next - section_begin), section->name); | |
7983 | } | |
01a8f077 | 7984 | } |
d11ae95e | 7985 | |
01a8f077 | 7986 | start = next; |
a2ff7a4b | 7987 | last_start = next; |
19e6b90e | 7988 | |
77145576 JK |
7989 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
7990 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
7991 | } |
7992 | putchar ('\n'); | |
01a8f077 JK |
7993 | |
7994 | free (range_entries); | |
7995 | ||
19e6b90e L |
7996 | return 1; |
7997 | } | |
7998 | ||
7999 | typedef struct Frame_Chunk | |
8000 | { | |
8001 | struct Frame_Chunk *next; | |
8002 | unsigned char *chunk_start; | |
a1165289 | 8003 | unsigned int ncols; |
19e6b90e L |
8004 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
8005 | short int *col_type; | |
8006 | int *col_offset; | |
8007 | char *augmentation; | |
8008 | unsigned int code_factor; | |
8009 | int data_factor; | |
bf5117e3 NC |
8010 | dwarf_vma pc_begin; |
8011 | dwarf_vma pc_range; | |
32ef3000 | 8012 | unsigned int cfa_reg; |
c8071705 | 8013 | dwarf_vma cfa_offset; |
a1165289 | 8014 | unsigned int ra; |
19e6b90e L |
8015 | unsigned char fde_encoding; |
8016 | unsigned char cfa_exp; | |
604282a7 JJ |
8017 | unsigned char ptr_size; |
8018 | unsigned char segment_size; | |
19e6b90e L |
8019 | } |
8020 | Frame_Chunk; | |
8021 | ||
1296bc99 AB |
8022 | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); |
8023 | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; | |
665ce1f6 L |
8024 | static const char *const *dwarf_regnames; |
8025 | static unsigned int dwarf_regnames_count; | |
8026 | ||
1296bc99 | 8027 | |
19e6b90e L |
8028 | /* A marker for a col_type that means this column was never referenced |
8029 | in the frame info. */ | |
8030 | #define DW_CFA_unreferenced (-1) | |
8031 | ||
a1165289 | 8032 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
8033 | -1 for invalid reg. */ |
8034 | ||
8035 | static int | |
8036 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 8037 | { |
a1165289 | 8038 | unsigned int prev = fc->ncols; |
19e6b90e | 8039 | |
665ce1f6 L |
8040 | if (reg < (unsigned int) fc->ncols) |
8041 | return 0; | |
8042 | ||
d9acf707 | 8043 | if (dwarf_regnames_count > 0 |
665ce1f6 L |
8044 | && reg > dwarf_regnames_count) |
8045 | return -1; | |
19e6b90e L |
8046 | |
8047 | fc->ncols = reg + 1; | |
a1165289 NC |
8048 | /* PR 17512: file: 10450-2643-0.004. |
8049 | If reg == -1 then this can happen... */ | |
8050 | if (fc->ncols == 0) | |
8051 | return -1; | |
8052 | ||
06614111 | 8053 | /* PR 17512: file: 2844a11d. */ |
d9acf707 | 8054 | if (fc->ncols > 1024 && dwarf_regnames_count == 0) |
06614111 NC |
8055 | { |
8056 | error (_("Unfeasibly large register number: %u\n"), reg); | |
8057 | fc->ncols = 0; | |
8058 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
8059 | we ever encounter a valid binary that exceeds it. */ | |
8060 | return -1; | |
8061 | } | |
8062 | ||
3f5e193b | 8063 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 8064 | sizeof (short int)); |
3f5e193b | 8065 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 8066 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
8067 | if (fc->col_type == NULL || fc->col_offset == NULL) |
8068 | { | |
8069 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
8070 | fc->ncols); | |
8071 | fc->ncols = 0; | |
8072 | return -1; | |
8073 | } | |
19e6b90e L |
8074 | |
8075 | while (prev < fc->ncols) | |
8076 | { | |
8077 | fc->col_type[prev] = DW_CFA_unreferenced; | |
8078 | fc->col_offset[prev] = 0; | |
8079 | prev++; | |
8080 | } | |
665ce1f6 | 8081 | return 1; |
19e6b90e L |
8082 | } |
8083 | ||
2dc4cec1 L |
8084 | static const char *const dwarf_regnames_i386[] = |
8085 | { | |
43234a1e L |
8086 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
8087 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
8088 | "eip", "eflags", NULL, /* 8 - 10 */ | |
8089 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
8090 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
8091 | NULL, NULL, /* 19 - 20 */ | |
8092 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
8093 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
8094 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
8095 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
8096 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
8097 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
8098 | "tr", "ldtr", /* 48 - 49 */ | |
8099 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
8100 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
8101 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
8102 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
8103 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
8104 | NULL, NULL, NULL, /* 90 - 92 */ | |
8105 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
8106 | }; |
8107 | ||
3d875af5 L |
8108 | static const char *const dwarf_regnames_iamcu[] = |
8109 | { | |
8110 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
8111 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
8112 | "eip", "eflags", NULL, /* 8 - 10 */ | |
8113 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
8114 | NULL, NULL, /* 19 - 20 */ | |
8115 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
8116 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
8117 | NULL, NULL, NULL, /* 37 - 39 */ | |
8118 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
8119 | "tr", "ldtr", /* 48 - 49 */ | |
8120 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
8121 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
8122 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
8123 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
8124 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
8125 | NULL, NULL, NULL, /* 90 - 92 */ | |
8126 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
8127 | }; | |
8128 | ||
99f6fdd9 | 8129 | static void |
b129eb0e RH |
8130 | init_dwarf_regnames_i386 (void) |
8131 | { | |
8132 | dwarf_regnames = dwarf_regnames_i386; | |
8133 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
1296bc99 | 8134 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
8135 | } |
8136 | ||
99f6fdd9 | 8137 | static void |
3d875af5 L |
8138 | init_dwarf_regnames_iamcu (void) |
8139 | { | |
8140 | dwarf_regnames = dwarf_regnames_iamcu; | |
8141 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
1296bc99 | 8142 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
3d875af5 L |
8143 | } |
8144 | ||
2dc4cec1 L |
8145 | static const char *const dwarf_regnames_x86_64[] = |
8146 | { | |
8147 | "rax", "rdx", "rcx", "rbx", | |
8148 | "rsi", "rdi", "rbp", "rsp", | |
8149 | "r8", "r9", "r10", "r11", | |
8150 | "r12", "r13", "r14", "r15", | |
8151 | "rip", | |
8152 | "xmm0", "xmm1", "xmm2", "xmm3", | |
8153 | "xmm4", "xmm5", "xmm6", "xmm7", | |
8154 | "xmm8", "xmm9", "xmm10", "xmm11", | |
8155 | "xmm12", "xmm13", "xmm14", "xmm15", | |
8156 | "st0", "st1", "st2", "st3", | |
8157 | "st4", "st5", "st6", "st7", | |
8158 | "mm0", "mm1", "mm2", "mm3", | |
8159 | "mm4", "mm5", "mm6", "mm7", | |
8160 | "rflags", | |
8161 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
8162 | "fs.base", "gs.base", NULL, NULL, | |
8163 | "tr", "ldtr", | |
43234a1e L |
8164 | "mxcsr", "fcw", "fsw", |
8165 | "xmm16", "xmm17", "xmm18", "xmm19", | |
8166 | "xmm20", "xmm21", "xmm22", "xmm23", | |
8167 | "xmm24", "xmm25", "xmm26", "xmm27", | |
8168 | "xmm28", "xmm29", "xmm30", "xmm31", | |
8169 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
8170 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
8171 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
8172 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
8173 | NULL, NULL, NULL, /* 115 - 117 */ | |
8174 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
8175 | }; |
8176 | ||
99f6fdd9 | 8177 | static void |
b129eb0e RH |
8178 | init_dwarf_regnames_x86_64 (void) |
8179 | { | |
8180 | dwarf_regnames = dwarf_regnames_x86_64; | |
8181 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
1296bc99 | 8182 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
8183 | } |
8184 | ||
4ee22035 RH |
8185 | static const char *const dwarf_regnames_aarch64[] = |
8186 | { | |
b4eb7656 AM |
8187 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
8188 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
8189 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
8190 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
8191 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
fab7c86e TC |
8192 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
8193 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", | |
8194 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", | |
b4eb7656 AM |
8195 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
8196 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
8197 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
8198 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
fab7c86e TC |
8199 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
8200 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", | |
8201 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", | |
8202 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", | |
4ee22035 RH |
8203 | }; |
8204 | ||
99f6fdd9 | 8205 | static void |
4ee22035 RH |
8206 | init_dwarf_regnames_aarch64 (void) |
8207 | { | |
8208 | dwarf_regnames = dwarf_regnames_aarch64; | |
8209 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
1296bc99 | 8210 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
4ee22035 RH |
8211 | } |
8212 | ||
d6bb17b0 AA |
8213 | static const char *const dwarf_regnames_s390[] = |
8214 | { | |
8215 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
8216 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
8217 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
8218 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
8219 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
8220 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
8221 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
8222 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
8223 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
8224 | "pswm", "pswa", | |
8225 | NULL, NULL, | |
8226 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
8227 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
8228 | }; | |
8229 | ||
99f6fdd9 | 8230 | static void |
d6bb17b0 AA |
8231 | init_dwarf_regnames_s390 (void) |
8232 | { | |
8233 | dwarf_regnames = dwarf_regnames_s390; | |
8234 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
1296bc99 | 8235 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
d6bb17b0 AA |
8236 | } |
8237 | ||
5bb0830d AB |
8238 | static const char *const dwarf_regnames_riscv[] = |
8239 | { | |
8240 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
8241 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
8242 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
8243 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
8244 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
8245 | "fs0", "fs1", /* 40 - 41 */ | |
8246 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
8247 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
8248 | "fs10", "fs11", /* 58 - 59 */ | |
8249 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
8250 | }; | |
8251 | ||
4762fe62 AB |
8252 | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles |
8253 | the large number of CSRs. */ | |
8254 | ||
8255 | static const char * | |
8256 | regname_internal_riscv (unsigned int regno) | |
8257 | { | |
8258 | const char *name = NULL; | |
8259 | ||
8260 | /* Lookup in the table first, this covers GPR and FPR. */ | |
8261 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) | |
8262 | name = dwarf_regnames_riscv [regno]; | |
8263 | else if (regno >= 4096 && regno <= 8191) | |
8264 | { | |
8265 | /* This might be a CSR, these live in a sparse number space from 4096 | |
8266 | to 8191 These numbers are defined in the RISC-V ELF ABI | |
8267 | document. */ | |
8268 | switch (regno) | |
8269 | { | |
8f595e9b NC |
8270 | #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \ |
8271 | case VALUE + 4096: name = #NAME; break; | |
4762fe62 AB |
8272 | #include "opcode/riscv-opc.h" |
8273 | #undef DECLARE_CSR | |
8274 | ||
8275 | default: | |
8276 | { | |
8277 | static char csr_name[10]; | |
8278 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); | |
8279 | name = csr_name; | |
8280 | } | |
8281 | break; | |
8282 | } | |
8283 | } | |
8284 | ||
8285 | return name; | |
8286 | } | |
8287 | ||
99f6fdd9 | 8288 | static void |
5bb0830d AB |
8289 | init_dwarf_regnames_riscv (void) |
8290 | { | |
4762fe62 AB |
8291 | dwarf_regnames = NULL; |
8292 | dwarf_regnames_count = 8192; | |
8293 | dwarf_regnames_lookup_func = regname_internal_riscv; | |
5bb0830d AB |
8294 | } |
8295 | ||
2dc4cec1 | 8296 | void |
955ff7fc | 8297 | init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) |
2dc4cec1 | 8298 | { |
1296bc99 AB |
8299 | dwarf_regnames_lookup_func = NULL; |
8300 | ||
2dc4cec1 L |
8301 | switch (e_machine) |
8302 | { | |
8303 | case EM_386: | |
b129eb0e | 8304 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
8305 | break; |
8306 | ||
3d875af5 L |
8307 | case EM_IAMCU: |
8308 | init_dwarf_regnames_iamcu (); | |
8309 | break; | |
8310 | ||
2dc4cec1 | 8311 | case EM_X86_64: |
7f502d6c | 8312 | case EM_L1OM: |
7a9068fe | 8313 | case EM_K1OM: |
b129eb0e | 8314 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
8315 | break; |
8316 | ||
4ee22035 RH |
8317 | case EM_AARCH64: |
8318 | init_dwarf_regnames_aarch64 (); | |
8319 | break; | |
8320 | ||
d6bb17b0 AA |
8321 | case EM_S390: |
8322 | init_dwarf_regnames_s390 (); | |
8323 | break; | |
8324 | ||
5bb0830d AB |
8325 | case EM_RISCV: |
8326 | init_dwarf_regnames_riscv (); | |
8327 | break; | |
8328 | ||
2dc4cec1 L |
8329 | default: |
8330 | break; | |
8331 | } | |
8332 | } | |
8333 | ||
229a22cf AB |
8334 | /* Initialize the DWARF register name lookup state based on the |
8335 | architecture and specific machine type of a BFD. */ | |
8336 | ||
8337 | void | |
8338 | init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, | |
8339 | unsigned long mach) | |
8340 | { | |
1296bc99 AB |
8341 | dwarf_regnames_lookup_func = NULL; |
8342 | ||
229a22cf AB |
8343 | switch (arch) |
8344 | { | |
8345 | case bfd_arch_i386: | |
8346 | switch (mach) | |
8347 | { | |
8348 | case bfd_mach_x86_64: | |
8349 | case bfd_mach_x86_64_intel_syntax: | |
229a22cf AB |
8350 | case bfd_mach_x64_32: |
8351 | case bfd_mach_x64_32_intel_syntax: | |
229a22cf AB |
8352 | init_dwarf_regnames_x86_64 (); |
8353 | break; | |
8354 | ||
8355 | default: | |
8356 | init_dwarf_regnames_i386 (); | |
8357 | break; | |
8358 | } | |
8359 | break; | |
8360 | ||
8361 | case bfd_arch_iamcu: | |
8362 | init_dwarf_regnames_iamcu (); | |
8363 | break; | |
8364 | ||
8365 | case bfd_arch_aarch64: | |
8366 | init_dwarf_regnames_aarch64(); | |
8367 | break; | |
8368 | ||
8369 | case bfd_arch_s390: | |
8370 | init_dwarf_regnames_s390 (); | |
8371 | break; | |
8372 | ||
8373 | case bfd_arch_riscv: | |
8374 | init_dwarf_regnames_riscv (); | |
8375 | break; | |
8376 | ||
8377 | default: | |
8378 | break; | |
8379 | } | |
8380 | } | |
8381 | ||
2dc4cec1 | 8382 | static const char * |
1296bc99 | 8383 | regname_internal_by_table_only (unsigned int regno) |
2dc4cec1 | 8384 | { |
1296bc99 | 8385 | if (dwarf_regnames != NULL |
2dc4cec1 L |
8386 | && regno < dwarf_regnames_count |
8387 | && dwarf_regnames [regno] != NULL) | |
1296bc99 AB |
8388 | return dwarf_regnames [regno]; |
8389 | ||
8390 | return NULL; | |
8391 | } | |
8392 | ||
8393 | static const char * | |
8394 | regname (unsigned int regno, int name_only_p) | |
8395 | { | |
8396 | static char reg[64]; | |
8397 | ||
8398 | const char *name = NULL; | |
8399 | ||
8400 | if (dwarf_regnames_lookup_func != NULL) | |
8401 | name = dwarf_regnames_lookup_func (regno); | |
8402 | ||
8403 | if (name != NULL) | |
2dc4cec1 | 8404 | { |
1296bc99 AB |
8405 | if (name_only_p) |
8406 | return name; | |
8407 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); | |
2dc4cec1 L |
8408 | } |
8409 | else | |
8410 | snprintf (reg, sizeof (reg), "r%d", regno); | |
8411 | return reg; | |
8412 | } | |
8413 | ||
19e6b90e | 8414 | static void |
a1165289 | 8415 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 8416 | { |
a1165289 | 8417 | unsigned int r; |
19e6b90e L |
8418 | char tmp[100]; |
8419 | ||
d8024a91 | 8420 | if (*max_regs != fc->ncols) |
19e6b90e L |
8421 | *max_regs = fc->ncols; |
8422 | ||
8423 | if (*need_col_headers) | |
8424 | { | |
8425 | *need_col_headers = 0; | |
8426 | ||
288f0ba2 | 8427 | printf ("%-*s CFA ", eh_addr_size * 2, " LOC"); |
19e6b90e L |
8428 | |
8429 | for (r = 0; r < *max_regs; r++) | |
8430 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
8431 | { | |
8432 | if (r == fc->ra) | |
50751e18 | 8433 | printf ("ra "); |
19e6b90e | 8434 | else |
2dc4cec1 | 8435 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
8436 | } |
8437 | ||
8438 | printf ("\n"); | |
8439 | } | |
8440 | ||
bf5117e3 | 8441 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
8442 | if (fc->cfa_exp) |
8443 | strcpy (tmp, "exp"); | |
8444 | else | |
c8071705 | 8445 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
8446 | printf ("%-8s ", tmp); |
8447 | ||
8448 | for (r = 0; r < fc->ncols; r++) | |
8449 | { | |
8450 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
8451 | { | |
8452 | switch (fc->col_type[r]) | |
8453 | { | |
8454 | case DW_CFA_undefined: | |
8455 | strcpy (tmp, "u"); | |
8456 | break; | |
8457 | case DW_CFA_same_value: | |
8458 | strcpy (tmp, "s"); | |
8459 | break; | |
8460 | case DW_CFA_offset: | |
8461 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
8462 | break; | |
12eae2d3 JJ |
8463 | case DW_CFA_val_offset: |
8464 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
8465 | break; | |
19e6b90e | 8466 | case DW_CFA_register: |
2dc4cec1 | 8467 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
8468 | break; |
8469 | case DW_CFA_expression: | |
8470 | strcpy (tmp, "exp"); | |
8471 | break; | |
12eae2d3 JJ |
8472 | case DW_CFA_val_expression: |
8473 | strcpy (tmp, "vexp"); | |
8474 | break; | |
19e6b90e L |
8475 | default: |
8476 | strcpy (tmp, "n/a"); | |
8477 | break; | |
8478 | } | |
2dc4cec1 | 8479 | printf ("%-5s ", tmp); |
19e6b90e L |
8480 | } |
8481 | } | |
8482 | printf ("\n"); | |
8483 | } | |
8484 | ||
49727e46 | 8485 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 8486 | |
49727e46 AM |
8487 | static unsigned char * |
8488 | read_cie (unsigned char *start, unsigned char *end, | |
8489 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 8490 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
8491 | { |
8492 | int version; | |
8493 | Frame_Chunk *fc; | |
49727e46 | 8494 | unsigned char *augmentation_data = NULL; |
bf59c5d5 | 8495 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 8496 | |
041830e0 | 8497 | * p_cie = NULL; |
f41e4712 NC |
8498 | /* PR 17512: file: 001-228113-0.004. */ |
8499 | if (start >= end) | |
8500 | return end; | |
8501 | ||
49727e46 AM |
8502 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
8503 | memset (fc, 0, sizeof (Frame_Chunk)); | |
8504 | ||
8505 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
8506 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
8507 | ||
8508 | version = *start++; | |
8509 | ||
8510 | fc->augmentation = (char *) start; | |
f41e4712 NC |
8511 | /* PR 17512: file: 001-228113-0.004. |
8512 | Skip past augmentation name, but avoid running off the end of the data. */ | |
8513 | while (start < end) | |
8514 | if (* start ++ == '\0') | |
8515 | break; | |
8516 | if (start == end) | |
8517 | { | |
8518 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 8519 | goto fail; |
f41e4712 | 8520 | } |
49727e46 AM |
8521 | |
8522 | if (strcmp (fc->augmentation, "eh") == 0) | |
8523 | start += eh_addr_size; | |
8524 | ||
8525 | if (version >= 4) | |
8526 | { | |
8527 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
8528 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
8529 | { | |
8530 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 8531 | goto fail; |
77ef8654 NC |
8532 | } |
8533 | ||
49727e46 | 8534 | GET (fc->segment_size, 1); |
77ef8654 NC |
8535 | /* PR 17512: file: e99d2804. */ |
8536 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
8537 | { | |
8538 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 8539 | goto fail; |
77ef8654 NC |
8540 | } |
8541 | ||
49727e46 AM |
8542 | eh_addr_size = fc->ptr_size; |
8543 | } | |
8544 | else | |
8545 | { | |
8546 | fc->ptr_size = eh_addr_size; | |
8547 | fc->segment_size = 0; | |
8548 | } | |
442a6ce8 | 8549 | |
cd30bcef AM |
8550 | READ_ULEB (fc->code_factor, start, end); |
8551 | READ_SLEB (fc->data_factor, start, end); | |
442a6ce8 | 8552 | |
49727e46 AM |
8553 | if (version == 1) |
8554 | { | |
8555 | GET (fc->ra, 1); | |
8556 | } | |
8557 | else | |
8558 | { | |
cd30bcef | 8559 | READ_ULEB (fc->ra, start, end); |
49727e46 AM |
8560 | } |
8561 | ||
8562 | if (fc->augmentation[0] == 'z') | |
8563 | { | |
cd30bcef | 8564 | READ_ULEB (augmentation_data_len, start, end); |
49727e46 | 8565 | augmentation_data = start; |
a1165289 | 8566 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 8567 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 8568 | { |
bf59c5d5 NC |
8569 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
8570 | dwarf_vmatoa ("x", augmentation_data_len), | |
8571 | (unsigned long) (end - start)); | |
442a6ce8 | 8572 | goto fail; |
a1165289 | 8573 | } |
9c0f3d3f | 8574 | start += augmentation_data_len; |
49727e46 AM |
8575 | } |
8576 | ||
8577 | if (augmentation_data_len) | |
8578 | { | |
058037d3 NC |
8579 | unsigned char *p; |
8580 | unsigned char *q; | |
8581 | unsigned char *qend; | |
b4eb7656 | 8582 | |
49727e46 AM |
8583 | p = (unsigned char *) fc->augmentation + 1; |
8584 | q = augmentation_data; | |
058037d3 NC |
8585 | qend = q + augmentation_data_len; |
8586 | ||
9c0f3d3f | 8587 | while (p < end && q < qend) |
49727e46 AM |
8588 | { |
8589 | if (*p == 'L') | |
8590 | q++; | |
8591 | else if (*p == 'P') | |
8592 | q += 1 + size_of_encoded_value (*q); | |
8593 | else if (*p == 'R') | |
8594 | fc->fde_encoding = *q++; | |
8595 | else if (*p == 'S') | |
8596 | ; | |
09038062 ST |
8597 | else if (*p == 'B') |
8598 | ; | |
49727e46 AM |
8599 | else |
8600 | break; | |
8601 | p++; | |
8602 | } | |
c361b9ac NC |
8603 | /* Note - it is OK if this loop terminates with q < qend. |
8604 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
8605 | } |
8606 | ||
8607 | *p_cie = fc; | |
8608 | if (p_version) | |
8609 | *p_version = version; | |
8610 | if (p_aug_len) | |
8611 | { | |
8612 | *p_aug_len = augmentation_data_len; | |
8613 | *p_aug = augmentation_data; | |
8614 | } | |
8615 | return start; | |
442a6ce8 NC |
8616 | |
8617 | fail: | |
8618 | free (fc->col_offset); | |
8619 | free (fc->col_type); | |
8620 | free (fc); | |
8621 | return end; | |
49727e46 AM |
8622 | } |
8623 | ||
d85bf2ba NC |
8624 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
8625 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
8626 | PRINTED contains the number of characters already written to the current | |
8627 | output line. */ | |
bf59c5d5 NC |
8628 | |
8629 | static void | |
d85bf2ba NC |
8630 | display_data (bfd_size_type printed, |
8631 | const unsigned char * data, | |
8632 | const bfd_size_type len) | |
bf59c5d5 | 8633 | { |
d85bf2ba NC |
8634 | if (do_wide || len < ((80 - printed) / 3)) |
8635 | for (printed = 0; printed < len; ++printed) | |
8636 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
8637 | else |
8638 | { | |
d85bf2ba | 8639 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 8640 | { |
d85bf2ba | 8641 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 8642 | putchar ('\n'); |
d85bf2ba | 8643 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
8644 | } |
8645 | } | |
d85bf2ba NC |
8646 | } |
8647 | ||
8648 | /* Prints out the contents on the augmentation data array. | |
8649 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
8650 | ||
8651 | static void | |
8652 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
8653 | { | |
8654 | bfd_size_type i; | |
8655 | ||
8656 | i = printf (_(" Augmentation data: ")); | |
8657 | display_data (i, data, len); | |
bf59c5d5 NC |
8658 | } |
8659 | ||
19e6b90e L |
8660 | static int |
8661 | display_debug_frames (struct dwarf_section *section, | |
8662 | void *file ATTRIBUTE_UNUSED) | |
8663 | { | |
8664 | unsigned char *start = section->start; | |
8665 | unsigned char *end = start + section->size; | |
8666 | unsigned char *section_start = start; | |
3391569f NC |
8667 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
8668 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 8669 | Frame_Chunk *rs; |
3391569f | 8670 | bfd_boolean is_eh = strcmp (section->name, ".eh_frame") == 0; |
a1165289 | 8671 | unsigned int max_regs = 0; |
665ce1f6 | 8672 | const char *bad_reg = _("bad register: "); |
77ef8654 | 8673 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 8674 | |
dda8d76d | 8675 | introduce (section, FALSE); |
19e6b90e L |
8676 | |
8677 | while (start < end) | |
8678 | { | |
8679 | unsigned char *saved_start; | |
8680 | unsigned char *block_end; | |
bf5117e3 NC |
8681 | dwarf_vma length; |
8682 | dwarf_vma cie_id; | |
19e6b90e L |
8683 | Frame_Chunk *fc; |
8684 | Frame_Chunk *cie; | |
8685 | int need_col_headers = 1; | |
8686 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 8687 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
8688 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
8689 | unsigned int offset_size; | |
8690 | unsigned int initial_length_size; | |
5b6312fd | 8691 | bfd_boolean all_nops; |
a788aedd | 8692 | static Frame_Chunk fde_fc; |
19e6b90e L |
8693 | |
8694 | saved_start = start; | |
19e6b90e | 8695 | |
0c588247 | 8696 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 8697 | |
19e6b90e L |
8698 | if (length == 0) |
8699 | { | |
8700 | printf ("\n%08lx ZERO terminator\n\n", | |
8701 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
8702 | /* Skip any zero terminators that directly follow. |
8703 | A corrupt section size could have loaded a whole | |
8704 | slew of zero filled memory bytes. eg | |
8705 | PR 17512: file: 070-19381-0.004. */ | |
8706 | while (start < end && * start == 0) | |
8707 | ++ start; | |
b758e50f | 8708 | continue; |
19e6b90e L |
8709 | } |
8710 | ||
8711 | if (length == 0xffffffff) | |
8712 | { | |
0c588247 | 8713 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
8714 | offset_size = 8; |
8715 | initial_length_size = 12; | |
8716 | } | |
8717 | else | |
8718 | { | |
8719 | offset_size = 4; | |
8720 | initial_length_size = 4; | |
8721 | } | |
8722 | ||
8723 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 8724 | if (block_end > end || block_end < start) |
53b8873b | 8725 | { |
bf5117e3 NC |
8726 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
8727 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
8728 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
8729 | block_end = end; |
8730 | } | |
0c588247 NC |
8731 | |
8732 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 8733 | |
846a11e4 NC |
8734 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
8735 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
8736 | { |
8737 | int version; | |
a1165289 | 8738 | unsigned int mreg; |
19e6b90e | 8739 | |
49727e46 AM |
8740 | start = read_cie (start, end, &cie, &version, |
8741 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
8742 | /* PR 17512: file: 027-135133-0.005. */ |
8743 | if (cie == NULL) | |
8744 | break; | |
a1165289 | 8745 | |
49727e46 | 8746 | fc = cie; |
19e6b90e L |
8747 | fc->next = chunks; |
8748 | chunks = fc; | |
8749 | fc->chunk_start = saved_start; | |
a1165289 | 8750 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8751 | if (mreg < fc->ra) |
8752 | mreg = fc->ra; | |
06614111 NC |
8753 | if (frame_need_space (fc, mreg) < 0) |
8754 | break; | |
49727e46 AM |
8755 | if (fc->fde_encoding) |
8756 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 8757 | |
bf5117e3 NC |
8758 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
8759 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 8760 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 8761 | |
19e6b90e | 8762 | if (do_debug_frames_interp) |
bf5117e3 NC |
8763 | { |
8764 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
8765 | fc->code_factor, fc->data_factor, fc->ra); | |
8766 | } | |
19e6b90e L |
8767 | else |
8768 | { | |
bf5117e3 | 8769 | printf ("CIE\n"); |
19e6b90e L |
8770 | printf (" Version: %d\n", version); |
8771 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
8772 | if (version >= 4) |
8773 | { | |
8774 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
8775 | printf (" Segment Size: %u\n", fc->segment_size); | |
8776 | } | |
19e6b90e L |
8777 | printf (" Code alignment factor: %u\n", fc->code_factor); |
8778 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
8779 | printf (" Return address column: %d\n", fc->ra); | |
8780 | ||
8781 | if (augmentation_data_len) | |
bf59c5d5 | 8782 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 8783 | |
19e6b90e L |
8784 | putchar ('\n'); |
8785 | } | |
19e6b90e L |
8786 | } |
8787 | else | |
8788 | { | |
8789 | unsigned char *look_for; | |
604282a7 | 8790 | unsigned long segment_selector; |
19e6b90e | 8791 | |
49727e46 AM |
8792 | if (is_eh) |
8793 | { | |
8794 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
8795 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
8796 | } | |
8797 | else | |
8798 | look_for = section_start + cie_id; | |
19e6b90e | 8799 | |
49727e46 AM |
8800 | if (look_for <= saved_start) |
8801 | { | |
8802 | for (cie = chunks; cie ; cie = cie->next) | |
8803 | if (cie->chunk_start == look_for) | |
8804 | break; | |
8805 | } | |
8806 | else | |
8807 | { | |
8808 | for (cie = forward_refs; cie ; cie = cie->next) | |
8809 | if (cie->chunk_start == look_for) | |
8810 | break; | |
8811 | if (!cie) | |
8812 | { | |
8813 | unsigned int off_size; | |
8814 | unsigned char *cie_scan; | |
19e6b90e | 8815 | |
49727e46 AM |
8816 | cie_scan = look_for; |
8817 | off_size = 4; | |
8818 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
8819 | if (length == 0xffffffff) | |
8820 | { | |
8821 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
8822 | off_size = 8; | |
8823 | } | |
8824 | if (length != 0) | |
8825 | { | |
8826 | dwarf_vma c_id; | |
8827 | ||
8828 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
8829 | if (is_eh | |
8830 | ? c_id == 0 | |
8831 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
8832 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
8833 | { | |
8834 | int version; | |
a1165289 | 8835 | unsigned int mreg; |
49727e46 AM |
8836 | |
8837 | read_cie (cie_scan, end, &cie, &version, | |
8838 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
8839 | /* PR 17512: file: 3450-2098-0.004. */ |
8840 | if (cie == NULL) | |
8841 | { | |
8842 | warn (_("Failed to read CIE information\n")); | |
8843 | break; | |
8844 | } | |
49727e46 AM |
8845 | cie->next = forward_refs; |
8846 | forward_refs = cie; | |
8847 | cie->chunk_start = look_for; | |
a1165289 | 8848 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8849 | if (mreg < cie->ra) |
8850 | mreg = cie->ra; | |
06614111 NC |
8851 | if (frame_need_space (cie, mreg) < 0) |
8852 | { | |
8853 | warn (_("Invalid max register\n")); | |
8854 | break; | |
8855 | } | |
49727e46 AM |
8856 | if (cie->fde_encoding) |
8857 | encoded_ptr_size | |
8858 | = size_of_encoded_value (cie->fde_encoding); | |
8859 | } | |
8860 | } | |
8861 | } | |
8862 | } | |
8863 | ||
8864 | fc = &fde_fc; | |
8865 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
8866 | |
8867 | if (!cie) | |
8868 | { | |
bf5117e3 NC |
8869 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
8870 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
8871 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 8872 | fc->ncols = 0; |
3f5e193b NC |
8873 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
8874 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
8875 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
8876 | { | |
8877 | warn (_("Invalid max register\n")); | |
8878 | break; | |
8879 | } | |
19e6b90e L |
8880 | cie = fc; |
8881 | fc->augmentation = ""; | |
8882 | fc->fde_encoding = 0; | |
604282a7 JJ |
8883 | fc->ptr_size = eh_addr_size; |
8884 | fc->segment_size = 0; | |
19e6b90e L |
8885 | } |
8886 | else | |
8887 | { | |
8888 | fc->ncols = cie->ncols; | |
3f5e193b NC |
8889 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
8890 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
8891 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
8892 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
8893 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
8894 | fc->ptr_size = cie->ptr_size; |
8895 | eh_addr_size = cie->ptr_size; | |
8896 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
8897 | fc->code_factor = cie->code_factor; |
8898 | fc->data_factor = cie->data_factor; | |
8899 | fc->cfa_reg = cie->cfa_reg; | |
8900 | fc->cfa_offset = cie->cfa_offset; | |
8901 | fc->ra = cie->ra; | |
06614111 NC |
8902 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
8903 | { | |
8904 | warn (_("Invalid max register\n")); | |
8905 | break; | |
8906 | } | |
19e6b90e L |
8907 | fc->fde_encoding = cie->fde_encoding; |
8908 | } | |
8909 | ||
8910 | if (fc->fde_encoding) | |
8911 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
8912 | ||
604282a7 JJ |
8913 | segment_selector = 0; |
8914 | if (fc->segment_size) | |
c8071705 NC |
8915 | { |
8916 | if (fc->segment_size > sizeof (segment_selector)) | |
8917 | { | |
8918 | /* PR 17512: file: 9e196b3e. */ | |
8919 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
8920 | fc->segment_size = 4; | |
8921 | } | |
8922 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
8923 | } | |
041830e0 NC |
8924 | |
8925 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 8926 | |
0c588247 NC |
8927 | /* FIXME: It appears that sometimes the final pc_range value is |
8928 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
8929 | run of the "objcopy on compressed debug sections" test for an | |
8930 | example of this. */ | |
8931 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 8932 | |
19e6b90e L |
8933 | if (cie->augmentation[0] == 'z') |
8934 | { | |
cd30bcef | 8935 | READ_ULEB (augmentation_data_len, start, end); |
19e6b90e | 8936 | augmentation_data = start; |
bf59c5d5 | 8937 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
d292364e | 8938 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
0a9d414a | 8939 | { |
d292364e AM |
8940 | warn (_("Augmentation data too long: 0x%s, " |
8941 | "expected at most %#lx\n"), | |
8942 | dwarf_vmatoa ("x", augmentation_data_len), | |
8943 | (unsigned long) (end - start)); | |
0a9d414a NC |
8944 | start = end; |
8945 | augmentation_data = NULL; | |
8946 | augmentation_data_len = 0; | |
8947 | } | |
d292364e | 8948 | start += augmentation_data_len; |
19e6b90e L |
8949 | } |
8950 | ||
bf5117e3 NC |
8951 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
8952 | (unsigned long)(saved_start - section_start), | |
8953 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 8954 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 8955 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 8956 | |
604282a7 JJ |
8957 | if (fc->segment_size) |
8958 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
8959 | |
8960 | printf ("%s..%s\n", | |
8961 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
8962 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
8963 | ||
19e6b90e L |
8964 | if (! do_debug_frames_interp && augmentation_data_len) |
8965 | { | |
bf59c5d5 | 8966 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
8967 | putchar ('\n'); |
8968 | } | |
8969 | } | |
8970 | ||
8971 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
8972 | we're about to interpret instructions for the chunk. */ | |
8973 | /* ??? At present we need to do this always, since this sizes the | |
8974 | fc->col_type and fc->col_offset arrays, which we write into always. | |
8975 | We should probably split the interpreted and non-interpreted bits | |
8976 | into two different routines, since there's so much that doesn't | |
8977 | really overlap between them. */ | |
8978 | if (1 || do_debug_frames_interp) | |
8979 | { | |
8980 | /* Start by making a pass over the chunk, allocating storage | |
8981 | and taking note of what registers are used. */ | |
8982 | unsigned char *tmp = start; | |
8983 | ||
8984 | while (start < block_end) | |
8985 | { | |
041830e0 NC |
8986 | unsigned int reg, op, opa; |
8987 | unsigned long temp; | |
5929c344 | 8988 | unsigned char * new_start; |
19e6b90e L |
8989 | |
8990 | op = *start++; | |
8991 | opa = op & 0x3f; | |
8992 | if (op & 0xc0) | |
8993 | op &= 0xc0; | |
8994 | ||
8995 | /* Warning: if you add any more cases to this switch, be | |
8996 | sure to add them to the corresponding switch below. */ | |
8997 | switch (op) | |
8998 | { | |
8999 | case DW_CFA_advance_loc: | |
9000 | break; | |
9001 | case DW_CFA_offset: | |
cd30bcef | 9002 | SKIP_ULEB (start, end); |
665ce1f6 L |
9003 | if (frame_need_space (fc, opa) >= 0) |
9004 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
9005 | break; |
9006 | case DW_CFA_restore: | |
665ce1f6 L |
9007 | if (frame_need_space (fc, opa) >= 0) |
9008 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
9009 | break; |
9010 | case DW_CFA_set_loc: | |
9011 | start += encoded_ptr_size; | |
9012 | break; | |
9013 | case DW_CFA_advance_loc1: | |
9014 | start += 1; | |
9015 | break; | |
9016 | case DW_CFA_advance_loc2: | |
9017 | start += 2; | |
9018 | break; | |
9019 | case DW_CFA_advance_loc4: | |
9020 | start += 4; | |
9021 | break; | |
9022 | case DW_CFA_offset_extended: | |
12eae2d3 | 9023 | case DW_CFA_val_offset: |
cd30bcef AM |
9024 | READ_ULEB (reg, start, end); |
9025 | SKIP_ULEB (start, end); | |
665ce1f6 L |
9026 | if (frame_need_space (fc, reg) >= 0) |
9027 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9028 | break; |
9029 | case DW_CFA_restore_extended: | |
cd30bcef | 9030 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9031 | if (frame_need_space (fc, reg) >= 0) |
9032 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9033 | break; |
9034 | case DW_CFA_undefined: | |
cd30bcef | 9035 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9036 | if (frame_need_space (fc, reg) >= 0) |
9037 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9038 | break; |
9039 | case DW_CFA_same_value: | |
cd30bcef | 9040 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9041 | if (frame_need_space (fc, reg) >= 0) |
9042 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9043 | break; |
9044 | case DW_CFA_register: | |
cd30bcef AM |
9045 | READ_ULEB (reg, start, end); |
9046 | SKIP_ULEB (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_def_cfa: | |
cd30bcef AM |
9051 | SKIP_ULEB (start, end); |
9052 | SKIP_ULEB (start, end); | |
19e6b90e L |
9053 | break; |
9054 | case DW_CFA_def_cfa_register: | |
cd30bcef | 9055 | SKIP_ULEB (start, end); |
19e6b90e L |
9056 | break; |
9057 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 9058 | SKIP_ULEB (start, end); |
19e6b90e L |
9059 | break; |
9060 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 9061 | READ_ULEB (temp, start, end); |
5929c344 NC |
9062 | new_start = start + temp; |
9063 | if (new_start < start) | |
041830e0 NC |
9064 | { |
9065 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
9066 | start = block_end; | |
9067 | } | |
9068 | else | |
5929c344 | 9069 | start = new_start; |
19e6b90e L |
9070 | break; |
9071 | case DW_CFA_expression: | |
12eae2d3 | 9072 | case DW_CFA_val_expression: |
cd30bcef AM |
9073 | READ_ULEB (reg, start, end); |
9074 | READ_ULEB (temp, start, end); | |
5929c344 NC |
9075 | new_start = start + temp; |
9076 | if (new_start < start) | |
041830e0 | 9077 | { |
b4eb7656 | 9078 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
9079 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
9080 | start = block_end; | |
9081 | } | |
9082 | else | |
5929c344 | 9083 | start = new_start; |
665ce1f6 L |
9084 | if (frame_need_space (fc, reg) >= 0) |
9085 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9086 | break; |
9087 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 9088 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
9089 | READ_ULEB (reg, start, end); |
9090 | SKIP_SLEB (start, end); | |
665ce1f6 L |
9091 | if (frame_need_space (fc, reg) >= 0) |
9092 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
9093 | break; |
9094 | case DW_CFA_def_cfa_sf: | |
cd30bcef AM |
9095 | SKIP_ULEB (start, end); |
9096 | SKIP_SLEB (start, end); | |
19e6b90e L |
9097 | break; |
9098 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 9099 | SKIP_SLEB (start, end); |
19e6b90e L |
9100 | break; |
9101 | case DW_CFA_MIPS_advance_loc8: | |
9102 | start += 8; | |
9103 | break; | |
9104 | case DW_CFA_GNU_args_size: | |
cd30bcef | 9105 | SKIP_ULEB (start, end); |
19e6b90e L |
9106 | break; |
9107 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
9108 | READ_ULEB (reg, start, end); |
9109 | SKIP_ULEB (start, end); | |
665ce1f6 L |
9110 | if (frame_need_space (fc, reg) >= 0) |
9111 | fc->col_type[reg] = DW_CFA_undefined; | |
9112 | break; | |
19e6b90e L |
9113 | default: |
9114 | break; | |
9115 | } | |
9116 | } | |
9117 | start = tmp; | |
9118 | } | |
9119 | ||
5b6312fd NC |
9120 | all_nops = TRUE; |
9121 | ||
19e6b90e L |
9122 | /* Now we know what registers are used, make a second pass over |
9123 | the chunk, this time actually printing out the info. */ | |
9124 | ||
9125 | while (start < block_end) | |
9126 | { | |
362beea4 | 9127 | unsigned char * tmp; |
19e6b90e | 9128 | unsigned op, opa; |
7f2c8a1d NC |
9129 | unsigned long ul, roffs; |
9130 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
9131 | are various functions, notably frame_space_needed() that assume that | |
9132 | reg is an unsigned int. */ | |
9133 | unsigned int reg; | |
9134 | dwarf_signed_vma l; | |
bf5117e3 | 9135 | dwarf_vma ofs; |
19e6b90e | 9136 | dwarf_vma vma; |
665ce1f6 | 9137 | const char *reg_prefix = ""; |
19e6b90e L |
9138 | |
9139 | op = *start++; | |
9140 | opa = op & 0x3f; | |
9141 | if (op & 0xc0) | |
9142 | op &= 0xc0; | |
9143 | ||
5b6312fd NC |
9144 | /* Make a note if something other than DW_CFA_nop happens. */ |
9145 | if (op != DW_CFA_nop) | |
9146 | all_nops = FALSE; | |
9147 | ||
19e6b90e L |
9148 | /* Warning: if you add any more cases to this switch, be |
9149 | sure to add them to the corresponding switch above. */ | |
9150 | switch (op) | |
9151 | { | |
9152 | case DW_CFA_advance_loc: | |
9153 | if (do_debug_frames_interp) | |
9154 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9155 | else | |
bf5117e3 | 9156 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 9157 | opa * fc->code_factor, |
b4eb7656 | 9158 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
9159 | fc->pc_begin + opa * fc->code_factor, |
9160 | fc->ptr_size)); | |
19e6b90e L |
9161 | fc->pc_begin += opa * fc->code_factor; |
9162 | break; | |
9163 | ||
9164 | case DW_CFA_offset: | |
cd30bcef | 9165 | READ_ULEB (roffs, start, end); |
665ce1f6 L |
9166 | if (opa >= (unsigned int) fc->ncols) |
9167 | reg_prefix = bad_reg; | |
9168 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9169 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
9170 | reg_prefix, regname (opa, 0), | |
9171 | roffs * fc->data_factor); | |
9172 | if (*reg_prefix == '\0') | |
9173 | { | |
9174 | fc->col_type[opa] = DW_CFA_offset; | |
9175 | fc->col_offset[opa] = roffs * fc->data_factor; | |
9176 | } | |
19e6b90e L |
9177 | break; |
9178 | ||
9179 | case DW_CFA_restore: | |
50751e18 | 9180 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
9181 | reg_prefix = bad_reg; |
9182 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9183 | printf (" DW_CFA_restore: %s%s\n", | |
9184 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
9185 | if (*reg_prefix != '\0') |
9186 | break; | |
9187 | ||
9188 | if (opa >= (unsigned int) cie->ncols | |
9189 | || (do_debug_frames_interp | |
9190 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
9191 | { | |
9192 | fc->col_type[opa] = DW_CFA_undefined; | |
9193 | fc->col_offset[opa] = 0; | |
9194 | } | |
9195 | else | |
665ce1f6 L |
9196 | { |
9197 | fc->col_type[opa] = cie->col_type[opa]; | |
9198 | fc->col_offset[opa] = cie->col_offset[opa]; | |
9199 | } | |
19e6b90e L |
9200 | break; |
9201 | ||
9202 | case DW_CFA_set_loc: | |
6937bb54 | 9203 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
9204 | if (do_debug_frames_interp) |
9205 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9206 | else | |
bf5117e3 NC |
9207 | printf (" DW_CFA_set_loc: %s\n", |
9208 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
9209 | fc->pc_begin = vma; |
9210 | break; | |
9211 | ||
9212 | case DW_CFA_advance_loc1: | |
0c588247 | 9213 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
9214 | if (do_debug_frames_interp) |
9215 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9216 | else | |
bf5117e3 NC |
9217 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
9218 | (unsigned long) (ofs * fc->code_factor), | |
9219 | dwarf_vmatoa_1 (NULL, | |
9220 | fc->pc_begin + ofs * fc->code_factor, | |
9221 | fc->ptr_size)); | |
19e6b90e L |
9222 | fc->pc_begin += ofs * fc->code_factor; |
9223 | break; | |
9224 | ||
9225 | case DW_CFA_advance_loc2: | |
6937bb54 | 9226 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
9227 | if (do_debug_frames_interp) |
9228 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9229 | else | |
bf5117e3 NC |
9230 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
9231 | (unsigned long) (ofs * fc->code_factor), | |
9232 | dwarf_vmatoa_1 (NULL, | |
9233 | fc->pc_begin + ofs * fc->code_factor, | |
9234 | fc->ptr_size)); | |
19e6b90e L |
9235 | fc->pc_begin += ofs * fc->code_factor; |
9236 | break; | |
9237 | ||
9238 | case DW_CFA_advance_loc4: | |
6937bb54 | 9239 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
9240 | if (do_debug_frames_interp) |
9241 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9242 | else | |
bf5117e3 NC |
9243 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
9244 | (unsigned long) (ofs * fc->code_factor), | |
9245 | dwarf_vmatoa_1 (NULL, | |
9246 | fc->pc_begin + ofs * fc->code_factor, | |
9247 | fc->ptr_size)); | |
19e6b90e L |
9248 | fc->pc_begin += ofs * fc->code_factor; |
9249 | break; | |
9250 | ||
9251 | case DW_CFA_offset_extended: | |
cd30bcef AM |
9252 | READ_ULEB (reg, start, end); |
9253 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
9254 | if (reg >= (unsigned int) fc->ncols) |
9255 | reg_prefix = bad_reg; | |
9256 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9257 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
9258 | reg_prefix, regname (reg, 0), | |
9259 | roffs * fc->data_factor); | |
9260 | if (*reg_prefix == '\0') | |
9261 | { | |
9262 | fc->col_type[reg] = DW_CFA_offset; | |
9263 | fc->col_offset[reg] = roffs * fc->data_factor; | |
9264 | } | |
19e6b90e L |
9265 | break; |
9266 | ||
12eae2d3 | 9267 | case DW_CFA_val_offset: |
cd30bcef AM |
9268 | READ_ULEB (reg, start, end); |
9269 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
9270 | if (reg >= (unsigned int) fc->ncols) |
9271 | reg_prefix = bad_reg; | |
9272 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 9273 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
9274 | reg_prefix, regname (reg, 0), |
9275 | roffs * fc->data_factor); | |
9276 | if (*reg_prefix == '\0') | |
9277 | { | |
9278 | fc->col_type[reg] = DW_CFA_val_offset; | |
9279 | fc->col_offset[reg] = roffs * fc->data_factor; | |
9280 | } | |
12eae2d3 JJ |
9281 | break; |
9282 | ||
19e6b90e | 9283 | case DW_CFA_restore_extended: |
cd30bcef | 9284 | READ_ULEB (reg, start, end); |
50751e18 | 9285 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
9286 | reg_prefix = bad_reg; |
9287 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9288 | printf (" DW_CFA_restore_extended: %s%s\n", | |
9289 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
9290 | if (*reg_prefix != '\0') |
9291 | break; | |
9292 | ||
9293 | if (reg >= (unsigned int) cie->ncols) | |
9294 | { | |
9295 | fc->col_type[reg] = DW_CFA_undefined; | |
9296 | fc->col_offset[reg] = 0; | |
9297 | } | |
9298 | else | |
665ce1f6 L |
9299 | { |
9300 | fc->col_type[reg] = cie->col_type[reg]; | |
9301 | fc->col_offset[reg] = cie->col_offset[reg]; | |
9302 | } | |
19e6b90e L |
9303 | break; |
9304 | ||
9305 | case DW_CFA_undefined: | |
cd30bcef | 9306 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9307 | if (reg >= (unsigned int) fc->ncols) |
9308 | reg_prefix = bad_reg; | |
9309 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9310 | printf (" DW_CFA_undefined: %s%s\n", | |
9311 | reg_prefix, regname (reg, 0)); | |
9312 | if (*reg_prefix == '\0') | |
9313 | { | |
9314 | fc->col_type[reg] = DW_CFA_undefined; | |
9315 | fc->col_offset[reg] = 0; | |
9316 | } | |
19e6b90e L |
9317 | break; |
9318 | ||
9319 | case DW_CFA_same_value: | |
cd30bcef | 9320 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9321 | if (reg >= (unsigned int) fc->ncols) |
9322 | reg_prefix = bad_reg; | |
9323 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9324 | printf (" DW_CFA_same_value: %s%s\n", | |
9325 | reg_prefix, regname (reg, 0)); | |
9326 | if (*reg_prefix == '\0') | |
9327 | { | |
9328 | fc->col_type[reg] = DW_CFA_same_value; | |
9329 | fc->col_offset[reg] = 0; | |
9330 | } | |
19e6b90e L |
9331 | break; |
9332 | ||
9333 | case DW_CFA_register: | |
cd30bcef AM |
9334 | READ_ULEB (reg, start, end); |
9335 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
9336 | if (reg >= (unsigned int) fc->ncols) |
9337 | reg_prefix = bad_reg; | |
9338 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 9339 | { |
665ce1f6 L |
9340 | printf (" DW_CFA_register: %s%s in ", |
9341 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
9342 | puts (regname (roffs, 0)); |
9343 | } | |
665ce1f6 L |
9344 | if (*reg_prefix == '\0') |
9345 | { | |
9346 | fc->col_type[reg] = DW_CFA_register; | |
9347 | fc->col_offset[reg] = roffs; | |
9348 | } | |
19e6b90e L |
9349 | break; |
9350 | ||
9351 | case DW_CFA_remember_state: | |
9352 | if (! do_debug_frames_interp) | |
9353 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 9354 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 9355 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
9356 | rs->cfa_reg = fc->cfa_reg; |
9357 | rs->ra = fc->ra; | |
9358 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 9359 | rs->ncols = fc->ncols; |
3f5e193b | 9360 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 9361 | sizeof (* rs->col_type)); |
d71ad7fc RC |
9362 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
9363 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
9364 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
9365 | rs->next = remembered_state; |
9366 | remembered_state = rs; | |
9367 | break; | |
9368 | ||
9369 | case DW_CFA_restore_state: | |
9370 | if (! do_debug_frames_interp) | |
9371 | printf (" DW_CFA_restore_state\n"); | |
9372 | rs = remembered_state; | |
9373 | if (rs) | |
9374 | { | |
9375 | remembered_state = rs->next; | |
d71ad7fc RC |
9376 | fc->cfa_offset = rs->cfa_offset; |
9377 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
9378 | fc->ra = rs->ra; |
9379 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
9380 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
9381 | { | |
1306a742 | 9382 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
9383 | fc->ncols = 0; |
9384 | break; | |
9385 | } | |
d71ad7fc | 9386 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 9387 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 9388 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
9389 | free (rs->col_type); |
9390 | free (rs->col_offset); | |
9391 | free (rs); | |
9392 | } | |
9393 | else if (do_debug_frames_interp) | |
9394 | printf ("Mismatched DW_CFA_restore_state\n"); | |
9395 | break; | |
9396 | ||
9397 | case DW_CFA_def_cfa: | |
cd30bcef AM |
9398 | READ_ULEB (fc->cfa_reg, start, end); |
9399 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
9400 | fc->cfa_exp = 0; |
9401 | if (! do_debug_frames_interp) | |
2dc4cec1 | 9402 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 9403 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
9404 | break; |
9405 | ||
9406 | case DW_CFA_def_cfa_register: | |
cd30bcef | 9407 | READ_ULEB (fc->cfa_reg, start, end); |
19e6b90e L |
9408 | fc->cfa_exp = 0; |
9409 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
9410 | printf (" DW_CFA_def_cfa_register: %s\n", |
9411 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
9412 | break; |
9413 | ||
9414 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 9415 | READ_ULEB (fc->cfa_offset, start, end); |
19e6b90e | 9416 | if (! do_debug_frames_interp) |
c8071705 | 9417 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
9418 | break; |
9419 | ||
9420 | case DW_CFA_nop: | |
9421 | if (! do_debug_frames_interp) | |
9422 | printf (" DW_CFA_nop\n"); | |
9423 | break; | |
9424 | ||
9425 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 9426 | READ_ULEB (ul, start, end); |
7460c0ab | 9427 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 9428 | { |
a1165289 | 9429 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
9430 | break; |
9431 | } | |
19e6b90e L |
9432 | if (! do_debug_frames_interp) |
9433 | { | |
9434 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
9435 | decode_location_expression (start, eh_addr_size, 0, -1, |
9436 | ul, 0, section); | |
19e6b90e L |
9437 | printf (")\n"); |
9438 | } | |
9439 | fc->cfa_exp = 1; | |
9440 | start += ul; | |
9441 | break; | |
9442 | ||
9443 | case DW_CFA_expression: | |
cd30bcef AM |
9444 | READ_ULEB (reg, start, end); |
9445 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
9446 | if (reg >= (unsigned int) fc->ncols) |
9447 | reg_prefix = bad_reg; | |
6937bb54 | 9448 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 9449 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
9450 | tmp = start + ul; |
9451 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 9452 | { |
a1165289 | 9453 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
9454 | break; |
9455 | } | |
665ce1f6 | 9456 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 9457 | { |
665ce1f6 L |
9458 | printf (" DW_CFA_expression: %s%s (", |
9459 | reg_prefix, regname (reg, 0)); | |
b7807392 | 9460 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 9461 | ul, 0, section); |
19e6b90e L |
9462 | printf (")\n"); |
9463 | } | |
665ce1f6 L |
9464 | if (*reg_prefix == '\0') |
9465 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 9466 | start = tmp; |
19e6b90e L |
9467 | break; |
9468 | ||
12eae2d3 | 9469 | case DW_CFA_val_expression: |
cd30bcef AM |
9470 | READ_ULEB (reg, start, end); |
9471 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
9472 | if (reg >= (unsigned int) fc->ncols) |
9473 | reg_prefix = bad_reg; | |
362beea4 NC |
9474 | tmp = start + ul; |
9475 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 9476 | { |
a1165289 | 9477 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
9478 | break; |
9479 | } | |
665ce1f6 | 9480 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 9481 | { |
665ce1f6 L |
9482 | printf (" DW_CFA_val_expression: %s%s (", |
9483 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
9484 | decode_location_expression (start, eh_addr_size, 0, -1, |
9485 | ul, 0, section); | |
12eae2d3 JJ |
9486 | printf (")\n"); |
9487 | } | |
665ce1f6 L |
9488 | if (*reg_prefix == '\0') |
9489 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 9490 | start = tmp; |
12eae2d3 JJ |
9491 | break; |
9492 | ||
19e6b90e | 9493 | case DW_CFA_offset_extended_sf: |
cd30bcef AM |
9494 | READ_ULEB (reg, start, end); |
9495 | READ_SLEB (l, start, end); | |
665ce1f6 L |
9496 | if (frame_need_space (fc, reg) < 0) |
9497 | reg_prefix = bad_reg; | |
9498 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9499 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
9500 | reg_prefix, regname (reg, 0), | |
c8071705 | 9501 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9502 | if (*reg_prefix == '\0') |
9503 | { | |
9504 | fc->col_type[reg] = DW_CFA_offset; | |
9505 | fc->col_offset[reg] = l * fc->data_factor; | |
9506 | } | |
19e6b90e L |
9507 | break; |
9508 | ||
12eae2d3 | 9509 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
9510 | READ_ULEB (reg, start, end); |
9511 | READ_SLEB (l, start, end); | |
665ce1f6 L |
9512 | if (frame_need_space (fc, reg) < 0) |
9513 | reg_prefix = bad_reg; | |
9514 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 9515 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 9516 | reg_prefix, regname (reg, 0), |
c8071705 | 9517 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9518 | if (*reg_prefix == '\0') |
9519 | { | |
9520 | fc->col_type[reg] = DW_CFA_val_offset; | |
9521 | fc->col_offset[reg] = l * fc->data_factor; | |
9522 | } | |
12eae2d3 JJ |
9523 | break; |
9524 | ||
19e6b90e | 9525 | case DW_CFA_def_cfa_sf: |
cd30bcef AM |
9526 | READ_ULEB (fc->cfa_reg, start, end); |
9527 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
9528 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
9529 | fc->cfa_exp = 0; | |
9530 | if (! do_debug_frames_interp) | |
2dc4cec1 | 9531 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 9532 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
9533 | break; |
9534 | ||
9535 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 9536 | READ_ULEB (fc->cfa_offset, start, end); |
c8071705 | 9537 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 9538 | if (! do_debug_frames_interp) |
c8071705 | 9539 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
9540 | break; |
9541 | ||
9542 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 9543 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
9544 | if (do_debug_frames_interp) |
9545 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9546 | else | |
bf5117e3 NC |
9547 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
9548 | (unsigned long) (ofs * fc->code_factor), | |
9549 | dwarf_vmatoa_1 (NULL, | |
9550 | fc->pc_begin + ofs * fc->code_factor, | |
9551 | fc->ptr_size)); | |
19e6b90e L |
9552 | fc->pc_begin += ofs * fc->code_factor; |
9553 | break; | |
9554 | ||
9555 | case DW_CFA_GNU_window_save: | |
9556 | if (! do_debug_frames_interp) | |
9557 | printf (" DW_CFA_GNU_window_save\n"); | |
9558 | break; | |
9559 | ||
9560 | case DW_CFA_GNU_args_size: | |
cd30bcef | 9561 | READ_ULEB (ul, start, end); |
19e6b90e L |
9562 | if (! do_debug_frames_interp) |
9563 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
9564 | break; | |
9565 | ||
9566 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
9567 | READ_ULEB (reg, start, end); |
9568 | READ_SLEB (l, start, end); | |
7f2c8a1d | 9569 | l = - l; |
665ce1f6 L |
9570 | if (frame_need_space (fc, reg) < 0) |
9571 | reg_prefix = bad_reg; | |
9572 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9573 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
9574 | reg_prefix, regname (reg, 0), | |
c8071705 | 9575 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9576 | if (*reg_prefix == '\0') |
9577 | { | |
9578 | fc->col_type[reg] = DW_CFA_offset; | |
9579 | fc->col_offset[reg] = l * fc->data_factor; | |
9580 | } | |
19e6b90e L |
9581 | break; |
9582 | ||
9583 | default: | |
53b8873b NC |
9584 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
9585 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
9586 | else | |
f41e4712 | 9587 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
9588 | start = block_end; |
9589 | } | |
9590 | } | |
9591 | ||
5b6312fd NC |
9592 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
9593 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
9594 | frame_display_row (fc, &need_col_headers, &max_regs); |
9595 | ||
a788aedd AM |
9596 | if (fde_fc.col_type != NULL) |
9597 | { | |
9598 | free (fde_fc.col_type); | |
9599 | fde_fc.col_type = NULL; | |
9600 | } | |
9601 | if (fde_fc.col_offset != NULL) | |
9602 | { | |
9603 | free (fde_fc.col_offset); | |
9604 | fde_fc.col_offset = NULL; | |
9605 | } | |
9606 | ||
19e6b90e | 9607 | start = block_end; |
604282a7 | 9608 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
9609 | } |
9610 | ||
9611 | printf ("\n"); | |
9612 | ||
3391569f NC |
9613 | while (remembered_state != NULL) |
9614 | { | |
9615 | rs = remembered_state; | |
9616 | remembered_state = rs->next; | |
9617 | free (rs->col_type); | |
9618 | free (rs->col_offset); | |
9619 | rs->next = NULL; /* Paranoia. */ | |
9620 | free (rs); | |
9621 | } | |
9622 | ||
9623 | while (chunks != NULL) | |
9624 | { | |
9625 | rs = chunks; | |
9626 | chunks = rs->next; | |
9627 | free (rs->col_type); | |
9628 | free (rs->col_offset); | |
9629 | rs->next = NULL; /* Paranoia. */ | |
9630 | free (rs); | |
9631 | } | |
9632 | ||
9633 | while (forward_refs != NULL) | |
9634 | { | |
9635 | rs = forward_refs; | |
9636 | forward_refs = rs->next; | |
9637 | free (rs->col_type); | |
9638 | free (rs->col_offset); | |
9639 | rs->next = NULL; /* Paranoia. */ | |
9640 | free (rs); | |
9641 | } | |
9642 | ||
19e6b90e L |
9643 | return 1; |
9644 | } | |
9645 | ||
9646 | #undef GET | |
19e6b90e | 9647 | |
61364358 JK |
9648 | static int |
9649 | display_debug_names (struct dwarf_section *section, void *file) | |
9650 | { | |
9651 | unsigned char *hdrptr = section->start; | |
9652 | dwarf_vma unit_length; | |
9653 | unsigned char *unit_start; | |
9654 | const unsigned char *const section_end = section->start + section->size; | |
9655 | unsigned char *unit_end; | |
9656 | ||
dda8d76d | 9657 | introduce (section, FALSE); |
61364358 | 9658 | |
dda8d76d | 9659 | load_debug_section_with_follow (str, file); |
61364358 JK |
9660 | |
9661 | for (; hdrptr < section_end; hdrptr = unit_end) | |
9662 | { | |
9663 | unsigned int offset_size; | |
9664 | uint16_t dwarf_version, padding; | |
9665 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
9666 | uint32_t bucket_count, name_count, abbrev_table_size; | |
9667 | uint32_t augmentation_string_size; | |
9668 | unsigned int i; | |
e98fdf1a | 9669 | unsigned long sec_off; |
48467cb9 TV |
9670 | bfd_boolean augmentation_printable; |
9671 | const char *augmentation_string; | |
61364358 JK |
9672 | |
9673 | unit_start = hdrptr; | |
9674 | ||
9675 | /* Get and check the length of the block. */ | |
9676 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
9677 | ||
9678 | if (unit_length == 0xffffffff) | |
9679 | { | |
9680 | /* This section is 64-bit DWARF. */ | |
9681 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
9682 | offset_size = 8; | |
9683 | } | |
9684 | else | |
9685 | offset_size = 4; | |
9686 | unit_end = hdrptr + unit_length; | |
9687 | ||
e98fdf1a AM |
9688 | sec_off = hdrptr - section->start; |
9689 | if (sec_off + unit_length < sec_off | |
9690 | || sec_off + unit_length > section->size) | |
61364358 | 9691 | { |
e98fdf1a AM |
9692 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
9693 | section->name, | |
9694 | (unsigned long) (unit_start - section->start), | |
9695 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
9696 | return 0; |
9697 | } | |
9698 | ||
9699 | /* Get and check the version number. */ | |
9700 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
9701 | printf (_("Version %ld\n"), (long) dwarf_version); | |
9702 | ||
9703 | /* Prior versions did not exist, and future versions may not be | |
9704 | backwards compatible. */ | |
9705 | if (dwarf_version != 5) | |
9706 | { | |
9707 | warn (_("Only DWARF version 5 .debug_names " | |
9708 | "is currently supported.\n")); | |
9709 | return 0; | |
9710 | } | |
9711 | ||
9712 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
9713 | if (padding != 0) | |
9714 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
9715 | padding); | |
9716 | ||
9717 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
9718 | if (comp_unit_count == 0) | |
9719 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
9720 | ||
9721 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
9722 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
9723 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
9724 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
9725 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
9726 | ||
9727 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
9728 | if (augmentation_string_size % 4 != 0) | |
9729 | { | |
9730 | warn (_("Augmentation string length %u must be rounded up " | |
9731 | "to a multiple of 4 in .debug_names.\n"), | |
9732 | augmentation_string_size); | |
9733 | augmentation_string_size += (-augmentation_string_size) & 3; | |
9734 | } | |
48467cb9 | 9735 | |
61364358 | 9736 | printf (_("Augmentation string:")); |
48467cb9 TV |
9737 | |
9738 | augmentation_printable = TRUE; | |
9739 | augmentation_string = (const char *) hdrptr; | |
9740 | ||
61364358 JK |
9741 | for (i = 0; i < augmentation_string_size; i++) |
9742 | { | |
9743 | unsigned char uc; | |
9744 | ||
9745 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
9746 | printf (" %02x", uc); | |
48467cb9 TV |
9747 | |
9748 | if (uc != 0 && !ISPRINT (uc)) | |
9749 | augmentation_printable = FALSE; | |
9750 | } | |
9751 | ||
9752 | if (augmentation_printable) | |
9753 | { | |
9754 | printf (" (\""); | |
9755 | for (i = 0; | |
9756 | i < augmentation_string_size && augmentation_string[i]; | |
9757 | ++i) | |
9758 | putchar (augmentation_string[i]); | |
9759 | printf ("\")"); | |
61364358 | 9760 | } |
61364358 JK |
9761 | putchar ('\n'); |
9762 | ||
9763 | printf (_("CU table:\n")); | |
9764 | for (i = 0; i < comp_unit_count; i++) | |
9765 | { | |
9766 | uint64_t cu_offset; | |
9767 | ||
9768 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
9769 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
9770 | } | |
9771 | putchar ('\n'); | |
9772 | ||
9773 | printf (_("TU table:\n")); | |
9774 | for (i = 0; i < local_type_unit_count; i++) | |
9775 | { | |
9776 | uint64_t tu_offset; | |
9777 | ||
9778 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
9779 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
9780 | } | |
9781 | putchar ('\n'); | |
9782 | ||
9783 | printf (_("Foreign TU table:\n")); | |
9784 | for (i = 0; i < foreign_type_unit_count; i++) | |
9785 | { | |
9786 | uint64_t signature; | |
9787 | ||
9788 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
9789 | printf (_("[%3u] "), i); | |
9790 | print_dwarf_vma (signature, 8); | |
9791 | putchar ('\n'); | |
9792 | } | |
9793 | putchar ('\n'); | |
9794 | ||
9795 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
9796 | hdrptr += bucket_count * sizeof (uint32_t); | |
9797 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
9798 | hdrptr += name_count * sizeof (uint32_t); | |
9799 | unsigned char *const name_table_string_offsets = hdrptr; | |
9800 | hdrptr += name_count * offset_size; | |
9801 | unsigned char *const name_table_entry_offsets = hdrptr; | |
9802 | hdrptr += name_count * offset_size; | |
9803 | unsigned char *const abbrev_table = hdrptr; | |
9804 | hdrptr += abbrev_table_size; | |
9805 | const unsigned char *const abbrev_table_end = hdrptr; | |
9806 | unsigned char *const entry_pool = hdrptr; | |
9807 | if (hdrptr > unit_end) | |
9808 | { | |
9809 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
9810 | "for unit 0x%lx in the debug_names\n"), | |
9811 | (long) (hdrptr - section->start), | |
9812 | (long) (unit_end - section->start), | |
9813 | (long) (unit_start - section->start)); | |
9814 | return 0; | |
9815 | } | |
9816 | ||
9817 | size_t buckets_filled = 0; | |
9818 | size_t bucketi; | |
9819 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
9820 | { | |
9821 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
9822 | ||
9823 | if (bucket != 0) | |
9824 | ++buckets_filled; | |
9825 | } | |
d3a49aa8 AM |
9826 | printf (ngettext ("Used %zu of %lu bucket.\n", |
9827 | "Used %zu of %lu buckets.\n", | |
9828 | bucket_count), | |
9829 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 9830 | |
0a79bef4 | 9831 | uint32_t hash_prev = 0; |
61364358 JK |
9832 | size_t hash_clash_count = 0; |
9833 | size_t longest_clash = 0; | |
9834 | size_t this_length = 0; | |
9835 | size_t hashi; | |
9836 | for (hashi = 0; hashi < name_count; hashi++) | |
9837 | { | |
9838 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
9839 | ||
9840 | if (hashi > 0) | |
9841 | { | |
9842 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
9843 | { | |
9844 | ++hash_clash_count; | |
9845 | ++this_length; | |
9846 | longest_clash = MAX (longest_clash, this_length); | |
9847 | } | |
9848 | else | |
9849 | this_length = 0; | |
9850 | } | |
9851 | hash_prev = hash_this; | |
9852 | } | |
9853 | printf (_("Out of %lu items there are %zu bucket clashes" | |
9854 | " (longest of %zu entries).\n"), | |
9855 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
9856 | assert (name_count == buckets_filled + hash_clash_count); | |
9857 | ||
9858 | struct abbrev_lookup_entry | |
9859 | { | |
9860 | dwarf_vma abbrev_tag; | |
9861 | unsigned char *abbrev_lookup_ptr; | |
9862 | }; | |
9863 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
9864 | size_t abbrev_lookup_used = 0; | |
9865 | size_t abbrev_lookup_allocated = 0; | |
9866 | ||
9867 | unsigned char *abbrevptr = abbrev_table; | |
9868 | for (;;) | |
9869 | { | |
cd30bcef AM |
9870 | dwarf_vma abbrev_tag; |
9871 | ||
9872 | READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end); | |
61364358 JK |
9873 | if (abbrev_tag == 0) |
9874 | break; | |
9875 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
9876 | { | |
9877 | abbrev_lookup_allocated = MAX (0x100, | |
9878 | abbrev_lookup_allocated * 2); | |
9879 | abbrev_lookup = xrealloc (abbrev_lookup, | |
9880 | (abbrev_lookup_allocated | |
9881 | * sizeof (*abbrev_lookup))); | |
9882 | } | |
9883 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
9884 | struct abbrev_lookup_entry *entry; | |
9885 | for (entry = abbrev_lookup; | |
9886 | entry < abbrev_lookup + abbrev_lookup_used; | |
9887 | entry++) | |
9888 | if (entry->abbrev_tag == abbrev_tag) | |
9889 | { | |
9890 | warn (_("Duplicate abbreviation tag %lu " | |
9891 | "in unit 0x%lx in the debug_names\n"), | |
9892 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
9893 | break; | |
9894 | } | |
9895 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
9896 | entry->abbrev_tag = abbrev_tag; | |
9897 | entry->abbrev_lookup_ptr = abbrevptr; | |
9898 | ||
9899 | /* Skip DWARF tag. */ | |
cd30bcef | 9900 | SKIP_ULEB (abbrevptr, abbrev_table_end); |
61364358 JK |
9901 | for (;;) |
9902 | { | |
cd30bcef AM |
9903 | dwarf_vma xindex, form; |
9904 | ||
9905 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9906 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9907 | if (xindex == 0 && form == 0) |
61364358 JK |
9908 | break; |
9909 | } | |
9910 | } | |
9911 | ||
9912 | printf (_("\nSymbol table:\n")); | |
9913 | uint32_t namei; | |
9914 | for (namei = 0; namei < name_count; ++namei) | |
9915 | { | |
9916 | uint64_t string_offset, entry_offset; | |
9917 | ||
9918 | SAFE_BYTE_GET (string_offset, | |
9919 | name_table_string_offsets + namei * offset_size, | |
9920 | offset_size, unit_end); | |
9921 | SAFE_BYTE_GET (entry_offset, | |
9922 | name_table_entry_offsets + namei * offset_size, | |
9923 | offset_size, unit_end); | |
9924 | ||
9925 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
9926 | fetch_indirect_string (string_offset)); | |
9927 | ||
9928 | unsigned char *entryptr = entry_pool + entry_offset; | |
9929 | ||
279edac5 AM |
9930 | /* We need to scan first whether there is a single or multiple |
9931 | entries. TAGNO is -2 for the first entry, it is -1 for the | |
9932 | initial tag read of the second entry, then it becomes 0 for the | |
9933 | first entry for real printing etc. */ | |
61364358 JK |
9934 | int tagno = -2; |
9935 | /* Initialize it due to a false compiler warning. */ | |
9936 | dwarf_vma second_abbrev_tag = -1; | |
9937 | for (;;) | |
9938 | { | |
cd30bcef AM |
9939 | dwarf_vma abbrev_tag; |
9940 | dwarf_vma dwarf_tag; | |
9941 | const struct abbrev_lookup_entry *entry; | |
9942 | ||
9943 | READ_ULEB (abbrev_tag, entryptr, unit_end); | |
61364358 JK |
9944 | if (tagno == -1) |
9945 | { | |
9946 | second_abbrev_tag = abbrev_tag; | |
9947 | tagno = 0; | |
9948 | entryptr = entry_pool + entry_offset; | |
9949 | continue; | |
9950 | } | |
9951 | if (abbrev_tag == 0) | |
9952 | break; | |
9953 | if (tagno >= 0) | |
9954 | printf ("%s<%lu>", | |
9955 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
9956 | (unsigned long) abbrev_tag); | |
9957 | ||
61364358 JK |
9958 | for (entry = abbrev_lookup; |
9959 | entry < abbrev_lookup + abbrev_lookup_used; | |
9960 | entry++) | |
9961 | if (entry->abbrev_tag == abbrev_tag) | |
9962 | break; | |
9963 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
9964 | { | |
9965 | warn (_("Undefined abbreviation tag %lu " | |
9966 | "in unit 0x%lx in the debug_names\n"), | |
9967 | (long) abbrev_tag, | |
9968 | (long) (unit_start - section->start)); | |
9969 | break; | |
9970 | } | |
9971 | abbrevptr = entry->abbrev_lookup_ptr; | |
cd30bcef | 9972 | READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end); |
61364358 JK |
9973 | if (tagno >= 0) |
9974 | printf (" %s", get_TAG_name (dwarf_tag)); | |
9975 | for (;;) | |
9976 | { | |
cd30bcef AM |
9977 | dwarf_vma xindex, form; |
9978 | ||
9979 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9980 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9981 | if (xindex == 0 && form == 0) |
61364358 JK |
9982 | break; |
9983 | ||
9984 | if (tagno >= 0) | |
1d827a72 | 9985 | printf (" %s", get_IDX_name (xindex)); |
ec1b0fbb NC |
9986 | entryptr = read_and_display_attr_value (0, form, 0, |
9987 | unit_start, entryptr, unit_end, | |
9988 | 0, 0, offset_size, | |
61364358 JK |
9989 | dwarf_version, NULL, |
9990 | (tagno < 0), NULL, | |
ec1b0fbb | 9991 | NULL, '=', -1); |
61364358 JK |
9992 | } |
9993 | ++tagno; | |
9994 | } | |
9995 | if (tagno <= 0) | |
9996 | printf (_(" <no entries>")); | |
9997 | putchar ('\n'); | |
9998 | } | |
9999 | ||
10000 | free (abbrev_lookup); | |
10001 | } | |
10002 | ||
10003 | return 1; | |
10004 | } | |
10005 | ||
dda8d76d | 10006 | static int |
d85bf2ba NC |
10007 | display_debug_links (struct dwarf_section * section, |
10008 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
10009 | { |
10010 | const unsigned char * filename; | |
10011 | unsigned int filelen; | |
10012 | ||
10013 | introduce (section, FALSE); | |
10014 | ||
10015 | /* The .gnu_debuglink section is formatted as: | |
10016 | (c-string) Filename. | |
10017 | (padding) If needed to reach a 4 byte boundary. | |
10018 | (uint32_t) CRC32 value. | |
10019 | ||
10020 | The .gun_debugaltlink section is formatted as: | |
10021 | (c-string) Filename. | |
10022 | (binary) Build-ID. */ | |
521d4b19 | 10023 | |
dda8d76d NC |
10024 | filename = section->start; |
10025 | filelen = strnlen ((const char *) filename, section->size); | |
10026 | if (filelen == section->size) | |
10027 | { | |
10028 | warn (_("The debuglink filename is corrupt/missing\n")); | |
10029 | return 0; | |
10030 | } | |
10031 | ||
10032 | printf (_(" Separate debug info file: %s\n"), filename); | |
10033 | ||
10034 | if (const_strneq (section->name, ".gnu_debuglink")) | |
10035 | { | |
10036 | unsigned int crc32; | |
10037 | unsigned int crc_offset; | |
10038 | ||
10039 | crc_offset = filelen + 1; | |
10040 | crc_offset = (crc_offset + 3) & ~3; | |
10041 | if (crc_offset + 4 > section->size) | |
10042 | { | |
10043 | warn (_("CRC offset missing/truncated\n")); | |
10044 | return 0; | |
10045 | } | |
10046 | ||
10047 | crc32 = byte_get (filename + crc_offset, 4); | |
10048 | ||
10049 | printf (_(" CRC value: %#x\n"), crc32); | |
10050 | ||
10051 | if (crc_offset + 4 < section->size) | |
10052 | { | |
10053 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
10054 | (long)(section->size - (crc_offset + 4))); | |
10055 | return 0; | |
10056 | } | |
10057 | } | |
10058 | else /* const_strneq (section->name, ".gnu_debugaltlink") */ | |
10059 | { | |
10060 | const unsigned char * build_id = section->start + filelen + 1; | |
10061 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
10062 | bfd_size_type printed; | |
10063 | ||
10064 | /* FIXME: Should we support smaller build-id notes ? */ | |
10065 | if (build_id_len < 0x14) | |
10066 | { | |
10067 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
10068 | return 0; | |
10069 | } | |
10070 | ||
10071 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 10072 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
10073 | putchar ('\n'); |
10074 | } | |
10075 | ||
10076 | putchar ('\n'); | |
10077 | return 1; | |
10078 | } | |
10079 | ||
5bbdf3d5 DE |
10080 | static int |
10081 | display_gdb_index (struct dwarf_section *section, | |
10082 | void *file ATTRIBUTE_UNUSED) | |
10083 | { | |
10084 | unsigned char *start = section->start; | |
10085 | uint32_t version; | |
10086 | uint32_t cu_list_offset, tu_list_offset; | |
10087 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
10088 | unsigned int cu_list_elements, tu_list_elements; | |
10089 | unsigned int address_table_size, symbol_table_slots; | |
10090 | unsigned char *cu_list, *tu_list; | |
10091 | unsigned char *address_table, *symbol_table, *constant_pool; | |
10092 | unsigned int i; | |
10093 | ||
10094 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
10095 | ||
dda8d76d | 10096 | introduce (section, FALSE); |
5bbdf3d5 DE |
10097 | |
10098 | if (section->size < 6 * sizeof (uint32_t)) | |
10099 | { | |
10100 | warn (_("Truncated header in the %s section.\n"), section->name); | |
10101 | return 0; | |
10102 | } | |
10103 | ||
10104 | version = byte_get_little_endian (start, 4); | |
da88a764 | 10105 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
10106 | |
10107 | /* Prior versions are obsolete, and future versions may not be | |
10108 | backwards compatible. */ | |
aa170720 | 10109 | if (version < 3 || version > 8) |
5bbdf3d5 | 10110 | { |
da88a764 | 10111 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
10112 | return 0; |
10113 | } | |
8d6eee87 TT |
10114 | if (version < 4) |
10115 | warn (_("The address table data in version 3 may be wrong.\n")); | |
10116 | if (version < 5) | |
10117 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
10118 | if (version < 6) | |
10119 | warn (_("Version 5 does not include inlined functions.\n")); | |
10120 | if (version < 7) | |
10121 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
10122 | /* Version 7 indices generated by Gold have bad type unit references, |
10123 | PR binutils/15021. But we don't know if the index was generated by | |
10124 | Gold or not, so to avoid worrying users with gdb-generated indices | |
10125 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
10126 | |
10127 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
10128 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
10129 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
10130 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
10131 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
10132 | ||
10133 | if (cu_list_offset > section->size | |
10134 | || tu_list_offset > section->size | |
10135 | || address_table_offset > section->size | |
10136 | || symbol_table_offset > section->size | |
10137 | || constant_pool_offset > section->size) | |
10138 | { | |
10139 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
10140 | return 0; | |
10141 | } | |
10142 | ||
53774b7e NC |
10143 | /* PR 17531: file: 418d0a8a. */ |
10144 | if (tu_list_offset < cu_list_offset) | |
10145 | { | |
10146 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
10147 | tu_list_offset, cu_list_offset); | |
10148 | return 0; | |
10149 | } | |
10150 | ||
5bbdf3d5 | 10151 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
10152 | |
10153 | if (address_table_offset < tu_list_offset) | |
10154 | { | |
10155 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
10156 | address_table_offset, tu_list_offset); | |
10157 | return 0; | |
10158 | } | |
10159 | ||
5bbdf3d5 | 10160 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
10161 | |
10162 | /* PR 17531: file: 18a47d3d. */ | |
10163 | if (symbol_table_offset < address_table_offset) | |
10164 | { | |
13bace4a | 10165 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
10166 | symbol_table_offset, address_table_offset); |
10167 | return 0; | |
10168 | } | |
10169 | ||
5bbdf3d5 | 10170 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
10171 | |
10172 | if (constant_pool_offset < symbol_table_offset) | |
10173 | { | |
10174 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
10175 | constant_pool_offset, symbol_table_offset); | |
10176 | return 0; | |
10177 | } | |
10178 | ||
5bbdf3d5 DE |
10179 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
10180 | ||
10181 | cu_list = start + cu_list_offset; | |
10182 | tu_list = start + tu_list_offset; | |
10183 | address_table = start + address_table_offset; | |
10184 | symbol_table = start + symbol_table_offset; | |
10185 | constant_pool = start + constant_pool_offset; | |
10186 | ||
28d909e5 | 10187 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 10188 | { |
1306a742 | 10189 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
10190 | return 0; |
10191 | } | |
b4eb7656 | 10192 | |
5bbdf3d5 DE |
10193 | printf (_("\nCU table:\n")); |
10194 | for (i = 0; i < cu_list_elements; i += 2) | |
10195 | { | |
10196 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
10197 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
10198 | ||
10199 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
10200 | (unsigned long) cu_offset, | |
10201 | (unsigned long) (cu_offset + cu_length - 1)); | |
10202 | } | |
10203 | ||
10204 | printf (_("\nTU table:\n")); | |
10205 | for (i = 0; i < tu_list_elements; i += 3) | |
10206 | { | |
10207 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
10208 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
10209 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
10210 | ||
10211 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
10212 | (unsigned long) tu_offset, | |
10213 | (unsigned long) type_offset); | |
10214 | print_dwarf_vma (signature, 8); | |
10215 | printf ("\n"); | |
10216 | } | |
10217 | ||
10218 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
10219 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
10220 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
10221 | { |
10222 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
10223 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
10224 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
10225 | ||
10226 | print_dwarf_vma (low, 8); | |
10227 | print_dwarf_vma (high, 8); | |
da88a764 | 10228 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
10229 | } |
10230 | ||
10231 | printf (_("\nSymbol table:\n")); | |
10232 | for (i = 0; i < symbol_table_slots; ++i) | |
10233 | { | |
10234 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
10235 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
10236 | uint32_t num_cus, cu; | |
10237 | ||
10238 | if (name_offset != 0 | |
10239 | || cu_vector_offset != 0) | |
10240 | { | |
10241 | unsigned int j; | |
362beea4 | 10242 | unsigned char * adr; |
5bbdf3d5 | 10243 | |
362beea4 | 10244 | adr = constant_pool + name_offset; |
53774b7e | 10245 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 10246 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
10247 | { |
10248 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
10249 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
10250 | name_offset, i); | |
10251 | } | |
10252 | else | |
acff9664 NC |
10253 | printf ("[%3u] %.*s:", i, |
10254 | (int) (section->size - (constant_pool_offset + name_offset)), | |
10255 | constant_pool + name_offset); | |
53774b7e | 10256 | |
362beea4 NC |
10257 | adr = constant_pool + cu_vector_offset; |
10258 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
10259 | { |
10260 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
10261 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
10262 | cu_vector_offset, i); | |
10263 | continue; | |
10264 | } | |
57028622 | 10265 | |
362beea4 | 10266 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 10267 | |
362beea4 | 10268 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 10269 | if (num_cus * 4 < num_cus |
362beea4 NC |
10270 | || adr >= section->start + section->size |
10271 | || adr < constant_pool) | |
53774b7e NC |
10272 | { |
10273 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 10274 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
10275 | num_cus, i); |
10276 | continue; | |
10277 | } | |
10278 | ||
8d6eee87 TT |
10279 | if (num_cus > 1) |
10280 | printf ("\n"); | |
f3853b34 | 10281 | |
5bbdf3d5 DE |
10282 | for (j = 0; j < num_cus; ++j) |
10283 | { | |
7c1cef97 | 10284 | int is_static; |
8d6eee87 TT |
10285 | gdb_index_symbol_kind kind; |
10286 | ||
5bbdf3d5 | 10287 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 10288 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
10289 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
10290 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 10291 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 10292 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
10293 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
10294 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 10295 | else |
8d6eee87 TT |
10296 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
10297 | ||
459d52c8 DE |
10298 | printf (" [%s, %s]", |
10299 | is_static ? _("static") : _("global"), | |
10300 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
10301 | if (num_cus > 1) |
10302 | printf ("\n"); | |
5bbdf3d5 | 10303 | } |
8d6eee87 TT |
10304 | if (num_cus <= 1) |
10305 | printf ("\n"); | |
5bbdf3d5 DE |
10306 | } |
10307 | } | |
10308 | ||
10309 | return 1; | |
10310 | } | |
10311 | ||
657d0d47 CC |
10312 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
10313 | ||
10314 | static void | |
10315 | prealloc_cu_tu_list (unsigned int nshndx) | |
10316 | { | |
10317 | if (shndx_pool == NULL) | |
10318 | { | |
10319 | shndx_pool_size = nshndx; | |
10320 | shndx_pool_used = 0; | |
10321 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
10322 | sizeof (unsigned int)); | |
10323 | } | |
10324 | else | |
10325 | { | |
10326 | shndx_pool_size = shndx_pool_used + nshndx; | |
10327 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
10328 | sizeof (unsigned int)); | |
10329 | } | |
10330 | } | |
10331 | ||
10332 | static void | |
10333 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
10334 | { | |
10335 | if (shndx_pool_used >= shndx_pool_size) | |
10336 | { | |
10337 | error (_("Internal error: out of space in the shndx pool.\n")); | |
10338 | return; | |
10339 | } | |
10340 | shndx_pool [shndx_pool_used++] = shndx; | |
10341 | } | |
10342 | ||
10343 | static void | |
10344 | end_cu_tu_entry (void) | |
10345 | { | |
10346 | if (shndx_pool_used >= shndx_pool_size) | |
10347 | { | |
10348 | error (_("Internal error: out of space in the shndx pool.\n")); | |
10349 | return; | |
10350 | } | |
10351 | shndx_pool [shndx_pool_used++] = 0; | |
10352 | } | |
10353 | ||
341f9135 CC |
10354 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
10355 | ||
10356 | static const char * | |
10357 | get_DW_SECT_short_name (unsigned int dw_sect) | |
10358 | { | |
10359 | static char buf[16]; | |
10360 | ||
10361 | switch (dw_sect) | |
10362 | { | |
10363 | case DW_SECT_INFO: | |
10364 | return "info"; | |
10365 | case DW_SECT_TYPES: | |
10366 | return "types"; | |
10367 | case DW_SECT_ABBREV: | |
10368 | return "abbrev"; | |
10369 | case DW_SECT_LINE: | |
10370 | return "line"; | |
10371 | case DW_SECT_LOC: | |
10372 | return "loc"; | |
10373 | case DW_SECT_STR_OFFSETS: | |
10374 | return "str_off"; | |
10375 | case DW_SECT_MACINFO: | |
10376 | return "macinfo"; | |
10377 | case DW_SECT_MACRO: | |
10378 | return "macro"; | |
10379 | default: | |
b4eb7656 | 10380 | break; |
341f9135 CC |
10381 | } |
10382 | ||
10383 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
10384 | return buf; | |
10385 | } | |
10386 | ||
10387 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
10388 | These sections are extensions for Fission. | |
10389 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
10390 | |
10391 | static int | |
10392 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
10393 | { | |
10394 | unsigned char *phdr = section->start; | |
10395 | unsigned char *limit = phdr + section->size; | |
10396 | unsigned char *phash; | |
10397 | unsigned char *pindex; | |
10398 | unsigned char *ppool; | |
10399 | unsigned int version; | |
341f9135 | 10400 | unsigned int ncols = 0; |
657d0d47 CC |
10401 | unsigned int nused; |
10402 | unsigned int nslots; | |
10403 | unsigned int i; | |
341f9135 CC |
10404 | unsigned int j; |
10405 | dwarf_vma signature_high; | |
10406 | dwarf_vma signature_low; | |
10407 | char buf[64]; | |
657d0d47 | 10408 | |
6937bb54 NC |
10409 | /* PR 17512: file: 002-168123-0.004. */ |
10410 | if (phdr == NULL) | |
10411 | { | |
10412 | warn (_("Section %s is empty\n"), section->name); | |
10413 | return 0; | |
10414 | } | |
10415 | /* PR 17512: file: 002-376-0.004. */ | |
10416 | if (section->size < 24) | |
10417 | { | |
72c61a0d | 10418 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
10419 | section->name); |
10420 | return 0; | |
10421 | } | |
10422 | ||
10423 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 10424 | if (version >= 2) |
6937bb54 NC |
10425 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
10426 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
10427 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
10428 | ||
657d0d47 | 10429 | phash = phdr + 16; |
8e2e3c6c AM |
10430 | pindex = phash + (size_t) nslots * 8; |
10431 | ppool = pindex + (size_t) nslots * 4; | |
57028622 | 10432 | |
657d0d47 CC |
10433 | if (do_display) |
10434 | { | |
dda8d76d NC |
10435 | introduce (section, FALSE); |
10436 | ||
8e2e3c6c | 10437 | printf (_(" Version: %u\n"), version); |
341f9135 | 10438 | if (version >= 2) |
8e2e3c6c AM |
10439 | printf (_(" Number of columns: %u\n"), ncols); |
10440 | printf (_(" Number of used entries: %u\n"), nused); | |
10441 | printf (_(" Number of slots: %u\n\n"), nslots); | |
657d0d47 CC |
10442 | } |
10443 | ||
8e2e3c6c AM |
10444 | /* PR 17531: file: 45d69832. */ |
10445 | if ((size_t) nslots * 8 / 8 != nslots | |
10446 | || phash < phdr || phash > limit | |
10447 | || pindex < phash || pindex > limit | |
10448 | || ppool < pindex || ppool > limit) | |
657d0d47 | 10449 | { |
8e2e3c6c AM |
10450 | warn (ngettext ("Section %s is too small for %u slot\n", |
10451 | "Section %s is too small for %u slots\n", | |
10452 | nslots), | |
657d0d47 CC |
10453 | section->name, nslots); |
10454 | return 0; | |
10455 | } | |
10456 | ||
341f9135 | 10457 | if (version == 1) |
657d0d47 | 10458 | { |
341f9135 CC |
10459 | if (!do_display) |
10460 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
10461 | for (i = 0; i < nslots; i++) | |
657d0d47 | 10462 | { |
341f9135 CC |
10463 | unsigned char *shndx_list; |
10464 | unsigned int shndx; | |
10465 | ||
6937bb54 | 10466 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 10467 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 10468 | { |
6937bb54 | 10469 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 10470 | shndx_list = ppool + j * 4; |
f3853b34 NC |
10471 | /* PR 17531: file: 705e010d. */ |
10472 | if (shndx_list < ppool) | |
10473 | { | |
10474 | warn (_("Section index pool located before start of section\n")); | |
10475 | return 0; | |
10476 | } | |
10477 | ||
341f9135 CC |
10478 | if (do_display) |
10479 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
10480 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10481 | buf, sizeof (buf))); | |
10482 | for (;;) | |
657d0d47 | 10483 | { |
341f9135 CC |
10484 | if (shndx_list >= limit) |
10485 | { | |
10486 | warn (_("Section %s too small for shndx pool\n"), | |
10487 | section->name); | |
10488 | return 0; | |
10489 | } | |
6937bb54 | 10490 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
10491 | if (shndx == 0) |
10492 | break; | |
10493 | if (do_display) | |
10494 | printf (" %d", shndx); | |
10495 | else | |
10496 | add_shndx_to_cu_tu_entry (shndx); | |
10497 | shndx_list += 4; | |
657d0d47 | 10498 | } |
657d0d47 | 10499 | if (do_display) |
341f9135 | 10500 | printf ("\n"); |
657d0d47 | 10501 | else |
341f9135 CC |
10502 | end_cu_tu_entry (); |
10503 | } | |
10504 | phash += 8; | |
10505 | pindex += 4; | |
10506 | } | |
10507 | } | |
10508 | else if (version == 2) | |
10509 | { | |
10510 | unsigned int val; | |
10511 | unsigned int dw_sect; | |
10512 | unsigned char *ph = phash; | |
10513 | unsigned char *pi = pindex; | |
8e2e3c6c AM |
10514 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
10515 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
10516 | unsigned char *pend = psizes + (size_t) nused * ncols * 4; | |
341f9135 CC |
10517 | bfd_boolean is_tu_index; |
10518 | struct cu_tu_set *this_set = NULL; | |
10519 | unsigned int row; | |
10520 | unsigned char *prow; | |
10521 | ||
10522 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
10523 | ||
362beea4 | 10524 | /* PR 17531: file: 0dd159bf. |
8e2e3c6c AM |
10525 | Check for integer overflow (can occur when size_t is 32-bit) |
10526 | with overlarge ncols or nused values. */ | |
4ac948a0 NC |
10527 | if (ncols > 0 |
10528 | && ((size_t) ncols * 4 / 4 != ncols | |
10529 | || (size_t) nused * ncols * 4 / ((size_t) ncols * 4) != nused | |
10530 | || poffsets < ppool || poffsets > limit | |
10531 | || psizes < poffsets || psizes > limit | |
10532 | || pend < psizes || pend > limit)) | |
341f9135 CC |
10533 | { |
10534 | warn (_("Section %s too small for offset and size tables\n"), | |
10535 | section->name); | |
10536 | return 0; | |
10537 | } | |
10538 | ||
10539 | if (do_display) | |
10540 | { | |
10541 | printf (_(" Offset table\n")); | |
10542 | printf (" slot %-16s ", | |
10543 | is_tu_index ? _("signature") : _("dwo_id")); | |
10544 | } | |
10545 | else | |
10546 | { | |
10547 | if (is_tu_index) | |
10548 | { | |
10549 | tu_count = nused; | |
72c61a0d | 10550 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 10551 | this_set = tu_sets; |
657d0d47 | 10552 | } |
657d0d47 | 10553 | else |
341f9135 CC |
10554 | { |
10555 | cu_count = nused; | |
72c61a0d | 10556 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
10557 | this_set = cu_sets; |
10558 | } | |
10559 | } | |
6937bb54 | 10560 | |
341f9135 CC |
10561 | if (do_display) |
10562 | { | |
10563 | for (j = 0; j < ncols; j++) | |
10564 | { | |
6937bb54 | 10565 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
10566 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
10567 | } | |
10568 | printf ("\n"); | |
10569 | } | |
6937bb54 | 10570 | |
341f9135 CC |
10571 | for (i = 0; i < nslots; i++) |
10572 | { | |
6937bb54 NC |
10573 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
10574 | ||
10575 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10576 | if (row != 0) |
10577 | { | |
591f7597 | 10578 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 10579 | if (row > nused) |
591f7597 NC |
10580 | { |
10581 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
10582 | row, nused); | |
10583 | return 0; | |
10584 | } | |
10585 | ||
341f9135 | 10586 | if (!do_display) |
6aea08d9 NC |
10587 | { |
10588 | size_t num_copy = sizeof (uint64_t); | |
10589 | ||
10590 | /* PR 23064: Beware of buffer overflow. */ | |
10591 | if (ph + num_copy < limit) | |
10592 | memcpy (&this_set[row - 1].signature, ph, num_copy); | |
10593 | else | |
10594 | { | |
10595 | warn (_("Signature (%p) extends beyond end of space in section\n"), ph); | |
10596 | return 0; | |
10597 | } | |
10598 | } | |
6937bb54 | 10599 | |
341f9135 | 10600 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
10601 | /* PR 17531: file: b8ce60a8. */ |
10602 | if (prow < poffsets || prow > limit) | |
10603 | { | |
10604 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
10605 | row, ncols); | |
10606 | return 0; | |
10607 | } | |
3aade688 | 10608 | |
341f9135 CC |
10609 | if (do_display) |
10610 | printf (_(" [%3d] 0x%s"), | |
10611 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10612 | buf, sizeof (buf))); | |
10613 | for (j = 0; j < ncols; j++) | |
10614 | { | |
6937bb54 | 10615 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
10616 | if (do_display) |
10617 | printf (" %8d", val); | |
10618 | else | |
10619 | { | |
6937bb54 | 10620 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
10621 | |
10622 | /* PR 17531: file: 10796eb3. */ | |
10623 | if (dw_sect >= DW_SECT_MAX) | |
10624 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10625 | else | |
10626 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
10627 | } |
10628 | } | |
6937bb54 | 10629 | |
341f9135 CC |
10630 | if (do_display) |
10631 | printf ("\n"); | |
10632 | } | |
10633 | ph += 8; | |
10634 | pi += 4; | |
10635 | } | |
10636 | ||
10637 | ph = phash; | |
10638 | pi = pindex; | |
10639 | if (do_display) | |
b4eb7656 | 10640 | { |
341f9135 CC |
10641 | printf ("\n"); |
10642 | printf (_(" Size table\n")); | |
10643 | printf (" slot %-16s ", | |
10644 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 10645 | } |
6937bb54 | 10646 | |
341f9135 CC |
10647 | for (j = 0; j < ncols; j++) |
10648 | { | |
6937bb54 | 10649 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
10650 | if (do_display) |
10651 | printf (" %8s", get_DW_SECT_short_name (val)); | |
10652 | } | |
6937bb54 | 10653 | |
341f9135 CC |
10654 | if (do_display) |
10655 | printf ("\n"); | |
6937bb54 | 10656 | |
341f9135 CC |
10657 | for (i = 0; i < nslots; i++) |
10658 | { | |
6937bb54 NC |
10659 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
10660 | ||
10661 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10662 | if (row != 0) |
10663 | { | |
10664 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 10665 | |
341f9135 CC |
10666 | if (do_display) |
10667 | printf (_(" [%3d] 0x%s"), | |
10668 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10669 | buf, sizeof (buf))); | |
6937bb54 | 10670 | |
341f9135 CC |
10671 | for (j = 0; j < ncols; j++) |
10672 | { | |
6937bb54 | 10673 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
10674 | if (do_display) |
10675 | printf (" %8d", val); | |
10676 | else | |
10677 | { | |
6937bb54 | 10678 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
10679 | if (dw_sect >= DW_SECT_MAX) |
10680 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10681 | else | |
341f9135 CC |
10682 | this_set [row - 1].section_sizes [dw_sect] = val; |
10683 | } | |
10684 | } | |
6937bb54 | 10685 | |
341f9135 CC |
10686 | if (do_display) |
10687 | printf ("\n"); | |
10688 | } | |
6937bb54 | 10689 | |
341f9135 CC |
10690 | ph += 8; |
10691 | pi += 4; | |
657d0d47 | 10692 | } |
657d0d47 | 10693 | } |
341f9135 | 10694 | else if (do_display) |
6937bb54 | 10695 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
10696 | |
10697 | if (do_display) | |
10698 | printf ("\n"); | |
10699 | ||
10700 | return 1; | |
10701 | } | |
10702 | ||
288f0ba2 AM |
10703 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
10704 | ||
657d0d47 CC |
10705 | /* Load the CU and TU indexes if present. This will build a list of |
10706 | section sets that we can use to associate a .debug_info.dwo section | |
10707 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
10708 | ||
43a444f9 | 10709 | static bfd_boolean |
657d0d47 CC |
10710 | load_cu_tu_indexes (void *file) |
10711 | { | |
10712 | /* If we have already loaded (or tried to load) the CU and TU indexes | |
10713 | then do not bother to repeat the task. */ | |
43a444f9 NC |
10714 | if (cu_tu_indexes_read == -1) |
10715 | { | |
10716 | cu_tu_indexes_read = TRUE; | |
521d4b19 | 10717 | |
dda8d76d | 10718 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 NC |
10719 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
10720 | cu_tu_indexes_read = FALSE; | |
10721 | ||
dda8d76d | 10722 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 NC |
10723 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
10724 | cu_tu_indexes_read = FALSE; | |
10725 | } | |
657d0d47 | 10726 | |
43a444f9 | 10727 | return (bfd_boolean) cu_tu_indexes_read; |
657d0d47 CC |
10728 | } |
10729 | ||
10730 | /* Find the set of sections that includes section SHNDX. */ | |
10731 | ||
10732 | unsigned int * | |
10733 | find_cu_tu_set (void *file, unsigned int shndx) | |
10734 | { | |
10735 | unsigned int i; | |
10736 | ||
43a444f9 NC |
10737 | if (! load_cu_tu_indexes (file)) |
10738 | return NULL; | |
657d0d47 CC |
10739 | |
10740 | /* Find SHNDX in the shndx pool. */ | |
10741 | for (i = 0; i < shndx_pool_used; i++) | |
10742 | if (shndx_pool [i] == shndx) | |
10743 | break; | |
10744 | ||
10745 | if (i >= shndx_pool_used) | |
10746 | return NULL; | |
10747 | ||
10748 | /* Now backup to find the first entry in the set. */ | |
10749 | while (i > 0 && shndx_pool [i - 1] != 0) | |
10750 | i--; | |
10751 | ||
10752 | return shndx_pool + i; | |
10753 | } | |
10754 | ||
10755 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
10756 | ||
10757 | static int | |
10758 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
10759 | { | |
10760 | return process_cu_tu_index (section, 1); | |
10761 | } | |
10762 | ||
19e6b90e L |
10763 | static int |
10764 | display_debug_not_supported (struct dwarf_section *section, | |
10765 | void *file ATTRIBUTE_UNUSED) | |
10766 | { | |
10767 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
10768 | section->name); | |
10769 | ||
10770 | return 1; | |
10771 | } | |
10772 | ||
1306a742 NC |
10773 | /* Like malloc, but takes two parameters like calloc. |
10774 | Verifies that the first parameter is not too large. | |
82b1b41b | 10775 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 10776 | |
19e6b90e L |
10777 | void * |
10778 | cmalloc (size_t nmemb, size_t size) | |
10779 | { | |
10780 | /* Check for overflow. */ | |
10781 | if (nmemb >= ~(size_t) 0 / size) | |
10782 | return NULL; | |
82b1b41b NC |
10783 | |
10784 | return xmalloc (nmemb * size); | |
19e6b90e L |
10785 | } |
10786 | ||
1306a742 NC |
10787 | /* Like xmalloc, but takes two parameters like calloc. |
10788 | Verifies that the first parameter is not too large. | |
10789 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 10790 | |
72c61a0d | 10791 | void * |
1306a742 | 10792 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
10793 | { |
10794 | /* Check for overflow. */ | |
10795 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
10796 | { |
10797 | fprintf (stderr, | |
10798 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
10799 | (long) nmemb); | |
10800 | xexit (1); | |
10801 | } | |
72c61a0d | 10802 | |
1306a742 | 10803 | return xmalloc (nmemb * size); |
72c61a0d NC |
10804 | } |
10805 | ||
1306a742 NC |
10806 | /* Like xrealloc, but takes three parameters. |
10807 | Verifies that the second parameter is not too large. | |
10808 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 10809 | |
19e6b90e | 10810 | void * |
1306a742 | 10811 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
10812 | { |
10813 | /* Check for overflow. */ | |
10814 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10815 | { |
dda8d76d NC |
10816 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
10817 | (long) nmemb); | |
8490fb40 NC |
10818 | xexit (1); |
10819 | } | |
82b1b41b | 10820 | |
1306a742 | 10821 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
10822 | } |
10823 | ||
1306a742 | 10824 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 10825 | |
19e6b90e | 10826 | void * |
1306a742 | 10827 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
10828 | { |
10829 | /* Check for overflow. */ | |
10830 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10831 | { |
dda8d76d NC |
10832 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
10833 | (long) nmemb); | |
8490fb40 NC |
10834 | xexit (1); |
10835 | } | |
82b1b41b | 10836 | |
1306a742 | 10837 | return xcalloc (nmemb, size); |
19e6b90e L |
10838 | } |
10839 | ||
dda8d76d NC |
10840 | static unsigned long |
10841 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
10842 | const unsigned char * buf, | |
10843 | bfd_size_type len) | |
10844 | { | |
10845 | static const unsigned long crc32_table[256] = | |
10846 | { | |
10847 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
10848 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
10849 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
10850 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
10851 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
10852 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
10853 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
10854 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
10855 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
10856 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
10857 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
10858 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
10859 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
10860 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
10861 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
10862 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
10863 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
10864 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
10865 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
10866 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
10867 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
10868 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
10869 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
10870 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
10871 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
10872 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
10873 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
10874 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
10875 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
10876 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
10877 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
10878 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
10879 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
10880 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
10881 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
10882 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
10883 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
10884 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
10885 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
10886 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
10887 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
10888 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
10889 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
10890 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
10891 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
10892 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
10893 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
10894 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
10895 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
10896 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
10897 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
10898 | 0x2d02ef8d | |
10899 | }; | |
10900 | const unsigned char *end; | |
10901 | ||
10902 | crc = ~crc & 0xffffffff; | |
10903 | for (end = buf + len; buf < end; ++ buf) | |
10904 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
10905 | return ~crc & 0xffffffff; | |
10906 | } | |
10907 | ||
10908 | typedef bfd_boolean (* check_func_type) (const char *, void *); | |
10909 | typedef const char * (* parse_func_type) (struct dwarf_section *, void *); | |
10910 | ||
10911 | static bfd_boolean | |
10912 | check_gnu_debuglink (const char * pathname, void * crc_pointer) | |
10913 | { | |
10914 | static unsigned char buffer [8 * 1024]; | |
10915 | FILE * f; | |
10916 | bfd_size_type count; | |
10917 | unsigned long crc = 0; | |
10918 | void * sep_data; | |
10919 | ||
10920 | sep_data = open_debug_file (pathname); | |
10921 | if (sep_data == NULL) | |
10922 | return FALSE; | |
10923 | ||
10924 | /* Yes - we are opening the file twice... */ | |
10925 | f = fopen (pathname, "rb"); | |
10926 | if (f == NULL) | |
10927 | { | |
10928 | /* Paranoia: This should never happen. */ | |
10929 | close_debug_file (sep_data); | |
10930 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
10931 | return FALSE; | |
10932 | } | |
10933 | ||
10934 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
10935 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
10936 | ||
10937 | fclose (f); | |
10938 | ||
10939 | if (crc != * (unsigned long *) crc_pointer) | |
10940 | { | |
10941 | close_debug_file (sep_data); | |
10942 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
10943 | pathname); | |
10944 | return FALSE; | |
10945 | } | |
10946 | ||
10947 | return TRUE; | |
10948 | } | |
10949 | ||
10950 | static const char * | |
10951 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
10952 | { | |
10953 | const char * name; | |
10954 | unsigned int crc_offset; | |
10955 | unsigned long * crc32 = (unsigned long *) data; | |
10956 | ||
10957 | /* The name is first. | |
10958 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
10959 | name = (const char *) section->start; | |
10960 | ||
10961 | crc_offset = strnlen (name, section->size) + 1; | |
10962 | crc_offset = (crc_offset + 3) & ~3; | |
10963 | if (crc_offset + 4 > section->size) | |
10964 | return NULL; | |
10965 | ||
10966 | * crc32 = byte_get (section->start + crc_offset, 4); | |
10967 | return name; | |
10968 | } | |
10969 | ||
10970 | static bfd_boolean | |
10971 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) | |
10972 | { | |
10973 | void * sep_data = open_debug_file (filename); | |
10974 | ||
10975 | if (sep_data == NULL) | |
10976 | return FALSE; | |
10977 | ||
10978 | /* FIXME: We should now extract the build-id in the separate file | |
10979 | and check it... */ | |
10980 | ||
10981 | return TRUE; | |
10982 | } | |
10983 | ||
10984 | typedef struct build_id_data | |
10985 | { | |
10986 | bfd_size_type len; | |
10987 | const unsigned char * data; | |
10988 | } Build_id_data; | |
10989 | ||
10990 | static const char * | |
10991 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
10992 | { | |
10993 | const char * name; | |
10994 | bfd_size_type namelen; | |
10995 | bfd_size_type id_len; | |
10996 | Build_id_data * build_id_data; | |
10997 | ||
10998 | /* The name is first. | |
10999 | The build-id follows immediately, with no padding, up to the section's end. */ | |
11000 | ||
11001 | name = (const char *) section->start; | |
11002 | namelen = strnlen (name, section->size) + 1; | |
11003 | if (namelen >= section->size) | |
11004 | return NULL; | |
11005 | ||
11006 | id_len = section->size - namelen; | |
11007 | if (id_len < 0x14) | |
11008 | return NULL; | |
11009 | ||
dfbee680 | 11010 | build_id_data = (Build_id_data *) data; |
dda8d76d NC |
11011 | build_id_data->len = id_len; |
11012 | build_id_data->data = section->start + namelen; | |
11013 | ||
dda8d76d NC |
11014 | return name; |
11015 | } | |
11016 | ||
24841daa NC |
11017 | static void |
11018 | add_separate_debug_file (const char * filename, void * handle) | |
11019 | { | |
11020 | separate_info * i = xmalloc (sizeof * i); | |
11021 | ||
11022 | i->filename = filename; | |
11023 | i->handle = handle; | |
11024 | i->next = first_separate_info; | |
11025 | first_separate_info = i; | |
11026 | } | |
11027 | ||
301a9420 AM |
11028 | #if HAVE_LIBDEBUGINFOD |
11029 | /* Query debuginfod servers for the target debuglink or debugaltlink | |
11030 | file. If successful, store the path of the file in filename and | |
11031 | return TRUE, otherwise return FALSE. */ | |
11032 | ||
11033 | static bfd_boolean | |
11034 | debuginfod_fetch_separate_debug_info (struct dwarf_section * section, | |
11035 | char ** filename, | |
11036 | void * file) | |
11037 | { | |
11038 | size_t build_id_len; | |
11039 | unsigned char * build_id; | |
11040 | ||
11041 | if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0) | |
11042 | { | |
11043 | /* Get the build-id of file. */ | |
11044 | build_id = get_build_id (file); | |
11045 | build_id_len = 0; | |
11046 | } | |
11047 | else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0) | |
11048 | { | |
11049 | /* Get the build-id of the debugaltlink file. */ | |
11050 | unsigned int filelen; | |
11051 | ||
11052 | filelen = strnlen ((const char *)section->start, section->size); | |
11053 | if (filelen == section->size) | |
11054 | /* Corrupt debugaltlink. */ | |
11055 | return FALSE; | |
11056 | ||
11057 | build_id = section->start + filelen + 1; | |
11058 | build_id_len = section->size - (filelen + 1); | |
11059 | ||
11060 | if (build_id_len == 0) | |
11061 | return FALSE; | |
11062 | } | |
11063 | else | |
11064 | return FALSE; | |
11065 | ||
11066 | if (build_id) | |
11067 | { | |
11068 | int fd; | |
11069 | debuginfod_client * client; | |
11070 | ||
11071 | client = debuginfod_begin (); | |
11072 | if (client == NULL) | |
11073 | return FALSE; | |
11074 | ||
11075 | /* Query debuginfod servers for the target file. If found its path | |
11076 | will be stored in filename. */ | |
11077 | fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename); | |
11078 | debuginfod_end (client); | |
11079 | ||
11080 | /* Only free build_id if we allocated space for a hex string | |
11081 | in get_build_id (). */ | |
11082 | if (build_id_len == 0) | |
11083 | free (build_id); | |
11084 | ||
11085 | if (fd >= 0) | |
11086 | { | |
11087 | /* File successfully retrieved. Close fd since we want to | |
11088 | use open_debug_file () on filename instead. */ | |
11089 | close (fd); | |
11090 | return TRUE; | |
11091 | } | |
11092 | } | |
11093 | ||
11094 | return FALSE; | |
11095 | } | |
11096 | #endif | |
11097 | ||
dda8d76d NC |
11098 | static void * |
11099 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 11100 | struct dwarf_section * xlink, |
dda8d76d NC |
11101 | parse_func_type parse_func, |
11102 | check_func_type check_func, | |
301a9420 AM |
11103 | void * func_data, |
11104 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
11105 | { |
11106 | const char * separate_filename; | |
24841daa | 11107 | char * debug_filename; |
dda8d76d NC |
11108 | char * canon_dir; |
11109 | size_t canon_dirlen; | |
11110 | size_t dirlen; | |
11111 | ||
2b63c337 | 11112 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
11113 | { |
11114 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 11115 | xlink->name ? xlink->name : xlink->uncompressed_name); |
ce139cd5 | 11116 | return NULL; |
dda8d76d | 11117 | } |
521d4b19 | 11118 | |
dda8d76d NC |
11119 | /* Attempt to locate the separate file. |
11120 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
11121 | ||
11122 | canon_dir = lrealpath (main_filename); | |
521d4b19 | 11123 | |
dda8d76d NC |
11124 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) |
11125 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
11126 | break; | |
11127 | canon_dir[canon_dirlen] = '\0'; | |
11128 | ||
11129 | #ifndef DEBUGDIR | |
11130 | #define DEBUGDIR "/lib/debug" | |
11131 | #endif | |
11132 | #ifndef EXTRA_DEBUG_ROOT1 | |
11133 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
11134 | #endif | |
11135 | #ifndef EXTRA_DEBUG_ROOT2 | |
11136 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
11137 | #endif | |
11138 | ||
24841daa NC |
11139 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
11140 | + canon_dirlen | |
11141 | + strlen (".debug/") | |
dda8d76d | 11142 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 11143 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
11144 | #endif |
11145 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 11146 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 11147 | #endif |
24841daa NC |
11148 | + strlen (separate_filename) |
11149 | + 1); | |
11150 | if (debug_filename == NULL) | |
dda8d76d NC |
11151 | { |
11152 | warn (_("Out of memory")); | |
3391569f | 11153 | free (canon_dir); |
dda8d76d NC |
11154 | return NULL; |
11155 | } | |
11156 | ||
11157 | /* First try in the current directory. */ | |
24841daa NC |
11158 | sprintf (debug_filename, "%s", separate_filename); |
11159 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11160 | goto found; |
11161 | ||
11162 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
11163 | sprintf (debug_filename, ".debug/%s", separate_filename); |
11164 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11165 | goto found; |
11166 | ||
11167 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
11168 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
11169 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11170 | goto found; |
11171 | ||
11172 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
11173 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
11174 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11175 | goto found; |
11176 | ||
11177 | #ifdef EXTRA_DEBUG_ROOT1 | |
11178 | /* Try the first extra debug file root. */ | |
24841daa NC |
11179 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
11180 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 11181 | goto found; |
39f0547e NC |
11182 | |
11183 | /* Try the first extra debug file root. */ | |
11184 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
11185 | if (check_func (debug_filename, func_data)) | |
11186 | goto found; | |
dda8d76d NC |
11187 | #endif |
11188 | ||
11189 | #ifdef EXTRA_DEBUG_ROOT2 | |
11190 | /* Try the second extra debug file root. */ | |
24841daa NC |
11191 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
11192 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
11193 | goto found; |
11194 | #endif | |
11195 | ||
24841daa NC |
11196 | /* Then try in the global debug_filename directory. */ |
11197 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
11198 | dirlen = strlen (DEBUGDIR) - 1; |
11199 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
11200 | strcat (debug_filename, "/"); |
11201 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 11202 | |
24841daa | 11203 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
11204 | goto found; |
11205 | ||
301a9420 AM |
11206 | #if HAVE_LIBDEBUGINFOD |
11207 | { | |
11208 | char * tmp_filename; | |
11209 | ||
11210 | if (debuginfod_fetch_separate_debug_info (xlink, | |
11211 | & tmp_filename, | |
11212 | file)) | |
11213 | { | |
11214 | /* File successfully downloaded from server, replace | |
11215 | debug_filename with the file's path. */ | |
11216 | free (debug_filename); | |
11217 | debug_filename = tmp_filename; | |
11218 | goto found; | |
11219 | } | |
11220 | } | |
11221 | #endif | |
11222 | ||
ecd65684 L |
11223 | if (do_debug_links) |
11224 | { | |
11225 | /* Failed to find the file. */ | |
11226 | warn (_("could not find separate debug file '%s'\n"), | |
11227 | separate_filename); | |
11228 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
11229 | |
11230 | #ifdef EXTRA_DEBUG_ROOT2 | |
ecd65684 L |
11231 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, |
11232 | separate_filename); | |
11233 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
11234 | #endif |
11235 | ||
11236 | #ifdef EXTRA_DEBUG_ROOT1 | |
ecd65684 L |
11237 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, |
11238 | canon_dir, separate_filename); | |
11239 | warn (_("tried: %s\n"), debug_filename); | |
39f0547e | 11240 | |
ecd65684 L |
11241 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, |
11242 | separate_filename); | |
11243 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
11244 | #endif |
11245 | ||
ecd65684 L |
11246 | sprintf (debug_filename, "%s.debug/%s", canon_dir, |
11247 | separate_filename); | |
11248 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11249 | |
ecd65684 L |
11250 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
11251 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11252 | |
ecd65684 L |
11253 | sprintf (debug_filename, ".debug/%s", separate_filename); |
11254 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11255 | |
ecd65684 L |
11256 | sprintf (debug_filename, "%s", separate_filename); |
11257 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11258 | |
301a9420 | 11259 | #if HAVE_LIBDEBUGINFOD |
ecd65684 L |
11260 | { |
11261 | char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR); | |
11262 | if (urls == NULL) | |
11263 | urls = ""; | |
301a9420 | 11264 | |
ecd65684 L |
11265 | warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls); |
11266 | } | |
301a9420 | 11267 | #endif |
ecd65684 | 11268 | } |
301a9420 | 11269 | |
dda8d76d | 11270 | free (canon_dir); |
24841daa | 11271 | free (debug_filename); |
dda8d76d NC |
11272 | return NULL; |
11273 | ||
11274 | found: | |
11275 | free (canon_dir); | |
11276 | ||
24841daa NC |
11277 | void * debug_handle; |
11278 | ||
dda8d76d | 11279 | /* Now open the file.... */ |
24841daa | 11280 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 11281 | { |
24841daa NC |
11282 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
11283 | free (debug_filename); | |
ce139cd5 | 11284 | return NULL; |
dda8d76d NC |
11285 | } |
11286 | ||
11287 | /* FIXME: We do not check to see if there are any other separate debug info | |
11288 | files that would also match. */ | |
11289 | ||
ca0e11aa NC |
11290 | if (do_debug_links) |
11291 | printf (_("\n%s: Found separate debug info file: %s\n"), main_filename, debug_filename); | |
24841daa | 11292 | add_separate_debug_file (debug_filename, debug_handle); |
dda8d76d | 11293 | |
24841daa | 11294 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 11295 | the structure returned by open_debug_file(). */ |
24841daa | 11296 | return debug_handle; |
dda8d76d NC |
11297 | } |
11298 | ||
d85bf2ba NC |
11299 | /* Attempt to load a separate dwarf object file. */ |
11300 | ||
11301 | static void * | |
24841daa | 11302 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 11303 | { |
24841daa NC |
11304 | char * separate_filename; |
11305 | void * separate_handle; | |
d85bf2ba | 11306 | |
d9d9d8ef TV |
11307 | if (IS_ABSOLUTE_PATH (name)) |
11308 | separate_filename = strdup (name); | |
11309 | else | |
11310 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
11311 | separate_filename = concat (dir, "/", name, NULL); | |
24841daa | 11312 | if (separate_filename == NULL) |
d85bf2ba NC |
11313 | { |
11314 | warn (_("Out of memory allocating dwo filename\n")); | |
11315 | return NULL; | |
11316 | } | |
11317 | ||
24841daa | 11318 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 11319 | { |
24841daa NC |
11320 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
11321 | free (separate_filename); | |
d85bf2ba NC |
11322 | return NULL; |
11323 | } | |
11324 | ||
11325 | /* FIXME: We should check the dwo_id. */ | |
11326 | ||
24841daa NC |
11327 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
11328 | add_separate_debug_file (separate_filename, separate_handle); | |
11329 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
11330 | return separate_handle; | |
d85bf2ba NC |
11331 | } |
11332 | ||
e38332c2 NC |
11333 | static void |
11334 | load_debug_sup_file (const char * main_filename, void * file) | |
11335 | { | |
11336 | if (! load_debug_section (debug_sup, file)) | |
11337 | return; /* No .debug_sup section. */ | |
11338 | ||
11339 | struct dwarf_section * section; | |
11340 | section = & debug_displays [debug_sup].section; | |
11341 | assert (section != NULL); | |
11342 | ||
11343 | if (section->start == NULL || section->size < 5) | |
11344 | { | |
11345 | warn (_(".debug_sup section is corrupt/empty\n")); | |
11346 | return; | |
11347 | } | |
11348 | ||
11349 | if (section->start[2] != 0) | |
11350 | return; /* This is a supplementary file. */ | |
11351 | ||
11352 | const char * filename = (const char *) section->start + 3; | |
11353 | if (strnlen (filename, section->size - 3) == section->size - 3) | |
11354 | { | |
11355 | warn (_("filename in .debug_sup section is corrupt\n")); | |
11356 | return; | |
11357 | } | |
11358 | ||
11359 | if (filename[0] != '/' && strchr (main_filename, '/')) | |
11360 | { | |
11361 | char * new_name; | |
11362 | if (asprintf (& new_name, "%.*s/%s", | |
11363 | (int) (strrchr (main_filename, '/') - main_filename), | |
11364 | main_filename, | |
11365 | filename) < 3) | |
11366 | warn (_("unable to construct path for supplementary debug file")); | |
11367 | else | |
11368 | filename = new_name; | |
11369 | } | |
11370 | ||
11371 | void * handle; | |
11372 | handle = open_debug_file (filename); | |
11373 | if (handle == NULL) | |
11374 | { | |
11375 | warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename); | |
11376 | return; | |
11377 | } | |
11378 | ||
11379 | printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename, filename); | |
11380 | ||
11381 | /* FIXME: Compare the checksums, if present. */ | |
11382 | add_separate_debug_file (filename, handle); | |
11383 | } | |
11384 | ||
ce139cd5 NC |
11385 | /* Load a debuglink section and/or a debugaltlink section, if either are present. |
11386 | Recursively check the loaded files for more of these sections. | |
e38332c2 NC |
11387 | Also follow any links in .debug_sup sections. |
11388 | FIXME: Should also check for DWO_* entries in the newly loaded files. */ | |
ce139cd5 NC |
11389 | |
11390 | static void | |
11391 | check_for_and_load_links (void * file, const char * filename) | |
11392 | { | |
11393 | void * handle = NULL; | |
11394 | ||
11395 | if (load_debug_section (gnu_debugaltlink, file)) | |
11396 | { | |
11397 | Build_id_data build_id_data; | |
11398 | ||
11399 | handle = load_separate_debug_info (filename, | |
11400 | & debug_displays[gnu_debugaltlink].section, | |
11401 | parse_gnu_debugaltlink, | |
11402 | check_gnu_debugaltlink, | |
11403 | & build_id_data, | |
11404 | file); | |
11405 | if (handle) | |
11406 | { | |
11407 | assert (handle == first_separate_info->handle); | |
11408 | check_for_and_load_links (first_separate_info->handle, | |
11409 | first_separate_info->filename); | |
11410 | } | |
11411 | } | |
11412 | ||
11413 | if (load_debug_section (gnu_debuglink, file)) | |
11414 | { | |
11415 | unsigned long crc32; | |
11416 | ||
11417 | handle = load_separate_debug_info (filename, | |
11418 | & debug_displays[gnu_debuglink].section, | |
11419 | parse_gnu_debuglink, | |
11420 | check_gnu_debuglink, | |
11421 | & crc32, | |
11422 | file); | |
11423 | if (handle) | |
11424 | { | |
11425 | assert (handle == first_separate_info->handle); | |
11426 | check_for_and_load_links (first_separate_info->handle, | |
11427 | first_separate_info->filename); | |
11428 | } | |
11429 | } | |
e38332c2 NC |
11430 | |
11431 | load_debug_sup_file (filename, file); | |
ce139cd5 NC |
11432 | } |
11433 | ||
24841daa NC |
11434 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
11435 | Returns TRUE if any were found, FALSE otherwise. | |
11436 | If TRUE is returned then the linked list starting at first_separate_info | |
11437 | will be populated with open file handles. */ | |
dda8d76d | 11438 | |
24841daa NC |
11439 | bfd_boolean |
11440 | load_separate_debug_files (void * file, const char * filename) | |
dda8d76d | 11441 | { |
8de3a6e2 NC |
11442 | /* Skip this operation if we are not interested in debug links. */ |
11443 | if (! do_follow_links && ! do_debug_links) | |
24841daa | 11444 | return FALSE; |
8de3a6e2 | 11445 | |
24841daa | 11446 | /* See if there are any dwo links. */ |
d85bf2ba NC |
11447 | if (load_debug_section (str, file) |
11448 | && load_debug_section (abbrev, file) | |
11449 | && load_debug_section (info, file)) | |
11450 | { | |
24841daa | 11451 | free_dwo_info (); |
d85bf2ba | 11452 | |
50ea0877 NC |
11453 | if (process_debug_info (& debug_displays[info].section, file, abbrev, |
11454 | TRUE, FALSE)) | |
d85bf2ba | 11455 | { |
24841daa NC |
11456 | bfd_boolean introduced = FALSE; |
11457 | dwo_info * dwinfo; | |
11458 | const char * dir = NULL; | |
11459 | const char * id = NULL; | |
50ea0877 | 11460 | const char * name = NULL; |
24841daa NC |
11461 | |
11462 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 11463 | { |
50ea0877 | 11464 | /* Accumulate NAME, DIR and ID fields. */ |
24841daa | 11465 | switch (dwinfo->type) |
d85bf2ba | 11466 | { |
24841daa | 11467 | case DWO_NAME: |
50ea0877 NC |
11468 | if (name != NULL) |
11469 | warn (_("Multiple DWO_NAMEs encountered for the same CU\n")); | |
11470 | name = dwinfo->value; | |
11471 | break; | |
11472 | ||
11473 | case DWO_DIR: | |
11474 | /* There can be multiple DW_AT_comp_dir entries in a CU, | |
11475 | so do not complain. */ | |
11476 | dir = dwinfo->value; | |
11477 | break; | |
11478 | ||
11479 | case DWO_ID: | |
11480 | if (id != NULL) | |
11481 | warn (_("multiple DWO_IDs encountered for the same CU\n")); | |
11482 | id = dwinfo->value; | |
11483 | break; | |
11484 | ||
11485 | default: | |
11486 | error (_("Unexpected DWO INFO type")); | |
11487 | break; | |
11488 | } | |
11489 | ||
11490 | /* If we have reached the end of our list, or we are changing | |
11491 | CUs, then display the information that we have accumulated | |
11492 | so far. */ | |
11493 | if (name != NULL | |
11494 | && (dwinfo->next == NULL | |
11495 | || dwinfo->next->cu_offset != dwinfo->cu_offset)) | |
11496 | { | |
24841daa NC |
11497 | if (do_debug_links) |
11498 | { | |
11499 | if (! introduced) | |
11500 | { | |
11501 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
11502 | debug_displays [info].section.uncompressed_name); | |
11503 | introduced = TRUE; | |
11504 | } | |
d85bf2ba | 11505 | |
50ea0877 | 11506 | printf (_(" Name: %s\n"), name); |
24841daa NC |
11507 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); |
11508 | if (id != NULL) | |
11509 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
11510 | else | |
50ea0877 | 11511 | printf (_(" ID: <not specified>\n")); |
24841daa NC |
11512 | printf ("\n\n"); |
11513 | } | |
11514 | ||
11515 | if (do_follow_links) | |
50ea0877 | 11516 | load_dwo_file (filename, name, dir, id); |
24841daa | 11517 | |
50ea0877 | 11518 | name = dir = id = NULL; |
24841daa | 11519 | } |
d85bf2ba NC |
11520 | } |
11521 | } | |
11522 | } | |
11523 | ||
dda8d76d | 11524 | if (! do_follow_links) |
8de3a6e2 NC |
11525 | /* The other debug links will be displayed by display_debug_links() |
11526 | so we do not need to do any further processing here. */ | |
24841daa | 11527 | return FALSE; |
dda8d76d NC |
11528 | |
11529 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
dda8d76d | 11530 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ |
d85bf2ba | 11531 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 11532 | |
ce139cd5 | 11533 | check_for_and_load_links (file, filename); |
24841daa NC |
11534 | if (first_separate_info != NULL) |
11535 | return TRUE; | |
11536 | ||
dda8d76d | 11537 | do_follow_links = 0; |
24841daa | 11538 | return FALSE; |
521d4b19 | 11539 | } |
dda8d76d | 11540 | |
19e6b90e L |
11541 | void |
11542 | free_debug_memory (void) | |
11543 | { | |
3f5e193b | 11544 | unsigned int i; |
19e6b90e | 11545 | |
bcd213b2 | 11546 | free_all_abbrevs (); |
19e6b90e | 11547 | |
bcd213b2 NC |
11548 | free (cu_abbrev_map); |
11549 | cu_abbrev_map = NULL; | |
11550 | next_free_abbrev_map_entry = 0; | |
521d4b19 | 11551 | |
288f0ba2 AM |
11552 | free (shndx_pool); |
11553 | shndx_pool = NULL; | |
11554 | shndx_pool_size = 0; | |
11555 | shndx_pool_used = 0; | |
11556 | free (cu_sets); | |
11557 | cu_sets = NULL; | |
11558 | cu_count = 0; | |
11559 | free (tu_sets); | |
11560 | tu_sets = NULL; | |
11561 | tu_count = 0; | |
11562 | ||
11563 | memset (level_type_signed, 0, sizeof level_type_signed); | |
11564 | cu_tu_indexes_read = -1; | |
11565 | ||
19e6b90e | 11566 | for (i = 0; i < max; i++) |
3f5e193b | 11567 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 11568 | |
cc86f28f | 11569 | if (debug_information != NULL) |
19e6b90e | 11570 | { |
82fcdb39 | 11571 | for (i = 0; i < alloc_num_debug_info_entries; i++) |
19e6b90e | 11572 | { |
82fcdb39 | 11573 | if (debug_information [i].max_loc_offsets) |
19e6b90e | 11574 | { |
82fcdb39 AM |
11575 | free (debug_information [i].loc_offsets); |
11576 | free (debug_information [i].have_frame_base); | |
19e6b90e | 11577 | } |
82fcdb39 AM |
11578 | if (debug_information [i].max_range_lists) |
11579 | free (debug_information [i].range_lists); | |
19e6b90e L |
11580 | } |
11581 | free (debug_information); | |
11582 | debug_information = NULL; | |
82b1b41b | 11583 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 11584 | } |
dda8d76d | 11585 | |
24841daa NC |
11586 | separate_info * d; |
11587 | separate_info * next; | |
dda8d76d | 11588 | |
24841daa NC |
11589 | for (d = first_separate_info; d != NULL; d = next) |
11590 | { | |
11591 | close_debug_file (d->handle); | |
11592 | free ((void *) d->filename); | |
11593 | next = d->next; | |
11594 | free ((void *) d); | |
dda8d76d | 11595 | } |
24841daa | 11596 | first_separate_info = NULL; |
521d4b19 | 11597 | |
24841daa | 11598 | free_dwo_info (); |
19e6b90e L |
11599 | } |
11600 | ||
4cb93e3b TG |
11601 | void |
11602 | dwarf_select_sections_by_names (const char *names) | |
11603 | { | |
11604 | typedef struct | |
11605 | { | |
11606 | const char * option; | |
11607 | int * variable; | |
f9f0e732 | 11608 | int val; |
4cb93e3b TG |
11609 | } |
11610 | debug_dump_long_opts; | |
11611 | ||
11612 | static const debug_dump_long_opts opts_table [] = | |
11613 | { | |
11614 | /* Please keep this table alpha- sorted. */ | |
11615 | { "Ranges", & do_debug_ranges, 1 }, | |
11616 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 11617 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 11618 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
11619 | { "cu_index", & do_debug_cu_index, 1 }, |
11620 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 11621 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
11622 | { "frames", & do_debug_frames, 1 }, |
11623 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
11624 | /* The special .gdb_index section. */ |
11625 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
11626 | { "info", & do_debug_info, 1 }, |
11627 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 11628 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
11629 | { "loc", & do_debug_loc, 1 }, |
11630 | { "macro", & do_debug_macinfo, 1 }, | |
c46b7066 | 11631 | { "no-follow-links", & do_follow_links, 0 }, |
4cb93e3b | 11632 | { "pubnames", & do_debug_pubnames, 1 }, |
357da287 | 11633 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 11634 | /* This entry is for compatibility |
4cb93e3b TG |
11635 | with earlier versions of readelf. */ |
11636 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 11637 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 11638 | { "str", & do_debug_str, 1 }, |
e4b7104b | 11639 | { "str-offsets", & do_debug_str_offsets, 1 }, |
6f875884 TG |
11640 | /* These trace_* sections are used by Itanium VMS. */ |
11641 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
11642 | { "trace_aranges", & do_trace_aranges, 1 }, | |
11643 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
11644 | { NULL, NULL, 0 } |
11645 | }; | |
11646 | ||
11647 | const char *p; | |
467c65bc | 11648 | |
4cb93e3b TG |
11649 | p = names; |
11650 | while (*p) | |
11651 | { | |
11652 | const debug_dump_long_opts * entry; | |
467c65bc | 11653 | |
4cb93e3b TG |
11654 | for (entry = opts_table; entry->option; entry++) |
11655 | { | |
11656 | size_t len = strlen (entry->option); | |
467c65bc | 11657 | |
4cb93e3b TG |
11658 | if (strncmp (p, entry->option, len) == 0 |
11659 | && (p[len] == ',' || p[len] == '\0')) | |
11660 | { | |
c46b7066 | 11661 | * entry->variable = entry->val; |
467c65bc | 11662 | |
4cb93e3b TG |
11663 | /* The --debug-dump=frames-interp option also |
11664 | enables the --debug-dump=frames option. */ | |
11665 | if (do_debug_frames_interp) | |
11666 | do_debug_frames = 1; | |
11667 | ||
11668 | p += len; | |
11669 | break; | |
11670 | } | |
11671 | } | |
467c65bc | 11672 | |
4cb93e3b TG |
11673 | if (entry->option == NULL) |
11674 | { | |
11675 | warn (_("Unrecognized debug option '%s'\n"), p); | |
11676 | p = strchr (p, ','); | |
11677 | if (p == NULL) | |
11678 | break; | |
11679 | } | |
467c65bc | 11680 | |
4cb93e3b TG |
11681 | if (*p == ',') |
11682 | p++; | |
11683 | } | |
11684 | } | |
11685 | ||
11686 | void | |
11687 | dwarf_select_sections_by_letters (const char *letters) | |
11688 | { | |
91d6fa6a | 11689 | unsigned int lindex = 0; |
4cb93e3b | 11690 | |
91d6fa6a NC |
11691 | while (letters[lindex]) |
11692 | switch (letters[lindex++]) | |
4cb93e3b | 11693 | { |
dda8d76d NC |
11694 | case 'A': do_debug_addr = 1; break; |
11695 | case 'a': do_debug_abbrevs = 1; break; | |
11696 | case 'c': do_debug_cu_index = 1; break; | |
11697 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
11698 | case 'f': do_debug_frames = 1; break; | |
11699 | case 'g': do_gdb_index = 1; break; | |
11700 | case 'i': do_debug_info = 1; break; | |
11701 | case 'K': do_follow_links = 1; break; | |
c46b7066 | 11702 | case 'N': do_follow_links = 0; break; |
dda8d76d NC |
11703 | case 'k': do_debug_links = 1; break; |
11704 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
11705 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
11706 | case 'm': do_debug_macinfo = 1; break; | |
e4b7104b | 11707 | case 'O': do_debug_str_offsets = 1; break; |
dda8d76d NC |
11708 | case 'o': do_debug_loc = 1; break; |
11709 | case 'p': do_debug_pubnames = 1; break; | |
11710 | case 'R': do_debug_ranges = 1; break; | |
11711 | case 'r': do_debug_aranges = 1; break; | |
11712 | case 's': do_debug_str = 1; break; | |
11713 | case 'T': do_trace_aranges = 1; break; | |
11714 | case 't': do_debug_pubtypes = 1; break; | |
11715 | case 'U': do_trace_info = 1; break; | |
11716 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 11717 | |
4cb93e3b | 11718 | default: |
7cc78d07 | 11719 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
11720 | break; |
11721 | } | |
11722 | } | |
11723 | ||
11724 | void | |
11725 | dwarf_select_sections_all (void) | |
11726 | { | |
11727 | do_debug_info = 1; | |
11728 | do_debug_abbrevs = 1; | |
11729 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
11730 | do_debug_pubnames = 1; | |
f9f0e732 | 11731 | do_debug_pubtypes = 1; |
4cb93e3b TG |
11732 | do_debug_aranges = 1; |
11733 | do_debug_ranges = 1; | |
11734 | do_debug_frames = 1; | |
11735 | do_debug_macinfo = 1; | |
11736 | do_debug_str = 1; | |
11737 | do_debug_loc = 1; | |
5bbdf3d5 | 11738 | do_gdb_index = 1; |
6f875884 TG |
11739 | do_trace_info = 1; |
11740 | do_trace_abbrevs = 1; | |
11741 | do_trace_aranges = 1; | |
657d0d47 CC |
11742 | do_debug_addr = 1; |
11743 | do_debug_cu_index = 1; | |
dda8d76d NC |
11744 | do_follow_links = 1; |
11745 | do_debug_links = 1; | |
e4b7104b | 11746 | do_debug_str_offsets = 1; |
4cb93e3b TG |
11747 | } |
11748 | ||
208599d9 AM |
11749 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0 |
11750 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0 | |
dda8d76d NC |
11751 | |
11752 | /* N.B. The order here must match the order in section_display_enum. */ | |
11753 | ||
19e6b90e L |
11754 | struct dwarf_section_display debug_displays[] = |
11755 | { | |
dda8d76d NC |
11756 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, |
11757 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE }, | |
11758 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
11759 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE }, | |
11760 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
11761 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE }, | |
11762 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, | |
11763 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
11764 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
11765 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
11766 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
11767 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
11768 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
11769 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
11770 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE }, | |
11771 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, | |
11772 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
11773 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
11774 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
11775 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
11776 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE }, | |
11777 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
11778 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE }, | |
11779 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE }, | |
11780 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE }, | |
11781 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE }, | |
11782 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE }, | |
11783 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE }, | |
11784 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
11785 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE }, | |
11786 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
11787 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
11788 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
11789 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
11790 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE }, | |
e4b7104b NC |
11791 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, TRUE }, |
11792 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, TRUE }, | |
dda8d76d NC |
11793 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE }, |
11794 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
11795 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
11796 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
11797 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
e38332c2 | 11798 | { { ".debug_sup", "", NO_ABBREVS }, display_debug_sup, &do_debug_links, FALSE }, |
dda8d76d NC |
11799 | /* Separate debug info files can containt their own .debug_str section, |
11800 | and this might be in *addition* to a .debug_str section already present | |
11801 | in the main file. Hence we need to have two entries for .debug_str. */ | |
11802 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
19e6b90e | 11803 | }; |
b451e98a JK |
11804 | |
11805 | /* A static assertion. */ | |
11806 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |