Commit | Line | Data |
---|---|---|
19e6b90e | 1 | /* dwarf.c -- display DWARF contents of a BFD binary file |
b3adc24a | 2 | Copyright (C) 2005-2020 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 | ||
61364358 JK |
39 | #undef MAX |
40 | #undef MIN | |
41 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) | |
42 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | |
19e6b90e | 43 | |
18464d4d | 44 | static const char *regname (unsigned int regno, int row); |
1296bc99 | 45 | static const char *regname_internal_by_table_only (unsigned int regno); |
18464d4d | 46 | |
19e6b90e L |
47 | static int have_frame_base; |
48 | static int need_base_address; | |
49 | ||
19e6b90e | 50 | static unsigned int num_debug_info_entries = 0; |
82b1b41b | 51 | static unsigned int alloc_num_debug_info_entries = 0; |
19e6b90e | 52 | static debug_info *debug_information = NULL; |
cc86f28f NC |
53 | /* Special value for num_debug_info_entries to indicate |
54 | that the .debug_info section could not be loaded/parsed. */ | |
55 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 | |
19e6b90e | 56 | |
24841daa NC |
57 | /* A .debug_info section can contain multiple links to separate |
58 | DWO object files. We use these structures to record these links. */ | |
59 | typedef enum dwo_type | |
60 | { | |
61 | DWO_NAME, | |
62 | DWO_DIR, | |
63 | DWO_ID | |
64 | } dwo_type; | |
65 | ||
66 | typedef struct dwo_info | |
67 | { | |
68 | dwo_type type; | |
69 | const char * value; | |
70 | struct dwo_info * next; | |
71 | } dwo_info; | |
72 | ||
73 | static dwo_info * first_dwo_info = NULL; | |
74 | static bfd_boolean need_dwo_info; | |
75 | ||
76 | separate_info * first_separate_info = NULL; | |
d85bf2ba | 77 | |
77ef8654 | 78 | unsigned int eh_addr_size; |
19e6b90e L |
79 | |
80 | int do_debug_info; | |
81 | int do_debug_abbrevs; | |
82 | int do_debug_lines; | |
83 | int do_debug_pubnames; | |
f9f0e732 | 84 | int do_debug_pubtypes; |
19e6b90e L |
85 | int do_debug_aranges; |
86 | int do_debug_ranges; | |
87 | int do_debug_frames; | |
88 | int do_debug_frames_interp; | |
89 | int do_debug_macinfo; | |
90 | int do_debug_str; | |
e4b7104b | 91 | int do_debug_str_offsets; |
19e6b90e | 92 | int do_debug_loc; |
5bbdf3d5 | 93 | int do_gdb_index; |
6f875884 TG |
94 | int do_trace_info; |
95 | int do_trace_abbrevs; | |
96 | int do_trace_aranges; | |
657d0d47 CC |
97 | int do_debug_addr; |
98 | int do_debug_cu_index; | |
a262ae96 | 99 | int do_wide; |
dda8d76d NC |
100 | int do_debug_links; |
101 | int do_follow_links; | |
546cb2d8 | 102 | bfd_boolean do_checks; |
19e6b90e | 103 | |
fd2f0033 TT |
104 | int dwarf_cutoff_level = -1; |
105 | unsigned long dwarf_start_die; | |
106 | ||
4723351a CC |
107 | int dwarf_check = 0; |
108 | ||
9f272209 AO |
109 | /* Convenient constant, to avoid having to cast -1 to dwarf_vma when |
110 | testing whether e.g. a locview list is present. */ | |
111 | static const dwarf_vma vm1 = -1; | |
112 | ||
341f9135 CC |
113 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
114 | sections. For version 1 package files, each set is stored in SHNDX_POOL | |
115 | as a zero-terminated list of section indexes comprising one set of debug | |
116 | sections from a .dwo file. */ | |
117 | ||
341f9135 CC |
118 | static unsigned int *shndx_pool = NULL; |
119 | static unsigned int shndx_pool_size = 0; | |
120 | static unsigned int shndx_pool_used = 0; | |
121 | ||
122 | /* For version 2 package files, each set contains an array of section offsets | |
123 | and an array of section sizes, giving the offset and size of the | |
124 | contribution from a CU or TU within one of the debug sections. | |
125 | When displaying debug info from a package file, we need to use these | |
126 | tables to locate the corresponding contributions to each section. */ | |
127 | ||
128 | struct cu_tu_set | |
129 | { | |
ec1b0fbb NC |
130 | uint64_t signature; |
131 | dwarf_vma section_offsets[DW_SECT_MAX]; | |
132 | size_t section_sizes[DW_SECT_MAX]; | |
341f9135 CC |
133 | }; |
134 | ||
135 | static int cu_count = 0; | |
136 | static int tu_count = 0; | |
137 | static struct cu_tu_set *cu_sets = NULL; | |
138 | static struct cu_tu_set *tu_sets = NULL; | |
139 | ||
43a444f9 | 140 | static bfd_boolean load_cu_tu_indexes (void *); |
341f9135 | 141 | |
ec1b0fbb NC |
142 | /* An array that indicates for a given level of CU nesting whether |
143 | the latest DW_AT_type seen for that level was a signed type or | |
144 | an unsigned type. */ | |
145 | #define MAX_CU_NESTING (1 << 8) | |
146 | static bfd_boolean level_type_signed[MAX_CU_NESTING]; | |
147 | ||
4cb93e3b TG |
148 | /* Values for do_debug_lines. */ |
149 | #define FLAG_DEBUG_LINES_RAW 1 | |
150 | #define FLAG_DEBUG_LINES_DECODED 2 | |
151 | ||
77ef8654 | 152 | static unsigned int |
f1c4cc75 RH |
153 | size_of_encoded_value (int encoding) |
154 | { | |
155 | switch (encoding & 0x7) | |
156 | { | |
157 | default: /* ??? */ | |
158 | case 0: return eh_addr_size; | |
159 | case 2: return 2; | |
160 | case 3: return 4; | |
161 | case 4: return 8; | |
162 | } | |
163 | } | |
164 | ||
165 | static dwarf_vma | |
041830e0 | 166 | get_encoded_value (unsigned char **pdata, |
bad62cf5 | 167 | int encoding, |
041830e0 NC |
168 | struct dwarf_section *section, |
169 | unsigned char * end) | |
f1c4cc75 | 170 | { |
041830e0 | 171 | unsigned char * data = * pdata; |
6937bb54 | 172 | unsigned int size = size_of_encoded_value (encoding); |
bad62cf5 | 173 | dwarf_vma val; |
f1c4cc75 | 174 | |
041830e0 NC |
175 | if (data + size >= end) |
176 | { | |
177 | warn (_("Encoded value extends past end of section\n")); | |
178 | * pdata = end; | |
179 | return 0; | |
180 | } | |
181 | ||
6937bb54 NC |
182 | /* PR 17512: file: 002-829853-0.004. */ |
183 | if (size > 8) | |
184 | { | |
185 | warn (_("Encoded size of %d is too large to read\n"), size); | |
186 | * pdata = end; | |
187 | return 0; | |
188 | } | |
189 | ||
0a9d414a NC |
190 | /* PR 17512: file: 1085-5603-0.004. */ |
191 | if (size == 0) | |
192 | { | |
193 | warn (_("Encoded size of 0 is too small to read\n")); | |
194 | * pdata = end; | |
195 | return 0; | |
196 | } | |
197 | ||
f1c4cc75 | 198 | if (encoding & DW_EH_PE_signed) |
bad62cf5 | 199 | val = byte_get_signed (data, size); |
f1c4cc75 | 200 | else |
bad62cf5 AM |
201 | val = byte_get (data, size); |
202 | ||
203 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
204 | val += section->address + (data - section->start); | |
041830e0 NC |
205 | |
206 | * pdata = data + size; | |
bad62cf5 | 207 | return val; |
f1c4cc75 RH |
208 | } |
209 | ||
4c219c2e AM |
210 | #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG |
211 | # ifndef __MINGW32__ | |
212 | # define DWARF_VMA_FMT "ll" | |
213 | # define DWARF_VMA_FMT_LONG "%16.16llx" | |
214 | # else | |
215 | # define DWARF_VMA_FMT "I64" | |
216 | # define DWARF_VMA_FMT_LONG "%016I64x" | |
217 | # endif | |
2e14fae2 | 218 | #else |
4c219c2e AM |
219 | # define DWARF_VMA_FMT "l" |
220 | # define DWARF_VMA_FMT_LONG "%16.16lx" | |
2d9472a2 NC |
221 | #endif |
222 | ||
bf5117e3 NC |
223 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
224 | buffer containing the converted VALUE. The value is converted according | |
225 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then | |
226 | it specifies the maximum number of bytes to be displayed in the converted | |
227 | value and FMTCH is ignored - hex is always used. */ | |
467c65bc | 228 | |
47704ddf | 229 | static const char * |
bf5117e3 | 230 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
47704ddf KT |
231 | { |
232 | /* As dwarf_vmatoa is used more then once in a printf call | |
233 | for output, we are cycling through an fixed array of pointers | |
234 | for return address. */ | |
235 | static int buf_pos = 0; | |
467c65bc NC |
236 | static struct dwarf_vmatoa_buf |
237 | { | |
47704ddf KT |
238 | char place[64]; |
239 | } buf[16]; | |
47704ddf KT |
240 | char *ret; |
241 | ||
47704ddf | 242 | ret = buf[buf_pos++].place; |
467c65bc | 243 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf | 244 | |
bf5117e3 NC |
245 | if (num_bytes) |
246 | { | |
222c2bf0 | 247 | /* Printf does not have a way of specifying a maximum field width for an |
bf5117e3 NC |
248 | integer value, so we print the full value into a buffer and then select |
249 | the precision we need. */ | |
250 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); | |
251 | if (num_bytes > 8) | |
252 | num_bytes = 8; | |
253 | return ret + (16 - 2 * num_bytes); | |
254 | } | |
255 | else | |
256 | { | |
257 | char fmt[32]; | |
258 | ||
0bae9e9e NC |
259 | if (fmtch) |
260 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); | |
261 | else | |
262 | sprintf (fmt, "%%%s", DWARF_VMA_FMT); | |
bf5117e3 NC |
263 | snprintf (ret, sizeof (buf[0].place), fmt, value); |
264 | return ret; | |
265 | } | |
266 | } | |
47704ddf | 267 | |
bf5117e3 NC |
268 | static inline const char * |
269 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) | |
270 | { | |
271 | return dwarf_vmatoa_1 (fmtch, value, 0); | |
272 | } | |
273 | ||
274 | /* Print a dwarf_vma value (typically an address, offset or length) in | |
275 | hexadecimal format, followed by a space. The length of the VALUE (and | |
276 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ | |
277 | ||
278 | static void | |
279 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) | |
280 | { | |
281 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); | |
47704ddf KT |
282 | } |
283 | ||
9f272209 AO |
284 | /* Print a view number in hexadecimal value, with the same width |
285 | print_dwarf_vma would have printed it with the same num_bytes. | |
286 | Print blanks for zero view, unless force is nonzero. */ | |
287 | ||
288 | static void | |
289 | print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force) | |
290 | { | |
291 | int len; | |
292 | if (!num_bytes) | |
293 | len = 4; | |
294 | else | |
295 | len = num_bytes * 2; | |
296 | ||
297 | assert (value == (unsigned long) value); | |
298 | if (value || force) | |
299 | printf ("v%0*lx ", len - 1, (unsigned long) value); | |
300 | else | |
301 | printf ("%*s", len + 1, ""); | |
302 | } | |
303 | ||
74bc6052 CC |
304 | /* Format a 64-bit value, given as two 32-bit values, in hex. |
305 | For reentrancy, this uses a buffer provided by the caller. */ | |
306 | ||
307 | static const char * | |
308 | dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, | |
309 | unsigned int buf_len) | |
310 | { | |
311 | int len = 0; | |
312 | ||
313 | if (hvalue == 0) | |
314 | snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); | |
315 | else | |
316 | { | |
317 | len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); | |
318 | snprintf (buf + len, buf_len - len, | |
319 | "%08" DWARF_VMA_FMT "x", lvalue); | |
320 | } | |
321 | ||
322 | return buf; | |
323 | } | |
324 | ||
f6f0e17b NC |
325 | /* Read in a LEB128 encoded value starting at address DATA. |
326 | If SIGN is true, return a signed LEB128 value. | |
327 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
cd30bcef AM |
328 | If STATUS_RETURN in not NULL, return with bit 0 (LSB) set if the |
329 | terminating byte was not found and with bit 1 set if the value | |
330 | overflows a dwarf_vma. | |
f6f0e17b NC |
331 | No bytes will be read at address END or beyond. */ |
332 | ||
467c65bc | 333 | dwarf_vma |
f6f0e17b | 334 | read_leb128 (unsigned char *data, |
cd30bcef | 335 | const unsigned char *const end, |
f6f0e17b | 336 | bfd_boolean sign, |
cd30bcef AM |
337 | unsigned int *length_return, |
338 | int *status_return) | |
19e6b90e | 339 | { |
467c65bc | 340 | dwarf_vma result = 0; |
19e6b90e L |
341 | unsigned int num_read = 0; |
342 | unsigned int shift = 0; | |
cd30bcef | 343 | int status = 1; |
19e6b90e | 344 | |
f6f0e17b | 345 | while (data < end) |
19e6b90e | 346 | { |
cd30bcef | 347 | unsigned char byte = *data++; |
08d7da7d NC |
348 | bfd_boolean cont = (byte & 0x80) ? TRUE : FALSE; |
349 | ||
350 | byte &= 0x7f; | |
19e6b90e L |
351 | num_read++; |
352 | ||
cd30bcef AM |
353 | if (shift < sizeof (result) * 8) |
354 | { | |
08d7da7d NC |
355 | result |= ((dwarf_vma) byte) << shift; |
356 | if (sign) | |
357 | { | |
358 | if ((((dwarf_signed_vma) result >> shift) & 0x7f) != byte) | |
359 | /* Overflow. */ | |
360 | status |= 2; | |
361 | } | |
362 | else if ((result >> shift) != byte) | |
363 | { | |
364 | /* Overflow. */ | |
365 | status |= 2; | |
366 | } | |
367 | ||
cd30bcef AM |
368 | shift += 7; |
369 | } | |
08d7da7d NC |
370 | else if (byte != 0) |
371 | { | |
372 | status |= 2; | |
373 | } | |
19e6b90e | 374 | |
08d7da7d | 375 | if (!cont) |
cd30bcef AM |
376 | { |
377 | status &= ~1; | |
378 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) | |
379 | result |= -((dwarf_vma) 1 << shift); | |
380 | break; | |
381 | } | |
19e6b90e | 382 | } |
19e6b90e L |
383 | |
384 | if (length_return != NULL) | |
385 | *length_return = num_read; | |
cd30bcef AM |
386 | if (status_return != NULL) |
387 | *status_return = status; | |
19e6b90e L |
388 | |
389 | return result; | |
390 | } | |
391 | ||
d11ae95e NC |
392 | /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value. |
393 | Checks to make sure that the read will not reach or pass END | |
394 | and that VAL is big enough to hold AMOUNT bytes. */ | |
0c588247 NC |
395 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
396 | do \ | |
397 | { \ | |
398 | unsigned int amount = (AMOUNT); \ | |
34b9f729 NC |
399 | if (sizeof (VAL) < amount) \ |
400 | { \ | |
d3a49aa8 AM |
401 | error (ngettext ("internal error: attempt to read %d byte " \ |
402 | "of data in to %d sized variable", \ | |
403 | "internal error: attempt to read %d bytes " \ | |
404 | "of data in to %d sized variable", \ | |
405 | amount), \ | |
34b9f729 NC |
406 | amount, (int) sizeof (VAL)); \ |
407 | amount = sizeof (VAL); \ | |
408 | } \ | |
0c588247 NC |
409 | if (((PTR) + amount) >= (END)) \ |
410 | { \ | |
411 | if ((PTR) < (END)) \ | |
412 | amount = (END) - (PTR); \ | |
413 | else \ | |
414 | amount = 0; \ | |
415 | } \ | |
6937bb54 | 416 | if (amount == 0 || amount > 8) \ |
0c588247 | 417 | VAL = 0; \ |
6937bb54 NC |
418 | else \ |
419 | VAL = byte_get ((PTR), amount); \ | |
0c588247 NC |
420 | } \ |
421 | while (0) | |
422 | ||
d11ae95e | 423 | /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
424 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
425 | do \ | |
426 | { \ | |
427 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
428 | PTR += AMOUNT; \ | |
429 | } \ | |
430 | while (0) | |
431 | ||
d11ae95e | 432 | /* Like SAFE_BYTE_GET, but reads a signed value. */ |
0c588247 NC |
433 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
434 | do \ | |
435 | { \ | |
436 | unsigned int amount = (AMOUNT); \ | |
437 | if (((PTR) + amount) >= (END)) \ | |
438 | { \ | |
439 | if ((PTR) < (END)) \ | |
440 | amount = (END) - (PTR); \ | |
441 | else \ | |
442 | amount = 0; \ | |
443 | } \ | |
444 | if (amount) \ | |
445 | VAL = byte_get_signed ((PTR), amount); \ | |
446 | else \ | |
447 | VAL = 0; \ | |
448 | } \ | |
449 | while (0) | |
450 | ||
d11ae95e | 451 | /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
452 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
453 | do \ | |
454 | { \ | |
455 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
456 | PTR += AMOUNT; \ | |
457 | } \ | |
458 | while (0) | |
459 | ||
460 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ | |
461 | do \ | |
462 | { \ | |
87bc83b3 | 463 | if (((PTR) + 8) <= (END)) \ |
0c588247 NC |
464 | { \ |
465 | byte_get_64 ((PTR), (HIGH), (LOW)); \ | |
466 | } \ | |
467 | else \ | |
468 | { \ | |
0c588247 NC |
469 | * (LOW) = * (HIGH) = 0; \ |
470 | } \ | |
471 | } \ | |
472 | while (0) | |
473 | ||
19e6b90e L |
474 | typedef struct State_Machine_Registers |
475 | { | |
467c65bc | 476 | dwarf_vma address; |
ba8826a8 | 477 | unsigned int view; |
19e6b90e L |
478 | unsigned int file; |
479 | unsigned int line; | |
480 | unsigned int column; | |
481 | int is_stmt; | |
482 | int basic_block; | |
a233b20c JJ |
483 | unsigned char op_index; |
484 | unsigned char end_sequence; | |
ba8826a8 AO |
485 | /* This variable hold the number of the last entry seen |
486 | in the File Table. */ | |
19e6b90e L |
487 | unsigned int last_file_entry; |
488 | } SMR; | |
489 | ||
490 | static SMR state_machine_regs; | |
491 | ||
492 | static void | |
493 | reset_state_machine (int is_stmt) | |
494 | { | |
495 | state_machine_regs.address = 0; | |
ba8826a8 | 496 | state_machine_regs.view = 0; |
a233b20c | 497 | state_machine_regs.op_index = 0; |
19e6b90e L |
498 | state_machine_regs.file = 1; |
499 | state_machine_regs.line = 1; | |
500 | state_machine_regs.column = 0; | |
501 | state_machine_regs.is_stmt = is_stmt; | |
502 | state_machine_regs.basic_block = 0; | |
503 | state_machine_regs.end_sequence = 0; | |
504 | state_machine_regs.last_file_entry = 0; | |
505 | } | |
506 | ||
507 | /* Handled an extend line op. | |
508 | Returns the number of bytes read. */ | |
509 | ||
cd30bcef | 510 | static size_t |
f6f0e17b NC |
511 | process_extended_line_op (unsigned char * data, |
512 | int is_stmt, | |
513 | unsigned char * end) | |
19e6b90e L |
514 | { |
515 | unsigned char op_code; | |
cd30bcef | 516 | size_t len, header_len; |
19e6b90e | 517 | unsigned char *name; |
143a3db0 | 518 | unsigned char *orig_data = data; |
cd30bcef | 519 | dwarf_vma adr, val; |
19e6b90e | 520 | |
cd30bcef AM |
521 | READ_ULEB (len, data, end); |
522 | header_len = data - orig_data; | |
19e6b90e | 523 | |
cd30bcef | 524 | if (len == 0 || data == end || len > (size_t) (end - data)) |
19e6b90e | 525 | { |
f41e4712 | 526 | warn (_("Badly formed extended line op encountered!\n")); |
cd30bcef | 527 | return header_len; |
19e6b90e L |
528 | } |
529 | ||
19e6b90e L |
530 | op_code = *data++; |
531 | ||
532 | printf (_(" Extended opcode %d: "), op_code); | |
533 | ||
534 | switch (op_code) | |
535 | { | |
536 | case DW_LNE_end_sequence: | |
537 | printf (_("End of Sequence\n\n")); | |
538 | reset_state_machine (is_stmt); | |
539 | break; | |
540 | ||
541 | case DW_LNE_set_address: | |
6937bb54 | 542 | /* PR 17512: file: 002-100480-0.004. */ |
cd30bcef | 543 | if (len - 1 > 8) |
77ef8654 | 544 | { |
cd30bcef AM |
545 | warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"), |
546 | (unsigned long) len - 1); | |
77ef8654 NC |
547 | adr = 0; |
548 | } | |
549 | else | |
cd30bcef | 550 | SAFE_BYTE_GET (adr, data, len - 1, end); |
47704ddf | 551 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 552 | state_machine_regs.address = adr; |
ba8826a8 | 553 | state_machine_regs.view = 0; |
a233b20c | 554 | state_machine_regs.op_index = 0; |
19e6b90e L |
555 | break; |
556 | ||
557 | case DW_LNE_define_file: | |
143a3db0 | 558 | printf (_("define new File Table entry\n")); |
19e6b90e | 559 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 560 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 561 | |
d949ff56 NC |
562 | { |
563 | size_t l; | |
564 | ||
565 | name = data; | |
566 | l = strnlen ((char *) data, end - data); | |
cd30bcef AM |
567 | data += l + 1; |
568 | READ_ULEB (val, data, end); | |
569 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
570 | READ_ULEB (val, data, end); | |
571 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
572 | READ_ULEB (val, data, end); | |
573 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
d949ff56 NC |
574 | printf ("%.*s\n\n", (int) l, name); |
575 | } | |
f6f0e17b | 576 | |
cd30bcef | 577 | if (((size_t) (data - orig_data) != len + header_len) || data == end) |
b4eb7656 | 578 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
579 | break; |
580 | ||
ed4a4bdf | 581 | case DW_LNE_set_discriminator: |
cd30bcef AM |
582 | READ_ULEB (val, data, end); |
583 | printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val)); | |
ed4a4bdf CC |
584 | break; |
585 | ||
e2a0d921 NC |
586 | /* HP extensions. */ |
587 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 588 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
589 | break; |
590 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 591 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
592 | break; |
593 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 594 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
595 | break; |
596 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 597 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
598 | break; |
599 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 600 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
601 | break; |
602 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 603 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
604 | break; |
605 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 606 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
607 | break; |
608 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 609 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
610 | break; |
611 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 612 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
613 | break; |
614 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 615 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 616 | break; |
43294ab7 TG |
617 | case DW_LNE_HP_source_file_correlation: |
618 | { | |
cd30bcef | 619 | unsigned char *edata = data + len - 1; |
b4eb7656 AM |
620 | |
621 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
622 | ||
623 | while (data < edata) | |
624 | { | |
625 | unsigned int opc; | |
626 | ||
cd30bcef | 627 | READ_ULEB (opc, data, edata); |
b4eb7656 AM |
628 | |
629 | switch (opc) | |
630 | { | |
631 | case DW_LNE_HP_SFC_formfeed: | |
632 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
633 | break; | |
634 | case DW_LNE_HP_SFC_set_listing_line: | |
cd30bcef | 635 | READ_ULEB (val, data, edata); |
b4eb7656 | 636 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", |
cd30bcef | 637 | dwarf_vmatoa ("u", val)); |
b4eb7656 AM |
638 | break; |
639 | case DW_LNE_HP_SFC_associate: | |
640 | printf (" DW_LNE_HP_SFC_associate "); | |
cd30bcef AM |
641 | READ_ULEB (val, data, edata); |
642 | printf ("(%s", dwarf_vmatoa ("u", val)); | |
643 | READ_ULEB (val, data, edata); | |
644 | printf (",%s", dwarf_vmatoa ("u", val)); | |
645 | READ_ULEB (val, data, edata); | |
646 | printf (",%s)\n", dwarf_vmatoa ("u", val)); | |
b4eb7656 AM |
647 | break; |
648 | default: | |
649 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
650 | data = edata; | |
651 | break; | |
652 | } | |
653 | } | |
43294ab7 TG |
654 | } |
655 | break; | |
cecf136e | 656 | |
19e6b90e | 657 | default: |
7e665af3 | 658 | { |
cd30bcef | 659 | unsigned int rlen = len - 1; |
b4eb7656 AM |
660 | |
661 | if (op_code >= DW_LNE_lo_user | |
662 | /* The test against DW_LNW_hi_user is redundant due to | |
663 | the limited range of the unsigned char data type used | |
664 | for op_code. */ | |
665 | /*&& op_code <= DW_LNE_hi_user*/) | |
666 | printf (_("user defined: ")); | |
667 | else | |
668 | printf (_("UNKNOWN: ")); | |
669 | printf (_("length %d ["), rlen); | |
670 | for (; rlen; rlen--) | |
671 | printf (" %02x", *data++); | |
672 | printf ("]\n"); | |
7e665af3 | 673 | } |
19e6b90e L |
674 | break; |
675 | } | |
676 | ||
cd30bcef | 677 | return len + header_len; |
19e6b90e L |
678 | } |
679 | ||
0c588247 | 680 | static const unsigned char * |
467c65bc | 681 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
682 | { |
683 | struct dwarf_section *section = &debug_displays [str].section; | |
d949ff56 | 684 | const unsigned char * ret; |
19e6b90e L |
685 | |
686 | if (section->start == NULL) | |
0c588247 | 687 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e | 688 | |
d949ff56 | 689 | if (offset >= section->size) |
19e6b90e | 690 | { |
467c65bc NC |
691 | warn (_("DW_FORM_strp offset too big: %s\n"), |
692 | dwarf_vmatoa ("x", offset)); | |
0c588247 | 693 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
694 | } |
695 | ||
d949ff56 NC |
696 | ret = section->start + offset; |
697 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
698 | NUL byte. Since our caller is expecting to receive a well formed C | |
699 | string we test for the lack of a terminating byte here. */ | |
700 | if (strnlen ((const char *) ret, section->size - offset) | |
701 | == section->size - offset) | |
702 | ret = (const unsigned char *) | |
703 | _("<no NUL byte at end of .debug_str section>"); | |
704 | ||
705 | return ret; | |
19e6b90e L |
706 | } |
707 | ||
77145576 JK |
708 | static const unsigned char * |
709 | fetch_indirect_line_string (dwarf_vma offset) | |
710 | { | |
711 | struct dwarf_section *section = &debug_displays [line_str].section; | |
d949ff56 | 712 | const unsigned char * ret; |
77145576 JK |
713 | |
714 | if (section->start == NULL) | |
715 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
716 | ||
d949ff56 | 717 | if (offset >= section->size) |
77145576 JK |
718 | { |
719 | warn (_("DW_FORM_line_strp offset too big: %s\n"), | |
720 | dwarf_vmatoa ("x", offset)); | |
721 | return (const unsigned char *) _("<offset is too big>"); | |
722 | } | |
723 | ||
d949ff56 NC |
724 | ret = section->start + offset; |
725 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
726 | with a NUL byte. Since our caller is expecting to receive a well formed | |
727 | C string we test for the lack of a terminating byte here. */ | |
728 | if (strnlen ((const char *) ret, section->size - offset) | |
729 | == section->size - offset) | |
730 | ret = (const unsigned char *) | |
731 | _("<no NUL byte at end of .debug_line_str section>"); | |
732 | ||
733 | return ret; | |
77145576 JK |
734 | } |
735 | ||
4723351a | 736 | static const char * |
341f9135 | 737 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
d85bf2ba | 738 | dwarf_vma offset_size, bfd_boolean dwo) |
4723351a CC |
739 | { |
740 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
741 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
742 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
743 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
e4b7104b | 744 | dwarf_vma index_offset; |
4723351a | 745 | dwarf_vma str_offset; |
d949ff56 | 746 | const char * ret; |
e4b7104b NC |
747 | unsigned char *curr = index_section->start; |
748 | const unsigned char *end = curr + index_section->size; | |
749 | dwarf_vma length; | |
4723351a CC |
750 | |
751 | if (index_section->start == NULL) | |
752 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
753 | : _("<no .debug_str_offsets section>")); | |
754 | ||
e4b7104b NC |
755 | if (str_section->start == NULL) |
756 | return (dwo ? _("<no .debug_str.dwo section>") | |
757 | : _("<no .debug_str section>")); | |
758 | ||
759 | /* FIXME: We should cache the length... */ | |
760 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); | |
761 | if (length == 0xffffffff) | |
762 | { | |
763 | if (offset_size != 8) | |
39f381cb | 764 | warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size)); |
e4b7104b NC |
765 | SAFE_BYTE_GET_AND_INC (length, curr, 8, end); |
766 | } | |
767 | else if (offset_size != 4) | |
768 | { | |
39f381cb | 769 | warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size)); |
e4b7104b NC |
770 | } |
771 | ||
39f381cb | 772 | if (length == 0) |
e4b7104b | 773 | { |
39f381cb NC |
774 | /* This is probably an old style .debug_str_offset section which |
775 | just contains offsets and no header (and the first offset is 0). */ | |
776 | curr = index_section->start; | |
777 | length = index_section->size; | |
778 | } | |
779 | else | |
780 | { | |
781 | /* Skip the version and padding bytes. | |
782 | We assume that they are correct. */ | |
783 | curr += 4; | |
784 | ||
785 | /* FIXME: The code below assumes that there is only one table | |
786 | in the .debug_str_offsets section, so check that now. */ | |
787 | if ((offset_size == 4 && curr + length < (end - 8)) | |
788 | || (offset_size == 8 && curr + length < (end - 16))) | |
789 | { | |
790 | warn (_("index table size is too small %s vs %s\n"), | |
791 | dwarf_vmatoa ("x", length), | |
792 | dwarf_vmatoa ("x", index_section->size)); | |
793 | return _("<table too small>"); | |
794 | } | |
e4b7104b NC |
795 | } |
796 | ||
797 | index_offset = idx * offset_size; | |
798 | ||
341f9135 CC |
799 | if (this_set != NULL) |
800 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
e4b7104b NC |
801 | |
802 | if (index_offset >= length) | |
4723351a | 803 | { |
e4b7104b NC |
804 | warn (_("DW_FORM_GNU_str_index offset too big: %s vs %s\n"), |
805 | dwarf_vmatoa ("x", index_offset), | |
806 | dwarf_vmatoa ("x", length)); | |
4723351a CC |
807 | return _("<index offset is too big>"); |
808 | } | |
809 | ||
e4b7104b | 810 | str_offset = byte_get (curr + index_offset, offset_size); |
4723351a | 811 | str_offset -= str_section->address; |
d949ff56 | 812 | if (str_offset >= str_section->size) |
4723351a CC |
813 | { |
814 | warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), | |
815 | dwarf_vmatoa ("x", str_offset)); | |
816 | return _("<indirect index offset is too big>"); | |
817 | } | |
818 | ||
d949ff56 NC |
819 | ret = (const char *) str_section->start + str_offset; |
820 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. | |
821 | Since our caller is expecting to receive a well formed C string we test | |
822 | for the lack of a terminating byte here. */ | |
823 | if (strnlen (ret, str_section->size - str_offset) | |
824 | == str_section->size - str_offset) | |
825 | ret = (const char *) _("<no NUL byte at end of section>"); | |
826 | ||
827 | return ret; | |
4723351a CC |
828 | } |
829 | ||
830 | static const char * | |
831 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
832 | { | |
833 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
834 | ||
835 | if (section->start == NULL) | |
836 | return (_("<no .debug_addr section>")); | |
837 | ||
838 | if (offset + bytes > section->size) | |
839 | { | |
840 | warn (_("Offset into section %s too big: %s\n"), | |
b4eb7656 | 841 | section->name, dwarf_vmatoa ("x", offset)); |
4723351a CC |
842 | return "<offset too big>"; |
843 | } | |
844 | ||
845 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
846 | } | |
847 | ||
848 | ||
19e6b90e L |
849 | /* FIXME: There are better and more efficient ways to handle |
850 | these structures. For now though, I just want something that | |
851 | is simple to implement. */ | |
bcd213b2 | 852 | /* Records a single attribute in an abbrev. */ |
19e6b90e L |
853 | typedef struct abbrev_attr |
854 | { | |
bcd213b2 NC |
855 | unsigned long attribute; |
856 | unsigned long form; | |
857 | bfd_signed_vma implicit_const; | |
858 | struct abbrev_attr * next; | |
19e6b90e L |
859 | } |
860 | abbrev_attr; | |
861 | ||
bcd213b2 | 862 | /* Records a single abbrev. */ |
19e6b90e L |
863 | typedef struct abbrev_entry |
864 | { | |
bcd213b2 NC |
865 | unsigned long number; |
866 | unsigned long tag; | |
867 | int children; | |
868 | struct abbrev_attr * first_attr; | |
869 | struct abbrev_attr * last_attr; | |
870 | struct abbrev_entry * next; | |
19e6b90e L |
871 | } |
872 | abbrev_entry; | |
873 | ||
bcd213b2 NC |
874 | /* Records a set of abbreviations. */ |
875 | typedef struct abbrev_list | |
876 | { | |
877 | abbrev_entry * first_abbrev; | |
878 | abbrev_entry * last_abbrev; | |
76868f36 | 879 | dwarf_vma abbrev_base; |
bcd213b2 NC |
880 | dwarf_vma abbrev_offset; |
881 | struct abbrev_list * next; | |
882 | unsigned char * start_of_next_abbrevs; | |
883 | } | |
884 | abbrev_list; | |
885 | ||
886 | /* Records all the abbrevs found so far. */ | |
887 | static struct abbrev_list * abbrev_lists = NULL; | |
888 | ||
889 | typedef struct abbrev_map | |
890 | { | |
891 | dwarf_vma start; | |
892 | dwarf_vma end; | |
893 | abbrev_list * list; | |
894 | } abbrev_map; | |
895 | ||
896 | /* Maps between CU offsets and abbrev sets. */ | |
897 | static abbrev_map * cu_abbrev_map = NULL; | |
898 | static unsigned long num_abbrev_map_entries = 0; | |
899 | static unsigned long next_free_abbrev_map_entry = 0; | |
900 | ||
901 | #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8 | |
902 | #define ABBREV_MAP_ENTRIES_INCREMENT 8 | |
903 | ||
904 | static void | |
905 | record_abbrev_list_for_cu (dwarf_vma start, dwarf_vma end, abbrev_list * list) | |
906 | { | |
907 | if (cu_abbrev_map == NULL) | |
908 | { | |
909 | num_abbrev_map_entries = INITIAL_NUM_ABBREV_MAP_ENTRIES; | |
910 | cu_abbrev_map = xmalloc (num_abbrev_map_entries * sizeof (* cu_abbrev_map)); | |
911 | } | |
912 | else if (next_free_abbrev_map_entry == num_abbrev_map_entries) | |
913 | { | |
914 | num_abbrev_map_entries += ABBREV_MAP_ENTRIES_INCREMENT; | |
915 | cu_abbrev_map = xrealloc (cu_abbrev_map, num_abbrev_map_entries * sizeof (* cu_abbrev_map)); | |
916 | } | |
917 | ||
918 | cu_abbrev_map[next_free_abbrev_map_entry].start = start; | |
919 | cu_abbrev_map[next_free_abbrev_map_entry].end = end; | |
920 | cu_abbrev_map[next_free_abbrev_map_entry].list = list; | |
921 | next_free_abbrev_map_entry ++; | |
922 | } | |
19e6b90e L |
923 | |
924 | static void | |
bcd213b2 | 925 | free_all_abbrevs (void) |
19e6b90e | 926 | { |
bcd213b2 | 927 | abbrev_list * list; |
19e6b90e | 928 | |
bcd213b2 | 929 | for (list = abbrev_lists; list != NULL;) |
19e6b90e | 930 | { |
bcd213b2 NC |
931 | abbrev_list * next = list->next; |
932 | abbrev_entry * abbrv; | |
19e6b90e | 933 | |
bcd213b2 | 934 | for (abbrv = list->first_abbrev; abbrv != NULL;) |
19e6b90e | 935 | { |
bcd213b2 NC |
936 | abbrev_entry * next_abbrev = abbrv->next; |
937 | abbrev_attr * attr; | |
938 | ||
939 | for (attr = abbrv->first_attr; attr;) | |
940 | { | |
941 | abbrev_attr *next_attr = attr->next; | |
19e6b90e | 942 | |
bcd213b2 NC |
943 | free (attr); |
944 | attr = next_attr; | |
945 | } | |
946 | ||
947 | free (abbrv); | |
948 | abbrv = next_abbrev; | |
19e6b90e L |
949 | } |
950 | ||
bcd213b2 NC |
951 | free (list); |
952 | list = next; | |
19e6b90e L |
953 | } |
954 | ||
bcd213b2 NC |
955 | abbrev_lists = NULL; |
956 | } | |
957 | ||
958 | static abbrev_list * | |
76868f36 | 959 | new_abbrev_list (dwarf_vma abbrev_base, dwarf_vma abbrev_offset) |
bcd213b2 NC |
960 | { |
961 | abbrev_list * list = (abbrev_list *) xcalloc (sizeof * list, 1); | |
962 | ||
76868f36 | 963 | list->abbrev_base = abbrev_base; |
bcd213b2 NC |
964 | list->abbrev_offset = abbrev_offset; |
965 | ||
966 | list->next = abbrev_lists; | |
967 | abbrev_lists = list; | |
968 | ||
969 | return list; | |
970 | } | |
971 | ||
972 | static abbrev_list * | |
76868f36 L |
973 | find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base, |
974 | dwarf_vma abbrev_offset) | |
bcd213b2 NC |
975 | { |
976 | abbrev_list * list; | |
977 | ||
978 | for (list = abbrev_lists; list != NULL; list = list->next) | |
76868f36 L |
979 | if (list->abbrev_base == abbrev_base |
980 | && list->abbrev_offset == abbrev_offset) | |
bcd213b2 NC |
981 | return list; |
982 | ||
983 | return NULL; | |
984 | } | |
985 | ||
986 | /* Find the abbreviation map for the CU that includes OFFSET. | |
987 | OFFSET is an absolute offset from the start of the .debug_info section. */ | |
988 | /* FIXME: This function is going to slow down readelf & objdump. | |
989 | Consider using a better algorithm to mitigate this effect. */ | |
990 | ||
991 | static abbrev_map * | |
992 | find_abbrev_map_by_offset (dwarf_vma offset) | |
993 | { | |
994 | unsigned long i; | |
995 | ||
996 | for (i = 0; i < next_free_abbrev_map_entry; i++) | |
997 | if (cu_abbrev_map[i].start <= offset | |
998 | && cu_abbrev_map[i].end > offset) | |
999 | return cu_abbrev_map + i; | |
1000 | ||
1001 | return NULL; | |
19e6b90e L |
1002 | } |
1003 | ||
1004 | static void | |
bcd213b2 NC |
1005 | add_abbrev (unsigned long number, |
1006 | unsigned long tag, | |
1007 | int children, | |
1008 | abbrev_list * list) | |
19e6b90e | 1009 | { |
bcd213b2 | 1010 | abbrev_entry * entry; |
19e6b90e | 1011 | |
bcd213b2 | 1012 | entry = (abbrev_entry *) xmalloc (sizeof (*entry)); |
19e6b90e | 1013 | |
bcd213b2 | 1014 | entry->number = number; |
19e6b90e L |
1015 | entry->tag = tag; |
1016 | entry->children = children; | |
1017 | entry->first_attr = NULL; | |
1018 | entry->last_attr = NULL; | |
1019 | entry->next = NULL; | |
1020 | ||
bcd213b2 NC |
1021 | assert (list != NULL); |
1022 | ||
1023 | if (list->first_abbrev == NULL) | |
1024 | list->first_abbrev = entry; | |
19e6b90e | 1025 | else |
bcd213b2 | 1026 | list->last_abbrev->next = entry; |
19e6b90e | 1027 | |
bcd213b2 | 1028 | list->last_abbrev = entry; |
19e6b90e L |
1029 | } |
1030 | ||
1031 | static void | |
bcd213b2 NC |
1032 | add_abbrev_attr (unsigned long attribute, |
1033 | unsigned long form, | |
1034 | bfd_signed_vma implicit_const, | |
1035 | abbrev_list * list) | |
19e6b90e L |
1036 | { |
1037 | abbrev_attr *attr; | |
1038 | ||
bcd213b2 | 1039 | attr = (abbrev_attr *) xmalloc (sizeof (*attr)); |
19e6b90e L |
1040 | |
1041 | attr->attribute = attribute; | |
1042 | attr->form = form; | |
77145576 | 1043 | attr->implicit_const = implicit_const; |
19e6b90e L |
1044 | attr->next = NULL; |
1045 | ||
bcd213b2 NC |
1046 | assert (list != NULL && list->last_abbrev != NULL); |
1047 | ||
1048 | if (list->last_abbrev->first_attr == NULL) | |
1049 | list->last_abbrev->first_attr = attr; | |
19e6b90e | 1050 | else |
bcd213b2 | 1051 | list->last_abbrev->last_attr->next = attr; |
19e6b90e | 1052 | |
bcd213b2 | 1053 | list->last_abbrev->last_attr = attr; |
19e6b90e L |
1054 | } |
1055 | ||
1056 | /* Processes the (partial) contents of a .debug_abbrev section. | |
1057 | Returns NULL if the end of the section was encountered. | |
1058 | Returns the address after the last byte read if the end of | |
1059 | an abbreviation set was found. */ | |
1060 | ||
1061 | static unsigned char * | |
bcd213b2 NC |
1062 | process_abbrev_set (unsigned char * start, |
1063 | const unsigned char * end, | |
1064 | abbrev_list * list) | |
19e6b90e | 1065 | { |
19e6b90e L |
1066 | while (start < end) |
1067 | { | |
19e6b90e L |
1068 | unsigned long entry; |
1069 | unsigned long tag; | |
1070 | unsigned long attribute; | |
1071 | int children; | |
1072 | ||
cd30bcef | 1073 | READ_ULEB (entry, start, end); |
19e6b90e | 1074 | |
bcd213b2 | 1075 | /* A single zero is supposed to end the set according |
19e6b90e L |
1076 | to the standard. If there's more, then signal that to |
1077 | the caller. */ | |
f6f0e17b NC |
1078 | if (start == end) |
1079 | return NULL; | |
19e6b90e | 1080 | if (entry == 0) |
f6f0e17b | 1081 | return start; |
19e6b90e | 1082 | |
cd30bcef | 1083 | READ_ULEB (tag, start, end); |
f6f0e17b NC |
1084 | if (start == end) |
1085 | return NULL; | |
19e6b90e L |
1086 | |
1087 | children = *start++; | |
1088 | ||
bcd213b2 | 1089 | add_abbrev (entry, tag, children, list); |
19e6b90e L |
1090 | |
1091 | do | |
1092 | { | |
1093 | unsigned long form; | |
77145576 JK |
1094 | /* Initialize it due to a false compiler warning. */ |
1095 | bfd_signed_vma implicit_const = -1; | |
19e6b90e | 1096 | |
cd30bcef | 1097 | READ_ULEB (attribute, start, end); |
f6f0e17b NC |
1098 | if (start == end) |
1099 | break; | |
19e6b90e | 1100 | |
cd30bcef | 1101 | READ_ULEB (form, start, end); |
f6f0e17b NC |
1102 | if (start == end) |
1103 | break; | |
19e6b90e | 1104 | |
77145576 JK |
1105 | if (form == DW_FORM_implicit_const) |
1106 | { | |
cd30bcef | 1107 | READ_SLEB (implicit_const, start, end); |
77145576 JK |
1108 | if (start == end) |
1109 | break; | |
1110 | } | |
1111 | ||
bcd213b2 | 1112 | add_abbrev_attr (attribute, form, implicit_const, list); |
19e6b90e L |
1113 | } |
1114 | while (attribute != 0); | |
1115 | } | |
1116 | ||
399c99f7 L |
1117 | /* Report the missing single zero which ends the section. */ |
1118 | error (_(".debug_abbrev section not zero terminated\n")); | |
1119 | ||
19e6b90e L |
1120 | return NULL; |
1121 | } | |
1122 | ||
a19c41a7 | 1123 | static const char * |
19e6b90e L |
1124 | get_TAG_name (unsigned long tag) |
1125 | { | |
04914e37 | 1126 | const char *name = get_DW_TAG_name ((unsigned int) tag); |
a19c41a7 TT |
1127 | |
1128 | if (name == NULL) | |
19e6b90e | 1129 | { |
a19c41a7 | 1130 | static char buffer[100]; |
19e6b90e | 1131 | |
04914e37 NC |
1132 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
1133 | snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag); | |
1134 | else | |
1135 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag); | |
a19c41a7 | 1136 | return buffer; |
19e6b90e | 1137 | } |
a19c41a7 TT |
1138 | |
1139 | return name; | |
19e6b90e L |
1140 | } |
1141 | ||
a19c41a7 | 1142 | static const char * |
19e6b90e L |
1143 | get_FORM_name (unsigned long form) |
1144 | { | |
399c99f7 | 1145 | const char *name; |
bf5117e3 | 1146 | |
399c99f7 L |
1147 | if (form == 0) |
1148 | return "DW_FORM value: 0"; | |
a19c41a7 | 1149 | |
399c99f7 | 1150 | name = get_DW_FORM_name (form); |
a19c41a7 | 1151 | if (name == NULL) |
19e6b90e | 1152 | { |
a19c41a7 | 1153 | static char buffer[100]; |
19e6b90e | 1154 | |
a19c41a7 TT |
1155 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
1156 | return buffer; | |
19e6b90e | 1157 | } |
a19c41a7 TT |
1158 | |
1159 | return name; | |
19e6b90e L |
1160 | } |
1161 | ||
61364358 JK |
1162 | static const char * |
1163 | get_IDX_name (unsigned long idx) | |
1164 | { | |
1165 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
1166 | ||
1167 | if (name == NULL) | |
1168 | { | |
1169 | static char buffer[100]; | |
1170 | ||
1171 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1172 | return buffer; | |
1173 | } | |
1174 | ||
1175 | return name; | |
1176 | } | |
1177 | ||
19e6b90e | 1178 | static unsigned char * |
0c588247 NC |
1179 | display_block (unsigned char *data, |
1180 | dwarf_vma length, | |
ef0b5f1c | 1181 | const unsigned char * const end, char delimiter) |
19e6b90e | 1182 | { |
0c588247 NC |
1183 | dwarf_vma maxlen; |
1184 | ||
ef0b5f1c | 1185 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
1186 | if (data > end) |
1187 | return (unsigned char *) end; | |
19e6b90e | 1188 | |
0c588247 NC |
1189 | maxlen = (dwarf_vma) (end - data); |
1190 | length = length > maxlen ? maxlen : length; | |
1191 | ||
19e6b90e L |
1192 | while (length --) |
1193 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1194 | ||
1195 | return data; | |
1196 | } | |
1197 | ||
1198 | static int | |
1199 | decode_location_expression (unsigned char * data, | |
1200 | unsigned int pointer_size, | |
b7807392 JJ |
1201 | unsigned int offset_size, |
1202 | int dwarf_version, | |
467c65bc NC |
1203 | dwarf_vma length, |
1204 | dwarf_vma cu_offset, | |
f1c4cc75 | 1205 | struct dwarf_section * section) |
19e6b90e L |
1206 | { |
1207 | unsigned op; | |
467c65bc | 1208 | dwarf_vma uvalue; |
0c588247 | 1209 | dwarf_signed_vma svalue; |
19e6b90e L |
1210 | unsigned char *end = data + length; |
1211 | int need_frame_base = 0; | |
1212 | ||
1213 | while (data < end) | |
1214 | { | |
1215 | op = *data++; | |
1216 | ||
1217 | switch (op) | |
1218 | { | |
1219 | case DW_OP_addr: | |
0c588247 NC |
1220 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1221 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1222 | break; |
1223 | case DW_OP_deref: | |
1224 | printf ("DW_OP_deref"); | |
1225 | break; | |
1226 | case DW_OP_const1u: | |
0c588247 NC |
1227 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1228 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1229 | break; |
1230 | case DW_OP_const1s: | |
0c588247 NC |
1231 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1232 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1233 | break; |
1234 | case DW_OP_const2u: | |
87bc83b3 | 1235 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1236 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1237 | break; |
1238 | case DW_OP_const2s: | |
0c588247 NC |
1239 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1240 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1241 | break; |
1242 | case DW_OP_const4u: | |
0c588247 NC |
1243 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1244 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1245 | break; |
1246 | case DW_OP_const4s: | |
0c588247 NC |
1247 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1248 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1249 | break; |
1250 | case DW_OP_const8u: | |
0c588247 NC |
1251 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1252 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1253 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1254 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1255 | break; |
1256 | case DW_OP_const8s: | |
0c588247 NC |
1257 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1258 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1259 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1260 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1261 | break; |
1262 | case DW_OP_constu: | |
cd30bcef AM |
1263 | READ_ULEB (uvalue, data, end); |
1264 | printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1265 | break; |
1266 | case DW_OP_consts: | |
cd30bcef AM |
1267 | READ_SLEB (svalue, data, end); |
1268 | printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1269 | break; |
1270 | case DW_OP_dup: | |
1271 | printf ("DW_OP_dup"); | |
1272 | break; | |
1273 | case DW_OP_drop: | |
1274 | printf ("DW_OP_drop"); | |
1275 | break; | |
1276 | case DW_OP_over: | |
1277 | printf ("DW_OP_over"); | |
1278 | break; | |
1279 | case DW_OP_pick: | |
0c588247 NC |
1280 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1281 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1282 | break; |
1283 | case DW_OP_swap: | |
1284 | printf ("DW_OP_swap"); | |
1285 | break; | |
1286 | case DW_OP_rot: | |
1287 | printf ("DW_OP_rot"); | |
1288 | break; | |
1289 | case DW_OP_xderef: | |
1290 | printf ("DW_OP_xderef"); | |
1291 | break; | |
1292 | case DW_OP_abs: | |
1293 | printf ("DW_OP_abs"); | |
1294 | break; | |
1295 | case DW_OP_and: | |
1296 | printf ("DW_OP_and"); | |
1297 | break; | |
1298 | case DW_OP_div: | |
1299 | printf ("DW_OP_div"); | |
1300 | break; | |
1301 | case DW_OP_minus: | |
1302 | printf ("DW_OP_minus"); | |
1303 | break; | |
1304 | case DW_OP_mod: | |
1305 | printf ("DW_OP_mod"); | |
1306 | break; | |
1307 | case DW_OP_mul: | |
1308 | printf ("DW_OP_mul"); | |
1309 | break; | |
1310 | case DW_OP_neg: | |
1311 | printf ("DW_OP_neg"); | |
1312 | break; | |
1313 | case DW_OP_not: | |
1314 | printf ("DW_OP_not"); | |
1315 | break; | |
1316 | case DW_OP_or: | |
1317 | printf ("DW_OP_or"); | |
1318 | break; | |
1319 | case DW_OP_plus: | |
1320 | printf ("DW_OP_plus"); | |
1321 | break; | |
1322 | case DW_OP_plus_uconst: | |
cd30bcef AM |
1323 | READ_ULEB (uvalue, data, end); |
1324 | printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1325 | break; |
1326 | case DW_OP_shl: | |
1327 | printf ("DW_OP_shl"); | |
1328 | break; | |
1329 | case DW_OP_shr: | |
1330 | printf ("DW_OP_shr"); | |
1331 | break; | |
1332 | case DW_OP_shra: | |
1333 | printf ("DW_OP_shra"); | |
1334 | break; | |
1335 | case DW_OP_xor: | |
1336 | printf ("DW_OP_xor"); | |
1337 | break; | |
1338 | case DW_OP_bra: | |
0c588247 NC |
1339 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1340 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1341 | break; |
1342 | case DW_OP_eq: | |
1343 | printf ("DW_OP_eq"); | |
1344 | break; | |
1345 | case DW_OP_ge: | |
1346 | printf ("DW_OP_ge"); | |
1347 | break; | |
1348 | case DW_OP_gt: | |
1349 | printf ("DW_OP_gt"); | |
1350 | break; | |
1351 | case DW_OP_le: | |
1352 | printf ("DW_OP_le"); | |
1353 | break; | |
1354 | case DW_OP_lt: | |
1355 | printf ("DW_OP_lt"); | |
1356 | break; | |
1357 | case DW_OP_ne: | |
1358 | printf ("DW_OP_ne"); | |
1359 | break; | |
1360 | case DW_OP_skip: | |
0c588247 NC |
1361 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1362 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1363 | break; |
1364 | ||
1365 | case DW_OP_lit0: | |
1366 | case DW_OP_lit1: | |
1367 | case DW_OP_lit2: | |
1368 | case DW_OP_lit3: | |
1369 | case DW_OP_lit4: | |
1370 | case DW_OP_lit5: | |
1371 | case DW_OP_lit6: | |
1372 | case DW_OP_lit7: | |
1373 | case DW_OP_lit8: | |
1374 | case DW_OP_lit9: | |
1375 | case DW_OP_lit10: | |
1376 | case DW_OP_lit11: | |
1377 | case DW_OP_lit12: | |
1378 | case DW_OP_lit13: | |
1379 | case DW_OP_lit14: | |
1380 | case DW_OP_lit15: | |
1381 | case DW_OP_lit16: | |
1382 | case DW_OP_lit17: | |
1383 | case DW_OP_lit18: | |
1384 | case DW_OP_lit19: | |
1385 | case DW_OP_lit20: | |
1386 | case DW_OP_lit21: | |
1387 | case DW_OP_lit22: | |
1388 | case DW_OP_lit23: | |
1389 | case DW_OP_lit24: | |
1390 | case DW_OP_lit25: | |
1391 | case DW_OP_lit26: | |
1392 | case DW_OP_lit27: | |
1393 | case DW_OP_lit28: | |
1394 | case DW_OP_lit29: | |
1395 | case DW_OP_lit30: | |
1396 | case DW_OP_lit31: | |
1397 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1398 | break; | |
1399 | ||
1400 | case DW_OP_reg0: | |
1401 | case DW_OP_reg1: | |
1402 | case DW_OP_reg2: | |
1403 | case DW_OP_reg3: | |
1404 | case DW_OP_reg4: | |
1405 | case DW_OP_reg5: | |
1406 | case DW_OP_reg6: | |
1407 | case DW_OP_reg7: | |
1408 | case DW_OP_reg8: | |
1409 | case DW_OP_reg9: | |
1410 | case DW_OP_reg10: | |
1411 | case DW_OP_reg11: | |
1412 | case DW_OP_reg12: | |
1413 | case DW_OP_reg13: | |
1414 | case DW_OP_reg14: | |
1415 | case DW_OP_reg15: | |
1416 | case DW_OP_reg16: | |
1417 | case DW_OP_reg17: | |
1418 | case DW_OP_reg18: | |
1419 | case DW_OP_reg19: | |
1420 | case DW_OP_reg20: | |
1421 | case DW_OP_reg21: | |
1422 | case DW_OP_reg22: | |
1423 | case DW_OP_reg23: | |
1424 | case DW_OP_reg24: | |
1425 | case DW_OP_reg25: | |
1426 | case DW_OP_reg26: | |
1427 | case DW_OP_reg27: | |
1428 | case DW_OP_reg28: | |
1429 | case DW_OP_reg29: | |
1430 | case DW_OP_reg30: | |
1431 | case DW_OP_reg31: | |
18464d4d JK |
1432 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1433 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1434 | break; |
1435 | ||
1436 | case DW_OP_breg0: | |
1437 | case DW_OP_breg1: | |
1438 | case DW_OP_breg2: | |
1439 | case DW_OP_breg3: | |
1440 | case DW_OP_breg4: | |
1441 | case DW_OP_breg5: | |
1442 | case DW_OP_breg6: | |
1443 | case DW_OP_breg7: | |
1444 | case DW_OP_breg8: | |
1445 | case DW_OP_breg9: | |
1446 | case DW_OP_breg10: | |
1447 | case DW_OP_breg11: | |
1448 | case DW_OP_breg12: | |
1449 | case DW_OP_breg13: | |
1450 | case DW_OP_breg14: | |
1451 | case DW_OP_breg15: | |
1452 | case DW_OP_breg16: | |
1453 | case DW_OP_breg17: | |
1454 | case DW_OP_breg18: | |
1455 | case DW_OP_breg19: | |
1456 | case DW_OP_breg20: | |
1457 | case DW_OP_breg21: | |
1458 | case DW_OP_breg22: | |
1459 | case DW_OP_breg23: | |
1460 | case DW_OP_breg24: | |
1461 | case DW_OP_breg25: | |
1462 | case DW_OP_breg26: | |
1463 | case DW_OP_breg27: | |
1464 | case DW_OP_breg28: | |
1465 | case DW_OP_breg29: | |
1466 | case DW_OP_breg30: | |
1467 | case DW_OP_breg31: | |
cd30bcef AM |
1468 | READ_SLEB (svalue, data, end); |
1469 | printf ("DW_OP_breg%d (%s): %s", op - DW_OP_breg0, | |
1470 | regname (op - DW_OP_breg0, 1), dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1471 | break; |
1472 | ||
1473 | case DW_OP_regx: | |
cd30bcef | 1474 | READ_ULEB (uvalue, data, end); |
467c65bc NC |
1475 | printf ("DW_OP_regx: %s (%s)", |
1476 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1477 | break; |
1478 | case DW_OP_fbreg: | |
1479 | need_frame_base = 1; | |
cd30bcef AM |
1480 | READ_SLEB (svalue, data, end); |
1481 | printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1482 | break; |
1483 | case DW_OP_bregx: | |
cd30bcef AM |
1484 | READ_ULEB (uvalue, data, end); |
1485 | READ_SLEB (svalue, data, end); | |
467c65bc NC |
1486 | printf ("DW_OP_bregx: %s (%s) %s", |
1487 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
cd30bcef | 1488 | dwarf_vmatoa ("d", svalue)); |
19e6b90e L |
1489 | break; |
1490 | case DW_OP_piece: | |
cd30bcef AM |
1491 | READ_ULEB (uvalue, data, end); |
1492 | printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1493 | break; |
1494 | case DW_OP_deref_size: | |
0c588247 NC |
1495 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1496 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1497 | break; |
1498 | case DW_OP_xderef_size: | |
0c588247 NC |
1499 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1500 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1501 | break; |
1502 | case DW_OP_nop: | |
1503 | printf ("DW_OP_nop"); | |
1504 | break; | |
1505 | ||
1506 | /* DWARF 3 extensions. */ | |
1507 | case DW_OP_push_object_address: | |
1508 | printf ("DW_OP_push_object_address"); | |
1509 | break; | |
1510 | case DW_OP_call2: | |
d85bf2ba | 1511 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1512 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1513 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1514 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1515 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1516 | break; |
1517 | case DW_OP_call4: | |
d85bf2ba | 1518 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1519 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1520 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1521 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1522 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1523 | break; |
1524 | case DW_OP_call_ref: | |
d85bf2ba | 1525 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
e2a0d921 | 1526 | this ought to be an 8-byte wide computation. */ |
b7807392 JJ |
1527 | if (dwarf_version == -1) |
1528 | { | |
1529 | printf (_("(DW_OP_call_ref in frame info)")); | |
1530 | /* No way to tell where the next op is, so just bail. */ | |
1531 | return need_frame_base; | |
1532 | } | |
1533 | if (dwarf_version == 2) | |
1534 | { | |
0c588247 | 1535 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1536 | } |
1537 | else | |
1538 | { | |
0c588247 | 1539 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1540 | } |
0c588247 | 1541 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1542 | break; |
a87b0a59 NS |
1543 | case DW_OP_form_tls_address: |
1544 | printf ("DW_OP_form_tls_address"); | |
1545 | break; | |
e2a0d921 NC |
1546 | case DW_OP_call_frame_cfa: |
1547 | printf ("DW_OP_call_frame_cfa"); | |
1548 | break; | |
1549 | case DW_OP_bit_piece: | |
1550 | printf ("DW_OP_bit_piece: "); | |
cd30bcef AM |
1551 | READ_ULEB (uvalue, data, end); |
1552 | printf (_("size: %s "), dwarf_vmatoa ("u", uvalue)); | |
1553 | READ_ULEB (uvalue, data, end); | |
1554 | printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue)); | |
e2a0d921 | 1555 | break; |
19e6b90e | 1556 | |
3244e8f5 JJ |
1557 | /* DWARF 4 extensions. */ |
1558 | case DW_OP_stack_value: | |
1559 | printf ("DW_OP_stack_value"); | |
1560 | break; | |
1561 | ||
1562 | case DW_OP_implicit_value: | |
1563 | printf ("DW_OP_implicit_value"); | |
cd30bcef | 1564 | READ_ULEB (uvalue, data, end); |
ef0b5f1c | 1565 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1566 | break; |
1567 | ||
19e6b90e L |
1568 | /* GNU extensions. */ |
1569 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1570 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1571 | break; |
1572 | case DW_OP_GNU_uninit: | |
1573 | printf ("DW_OP_GNU_uninit"); | |
1574 | /* FIXME: Is there data associated with this OP ? */ | |
1575 | break; | |
f1c4cc75 RH |
1576 | case DW_OP_GNU_encoded_addr: |
1577 | { | |
6937bb54 | 1578 | int encoding = 0; |
f1c4cc75 | 1579 | dwarf_vma addr; |
467c65bc | 1580 | |
6937bb54 NC |
1581 | if (data < end) |
1582 | encoding = *data++; | |
041830e0 | 1583 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1584 | |
1585 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1586 | print_dwarf_vma (addr, pointer_size); | |
1587 | } | |
1588 | break; | |
bc0a77d2 | 1589 | case DW_OP_implicit_pointer: |
b7807392 | 1590 | case DW_OP_GNU_implicit_pointer: |
d85bf2ba | 1591 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
b7807392 JJ |
1592 | this ought to be an 8-byte wide computation. */ |
1593 | if (dwarf_version == -1) | |
1594 | { | |
bc0a77d2 JK |
1595 | printf (_("(%s in frame info)"), |
1596 | (op == DW_OP_implicit_pointer | |
1597 | ? "DW_OP_implicit_pointer" | |
1598 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1599 | /* No way to tell where the next op is, so just bail. */ |
1600 | return need_frame_base; | |
1601 | } | |
1602 | if (dwarf_version == 2) | |
1603 | { | |
0c588247 | 1604 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1605 | } |
1606 | else | |
1607 | { | |
0c588247 | 1608 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1609 | } |
cd30bcef | 1610 | READ_SLEB (svalue, data, end); |
bc0a77d2 JK |
1611 | printf ("%s: <0x%s> %s", |
1612 | (op == DW_OP_implicit_pointer | |
1613 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 | 1614 | dwarf_vmatoa ("x", uvalue), |
cd30bcef | 1615 | dwarf_vmatoa ("d", svalue)); |
b7807392 | 1616 | break; |
77145576 | 1617 | case DW_OP_entry_value: |
0892011d | 1618 | case DW_OP_GNU_entry_value: |
cd30bcef | 1619 | READ_ULEB (uvalue, data, end); |
058037d3 NC |
1620 | /* PR 17531: file: 0cc9cd00. */ |
1621 | if (uvalue > (dwarf_vma) (end - data)) | |
1622 | uvalue = end - data; | |
77145576 JK |
1623 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1624 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1625 | if (decode_location_expression (data, pointer_size, offset_size, |
1626 | dwarf_version, uvalue, | |
1627 | cu_offset, section)) | |
1628 | need_frame_base = 1; | |
1629 | putchar (')'); | |
1630 | data += uvalue; | |
6937bb54 NC |
1631 | if (data > end) |
1632 | data = end; | |
0892011d | 1633 | break; |
bc0a77d2 | 1634 | case DW_OP_const_type: |
0892011d | 1635 | case DW_OP_GNU_const_type: |
cd30bcef | 1636 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1637 | printf ("%s: <0x%s> ", |
1638 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1639 | : "DW_OP_GNU_const_type"), | |
0892011d | 1640 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1641 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1642 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1643 | break; |
bc0a77d2 | 1644 | case DW_OP_regval_type: |
0892011d | 1645 | case DW_OP_GNU_regval_type: |
cd30bcef | 1646 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1647 | printf ("%s: %s (%s)", |
1648 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1649 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1650 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
cd30bcef | 1651 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1652 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1653 | break; | |
bc0a77d2 | 1654 | case DW_OP_deref_type: |
0892011d | 1655 | case DW_OP_GNU_deref_type: |
0c588247 | 1656 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1657 | printf ("%s: %ld", |
1658 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1659 | : "DW_OP_GNU_deref_type"), | |
1660 | (long) uvalue); | |
cd30bcef | 1661 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1662 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1663 | break; | |
bc0a77d2 | 1664 | case DW_OP_convert: |
0892011d | 1665 | case DW_OP_GNU_convert: |
cd30bcef | 1666 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1667 | printf ("%s <0x%s>", |
1668 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1669 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1670 | break; |
bc0a77d2 | 1671 | case DW_OP_reinterpret: |
0892011d | 1672 | case DW_OP_GNU_reinterpret: |
cd30bcef | 1673 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1674 | printf ("%s <0x%s>", |
1675 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1676 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1677 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1678 | break; | |
1679 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1680 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1681 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1682 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1683 | break; |
b4eb7656 | 1684 | case DW_OP_GNU_addr_index: |
cd30bcef | 1685 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1686 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1687 | break; | |
1688 | case DW_OP_GNU_const_index: | |
cd30bcef | 1689 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1690 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1691 | break; | |
f384a1f0 KB |
1692 | case DW_OP_GNU_variable_value: |
1693 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1694 | this ought to be an 8-byte wide computation. */ | |
1695 | if (dwarf_version == -1) | |
1696 | { | |
1697 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1698 | /* No way to tell where the next op is, so just bail. */ | |
1699 | return need_frame_base; | |
1700 | } | |
1701 | if (dwarf_version == 2) | |
1702 | { | |
1703 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1704 | } | |
1705 | else | |
1706 | { | |
1707 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1708 | } | |
1709 | printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1710 | break; | |
e2a0d921 NC |
1711 | |
1712 | /* HP extensions. */ | |
1713 | case DW_OP_HP_is_value: | |
1714 | printf ("DW_OP_HP_is_value"); | |
1715 | /* FIXME: Is there data associated with this OP ? */ | |
1716 | break; | |
1717 | case DW_OP_HP_fltconst4: | |
1718 | printf ("DW_OP_HP_fltconst4"); | |
1719 | /* FIXME: Is there data associated with this OP ? */ | |
1720 | break; | |
1721 | case DW_OP_HP_fltconst8: | |
1722 | printf ("DW_OP_HP_fltconst8"); | |
1723 | /* FIXME: Is there data associated with this OP ? */ | |
1724 | break; | |
1725 | case DW_OP_HP_mod_range: | |
1726 | printf ("DW_OP_HP_mod_range"); | |
1727 | /* FIXME: Is there data associated with this OP ? */ | |
1728 | break; | |
1729 | case DW_OP_HP_unmod_range: | |
1730 | printf ("DW_OP_HP_unmod_range"); | |
1731 | /* FIXME: Is there data associated with this OP ? */ | |
1732 | break; | |
1733 | case DW_OP_HP_tls: | |
1734 | printf ("DW_OP_HP_tls"); | |
1735 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1736 | break; |
1737 | ||
35d60fe4 NC |
1738 | /* PGI (STMicroelectronics) extensions. */ |
1739 | case DW_OP_PGI_omp_thread_num: | |
1740 | /* Pushes the thread number for the current thread as it would be | |
1741 | returned by the standard OpenMP library function: | |
1742 | omp_get_thread_num(). The "current thread" is the thread for | |
1743 | which the expression is being evaluated. */ | |
1744 | printf ("DW_OP_PGI_omp_thread_num"); | |
1745 | break; | |
1746 | ||
19e6b90e L |
1747 | default: |
1748 | if (op >= DW_OP_lo_user | |
1749 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1750 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1751 | else |
0502a2b4 | 1752 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1753 | /* No way to tell where the next op is, so just bail. */ |
1754 | return need_frame_base; | |
1755 | } | |
1756 | ||
1757 | /* Separate the ops. */ | |
1758 | if (data < end) | |
1759 | printf ("; "); | |
1760 | } | |
1761 | ||
1762 | return need_frame_base; | |
1763 | } | |
1764 | ||
341f9135 CC |
1765 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1766 | This is used for DWARF package files. */ | |
1767 | ||
1768 | static struct cu_tu_set * | |
1769 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1770 | { | |
1771 | struct cu_tu_set *p; | |
1772 | unsigned int nsets; | |
1773 | unsigned int dw_sect; | |
1774 | ||
1775 | if (do_types) | |
1776 | { | |
1777 | p = tu_sets; | |
1778 | nsets = tu_count; | |
1779 | dw_sect = DW_SECT_TYPES; | |
1780 | } | |
1781 | else | |
1782 | { | |
1783 | p = cu_sets; | |
1784 | nsets = cu_count; | |
1785 | dw_sect = DW_SECT_INFO; | |
1786 | } | |
1787 | while (nsets > 0) | |
1788 | { | |
1789 | if (p->section_offsets [dw_sect] == cu_offset) | |
1790 | return p; | |
1791 | p++; | |
1792 | nsets--; | |
1793 | } | |
1794 | return NULL; | |
1795 | } | |
1796 | ||
a69c4772 NC |
1797 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1798 | static void | |
1799 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1800 | { | |
1801 | dwarf_vma tmp = * low_bits; | |
1802 | ||
1803 | tmp += inc; | |
1804 | ||
1805 | /* FIXME: There is probably a better way of handling this: | |
1806 | ||
1807 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1808 | type. Plus regardless of its size LOW_BITS is meant to | |
1809 | only hold 32-bits, so if there is overflow or wrap around | |
1810 | we must propagate into HIGH_BITS. */ | |
1811 | if (tmp < * low_bits) | |
1812 | { | |
1813 | ++ * high_bits; | |
1814 | } | |
1815 | else if (sizeof (tmp) > 8 | |
1816 | && (tmp >> 31) > 1) | |
1817 | { | |
1818 | ++ * high_bits; | |
1819 | tmp &= 0xFFFFFFFF; | |
1820 | } | |
1821 | ||
1822 | * low_bits = tmp; | |
1823 | } | |
1824 | ||
dda8d76d NC |
1825 | static const char * |
1826 | fetch_alt_indirect_string (dwarf_vma offset) | |
1827 | { | |
24841daa | 1828 | separate_info * i; |
dda8d76d NC |
1829 | |
1830 | if (! do_follow_links) | |
1831 | return ""; | |
1832 | ||
24841daa NC |
1833 | if (first_separate_info == NULL) |
1834 | return _("<no links available>"); | |
dda8d76d | 1835 | |
24841daa NC |
1836 | for (i = first_separate_info; i != NULL; i = i->next) |
1837 | { | |
1838 | struct dwarf_section * section; | |
1839 | const char * ret; | |
dda8d76d | 1840 | |
24841daa NC |
1841 | if (! load_debug_section (separate_debug_str, i->handle)) |
1842 | continue; | |
dda8d76d | 1843 | |
24841daa | 1844 | section = &debug_displays [separate_debug_str].section; |
dda8d76d | 1845 | |
24841daa NC |
1846 | if (section->start == NULL) |
1847 | continue; | |
dda8d76d | 1848 | |
24841daa NC |
1849 | if (offset >= section->size) |
1850 | continue; | |
1851 | ||
1852 | ret = (const char *) (section->start + offset); | |
1853 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1854 | NUL byte. Since our caller is expecting to receive a well formed C | |
1855 | string we test for the lack of a terminating byte here. */ | |
1856 | if (strnlen ((const char *) ret, section->size - offset) | |
1857 | == section->size - offset) | |
1858 | return _("<no NUL byte at end of alt .debug_str section>"); | |
1859 | ||
1860 | return ret; | |
1861 | } | |
1862 | ||
1863 | warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"), | |
1864 | dwarf_vmatoa ("x", offset)); | |
1865 | return _("<offset is too big>"); | |
dda8d76d NC |
1866 | } |
1867 | ||
d85bf2ba NC |
1868 | static const char * |
1869 | get_AT_name (unsigned long attribute) | |
1870 | { | |
1871 | const char *name; | |
1872 | ||
1873 | if (attribute == 0) | |
1874 | return "DW_AT value: 0"; | |
1875 | ||
1876 | /* One value is shared by the MIPS and HP extensions: */ | |
1877 | if (attribute == DW_AT_MIPS_fde) | |
1878 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1879 | ||
1880 | name = get_DW_AT_name (attribute); | |
1881 | ||
1882 | if (name == NULL) | |
1883 | { | |
1884 | static char buffer[100]; | |
1885 | ||
1886 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1887 | attribute); | |
1888 | return buffer; | |
1889 | } | |
1890 | ||
1891 | return name; | |
1892 | } | |
1893 | ||
24841daa NC |
1894 | static void |
1895 | add_dwo_info (const char * field, dwo_type type) | |
1896 | { | |
1897 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); | |
1898 | ||
1899 | dwinfo->type = type; | |
1900 | dwinfo->value = field; | |
1901 | dwinfo->next = first_dwo_info; | |
1902 | first_dwo_info = dwinfo; | |
1903 | } | |
1904 | ||
1905 | static void | |
1906 | add_dwo_name (const char * name) | |
1907 | { | |
1908 | add_dwo_info (name, DWO_NAME); | |
1909 | } | |
1910 | ||
1911 | static void | |
1912 | add_dwo_dir (const char * dir) | |
1913 | { | |
1914 | add_dwo_info (dir, DWO_DIR); | |
1915 | } | |
1916 | ||
1917 | static void | |
1918 | add_dwo_id (const char * id) | |
1919 | { | |
1920 | add_dwo_info (id, DWO_ID); | |
1921 | } | |
1922 | ||
1923 | static void | |
1924 | free_dwo_info (void) | |
1925 | { | |
1926 | dwo_info * dwinfo; | |
1927 | dwo_info * next; | |
1928 | ||
1929 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) | |
1930 | { | |
1931 | next = dwinfo->next; | |
1932 | free (dwinfo); | |
1933 | } | |
1934 | first_dwo_info = NULL; | |
1935 | } | |
1936 | ||
afc72f15 NC |
1937 | /* Ensure that START + UVALUE is less than END. |
1938 | Return an adjusted UVALUE if necessary to ensure this relationship. */ | |
1939 | ||
1940 | static inline dwarf_vma | |
1941 | check_uvalue (const unsigned char * start, | |
1942 | dwarf_vma uvalue, | |
1943 | const unsigned char * end) | |
1944 | { | |
1945 | dwarf_vma max_uvalue = end - start; | |
1946 | ||
afc72f15 NC |
1947 | /* See PR 17512: file: 008-103549-0.001:0.1. |
1948 | and PR 24829 for examples of where these tests are triggered. */ | |
a85eba51 | 1949 | if (uvalue > max_uvalue) |
afc72f15 NC |
1950 | { |
1951 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1952 | uvalue = max_uvalue; | |
1953 | } | |
1954 | ||
1955 | return uvalue; | |
1956 | } | |
1957 | ||
ec1b0fbb NC |
1958 | static unsigned char * |
1959 | skip_attr_bytes (unsigned long form, | |
1960 | unsigned char * data, | |
1961 | unsigned const char * end, | |
1962 | dwarf_vma pointer_size, | |
1963 | dwarf_vma offset_size, | |
1964 | int dwarf_version, | |
1965 | dwarf_vma * value_return) | |
1966 | { | |
cd30bcef AM |
1967 | dwarf_signed_vma svalue; |
1968 | dwarf_vma uvalue = 0; | |
ec1b0fbb NC |
1969 | |
1970 | * value_return = 0; | |
1971 | ||
1972 | switch (form) | |
1973 | { | |
1974 | case DW_FORM_ref_addr: | |
1975 | if (dwarf_version == 2) | |
1976 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
59624513 | 1977 | else if (dwarf_version > 2) |
ec1b0fbb NC |
1978 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1979 | else | |
1980 | return NULL; | |
1981 | break; | |
1982 | ||
1983 | case DW_FORM_addr: | |
1984 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1985 | break; | |
1986 | ||
1987 | case DW_FORM_strp: | |
1988 | case DW_FORM_line_strp: | |
1989 | case DW_FORM_sec_offset: | |
1990 | case DW_FORM_GNU_ref_alt: | |
1991 | case DW_FORM_GNU_strp_alt: | |
1992 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1993 | break; | |
1994 | ||
1995 | case DW_FORM_flag_present: | |
1996 | uvalue = 1; | |
1997 | break; | |
1998 | ||
1999 | case DW_FORM_ref1: | |
2000 | case DW_FORM_flag: | |
2001 | case DW_FORM_data1: | |
2002 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
2003 | break; | |
2004 | ||
2005 | case DW_FORM_ref2: | |
2006 | case DW_FORM_data2: | |
2007 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); | |
2008 | break; | |
2009 | ||
2010 | case DW_FORM_ref4: | |
2011 | case DW_FORM_data4: | |
2012 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
2013 | break; | |
2014 | ||
2015 | case DW_FORM_sdata: | |
cd30bcef AM |
2016 | READ_SLEB (svalue, data, end); |
2017 | uvalue = svalue; | |
ec1b0fbb NC |
2018 | break; |
2019 | ||
2020 | case DW_FORM_ref_udata: | |
2021 | case DW_FORM_udata: | |
2022 | case DW_FORM_GNU_str_index: | |
2023 | case DW_FORM_GNU_addr_index: | |
cd30bcef | 2024 | READ_ULEB (uvalue, data, end); |
ec1b0fbb NC |
2025 | break; |
2026 | ||
2027 | case DW_FORM_ref8: | |
2028 | case DW_FORM_data8: | |
59624513 | 2029 | case DW_FORM_ref_sig8: |
ec1b0fbb NC |
2030 | data += 8; |
2031 | break; | |
2032 | ||
2033 | case DW_FORM_data16: | |
2034 | data += 16; | |
2035 | break; | |
2036 | ||
2037 | case DW_FORM_string: | |
2038 | data += strnlen ((char *) data, end - data) + 1; | |
2039 | break; | |
2040 | ||
2041 | case DW_FORM_block: | |
2042 | case DW_FORM_exprloc: | |
cd30bcef | 2043 | READ_ULEB (uvalue, data, end); |
59624513 | 2044 | data += uvalue; |
ec1b0fbb NC |
2045 | break; |
2046 | ||
2047 | case DW_FORM_block1: | |
2048 | SAFE_BYTE_GET (uvalue, data, 1, end); | |
2049 | data += 1 + uvalue; | |
2050 | break; | |
2051 | ||
2052 | case DW_FORM_block2: | |
2053 | SAFE_BYTE_GET (uvalue, data, 2, end); | |
2054 | data += 2 + uvalue; | |
2055 | break; | |
2056 | ||
2057 | case DW_FORM_block4: | |
2058 | SAFE_BYTE_GET (uvalue, data, 4, end); | |
2059 | data += 4 + uvalue; | |
2060 | break; | |
2061 | ||
ec1b0fbb | 2062 | case DW_FORM_indirect: |
59624513 NC |
2063 | READ_ULEB (form, data, end); |
2064 | if (form == DW_FORM_implicit_const) | |
2065 | SKIP_ULEB (data, end); | |
2066 | return skip_attr_bytes (form, data, end, pointer_size, offset_size, dwarf_version, value_return); | |
2067 | ||
ec1b0fbb NC |
2068 | default: |
2069 | return NULL; | |
2070 | } | |
2071 | ||
2072 | * value_return = uvalue; | |
2073 | if (data > end) | |
2074 | data = (unsigned char *) end; | |
2075 | return data; | |
2076 | } | |
2077 | ||
bcd213b2 NC |
2078 | /* Given form FORM with value UVALUE, locate and return the abbreviation |
2079 | associated with it. */ | |
2080 | ||
2081 | static abbrev_entry * | |
2082 | get_type_abbrev_from_form (unsigned long form, | |
2083 | unsigned long uvalue, | |
2084 | dwarf_vma cu_offset, | |
2085 | const struct dwarf_section * section, | |
2086 | unsigned long * abbrev_num_return, | |
2087 | unsigned char ** data_return, | |
2088 | unsigned long * cu_offset_return) | |
2089 | { | |
2090 | unsigned long abbrev_number; | |
2091 | abbrev_map * map; | |
2092 | abbrev_entry * entry; | |
2093 | unsigned char * data; | |
2094 | ||
2095 | if (abbrev_num_return != NULL) | |
2096 | * abbrev_num_return = 0; | |
2097 | if (data_return != NULL) | |
2098 | * data_return = NULL; | |
2099 | ||
2100 | switch (form) | |
2101 | { | |
2102 | case DW_FORM_GNU_ref_alt: | |
2103 | /* FIXME: We are unable to handle this form at the moment. */ | |
2104 | return NULL; | |
2105 | ||
2106 | case DW_FORM_ref_addr: | |
2107 | if (uvalue >= section->size) | |
2108 | { | |
2109 | warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"), | |
2110 | uvalue, (long) section->size, section->name); | |
2111 | return NULL; | |
2112 | } | |
2113 | break; | |
2114 | ||
2115 | case DW_FORM_ref1: | |
2116 | case DW_FORM_ref2: | |
2117 | case DW_FORM_ref4: | |
2118 | case DW_FORM_ref_udata: | |
2119 | if (uvalue + cu_offset > section->size) | |
2120 | { | |
2121 | warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > section size %lx\n"), | |
2122 | uvalue, (long) cu_offset, (long) section->size); | |
2123 | return NULL; | |
2124 | } | |
2125 | uvalue += cu_offset; | |
2126 | break; | |
2127 | ||
2128 | /* FIXME: Are there other DW_FORMs that can be used by types ? */ | |
2129 | ||
2130 | default: | |
2131 | warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form); | |
2132 | return NULL; | |
2133 | } | |
2134 | ||
2135 | data = (unsigned char *) section->start + uvalue; | |
2136 | map = find_abbrev_map_by_offset (uvalue); | |
2137 | ||
2138 | if (map == NULL) | |
2139 | { | |
2140 | warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue); | |
2141 | return NULL; | |
2142 | } | |
2143 | if (map->list == NULL) | |
2144 | { | |
2145 | warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue); | |
2146 | return NULL; | |
2147 | } | |
2148 | ||
2149 | if (cu_offset_return != NULL) | |
2150 | { | |
2151 | if (form == DW_FORM_ref_addr) | |
2152 | * cu_offset_return = map->start; | |
2153 | else | |
2154 | * cu_offset_return = cu_offset; | |
2155 | } | |
2156 | ||
2157 | READ_ULEB (abbrev_number, data, section->start + section->size); | |
2158 | ||
2159 | for (entry = map->list->first_abbrev; entry != NULL; entry = entry->next) | |
2160 | if (entry->number == abbrev_number) | |
2161 | break; | |
2162 | ||
2163 | if (abbrev_num_return != NULL) | |
2164 | * abbrev_num_return = abbrev_number; | |
2165 | ||
2166 | if (data_return != NULL) | |
2167 | * data_return = data; | |
2168 | ||
2169 | if (entry == NULL) | |
2170 | warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number); | |
2171 | ||
2172 | return entry; | |
2173 | } | |
2174 | ||
2175 | /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY | |
2176 | can be determined to be a signed type. The data for ENTRY can be | |
2177 | found starting at DATA. */ | |
ec1b0fbb NC |
2178 | |
2179 | static void | |
bcd213b2 NC |
2180 | get_type_signedness (abbrev_entry * entry, |
2181 | const struct dwarf_section * section, | |
ec1b0fbb NC |
2182 | unsigned char * data, |
2183 | unsigned const char * end, | |
bcd213b2 | 2184 | dwarf_vma cu_offset, |
ec1b0fbb NC |
2185 | dwarf_vma pointer_size, |
2186 | dwarf_vma offset_size, | |
2187 | int dwarf_version, | |
2188 | bfd_boolean * is_signed, | |
59624513 | 2189 | unsigned int nesting) |
ec1b0fbb | 2190 | { |
ec1b0fbb NC |
2191 | abbrev_attr * attr; |
2192 | ||
2193 | * is_signed = FALSE; | |
2194 | ||
59624513 NC |
2195 | #define MAX_NESTING 20 |
2196 | if (nesting > MAX_NESTING) | |
2197 | { | |
2198 | /* FIXME: Warn - or is this expected ? | |
2199 | NB/ We need to avoid infinite recursion. */ | |
2200 | return; | |
2201 | } | |
2202 | ||
ec1b0fbb NC |
2203 | for (attr = entry->first_attr; |
2204 | attr != NULL && attr->attribute; | |
2205 | attr = attr->next) | |
2206 | { | |
bcd213b2 | 2207 | unsigned char * orig_data = data; |
ec1b0fbb NC |
2208 | dwarf_vma uvalue = 0; |
2209 | ||
2210 | data = skip_attr_bytes (attr->form, data, end, pointer_size, | |
2211 | offset_size, dwarf_version, & uvalue); | |
2212 | if (data == NULL) | |
2213 | return; | |
2214 | ||
2215 | switch (attr->attribute) | |
2216 | { | |
bcd213b2 | 2217 | case DW_AT_linkage_name: |
ec1b0fbb | 2218 | case DW_AT_name: |
bcd213b2 NC |
2219 | if (do_wide) |
2220 | { | |
2221 | if (attr->form == DW_FORM_strp) | |
2222 | printf (", %s", fetch_indirect_string (uvalue)); | |
2223 | else if (attr->form == DW_FORM_string) | |
2224 | printf (", %s", orig_data); | |
2225 | } | |
ec1b0fbb | 2226 | break; |
bcd213b2 | 2227 | |
ec1b0fbb NC |
2228 | case DW_AT_type: |
2229 | /* Recurse. */ | |
bcd213b2 NC |
2230 | { |
2231 | abbrev_entry * type_abbrev; | |
2232 | unsigned char * type_data; | |
2233 | unsigned long type_cu_offset; | |
2234 | ||
2235 | type_abbrev = get_type_abbrev_from_form (attr->form, | |
2236 | uvalue, | |
2237 | cu_offset, | |
2238 | section, | |
2239 | NULL /* abbrev num return */, | |
2240 | & type_data, | |
2241 | & type_cu_offset); | |
2242 | if (type_abbrev == NULL) | |
2243 | break; | |
2244 | ||
2245 | get_type_signedness (type_abbrev, section, type_data, end, type_cu_offset, | |
2246 | pointer_size, offset_size, dwarf_version, | |
2247 | is_signed, nesting + 1); | |
2248 | } | |
ec1b0fbb NC |
2249 | break; |
2250 | ||
2251 | case DW_AT_encoding: | |
2252 | /* Determine signness. */ | |
2253 | switch (uvalue) | |
2254 | { | |
2255 | case DW_ATE_address: | |
2256 | /* FIXME - some architectures have signed addresses. */ | |
2257 | case DW_ATE_boolean: | |
2258 | case DW_ATE_unsigned: | |
2259 | case DW_ATE_unsigned_char: | |
2260 | case DW_ATE_unsigned_fixed: | |
2261 | * is_signed = FALSE; | |
2262 | break; | |
2263 | ||
2264 | default: | |
2265 | case DW_ATE_complex_float: | |
2266 | case DW_ATE_float: | |
2267 | case DW_ATE_signed: | |
2268 | case DW_ATE_signed_char: | |
2269 | case DW_ATE_imaginary_float: | |
2270 | case DW_ATE_decimal_float: | |
2271 | case DW_ATE_signed_fixed: | |
2272 | * is_signed = TRUE; | |
2273 | break; | |
2274 | } | |
2275 | break; | |
2276 | } | |
2277 | } | |
2278 | } | |
2279 | ||
2280 | static void | |
2281 | read_and_print_leb128 (unsigned char * data, | |
2282 | unsigned int * bytes_read, | |
2283 | unsigned const char * end, | |
2284 | bfd_boolean is_signed) | |
2285 | { | |
cd30bcef AM |
2286 | int status; |
2287 | dwarf_vma val = read_leb128 (data, end, is_signed, bytes_read, &status); | |
2288 | if (status != 0) | |
1b513401 | 2289 | report_leb_status (status, __FILE__, __LINE__); |
ec1b0fbb | 2290 | else |
cd30bcef | 2291 | printf ("%s", dwarf_vmatoa (is_signed ? "d" : "u", val)); |
ec1b0fbb NC |
2292 | } |
2293 | ||
2294 | static void | |
2295 | display_discr_list (unsigned long form, | |
2296 | dwarf_vma uvalue, | |
2297 | unsigned char * data, | |
2298 | unsigned const char * end, | |
2299 | int level) | |
2300 | { | |
2301 | if (uvalue == 0) | |
2302 | { | |
2303 | printf ("[default]"); | |
2304 | return; | |
2305 | } | |
2306 | ||
2307 | switch (form) | |
2308 | { | |
2309 | case DW_FORM_block: | |
2310 | case DW_FORM_block1: | |
2311 | case DW_FORM_block2: | |
2312 | case DW_FORM_block4: | |
2313 | /* Move data pointer back to the start of the byte array. */ | |
2314 | data -= uvalue; | |
2315 | break; | |
2316 | default: | |
2317 | printf ("<corrupt>\n"); | |
2318 | warn (_("corrupt discr_list - not using a block form\n")); | |
2319 | return; | |
2320 | } | |
2321 | ||
2322 | if (uvalue < 2) | |
2323 | { | |
2324 | printf ("<corrupt>\n"); | |
2325 | warn (_("corrupt discr_list - block not long enough\n")); | |
2326 | return; | |
2327 | } | |
2328 | ||
2329 | bfd_boolean is_signed = | |
2330 | (level > 0 && level <= MAX_CU_NESTING) | |
2331 | ? level_type_signed [level - 1] : FALSE; | |
2332 | ||
2333 | printf ("("); | |
2334 | while (uvalue) | |
2335 | { | |
2336 | unsigned char discriminant; | |
2337 | unsigned int bytes_read; | |
2338 | ||
2339 | SAFE_BYTE_GET (discriminant, data, 1, end); | |
2340 | -- uvalue; | |
2341 | data ++; | |
2342 | ||
2343 | assert (uvalue > 0); | |
2344 | switch (discriminant) | |
2345 | { | |
2346 | case DW_DSC_label: | |
2347 | printf ("label "); | |
2348 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2349 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2350 | uvalue -= bytes_read; | |
2351 | data += bytes_read; | |
2352 | break; | |
2353 | ||
2354 | case DW_DSC_range: | |
2355 | printf ("range "); | |
2356 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2357 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2358 | uvalue -= bytes_read; | |
2359 | data += bytes_read; | |
2360 | ||
2361 | printf (".."); | |
2362 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2363 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2364 | uvalue -= bytes_read; | |
2365 | data += bytes_read; | |
2366 | break; | |
2367 | ||
2368 | default: | |
2369 | printf ("<corrupt>\n"); | |
2370 | warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"), | |
2371 | discriminant); | |
2372 | return; | |
2373 | } | |
2374 | ||
2375 | if (uvalue) | |
2376 | printf (", "); | |
2377 | } | |
2378 | ||
2379 | if (is_signed) | |
2380 | printf (")(signed)"); | |
2381 | else | |
2382 | printf (")(unsigned)"); | |
2383 | } | |
2384 | ||
19e6b90e | 2385 | static unsigned char * |
dda8d76d NC |
2386 | read_and_display_attr_value (unsigned long attribute, |
2387 | unsigned long form, | |
2388 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 2389 | unsigned char * start, |
dda8d76d NC |
2390 | unsigned char * data, |
2391 | unsigned char * end, | |
2392 | dwarf_vma cu_offset, | |
2393 | dwarf_vma pointer_size, | |
2394 | dwarf_vma offset_size, | |
2395 | int dwarf_version, | |
2396 | debug_info * debug_info_p, | |
2397 | int do_loc, | |
2398 | struct dwarf_section * section, | |
2399 | struct cu_tu_set * this_set, | |
ec1b0fbb NC |
2400 | char delimiter, |
2401 | int level) | |
19e6b90e | 2402 | { |
cd30bcef | 2403 | dwarf_signed_vma svalue; |
ec1b0fbb NC |
2404 | dwarf_vma uvalue = 0; |
2405 | unsigned char * block_start = NULL; | |
2406 | unsigned char * orig_data = data; | |
19e6b90e | 2407 | |
f41e4712 | 2408 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 2409 | { |
f41e4712 | 2410 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
2411 | return data; |
2412 | } | |
2413 | ||
19e6b90e L |
2414 | switch (form) |
2415 | { | |
2416 | default: | |
2417 | break; | |
2418 | ||
2419 | case DW_FORM_ref_addr: | |
2420 | if (dwarf_version == 2) | |
0c588247 | 2421 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
ec47b32a | 2422 | else if (dwarf_version > 2) |
0c588247 | 2423 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 2424 | else |
ec47b32a | 2425 | error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n")); |
19e6b90e L |
2426 | break; |
2427 | ||
2428 | case DW_FORM_addr: | |
0c588247 | 2429 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
2430 | break; |
2431 | ||
2432 | case DW_FORM_strp: | |
77145576 | 2433 | case DW_FORM_line_strp: |
932fd279 | 2434 | case DW_FORM_sec_offset: |
a081f3cd JJ |
2435 | case DW_FORM_GNU_ref_alt: |
2436 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 2437 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
2438 | break; |
2439 | ||
932fd279 JJ |
2440 | case DW_FORM_flag_present: |
2441 | uvalue = 1; | |
2442 | break; | |
2443 | ||
19e6b90e L |
2444 | case DW_FORM_ref1: |
2445 | case DW_FORM_flag: | |
2446 | case DW_FORM_data1: | |
0c588247 | 2447 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
2448 | break; |
2449 | ||
2450 | case DW_FORM_ref2: | |
2451 | case DW_FORM_data2: | |
0c588247 | 2452 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
2453 | break; |
2454 | ||
2455 | case DW_FORM_ref4: | |
2456 | case DW_FORM_data4: | |
0c588247 | 2457 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
2458 | break; |
2459 | ||
2460 | case DW_FORM_sdata: | |
cd30bcef AM |
2461 | READ_SLEB (svalue, data, end); |
2462 | uvalue = svalue; | |
19e6b90e L |
2463 | break; |
2464 | ||
4723351a | 2465 | case DW_FORM_GNU_str_index: |
19e6b90e L |
2466 | case DW_FORM_ref_udata: |
2467 | case DW_FORM_udata: | |
cd30bcef AM |
2468 | case DW_FORM_GNU_addr_index: |
2469 | READ_ULEB (uvalue, data, end); | |
19e6b90e L |
2470 | break; |
2471 | ||
2472 | case DW_FORM_indirect: | |
cd30bcef | 2473 | READ_ULEB (form, data, end); |
19e6b90e | 2474 | if (!do_loc) |
ef0b5f1c | 2475 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 | 2476 | if (form == DW_FORM_implicit_const) |
cd30bcef | 2477 | READ_SLEB (implicit_const, data, end); |
ec1b0fbb NC |
2478 | return read_and_display_attr_value (attribute, form, implicit_const, |
2479 | start, data, end, | |
2480 | cu_offset, pointer_size, | |
19e6b90e | 2481 | offset_size, dwarf_version, |
ec4d4525 | 2482 | debug_info_p, do_loc, |
ec1b0fbb | 2483 | section, this_set, delimiter, level); |
19e6b90e L |
2484 | } |
2485 | ||
2486 | switch (form) | |
2487 | { | |
2488 | case DW_FORM_ref_addr: | |
2489 | if (!do_loc) | |
bcd213b2 | 2490 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2491 | break; |
2492 | ||
a081f3cd JJ |
2493 | case DW_FORM_GNU_ref_alt: |
2494 | if (!do_loc) | |
bcd213b2 | 2495 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); |
dda8d76d | 2496 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
2497 | break; |
2498 | ||
19e6b90e L |
2499 | case DW_FORM_ref1: |
2500 | case DW_FORM_ref2: | |
2501 | case DW_FORM_ref4: | |
2502 | case DW_FORM_ref_udata: | |
2503 | if (!do_loc) | |
ef0b5f1c | 2504 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
2505 | break; |
2506 | ||
2507 | case DW_FORM_data4: | |
2508 | case DW_FORM_addr: | |
932fd279 | 2509 | case DW_FORM_sec_offset: |
19e6b90e | 2510 | if (!do_loc) |
ef0b5f1c | 2511 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2512 | break; |
2513 | ||
932fd279 | 2514 | case DW_FORM_flag_present: |
19e6b90e L |
2515 | case DW_FORM_flag: |
2516 | case DW_FORM_data1: | |
2517 | case DW_FORM_data2: | |
2518 | case DW_FORM_sdata: | |
2519 | case DW_FORM_udata: | |
2520 | if (!do_loc) | |
ef0b5f1c | 2521 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
2522 | break; |
2523 | ||
77145576 JK |
2524 | case DW_FORM_implicit_const: |
2525 | if (!do_loc) | |
2526 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
2527 | break; | |
2528 | ||
19e6b90e L |
2529 | case DW_FORM_ref8: |
2530 | case DW_FORM_data8: | |
2bc8690c | 2531 | if (!do_loc) |
19e6b90e | 2532 | { |
74bc6052 | 2533 | dwarf_vma high_bits; |
a69c4772 | 2534 | dwarf_vma utmp; |
74bc6052 CC |
2535 | char buf[64]; |
2536 | ||
0c588247 | 2537 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
2538 | utmp = uvalue; |
2539 | if (form == DW_FORM_ref8) | |
2540 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 2541 | printf ("%c0x%s", delimiter, |
a69c4772 | 2542 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 2543 | } |
0c588247 | 2544 | |
19e6b90e L |
2545 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2546 | && num_debug_info_entries == 0) | |
2547 | { | |
2548 | if (sizeof (uvalue) == 8) | |
0c588247 | 2549 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 2550 | else |
467c65bc | 2551 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 2552 | } |
0c588247 | 2553 | |
19e6b90e L |
2554 | data += 8; |
2555 | break; | |
2556 | ||
2f6cd591 JK |
2557 | case DW_FORM_data16: |
2558 | if (!do_loc) | |
2559 | { | |
2560 | dwarf_vma left_high_bits, left_low_bits; | |
2561 | dwarf_vma right_high_bits, right_low_bits; | |
2562 | ||
2563 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
2564 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
2565 | if (byte_get == byte_get_little_endian) | |
2566 | { | |
2567 | /* Swap them. */ | |
2568 | left_high_bits ^= right_high_bits; | |
2569 | right_high_bits ^= left_high_bits; | |
2570 | left_high_bits ^= right_high_bits; | |
2571 | left_low_bits ^= right_low_bits; | |
2572 | right_low_bits ^= left_low_bits; | |
2573 | left_low_bits ^= right_low_bits; | |
2574 | } | |
2575 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
2576 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
2577 | left_high_bits, left_low_bits, right_high_bits, | |
2578 | right_low_bits); | |
2579 | } | |
2580 | data += 16; | |
2581 | break; | |
2582 | ||
19e6b90e L |
2583 | case DW_FORM_string: |
2584 | if (!do_loc) | |
ef0b5f1c | 2585 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 2586 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
2587 | break; |
2588 | ||
2589 | case DW_FORM_block: | |
932fd279 | 2590 | case DW_FORM_exprloc: |
cd30bcef AM |
2591 | READ_ULEB (uvalue, data, end); |
2592 | do_block: | |
2593 | block_start = data; | |
a1165289 NC |
2594 | if (block_start >= end) |
2595 | { | |
2596 | warn (_("Block ends prematurely\n")); | |
2597 | uvalue = 0; | |
2598 | block_start = end; | |
2599 | } | |
afc72f15 NC |
2600 | |
2601 | uvalue = check_uvalue (block_start, uvalue, end); | |
2602 | ||
19e6b90e L |
2603 | if (do_loc) |
2604 | data = block_start + uvalue; | |
2605 | else | |
ef0b5f1c | 2606 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2607 | break; |
2608 | ||
2609 | case DW_FORM_block1: | |
cd30bcef AM |
2610 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2611 | goto do_block; | |
19e6b90e L |
2612 | |
2613 | case DW_FORM_block2: | |
cd30bcef AM |
2614 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2615 | goto do_block; | |
19e6b90e L |
2616 | |
2617 | case DW_FORM_block4: | |
cd30bcef AM |
2618 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2619 | goto do_block; | |
19e6b90e L |
2620 | |
2621 | case DW_FORM_strp: | |
2622 | if (!do_loc) | |
ef0b5f1c | 2623 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, |
47704ddf KT |
2624 | dwarf_vmatoa ("x", uvalue), |
2625 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
2626 | break; |
2627 | ||
77145576 JK |
2628 | case DW_FORM_line_strp: |
2629 | if (!do_loc) | |
2630 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2631 | dwarf_vmatoa ("x", uvalue), | |
2632 | fetch_indirect_line_string (uvalue)); | |
2633 | break; | |
2634 | ||
4723351a CC |
2635 | case DW_FORM_GNU_str_index: |
2636 | if (!do_loc) | |
b4eb7656 | 2637 | { |
d85bf2ba NC |
2638 | const char * suffix = strrchr (section->name, '.'); |
2639 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
b4eb7656 | 2640 | |
ef0b5f1c | 2641 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2642 | dwarf_vmatoa ("x", uvalue), |
2643 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2644 | } | |
4723351a CC |
2645 | break; |
2646 | ||
a081f3cd JJ |
2647 | case DW_FORM_GNU_strp_alt: |
2648 | if (!do_loc) | |
dda8d76d NC |
2649 | { |
2650 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2651 | dwarf_vmatoa ("x", uvalue), | |
2652 | fetch_alt_indirect_string (uvalue)); | |
2653 | } | |
a081f3cd JJ |
2654 | break; |
2655 | ||
19e6b90e L |
2656 | case DW_FORM_indirect: |
2657 | /* Handled above. */ | |
2658 | break; | |
2659 | ||
2b6f5997 CC |
2660 | case DW_FORM_ref_sig8: |
2661 | if (!do_loc) | |
2662 | { | |
74bc6052 CC |
2663 | dwarf_vma high_bits; |
2664 | char buf[64]; | |
2665 | ||
0c588247 | 2666 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
ef0b5f1c | 2667 | printf ("%csignature: 0x%s", delimiter, |
74bc6052 | 2668 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); |
2b6f5997 | 2669 | } |
74bc6052 | 2670 | data += 8; |
2b6f5997 CC |
2671 | break; |
2672 | ||
4723351a CC |
2673 | case DW_FORM_GNU_addr_index: |
2674 | if (!do_loc) | |
ef0b5f1c | 2675 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2676 | dwarf_vmatoa ("x", uvalue), |
2677 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
4723351a CC |
2678 | break; |
2679 | ||
19e6b90e L |
2680 | default: |
2681 | warn (_("Unrecognized form: %lu\n"), form); | |
2682 | break; | |
2683 | } | |
2684 | ||
19e6b90e | 2685 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2686 | && num_debug_info_entries == 0 |
2687 | && debug_info_p != NULL) | |
19e6b90e L |
2688 | { |
2689 | switch (attribute) | |
2690 | { | |
2691 | case DW_AT_frame_base: | |
2692 | have_frame_base = 1; | |
1a0670f3 | 2693 | /* Fall through. */ |
19e6b90e | 2694 | case DW_AT_location: |
9f272209 | 2695 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2696 | case DW_AT_string_length: |
2697 | case DW_AT_return_addr: | |
19e6b90e L |
2698 | case DW_AT_data_member_location: |
2699 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2700 | case DW_AT_segment: |
2701 | case DW_AT_static_link: | |
2702 | case DW_AT_use_location: | |
bc0a77d2 | 2703 | case DW_AT_call_value: |
629e7ca8 | 2704 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2705 | case DW_AT_call_data_value: |
629e7ca8 | 2706 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2707 | case DW_AT_call_target: |
629e7ca8 | 2708 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2709 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2710 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2711 | if ((dwarf_version < 4 |
212b6063 | 2712 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2713 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2714 | { |
2715 | /* Process location list. */ | |
91d6fa6a | 2716 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2717 | unsigned int num = debug_info_p->num_loc_offsets; |
2718 | ||
91d6fa6a | 2719 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2720 | { |
91d6fa6a | 2721 | lmax += 1024; |
467c65bc | 2722 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2723 | xcrealloc (debug_info_p->loc_offsets, |
2724 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2725 | debug_info_p->loc_views = (dwarf_vma *) |
2726 | xcrealloc (debug_info_p->loc_views, | |
2727 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2728 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2729 | xcrealloc (debug_info_p->have_frame_base, |
2730 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2731 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2732 | } |
341f9135 | 2733 | if (this_set != NULL) |
b4eb7656 | 2734 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2735 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2736 | if (attribute != DW_AT_GNU_locviews) |
2737 | { | |
a7504f87 NC |
2738 | /* Corrupt DWARF info can produce more offsets than views. |
2739 | See PR 23062 for an example. */ | |
2740 | if (debug_info_p->num_loc_offsets | |
2741 | > debug_info_p->num_loc_views) | |
2742 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2743 | else | |
2744 | { | |
2745 | debug_info_p->loc_offsets [num] = uvalue; | |
2746 | debug_info_p->num_loc_offsets++; | |
2747 | } | |
9f272209 AO |
2748 | } |
2749 | else | |
2750 | { | |
2751 | assert (debug_info_p->num_loc_views <= num); | |
2752 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2753 | if (num > debug_info_p->num_loc_offsets) |
2754 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2755 | else | |
2756 | { | |
2757 | debug_info_p->loc_views [num] = uvalue; | |
2758 | debug_info_p->num_loc_views++; | |
2759 | } | |
9f272209 | 2760 | } |
19e6b90e L |
2761 | } |
2762 | break; | |
e2a0d921 | 2763 | |
19e6b90e L |
2764 | case DW_AT_low_pc: |
2765 | if (need_base_address) | |
2766 | debug_info_p->base_address = uvalue; | |
2767 | break; | |
2768 | ||
4723351a | 2769 | case DW_AT_GNU_addr_base: |
b4eb7656 | 2770 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2771 | break; |
2772 | ||
2773 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2774 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2775 | break; |
2776 | ||
19e6b90e | 2777 | case DW_AT_ranges: |
b4eb7656 | 2778 | if ((dwarf_version < 4 |
212b6063 | 2779 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2780 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2781 | { |
2782 | /* Process range list. */ | |
91d6fa6a | 2783 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2784 | unsigned int num = debug_info_p->num_range_lists; |
2785 | ||
91d6fa6a | 2786 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2787 | { |
91d6fa6a | 2788 | lmax += 1024; |
467c65bc | 2789 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2790 | xcrealloc (debug_info_p->range_lists, |
2791 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2792 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2793 | } |
2794 | debug_info_p->range_lists [num] = uvalue; | |
2795 | debug_info_p->num_range_lists++; | |
2796 | } | |
2797 | break; | |
2798 | ||
d85bf2ba NC |
2799 | case DW_AT_GNU_dwo_name: |
2800 | case DW_AT_dwo_name: | |
2801 | if (need_dwo_info) | |
2802 | switch (form) | |
2803 | { | |
2804 | case DW_FORM_strp: | |
24841daa | 2805 | add_dwo_name ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba | 2806 | break; |
5568cc9e NC |
2807 | case DW_FORM_GNU_strp_alt: |
2808 | add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue)); | |
2809 | break; | |
d85bf2ba | 2810 | case DW_FORM_GNU_str_index: |
24841daa | 2811 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2812 | break; |
2813 | case DW_FORM_string: | |
24841daa | 2814 | add_dwo_name ((const char *) orig_data); |
d85bf2ba NC |
2815 | break; |
2816 | default: | |
2817 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2818 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2819 | break; |
2820 | } | |
2821 | break; | |
2822 | ||
2823 | case DW_AT_comp_dir: | |
2824 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2825 | if (need_dwo_info) | |
2826 | switch (form) | |
2827 | { | |
2828 | case DW_FORM_strp: | |
24841daa | 2829 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba | 2830 | break; |
5568cc9e NC |
2831 | case DW_FORM_GNU_strp_alt: |
2832 | add_dwo_dir (fetch_alt_indirect_string (uvalue)); | |
2833 | break; | |
d85bf2ba | 2834 | case DW_FORM_line_strp: |
24841daa | 2835 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue)); |
d85bf2ba NC |
2836 | break; |
2837 | case DW_FORM_GNU_str_index: | |
24841daa | 2838 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2839 | break; |
2840 | case DW_FORM_string: | |
24841daa | 2841 | add_dwo_dir ((const char *) orig_data); |
d85bf2ba NC |
2842 | break; |
2843 | default: | |
2844 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2845 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2846 | break; |
2847 | } | |
2848 | break; | |
2849 | ||
2850 | case DW_AT_GNU_dwo_id: | |
2851 | if (need_dwo_info) | |
2852 | switch (form) | |
2853 | { | |
2854 | case DW_FORM_data8: | |
24841daa NC |
2855 | /* FIXME: Record the length of the ID as well ? */ |
2856 | add_dwo_id ((const char *) (data - 8)); | |
d85bf2ba NC |
2857 | break; |
2858 | default: | |
2859 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2860 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2861 | break; |
2862 | } | |
2863 | break; | |
2864 | ||
19e6b90e L |
2865 | default: |
2866 | break; | |
2867 | } | |
2868 | } | |
2869 | ||
4ccf1e31 | 2870 | if (do_loc || attribute == 0) |
19e6b90e L |
2871 | return data; |
2872 | ||
ec4d4525 | 2873 | /* For some attributes we can display further information. */ |
19e6b90e L |
2874 | switch (attribute) |
2875 | { | |
ec1b0fbb | 2876 | case DW_AT_type: |
b3fe587e AM |
2877 | if (level >= 0 && level < MAX_CU_NESTING |
2878 | && uvalue < (size_t) (end - start)) | |
ec1b0fbb NC |
2879 | { |
2880 | bfd_boolean is_signed = FALSE; | |
bcd213b2 NC |
2881 | abbrev_entry * type_abbrev; |
2882 | unsigned char * type_data; | |
2883 | unsigned long type_cu_offset; | |
2884 | ||
2885 | type_abbrev = get_type_abbrev_from_form (form, uvalue, cu_offset, | |
2886 | section, NULL, & type_data, & type_cu_offset); | |
2887 | if (type_abbrev != NULL) | |
2888 | { | |
2889 | get_type_signedness (type_abbrev, section, type_data, end, type_cu_offset, | |
2890 | pointer_size, offset_size, dwarf_version, | |
2891 | & is_signed, 0); | |
2892 | } | |
ec1b0fbb NC |
2893 | level_type_signed[level] = is_signed; |
2894 | } | |
2895 | break; | |
2896 | ||
19e6b90e | 2897 | case DW_AT_inline: |
2e9e81a8 | 2898 | printf ("\t"); |
19e6b90e L |
2899 | switch (uvalue) |
2900 | { | |
2901 | case DW_INL_not_inlined: | |
2902 | printf (_("(not inlined)")); | |
2903 | break; | |
2904 | case DW_INL_inlined: | |
2905 | printf (_("(inlined)")); | |
2906 | break; | |
2907 | case DW_INL_declared_not_inlined: | |
2908 | printf (_("(declared as inline but ignored)")); | |
2909 | break; | |
2910 | case DW_INL_declared_inlined: | |
2911 | printf (_("(declared as inline and inlined)")); | |
2912 | break; | |
2913 | default: | |
47704ddf KT |
2914 | printf (_(" (Unknown inline attribute value: %s)"), |
2915 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
2916 | break; |
2917 | } | |
2918 | break; | |
2919 | ||
2920 | case DW_AT_language: | |
2e9e81a8 | 2921 | printf ("\t"); |
19e6b90e L |
2922 | switch (uvalue) |
2923 | { | |
4b78141a | 2924 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 2925 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
2926 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
2927 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 2928 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
2929 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
2930 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
2931 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
2932 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 2933 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 2934 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 2935 | /* DWARF 2.1 values. */ |
4b78141a | 2936 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
2937 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
2938 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
2939 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
2940 | /* DWARF 3 values. */ |
2941 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
2942 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
2943 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
2944 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
2945 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
2946 | /* DWARF 4 values. */ |
2947 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 2948 | /* DWARF 5 values. */ |
2008a0db | 2949 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 2950 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
2951 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
2952 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
2953 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 2954 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
2955 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
2956 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 2957 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
2958 | case DW_LANG_Swift: printf ("(Swift)"); break; |
2959 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
2960 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 2961 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
2962 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
2963 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 2964 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
2965 | /* MIPS extension. */ |
2966 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
2967 | /* UPC extension. */ | |
2968 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
2969 | default: | |
4b78141a | 2970 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 2971 | printf (_("(implementation defined: %s)"), |
467c65bc | 2972 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 2973 | else |
9cf03b7e | 2974 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2975 | break; |
2976 | } | |
2977 | break; | |
2978 | ||
2979 | case DW_AT_encoding: | |
2e9e81a8 | 2980 | printf ("\t"); |
19e6b90e L |
2981 | switch (uvalue) |
2982 | { | |
2983 | case DW_ATE_void: printf ("(void)"); break; | |
2984 | case DW_ATE_address: printf ("(machine address)"); break; | |
2985 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
2986 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
2987 | case DW_ATE_float: printf ("(float)"); break; | |
2988 | case DW_ATE_signed: printf ("(signed)"); break; | |
2989 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
2990 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
2991 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 2992 | /* DWARF 2.1 values: */ |
19e6b90e L |
2993 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
2994 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
2995 | /* DWARF 3 values: */ |
2996 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
2997 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
2998 | case DW_ATE_edited: printf ("(edited)"); break; | |
2999 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
3000 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
3001 | /* DWARF 4 values: */ |
3002 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
3003 | /* DWARF 5 values: */ | |
3004 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
3005 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
3006 | ||
e2a0d921 NC |
3007 | /* HP extensions: */ |
3008 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
3009 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
3010 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
3011 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
3012 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
3013 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
3014 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
3015 | ||
19e6b90e L |
3016 | default: |
3017 | if (uvalue >= DW_ATE_lo_user | |
3018 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 3019 | printf (_("(user defined type)")); |
19e6b90e | 3020 | else |
9cf03b7e | 3021 | printf (_("(unknown type)")); |
19e6b90e L |
3022 | break; |
3023 | } | |
3024 | break; | |
3025 | ||
3026 | case DW_AT_accessibility: | |
2e9e81a8 | 3027 | printf ("\t"); |
19e6b90e L |
3028 | switch (uvalue) |
3029 | { | |
3030 | case DW_ACCESS_public: printf ("(public)"); break; | |
3031 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
3032 | case DW_ACCESS_private: printf ("(private)"); break; | |
3033 | default: | |
9cf03b7e | 3034 | printf (_("(unknown accessibility)")); |
19e6b90e L |
3035 | break; |
3036 | } | |
3037 | break; | |
3038 | ||
3039 | case DW_AT_visibility: | |
2e9e81a8 | 3040 | printf ("\t"); |
19e6b90e L |
3041 | switch (uvalue) |
3042 | { | |
3043 | case DW_VIS_local: printf ("(local)"); break; | |
3044 | case DW_VIS_exported: printf ("(exported)"); break; | |
3045 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 3046 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
3047 | } |
3048 | break; | |
3049 | ||
04914e37 NC |
3050 | case DW_AT_endianity: |
3051 | printf ("\t"); | |
3052 | switch (uvalue) | |
3053 | { | |
3054 | case DW_END_default: printf ("(default)"); break; | |
3055 | case DW_END_big: printf ("(big)"); break; | |
3056 | case DW_END_little: printf ("(little)"); break; | |
3057 | default: | |
3058 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
3059 | printf (_("(user specified)")); | |
3060 | else | |
3061 | printf (_("(unknown endianity)")); | |
3062 | break; | |
3063 | } | |
3064 | break; | |
3065 | ||
19e6b90e | 3066 | case DW_AT_virtuality: |
2e9e81a8 | 3067 | printf ("\t"); |
19e6b90e L |
3068 | switch (uvalue) |
3069 | { | |
3070 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
3071 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
3072 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 3073 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
3074 | } |
3075 | break; | |
3076 | ||
3077 | case DW_AT_identifier_case: | |
2e9e81a8 | 3078 | printf ("\t"); |
19e6b90e L |
3079 | switch (uvalue) |
3080 | { | |
3081 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
3082 | case DW_ID_up_case: printf ("(up_case)"); break; | |
3083 | case DW_ID_down_case: printf ("(down_case)"); break; | |
3084 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 3085 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
3086 | } |
3087 | break; | |
3088 | ||
3089 | case DW_AT_calling_convention: | |
2e9e81a8 | 3090 | printf ("\t"); |
19e6b90e L |
3091 | switch (uvalue) |
3092 | { | |
3093 | case DW_CC_normal: printf ("(normal)"); break; | |
3094 | case DW_CC_program: printf ("(program)"); break; | |
3095 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
3096 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
3097 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
3098 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
3099 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
3100 | default: |
3101 | if (uvalue >= DW_CC_lo_user | |
3102 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 3103 | printf (_("(user defined)")); |
19e6b90e | 3104 | else |
9cf03b7e | 3105 | printf (_("(unknown convention)")); |
19e6b90e L |
3106 | } |
3107 | break; | |
3108 | ||
3109 | case DW_AT_ordering: | |
2e9e81a8 | 3110 | printf ("\t"); |
19e6b90e L |
3111 | switch (uvalue) |
3112 | { | |
04914e37 | 3113 | case 255: |
9cf03b7e | 3114 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
3115 | case 0: printf ("(row major)"); break; |
3116 | case 1: printf ("(column major)"); break; | |
3117 | } | |
3118 | break; | |
3119 | ||
04914e37 NC |
3120 | case DW_AT_decimal_sign: |
3121 | printf ("\t"); | |
3122 | switch (uvalue) | |
3123 | { | |
3124 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
3125 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
3126 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
3127 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
3128 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
3129 | default: printf (_("(unrecognised)")); break; | |
3130 | } | |
3131 | break; | |
3132 | ||
3133 | case DW_AT_defaulted: | |
3134 | printf ("\t"); | |
3135 | switch (uvalue) | |
3136 | { | |
3137 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
3138 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
3139 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
3140 | default: printf (_("(unrecognised)")); break; | |
3141 | } | |
3142 | break; | |
3143 | ||
3144 | case DW_AT_discr_list: | |
3145 | printf ("\t"); | |
ec1b0fbb | 3146 | display_discr_list (form, uvalue, data, end, level); |
04914e37 NC |
3147 | break; |
3148 | ||
19e6b90e L |
3149 | case DW_AT_frame_base: |
3150 | have_frame_base = 1; | |
1a0670f3 | 3151 | /* Fall through. */ |
19e6b90e | 3152 | case DW_AT_location: |
e2a0d921 NC |
3153 | case DW_AT_string_length: |
3154 | case DW_AT_return_addr: | |
19e6b90e L |
3155 | case DW_AT_data_member_location: |
3156 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
3157 | case DW_AT_segment: |
3158 | case DW_AT_static_link: | |
3159 | case DW_AT_use_location: | |
bc0a77d2 | 3160 | case DW_AT_call_value: |
629e7ca8 | 3161 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 3162 | case DW_AT_call_data_value: |
629e7ca8 | 3163 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 3164 | case DW_AT_call_target: |
629e7ca8 | 3165 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 3166 | case DW_AT_call_target_clobbered: |
629e7ca8 | 3167 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 3168 | if ((dwarf_version < 4 |
b4eb7656 | 3169 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 3170 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 3171 | printf (_(" (location list)")); |
e2a0d921 | 3172 | /* Fall through. */ |
19e6b90e L |
3173 | case DW_AT_allocated: |
3174 | case DW_AT_associated: | |
3175 | case DW_AT_data_location: | |
3176 | case DW_AT_stride: | |
3177 | case DW_AT_upper_bound: | |
cecf136e | 3178 | case DW_AT_lower_bound: |
19e6b90e L |
3179 | if (block_start) |
3180 | { | |
3181 | int need_frame_base; | |
3182 | ||
2e9e81a8 | 3183 | printf ("\t("); |
19e6b90e L |
3184 | need_frame_base = decode_location_expression (block_start, |
3185 | pointer_size, | |
b7807392 JJ |
3186 | offset_size, |
3187 | dwarf_version, | |
19e6b90e | 3188 | uvalue, |
f1c4cc75 | 3189 | cu_offset, section); |
19e6b90e L |
3190 | printf (")"); |
3191 | if (need_frame_base && !have_frame_base) | |
3192 | printf (_(" [without DW_AT_frame_base]")); | |
3193 | } | |
19e6b90e L |
3194 | break; |
3195 | ||
c54207d3 NC |
3196 | case DW_AT_data_bit_offset: |
3197 | case DW_AT_byte_size: | |
3198 | case DW_AT_bit_size: | |
3199 | case DW_AT_string_length_byte_size: | |
3200 | case DW_AT_string_length_bit_size: | |
3201 | case DW_AT_bit_stride: | |
3202 | if (form == DW_FORM_exprloc) | |
3203 | { | |
3204 | printf ("\t("); | |
3205 | (void) decode_location_expression (block_start, pointer_size, | |
3206 | offset_size, dwarf_version, | |
3207 | uvalue, cu_offset, section); | |
3208 | printf (")"); | |
3209 | } | |
3210 | break; | |
3211 | ||
ec4d4525 NC |
3212 | case DW_AT_import: |
3213 | { | |
bcd213b2 NC |
3214 | unsigned long abbrev_number; |
3215 | abbrev_entry *entry; | |
2b6f5997 | 3216 | |
bcd213b2 NC |
3217 | entry = get_type_abbrev_from_form (form, uvalue, cu_offset, |
3218 | section, & abbrev_number, NULL, NULL); | |
3219 | if (entry == NULL) | |
3220 | { | |
3221 | if (form != DW_FORM_GNU_ref_alt) | |
3222 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), | |
3223 | dwarf_vmatoa ("x", uvalue), | |
3224 | (unsigned long) (orig_data - section->start)); | |
3225 | } | |
6e3d6dc1 NC |
3226 | else |
3227 | { | |
2e9e81a8 | 3228 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
bcd213b2 | 3229 | printf (" (%s)", get_TAG_name (entry->tag)); |
6e3d6dc1 NC |
3230 | printf ("]"); |
3231 | } | |
ec4d4525 NC |
3232 | } |
3233 | break; | |
3234 | ||
19e6b90e L |
3235 | default: |
3236 | break; | |
3237 | } | |
3238 | ||
3239 | return data; | |
3240 | } | |
3241 | ||
19e6b90e | 3242 | static unsigned char * |
dda8d76d NC |
3243 | read_and_display_attr (unsigned long attribute, |
3244 | unsigned long form, | |
3245 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 3246 | unsigned char * start, |
dda8d76d NC |
3247 | unsigned char * data, |
3248 | unsigned char * end, | |
3249 | dwarf_vma cu_offset, | |
3250 | dwarf_vma pointer_size, | |
3251 | dwarf_vma offset_size, | |
3252 | int dwarf_version, | |
3253 | debug_info * debug_info_p, | |
3254 | int do_loc, | |
3255 | struct dwarf_section * section, | |
ec1b0fbb NC |
3256 | struct cu_tu_set * this_set, |
3257 | int level) | |
19e6b90e L |
3258 | { |
3259 | if (!do_loc) | |
750f03b7 | 3260 | printf (" %-18s:", get_AT_name (attribute)); |
ec1b0fbb NC |
3261 | data = read_and_display_attr_value (attribute, form, implicit_const, |
3262 | start, data, end, | |
f6f0e17b | 3263 | cu_offset, pointer_size, offset_size, |
19e6b90e | 3264 | dwarf_version, debug_info_p, |
ec1b0fbb | 3265 | do_loc, section, this_set, ' ', level); |
19e6b90e L |
3266 | if (!do_loc) |
3267 | printf ("\n"); | |
3268 | return data; | |
3269 | } | |
3270 | ||
dda8d76d | 3271 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
3272 | following debug links, then attempt to load the requested section |
3273 | from one of the separate debug info files. */ | |
dda8d76d NC |
3274 | |
3275 | static bfd_boolean | |
3276 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, | |
24841daa | 3277 | void * handle) |
dda8d76d | 3278 | { |
24841daa | 3279 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 3280 | { |
24841daa NC |
3281 | if (debug_displays[sec_enum].section.filename == NULL) |
3282 | { | |
3283 | /* See if we can associate a filename with this section. */ | |
3284 | separate_info * i; | |
3285 | ||
3286 | for (i = first_separate_info; i != NULL; i = i->next) | |
3287 | if (i->handle == handle) | |
3288 | { | |
3289 | debug_displays[sec_enum].section.filename = i->filename; | |
3290 | break; | |
3291 | } | |
3292 | } | |
3293 | ||
dda8d76d NC |
3294 | return TRUE; |
3295 | } | |
3296 | ||
24841daa NC |
3297 | if (do_follow_links) |
3298 | { | |
3299 | separate_info * i; | |
3300 | ||
3301 | for (i = first_separate_info; i != NULL; i = i->next) | |
3302 | { | |
3303 | if (load_debug_section (sec_enum, i->handle)) | |
3304 | { | |
3305 | debug_displays[sec_enum].section.filename = i->filename; | |
3306 | ||
3307 | /* FIXME: We should check to see if any of the remaining debug info | |
3308 | files also contain this section, and, umm, do something about it. */ | |
3309 | return TRUE; | |
3310 | } | |
3311 | } | |
3312 | } | |
dda8d76d NC |
3313 | |
3314 | return FALSE; | |
3315 | } | |
3316 | ||
3317 | static void | |
3318 | introduce (struct dwarf_section * section, bfd_boolean raw) | |
3319 | { | |
3320 | if (raw) | |
3321 | { | |
3322 | if (do_follow_links && section->filename) | |
3323 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
3324 | section->name, section->filename); | |
3325 | else | |
3326 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
3327 | } | |
3328 | else | |
3329 | { | |
3330 | if (do_follow_links && section->filename) | |
3331 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
3332 | section->name, section->filename); | |
3333 | else | |
3334 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3335 | } | |
3336 | } | |
3337 | ||
d85bf2ba NC |
3338 | /* Process the contents of a .debug_info section. |
3339 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
3340 | and we do not want to display anything to the user. | |
3341 | If do_types is TRUE, we are processing a .debug_types section instead of | |
3342 | a .debug_info section. | |
3343 | The information displayed is restricted by the values in DWARF_START_DIE | |
3344 | and DWARF_CUTOFF_LEVEL. | |
3345 | Returns TRUE upon success. Otherwise an error or warning message is | |
3346 | printed and FALSE is returned. */ | |
19e6b90e | 3347 | |
d85bf2ba NC |
3348 | static bfd_boolean |
3349 | process_debug_info (struct dwarf_section * section, | |
3350 | void * file, | |
3351 | enum dwarf_section_display_enum abbrev_sec, | |
3352 | bfd_boolean do_loc, | |
3353 | bfd_boolean do_types) | |
19e6b90e L |
3354 | { |
3355 | unsigned char *start = section->start; | |
3356 | unsigned char *end = start + section->size; | |
3357 | unsigned char *section_begin; | |
3358 | unsigned int unit; | |
3359 | unsigned int num_units = 0; | |
3360 | ||
3361 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3362 | && num_debug_info_entries == 0 |
3363 | && ! do_types) | |
19e6b90e | 3364 | { |
767221a9 | 3365 | dwarf_vma length; |
19e6b90e L |
3366 | |
3367 | /* First scan the section to get the number of comp units. */ | |
3368 | for (section_begin = start, num_units = 0; section_begin < end; | |
3369 | num_units ++) | |
3370 | { | |
3371 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
3372 | will be the length. For a 64-bit DWARF section, it'll be | |
3373 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 3374 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
3375 | |
3376 | if (length == 0xffffffff) | |
3377 | { | |
0c588247 | 3378 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
3379 | section_begin += length + 12; |
3380 | } | |
ec4d4525 NC |
3381 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
3382 | { | |
767221a9 NC |
3383 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
3384 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3385 | return FALSE; |
ec4d4525 | 3386 | } |
19e6b90e L |
3387 | else |
3388 | section_begin += length + 4; | |
aca88567 NC |
3389 | |
3390 | /* Negative values are illegal, they may even cause infinite | |
3391 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
3392 | relocations to an object file, or if the file is corrupt. */ |
3393 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 3394 | { |
767221a9 NC |
3395 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
3396 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3397 | return FALSE; |
aca88567 | 3398 | } |
19e6b90e L |
3399 | } |
3400 | ||
3401 | if (num_units == 0) | |
3402 | { | |
f41e4712 | 3403 | error (_("No comp units in %s section ?\n"), section->name); |
d85bf2ba | 3404 | return FALSE; |
19e6b90e L |
3405 | } |
3406 | ||
3407 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 3408 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 3409 | sizeof (* debug_information)); |
19e6b90e L |
3410 | if (debug_information == NULL) |
3411 | { | |
f41e4712 | 3412 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 3413 | num_units); |
82b1b41b | 3414 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
d85bf2ba | 3415 | return FALSE; |
19e6b90e | 3416 | } |
d85bf2ba | 3417 | |
03a91817 NC |
3418 | /* PR 17531: file: 92ca3797. |
3419 | We cannot rely upon the debug_information array being initialised | |
3420 | before it is used. A corrupt file could easily contain references | |
3421 | to a unit for which information has not been made available. So | |
3422 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
3423 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
3424 | ||
82b1b41b | 3425 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
3426 | } |
3427 | ||
3428 | if (!do_loc) | |
3429 | { | |
dda8d76d NC |
3430 | load_debug_section_with_follow (str, file); |
3431 | load_debug_section_with_follow (line_str, file); | |
3432 | load_debug_section_with_follow (str_dwo, file); | |
3433 | load_debug_section_with_follow (str_index, file); | |
3434 | load_debug_section_with_follow (str_index_dwo, file); | |
3435 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e | 3436 | } |
e4b7104b | 3437 | |
dda8d76d | 3438 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 3439 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
3440 | { |
3441 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 3442 | debug_displays [abbrev_sec].section.uncompressed_name); |
d85bf2ba | 3443 | return FALSE; |
19e6b90e L |
3444 | } |
3445 | ||
dda8d76d NC |
3446 | if (!do_loc && dwarf_start_die == 0) |
3447 | introduce (section, FALSE); | |
bcd213b2 NC |
3448 | |
3449 | free_all_abbrevs (); | |
3450 | free (cu_abbrev_map); | |
3451 | cu_abbrev_map = NULL; | |
3452 | next_free_abbrev_map_entry = 0; | |
dda8d76d | 3453 | |
bcd213b2 NC |
3454 | /* In order to be able to resolve DW_FORM_ref_attr forms we need |
3455 | to load *all* of the abbrevs for all CUs in this .debug_info | |
3456 | section. This does effectively mean that we (partially) read | |
3457 | every CU header twice. */ | |
3458 | for (section_begin = start; start < end;) | |
3459 | { | |
3460 | DWARF2_Internal_CompUnit compunit; | |
3461 | unsigned char * hdrptr; | |
76868f36 L |
3462 | dwarf_vma abbrev_base; |
3463 | size_t abbrev_size; | |
bcd213b2 NC |
3464 | dwarf_vma cu_offset; |
3465 | unsigned int offset_size; | |
3466 | unsigned int initial_length_size; | |
3467 | struct cu_tu_set * this_set; | |
3468 | abbrev_list * list; | |
3469 | ||
3470 | hdrptr = start; | |
3471 | ||
3472 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); | |
3473 | ||
3474 | if (compunit.cu_length == 0xffffffff) | |
3475 | { | |
3476 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); | |
3477 | offset_size = 8; | |
3478 | initial_length_size = 12; | |
3479 | } | |
3480 | else | |
3481 | { | |
3482 | offset_size = 4; | |
3483 | initial_length_size = 4; | |
3484 | } | |
3485 | ||
3486 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); | |
3487 | ||
3488 | cu_offset = start - section_begin; | |
3489 | ||
3490 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); | |
3491 | ||
3492 | if (compunit.cu_version < 5) | |
3493 | { | |
3494 | compunit.cu_unit_type = DW_UT_compile; | |
3495 | /* Initialize it due to a false compiler warning. */ | |
3496 | compunit.cu_pointer_size = -1; | |
3497 | } | |
3498 | else | |
3499 | { | |
3500 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3501 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3502 | ||
3503 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3504 | } | |
3505 | ||
3506 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); | |
3507 | ||
76868f36 L |
3508 | if (this_set == NULL) |
3509 | { | |
3510 | abbrev_base = 0; | |
3511 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3512 | } | |
3513 | else | |
3514 | { | |
3515 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3516 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3517 | } | |
3518 | ||
3519 | list = find_abbrev_list_by_abbrev_offset (abbrev_base, | |
3520 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3521 | if (list == NULL) |
3522 | { | |
bcd213b2 NC |
3523 | unsigned char * next; |
3524 | ||
76868f36 L |
3525 | list = new_abbrev_list (abbrev_base, |
3526 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3527 | next = process_abbrev_set |
3528 | (((unsigned char *) debug_displays [abbrev_sec].section.start | |
3529 | + abbrev_base + compunit.cu_abbrev_offset), | |
3530 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3531 | + abbrev_base + abbrev_size), | |
3532 | list); | |
3533 | list->start_of_next_abbrevs = next; | |
3534 | } | |
3535 | ||
3536 | start = section_begin + cu_offset + compunit.cu_length | |
3537 | + initial_length_size; | |
3538 | record_abbrev_list_for_cu (cu_offset, start - section_begin, list); | |
3539 | } | |
3540 | ||
3541 | for (start = section_begin, unit = 0; start < end; unit++) | |
19e6b90e L |
3542 | { |
3543 | DWARF2_Internal_CompUnit compunit; | |
3544 | unsigned char *hdrptr; | |
19e6b90e | 3545 | unsigned char *tags; |
fd2f0033 | 3546 | int level, last_level, saved_level; |
467c65bc | 3547 | dwarf_vma cu_offset; |
e98fdf1a | 3548 | unsigned long sec_off; |
bf5117e3 | 3549 | unsigned int offset_size; |
19485196 | 3550 | unsigned int initial_length_size; |
74bc6052 CC |
3551 | dwarf_vma signature_high = 0; |
3552 | dwarf_vma signature_low = 0; | |
767221a9 | 3553 | dwarf_vma type_offset = 0; |
341f9135 CC |
3554 | struct cu_tu_set *this_set; |
3555 | dwarf_vma abbrev_base; | |
3556 | size_t abbrev_size; | |
bcd213b2 | 3557 | abbrev_list * list = NULL; |
19e6b90e L |
3558 | |
3559 | hdrptr = start; | |
3560 | ||
0c588247 | 3561 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
3562 | |
3563 | if (compunit.cu_length == 0xffffffff) | |
3564 | { | |
0c588247 | 3565 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
3566 | offset_size = 8; |
3567 | initial_length_size = 12; | |
3568 | } | |
3569 | else | |
3570 | { | |
3571 | offset_size = 4; | |
3572 | initial_length_size = 4; | |
3573 | } | |
3574 | ||
0c588247 | 3575 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
3576 | |
3577 | cu_offset = start - section_begin; | |
19e6b90e | 3578 | |
341f9135 CC |
3579 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3580 | ||
77145576 JK |
3581 | if (compunit.cu_version < 5) |
3582 | { | |
3583 | compunit.cu_unit_type = DW_UT_compile; | |
3584 | /* Initialize it due to a false compiler warning. */ | |
3585 | compunit.cu_pointer_size = -1; | |
3586 | } | |
3587 | else | |
3588 | { | |
3589 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3590 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3591 | ||
3592 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3593 | } | |
3594 | ||
0c588247 | 3595 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 3596 | |
341f9135 CC |
3597 | if (this_set == NULL) |
3598 | { | |
3599 | abbrev_base = 0; | |
3600 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3601 | } | |
3602 | else | |
3603 | { | |
3604 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3605 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3606 | } | |
3607 | ||
77145576 JK |
3608 | if (compunit.cu_version < 5) |
3609 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3610 | ||
f41e4712 NC |
3611 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
3612 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
3613 | { | |
3614 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
3615 | compunit.cu_pointer_size, offset_size); | |
3616 | compunit.cu_pointer_size = offset_size; | |
3617 | } | |
2b6f5997 CC |
3618 | |
3619 | if (do_types) | |
b4eb7656 | 3620 | { |
0c588247 | 3621 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 3622 | hdrptr += 8; |
0c588247 | 3623 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 3624 | } |
2b6f5997 | 3625 | |
ae7e7825 NC |
3626 | if (dwarf_start_die > (cu_offset + compunit.cu_length |
3627 | + initial_length_size)) | |
3628 | { | |
3629 | start = section_begin + cu_offset + compunit.cu_length | |
3630 | + initial_length_size; | |
3631 | continue; | |
3632 | } | |
3633 | ||
19e6b90e | 3634 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 | 3635 | && num_debug_info_entries == 0 |
c4b2f181 | 3636 | && alloc_num_debug_info_entries > unit |
2b6f5997 | 3637 | && ! do_types) |
19e6b90e L |
3638 | { |
3639 | debug_information [unit].cu_offset = cu_offset; | |
3640 | debug_information [unit].pointer_size | |
3641 | = compunit.cu_pointer_size; | |
b7807392 JJ |
3642 | debug_information [unit].offset_size = offset_size; |
3643 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 3644 | debug_information [unit].base_address = 0; |
4723351a CC |
3645 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
3646 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
3647 | debug_information [unit].loc_offsets = NULL; |
3648 | debug_information [unit].have_frame_base = NULL; | |
3649 | debug_information [unit].max_loc_offsets = 0; | |
3650 | debug_information [unit].num_loc_offsets = 0; | |
3651 | debug_information [unit].range_lists = NULL; | |
3652 | debug_information [unit].max_range_lists= 0; | |
3653 | debug_information [unit].num_range_lists = 0; | |
3654 | } | |
3655 | ||
fd2f0033 | 3656 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 3657 | { |
47704ddf KT |
3658 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3659 | dwarf_vmatoa ("x", cu_offset)); | |
3660 | printf (_(" Length: 0x%s (%s)\n"), | |
3661 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3662 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3663 | printf (_(" Version: %d\n"), compunit.cu_version); |
debd1a62 MW |
3664 | if (compunit.cu_version >= 5) |
3665 | printf (_(" Unit Type: %s (%x)\n"), | |
3666 | get_DW_UT_name (compunit.cu_unit_type) ?: "???", | |
3667 | compunit.cu_unit_type); | |
7282333f AM |
3668 | printf (_(" Abbrev Offset: 0x%s\n"), |
3669 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3670 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3671 | if (do_types) |
3672 | { | |
74bc6052 CC |
3673 | char buf[64]; |
3674 | ||
3675 | printf (_(" Signature: 0x%s\n"), | |
3676 | dwarf_vmatoa64 (signature_high, signature_low, | |
3677 | buf, sizeof (buf))); | |
3678 | printf (_(" Type Offset: 0x%s\n"), | |
3679 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3680 | } |
341f9135 CC |
3681 | if (this_set != NULL) |
3682 | { | |
3683 | dwarf_vma *offsets = this_set->section_offsets; | |
3684 | size_t *sizes = this_set->section_sizes; | |
3685 | ||
3686 | printf (_(" Section contributions:\n")); | |
3687 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3688 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3689 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3690 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3691 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3692 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3693 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3694 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3695 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3696 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3697 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3698 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3699 | } | |
19e6b90e L |
3700 | } |
3701 | ||
e98fdf1a AM |
3702 | sec_off = cu_offset + initial_length_size; |
3703 | if (sec_off + compunit.cu_length < sec_off | |
3704 | || sec_off + compunit.cu_length > section->size) | |
460c89ff | 3705 | { |
e98fdf1a AM |
3706 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
3707 | section->name, | |
3708 | (unsigned long) cu_offset, | |
19485196 NC |
3709 | dwarf_vmatoa ("x", compunit.cu_length)); |
3710 | num_units = unit; | |
3711 | break; | |
3712 | } | |
3713 | ||
460c89ff NS |
3714 | tags = hdrptr; |
3715 | start += compunit.cu_length + initial_length_size; | |
3716 | ||
77145576 | 3717 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3718 | { |
47704ddf KT |
3719 | warn (_("CU at offset %s contains corrupt or " |
3720 | "unsupported version number: %d.\n"), | |
3721 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3722 | continue; |
3723 | } | |
3724 | ||
77145576 | 3725 | if (compunit.cu_unit_type != DW_UT_compile |
ec47b32a | 3726 | && compunit.cu_unit_type != DW_UT_partial |
77145576 JK |
3727 | && compunit.cu_unit_type != DW_UT_type) |
3728 | { | |
3729 | warn (_("CU at offset %s contains corrupt or " | |
3730 | "unsupported unit type: %d.\n"), | |
3731 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3732 | continue; | |
3733 | } | |
3734 | ||
d493b283 | 3735 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 3736 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
3737 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
3738 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 3739 | (unsigned long) abbrev_size); |
b4eb7656 | 3740 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
3741 | else if ((abbrev_base + abbrev_size) |
3742 | > debug_displays [abbrev_sec].section.size) | |
3743 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
3744 | (unsigned long) abbrev_base + abbrev_size, | |
3745 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff | 3746 | else |
bcd213b2 | 3747 | { |
76868f36 L |
3748 | list = find_abbrev_list_by_abbrev_offset (abbrev_base, |
3749 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3750 | if (list == NULL) |
3751 | { | |
3752 | unsigned char * next; | |
3753 | ||
76868f36 L |
3754 | list = new_abbrev_list (abbrev_base, |
3755 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3756 | next = process_abbrev_set |
3757 | (((unsigned char *) debug_displays [abbrev_sec].section.start | |
3758 | + abbrev_base + compunit.cu_abbrev_offset), | |
3759 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3760 | + abbrev_base + abbrev_size), | |
3761 | list); | |
3762 | list->start_of_next_abbrevs = next; | |
3763 | } | |
3764 | } | |
19e6b90e L |
3765 | |
3766 | level = 0; | |
fd2f0033 TT |
3767 | last_level = level; |
3768 | saved_level = -1; | |
19e6b90e L |
3769 | while (tags < start) |
3770 | { | |
19e6b90e | 3771 | unsigned long abbrev_number; |
ec4d4525 | 3772 | unsigned long die_offset; |
19e6b90e L |
3773 | abbrev_entry *entry; |
3774 | abbrev_attr *attr; | |
fd2f0033 | 3775 | int do_printing = 1; |
19e6b90e | 3776 | |
ec4d4525 NC |
3777 | die_offset = tags - section_begin; |
3778 | ||
cd30bcef | 3779 | READ_ULEB (abbrev_number, tags, start); |
19e6b90e | 3780 | |
eb7cc021 JK |
3781 | /* A null DIE marks the end of a list of siblings or it may also be |
3782 | a section padding. */ | |
19e6b90e L |
3783 | if (abbrev_number == 0) |
3784 | { | |
eb7cc021 JK |
3785 | /* Check if it can be a section padding for the last CU. */ |
3786 | if (level == 0 && start == end) | |
3787 | { | |
3788 | unsigned char *chk; | |
3789 | ||
3790 | for (chk = tags; chk < start; chk++) | |
3791 | if (*chk != 0) | |
3792 | break; | |
3793 | if (chk == start) | |
3794 | break; | |
3795 | } | |
3796 | ||
4337774f TT |
3797 | if (!do_loc && die_offset >= dwarf_start_die |
3798 | && (dwarf_cutoff_level == -1 | |
3799 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3800 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3801 | level, die_offset); | |
3802 | ||
19e6b90e | 3803 | --level; |
ec4d4525 NC |
3804 | if (level < 0) |
3805 | { | |
3806 | static unsigned num_bogus_warns = 0; | |
3807 | ||
3808 | if (num_bogus_warns < 3) | |
3809 | { | |
4723351a CC |
3810 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3811 | die_offset, section->name); | |
ec4d4525 NC |
3812 | num_bogus_warns ++; |
3813 | if (num_bogus_warns == 3) | |
3814 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3815 | } | |
3816 | } | |
fd2f0033 | 3817 | if (dwarf_start_die != 0 && level < saved_level) |
d85bf2ba | 3818 | return TRUE; |
19e6b90e L |
3819 | continue; |
3820 | } | |
3821 | ||
4b78141a | 3822 | if (!do_loc) |
fd2f0033 TT |
3823 | { |
3824 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
3825 | do_printing = 0; | |
3826 | else | |
3827 | { | |
3828 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
3829 | saved_level = level; | |
3830 | do_printing = (dwarf_cutoff_level == -1 | |
3831 | || level < dwarf_cutoff_level); | |
3832 | if (do_printing) | |
3833 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
3834 | level, die_offset, abbrev_number); | |
3835 | else if (dwarf_cutoff_level == -1 | |
3836 | || last_level < dwarf_cutoff_level) | |
3837 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
3838 | last_level = level; | |
3839 | } | |
3840 | } | |
cecf136e | 3841 | |
19e6b90e L |
3842 | /* Scan through the abbreviation list until we reach the |
3843 | correct entry. */ | |
bcd213b2 | 3844 | if (list == NULL) |
19e6b90e L |
3845 | continue; |
3846 | ||
bcd213b2 NC |
3847 | for (entry = list->first_abbrev; entry != NULL; entry = entry->next) |
3848 | if (entry->number == abbrev_number) | |
3849 | break; | |
3850 | ||
19e6b90e L |
3851 | if (entry == NULL) |
3852 | { | |
fd2f0033 | 3853 | if (!do_loc && do_printing) |
4b78141a NC |
3854 | { |
3855 | printf ("\n"); | |
3856 | fflush (stdout); | |
3857 | } | |
f3853b34 | 3858 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 3859 | die_offset, abbrev_number); |
d85bf2ba | 3860 | return FALSE; |
19e6b90e L |
3861 | } |
3862 | ||
fd2f0033 | 3863 | if (!do_loc && do_printing) |
cc5914eb | 3864 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 3865 | |
19e6b90e L |
3866 | switch (entry->tag) |
3867 | { | |
3868 | default: | |
3869 | need_base_address = 0; | |
3870 | break; | |
3871 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
3872 | need_base_address = 1; |
3873 | need_dwo_info = do_loc; | |
19e6b90e L |
3874 | break; |
3875 | case DW_TAG_entry_point: | |
19e6b90e L |
3876 | case DW_TAG_subprogram: |
3877 | need_base_address = 0; | |
3878 | /* Assuming that there is no DW_AT_frame_base. */ | |
3879 | have_frame_base = 0; | |
3880 | break; | |
3881 | } | |
3882 | ||
9f272209 AO |
3883 | debug_info *debug_info_p = |
3884 | (debug_information && unit < alloc_num_debug_info_entries) | |
3885 | ? debug_information + unit : NULL; | |
3886 | ||
3887 | assert (!debug_info_p | |
3888 | || (debug_info_p->num_loc_offsets | |
3889 | == debug_info_p->num_loc_views)); | |
3890 | ||
399c99f7 L |
3891 | for (attr = entry->first_attr; |
3892 | attr && attr->attribute; | |
3893 | attr = attr->next) | |
4b78141a | 3894 | { |
fd2f0033 | 3895 | if (! do_loc && do_printing) |
4b78141a | 3896 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 | 3897 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
3898 | tags = read_and_display_attr (attr->attribute, |
3899 | attr->form, | |
77145576 | 3900 | attr->implicit_const, |
ec1b0fbb | 3901 | section_begin, |
341f9135 | 3902 | tags, |
f6f0e17b | 3903 | end, |
341f9135 | 3904 | cu_offset, |
4b78141a NC |
3905 | compunit.cu_pointer_size, |
3906 | offset_size, | |
3907 | compunit.cu_version, | |
9f272209 | 3908 | debug_info_p, |
341f9135 CC |
3909 | do_loc || ! do_printing, |
3910 | section, | |
ec1b0fbb NC |
3911 | this_set, |
3912 | level); | |
4b78141a | 3913 | } |
cecf136e | 3914 | |
9f272209 AO |
3915 | /* If a locview attribute appears before a location one, |
3916 | make sure we don't associate it with an earlier | |
3917 | loclist. */ | |
3918 | if (debug_info_p) | |
3919 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
3920 | { | |
3921 | case 1: | |
3922 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
3923 | debug_info_p->num_loc_views++; | |
3924 | assert (debug_info_p->num_loc_views | |
3925 | == debug_info_p->num_loc_offsets); | |
3926 | break; | |
3927 | ||
3928 | case 0: | |
3929 | break; | |
3930 | ||
3931 | case -1: | |
3932 | warn(_("DIE has locviews without loclist\n")); | |
3933 | debug_info_p->num_loc_views--; | |
3934 | break; | |
3935 | ||
3936 | default: | |
3937 | assert (0); | |
3938 | } | |
3939 | ||
b4eb7656 AM |
3940 | if (entry->children) |
3941 | ++level; | |
3942 | } | |
19e6b90e | 3943 | } |
cecf136e | 3944 | |
19e6b90e L |
3945 | /* Set num_debug_info_entries here so that it can be used to check if |
3946 | we need to process .debug_loc and .debug_ranges sections. */ | |
3947 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3948 | && num_debug_info_entries == 0 |
3949 | && ! do_types) | |
82b1b41b | 3950 | { |
b4eb7656 | 3951 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
3952 | num_debug_info_entries = alloc_num_debug_info_entries; |
3953 | else | |
3954 | num_debug_info_entries = num_units; | |
3955 | } | |
cecf136e | 3956 | |
19e6b90e | 3957 | if (!do_loc) |
467c65bc | 3958 | printf ("\n"); |
cecf136e | 3959 | |
d85bf2ba | 3960 | return TRUE; |
19e6b90e L |
3961 | } |
3962 | ||
3963 | /* Locate and scan the .debug_info section in the file and record the pointer | |
3964 | sizes and offsets for the compilation units in it. Usually an executable | |
3965 | will have just one pointer size, but this is not guaranteed, and so we try | |
3966 | not to make any assumptions. Returns zero upon failure, or the number of | |
3967 | compilation units upon success. */ | |
3968 | ||
3969 | static unsigned int | |
3970 | load_debug_info (void * file) | |
3971 | { | |
1febe64d | 3972 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 3973 | section then do not bother to repeat the task. */ |
cc86f28f | 3974 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
3975 | return 0; |
3976 | ||
19e6b90e L |
3977 | /* If we already have the information there is nothing else to do. */ |
3978 | if (num_debug_info_entries > 0) | |
3979 | return num_debug_info_entries; | |
3980 | ||
341f9135 | 3981 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 3982 | (void) load_cu_tu_indexes (file); |
341f9135 | 3983 | |
dda8d76d | 3984 | if (load_debug_section_with_follow (info, file) |
d85bf2ba | 3985 | && process_debug_info (&debug_displays [info].section, file, abbrev, TRUE, FALSE)) |
19e6b90e | 3986 | return num_debug_info_entries; |
82b1b41b | 3987 | |
dda8d76d | 3988 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 3989 | && process_debug_info (&debug_displays [info_dwo].section, file, |
d85bf2ba | 3990 | abbrev_dwo, TRUE, FALSE)) |
4723351a | 3991 | return num_debug_info_entries; |
1febe64d | 3992 | |
cc86f28f | 3993 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 3994 | return 0; |
19e6b90e L |
3995 | } |
3996 | ||
b40bf0a2 NC |
3997 | /* Read a DWARF .debug_line section header starting at DATA. |
3998 | Upon success returns an updated DATA pointer and the LINFO | |
3999 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
4000 | Otherwise returns NULL. */ | |
19e6b90e | 4001 | |
b40bf0a2 NC |
4002 | static unsigned char * |
4003 | read_debug_line_header (struct dwarf_section * section, | |
4004 | unsigned char * data, | |
4005 | unsigned char * end, | |
4006 | DWARF2_Internal_LineInfo * linfo, | |
4007 | unsigned char ** end_of_sequence) | |
4008 | { | |
4009 | unsigned char *hdrptr; | |
b40bf0a2 | 4010 | unsigned int initial_length_size; |
19e6b90e | 4011 | |
b40bf0a2 NC |
4012 | /* Extract information from the Line Number Program Header. |
4013 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 4014 | hdrptr = data; |
19e6b90e | 4015 | |
b40bf0a2 NC |
4016 | /* Get and check the length of the block. */ |
4017 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 4018 | |
b40bf0a2 | 4019 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
4020 | { |
4021 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 4022 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 4023 | linfo->li_offset_size = 8; |
f41e4712 NC |
4024 | initial_length_size = 12; |
4025 | } | |
4026 | else | |
4027 | { | |
77145576 | 4028 | linfo->li_offset_size = 4; |
f41e4712 NC |
4029 | initial_length_size = 4; |
4030 | } | |
19e6b90e | 4031 | |
b40bf0a2 | 4032 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 4033 | { |
8fcc61b4 NC |
4034 | /* If the length field has a relocation against it, then we should |
4035 | not complain if it is inaccurate (and probably negative). This | |
4036 | happens in object files when the .debug_line section is actually | |
4037 | comprised of several different .debug_line.* sections, (some of | |
4038 | which may be removed by linker garbage collection), and a relocation | |
4039 | is used to compute the correct length once that is done. */ | |
77145576 | 4040 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 4041 | { |
8fcc61b4 | 4042 | linfo->li_length = (end - data) - initial_length_size; |
b40bf0a2 NC |
4043 | } |
4044 | else | |
4045 | { | |
8fcc61b4 NC |
4046 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
4047 | (long) linfo->li_length); | |
b40bf0a2 NC |
4048 | return NULL; |
4049 | } | |
f41e4712 | 4050 | } |
19e6b90e | 4051 | |
b40bf0a2 NC |
4052 | /* Get and check the version number. */ |
4053 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
4054 | ||
4055 | if (linfo->li_version != 2 | |
4056 | && linfo->li_version != 3 | |
77145576 JK |
4057 | && linfo->li_version != 4 |
4058 | && linfo->li_version != 5) | |
f41e4712 | 4059 | { |
77145576 JK |
4060 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
4061 | "is currently supported.\n")); | |
b40bf0a2 | 4062 | return NULL; |
f41e4712 | 4063 | } |
19e6b90e | 4064 | |
77145576 JK |
4065 | if (linfo->li_version >= 5) |
4066 | { | |
5496f3c6 | 4067 | SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end); |
77145576 | 4068 | |
5496f3c6 NC |
4069 | SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end); |
4070 | if (linfo->li_segment_size != 0) | |
77145576 JK |
4071 | { |
4072 | warn (_("The %s section contains " | |
4073 | "unsupported segment selector size: %d.\n"), | |
5496f3c6 NC |
4074 | section->name, linfo->li_segment_size); |
4075 | return NULL; | |
77145576 JK |
4076 | } |
4077 | } | |
4078 | ||
4079 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
4080 | linfo->li_offset_size, end); | |
b40bf0a2 | 4081 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 4082 | |
b40bf0a2 | 4083 | if (linfo->li_version >= 4) |
f41e4712 | 4084 | { |
b40bf0a2 | 4085 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 4086 | |
b40bf0a2 | 4087 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
4088 | { |
4089 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 4090 | return NULL; |
a233b20c | 4091 | } |
f41e4712 NC |
4092 | } |
4093 | else | |
b40bf0a2 | 4094 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 4095 | |
b40bf0a2 | 4096 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 4097 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
4098 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
4099 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 4100 | |
b40bf0a2 | 4101 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 4102 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
4103 | if (* end_of_sequence > end) |
4104 | { | |
4c219c2e AM |
4105 | warn (_("Line length %s extends beyond end of section\n"), |
4106 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
4107 | * end_of_sequence = end; |
4108 | return NULL; | |
4109 | } | |
4110 | ||
b40bf0a2 NC |
4111 | return hdrptr; |
4112 | } | |
19e6b90e | 4113 | |
77145576 | 4114 | static unsigned char * |
dda8d76d NC |
4115 | display_formatted_table (unsigned char * data, |
4116 | unsigned char * start, | |
4117 | unsigned char * end, | |
4118 | const DWARF2_Internal_LineInfo * linfo, | |
4119 | struct dwarf_section * section, | |
7b8d9e8c | 4120 | bfd_boolean is_dir) |
77145576 JK |
4121 | { |
4122 | unsigned char *format_start, format_count, *format, formati; | |
4123 | dwarf_vma data_count, datai; | |
cd30bcef | 4124 | unsigned int namepass, last_entry = 0; |
5496f3c6 NC |
4125 | const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table"); |
4126 | ||
77145576 | 4127 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
546cb2d8 NC |
4128 | if (do_checks && format_count > 5) |
4129 | warn (_("Unexpectedly large number of columns in the %s (%u)\n"), | |
4130 | table_name, format_count); | |
4131 | ||
77145576 JK |
4132 | format_start = data; |
4133 | for (formati = 0; formati < format_count; formati++) | |
4134 | { | |
cd30bcef AM |
4135 | SKIP_ULEB (data, end); |
4136 | SKIP_ULEB (data, end); | |
77145576 JK |
4137 | if (data == end) |
4138 | { | |
5496f3c6 | 4139 | warn (_("%s: Corrupt format description entry\n"), table_name); |
77145576 JK |
4140 | return data; |
4141 | } | |
4142 | } | |
4143 | ||
cd30bcef | 4144 | READ_ULEB (data_count, data, end); |
546cb2d8 | 4145 | if (data_count == 0) |
77145576 | 4146 | { |
546cb2d8 | 4147 | printf (_("\n The %s is empty.\n"), table_name); |
77145576 JK |
4148 | return data; |
4149 | } | |
546cb2d8 | 4150 | else if (data == end) |
77145576 | 4151 | { |
546cb2d8 NC |
4152 | warn (_("%s: Corrupt entry count - expected %s but none found\n"), |
4153 | table_name, dwarf_vmatoa ("x", data_count)); | |
77145576 JK |
4154 | return data; |
4155 | } | |
546cb2d8 | 4156 | |
5496f3c6 NC |
4157 | else if (format_count == 0) |
4158 | { | |
4159 | warn (_("%s: format count is zero, but the table is not empty\n"), | |
4160 | table_name); | |
4161 | return end; | |
4162 | } | |
77145576 | 4163 | |
5496f3c6 NC |
4164 | printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"), |
4165 | table_name, (long) (data - start), dwarf_vmatoa ("u", data_count), | |
4166 | format_count); | |
77145576 JK |
4167 | |
4168 | printf (_(" Entry")); | |
4169 | /* Delay displaying name as the last entry for better screen layout. */ | |
4170 | for (namepass = 0; namepass < 2; namepass++) | |
4171 | { | |
4172 | format = format_start; | |
4173 | for (formati = 0; formati < format_count; formati++) | |
4174 | { | |
4175 | dwarf_vma content_type; | |
4176 | ||
cd30bcef | 4177 | READ_ULEB (content_type, format, end); |
77145576 JK |
4178 | if ((content_type == DW_LNCT_path) == (namepass == 1)) |
4179 | switch (content_type) | |
4180 | { | |
4181 | case DW_LNCT_path: | |
4182 | printf (_("\tName")); | |
4183 | break; | |
4184 | case DW_LNCT_directory_index: | |
4185 | printf (_("\tDir")); | |
4186 | break; | |
4187 | case DW_LNCT_timestamp: | |
4188 | printf (_("\tTime")); | |
4189 | break; | |
4190 | case DW_LNCT_size: | |
4191 | printf (_("\tSize")); | |
4192 | break; | |
4193 | case DW_LNCT_MD5: | |
5496f3c6 | 4194 | printf (_("\tMD5\t\t\t")); |
77145576 JK |
4195 | break; |
4196 | default: | |
4197 | printf (_("\t(Unknown format content type %s)"), | |
4198 | dwarf_vmatoa ("u", content_type)); | |
4199 | } | |
cd30bcef | 4200 | SKIP_ULEB (format, end); |
77145576 JK |
4201 | } |
4202 | } | |
4203 | putchar ('\n'); | |
4204 | ||
4205 | for (datai = 0; datai < data_count; datai++) | |
4206 | { | |
4207 | unsigned char *datapass = data; | |
4208 | ||
4209 | printf (" %d", last_entry++); | |
4210 | /* Delay displaying name as the last entry for better screen layout. */ | |
4211 | for (namepass = 0; namepass < 2; namepass++) | |
4212 | { | |
4213 | format = format_start; | |
4214 | data = datapass; | |
4215 | for (formati = 0; formati < format_count; formati++) | |
4216 | { | |
4217 | dwarf_vma content_type, form; | |
4218 | ||
cd30bcef AM |
4219 | READ_ULEB (content_type, format, end); |
4220 | READ_ULEB (form, format, end); | |
4221 | data = read_and_display_attr_value (0, form, 0, start, data, end, | |
4222 | 0, 0, linfo->li_offset_size, | |
77145576 JK |
4223 | linfo->li_version, NULL, |
4224 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
ec1b0fbb | 4225 | section, NULL, '\t', -1); |
77145576 JK |
4226 | } |
4227 | } | |
5496f3c6 NC |
4228 | |
4229 | if (data == end && (datai < data_count - 1)) | |
77145576 | 4230 | { |
5496f3c6 | 4231 | warn (_("\n%s: Corrupt entries list\n"), table_name); |
77145576 JK |
4232 | return data; |
4233 | } | |
4234 | putchar ('\n'); | |
4235 | } | |
4236 | return data; | |
4237 | } | |
4238 | ||
b40bf0a2 | 4239 | static int |
dda8d76d NC |
4240 | display_debug_lines_raw (struct dwarf_section * section, |
4241 | unsigned char * data, | |
4242 | unsigned char * end, | |
4243 | void * file) | |
b40bf0a2 NC |
4244 | { |
4245 | unsigned char *start = section->start; | |
ba8826a8 | 4246 | int verbose_view = 0; |
19e6b90e | 4247 | |
dda8d76d | 4248 | introduce (section, TRUE); |
19e6b90e | 4249 | |
b40bf0a2 NC |
4250 | while (data < end) |
4251 | { | |
4252 | static DWARF2_Internal_LineInfo saved_linfo; | |
4253 | DWARF2_Internal_LineInfo linfo; | |
4254 | unsigned char *standard_opcodes; | |
4255 | unsigned char *end_of_sequence; | |
fe59e83d | 4256 | int i; |
19e6b90e | 4257 | |
4925cdd7 NC |
4258 | if (const_strneq (section->name, ".debug_line.") |
4259 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4260 | These are full debug_line sections. */ | |
4261 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 4262 | { |
b40bf0a2 NC |
4263 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
4264 | section containing just the Line Number Statements. They are | |
4265 | created by the assembler and intended to be used alongside gcc's | |
4266 | -ffunction-sections command line option. When the linker's | |
4267 | garbage collection decides to discard a .text.<foo> section it | |
4268 | can then also discard the line number information in .debug_line.<foo>. | |
4269 | ||
4925cdd7 | 4270 | Since the section is a fragment it does not have the details |
b40bf0a2 | 4271 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 4272 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
4273 | end_of_sequence = end; |
4274 | standard_opcodes = NULL; | |
4275 | linfo = saved_linfo; | |
058037d3 NC |
4276 | /* PR 17531: file: 0522b371. */ |
4277 | if (linfo.li_line_range == 0) | |
4278 | { | |
1306a742 | 4279 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4280 | return 0; |
4281 | } | |
b40bf0a2 | 4282 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4283 | } |
19e6b90e L |
4284 | else |
4285 | { | |
b40bf0a2 | 4286 | unsigned char * hdrptr; |
19e6b90e | 4287 | |
b40bf0a2 NC |
4288 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4289 | & end_of_sequence)) == NULL) | |
4290 | return 0; | |
19e6b90e | 4291 | |
b40bf0a2 NC |
4292 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
4293 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
4294 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
5496f3c6 NC |
4295 | if (linfo.li_version >= 5) |
4296 | { | |
4297 | printf (_(" Address size (bytes): %d\n"), linfo.li_address_size); | |
4298 | printf (_(" Segment selector (bytes): %d\n"), linfo.li_segment_size); | |
4299 | } | |
77ef8654 | 4300 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
4301 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
4302 | if (linfo.li_version >= 4) | |
4303 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
4304 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
4305 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
4306 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
4307 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 4308 | |
0a9d414a NC |
4309 | /* PR 17512: file: 1665-6428-0.004. */ |
4310 | if (linfo.li_line_range == 0) | |
4311 | { | |
4312 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4313 | linfo.li_line_range = 1; | |
4314 | } | |
77ef8654 | 4315 | |
b40bf0a2 | 4316 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4317 | |
b40bf0a2 NC |
4318 | /* Display the contents of the Opcodes table. */ |
4319 | standard_opcodes = hdrptr; | |
19e6b90e | 4320 | |
6937bb54 NC |
4321 | /* PR 17512: file: 002-417945-0.004. */ |
4322 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
4323 | { | |
4324 | warn (_("Line Base extends beyond end of section\n")); | |
4325 | return 0; | |
4326 | } | |
4327 | ||
b40bf0a2 | 4328 | printf (_("\n Opcodes:\n")); |
19e6b90e | 4329 | |
b40bf0a2 | 4330 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
4331 | printf (ngettext (" Opcode %d has %d arg\n", |
4332 | " Opcode %d has %d args\n", | |
4333 | standard_opcodes[i - 1]), | |
4334 | i, standard_opcodes[i - 1]); | |
19e6b90e | 4335 | |
b40bf0a2 NC |
4336 | /* Display the contents of the Directory table. */ |
4337 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 4338 | |
77145576 | 4339 | if (linfo.li_version >= 5) |
b40bf0a2 | 4340 | { |
dda8d76d | 4341 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 4342 | |
77145576 | 4343 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 4344 | TRUE); |
77145576 | 4345 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 4346 | FALSE); |
77145576 JK |
4347 | } |
4348 | else | |
4349 | { | |
4350 | if (*data == 0) | |
4351 | printf (_("\n The Directory Table is empty.\n")); | |
4352 | else | |
a233b20c | 4353 | { |
77145576 | 4354 | unsigned int last_dir_entry = 0; |
6937bb54 | 4355 | |
77145576 JK |
4356 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
4357 | (long)(data - start)); | |
19e6b90e | 4358 | |
77145576 JK |
4359 | while (data < end && *data != 0) |
4360 | { | |
4361 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 4362 | |
77145576 JK |
4363 | data += strnlen ((char *) data, end - data) + 1; |
4364 | } | |
19e6b90e | 4365 | |
77145576 JK |
4366 | /* PR 17512: file: 002-132094-0.004. */ |
4367 | if (data >= end - 1) | |
4368 | break; | |
4369 | } | |
19e6b90e | 4370 | |
77145576 JK |
4371 | /* Skip the NUL at the end of the table. */ |
4372 | data++; | |
19e6b90e | 4373 | |
77145576 JK |
4374 | /* Display the contents of the File Name table. */ |
4375 | if (*data == 0) | |
4376 | printf (_("\n The File Name Table is empty.\n")); | |
4377 | else | |
4378 | { | |
4379 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
4380 | (long)(data - start)); | |
4381 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 4382 | |
77145576 | 4383 | while (data < end && *data != 0) |
b40bf0a2 | 4384 | { |
77145576 | 4385 | unsigned char *name; |
cd30bcef | 4386 | dwarf_vma val; |
77145576 JK |
4387 | |
4388 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
4389 | name = data; | |
4390 | data += strnlen ((char *) data, end - data) + 1; | |
4391 | ||
cd30bcef AM |
4392 | READ_ULEB (val, data, end); |
4393 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4394 | READ_ULEB (val, data, end); | |
4395 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4396 | READ_ULEB (val, data, end); | |
4397 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
77145576 JK |
4398 | printf ("%.*s\n", (int)(end - name), name); |
4399 | ||
4400 | if (data == end) | |
4401 | { | |
4402 | warn (_("Corrupt file name table entry\n")); | |
4403 | break; | |
4404 | } | |
b40bf0a2 | 4405 | } |
a233b20c | 4406 | } |
77145576 JK |
4407 | |
4408 | /* Skip the NUL at the end of the table. */ | |
4409 | data++; | |
b40bf0a2 | 4410 | } |
19e6b90e | 4411 | |
b40bf0a2 NC |
4412 | putchar ('\n'); |
4413 | saved_linfo = linfo; | |
4414 | } | |
19e6b90e | 4415 | |
b40bf0a2 NC |
4416 | /* Now display the statements. */ |
4417 | if (data >= end_of_sequence) | |
4418 | printf (_(" No Line Number Statements.\n")); | |
4419 | else | |
4420 | { | |
4421 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 4422 | |
b40bf0a2 NC |
4423 | while (data < end_of_sequence) |
4424 | { | |
4425 | unsigned char op_code; | |
4426 | dwarf_signed_vma adv; | |
4427 | dwarf_vma uladv; | |
19e6b90e | 4428 | |
fe59e83d CC |
4429 | printf (" [0x%08lx]", (long)(data - start)); |
4430 | ||
b40bf0a2 | 4431 | op_code = *data++; |
19e6b90e | 4432 | |
b40bf0a2 | 4433 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 4434 | { |
b40bf0a2 NC |
4435 | op_code -= linfo.li_opcode_base; |
4436 | uladv = (op_code / linfo.li_line_range); | |
4437 | if (linfo.li_max_ops_per_insn == 1) | |
4438 | { | |
4439 | uladv *= linfo.li_min_insn_length; | |
4440 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4441 | if (uladv) |
4442 | state_machine_regs.view = 0; | |
b40bf0a2 | 4443 | printf (_(" Special opcode %d: " |
ba8826a8 | 4444 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 4445 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4446 | dwarf_vmatoa ("x", state_machine_regs.address), |
4447 | verbose_view && uladv | |
4448 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4449 | } |
4450 | else | |
4451 | { | |
ba8826a8 AO |
4452 | unsigned addrdelta |
4453 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
4454 | / linfo.li_max_ops_per_insn) |
4455 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
4456 | |
4457 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
4458 | state_machine_regs.op_index |
4459 | = (state_machine_regs.op_index + uladv) | |
4460 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4461 | if (addrdelta) |
4462 | state_machine_regs.view = 0; | |
b40bf0a2 | 4463 | printf (_(" Special opcode %d: " |
ba8826a8 | 4464 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
4465 | op_code, dwarf_vmatoa ("u", uladv), |
4466 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4467 | state_machine_regs.op_index, |
4468 | verbose_view && addrdelta | |
4469 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4470 | } |
4471 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
4472 | state_machine_regs.line += adv; | |
ba8826a8 | 4473 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 4474 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
4475 | if (verbose_view || state_machine_regs.view) |
4476 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4477 | else | |
4478 | putchar ('\n'); | |
4479 | state_machine_regs.view++; | |
19e6b90e | 4480 | } |
cd30bcef AM |
4481 | else |
4482 | switch (op_code) | |
4483 | { | |
4484 | case DW_LNS_extended_op: | |
4485 | data += process_extended_line_op (data, | |
4486 | linfo.li_default_is_stmt, | |
4487 | end); | |
4488 | break; | |
4489 | ||
4490 | case DW_LNS_copy: | |
4491 | printf (_(" Copy")); | |
4492 | if (verbose_view || state_machine_regs.view) | |
4493 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4494 | else | |
4495 | putchar ('\n'); | |
4496 | state_machine_regs.view++; | |
4497 | break; | |
4498 | ||
4499 | case DW_LNS_advance_pc: | |
4500 | READ_ULEB (uladv, data, end); | |
4501 | if (linfo.li_max_ops_per_insn == 1) | |
4502 | { | |
4503 | uladv *= linfo.li_min_insn_length; | |
4504 | state_machine_regs.address += uladv; | |
4505 | if (uladv) | |
4506 | state_machine_regs.view = 0; | |
4507 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
4508 | dwarf_vmatoa ("u", uladv), | |
4509 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4510 | verbose_view && uladv | |
4511 | ? _(" (reset view)") : ""); | |
4512 | } | |
4513 | else | |
4514 | { | |
4515 | unsigned addrdelta | |
4516 | = ((state_machine_regs.op_index + uladv) | |
4517 | / linfo.li_max_ops_per_insn) | |
4518 | * linfo.li_min_insn_length; | |
4519 | state_machine_regs.address | |
4520 | += addrdelta; | |
4521 | state_machine_regs.op_index | |
4522 | = (state_machine_regs.op_index + uladv) | |
4523 | % linfo.li_max_ops_per_insn; | |
4524 | if (addrdelta) | |
4525 | state_machine_regs.view = 0; | |
4526 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
4527 | dwarf_vmatoa ("u", uladv), | |
4528 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4529 | state_machine_regs.op_index, | |
4530 | verbose_view && addrdelta | |
4531 | ? _(" (reset view)") : ""); | |
4532 | } | |
4533 | break; | |
4534 | ||
4535 | case DW_LNS_advance_line: | |
4536 | READ_SLEB (adv, data, end); | |
4537 | state_machine_regs.line += adv; | |
4538 | printf (_(" Advance Line by %s to %d\n"), | |
4539 | dwarf_vmatoa ("d", adv), | |
4540 | state_machine_regs.line); | |
4541 | break; | |
4542 | ||
4543 | case DW_LNS_set_file: | |
4544 | READ_ULEB (uladv, data, end); | |
4545 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
4546 | dwarf_vmatoa ("u", uladv)); | |
4547 | state_machine_regs.file = uladv; | |
4548 | break; | |
4549 | ||
4550 | case DW_LNS_set_column: | |
4551 | READ_ULEB (uladv, data, end); | |
4552 | printf (_(" Set column to %s\n"), | |
4553 | dwarf_vmatoa ("u", uladv)); | |
4554 | state_machine_regs.column = uladv; | |
4555 | break; | |
4556 | ||
4557 | case DW_LNS_negate_stmt: | |
4558 | adv = state_machine_regs.is_stmt; | |
4559 | adv = ! adv; | |
4560 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
4561 | state_machine_regs.is_stmt = adv; | |
4562 | break; | |
4563 | ||
4564 | case DW_LNS_set_basic_block: | |
4565 | printf (_(" Set basic block\n")); | |
4566 | state_machine_regs.basic_block = 1; | |
4567 | break; | |
4568 | ||
4569 | case DW_LNS_const_add_pc: | |
4570 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4571 | if (linfo.li_max_ops_per_insn) | |
4572 | { | |
4573 | uladv *= linfo.li_min_insn_length; | |
4574 | state_machine_regs.address += uladv; | |
4575 | if (uladv) | |
4576 | state_machine_regs.view = 0; | |
4577 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
4578 | dwarf_vmatoa ("u", uladv), | |
4579 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4580 | verbose_view && uladv | |
4581 | ? _(" (reset view)") : ""); | |
4582 | } | |
4583 | else | |
4584 | { | |
4585 | unsigned addrdelta | |
4586 | = ((state_machine_regs.op_index + uladv) | |
4587 | / linfo.li_max_ops_per_insn) | |
4588 | * linfo.li_min_insn_length; | |
4589 | state_machine_regs.address | |
4590 | += addrdelta; | |
4591 | state_machine_regs.op_index | |
4592 | = (state_machine_regs.op_index + uladv) | |
4593 | % linfo.li_max_ops_per_insn; | |
4594 | if (addrdelta) | |
4595 | state_machine_regs.view = 0; | |
4596 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
4597 | dwarf_vmatoa ("u", uladv), | |
4598 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4599 | state_machine_regs.op_index, | |
4600 | verbose_view && addrdelta | |
4601 | ? _(" (reset view)") : ""); | |
4602 | } | |
4603 | break; | |
4604 | ||
4605 | case DW_LNS_fixed_advance_pc: | |
4606 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4607 | state_machine_regs.address += uladv; | |
4608 | state_machine_regs.op_index = 0; | |
4609 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
4610 | dwarf_vmatoa ("u", uladv), | |
4611 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
4612 | /* Do NOT reset view. */ | |
4613 | break; | |
4614 | ||
4615 | case DW_LNS_set_prologue_end: | |
4616 | printf (_(" Set prologue_end to true\n")); | |
4617 | break; | |
4618 | ||
4619 | case DW_LNS_set_epilogue_begin: | |
4620 | printf (_(" Set epilogue_begin to true\n")); | |
4621 | break; | |
4622 | ||
4623 | case DW_LNS_set_isa: | |
4624 | READ_ULEB (uladv, data, end); | |
4625 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
4626 | break; | |
4627 | ||
4628 | default: | |
4629 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4630 | ||
4631 | if (standard_opcodes != NULL) | |
4632 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4633 | { | |
4634 | READ_ULEB (uladv, data, end); | |
4635 | printf ("0x%s%s", dwarf_vmatoa ("x", uladv), | |
4636 | i == 1 ? "" : ", "); | |
4637 | } | |
4638 | putchar ('\n'); | |
4639 | break; | |
4640 | } | |
19e6b90e | 4641 | } |
b40bf0a2 | 4642 | putchar ('\n'); |
19e6b90e | 4643 | } |
19e6b90e L |
4644 | } |
4645 | ||
4646 | return 1; | |
4647 | } | |
4648 | ||
a262ae96 NC |
4649 | typedef struct |
4650 | { | |
467c65bc NC |
4651 | unsigned char *name; |
4652 | unsigned int directory_index; | |
4653 | unsigned int modification_date; | |
4654 | unsigned int length; | |
a262ae96 NC |
4655 | } File_Entry; |
4656 | ||
4657 | /* Output a decoded representation of the .debug_line section. */ | |
4658 | ||
4659 | static int | |
dda8d76d | 4660 | display_debug_lines_decoded (struct dwarf_section * section, |
ec1b0fbb | 4661 | unsigned char * start, |
dda8d76d NC |
4662 | unsigned char * data, |
4663 | unsigned char * end, | |
4664 | void * fileptr) | |
a262ae96 | 4665 | { |
b40bf0a2 NC |
4666 | static DWARF2_Internal_LineInfo saved_linfo; |
4667 | ||
dda8d76d | 4668 | introduce (section, FALSE); |
a262ae96 NC |
4669 | |
4670 | while (data < end) | |
4671 | { | |
4672 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4673 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4674 | unsigned char *standard_opcodes; |
4675 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4676 | int i; |
4677 | File_Entry *file_table = NULL; | |
143a3db0 | 4678 | unsigned int n_files = 0; |
a262ae96 | 4679 | unsigned char **directory_table = NULL; |
77145576 | 4680 | dwarf_vma n_directories = 0; |
a262ae96 | 4681 | |
4925cdd7 NC |
4682 | if (const_strneq (section->name, ".debug_line.") |
4683 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4684 | These are full debug_line sections. */ | |
4685 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4686 | { |
4925cdd7 | 4687 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4688 | end_of_sequence = end; |
4689 | standard_opcodes = NULL; | |
4690 | linfo = saved_linfo; | |
058037d3 NC |
4691 | /* PR 17531: file: 0522b371. */ |
4692 | if (linfo.li_line_range == 0) | |
4693 | { | |
1306a742 | 4694 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4695 | return 0; |
4696 | } | |
b40bf0a2 | 4697 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4698 | } |
a262ae96 | 4699 | else |
b4eb7656 | 4700 | { |
b40bf0a2 | 4701 | unsigned char *hdrptr; |
a262ae96 | 4702 | |
b40bf0a2 NC |
4703 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4704 | & end_of_sequence)) == NULL) | |
a233b20c | 4705 | return 0; |
0c588247 | 4706 | |
058037d3 NC |
4707 | /* PR 17531: file: 0522b371. */ |
4708 | if (linfo.li_line_range == 0) | |
4709 | { | |
4710 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4711 | linfo.li_line_range = 1; | |
4712 | } | |
b40bf0a2 | 4713 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4714 | |
b40bf0a2 NC |
4715 | /* Save a pointer to the contents of the Opcodes table. */ |
4716 | standard_opcodes = hdrptr; | |
a262ae96 | 4717 | |
b40bf0a2 NC |
4718 | /* Traverse the Directory table just to count entries. */ |
4719 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4720 | /* PR 20440 */ |
4721 | if (data >= end) | |
4722 | { | |
4723 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4724 | linfo.li_opcode_base); | |
4725 | return 0; | |
4726 | } | |
4727 | ||
77145576 | 4728 | if (linfo.li_version >= 5) |
b40bf0a2 | 4729 | { |
77145576 JK |
4730 | unsigned char *format_start, format_count, *format; |
4731 | dwarf_vma formati, entryi; | |
a262ae96 | 4732 | |
dda8d76d | 4733 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4734 | |
4735 | /* Skip directories format. */ | |
4736 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4737 | if (do_checks && format_count > 1) |
4738 | warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"), | |
4739 | format_count); | |
77145576 JK |
4740 | format_start = data; |
4741 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4742 | { |
cd30bcef AM |
4743 | SKIP_ULEB (data, end); |
4744 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4745 | } |
a262ae96 | 4746 | |
cd30bcef | 4747 | READ_ULEB (n_directories, data, end); |
77145576 | 4748 | if (data == end) |
d8024a91 | 4749 | { |
77145576 | 4750 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
4751 | break; |
4752 | } | |
4753 | ||
070b775f NC |
4754 | if (n_directories == 0) |
4755 | directory_table = NULL; | |
4756 | else | |
4757 | directory_table = (unsigned char **) | |
4758 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 4759 | |
77145576 | 4760 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 4761 | { |
77145576 | 4762 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 4763 | |
77145576 JK |
4764 | format = format_start; |
4765 | for (formati = 0; formati < format_count; formati++) | |
4766 | { | |
4767 | dwarf_vma content_type, form; | |
4768 | dwarf_vma uvalue; | |
4769 | ||
cd30bcef AM |
4770 | READ_ULEB (content_type, format, end); |
4771 | READ_ULEB (form, format, end); | |
77145576 JK |
4772 | if (data == end) |
4773 | { | |
4774 | warn (_("Corrupt directories list\n")); | |
4775 | break; | |
4776 | } | |
4777 | switch (content_type) | |
4778 | { | |
4779 | case DW_LNCT_path: | |
4780 | switch (form) | |
4781 | { | |
4782 | case DW_FORM_string: | |
4783 | *pathp = data; | |
4784 | break; | |
4785 | case DW_FORM_line_strp: | |
4786 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4787 | end); | |
4788 | /* Remove const by the cast. */ | |
4789 | *pathp = (unsigned char *) | |
4790 | fetch_indirect_line_string (uvalue); | |
4791 | break; | |
4792 | } | |
4793 | break; | |
4794 | } | |
cd30bcef AM |
4795 | data = read_and_display_attr_value (0, form, 0, start, |
4796 | data, end, 0, 0, | |
77145576 JK |
4797 | linfo.li_offset_size, |
4798 | linfo.li_version, | |
4799 | NULL, 1, section, | |
ec1b0fbb | 4800 | NULL, '\t', -1); |
77145576 JK |
4801 | } |
4802 | if (data == end) | |
4803 | { | |
4804 | warn (_("Corrupt directories list\n")); | |
4805 | break; | |
4806 | } | |
4807 | } | |
a262ae96 | 4808 | |
77145576 JK |
4809 | /* Skip files format. */ |
4810 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4811 | if (do_checks && format_count > 5) |
4812 | warn (_("Unexpectedly large number of columns in the file name table (%u)\n"), | |
4813 | format_count); | |
77145576 JK |
4814 | format_start = data; |
4815 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4816 | { |
cd30bcef AM |
4817 | SKIP_ULEB (data, end); |
4818 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4819 | } |
a262ae96 | 4820 | |
cd30bcef | 4821 | READ_ULEB (n_files, data, end); |
070b775f | 4822 | if (data == end && n_files > 0) |
d8024a91 | 4823 | { |
77145576 | 4824 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
4825 | break; |
4826 | } | |
4827 | ||
070b775f NC |
4828 | if (n_files == 0) |
4829 | file_table = NULL; | |
4830 | else | |
4831 | file_table = (File_Entry *) xcalloc (1, n_files | |
4832 | * sizeof (File_Entry)); | |
a262ae96 | 4833 | |
77145576 | 4834 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 4835 | { |
77145576 | 4836 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 4837 | |
77145576 JK |
4838 | format = format_start; |
4839 | for (formati = 0; formati < format_count; formati++) | |
4840 | { | |
4841 | dwarf_vma content_type, form; | |
4842 | dwarf_vma uvalue; | |
cd30bcef | 4843 | unsigned char *tmp; |
77145576 | 4844 | |
cd30bcef AM |
4845 | READ_ULEB (content_type, format, end); |
4846 | READ_ULEB (form, format, end); | |
77145576 JK |
4847 | if (data == end) |
4848 | { | |
4849 | warn (_("Corrupt file name list\n")); | |
4850 | break; | |
4851 | } | |
4852 | switch (content_type) | |
4853 | { | |
4854 | case DW_LNCT_path: | |
4855 | switch (form) | |
4856 | { | |
4857 | case DW_FORM_string: | |
4858 | file->name = data; | |
4859 | break; | |
4860 | case DW_FORM_line_strp: | |
4861 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4862 | end); | |
4863 | /* Remove const by the cast. */ | |
4864 | file->name = (unsigned char *) | |
4865 | fetch_indirect_line_string (uvalue); | |
4866 | break; | |
4867 | } | |
4868 | break; | |
4869 | case DW_LNCT_directory_index: | |
4870 | switch (form) | |
4871 | { | |
4872 | case DW_FORM_data1: | |
4873 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
4874 | end); | |
4875 | break; | |
4876 | case DW_FORM_data2: | |
4877 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
4878 | end); | |
4879 | break; | |
4880 | case DW_FORM_udata: | |
cd30bcef AM |
4881 | tmp = data; |
4882 | READ_ULEB (file->directory_index, tmp, end); | |
77145576 JK |
4883 | break; |
4884 | } | |
4885 | break; | |
4886 | } | |
cd30bcef AM |
4887 | data = read_and_display_attr_value (0, form, 0, start, |
4888 | data, end, 0, 0, | |
77145576 JK |
4889 | linfo.li_offset_size, |
4890 | linfo.li_version, | |
4891 | NULL, 1, section, | |
ec1b0fbb | 4892 | NULL, '\t', -1); |
77145576 JK |
4893 | } |
4894 | if (data == end) | |
4895 | { | |
4896 | warn (_("Corrupt file name list\n")); | |
4897 | break; | |
4898 | } | |
4899 | } | |
4900 | } | |
4901 | else | |
4902 | { | |
4903 | if (*data != 0) | |
b40bf0a2 | 4904 | { |
77145576 JK |
4905 | unsigned char *ptr_directory_table = data; |
4906 | ||
4907 | while (data < end && *data != 0) | |
4908 | { | |
4909 | data += strnlen ((char *) data, end - data) + 1; | |
4910 | n_directories++; | |
4911 | } | |
4912 | ||
4913 | /* PR 20440 */ | |
4914 | if (data >= end) | |
4915 | { | |
4916 | warn (_("directory table ends unexpectedly\n")); | |
4917 | n_directories = 0; | |
4918 | break; | |
4919 | } | |
4920 | ||
4921 | /* Go through the directory table again to save the directories. */ | |
4922 | directory_table = (unsigned char **) | |
4923 | xmalloc (n_directories * sizeof (unsigned char *)); | |
4924 | ||
4925 | i = 0; | |
4926 | while (*ptr_directory_table != 0) | |
4927 | { | |
4928 | directory_table[i] = ptr_directory_table; | |
4929 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
4930 | ptr_directory_table - end) + 1; | |
4931 | i++; | |
4932 | } | |
b40bf0a2 | 4933 | } |
77145576 JK |
4934 | /* Skip the NUL at the end of the table. */ |
4935 | data++; | |
4936 | ||
4937 | /* Traverse the File Name table just to count the entries. */ | |
4938 | if (data < end && *data != 0) | |
b40bf0a2 | 4939 | { |
77145576 JK |
4940 | unsigned char *ptr_file_name_table = data; |
4941 | ||
4942 | while (data < end && *data != 0) | |
db9537d2 | 4943 | { |
cd30bcef AM |
4944 | /* Skip Name, directory index, last modification |
4945 | time and length of file. */ | |
77145576 | 4946 | data += strnlen ((char *) data, end - data) + 1; |
cd30bcef AM |
4947 | SKIP_ULEB (data, end); |
4948 | SKIP_ULEB (data, end); | |
4949 | SKIP_ULEB (data, end); | |
77145576 | 4950 | n_files++; |
db9537d2 | 4951 | } |
a262ae96 | 4952 | |
77145576 JK |
4953 | if (data >= end) |
4954 | { | |
4955 | warn (_("file table ends unexpectedly\n")); | |
4956 | n_files = 0; | |
4957 | break; | |
4958 | } | |
4959 | ||
4960 | /* Go through the file table again to save the strings. */ | |
4961 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 4962 | |
77145576 JK |
4963 | i = 0; |
4964 | while (*ptr_file_name_table != 0) | |
4965 | { | |
77145576 JK |
4966 | file_table[i].name = ptr_file_name_table; |
4967 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
4968 | end - ptr_file_name_table) + 1; | |
4969 | ||
4970 | /* We are not interested in directory, time or size. */ | |
cd30bcef AM |
4971 | READ_ULEB (file_table[i].directory_index, |
4972 | ptr_file_name_table, end); | |
4973 | READ_ULEB (file_table[i].modification_date, | |
4974 | ptr_file_name_table, end); | |
4975 | READ_ULEB (file_table[i].length, | |
4976 | ptr_file_name_table, end); | |
77145576 JK |
4977 | i++; |
4978 | } | |
4979 | i = 0; | |
b40bf0a2 | 4980 | } |
77145576 JK |
4981 | |
4982 | /* Skip the NUL at the end of the table. */ | |
4983 | data++; | |
b40bf0a2 | 4984 | } |
cc5914eb | 4985 | |
77145576 | 4986 | /* Print the Compilation Unit's name and a header. */ |
f082820d | 4987 | if (file_table == NULL) |
070b775f | 4988 | printf (_("CU: No directory table\n")); |
f082820d AM |
4989 | else if (directory_table == NULL) |
4990 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
4991 | else |
4992 | { | |
4993 | unsigned int ix = file_table[0].directory_index; | |
4994 | const char *directory; | |
4995 | ||
4996 | if (ix == 0) | |
4997 | directory = "."; | |
4998 | /* PR 20439 */ | |
4999 | else if (n_directories == 0) | |
5000 | directory = _("<unknown>"); | |
5001 | else if (ix > n_directories) | |
5002 | { | |
5003 | warn (_("directory index %u > number of directories %s\n"), | |
5004 | ix, dwarf_vmatoa ("u", n_directories)); | |
5005 | directory = _("<corrupt>"); | |
5006 | } | |
5007 | else | |
5008 | directory = (char *) directory_table[ix - 1]; | |
5009 | ||
5010 | if (do_wide || strlen (directory) < 76) | |
5011 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
5012 | else | |
5013 | printf ("%s:\n", file_table[0].name); | |
77145576 | 5014 | } |
a262ae96 | 5015 | |
070b775f NC |
5016 | if (n_files > 0) |
5017 | printf (_("File name Line number Starting address View Stmt\n")); | |
5018 | else | |
5019 | printf (_("CU: Empty file name table\n")); | |
b40bf0a2 NC |
5020 | saved_linfo = linfo; |
5021 | } | |
a262ae96 NC |
5022 | |
5023 | /* This loop iterates through the Dwarf Line Number Program. */ | |
5024 | while (data < end_of_sequence) | |
b4eb7656 | 5025 | { |
a262ae96 | 5026 | unsigned char op_code; |
ba8826a8 | 5027 | int xop; |
b4eb7656 AM |
5028 | int adv; |
5029 | unsigned long int uladv; | |
b4eb7656 | 5030 | int is_special_opcode = 0; |
a262ae96 | 5031 | |
b4eb7656 | 5032 | op_code = *data++; |
ba8826a8 | 5033 | xop = op_code; |
a262ae96 | 5034 | |
b4eb7656 | 5035 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 5036 | { |
91d6fa6a | 5037 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
5038 | uladv = (op_code / linfo.li_line_range); |
5039 | if (linfo.li_max_ops_per_insn == 1) | |
5040 | { | |
5041 | uladv *= linfo.li_min_insn_length; | |
5042 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
5043 | if (uladv) |
5044 | state_machine_regs.view = 0; | |
a233b20c JJ |
5045 | } |
5046 | else | |
5047 | { | |
ba8826a8 AO |
5048 | unsigned addrdelta |
5049 | = ((state_machine_regs.op_index + uladv) | |
5050 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 5051 | * linfo.li_min_insn_length; |
ba8826a8 AO |
5052 | state_machine_regs.address |
5053 | += addrdelta; | |
a233b20c JJ |
5054 | state_machine_regs.op_index |
5055 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 5056 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
5057 | if (addrdelta) |
5058 | state_machine_regs.view = 0; | |
a233b20c | 5059 | } |
a262ae96 | 5060 | |
b4eb7656 AM |
5061 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
5062 | state_machine_regs.line += adv; | |
5063 | is_special_opcode = 1; | |
ba8826a8 | 5064 | /* Increment view after printing this row. */ |
b4eb7656 | 5065 | } |
cd30bcef AM |
5066 | else |
5067 | switch (op_code) | |
5068 | { | |
5069 | case DW_LNS_extended_op: | |
5070 | { | |
5071 | unsigned int ext_op_code_len; | |
5072 | unsigned char ext_op_code; | |
5073 | unsigned char *op_code_end; | |
5074 | unsigned char *op_code_data = data; | |
5075 | ||
5076 | READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence); | |
5077 | op_code_end = op_code_data + ext_op_code_len; | |
5078 | if (ext_op_code_len == 0 || op_code_end > end_of_sequence) | |
5079 | { | |
5080 | warn (_("Badly formed extended line op encountered!\n")); | |
5081 | break; | |
5082 | } | |
5083 | ext_op_code = *op_code_data++; | |
5084 | xop = ext_op_code; | |
5085 | xop = -xop; | |
5086 | ||
5087 | switch (ext_op_code) | |
5088 | { | |
5089 | case DW_LNE_end_sequence: | |
5090 | /* Reset stuff after printing this row. */ | |
5091 | break; | |
5092 | case DW_LNE_set_address: | |
5093 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
5094 | op_code_data, | |
5095 | op_code_end - op_code_data, | |
5096 | op_code_end); | |
5097 | state_machine_regs.op_index = 0; | |
5098 | state_machine_regs.view = 0; | |
5099 | break; | |
5100 | case DW_LNE_define_file: | |
5101 | file_table = (File_Entry *) xrealloc | |
5102 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
5103 | ||
5104 | ++state_machine_regs.last_file_entry; | |
5105 | /* Source file name. */ | |
5106 | file_table[n_files].name = op_code_data; | |
5107 | op_code_data += strlen ((char *) op_code_data) + 1; | |
5108 | /* Directory index. */ | |
5109 | READ_ULEB (file_table[n_files].directory_index, | |
5110 | op_code_data, op_code_end); | |
5111 | /* Last modification time. */ | |
5112 | READ_ULEB (file_table[n_files].modification_date, | |
5113 | op_code_data, op_code_end); | |
5114 | /* File length. */ | |
5115 | READ_ULEB (file_table[n_files].length, | |
5116 | op_code_data, op_code_end); | |
5117 | n_files++; | |
5118 | break; | |
5119 | ||
5120 | case DW_LNE_set_discriminator: | |
5121 | case DW_LNE_HP_set_sequence: | |
5122 | /* Simply ignored. */ | |
5123 | break; | |
5124 | ||
5125 | default: | |
5126 | printf (_("UNKNOWN (%u): length %ld\n"), | |
27653fba | 5127 | ext_op_code, (long int) (op_code_data - data)); |
cd30bcef AM |
5128 | break; |
5129 | } | |
5130 | data = op_code_end; | |
5131 | break; | |
5132 | } | |
5133 | case DW_LNS_copy: | |
5134 | /* Increment view after printing this row. */ | |
5135 | break; | |
5136 | ||
5137 | case DW_LNS_advance_pc: | |
5138 | READ_ULEB (uladv, data, end); | |
5139 | if (linfo.li_max_ops_per_insn == 1) | |
5140 | { | |
5141 | uladv *= linfo.li_min_insn_length; | |
5142 | state_machine_regs.address += uladv; | |
5143 | if (uladv) | |
5144 | state_machine_regs.view = 0; | |
5145 | } | |
5146 | else | |
5147 | { | |
5148 | unsigned addrdelta | |
5149 | = ((state_machine_regs.op_index + uladv) | |
5150 | / linfo.li_max_ops_per_insn) | |
5151 | * linfo.li_min_insn_length; | |
5152 | state_machine_regs.address | |
5153 | += addrdelta; | |
5154 | state_machine_regs.op_index | |
5155 | = (state_machine_regs.op_index + uladv) | |
5156 | % linfo.li_max_ops_per_insn; | |
5157 | if (addrdelta) | |
5158 | state_machine_regs.view = 0; | |
5159 | } | |
5160 | break; | |
5161 | ||
5162 | case DW_LNS_advance_line: | |
5163 | READ_SLEB (adv, data, end); | |
5164 | state_machine_regs.line += adv; | |
5165 | break; | |
5166 | ||
5167 | case DW_LNS_set_file: | |
5168 | READ_ULEB (uladv, data, end); | |
5169 | state_machine_regs.file = uladv; | |
5170 | ||
5171 | { | |
5172 | unsigned file = state_machine_regs.file - 1; | |
5173 | unsigned dir; | |
5174 | ||
5175 | if (file_table == NULL || n_files == 0) | |
5176 | printf (_("\n [Use file table entry %d]\n"), file); | |
5177 | /* PR 20439 */ | |
5178 | else if (file >= n_files) | |
5179 | { | |
5180 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
5181 | printf (_("\n <over large file table index %u>"), file); | |
5182 | } | |
5183 | else if ((dir = file_table[file].directory_index) == 0) | |
5184 | /* If directory index is 0, that means current directory. */ | |
5185 | printf ("\n./%s:[++]\n", file_table[file].name); | |
5186 | else if (directory_table == NULL || n_directories == 0) | |
5187 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
5188 | file_table[file].name, dir); | |
5189 | /* PR 20439 */ | |
5190 | else if (dir > n_directories) | |
5191 | { | |
5192 | warn (_("directory index %u > number of directories %s\n"), | |
5193 | dir, dwarf_vmatoa ("u", n_directories)); | |
5194 | printf (_("\n <over large directory table entry %u>\n"), dir); | |
5195 | } | |
5196 | else | |
5197 | printf ("\n%s/%s:\n", | |
5198 | /* The directory index starts counting at 1. */ | |
5199 | directory_table[dir - 1], file_table[file].name); | |
5200 | } | |
5201 | break; | |
5202 | ||
5203 | case DW_LNS_set_column: | |
5204 | READ_ULEB (uladv, data, end); | |
5205 | state_machine_regs.column = uladv; | |
5206 | break; | |
5207 | ||
5208 | case DW_LNS_negate_stmt: | |
5209 | adv = state_machine_regs.is_stmt; | |
5210 | adv = ! adv; | |
5211 | state_machine_regs.is_stmt = adv; | |
5212 | break; | |
5213 | ||
5214 | case DW_LNS_set_basic_block: | |
5215 | state_machine_regs.basic_block = 1; | |
5216 | break; | |
5217 | ||
5218 | case DW_LNS_const_add_pc: | |
5219 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
5220 | if (linfo.li_max_ops_per_insn == 1) | |
5221 | { | |
5222 | uladv *= linfo.li_min_insn_length; | |
5223 | state_machine_regs.address += uladv; | |
5224 | if (uladv) | |
5225 | state_machine_regs.view = 0; | |
5226 | } | |
5227 | else | |
5228 | { | |
5229 | unsigned addrdelta | |
5230 | = ((state_machine_regs.op_index + uladv) | |
5231 | / linfo.li_max_ops_per_insn) | |
5232 | * linfo.li_min_insn_length; | |
5233 | state_machine_regs.address | |
5234 | += addrdelta; | |
5235 | state_machine_regs.op_index | |
5236 | = (state_machine_regs.op_index + uladv) | |
5237 | % linfo.li_max_ops_per_insn; | |
5238 | if (addrdelta) | |
5239 | state_machine_regs.view = 0; | |
5240 | } | |
5241 | break; | |
5242 | ||
5243 | case DW_LNS_fixed_advance_pc: | |
5244 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
5245 | state_machine_regs.address += uladv; | |
5246 | state_machine_regs.op_index = 0; | |
5247 | /* Do NOT reset view. */ | |
5248 | break; | |
5249 | ||
5250 | case DW_LNS_set_prologue_end: | |
5251 | break; | |
5252 | ||
5253 | case DW_LNS_set_epilogue_begin: | |
5254 | break; | |
5255 | ||
5256 | case DW_LNS_set_isa: | |
5257 | READ_ULEB (uladv, data, end); | |
5258 | printf (_(" Set ISA to %lu\n"), uladv); | |
5259 | break; | |
5260 | ||
5261 | default: | |
5262 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
5263 | ||
5264 | if (standard_opcodes != NULL) | |
5265 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
5266 | { | |
5267 | dwarf_vma val; | |
5268 | ||
5269 | READ_ULEB (val, data, end); | |
5270 | printf ("0x%s%s", dwarf_vmatoa ("x", val), | |
5271 | i == 1 ? "" : ", "); | |
5272 | } | |
5273 | putchar ('\n'); | |
5274 | break; | |
5275 | } | |
a262ae96 | 5276 | |
b4eb7656 AM |
5277 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
5278 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
5279 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
5280 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
5281 | { |
5282 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
5283 | char *fileName; | |
5284 | char *newFileName = NULL; | |
5285 | size_t fileNameLength; | |
b40bf0a2 NC |
5286 | |
5287 | if (file_table) | |
db9537d2 NC |
5288 | { |
5289 | unsigned indx = state_machine_regs.file - 1; | |
5290 | /* PR 20439 */ | |
5291 | if (indx >= n_files) | |
5292 | { | |
5293 | warn (_("corrupt file index %u encountered\n"), indx); | |
5294 | fileName = _("<corrupt>"); | |
5295 | } | |
5296 | else | |
5297 | fileName = (char *) file_table[indx].name; | |
5298 | } | |
b40bf0a2 | 5299 | else |
db9537d2 | 5300 | fileName = _("<unknown>"); |
b40bf0a2 NC |
5301 | |
5302 | fileNameLength = strlen (fileName); | |
a262ae96 | 5303 | |
b4eb7656 AM |
5304 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
5305 | { | |
5306 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
5307 | /* Truncate file name */ | |
5308 | strncpy (newFileName, | |
5309 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
5310 | MAX_FILENAME_LENGTH + 1); | |
e1104d08 NC |
5311 | /* FIXME: This is to pacify gcc-10 which can warn that the |
5312 | strncpy above might leave a non-NUL terminated string | |
5313 | in newFileName. It won't, but gcc's analysis doesn't | |
5314 | quite go far enough to discover this. */ | |
5315 | newFileName[MAX_FILENAME_LENGTH] = 0; | |
b4eb7656 AM |
5316 | } |
5317 | else | |
5318 | { | |
5319 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
5320 | strncpy (newFileName, fileName, fileNameLength + 1); | |
5321 | } | |
5322 | ||
af2b3186 TV |
5323 | /* A row with end_seq set to true has a meaningful address, but |
5324 | the other information in the same row is not significant. | |
5325 | In such a row, print line as "-", and don't print | |
5326 | view/is_stmt. */ | |
b4eb7656 AM |
5327 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) |
5328 | { | |
a233b20c | 5329 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5330 | { |
5331 | if (xop == -DW_LNE_end_sequence) | |
5332 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x", | |
5333 | newFileName, "-", | |
5334 | state_machine_regs.address); | |
5335 | else | |
5336 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", | |
5337 | newFileName, state_machine_regs.line, | |
5338 | state_machine_regs.address); | |
5339 | } | |
a233b20c | 5340 | else |
af2b3186 TV |
5341 | { |
5342 | if (xop == -DW_LNE_end_sequence) | |
5343 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5344 | newFileName, "-", | |
5345 | state_machine_regs.address, | |
5346 | state_machine_regs.op_index); | |
5347 | else | |
5348 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5349 | newFileName, state_machine_regs.line, | |
5350 | state_machine_regs.address, | |
5351 | state_machine_regs.op_index); | |
5352 | } | |
b4eb7656 AM |
5353 | } |
5354 | else | |
5355 | { | |
a233b20c | 5356 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5357 | { |
5358 | if (xop == -DW_LNE_end_sequence) | |
5359 | printf ("%s %11s %#18" DWARF_VMA_FMT "x", | |
5360 | newFileName, "-", | |
5361 | state_machine_regs.address); | |
5362 | else | |
5363 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", | |
5364 | newFileName, state_machine_regs.line, | |
5365 | state_machine_regs.address); | |
5366 | } | |
a233b20c | 5367 | else |
af2b3186 TV |
5368 | { |
5369 | if (xop == -DW_LNE_end_sequence) | |
5370 | printf ("%s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5371 | newFileName, "-", | |
5372 | state_machine_regs.address, | |
5373 | state_machine_regs.op_index); | |
5374 | else | |
5375 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5376 | newFileName, state_machine_regs.line, | |
5377 | state_machine_regs.address, | |
5378 | state_machine_regs.op_index); | |
5379 | } | |
b4eb7656 | 5380 | } |
a262ae96 | 5381 | |
af2b3186 TV |
5382 | if (xop != -DW_LNE_end_sequence) |
5383 | { | |
5384 | if (state_machine_regs.view) | |
5385 | printf (" %6u", state_machine_regs.view); | |
5386 | else | |
5387 | printf (" "); | |
17f6ade2 | 5388 | |
af2b3186 TV |
5389 | if (state_machine_regs.is_stmt) |
5390 | printf (" x"); | |
5391 | } | |
17f6ade2 JD |
5392 | |
5393 | putchar ('\n'); | |
ba8826a8 AO |
5394 | state_machine_regs.view++; |
5395 | ||
5396 | if (xop == -DW_LNE_end_sequence) | |
5397 | { | |
5398 | reset_state_machine (linfo.li_default_is_stmt); | |
5399 | putchar ('\n'); | |
5400 | } | |
a262ae96 | 5401 | |
b4eb7656 AM |
5402 | free (newFileName); |
5403 | } | |
5404 | } | |
b40bf0a2 NC |
5405 | |
5406 | if (file_table) | |
5407 | { | |
5408 | free (file_table); | |
5409 | file_table = NULL; | |
5410 | n_files = 0; | |
5411 | } | |
5412 | ||
5413 | if (directory_table) | |
5414 | { | |
5415 | free (directory_table); | |
5416 | directory_table = NULL; | |
5417 | n_directories = 0; | |
5418 | } | |
5419 | ||
a262ae96 NC |
5420 | putchar ('\n'); |
5421 | } | |
5422 | ||
5423 | return 1; | |
5424 | } | |
5425 | ||
5426 | static int | |
77145576 | 5427 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
5428 | { |
5429 | unsigned char *data = section->start; | |
5430 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
5431 | int retValRaw = 1; |
5432 | int retValDecoded = 1; | |
a262ae96 | 5433 | |
008f4c78 NC |
5434 | if (do_debug_lines == 0) |
5435 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
5436 | ||
4cb93e3b | 5437 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 5438 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 5439 | |
4cb93e3b | 5440 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
ec1b0fbb | 5441 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
a262ae96 | 5442 | |
4cb93e3b | 5443 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
5444 | return 0; |
5445 | ||
5446 | return 1; | |
5447 | } | |
5448 | ||
6e3d6dc1 NC |
5449 | static debug_info * |
5450 | find_debug_info_for_offset (unsigned long offset) | |
5451 | { | |
5452 | unsigned int i; | |
5453 | ||
5454 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
5455 | return NULL; | |
5456 | ||
5457 | for (i = 0; i < num_debug_info_entries; i++) | |
5458 | if (debug_information[i].cu_offset == offset) | |
5459 | return debug_information + i; | |
5460 | ||
5461 | return NULL; | |
5462 | } | |
5463 | ||
459d52c8 DE |
5464 | static const char * |
5465 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
5466 | { | |
5467 | /* See gdb/gdb-index.h. */ | |
5468 | static const char * const kinds[] = | |
5469 | { | |
5470 | N_ ("no info"), | |
5471 | N_ ("type"), | |
5472 | N_ ("variable"), | |
5473 | N_ ("function"), | |
5474 | N_ ("other"), | |
5475 | N_ ("unused5"), | |
5476 | N_ ("unused6"), | |
5477 | N_ ("unused7") | |
5478 | }; | |
5479 | ||
5480 | return _ (kinds[kind]); | |
5481 | } | |
5482 | ||
19e6b90e | 5483 | static int |
459d52c8 DE |
5484 | display_debug_pubnames_worker (struct dwarf_section *section, |
5485 | void *file ATTRIBUTE_UNUSED, | |
5486 | int is_gnu) | |
19e6b90e | 5487 | { |
91d6fa6a | 5488 | DWARF2_Internal_PubNames names; |
19e6b90e L |
5489 | unsigned char *start = section->start; |
5490 | unsigned char *end = start + section->size; | |
5491 | ||
6e3d6dc1 NC |
5492 | /* It does not matter if this load fails, |
5493 | we test for that later on. */ | |
5494 | load_debug_info (file); | |
5495 | ||
dda8d76d | 5496 | introduce (section, FALSE); |
19e6b90e L |
5497 | |
5498 | while (start < end) | |
5499 | { | |
5500 | unsigned char *data; | |
e98fdf1a | 5501 | unsigned long sec_off; |
bf5117e3 | 5502 | unsigned int offset_size, initial_length_size; |
19e6b90e | 5503 | |
e98fdf1a | 5504 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 5505 | if (names.pn_length == 0xffffffff) |
19e6b90e | 5506 | { |
e98fdf1a | 5507 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e L |
5508 | offset_size = 8; |
5509 | initial_length_size = 12; | |
5510 | } | |
5511 | else | |
5512 | { | |
5513 | offset_size = 4; | |
5514 | initial_length_size = 4; | |
5515 | } | |
5516 | ||
e98fdf1a AM |
5517 | sec_off = start - section->start; |
5518 | if (sec_off + names.pn_length < sec_off | |
5519 | || sec_off + names.pn_length > section->size) | |
5520 | { | |
5521 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
5522 | section->name, | |
5523 | sec_off - initial_length_size, | |
5524 | dwarf_vmatoa ("x", names.pn_length)); | |
5525 | break; | |
5526 | } | |
5527 | ||
5528 | data = start; | |
5529 | start += names.pn_length; | |
5530 | ||
0c588247 NC |
5531 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
5532 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
5533 | |
5534 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
5535 | && num_debug_info_entries > 0 | |
91d6fa6a | 5536 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 5537 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 5538 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 5539 | |
0c588247 | 5540 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 5541 | |
058037d3 NC |
5542 | printf (_(" Length: %ld\n"), |
5543 | (long) names.pn_length); | |
5544 | printf (_(" Version: %d\n"), | |
5545 | names.pn_version); | |
5546 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
5547 | (unsigned long) names.pn_offset); | |
5548 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
5549 | (long) names.pn_size); | |
19e6b90e | 5550 | |
91d6fa6a | 5551 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
5552 | { |
5553 | static int warned = 0; | |
5554 | ||
5555 | if (! warned) | |
5556 | { | |
5557 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
5558 | warned = 1; | |
5559 | } | |
5560 | ||
5561 | continue; | |
5562 | } | |
5563 | ||
459d52c8 DE |
5564 | if (is_gnu) |
5565 | printf (_("\n Offset Kind Name\n")); | |
5566 | else | |
5567 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 5568 | |
e98fdf1a | 5569 | while (1) |
19e6b90e | 5570 | { |
f41e4712 | 5571 | bfd_size_type maxprint; |
e98fdf1a | 5572 | dwarf_vma offset; |
f41e4712 | 5573 | |
0c588247 | 5574 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e | 5575 | |
e98fdf1a AM |
5576 | if (offset == 0) |
5577 | break; | |
b4eb7656 | 5578 | |
e98fdf1a AM |
5579 | data += offset_size; |
5580 | if (data >= end) | |
5581 | break; | |
5582 | maxprint = (end - data) - 1; | |
f41e4712 | 5583 | |
e98fdf1a AM |
5584 | if (is_gnu) |
5585 | { | |
5586 | unsigned int kind_data; | |
5587 | gdb_index_symbol_kind kind; | |
5588 | const char *kind_name; | |
5589 | int is_static; | |
5590 | ||
5591 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
5592 | data++; | |
5593 | maxprint --; | |
5594 | /* GCC computes the kind as the upper byte in the CU index | |
5595 | word, and then right shifts it by the CU index size. | |
5596 | Left shift KIND to where the gdb-index.h accessor macros | |
5597 | can use it. */ | |
5598 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
5599 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
5600 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
5601 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
5602 | printf (" %-6lx %s,%-10s %.*s\n", | |
5603 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
5604 | kind_name, (int) maxprint, data); | |
19e6b90e | 5605 | } |
e98fdf1a AM |
5606 | else |
5607 | printf (" %-6lx\t%.*s\n", | |
5608 | (unsigned long) offset, (int) maxprint, data); | |
5609 | ||
5610 | data += strnlen ((char *) data, maxprint) + 1; | |
5611 | if (data >= end) | |
5612 | break; | |
19e6b90e | 5613 | } |
19e6b90e L |
5614 | } |
5615 | ||
5616 | printf ("\n"); | |
5617 | return 1; | |
5618 | } | |
5619 | ||
459d52c8 DE |
5620 | static int |
5621 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
5622 | { | |
5623 | return display_debug_pubnames_worker (section, file, 0); | |
5624 | } | |
5625 | ||
5626 | static int | |
5627 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
5628 | { | |
5629 | return display_debug_pubnames_worker (section, file, 1); | |
5630 | } | |
5631 | ||
19e6b90e L |
5632 | static int |
5633 | display_debug_macinfo (struct dwarf_section *section, | |
5634 | void *file ATTRIBUTE_UNUSED) | |
5635 | { | |
5636 | unsigned char *start = section->start; | |
5637 | unsigned char *end = start + section->size; | |
5638 | unsigned char *curr = start; | |
19e6b90e L |
5639 | enum dwarf_macinfo_record_type op; |
5640 | ||
dda8d76d | 5641 | introduce (section, FALSE); |
19e6b90e L |
5642 | |
5643 | while (curr < end) | |
5644 | { | |
5645 | unsigned int lineno; | |
0c588247 | 5646 | const unsigned char *string; |
19e6b90e | 5647 | |
3f5e193b | 5648 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
5649 | curr++; |
5650 | ||
5651 | switch (op) | |
5652 | { | |
5653 | case DW_MACINFO_start_file: | |
5654 | { | |
5655 | unsigned int filenum; | |
5656 | ||
cd30bcef AM |
5657 | READ_ULEB (lineno, curr, end); |
5658 | READ_ULEB (filenum, curr, end); | |
19e6b90e L |
5659 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), |
5660 | lineno, filenum); | |
5661 | } | |
5662 | break; | |
5663 | ||
5664 | case DW_MACINFO_end_file: | |
5665 | printf (_(" DW_MACINFO_end_file\n")); | |
5666 | break; | |
5667 | ||
5668 | case DW_MACINFO_define: | |
cd30bcef | 5669 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5670 | string = curr; |
5671 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5672 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
5673 | lineno, string); | |
5674 | break; | |
5675 | ||
5676 | case DW_MACINFO_undef: | |
cd30bcef | 5677 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5678 | string = curr; |
5679 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5680 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
5681 | lineno, string); | |
5682 | break; | |
5683 | ||
5684 | case DW_MACINFO_vendor_ext: | |
5685 | { | |
5686 | unsigned int constant; | |
5687 | ||
cd30bcef | 5688 | READ_ULEB (constant, curr, end); |
0c588247 NC |
5689 | string = curr; |
5690 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5691 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
5692 | constant, string); | |
5693 | } | |
5694 | break; | |
5695 | } | |
5696 | } | |
5697 | ||
5698 | return 1; | |
5699 | } | |
5700 | ||
4ccf1e31 JJ |
5701 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5702 | filename and dirname corresponding to file name table entry with index | |
5703 | FILEIDX. Return NULL on failure. */ | |
5704 | ||
5705 | static unsigned char * | |
f6f0e17b NC |
5706 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5707 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5708 | unsigned char **dir_name) |
5709 | { | |
5710 | struct dwarf_section *section = &debug_displays [line].section; | |
5711 | unsigned char *hdrptr, *dirtable, *file_name; | |
5712 | unsigned int offset_size, initial_length_size; | |
cd30bcef | 5713 | unsigned int version, opcode_base; |
4ccf1e31 | 5714 | dwarf_vma length, diridx; |
f6f0e17b | 5715 | const unsigned char * end; |
4ccf1e31 JJ |
5716 | |
5717 | *dir_name = NULL; | |
5718 | if (section->start == NULL | |
5719 | || line_offset >= section->size | |
5720 | || fileidx == 0) | |
5721 | return NULL; | |
5722 | ||
5723 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5724 | end = section->start + section->size; |
0c588247 NC |
5725 | |
5726 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5727 | if (length == 0xffffffff) |
5728 | { | |
5729 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5730 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
5731 | offset_size = 8; |
5732 | initial_length_size = 12; | |
5733 | } | |
5734 | else | |
5735 | { | |
5736 | offset_size = 4; | |
5737 | initial_length_size = 4; | |
5738 | } | |
e98fdf1a AM |
5739 | if (length + initial_length_size < length |
5740 | || length + initial_length_size > section->size) | |
4ccf1e31 | 5741 | return NULL; |
0c588247 NC |
5742 | |
5743 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5744 | if (version != 2 && version != 3 && version != 4) |
5745 | return NULL; | |
5746 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5747 | if (version >= 4) | |
5748 | hdrptr++; /* Skip max_ops_per_insn. */ | |
5749 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
5750 | |
5751 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
5752 | if (opcode_base == 0) |
5753 | return NULL; | |
0c588247 | 5754 | |
4ccf1e31 | 5755 | hdrptr += opcode_base - 1; |
5c1c468d NC |
5756 | if (hdrptr >= end) |
5757 | return NULL; | |
5758 | ||
4ccf1e31 JJ |
5759 | dirtable = hdrptr; |
5760 | /* Skip over dirname table. */ | |
5761 | while (*hdrptr != '\0') | |
5c1c468d NC |
5762 | { |
5763 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; | |
5764 | if (hdrptr >= end) | |
5765 | return NULL; | |
5766 | } | |
4ccf1e31 | 5767 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 5768 | |
4ccf1e31 | 5769 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 5770 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 5771 | { |
0c588247 | 5772 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
cd30bcef AM |
5773 | SKIP_ULEB (hdrptr, end); |
5774 | SKIP_ULEB (hdrptr, end); | |
5775 | SKIP_ULEB (hdrptr, end); | |
4ccf1e31 | 5776 | } |
5c1c468d | 5777 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 5778 | return NULL; |
5c1c468d | 5779 | |
4ccf1e31 | 5780 | file_name = hdrptr; |
0c588247 | 5781 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
5c1c468d NC |
5782 | if (hdrptr >= end) |
5783 | return NULL; | |
cd30bcef | 5784 | READ_ULEB (diridx, hdrptr, end); |
4ccf1e31 JJ |
5785 | if (diridx == 0) |
5786 | return file_name; | |
5c1c468d | 5787 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
0c588247 | 5788 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
5c1c468d | 5789 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
5790 | return NULL; |
5791 | *dir_name = dirtable; | |
5792 | return file_name; | |
5793 | } | |
5794 | ||
5795 | static int | |
5796 | display_debug_macro (struct dwarf_section *section, | |
5797 | void *file) | |
5798 | { | |
5799 | unsigned char *start = section->start; | |
5800 | unsigned char *end = start + section->size; | |
5801 | unsigned char *curr = start; | |
5802 | unsigned char *extended_op_buf[256]; | |
4ccf1e31 | 5803 | |
dda8d76d NC |
5804 | load_debug_section_with_follow (str, file); |
5805 | load_debug_section_with_follow (line, file); | |
e4b7104b | 5806 | load_debug_section_with_follow (str_index, file); |
4ccf1e31 | 5807 | |
dda8d76d | 5808 | introduce (section, FALSE); |
4ccf1e31 JJ |
5809 | |
5810 | while (curr < end) | |
5811 | { | |
5812 | unsigned int lineno, version, flags; | |
5813 | unsigned int offset_size = 4; | |
0c588247 | 5814 | const unsigned char *string; |
4ccf1e31 JJ |
5815 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
5816 | unsigned char **extended_ops = NULL; | |
5817 | ||
0c588247 | 5818 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 5819 | if (version != 4 && version != 5) |
4ccf1e31 | 5820 | { |
7a7e1061 | 5821 | error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"), |
4ccf1e31 JJ |
5822 | section->name); |
5823 | return 0; | |
5824 | } | |
5825 | ||
0c588247 | 5826 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
4ccf1e31 JJ |
5827 | if (flags & 1) |
5828 | offset_size = 8; | |
5829 | printf (_(" Offset: 0x%lx\n"), | |
5830 | (unsigned long) sec_offset); | |
5831 | printf (_(" Version: %d\n"), version); | |
5832 | printf (_(" Offset size: %d\n"), offset_size); | |
5833 | if (flags & 2) | |
5834 | { | |
0c588247 | 5835 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
5836 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
5837 | (unsigned long) line_offset); | |
5838 | } | |
5839 | if (flags & 4) | |
5840 | { | |
0c588247 | 5841 | unsigned int i, count, op; |
4ccf1e31 | 5842 | dwarf_vma nargs, n; |
0c588247 NC |
5843 | |
5844 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 5845 | |
4ccf1e31 JJ |
5846 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
5847 | extended_ops = extended_op_buf; | |
5848 | if (count) | |
5849 | { | |
5850 | printf (_(" Extension opcode arguments:\n")); | |
5851 | for (i = 0; i < count; i++) | |
5852 | { | |
0c588247 | 5853 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 5854 | extended_ops[op] = curr; |
cd30bcef | 5855 | READ_ULEB (nargs, curr, end); |
4ccf1e31 | 5856 | if (nargs == 0) |
7a7e1061 | 5857 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
5858 | else |
5859 | { | |
7a7e1061 | 5860 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
5861 | for (n = 0; n < nargs; n++) |
5862 | { | |
0c588247 NC |
5863 | unsigned int form; |
5864 | ||
5865 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
5866 | printf ("%s%s", get_FORM_name (form), |
5867 | n == nargs - 1 ? "\n" : ", "); | |
5868 | switch (form) | |
5869 | { | |
5870 | case DW_FORM_data1: | |
5871 | case DW_FORM_data2: | |
5872 | case DW_FORM_data4: | |
5873 | case DW_FORM_data8: | |
5874 | case DW_FORM_sdata: | |
5875 | case DW_FORM_udata: | |
5876 | case DW_FORM_block: | |
5877 | case DW_FORM_block1: | |
5878 | case DW_FORM_block2: | |
5879 | case DW_FORM_block4: | |
5880 | case DW_FORM_flag: | |
5881 | case DW_FORM_string: | |
5882 | case DW_FORM_strp: | |
5883 | case DW_FORM_sec_offset: | |
5884 | break; | |
5885 | default: | |
5886 | error (_("Invalid extension opcode form %s\n"), | |
5887 | get_FORM_name (form)); | |
5888 | return 0; | |
5889 | } | |
5890 | } | |
5891 | } | |
5892 | } | |
5893 | } | |
5894 | } | |
5895 | printf ("\n"); | |
5896 | ||
5897 | while (1) | |
5898 | { | |
5899 | unsigned int op; | |
5900 | ||
5901 | if (curr >= end) | |
5902 | { | |
5903 | error (_(".debug_macro section not zero terminated\n")); | |
5904 | return 0; | |
5905 | } | |
5906 | ||
0c588247 | 5907 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
5908 | if (op == 0) |
5909 | break; | |
5910 | ||
5911 | switch (op) | |
5912 | { | |
e4b7104b NC |
5913 | case DW_MACRO_define: |
5914 | READ_ULEB (lineno, curr, end); | |
5915 | string = curr; | |
5916 | curr += strnlen ((char *) string, end - string) + 1; | |
5917 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), | |
5918 | lineno, string); | |
5919 | break; | |
5920 | ||
5921 | case DW_MACRO_undef: | |
5922 | READ_ULEB (lineno, curr, end); | |
5923 | string = curr; | |
5924 | curr += strnlen ((char *) string, end - string) + 1; | |
5925 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), | |
5926 | lineno, string); | |
5927 | break; | |
5928 | ||
7a7e1061 | 5929 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
5930 | { |
5931 | unsigned int filenum; | |
5932 | unsigned char *file_name = NULL, *dir_name = NULL; | |
5933 | ||
cd30bcef AM |
5934 | READ_ULEB (lineno, curr, end); |
5935 | READ_ULEB (filenum, curr, end); | |
4ccf1e31 JJ |
5936 | |
5937 | if ((flags & 2) == 0) | |
7a7e1061 | 5938 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
5939 | else |
5940 | file_name | |
5941 | = get_line_filename_and_dirname (line_offset, filenum, | |
5942 | &dir_name); | |
5943 | if (file_name == NULL) | |
7a7e1061 | 5944 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
5945 | lineno, filenum); |
5946 | else | |
7a7e1061 | 5947 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
5948 | lineno, filenum, |
5949 | dir_name != NULL ? (const char *) dir_name : "", | |
5950 | dir_name != NULL ? "/" : "", file_name); | |
5951 | } | |
5952 | break; | |
5953 | ||
7a7e1061 JK |
5954 | case DW_MACRO_end_file: |
5955 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
5956 | break; |
5957 | ||
7a7e1061 | 5958 | case DW_MACRO_define_strp: |
cd30bcef | 5959 | READ_ULEB (lineno, curr, end); |
0c588247 | 5960 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5961 | string = fetch_indirect_string (offset); |
7a7e1061 | 5962 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5963 | lineno, string); |
5964 | break; | |
5965 | ||
7a7e1061 | 5966 | case DW_MACRO_undef_strp: |
cd30bcef | 5967 | READ_ULEB (lineno, curr, end); |
0c588247 | 5968 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5969 | string = fetch_indirect_string (offset); |
7a7e1061 | 5970 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5971 | lineno, string); |
5972 | break; | |
5973 | ||
7a7e1061 | 5974 | case DW_MACRO_import: |
0c588247 | 5975 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5976 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
5977 | (unsigned long) offset); |
5978 | break; | |
5979 | ||
7a7e1061 | 5980 | case DW_MACRO_define_sup: |
cd30bcef | 5981 | READ_ULEB (lineno, curr, end); |
0c588247 | 5982 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5983 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5984 | lineno, (unsigned long) offset); |
5985 | break; | |
5986 | ||
7a7e1061 | 5987 | case DW_MACRO_undef_sup: |
cd30bcef | 5988 | READ_ULEB (lineno, curr, end); |
0c588247 | 5989 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5990 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5991 | lineno, (unsigned long) offset); |
5992 | break; | |
5993 | ||
7a7e1061 | 5994 | case DW_MACRO_import_sup: |
0c588247 | 5995 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5996 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
5997 | (unsigned long) offset); |
5998 | break; | |
5999 | ||
e4b7104b NC |
6000 | case DW_MACRO_define_strx: |
6001 | case DW_MACRO_undef_strx: | |
6002 | READ_ULEB (lineno, curr, end); | |
6003 | READ_ULEB (offset, curr, end); | |
6004 | string = (const unsigned char *) | |
6005 | fetch_indexed_string (offset, NULL, offset_size, FALSE); | |
6006 | if (op == DW_MACRO_define_strx) | |
6007 | printf (" DW_MACRO_define_strx "); | |
6008 | else | |
6009 | printf (" DW_MACRO_undef_strx "); | |
6010 | if (do_wide) | |
39f381cb | 6011 | printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset)); |
e4b7104b NC |
6012 | printf (_("lineno : %d macro : %s\n"), |
6013 | lineno, string); | |
6014 | break; | |
6015 | ||
4ccf1e31 | 6016 | default: |
e4b7104b NC |
6017 | if (op >= DW_MACRO_lo_user && op <= DW_MACRO_hi_user) |
6018 | { | |
6019 | printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op); | |
6020 | break; | |
6021 | } | |
6022 | ||
4ccf1e31 JJ |
6023 | if (extended_ops == NULL || extended_ops[op] == NULL) |
6024 | { | |
6025 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
6026 | return 0; | |
6027 | } | |
6028 | else | |
6029 | { | |
6030 | /* Skip over unhandled opcodes. */ | |
6031 | dwarf_vma nargs, n; | |
6032 | unsigned char *desc = extended_ops[op]; | |
cd30bcef | 6033 | READ_ULEB (nargs, desc, end); |
4ccf1e31 JJ |
6034 | if (nargs == 0) |
6035 | { | |
7a7e1061 | 6036 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
6037 | break; |
6038 | } | |
7a7e1061 | 6039 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
6040 | for (n = 0; n < nargs; n++) |
6041 | { | |
0c588247 NC |
6042 | int val; |
6043 | ||
77145576 | 6044 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 6045 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 6046 | curr |
77145576 | 6047 | = read_and_display_attr_value (0, val, 0, |
ec1b0fbb | 6048 | start, curr, end, 0, 0, offset_size, |
341f9135 | 6049 | version, NULL, 0, NULL, |
ec1b0fbb | 6050 | NULL, ' ', -1); |
4ccf1e31 JJ |
6051 | if (n != nargs - 1) |
6052 | printf (","); | |
6053 | } | |
6054 | printf ("\n"); | |
6055 | } | |
6056 | break; | |
6057 | } | |
6058 | } | |
6059 | ||
6060 | printf ("\n"); | |
b4eb7656 | 6061 | } |
4ccf1e31 JJ |
6062 | |
6063 | return 1; | |
6064 | } | |
6065 | ||
19e6b90e L |
6066 | static int |
6067 | display_debug_abbrev (struct dwarf_section *section, | |
6068 | void *file ATTRIBUTE_UNUSED) | |
6069 | { | |
6070 | abbrev_entry *entry; | |
6071 | unsigned char *start = section->start; | |
bcd213b2 | 6072 | const unsigned char *end = start + section->size; |
19e6b90e | 6073 | |
dda8d76d | 6074 | introduce (section, FALSE); |
19e6b90e L |
6075 | |
6076 | do | |
6077 | { | |
bcd213b2 NC |
6078 | abbrev_list * list; |
6079 | dwarf_vma offset; | |
7282333f | 6080 | |
bcd213b2 | 6081 | offset = start - section->start; |
76868f36 | 6082 | list = find_abbrev_list_by_abbrev_offset (0, offset); |
bcd213b2 NC |
6083 | if (list == NULL) |
6084 | { | |
76868f36 | 6085 | list = new_abbrev_list (0, offset); |
bcd213b2 NC |
6086 | start = process_abbrev_set (start, end, list); |
6087 | list->start_of_next_abbrevs = start; | |
6088 | } | |
6089 | else | |
6090 | start = list->start_of_next_abbrevs; | |
19e6b90e | 6091 | |
bcd213b2 | 6092 | if (list->first_abbrev == NULL) |
19e6b90e L |
6093 | continue; |
6094 | ||
bcd213b2 | 6095 | printf (_(" Number TAG (0x%lx)\n"), (long) offset); |
19e6b90e | 6096 | |
bcd213b2 | 6097 | for (entry = list->first_abbrev; entry; entry = entry->next) |
19e6b90e L |
6098 | { |
6099 | abbrev_attr *attr; | |
6100 | ||
cc5914eb | 6101 | printf (" %ld %s [%s]\n", |
bcd213b2 | 6102 | entry->number, |
19e6b90e L |
6103 | get_TAG_name (entry->tag), |
6104 | entry->children ? _("has children") : _("no children")); | |
6105 | ||
6106 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
6107 | { |
6108 | printf (" %-18s %s", | |
6109 | get_AT_name (attr->attribute), | |
6110 | get_FORM_name (attr->form)); | |
6111 | if (attr->form == DW_FORM_implicit_const) | |
6112 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
6113 | putchar ('\n'); | |
6114 | } | |
19e6b90e L |
6115 | } |
6116 | } | |
6117 | while (start); | |
6118 | ||
6119 | printf ("\n"); | |
6120 | ||
6121 | return 1; | |
6122 | } | |
6123 | ||
42bcef4a AB |
6124 | /* Return true when ADDR is the maximum address, when addresses are |
6125 | POINTER_SIZE bytes long. */ | |
6126 | ||
6127 | static bfd_boolean | |
6128 | is_max_address (dwarf_vma addr, unsigned int pointer_size) | |
6129 | { | |
6130 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
6131 | return ((addr & mask) == mask); | |
6132 | } | |
6133 | ||
9f272209 AO |
6134 | /* Display a view pair list starting at *VSTART_PTR and ending at |
6135 | VLISTEND within SECTION. */ | |
6136 | ||
6137 | static void | |
6138 | display_view_pair_list (struct dwarf_section *section, | |
6139 | unsigned char **vstart_ptr, | |
6140 | unsigned int debug_info_entry, | |
6141 | unsigned char *vlistend) | |
6142 | { | |
6143 | unsigned char *vstart = *vstart_ptr; | |
6144 | unsigned char *section_end = section->start + section->size; | |
6145 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
6146 | ||
6147 | if (vlistend < section_end) | |
6148 | section_end = vlistend; | |
6149 | ||
6150 | putchar ('\n'); | |
6151 | ||
6152 | while (vstart < section_end) | |
6153 | { | |
6154 | dwarf_vma off = vstart - section->start; | |
6155 | dwarf_vma vbegin, vend; | |
6156 | ||
cd30bcef | 6157 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 | 6158 | if (vstart == section_end) |
cd30bcef | 6159 | break; |
9f272209 | 6160 | |
cd30bcef | 6161 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6162 | printf (" %8.8lx ", (unsigned long) off); |
6163 | ||
6164 | print_dwarf_view (vbegin, pointer_size, 1); | |
6165 | print_dwarf_view (vend, pointer_size, 1); | |
6166 | printf (_("location view pair\n")); | |
6167 | } | |
6168 | ||
6169 | putchar ('\n'); | |
6170 | *vstart_ptr = vstart; | |
6171 | } | |
6172 | ||
4723351a CC |
6173 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
6174 | ||
6175 | static void | |
6176 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
6177 | unsigned char **start_ptr, |
6178 | unsigned int debug_info_entry, | |
359ca075 JK |
6179 | dwarf_vma offset, |
6180 | dwarf_vma base_address, | |
9f272209 | 6181 | unsigned char **vstart_ptr, |
b4eb7656 | 6182 | int has_frame_base) |
4723351a | 6183 | { |
9f272209 | 6184 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6185 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6186 | unsigned long cu_offset; |
6187 | unsigned int pointer_size; | |
6188 | unsigned int offset_size; | |
6189 | int dwarf_version; | |
4723351a CC |
6190 | |
6191 | dwarf_vma begin; | |
6192 | dwarf_vma end; | |
6193 | unsigned short length; | |
6194 | int need_frame_base; | |
6195 | ||
82b1b41b NC |
6196 | if (debug_info_entry >= num_debug_info_entries) |
6197 | { | |
6198 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
6199 | debug_info_entry); | |
6200 | return; | |
6201 | } | |
b4eb7656 | 6202 | |
82b1b41b NC |
6203 | cu_offset = debug_information [debug_info_entry].cu_offset; |
6204 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6205 | offset_size = debug_information [debug_info_entry].offset_size; | |
6206 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 6207 | |
f41e4712 NC |
6208 | if (pointer_size < 2 || pointer_size > 8) |
6209 | { | |
6210 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6211 | pointer_size, debug_info_entry); | |
6212 | return; | |
6213 | } | |
6214 | ||
4723351a CC |
6215 | while (1) |
6216 | { | |
359ca075 | 6217 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 6218 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 6219 | |
4723351a | 6220 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
6221 | { |
6222 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6223 | (unsigned long) offset); |
b4eb7656 AM |
6224 | break; |
6225 | } | |
4723351a | 6226 | |
359ca075 | 6227 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 6228 | |
0c588247 NC |
6229 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
6230 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 6231 | |
4723351a | 6232 | if (begin == 0 && end == 0) |
b4eb7656 | 6233 | { |
d1c4b12b NC |
6234 | /* PR 18374: In a object file we can have a location list that |
6235 | starts with a begin and end of 0 because there are relocations | |
6236 | that need to be applied to the addresses. Actually applying | |
6237 | the relocations now does not help as they will probably resolve | |
6238 | to 0, since the object file has not been fully linked. Real | |
6239 | end of list markers will not have any relocations against them. */ | |
6240 | if (! reloc_at (section, off) | |
6241 | && ! reloc_at (section, off + pointer_size)) | |
6242 | { | |
6243 | printf (_("<End of list>\n")); | |
6244 | break; | |
6245 | } | |
b4eb7656 | 6246 | } |
4723351a CC |
6247 | |
6248 | /* Check base address specifiers. */ | |
42bcef4a AB |
6249 | if (is_max_address (begin, pointer_size) |
6250 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
6251 | { |
6252 | base_address = end; | |
6253 | print_dwarf_vma (begin, pointer_size); | |
6254 | print_dwarf_vma (end, pointer_size); | |
6255 | printf (_("(base address)\n")); | |
6256 | continue; | |
6257 | } | |
4723351a | 6258 | |
9f272209 AO |
6259 | if (vstart) |
6260 | { | |
9f272209 AO |
6261 | off = offset + (vstart - *start_ptr); |
6262 | ||
cd30bcef | 6263 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
6264 | print_dwarf_view (vbegin, pointer_size, 1); |
6265 | ||
cd30bcef | 6266 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6267 | print_dwarf_view (vend, pointer_size, 1); |
6268 | ||
6269 | printf (_("views at %8.8lx for:\n %*s "), | |
6270 | (unsigned long) off, 8, ""); | |
6271 | } | |
6272 | ||
4723351a | 6273 | if (start + 2 > section_end) |
b4eb7656 AM |
6274 | { |
6275 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6276 | (unsigned long) offset); |
b4eb7656 AM |
6277 | break; |
6278 | } | |
4723351a | 6279 | |
0c588247 | 6280 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
6281 | |
6282 | if (start + length > section_end) | |
b4eb7656 AM |
6283 | { |
6284 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6285 | (unsigned long) offset); |
b4eb7656 AM |
6286 | break; |
6287 | } | |
4723351a CC |
6288 | |
6289 | print_dwarf_vma (begin + base_address, pointer_size); | |
6290 | print_dwarf_vma (end + base_address, pointer_size); | |
6291 | ||
6292 | putchar ('('); | |
6293 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6294 | pointer_size, |
6295 | offset_size, | |
6296 | dwarf_version, | |
6297 | length, | |
6298 | cu_offset, section); | |
4723351a CC |
6299 | putchar (')'); |
6300 | ||
6301 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6302 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 6303 | |
9f272209 | 6304 | if (begin == end && vbegin == vend) |
b4eb7656 | 6305 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6306 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 6307 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
6308 | |
6309 | putchar ('\n'); | |
6310 | ||
6311 | start += length; | |
6312 | } | |
6313 | ||
6314 | *start_ptr = start; | |
9f272209 | 6315 | *vstart_ptr = vstart; |
4723351a CC |
6316 | } |
6317 | ||
77145576 JK |
6318 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
6319 | ||
6320 | static void | |
6321 | display_loclists_list (struct dwarf_section *section, | |
6322 | unsigned char **start_ptr, | |
6323 | unsigned int debug_info_entry, | |
6324 | dwarf_vma offset, | |
6325 | dwarf_vma base_address, | |
9f272209 | 6326 | unsigned char **vstart_ptr, |
77145576 JK |
6327 | int has_frame_base) |
6328 | { | |
9f272209 | 6329 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
6330 | unsigned char *section_end = section->start + section->size; |
6331 | unsigned long cu_offset; | |
6332 | unsigned int pointer_size; | |
6333 | unsigned int offset_size; | |
6334 | int dwarf_version; | |
77145576 | 6335 | |
9dfd0db9 | 6336 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
6337 | dwarf_vma begin = -1, vbegin = -1; |
6338 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
6339 | dwarf_vma length; |
6340 | int need_frame_base; | |
6341 | ||
6342 | if (debug_info_entry >= num_debug_info_entries) | |
6343 | { | |
6344 | warn (_("No debug information available for " | |
6345 | "loclists lists of entry: %u\n"), | |
6346 | debug_info_entry); | |
6347 | return; | |
6348 | } | |
6349 | ||
6350 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6351 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6352 | offset_size = debug_information [debug_info_entry].offset_size; | |
6353 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6354 | ||
6355 | if (pointer_size < 2 || pointer_size > 8) | |
6356 | { | |
6357 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6358 | pointer_size, debug_info_entry); | |
6359 | return; | |
6360 | } | |
6361 | ||
6362 | while (1) | |
6363 | { | |
6364 | dwarf_vma off = offset + (start - *start_ptr); | |
6365 | enum dwarf_location_list_entry_type llet; | |
6366 | ||
6367 | if (start + 1 > section_end) | |
6368 | { | |
6369 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6370 | (unsigned long) offset); | |
6371 | break; | |
6372 | } | |
6373 | ||
6374 | printf (" %8.8lx ", (unsigned long) off); | |
6375 | ||
6376 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
6377 | ||
1c9f770d MW |
6378 | if (vstart && (llet == DW_LLE_offset_pair |
6379 | || llet == DW_LLE_start_end | |
6380 | || llet == DW_LLE_start_length)) | |
9f272209 AO |
6381 | { |
6382 | off = offset + (vstart - *start_ptr); | |
6383 | ||
cd30bcef | 6384 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
6385 | print_dwarf_view (vbegin, pointer_size, 1); |
6386 | ||
cd30bcef | 6387 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6388 | print_dwarf_view (vend, pointer_size, 1); |
6389 | ||
6390 | printf (_("views at %8.8lx for:\n %*s "), | |
6391 | (unsigned long) off, 8, ""); | |
6392 | } | |
6393 | ||
77145576 JK |
6394 | switch (llet) |
6395 | { | |
6396 | case DW_LLE_end_of_list: | |
6397 | printf (_("<End of list>\n")); | |
6398 | break; | |
6399 | case DW_LLE_offset_pair: | |
cd30bcef | 6400 | READ_ULEB (begin, start, section_end); |
1c9f770d | 6401 | begin += base_address; |
cd30bcef | 6402 | READ_ULEB (end, start, section_end); |
1c9f770d MW |
6403 | end += base_address; |
6404 | break; | |
6405 | case DW_LLE_start_end: | |
6406 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6407 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
6408 | break; | |
6409 | case DW_LLE_start_length: | |
6410 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6411 | READ_ULEB (end, start, section_end); | |
6412 | end += begin; | |
77145576 JK |
6413 | break; |
6414 | case DW_LLE_base_address: | |
6415 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
6416 | section_end); | |
6417 | print_dwarf_vma (base_address, pointer_size); | |
6418 | printf (_("(base address)\n")); | |
6419 | break; | |
9f272209 AO |
6420 | #ifdef DW_LLE_view_pair |
6421 | case DW_LLE_view_pair: | |
6422 | if (vstart) | |
6423 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
cd30bcef | 6424 | READ_ULEB (vbegin, start, section_end); |
9f272209 AO |
6425 | print_dwarf_view (vbegin, pointer_size, 1); |
6426 | ||
cd30bcef | 6427 | READ_ULEB (vend, start, section_end); |
9f272209 AO |
6428 | print_dwarf_view (vend, pointer_size, 1); |
6429 | ||
6430 | printf (_("views for:\n")); | |
6431 | continue; | |
6432 | #endif | |
77145576 JK |
6433 | default: |
6434 | error (_("Invalid location list entry type %d\n"), llet); | |
6435 | return; | |
6436 | } | |
6437 | if (llet == DW_LLE_end_of_list) | |
6438 | break; | |
1c9f770d MW |
6439 | if (llet != DW_LLE_offset_pair |
6440 | && llet != DW_LLE_start_end | |
6441 | && llet != DW_LLE_start_length) | |
77145576 JK |
6442 | continue; |
6443 | ||
6444 | if (start + 2 > section_end) | |
6445 | { | |
6446 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6447 | (unsigned long) offset); | |
6448 | break; | |
6449 | } | |
6450 | ||
cd30bcef | 6451 | READ_ULEB (length, start, section_end); |
77145576 | 6452 | |
1c9f770d MW |
6453 | print_dwarf_vma (begin, pointer_size); |
6454 | print_dwarf_vma (end, pointer_size); | |
77145576 JK |
6455 | |
6456 | putchar ('('); | |
6457 | need_frame_base = decode_location_expression (start, | |
6458 | pointer_size, | |
6459 | offset_size, | |
6460 | dwarf_version, | |
6461 | length, | |
6462 | cu_offset, section); | |
6463 | putchar (')'); | |
6464 | ||
6465 | if (need_frame_base && !has_frame_base) | |
6466 | printf (_(" [without DW_AT_frame_base]")); | |
6467 | ||
9f272209 | 6468 | if (begin == end && vbegin == vend) |
77145576 | 6469 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6470 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
6471 | fputs (_(" (start > end)"), stdout); |
6472 | ||
6473 | putchar ('\n'); | |
6474 | ||
6475 | start += length; | |
9f272209 | 6476 | vbegin = vend = -1; |
77145576 JK |
6477 | } |
6478 | ||
9f272209 AO |
6479 | if (vbegin != vm1 || vend != vm1) |
6480 | printf (_("Trailing view pair not used in a range")); | |
6481 | ||
77145576 | 6482 | *start_ptr = start; |
9f272209 | 6483 | *vstart_ptr = vstart; |
77145576 JK |
6484 | } |
6485 | ||
fab128ef CC |
6486 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
6487 | right-adjusted in a field of length LEN, and followed by a space. */ | |
6488 | ||
6489 | static void | |
6490 | print_addr_index (unsigned int idx, unsigned int len) | |
6491 | { | |
6492 | static char buf[15]; | |
6493 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 6494 | printf ("%*s ", len, buf); |
fab128ef CC |
6495 | } |
6496 | ||
4723351a CC |
6497 | /* Display a location list from a .dwo section. It uses address indexes rather |
6498 | than embedded addresses. This code closely follows display_loc_list, but the | |
6499 | two are sufficiently different that combining things is very ugly. */ | |
6500 | ||
6501 | static void | |
6502 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
6503 | unsigned char **start_ptr, |
6504 | unsigned int debug_info_entry, | |
359ca075 | 6505 | dwarf_vma offset, |
9f272209 | 6506 | unsigned char **vstart_ptr, |
b4eb7656 | 6507 | int has_frame_base) |
4723351a | 6508 | { |
9f272209 | 6509 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6510 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6511 | unsigned long cu_offset; |
6512 | unsigned int pointer_size; | |
6513 | unsigned int offset_size; | |
6514 | int dwarf_version; | |
4723351a CC |
6515 | int entry_type; |
6516 | unsigned short length; | |
6517 | int need_frame_base; | |
fab128ef | 6518 | unsigned int idx; |
4723351a | 6519 | |
82b1b41b NC |
6520 | if (debug_info_entry >= num_debug_info_entries) |
6521 | { | |
6522 | warn (_("No debug information for loc lists of entry: %u\n"), | |
6523 | debug_info_entry); | |
6524 | return; | |
6525 | } | |
6526 | ||
6527 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6528 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6529 | offset_size = debug_information [debug_info_entry].offset_size; | |
6530 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6531 | ||
f41e4712 NC |
6532 | if (pointer_size < 2 || pointer_size > 8) |
6533 | { | |
6534 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6535 | pointer_size, debug_info_entry); | |
6536 | return; | |
6537 | } | |
6538 | ||
4723351a CC |
6539 | while (1) |
6540 | { | |
359ca075 | 6541 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 6542 | |
fab128ef | 6543 | if (start >= section_end) |
b4eb7656 AM |
6544 | { |
6545 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6546 | (unsigned long) offset); |
b4eb7656 AM |
6547 | break; |
6548 | } | |
4723351a | 6549 | |
0c588247 | 6550 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
6551 | |
6552 | if (vstart) | |
6553 | switch (entry_type) | |
6554 | { | |
6555 | default: | |
6556 | break; | |
6557 | ||
6558 | case 2: | |
6559 | case 3: | |
6560 | case 4: | |
6561 | { | |
6562 | dwarf_vma view; | |
6563 | dwarf_vma off = offset + (vstart - *start_ptr); | |
6564 | ||
cd30bcef | 6565 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6566 | print_dwarf_view (view, 8, 1); |
6567 | ||
cd30bcef | 6568 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6569 | print_dwarf_view (view, 8, 1); |
6570 | ||
6571 | printf (_("views at %8.8lx for:\n %*s "), | |
6572 | (unsigned long) off, 8, ""); | |
6573 | ||
6574 | } | |
6575 | break; | |
6576 | } | |
6577 | ||
4723351a | 6578 | switch (entry_type) |
b4eb7656 AM |
6579 | { |
6580 | case 0: /* A terminating entry. */ | |
6581 | *start_ptr = start; | |
9f272209 | 6582 | *vstart_ptr = vstart; |
b4eb7656 AM |
6583 | printf (_("<End of list>\n")); |
6584 | return; | |
6585 | case 1: /* A base-address entry. */ | |
cd30bcef | 6586 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6587 | print_addr_index (idx, 8); |
9f272209 | 6588 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
6589 | printf (_("(base address selection entry)\n")); |
6590 | continue; | |
6591 | case 2: /* A start/end entry. */ | |
cd30bcef | 6592 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6593 | print_addr_index (idx, 8); |
cd30bcef | 6594 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6595 | print_addr_index (idx, 8); |
6596 | break; | |
6597 | case 3: /* A start/length entry. */ | |
cd30bcef | 6598 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6599 | print_addr_index (idx, 8); |
6600 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6601 | printf ("%08x ", idx); | |
6602 | break; | |
6603 | case 4: /* An offset pair entry. */ | |
6604 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6605 | printf ("%08x ", idx); | |
6606 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6607 | printf ("%08x ", idx); | |
6608 | break; | |
6609 | default: | |
6610 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
6611 | *start_ptr = start; | |
9f272209 | 6612 | *vstart_ptr = vstart; |
b4eb7656 AM |
6613 | return; |
6614 | } | |
4723351a CC |
6615 | |
6616 | if (start + 2 > section_end) | |
b4eb7656 AM |
6617 | { |
6618 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6619 | (unsigned long) offset); |
b4eb7656 AM |
6620 | break; |
6621 | } | |
4723351a | 6622 | |
0c588247 | 6623 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6624 | if (start + length > section_end) |
b4eb7656 AM |
6625 | { |
6626 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6627 | (unsigned long) offset); |
b4eb7656 AM |
6628 | break; |
6629 | } | |
4723351a CC |
6630 | |
6631 | putchar ('('); | |
6632 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6633 | pointer_size, |
6634 | offset_size, | |
6635 | dwarf_version, | |
6636 | length, | |
6637 | cu_offset, section); | |
4723351a CC |
6638 | putchar (')'); |
6639 | ||
6640 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6641 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
6642 | |
6643 | putchar ('\n'); | |
6644 | ||
6645 | start += length; | |
6646 | } | |
6647 | ||
6648 | *start_ptr = start; | |
9f272209 | 6649 | *vstart_ptr = vstart; |
4723351a CC |
6650 | } |
6651 | ||
9f272209 AO |
6652 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
6653 | loc_views. */ | |
51d0d03f | 6654 | |
9f272209 | 6655 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
6656 | |
6657 | static int | |
6658 | loc_offsets_compar (const void *ap, const void *bp) | |
6659 | { | |
6660 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
6661 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
6662 | ||
9f272209 AO |
6663 | int ret = (a > b) - (b > a); |
6664 | if (ret) | |
6665 | return ret; | |
6666 | ||
6667 | a = loc_views[*(const unsigned int *) ap]; | |
6668 | b = loc_views[*(const unsigned int *) bp]; | |
6669 | ||
6670 | ret = (a > b) - (b > a); | |
6671 | ||
6672 | return ret; | |
51d0d03f JJ |
6673 | } |
6674 | ||
19e6b90e L |
6675 | static int |
6676 | display_debug_loc (struct dwarf_section *section, void *file) | |
6677 | { | |
9f272209 | 6678 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
6679 | unsigned long bytes; |
6680 | unsigned char *section_begin = start; | |
6681 | unsigned int num_loc_list = 0; | |
6682 | unsigned long last_offset = 0; | |
9f272209 | 6683 | unsigned long last_view = 0; |
19e6b90e L |
6684 | unsigned int first = 0; |
6685 | unsigned int i; | |
6686 | unsigned int j; | |
6687 | int seen_first_offset = 0; | |
51d0d03f | 6688 | int locs_sorted = 1; |
9f272209 | 6689 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6690 | unsigned int *array = NULL; |
4723351a | 6691 | const char *suffix = strrchr (section->name, '.'); |
24841daa | 6692 | bfd_boolean is_dwo = FALSE; |
77145576 JK |
6693 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6694 | dwarf_vma expected_start = 0; | |
4723351a CC |
6695 | |
6696 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
24841daa | 6697 | is_dwo = TRUE; |
19e6b90e L |
6698 | |
6699 | bytes = section->size; | |
19e6b90e L |
6700 | |
6701 | if (bytes == 0) | |
6702 | { | |
6703 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6704 | return 0; | |
6705 | } | |
6706 | ||
77145576 JK |
6707 | if (is_loclists) |
6708 | { | |
6709 | unsigned char *hdrptr = section_begin; | |
6710 | dwarf_vma ll_length; | |
6711 | unsigned short ll_version; | |
6712 | unsigned char *end = section_begin + section->size; | |
6713 | unsigned char address_size, segment_selector_size; | |
6714 | uint32_t offset_entry_count; | |
6715 | ||
6716 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6717 | if (ll_length == 0xffffffff) | |
6718 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6719 | ||
6720 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6721 | if (ll_version != 5) | |
6722 | { | |
6723 | warn (_("The %s section contains corrupt or " | |
6724 | "unsupported version number: %d.\n"), | |
6725 | section->name, ll_version); | |
6726 | return 0; | |
6727 | } | |
6728 | ||
6729 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6730 | ||
6731 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6732 | if (segment_selector_size != 0) | |
6733 | { | |
6734 | warn (_("The %s section contains " | |
6735 | "unsupported segment selector size: %d.\n"), | |
6736 | section->name, segment_selector_size); | |
6737 | return 0; | |
6738 | } | |
6739 | ||
6740 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
6741 | if (offset_entry_count != 0) | |
6742 | { | |
6743 | warn (_("The %s section contains " | |
6744 | "unsupported offset entry count: %d.\n"), | |
6745 | section->name, offset_entry_count); | |
6746 | return 0; | |
6747 | } | |
6748 | ||
6749 | expected_start = hdrptr - section_begin; | |
6750 | } | |
6751 | ||
1febe64d NC |
6752 | if (load_debug_info (file) == 0) |
6753 | { | |
6754 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6755 | section->name); | |
6756 | return 0; | |
6757 | } | |
19e6b90e L |
6758 | |
6759 | /* Check the order of location list in .debug_info section. If | |
6760 | offsets of location lists are in the ascending order, we can | |
6761 | use `debug_information' directly. */ | |
6762 | for (i = 0; i < num_debug_info_entries; i++) | |
6763 | { | |
6764 | unsigned int num; | |
6765 | ||
6766 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
6767 | if (num > num_loc_list) |
6768 | num_loc_list = num; | |
19e6b90e L |
6769 | |
6770 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 6771 | if (locs_sorted && num != 0) |
19e6b90e L |
6772 | { |
6773 | if (!seen_first_offset) | |
6774 | { | |
6775 | /* This is the first location list. */ | |
6776 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 6777 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
6778 | first = i; |
6779 | seen_first_offset = 1; | |
6780 | j = 1; | |
6781 | } | |
6782 | else | |
6783 | j = 0; | |
6784 | ||
6785 | for (; j < num; j++) | |
6786 | { | |
6787 | if (last_offset > | |
9f272209 AO |
6788 | debug_information [i].loc_offsets [j] |
6789 | || (last_offset == debug_information [i].loc_offsets [j] | |
6790 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 6791 | { |
51d0d03f | 6792 | locs_sorted = 0; |
19e6b90e L |
6793 | break; |
6794 | } | |
6795 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 6796 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
6797 | } |
6798 | } | |
6799 | } | |
6800 | ||
19e6b90e L |
6801 | if (!seen_first_offset) |
6802 | error (_("No location lists in .debug_info section!\n")); | |
6803 | ||
d4bfc77b | 6804 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
6805 | && debug_information [first].loc_offsets [0] != expected_start |
6806 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
6807 | warn (_("Location lists in %s section start at 0x%s\n"), |
6808 | section->name, | |
6809 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 6810 | |
51d0d03f JJ |
6811 | if (!locs_sorted) |
6812 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d NC |
6813 | |
6814 | introduce (section, FALSE); | |
6815 | ||
d1c4b12b NC |
6816 | if (reloc_at (section, 0)) |
6817 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 6818 | |
d1c4b12b | 6819 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
6820 | |
6821 | seen_first_offset = 0; | |
6822 | for (i = first; i < num_debug_info_entries; i++) | |
6823 | { | |
9f272209 | 6824 | dwarf_vma offset, voffset; |
359ca075 | 6825 | dwarf_vma base_address; |
d1c4b12b | 6826 | unsigned int k; |
19e6b90e L |
6827 | int has_frame_base; |
6828 | ||
51d0d03f JJ |
6829 | if (!locs_sorted) |
6830 | { | |
6831 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
6832 | array[k] = k; | |
6833 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 6834 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
6835 | qsort (array, debug_information [i].num_loc_offsets, |
6836 | sizeof (*array), loc_offsets_compar); | |
6837 | } | |
19e6b90e | 6838 | |
9f272209 | 6839 | int adjacent_view_loclists = 1; |
51d0d03f | 6840 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 6841 | { |
51d0d03f JJ |
6842 | j = locs_sorted ? k : array[k]; |
6843 | if (k | |
9f272209 | 6844 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 6845 | ? k - 1 : array [k - 1]] |
9f272209 AO |
6846 | == debug_information [i].loc_offsets [j]) |
6847 | && (debug_information [i].loc_views [locs_sorted | |
6848 | ? k - 1 : array [k - 1]] | |
6849 | == debug_information [i].loc_views [j])) | |
51d0d03f | 6850 | continue; |
19e6b90e | 6851 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 6852 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 6853 | next = section_begin + offset; |
9f272209 AO |
6854 | voffset = debug_information [i].loc_views [j]; |
6855 | if (voffset != vm1) | |
6856 | vnext = section_begin + voffset; | |
6857 | else | |
6858 | vnext = NULL; | |
19e6b90e L |
6859 | base_address = debug_information [i].base_address; |
6860 | ||
9f272209 AO |
6861 | if (vnext && vnext < next) |
6862 | { | |
6863 | vstart = vnext; | |
6864 | display_view_pair_list (section, &vstart, i, next); | |
6865 | if (start == vnext) | |
6866 | start = vstart; | |
6867 | } | |
6868 | ||
6869 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
6870 | seen_first_offset = 1; |
6871 | else | |
6872 | { | |
6873 | if (start < next) | |
6874 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6875 | (unsigned long) (start - section_begin), |
c8071705 | 6876 | (unsigned long) offset); |
19e6b90e L |
6877 | else if (start > next) |
6878 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6879 | (unsigned long) (start - section_begin), |
c8071705 | 6880 | (unsigned long) offset); |
19e6b90e L |
6881 | } |
6882 | start = next; | |
9f272209 | 6883 | vstart = vnext; |
19e6b90e L |
6884 | |
6885 | if (offset >= bytes) | |
6886 | { | |
6887 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 6888 | (unsigned long) offset); |
19e6b90e L |
6889 | continue; |
6890 | } | |
6891 | ||
9f272209 AO |
6892 | if (vnext && voffset >= bytes) |
6893 | { | |
6894 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
6895 | (unsigned long) voffset); | |
6896 | continue; | |
6897 | } | |
6898 | ||
77145576 JK |
6899 | if (!is_loclists) |
6900 | { | |
6901 | if (is_dwo) | |
6902 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 6903 | &vstart, has_frame_base); |
77145576 JK |
6904 | else |
6905 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 6906 | &vstart, has_frame_base); |
77145576 | 6907 | } |
b4eb7656 | 6908 | else |
77145576 JK |
6909 | { |
6910 | if (is_dwo) | |
6911 | warn (_("DWO is not yet supported.\n")); | |
6912 | else | |
6913 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
6914 | &vstart, has_frame_base); |
6915 | } | |
6916 | ||
6917 | /* FIXME: this arrangement is quite simplistic. Nothing | |
6918 | requires locview lists to be adjacent to corresponding | |
6919 | loclists, and a single loclist could be augmented by | |
6920 | different locview lists, and vice-versa, unlikely as it | |
6921 | is that it would make sense to do so. Hopefully we'll | |
6922 | have view pair support built into loclists before we ever | |
6923 | need to address all these possibilities. */ | |
6924 | if (adjacent_view_loclists && vnext | |
6925 | && vnext != start && vstart != next) | |
6926 | { | |
6927 | adjacent_view_loclists = 0; | |
6928 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 6929 | } |
9f272209 AO |
6930 | |
6931 | if (vnext && vnext == start) | |
6932 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
6933 | } |
6934 | } | |
031cd65f | 6935 | |
4723351a | 6936 | if (start < section->start + section->size) |
d3a49aa8 AM |
6937 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
6938 | "There are %ld unused bytes at the end of section %s\n", | |
6939 | (long) (section->start + section->size - start)), | |
4723351a | 6940 | (long) (section->start + section->size - start), section->name); |
98fb390a | 6941 | putchar ('\n'); |
51d0d03f | 6942 | free (array); |
19e6b90e L |
6943 | return 1; |
6944 | } | |
6945 | ||
6946 | static int | |
6947 | display_debug_str (struct dwarf_section *section, | |
6948 | void *file ATTRIBUTE_UNUSED) | |
6949 | { | |
6950 | unsigned char *start = section->start; | |
6951 | unsigned long bytes = section->size; | |
6952 | dwarf_vma addr = section->address; | |
6953 | ||
6954 | if (bytes == 0) | |
6955 | { | |
6956 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6957 | return 0; | |
6958 | } | |
6959 | ||
dda8d76d | 6960 | introduce (section, FALSE); |
19e6b90e L |
6961 | |
6962 | while (bytes) | |
6963 | { | |
6964 | int j; | |
6965 | int k; | |
6966 | int lbytes; | |
6967 | ||
6968 | lbytes = (bytes > 16 ? 16 : bytes); | |
6969 | ||
6970 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
6971 | ||
6972 | for (j = 0; j < 16; j++) | |
6973 | { | |
6974 | if (j < lbytes) | |
6975 | printf ("%2.2x", start[j]); | |
6976 | else | |
6977 | printf (" "); | |
6978 | ||
6979 | if ((j & 3) == 3) | |
6980 | printf (" "); | |
6981 | } | |
6982 | ||
6983 | for (j = 0; j < lbytes; j++) | |
6984 | { | |
6985 | k = start[j]; | |
6986 | if (k >= ' ' && k < 0x80) | |
6987 | printf ("%c", k); | |
6988 | else | |
6989 | printf ("."); | |
6990 | } | |
6991 | ||
6992 | putchar ('\n'); | |
6993 | ||
6994 | start += lbytes; | |
6995 | addr += lbytes; | |
6996 | bytes -= lbytes; | |
6997 | } | |
6998 | ||
6999 | putchar ('\n'); | |
7000 | ||
7001 | return 1; | |
7002 | } | |
7003 | ||
19e6b90e L |
7004 | static int |
7005 | display_debug_info (struct dwarf_section *section, void *file) | |
7006 | { | |
d85bf2ba | 7007 | return process_debug_info (section, file, section->abbrev_sec, FALSE, FALSE); |
19e6b90e L |
7008 | } |
7009 | ||
2b6f5997 CC |
7010 | static int |
7011 | display_debug_types (struct dwarf_section *section, void *file) | |
7012 | { | |
d85bf2ba | 7013 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
6f875884 TG |
7014 | } |
7015 | ||
7016 | static int | |
7017 | display_trace_info (struct dwarf_section *section, void *file) | |
7018 | { | |
d85bf2ba | 7019 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
2b6f5997 | 7020 | } |
19e6b90e L |
7021 | |
7022 | static int | |
7023 | display_debug_aranges (struct dwarf_section *section, | |
7024 | void *file ATTRIBUTE_UNUSED) | |
7025 | { | |
7026 | unsigned char *start = section->start; | |
7027 | unsigned char *end = start + section->size; | |
7028 | ||
dda8d76d | 7029 | introduce (section, FALSE); |
19e6b90e | 7030 | |
6e3d6dc1 NC |
7031 | /* It does not matter if this load fails, |
7032 | we test for that later on. */ | |
7033 | load_debug_info (file); | |
7034 | ||
19e6b90e L |
7035 | while (start < end) |
7036 | { | |
7037 | unsigned char *hdrptr; | |
7038 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 7039 | unsigned char *addr_ranges; |
2d9472a2 NC |
7040 | dwarf_vma length; |
7041 | dwarf_vma address; | |
e98fdf1a | 7042 | unsigned long sec_off; |
53b8873b | 7043 | unsigned char address_size; |
19e6b90e | 7044 | int excess; |
bf5117e3 NC |
7045 | unsigned int offset_size; |
7046 | unsigned int initial_length_size; | |
19e6b90e L |
7047 | |
7048 | hdrptr = start; | |
7049 | ||
0c588247 | 7050 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
7051 | if (arange.ar_length == 0xffffffff) |
7052 | { | |
0c588247 | 7053 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
7054 | offset_size = 8; |
7055 | initial_length_size = 12; | |
7056 | } | |
7057 | else | |
7058 | { | |
7059 | offset_size = 4; | |
7060 | initial_length_size = 4; | |
7061 | } | |
7062 | ||
e98fdf1a AM |
7063 | sec_off = hdrptr - section->start; |
7064 | if (sec_off + arange.ar_length < sec_off | |
7065 | || sec_off + arange.ar_length > section->size) | |
7066 | { | |
7067 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
7068 | section->name, | |
7069 | sec_off - initial_length_size, | |
7070 | dwarf_vmatoa ("x", arange.ar_length)); | |
7071 | break; | |
7072 | } | |
7073 | ||
0c588247 NC |
7074 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
7075 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 7076 | |
6e3d6dc1 NC |
7077 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
7078 | && num_debug_info_entries > 0 | |
7079 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
7080 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 7081 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 7082 | |
0c588247 NC |
7083 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
7084 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
7085 | |
7086 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
7087 | { | |
67f101ee NC |
7088 | /* PR 19872: A version number of 0 probably means that there is |
7089 | padding at the end of the .debug_aranges section. Gold puts | |
7090 | it there when performing an incremental link, for example. | |
7091 | So do not generate a warning in this case. */ | |
7092 | if (arange.ar_version) | |
7093 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
7094 | break; |
7095 | } | |
7096 | ||
47704ddf KT |
7097 | printf (_(" Length: %ld\n"), |
7098 | (long) arange.ar_length); | |
19e6b90e | 7099 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
7100 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
7101 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
7102 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
7103 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
7104 | ||
53b8873b NC |
7105 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
7106 | ||
f41e4712 NC |
7107 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
7108 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
7109 | { |
7110 | error (_("Invalid address size in %s section!\n"), | |
7111 | section->name); | |
7112 | break; | |
7113 | } | |
7114 | ||
53b8873b NC |
7115 | /* The DWARF spec does not require that the address size be a power |
7116 | of two, but we do. This will have to change if we ever encounter | |
7117 | an uneven architecture. */ | |
7118 | if ((address_size & (address_size - 1)) != 0) | |
7119 | { | |
7120 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
7121 | break; | |
7122 | } | |
cecf136e | 7123 | |
209c9a13 NC |
7124 | if (address_size > 4) |
7125 | printf (_("\n Address Length\n")); | |
7126 | else | |
7127 | printf (_("\n Address Length\n")); | |
19e6b90e | 7128 | |
91d6fa6a | 7129 | addr_ranges = hdrptr; |
19e6b90e | 7130 | |
53b8873b NC |
7131 | /* Must pad to an alignment boundary that is twice the address size. */ |
7132 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 7133 | if (excess) |
91d6fa6a | 7134 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 7135 | |
e98fdf1a | 7136 | start += arange.ar_length + initial_length_size; |
1617e571 | 7137 | |
91d6fa6a | 7138 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 7139 | { |
0c588247 NC |
7140 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
7141 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 7142 | |
80c35038 | 7143 | printf (" "); |
2d9472a2 NC |
7144 | print_dwarf_vma (address, address_size); |
7145 | print_dwarf_vma (length, address_size); | |
7146 | putchar ('\n'); | |
19e6b90e | 7147 | } |
19e6b90e L |
7148 | } |
7149 | ||
7150 | printf ("\n"); | |
7151 | ||
7152 | return 1; | |
7153 | } | |
7154 | ||
4723351a CC |
7155 | /* Comparison function for qsort. */ |
7156 | static int | |
7157 | comp_addr_base (const void * v0, const void * v1) | |
7158 | { | |
d367307b AM |
7159 | debug_info *info0 = *(debug_info **) v0; |
7160 | debug_info *info1 = *(debug_info **) v1; | |
4723351a CC |
7161 | return info0->addr_base - info1->addr_base; |
7162 | } | |
7163 | ||
7164 | /* Display the debug_addr section. */ | |
7165 | static int | |
7166 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 7167 | void *file) |
4723351a CC |
7168 | { |
7169 | debug_info **debug_addr_info; | |
7170 | unsigned char *entry; | |
7171 | unsigned char *end; | |
7172 | unsigned int i; | |
7173 | unsigned int count; | |
7174 | ||
7175 | if (section->size == 0) | |
7176 | { | |
7177 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7178 | return 0; | |
7179 | } | |
7180 | ||
7181 | if (load_debug_info (file) == 0) | |
7182 | { | |
7183 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7184 | section->name); | |
7185 | return 0; | |
7186 | } | |
7187 | ||
dda8d76d | 7188 | introduce (section, FALSE); |
4723351a | 7189 | |
1306a742 NC |
7190 | /* PR 17531: file: cf38d01b. |
7191 | We use xcalloc because a corrupt file may not have initialised all of the | |
7192 | fields in the debug_info structure, which means that the sort below might | |
7193 | try to move uninitialised data. */ | |
7194 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 7195 | sizeof (debug_info *)); |
4723351a CC |
7196 | |
7197 | count = 0; | |
7198 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 7199 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
7200 | { |
7201 | /* PR 17531: file: cf38d01b. */ | |
7202 | if (debug_information[i].addr_base >= section->size) | |
7203 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
7204 | (unsigned long) debug_information[i].addr_base, i); | |
7205 | else | |
7206 | debug_addr_info [count++] = debug_information + i; | |
7207 | } | |
4723351a CC |
7208 | |
7209 | /* Add a sentinel to make iteration convenient. */ | |
7210 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
7211 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 7212 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 7213 | |
4723351a CC |
7214 | for (i = 0; i < count; i++) |
7215 | { | |
7216 | unsigned int idx; | |
fab128ef | 7217 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
7218 | |
7219 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 7220 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 7221 | |
fab128ef | 7222 | printf (_("\tIndex\tAddress\n")); |
4723351a CC |
7223 | entry = section->start + debug_addr_info [i]->addr_base; |
7224 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
7225 | idx = 0; | |
7226 | while (entry < end) | |
b4eb7656 AM |
7227 | { |
7228 | dwarf_vma base = byte_get (entry, address_size); | |
7229 | printf (_("\t%d:\t"), idx); | |
7230 | print_dwarf_vma (base, address_size); | |
7231 | printf ("\n"); | |
7232 | entry += address_size; | |
7233 | idx++; | |
7234 | } | |
4723351a CC |
7235 | } |
7236 | printf ("\n"); | |
7237 | ||
7238 | free (debug_addr_info); | |
7239 | return 1; | |
7240 | } | |
7241 | ||
7242 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 7243 | |
4723351a CC |
7244 | static int |
7245 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 7246 | void *file ATTRIBUTE_UNUSED) |
4723351a | 7247 | { |
9f27c364 HPN |
7248 | unsigned long idx; |
7249 | ||
4723351a CC |
7250 | if (section->size == 0) |
7251 | { | |
7252 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7253 | return 0; | |
7254 | } | |
e4b7104b NC |
7255 | |
7256 | unsigned char *start = section->start; | |
7257 | unsigned char *end = start + section->size; | |
7258 | unsigned char *curr = start; | |
7259 | ||
39f381cb NC |
7260 | const char * suffix = strrchr (section->name, '.'); |
7261 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
7262 | ||
7263 | if (dwo) | |
7264 | load_debug_section_with_follow (str_dwo, file); | |
7265 | else | |
7266 | load_debug_section_with_follow (str, file); | |
e4b7104b NC |
7267 | |
7268 | introduce (section, FALSE); | |
7269 | ||
7270 | while (curr < end) | |
7271 | { | |
7272 | dwarf_vma length; | |
7273 | dwarf_vma entry_length; | |
7274 | ||
7275 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); | |
7276 | /* FIXME: We assume that this means 64-bit DWARF is being used. */ | |
7277 | if (length == 0xffffffff) | |
7278 | { | |
7279 | SAFE_BYTE_GET (length, curr, 8, end); | |
7280 | entry_length = 8; | |
7281 | } | |
7282 | else | |
7283 | entry_length = 4; | |
7284 | ||
39f381cb NC |
7285 | if (length == 0) |
7286 | { | |
7287 | /* This is probably an old style .debug_str_offset section which | |
7288 | just contains offsets and no header (and the first offset is 0). */ | |
7289 | length = section->size; | |
7290 | curr = section->start; | |
e4b7104b | 7291 | |
39f381cb NC |
7292 | printf (_(" Length: %#lx\n"), (unsigned long) length); |
7293 | printf (_(" Index Offset [String]\n")); | |
7294 | } | |
7295 | else | |
7296 | { | |
7297 | int version; | |
7298 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); | |
7299 | if (version != 5) | |
7300 | warn (_("Unexpected version number in str_offset header: %#x\n"), version); | |
7301 | ||
7302 | int padding; | |
7303 | SAFE_BYTE_GET_AND_INC (padding, curr, 2, end); | |
7304 | if (padding != 0) | |
7305 | warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding); | |
7306 | ||
7307 | printf (_(" Length: %#lx\n"), (unsigned long) length); | |
7308 | printf (_(" Version: %#lx\n"), (unsigned long) version); | |
7309 | printf (_(" Index Offset [String]\n")); | |
7310 | } | |
e4b7104b | 7311 | |
9f27c364 | 7312 | for (idx = 0; length >= entry_length && curr < end; idx++) |
e4b7104b NC |
7313 | { |
7314 | dwarf_vma offset; | |
7315 | const unsigned char * string; | |
7316 | ||
7317 | SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, end); | |
39f381cb NC |
7318 | if (dwo) |
7319 | string = (const unsigned char *) | |
9f27c364 | 7320 | fetch_indexed_string (idx, NULL, entry_length, dwo); |
39f381cb NC |
7321 | else |
7322 | string = fetch_indirect_string (offset); | |
7323 | ||
9f27c364 | 7324 | printf (" %8lu %8s %s\n", idx, dwarf_vmatoa ("x", offset), |
e4b7104b NC |
7325 | string); |
7326 | } | |
7327 | } | |
39f381cb | 7328 | |
4723351a CC |
7329 | return 1; |
7330 | } | |
7331 | ||
01a8f077 JK |
7332 | /* Each debug_information[x].range_lists[y] gets this representation for |
7333 | sorting purposes. */ | |
7334 | ||
7335 | struct range_entry | |
467c65bc NC |
7336 | { |
7337 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 7338 | dwarf_vma ranges_offset; |
01a8f077 | 7339 | |
467c65bc NC |
7340 | /* Original debug_information to find parameters of the data. */ |
7341 | debug_info *debug_info_p; | |
7342 | }; | |
01a8f077 JK |
7343 | |
7344 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
7345 | ||
7346 | static int | |
7347 | range_entry_compar (const void *ap, const void *bp) | |
7348 | { | |
3f5e193b NC |
7349 | const struct range_entry *a_re = (const struct range_entry *) ap; |
7350 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
7351 | const dwarf_vma a = a_re->ranges_offset; |
7352 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
7353 | |
7354 | return (a > b) - (b > a); | |
7355 | } | |
7356 | ||
77145576 JK |
7357 | static void |
7358 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
7359 | unsigned int pointer_size, unsigned long offset, | |
7360 | unsigned long base_address) | |
7361 | { | |
7362 | while (start < finish) | |
7363 | { | |
7364 | dwarf_vma begin; | |
7365 | dwarf_vma end; | |
7366 | ||
7367 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7368 | if (start >= finish) | |
7369 | break; | |
7370 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7371 | ||
d11ae95e | 7372 | |
77145576 JK |
7373 | printf (" %8.8lx ", offset); |
7374 | ||
7375 | if (begin == 0 && end == 0) | |
7376 | { | |
7377 | printf (_("<End of list>\n")); | |
7378 | break; | |
7379 | } | |
7380 | ||
7381 | /* Check base address specifiers. */ | |
7382 | if (is_max_address (begin, pointer_size) | |
7383 | && !is_max_address (end, pointer_size)) | |
7384 | { | |
7385 | base_address = end; | |
7386 | print_dwarf_vma (begin, pointer_size); | |
7387 | print_dwarf_vma (end, pointer_size); | |
7388 | printf ("(base address)\n"); | |
7389 | continue; | |
7390 | } | |
7391 | ||
7392 | print_dwarf_vma (begin + base_address, pointer_size); | |
7393 | print_dwarf_vma (end + base_address, pointer_size); | |
7394 | ||
7395 | if (begin == end) | |
7396 | fputs (_("(start == end)"), stdout); | |
7397 | else if (begin > end) | |
7398 | fputs (_("(start > end)"), stdout); | |
7399 | ||
7400 | putchar ('\n'); | |
7401 | } | |
7402 | } | |
7403 | ||
7404 | static void | |
7405 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
7406 | unsigned int pointer_size, unsigned long offset, | |
7407 | unsigned long base_address) | |
7408 | { | |
7409 | unsigned char *next = start; | |
7410 | ||
7411 | while (1) | |
7412 | { | |
7413 | unsigned long off = offset + (start - next); | |
7414 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
7415 | /* Initialize it due to a false compiler warning. */ |
7416 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
7417 | |
7418 | if (start + 1 > finish) | |
7419 | { | |
7420 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
7421 | offset); | |
7422 | break; | |
7423 | } | |
7424 | ||
7425 | printf (" %8.8lx ", off); | |
7426 | ||
7427 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
7428 | ||
7429 | switch (rlet) | |
7430 | { | |
7431 | case DW_RLE_end_of_list: | |
7432 | printf (_("<End of list>\n")); | |
7433 | break; | |
7434 | case DW_RLE_base_address: | |
7435 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
7436 | print_dwarf_vma (base_address, pointer_size); | |
7437 | printf (_("(base address)\n")); | |
7438 | break; | |
7439 | case DW_RLE_start_length: | |
7440 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
cd30bcef | 7441 | READ_ULEB (length, start, finish); |
77145576 JK |
7442 | end = begin + length; |
7443 | break; | |
7444 | case DW_RLE_offset_pair: | |
cd30bcef AM |
7445 | READ_ULEB (begin, start, finish); |
7446 | READ_ULEB (end, start, finish); | |
77145576 JK |
7447 | break; |
7448 | case DW_RLE_start_end: | |
7449 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7450 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7451 | break; | |
7452 | default: | |
7453 | error (_("Invalid range list entry type %d\n"), rlet); | |
7454 | rlet = DW_RLE_end_of_list; | |
7455 | break; | |
7456 | } | |
7457 | if (rlet == DW_RLE_end_of_list) | |
7458 | break; | |
7459 | if (rlet == DW_RLE_base_address) | |
7460 | continue; | |
7461 | ||
7462 | print_dwarf_vma (begin + base_address, pointer_size); | |
7463 | print_dwarf_vma (end + base_address, pointer_size); | |
7464 | ||
7465 | if (begin == end) | |
7466 | fputs (_("(start == end)"), stdout); | |
7467 | else if (begin > end) | |
7468 | fputs (_("(start > end)"), stdout); | |
7469 | ||
7470 | putchar ('\n'); | |
7471 | } | |
7472 | } | |
7473 | ||
19e6b90e L |
7474 | static int |
7475 | display_debug_ranges (struct dwarf_section *section, | |
7476 | void *file ATTRIBUTE_UNUSED) | |
7477 | { | |
7478 | unsigned char *start = section->start; | |
a2ff7a4b | 7479 | unsigned char *last_start = start; |
f6f0e17b | 7480 | unsigned long bytes = section->size; |
19e6b90e | 7481 | unsigned char *section_begin = start; |
f6f0e17b | 7482 | unsigned char *finish = start + bytes; |
01a8f077 JK |
7483 | unsigned int num_range_list, i; |
7484 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
7485 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
7486 | /* Initialize it due to a false compiler warning. */ | |
7487 | unsigned char address_size = 0; | |
cb4c35cf | 7488 | dwarf_vma last_offset = 0; |
19e6b90e | 7489 | |
19e6b90e L |
7490 | if (bytes == 0) |
7491 | { | |
7492 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7493 | return 0; | |
7494 | } | |
7495 | ||
77145576 JK |
7496 | if (is_rnglists) |
7497 | { | |
7498 | dwarf_vma initial_length; | |
7499 | unsigned int initial_length_size; | |
7500 | unsigned char segment_selector_size; | |
7501 | unsigned int offset_size, offset_entry_count; | |
7502 | unsigned short version; | |
7503 | ||
7504 | /* Get and check the length of the block. */ | |
7505 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
7506 | ||
7507 | if (initial_length == 0xffffffff) | |
7508 | { | |
7509 | /* This section is 64-bit DWARF 3. */ | |
7510 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
7511 | offset_size = 8; | |
7512 | initial_length_size = 12; | |
7513 | } | |
7514 | else | |
7515 | { | |
7516 | offset_size = 4; | |
7517 | initial_length_size = 4; | |
7518 | } | |
7519 | ||
7520 | if (initial_length + initial_length_size > section->size) | |
7521 | { | |
7522 | /* If the length field has a relocation against it, then we should | |
7523 | not complain if it is inaccurate (and probably negative). | |
7524 | It is copied from .debug_line handling code. */ | |
7525 | if (reloc_at (section, (start - section->start) - offset_size)) | |
7526 | { | |
7527 | initial_length = (finish - start) - initial_length_size; | |
7528 | } | |
7529 | else | |
7530 | { | |
7531 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
7532 | (long) initial_length); | |
7533 | return 0; | |
7534 | } | |
7535 | } | |
7536 | ||
7537 | /* Get and check the version number. */ | |
7538 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
7539 | ||
7540 | if (version != 5) | |
7541 | { | |
7542 | warn (_("Only DWARF version 5 debug_rnglists info " | |
7543 | "is currently supported.\n")); | |
7544 | return 0; | |
7545 | } | |
7546 | ||
7547 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
7548 | ||
7549 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
7550 | if (segment_selector_size != 0) | |
7551 | { | |
7552 | warn (_("The %s section contains " | |
7553 | "unsupported segment selector size: %d.\n"), | |
7554 | section->name, segment_selector_size); | |
7555 | return 0; | |
7556 | } | |
7557 | ||
7558 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
7559 | if (offset_entry_count != 0) | |
7560 | { | |
7561 | warn (_("The %s section contains " | |
7562 | "unsupported offset entry count: %u.\n"), | |
7563 | section->name, offset_entry_count); | |
7564 | return 0; | |
7565 | } | |
7566 | } | |
7567 | ||
1febe64d NC |
7568 | if (load_debug_info (file) == 0) |
7569 | { | |
7570 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7571 | section->name); | |
7572 | return 0; | |
7573 | } | |
19e6b90e | 7574 | |
01a8f077 | 7575 | num_range_list = 0; |
19e6b90e | 7576 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 7577 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 7578 | |
01a8f077 | 7579 | if (num_range_list == 0) |
4723351a CC |
7580 | { |
7581 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 7582 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
7583 | printf (_("No range lists in .debug_info section.\n")); |
7584 | return 1; | |
7585 | } | |
19e6b90e | 7586 | |
3f5e193b NC |
7587 | range_entries = (struct range_entry *) |
7588 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 7589 | range_entry_fill = range_entries; |
19e6b90e | 7590 | |
01a8f077 JK |
7591 | for (i = 0; i < num_debug_info_entries; i++) |
7592 | { | |
7593 | debug_info *debug_info_p = &debug_information[i]; | |
7594 | unsigned int j; | |
7595 | ||
7596 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
7597 | { | |
7598 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
7599 | range_entry_fill->debug_info_p = debug_info_p; | |
7600 | range_entry_fill++; | |
19e6b90e L |
7601 | } |
7602 | } | |
7603 | ||
01a8f077 JK |
7604 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
7605 | range_entry_compar); | |
19e6b90e | 7606 | |
d493b283 | 7607 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 7608 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 7609 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 7610 | |
dda8d76d NC |
7611 | introduce (section, FALSE); |
7612 | ||
19e6b90e L |
7613 | printf (_(" Offset Begin End\n")); |
7614 | ||
01a8f077 | 7615 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 7616 | { |
01a8f077 JK |
7617 | struct range_entry *range_entry = &range_entries[i]; |
7618 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 7619 | unsigned int pointer_size; |
359ca075 | 7620 | dwarf_vma offset; |
01a8f077 | 7621 | unsigned char *next; |
359ca075 | 7622 | dwarf_vma base_address; |
19e6b90e | 7623 | |
77145576 | 7624 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 7625 | offset = range_entry->ranges_offset; |
01a8f077 JK |
7626 | next = section_begin + offset; |
7627 | base_address = debug_info_p->base_address; | |
cecf136e | 7628 | |
f41e4712 NC |
7629 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
7630 | if (pointer_size < 2 || pointer_size > 8) | |
7631 | { | |
7632 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 7633 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
7634 | continue; |
7635 | } | |
b4eb7656 | 7636 | |
d11ae95e NC |
7637 | if (next < section_begin || next >= finish) |
7638 | { | |
7639 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
7640 | (unsigned long) offset, i); | |
7641 | continue; | |
7642 | } | |
7643 | ||
cb4c35cf AB |
7644 | /* If multiple DWARF entities reference the same range then we will |
7645 | have multiple entries in the `range_entries' list for the same | |
7646 | offset. Thanks to the sort above these will all be consecutive in | |
7647 | the `range_entries' list, so we can easily ignore duplicates | |
7648 | here. */ | |
7649 | if (i > 0 && last_offset == offset) | |
7650 | continue; | |
7651 | last_offset = offset; | |
7652 | ||
4723351a | 7653 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 7654 | { |
01a8f077 JK |
7655 | if (start < next) |
7656 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
7657 | (unsigned long) (start - section_begin), | |
7658 | (unsigned long) (next - section_begin), section->name); | |
7659 | else if (start > next) | |
a2ff7a4b AM |
7660 | { |
7661 | if (next == last_start) | |
7662 | continue; | |
7663 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
7664 | (unsigned long) (start - section_begin), | |
7665 | (unsigned long) (next - section_begin), section->name); | |
7666 | } | |
01a8f077 | 7667 | } |
d11ae95e | 7668 | |
01a8f077 | 7669 | start = next; |
a2ff7a4b | 7670 | last_start = next; |
19e6b90e | 7671 | |
77145576 JK |
7672 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
7673 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
7674 | } |
7675 | putchar ('\n'); | |
01a8f077 JK |
7676 | |
7677 | free (range_entries); | |
7678 | ||
19e6b90e L |
7679 | return 1; |
7680 | } | |
7681 | ||
7682 | typedef struct Frame_Chunk | |
7683 | { | |
7684 | struct Frame_Chunk *next; | |
7685 | unsigned char *chunk_start; | |
a1165289 | 7686 | unsigned int ncols; |
19e6b90e L |
7687 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
7688 | short int *col_type; | |
7689 | int *col_offset; | |
7690 | char *augmentation; | |
7691 | unsigned int code_factor; | |
7692 | int data_factor; | |
bf5117e3 NC |
7693 | dwarf_vma pc_begin; |
7694 | dwarf_vma pc_range; | |
32ef3000 | 7695 | unsigned int cfa_reg; |
c8071705 | 7696 | dwarf_vma cfa_offset; |
a1165289 | 7697 | unsigned int ra; |
19e6b90e L |
7698 | unsigned char fde_encoding; |
7699 | unsigned char cfa_exp; | |
604282a7 JJ |
7700 | unsigned char ptr_size; |
7701 | unsigned char segment_size; | |
19e6b90e L |
7702 | } |
7703 | Frame_Chunk; | |
7704 | ||
1296bc99 AB |
7705 | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); |
7706 | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; | |
665ce1f6 L |
7707 | static const char *const *dwarf_regnames; |
7708 | static unsigned int dwarf_regnames_count; | |
7709 | ||
1296bc99 | 7710 | |
19e6b90e L |
7711 | /* A marker for a col_type that means this column was never referenced |
7712 | in the frame info. */ | |
7713 | #define DW_CFA_unreferenced (-1) | |
7714 | ||
a1165289 | 7715 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
7716 | -1 for invalid reg. */ |
7717 | ||
7718 | static int | |
7719 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 7720 | { |
a1165289 | 7721 | unsigned int prev = fc->ncols; |
19e6b90e | 7722 | |
665ce1f6 L |
7723 | if (reg < (unsigned int) fc->ncols) |
7724 | return 0; | |
7725 | ||
d9acf707 | 7726 | if (dwarf_regnames_count > 0 |
665ce1f6 L |
7727 | && reg > dwarf_regnames_count) |
7728 | return -1; | |
19e6b90e L |
7729 | |
7730 | fc->ncols = reg + 1; | |
a1165289 NC |
7731 | /* PR 17512: file: 10450-2643-0.004. |
7732 | If reg == -1 then this can happen... */ | |
7733 | if (fc->ncols == 0) | |
7734 | return -1; | |
7735 | ||
06614111 | 7736 | /* PR 17512: file: 2844a11d. */ |
d9acf707 | 7737 | if (fc->ncols > 1024 && dwarf_regnames_count == 0) |
06614111 NC |
7738 | { |
7739 | error (_("Unfeasibly large register number: %u\n"), reg); | |
7740 | fc->ncols = 0; | |
7741 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
7742 | we ever encounter a valid binary that exceeds it. */ | |
7743 | return -1; | |
7744 | } | |
7745 | ||
3f5e193b | 7746 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 7747 | sizeof (short int)); |
3f5e193b | 7748 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 7749 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
7750 | if (fc->col_type == NULL || fc->col_offset == NULL) |
7751 | { | |
7752 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
7753 | fc->ncols); | |
7754 | fc->ncols = 0; | |
7755 | return -1; | |
7756 | } | |
19e6b90e L |
7757 | |
7758 | while (prev < fc->ncols) | |
7759 | { | |
7760 | fc->col_type[prev] = DW_CFA_unreferenced; | |
7761 | fc->col_offset[prev] = 0; | |
7762 | prev++; | |
7763 | } | |
665ce1f6 | 7764 | return 1; |
19e6b90e L |
7765 | } |
7766 | ||
2dc4cec1 L |
7767 | static const char *const dwarf_regnames_i386[] = |
7768 | { | |
43234a1e L |
7769 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
7770 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7771 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7772 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
7773 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
7774 | NULL, NULL, /* 19 - 20 */ | |
7775 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
7776 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
7777 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
7778 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
7779 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
7780 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7781 | "tr", "ldtr", /* 48 - 49 */ | |
7782 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7783 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7784 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7785 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7786 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7787 | NULL, NULL, NULL, /* 90 - 92 */ | |
7788 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
7789 | }; |
7790 | ||
3d875af5 L |
7791 | static const char *const dwarf_regnames_iamcu[] = |
7792 | { | |
7793 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
7794 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7795 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7796 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
7797 | NULL, NULL, /* 19 - 20 */ | |
7798 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
7799 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
7800 | NULL, NULL, NULL, /* 37 - 39 */ | |
7801 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7802 | "tr", "ldtr", /* 48 - 49 */ | |
7803 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7804 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7805 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7806 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7807 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7808 | NULL, NULL, NULL, /* 90 - 92 */ | |
7809 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
7810 | }; | |
7811 | ||
99f6fdd9 | 7812 | static void |
b129eb0e RH |
7813 | init_dwarf_regnames_i386 (void) |
7814 | { | |
7815 | dwarf_regnames = dwarf_regnames_i386; | |
7816 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
1296bc99 | 7817 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
7818 | } |
7819 | ||
99f6fdd9 | 7820 | static void |
3d875af5 L |
7821 | init_dwarf_regnames_iamcu (void) |
7822 | { | |
7823 | dwarf_regnames = dwarf_regnames_iamcu; | |
7824 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
1296bc99 | 7825 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
3d875af5 L |
7826 | } |
7827 | ||
2dc4cec1 L |
7828 | static const char *const dwarf_regnames_x86_64[] = |
7829 | { | |
7830 | "rax", "rdx", "rcx", "rbx", | |
7831 | "rsi", "rdi", "rbp", "rsp", | |
7832 | "r8", "r9", "r10", "r11", | |
7833 | "r12", "r13", "r14", "r15", | |
7834 | "rip", | |
7835 | "xmm0", "xmm1", "xmm2", "xmm3", | |
7836 | "xmm4", "xmm5", "xmm6", "xmm7", | |
7837 | "xmm8", "xmm9", "xmm10", "xmm11", | |
7838 | "xmm12", "xmm13", "xmm14", "xmm15", | |
7839 | "st0", "st1", "st2", "st3", | |
7840 | "st4", "st5", "st6", "st7", | |
7841 | "mm0", "mm1", "mm2", "mm3", | |
7842 | "mm4", "mm5", "mm6", "mm7", | |
7843 | "rflags", | |
7844 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
7845 | "fs.base", "gs.base", NULL, NULL, | |
7846 | "tr", "ldtr", | |
43234a1e L |
7847 | "mxcsr", "fcw", "fsw", |
7848 | "xmm16", "xmm17", "xmm18", "xmm19", | |
7849 | "xmm20", "xmm21", "xmm22", "xmm23", | |
7850 | "xmm24", "xmm25", "xmm26", "xmm27", | |
7851 | "xmm28", "xmm29", "xmm30", "xmm31", | |
7852 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
7853 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
7854 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
7855 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
7856 | NULL, NULL, NULL, /* 115 - 117 */ | |
7857 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
7858 | }; |
7859 | ||
99f6fdd9 | 7860 | static void |
b129eb0e RH |
7861 | init_dwarf_regnames_x86_64 (void) |
7862 | { | |
7863 | dwarf_regnames = dwarf_regnames_x86_64; | |
7864 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
1296bc99 | 7865 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
7866 | } |
7867 | ||
4ee22035 RH |
7868 | static const char *const dwarf_regnames_aarch64[] = |
7869 | { | |
b4eb7656 AM |
7870 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
7871 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
7872 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
7873 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
7874 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
fab7c86e TC |
7875 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
7876 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", | |
7877 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", | |
b4eb7656 AM |
7878 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
7879 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
7880 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
7881 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
fab7c86e TC |
7882 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
7883 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", | |
7884 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", | |
7885 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", | |
4ee22035 RH |
7886 | }; |
7887 | ||
99f6fdd9 | 7888 | static void |
4ee22035 RH |
7889 | init_dwarf_regnames_aarch64 (void) |
7890 | { | |
7891 | dwarf_regnames = dwarf_regnames_aarch64; | |
7892 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
1296bc99 | 7893 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
4ee22035 RH |
7894 | } |
7895 | ||
d6bb17b0 AA |
7896 | static const char *const dwarf_regnames_s390[] = |
7897 | { | |
7898 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
7899 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7900 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7901 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
7902 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
7903 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
7904 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
7905 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
7906 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
7907 | "pswm", "pswa", | |
7908 | NULL, NULL, | |
7909 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
7910 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
7911 | }; | |
7912 | ||
99f6fdd9 | 7913 | static void |
d6bb17b0 AA |
7914 | init_dwarf_regnames_s390 (void) |
7915 | { | |
7916 | dwarf_regnames = dwarf_regnames_s390; | |
7917 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
1296bc99 | 7918 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
d6bb17b0 AA |
7919 | } |
7920 | ||
5bb0830d AB |
7921 | static const char *const dwarf_regnames_riscv[] = |
7922 | { | |
7923 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
7924 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
7925 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
7926 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
7927 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
7928 | "fs0", "fs1", /* 40 - 41 */ | |
7929 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
7930 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
7931 | "fs10", "fs11", /* 58 - 59 */ | |
7932 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
7933 | }; | |
7934 | ||
4762fe62 AB |
7935 | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles |
7936 | the large number of CSRs. */ | |
7937 | ||
7938 | static const char * | |
7939 | regname_internal_riscv (unsigned int regno) | |
7940 | { | |
7941 | const char *name = NULL; | |
7942 | ||
7943 | /* Lookup in the table first, this covers GPR and FPR. */ | |
7944 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) | |
7945 | name = dwarf_regnames_riscv [regno]; | |
7946 | else if (regno >= 4096 && regno <= 8191) | |
7947 | { | |
7948 | /* This might be a CSR, these live in a sparse number space from 4096 | |
7949 | to 8191 These numbers are defined in the RISC-V ELF ABI | |
7950 | document. */ | |
7951 | switch (regno) | |
7952 | { | |
8f595e9b NC |
7953 | #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \ |
7954 | case VALUE + 4096: name = #NAME; break; | |
4762fe62 AB |
7955 | #include "opcode/riscv-opc.h" |
7956 | #undef DECLARE_CSR | |
7957 | ||
7958 | default: | |
7959 | { | |
7960 | static char csr_name[10]; | |
7961 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); | |
7962 | name = csr_name; | |
7963 | } | |
7964 | break; | |
7965 | } | |
7966 | } | |
7967 | ||
7968 | return name; | |
7969 | } | |
7970 | ||
99f6fdd9 | 7971 | static void |
5bb0830d AB |
7972 | init_dwarf_regnames_riscv (void) |
7973 | { | |
4762fe62 AB |
7974 | dwarf_regnames = NULL; |
7975 | dwarf_regnames_count = 8192; | |
7976 | dwarf_regnames_lookup_func = regname_internal_riscv; | |
5bb0830d AB |
7977 | } |
7978 | ||
2dc4cec1 | 7979 | void |
955ff7fc | 7980 | init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) |
2dc4cec1 | 7981 | { |
1296bc99 AB |
7982 | dwarf_regnames_lookup_func = NULL; |
7983 | ||
2dc4cec1 L |
7984 | switch (e_machine) |
7985 | { | |
7986 | case EM_386: | |
b129eb0e | 7987 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
7988 | break; |
7989 | ||
3d875af5 L |
7990 | case EM_IAMCU: |
7991 | init_dwarf_regnames_iamcu (); | |
7992 | break; | |
7993 | ||
2dc4cec1 | 7994 | case EM_X86_64: |
7f502d6c | 7995 | case EM_L1OM: |
7a9068fe | 7996 | case EM_K1OM: |
b129eb0e | 7997 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
7998 | break; |
7999 | ||
4ee22035 RH |
8000 | case EM_AARCH64: |
8001 | init_dwarf_regnames_aarch64 (); | |
8002 | break; | |
8003 | ||
d6bb17b0 AA |
8004 | case EM_S390: |
8005 | init_dwarf_regnames_s390 (); | |
8006 | break; | |
8007 | ||
5bb0830d AB |
8008 | case EM_RISCV: |
8009 | init_dwarf_regnames_riscv (); | |
8010 | break; | |
8011 | ||
2dc4cec1 L |
8012 | default: |
8013 | break; | |
8014 | } | |
8015 | } | |
8016 | ||
229a22cf AB |
8017 | /* Initialize the DWARF register name lookup state based on the |
8018 | architecture and specific machine type of a BFD. */ | |
8019 | ||
8020 | void | |
8021 | init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, | |
8022 | unsigned long mach) | |
8023 | { | |
1296bc99 AB |
8024 | dwarf_regnames_lookup_func = NULL; |
8025 | ||
229a22cf AB |
8026 | switch (arch) |
8027 | { | |
8028 | case bfd_arch_i386: | |
8029 | switch (mach) | |
8030 | { | |
8031 | case bfd_mach_x86_64: | |
8032 | case bfd_mach_x86_64_intel_syntax: | |
229a22cf AB |
8033 | case bfd_mach_x64_32: |
8034 | case bfd_mach_x64_32_intel_syntax: | |
229a22cf AB |
8035 | init_dwarf_regnames_x86_64 (); |
8036 | break; | |
8037 | ||
8038 | default: | |
8039 | init_dwarf_regnames_i386 (); | |
8040 | break; | |
8041 | } | |
8042 | break; | |
8043 | ||
8044 | case bfd_arch_iamcu: | |
8045 | init_dwarf_regnames_iamcu (); | |
8046 | break; | |
8047 | ||
8048 | case bfd_arch_aarch64: | |
8049 | init_dwarf_regnames_aarch64(); | |
8050 | break; | |
8051 | ||
8052 | case bfd_arch_s390: | |
8053 | init_dwarf_regnames_s390 (); | |
8054 | break; | |
8055 | ||
8056 | case bfd_arch_riscv: | |
8057 | init_dwarf_regnames_riscv (); | |
8058 | break; | |
8059 | ||
8060 | default: | |
8061 | break; | |
8062 | } | |
8063 | } | |
8064 | ||
2dc4cec1 | 8065 | static const char * |
1296bc99 | 8066 | regname_internal_by_table_only (unsigned int regno) |
2dc4cec1 | 8067 | { |
1296bc99 | 8068 | if (dwarf_regnames != NULL |
2dc4cec1 L |
8069 | && regno < dwarf_regnames_count |
8070 | && dwarf_regnames [regno] != NULL) | |
1296bc99 AB |
8071 | return dwarf_regnames [regno]; |
8072 | ||
8073 | return NULL; | |
8074 | } | |
8075 | ||
8076 | static const char * | |
8077 | regname (unsigned int regno, int name_only_p) | |
8078 | { | |
8079 | static char reg[64]; | |
8080 | ||
8081 | const char *name = NULL; | |
8082 | ||
8083 | if (dwarf_regnames_lookup_func != NULL) | |
8084 | name = dwarf_regnames_lookup_func (regno); | |
8085 | ||
8086 | if (name != NULL) | |
2dc4cec1 | 8087 | { |
1296bc99 AB |
8088 | if (name_only_p) |
8089 | return name; | |
8090 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); | |
2dc4cec1 L |
8091 | } |
8092 | else | |
8093 | snprintf (reg, sizeof (reg), "r%d", regno); | |
8094 | return reg; | |
8095 | } | |
8096 | ||
19e6b90e | 8097 | static void |
a1165289 | 8098 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 8099 | { |
a1165289 | 8100 | unsigned int r; |
19e6b90e L |
8101 | char tmp[100]; |
8102 | ||
d8024a91 | 8103 | if (*max_regs != fc->ncols) |
19e6b90e L |
8104 | *max_regs = fc->ncols; |
8105 | ||
8106 | if (*need_col_headers) | |
8107 | { | |
91d6fa6a | 8108 | static const char *sloc = " LOC"; |
2dc4cec1 | 8109 | |
19e6b90e L |
8110 | *need_col_headers = 0; |
8111 | ||
91d6fa6a | 8112 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
8113 | |
8114 | for (r = 0; r < *max_regs; r++) | |
8115 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
8116 | { | |
8117 | if (r == fc->ra) | |
50751e18 | 8118 | printf ("ra "); |
19e6b90e | 8119 | else |
2dc4cec1 | 8120 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
8121 | } |
8122 | ||
8123 | printf ("\n"); | |
8124 | } | |
8125 | ||
bf5117e3 | 8126 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
8127 | if (fc->cfa_exp) |
8128 | strcpy (tmp, "exp"); | |
8129 | else | |
c8071705 | 8130 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
8131 | printf ("%-8s ", tmp); |
8132 | ||
8133 | for (r = 0; r < fc->ncols; r++) | |
8134 | { | |
8135 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
8136 | { | |
8137 | switch (fc->col_type[r]) | |
8138 | { | |
8139 | case DW_CFA_undefined: | |
8140 | strcpy (tmp, "u"); | |
8141 | break; | |
8142 | case DW_CFA_same_value: | |
8143 | strcpy (tmp, "s"); | |
8144 | break; | |
8145 | case DW_CFA_offset: | |
8146 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
8147 | break; | |
12eae2d3 JJ |
8148 | case DW_CFA_val_offset: |
8149 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
8150 | break; | |
19e6b90e | 8151 | case DW_CFA_register: |
2dc4cec1 | 8152 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
8153 | break; |
8154 | case DW_CFA_expression: | |
8155 | strcpy (tmp, "exp"); | |
8156 | break; | |
12eae2d3 JJ |
8157 | case DW_CFA_val_expression: |
8158 | strcpy (tmp, "vexp"); | |
8159 | break; | |
19e6b90e L |
8160 | default: |
8161 | strcpy (tmp, "n/a"); | |
8162 | break; | |
8163 | } | |
2dc4cec1 | 8164 | printf ("%-5s ", tmp); |
19e6b90e L |
8165 | } |
8166 | } | |
8167 | printf ("\n"); | |
8168 | } | |
8169 | ||
49727e46 | 8170 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 8171 | |
49727e46 AM |
8172 | static unsigned char * |
8173 | read_cie (unsigned char *start, unsigned char *end, | |
8174 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 8175 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
8176 | { |
8177 | int version; | |
8178 | Frame_Chunk *fc; | |
49727e46 | 8179 | unsigned char *augmentation_data = NULL; |
bf59c5d5 | 8180 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 8181 | |
041830e0 | 8182 | * p_cie = NULL; |
f41e4712 NC |
8183 | /* PR 17512: file: 001-228113-0.004. */ |
8184 | if (start >= end) | |
8185 | return end; | |
8186 | ||
49727e46 AM |
8187 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
8188 | memset (fc, 0, sizeof (Frame_Chunk)); | |
8189 | ||
8190 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
8191 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
8192 | ||
8193 | version = *start++; | |
8194 | ||
8195 | fc->augmentation = (char *) start; | |
f41e4712 NC |
8196 | /* PR 17512: file: 001-228113-0.004. |
8197 | Skip past augmentation name, but avoid running off the end of the data. */ | |
8198 | while (start < end) | |
8199 | if (* start ++ == '\0') | |
8200 | break; | |
8201 | if (start == end) | |
8202 | { | |
8203 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 8204 | goto fail; |
f41e4712 | 8205 | } |
49727e46 AM |
8206 | |
8207 | if (strcmp (fc->augmentation, "eh") == 0) | |
8208 | start += eh_addr_size; | |
8209 | ||
8210 | if (version >= 4) | |
8211 | { | |
8212 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
8213 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
8214 | { | |
8215 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 8216 | goto fail; |
77ef8654 NC |
8217 | } |
8218 | ||
49727e46 | 8219 | GET (fc->segment_size, 1); |
77ef8654 NC |
8220 | /* PR 17512: file: e99d2804. */ |
8221 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
8222 | { | |
8223 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 8224 | goto fail; |
77ef8654 NC |
8225 | } |
8226 | ||
49727e46 AM |
8227 | eh_addr_size = fc->ptr_size; |
8228 | } | |
8229 | else | |
8230 | { | |
8231 | fc->ptr_size = eh_addr_size; | |
8232 | fc->segment_size = 0; | |
8233 | } | |
442a6ce8 | 8234 | |
cd30bcef AM |
8235 | READ_ULEB (fc->code_factor, start, end); |
8236 | READ_SLEB (fc->data_factor, start, end); | |
442a6ce8 | 8237 | |
49727e46 AM |
8238 | if (version == 1) |
8239 | { | |
8240 | GET (fc->ra, 1); | |
8241 | } | |
8242 | else | |
8243 | { | |
cd30bcef | 8244 | READ_ULEB (fc->ra, start, end); |
49727e46 AM |
8245 | } |
8246 | ||
8247 | if (fc->augmentation[0] == 'z') | |
8248 | { | |
cd30bcef | 8249 | READ_ULEB (augmentation_data_len, start, end); |
49727e46 | 8250 | augmentation_data = start; |
a1165289 | 8251 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 8252 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 8253 | { |
bf59c5d5 NC |
8254 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
8255 | dwarf_vmatoa ("x", augmentation_data_len), | |
8256 | (unsigned long) (end - start)); | |
442a6ce8 | 8257 | goto fail; |
a1165289 | 8258 | } |
9c0f3d3f | 8259 | start += augmentation_data_len; |
49727e46 AM |
8260 | } |
8261 | ||
8262 | if (augmentation_data_len) | |
8263 | { | |
058037d3 NC |
8264 | unsigned char *p; |
8265 | unsigned char *q; | |
8266 | unsigned char *qend; | |
b4eb7656 | 8267 | |
49727e46 AM |
8268 | p = (unsigned char *) fc->augmentation + 1; |
8269 | q = augmentation_data; | |
058037d3 NC |
8270 | qend = q + augmentation_data_len; |
8271 | ||
9c0f3d3f | 8272 | while (p < end && q < qend) |
49727e46 AM |
8273 | { |
8274 | if (*p == 'L') | |
8275 | q++; | |
8276 | else if (*p == 'P') | |
8277 | q += 1 + size_of_encoded_value (*q); | |
8278 | else if (*p == 'R') | |
8279 | fc->fde_encoding = *q++; | |
8280 | else if (*p == 'S') | |
8281 | ; | |
09038062 ST |
8282 | else if (*p == 'B') |
8283 | ; | |
49727e46 AM |
8284 | else |
8285 | break; | |
8286 | p++; | |
8287 | } | |
c361b9ac NC |
8288 | /* Note - it is OK if this loop terminates with q < qend. |
8289 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
8290 | } |
8291 | ||
8292 | *p_cie = fc; | |
8293 | if (p_version) | |
8294 | *p_version = version; | |
8295 | if (p_aug_len) | |
8296 | { | |
8297 | *p_aug_len = augmentation_data_len; | |
8298 | *p_aug = augmentation_data; | |
8299 | } | |
8300 | return start; | |
442a6ce8 NC |
8301 | |
8302 | fail: | |
8303 | free (fc->col_offset); | |
8304 | free (fc->col_type); | |
8305 | free (fc); | |
8306 | return end; | |
49727e46 AM |
8307 | } |
8308 | ||
d85bf2ba NC |
8309 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
8310 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
8311 | PRINTED contains the number of characters already written to the current | |
8312 | output line. */ | |
bf59c5d5 NC |
8313 | |
8314 | static void | |
d85bf2ba NC |
8315 | display_data (bfd_size_type printed, |
8316 | const unsigned char * data, | |
8317 | const bfd_size_type len) | |
bf59c5d5 | 8318 | { |
d85bf2ba NC |
8319 | if (do_wide || len < ((80 - printed) / 3)) |
8320 | for (printed = 0; printed < len; ++printed) | |
8321 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
8322 | else |
8323 | { | |
d85bf2ba | 8324 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 8325 | { |
d85bf2ba | 8326 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 8327 | putchar ('\n'); |
d85bf2ba | 8328 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
8329 | } |
8330 | } | |
d85bf2ba NC |
8331 | } |
8332 | ||
8333 | /* Prints out the contents on the augmentation data array. | |
8334 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
8335 | ||
8336 | static void | |
8337 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
8338 | { | |
8339 | bfd_size_type i; | |
8340 | ||
8341 | i = printf (_(" Augmentation data: ")); | |
8342 | display_data (i, data, len); | |
bf59c5d5 NC |
8343 | } |
8344 | ||
19e6b90e L |
8345 | static int |
8346 | display_debug_frames (struct dwarf_section *section, | |
8347 | void *file ATTRIBUTE_UNUSED) | |
8348 | { | |
8349 | unsigned char *start = section->start; | |
8350 | unsigned char *end = start + section->size; | |
8351 | unsigned char *section_start = start; | |
3391569f NC |
8352 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
8353 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 8354 | Frame_Chunk *rs; |
3391569f | 8355 | bfd_boolean is_eh = strcmp (section->name, ".eh_frame") == 0; |
a1165289 | 8356 | unsigned int max_regs = 0; |
665ce1f6 | 8357 | const char *bad_reg = _("bad register: "); |
77ef8654 | 8358 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 8359 | |
dda8d76d | 8360 | introduce (section, FALSE); |
19e6b90e L |
8361 | |
8362 | while (start < end) | |
8363 | { | |
8364 | unsigned char *saved_start; | |
8365 | unsigned char *block_end; | |
bf5117e3 NC |
8366 | dwarf_vma length; |
8367 | dwarf_vma cie_id; | |
19e6b90e L |
8368 | Frame_Chunk *fc; |
8369 | Frame_Chunk *cie; | |
8370 | int need_col_headers = 1; | |
8371 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 8372 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
8373 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
8374 | unsigned int offset_size; | |
8375 | unsigned int initial_length_size; | |
5b6312fd | 8376 | bfd_boolean all_nops; |
a788aedd | 8377 | static Frame_Chunk fde_fc; |
19e6b90e L |
8378 | |
8379 | saved_start = start; | |
19e6b90e | 8380 | |
0c588247 | 8381 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 8382 | |
19e6b90e L |
8383 | if (length == 0) |
8384 | { | |
8385 | printf ("\n%08lx ZERO terminator\n\n", | |
8386 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
8387 | /* Skip any zero terminators that directly follow. |
8388 | A corrupt section size could have loaded a whole | |
8389 | slew of zero filled memory bytes. eg | |
8390 | PR 17512: file: 070-19381-0.004. */ | |
8391 | while (start < end && * start == 0) | |
8392 | ++ start; | |
b758e50f | 8393 | continue; |
19e6b90e L |
8394 | } |
8395 | ||
8396 | if (length == 0xffffffff) | |
8397 | { | |
0c588247 | 8398 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
8399 | offset_size = 8; |
8400 | initial_length_size = 12; | |
8401 | } | |
8402 | else | |
8403 | { | |
8404 | offset_size = 4; | |
8405 | initial_length_size = 4; | |
8406 | } | |
8407 | ||
8408 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 8409 | if (block_end > end || block_end < start) |
53b8873b | 8410 | { |
bf5117e3 NC |
8411 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
8412 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
8413 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
8414 | block_end = end; |
8415 | } | |
0c588247 NC |
8416 | |
8417 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 8418 | |
846a11e4 NC |
8419 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
8420 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
8421 | { |
8422 | int version; | |
a1165289 | 8423 | unsigned int mreg; |
19e6b90e | 8424 | |
49727e46 AM |
8425 | start = read_cie (start, end, &cie, &version, |
8426 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
8427 | /* PR 17512: file: 027-135133-0.005. */ |
8428 | if (cie == NULL) | |
8429 | break; | |
a1165289 | 8430 | |
49727e46 | 8431 | fc = cie; |
19e6b90e L |
8432 | fc->next = chunks; |
8433 | chunks = fc; | |
8434 | fc->chunk_start = saved_start; | |
a1165289 | 8435 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8436 | if (mreg < fc->ra) |
8437 | mreg = fc->ra; | |
06614111 NC |
8438 | if (frame_need_space (fc, mreg) < 0) |
8439 | break; | |
49727e46 AM |
8440 | if (fc->fde_encoding) |
8441 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 8442 | |
bf5117e3 NC |
8443 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
8444 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 8445 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 8446 | |
19e6b90e | 8447 | if (do_debug_frames_interp) |
bf5117e3 NC |
8448 | { |
8449 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
8450 | fc->code_factor, fc->data_factor, fc->ra); | |
8451 | } | |
19e6b90e L |
8452 | else |
8453 | { | |
bf5117e3 | 8454 | printf ("CIE\n"); |
19e6b90e L |
8455 | printf (" Version: %d\n", version); |
8456 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
8457 | if (version >= 4) |
8458 | { | |
8459 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
8460 | printf (" Segment Size: %u\n", fc->segment_size); | |
8461 | } | |
19e6b90e L |
8462 | printf (" Code alignment factor: %u\n", fc->code_factor); |
8463 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
8464 | printf (" Return address column: %d\n", fc->ra); | |
8465 | ||
8466 | if (augmentation_data_len) | |
bf59c5d5 | 8467 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 8468 | |
19e6b90e L |
8469 | putchar ('\n'); |
8470 | } | |
19e6b90e L |
8471 | } |
8472 | else | |
8473 | { | |
8474 | unsigned char *look_for; | |
604282a7 | 8475 | unsigned long segment_selector; |
19e6b90e | 8476 | |
49727e46 AM |
8477 | if (is_eh) |
8478 | { | |
8479 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
8480 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
8481 | } | |
8482 | else | |
8483 | look_for = section_start + cie_id; | |
19e6b90e | 8484 | |
49727e46 AM |
8485 | if (look_for <= saved_start) |
8486 | { | |
8487 | for (cie = chunks; cie ; cie = cie->next) | |
8488 | if (cie->chunk_start == look_for) | |
8489 | break; | |
8490 | } | |
8491 | else | |
8492 | { | |
8493 | for (cie = forward_refs; cie ; cie = cie->next) | |
8494 | if (cie->chunk_start == look_for) | |
8495 | break; | |
8496 | if (!cie) | |
8497 | { | |
8498 | unsigned int off_size; | |
8499 | unsigned char *cie_scan; | |
19e6b90e | 8500 | |
49727e46 AM |
8501 | cie_scan = look_for; |
8502 | off_size = 4; | |
8503 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
8504 | if (length == 0xffffffff) | |
8505 | { | |
8506 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
8507 | off_size = 8; | |
8508 | } | |
8509 | if (length != 0) | |
8510 | { | |
8511 | dwarf_vma c_id; | |
8512 | ||
8513 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
8514 | if (is_eh | |
8515 | ? c_id == 0 | |
8516 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
8517 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
8518 | { | |
8519 | int version; | |
a1165289 | 8520 | unsigned int mreg; |
49727e46 AM |
8521 | |
8522 | read_cie (cie_scan, end, &cie, &version, | |
8523 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
8524 | /* PR 17512: file: 3450-2098-0.004. */ |
8525 | if (cie == NULL) | |
8526 | { | |
8527 | warn (_("Failed to read CIE information\n")); | |
8528 | break; | |
8529 | } | |
49727e46 AM |
8530 | cie->next = forward_refs; |
8531 | forward_refs = cie; | |
8532 | cie->chunk_start = look_for; | |
a1165289 | 8533 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8534 | if (mreg < cie->ra) |
8535 | mreg = cie->ra; | |
06614111 NC |
8536 | if (frame_need_space (cie, mreg) < 0) |
8537 | { | |
8538 | warn (_("Invalid max register\n")); | |
8539 | break; | |
8540 | } | |
49727e46 AM |
8541 | if (cie->fde_encoding) |
8542 | encoded_ptr_size | |
8543 | = size_of_encoded_value (cie->fde_encoding); | |
8544 | } | |
8545 | } | |
8546 | } | |
8547 | } | |
8548 | ||
8549 | fc = &fde_fc; | |
8550 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
8551 | |
8552 | if (!cie) | |
8553 | { | |
bf5117e3 NC |
8554 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
8555 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
8556 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 8557 | fc->ncols = 0; |
3f5e193b NC |
8558 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
8559 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
8560 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
8561 | { | |
8562 | warn (_("Invalid max register\n")); | |
8563 | break; | |
8564 | } | |
19e6b90e L |
8565 | cie = fc; |
8566 | fc->augmentation = ""; | |
8567 | fc->fde_encoding = 0; | |
604282a7 JJ |
8568 | fc->ptr_size = eh_addr_size; |
8569 | fc->segment_size = 0; | |
19e6b90e L |
8570 | } |
8571 | else | |
8572 | { | |
8573 | fc->ncols = cie->ncols; | |
3f5e193b NC |
8574 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
8575 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
8576 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
8577 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
8578 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
8579 | fc->ptr_size = cie->ptr_size; |
8580 | eh_addr_size = cie->ptr_size; | |
8581 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
8582 | fc->code_factor = cie->code_factor; |
8583 | fc->data_factor = cie->data_factor; | |
8584 | fc->cfa_reg = cie->cfa_reg; | |
8585 | fc->cfa_offset = cie->cfa_offset; | |
8586 | fc->ra = cie->ra; | |
06614111 NC |
8587 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
8588 | { | |
8589 | warn (_("Invalid max register\n")); | |
8590 | break; | |
8591 | } | |
19e6b90e L |
8592 | fc->fde_encoding = cie->fde_encoding; |
8593 | } | |
8594 | ||
8595 | if (fc->fde_encoding) | |
8596 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
8597 | ||
604282a7 JJ |
8598 | segment_selector = 0; |
8599 | if (fc->segment_size) | |
c8071705 NC |
8600 | { |
8601 | if (fc->segment_size > sizeof (segment_selector)) | |
8602 | { | |
8603 | /* PR 17512: file: 9e196b3e. */ | |
8604 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
8605 | fc->segment_size = 4; | |
8606 | } | |
8607 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
8608 | } | |
041830e0 NC |
8609 | |
8610 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 8611 | |
0c588247 NC |
8612 | /* FIXME: It appears that sometimes the final pc_range value is |
8613 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
8614 | run of the "objcopy on compressed debug sections" test for an | |
8615 | example of this. */ | |
8616 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 8617 | |
19e6b90e L |
8618 | if (cie->augmentation[0] == 'z') |
8619 | { | |
cd30bcef | 8620 | READ_ULEB (augmentation_data_len, start, end); |
19e6b90e | 8621 | augmentation_data = start; |
bf59c5d5 | 8622 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
d292364e | 8623 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
0a9d414a | 8624 | { |
d292364e AM |
8625 | warn (_("Augmentation data too long: 0x%s, " |
8626 | "expected at most %#lx\n"), | |
8627 | dwarf_vmatoa ("x", augmentation_data_len), | |
8628 | (unsigned long) (end - start)); | |
0a9d414a NC |
8629 | start = end; |
8630 | augmentation_data = NULL; | |
8631 | augmentation_data_len = 0; | |
8632 | } | |
d292364e | 8633 | start += augmentation_data_len; |
19e6b90e L |
8634 | } |
8635 | ||
bf5117e3 NC |
8636 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
8637 | (unsigned long)(saved_start - section_start), | |
8638 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 8639 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 8640 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 8641 | |
604282a7 JJ |
8642 | if (fc->segment_size) |
8643 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
8644 | |
8645 | printf ("%s..%s\n", | |
8646 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
8647 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
8648 | ||
19e6b90e L |
8649 | if (! do_debug_frames_interp && augmentation_data_len) |
8650 | { | |
bf59c5d5 | 8651 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
8652 | putchar ('\n'); |
8653 | } | |
8654 | } | |
8655 | ||
8656 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
8657 | we're about to interpret instructions for the chunk. */ | |
8658 | /* ??? At present we need to do this always, since this sizes the | |
8659 | fc->col_type and fc->col_offset arrays, which we write into always. | |
8660 | We should probably split the interpreted and non-interpreted bits | |
8661 | into two different routines, since there's so much that doesn't | |
8662 | really overlap between them. */ | |
8663 | if (1 || do_debug_frames_interp) | |
8664 | { | |
8665 | /* Start by making a pass over the chunk, allocating storage | |
8666 | and taking note of what registers are used. */ | |
8667 | unsigned char *tmp = start; | |
8668 | ||
8669 | while (start < block_end) | |
8670 | { | |
041830e0 NC |
8671 | unsigned int reg, op, opa; |
8672 | unsigned long temp; | |
5929c344 | 8673 | unsigned char * new_start; |
19e6b90e L |
8674 | |
8675 | op = *start++; | |
8676 | opa = op & 0x3f; | |
8677 | if (op & 0xc0) | |
8678 | op &= 0xc0; | |
8679 | ||
8680 | /* Warning: if you add any more cases to this switch, be | |
8681 | sure to add them to the corresponding switch below. */ | |
8682 | switch (op) | |
8683 | { | |
8684 | case DW_CFA_advance_loc: | |
8685 | break; | |
8686 | case DW_CFA_offset: | |
cd30bcef | 8687 | SKIP_ULEB (start, end); |
665ce1f6 L |
8688 | if (frame_need_space (fc, opa) >= 0) |
8689 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8690 | break; |
8691 | case DW_CFA_restore: | |
665ce1f6 L |
8692 | if (frame_need_space (fc, opa) >= 0) |
8693 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8694 | break; |
8695 | case DW_CFA_set_loc: | |
8696 | start += encoded_ptr_size; | |
8697 | break; | |
8698 | case DW_CFA_advance_loc1: | |
8699 | start += 1; | |
8700 | break; | |
8701 | case DW_CFA_advance_loc2: | |
8702 | start += 2; | |
8703 | break; | |
8704 | case DW_CFA_advance_loc4: | |
8705 | start += 4; | |
8706 | break; | |
8707 | case DW_CFA_offset_extended: | |
12eae2d3 | 8708 | case DW_CFA_val_offset: |
cd30bcef AM |
8709 | READ_ULEB (reg, start, end); |
8710 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8711 | if (frame_need_space (fc, reg) >= 0) |
8712 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8713 | break; |
8714 | case DW_CFA_restore_extended: | |
cd30bcef | 8715 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8716 | if (frame_need_space (fc, reg) >= 0) |
8717 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8718 | break; |
8719 | case DW_CFA_undefined: | |
cd30bcef | 8720 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8721 | if (frame_need_space (fc, reg) >= 0) |
8722 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8723 | break; |
8724 | case DW_CFA_same_value: | |
cd30bcef | 8725 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8726 | if (frame_need_space (fc, reg) >= 0) |
8727 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8728 | break; |
8729 | case DW_CFA_register: | |
cd30bcef AM |
8730 | READ_ULEB (reg, start, end); |
8731 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8732 | if (frame_need_space (fc, reg) >= 0) |
8733 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8734 | break; |
8735 | case DW_CFA_def_cfa: | |
cd30bcef AM |
8736 | SKIP_ULEB (start, end); |
8737 | SKIP_ULEB (start, end); | |
19e6b90e L |
8738 | break; |
8739 | case DW_CFA_def_cfa_register: | |
cd30bcef | 8740 | SKIP_ULEB (start, end); |
19e6b90e L |
8741 | break; |
8742 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 8743 | SKIP_ULEB (start, end); |
19e6b90e L |
8744 | break; |
8745 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 8746 | READ_ULEB (temp, start, end); |
5929c344 NC |
8747 | new_start = start + temp; |
8748 | if (new_start < start) | |
041830e0 NC |
8749 | { |
8750 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
8751 | start = block_end; | |
8752 | } | |
8753 | else | |
5929c344 | 8754 | start = new_start; |
19e6b90e L |
8755 | break; |
8756 | case DW_CFA_expression: | |
12eae2d3 | 8757 | case DW_CFA_val_expression: |
cd30bcef AM |
8758 | READ_ULEB (reg, start, end); |
8759 | READ_ULEB (temp, start, end); | |
5929c344 NC |
8760 | new_start = start + temp; |
8761 | if (new_start < start) | |
041830e0 | 8762 | { |
b4eb7656 | 8763 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
8764 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
8765 | start = block_end; | |
8766 | } | |
8767 | else | |
5929c344 | 8768 | start = new_start; |
665ce1f6 L |
8769 | if (frame_need_space (fc, reg) >= 0) |
8770 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8771 | break; |
8772 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 8773 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
8774 | READ_ULEB (reg, start, end); |
8775 | SKIP_SLEB (start, end); | |
665ce1f6 L |
8776 | if (frame_need_space (fc, reg) >= 0) |
8777 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8778 | break; |
8779 | case DW_CFA_def_cfa_sf: | |
cd30bcef AM |
8780 | SKIP_ULEB (start, end); |
8781 | SKIP_SLEB (start, end); | |
19e6b90e L |
8782 | break; |
8783 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 8784 | SKIP_SLEB (start, end); |
19e6b90e L |
8785 | break; |
8786 | case DW_CFA_MIPS_advance_loc8: | |
8787 | start += 8; | |
8788 | break; | |
8789 | case DW_CFA_GNU_args_size: | |
cd30bcef | 8790 | SKIP_ULEB (start, end); |
19e6b90e L |
8791 | break; |
8792 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
8793 | READ_ULEB (reg, start, end); |
8794 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8795 | if (frame_need_space (fc, reg) >= 0) |
8796 | fc->col_type[reg] = DW_CFA_undefined; | |
8797 | break; | |
19e6b90e L |
8798 | default: |
8799 | break; | |
8800 | } | |
8801 | } | |
8802 | start = tmp; | |
8803 | } | |
8804 | ||
5b6312fd NC |
8805 | all_nops = TRUE; |
8806 | ||
19e6b90e L |
8807 | /* Now we know what registers are used, make a second pass over |
8808 | the chunk, this time actually printing out the info. */ | |
8809 | ||
8810 | while (start < block_end) | |
8811 | { | |
362beea4 | 8812 | unsigned char * tmp; |
19e6b90e | 8813 | unsigned op, opa; |
7f2c8a1d NC |
8814 | unsigned long ul, roffs; |
8815 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
8816 | are various functions, notably frame_space_needed() that assume that | |
8817 | reg is an unsigned int. */ | |
8818 | unsigned int reg; | |
8819 | dwarf_signed_vma l; | |
bf5117e3 | 8820 | dwarf_vma ofs; |
19e6b90e | 8821 | dwarf_vma vma; |
665ce1f6 | 8822 | const char *reg_prefix = ""; |
19e6b90e L |
8823 | |
8824 | op = *start++; | |
8825 | opa = op & 0x3f; | |
8826 | if (op & 0xc0) | |
8827 | op &= 0xc0; | |
8828 | ||
5b6312fd NC |
8829 | /* Make a note if something other than DW_CFA_nop happens. */ |
8830 | if (op != DW_CFA_nop) | |
8831 | all_nops = FALSE; | |
8832 | ||
19e6b90e L |
8833 | /* Warning: if you add any more cases to this switch, be |
8834 | sure to add them to the corresponding switch above. */ | |
8835 | switch (op) | |
8836 | { | |
8837 | case DW_CFA_advance_loc: | |
8838 | if (do_debug_frames_interp) | |
8839 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8840 | else | |
bf5117e3 | 8841 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 8842 | opa * fc->code_factor, |
b4eb7656 | 8843 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
8844 | fc->pc_begin + opa * fc->code_factor, |
8845 | fc->ptr_size)); | |
19e6b90e L |
8846 | fc->pc_begin += opa * fc->code_factor; |
8847 | break; | |
8848 | ||
8849 | case DW_CFA_offset: | |
cd30bcef | 8850 | READ_ULEB (roffs, start, end); |
665ce1f6 L |
8851 | if (opa >= (unsigned int) fc->ncols) |
8852 | reg_prefix = bad_reg; | |
8853 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8854 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
8855 | reg_prefix, regname (opa, 0), | |
8856 | roffs * fc->data_factor); | |
8857 | if (*reg_prefix == '\0') | |
8858 | { | |
8859 | fc->col_type[opa] = DW_CFA_offset; | |
8860 | fc->col_offset[opa] = roffs * fc->data_factor; | |
8861 | } | |
19e6b90e L |
8862 | break; |
8863 | ||
8864 | case DW_CFA_restore: | |
50751e18 | 8865 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
8866 | reg_prefix = bad_reg; |
8867 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8868 | printf (" DW_CFA_restore: %s%s\n", | |
8869 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
8870 | if (*reg_prefix != '\0') |
8871 | break; | |
8872 | ||
8873 | if (opa >= (unsigned int) cie->ncols | |
8874 | || (do_debug_frames_interp | |
8875 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
8876 | { | |
8877 | fc->col_type[opa] = DW_CFA_undefined; | |
8878 | fc->col_offset[opa] = 0; | |
8879 | } | |
8880 | else | |
665ce1f6 L |
8881 | { |
8882 | fc->col_type[opa] = cie->col_type[opa]; | |
8883 | fc->col_offset[opa] = cie->col_offset[opa]; | |
8884 | } | |
19e6b90e L |
8885 | break; |
8886 | ||
8887 | case DW_CFA_set_loc: | |
6937bb54 | 8888 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
8889 | if (do_debug_frames_interp) |
8890 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8891 | else | |
bf5117e3 NC |
8892 | printf (" DW_CFA_set_loc: %s\n", |
8893 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
8894 | fc->pc_begin = vma; |
8895 | break; | |
8896 | ||
8897 | case DW_CFA_advance_loc1: | |
0c588247 | 8898 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
8899 | if (do_debug_frames_interp) |
8900 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8901 | else | |
bf5117e3 NC |
8902 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
8903 | (unsigned long) (ofs * fc->code_factor), | |
8904 | dwarf_vmatoa_1 (NULL, | |
8905 | fc->pc_begin + ofs * fc->code_factor, | |
8906 | fc->ptr_size)); | |
19e6b90e L |
8907 | fc->pc_begin += ofs * fc->code_factor; |
8908 | break; | |
8909 | ||
8910 | case DW_CFA_advance_loc2: | |
6937bb54 | 8911 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
8912 | if (do_debug_frames_interp) |
8913 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8914 | else | |
bf5117e3 NC |
8915 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
8916 | (unsigned long) (ofs * fc->code_factor), | |
8917 | dwarf_vmatoa_1 (NULL, | |
8918 | fc->pc_begin + ofs * fc->code_factor, | |
8919 | fc->ptr_size)); | |
19e6b90e L |
8920 | fc->pc_begin += ofs * fc->code_factor; |
8921 | break; | |
8922 | ||
8923 | case DW_CFA_advance_loc4: | |
6937bb54 | 8924 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
8925 | if (do_debug_frames_interp) |
8926 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8927 | else | |
bf5117e3 NC |
8928 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
8929 | (unsigned long) (ofs * fc->code_factor), | |
8930 | dwarf_vmatoa_1 (NULL, | |
8931 | fc->pc_begin + ofs * fc->code_factor, | |
8932 | fc->ptr_size)); | |
19e6b90e L |
8933 | fc->pc_begin += ofs * fc->code_factor; |
8934 | break; | |
8935 | ||
8936 | case DW_CFA_offset_extended: | |
cd30bcef AM |
8937 | READ_ULEB (reg, start, end); |
8938 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
8939 | if (reg >= (unsigned int) fc->ncols) |
8940 | reg_prefix = bad_reg; | |
8941 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8942 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
8943 | reg_prefix, regname (reg, 0), | |
8944 | roffs * fc->data_factor); | |
8945 | if (*reg_prefix == '\0') | |
8946 | { | |
8947 | fc->col_type[reg] = DW_CFA_offset; | |
8948 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8949 | } | |
19e6b90e L |
8950 | break; |
8951 | ||
12eae2d3 | 8952 | case DW_CFA_val_offset: |
cd30bcef AM |
8953 | READ_ULEB (reg, start, end); |
8954 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
8955 | if (reg >= (unsigned int) fc->ncols) |
8956 | reg_prefix = bad_reg; | |
8957 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8958 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
8959 | reg_prefix, regname (reg, 0), |
8960 | roffs * fc->data_factor); | |
8961 | if (*reg_prefix == '\0') | |
8962 | { | |
8963 | fc->col_type[reg] = DW_CFA_val_offset; | |
8964 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8965 | } | |
12eae2d3 JJ |
8966 | break; |
8967 | ||
19e6b90e | 8968 | case DW_CFA_restore_extended: |
cd30bcef | 8969 | READ_ULEB (reg, start, end); |
50751e18 | 8970 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
8971 | reg_prefix = bad_reg; |
8972 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8973 | printf (" DW_CFA_restore_extended: %s%s\n", | |
8974 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
8975 | if (*reg_prefix != '\0') |
8976 | break; | |
8977 | ||
8978 | if (reg >= (unsigned int) cie->ncols) | |
8979 | { | |
8980 | fc->col_type[reg] = DW_CFA_undefined; | |
8981 | fc->col_offset[reg] = 0; | |
8982 | } | |
8983 | else | |
665ce1f6 L |
8984 | { |
8985 | fc->col_type[reg] = cie->col_type[reg]; | |
8986 | fc->col_offset[reg] = cie->col_offset[reg]; | |
8987 | } | |
19e6b90e L |
8988 | break; |
8989 | ||
8990 | case DW_CFA_undefined: | |
cd30bcef | 8991 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8992 | if (reg >= (unsigned int) fc->ncols) |
8993 | reg_prefix = bad_reg; | |
8994 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8995 | printf (" DW_CFA_undefined: %s%s\n", | |
8996 | reg_prefix, regname (reg, 0)); | |
8997 | if (*reg_prefix == '\0') | |
8998 | { | |
8999 | fc->col_type[reg] = DW_CFA_undefined; | |
9000 | fc->col_offset[reg] = 0; | |
9001 | } | |
19e6b90e L |
9002 | break; |
9003 | ||
9004 | case DW_CFA_same_value: | |
cd30bcef | 9005 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9006 | if (reg >= (unsigned int) fc->ncols) |
9007 | reg_prefix = bad_reg; | |
9008 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9009 | printf (" DW_CFA_same_value: %s%s\n", | |
9010 | reg_prefix, regname (reg, 0)); | |
9011 | if (*reg_prefix == '\0') | |
9012 | { | |
9013 | fc->col_type[reg] = DW_CFA_same_value; | |
9014 | fc->col_offset[reg] = 0; | |
9015 | } | |
19e6b90e L |
9016 | break; |
9017 | ||
9018 | case DW_CFA_register: | |
cd30bcef AM |
9019 | READ_ULEB (reg, start, end); |
9020 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
9021 | if (reg >= (unsigned int) fc->ncols) |
9022 | reg_prefix = bad_reg; | |
9023 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 9024 | { |
665ce1f6 L |
9025 | printf (" DW_CFA_register: %s%s in ", |
9026 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
9027 | puts (regname (roffs, 0)); |
9028 | } | |
665ce1f6 L |
9029 | if (*reg_prefix == '\0') |
9030 | { | |
9031 | fc->col_type[reg] = DW_CFA_register; | |
9032 | fc->col_offset[reg] = roffs; | |
9033 | } | |
19e6b90e L |
9034 | break; |
9035 | ||
9036 | case DW_CFA_remember_state: | |
9037 | if (! do_debug_frames_interp) | |
9038 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 9039 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 9040 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
9041 | rs->cfa_reg = fc->cfa_reg; |
9042 | rs->ra = fc->ra; | |
9043 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 9044 | rs->ncols = fc->ncols; |
3f5e193b | 9045 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 9046 | sizeof (* rs->col_type)); |
d71ad7fc RC |
9047 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
9048 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
9049 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
9050 | rs->next = remembered_state; |
9051 | remembered_state = rs; | |
9052 | break; | |
9053 | ||
9054 | case DW_CFA_restore_state: | |
9055 | if (! do_debug_frames_interp) | |
9056 | printf (" DW_CFA_restore_state\n"); | |
9057 | rs = remembered_state; | |
9058 | if (rs) | |
9059 | { | |
9060 | remembered_state = rs->next; | |
d71ad7fc RC |
9061 | fc->cfa_offset = rs->cfa_offset; |
9062 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
9063 | fc->ra = rs->ra; |
9064 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
9065 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
9066 | { | |
1306a742 | 9067 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
9068 | fc->ncols = 0; |
9069 | break; | |
9070 | } | |
d71ad7fc | 9071 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 9072 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 9073 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
9074 | free (rs->col_type); |
9075 | free (rs->col_offset); | |
9076 | free (rs); | |
9077 | } | |
9078 | else if (do_debug_frames_interp) | |
9079 | printf ("Mismatched DW_CFA_restore_state\n"); | |
9080 | break; | |
9081 | ||
9082 | case DW_CFA_def_cfa: | |
cd30bcef AM |
9083 | READ_ULEB (fc->cfa_reg, start, end); |
9084 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
9085 | fc->cfa_exp = 0; |
9086 | if (! do_debug_frames_interp) | |
2dc4cec1 | 9087 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 9088 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
9089 | break; |
9090 | ||
9091 | case DW_CFA_def_cfa_register: | |
cd30bcef | 9092 | READ_ULEB (fc->cfa_reg, start, end); |
19e6b90e L |
9093 | fc->cfa_exp = 0; |
9094 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
9095 | printf (" DW_CFA_def_cfa_register: %s\n", |
9096 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
9097 | break; |
9098 | ||
9099 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 9100 | READ_ULEB (fc->cfa_offset, start, end); |
19e6b90e | 9101 | if (! do_debug_frames_interp) |
c8071705 | 9102 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
9103 | break; |
9104 | ||
9105 | case DW_CFA_nop: | |
9106 | if (! do_debug_frames_interp) | |
9107 | printf (" DW_CFA_nop\n"); | |
9108 | break; | |
9109 | ||
9110 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 9111 | READ_ULEB (ul, start, end); |
7460c0ab | 9112 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 9113 | { |
a1165289 | 9114 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
9115 | break; |
9116 | } | |
19e6b90e L |
9117 | if (! do_debug_frames_interp) |
9118 | { | |
9119 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
9120 | decode_location_expression (start, eh_addr_size, 0, -1, |
9121 | ul, 0, section); | |
19e6b90e L |
9122 | printf (")\n"); |
9123 | } | |
9124 | fc->cfa_exp = 1; | |
9125 | start += ul; | |
9126 | break; | |
9127 | ||
9128 | case DW_CFA_expression: | |
cd30bcef AM |
9129 | READ_ULEB (reg, start, end); |
9130 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
9131 | if (reg >= (unsigned int) fc->ncols) |
9132 | reg_prefix = bad_reg; | |
6937bb54 | 9133 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 9134 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
9135 | tmp = start + ul; |
9136 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 9137 | { |
a1165289 | 9138 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
9139 | break; |
9140 | } | |
665ce1f6 | 9141 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 9142 | { |
665ce1f6 L |
9143 | printf (" DW_CFA_expression: %s%s (", |
9144 | reg_prefix, regname (reg, 0)); | |
b7807392 | 9145 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 9146 | ul, 0, section); |
19e6b90e L |
9147 | printf (")\n"); |
9148 | } | |
665ce1f6 L |
9149 | if (*reg_prefix == '\0') |
9150 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 9151 | start = tmp; |
19e6b90e L |
9152 | break; |
9153 | ||
12eae2d3 | 9154 | case DW_CFA_val_expression: |
cd30bcef AM |
9155 | READ_ULEB (reg, start, end); |
9156 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
9157 | if (reg >= (unsigned int) fc->ncols) |
9158 | reg_prefix = bad_reg; | |
362beea4 NC |
9159 | tmp = start + ul; |
9160 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 9161 | { |
a1165289 | 9162 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
9163 | break; |
9164 | } | |
665ce1f6 | 9165 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 9166 | { |
665ce1f6 L |
9167 | printf (" DW_CFA_val_expression: %s%s (", |
9168 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
9169 | decode_location_expression (start, eh_addr_size, 0, -1, |
9170 | ul, 0, section); | |
12eae2d3 JJ |
9171 | printf (")\n"); |
9172 | } | |
665ce1f6 L |
9173 | if (*reg_prefix == '\0') |
9174 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 9175 | start = tmp; |
12eae2d3 JJ |
9176 | break; |
9177 | ||
19e6b90e | 9178 | case DW_CFA_offset_extended_sf: |
cd30bcef AM |
9179 | READ_ULEB (reg, start, end); |
9180 | READ_SLEB (l, start, end); | |
665ce1f6 L |
9181 | if (frame_need_space (fc, reg) < 0) |
9182 | reg_prefix = bad_reg; | |
9183 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9184 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
9185 | reg_prefix, regname (reg, 0), | |
c8071705 | 9186 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9187 | if (*reg_prefix == '\0') |
9188 | { | |
9189 | fc->col_type[reg] = DW_CFA_offset; | |
9190 | fc->col_offset[reg] = l * fc->data_factor; | |
9191 | } | |
19e6b90e L |
9192 | break; |
9193 | ||
12eae2d3 | 9194 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
9195 | READ_ULEB (reg, start, end); |
9196 | READ_SLEB (l, start, end); | |
665ce1f6 L |
9197 | if (frame_need_space (fc, reg) < 0) |
9198 | reg_prefix = bad_reg; | |
9199 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 9200 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 9201 | reg_prefix, regname (reg, 0), |
c8071705 | 9202 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9203 | if (*reg_prefix == '\0') |
9204 | { | |
9205 | fc->col_type[reg] = DW_CFA_val_offset; | |
9206 | fc->col_offset[reg] = l * fc->data_factor; | |
9207 | } | |
12eae2d3 JJ |
9208 | break; |
9209 | ||
19e6b90e | 9210 | case DW_CFA_def_cfa_sf: |
cd30bcef AM |
9211 | READ_ULEB (fc->cfa_reg, start, end); |
9212 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
9213 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
9214 | fc->cfa_exp = 0; | |
9215 | if (! do_debug_frames_interp) | |
2dc4cec1 | 9216 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 9217 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
9218 | break; |
9219 | ||
9220 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 9221 | READ_ULEB (fc->cfa_offset, start, end); |
c8071705 | 9222 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 9223 | if (! do_debug_frames_interp) |
c8071705 | 9224 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
9225 | break; |
9226 | ||
9227 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 9228 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
9229 | if (do_debug_frames_interp) |
9230 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9231 | else | |
bf5117e3 NC |
9232 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
9233 | (unsigned long) (ofs * fc->code_factor), | |
9234 | dwarf_vmatoa_1 (NULL, | |
9235 | fc->pc_begin + ofs * fc->code_factor, | |
9236 | fc->ptr_size)); | |
19e6b90e L |
9237 | fc->pc_begin += ofs * fc->code_factor; |
9238 | break; | |
9239 | ||
9240 | case DW_CFA_GNU_window_save: | |
9241 | if (! do_debug_frames_interp) | |
9242 | printf (" DW_CFA_GNU_window_save\n"); | |
9243 | break; | |
9244 | ||
9245 | case DW_CFA_GNU_args_size: | |
cd30bcef | 9246 | READ_ULEB (ul, start, end); |
19e6b90e L |
9247 | if (! do_debug_frames_interp) |
9248 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
9249 | break; | |
9250 | ||
9251 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
9252 | READ_ULEB (reg, start, end); |
9253 | READ_SLEB (l, start, end); | |
7f2c8a1d | 9254 | l = - l; |
665ce1f6 L |
9255 | if (frame_need_space (fc, reg) < 0) |
9256 | reg_prefix = bad_reg; | |
9257 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9258 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
9259 | reg_prefix, regname (reg, 0), | |
c8071705 | 9260 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9261 | if (*reg_prefix == '\0') |
9262 | { | |
9263 | fc->col_type[reg] = DW_CFA_offset; | |
9264 | fc->col_offset[reg] = l * fc->data_factor; | |
9265 | } | |
19e6b90e L |
9266 | break; |
9267 | ||
9268 | default: | |
53b8873b NC |
9269 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
9270 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
9271 | else | |
f41e4712 | 9272 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
9273 | start = block_end; |
9274 | } | |
9275 | } | |
9276 | ||
5b6312fd NC |
9277 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
9278 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
9279 | frame_display_row (fc, &need_col_headers, &max_regs); |
9280 | ||
a788aedd AM |
9281 | if (fde_fc.col_type != NULL) |
9282 | { | |
9283 | free (fde_fc.col_type); | |
9284 | fde_fc.col_type = NULL; | |
9285 | } | |
9286 | if (fde_fc.col_offset != NULL) | |
9287 | { | |
9288 | free (fde_fc.col_offset); | |
9289 | fde_fc.col_offset = NULL; | |
9290 | } | |
9291 | ||
19e6b90e | 9292 | start = block_end; |
604282a7 | 9293 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
9294 | } |
9295 | ||
9296 | printf ("\n"); | |
9297 | ||
3391569f NC |
9298 | while (remembered_state != NULL) |
9299 | { | |
9300 | rs = remembered_state; | |
9301 | remembered_state = rs->next; | |
9302 | free (rs->col_type); | |
9303 | free (rs->col_offset); | |
9304 | rs->next = NULL; /* Paranoia. */ | |
9305 | free (rs); | |
9306 | } | |
9307 | ||
9308 | while (chunks != NULL) | |
9309 | { | |
9310 | rs = chunks; | |
9311 | chunks = rs->next; | |
9312 | free (rs->col_type); | |
9313 | free (rs->col_offset); | |
9314 | rs->next = NULL; /* Paranoia. */ | |
9315 | free (rs); | |
9316 | } | |
9317 | ||
9318 | while (forward_refs != NULL) | |
9319 | { | |
9320 | rs = forward_refs; | |
9321 | forward_refs = rs->next; | |
9322 | free (rs->col_type); | |
9323 | free (rs->col_offset); | |
9324 | rs->next = NULL; /* Paranoia. */ | |
9325 | free (rs); | |
9326 | } | |
9327 | ||
19e6b90e L |
9328 | return 1; |
9329 | } | |
9330 | ||
9331 | #undef GET | |
19e6b90e | 9332 | |
61364358 JK |
9333 | static int |
9334 | display_debug_names (struct dwarf_section *section, void *file) | |
9335 | { | |
9336 | unsigned char *hdrptr = section->start; | |
9337 | dwarf_vma unit_length; | |
9338 | unsigned char *unit_start; | |
9339 | const unsigned char *const section_end = section->start + section->size; | |
9340 | unsigned char *unit_end; | |
9341 | ||
dda8d76d | 9342 | introduce (section, FALSE); |
61364358 | 9343 | |
dda8d76d | 9344 | load_debug_section_with_follow (str, file); |
61364358 JK |
9345 | |
9346 | for (; hdrptr < section_end; hdrptr = unit_end) | |
9347 | { | |
9348 | unsigned int offset_size; | |
9349 | uint16_t dwarf_version, padding; | |
9350 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
9351 | uint32_t bucket_count, name_count, abbrev_table_size; | |
9352 | uint32_t augmentation_string_size; | |
9353 | unsigned int i; | |
e98fdf1a | 9354 | unsigned long sec_off; |
48467cb9 TV |
9355 | bfd_boolean augmentation_printable; |
9356 | const char *augmentation_string; | |
61364358 JK |
9357 | |
9358 | unit_start = hdrptr; | |
9359 | ||
9360 | /* Get and check the length of the block. */ | |
9361 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
9362 | ||
9363 | if (unit_length == 0xffffffff) | |
9364 | { | |
9365 | /* This section is 64-bit DWARF. */ | |
9366 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
9367 | offset_size = 8; | |
9368 | } | |
9369 | else | |
9370 | offset_size = 4; | |
9371 | unit_end = hdrptr + unit_length; | |
9372 | ||
e98fdf1a AM |
9373 | sec_off = hdrptr - section->start; |
9374 | if (sec_off + unit_length < sec_off | |
9375 | || sec_off + unit_length > section->size) | |
61364358 | 9376 | { |
e98fdf1a AM |
9377 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
9378 | section->name, | |
9379 | (unsigned long) (unit_start - section->start), | |
9380 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
9381 | return 0; |
9382 | } | |
9383 | ||
9384 | /* Get and check the version number. */ | |
9385 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
9386 | printf (_("Version %ld\n"), (long) dwarf_version); | |
9387 | ||
9388 | /* Prior versions did not exist, and future versions may not be | |
9389 | backwards compatible. */ | |
9390 | if (dwarf_version != 5) | |
9391 | { | |
9392 | warn (_("Only DWARF version 5 .debug_names " | |
9393 | "is currently supported.\n")); | |
9394 | return 0; | |
9395 | } | |
9396 | ||
9397 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
9398 | if (padding != 0) | |
9399 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
9400 | padding); | |
9401 | ||
9402 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
9403 | if (comp_unit_count == 0) | |
9404 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
9405 | ||
9406 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
9407 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
9408 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
9409 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
9410 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
9411 | ||
9412 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
9413 | if (augmentation_string_size % 4 != 0) | |
9414 | { | |
9415 | warn (_("Augmentation string length %u must be rounded up " | |
9416 | "to a multiple of 4 in .debug_names.\n"), | |
9417 | augmentation_string_size); | |
9418 | augmentation_string_size += (-augmentation_string_size) & 3; | |
9419 | } | |
48467cb9 | 9420 | |
61364358 | 9421 | printf (_("Augmentation string:")); |
48467cb9 TV |
9422 | |
9423 | augmentation_printable = TRUE; | |
9424 | augmentation_string = (const char *) hdrptr; | |
9425 | ||
61364358 JK |
9426 | for (i = 0; i < augmentation_string_size; i++) |
9427 | { | |
9428 | unsigned char uc; | |
9429 | ||
9430 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
9431 | printf (" %02x", uc); | |
48467cb9 TV |
9432 | |
9433 | if (uc != 0 && !ISPRINT (uc)) | |
9434 | augmentation_printable = FALSE; | |
9435 | } | |
9436 | ||
9437 | if (augmentation_printable) | |
9438 | { | |
9439 | printf (" (\""); | |
9440 | for (i = 0; | |
9441 | i < augmentation_string_size && augmentation_string[i]; | |
9442 | ++i) | |
9443 | putchar (augmentation_string[i]); | |
9444 | printf ("\")"); | |
61364358 | 9445 | } |
61364358 JK |
9446 | putchar ('\n'); |
9447 | ||
9448 | printf (_("CU table:\n")); | |
9449 | for (i = 0; i < comp_unit_count; i++) | |
9450 | { | |
9451 | uint64_t cu_offset; | |
9452 | ||
9453 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
9454 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
9455 | } | |
9456 | putchar ('\n'); | |
9457 | ||
9458 | printf (_("TU table:\n")); | |
9459 | for (i = 0; i < local_type_unit_count; i++) | |
9460 | { | |
9461 | uint64_t tu_offset; | |
9462 | ||
9463 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
9464 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
9465 | } | |
9466 | putchar ('\n'); | |
9467 | ||
9468 | printf (_("Foreign TU table:\n")); | |
9469 | for (i = 0; i < foreign_type_unit_count; i++) | |
9470 | { | |
9471 | uint64_t signature; | |
9472 | ||
9473 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
9474 | printf (_("[%3u] "), i); | |
9475 | print_dwarf_vma (signature, 8); | |
9476 | putchar ('\n'); | |
9477 | } | |
9478 | putchar ('\n'); | |
9479 | ||
9480 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
9481 | hdrptr += bucket_count * sizeof (uint32_t); | |
9482 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
9483 | hdrptr += name_count * sizeof (uint32_t); | |
9484 | unsigned char *const name_table_string_offsets = hdrptr; | |
9485 | hdrptr += name_count * offset_size; | |
9486 | unsigned char *const name_table_entry_offsets = hdrptr; | |
9487 | hdrptr += name_count * offset_size; | |
9488 | unsigned char *const abbrev_table = hdrptr; | |
9489 | hdrptr += abbrev_table_size; | |
9490 | const unsigned char *const abbrev_table_end = hdrptr; | |
9491 | unsigned char *const entry_pool = hdrptr; | |
9492 | if (hdrptr > unit_end) | |
9493 | { | |
9494 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
9495 | "for unit 0x%lx in the debug_names\n"), | |
9496 | (long) (hdrptr - section->start), | |
9497 | (long) (unit_end - section->start), | |
9498 | (long) (unit_start - section->start)); | |
9499 | return 0; | |
9500 | } | |
9501 | ||
9502 | size_t buckets_filled = 0; | |
9503 | size_t bucketi; | |
9504 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
9505 | { | |
9506 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
9507 | ||
9508 | if (bucket != 0) | |
9509 | ++buckets_filled; | |
9510 | } | |
d3a49aa8 AM |
9511 | printf (ngettext ("Used %zu of %lu bucket.\n", |
9512 | "Used %zu of %lu buckets.\n", | |
9513 | bucket_count), | |
9514 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 9515 | |
0a79bef4 | 9516 | uint32_t hash_prev = 0; |
61364358 JK |
9517 | size_t hash_clash_count = 0; |
9518 | size_t longest_clash = 0; | |
9519 | size_t this_length = 0; | |
9520 | size_t hashi; | |
9521 | for (hashi = 0; hashi < name_count; hashi++) | |
9522 | { | |
9523 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
9524 | ||
9525 | if (hashi > 0) | |
9526 | { | |
9527 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
9528 | { | |
9529 | ++hash_clash_count; | |
9530 | ++this_length; | |
9531 | longest_clash = MAX (longest_clash, this_length); | |
9532 | } | |
9533 | else | |
9534 | this_length = 0; | |
9535 | } | |
9536 | hash_prev = hash_this; | |
9537 | } | |
9538 | printf (_("Out of %lu items there are %zu bucket clashes" | |
9539 | " (longest of %zu entries).\n"), | |
9540 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
9541 | assert (name_count == buckets_filled + hash_clash_count); | |
9542 | ||
9543 | struct abbrev_lookup_entry | |
9544 | { | |
9545 | dwarf_vma abbrev_tag; | |
9546 | unsigned char *abbrev_lookup_ptr; | |
9547 | }; | |
9548 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
9549 | size_t abbrev_lookup_used = 0; | |
9550 | size_t abbrev_lookup_allocated = 0; | |
9551 | ||
9552 | unsigned char *abbrevptr = abbrev_table; | |
9553 | for (;;) | |
9554 | { | |
cd30bcef AM |
9555 | dwarf_vma abbrev_tag; |
9556 | ||
9557 | READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end); | |
61364358 JK |
9558 | if (abbrev_tag == 0) |
9559 | break; | |
9560 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
9561 | { | |
9562 | abbrev_lookup_allocated = MAX (0x100, | |
9563 | abbrev_lookup_allocated * 2); | |
9564 | abbrev_lookup = xrealloc (abbrev_lookup, | |
9565 | (abbrev_lookup_allocated | |
9566 | * sizeof (*abbrev_lookup))); | |
9567 | } | |
9568 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
9569 | struct abbrev_lookup_entry *entry; | |
9570 | for (entry = abbrev_lookup; | |
9571 | entry < abbrev_lookup + abbrev_lookup_used; | |
9572 | entry++) | |
9573 | if (entry->abbrev_tag == abbrev_tag) | |
9574 | { | |
9575 | warn (_("Duplicate abbreviation tag %lu " | |
9576 | "in unit 0x%lx in the debug_names\n"), | |
9577 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
9578 | break; | |
9579 | } | |
9580 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
9581 | entry->abbrev_tag = abbrev_tag; | |
9582 | entry->abbrev_lookup_ptr = abbrevptr; | |
9583 | ||
9584 | /* Skip DWARF tag. */ | |
cd30bcef | 9585 | SKIP_ULEB (abbrevptr, abbrev_table_end); |
61364358 JK |
9586 | for (;;) |
9587 | { | |
cd30bcef AM |
9588 | dwarf_vma xindex, form; |
9589 | ||
9590 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9591 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9592 | if (xindex == 0 && form == 0) |
61364358 JK |
9593 | break; |
9594 | } | |
9595 | } | |
9596 | ||
9597 | printf (_("\nSymbol table:\n")); | |
9598 | uint32_t namei; | |
9599 | for (namei = 0; namei < name_count; ++namei) | |
9600 | { | |
9601 | uint64_t string_offset, entry_offset; | |
9602 | ||
9603 | SAFE_BYTE_GET (string_offset, | |
9604 | name_table_string_offsets + namei * offset_size, | |
9605 | offset_size, unit_end); | |
9606 | SAFE_BYTE_GET (entry_offset, | |
9607 | name_table_entry_offsets + namei * offset_size, | |
9608 | offset_size, unit_end); | |
9609 | ||
9610 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
9611 | fetch_indirect_string (string_offset)); | |
9612 | ||
9613 | unsigned char *entryptr = entry_pool + entry_offset; | |
9614 | ||
279edac5 AM |
9615 | /* We need to scan first whether there is a single or multiple |
9616 | entries. TAGNO is -2 for the first entry, it is -1 for the | |
9617 | initial tag read of the second entry, then it becomes 0 for the | |
9618 | first entry for real printing etc. */ | |
61364358 JK |
9619 | int tagno = -2; |
9620 | /* Initialize it due to a false compiler warning. */ | |
9621 | dwarf_vma second_abbrev_tag = -1; | |
9622 | for (;;) | |
9623 | { | |
cd30bcef AM |
9624 | dwarf_vma abbrev_tag; |
9625 | dwarf_vma dwarf_tag; | |
9626 | const struct abbrev_lookup_entry *entry; | |
9627 | ||
9628 | READ_ULEB (abbrev_tag, entryptr, unit_end); | |
61364358 JK |
9629 | if (tagno == -1) |
9630 | { | |
9631 | second_abbrev_tag = abbrev_tag; | |
9632 | tagno = 0; | |
9633 | entryptr = entry_pool + entry_offset; | |
9634 | continue; | |
9635 | } | |
9636 | if (abbrev_tag == 0) | |
9637 | break; | |
9638 | if (tagno >= 0) | |
9639 | printf ("%s<%lu>", | |
9640 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
9641 | (unsigned long) abbrev_tag); | |
9642 | ||
61364358 JK |
9643 | for (entry = abbrev_lookup; |
9644 | entry < abbrev_lookup + abbrev_lookup_used; | |
9645 | entry++) | |
9646 | if (entry->abbrev_tag == abbrev_tag) | |
9647 | break; | |
9648 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
9649 | { | |
9650 | warn (_("Undefined abbreviation tag %lu " | |
9651 | "in unit 0x%lx in the debug_names\n"), | |
9652 | (long) abbrev_tag, | |
9653 | (long) (unit_start - section->start)); | |
9654 | break; | |
9655 | } | |
9656 | abbrevptr = entry->abbrev_lookup_ptr; | |
cd30bcef | 9657 | READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end); |
61364358 JK |
9658 | if (tagno >= 0) |
9659 | printf (" %s", get_TAG_name (dwarf_tag)); | |
9660 | for (;;) | |
9661 | { | |
cd30bcef AM |
9662 | dwarf_vma xindex, form; |
9663 | ||
9664 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9665 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9666 | if (xindex == 0 && form == 0) |
61364358 JK |
9667 | break; |
9668 | ||
9669 | if (tagno >= 0) | |
1d827a72 | 9670 | printf (" %s", get_IDX_name (xindex)); |
ec1b0fbb NC |
9671 | entryptr = read_and_display_attr_value (0, form, 0, |
9672 | unit_start, entryptr, unit_end, | |
9673 | 0, 0, offset_size, | |
61364358 JK |
9674 | dwarf_version, NULL, |
9675 | (tagno < 0), NULL, | |
ec1b0fbb | 9676 | NULL, '=', -1); |
61364358 JK |
9677 | } |
9678 | ++tagno; | |
9679 | } | |
9680 | if (tagno <= 0) | |
9681 | printf (_(" <no entries>")); | |
9682 | putchar ('\n'); | |
9683 | } | |
9684 | ||
9685 | free (abbrev_lookup); | |
9686 | } | |
9687 | ||
9688 | return 1; | |
9689 | } | |
9690 | ||
dda8d76d | 9691 | static int |
d85bf2ba NC |
9692 | display_debug_links (struct dwarf_section * section, |
9693 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
9694 | { |
9695 | const unsigned char * filename; | |
9696 | unsigned int filelen; | |
9697 | ||
9698 | introduce (section, FALSE); | |
9699 | ||
9700 | /* The .gnu_debuglink section is formatted as: | |
9701 | (c-string) Filename. | |
9702 | (padding) If needed to reach a 4 byte boundary. | |
9703 | (uint32_t) CRC32 value. | |
9704 | ||
9705 | The .gun_debugaltlink section is formatted as: | |
9706 | (c-string) Filename. | |
9707 | (binary) Build-ID. */ | |
9708 | ||
9709 | filename = section->start; | |
9710 | filelen = strnlen ((const char *) filename, section->size); | |
9711 | if (filelen == section->size) | |
9712 | { | |
9713 | warn (_("The debuglink filename is corrupt/missing\n")); | |
9714 | return 0; | |
9715 | } | |
9716 | ||
9717 | printf (_(" Separate debug info file: %s\n"), filename); | |
9718 | ||
9719 | if (const_strneq (section->name, ".gnu_debuglink")) | |
9720 | { | |
9721 | unsigned int crc32; | |
9722 | unsigned int crc_offset; | |
9723 | ||
9724 | crc_offset = filelen + 1; | |
9725 | crc_offset = (crc_offset + 3) & ~3; | |
9726 | if (crc_offset + 4 > section->size) | |
9727 | { | |
9728 | warn (_("CRC offset missing/truncated\n")); | |
9729 | return 0; | |
9730 | } | |
9731 | ||
9732 | crc32 = byte_get (filename + crc_offset, 4); | |
9733 | ||
9734 | printf (_(" CRC value: %#x\n"), crc32); | |
9735 | ||
9736 | if (crc_offset + 4 < section->size) | |
9737 | { | |
9738 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
9739 | (long)(section->size - (crc_offset + 4))); | |
9740 | return 0; | |
9741 | } | |
9742 | } | |
9743 | else /* const_strneq (section->name, ".gnu_debugaltlink") */ | |
9744 | { | |
9745 | const unsigned char * build_id = section->start + filelen + 1; | |
9746 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
9747 | bfd_size_type printed; | |
9748 | ||
9749 | /* FIXME: Should we support smaller build-id notes ? */ | |
9750 | if (build_id_len < 0x14) | |
9751 | { | |
9752 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
9753 | return 0; | |
9754 | } | |
9755 | ||
9756 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 9757 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
9758 | putchar ('\n'); |
9759 | } | |
9760 | ||
9761 | putchar ('\n'); | |
9762 | return 1; | |
9763 | } | |
9764 | ||
5bbdf3d5 DE |
9765 | static int |
9766 | display_gdb_index (struct dwarf_section *section, | |
9767 | void *file ATTRIBUTE_UNUSED) | |
9768 | { | |
9769 | unsigned char *start = section->start; | |
9770 | uint32_t version; | |
9771 | uint32_t cu_list_offset, tu_list_offset; | |
9772 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
9773 | unsigned int cu_list_elements, tu_list_elements; | |
9774 | unsigned int address_table_size, symbol_table_slots; | |
9775 | unsigned char *cu_list, *tu_list; | |
9776 | unsigned char *address_table, *symbol_table, *constant_pool; | |
9777 | unsigned int i; | |
9778 | ||
9779 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
9780 | ||
dda8d76d | 9781 | introduce (section, FALSE); |
5bbdf3d5 DE |
9782 | |
9783 | if (section->size < 6 * sizeof (uint32_t)) | |
9784 | { | |
9785 | warn (_("Truncated header in the %s section.\n"), section->name); | |
9786 | return 0; | |
9787 | } | |
9788 | ||
9789 | version = byte_get_little_endian (start, 4); | |
da88a764 | 9790 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
9791 | |
9792 | /* Prior versions are obsolete, and future versions may not be | |
9793 | backwards compatible. */ | |
aa170720 | 9794 | if (version < 3 || version > 8) |
5bbdf3d5 | 9795 | { |
da88a764 | 9796 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
9797 | return 0; |
9798 | } | |
8d6eee87 TT |
9799 | if (version < 4) |
9800 | warn (_("The address table data in version 3 may be wrong.\n")); | |
9801 | if (version < 5) | |
9802 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
9803 | if (version < 6) | |
9804 | warn (_("Version 5 does not include inlined functions.\n")); | |
9805 | if (version < 7) | |
9806 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
9807 | /* Version 7 indices generated by Gold have bad type unit references, |
9808 | PR binutils/15021. But we don't know if the index was generated by | |
9809 | Gold or not, so to avoid worrying users with gdb-generated indices | |
9810 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
9811 | |
9812 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
9813 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
9814 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
9815 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
9816 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
9817 | ||
9818 | if (cu_list_offset > section->size | |
9819 | || tu_list_offset > section->size | |
9820 | || address_table_offset > section->size | |
9821 | || symbol_table_offset > section->size | |
9822 | || constant_pool_offset > section->size) | |
9823 | { | |
9824 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
9825 | return 0; | |
9826 | } | |
9827 | ||
53774b7e NC |
9828 | /* PR 17531: file: 418d0a8a. */ |
9829 | if (tu_list_offset < cu_list_offset) | |
9830 | { | |
9831 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
9832 | tu_list_offset, cu_list_offset); | |
9833 | return 0; | |
9834 | } | |
9835 | ||
5bbdf3d5 | 9836 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
9837 | |
9838 | if (address_table_offset < tu_list_offset) | |
9839 | { | |
9840 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
9841 | address_table_offset, tu_list_offset); | |
9842 | return 0; | |
9843 | } | |
9844 | ||
5bbdf3d5 | 9845 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
9846 | |
9847 | /* PR 17531: file: 18a47d3d. */ | |
9848 | if (symbol_table_offset < address_table_offset) | |
9849 | { | |
13bace4a | 9850 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
9851 | symbol_table_offset, address_table_offset); |
9852 | return 0; | |
9853 | } | |
9854 | ||
5bbdf3d5 | 9855 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
9856 | |
9857 | if (constant_pool_offset < symbol_table_offset) | |
9858 | { | |
9859 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
9860 | constant_pool_offset, symbol_table_offset); | |
9861 | return 0; | |
9862 | } | |
9863 | ||
5bbdf3d5 DE |
9864 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
9865 | ||
9866 | cu_list = start + cu_list_offset; | |
9867 | tu_list = start + tu_list_offset; | |
9868 | address_table = start + address_table_offset; | |
9869 | symbol_table = start + symbol_table_offset; | |
9870 | constant_pool = start + constant_pool_offset; | |
9871 | ||
28d909e5 | 9872 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 9873 | { |
1306a742 | 9874 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
9875 | return 0; |
9876 | } | |
b4eb7656 | 9877 | |
5bbdf3d5 DE |
9878 | printf (_("\nCU table:\n")); |
9879 | for (i = 0; i < cu_list_elements; i += 2) | |
9880 | { | |
9881 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
9882 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
9883 | ||
9884 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
9885 | (unsigned long) cu_offset, | |
9886 | (unsigned long) (cu_offset + cu_length - 1)); | |
9887 | } | |
9888 | ||
9889 | printf (_("\nTU table:\n")); | |
9890 | for (i = 0; i < tu_list_elements; i += 3) | |
9891 | { | |
9892 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
9893 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
9894 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
9895 | ||
9896 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
9897 | (unsigned long) tu_offset, | |
9898 | (unsigned long) type_offset); | |
9899 | print_dwarf_vma (signature, 8); | |
9900 | printf ("\n"); | |
9901 | } | |
9902 | ||
9903 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
9904 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
9905 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
9906 | { |
9907 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
9908 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
9909 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
9910 | ||
9911 | print_dwarf_vma (low, 8); | |
9912 | print_dwarf_vma (high, 8); | |
da88a764 | 9913 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
9914 | } |
9915 | ||
9916 | printf (_("\nSymbol table:\n")); | |
9917 | for (i = 0; i < symbol_table_slots; ++i) | |
9918 | { | |
9919 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
9920 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
9921 | uint32_t num_cus, cu; | |
9922 | ||
9923 | if (name_offset != 0 | |
9924 | || cu_vector_offset != 0) | |
9925 | { | |
9926 | unsigned int j; | |
362beea4 | 9927 | unsigned char * adr; |
5bbdf3d5 | 9928 | |
362beea4 | 9929 | adr = constant_pool + name_offset; |
53774b7e | 9930 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 9931 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
9932 | { |
9933 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
9934 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
9935 | name_offset, i); | |
9936 | } | |
9937 | else | |
acff9664 NC |
9938 | printf ("[%3u] %.*s:", i, |
9939 | (int) (section->size - (constant_pool_offset + name_offset)), | |
9940 | constant_pool + name_offset); | |
53774b7e | 9941 | |
362beea4 NC |
9942 | adr = constant_pool + cu_vector_offset; |
9943 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
9944 | { |
9945 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
9946 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
9947 | cu_vector_offset, i); | |
9948 | continue; | |
9949 | } | |
57028622 | 9950 | |
362beea4 | 9951 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 9952 | |
362beea4 | 9953 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 9954 | if (num_cus * 4 < num_cus |
362beea4 NC |
9955 | || adr >= section->start + section->size |
9956 | || adr < constant_pool) | |
53774b7e NC |
9957 | { |
9958 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 9959 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
9960 | num_cus, i); |
9961 | continue; | |
9962 | } | |
9963 | ||
8d6eee87 TT |
9964 | if (num_cus > 1) |
9965 | printf ("\n"); | |
f3853b34 | 9966 | |
5bbdf3d5 DE |
9967 | for (j = 0; j < num_cus; ++j) |
9968 | { | |
7c1cef97 | 9969 | int is_static; |
8d6eee87 TT |
9970 | gdb_index_symbol_kind kind; |
9971 | ||
5bbdf3d5 | 9972 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 9973 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
9974 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
9975 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 9976 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 9977 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
9978 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
9979 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 9980 | else |
8d6eee87 TT |
9981 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
9982 | ||
459d52c8 DE |
9983 | printf (" [%s, %s]", |
9984 | is_static ? _("static") : _("global"), | |
9985 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
9986 | if (num_cus > 1) |
9987 | printf ("\n"); | |
5bbdf3d5 | 9988 | } |
8d6eee87 TT |
9989 | if (num_cus <= 1) |
9990 | printf ("\n"); | |
5bbdf3d5 DE |
9991 | } |
9992 | } | |
9993 | ||
9994 | return 1; | |
9995 | } | |
9996 | ||
657d0d47 CC |
9997 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
9998 | ||
9999 | static void | |
10000 | prealloc_cu_tu_list (unsigned int nshndx) | |
10001 | { | |
10002 | if (shndx_pool == NULL) | |
10003 | { | |
10004 | shndx_pool_size = nshndx; | |
10005 | shndx_pool_used = 0; | |
10006 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
10007 | sizeof (unsigned int)); | |
10008 | } | |
10009 | else | |
10010 | { | |
10011 | shndx_pool_size = shndx_pool_used + nshndx; | |
10012 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
10013 | sizeof (unsigned int)); | |
10014 | } | |
10015 | } | |
10016 | ||
10017 | static void | |
10018 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
10019 | { | |
10020 | if (shndx_pool_used >= shndx_pool_size) | |
10021 | { | |
10022 | error (_("Internal error: out of space in the shndx pool.\n")); | |
10023 | return; | |
10024 | } | |
10025 | shndx_pool [shndx_pool_used++] = shndx; | |
10026 | } | |
10027 | ||
10028 | static void | |
10029 | end_cu_tu_entry (void) | |
10030 | { | |
10031 | if (shndx_pool_used >= shndx_pool_size) | |
10032 | { | |
10033 | error (_("Internal error: out of space in the shndx pool.\n")); | |
10034 | return; | |
10035 | } | |
10036 | shndx_pool [shndx_pool_used++] = 0; | |
10037 | } | |
10038 | ||
341f9135 CC |
10039 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
10040 | ||
10041 | static const char * | |
10042 | get_DW_SECT_short_name (unsigned int dw_sect) | |
10043 | { | |
10044 | static char buf[16]; | |
10045 | ||
10046 | switch (dw_sect) | |
10047 | { | |
10048 | case DW_SECT_INFO: | |
10049 | return "info"; | |
10050 | case DW_SECT_TYPES: | |
10051 | return "types"; | |
10052 | case DW_SECT_ABBREV: | |
10053 | return "abbrev"; | |
10054 | case DW_SECT_LINE: | |
10055 | return "line"; | |
10056 | case DW_SECT_LOC: | |
10057 | return "loc"; | |
10058 | case DW_SECT_STR_OFFSETS: | |
10059 | return "str_off"; | |
10060 | case DW_SECT_MACINFO: | |
10061 | return "macinfo"; | |
10062 | case DW_SECT_MACRO: | |
10063 | return "macro"; | |
10064 | default: | |
b4eb7656 | 10065 | break; |
341f9135 CC |
10066 | } |
10067 | ||
10068 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
10069 | return buf; | |
10070 | } | |
10071 | ||
10072 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
10073 | These sections are extensions for Fission. | |
10074 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
10075 | |
10076 | static int | |
10077 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
10078 | { | |
10079 | unsigned char *phdr = section->start; | |
10080 | unsigned char *limit = phdr + section->size; | |
10081 | unsigned char *phash; | |
10082 | unsigned char *pindex; | |
10083 | unsigned char *ppool; | |
10084 | unsigned int version; | |
341f9135 | 10085 | unsigned int ncols = 0; |
657d0d47 CC |
10086 | unsigned int nused; |
10087 | unsigned int nslots; | |
10088 | unsigned int i; | |
341f9135 CC |
10089 | unsigned int j; |
10090 | dwarf_vma signature_high; | |
10091 | dwarf_vma signature_low; | |
10092 | char buf[64]; | |
657d0d47 | 10093 | |
6937bb54 NC |
10094 | /* PR 17512: file: 002-168123-0.004. */ |
10095 | if (phdr == NULL) | |
10096 | { | |
10097 | warn (_("Section %s is empty\n"), section->name); | |
10098 | return 0; | |
10099 | } | |
10100 | /* PR 17512: file: 002-376-0.004. */ | |
10101 | if (section->size < 24) | |
10102 | { | |
72c61a0d | 10103 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
10104 | section->name); |
10105 | return 0; | |
10106 | } | |
10107 | ||
10108 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 10109 | if (version >= 2) |
6937bb54 NC |
10110 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
10111 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
10112 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
10113 | ||
657d0d47 | 10114 | phash = phdr + 16; |
8e2e3c6c AM |
10115 | pindex = phash + (size_t) nslots * 8; |
10116 | ppool = pindex + (size_t) nslots * 4; | |
57028622 | 10117 | |
657d0d47 CC |
10118 | if (do_display) |
10119 | { | |
dda8d76d NC |
10120 | introduce (section, FALSE); |
10121 | ||
8e2e3c6c | 10122 | printf (_(" Version: %u\n"), version); |
341f9135 | 10123 | if (version >= 2) |
8e2e3c6c AM |
10124 | printf (_(" Number of columns: %u\n"), ncols); |
10125 | printf (_(" Number of used entries: %u\n"), nused); | |
10126 | printf (_(" Number of slots: %u\n\n"), nslots); | |
657d0d47 CC |
10127 | } |
10128 | ||
8e2e3c6c AM |
10129 | /* PR 17531: file: 45d69832. */ |
10130 | if ((size_t) nslots * 8 / 8 != nslots | |
10131 | || phash < phdr || phash > limit | |
10132 | || pindex < phash || pindex > limit | |
10133 | || ppool < pindex || ppool > limit) | |
657d0d47 | 10134 | { |
8e2e3c6c AM |
10135 | warn (ngettext ("Section %s is too small for %u slot\n", |
10136 | "Section %s is too small for %u slots\n", | |
10137 | nslots), | |
657d0d47 CC |
10138 | section->name, nslots); |
10139 | return 0; | |
10140 | } | |
10141 | ||
341f9135 | 10142 | if (version == 1) |
657d0d47 | 10143 | { |
341f9135 CC |
10144 | if (!do_display) |
10145 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
10146 | for (i = 0; i < nslots; i++) | |
657d0d47 | 10147 | { |
341f9135 CC |
10148 | unsigned char *shndx_list; |
10149 | unsigned int shndx; | |
10150 | ||
6937bb54 | 10151 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 10152 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 10153 | { |
6937bb54 | 10154 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 10155 | shndx_list = ppool + j * 4; |
f3853b34 NC |
10156 | /* PR 17531: file: 705e010d. */ |
10157 | if (shndx_list < ppool) | |
10158 | { | |
10159 | warn (_("Section index pool located before start of section\n")); | |
10160 | return 0; | |
10161 | } | |
10162 | ||
341f9135 CC |
10163 | if (do_display) |
10164 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
10165 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10166 | buf, sizeof (buf))); | |
10167 | for (;;) | |
657d0d47 | 10168 | { |
341f9135 CC |
10169 | if (shndx_list >= limit) |
10170 | { | |
10171 | warn (_("Section %s too small for shndx pool\n"), | |
10172 | section->name); | |
10173 | return 0; | |
10174 | } | |
6937bb54 | 10175 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
10176 | if (shndx == 0) |
10177 | break; | |
10178 | if (do_display) | |
10179 | printf (" %d", shndx); | |
10180 | else | |
10181 | add_shndx_to_cu_tu_entry (shndx); | |
10182 | shndx_list += 4; | |
657d0d47 | 10183 | } |
657d0d47 | 10184 | if (do_display) |
341f9135 | 10185 | printf ("\n"); |
657d0d47 | 10186 | else |
341f9135 CC |
10187 | end_cu_tu_entry (); |
10188 | } | |
10189 | phash += 8; | |
10190 | pindex += 4; | |
10191 | } | |
10192 | } | |
10193 | else if (version == 2) | |
10194 | { | |
10195 | unsigned int val; | |
10196 | unsigned int dw_sect; | |
10197 | unsigned char *ph = phash; | |
10198 | unsigned char *pi = pindex; | |
8e2e3c6c AM |
10199 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
10200 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
10201 | unsigned char *pend = psizes + (size_t) nused * ncols * 4; | |
341f9135 CC |
10202 | bfd_boolean is_tu_index; |
10203 | struct cu_tu_set *this_set = NULL; | |
10204 | unsigned int row; | |
10205 | unsigned char *prow; | |
10206 | ||
10207 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
10208 | ||
362beea4 | 10209 | /* PR 17531: file: 0dd159bf. |
8e2e3c6c AM |
10210 | Check for integer overflow (can occur when size_t is 32-bit) |
10211 | with overlarge ncols or nused values. */ | |
4ac948a0 NC |
10212 | if (ncols > 0 |
10213 | && ((size_t) ncols * 4 / 4 != ncols | |
10214 | || (size_t) nused * ncols * 4 / ((size_t) ncols * 4) != nused | |
10215 | || poffsets < ppool || poffsets > limit | |
10216 | || psizes < poffsets || psizes > limit | |
10217 | || pend < psizes || pend > limit)) | |
341f9135 CC |
10218 | { |
10219 | warn (_("Section %s too small for offset and size tables\n"), | |
10220 | section->name); | |
10221 | return 0; | |
10222 | } | |
10223 | ||
10224 | if (do_display) | |
10225 | { | |
10226 | printf (_(" Offset table\n")); | |
10227 | printf (" slot %-16s ", | |
10228 | is_tu_index ? _("signature") : _("dwo_id")); | |
10229 | } | |
10230 | else | |
10231 | { | |
10232 | if (is_tu_index) | |
10233 | { | |
10234 | tu_count = nused; | |
72c61a0d | 10235 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 10236 | this_set = tu_sets; |
657d0d47 | 10237 | } |
657d0d47 | 10238 | else |
341f9135 CC |
10239 | { |
10240 | cu_count = nused; | |
72c61a0d | 10241 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
10242 | this_set = cu_sets; |
10243 | } | |
10244 | } | |
6937bb54 | 10245 | |
341f9135 CC |
10246 | if (do_display) |
10247 | { | |
10248 | for (j = 0; j < ncols; j++) | |
10249 | { | |
6937bb54 | 10250 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
10251 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
10252 | } | |
10253 | printf ("\n"); | |
10254 | } | |
6937bb54 | 10255 | |
341f9135 CC |
10256 | for (i = 0; i < nslots; i++) |
10257 | { | |
6937bb54 NC |
10258 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
10259 | ||
10260 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10261 | if (row != 0) |
10262 | { | |
591f7597 | 10263 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 10264 | if (row > nused) |
591f7597 NC |
10265 | { |
10266 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
10267 | row, nused); | |
10268 | return 0; | |
10269 | } | |
10270 | ||
341f9135 | 10271 | if (!do_display) |
6aea08d9 NC |
10272 | { |
10273 | size_t num_copy = sizeof (uint64_t); | |
10274 | ||
10275 | /* PR 23064: Beware of buffer overflow. */ | |
10276 | if (ph + num_copy < limit) | |
10277 | memcpy (&this_set[row - 1].signature, ph, num_copy); | |
10278 | else | |
10279 | { | |
10280 | warn (_("Signature (%p) extends beyond end of space in section\n"), ph); | |
10281 | return 0; | |
10282 | } | |
10283 | } | |
6937bb54 | 10284 | |
341f9135 | 10285 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
10286 | /* PR 17531: file: b8ce60a8. */ |
10287 | if (prow < poffsets || prow > limit) | |
10288 | { | |
10289 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
10290 | row, ncols); | |
10291 | return 0; | |
10292 | } | |
3aade688 | 10293 | |
341f9135 CC |
10294 | if (do_display) |
10295 | printf (_(" [%3d] 0x%s"), | |
10296 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10297 | buf, sizeof (buf))); | |
10298 | for (j = 0; j < ncols; j++) | |
10299 | { | |
6937bb54 | 10300 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
10301 | if (do_display) |
10302 | printf (" %8d", val); | |
10303 | else | |
10304 | { | |
6937bb54 | 10305 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
10306 | |
10307 | /* PR 17531: file: 10796eb3. */ | |
10308 | if (dw_sect >= DW_SECT_MAX) | |
10309 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10310 | else | |
10311 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
10312 | } |
10313 | } | |
6937bb54 | 10314 | |
341f9135 CC |
10315 | if (do_display) |
10316 | printf ("\n"); | |
10317 | } | |
10318 | ph += 8; | |
10319 | pi += 4; | |
10320 | } | |
10321 | ||
10322 | ph = phash; | |
10323 | pi = pindex; | |
10324 | if (do_display) | |
b4eb7656 | 10325 | { |
341f9135 CC |
10326 | printf ("\n"); |
10327 | printf (_(" Size table\n")); | |
10328 | printf (" slot %-16s ", | |
10329 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 10330 | } |
6937bb54 | 10331 | |
341f9135 CC |
10332 | for (j = 0; j < ncols; j++) |
10333 | { | |
6937bb54 | 10334 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
10335 | if (do_display) |
10336 | printf (" %8s", get_DW_SECT_short_name (val)); | |
10337 | } | |
6937bb54 | 10338 | |
341f9135 CC |
10339 | if (do_display) |
10340 | printf ("\n"); | |
6937bb54 | 10341 | |
341f9135 CC |
10342 | for (i = 0; i < nslots; i++) |
10343 | { | |
6937bb54 NC |
10344 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
10345 | ||
10346 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10347 | if (row != 0) |
10348 | { | |
10349 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 10350 | |
341f9135 CC |
10351 | if (do_display) |
10352 | printf (_(" [%3d] 0x%s"), | |
10353 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10354 | buf, sizeof (buf))); | |
6937bb54 | 10355 | |
341f9135 CC |
10356 | for (j = 0; j < ncols; j++) |
10357 | { | |
6937bb54 | 10358 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
10359 | if (do_display) |
10360 | printf (" %8d", val); | |
10361 | else | |
10362 | { | |
6937bb54 | 10363 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
10364 | if (dw_sect >= DW_SECT_MAX) |
10365 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10366 | else | |
341f9135 CC |
10367 | this_set [row - 1].section_sizes [dw_sect] = val; |
10368 | } | |
10369 | } | |
6937bb54 | 10370 | |
341f9135 CC |
10371 | if (do_display) |
10372 | printf ("\n"); | |
10373 | } | |
6937bb54 | 10374 | |
341f9135 CC |
10375 | ph += 8; |
10376 | pi += 4; | |
657d0d47 | 10377 | } |
657d0d47 | 10378 | } |
341f9135 | 10379 | else if (do_display) |
6937bb54 | 10380 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
10381 | |
10382 | if (do_display) | |
10383 | printf ("\n"); | |
10384 | ||
10385 | return 1; | |
10386 | } | |
10387 | ||
10388 | /* Load the CU and TU indexes if present. This will build a list of | |
10389 | section sets that we can use to associate a .debug_info.dwo section | |
10390 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
10391 | ||
43a444f9 | 10392 | static bfd_boolean |
657d0d47 CC |
10393 | load_cu_tu_indexes (void *file) |
10394 | { | |
43a444f9 NC |
10395 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
10396 | ||
657d0d47 CC |
10397 | /* If we have already loaded (or tried to load) the CU and TU indexes |
10398 | then do not bother to repeat the task. */ | |
43a444f9 NC |
10399 | if (cu_tu_indexes_read == -1) |
10400 | { | |
10401 | cu_tu_indexes_read = TRUE; | |
10402 | ||
dda8d76d | 10403 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 NC |
10404 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
10405 | cu_tu_indexes_read = FALSE; | |
10406 | ||
dda8d76d | 10407 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 NC |
10408 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
10409 | cu_tu_indexes_read = FALSE; | |
10410 | } | |
657d0d47 | 10411 | |
43a444f9 | 10412 | return (bfd_boolean) cu_tu_indexes_read; |
657d0d47 CC |
10413 | } |
10414 | ||
10415 | /* Find the set of sections that includes section SHNDX. */ | |
10416 | ||
10417 | unsigned int * | |
10418 | find_cu_tu_set (void *file, unsigned int shndx) | |
10419 | { | |
10420 | unsigned int i; | |
10421 | ||
43a444f9 NC |
10422 | if (! load_cu_tu_indexes (file)) |
10423 | return NULL; | |
657d0d47 CC |
10424 | |
10425 | /* Find SHNDX in the shndx pool. */ | |
10426 | for (i = 0; i < shndx_pool_used; i++) | |
10427 | if (shndx_pool [i] == shndx) | |
10428 | break; | |
10429 | ||
10430 | if (i >= shndx_pool_used) | |
10431 | return NULL; | |
10432 | ||
10433 | /* Now backup to find the first entry in the set. */ | |
10434 | while (i > 0 && shndx_pool [i - 1] != 0) | |
10435 | i--; | |
10436 | ||
10437 | return shndx_pool + i; | |
10438 | } | |
10439 | ||
10440 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
10441 | ||
10442 | static int | |
10443 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
10444 | { | |
10445 | return process_cu_tu_index (section, 1); | |
10446 | } | |
10447 | ||
19e6b90e L |
10448 | static int |
10449 | display_debug_not_supported (struct dwarf_section *section, | |
10450 | void *file ATTRIBUTE_UNUSED) | |
10451 | { | |
10452 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
10453 | section->name); | |
10454 | ||
10455 | return 1; | |
10456 | } | |
10457 | ||
1306a742 NC |
10458 | /* Like malloc, but takes two parameters like calloc. |
10459 | Verifies that the first parameter is not too large. | |
82b1b41b | 10460 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 10461 | |
19e6b90e L |
10462 | void * |
10463 | cmalloc (size_t nmemb, size_t size) | |
10464 | { | |
10465 | /* Check for overflow. */ | |
10466 | if (nmemb >= ~(size_t) 0 / size) | |
10467 | return NULL; | |
82b1b41b NC |
10468 | |
10469 | return xmalloc (nmemb * size); | |
19e6b90e L |
10470 | } |
10471 | ||
1306a742 NC |
10472 | /* Like xmalloc, but takes two parameters like calloc. |
10473 | Verifies that the first parameter is not too large. | |
10474 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 10475 | |
72c61a0d | 10476 | void * |
1306a742 | 10477 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
10478 | { |
10479 | /* Check for overflow. */ | |
10480 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
10481 | { |
10482 | fprintf (stderr, | |
10483 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
10484 | (long) nmemb); | |
10485 | xexit (1); | |
10486 | } | |
72c61a0d | 10487 | |
1306a742 | 10488 | return xmalloc (nmemb * size); |
72c61a0d NC |
10489 | } |
10490 | ||
1306a742 NC |
10491 | /* Like xrealloc, but takes three parameters. |
10492 | Verifies that the second parameter is not too large. | |
10493 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 10494 | |
19e6b90e | 10495 | void * |
1306a742 | 10496 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
10497 | { |
10498 | /* Check for overflow. */ | |
10499 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10500 | { |
dda8d76d NC |
10501 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
10502 | (long) nmemb); | |
8490fb40 NC |
10503 | xexit (1); |
10504 | } | |
82b1b41b | 10505 | |
1306a742 | 10506 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
10507 | } |
10508 | ||
1306a742 | 10509 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 10510 | |
19e6b90e | 10511 | void * |
1306a742 | 10512 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
10513 | { |
10514 | /* Check for overflow. */ | |
10515 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10516 | { |
dda8d76d NC |
10517 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
10518 | (long) nmemb); | |
8490fb40 NC |
10519 | xexit (1); |
10520 | } | |
82b1b41b | 10521 | |
1306a742 | 10522 | return xcalloc (nmemb, size); |
19e6b90e L |
10523 | } |
10524 | ||
dda8d76d NC |
10525 | static unsigned long |
10526 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
10527 | const unsigned char * buf, | |
10528 | bfd_size_type len) | |
10529 | { | |
10530 | static const unsigned long crc32_table[256] = | |
10531 | { | |
10532 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
10533 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
10534 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
10535 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
10536 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
10537 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
10538 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
10539 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
10540 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
10541 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
10542 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
10543 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
10544 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
10545 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
10546 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
10547 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
10548 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
10549 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
10550 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
10551 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
10552 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
10553 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
10554 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
10555 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
10556 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
10557 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
10558 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
10559 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
10560 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
10561 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
10562 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
10563 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
10564 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
10565 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
10566 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
10567 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
10568 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
10569 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
10570 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
10571 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
10572 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
10573 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
10574 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
10575 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
10576 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
10577 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
10578 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
10579 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
10580 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
10581 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
10582 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
10583 | 0x2d02ef8d | |
10584 | }; | |
10585 | const unsigned char *end; | |
10586 | ||
10587 | crc = ~crc & 0xffffffff; | |
10588 | for (end = buf + len; buf < end; ++ buf) | |
10589 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
10590 | return ~crc & 0xffffffff; | |
10591 | } | |
10592 | ||
10593 | typedef bfd_boolean (* check_func_type) (const char *, void *); | |
10594 | typedef const char * (* parse_func_type) (struct dwarf_section *, void *); | |
10595 | ||
10596 | static bfd_boolean | |
10597 | check_gnu_debuglink (const char * pathname, void * crc_pointer) | |
10598 | { | |
10599 | static unsigned char buffer [8 * 1024]; | |
10600 | FILE * f; | |
10601 | bfd_size_type count; | |
10602 | unsigned long crc = 0; | |
10603 | void * sep_data; | |
10604 | ||
10605 | sep_data = open_debug_file (pathname); | |
10606 | if (sep_data == NULL) | |
10607 | return FALSE; | |
10608 | ||
10609 | /* Yes - we are opening the file twice... */ | |
10610 | f = fopen (pathname, "rb"); | |
10611 | if (f == NULL) | |
10612 | { | |
10613 | /* Paranoia: This should never happen. */ | |
10614 | close_debug_file (sep_data); | |
10615 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
10616 | return FALSE; | |
10617 | } | |
10618 | ||
10619 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
10620 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
10621 | ||
10622 | fclose (f); | |
10623 | ||
10624 | if (crc != * (unsigned long *) crc_pointer) | |
10625 | { | |
10626 | close_debug_file (sep_data); | |
10627 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
10628 | pathname); | |
10629 | return FALSE; | |
10630 | } | |
10631 | ||
10632 | return TRUE; | |
10633 | } | |
10634 | ||
10635 | static const char * | |
10636 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
10637 | { | |
10638 | const char * name; | |
10639 | unsigned int crc_offset; | |
10640 | unsigned long * crc32 = (unsigned long *) data; | |
10641 | ||
10642 | /* The name is first. | |
10643 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
10644 | name = (const char *) section->start; | |
10645 | ||
39f0547e | 10646 | |
dda8d76d NC |
10647 | crc_offset = strnlen (name, section->size) + 1; |
10648 | crc_offset = (crc_offset + 3) & ~3; | |
10649 | if (crc_offset + 4 > section->size) | |
10650 | return NULL; | |
10651 | ||
10652 | * crc32 = byte_get (section->start + crc_offset, 4); | |
10653 | return name; | |
10654 | } | |
10655 | ||
10656 | static bfd_boolean | |
10657 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) | |
10658 | { | |
10659 | void * sep_data = open_debug_file (filename); | |
10660 | ||
10661 | if (sep_data == NULL) | |
10662 | return FALSE; | |
10663 | ||
10664 | /* FIXME: We should now extract the build-id in the separate file | |
10665 | and check it... */ | |
10666 | ||
10667 | return TRUE; | |
10668 | } | |
10669 | ||
10670 | typedef struct build_id_data | |
10671 | { | |
10672 | bfd_size_type len; | |
10673 | const unsigned char * data; | |
10674 | } Build_id_data; | |
10675 | ||
10676 | static const char * | |
10677 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
10678 | { | |
10679 | const char * name; | |
10680 | bfd_size_type namelen; | |
10681 | bfd_size_type id_len; | |
10682 | Build_id_data * build_id_data; | |
10683 | ||
10684 | /* The name is first. | |
10685 | The build-id follows immediately, with no padding, up to the section's end. */ | |
10686 | ||
10687 | name = (const char *) section->start; | |
10688 | namelen = strnlen (name, section->size) + 1; | |
10689 | if (namelen >= section->size) | |
10690 | return NULL; | |
10691 | ||
10692 | id_len = section->size - namelen; | |
10693 | if (id_len < 0x14) | |
10694 | return NULL; | |
10695 | ||
dfbee680 | 10696 | build_id_data = (Build_id_data *) data; |
dda8d76d NC |
10697 | build_id_data->len = id_len; |
10698 | build_id_data->data = section->start + namelen; | |
10699 | ||
dda8d76d NC |
10700 | return name; |
10701 | } | |
10702 | ||
24841daa NC |
10703 | static void |
10704 | add_separate_debug_file (const char * filename, void * handle) | |
10705 | { | |
10706 | separate_info * i = xmalloc (sizeof * i); | |
10707 | ||
10708 | i->filename = filename; | |
10709 | i->handle = handle; | |
10710 | i->next = first_separate_info; | |
10711 | first_separate_info = i; | |
10712 | } | |
10713 | ||
301a9420 AM |
10714 | #if HAVE_LIBDEBUGINFOD |
10715 | /* Query debuginfod servers for the target debuglink or debugaltlink | |
10716 | file. If successful, store the path of the file in filename and | |
10717 | return TRUE, otherwise return FALSE. */ | |
10718 | ||
10719 | static bfd_boolean | |
10720 | debuginfod_fetch_separate_debug_info (struct dwarf_section * section, | |
10721 | char ** filename, | |
10722 | void * file) | |
10723 | { | |
10724 | size_t build_id_len; | |
10725 | unsigned char * build_id; | |
10726 | ||
10727 | if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0) | |
10728 | { | |
10729 | /* Get the build-id of file. */ | |
10730 | build_id = get_build_id (file); | |
10731 | build_id_len = 0; | |
10732 | } | |
10733 | else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0) | |
10734 | { | |
10735 | /* Get the build-id of the debugaltlink file. */ | |
10736 | unsigned int filelen; | |
10737 | ||
10738 | filelen = strnlen ((const char *)section->start, section->size); | |
10739 | if (filelen == section->size) | |
10740 | /* Corrupt debugaltlink. */ | |
10741 | return FALSE; | |
10742 | ||
10743 | build_id = section->start + filelen + 1; | |
10744 | build_id_len = section->size - (filelen + 1); | |
10745 | ||
10746 | if (build_id_len == 0) | |
10747 | return FALSE; | |
10748 | } | |
10749 | else | |
10750 | return FALSE; | |
10751 | ||
10752 | if (build_id) | |
10753 | { | |
10754 | int fd; | |
10755 | debuginfod_client * client; | |
10756 | ||
10757 | client = debuginfod_begin (); | |
10758 | if (client == NULL) | |
10759 | return FALSE; | |
10760 | ||
10761 | /* Query debuginfod servers for the target file. If found its path | |
10762 | will be stored in filename. */ | |
10763 | fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename); | |
10764 | debuginfod_end (client); | |
10765 | ||
10766 | /* Only free build_id if we allocated space for a hex string | |
10767 | in get_build_id (). */ | |
10768 | if (build_id_len == 0) | |
10769 | free (build_id); | |
10770 | ||
10771 | if (fd >= 0) | |
10772 | { | |
10773 | /* File successfully retrieved. Close fd since we want to | |
10774 | use open_debug_file () on filename instead. */ | |
10775 | close (fd); | |
10776 | return TRUE; | |
10777 | } | |
10778 | } | |
10779 | ||
10780 | return FALSE; | |
10781 | } | |
10782 | #endif | |
10783 | ||
dda8d76d NC |
10784 | static void * |
10785 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 10786 | struct dwarf_section * xlink, |
dda8d76d NC |
10787 | parse_func_type parse_func, |
10788 | check_func_type check_func, | |
301a9420 AM |
10789 | void * func_data, |
10790 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
10791 | { |
10792 | const char * separate_filename; | |
24841daa | 10793 | char * debug_filename; |
dda8d76d NC |
10794 | char * canon_dir; |
10795 | size_t canon_dirlen; | |
10796 | size_t dirlen; | |
10797 | ||
2b63c337 | 10798 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
10799 | { |
10800 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 10801 | xlink->name ? xlink->name : xlink->uncompressed_name); |
ce139cd5 | 10802 | return NULL; |
dda8d76d NC |
10803 | } |
10804 | ||
10805 | /* Attempt to locate the separate file. | |
10806 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
10807 | ||
10808 | canon_dir = lrealpath (main_filename); | |
10809 | ||
10810 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) | |
10811 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
10812 | break; | |
10813 | canon_dir[canon_dirlen] = '\0'; | |
10814 | ||
10815 | #ifndef DEBUGDIR | |
10816 | #define DEBUGDIR "/lib/debug" | |
10817 | #endif | |
10818 | #ifndef EXTRA_DEBUG_ROOT1 | |
10819 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
10820 | #endif | |
10821 | #ifndef EXTRA_DEBUG_ROOT2 | |
10822 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
10823 | #endif | |
10824 | ||
24841daa NC |
10825 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
10826 | + canon_dirlen | |
10827 | + strlen (".debug/") | |
dda8d76d | 10828 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 10829 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
10830 | #endif |
10831 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 10832 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 10833 | #endif |
24841daa NC |
10834 | + strlen (separate_filename) |
10835 | + 1); | |
10836 | if (debug_filename == NULL) | |
dda8d76d NC |
10837 | { |
10838 | warn (_("Out of memory")); | |
3391569f | 10839 | free (canon_dir); |
dda8d76d NC |
10840 | return NULL; |
10841 | } | |
10842 | ||
10843 | /* First try in the current directory. */ | |
24841daa NC |
10844 | sprintf (debug_filename, "%s", separate_filename); |
10845 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10846 | goto found; |
10847 | ||
10848 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
10849 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10850 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10851 | goto found; |
10852 | ||
10853 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
10854 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10855 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10856 | goto found; |
10857 | ||
10858 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
10859 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10860 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10861 | goto found; |
10862 | ||
10863 | #ifdef EXTRA_DEBUG_ROOT1 | |
10864 | /* Try the first extra debug file root. */ | |
24841daa NC |
10865 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10866 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 10867 | goto found; |
39f0547e NC |
10868 | |
10869 | /* Try the first extra debug file root. */ | |
10870 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
10871 | if (check_func (debug_filename, func_data)) | |
10872 | goto found; | |
dda8d76d NC |
10873 | #endif |
10874 | ||
10875 | #ifdef EXTRA_DEBUG_ROOT2 | |
10876 | /* Try the second extra debug file root. */ | |
24841daa NC |
10877 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10878 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10879 | goto found; |
10880 | #endif | |
10881 | ||
24841daa NC |
10882 | /* Then try in the global debug_filename directory. */ |
10883 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
10884 | dirlen = strlen (DEBUGDIR) - 1; |
10885 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
10886 | strcat (debug_filename, "/"); |
10887 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 10888 | |
24841daa | 10889 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
10890 | goto found; |
10891 | ||
301a9420 AM |
10892 | #if HAVE_LIBDEBUGINFOD |
10893 | { | |
10894 | char * tmp_filename; | |
10895 | ||
10896 | if (debuginfod_fetch_separate_debug_info (xlink, | |
10897 | & tmp_filename, | |
10898 | file)) | |
10899 | { | |
10900 | /* File successfully downloaded from server, replace | |
10901 | debug_filename with the file's path. */ | |
10902 | free (debug_filename); | |
10903 | debug_filename = tmp_filename; | |
10904 | goto found; | |
10905 | } | |
10906 | } | |
10907 | #endif | |
10908 | ||
dda8d76d NC |
10909 | /* Failed to find the file. */ |
10910 | warn (_("could not find separate debug file '%s'\n"), separate_filename); | |
24841daa | 10911 | warn (_("tried: %s\n"), debug_filename); |
dda8d76d NC |
10912 | |
10913 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa NC |
10914 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10915 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10916 | #endif |
10917 | ||
10918 | #ifdef EXTRA_DEBUG_ROOT1 | |
39f0547e NC |
10919 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); |
10920 | warn (_("tried: %s\n"), debug_filename); | |
10921 | ||
24841daa NC |
10922 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10923 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10924 | #endif |
10925 | ||
24841daa NC |
10926 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10927 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10928 | |
24841daa NC |
10929 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10930 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10931 | |
24841daa NC |
10932 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10933 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10934 | |
24841daa NC |
10935 | sprintf (debug_filename, "%s", separate_filename); |
10936 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10937 | |
301a9420 AM |
10938 | #if HAVE_LIBDEBUGINFOD |
10939 | { | |
10940 | char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR); | |
10941 | if (urls == NULL) | |
10942 | urls = ""; | |
10943 | ||
10944 | warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls); | |
10945 | } | |
10946 | #endif | |
10947 | ||
dda8d76d | 10948 | free (canon_dir); |
24841daa | 10949 | free (debug_filename); |
dda8d76d NC |
10950 | return NULL; |
10951 | ||
10952 | found: | |
10953 | free (canon_dir); | |
10954 | ||
24841daa NC |
10955 | void * debug_handle; |
10956 | ||
dda8d76d | 10957 | /* Now open the file.... */ |
24841daa | 10958 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 10959 | { |
24841daa NC |
10960 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
10961 | free (debug_filename); | |
ce139cd5 | 10962 | return NULL; |
dda8d76d NC |
10963 | } |
10964 | ||
10965 | /* FIXME: We do not check to see if there are any other separate debug info | |
10966 | files that would also match. */ | |
10967 | ||
24841daa NC |
10968 | printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debug_filename); |
10969 | add_separate_debug_file (debug_filename, debug_handle); | |
dda8d76d | 10970 | |
24841daa | 10971 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 10972 | the structure returned by open_debug_file(). */ |
24841daa | 10973 | return debug_handle; |
dda8d76d NC |
10974 | } |
10975 | ||
d85bf2ba NC |
10976 | /* Attempt to load a separate dwarf object file. */ |
10977 | ||
10978 | static void * | |
24841daa | 10979 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 10980 | { |
24841daa NC |
10981 | char * separate_filename; |
10982 | void * separate_handle; | |
d85bf2ba NC |
10983 | |
10984 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
24841daa NC |
10985 | separate_filename = concat (dir, "/", name, NULL); |
10986 | if (separate_filename == NULL) | |
d85bf2ba NC |
10987 | { |
10988 | warn (_("Out of memory allocating dwo filename\n")); | |
10989 | return NULL; | |
10990 | } | |
10991 | ||
24841daa | 10992 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 10993 | { |
24841daa NC |
10994 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
10995 | free (separate_filename); | |
d85bf2ba NC |
10996 | return NULL; |
10997 | } | |
10998 | ||
10999 | /* FIXME: We should check the dwo_id. */ | |
11000 | ||
24841daa NC |
11001 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
11002 | add_separate_debug_file (separate_filename, separate_handle); | |
11003 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
11004 | return separate_handle; | |
d85bf2ba NC |
11005 | } |
11006 | ||
ce139cd5 NC |
11007 | /* Load a debuglink section and/or a debugaltlink section, if either are present. |
11008 | Recursively check the loaded files for more of these sections. | |
11009 | FIXME: Should also check for DWO_* entries in the newlu loaded files. */ | |
11010 | ||
11011 | static void | |
11012 | check_for_and_load_links (void * file, const char * filename) | |
11013 | { | |
11014 | void * handle = NULL; | |
11015 | ||
11016 | if (load_debug_section (gnu_debugaltlink, file)) | |
11017 | { | |
11018 | Build_id_data build_id_data; | |
11019 | ||
11020 | handle = load_separate_debug_info (filename, | |
11021 | & debug_displays[gnu_debugaltlink].section, | |
11022 | parse_gnu_debugaltlink, | |
11023 | check_gnu_debugaltlink, | |
11024 | & build_id_data, | |
11025 | file); | |
11026 | if (handle) | |
11027 | { | |
11028 | assert (handle == first_separate_info->handle); | |
11029 | check_for_and_load_links (first_separate_info->handle, | |
11030 | first_separate_info->filename); | |
11031 | } | |
11032 | } | |
11033 | ||
11034 | if (load_debug_section (gnu_debuglink, file)) | |
11035 | { | |
11036 | unsigned long crc32; | |
11037 | ||
11038 | handle = load_separate_debug_info (filename, | |
11039 | & debug_displays[gnu_debuglink].section, | |
11040 | parse_gnu_debuglink, | |
11041 | check_gnu_debuglink, | |
11042 | & crc32, | |
11043 | file); | |
11044 | if (handle) | |
11045 | { | |
11046 | assert (handle == first_separate_info->handle); | |
11047 | check_for_and_load_links (first_separate_info->handle, | |
11048 | first_separate_info->filename); | |
11049 | } | |
11050 | } | |
11051 | } | |
11052 | ||
24841daa NC |
11053 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
11054 | Returns TRUE if any were found, FALSE otherwise. | |
11055 | If TRUE is returned then the linked list starting at first_separate_info | |
11056 | will be populated with open file handles. */ | |
dda8d76d | 11057 | |
24841daa NC |
11058 | bfd_boolean |
11059 | load_separate_debug_files (void * file, const char * filename) | |
dda8d76d | 11060 | { |
8de3a6e2 NC |
11061 | /* Skip this operation if we are not interested in debug links. */ |
11062 | if (! do_follow_links && ! do_debug_links) | |
24841daa | 11063 | return FALSE; |
8de3a6e2 | 11064 | |
24841daa | 11065 | /* See if there are any dwo links. */ |
d85bf2ba NC |
11066 | if (load_debug_section (str, file) |
11067 | && load_debug_section (abbrev, file) | |
11068 | && load_debug_section (info, file)) | |
11069 | { | |
24841daa | 11070 | free_dwo_info (); |
d85bf2ba NC |
11071 | |
11072 | if (process_debug_info (& debug_displays[info].section, file, abbrev, TRUE, FALSE)) | |
11073 | { | |
24841daa NC |
11074 | bfd_boolean introduced = FALSE; |
11075 | dwo_info * dwinfo; | |
11076 | const char * dir = NULL; | |
11077 | const char * id = NULL; | |
11078 | ||
11079 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 11080 | { |
24841daa | 11081 | switch (dwinfo->type) |
d85bf2ba | 11082 | { |
24841daa NC |
11083 | case DWO_NAME: |
11084 | if (do_debug_links) | |
11085 | { | |
11086 | if (! introduced) | |
11087 | { | |
11088 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
11089 | debug_displays [info].section.uncompressed_name); | |
11090 | introduced = TRUE; | |
11091 | } | |
d85bf2ba | 11092 | |
24841daa NC |
11093 | printf (_(" Name: %s\n"), dwinfo->value); |
11094 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); | |
11095 | if (id != NULL) | |
11096 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
11097 | else | |
11098 | printf (_(" ID: <unknown>\n")); | |
11099 | printf ("\n\n"); | |
11100 | } | |
11101 | ||
11102 | if (do_follow_links) | |
11103 | load_dwo_file (filename, dwinfo->value, dir, id); | |
11104 | break; | |
11105 | ||
11106 | case DWO_DIR: | |
11107 | dir = dwinfo->value; | |
11108 | break; | |
11109 | ||
11110 | case DWO_ID: | |
11111 | id = dwinfo->value; | |
11112 | break; | |
11113 | ||
11114 | default: | |
11115 | error (_("Unexpected DWO INFO type")); | |
11116 | break; | |
11117 | } | |
d85bf2ba NC |
11118 | } |
11119 | } | |
11120 | } | |
11121 | ||
dda8d76d | 11122 | if (! do_follow_links) |
8de3a6e2 NC |
11123 | /* The other debug links will be displayed by display_debug_links() |
11124 | so we do not need to do any further processing here. */ | |
24841daa | 11125 | return FALSE; |
dda8d76d NC |
11126 | |
11127 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
dda8d76d | 11128 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ |
d85bf2ba | 11129 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 11130 | |
ce139cd5 | 11131 | check_for_and_load_links (file, filename); |
24841daa NC |
11132 | if (first_separate_info != NULL) |
11133 | return TRUE; | |
11134 | ||
dda8d76d | 11135 | do_follow_links = 0; |
24841daa | 11136 | return FALSE; |
dda8d76d NC |
11137 | } |
11138 | ||
19e6b90e L |
11139 | void |
11140 | free_debug_memory (void) | |
11141 | { | |
3f5e193b | 11142 | unsigned int i; |
19e6b90e | 11143 | |
bcd213b2 | 11144 | free_all_abbrevs (); |
19e6b90e | 11145 | |
bcd213b2 NC |
11146 | free (cu_abbrev_map); |
11147 | cu_abbrev_map = NULL; | |
11148 | next_free_abbrev_map_entry = 0; | |
11149 | ||
19e6b90e | 11150 | for (i = 0; i < max; i++) |
3f5e193b | 11151 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 11152 | |
cc86f28f | 11153 | if (debug_information != NULL) |
19e6b90e | 11154 | { |
82fcdb39 | 11155 | for (i = 0; i < alloc_num_debug_info_entries; i++) |
19e6b90e | 11156 | { |
82fcdb39 | 11157 | if (debug_information [i].max_loc_offsets) |
19e6b90e | 11158 | { |
82fcdb39 AM |
11159 | free (debug_information [i].loc_offsets); |
11160 | free (debug_information [i].have_frame_base); | |
19e6b90e | 11161 | } |
82fcdb39 AM |
11162 | if (debug_information [i].max_range_lists) |
11163 | free (debug_information [i].range_lists); | |
19e6b90e L |
11164 | } |
11165 | free (debug_information); | |
11166 | debug_information = NULL; | |
82b1b41b | 11167 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 11168 | } |
dda8d76d | 11169 | |
24841daa NC |
11170 | separate_info * d; |
11171 | separate_info * next; | |
dda8d76d | 11172 | |
24841daa NC |
11173 | for (d = first_separate_info; d != NULL; d = next) |
11174 | { | |
11175 | close_debug_file (d->handle); | |
11176 | free ((void *) d->filename); | |
11177 | next = d->next; | |
11178 | free ((void *) d); | |
dda8d76d | 11179 | } |
24841daa NC |
11180 | first_separate_info = NULL; |
11181 | ||
11182 | free_dwo_info (); | |
19e6b90e L |
11183 | } |
11184 | ||
4cb93e3b TG |
11185 | void |
11186 | dwarf_select_sections_by_names (const char *names) | |
11187 | { | |
11188 | typedef struct | |
11189 | { | |
11190 | const char * option; | |
11191 | int * variable; | |
f9f0e732 | 11192 | int val; |
4cb93e3b TG |
11193 | } |
11194 | debug_dump_long_opts; | |
11195 | ||
11196 | static const debug_dump_long_opts opts_table [] = | |
11197 | { | |
11198 | /* Please keep this table alpha- sorted. */ | |
11199 | { "Ranges", & do_debug_ranges, 1 }, | |
11200 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 11201 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 11202 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
11203 | { "cu_index", & do_debug_cu_index, 1 }, |
11204 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 11205 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
11206 | { "frames", & do_debug_frames, 1 }, |
11207 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
11208 | /* The special .gdb_index section. */ |
11209 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
11210 | { "info", & do_debug_info, 1 }, |
11211 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 11212 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
11213 | { "loc", & do_debug_loc, 1 }, |
11214 | { "macro", & do_debug_macinfo, 1 }, | |
11215 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 11216 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 11217 | /* This entry is for compatibility |
4cb93e3b TG |
11218 | with earlier versions of readelf. */ |
11219 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 11220 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 11221 | { "str", & do_debug_str, 1 }, |
e4b7104b | 11222 | { "str-offsets", & do_debug_str_offsets, 1 }, |
6f875884 TG |
11223 | /* These trace_* sections are used by Itanium VMS. */ |
11224 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
11225 | { "trace_aranges", & do_trace_aranges, 1 }, | |
11226 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
11227 | { NULL, NULL, 0 } |
11228 | }; | |
11229 | ||
11230 | const char *p; | |
467c65bc | 11231 | |
4cb93e3b TG |
11232 | p = names; |
11233 | while (*p) | |
11234 | { | |
11235 | const debug_dump_long_opts * entry; | |
467c65bc | 11236 | |
4cb93e3b TG |
11237 | for (entry = opts_table; entry->option; entry++) |
11238 | { | |
11239 | size_t len = strlen (entry->option); | |
467c65bc | 11240 | |
4cb93e3b TG |
11241 | if (strncmp (p, entry->option, len) == 0 |
11242 | && (p[len] == ',' || p[len] == '\0')) | |
11243 | { | |
11244 | * entry->variable |= entry->val; | |
467c65bc | 11245 | |
4cb93e3b TG |
11246 | /* The --debug-dump=frames-interp option also |
11247 | enables the --debug-dump=frames option. */ | |
11248 | if (do_debug_frames_interp) | |
11249 | do_debug_frames = 1; | |
11250 | ||
11251 | p += len; | |
11252 | break; | |
11253 | } | |
11254 | } | |
467c65bc | 11255 | |
4cb93e3b TG |
11256 | if (entry->option == NULL) |
11257 | { | |
11258 | warn (_("Unrecognized debug option '%s'\n"), p); | |
11259 | p = strchr (p, ','); | |
11260 | if (p == NULL) | |
11261 | break; | |
11262 | } | |
467c65bc | 11263 | |
4cb93e3b TG |
11264 | if (*p == ',') |
11265 | p++; | |
11266 | } | |
11267 | } | |
11268 | ||
11269 | void | |
11270 | dwarf_select_sections_by_letters (const char *letters) | |
11271 | { | |
91d6fa6a | 11272 | unsigned int lindex = 0; |
4cb93e3b | 11273 | |
91d6fa6a NC |
11274 | while (letters[lindex]) |
11275 | switch (letters[lindex++]) | |
4cb93e3b | 11276 | { |
dda8d76d NC |
11277 | case 'A': do_debug_addr = 1; break; |
11278 | case 'a': do_debug_abbrevs = 1; break; | |
11279 | case 'c': do_debug_cu_index = 1; break; | |
11280 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
11281 | case 'f': do_debug_frames = 1; break; | |
11282 | case 'g': do_gdb_index = 1; break; | |
11283 | case 'i': do_debug_info = 1; break; | |
11284 | case 'K': do_follow_links = 1; break; | |
11285 | case 'k': do_debug_links = 1; break; | |
11286 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
11287 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
11288 | case 'm': do_debug_macinfo = 1; break; | |
e4b7104b | 11289 | case 'O': do_debug_str_offsets = 1; break; |
dda8d76d NC |
11290 | case 'o': do_debug_loc = 1; break; |
11291 | case 'p': do_debug_pubnames = 1; break; | |
11292 | case 'R': do_debug_ranges = 1; break; | |
11293 | case 'r': do_debug_aranges = 1; break; | |
11294 | case 's': do_debug_str = 1; break; | |
11295 | case 'T': do_trace_aranges = 1; break; | |
11296 | case 't': do_debug_pubtypes = 1; break; | |
11297 | case 'U': do_trace_info = 1; break; | |
11298 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 11299 | |
4cb93e3b | 11300 | default: |
7cc78d07 | 11301 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
11302 | break; |
11303 | } | |
11304 | } | |
11305 | ||
11306 | void | |
11307 | dwarf_select_sections_all (void) | |
11308 | { | |
11309 | do_debug_info = 1; | |
11310 | do_debug_abbrevs = 1; | |
11311 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
11312 | do_debug_pubnames = 1; | |
f9f0e732 | 11313 | do_debug_pubtypes = 1; |
4cb93e3b TG |
11314 | do_debug_aranges = 1; |
11315 | do_debug_ranges = 1; | |
11316 | do_debug_frames = 1; | |
11317 | do_debug_macinfo = 1; | |
11318 | do_debug_str = 1; | |
11319 | do_debug_loc = 1; | |
5bbdf3d5 | 11320 | do_gdb_index = 1; |
6f875884 TG |
11321 | do_trace_info = 1; |
11322 | do_trace_abbrevs = 1; | |
11323 | do_trace_aranges = 1; | |
657d0d47 CC |
11324 | do_debug_addr = 1; |
11325 | do_debug_cu_index = 1; | |
dda8d76d NC |
11326 | do_follow_links = 1; |
11327 | do_debug_links = 1; | |
e4b7104b | 11328 | do_debug_str_offsets = 1; |
4cb93e3b TG |
11329 | } |
11330 | ||
dda8d76d NC |
11331 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL |
11332 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL | |
11333 | ||
11334 | /* N.B. The order here must match the order in section_display_enum. */ | |
11335 | ||
19e6b90e L |
11336 | struct dwarf_section_display debug_displays[] = |
11337 | { | |
dda8d76d NC |
11338 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, |
11339 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE }, | |
11340 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
11341 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE }, | |
11342 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
11343 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE }, | |
11344 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, | |
11345 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
11346 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
11347 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
11348 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
11349 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
11350 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
11351 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
11352 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE }, | |
11353 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, | |
11354 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
11355 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
11356 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
11357 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
11358 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE }, | |
11359 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
11360 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE }, | |
11361 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE }, | |
11362 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE }, | |
11363 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE }, | |
11364 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE }, | |
11365 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE }, | |
11366 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
11367 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE }, | |
11368 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
11369 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
11370 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
11371 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
11372 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE }, | |
e4b7104b NC |
11373 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, TRUE }, |
11374 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, TRUE }, | |
dda8d76d NC |
11375 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE }, |
11376 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
11377 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
11378 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
11379 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
11380 | /* Separate debug info files can containt their own .debug_str section, | |
11381 | and this might be in *addition* to a .debug_str section already present | |
11382 | in the main file. Hence we need to have two entries for .debug_str. */ | |
11383 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
19e6b90e | 11384 | }; |
b451e98a JK |
11385 | |
11386 | /* A static assertion. */ | |
11387 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |