]>
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. */ | |
852 | typedef struct abbrev_attr | |
853 | { | |
854 | unsigned long attribute; | |
855 | unsigned long form; | |
77145576 | 856 | bfd_signed_vma implicit_const; |
19e6b90e L |
857 | struct abbrev_attr *next; |
858 | } | |
859 | abbrev_attr; | |
860 | ||
861 | typedef struct abbrev_entry | |
862 | { | |
863 | unsigned long entry; | |
864 | unsigned long tag; | |
865 | int children; | |
866 | struct abbrev_attr *first_attr; | |
867 | struct abbrev_attr *last_attr; | |
868 | struct abbrev_entry *next; | |
869 | } | |
870 | abbrev_entry; | |
871 | ||
872 | static abbrev_entry *first_abbrev = NULL; | |
873 | static abbrev_entry *last_abbrev = NULL; | |
874 | ||
875 | static void | |
876 | free_abbrevs (void) | |
877 | { | |
91d6fa6a | 878 | abbrev_entry *abbrv; |
19e6b90e | 879 | |
91d6fa6a | 880 | for (abbrv = first_abbrev; abbrv;) |
19e6b90e | 881 | { |
91d6fa6a | 882 | abbrev_entry *next_abbrev = abbrv->next; |
19e6b90e L |
883 | abbrev_attr *attr; |
884 | ||
91d6fa6a | 885 | for (attr = abbrv->first_attr; attr;) |
19e6b90e | 886 | { |
91d6fa6a | 887 | abbrev_attr *next_attr = attr->next; |
19e6b90e L |
888 | |
889 | free (attr); | |
91d6fa6a | 890 | attr = next_attr; |
19e6b90e L |
891 | } |
892 | ||
91d6fa6a NC |
893 | free (abbrv); |
894 | abbrv = next_abbrev; | |
19e6b90e L |
895 | } |
896 | ||
897 | last_abbrev = first_abbrev = NULL; | |
898 | } | |
899 | ||
900 | static void | |
901 | add_abbrev (unsigned long number, unsigned long tag, int children) | |
902 | { | |
903 | abbrev_entry *entry; | |
904 | ||
3f5e193b | 905 | entry = (abbrev_entry *) malloc (sizeof (*entry)); |
19e6b90e L |
906 | if (entry == NULL) |
907 | /* ugg */ | |
908 | return; | |
909 | ||
910 | entry->entry = number; | |
911 | entry->tag = tag; | |
912 | entry->children = children; | |
913 | entry->first_attr = NULL; | |
914 | entry->last_attr = NULL; | |
915 | entry->next = NULL; | |
916 | ||
917 | if (first_abbrev == NULL) | |
918 | first_abbrev = entry; | |
919 | else | |
920 | last_abbrev->next = entry; | |
921 | ||
922 | last_abbrev = entry; | |
923 | } | |
924 | ||
925 | static void | |
77145576 JK |
926 | add_abbrev_attr (unsigned long attribute, unsigned long form, |
927 | bfd_signed_vma implicit_const) | |
19e6b90e L |
928 | { |
929 | abbrev_attr *attr; | |
930 | ||
3f5e193b | 931 | attr = (abbrev_attr *) malloc (sizeof (*attr)); |
19e6b90e L |
932 | if (attr == NULL) |
933 | /* ugg */ | |
934 | return; | |
935 | ||
936 | attr->attribute = attribute; | |
937 | attr->form = form; | |
77145576 | 938 | attr->implicit_const = implicit_const; |
19e6b90e L |
939 | attr->next = NULL; |
940 | ||
941 | if (last_abbrev->first_attr == NULL) | |
942 | last_abbrev->first_attr = attr; | |
943 | else | |
944 | last_abbrev->last_attr->next = attr; | |
945 | ||
946 | last_abbrev->last_attr = attr; | |
947 | } | |
948 | ||
949 | /* Processes the (partial) contents of a .debug_abbrev section. | |
950 | Returns NULL if the end of the section was encountered. | |
951 | Returns the address after the last byte read if the end of | |
952 | an abbreviation set was found. */ | |
953 | ||
954 | static unsigned char * | |
955 | process_abbrev_section (unsigned char *start, unsigned char *end) | |
956 | { | |
957 | if (first_abbrev != NULL) | |
958 | return NULL; | |
959 | ||
960 | while (start < end) | |
961 | { | |
19e6b90e L |
962 | unsigned long entry; |
963 | unsigned long tag; | |
964 | unsigned long attribute; | |
965 | int children; | |
966 | ||
cd30bcef | 967 | READ_ULEB (entry, start, end); |
19e6b90e L |
968 | |
969 | /* A single zero is supposed to end the section according | |
970 | to the standard. If there's more, then signal that to | |
971 | the caller. */ | |
f6f0e17b NC |
972 | if (start == end) |
973 | return NULL; | |
19e6b90e | 974 | if (entry == 0) |
f6f0e17b | 975 | return start; |
19e6b90e | 976 | |
cd30bcef | 977 | READ_ULEB (tag, start, end); |
f6f0e17b NC |
978 | if (start == end) |
979 | return NULL; | |
19e6b90e L |
980 | |
981 | children = *start++; | |
982 | ||
983 | add_abbrev (entry, tag, children); | |
984 | ||
985 | do | |
986 | { | |
987 | unsigned long form; | |
77145576 JK |
988 | /* Initialize it due to a false compiler warning. */ |
989 | bfd_signed_vma implicit_const = -1; | |
19e6b90e | 990 | |
cd30bcef | 991 | READ_ULEB (attribute, start, end); |
f6f0e17b NC |
992 | if (start == end) |
993 | break; | |
19e6b90e | 994 | |
cd30bcef | 995 | READ_ULEB (form, start, end); |
f6f0e17b NC |
996 | if (start == end) |
997 | break; | |
19e6b90e | 998 | |
77145576 JK |
999 | if (form == DW_FORM_implicit_const) |
1000 | { | |
cd30bcef | 1001 | READ_SLEB (implicit_const, start, end); |
77145576 JK |
1002 | if (start == end) |
1003 | break; | |
1004 | } | |
1005 | ||
1006 | add_abbrev_attr (attribute, form, implicit_const); | |
19e6b90e L |
1007 | } |
1008 | while (attribute != 0); | |
1009 | } | |
1010 | ||
399c99f7 L |
1011 | /* Report the missing single zero which ends the section. */ |
1012 | error (_(".debug_abbrev section not zero terminated\n")); | |
1013 | ||
19e6b90e L |
1014 | return NULL; |
1015 | } | |
1016 | ||
a19c41a7 | 1017 | static const char * |
19e6b90e L |
1018 | get_TAG_name (unsigned long tag) |
1019 | { | |
04914e37 | 1020 | const char *name = get_DW_TAG_name ((unsigned int) tag); |
a19c41a7 TT |
1021 | |
1022 | if (name == NULL) | |
19e6b90e | 1023 | { |
a19c41a7 | 1024 | static char buffer[100]; |
19e6b90e | 1025 | |
04914e37 NC |
1026 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
1027 | snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag); | |
1028 | else | |
1029 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag); | |
a19c41a7 | 1030 | return buffer; |
19e6b90e | 1031 | } |
a19c41a7 TT |
1032 | |
1033 | return name; | |
19e6b90e L |
1034 | } |
1035 | ||
a19c41a7 | 1036 | static const char * |
19e6b90e L |
1037 | get_FORM_name (unsigned long form) |
1038 | { | |
399c99f7 | 1039 | const char *name; |
bf5117e3 | 1040 | |
399c99f7 L |
1041 | if (form == 0) |
1042 | return "DW_FORM value: 0"; | |
a19c41a7 | 1043 | |
399c99f7 | 1044 | name = get_DW_FORM_name (form); |
a19c41a7 | 1045 | if (name == NULL) |
19e6b90e | 1046 | { |
a19c41a7 | 1047 | static char buffer[100]; |
19e6b90e | 1048 | |
a19c41a7 TT |
1049 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
1050 | return buffer; | |
19e6b90e | 1051 | } |
a19c41a7 TT |
1052 | |
1053 | return name; | |
19e6b90e L |
1054 | } |
1055 | ||
61364358 JK |
1056 | static const char * |
1057 | get_IDX_name (unsigned long idx) | |
1058 | { | |
1059 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
1060 | ||
1061 | if (name == NULL) | |
1062 | { | |
1063 | static char buffer[100]; | |
1064 | ||
1065 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1066 | return buffer; | |
1067 | } | |
1068 | ||
1069 | return name; | |
1070 | } | |
1071 | ||
19e6b90e | 1072 | static unsigned char * |
0c588247 NC |
1073 | display_block (unsigned char *data, |
1074 | dwarf_vma length, | |
ef0b5f1c | 1075 | const unsigned char * const end, char delimiter) |
19e6b90e | 1076 | { |
0c588247 NC |
1077 | dwarf_vma maxlen; |
1078 | ||
ef0b5f1c | 1079 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
1080 | if (data > end) |
1081 | return (unsigned char *) end; | |
19e6b90e | 1082 | |
0c588247 NC |
1083 | maxlen = (dwarf_vma) (end - data); |
1084 | length = length > maxlen ? maxlen : length; | |
1085 | ||
19e6b90e L |
1086 | while (length --) |
1087 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1088 | ||
1089 | return data; | |
1090 | } | |
1091 | ||
1092 | static int | |
1093 | decode_location_expression (unsigned char * data, | |
1094 | unsigned int pointer_size, | |
b7807392 JJ |
1095 | unsigned int offset_size, |
1096 | int dwarf_version, | |
467c65bc NC |
1097 | dwarf_vma length, |
1098 | dwarf_vma cu_offset, | |
f1c4cc75 | 1099 | struct dwarf_section * section) |
19e6b90e L |
1100 | { |
1101 | unsigned op; | |
467c65bc | 1102 | dwarf_vma uvalue; |
0c588247 | 1103 | dwarf_signed_vma svalue; |
19e6b90e L |
1104 | unsigned char *end = data + length; |
1105 | int need_frame_base = 0; | |
1106 | ||
1107 | while (data < end) | |
1108 | { | |
1109 | op = *data++; | |
1110 | ||
1111 | switch (op) | |
1112 | { | |
1113 | case DW_OP_addr: | |
0c588247 NC |
1114 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1115 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1116 | break; |
1117 | case DW_OP_deref: | |
1118 | printf ("DW_OP_deref"); | |
1119 | break; | |
1120 | case DW_OP_const1u: | |
0c588247 NC |
1121 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1122 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1123 | break; |
1124 | case DW_OP_const1s: | |
0c588247 NC |
1125 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1126 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1127 | break; |
1128 | case DW_OP_const2u: | |
87bc83b3 | 1129 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1130 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1131 | break; |
1132 | case DW_OP_const2s: | |
0c588247 NC |
1133 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1134 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1135 | break; |
1136 | case DW_OP_const4u: | |
0c588247 NC |
1137 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1138 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1139 | break; |
1140 | case DW_OP_const4s: | |
0c588247 NC |
1141 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1142 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1143 | break; |
1144 | case DW_OP_const8u: | |
0c588247 NC |
1145 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1146 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1147 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1148 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1149 | break; |
1150 | case DW_OP_const8s: | |
0c588247 NC |
1151 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1152 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1153 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1154 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1155 | break; |
1156 | case DW_OP_constu: | |
cd30bcef AM |
1157 | READ_ULEB (uvalue, data, end); |
1158 | printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1159 | break; |
1160 | case DW_OP_consts: | |
cd30bcef AM |
1161 | READ_SLEB (svalue, data, end); |
1162 | printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1163 | break; |
1164 | case DW_OP_dup: | |
1165 | printf ("DW_OP_dup"); | |
1166 | break; | |
1167 | case DW_OP_drop: | |
1168 | printf ("DW_OP_drop"); | |
1169 | break; | |
1170 | case DW_OP_over: | |
1171 | printf ("DW_OP_over"); | |
1172 | break; | |
1173 | case DW_OP_pick: | |
0c588247 NC |
1174 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1175 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1176 | break; |
1177 | case DW_OP_swap: | |
1178 | printf ("DW_OP_swap"); | |
1179 | break; | |
1180 | case DW_OP_rot: | |
1181 | printf ("DW_OP_rot"); | |
1182 | break; | |
1183 | case DW_OP_xderef: | |
1184 | printf ("DW_OP_xderef"); | |
1185 | break; | |
1186 | case DW_OP_abs: | |
1187 | printf ("DW_OP_abs"); | |
1188 | break; | |
1189 | case DW_OP_and: | |
1190 | printf ("DW_OP_and"); | |
1191 | break; | |
1192 | case DW_OP_div: | |
1193 | printf ("DW_OP_div"); | |
1194 | break; | |
1195 | case DW_OP_minus: | |
1196 | printf ("DW_OP_minus"); | |
1197 | break; | |
1198 | case DW_OP_mod: | |
1199 | printf ("DW_OP_mod"); | |
1200 | break; | |
1201 | case DW_OP_mul: | |
1202 | printf ("DW_OP_mul"); | |
1203 | break; | |
1204 | case DW_OP_neg: | |
1205 | printf ("DW_OP_neg"); | |
1206 | break; | |
1207 | case DW_OP_not: | |
1208 | printf ("DW_OP_not"); | |
1209 | break; | |
1210 | case DW_OP_or: | |
1211 | printf ("DW_OP_or"); | |
1212 | break; | |
1213 | case DW_OP_plus: | |
1214 | printf ("DW_OP_plus"); | |
1215 | break; | |
1216 | case DW_OP_plus_uconst: | |
cd30bcef AM |
1217 | READ_ULEB (uvalue, data, end); |
1218 | printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1219 | break; |
1220 | case DW_OP_shl: | |
1221 | printf ("DW_OP_shl"); | |
1222 | break; | |
1223 | case DW_OP_shr: | |
1224 | printf ("DW_OP_shr"); | |
1225 | break; | |
1226 | case DW_OP_shra: | |
1227 | printf ("DW_OP_shra"); | |
1228 | break; | |
1229 | case DW_OP_xor: | |
1230 | printf ("DW_OP_xor"); | |
1231 | break; | |
1232 | case DW_OP_bra: | |
0c588247 NC |
1233 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1234 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1235 | break; |
1236 | case DW_OP_eq: | |
1237 | printf ("DW_OP_eq"); | |
1238 | break; | |
1239 | case DW_OP_ge: | |
1240 | printf ("DW_OP_ge"); | |
1241 | break; | |
1242 | case DW_OP_gt: | |
1243 | printf ("DW_OP_gt"); | |
1244 | break; | |
1245 | case DW_OP_le: | |
1246 | printf ("DW_OP_le"); | |
1247 | break; | |
1248 | case DW_OP_lt: | |
1249 | printf ("DW_OP_lt"); | |
1250 | break; | |
1251 | case DW_OP_ne: | |
1252 | printf ("DW_OP_ne"); | |
1253 | break; | |
1254 | case DW_OP_skip: | |
0c588247 NC |
1255 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1256 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1257 | break; |
1258 | ||
1259 | case DW_OP_lit0: | |
1260 | case DW_OP_lit1: | |
1261 | case DW_OP_lit2: | |
1262 | case DW_OP_lit3: | |
1263 | case DW_OP_lit4: | |
1264 | case DW_OP_lit5: | |
1265 | case DW_OP_lit6: | |
1266 | case DW_OP_lit7: | |
1267 | case DW_OP_lit8: | |
1268 | case DW_OP_lit9: | |
1269 | case DW_OP_lit10: | |
1270 | case DW_OP_lit11: | |
1271 | case DW_OP_lit12: | |
1272 | case DW_OP_lit13: | |
1273 | case DW_OP_lit14: | |
1274 | case DW_OP_lit15: | |
1275 | case DW_OP_lit16: | |
1276 | case DW_OP_lit17: | |
1277 | case DW_OP_lit18: | |
1278 | case DW_OP_lit19: | |
1279 | case DW_OP_lit20: | |
1280 | case DW_OP_lit21: | |
1281 | case DW_OP_lit22: | |
1282 | case DW_OP_lit23: | |
1283 | case DW_OP_lit24: | |
1284 | case DW_OP_lit25: | |
1285 | case DW_OP_lit26: | |
1286 | case DW_OP_lit27: | |
1287 | case DW_OP_lit28: | |
1288 | case DW_OP_lit29: | |
1289 | case DW_OP_lit30: | |
1290 | case DW_OP_lit31: | |
1291 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1292 | break; | |
1293 | ||
1294 | case DW_OP_reg0: | |
1295 | case DW_OP_reg1: | |
1296 | case DW_OP_reg2: | |
1297 | case DW_OP_reg3: | |
1298 | case DW_OP_reg4: | |
1299 | case DW_OP_reg5: | |
1300 | case DW_OP_reg6: | |
1301 | case DW_OP_reg7: | |
1302 | case DW_OP_reg8: | |
1303 | case DW_OP_reg9: | |
1304 | case DW_OP_reg10: | |
1305 | case DW_OP_reg11: | |
1306 | case DW_OP_reg12: | |
1307 | case DW_OP_reg13: | |
1308 | case DW_OP_reg14: | |
1309 | case DW_OP_reg15: | |
1310 | case DW_OP_reg16: | |
1311 | case DW_OP_reg17: | |
1312 | case DW_OP_reg18: | |
1313 | case DW_OP_reg19: | |
1314 | case DW_OP_reg20: | |
1315 | case DW_OP_reg21: | |
1316 | case DW_OP_reg22: | |
1317 | case DW_OP_reg23: | |
1318 | case DW_OP_reg24: | |
1319 | case DW_OP_reg25: | |
1320 | case DW_OP_reg26: | |
1321 | case DW_OP_reg27: | |
1322 | case DW_OP_reg28: | |
1323 | case DW_OP_reg29: | |
1324 | case DW_OP_reg30: | |
1325 | case DW_OP_reg31: | |
18464d4d JK |
1326 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1327 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1328 | break; |
1329 | ||
1330 | case DW_OP_breg0: | |
1331 | case DW_OP_breg1: | |
1332 | case DW_OP_breg2: | |
1333 | case DW_OP_breg3: | |
1334 | case DW_OP_breg4: | |
1335 | case DW_OP_breg5: | |
1336 | case DW_OP_breg6: | |
1337 | case DW_OP_breg7: | |
1338 | case DW_OP_breg8: | |
1339 | case DW_OP_breg9: | |
1340 | case DW_OP_breg10: | |
1341 | case DW_OP_breg11: | |
1342 | case DW_OP_breg12: | |
1343 | case DW_OP_breg13: | |
1344 | case DW_OP_breg14: | |
1345 | case DW_OP_breg15: | |
1346 | case DW_OP_breg16: | |
1347 | case DW_OP_breg17: | |
1348 | case DW_OP_breg18: | |
1349 | case DW_OP_breg19: | |
1350 | case DW_OP_breg20: | |
1351 | case DW_OP_breg21: | |
1352 | case DW_OP_breg22: | |
1353 | case DW_OP_breg23: | |
1354 | case DW_OP_breg24: | |
1355 | case DW_OP_breg25: | |
1356 | case DW_OP_breg26: | |
1357 | case DW_OP_breg27: | |
1358 | case DW_OP_breg28: | |
1359 | case DW_OP_breg29: | |
1360 | case DW_OP_breg30: | |
1361 | case DW_OP_breg31: | |
cd30bcef AM |
1362 | READ_SLEB (svalue, data, end); |
1363 | printf ("DW_OP_breg%d (%s): %s", op - DW_OP_breg0, | |
1364 | regname (op - DW_OP_breg0, 1), dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1365 | break; |
1366 | ||
1367 | case DW_OP_regx: | |
cd30bcef | 1368 | READ_ULEB (uvalue, data, end); |
467c65bc NC |
1369 | printf ("DW_OP_regx: %s (%s)", |
1370 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1371 | break; |
1372 | case DW_OP_fbreg: | |
1373 | need_frame_base = 1; | |
cd30bcef AM |
1374 | READ_SLEB (svalue, data, end); |
1375 | printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1376 | break; |
1377 | case DW_OP_bregx: | |
cd30bcef AM |
1378 | READ_ULEB (uvalue, data, end); |
1379 | READ_SLEB (svalue, data, end); | |
467c65bc NC |
1380 | printf ("DW_OP_bregx: %s (%s) %s", |
1381 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
cd30bcef | 1382 | dwarf_vmatoa ("d", svalue)); |
19e6b90e L |
1383 | break; |
1384 | case DW_OP_piece: | |
cd30bcef AM |
1385 | READ_ULEB (uvalue, data, end); |
1386 | printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1387 | break; |
1388 | case DW_OP_deref_size: | |
0c588247 NC |
1389 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1390 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1391 | break; |
1392 | case DW_OP_xderef_size: | |
0c588247 NC |
1393 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1394 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1395 | break; |
1396 | case DW_OP_nop: | |
1397 | printf ("DW_OP_nop"); | |
1398 | break; | |
1399 | ||
1400 | /* DWARF 3 extensions. */ | |
1401 | case DW_OP_push_object_address: | |
1402 | printf ("DW_OP_push_object_address"); | |
1403 | break; | |
1404 | case DW_OP_call2: | |
d85bf2ba | 1405 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1406 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1407 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1408 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1409 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1410 | break; |
1411 | case DW_OP_call4: | |
d85bf2ba | 1412 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1413 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1414 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1415 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1416 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1417 | break; |
1418 | case DW_OP_call_ref: | |
d85bf2ba | 1419 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
e2a0d921 | 1420 | this ought to be an 8-byte wide computation. */ |
b7807392 JJ |
1421 | if (dwarf_version == -1) |
1422 | { | |
1423 | printf (_("(DW_OP_call_ref in frame info)")); | |
1424 | /* No way to tell where the next op is, so just bail. */ | |
1425 | return need_frame_base; | |
1426 | } | |
1427 | if (dwarf_version == 2) | |
1428 | { | |
0c588247 | 1429 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1430 | } |
1431 | else | |
1432 | { | |
0c588247 | 1433 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1434 | } |
0c588247 | 1435 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1436 | break; |
a87b0a59 NS |
1437 | case DW_OP_form_tls_address: |
1438 | printf ("DW_OP_form_tls_address"); | |
1439 | break; | |
e2a0d921 NC |
1440 | case DW_OP_call_frame_cfa: |
1441 | printf ("DW_OP_call_frame_cfa"); | |
1442 | break; | |
1443 | case DW_OP_bit_piece: | |
1444 | printf ("DW_OP_bit_piece: "); | |
cd30bcef AM |
1445 | READ_ULEB (uvalue, data, end); |
1446 | printf (_("size: %s "), dwarf_vmatoa ("u", uvalue)); | |
1447 | READ_ULEB (uvalue, data, end); | |
1448 | printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue)); | |
e2a0d921 | 1449 | break; |
19e6b90e | 1450 | |
3244e8f5 JJ |
1451 | /* DWARF 4 extensions. */ |
1452 | case DW_OP_stack_value: | |
1453 | printf ("DW_OP_stack_value"); | |
1454 | break; | |
1455 | ||
1456 | case DW_OP_implicit_value: | |
1457 | printf ("DW_OP_implicit_value"); | |
cd30bcef | 1458 | READ_ULEB (uvalue, data, end); |
ef0b5f1c | 1459 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1460 | break; |
1461 | ||
19e6b90e L |
1462 | /* GNU extensions. */ |
1463 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1464 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1465 | break; |
1466 | case DW_OP_GNU_uninit: | |
1467 | printf ("DW_OP_GNU_uninit"); | |
1468 | /* FIXME: Is there data associated with this OP ? */ | |
1469 | break; | |
f1c4cc75 RH |
1470 | case DW_OP_GNU_encoded_addr: |
1471 | { | |
6937bb54 | 1472 | int encoding = 0; |
f1c4cc75 | 1473 | dwarf_vma addr; |
467c65bc | 1474 | |
6937bb54 NC |
1475 | if (data < end) |
1476 | encoding = *data++; | |
041830e0 | 1477 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1478 | |
1479 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1480 | print_dwarf_vma (addr, pointer_size); | |
1481 | } | |
1482 | break; | |
bc0a77d2 | 1483 | case DW_OP_implicit_pointer: |
b7807392 | 1484 | case DW_OP_GNU_implicit_pointer: |
d85bf2ba | 1485 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
b7807392 JJ |
1486 | this ought to be an 8-byte wide computation. */ |
1487 | if (dwarf_version == -1) | |
1488 | { | |
bc0a77d2 JK |
1489 | printf (_("(%s in frame info)"), |
1490 | (op == DW_OP_implicit_pointer | |
1491 | ? "DW_OP_implicit_pointer" | |
1492 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1493 | /* No way to tell where the next op is, so just bail. */ |
1494 | return need_frame_base; | |
1495 | } | |
1496 | if (dwarf_version == 2) | |
1497 | { | |
0c588247 | 1498 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1499 | } |
1500 | else | |
1501 | { | |
0c588247 | 1502 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1503 | } |
cd30bcef | 1504 | READ_SLEB (svalue, data, end); |
bc0a77d2 JK |
1505 | printf ("%s: <0x%s> %s", |
1506 | (op == DW_OP_implicit_pointer | |
1507 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 | 1508 | dwarf_vmatoa ("x", uvalue), |
cd30bcef | 1509 | dwarf_vmatoa ("d", svalue)); |
b7807392 | 1510 | break; |
77145576 | 1511 | case DW_OP_entry_value: |
0892011d | 1512 | case DW_OP_GNU_entry_value: |
cd30bcef | 1513 | READ_ULEB (uvalue, data, end); |
058037d3 NC |
1514 | /* PR 17531: file: 0cc9cd00. */ |
1515 | if (uvalue > (dwarf_vma) (end - data)) | |
1516 | uvalue = end - data; | |
77145576 JK |
1517 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1518 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1519 | if (decode_location_expression (data, pointer_size, offset_size, |
1520 | dwarf_version, uvalue, | |
1521 | cu_offset, section)) | |
1522 | need_frame_base = 1; | |
1523 | putchar (')'); | |
1524 | data += uvalue; | |
6937bb54 NC |
1525 | if (data > end) |
1526 | data = end; | |
0892011d | 1527 | break; |
bc0a77d2 | 1528 | case DW_OP_const_type: |
0892011d | 1529 | case DW_OP_GNU_const_type: |
cd30bcef | 1530 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1531 | printf ("%s: <0x%s> ", |
1532 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1533 | : "DW_OP_GNU_const_type"), | |
0892011d | 1534 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1535 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1536 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1537 | break; |
bc0a77d2 | 1538 | case DW_OP_regval_type: |
0892011d | 1539 | case DW_OP_GNU_regval_type: |
cd30bcef | 1540 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1541 | printf ("%s: %s (%s)", |
1542 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1543 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1544 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
cd30bcef | 1545 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1546 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1547 | break; | |
bc0a77d2 | 1548 | case DW_OP_deref_type: |
0892011d | 1549 | case DW_OP_GNU_deref_type: |
0c588247 | 1550 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1551 | printf ("%s: %ld", |
1552 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1553 | : "DW_OP_GNU_deref_type"), | |
1554 | (long) uvalue); | |
cd30bcef | 1555 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1556 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1557 | break; | |
bc0a77d2 | 1558 | case DW_OP_convert: |
0892011d | 1559 | case DW_OP_GNU_convert: |
cd30bcef | 1560 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1561 | printf ("%s <0x%s>", |
1562 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1563 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1564 | break; |
bc0a77d2 | 1565 | case DW_OP_reinterpret: |
0892011d | 1566 | case DW_OP_GNU_reinterpret: |
cd30bcef | 1567 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1568 | printf ("%s <0x%s>", |
1569 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1570 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1571 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1572 | break; | |
1573 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1574 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1575 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1576 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1577 | break; |
b4eb7656 | 1578 | case DW_OP_GNU_addr_index: |
cd30bcef | 1579 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1580 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1581 | break; | |
1582 | case DW_OP_GNU_const_index: | |
cd30bcef | 1583 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1584 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1585 | break; | |
f384a1f0 KB |
1586 | case DW_OP_GNU_variable_value: |
1587 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1588 | this ought to be an 8-byte wide computation. */ | |
1589 | if (dwarf_version == -1) | |
1590 | { | |
1591 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1592 | /* No way to tell where the next op is, so just bail. */ | |
1593 | return need_frame_base; | |
1594 | } | |
1595 | if (dwarf_version == 2) | |
1596 | { | |
1597 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1598 | } | |
1599 | else | |
1600 | { | |
1601 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1602 | } | |
1603 | printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1604 | break; | |
e2a0d921 NC |
1605 | |
1606 | /* HP extensions. */ | |
1607 | case DW_OP_HP_is_value: | |
1608 | printf ("DW_OP_HP_is_value"); | |
1609 | /* FIXME: Is there data associated with this OP ? */ | |
1610 | break; | |
1611 | case DW_OP_HP_fltconst4: | |
1612 | printf ("DW_OP_HP_fltconst4"); | |
1613 | /* FIXME: Is there data associated with this OP ? */ | |
1614 | break; | |
1615 | case DW_OP_HP_fltconst8: | |
1616 | printf ("DW_OP_HP_fltconst8"); | |
1617 | /* FIXME: Is there data associated with this OP ? */ | |
1618 | break; | |
1619 | case DW_OP_HP_mod_range: | |
1620 | printf ("DW_OP_HP_mod_range"); | |
1621 | /* FIXME: Is there data associated with this OP ? */ | |
1622 | break; | |
1623 | case DW_OP_HP_unmod_range: | |
1624 | printf ("DW_OP_HP_unmod_range"); | |
1625 | /* FIXME: Is there data associated with this OP ? */ | |
1626 | break; | |
1627 | case DW_OP_HP_tls: | |
1628 | printf ("DW_OP_HP_tls"); | |
1629 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1630 | break; |
1631 | ||
35d60fe4 NC |
1632 | /* PGI (STMicroelectronics) extensions. */ |
1633 | case DW_OP_PGI_omp_thread_num: | |
1634 | /* Pushes the thread number for the current thread as it would be | |
1635 | returned by the standard OpenMP library function: | |
1636 | omp_get_thread_num(). The "current thread" is the thread for | |
1637 | which the expression is being evaluated. */ | |
1638 | printf ("DW_OP_PGI_omp_thread_num"); | |
1639 | break; | |
1640 | ||
19e6b90e L |
1641 | default: |
1642 | if (op >= DW_OP_lo_user | |
1643 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1644 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1645 | else |
0502a2b4 | 1646 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1647 | /* No way to tell where the next op is, so just bail. */ |
1648 | return need_frame_base; | |
1649 | } | |
1650 | ||
1651 | /* Separate the ops. */ | |
1652 | if (data < end) | |
1653 | printf ("; "); | |
1654 | } | |
1655 | ||
1656 | return need_frame_base; | |
1657 | } | |
1658 | ||
341f9135 CC |
1659 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1660 | This is used for DWARF package files. */ | |
1661 | ||
1662 | static struct cu_tu_set * | |
1663 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1664 | { | |
1665 | struct cu_tu_set *p; | |
1666 | unsigned int nsets; | |
1667 | unsigned int dw_sect; | |
1668 | ||
1669 | if (do_types) | |
1670 | { | |
1671 | p = tu_sets; | |
1672 | nsets = tu_count; | |
1673 | dw_sect = DW_SECT_TYPES; | |
1674 | } | |
1675 | else | |
1676 | { | |
1677 | p = cu_sets; | |
1678 | nsets = cu_count; | |
1679 | dw_sect = DW_SECT_INFO; | |
1680 | } | |
1681 | while (nsets > 0) | |
1682 | { | |
1683 | if (p->section_offsets [dw_sect] == cu_offset) | |
1684 | return p; | |
1685 | p++; | |
1686 | nsets--; | |
1687 | } | |
1688 | return NULL; | |
1689 | } | |
1690 | ||
a69c4772 NC |
1691 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1692 | static void | |
1693 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1694 | { | |
1695 | dwarf_vma tmp = * low_bits; | |
1696 | ||
1697 | tmp += inc; | |
1698 | ||
1699 | /* FIXME: There is probably a better way of handling this: | |
1700 | ||
1701 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1702 | type. Plus regardless of its size LOW_BITS is meant to | |
1703 | only hold 32-bits, so if there is overflow or wrap around | |
1704 | we must propagate into HIGH_BITS. */ | |
1705 | if (tmp < * low_bits) | |
1706 | { | |
1707 | ++ * high_bits; | |
1708 | } | |
1709 | else if (sizeof (tmp) > 8 | |
1710 | && (tmp >> 31) > 1) | |
1711 | { | |
1712 | ++ * high_bits; | |
1713 | tmp &= 0xFFFFFFFF; | |
1714 | } | |
1715 | ||
1716 | * low_bits = tmp; | |
1717 | } | |
1718 | ||
dda8d76d NC |
1719 | static const char * |
1720 | fetch_alt_indirect_string (dwarf_vma offset) | |
1721 | { | |
24841daa | 1722 | separate_info * i; |
dda8d76d NC |
1723 | |
1724 | if (! do_follow_links) | |
1725 | return ""; | |
1726 | ||
24841daa NC |
1727 | if (first_separate_info == NULL) |
1728 | return _("<no links available>"); | |
dda8d76d | 1729 | |
24841daa NC |
1730 | for (i = first_separate_info; i != NULL; i = i->next) |
1731 | { | |
1732 | struct dwarf_section * section; | |
1733 | const char * ret; | |
dda8d76d | 1734 | |
24841daa NC |
1735 | if (! load_debug_section (separate_debug_str, i->handle)) |
1736 | continue; | |
dda8d76d | 1737 | |
24841daa | 1738 | section = &debug_displays [separate_debug_str].section; |
dda8d76d | 1739 | |
24841daa NC |
1740 | if (section->start == NULL) |
1741 | continue; | |
dda8d76d | 1742 | |
24841daa NC |
1743 | if (offset >= section->size) |
1744 | continue; | |
1745 | ||
1746 | ret = (const char *) (section->start + offset); | |
1747 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1748 | NUL byte. Since our caller is expecting to receive a well formed C | |
1749 | string we test for the lack of a terminating byte here. */ | |
1750 | if (strnlen ((const char *) ret, section->size - offset) | |
1751 | == section->size - offset) | |
1752 | return _("<no NUL byte at end of alt .debug_str section>"); | |
1753 | ||
1754 | return ret; | |
1755 | } | |
1756 | ||
1757 | warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"), | |
1758 | dwarf_vmatoa ("x", offset)); | |
1759 | return _("<offset is too big>"); | |
dda8d76d NC |
1760 | } |
1761 | ||
d85bf2ba NC |
1762 | static const char * |
1763 | get_AT_name (unsigned long attribute) | |
1764 | { | |
1765 | const char *name; | |
1766 | ||
1767 | if (attribute == 0) | |
1768 | return "DW_AT value: 0"; | |
1769 | ||
1770 | /* One value is shared by the MIPS and HP extensions: */ | |
1771 | if (attribute == DW_AT_MIPS_fde) | |
1772 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1773 | ||
1774 | name = get_DW_AT_name (attribute); | |
1775 | ||
1776 | if (name == NULL) | |
1777 | { | |
1778 | static char buffer[100]; | |
1779 | ||
1780 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1781 | attribute); | |
1782 | return buffer; | |
1783 | } | |
1784 | ||
1785 | return name; | |
1786 | } | |
1787 | ||
24841daa NC |
1788 | static void |
1789 | add_dwo_info (const char * field, dwo_type type) | |
1790 | { | |
1791 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); | |
1792 | ||
1793 | dwinfo->type = type; | |
1794 | dwinfo->value = field; | |
1795 | dwinfo->next = first_dwo_info; | |
1796 | first_dwo_info = dwinfo; | |
1797 | } | |
1798 | ||
1799 | static void | |
1800 | add_dwo_name (const char * name) | |
1801 | { | |
1802 | add_dwo_info (name, DWO_NAME); | |
1803 | } | |
1804 | ||
1805 | static void | |
1806 | add_dwo_dir (const char * dir) | |
1807 | { | |
1808 | add_dwo_info (dir, DWO_DIR); | |
1809 | } | |
1810 | ||
1811 | static void | |
1812 | add_dwo_id (const char * id) | |
1813 | { | |
1814 | add_dwo_info (id, DWO_ID); | |
1815 | } | |
1816 | ||
1817 | static void | |
1818 | free_dwo_info (void) | |
1819 | { | |
1820 | dwo_info * dwinfo; | |
1821 | dwo_info * next; | |
1822 | ||
1823 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) | |
1824 | { | |
1825 | next = dwinfo->next; | |
1826 | free (dwinfo); | |
1827 | } | |
1828 | first_dwo_info = NULL; | |
1829 | } | |
1830 | ||
afc72f15 NC |
1831 | /* Ensure that START + UVALUE is less than END. |
1832 | Return an adjusted UVALUE if necessary to ensure this relationship. */ | |
1833 | ||
1834 | static inline dwarf_vma | |
1835 | check_uvalue (const unsigned char * start, | |
1836 | dwarf_vma uvalue, | |
1837 | const unsigned char * end) | |
1838 | { | |
1839 | dwarf_vma max_uvalue = end - start; | |
1840 | ||
afc72f15 NC |
1841 | /* See PR 17512: file: 008-103549-0.001:0.1. |
1842 | and PR 24829 for examples of where these tests are triggered. */ | |
a85eba51 | 1843 | if (uvalue > max_uvalue) |
afc72f15 NC |
1844 | { |
1845 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1846 | uvalue = max_uvalue; | |
1847 | } | |
1848 | ||
1849 | return uvalue; | |
1850 | } | |
1851 | ||
ec1b0fbb NC |
1852 | static unsigned char * |
1853 | skip_attr_bytes (unsigned long form, | |
1854 | unsigned char * data, | |
1855 | unsigned const char * end, | |
1856 | dwarf_vma pointer_size, | |
1857 | dwarf_vma offset_size, | |
1858 | int dwarf_version, | |
1859 | dwarf_vma * value_return) | |
1860 | { | |
cd30bcef AM |
1861 | dwarf_signed_vma svalue; |
1862 | dwarf_vma uvalue = 0; | |
ec1b0fbb NC |
1863 | |
1864 | * value_return = 0; | |
1865 | ||
1866 | switch (form) | |
1867 | { | |
1868 | case DW_FORM_ref_addr: | |
1869 | if (dwarf_version == 2) | |
1870 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1871 | else if (dwarf_version == 3 || dwarf_version == 4) | |
1872 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1873 | else | |
1874 | return NULL; | |
1875 | break; | |
1876 | ||
1877 | case DW_FORM_addr: | |
1878 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1879 | break; | |
1880 | ||
1881 | case DW_FORM_strp: | |
1882 | case DW_FORM_line_strp: | |
1883 | case DW_FORM_sec_offset: | |
1884 | case DW_FORM_GNU_ref_alt: | |
1885 | case DW_FORM_GNU_strp_alt: | |
1886 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1887 | break; | |
1888 | ||
1889 | case DW_FORM_flag_present: | |
1890 | uvalue = 1; | |
1891 | break; | |
1892 | ||
1893 | case DW_FORM_ref1: | |
1894 | case DW_FORM_flag: | |
1895 | case DW_FORM_data1: | |
1896 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
1897 | break; | |
1898 | ||
1899 | case DW_FORM_ref2: | |
1900 | case DW_FORM_data2: | |
1901 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); | |
1902 | break; | |
1903 | ||
1904 | case DW_FORM_ref4: | |
1905 | case DW_FORM_data4: | |
1906 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1907 | break; | |
1908 | ||
1909 | case DW_FORM_sdata: | |
cd30bcef AM |
1910 | READ_SLEB (svalue, data, end); |
1911 | uvalue = svalue; | |
ec1b0fbb NC |
1912 | break; |
1913 | ||
1914 | case DW_FORM_ref_udata: | |
1915 | case DW_FORM_udata: | |
1916 | case DW_FORM_GNU_str_index: | |
1917 | case DW_FORM_GNU_addr_index: | |
cd30bcef | 1918 | READ_ULEB (uvalue, data, end); |
ec1b0fbb NC |
1919 | break; |
1920 | ||
1921 | case DW_FORM_ref8: | |
1922 | case DW_FORM_data8: | |
1923 | data += 8; | |
1924 | break; | |
1925 | ||
1926 | case DW_FORM_data16: | |
1927 | data += 16; | |
1928 | break; | |
1929 | ||
1930 | case DW_FORM_string: | |
1931 | data += strnlen ((char *) data, end - data) + 1; | |
1932 | break; | |
1933 | ||
1934 | case DW_FORM_block: | |
1935 | case DW_FORM_exprloc: | |
cd30bcef | 1936 | READ_ULEB (uvalue, data, end); |
ec1b0fbb NC |
1937 | break; |
1938 | ||
1939 | case DW_FORM_block1: | |
1940 | SAFE_BYTE_GET (uvalue, data, 1, end); | |
1941 | data += 1 + uvalue; | |
1942 | break; | |
1943 | ||
1944 | case DW_FORM_block2: | |
1945 | SAFE_BYTE_GET (uvalue, data, 2, end); | |
1946 | data += 2 + uvalue; | |
1947 | break; | |
1948 | ||
1949 | case DW_FORM_block4: | |
1950 | SAFE_BYTE_GET (uvalue, data, 4, end); | |
1951 | data += 4 + uvalue; | |
1952 | break; | |
1953 | ||
1954 | case DW_FORM_ref_sig8: | |
1955 | data += 8; | |
1956 | break; | |
1957 | ||
1958 | case DW_FORM_indirect: | |
1959 | /* FIXME: Handle this form. */ | |
1960 | default: | |
1961 | return NULL; | |
1962 | } | |
1963 | ||
1964 | * value_return = uvalue; | |
1965 | if (data > end) | |
1966 | data = (unsigned char *) end; | |
1967 | return data; | |
1968 | } | |
1969 | ||
1970 | /* Return IS_SIGNED set to TRUE if the type at | |
1971 | DATA can be determined to be a signed type. */ | |
1972 | ||
1973 | static void | |
1974 | get_type_signedness (unsigned char * start, | |
1975 | unsigned char * data, | |
1976 | unsigned const char * end, | |
1977 | dwarf_vma pointer_size, | |
1978 | dwarf_vma offset_size, | |
1979 | int dwarf_version, | |
1980 | bfd_boolean * is_signed, | |
1981 | bfd_boolean is_nested) | |
1982 | { | |
1983 | unsigned long abbrev_number; | |
ec1b0fbb NC |
1984 | abbrev_entry * entry; |
1985 | abbrev_attr * attr; | |
1986 | ||
1987 | * is_signed = FALSE; | |
1988 | ||
cd30bcef | 1989 | READ_ULEB (abbrev_number, data, end); |
ec1b0fbb NC |
1990 | |
1991 | for (entry = first_abbrev; | |
1992 | entry != NULL && entry->entry != abbrev_number; | |
1993 | entry = entry->next) | |
1994 | continue; | |
1995 | ||
1996 | if (entry == NULL) | |
1997 | /* FIXME: Issue a warning ? */ | |
1998 | return; | |
1999 | ||
2000 | for (attr = entry->first_attr; | |
2001 | attr != NULL && attr->attribute; | |
2002 | attr = attr->next) | |
2003 | { | |
2004 | dwarf_vma uvalue = 0; | |
2005 | ||
2006 | data = skip_attr_bytes (attr->form, data, end, pointer_size, | |
2007 | offset_size, dwarf_version, & uvalue); | |
2008 | if (data == NULL) | |
2009 | return; | |
2010 | ||
2011 | switch (attr->attribute) | |
2012 | { | |
2013 | #if 0 /* FIXME: It would be nice to print the name of the type, | |
2014 | but this would mean updating a lot of binutils tests. */ | |
2015 | case DW_AT_name: | |
2016 | if (attr->form == DW_FORM_strp) | |
2017 | printf ("%s", fetch_indirect_string (uvalue)); | |
2018 | break; | |
2019 | #endif | |
2020 | case DW_AT_type: | |
2021 | /* Recurse. */ | |
2022 | if (is_nested) | |
2023 | { | |
2024 | /* FIXME: Warn - or is this expected ? | |
2025 | NB/ We need to avoid infinite recursion. */ | |
2026 | return; | |
2027 | } | |
b3fe587e AM |
2028 | if (uvalue >= (size_t) (end - start)) |
2029 | return; | |
ec1b0fbb NC |
2030 | get_type_signedness (start, start + uvalue, end, pointer_size, |
2031 | offset_size, dwarf_version, is_signed, TRUE); | |
2032 | break; | |
2033 | ||
2034 | case DW_AT_encoding: | |
2035 | /* Determine signness. */ | |
2036 | switch (uvalue) | |
2037 | { | |
2038 | case DW_ATE_address: | |
2039 | /* FIXME - some architectures have signed addresses. */ | |
2040 | case DW_ATE_boolean: | |
2041 | case DW_ATE_unsigned: | |
2042 | case DW_ATE_unsigned_char: | |
2043 | case DW_ATE_unsigned_fixed: | |
164cbceb | 2044 | case DW_ATE_CHERI_unsigned_intcap: |
ec1b0fbb NC |
2045 | * is_signed = FALSE; |
2046 | break; | |
2047 | ||
2048 | default: | |
2049 | case DW_ATE_complex_float: | |
2050 | case DW_ATE_float: | |
2051 | case DW_ATE_signed: | |
2052 | case DW_ATE_signed_char: | |
2053 | case DW_ATE_imaginary_float: | |
2054 | case DW_ATE_decimal_float: | |
2055 | case DW_ATE_signed_fixed: | |
164cbceb | 2056 | case DW_ATE_CHERI_signed_intcap: |
ec1b0fbb NC |
2057 | * is_signed = TRUE; |
2058 | break; | |
2059 | } | |
2060 | break; | |
2061 | } | |
2062 | } | |
2063 | } | |
2064 | ||
2065 | static void | |
2066 | read_and_print_leb128 (unsigned char * data, | |
2067 | unsigned int * bytes_read, | |
2068 | unsigned const char * end, | |
2069 | bfd_boolean is_signed) | |
2070 | { | |
cd30bcef AM |
2071 | int status; |
2072 | dwarf_vma val = read_leb128 (data, end, is_signed, bytes_read, &status); | |
2073 | if (status != 0) | |
1b513401 | 2074 | report_leb_status (status, __FILE__, __LINE__); |
ec1b0fbb | 2075 | else |
cd30bcef | 2076 | printf ("%s", dwarf_vmatoa (is_signed ? "d" : "u", val)); |
ec1b0fbb NC |
2077 | } |
2078 | ||
2079 | static void | |
2080 | display_discr_list (unsigned long form, | |
2081 | dwarf_vma uvalue, | |
2082 | unsigned char * data, | |
2083 | unsigned const char * end, | |
2084 | int level) | |
2085 | { | |
2086 | if (uvalue == 0) | |
2087 | { | |
2088 | printf ("[default]"); | |
2089 | return; | |
2090 | } | |
2091 | ||
2092 | switch (form) | |
2093 | { | |
2094 | case DW_FORM_block: | |
2095 | case DW_FORM_block1: | |
2096 | case DW_FORM_block2: | |
2097 | case DW_FORM_block4: | |
2098 | /* Move data pointer back to the start of the byte array. */ | |
2099 | data -= uvalue; | |
2100 | break; | |
2101 | default: | |
2102 | printf ("<corrupt>\n"); | |
2103 | warn (_("corrupt discr_list - not using a block form\n")); | |
2104 | return; | |
2105 | } | |
2106 | ||
2107 | if (uvalue < 2) | |
2108 | { | |
2109 | printf ("<corrupt>\n"); | |
2110 | warn (_("corrupt discr_list - block not long enough\n")); | |
2111 | return; | |
2112 | } | |
2113 | ||
2114 | bfd_boolean is_signed = | |
2115 | (level > 0 && level <= MAX_CU_NESTING) | |
2116 | ? level_type_signed [level - 1] : FALSE; | |
2117 | ||
2118 | printf ("("); | |
2119 | while (uvalue) | |
2120 | { | |
2121 | unsigned char discriminant; | |
2122 | unsigned int bytes_read; | |
2123 | ||
2124 | SAFE_BYTE_GET (discriminant, data, 1, end); | |
2125 | -- uvalue; | |
2126 | data ++; | |
2127 | ||
2128 | assert (uvalue > 0); | |
2129 | switch (discriminant) | |
2130 | { | |
2131 | case DW_DSC_label: | |
2132 | printf ("label "); | |
2133 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2134 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2135 | uvalue -= bytes_read; | |
2136 | data += bytes_read; | |
2137 | break; | |
2138 | ||
2139 | case DW_DSC_range: | |
2140 | printf ("range "); | |
2141 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2142 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2143 | uvalue -= bytes_read; | |
2144 | data += bytes_read; | |
2145 | ||
2146 | printf (".."); | |
2147 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2148 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2149 | uvalue -= bytes_read; | |
2150 | data += bytes_read; | |
2151 | break; | |
2152 | ||
2153 | default: | |
2154 | printf ("<corrupt>\n"); | |
2155 | warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"), | |
2156 | discriminant); | |
2157 | return; | |
2158 | } | |
2159 | ||
2160 | if (uvalue) | |
2161 | printf (", "); | |
2162 | } | |
2163 | ||
2164 | if (is_signed) | |
2165 | printf (")(signed)"); | |
2166 | else | |
2167 | printf (")(unsigned)"); | |
2168 | } | |
2169 | ||
19e6b90e | 2170 | static unsigned char * |
dda8d76d NC |
2171 | read_and_display_attr_value (unsigned long attribute, |
2172 | unsigned long form, | |
2173 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 2174 | unsigned char * start, |
dda8d76d NC |
2175 | unsigned char * data, |
2176 | unsigned char * end, | |
2177 | dwarf_vma cu_offset, | |
2178 | dwarf_vma pointer_size, | |
2179 | dwarf_vma offset_size, | |
2180 | int dwarf_version, | |
2181 | debug_info * debug_info_p, | |
2182 | int do_loc, | |
2183 | struct dwarf_section * section, | |
2184 | struct cu_tu_set * this_set, | |
ec1b0fbb NC |
2185 | char delimiter, |
2186 | int level) | |
19e6b90e | 2187 | { |
cd30bcef | 2188 | dwarf_signed_vma svalue; |
ec1b0fbb NC |
2189 | dwarf_vma uvalue = 0; |
2190 | unsigned char * block_start = NULL; | |
2191 | unsigned char * orig_data = data; | |
19e6b90e | 2192 | |
f41e4712 | 2193 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 2194 | { |
f41e4712 | 2195 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
2196 | return data; |
2197 | } | |
2198 | ||
19e6b90e L |
2199 | switch (form) |
2200 | { | |
2201 | default: | |
2202 | break; | |
2203 | ||
2204 | case DW_FORM_ref_addr: | |
2205 | if (dwarf_version == 2) | |
0c588247 | 2206 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
ec47b32a | 2207 | else if (dwarf_version > 2) |
0c588247 | 2208 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 2209 | else |
ec47b32a | 2210 | error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n")); |
467c65bc | 2211 | |
19e6b90e L |
2212 | break; |
2213 | ||
2214 | case DW_FORM_addr: | |
0c588247 | 2215 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
2216 | break; |
2217 | ||
2218 | case DW_FORM_strp: | |
77145576 | 2219 | case DW_FORM_line_strp: |
932fd279 | 2220 | case DW_FORM_sec_offset: |
a081f3cd JJ |
2221 | case DW_FORM_GNU_ref_alt: |
2222 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 2223 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
2224 | break; |
2225 | ||
932fd279 JJ |
2226 | case DW_FORM_flag_present: |
2227 | uvalue = 1; | |
2228 | break; | |
2229 | ||
19e6b90e L |
2230 | case DW_FORM_ref1: |
2231 | case DW_FORM_flag: | |
2232 | case DW_FORM_data1: | |
0c588247 | 2233 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
2234 | break; |
2235 | ||
2236 | case DW_FORM_ref2: | |
2237 | case DW_FORM_data2: | |
0c588247 | 2238 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
2239 | break; |
2240 | ||
2241 | case DW_FORM_ref4: | |
2242 | case DW_FORM_data4: | |
0c588247 | 2243 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
2244 | break; |
2245 | ||
2246 | case DW_FORM_sdata: | |
cd30bcef AM |
2247 | READ_SLEB (svalue, data, end); |
2248 | uvalue = svalue; | |
19e6b90e L |
2249 | break; |
2250 | ||
4723351a | 2251 | case DW_FORM_GNU_str_index: |
19e6b90e L |
2252 | case DW_FORM_ref_udata: |
2253 | case DW_FORM_udata: | |
cd30bcef AM |
2254 | case DW_FORM_GNU_addr_index: |
2255 | READ_ULEB (uvalue, data, end); | |
19e6b90e L |
2256 | break; |
2257 | ||
2258 | case DW_FORM_indirect: | |
cd30bcef | 2259 | READ_ULEB (form, data, end); |
19e6b90e | 2260 | if (!do_loc) |
ef0b5f1c | 2261 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 | 2262 | if (form == DW_FORM_implicit_const) |
cd30bcef | 2263 | READ_SLEB (implicit_const, data, end); |
ec1b0fbb NC |
2264 | return read_and_display_attr_value (attribute, form, implicit_const, |
2265 | start, data, end, | |
2266 | cu_offset, pointer_size, | |
19e6b90e | 2267 | offset_size, dwarf_version, |
ec4d4525 | 2268 | debug_info_p, do_loc, |
ec1b0fbb | 2269 | section, this_set, delimiter, level); |
19e6b90e L |
2270 | } |
2271 | ||
2272 | switch (form) | |
2273 | { | |
2274 | case DW_FORM_ref_addr: | |
2275 | if (!do_loc) | |
ef0b5f1c | 2276 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
19e6b90e L |
2277 | break; |
2278 | ||
a081f3cd JJ |
2279 | case DW_FORM_GNU_ref_alt: |
2280 | if (!do_loc) | |
ef0b5f1c | 2281 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
dda8d76d | 2282 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
2283 | break; |
2284 | ||
19e6b90e L |
2285 | case DW_FORM_ref1: |
2286 | case DW_FORM_ref2: | |
2287 | case DW_FORM_ref4: | |
2288 | case DW_FORM_ref_udata: | |
2289 | if (!do_loc) | |
ef0b5f1c | 2290 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
2291 | break; |
2292 | ||
2293 | case DW_FORM_data4: | |
2294 | case DW_FORM_addr: | |
932fd279 | 2295 | case DW_FORM_sec_offset: |
19e6b90e | 2296 | if (!do_loc) |
ef0b5f1c | 2297 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2298 | break; |
2299 | ||
932fd279 | 2300 | case DW_FORM_flag_present: |
19e6b90e L |
2301 | case DW_FORM_flag: |
2302 | case DW_FORM_data1: | |
2303 | case DW_FORM_data2: | |
2304 | case DW_FORM_sdata: | |
2305 | case DW_FORM_udata: | |
2306 | if (!do_loc) | |
ef0b5f1c | 2307 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
2308 | break; |
2309 | ||
77145576 JK |
2310 | case DW_FORM_implicit_const: |
2311 | if (!do_loc) | |
2312 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
2313 | break; | |
2314 | ||
19e6b90e L |
2315 | case DW_FORM_ref8: |
2316 | case DW_FORM_data8: | |
2bc8690c | 2317 | if (!do_loc) |
19e6b90e | 2318 | { |
74bc6052 | 2319 | dwarf_vma high_bits; |
a69c4772 | 2320 | dwarf_vma utmp; |
74bc6052 CC |
2321 | char buf[64]; |
2322 | ||
0c588247 | 2323 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
2324 | utmp = uvalue; |
2325 | if (form == DW_FORM_ref8) | |
2326 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 2327 | printf ("%c0x%s", delimiter, |
a69c4772 | 2328 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 2329 | } |
0c588247 | 2330 | |
19e6b90e L |
2331 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2332 | && num_debug_info_entries == 0) | |
2333 | { | |
2334 | if (sizeof (uvalue) == 8) | |
0c588247 | 2335 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 2336 | else |
467c65bc | 2337 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 2338 | } |
0c588247 | 2339 | |
19e6b90e L |
2340 | data += 8; |
2341 | break; | |
2342 | ||
2f6cd591 JK |
2343 | case DW_FORM_data16: |
2344 | if (!do_loc) | |
2345 | { | |
2346 | dwarf_vma left_high_bits, left_low_bits; | |
2347 | dwarf_vma right_high_bits, right_low_bits; | |
2348 | ||
2349 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
2350 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
2351 | if (byte_get == byte_get_little_endian) | |
2352 | { | |
2353 | /* Swap them. */ | |
2354 | left_high_bits ^= right_high_bits; | |
2355 | right_high_bits ^= left_high_bits; | |
2356 | left_high_bits ^= right_high_bits; | |
2357 | left_low_bits ^= right_low_bits; | |
2358 | right_low_bits ^= left_low_bits; | |
2359 | left_low_bits ^= right_low_bits; | |
2360 | } | |
2361 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
2362 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
2363 | left_high_bits, left_low_bits, right_high_bits, | |
2364 | right_low_bits); | |
2365 | } | |
2366 | data += 16; | |
2367 | break; | |
2368 | ||
19e6b90e L |
2369 | case DW_FORM_string: |
2370 | if (!do_loc) | |
ef0b5f1c | 2371 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 2372 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
2373 | break; |
2374 | ||
2375 | case DW_FORM_block: | |
932fd279 | 2376 | case DW_FORM_exprloc: |
cd30bcef AM |
2377 | READ_ULEB (uvalue, data, end); |
2378 | do_block: | |
2379 | block_start = data; | |
a1165289 NC |
2380 | if (block_start >= end) |
2381 | { | |
2382 | warn (_("Block ends prematurely\n")); | |
2383 | uvalue = 0; | |
2384 | block_start = end; | |
2385 | } | |
afc72f15 NC |
2386 | |
2387 | uvalue = check_uvalue (block_start, uvalue, end); | |
2388 | ||
19e6b90e L |
2389 | if (do_loc) |
2390 | data = block_start + uvalue; | |
2391 | else | |
ef0b5f1c | 2392 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2393 | break; |
2394 | ||
2395 | case DW_FORM_block1: | |
cd30bcef AM |
2396 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2397 | goto do_block; | |
19e6b90e L |
2398 | |
2399 | case DW_FORM_block2: | |
cd30bcef AM |
2400 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2401 | goto do_block; | |
19e6b90e L |
2402 | |
2403 | case DW_FORM_block4: | |
cd30bcef AM |
2404 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2405 | goto do_block; | |
19e6b90e L |
2406 | |
2407 | case DW_FORM_strp: | |
2408 | if (!do_loc) | |
ef0b5f1c | 2409 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, |
47704ddf KT |
2410 | dwarf_vmatoa ("x", uvalue), |
2411 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
2412 | break; |
2413 | ||
77145576 JK |
2414 | case DW_FORM_line_strp: |
2415 | if (!do_loc) | |
2416 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2417 | dwarf_vmatoa ("x", uvalue), | |
2418 | fetch_indirect_line_string (uvalue)); | |
2419 | break; | |
2420 | ||
4723351a CC |
2421 | case DW_FORM_GNU_str_index: |
2422 | if (!do_loc) | |
b4eb7656 | 2423 | { |
d85bf2ba NC |
2424 | const char * suffix = strrchr (section->name, '.'); |
2425 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
b4eb7656 | 2426 | |
ef0b5f1c | 2427 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2428 | dwarf_vmatoa ("x", uvalue), |
2429 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2430 | } | |
4723351a CC |
2431 | break; |
2432 | ||
a081f3cd JJ |
2433 | case DW_FORM_GNU_strp_alt: |
2434 | if (!do_loc) | |
dda8d76d NC |
2435 | { |
2436 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2437 | dwarf_vmatoa ("x", uvalue), | |
2438 | fetch_alt_indirect_string (uvalue)); | |
2439 | } | |
a081f3cd JJ |
2440 | break; |
2441 | ||
19e6b90e L |
2442 | case DW_FORM_indirect: |
2443 | /* Handled above. */ | |
2444 | break; | |
2445 | ||
2b6f5997 CC |
2446 | case DW_FORM_ref_sig8: |
2447 | if (!do_loc) | |
2448 | { | |
74bc6052 CC |
2449 | dwarf_vma high_bits; |
2450 | char buf[64]; | |
2451 | ||
0c588247 | 2452 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
ef0b5f1c | 2453 | printf ("%csignature: 0x%s", delimiter, |
74bc6052 | 2454 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); |
2b6f5997 | 2455 | } |
74bc6052 | 2456 | data += 8; |
2b6f5997 CC |
2457 | break; |
2458 | ||
4723351a CC |
2459 | case DW_FORM_GNU_addr_index: |
2460 | if (!do_loc) | |
ef0b5f1c | 2461 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2462 | dwarf_vmatoa ("x", uvalue), |
2463 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
4723351a CC |
2464 | break; |
2465 | ||
19e6b90e L |
2466 | default: |
2467 | warn (_("Unrecognized form: %lu\n"), form); | |
2468 | break; | |
2469 | } | |
2470 | ||
19e6b90e | 2471 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2472 | && num_debug_info_entries == 0 |
2473 | && debug_info_p != NULL) | |
19e6b90e L |
2474 | { |
2475 | switch (attribute) | |
2476 | { | |
2477 | case DW_AT_frame_base: | |
2478 | have_frame_base = 1; | |
1a0670f3 | 2479 | /* Fall through. */ |
19e6b90e | 2480 | case DW_AT_location: |
9f272209 | 2481 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2482 | case DW_AT_string_length: |
2483 | case DW_AT_return_addr: | |
19e6b90e L |
2484 | case DW_AT_data_member_location: |
2485 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2486 | case DW_AT_segment: |
2487 | case DW_AT_static_link: | |
2488 | case DW_AT_use_location: | |
bc0a77d2 | 2489 | case DW_AT_call_value: |
629e7ca8 | 2490 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2491 | case DW_AT_call_data_value: |
629e7ca8 | 2492 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2493 | case DW_AT_call_target: |
629e7ca8 | 2494 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2495 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2496 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2497 | if ((dwarf_version < 4 |
212b6063 | 2498 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2499 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2500 | { |
2501 | /* Process location list. */ | |
91d6fa6a | 2502 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2503 | unsigned int num = debug_info_p->num_loc_offsets; |
2504 | ||
91d6fa6a | 2505 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2506 | { |
91d6fa6a | 2507 | lmax += 1024; |
467c65bc | 2508 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2509 | xcrealloc (debug_info_p->loc_offsets, |
2510 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2511 | debug_info_p->loc_views = (dwarf_vma *) |
2512 | xcrealloc (debug_info_p->loc_views, | |
2513 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2514 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2515 | xcrealloc (debug_info_p->have_frame_base, |
2516 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2517 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2518 | } |
341f9135 | 2519 | if (this_set != NULL) |
b4eb7656 | 2520 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2521 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2522 | if (attribute != DW_AT_GNU_locviews) |
2523 | { | |
a7504f87 NC |
2524 | /* Corrupt DWARF info can produce more offsets than views. |
2525 | See PR 23062 for an example. */ | |
2526 | if (debug_info_p->num_loc_offsets | |
2527 | > debug_info_p->num_loc_views) | |
2528 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2529 | else | |
2530 | { | |
2531 | debug_info_p->loc_offsets [num] = uvalue; | |
2532 | debug_info_p->num_loc_offsets++; | |
2533 | } | |
9f272209 AO |
2534 | } |
2535 | else | |
2536 | { | |
2537 | assert (debug_info_p->num_loc_views <= num); | |
2538 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2539 | if (num > debug_info_p->num_loc_offsets) |
2540 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2541 | else | |
2542 | { | |
2543 | debug_info_p->loc_views [num] = uvalue; | |
2544 | debug_info_p->num_loc_views++; | |
2545 | } | |
9f272209 | 2546 | } |
19e6b90e L |
2547 | } |
2548 | break; | |
e2a0d921 | 2549 | |
19e6b90e L |
2550 | case DW_AT_low_pc: |
2551 | if (need_base_address) | |
2552 | debug_info_p->base_address = uvalue; | |
2553 | break; | |
2554 | ||
4723351a | 2555 | case DW_AT_GNU_addr_base: |
b4eb7656 | 2556 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2557 | break; |
2558 | ||
2559 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2560 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2561 | break; |
2562 | ||
19e6b90e | 2563 | case DW_AT_ranges: |
b4eb7656 | 2564 | if ((dwarf_version < 4 |
212b6063 | 2565 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2566 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2567 | { |
2568 | /* Process range list. */ | |
91d6fa6a | 2569 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2570 | unsigned int num = debug_info_p->num_range_lists; |
2571 | ||
91d6fa6a | 2572 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2573 | { |
91d6fa6a | 2574 | lmax += 1024; |
467c65bc | 2575 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2576 | xcrealloc (debug_info_p->range_lists, |
2577 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2578 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2579 | } |
2580 | debug_info_p->range_lists [num] = uvalue; | |
2581 | debug_info_p->num_range_lists++; | |
2582 | } | |
2583 | break; | |
2584 | ||
d85bf2ba NC |
2585 | case DW_AT_GNU_dwo_name: |
2586 | case DW_AT_dwo_name: | |
2587 | if (need_dwo_info) | |
2588 | switch (form) | |
2589 | { | |
2590 | case DW_FORM_strp: | |
24841daa | 2591 | add_dwo_name ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba | 2592 | break; |
5568cc9e NC |
2593 | case DW_FORM_GNU_strp_alt: |
2594 | add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue)); | |
2595 | break; | |
d85bf2ba | 2596 | case DW_FORM_GNU_str_index: |
24841daa | 2597 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2598 | break; |
2599 | case DW_FORM_string: | |
24841daa | 2600 | add_dwo_name ((const char *) orig_data); |
d85bf2ba NC |
2601 | break; |
2602 | default: | |
2603 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2604 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2605 | break; |
2606 | } | |
2607 | break; | |
2608 | ||
2609 | case DW_AT_comp_dir: | |
2610 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2611 | if (need_dwo_info) | |
2612 | switch (form) | |
2613 | { | |
2614 | case DW_FORM_strp: | |
24841daa | 2615 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba | 2616 | break; |
5568cc9e NC |
2617 | case DW_FORM_GNU_strp_alt: |
2618 | add_dwo_dir (fetch_alt_indirect_string (uvalue)); | |
2619 | break; | |
d85bf2ba | 2620 | case DW_FORM_line_strp: |
24841daa | 2621 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue)); |
d85bf2ba NC |
2622 | break; |
2623 | case DW_FORM_GNU_str_index: | |
24841daa | 2624 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2625 | break; |
2626 | case DW_FORM_string: | |
24841daa | 2627 | add_dwo_dir ((const char *) orig_data); |
d85bf2ba NC |
2628 | break; |
2629 | default: | |
2630 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2631 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2632 | break; |
2633 | } | |
2634 | break; | |
2635 | ||
2636 | case DW_AT_GNU_dwo_id: | |
2637 | if (need_dwo_info) | |
2638 | switch (form) | |
2639 | { | |
2640 | case DW_FORM_data8: | |
24841daa NC |
2641 | /* FIXME: Record the length of the ID as well ? */ |
2642 | add_dwo_id ((const char *) (data - 8)); | |
d85bf2ba NC |
2643 | break; |
2644 | default: | |
2645 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2646 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2647 | break; |
2648 | } | |
2649 | break; | |
2650 | ||
19e6b90e L |
2651 | default: |
2652 | break; | |
2653 | } | |
2654 | } | |
2655 | ||
4ccf1e31 | 2656 | if (do_loc || attribute == 0) |
19e6b90e L |
2657 | return data; |
2658 | ||
ec4d4525 | 2659 | /* For some attributes we can display further information. */ |
19e6b90e L |
2660 | switch (attribute) |
2661 | { | |
ec1b0fbb | 2662 | case DW_AT_type: |
b3fe587e AM |
2663 | if (level >= 0 && level < MAX_CU_NESTING |
2664 | && uvalue < (size_t) (end - start)) | |
ec1b0fbb NC |
2665 | { |
2666 | bfd_boolean is_signed = FALSE; | |
2667 | ||
2668 | get_type_signedness (start, start + uvalue, end, pointer_size, | |
2669 | offset_size, dwarf_version, & is_signed, FALSE); | |
2670 | level_type_signed[level] = is_signed; | |
2671 | } | |
2672 | break; | |
2673 | ||
19e6b90e | 2674 | case DW_AT_inline: |
2e9e81a8 | 2675 | printf ("\t"); |
19e6b90e L |
2676 | switch (uvalue) |
2677 | { | |
2678 | case DW_INL_not_inlined: | |
2679 | printf (_("(not inlined)")); | |
2680 | break; | |
2681 | case DW_INL_inlined: | |
2682 | printf (_("(inlined)")); | |
2683 | break; | |
2684 | case DW_INL_declared_not_inlined: | |
2685 | printf (_("(declared as inline but ignored)")); | |
2686 | break; | |
2687 | case DW_INL_declared_inlined: | |
2688 | printf (_("(declared as inline and inlined)")); | |
2689 | break; | |
2690 | default: | |
47704ddf KT |
2691 | printf (_(" (Unknown inline attribute value: %s)"), |
2692 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
2693 | break; |
2694 | } | |
2695 | break; | |
2696 | ||
2697 | case DW_AT_language: | |
2e9e81a8 | 2698 | printf ("\t"); |
19e6b90e L |
2699 | switch (uvalue) |
2700 | { | |
4b78141a | 2701 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 2702 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
2703 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
2704 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 2705 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
2706 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
2707 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
2708 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
2709 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 2710 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 2711 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 2712 | /* DWARF 2.1 values. */ |
4b78141a | 2713 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
2714 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
2715 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
2716 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
2717 | /* DWARF 3 values. */ |
2718 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
2719 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
2720 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
2721 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
2722 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
2723 | /* DWARF 4 values. */ |
2724 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 2725 | /* DWARF 5 values. */ |
2008a0db | 2726 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 2727 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
2728 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
2729 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
2730 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 2731 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
2732 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
2733 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 2734 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
2735 | case DW_LANG_Swift: printf ("(Swift)"); break; |
2736 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
2737 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 2738 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
2739 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
2740 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 2741 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
2742 | /* MIPS extension. */ |
2743 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
2744 | /* UPC extension. */ | |
2745 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
2746 | default: | |
4b78141a | 2747 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 2748 | printf (_("(implementation defined: %s)"), |
467c65bc | 2749 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 2750 | else |
9cf03b7e | 2751 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2752 | break; |
2753 | } | |
2754 | break; | |
2755 | ||
2756 | case DW_AT_encoding: | |
2e9e81a8 | 2757 | printf ("\t"); |
19e6b90e L |
2758 | switch (uvalue) |
2759 | { | |
2760 | case DW_ATE_void: printf ("(void)"); break; | |
2761 | case DW_ATE_address: printf ("(machine address)"); break; | |
2762 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
2763 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
2764 | case DW_ATE_float: printf ("(float)"); break; | |
2765 | case DW_ATE_signed: printf ("(signed)"); break; | |
2766 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
2767 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
2768 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 2769 | /* DWARF 2.1 values: */ |
19e6b90e L |
2770 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
2771 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
2772 | /* DWARF 3 values: */ |
2773 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
2774 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
2775 | case DW_ATE_edited: printf ("(edited)"); break; | |
2776 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
2777 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
2778 | /* DWARF 4 values: */ |
2779 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
2780 | /* DWARF 5 values: */ | |
2781 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
2782 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
2783 | ||
e2a0d921 NC |
2784 | /* HP extensions: */ |
2785 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
2786 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
2787 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
2788 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
2789 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
2790 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
2791 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
164cbceb LM |
2792 | |
2793 | case DW_ATE_CHERI_signed_intcap: | |
2794 | printf ("(CHERI intcap_t)"); | |
2795 | break; | |
2796 | case DW_ATE_CHERI_unsigned_intcap: | |
2797 | printf ("(CHERI uintcap_t)"); | |
2798 | break; | |
e2a0d921 | 2799 | |
19e6b90e L |
2800 | default: |
2801 | if (uvalue >= DW_ATE_lo_user | |
2802 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 2803 | printf (_("(user defined type)")); |
19e6b90e | 2804 | else |
9cf03b7e | 2805 | printf (_("(unknown type)")); |
19e6b90e L |
2806 | break; |
2807 | } | |
2808 | break; | |
2809 | ||
2810 | case DW_AT_accessibility: | |
2e9e81a8 | 2811 | printf ("\t"); |
19e6b90e L |
2812 | switch (uvalue) |
2813 | { | |
2814 | case DW_ACCESS_public: printf ("(public)"); break; | |
2815 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
2816 | case DW_ACCESS_private: printf ("(private)"); break; | |
2817 | default: | |
9cf03b7e | 2818 | printf (_("(unknown accessibility)")); |
19e6b90e L |
2819 | break; |
2820 | } | |
2821 | break; | |
2822 | ||
2823 | case DW_AT_visibility: | |
2e9e81a8 | 2824 | printf ("\t"); |
19e6b90e L |
2825 | switch (uvalue) |
2826 | { | |
2827 | case DW_VIS_local: printf ("(local)"); break; | |
2828 | case DW_VIS_exported: printf ("(exported)"); break; | |
2829 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 2830 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
2831 | } |
2832 | break; | |
2833 | ||
04914e37 NC |
2834 | case DW_AT_endianity: |
2835 | printf ("\t"); | |
2836 | switch (uvalue) | |
2837 | { | |
2838 | case DW_END_default: printf ("(default)"); break; | |
2839 | case DW_END_big: printf ("(big)"); break; | |
2840 | case DW_END_little: printf ("(little)"); break; | |
2841 | default: | |
2842 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
2843 | printf (_("(user specified)")); | |
2844 | else | |
2845 | printf (_("(unknown endianity)")); | |
2846 | break; | |
2847 | } | |
2848 | break; | |
2849 | ||
19e6b90e | 2850 | case DW_AT_virtuality: |
2e9e81a8 | 2851 | printf ("\t"); |
19e6b90e L |
2852 | switch (uvalue) |
2853 | { | |
2854 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
2855 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
2856 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 2857 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
2858 | } |
2859 | break; | |
2860 | ||
2861 | case DW_AT_identifier_case: | |
2e9e81a8 | 2862 | printf ("\t"); |
19e6b90e L |
2863 | switch (uvalue) |
2864 | { | |
2865 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
2866 | case DW_ID_up_case: printf ("(up_case)"); break; | |
2867 | case DW_ID_down_case: printf ("(down_case)"); break; | |
2868 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 2869 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
2870 | } |
2871 | break; | |
2872 | ||
2873 | case DW_AT_calling_convention: | |
2e9e81a8 | 2874 | printf ("\t"); |
19e6b90e L |
2875 | switch (uvalue) |
2876 | { | |
2877 | case DW_CC_normal: printf ("(normal)"); break; | |
2878 | case DW_CC_program: printf ("(program)"); break; | |
2879 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
2880 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
2881 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
2882 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
2883 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
2884 | default: |
2885 | if (uvalue >= DW_CC_lo_user | |
2886 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 2887 | printf (_("(user defined)")); |
19e6b90e | 2888 | else |
9cf03b7e | 2889 | printf (_("(unknown convention)")); |
19e6b90e L |
2890 | } |
2891 | break; | |
2892 | ||
2893 | case DW_AT_ordering: | |
2e9e81a8 | 2894 | printf ("\t"); |
19e6b90e L |
2895 | switch (uvalue) |
2896 | { | |
04914e37 | 2897 | case 255: |
9cf03b7e | 2898 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
2899 | case 0: printf ("(row major)"); break; |
2900 | case 1: printf ("(column major)"); break; | |
2901 | } | |
2902 | break; | |
2903 | ||
04914e37 NC |
2904 | case DW_AT_decimal_sign: |
2905 | printf ("\t"); | |
2906 | switch (uvalue) | |
2907 | { | |
2908 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
2909 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
2910 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
2911 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
2912 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
2913 | default: printf (_("(unrecognised)")); break; | |
2914 | } | |
2915 | break; | |
2916 | ||
2917 | case DW_AT_defaulted: | |
2918 | printf ("\t"); | |
2919 | switch (uvalue) | |
2920 | { | |
2921 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
2922 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
2923 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
2924 | default: printf (_("(unrecognised)")); break; | |
2925 | } | |
2926 | break; | |
2927 | ||
2928 | case DW_AT_discr_list: | |
2929 | printf ("\t"); | |
ec1b0fbb | 2930 | display_discr_list (form, uvalue, data, end, level); |
04914e37 NC |
2931 | break; |
2932 | ||
19e6b90e L |
2933 | case DW_AT_frame_base: |
2934 | have_frame_base = 1; | |
1a0670f3 | 2935 | /* Fall through. */ |
19e6b90e | 2936 | case DW_AT_location: |
e2a0d921 NC |
2937 | case DW_AT_string_length: |
2938 | case DW_AT_return_addr: | |
19e6b90e L |
2939 | case DW_AT_data_member_location: |
2940 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2941 | case DW_AT_segment: |
2942 | case DW_AT_static_link: | |
2943 | case DW_AT_use_location: | |
bc0a77d2 | 2944 | case DW_AT_call_value: |
629e7ca8 | 2945 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2946 | case DW_AT_call_data_value: |
629e7ca8 | 2947 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2948 | case DW_AT_call_target: |
629e7ca8 | 2949 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2950 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2951 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 2952 | if ((dwarf_version < 4 |
b4eb7656 | 2953 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2954 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 2955 | printf (_(" (location list)")); |
e2a0d921 | 2956 | /* Fall through. */ |
19e6b90e L |
2957 | case DW_AT_allocated: |
2958 | case DW_AT_associated: | |
2959 | case DW_AT_data_location: | |
2960 | case DW_AT_stride: | |
2961 | case DW_AT_upper_bound: | |
cecf136e | 2962 | case DW_AT_lower_bound: |
19e6b90e L |
2963 | if (block_start) |
2964 | { | |
2965 | int need_frame_base; | |
2966 | ||
2e9e81a8 | 2967 | printf ("\t("); |
19e6b90e L |
2968 | need_frame_base = decode_location_expression (block_start, |
2969 | pointer_size, | |
b7807392 JJ |
2970 | offset_size, |
2971 | dwarf_version, | |
19e6b90e | 2972 | uvalue, |
f1c4cc75 | 2973 | cu_offset, section); |
19e6b90e L |
2974 | printf (")"); |
2975 | if (need_frame_base && !have_frame_base) | |
2976 | printf (_(" [without DW_AT_frame_base]")); | |
2977 | } | |
19e6b90e L |
2978 | break; |
2979 | ||
c54207d3 NC |
2980 | case DW_AT_data_bit_offset: |
2981 | case DW_AT_byte_size: | |
2982 | case DW_AT_bit_size: | |
2983 | case DW_AT_string_length_byte_size: | |
2984 | case DW_AT_string_length_bit_size: | |
2985 | case DW_AT_bit_stride: | |
2986 | if (form == DW_FORM_exprloc) | |
2987 | { | |
2988 | printf ("\t("); | |
2989 | (void) decode_location_expression (block_start, pointer_size, | |
2990 | offset_size, dwarf_version, | |
2991 | uvalue, cu_offset, section); | |
2992 | printf (")"); | |
2993 | } | |
2994 | break; | |
2995 | ||
ec4d4525 NC |
2996 | case DW_AT_import: |
2997 | { | |
a081f3cd JJ |
2998 | if (form == DW_FORM_ref_sig8 |
2999 | || form == DW_FORM_GNU_ref_alt) | |
b4eb7656 | 3000 | break; |
2b6f5997 | 3001 | |
ec4d4525 NC |
3002 | if (form == DW_FORM_ref1 |
3003 | || form == DW_FORM_ref2 | |
a7a0b6a5 JK |
3004 | || form == DW_FORM_ref4 |
3005 | || form == DW_FORM_ref_udata) | |
ec4d4525 NC |
3006 | uvalue += cu_offset; |
3007 | ||
6e3d6dc1 | 3008 | if (uvalue >= section->size) |
f3853b34 | 3009 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), |
47704ddf KT |
3010 | dwarf_vmatoa ("x", uvalue), |
3011 | (unsigned long) (orig_data - section->start)); | |
6e3d6dc1 NC |
3012 | else |
3013 | { | |
3014 | unsigned long abbrev_number; | |
cd30bcef AM |
3015 | abbrev_entry *entry; |
3016 | unsigned char *p = section->start + uvalue; | |
6e3d6dc1 | 3017 | |
cd30bcef | 3018 | READ_ULEB (abbrev_number, p, end); |
cecf136e | 3019 | |
2e9e81a8 | 3020 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
afd6e1ff JJ |
3021 | /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
3022 | use different abbrev table, and we don't track .debug_info chunks | |
3023 | yet. */ | |
3024 | if (form != DW_FORM_ref_addr) | |
3025 | { | |
3026 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
3027 | if (entry->entry == abbrev_number) | |
3028 | break; | |
3029 | if (entry != NULL) | |
3030 | printf (" (%s)", get_TAG_name (entry->tag)); | |
3031 | } | |
6e3d6dc1 NC |
3032 | printf ("]"); |
3033 | } | |
ec4d4525 NC |
3034 | } |
3035 | break; | |
3036 | ||
19e6b90e L |
3037 | default: |
3038 | break; | |
3039 | } | |
3040 | ||
3041 | return data; | |
3042 | } | |
3043 | ||
19e6b90e | 3044 | static unsigned char * |
dda8d76d NC |
3045 | read_and_display_attr (unsigned long attribute, |
3046 | unsigned long form, | |
3047 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 3048 | unsigned char * start, |
dda8d76d NC |
3049 | unsigned char * data, |
3050 | unsigned char * end, | |
3051 | dwarf_vma cu_offset, | |
3052 | dwarf_vma pointer_size, | |
3053 | dwarf_vma offset_size, | |
3054 | int dwarf_version, | |
3055 | debug_info * debug_info_p, | |
3056 | int do_loc, | |
3057 | struct dwarf_section * section, | |
ec1b0fbb NC |
3058 | struct cu_tu_set * this_set, |
3059 | int level) | |
19e6b90e L |
3060 | { |
3061 | if (!do_loc) | |
750f03b7 | 3062 | printf (" %-18s:", get_AT_name (attribute)); |
ec1b0fbb NC |
3063 | data = read_and_display_attr_value (attribute, form, implicit_const, |
3064 | start, data, end, | |
f6f0e17b | 3065 | cu_offset, pointer_size, offset_size, |
19e6b90e | 3066 | dwarf_version, debug_info_p, |
ec1b0fbb | 3067 | do_loc, section, this_set, ' ', level); |
19e6b90e L |
3068 | if (!do_loc) |
3069 | printf ("\n"); | |
3070 | return data; | |
3071 | } | |
3072 | ||
dda8d76d | 3073 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
3074 | following debug links, then attempt to load the requested section |
3075 | from one of the separate debug info files. */ | |
dda8d76d NC |
3076 | |
3077 | static bfd_boolean | |
3078 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, | |
24841daa | 3079 | void * handle) |
dda8d76d | 3080 | { |
24841daa | 3081 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 3082 | { |
24841daa NC |
3083 | if (debug_displays[sec_enum].section.filename == NULL) |
3084 | { | |
3085 | /* See if we can associate a filename with this section. */ | |
3086 | separate_info * i; | |
3087 | ||
3088 | for (i = first_separate_info; i != NULL; i = i->next) | |
3089 | if (i->handle == handle) | |
3090 | { | |
3091 | debug_displays[sec_enum].section.filename = i->filename; | |
3092 | break; | |
3093 | } | |
3094 | } | |
3095 | ||
dda8d76d NC |
3096 | return TRUE; |
3097 | } | |
3098 | ||
24841daa NC |
3099 | if (do_follow_links) |
3100 | { | |
3101 | separate_info * i; | |
3102 | ||
3103 | for (i = first_separate_info; i != NULL; i = i->next) | |
3104 | { | |
3105 | if (load_debug_section (sec_enum, i->handle)) | |
3106 | { | |
3107 | debug_displays[sec_enum].section.filename = i->filename; | |
3108 | ||
3109 | /* FIXME: We should check to see if any of the remaining debug info | |
3110 | files also contain this section, and, umm, do something about it. */ | |
3111 | return TRUE; | |
3112 | } | |
3113 | } | |
3114 | } | |
dda8d76d NC |
3115 | |
3116 | return FALSE; | |
3117 | } | |
3118 | ||
3119 | static void | |
3120 | introduce (struct dwarf_section * section, bfd_boolean raw) | |
3121 | { | |
3122 | if (raw) | |
3123 | { | |
3124 | if (do_follow_links && section->filename) | |
3125 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
3126 | section->name, section->filename); | |
3127 | else | |
3128 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
3129 | } | |
3130 | else | |
3131 | { | |
3132 | if (do_follow_links && section->filename) | |
3133 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
3134 | section->name, section->filename); | |
3135 | else | |
3136 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3137 | } | |
3138 | } | |
3139 | ||
d85bf2ba NC |
3140 | /* Process the contents of a .debug_info section. |
3141 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
3142 | and we do not want to display anything to the user. | |
3143 | If do_types is TRUE, we are processing a .debug_types section instead of | |
3144 | a .debug_info section. | |
3145 | The information displayed is restricted by the values in DWARF_START_DIE | |
3146 | and DWARF_CUTOFF_LEVEL. | |
3147 | Returns TRUE upon success. Otherwise an error or warning message is | |
3148 | printed and FALSE is returned. */ | |
19e6b90e | 3149 | |
d85bf2ba NC |
3150 | static bfd_boolean |
3151 | process_debug_info (struct dwarf_section * section, | |
3152 | void * file, | |
3153 | enum dwarf_section_display_enum abbrev_sec, | |
3154 | bfd_boolean do_loc, | |
3155 | bfd_boolean do_types) | |
19e6b90e L |
3156 | { |
3157 | unsigned char *start = section->start; | |
3158 | unsigned char *end = start + section->size; | |
3159 | unsigned char *section_begin; | |
3160 | unsigned int unit; | |
3161 | unsigned int num_units = 0; | |
3162 | ||
3163 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3164 | && num_debug_info_entries == 0 |
3165 | && ! do_types) | |
19e6b90e | 3166 | { |
767221a9 | 3167 | dwarf_vma length; |
19e6b90e L |
3168 | |
3169 | /* First scan the section to get the number of comp units. */ | |
3170 | for (section_begin = start, num_units = 0; section_begin < end; | |
3171 | num_units ++) | |
3172 | { | |
3173 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
3174 | will be the length. For a 64-bit DWARF section, it'll be | |
3175 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 3176 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
3177 | |
3178 | if (length == 0xffffffff) | |
3179 | { | |
0c588247 | 3180 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
3181 | section_begin += length + 12; |
3182 | } | |
ec4d4525 NC |
3183 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
3184 | { | |
767221a9 NC |
3185 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
3186 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3187 | return FALSE; |
ec4d4525 | 3188 | } |
19e6b90e L |
3189 | else |
3190 | section_begin += length + 4; | |
aca88567 NC |
3191 | |
3192 | /* Negative values are illegal, they may even cause infinite | |
3193 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
3194 | relocations to an object file, or if the file is corrupt. */ |
3195 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 3196 | { |
767221a9 NC |
3197 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
3198 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3199 | return FALSE; |
aca88567 | 3200 | } |
19e6b90e L |
3201 | } |
3202 | ||
3203 | if (num_units == 0) | |
3204 | { | |
f41e4712 | 3205 | error (_("No comp units in %s section ?\n"), section->name); |
d85bf2ba | 3206 | return FALSE; |
19e6b90e L |
3207 | } |
3208 | ||
3209 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 3210 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 3211 | sizeof (* debug_information)); |
19e6b90e L |
3212 | if (debug_information == NULL) |
3213 | { | |
f41e4712 | 3214 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 3215 | num_units); |
82b1b41b | 3216 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
d85bf2ba | 3217 | return FALSE; |
19e6b90e | 3218 | } |
d85bf2ba | 3219 | |
03a91817 NC |
3220 | /* PR 17531: file: 92ca3797. |
3221 | We cannot rely upon the debug_information array being initialised | |
3222 | before it is used. A corrupt file could easily contain references | |
3223 | to a unit for which information has not been made available. So | |
3224 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
3225 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
3226 | ||
82b1b41b | 3227 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
3228 | } |
3229 | ||
3230 | if (!do_loc) | |
3231 | { | |
dda8d76d NC |
3232 | load_debug_section_with_follow (str, file); |
3233 | load_debug_section_with_follow (line_str, file); | |
3234 | load_debug_section_with_follow (str_dwo, file); | |
3235 | load_debug_section_with_follow (str_index, file); | |
3236 | load_debug_section_with_follow (str_index_dwo, file); | |
3237 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e | 3238 | } |
e4b7104b | 3239 | |
dda8d76d | 3240 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 3241 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
3242 | { |
3243 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 3244 | debug_displays [abbrev_sec].section.uncompressed_name); |
d85bf2ba | 3245 | return FALSE; |
19e6b90e L |
3246 | } |
3247 | ||
dda8d76d NC |
3248 | if (!do_loc && dwarf_start_die == 0) |
3249 | introduce (section, FALSE); | |
3250 | ||
19e6b90e L |
3251 | for (section_begin = start, unit = 0; start < end; unit++) |
3252 | { | |
3253 | DWARF2_Internal_CompUnit compunit; | |
3254 | unsigned char *hdrptr; | |
19e6b90e | 3255 | unsigned char *tags; |
fd2f0033 | 3256 | int level, last_level, saved_level; |
467c65bc | 3257 | dwarf_vma cu_offset; |
e98fdf1a | 3258 | unsigned long sec_off; |
bf5117e3 | 3259 | unsigned int offset_size; |
19485196 | 3260 | unsigned int initial_length_size; |
74bc6052 CC |
3261 | dwarf_vma signature_high = 0; |
3262 | dwarf_vma signature_low = 0; | |
767221a9 | 3263 | dwarf_vma type_offset = 0; |
341f9135 CC |
3264 | struct cu_tu_set *this_set; |
3265 | dwarf_vma abbrev_base; | |
3266 | size_t abbrev_size; | |
19e6b90e L |
3267 | |
3268 | hdrptr = start; | |
3269 | ||
0c588247 | 3270 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
3271 | |
3272 | if (compunit.cu_length == 0xffffffff) | |
3273 | { | |
0c588247 | 3274 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
3275 | offset_size = 8; |
3276 | initial_length_size = 12; | |
3277 | } | |
3278 | else | |
3279 | { | |
3280 | offset_size = 4; | |
3281 | initial_length_size = 4; | |
3282 | } | |
3283 | ||
0c588247 | 3284 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
3285 | |
3286 | cu_offset = start - section_begin; | |
19e6b90e | 3287 | |
341f9135 CC |
3288 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3289 | ||
77145576 JK |
3290 | if (compunit.cu_version < 5) |
3291 | { | |
3292 | compunit.cu_unit_type = DW_UT_compile; | |
3293 | /* Initialize it due to a false compiler warning. */ | |
3294 | compunit.cu_pointer_size = -1; | |
3295 | } | |
3296 | else | |
3297 | { | |
3298 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3299 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3300 | ||
3301 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3302 | } | |
3303 | ||
0c588247 | 3304 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 3305 | |
341f9135 CC |
3306 | if (this_set == NULL) |
3307 | { | |
3308 | abbrev_base = 0; | |
3309 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3310 | } | |
3311 | else | |
3312 | { | |
3313 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3314 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3315 | } | |
3316 | ||
77145576 JK |
3317 | if (compunit.cu_version < 5) |
3318 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3319 | ||
f41e4712 NC |
3320 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
3321 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
3322 | { | |
3323 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
3324 | compunit.cu_pointer_size, offset_size); | |
3325 | compunit.cu_pointer_size = offset_size; | |
3326 | } | |
2b6f5997 CC |
3327 | |
3328 | if (do_types) | |
b4eb7656 | 3329 | { |
0c588247 | 3330 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 3331 | hdrptr += 8; |
0c588247 | 3332 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 3333 | } |
2b6f5997 | 3334 | |
ae7e7825 NC |
3335 | if (dwarf_start_die > (cu_offset + compunit.cu_length |
3336 | + initial_length_size)) | |
3337 | { | |
3338 | start = section_begin + cu_offset + compunit.cu_length | |
3339 | + initial_length_size; | |
3340 | continue; | |
3341 | } | |
3342 | ||
19e6b90e | 3343 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 | 3344 | && num_debug_info_entries == 0 |
c4b2f181 | 3345 | && alloc_num_debug_info_entries > unit |
2b6f5997 | 3346 | && ! do_types) |
19e6b90e L |
3347 | { |
3348 | debug_information [unit].cu_offset = cu_offset; | |
3349 | debug_information [unit].pointer_size | |
3350 | = compunit.cu_pointer_size; | |
b7807392 JJ |
3351 | debug_information [unit].offset_size = offset_size; |
3352 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 3353 | debug_information [unit].base_address = 0; |
4723351a CC |
3354 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
3355 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
3356 | debug_information [unit].loc_offsets = NULL; |
3357 | debug_information [unit].have_frame_base = NULL; | |
3358 | debug_information [unit].max_loc_offsets = 0; | |
3359 | debug_information [unit].num_loc_offsets = 0; | |
3360 | debug_information [unit].range_lists = NULL; | |
3361 | debug_information [unit].max_range_lists= 0; | |
3362 | debug_information [unit].num_range_lists = 0; | |
3363 | } | |
3364 | ||
fd2f0033 | 3365 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 3366 | { |
47704ddf KT |
3367 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3368 | dwarf_vmatoa ("x", cu_offset)); | |
3369 | printf (_(" Length: 0x%s (%s)\n"), | |
3370 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3371 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3372 | printf (_(" Version: %d\n"), compunit.cu_version); |
debd1a62 MW |
3373 | if (compunit.cu_version >= 5) |
3374 | printf (_(" Unit Type: %s (%x)\n"), | |
3375 | get_DW_UT_name (compunit.cu_unit_type) ?: "???", | |
3376 | compunit.cu_unit_type); | |
7282333f AM |
3377 | printf (_(" Abbrev Offset: 0x%s\n"), |
3378 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3379 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3380 | if (do_types) |
3381 | { | |
74bc6052 CC |
3382 | char buf[64]; |
3383 | ||
3384 | printf (_(" Signature: 0x%s\n"), | |
3385 | dwarf_vmatoa64 (signature_high, signature_low, | |
3386 | buf, sizeof (buf))); | |
3387 | printf (_(" Type Offset: 0x%s\n"), | |
3388 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3389 | } |
341f9135 CC |
3390 | if (this_set != NULL) |
3391 | { | |
3392 | dwarf_vma *offsets = this_set->section_offsets; | |
3393 | size_t *sizes = this_set->section_sizes; | |
3394 | ||
3395 | printf (_(" Section contributions:\n")); | |
3396 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3397 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3398 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3399 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3400 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3401 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3402 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3403 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3404 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3405 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3406 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3407 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3408 | } | |
19e6b90e L |
3409 | } |
3410 | ||
e98fdf1a AM |
3411 | sec_off = cu_offset + initial_length_size; |
3412 | if (sec_off + compunit.cu_length < sec_off | |
3413 | || sec_off + compunit.cu_length > section->size) | |
460c89ff | 3414 | { |
e98fdf1a AM |
3415 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
3416 | section->name, | |
3417 | (unsigned long) cu_offset, | |
19485196 NC |
3418 | dwarf_vmatoa ("x", compunit.cu_length)); |
3419 | num_units = unit; | |
3420 | break; | |
3421 | } | |
3422 | ||
460c89ff NS |
3423 | tags = hdrptr; |
3424 | start += compunit.cu_length + initial_length_size; | |
3425 | ||
77145576 | 3426 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3427 | { |
47704ddf KT |
3428 | warn (_("CU at offset %s contains corrupt or " |
3429 | "unsupported version number: %d.\n"), | |
3430 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3431 | continue; |
3432 | } | |
3433 | ||
77145576 | 3434 | if (compunit.cu_unit_type != DW_UT_compile |
ec47b32a | 3435 | && compunit.cu_unit_type != DW_UT_partial |
77145576 JK |
3436 | && compunit.cu_unit_type != DW_UT_type) |
3437 | { | |
3438 | warn (_("CU at offset %s contains corrupt or " | |
3439 | "unsupported unit type: %d.\n"), | |
3440 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3441 | continue; | |
3442 | } | |
3443 | ||
19e6b90e L |
3444 | free_abbrevs (); |
3445 | ||
d493b283 | 3446 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 3447 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
3448 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
3449 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 3450 | (unsigned long) abbrev_size); |
b4eb7656 | 3451 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
3452 | else if ((abbrev_base + abbrev_size) |
3453 | > debug_displays [abbrev_sec].section.size) | |
3454 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
3455 | (unsigned long) abbrev_base + abbrev_size, | |
3456 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff NS |
3457 | else |
3458 | process_abbrev_section | |
341f9135 CC |
3459 | (((unsigned char *) debug_displays [abbrev_sec].section.start |
3460 | + abbrev_base + compunit.cu_abbrev_offset), | |
3461 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3462 | + abbrev_base + abbrev_size)); | |
19e6b90e L |
3463 | |
3464 | level = 0; | |
fd2f0033 TT |
3465 | last_level = level; |
3466 | saved_level = -1; | |
19e6b90e L |
3467 | while (tags < start) |
3468 | { | |
19e6b90e | 3469 | unsigned long abbrev_number; |
ec4d4525 | 3470 | unsigned long die_offset; |
19e6b90e L |
3471 | abbrev_entry *entry; |
3472 | abbrev_attr *attr; | |
fd2f0033 | 3473 | int do_printing = 1; |
19e6b90e | 3474 | |
ec4d4525 NC |
3475 | die_offset = tags - section_begin; |
3476 | ||
cd30bcef | 3477 | READ_ULEB (abbrev_number, tags, start); |
19e6b90e | 3478 | |
eb7cc021 JK |
3479 | /* A null DIE marks the end of a list of siblings or it may also be |
3480 | a section padding. */ | |
19e6b90e L |
3481 | if (abbrev_number == 0) |
3482 | { | |
eb7cc021 JK |
3483 | /* Check if it can be a section padding for the last CU. */ |
3484 | if (level == 0 && start == end) | |
3485 | { | |
3486 | unsigned char *chk; | |
3487 | ||
3488 | for (chk = tags; chk < start; chk++) | |
3489 | if (*chk != 0) | |
3490 | break; | |
3491 | if (chk == start) | |
3492 | break; | |
3493 | } | |
3494 | ||
4337774f TT |
3495 | if (!do_loc && die_offset >= dwarf_start_die |
3496 | && (dwarf_cutoff_level == -1 | |
3497 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3498 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3499 | level, die_offset); | |
3500 | ||
19e6b90e | 3501 | --level; |
ec4d4525 NC |
3502 | if (level < 0) |
3503 | { | |
3504 | static unsigned num_bogus_warns = 0; | |
3505 | ||
3506 | if (num_bogus_warns < 3) | |
3507 | { | |
4723351a CC |
3508 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3509 | die_offset, section->name); | |
ec4d4525 NC |
3510 | num_bogus_warns ++; |
3511 | if (num_bogus_warns == 3) | |
3512 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3513 | } | |
3514 | } | |
fd2f0033 | 3515 | if (dwarf_start_die != 0 && level < saved_level) |
d85bf2ba | 3516 | return TRUE; |
19e6b90e L |
3517 | continue; |
3518 | } | |
3519 | ||
4b78141a | 3520 | if (!do_loc) |
fd2f0033 TT |
3521 | { |
3522 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
3523 | do_printing = 0; | |
3524 | else | |
3525 | { | |
3526 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
3527 | saved_level = level; | |
3528 | do_printing = (dwarf_cutoff_level == -1 | |
3529 | || level < dwarf_cutoff_level); | |
3530 | if (do_printing) | |
3531 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
3532 | level, die_offset, abbrev_number); | |
3533 | else if (dwarf_cutoff_level == -1 | |
3534 | || last_level < dwarf_cutoff_level) | |
3535 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
3536 | last_level = level; | |
3537 | } | |
3538 | } | |
cecf136e | 3539 | |
19e6b90e L |
3540 | /* Scan through the abbreviation list until we reach the |
3541 | correct entry. */ | |
3542 | for (entry = first_abbrev; | |
3543 | entry && entry->entry != abbrev_number; | |
3544 | entry = entry->next) | |
3545 | continue; | |
3546 | ||
3547 | if (entry == NULL) | |
3548 | { | |
fd2f0033 | 3549 | if (!do_loc && do_printing) |
4b78141a NC |
3550 | { |
3551 | printf ("\n"); | |
3552 | fflush (stdout); | |
3553 | } | |
f3853b34 | 3554 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 3555 | die_offset, abbrev_number); |
d85bf2ba | 3556 | return FALSE; |
19e6b90e L |
3557 | } |
3558 | ||
fd2f0033 | 3559 | if (!do_loc && do_printing) |
cc5914eb | 3560 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 3561 | |
19e6b90e L |
3562 | switch (entry->tag) |
3563 | { | |
3564 | default: | |
3565 | need_base_address = 0; | |
3566 | break; | |
3567 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
3568 | need_base_address = 1; |
3569 | need_dwo_info = do_loc; | |
19e6b90e L |
3570 | break; |
3571 | case DW_TAG_entry_point: | |
19e6b90e L |
3572 | case DW_TAG_subprogram: |
3573 | need_base_address = 0; | |
3574 | /* Assuming that there is no DW_AT_frame_base. */ | |
3575 | have_frame_base = 0; | |
3576 | break; | |
3577 | } | |
3578 | ||
9f272209 AO |
3579 | debug_info *debug_info_p = |
3580 | (debug_information && unit < alloc_num_debug_info_entries) | |
3581 | ? debug_information + unit : NULL; | |
3582 | ||
3583 | assert (!debug_info_p | |
3584 | || (debug_info_p->num_loc_offsets | |
3585 | == debug_info_p->num_loc_views)); | |
3586 | ||
399c99f7 L |
3587 | for (attr = entry->first_attr; |
3588 | attr && attr->attribute; | |
3589 | attr = attr->next) | |
4b78141a | 3590 | { |
fd2f0033 | 3591 | if (! do_loc && do_printing) |
4b78141a | 3592 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 | 3593 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
3594 | tags = read_and_display_attr (attr->attribute, |
3595 | attr->form, | |
77145576 | 3596 | attr->implicit_const, |
ec1b0fbb | 3597 | section_begin, |
341f9135 | 3598 | tags, |
f6f0e17b | 3599 | end, |
341f9135 | 3600 | cu_offset, |
4b78141a NC |
3601 | compunit.cu_pointer_size, |
3602 | offset_size, | |
3603 | compunit.cu_version, | |
9f272209 | 3604 | debug_info_p, |
341f9135 CC |
3605 | do_loc || ! do_printing, |
3606 | section, | |
ec1b0fbb NC |
3607 | this_set, |
3608 | level); | |
4b78141a | 3609 | } |
cecf136e | 3610 | |
9f272209 AO |
3611 | /* If a locview attribute appears before a location one, |
3612 | make sure we don't associate it with an earlier | |
3613 | loclist. */ | |
3614 | if (debug_info_p) | |
3615 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
3616 | { | |
3617 | case 1: | |
3618 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
3619 | debug_info_p->num_loc_views++; | |
3620 | assert (debug_info_p->num_loc_views | |
3621 | == debug_info_p->num_loc_offsets); | |
3622 | break; | |
3623 | ||
3624 | case 0: | |
3625 | break; | |
3626 | ||
3627 | case -1: | |
3628 | warn(_("DIE has locviews without loclist\n")); | |
3629 | debug_info_p->num_loc_views--; | |
3630 | break; | |
3631 | ||
3632 | default: | |
3633 | assert (0); | |
3634 | } | |
3635 | ||
b4eb7656 AM |
3636 | if (entry->children) |
3637 | ++level; | |
3638 | } | |
19e6b90e | 3639 | } |
cecf136e | 3640 | |
19e6b90e L |
3641 | /* Set num_debug_info_entries here so that it can be used to check if |
3642 | we need to process .debug_loc and .debug_ranges sections. */ | |
3643 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3644 | && num_debug_info_entries == 0 |
3645 | && ! do_types) | |
82b1b41b | 3646 | { |
b4eb7656 | 3647 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
3648 | num_debug_info_entries = alloc_num_debug_info_entries; |
3649 | else | |
3650 | num_debug_info_entries = num_units; | |
3651 | } | |
cecf136e | 3652 | |
19e6b90e | 3653 | if (!do_loc) |
467c65bc | 3654 | printf ("\n"); |
cecf136e | 3655 | |
d85bf2ba | 3656 | return TRUE; |
19e6b90e L |
3657 | } |
3658 | ||
3659 | /* Locate and scan the .debug_info section in the file and record the pointer | |
3660 | sizes and offsets for the compilation units in it. Usually an executable | |
3661 | will have just one pointer size, but this is not guaranteed, and so we try | |
3662 | not to make any assumptions. Returns zero upon failure, or the number of | |
3663 | compilation units upon success. */ | |
3664 | ||
3665 | static unsigned int | |
3666 | load_debug_info (void * file) | |
3667 | { | |
1febe64d | 3668 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 3669 | section then do not bother to repeat the task. */ |
cc86f28f | 3670 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
3671 | return 0; |
3672 | ||
19e6b90e L |
3673 | /* If we already have the information there is nothing else to do. */ |
3674 | if (num_debug_info_entries > 0) | |
3675 | return num_debug_info_entries; | |
3676 | ||
341f9135 | 3677 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 3678 | (void) load_cu_tu_indexes (file); |
341f9135 | 3679 | |
dda8d76d | 3680 | if (load_debug_section_with_follow (info, file) |
d85bf2ba | 3681 | && process_debug_info (&debug_displays [info].section, file, abbrev, TRUE, FALSE)) |
19e6b90e | 3682 | return num_debug_info_entries; |
82b1b41b | 3683 | |
dda8d76d | 3684 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 3685 | && process_debug_info (&debug_displays [info_dwo].section, file, |
d85bf2ba | 3686 | abbrev_dwo, TRUE, FALSE)) |
4723351a | 3687 | return num_debug_info_entries; |
1febe64d | 3688 | |
cc86f28f | 3689 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 3690 | return 0; |
19e6b90e L |
3691 | } |
3692 | ||
b40bf0a2 NC |
3693 | /* Read a DWARF .debug_line section header starting at DATA. |
3694 | Upon success returns an updated DATA pointer and the LINFO | |
3695 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
3696 | Otherwise returns NULL. */ | |
19e6b90e | 3697 | |
b40bf0a2 NC |
3698 | static unsigned char * |
3699 | read_debug_line_header (struct dwarf_section * section, | |
3700 | unsigned char * data, | |
3701 | unsigned char * end, | |
3702 | DWARF2_Internal_LineInfo * linfo, | |
3703 | unsigned char ** end_of_sequence) | |
3704 | { | |
3705 | unsigned char *hdrptr; | |
b40bf0a2 | 3706 | unsigned int initial_length_size; |
19e6b90e | 3707 | |
b40bf0a2 NC |
3708 | /* Extract information from the Line Number Program Header. |
3709 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 3710 | hdrptr = data; |
19e6b90e | 3711 | |
b40bf0a2 NC |
3712 | /* Get and check the length of the block. */ |
3713 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 3714 | |
b40bf0a2 | 3715 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
3716 | { |
3717 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 3718 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 3719 | linfo->li_offset_size = 8; |
f41e4712 NC |
3720 | initial_length_size = 12; |
3721 | } | |
3722 | else | |
3723 | { | |
77145576 | 3724 | linfo->li_offset_size = 4; |
f41e4712 NC |
3725 | initial_length_size = 4; |
3726 | } | |
19e6b90e | 3727 | |
b40bf0a2 | 3728 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 3729 | { |
8fcc61b4 NC |
3730 | /* If the length field has a relocation against it, then we should |
3731 | not complain if it is inaccurate (and probably negative). This | |
3732 | happens in object files when the .debug_line section is actually | |
3733 | comprised of several different .debug_line.* sections, (some of | |
3734 | which may be removed by linker garbage collection), and a relocation | |
3735 | is used to compute the correct length once that is done. */ | |
77145576 | 3736 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 3737 | { |
8fcc61b4 | 3738 | linfo->li_length = (end - data) - initial_length_size; |
b40bf0a2 NC |
3739 | } |
3740 | else | |
3741 | { | |
8fcc61b4 NC |
3742 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
3743 | (long) linfo->li_length); | |
b40bf0a2 NC |
3744 | return NULL; |
3745 | } | |
f41e4712 | 3746 | } |
19e6b90e | 3747 | |
b40bf0a2 NC |
3748 | /* Get and check the version number. */ |
3749 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
3750 | ||
3751 | if (linfo->li_version != 2 | |
3752 | && linfo->li_version != 3 | |
77145576 JK |
3753 | && linfo->li_version != 4 |
3754 | && linfo->li_version != 5) | |
f41e4712 | 3755 | { |
77145576 JK |
3756 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
3757 | "is currently supported.\n")); | |
b40bf0a2 | 3758 | return NULL; |
f41e4712 | 3759 | } |
19e6b90e | 3760 | |
77145576 JK |
3761 | if (linfo->li_version >= 5) |
3762 | { | |
5496f3c6 | 3763 | SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end); |
77145576 | 3764 | |
5496f3c6 NC |
3765 | SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end); |
3766 | if (linfo->li_segment_size != 0) | |
77145576 JK |
3767 | { |
3768 | warn (_("The %s section contains " | |
3769 | "unsupported segment selector size: %d.\n"), | |
5496f3c6 NC |
3770 | section->name, linfo->li_segment_size); |
3771 | return NULL; | |
77145576 JK |
3772 | } |
3773 | } | |
3774 | ||
3775 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
3776 | linfo->li_offset_size, end); | |
b40bf0a2 | 3777 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 3778 | |
b40bf0a2 | 3779 | if (linfo->li_version >= 4) |
f41e4712 | 3780 | { |
b40bf0a2 | 3781 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 3782 | |
b40bf0a2 | 3783 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
3784 | { |
3785 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 3786 | return NULL; |
a233b20c | 3787 | } |
f41e4712 NC |
3788 | } |
3789 | else | |
b40bf0a2 | 3790 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 3791 | |
b40bf0a2 | 3792 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 3793 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
3794 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
3795 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 3796 | |
b40bf0a2 | 3797 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 3798 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
3799 | if (* end_of_sequence > end) |
3800 | { | |
4c219c2e AM |
3801 | warn (_("Line length %s extends beyond end of section\n"), |
3802 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
3803 | * end_of_sequence = end; |
3804 | return NULL; | |
3805 | } | |
3806 | ||
b40bf0a2 NC |
3807 | return hdrptr; |
3808 | } | |
19e6b90e | 3809 | |
77145576 | 3810 | static unsigned char * |
dda8d76d NC |
3811 | display_formatted_table (unsigned char * data, |
3812 | unsigned char * start, | |
3813 | unsigned char * end, | |
3814 | const DWARF2_Internal_LineInfo * linfo, | |
3815 | struct dwarf_section * section, | |
7b8d9e8c | 3816 | bfd_boolean is_dir) |
77145576 JK |
3817 | { |
3818 | unsigned char *format_start, format_count, *format, formati; | |
3819 | dwarf_vma data_count, datai; | |
cd30bcef | 3820 | unsigned int namepass, last_entry = 0; |
5496f3c6 NC |
3821 | const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table"); |
3822 | ||
77145576 | 3823 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
546cb2d8 NC |
3824 | if (do_checks && format_count > 5) |
3825 | warn (_("Unexpectedly large number of columns in the %s (%u)\n"), | |
3826 | table_name, format_count); | |
3827 | ||
77145576 JK |
3828 | format_start = data; |
3829 | for (formati = 0; formati < format_count; formati++) | |
3830 | { | |
cd30bcef AM |
3831 | SKIP_ULEB (data, end); |
3832 | SKIP_ULEB (data, end); | |
77145576 JK |
3833 | if (data == end) |
3834 | { | |
5496f3c6 | 3835 | warn (_("%s: Corrupt format description entry\n"), table_name); |
77145576 JK |
3836 | return data; |
3837 | } | |
3838 | } | |
3839 | ||
cd30bcef | 3840 | READ_ULEB (data_count, data, end); |
546cb2d8 | 3841 | if (data_count == 0) |
77145576 | 3842 | { |
546cb2d8 | 3843 | printf (_("\n The %s is empty.\n"), table_name); |
77145576 JK |
3844 | return data; |
3845 | } | |
546cb2d8 | 3846 | else if (data == end) |
77145576 | 3847 | { |
546cb2d8 NC |
3848 | warn (_("%s: Corrupt entry count - expected %s but none found\n"), |
3849 | table_name, dwarf_vmatoa ("x", data_count)); | |
77145576 JK |
3850 | return data; |
3851 | } | |
546cb2d8 | 3852 | |
5496f3c6 NC |
3853 | else if (format_count == 0) |
3854 | { | |
3855 | warn (_("%s: format count is zero, but the table is not empty\n"), | |
3856 | table_name); | |
3857 | return end; | |
3858 | } | |
77145576 | 3859 | |
5496f3c6 NC |
3860 | printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"), |
3861 | table_name, (long) (data - start), dwarf_vmatoa ("u", data_count), | |
3862 | format_count); | |
77145576 JK |
3863 | |
3864 | printf (_(" Entry")); | |
3865 | /* Delay displaying name as the last entry for better screen layout. */ | |
3866 | for (namepass = 0; namepass < 2; namepass++) | |
3867 | { | |
3868 | format = format_start; | |
3869 | for (formati = 0; formati < format_count; formati++) | |
3870 | { | |
3871 | dwarf_vma content_type; | |
3872 | ||
cd30bcef | 3873 | READ_ULEB (content_type, format, end); |
77145576 JK |
3874 | if ((content_type == DW_LNCT_path) == (namepass == 1)) |
3875 | switch (content_type) | |
3876 | { | |
3877 | case DW_LNCT_path: | |
3878 | printf (_("\tName")); | |
3879 | break; | |
3880 | case DW_LNCT_directory_index: | |
3881 | printf (_("\tDir")); | |
3882 | break; | |
3883 | case DW_LNCT_timestamp: | |
3884 | printf (_("\tTime")); | |
3885 | break; | |
3886 | case DW_LNCT_size: | |
3887 | printf (_("\tSize")); | |
3888 | break; | |
3889 | case DW_LNCT_MD5: | |
5496f3c6 | 3890 | printf (_("\tMD5\t\t\t")); |
77145576 JK |
3891 | break; |
3892 | default: | |
3893 | printf (_("\t(Unknown format content type %s)"), | |
3894 | dwarf_vmatoa ("u", content_type)); | |
3895 | } | |
cd30bcef | 3896 | SKIP_ULEB (format, end); |
77145576 JK |
3897 | } |
3898 | } | |
3899 | putchar ('\n'); | |
3900 | ||
3901 | for (datai = 0; datai < data_count; datai++) | |
3902 | { | |
3903 | unsigned char *datapass = data; | |
3904 | ||
3905 | printf (" %d", last_entry++); | |
3906 | /* Delay displaying name as the last entry for better screen layout. */ | |
3907 | for (namepass = 0; namepass < 2; namepass++) | |
3908 | { | |
3909 | format = format_start; | |
3910 | data = datapass; | |
3911 | for (formati = 0; formati < format_count; formati++) | |
3912 | { | |
3913 | dwarf_vma content_type, form; | |
3914 | ||
cd30bcef AM |
3915 | READ_ULEB (content_type, format, end); |
3916 | READ_ULEB (form, format, end); | |
3917 | data = read_and_display_attr_value (0, form, 0, start, data, end, | |
3918 | 0, 0, linfo->li_offset_size, | |
77145576 JK |
3919 | linfo->li_version, NULL, |
3920 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
ec1b0fbb | 3921 | section, NULL, '\t', -1); |
77145576 JK |
3922 | } |
3923 | } | |
5496f3c6 NC |
3924 | |
3925 | if (data == end && (datai < data_count - 1)) | |
77145576 | 3926 | { |
5496f3c6 | 3927 | warn (_("\n%s: Corrupt entries list\n"), table_name); |
77145576 JK |
3928 | return data; |
3929 | } | |
3930 | putchar ('\n'); | |
3931 | } | |
3932 | return data; | |
3933 | } | |
3934 | ||
b40bf0a2 | 3935 | static int |
dda8d76d NC |
3936 | display_debug_lines_raw (struct dwarf_section * section, |
3937 | unsigned char * data, | |
3938 | unsigned char * end, | |
3939 | void * file) | |
b40bf0a2 NC |
3940 | { |
3941 | unsigned char *start = section->start; | |
ba8826a8 | 3942 | int verbose_view = 0; |
19e6b90e | 3943 | |
dda8d76d | 3944 | introduce (section, TRUE); |
19e6b90e | 3945 | |
b40bf0a2 NC |
3946 | while (data < end) |
3947 | { | |
3948 | static DWARF2_Internal_LineInfo saved_linfo; | |
3949 | DWARF2_Internal_LineInfo linfo; | |
3950 | unsigned char *standard_opcodes; | |
3951 | unsigned char *end_of_sequence; | |
fe59e83d | 3952 | int i; |
19e6b90e | 3953 | |
4925cdd7 NC |
3954 | if (const_strneq (section->name, ".debug_line.") |
3955 | /* Note: the following does not apply to .debug_line.dwo sections. | |
3956 | These are full debug_line sections. */ | |
3957 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 3958 | { |
b40bf0a2 NC |
3959 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
3960 | section containing just the Line Number Statements. They are | |
3961 | created by the assembler and intended to be used alongside gcc's | |
3962 | -ffunction-sections command line option. When the linker's | |
3963 | garbage collection decides to discard a .text.<foo> section it | |
3964 | can then also discard the line number information in .debug_line.<foo>. | |
3965 | ||
4925cdd7 | 3966 | Since the section is a fragment it does not have the details |
b40bf0a2 | 3967 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 3968 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
3969 | end_of_sequence = end; |
3970 | standard_opcodes = NULL; | |
3971 | linfo = saved_linfo; | |
058037d3 NC |
3972 | /* PR 17531: file: 0522b371. */ |
3973 | if (linfo.li_line_range == 0) | |
3974 | { | |
1306a742 | 3975 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
3976 | return 0; |
3977 | } | |
b40bf0a2 | 3978 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3979 | } |
19e6b90e L |
3980 | else |
3981 | { | |
b40bf0a2 | 3982 | unsigned char * hdrptr; |
19e6b90e | 3983 | |
b40bf0a2 NC |
3984 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
3985 | & end_of_sequence)) == NULL) | |
3986 | return 0; | |
19e6b90e | 3987 | |
b40bf0a2 NC |
3988 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
3989 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
3990 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
5496f3c6 NC |
3991 | if (linfo.li_version >= 5) |
3992 | { | |
3993 | printf (_(" Address size (bytes): %d\n"), linfo.li_address_size); | |
3994 | printf (_(" Segment selector (bytes): %d\n"), linfo.li_segment_size); | |
3995 | } | |
77ef8654 | 3996 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
3997 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
3998 | if (linfo.li_version >= 4) | |
3999 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
4000 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
4001 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
4002 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
4003 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 4004 | |
0a9d414a NC |
4005 | /* PR 17512: file: 1665-6428-0.004. */ |
4006 | if (linfo.li_line_range == 0) | |
4007 | { | |
4008 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4009 | linfo.li_line_range = 1; | |
4010 | } | |
77ef8654 | 4011 | |
b40bf0a2 | 4012 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4013 | |
b40bf0a2 NC |
4014 | /* Display the contents of the Opcodes table. */ |
4015 | standard_opcodes = hdrptr; | |
19e6b90e | 4016 | |
6937bb54 NC |
4017 | /* PR 17512: file: 002-417945-0.004. */ |
4018 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
4019 | { | |
4020 | warn (_("Line Base extends beyond end of section\n")); | |
4021 | return 0; | |
4022 | } | |
4023 | ||
b40bf0a2 | 4024 | printf (_("\n Opcodes:\n")); |
19e6b90e | 4025 | |
b40bf0a2 | 4026 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
4027 | printf (ngettext (" Opcode %d has %d arg\n", |
4028 | " Opcode %d has %d args\n", | |
4029 | standard_opcodes[i - 1]), | |
4030 | i, standard_opcodes[i - 1]); | |
19e6b90e | 4031 | |
b40bf0a2 NC |
4032 | /* Display the contents of the Directory table. */ |
4033 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 4034 | |
77145576 | 4035 | if (linfo.li_version >= 5) |
b40bf0a2 | 4036 | { |
dda8d76d | 4037 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 4038 | |
77145576 | 4039 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 4040 | TRUE); |
77145576 | 4041 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 4042 | FALSE); |
77145576 JK |
4043 | } |
4044 | else | |
4045 | { | |
4046 | if (*data == 0) | |
4047 | printf (_("\n The Directory Table is empty.\n")); | |
4048 | else | |
a233b20c | 4049 | { |
77145576 | 4050 | unsigned int last_dir_entry = 0; |
6937bb54 | 4051 | |
77145576 JK |
4052 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
4053 | (long)(data - start)); | |
19e6b90e | 4054 | |
77145576 JK |
4055 | while (data < end && *data != 0) |
4056 | { | |
4057 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 4058 | |
77145576 JK |
4059 | data += strnlen ((char *) data, end - data) + 1; |
4060 | } | |
19e6b90e | 4061 | |
77145576 JK |
4062 | /* PR 17512: file: 002-132094-0.004. */ |
4063 | if (data >= end - 1) | |
4064 | break; | |
4065 | } | |
19e6b90e | 4066 | |
77145576 JK |
4067 | /* Skip the NUL at the end of the table. */ |
4068 | data++; | |
19e6b90e | 4069 | |
77145576 JK |
4070 | /* Display the contents of the File Name table. */ |
4071 | if (*data == 0) | |
4072 | printf (_("\n The File Name Table is empty.\n")); | |
4073 | else | |
4074 | { | |
4075 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
4076 | (long)(data - start)); | |
4077 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 4078 | |
77145576 | 4079 | while (data < end && *data != 0) |
b40bf0a2 | 4080 | { |
77145576 | 4081 | unsigned char *name; |
cd30bcef | 4082 | dwarf_vma val; |
77145576 JK |
4083 | |
4084 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
4085 | name = data; | |
4086 | data += strnlen ((char *) data, end - data) + 1; | |
4087 | ||
cd30bcef AM |
4088 | READ_ULEB (val, data, end); |
4089 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4090 | READ_ULEB (val, data, end); | |
4091 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4092 | READ_ULEB (val, data, end); | |
4093 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
77145576 JK |
4094 | printf ("%.*s\n", (int)(end - name), name); |
4095 | ||
4096 | if (data == end) | |
4097 | { | |
4098 | warn (_("Corrupt file name table entry\n")); | |
4099 | break; | |
4100 | } | |
b40bf0a2 | 4101 | } |
a233b20c | 4102 | } |
77145576 JK |
4103 | |
4104 | /* Skip the NUL at the end of the table. */ | |
4105 | data++; | |
b40bf0a2 | 4106 | } |
19e6b90e | 4107 | |
b40bf0a2 NC |
4108 | putchar ('\n'); |
4109 | saved_linfo = linfo; | |
4110 | } | |
19e6b90e | 4111 | |
b40bf0a2 NC |
4112 | /* Now display the statements. */ |
4113 | if (data >= end_of_sequence) | |
4114 | printf (_(" No Line Number Statements.\n")); | |
4115 | else | |
4116 | { | |
4117 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 4118 | |
b40bf0a2 NC |
4119 | while (data < end_of_sequence) |
4120 | { | |
4121 | unsigned char op_code; | |
4122 | dwarf_signed_vma adv; | |
4123 | dwarf_vma uladv; | |
19e6b90e | 4124 | |
fe59e83d CC |
4125 | printf (" [0x%08lx]", (long)(data - start)); |
4126 | ||
b40bf0a2 | 4127 | op_code = *data++; |
19e6b90e | 4128 | |
b40bf0a2 | 4129 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 4130 | { |
b40bf0a2 NC |
4131 | op_code -= linfo.li_opcode_base; |
4132 | uladv = (op_code / linfo.li_line_range); | |
4133 | if (linfo.li_max_ops_per_insn == 1) | |
4134 | { | |
4135 | uladv *= linfo.li_min_insn_length; | |
4136 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4137 | if (uladv) |
4138 | state_machine_regs.view = 0; | |
b40bf0a2 | 4139 | printf (_(" Special opcode %d: " |
ba8826a8 | 4140 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 4141 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4142 | dwarf_vmatoa ("x", state_machine_regs.address), |
4143 | verbose_view && uladv | |
4144 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4145 | } |
4146 | else | |
4147 | { | |
ba8826a8 AO |
4148 | unsigned addrdelta |
4149 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
4150 | / linfo.li_max_ops_per_insn) |
4151 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
4152 | |
4153 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
4154 | state_machine_regs.op_index |
4155 | = (state_machine_regs.op_index + uladv) | |
4156 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4157 | if (addrdelta) |
4158 | state_machine_regs.view = 0; | |
b40bf0a2 | 4159 | printf (_(" Special opcode %d: " |
ba8826a8 | 4160 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
4161 | op_code, dwarf_vmatoa ("u", uladv), |
4162 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4163 | state_machine_regs.op_index, |
4164 | verbose_view && addrdelta | |
4165 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4166 | } |
4167 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
4168 | state_machine_regs.line += adv; | |
ba8826a8 | 4169 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 4170 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
4171 | if (verbose_view || state_machine_regs.view) |
4172 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4173 | else | |
4174 | putchar ('\n'); | |
4175 | state_machine_regs.view++; | |
19e6b90e | 4176 | } |
cd30bcef AM |
4177 | else |
4178 | switch (op_code) | |
4179 | { | |
4180 | case DW_LNS_extended_op: | |
4181 | data += process_extended_line_op (data, | |
4182 | linfo.li_default_is_stmt, | |
4183 | end); | |
4184 | break; | |
4185 | ||
4186 | case DW_LNS_copy: | |
4187 | printf (_(" Copy")); | |
4188 | if (verbose_view || state_machine_regs.view) | |
4189 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4190 | else | |
4191 | putchar ('\n'); | |
4192 | state_machine_regs.view++; | |
4193 | break; | |
4194 | ||
4195 | case DW_LNS_advance_pc: | |
4196 | READ_ULEB (uladv, data, end); | |
4197 | if (linfo.li_max_ops_per_insn == 1) | |
4198 | { | |
4199 | uladv *= linfo.li_min_insn_length; | |
4200 | state_machine_regs.address += uladv; | |
4201 | if (uladv) | |
4202 | state_machine_regs.view = 0; | |
4203 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
4204 | dwarf_vmatoa ("u", uladv), | |
4205 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4206 | verbose_view && uladv | |
4207 | ? _(" (reset view)") : ""); | |
4208 | } | |
4209 | else | |
4210 | { | |
4211 | unsigned addrdelta | |
4212 | = ((state_machine_regs.op_index + uladv) | |
4213 | / linfo.li_max_ops_per_insn) | |
4214 | * linfo.li_min_insn_length; | |
4215 | state_machine_regs.address | |
4216 | += addrdelta; | |
4217 | state_machine_regs.op_index | |
4218 | = (state_machine_regs.op_index + uladv) | |
4219 | % linfo.li_max_ops_per_insn; | |
4220 | if (addrdelta) | |
4221 | state_machine_regs.view = 0; | |
4222 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
4223 | dwarf_vmatoa ("u", uladv), | |
4224 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4225 | state_machine_regs.op_index, | |
4226 | verbose_view && addrdelta | |
4227 | ? _(" (reset view)") : ""); | |
4228 | } | |
4229 | break; | |
4230 | ||
4231 | case DW_LNS_advance_line: | |
4232 | READ_SLEB (adv, data, end); | |
4233 | state_machine_regs.line += adv; | |
4234 | printf (_(" Advance Line by %s to %d\n"), | |
4235 | dwarf_vmatoa ("d", adv), | |
4236 | state_machine_regs.line); | |
4237 | break; | |
4238 | ||
4239 | case DW_LNS_set_file: | |
4240 | READ_ULEB (uladv, data, end); | |
4241 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
4242 | dwarf_vmatoa ("u", uladv)); | |
4243 | state_machine_regs.file = uladv; | |
4244 | break; | |
4245 | ||
4246 | case DW_LNS_set_column: | |
4247 | READ_ULEB (uladv, data, end); | |
4248 | printf (_(" Set column to %s\n"), | |
4249 | dwarf_vmatoa ("u", uladv)); | |
4250 | state_machine_regs.column = uladv; | |
4251 | break; | |
4252 | ||
4253 | case DW_LNS_negate_stmt: | |
4254 | adv = state_machine_regs.is_stmt; | |
4255 | adv = ! adv; | |
4256 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
4257 | state_machine_regs.is_stmt = adv; | |
4258 | break; | |
4259 | ||
4260 | case DW_LNS_set_basic_block: | |
4261 | printf (_(" Set basic block\n")); | |
4262 | state_machine_regs.basic_block = 1; | |
4263 | break; | |
4264 | ||
4265 | case DW_LNS_const_add_pc: | |
4266 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4267 | if (linfo.li_max_ops_per_insn) | |
4268 | { | |
4269 | uladv *= linfo.li_min_insn_length; | |
4270 | state_machine_regs.address += uladv; | |
4271 | if (uladv) | |
4272 | state_machine_regs.view = 0; | |
4273 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
4274 | dwarf_vmatoa ("u", uladv), | |
4275 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4276 | verbose_view && uladv | |
4277 | ? _(" (reset view)") : ""); | |
4278 | } | |
4279 | else | |
4280 | { | |
4281 | unsigned addrdelta | |
4282 | = ((state_machine_regs.op_index + uladv) | |
4283 | / linfo.li_max_ops_per_insn) | |
4284 | * linfo.li_min_insn_length; | |
4285 | state_machine_regs.address | |
4286 | += addrdelta; | |
4287 | state_machine_regs.op_index | |
4288 | = (state_machine_regs.op_index + uladv) | |
4289 | % linfo.li_max_ops_per_insn; | |
4290 | if (addrdelta) | |
4291 | state_machine_regs.view = 0; | |
4292 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
4293 | dwarf_vmatoa ("u", uladv), | |
4294 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4295 | state_machine_regs.op_index, | |
4296 | verbose_view && addrdelta | |
4297 | ? _(" (reset view)") : ""); | |
4298 | } | |
4299 | break; | |
4300 | ||
4301 | case DW_LNS_fixed_advance_pc: | |
4302 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4303 | state_machine_regs.address += uladv; | |
4304 | state_machine_regs.op_index = 0; | |
4305 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
4306 | dwarf_vmatoa ("u", uladv), | |
4307 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
4308 | /* Do NOT reset view. */ | |
4309 | break; | |
4310 | ||
4311 | case DW_LNS_set_prologue_end: | |
4312 | printf (_(" Set prologue_end to true\n")); | |
4313 | break; | |
4314 | ||
4315 | case DW_LNS_set_epilogue_begin: | |
4316 | printf (_(" Set epilogue_begin to true\n")); | |
4317 | break; | |
4318 | ||
4319 | case DW_LNS_set_isa: | |
4320 | READ_ULEB (uladv, data, end); | |
4321 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
4322 | break; | |
4323 | ||
4324 | default: | |
4325 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4326 | ||
4327 | if (standard_opcodes != NULL) | |
4328 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4329 | { | |
4330 | READ_ULEB (uladv, data, end); | |
4331 | printf ("0x%s%s", dwarf_vmatoa ("x", uladv), | |
4332 | i == 1 ? "" : ", "); | |
4333 | } | |
4334 | putchar ('\n'); | |
4335 | break; | |
4336 | } | |
19e6b90e | 4337 | } |
b40bf0a2 | 4338 | putchar ('\n'); |
19e6b90e | 4339 | } |
19e6b90e L |
4340 | } |
4341 | ||
4342 | return 1; | |
4343 | } | |
4344 | ||
a262ae96 NC |
4345 | typedef struct |
4346 | { | |
467c65bc NC |
4347 | unsigned char *name; |
4348 | unsigned int directory_index; | |
4349 | unsigned int modification_date; | |
4350 | unsigned int length; | |
a262ae96 NC |
4351 | } File_Entry; |
4352 | ||
4353 | /* Output a decoded representation of the .debug_line section. */ | |
4354 | ||
4355 | static int | |
dda8d76d | 4356 | display_debug_lines_decoded (struct dwarf_section * section, |
ec1b0fbb | 4357 | unsigned char * start, |
dda8d76d NC |
4358 | unsigned char * data, |
4359 | unsigned char * end, | |
4360 | void * fileptr) | |
a262ae96 | 4361 | { |
b40bf0a2 NC |
4362 | static DWARF2_Internal_LineInfo saved_linfo; |
4363 | ||
dda8d76d | 4364 | introduce (section, FALSE); |
a262ae96 NC |
4365 | |
4366 | while (data < end) | |
4367 | { | |
4368 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4369 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4370 | unsigned char *standard_opcodes; |
4371 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4372 | int i; |
4373 | File_Entry *file_table = NULL; | |
143a3db0 | 4374 | unsigned int n_files = 0; |
a262ae96 | 4375 | unsigned char **directory_table = NULL; |
77145576 | 4376 | dwarf_vma n_directories = 0; |
a262ae96 | 4377 | |
4925cdd7 NC |
4378 | if (const_strneq (section->name, ".debug_line.") |
4379 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4380 | These are full debug_line sections. */ | |
4381 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4382 | { |
4925cdd7 | 4383 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4384 | end_of_sequence = end; |
4385 | standard_opcodes = NULL; | |
4386 | linfo = saved_linfo; | |
058037d3 NC |
4387 | /* PR 17531: file: 0522b371. */ |
4388 | if (linfo.li_line_range == 0) | |
4389 | { | |
1306a742 | 4390 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4391 | return 0; |
4392 | } | |
b40bf0a2 | 4393 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4394 | } |
a262ae96 | 4395 | else |
b4eb7656 | 4396 | { |
b40bf0a2 | 4397 | unsigned char *hdrptr; |
a262ae96 | 4398 | |
b40bf0a2 NC |
4399 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4400 | & end_of_sequence)) == NULL) | |
a233b20c | 4401 | return 0; |
0c588247 | 4402 | |
058037d3 NC |
4403 | /* PR 17531: file: 0522b371. */ |
4404 | if (linfo.li_line_range == 0) | |
4405 | { | |
4406 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4407 | linfo.li_line_range = 1; | |
4408 | } | |
b40bf0a2 | 4409 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4410 | |
b40bf0a2 NC |
4411 | /* Save a pointer to the contents of the Opcodes table. */ |
4412 | standard_opcodes = hdrptr; | |
a262ae96 | 4413 | |
b40bf0a2 NC |
4414 | /* Traverse the Directory table just to count entries. */ |
4415 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4416 | /* PR 20440 */ |
4417 | if (data >= end) | |
4418 | { | |
4419 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4420 | linfo.li_opcode_base); | |
4421 | return 0; | |
4422 | } | |
4423 | ||
77145576 | 4424 | if (linfo.li_version >= 5) |
b40bf0a2 | 4425 | { |
77145576 JK |
4426 | unsigned char *format_start, format_count, *format; |
4427 | dwarf_vma formati, entryi; | |
a262ae96 | 4428 | |
dda8d76d | 4429 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4430 | |
4431 | /* Skip directories format. */ | |
4432 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4433 | if (do_checks && format_count > 1) |
4434 | warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"), | |
4435 | format_count); | |
77145576 JK |
4436 | format_start = data; |
4437 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4438 | { |
cd30bcef AM |
4439 | SKIP_ULEB (data, end); |
4440 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4441 | } |
a262ae96 | 4442 | |
cd30bcef | 4443 | READ_ULEB (n_directories, data, end); |
77145576 | 4444 | if (data == end) |
d8024a91 | 4445 | { |
77145576 | 4446 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
4447 | break; |
4448 | } | |
4449 | ||
070b775f NC |
4450 | if (n_directories == 0) |
4451 | directory_table = NULL; | |
4452 | else | |
4453 | directory_table = (unsigned char **) | |
4454 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 4455 | |
77145576 | 4456 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 4457 | { |
77145576 | 4458 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 4459 | |
77145576 JK |
4460 | format = format_start; |
4461 | for (formati = 0; formati < format_count; formati++) | |
4462 | { | |
4463 | dwarf_vma content_type, form; | |
4464 | dwarf_vma uvalue; | |
4465 | ||
cd30bcef AM |
4466 | READ_ULEB (content_type, format, end); |
4467 | READ_ULEB (form, format, end); | |
77145576 JK |
4468 | if (data == end) |
4469 | { | |
4470 | warn (_("Corrupt directories list\n")); | |
4471 | break; | |
4472 | } | |
4473 | switch (content_type) | |
4474 | { | |
4475 | case DW_LNCT_path: | |
4476 | switch (form) | |
4477 | { | |
4478 | case DW_FORM_string: | |
4479 | *pathp = data; | |
4480 | break; | |
4481 | case DW_FORM_line_strp: | |
4482 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4483 | end); | |
4484 | /* Remove const by the cast. */ | |
4485 | *pathp = (unsigned char *) | |
4486 | fetch_indirect_line_string (uvalue); | |
4487 | break; | |
4488 | } | |
4489 | break; | |
4490 | } | |
cd30bcef AM |
4491 | data = read_and_display_attr_value (0, form, 0, start, |
4492 | data, end, 0, 0, | |
77145576 JK |
4493 | linfo.li_offset_size, |
4494 | linfo.li_version, | |
4495 | NULL, 1, section, | |
ec1b0fbb | 4496 | NULL, '\t', -1); |
77145576 JK |
4497 | } |
4498 | if (data == end) | |
4499 | { | |
4500 | warn (_("Corrupt directories list\n")); | |
4501 | break; | |
4502 | } | |
4503 | } | |
a262ae96 | 4504 | |
77145576 JK |
4505 | /* Skip files format. */ |
4506 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4507 | if (do_checks && format_count > 5) |
4508 | warn (_("Unexpectedly large number of columns in the file name table (%u)\n"), | |
4509 | format_count); | |
77145576 JK |
4510 | format_start = data; |
4511 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4512 | { |
cd30bcef AM |
4513 | SKIP_ULEB (data, end); |
4514 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4515 | } |
a262ae96 | 4516 | |
cd30bcef | 4517 | READ_ULEB (n_files, data, end); |
070b775f | 4518 | if (data == end && n_files > 0) |
d8024a91 | 4519 | { |
77145576 | 4520 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
4521 | break; |
4522 | } | |
4523 | ||
070b775f NC |
4524 | if (n_files == 0) |
4525 | file_table = NULL; | |
4526 | else | |
4527 | file_table = (File_Entry *) xcalloc (1, n_files | |
4528 | * sizeof (File_Entry)); | |
a262ae96 | 4529 | |
77145576 | 4530 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 4531 | { |
77145576 | 4532 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 4533 | |
77145576 JK |
4534 | format = format_start; |
4535 | for (formati = 0; formati < format_count; formati++) | |
4536 | { | |
4537 | dwarf_vma content_type, form; | |
4538 | dwarf_vma uvalue; | |
cd30bcef | 4539 | unsigned char *tmp; |
77145576 | 4540 | |
cd30bcef AM |
4541 | READ_ULEB (content_type, format, end); |
4542 | READ_ULEB (form, format, end); | |
77145576 JK |
4543 | if (data == end) |
4544 | { | |
4545 | warn (_("Corrupt file name list\n")); | |
4546 | break; | |
4547 | } | |
4548 | switch (content_type) | |
4549 | { | |
4550 | case DW_LNCT_path: | |
4551 | switch (form) | |
4552 | { | |
4553 | case DW_FORM_string: | |
4554 | file->name = data; | |
4555 | break; | |
4556 | case DW_FORM_line_strp: | |
4557 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4558 | end); | |
4559 | /* Remove const by the cast. */ | |
4560 | file->name = (unsigned char *) | |
4561 | fetch_indirect_line_string (uvalue); | |
4562 | break; | |
4563 | } | |
4564 | break; | |
4565 | case DW_LNCT_directory_index: | |
4566 | switch (form) | |
4567 | { | |
4568 | case DW_FORM_data1: | |
4569 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
4570 | end); | |
4571 | break; | |
4572 | case DW_FORM_data2: | |
4573 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
4574 | end); | |
4575 | break; | |
4576 | case DW_FORM_udata: | |
cd30bcef AM |
4577 | tmp = data; |
4578 | READ_ULEB (file->directory_index, tmp, end); | |
77145576 JK |
4579 | break; |
4580 | } | |
4581 | break; | |
4582 | } | |
cd30bcef AM |
4583 | data = read_and_display_attr_value (0, form, 0, start, |
4584 | data, end, 0, 0, | |
77145576 JK |
4585 | linfo.li_offset_size, |
4586 | linfo.li_version, | |
4587 | NULL, 1, section, | |
ec1b0fbb | 4588 | NULL, '\t', -1); |
77145576 JK |
4589 | } |
4590 | if (data == end) | |
4591 | { | |
4592 | warn (_("Corrupt file name list\n")); | |
4593 | break; | |
4594 | } | |
4595 | } | |
4596 | } | |
4597 | else | |
4598 | { | |
4599 | if (*data != 0) | |
b40bf0a2 | 4600 | { |
77145576 JK |
4601 | unsigned char *ptr_directory_table = data; |
4602 | ||
4603 | while (data < end && *data != 0) | |
4604 | { | |
4605 | data += strnlen ((char *) data, end - data) + 1; | |
4606 | n_directories++; | |
4607 | } | |
4608 | ||
4609 | /* PR 20440 */ | |
4610 | if (data >= end) | |
4611 | { | |
4612 | warn (_("directory table ends unexpectedly\n")); | |
4613 | n_directories = 0; | |
4614 | break; | |
4615 | } | |
4616 | ||
4617 | /* Go through the directory table again to save the directories. */ | |
4618 | directory_table = (unsigned char **) | |
4619 | xmalloc (n_directories * sizeof (unsigned char *)); | |
4620 | ||
4621 | i = 0; | |
4622 | while (*ptr_directory_table != 0) | |
4623 | { | |
4624 | directory_table[i] = ptr_directory_table; | |
4625 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
4626 | ptr_directory_table - end) + 1; | |
4627 | i++; | |
4628 | } | |
b40bf0a2 | 4629 | } |
77145576 JK |
4630 | /* Skip the NUL at the end of the table. */ |
4631 | data++; | |
4632 | ||
4633 | /* Traverse the File Name table just to count the entries. */ | |
4634 | if (data < end && *data != 0) | |
b40bf0a2 | 4635 | { |
77145576 JK |
4636 | unsigned char *ptr_file_name_table = data; |
4637 | ||
4638 | while (data < end && *data != 0) | |
db9537d2 | 4639 | { |
cd30bcef AM |
4640 | /* Skip Name, directory index, last modification |
4641 | time and length of file. */ | |
77145576 | 4642 | data += strnlen ((char *) data, end - data) + 1; |
cd30bcef AM |
4643 | SKIP_ULEB (data, end); |
4644 | SKIP_ULEB (data, end); | |
4645 | SKIP_ULEB (data, end); | |
77145576 | 4646 | n_files++; |
db9537d2 | 4647 | } |
a262ae96 | 4648 | |
77145576 JK |
4649 | if (data >= end) |
4650 | { | |
4651 | warn (_("file table ends unexpectedly\n")); | |
4652 | n_files = 0; | |
4653 | break; | |
4654 | } | |
4655 | ||
4656 | /* Go through the file table again to save the strings. */ | |
4657 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 4658 | |
77145576 JK |
4659 | i = 0; |
4660 | while (*ptr_file_name_table != 0) | |
4661 | { | |
77145576 JK |
4662 | file_table[i].name = ptr_file_name_table; |
4663 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
4664 | end - ptr_file_name_table) + 1; | |
4665 | ||
4666 | /* We are not interested in directory, time or size. */ | |
cd30bcef AM |
4667 | READ_ULEB (file_table[i].directory_index, |
4668 | ptr_file_name_table, end); | |
4669 | READ_ULEB (file_table[i].modification_date, | |
4670 | ptr_file_name_table, end); | |
4671 | READ_ULEB (file_table[i].length, | |
4672 | ptr_file_name_table, end); | |
77145576 JK |
4673 | i++; |
4674 | } | |
4675 | i = 0; | |
b40bf0a2 | 4676 | } |
77145576 JK |
4677 | |
4678 | /* Skip the NUL at the end of the table. */ | |
4679 | data++; | |
b40bf0a2 | 4680 | } |
cc5914eb | 4681 | |
77145576 | 4682 | /* Print the Compilation Unit's name and a header. */ |
f082820d | 4683 | if (file_table == NULL) |
070b775f | 4684 | printf (_("CU: No directory table\n")); |
f082820d AM |
4685 | else if (directory_table == NULL) |
4686 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
4687 | else |
4688 | { | |
4689 | unsigned int ix = file_table[0].directory_index; | |
4690 | const char *directory; | |
4691 | ||
4692 | if (ix == 0) | |
4693 | directory = "."; | |
4694 | /* PR 20439 */ | |
4695 | else if (n_directories == 0) | |
4696 | directory = _("<unknown>"); | |
4697 | else if (ix > n_directories) | |
4698 | { | |
4699 | warn (_("directory index %u > number of directories %s\n"), | |
4700 | ix, dwarf_vmatoa ("u", n_directories)); | |
4701 | directory = _("<corrupt>"); | |
4702 | } | |
4703 | else | |
4704 | directory = (char *) directory_table[ix - 1]; | |
4705 | ||
4706 | if (do_wide || strlen (directory) < 76) | |
4707 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
4708 | else | |
4709 | printf ("%s:\n", file_table[0].name); | |
77145576 | 4710 | } |
a262ae96 | 4711 | |
070b775f NC |
4712 | if (n_files > 0) |
4713 | printf (_("File name Line number Starting address View Stmt\n")); | |
4714 | else | |
4715 | printf (_("CU: Empty file name table\n")); | |
b40bf0a2 NC |
4716 | saved_linfo = linfo; |
4717 | } | |
a262ae96 NC |
4718 | |
4719 | /* This loop iterates through the Dwarf Line Number Program. */ | |
4720 | while (data < end_of_sequence) | |
b4eb7656 | 4721 | { |
a262ae96 | 4722 | unsigned char op_code; |
ba8826a8 | 4723 | int xop; |
b4eb7656 AM |
4724 | int adv; |
4725 | unsigned long int uladv; | |
b4eb7656 | 4726 | int is_special_opcode = 0; |
a262ae96 | 4727 | |
b4eb7656 | 4728 | op_code = *data++; |
ba8826a8 | 4729 | xop = op_code; |
a262ae96 | 4730 | |
b4eb7656 | 4731 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 4732 | { |
91d6fa6a | 4733 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
4734 | uladv = (op_code / linfo.li_line_range); |
4735 | if (linfo.li_max_ops_per_insn == 1) | |
4736 | { | |
4737 | uladv *= linfo.li_min_insn_length; | |
4738 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4739 | if (uladv) |
4740 | state_machine_regs.view = 0; | |
a233b20c JJ |
4741 | } |
4742 | else | |
4743 | { | |
ba8826a8 AO |
4744 | unsigned addrdelta |
4745 | = ((state_machine_regs.op_index + uladv) | |
4746 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4747 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4748 | state_machine_regs.address |
4749 | += addrdelta; | |
a233b20c JJ |
4750 | state_machine_regs.op_index |
4751 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 4752 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
4753 | if (addrdelta) |
4754 | state_machine_regs.view = 0; | |
a233b20c | 4755 | } |
a262ae96 | 4756 | |
b4eb7656 AM |
4757 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
4758 | state_machine_regs.line += adv; | |
4759 | is_special_opcode = 1; | |
ba8826a8 | 4760 | /* Increment view after printing this row. */ |
b4eb7656 | 4761 | } |
cd30bcef AM |
4762 | else |
4763 | switch (op_code) | |
4764 | { | |
4765 | case DW_LNS_extended_op: | |
4766 | { | |
4767 | unsigned int ext_op_code_len; | |
4768 | unsigned char ext_op_code; | |
4769 | unsigned char *op_code_end; | |
4770 | unsigned char *op_code_data = data; | |
4771 | ||
4772 | READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence); | |
4773 | op_code_end = op_code_data + ext_op_code_len; | |
4774 | if (ext_op_code_len == 0 || op_code_end > end_of_sequence) | |
4775 | { | |
4776 | warn (_("Badly formed extended line op encountered!\n")); | |
4777 | break; | |
4778 | } | |
4779 | ext_op_code = *op_code_data++; | |
4780 | xop = ext_op_code; | |
4781 | xop = -xop; | |
4782 | ||
4783 | switch (ext_op_code) | |
4784 | { | |
4785 | case DW_LNE_end_sequence: | |
4786 | /* Reset stuff after printing this row. */ | |
4787 | break; | |
4788 | case DW_LNE_set_address: | |
4789 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
4790 | op_code_data, | |
4791 | op_code_end - op_code_data, | |
4792 | op_code_end); | |
4793 | state_machine_regs.op_index = 0; | |
4794 | state_machine_regs.view = 0; | |
4795 | break; | |
4796 | case DW_LNE_define_file: | |
4797 | file_table = (File_Entry *) xrealloc | |
4798 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
4799 | ||
4800 | ++state_machine_regs.last_file_entry; | |
4801 | /* Source file name. */ | |
4802 | file_table[n_files].name = op_code_data; | |
4803 | op_code_data += strlen ((char *) op_code_data) + 1; | |
4804 | /* Directory index. */ | |
4805 | READ_ULEB (file_table[n_files].directory_index, | |
4806 | op_code_data, op_code_end); | |
4807 | /* Last modification time. */ | |
4808 | READ_ULEB (file_table[n_files].modification_date, | |
4809 | op_code_data, op_code_end); | |
4810 | /* File length. */ | |
4811 | READ_ULEB (file_table[n_files].length, | |
4812 | op_code_data, op_code_end); | |
4813 | n_files++; | |
4814 | break; | |
4815 | ||
4816 | case DW_LNE_set_discriminator: | |
4817 | case DW_LNE_HP_set_sequence: | |
4818 | /* Simply ignored. */ | |
4819 | break; | |
4820 | ||
4821 | default: | |
4822 | printf (_("UNKNOWN (%u): length %ld\n"), | |
27653fba | 4823 | ext_op_code, (long int) (op_code_data - data)); |
cd30bcef AM |
4824 | break; |
4825 | } | |
4826 | data = op_code_end; | |
4827 | break; | |
4828 | } | |
4829 | case DW_LNS_copy: | |
4830 | /* Increment view after printing this row. */ | |
4831 | break; | |
4832 | ||
4833 | case DW_LNS_advance_pc: | |
4834 | READ_ULEB (uladv, data, end); | |
4835 | if (linfo.li_max_ops_per_insn == 1) | |
4836 | { | |
4837 | uladv *= linfo.li_min_insn_length; | |
4838 | state_machine_regs.address += uladv; | |
4839 | if (uladv) | |
4840 | state_machine_regs.view = 0; | |
4841 | } | |
4842 | else | |
4843 | { | |
4844 | unsigned addrdelta | |
4845 | = ((state_machine_regs.op_index + uladv) | |
4846 | / linfo.li_max_ops_per_insn) | |
4847 | * linfo.li_min_insn_length; | |
4848 | state_machine_regs.address | |
4849 | += addrdelta; | |
4850 | state_machine_regs.op_index | |
4851 | = (state_machine_regs.op_index + uladv) | |
4852 | % linfo.li_max_ops_per_insn; | |
4853 | if (addrdelta) | |
4854 | state_machine_regs.view = 0; | |
4855 | } | |
4856 | break; | |
4857 | ||
4858 | case DW_LNS_advance_line: | |
4859 | READ_SLEB (adv, data, end); | |
4860 | state_machine_regs.line += adv; | |
4861 | break; | |
4862 | ||
4863 | case DW_LNS_set_file: | |
4864 | READ_ULEB (uladv, data, end); | |
4865 | state_machine_regs.file = uladv; | |
4866 | ||
4867 | { | |
4868 | unsigned file = state_machine_regs.file - 1; | |
4869 | unsigned dir; | |
4870 | ||
4871 | if (file_table == NULL || n_files == 0) | |
4872 | printf (_("\n [Use file table entry %d]\n"), file); | |
4873 | /* PR 20439 */ | |
4874 | else if (file >= n_files) | |
4875 | { | |
4876 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
4877 | printf (_("\n <over large file table index %u>"), file); | |
4878 | } | |
4879 | else if ((dir = file_table[file].directory_index) == 0) | |
4880 | /* If directory index is 0, that means current directory. */ | |
4881 | printf ("\n./%s:[++]\n", file_table[file].name); | |
4882 | else if (directory_table == NULL || n_directories == 0) | |
4883 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
4884 | file_table[file].name, dir); | |
4885 | /* PR 20439 */ | |
4886 | else if (dir > n_directories) | |
4887 | { | |
4888 | warn (_("directory index %u > number of directories %s\n"), | |
4889 | dir, dwarf_vmatoa ("u", n_directories)); | |
4890 | printf (_("\n <over large directory table entry %u>\n"), dir); | |
4891 | } | |
4892 | else | |
4893 | printf ("\n%s/%s:\n", | |
4894 | /* The directory index starts counting at 1. */ | |
4895 | directory_table[dir - 1], file_table[file].name); | |
4896 | } | |
4897 | break; | |
4898 | ||
4899 | case DW_LNS_set_column: | |
4900 | READ_ULEB (uladv, data, end); | |
4901 | state_machine_regs.column = uladv; | |
4902 | break; | |
4903 | ||
4904 | case DW_LNS_negate_stmt: | |
4905 | adv = state_machine_regs.is_stmt; | |
4906 | adv = ! adv; | |
4907 | state_machine_regs.is_stmt = adv; | |
4908 | break; | |
4909 | ||
4910 | case DW_LNS_set_basic_block: | |
4911 | state_machine_regs.basic_block = 1; | |
4912 | break; | |
4913 | ||
4914 | case DW_LNS_const_add_pc: | |
4915 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4916 | if (linfo.li_max_ops_per_insn == 1) | |
4917 | { | |
4918 | uladv *= linfo.li_min_insn_length; | |
4919 | state_machine_regs.address += uladv; | |
4920 | if (uladv) | |
4921 | state_machine_regs.view = 0; | |
4922 | } | |
4923 | else | |
4924 | { | |
4925 | unsigned addrdelta | |
4926 | = ((state_machine_regs.op_index + uladv) | |
4927 | / linfo.li_max_ops_per_insn) | |
4928 | * linfo.li_min_insn_length; | |
4929 | state_machine_regs.address | |
4930 | += addrdelta; | |
4931 | state_machine_regs.op_index | |
4932 | = (state_machine_regs.op_index + uladv) | |
4933 | % linfo.li_max_ops_per_insn; | |
4934 | if (addrdelta) | |
4935 | state_machine_regs.view = 0; | |
4936 | } | |
4937 | break; | |
4938 | ||
4939 | case DW_LNS_fixed_advance_pc: | |
4940 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4941 | state_machine_regs.address += uladv; | |
4942 | state_machine_regs.op_index = 0; | |
4943 | /* Do NOT reset view. */ | |
4944 | break; | |
4945 | ||
4946 | case DW_LNS_set_prologue_end: | |
4947 | break; | |
4948 | ||
4949 | case DW_LNS_set_epilogue_begin: | |
4950 | break; | |
4951 | ||
4952 | case DW_LNS_set_isa: | |
4953 | READ_ULEB (uladv, data, end); | |
4954 | printf (_(" Set ISA to %lu\n"), uladv); | |
4955 | break; | |
4956 | ||
4957 | default: | |
4958 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4959 | ||
4960 | if (standard_opcodes != NULL) | |
4961 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4962 | { | |
4963 | dwarf_vma val; | |
4964 | ||
4965 | READ_ULEB (val, data, end); | |
4966 | printf ("0x%s%s", dwarf_vmatoa ("x", val), | |
4967 | i == 1 ? "" : ", "); | |
4968 | } | |
4969 | putchar ('\n'); | |
4970 | break; | |
4971 | } | |
a262ae96 | 4972 | |
b4eb7656 AM |
4973 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
4974 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
4975 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
4976 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
4977 | { |
4978 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
4979 | char *fileName; | |
4980 | char *newFileName = NULL; | |
4981 | size_t fileNameLength; | |
b40bf0a2 NC |
4982 | |
4983 | if (file_table) | |
db9537d2 NC |
4984 | { |
4985 | unsigned indx = state_machine_regs.file - 1; | |
4986 | /* PR 20439 */ | |
4987 | if (indx >= n_files) | |
4988 | { | |
4989 | warn (_("corrupt file index %u encountered\n"), indx); | |
4990 | fileName = _("<corrupt>"); | |
4991 | } | |
4992 | else | |
4993 | fileName = (char *) file_table[indx].name; | |
4994 | } | |
b40bf0a2 | 4995 | else |
db9537d2 | 4996 | fileName = _("<unknown>"); |
b40bf0a2 NC |
4997 | |
4998 | fileNameLength = strlen (fileName); | |
a262ae96 | 4999 | |
b4eb7656 AM |
5000 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
5001 | { | |
5002 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
5003 | /* Truncate file name */ | |
5004 | strncpy (newFileName, | |
5005 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
5006 | MAX_FILENAME_LENGTH + 1); | |
e1104d08 NC |
5007 | /* FIXME: This is to pacify gcc-10 which can warn that the |
5008 | strncpy above might leave a non-NUL terminated string | |
5009 | in newFileName. It won't, but gcc's analysis doesn't | |
5010 | quite go far enough to discover this. */ | |
5011 | newFileName[MAX_FILENAME_LENGTH] = 0; | |
b4eb7656 AM |
5012 | } |
5013 | else | |
5014 | { | |
5015 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
5016 | strncpy (newFileName, fileName, fileNameLength + 1); | |
5017 | } | |
5018 | ||
af2b3186 TV |
5019 | /* A row with end_seq set to true has a meaningful address, but |
5020 | the other information in the same row is not significant. | |
5021 | In such a row, print line as "-", and don't print | |
5022 | view/is_stmt. */ | |
b4eb7656 AM |
5023 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) |
5024 | { | |
a233b20c | 5025 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5026 | { |
5027 | if (xop == -DW_LNE_end_sequence) | |
5028 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x", | |
5029 | newFileName, "-", | |
5030 | state_machine_regs.address); | |
5031 | else | |
5032 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", | |
5033 | newFileName, state_machine_regs.line, | |
5034 | state_machine_regs.address); | |
5035 | } | |
a233b20c | 5036 | else |
af2b3186 TV |
5037 | { |
5038 | if (xop == -DW_LNE_end_sequence) | |
5039 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5040 | newFileName, "-", | |
5041 | state_machine_regs.address, | |
5042 | state_machine_regs.op_index); | |
5043 | else | |
5044 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5045 | newFileName, state_machine_regs.line, | |
5046 | state_machine_regs.address, | |
5047 | state_machine_regs.op_index); | |
5048 | } | |
b4eb7656 AM |
5049 | } |
5050 | else | |
5051 | { | |
a233b20c | 5052 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5053 | { |
5054 | if (xop == -DW_LNE_end_sequence) | |
5055 | printf ("%s %11s %#18" DWARF_VMA_FMT "x", | |
5056 | newFileName, "-", | |
5057 | state_machine_regs.address); | |
5058 | else | |
5059 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", | |
5060 | newFileName, state_machine_regs.line, | |
5061 | state_machine_regs.address); | |
5062 | } | |
a233b20c | 5063 | else |
af2b3186 TV |
5064 | { |
5065 | if (xop == -DW_LNE_end_sequence) | |
5066 | printf ("%s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5067 | newFileName, "-", | |
5068 | state_machine_regs.address, | |
5069 | state_machine_regs.op_index); | |
5070 | else | |
5071 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5072 | newFileName, state_machine_regs.line, | |
5073 | state_machine_regs.address, | |
5074 | state_machine_regs.op_index); | |
5075 | } | |
b4eb7656 | 5076 | } |
a262ae96 | 5077 | |
af2b3186 TV |
5078 | if (xop != -DW_LNE_end_sequence) |
5079 | { | |
5080 | if (state_machine_regs.view) | |
5081 | printf (" %6u", state_machine_regs.view); | |
5082 | else | |
5083 | printf (" "); | |
17f6ade2 | 5084 | |
af2b3186 TV |
5085 | if (state_machine_regs.is_stmt) |
5086 | printf (" x"); | |
5087 | } | |
17f6ade2 JD |
5088 | |
5089 | putchar ('\n'); | |
ba8826a8 AO |
5090 | state_machine_regs.view++; |
5091 | ||
5092 | if (xop == -DW_LNE_end_sequence) | |
5093 | { | |
5094 | reset_state_machine (linfo.li_default_is_stmt); | |
5095 | putchar ('\n'); | |
5096 | } | |
a262ae96 | 5097 | |
b4eb7656 AM |
5098 | free (newFileName); |
5099 | } | |
5100 | } | |
b40bf0a2 NC |
5101 | |
5102 | if (file_table) | |
5103 | { | |
5104 | free (file_table); | |
5105 | file_table = NULL; | |
5106 | n_files = 0; | |
5107 | } | |
5108 | ||
5109 | if (directory_table) | |
5110 | { | |
5111 | free (directory_table); | |
5112 | directory_table = NULL; | |
5113 | n_directories = 0; | |
5114 | } | |
5115 | ||
a262ae96 NC |
5116 | putchar ('\n'); |
5117 | } | |
5118 | ||
5119 | return 1; | |
5120 | } | |
5121 | ||
5122 | static int | |
77145576 | 5123 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
5124 | { |
5125 | unsigned char *data = section->start; | |
5126 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
5127 | int retValRaw = 1; |
5128 | int retValDecoded = 1; | |
a262ae96 | 5129 | |
008f4c78 NC |
5130 | if (do_debug_lines == 0) |
5131 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
5132 | ||
4cb93e3b | 5133 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 5134 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 5135 | |
4cb93e3b | 5136 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
ec1b0fbb | 5137 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
a262ae96 | 5138 | |
4cb93e3b | 5139 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
5140 | return 0; |
5141 | ||
5142 | return 1; | |
5143 | } | |
5144 | ||
6e3d6dc1 NC |
5145 | static debug_info * |
5146 | find_debug_info_for_offset (unsigned long offset) | |
5147 | { | |
5148 | unsigned int i; | |
5149 | ||
5150 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
5151 | return NULL; | |
5152 | ||
5153 | for (i = 0; i < num_debug_info_entries; i++) | |
5154 | if (debug_information[i].cu_offset == offset) | |
5155 | return debug_information + i; | |
5156 | ||
5157 | return NULL; | |
5158 | } | |
5159 | ||
459d52c8 DE |
5160 | static const char * |
5161 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
5162 | { | |
5163 | /* See gdb/gdb-index.h. */ | |
5164 | static const char * const kinds[] = | |
5165 | { | |
5166 | N_ ("no info"), | |
5167 | N_ ("type"), | |
5168 | N_ ("variable"), | |
5169 | N_ ("function"), | |
5170 | N_ ("other"), | |
5171 | N_ ("unused5"), | |
5172 | N_ ("unused6"), | |
5173 | N_ ("unused7") | |
5174 | }; | |
5175 | ||
5176 | return _ (kinds[kind]); | |
5177 | } | |
5178 | ||
19e6b90e | 5179 | static int |
459d52c8 DE |
5180 | display_debug_pubnames_worker (struct dwarf_section *section, |
5181 | void *file ATTRIBUTE_UNUSED, | |
5182 | int is_gnu) | |
19e6b90e | 5183 | { |
91d6fa6a | 5184 | DWARF2_Internal_PubNames names; |
19e6b90e L |
5185 | unsigned char *start = section->start; |
5186 | unsigned char *end = start + section->size; | |
5187 | ||
6e3d6dc1 NC |
5188 | /* It does not matter if this load fails, |
5189 | we test for that later on. */ | |
5190 | load_debug_info (file); | |
5191 | ||
dda8d76d | 5192 | introduce (section, FALSE); |
19e6b90e L |
5193 | |
5194 | while (start < end) | |
5195 | { | |
5196 | unsigned char *data; | |
e98fdf1a | 5197 | unsigned long sec_off; |
bf5117e3 | 5198 | unsigned int offset_size, initial_length_size; |
19e6b90e | 5199 | |
e98fdf1a | 5200 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 5201 | if (names.pn_length == 0xffffffff) |
19e6b90e | 5202 | { |
e98fdf1a | 5203 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e L |
5204 | offset_size = 8; |
5205 | initial_length_size = 12; | |
5206 | } | |
5207 | else | |
5208 | { | |
5209 | offset_size = 4; | |
5210 | initial_length_size = 4; | |
5211 | } | |
5212 | ||
e98fdf1a AM |
5213 | sec_off = start - section->start; |
5214 | if (sec_off + names.pn_length < sec_off | |
5215 | || sec_off + names.pn_length > section->size) | |
5216 | { | |
5217 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
5218 | section->name, | |
5219 | sec_off - initial_length_size, | |
5220 | dwarf_vmatoa ("x", names.pn_length)); | |
5221 | break; | |
5222 | } | |
5223 | ||
5224 | data = start; | |
5225 | start += names.pn_length; | |
5226 | ||
0c588247 NC |
5227 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
5228 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
5229 | |
5230 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
5231 | && num_debug_info_entries > 0 | |
91d6fa6a | 5232 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 5233 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 5234 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 5235 | |
0c588247 | 5236 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 5237 | |
058037d3 NC |
5238 | printf (_(" Length: %ld\n"), |
5239 | (long) names.pn_length); | |
5240 | printf (_(" Version: %d\n"), | |
5241 | names.pn_version); | |
5242 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
5243 | (unsigned long) names.pn_offset); | |
5244 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
5245 | (long) names.pn_size); | |
19e6b90e | 5246 | |
91d6fa6a | 5247 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
5248 | { |
5249 | static int warned = 0; | |
5250 | ||
5251 | if (! warned) | |
5252 | { | |
5253 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
5254 | warned = 1; | |
5255 | } | |
5256 | ||
5257 | continue; | |
5258 | } | |
5259 | ||
459d52c8 DE |
5260 | if (is_gnu) |
5261 | printf (_("\n Offset Kind Name\n")); | |
5262 | else | |
5263 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 5264 | |
e98fdf1a | 5265 | while (1) |
19e6b90e | 5266 | { |
f41e4712 | 5267 | bfd_size_type maxprint; |
e98fdf1a | 5268 | dwarf_vma offset; |
f41e4712 | 5269 | |
0c588247 | 5270 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e | 5271 | |
e98fdf1a AM |
5272 | if (offset == 0) |
5273 | break; | |
b4eb7656 | 5274 | |
e98fdf1a AM |
5275 | data += offset_size; |
5276 | if (data >= end) | |
5277 | break; | |
5278 | maxprint = (end - data) - 1; | |
f41e4712 | 5279 | |
e98fdf1a AM |
5280 | if (is_gnu) |
5281 | { | |
5282 | unsigned int kind_data; | |
5283 | gdb_index_symbol_kind kind; | |
5284 | const char *kind_name; | |
5285 | int is_static; | |
5286 | ||
5287 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
5288 | data++; | |
5289 | maxprint --; | |
5290 | /* GCC computes the kind as the upper byte in the CU index | |
5291 | word, and then right shifts it by the CU index size. | |
5292 | Left shift KIND to where the gdb-index.h accessor macros | |
5293 | can use it. */ | |
5294 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
5295 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
5296 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
5297 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
5298 | printf (" %-6lx %s,%-10s %.*s\n", | |
5299 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
5300 | kind_name, (int) maxprint, data); | |
19e6b90e | 5301 | } |
e98fdf1a AM |
5302 | else |
5303 | printf (" %-6lx\t%.*s\n", | |
5304 | (unsigned long) offset, (int) maxprint, data); | |
5305 | ||
5306 | data += strnlen ((char *) data, maxprint) + 1; | |
5307 | if (data >= end) | |
5308 | break; | |
19e6b90e | 5309 | } |
19e6b90e L |
5310 | } |
5311 | ||
5312 | printf ("\n"); | |
5313 | return 1; | |
5314 | } | |
5315 | ||
459d52c8 DE |
5316 | static int |
5317 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
5318 | { | |
5319 | return display_debug_pubnames_worker (section, file, 0); | |
5320 | } | |
5321 | ||
5322 | static int | |
5323 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
5324 | { | |
5325 | return display_debug_pubnames_worker (section, file, 1); | |
5326 | } | |
5327 | ||
19e6b90e L |
5328 | static int |
5329 | display_debug_macinfo (struct dwarf_section *section, | |
5330 | void *file ATTRIBUTE_UNUSED) | |
5331 | { | |
5332 | unsigned char *start = section->start; | |
5333 | unsigned char *end = start + section->size; | |
5334 | unsigned char *curr = start; | |
19e6b90e L |
5335 | enum dwarf_macinfo_record_type op; |
5336 | ||
dda8d76d | 5337 | introduce (section, FALSE); |
19e6b90e L |
5338 | |
5339 | while (curr < end) | |
5340 | { | |
5341 | unsigned int lineno; | |
0c588247 | 5342 | const unsigned char *string; |
19e6b90e | 5343 | |
3f5e193b | 5344 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
5345 | curr++; |
5346 | ||
5347 | switch (op) | |
5348 | { | |
5349 | case DW_MACINFO_start_file: | |
5350 | { | |
5351 | unsigned int filenum; | |
5352 | ||
cd30bcef AM |
5353 | READ_ULEB (lineno, curr, end); |
5354 | READ_ULEB (filenum, curr, end); | |
19e6b90e L |
5355 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), |
5356 | lineno, filenum); | |
5357 | } | |
5358 | break; | |
5359 | ||
5360 | case DW_MACINFO_end_file: | |
5361 | printf (_(" DW_MACINFO_end_file\n")); | |
5362 | break; | |
5363 | ||
5364 | case DW_MACINFO_define: | |
cd30bcef | 5365 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5366 | string = curr; |
5367 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5368 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
5369 | lineno, string); | |
5370 | break; | |
5371 | ||
5372 | case DW_MACINFO_undef: | |
cd30bcef | 5373 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5374 | string = curr; |
5375 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5376 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
5377 | lineno, string); | |
5378 | break; | |
5379 | ||
5380 | case DW_MACINFO_vendor_ext: | |
5381 | { | |
5382 | unsigned int constant; | |
5383 | ||
cd30bcef | 5384 | READ_ULEB (constant, curr, end); |
0c588247 NC |
5385 | string = curr; |
5386 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5387 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
5388 | constant, string); | |
5389 | } | |
5390 | break; | |
5391 | } | |
5392 | } | |
5393 | ||
5394 | return 1; | |
5395 | } | |
5396 | ||
4ccf1e31 JJ |
5397 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5398 | filename and dirname corresponding to file name table entry with index | |
5399 | FILEIDX. Return NULL on failure. */ | |
5400 | ||
5401 | static unsigned char * | |
f6f0e17b NC |
5402 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5403 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5404 | unsigned char **dir_name) |
5405 | { | |
5406 | struct dwarf_section *section = &debug_displays [line].section; | |
5407 | unsigned char *hdrptr, *dirtable, *file_name; | |
5408 | unsigned int offset_size, initial_length_size; | |
cd30bcef | 5409 | unsigned int version, opcode_base; |
4ccf1e31 | 5410 | dwarf_vma length, diridx; |
f6f0e17b | 5411 | const unsigned char * end; |
4ccf1e31 JJ |
5412 | |
5413 | *dir_name = NULL; | |
5414 | if (section->start == NULL | |
5415 | || line_offset >= section->size | |
5416 | || fileidx == 0) | |
5417 | return NULL; | |
5418 | ||
5419 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5420 | end = section->start + section->size; |
0c588247 NC |
5421 | |
5422 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5423 | if (length == 0xffffffff) |
5424 | { | |
5425 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5426 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
5427 | offset_size = 8; |
5428 | initial_length_size = 12; | |
5429 | } | |
5430 | else | |
5431 | { | |
5432 | offset_size = 4; | |
5433 | initial_length_size = 4; | |
5434 | } | |
e98fdf1a AM |
5435 | if (length + initial_length_size < length |
5436 | || length + initial_length_size > section->size) | |
4ccf1e31 | 5437 | return NULL; |
0c588247 NC |
5438 | |
5439 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5440 | if (version != 2 && version != 3 && version != 4) |
5441 | return NULL; | |
5442 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5443 | if (version >= 4) | |
5444 | hdrptr++; /* Skip max_ops_per_insn. */ | |
5445 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
5446 | |
5447 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
5448 | if (opcode_base == 0) |
5449 | return NULL; | |
0c588247 | 5450 | |
4ccf1e31 | 5451 | hdrptr += opcode_base - 1; |
5c1c468d NC |
5452 | if (hdrptr >= end) |
5453 | return NULL; | |
5454 | ||
4ccf1e31 JJ |
5455 | dirtable = hdrptr; |
5456 | /* Skip over dirname table. */ | |
5457 | while (*hdrptr != '\0') | |
5c1c468d NC |
5458 | { |
5459 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; | |
5460 | if (hdrptr >= end) | |
5461 | return NULL; | |
5462 | } | |
4ccf1e31 | 5463 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 5464 | |
4ccf1e31 | 5465 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 5466 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 5467 | { |
0c588247 | 5468 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
cd30bcef AM |
5469 | SKIP_ULEB (hdrptr, end); |
5470 | SKIP_ULEB (hdrptr, end); | |
5471 | SKIP_ULEB (hdrptr, end); | |
4ccf1e31 | 5472 | } |
5c1c468d | 5473 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 5474 | return NULL; |
5c1c468d | 5475 | |
4ccf1e31 | 5476 | file_name = hdrptr; |
0c588247 | 5477 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
5c1c468d NC |
5478 | if (hdrptr >= end) |
5479 | return NULL; | |
cd30bcef | 5480 | READ_ULEB (diridx, hdrptr, end); |
4ccf1e31 JJ |
5481 | if (diridx == 0) |
5482 | return file_name; | |
5c1c468d | 5483 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
0c588247 | 5484 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
5c1c468d | 5485 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
5486 | return NULL; |
5487 | *dir_name = dirtable; | |
5488 | return file_name; | |
5489 | } | |
5490 | ||
5491 | static int | |
5492 | display_debug_macro (struct dwarf_section *section, | |
5493 | void *file) | |
5494 | { | |
5495 | unsigned char *start = section->start; | |
5496 | unsigned char *end = start + section->size; | |
5497 | unsigned char *curr = start; | |
5498 | unsigned char *extended_op_buf[256]; | |
4ccf1e31 | 5499 | |
dda8d76d NC |
5500 | load_debug_section_with_follow (str, file); |
5501 | load_debug_section_with_follow (line, file); | |
e4b7104b | 5502 | load_debug_section_with_follow (str_index, file); |
4ccf1e31 | 5503 | |
dda8d76d | 5504 | introduce (section, FALSE); |
4ccf1e31 JJ |
5505 | |
5506 | while (curr < end) | |
5507 | { | |
5508 | unsigned int lineno, version, flags; | |
5509 | unsigned int offset_size = 4; | |
0c588247 | 5510 | const unsigned char *string; |
4ccf1e31 JJ |
5511 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
5512 | unsigned char **extended_ops = NULL; | |
5513 | ||
0c588247 | 5514 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 5515 | if (version != 4 && version != 5) |
4ccf1e31 | 5516 | { |
7a7e1061 | 5517 | error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"), |
4ccf1e31 JJ |
5518 | section->name); |
5519 | return 0; | |
5520 | } | |
5521 | ||
0c588247 | 5522 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
4ccf1e31 JJ |
5523 | if (flags & 1) |
5524 | offset_size = 8; | |
5525 | printf (_(" Offset: 0x%lx\n"), | |
5526 | (unsigned long) sec_offset); | |
5527 | printf (_(" Version: %d\n"), version); | |
5528 | printf (_(" Offset size: %d\n"), offset_size); | |
5529 | if (flags & 2) | |
5530 | { | |
0c588247 | 5531 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
5532 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
5533 | (unsigned long) line_offset); | |
5534 | } | |
5535 | if (flags & 4) | |
5536 | { | |
0c588247 | 5537 | unsigned int i, count, op; |
4ccf1e31 | 5538 | dwarf_vma nargs, n; |
0c588247 NC |
5539 | |
5540 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 5541 | |
4ccf1e31 JJ |
5542 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
5543 | extended_ops = extended_op_buf; | |
5544 | if (count) | |
5545 | { | |
5546 | printf (_(" Extension opcode arguments:\n")); | |
5547 | for (i = 0; i < count; i++) | |
5548 | { | |
0c588247 | 5549 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 5550 | extended_ops[op] = curr; |
cd30bcef | 5551 | READ_ULEB (nargs, curr, end); |
4ccf1e31 | 5552 | if (nargs == 0) |
7a7e1061 | 5553 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
5554 | else |
5555 | { | |
7a7e1061 | 5556 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
5557 | for (n = 0; n < nargs; n++) |
5558 | { | |
0c588247 NC |
5559 | unsigned int form; |
5560 | ||
5561 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
5562 | printf ("%s%s", get_FORM_name (form), |
5563 | n == nargs - 1 ? "\n" : ", "); | |
5564 | switch (form) | |
5565 | { | |
5566 | case DW_FORM_data1: | |
5567 | case DW_FORM_data2: | |
5568 | case DW_FORM_data4: | |
5569 | case DW_FORM_data8: | |
5570 | case DW_FORM_sdata: | |
5571 | case DW_FORM_udata: | |
5572 | case DW_FORM_block: | |
5573 | case DW_FORM_block1: | |
5574 | case DW_FORM_block2: | |
5575 | case DW_FORM_block4: | |
5576 | case DW_FORM_flag: | |
5577 | case DW_FORM_string: | |
5578 | case DW_FORM_strp: | |
5579 | case DW_FORM_sec_offset: | |
5580 | break; | |
5581 | default: | |
5582 | error (_("Invalid extension opcode form %s\n"), | |
5583 | get_FORM_name (form)); | |
5584 | return 0; | |
5585 | } | |
5586 | } | |
5587 | } | |
5588 | } | |
5589 | } | |
5590 | } | |
5591 | printf ("\n"); | |
5592 | ||
5593 | while (1) | |
5594 | { | |
5595 | unsigned int op; | |
5596 | ||
5597 | if (curr >= end) | |
5598 | { | |
5599 | error (_(".debug_macro section not zero terminated\n")); | |
5600 | return 0; | |
5601 | } | |
5602 | ||
0c588247 | 5603 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
5604 | if (op == 0) |
5605 | break; | |
5606 | ||
5607 | switch (op) | |
5608 | { | |
e4b7104b NC |
5609 | case DW_MACRO_define: |
5610 | READ_ULEB (lineno, curr, end); | |
5611 | string = curr; | |
5612 | curr += strnlen ((char *) string, end - string) + 1; | |
5613 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), | |
5614 | lineno, string); | |
5615 | break; | |
5616 | ||
5617 | case DW_MACRO_undef: | |
5618 | READ_ULEB (lineno, curr, end); | |
5619 | string = curr; | |
5620 | curr += strnlen ((char *) string, end - string) + 1; | |
5621 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), | |
5622 | lineno, string); | |
5623 | break; | |
5624 | ||
7a7e1061 | 5625 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
5626 | { |
5627 | unsigned int filenum; | |
5628 | unsigned char *file_name = NULL, *dir_name = NULL; | |
5629 | ||
cd30bcef AM |
5630 | READ_ULEB (lineno, curr, end); |
5631 | READ_ULEB (filenum, curr, end); | |
4ccf1e31 JJ |
5632 | |
5633 | if ((flags & 2) == 0) | |
7a7e1061 | 5634 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
5635 | else |
5636 | file_name | |
5637 | = get_line_filename_and_dirname (line_offset, filenum, | |
5638 | &dir_name); | |
5639 | if (file_name == NULL) | |
7a7e1061 | 5640 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
5641 | lineno, filenum); |
5642 | else | |
7a7e1061 | 5643 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
5644 | lineno, filenum, |
5645 | dir_name != NULL ? (const char *) dir_name : "", | |
5646 | dir_name != NULL ? "/" : "", file_name); | |
5647 | } | |
5648 | break; | |
5649 | ||
7a7e1061 JK |
5650 | case DW_MACRO_end_file: |
5651 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
5652 | break; |
5653 | ||
7a7e1061 | 5654 | case DW_MACRO_define_strp: |
cd30bcef | 5655 | READ_ULEB (lineno, curr, end); |
0c588247 | 5656 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5657 | string = fetch_indirect_string (offset); |
7a7e1061 | 5658 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5659 | lineno, string); |
5660 | break; | |
5661 | ||
7a7e1061 | 5662 | case DW_MACRO_undef_strp: |
cd30bcef | 5663 | READ_ULEB (lineno, curr, end); |
0c588247 | 5664 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5665 | string = fetch_indirect_string (offset); |
7a7e1061 | 5666 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5667 | lineno, string); |
5668 | break; | |
5669 | ||
7a7e1061 | 5670 | case DW_MACRO_import: |
0c588247 | 5671 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5672 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
5673 | (unsigned long) offset); |
5674 | break; | |
5675 | ||
7a7e1061 | 5676 | case DW_MACRO_define_sup: |
cd30bcef | 5677 | READ_ULEB (lineno, curr, end); |
0c588247 | 5678 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5679 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5680 | lineno, (unsigned long) offset); |
5681 | break; | |
5682 | ||
7a7e1061 | 5683 | case DW_MACRO_undef_sup: |
cd30bcef | 5684 | READ_ULEB (lineno, curr, end); |
0c588247 | 5685 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5686 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5687 | lineno, (unsigned long) offset); |
5688 | break; | |
5689 | ||
7a7e1061 | 5690 | case DW_MACRO_import_sup: |
0c588247 | 5691 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5692 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
5693 | (unsigned long) offset); |
5694 | break; | |
5695 | ||
e4b7104b NC |
5696 | case DW_MACRO_define_strx: |
5697 | case DW_MACRO_undef_strx: | |
5698 | READ_ULEB (lineno, curr, end); | |
5699 | READ_ULEB (offset, curr, end); | |
5700 | string = (const unsigned char *) | |
5701 | fetch_indexed_string (offset, NULL, offset_size, FALSE); | |
5702 | if (op == DW_MACRO_define_strx) | |
5703 | printf (" DW_MACRO_define_strx "); | |
5704 | else | |
5705 | printf (" DW_MACRO_undef_strx "); | |
5706 | if (do_wide) | |
39f381cb | 5707 | printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset)); |
e4b7104b NC |
5708 | printf (_("lineno : %d macro : %s\n"), |
5709 | lineno, string); | |
5710 | break; | |
5711 | ||
4ccf1e31 | 5712 | default: |
e4b7104b NC |
5713 | if (op >= DW_MACRO_lo_user && op <= DW_MACRO_hi_user) |
5714 | { | |
5715 | printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op); | |
5716 | break; | |
5717 | } | |
5718 | ||
4ccf1e31 JJ |
5719 | if (extended_ops == NULL || extended_ops[op] == NULL) |
5720 | { | |
5721 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
5722 | return 0; | |
5723 | } | |
5724 | else | |
5725 | { | |
5726 | /* Skip over unhandled opcodes. */ | |
5727 | dwarf_vma nargs, n; | |
5728 | unsigned char *desc = extended_ops[op]; | |
cd30bcef | 5729 | READ_ULEB (nargs, desc, end); |
4ccf1e31 JJ |
5730 | if (nargs == 0) |
5731 | { | |
7a7e1061 | 5732 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
5733 | break; |
5734 | } | |
7a7e1061 | 5735 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
5736 | for (n = 0; n < nargs; n++) |
5737 | { | |
0c588247 NC |
5738 | int val; |
5739 | ||
77145576 | 5740 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 5741 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 5742 | curr |
77145576 | 5743 | = read_and_display_attr_value (0, val, 0, |
ec1b0fbb | 5744 | start, curr, end, 0, 0, offset_size, |
341f9135 | 5745 | version, NULL, 0, NULL, |
ec1b0fbb | 5746 | NULL, ' ', -1); |
4ccf1e31 JJ |
5747 | if (n != nargs - 1) |
5748 | printf (","); | |
5749 | } | |
5750 | printf ("\n"); | |
5751 | } | |
5752 | break; | |
5753 | } | |
5754 | } | |
5755 | ||
5756 | printf ("\n"); | |
b4eb7656 | 5757 | } |
4ccf1e31 JJ |
5758 | |
5759 | return 1; | |
5760 | } | |
5761 | ||
19e6b90e L |
5762 | static int |
5763 | display_debug_abbrev (struct dwarf_section *section, | |
5764 | void *file ATTRIBUTE_UNUSED) | |
5765 | { | |
5766 | abbrev_entry *entry; | |
5767 | unsigned char *start = section->start; | |
5768 | unsigned char *end = start + section->size; | |
5769 | ||
dda8d76d | 5770 | introduce (section, FALSE); |
19e6b90e L |
5771 | |
5772 | do | |
5773 | { | |
7282333f AM |
5774 | unsigned char *last; |
5775 | ||
19e6b90e L |
5776 | free_abbrevs (); |
5777 | ||
7282333f | 5778 | last = start; |
19e6b90e L |
5779 | start = process_abbrev_section (start, end); |
5780 | ||
5781 | if (first_abbrev == NULL) | |
5782 | continue; | |
5783 | ||
7282333f | 5784 | printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start)); |
19e6b90e L |
5785 | |
5786 | for (entry = first_abbrev; entry; entry = entry->next) | |
5787 | { | |
5788 | abbrev_attr *attr; | |
5789 | ||
cc5914eb | 5790 | printf (" %ld %s [%s]\n", |
19e6b90e L |
5791 | entry->entry, |
5792 | get_TAG_name (entry->tag), | |
5793 | entry->children ? _("has children") : _("no children")); | |
5794 | ||
5795 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
5796 | { |
5797 | printf (" %-18s %s", | |
5798 | get_AT_name (attr->attribute), | |
5799 | get_FORM_name (attr->form)); | |
5800 | if (attr->form == DW_FORM_implicit_const) | |
5801 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
5802 | putchar ('\n'); | |
5803 | } | |
19e6b90e L |
5804 | } |
5805 | } | |
5806 | while (start); | |
5807 | ||
5808 | printf ("\n"); | |
5809 | ||
5810 | return 1; | |
5811 | } | |
5812 | ||
42bcef4a AB |
5813 | /* Return true when ADDR is the maximum address, when addresses are |
5814 | POINTER_SIZE bytes long. */ | |
5815 | ||
5816 | static bfd_boolean | |
5817 | is_max_address (dwarf_vma addr, unsigned int pointer_size) | |
5818 | { | |
5819 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
5820 | return ((addr & mask) == mask); | |
5821 | } | |
5822 | ||
9f272209 AO |
5823 | /* Display a view pair list starting at *VSTART_PTR and ending at |
5824 | VLISTEND within SECTION. */ | |
5825 | ||
5826 | static void | |
5827 | display_view_pair_list (struct dwarf_section *section, | |
5828 | unsigned char **vstart_ptr, | |
5829 | unsigned int debug_info_entry, | |
5830 | unsigned char *vlistend) | |
5831 | { | |
5832 | unsigned char *vstart = *vstart_ptr; | |
5833 | unsigned char *section_end = section->start + section->size; | |
5834 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
5835 | ||
5836 | if (vlistend < section_end) | |
5837 | section_end = vlistend; | |
5838 | ||
5839 | putchar ('\n'); | |
5840 | ||
5841 | while (vstart < section_end) | |
5842 | { | |
5843 | dwarf_vma off = vstart - section->start; | |
5844 | dwarf_vma vbegin, vend; | |
5845 | ||
cd30bcef | 5846 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 | 5847 | if (vstart == section_end) |
cd30bcef | 5848 | break; |
9f272209 | 5849 | |
cd30bcef | 5850 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
5851 | printf (" %8.8lx ", (unsigned long) off); |
5852 | ||
5853 | print_dwarf_view (vbegin, pointer_size, 1); | |
5854 | print_dwarf_view (vend, pointer_size, 1); | |
5855 | printf (_("location view pair\n")); | |
5856 | } | |
5857 | ||
5858 | putchar ('\n'); | |
5859 | *vstart_ptr = vstart; | |
5860 | } | |
5861 | ||
4723351a CC |
5862 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
5863 | ||
5864 | static void | |
5865 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
5866 | unsigned char **start_ptr, |
5867 | unsigned int debug_info_entry, | |
359ca075 JK |
5868 | dwarf_vma offset, |
5869 | dwarf_vma base_address, | |
9f272209 | 5870 | unsigned char **vstart_ptr, |
b4eb7656 | 5871 | int has_frame_base) |
4723351a | 5872 | { |
9f272209 | 5873 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 5874 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
5875 | unsigned long cu_offset; |
5876 | unsigned int pointer_size; | |
5877 | unsigned int offset_size; | |
5878 | int dwarf_version; | |
4723351a CC |
5879 | |
5880 | dwarf_vma begin; | |
5881 | dwarf_vma end; | |
5882 | unsigned short length; | |
5883 | int need_frame_base; | |
5884 | ||
82b1b41b NC |
5885 | if (debug_info_entry >= num_debug_info_entries) |
5886 | { | |
5887 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
5888 | debug_info_entry); | |
5889 | return; | |
5890 | } | |
b4eb7656 | 5891 | |
82b1b41b NC |
5892 | cu_offset = debug_information [debug_info_entry].cu_offset; |
5893 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5894 | offset_size = debug_information [debug_info_entry].offset_size; | |
5895 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 5896 | |
f41e4712 NC |
5897 | if (pointer_size < 2 || pointer_size > 8) |
5898 | { | |
5899 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5900 | pointer_size, debug_info_entry); | |
5901 | return; | |
5902 | } | |
5903 | ||
4723351a CC |
5904 | while (1) |
5905 | { | |
359ca075 | 5906 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 5907 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 5908 | |
4723351a | 5909 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
5910 | { |
5911 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5912 | (unsigned long) offset); |
b4eb7656 AM |
5913 | break; |
5914 | } | |
4723351a | 5915 | |
359ca075 | 5916 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 5917 | |
0c588247 NC |
5918 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
5919 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 5920 | |
4723351a | 5921 | if (begin == 0 && end == 0) |
b4eb7656 | 5922 | { |
d1c4b12b NC |
5923 | /* PR 18374: In a object file we can have a location list that |
5924 | starts with a begin and end of 0 because there are relocations | |
5925 | that need to be applied to the addresses. Actually applying | |
5926 | the relocations now does not help as they will probably resolve | |
5927 | to 0, since the object file has not been fully linked. Real | |
5928 | end of list markers will not have any relocations against them. */ | |
5929 | if (! reloc_at (section, off) | |
5930 | && ! reloc_at (section, off + pointer_size)) | |
5931 | { | |
5932 | printf (_("<End of list>\n")); | |
5933 | break; | |
5934 | } | |
b4eb7656 | 5935 | } |
4723351a CC |
5936 | |
5937 | /* Check base address specifiers. */ | |
42bcef4a AB |
5938 | if (is_max_address (begin, pointer_size) |
5939 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
5940 | { |
5941 | base_address = end; | |
5942 | print_dwarf_vma (begin, pointer_size); | |
5943 | print_dwarf_vma (end, pointer_size); | |
5944 | printf (_("(base address)\n")); | |
5945 | continue; | |
5946 | } | |
4723351a | 5947 | |
9f272209 AO |
5948 | if (vstart) |
5949 | { | |
9f272209 AO |
5950 | off = offset + (vstart - *start_ptr); |
5951 | ||
cd30bcef | 5952 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
5953 | print_dwarf_view (vbegin, pointer_size, 1); |
5954 | ||
cd30bcef | 5955 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
5956 | print_dwarf_view (vend, pointer_size, 1); |
5957 | ||
5958 | printf (_("views at %8.8lx for:\n %*s "), | |
5959 | (unsigned long) off, 8, ""); | |
5960 | } | |
5961 | ||
4723351a | 5962 | if (start + 2 > section_end) |
b4eb7656 AM |
5963 | { |
5964 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5965 | (unsigned long) offset); |
b4eb7656 AM |
5966 | break; |
5967 | } | |
4723351a | 5968 | |
0c588247 | 5969 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
5970 | |
5971 | if (start + length > section_end) | |
b4eb7656 AM |
5972 | { |
5973 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5974 | (unsigned long) offset); |
b4eb7656 AM |
5975 | break; |
5976 | } | |
4723351a CC |
5977 | |
5978 | print_dwarf_vma (begin + base_address, pointer_size); | |
5979 | print_dwarf_vma (end + base_address, pointer_size); | |
5980 | ||
5981 | putchar ('('); | |
5982 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
5983 | pointer_size, |
5984 | offset_size, | |
5985 | dwarf_version, | |
5986 | length, | |
5987 | cu_offset, section); | |
4723351a CC |
5988 | putchar (')'); |
5989 | ||
5990 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 5991 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 5992 | |
9f272209 | 5993 | if (begin == end && vbegin == vend) |
b4eb7656 | 5994 | fputs (_(" (start == end)"), stdout); |
9f272209 | 5995 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 5996 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
5997 | |
5998 | putchar ('\n'); | |
5999 | ||
6000 | start += length; | |
6001 | } | |
6002 | ||
6003 | *start_ptr = start; | |
9f272209 | 6004 | *vstart_ptr = vstart; |
4723351a CC |
6005 | } |
6006 | ||
77145576 JK |
6007 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
6008 | ||
6009 | static void | |
6010 | display_loclists_list (struct dwarf_section *section, | |
6011 | unsigned char **start_ptr, | |
6012 | unsigned int debug_info_entry, | |
6013 | dwarf_vma offset, | |
6014 | dwarf_vma base_address, | |
9f272209 | 6015 | unsigned char **vstart_ptr, |
77145576 JK |
6016 | int has_frame_base) |
6017 | { | |
9f272209 | 6018 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
6019 | unsigned char *section_end = section->start + section->size; |
6020 | unsigned long cu_offset; | |
6021 | unsigned int pointer_size; | |
6022 | unsigned int offset_size; | |
6023 | int dwarf_version; | |
77145576 | 6024 | |
9dfd0db9 | 6025 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
6026 | dwarf_vma begin = -1, vbegin = -1; |
6027 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
6028 | dwarf_vma length; |
6029 | int need_frame_base; | |
6030 | ||
6031 | if (debug_info_entry >= num_debug_info_entries) | |
6032 | { | |
6033 | warn (_("No debug information available for " | |
6034 | "loclists lists of entry: %u\n"), | |
6035 | debug_info_entry); | |
6036 | return; | |
6037 | } | |
6038 | ||
6039 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6040 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6041 | offset_size = debug_information [debug_info_entry].offset_size; | |
6042 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6043 | ||
6044 | if (pointer_size < 2 || pointer_size > 8) | |
6045 | { | |
6046 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6047 | pointer_size, debug_info_entry); | |
6048 | return; | |
6049 | } | |
6050 | ||
6051 | while (1) | |
6052 | { | |
6053 | dwarf_vma off = offset + (start - *start_ptr); | |
6054 | enum dwarf_location_list_entry_type llet; | |
6055 | ||
6056 | if (start + 1 > section_end) | |
6057 | { | |
6058 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6059 | (unsigned long) offset); | |
6060 | break; | |
6061 | } | |
6062 | ||
6063 | printf (" %8.8lx ", (unsigned long) off); | |
6064 | ||
6065 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
6066 | ||
1c9f770d MW |
6067 | if (vstart && (llet == DW_LLE_offset_pair |
6068 | || llet == DW_LLE_start_end | |
6069 | || llet == DW_LLE_start_length)) | |
9f272209 AO |
6070 | { |
6071 | off = offset + (vstart - *start_ptr); | |
6072 | ||
cd30bcef | 6073 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
6074 | print_dwarf_view (vbegin, pointer_size, 1); |
6075 | ||
cd30bcef | 6076 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6077 | print_dwarf_view (vend, pointer_size, 1); |
6078 | ||
6079 | printf (_("views at %8.8lx for:\n %*s "), | |
6080 | (unsigned long) off, 8, ""); | |
6081 | } | |
6082 | ||
77145576 JK |
6083 | switch (llet) |
6084 | { | |
6085 | case DW_LLE_end_of_list: | |
6086 | printf (_("<End of list>\n")); | |
6087 | break; | |
6088 | case DW_LLE_offset_pair: | |
cd30bcef | 6089 | READ_ULEB (begin, start, section_end); |
1c9f770d | 6090 | begin += base_address; |
cd30bcef | 6091 | READ_ULEB (end, start, section_end); |
1c9f770d MW |
6092 | end += base_address; |
6093 | break; | |
6094 | case DW_LLE_start_end: | |
6095 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6096 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
6097 | break; | |
6098 | case DW_LLE_start_length: | |
6099 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6100 | READ_ULEB (end, start, section_end); | |
6101 | end += begin; | |
77145576 JK |
6102 | break; |
6103 | case DW_LLE_base_address: | |
6104 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
6105 | section_end); | |
6106 | print_dwarf_vma (base_address, pointer_size); | |
6107 | printf (_("(base address)\n")); | |
6108 | break; | |
9f272209 AO |
6109 | #ifdef DW_LLE_view_pair |
6110 | case DW_LLE_view_pair: | |
6111 | if (vstart) | |
6112 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
cd30bcef | 6113 | READ_ULEB (vbegin, start, section_end); |
9f272209 AO |
6114 | print_dwarf_view (vbegin, pointer_size, 1); |
6115 | ||
cd30bcef | 6116 | READ_ULEB (vend, start, section_end); |
9f272209 AO |
6117 | print_dwarf_view (vend, pointer_size, 1); |
6118 | ||
6119 | printf (_("views for:\n")); | |
6120 | continue; | |
6121 | #endif | |
77145576 JK |
6122 | default: |
6123 | error (_("Invalid location list entry type %d\n"), llet); | |
6124 | return; | |
6125 | } | |
6126 | if (llet == DW_LLE_end_of_list) | |
6127 | break; | |
1c9f770d MW |
6128 | if (llet != DW_LLE_offset_pair |
6129 | && llet != DW_LLE_start_end | |
6130 | && llet != DW_LLE_start_length) | |
77145576 JK |
6131 | continue; |
6132 | ||
6133 | if (start + 2 > section_end) | |
6134 | { | |
6135 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6136 | (unsigned long) offset); | |
6137 | break; | |
6138 | } | |
6139 | ||
cd30bcef | 6140 | READ_ULEB (length, start, section_end); |
77145576 | 6141 | |
1c9f770d MW |
6142 | print_dwarf_vma (begin, pointer_size); |
6143 | print_dwarf_vma (end, pointer_size); | |
77145576 JK |
6144 | |
6145 | putchar ('('); | |
6146 | need_frame_base = decode_location_expression (start, | |
6147 | pointer_size, | |
6148 | offset_size, | |
6149 | dwarf_version, | |
6150 | length, | |
6151 | cu_offset, section); | |
6152 | putchar (')'); | |
6153 | ||
6154 | if (need_frame_base && !has_frame_base) | |
6155 | printf (_(" [without DW_AT_frame_base]")); | |
6156 | ||
9f272209 | 6157 | if (begin == end && vbegin == vend) |
77145576 | 6158 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6159 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
6160 | fputs (_(" (start > end)"), stdout); |
6161 | ||
6162 | putchar ('\n'); | |
6163 | ||
6164 | start += length; | |
9f272209 | 6165 | vbegin = vend = -1; |
77145576 JK |
6166 | } |
6167 | ||
9f272209 AO |
6168 | if (vbegin != vm1 || vend != vm1) |
6169 | printf (_("Trailing view pair not used in a range")); | |
6170 | ||
77145576 | 6171 | *start_ptr = start; |
9f272209 | 6172 | *vstart_ptr = vstart; |
77145576 JK |
6173 | } |
6174 | ||
fab128ef CC |
6175 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
6176 | right-adjusted in a field of length LEN, and followed by a space. */ | |
6177 | ||
6178 | static void | |
6179 | print_addr_index (unsigned int idx, unsigned int len) | |
6180 | { | |
6181 | static char buf[15]; | |
6182 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 6183 | printf ("%*s ", len, buf); |
fab128ef CC |
6184 | } |
6185 | ||
4723351a CC |
6186 | /* Display a location list from a .dwo section. It uses address indexes rather |
6187 | than embedded addresses. This code closely follows display_loc_list, but the | |
6188 | two are sufficiently different that combining things is very ugly. */ | |
6189 | ||
6190 | static void | |
6191 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
6192 | unsigned char **start_ptr, |
6193 | unsigned int debug_info_entry, | |
359ca075 | 6194 | dwarf_vma offset, |
9f272209 | 6195 | unsigned char **vstart_ptr, |
b4eb7656 | 6196 | int has_frame_base) |
4723351a | 6197 | { |
9f272209 | 6198 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6199 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6200 | unsigned long cu_offset; |
6201 | unsigned int pointer_size; | |
6202 | unsigned int offset_size; | |
6203 | int dwarf_version; | |
4723351a CC |
6204 | int entry_type; |
6205 | unsigned short length; | |
6206 | int need_frame_base; | |
fab128ef | 6207 | unsigned int idx; |
4723351a | 6208 | |
82b1b41b NC |
6209 | if (debug_info_entry >= num_debug_info_entries) |
6210 | { | |
6211 | warn (_("No debug information for loc lists of entry: %u\n"), | |
6212 | debug_info_entry); | |
6213 | return; | |
6214 | } | |
6215 | ||
6216 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6217 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6218 | offset_size = debug_information [debug_info_entry].offset_size; | |
6219 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6220 | ||
f41e4712 NC |
6221 | if (pointer_size < 2 || pointer_size > 8) |
6222 | { | |
6223 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6224 | pointer_size, debug_info_entry); | |
6225 | return; | |
6226 | } | |
6227 | ||
4723351a CC |
6228 | while (1) |
6229 | { | |
359ca075 | 6230 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 6231 | |
fab128ef | 6232 | if (start >= section_end) |
b4eb7656 AM |
6233 | { |
6234 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6235 | (unsigned long) offset); |
b4eb7656 AM |
6236 | break; |
6237 | } | |
4723351a | 6238 | |
0c588247 | 6239 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
6240 | |
6241 | if (vstart) | |
6242 | switch (entry_type) | |
6243 | { | |
6244 | default: | |
6245 | break; | |
6246 | ||
6247 | case 2: | |
6248 | case 3: | |
6249 | case 4: | |
6250 | { | |
6251 | dwarf_vma view; | |
6252 | dwarf_vma off = offset + (vstart - *start_ptr); | |
6253 | ||
cd30bcef | 6254 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6255 | print_dwarf_view (view, 8, 1); |
6256 | ||
cd30bcef | 6257 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6258 | print_dwarf_view (view, 8, 1); |
6259 | ||
6260 | printf (_("views at %8.8lx for:\n %*s "), | |
6261 | (unsigned long) off, 8, ""); | |
6262 | ||
6263 | } | |
6264 | break; | |
6265 | } | |
6266 | ||
4723351a | 6267 | switch (entry_type) |
b4eb7656 AM |
6268 | { |
6269 | case 0: /* A terminating entry. */ | |
6270 | *start_ptr = start; | |
9f272209 | 6271 | *vstart_ptr = vstart; |
b4eb7656 AM |
6272 | printf (_("<End of list>\n")); |
6273 | return; | |
6274 | case 1: /* A base-address entry. */ | |
cd30bcef | 6275 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6276 | print_addr_index (idx, 8); |
9f272209 | 6277 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
6278 | printf (_("(base address selection entry)\n")); |
6279 | continue; | |
6280 | case 2: /* A start/end entry. */ | |
cd30bcef | 6281 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6282 | print_addr_index (idx, 8); |
cd30bcef | 6283 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6284 | print_addr_index (idx, 8); |
6285 | break; | |
6286 | case 3: /* A start/length entry. */ | |
cd30bcef | 6287 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6288 | print_addr_index (idx, 8); |
6289 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6290 | printf ("%08x ", idx); | |
6291 | break; | |
6292 | case 4: /* An offset pair entry. */ | |
6293 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6294 | printf ("%08x ", idx); | |
6295 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6296 | printf ("%08x ", idx); | |
6297 | break; | |
6298 | default: | |
6299 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
6300 | *start_ptr = start; | |
9f272209 | 6301 | *vstart_ptr = vstart; |
b4eb7656 AM |
6302 | return; |
6303 | } | |
4723351a CC |
6304 | |
6305 | if (start + 2 > section_end) | |
b4eb7656 AM |
6306 | { |
6307 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6308 | (unsigned long) offset); |
b4eb7656 AM |
6309 | break; |
6310 | } | |
4723351a | 6311 | |
0c588247 | 6312 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6313 | if (start + length > section_end) |
b4eb7656 AM |
6314 | { |
6315 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6316 | (unsigned long) offset); |
b4eb7656 AM |
6317 | break; |
6318 | } | |
4723351a CC |
6319 | |
6320 | putchar ('('); | |
6321 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6322 | pointer_size, |
6323 | offset_size, | |
6324 | dwarf_version, | |
6325 | length, | |
6326 | cu_offset, section); | |
4723351a CC |
6327 | putchar (')'); |
6328 | ||
6329 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6330 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
6331 | |
6332 | putchar ('\n'); | |
6333 | ||
6334 | start += length; | |
6335 | } | |
6336 | ||
6337 | *start_ptr = start; | |
9f272209 | 6338 | *vstart_ptr = vstart; |
4723351a CC |
6339 | } |
6340 | ||
9f272209 AO |
6341 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
6342 | loc_views. */ | |
51d0d03f | 6343 | |
9f272209 | 6344 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
6345 | |
6346 | static int | |
6347 | loc_offsets_compar (const void *ap, const void *bp) | |
6348 | { | |
6349 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
6350 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
6351 | ||
9f272209 AO |
6352 | int ret = (a > b) - (b > a); |
6353 | if (ret) | |
6354 | return ret; | |
6355 | ||
6356 | a = loc_views[*(const unsigned int *) ap]; | |
6357 | b = loc_views[*(const unsigned int *) bp]; | |
6358 | ||
6359 | ret = (a > b) - (b > a); | |
6360 | ||
6361 | return ret; | |
51d0d03f JJ |
6362 | } |
6363 | ||
19e6b90e L |
6364 | static int |
6365 | display_debug_loc (struct dwarf_section *section, void *file) | |
6366 | { | |
9f272209 | 6367 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
6368 | unsigned long bytes; |
6369 | unsigned char *section_begin = start; | |
6370 | unsigned int num_loc_list = 0; | |
6371 | unsigned long last_offset = 0; | |
9f272209 | 6372 | unsigned long last_view = 0; |
19e6b90e L |
6373 | unsigned int first = 0; |
6374 | unsigned int i; | |
6375 | unsigned int j; | |
6376 | int seen_first_offset = 0; | |
51d0d03f | 6377 | int locs_sorted = 1; |
9f272209 | 6378 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6379 | unsigned int *array = NULL; |
4723351a | 6380 | const char *suffix = strrchr (section->name, '.'); |
24841daa | 6381 | bfd_boolean is_dwo = FALSE; |
77145576 JK |
6382 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6383 | dwarf_vma expected_start = 0; | |
4723351a CC |
6384 | |
6385 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
24841daa | 6386 | is_dwo = TRUE; |
19e6b90e L |
6387 | |
6388 | bytes = section->size; | |
19e6b90e L |
6389 | |
6390 | if (bytes == 0) | |
6391 | { | |
6392 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6393 | return 0; | |
6394 | } | |
6395 | ||
77145576 JK |
6396 | if (is_loclists) |
6397 | { | |
6398 | unsigned char *hdrptr = section_begin; | |
6399 | dwarf_vma ll_length; | |
6400 | unsigned short ll_version; | |
6401 | unsigned char *end = section_begin + section->size; | |
6402 | unsigned char address_size, segment_selector_size; | |
6403 | uint32_t offset_entry_count; | |
6404 | ||
6405 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6406 | if (ll_length == 0xffffffff) | |
6407 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6408 | ||
6409 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6410 | if (ll_version != 5) | |
6411 | { | |
6412 | warn (_("The %s section contains corrupt or " | |
6413 | "unsupported version number: %d.\n"), | |
6414 | section->name, ll_version); | |
6415 | return 0; | |
6416 | } | |
6417 | ||
6418 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6419 | ||
6420 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6421 | if (segment_selector_size != 0) | |
6422 | { | |
6423 | warn (_("The %s section contains " | |
6424 | "unsupported segment selector size: %d.\n"), | |
6425 | section->name, segment_selector_size); | |
6426 | return 0; | |
6427 | } | |
6428 | ||
6429 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
6430 | if (offset_entry_count != 0) | |
6431 | { | |
6432 | warn (_("The %s section contains " | |
6433 | "unsupported offset entry count: %d.\n"), | |
6434 | section->name, offset_entry_count); | |
6435 | return 0; | |
6436 | } | |
6437 | ||
6438 | expected_start = hdrptr - section_begin; | |
6439 | } | |
6440 | ||
1febe64d NC |
6441 | if (load_debug_info (file) == 0) |
6442 | { | |
6443 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6444 | section->name); | |
6445 | return 0; | |
6446 | } | |
19e6b90e L |
6447 | |
6448 | /* Check the order of location list in .debug_info section. If | |
6449 | offsets of location lists are in the ascending order, we can | |
6450 | use `debug_information' directly. */ | |
6451 | for (i = 0; i < num_debug_info_entries; i++) | |
6452 | { | |
6453 | unsigned int num; | |
6454 | ||
6455 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
6456 | if (num > num_loc_list) |
6457 | num_loc_list = num; | |
19e6b90e L |
6458 | |
6459 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 6460 | if (locs_sorted && num != 0) |
19e6b90e L |
6461 | { |
6462 | if (!seen_first_offset) | |
6463 | { | |
6464 | /* This is the first location list. */ | |
6465 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 6466 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
6467 | first = i; |
6468 | seen_first_offset = 1; | |
6469 | j = 1; | |
6470 | } | |
6471 | else | |
6472 | j = 0; | |
6473 | ||
6474 | for (; j < num; j++) | |
6475 | { | |
6476 | if (last_offset > | |
9f272209 AO |
6477 | debug_information [i].loc_offsets [j] |
6478 | || (last_offset == debug_information [i].loc_offsets [j] | |
6479 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 6480 | { |
51d0d03f | 6481 | locs_sorted = 0; |
19e6b90e L |
6482 | break; |
6483 | } | |
6484 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 6485 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
6486 | } |
6487 | } | |
6488 | } | |
6489 | ||
19e6b90e L |
6490 | if (!seen_first_offset) |
6491 | error (_("No location lists in .debug_info section!\n")); | |
6492 | ||
d4bfc77b | 6493 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
6494 | && debug_information [first].loc_offsets [0] != expected_start |
6495 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
6496 | warn (_("Location lists in %s section start at 0x%s\n"), |
6497 | section->name, | |
6498 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 6499 | |
51d0d03f JJ |
6500 | if (!locs_sorted) |
6501 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d NC |
6502 | |
6503 | introduce (section, FALSE); | |
6504 | ||
d1c4b12b NC |
6505 | if (reloc_at (section, 0)) |
6506 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 6507 | |
d1c4b12b | 6508 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
6509 | |
6510 | seen_first_offset = 0; | |
6511 | for (i = first; i < num_debug_info_entries; i++) | |
6512 | { | |
9f272209 | 6513 | dwarf_vma offset, voffset; |
359ca075 | 6514 | dwarf_vma base_address; |
d1c4b12b | 6515 | unsigned int k; |
19e6b90e L |
6516 | int has_frame_base; |
6517 | ||
51d0d03f JJ |
6518 | if (!locs_sorted) |
6519 | { | |
6520 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
6521 | array[k] = k; | |
6522 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 6523 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
6524 | qsort (array, debug_information [i].num_loc_offsets, |
6525 | sizeof (*array), loc_offsets_compar); | |
6526 | } | |
19e6b90e | 6527 | |
9f272209 | 6528 | int adjacent_view_loclists = 1; |
51d0d03f | 6529 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 6530 | { |
51d0d03f JJ |
6531 | j = locs_sorted ? k : array[k]; |
6532 | if (k | |
9f272209 | 6533 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 6534 | ? k - 1 : array [k - 1]] |
9f272209 AO |
6535 | == debug_information [i].loc_offsets [j]) |
6536 | && (debug_information [i].loc_views [locs_sorted | |
6537 | ? k - 1 : array [k - 1]] | |
6538 | == debug_information [i].loc_views [j])) | |
51d0d03f | 6539 | continue; |
19e6b90e | 6540 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 6541 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 6542 | next = section_begin + offset; |
9f272209 AO |
6543 | voffset = debug_information [i].loc_views [j]; |
6544 | if (voffset != vm1) | |
6545 | vnext = section_begin + voffset; | |
6546 | else | |
6547 | vnext = NULL; | |
19e6b90e L |
6548 | base_address = debug_information [i].base_address; |
6549 | ||
9f272209 AO |
6550 | if (vnext && vnext < next) |
6551 | { | |
6552 | vstart = vnext; | |
6553 | display_view_pair_list (section, &vstart, i, next); | |
6554 | if (start == vnext) | |
6555 | start = vstart; | |
6556 | } | |
6557 | ||
6558 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
6559 | seen_first_offset = 1; |
6560 | else | |
6561 | { | |
6562 | if (start < next) | |
6563 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6564 | (unsigned long) (start - section_begin), |
c8071705 | 6565 | (unsigned long) offset); |
19e6b90e L |
6566 | else if (start > next) |
6567 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6568 | (unsigned long) (start - section_begin), |
c8071705 | 6569 | (unsigned long) offset); |
19e6b90e L |
6570 | } |
6571 | start = next; | |
9f272209 | 6572 | vstart = vnext; |
19e6b90e L |
6573 | |
6574 | if (offset >= bytes) | |
6575 | { | |
6576 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 6577 | (unsigned long) offset); |
19e6b90e L |
6578 | continue; |
6579 | } | |
6580 | ||
9f272209 AO |
6581 | if (vnext && voffset >= bytes) |
6582 | { | |
6583 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
6584 | (unsigned long) voffset); | |
6585 | continue; | |
6586 | } | |
6587 | ||
77145576 JK |
6588 | if (!is_loclists) |
6589 | { | |
6590 | if (is_dwo) | |
6591 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 6592 | &vstart, has_frame_base); |
77145576 JK |
6593 | else |
6594 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 6595 | &vstart, has_frame_base); |
77145576 | 6596 | } |
b4eb7656 | 6597 | else |
77145576 JK |
6598 | { |
6599 | if (is_dwo) | |
6600 | warn (_("DWO is not yet supported.\n")); | |
6601 | else | |
6602 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
6603 | &vstart, has_frame_base); |
6604 | } | |
6605 | ||
6606 | /* FIXME: this arrangement is quite simplistic. Nothing | |
6607 | requires locview lists to be adjacent to corresponding | |
6608 | loclists, and a single loclist could be augmented by | |
6609 | different locview lists, and vice-versa, unlikely as it | |
6610 | is that it would make sense to do so. Hopefully we'll | |
6611 | have view pair support built into loclists before we ever | |
6612 | need to address all these possibilities. */ | |
6613 | if (adjacent_view_loclists && vnext | |
6614 | && vnext != start && vstart != next) | |
6615 | { | |
6616 | adjacent_view_loclists = 0; | |
6617 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 6618 | } |
9f272209 AO |
6619 | |
6620 | if (vnext && vnext == start) | |
6621 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
6622 | } |
6623 | } | |
031cd65f | 6624 | |
4723351a | 6625 | if (start < section->start + section->size) |
d3a49aa8 AM |
6626 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
6627 | "There are %ld unused bytes at the end of section %s\n", | |
6628 | (long) (section->start + section->size - start)), | |
4723351a | 6629 | (long) (section->start + section->size - start), section->name); |
98fb390a | 6630 | putchar ('\n'); |
51d0d03f | 6631 | free (array); |
19e6b90e L |
6632 | return 1; |
6633 | } | |
6634 | ||
6635 | static int | |
6636 | display_debug_str (struct dwarf_section *section, | |
6637 | void *file ATTRIBUTE_UNUSED) | |
6638 | { | |
6639 | unsigned char *start = section->start; | |
6640 | unsigned long bytes = section->size; | |
6641 | dwarf_vma addr = section->address; | |
6642 | ||
6643 | if (bytes == 0) | |
6644 | { | |
6645 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6646 | return 0; | |
6647 | } | |
6648 | ||
dda8d76d | 6649 | introduce (section, FALSE); |
19e6b90e L |
6650 | |
6651 | while (bytes) | |
6652 | { | |
6653 | int j; | |
6654 | int k; | |
6655 | int lbytes; | |
6656 | ||
6657 | lbytes = (bytes > 16 ? 16 : bytes); | |
6658 | ||
6659 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
6660 | ||
6661 | for (j = 0; j < 16; j++) | |
6662 | { | |
6663 | if (j < lbytes) | |
6664 | printf ("%2.2x", start[j]); | |
6665 | else | |
6666 | printf (" "); | |
6667 | ||
6668 | if ((j & 3) == 3) | |
6669 | printf (" "); | |
6670 | } | |
6671 | ||
6672 | for (j = 0; j < lbytes; j++) | |
6673 | { | |
6674 | k = start[j]; | |
6675 | if (k >= ' ' && k < 0x80) | |
6676 | printf ("%c", k); | |
6677 | else | |
6678 | printf ("."); | |
6679 | } | |
6680 | ||
6681 | putchar ('\n'); | |
6682 | ||
6683 | start += lbytes; | |
6684 | addr += lbytes; | |
6685 | bytes -= lbytes; | |
6686 | } | |
6687 | ||
6688 | putchar ('\n'); | |
6689 | ||
6690 | return 1; | |
6691 | } | |
6692 | ||
19e6b90e L |
6693 | static int |
6694 | display_debug_info (struct dwarf_section *section, void *file) | |
6695 | { | |
d85bf2ba | 6696 | return process_debug_info (section, file, section->abbrev_sec, FALSE, FALSE); |
19e6b90e L |
6697 | } |
6698 | ||
2b6f5997 CC |
6699 | static int |
6700 | display_debug_types (struct dwarf_section *section, void *file) | |
6701 | { | |
d85bf2ba | 6702 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
6f875884 TG |
6703 | } |
6704 | ||
6705 | static int | |
6706 | display_trace_info (struct dwarf_section *section, void *file) | |
6707 | { | |
d85bf2ba | 6708 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
2b6f5997 | 6709 | } |
19e6b90e L |
6710 | |
6711 | static int | |
6712 | display_debug_aranges (struct dwarf_section *section, | |
6713 | void *file ATTRIBUTE_UNUSED) | |
6714 | { | |
6715 | unsigned char *start = section->start; | |
6716 | unsigned char *end = start + section->size; | |
6717 | ||
dda8d76d | 6718 | introduce (section, FALSE); |
19e6b90e | 6719 | |
6e3d6dc1 NC |
6720 | /* It does not matter if this load fails, |
6721 | we test for that later on. */ | |
6722 | load_debug_info (file); | |
6723 | ||
19e6b90e L |
6724 | while (start < end) |
6725 | { | |
6726 | unsigned char *hdrptr; | |
6727 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 6728 | unsigned char *addr_ranges; |
2d9472a2 NC |
6729 | dwarf_vma length; |
6730 | dwarf_vma address; | |
e98fdf1a | 6731 | unsigned long sec_off; |
53b8873b | 6732 | unsigned char address_size; |
19e6b90e | 6733 | int excess; |
bf5117e3 NC |
6734 | unsigned int offset_size; |
6735 | unsigned int initial_length_size; | |
19e6b90e L |
6736 | |
6737 | hdrptr = start; | |
6738 | ||
0c588247 | 6739 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
6740 | if (arange.ar_length == 0xffffffff) |
6741 | { | |
0c588247 | 6742 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
6743 | offset_size = 8; |
6744 | initial_length_size = 12; | |
6745 | } | |
6746 | else | |
6747 | { | |
6748 | offset_size = 4; | |
6749 | initial_length_size = 4; | |
6750 | } | |
6751 | ||
e98fdf1a AM |
6752 | sec_off = hdrptr - section->start; |
6753 | if (sec_off + arange.ar_length < sec_off | |
6754 | || sec_off + arange.ar_length > section->size) | |
6755 | { | |
6756 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
6757 | section->name, | |
6758 | sec_off - initial_length_size, | |
6759 | dwarf_vmatoa ("x", arange.ar_length)); | |
6760 | break; | |
6761 | } | |
6762 | ||
0c588247 NC |
6763 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
6764 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 6765 | |
6e3d6dc1 NC |
6766 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
6767 | && num_debug_info_entries > 0 | |
6768 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
6769 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 6770 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 6771 | |
0c588247 NC |
6772 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
6773 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
6774 | |
6775 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
6776 | { | |
67f101ee NC |
6777 | /* PR 19872: A version number of 0 probably means that there is |
6778 | padding at the end of the .debug_aranges section. Gold puts | |
6779 | it there when performing an incremental link, for example. | |
6780 | So do not generate a warning in this case. */ | |
6781 | if (arange.ar_version) | |
6782 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
6783 | break; |
6784 | } | |
6785 | ||
47704ddf KT |
6786 | printf (_(" Length: %ld\n"), |
6787 | (long) arange.ar_length); | |
19e6b90e | 6788 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
6789 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
6790 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
6791 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
6792 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
6793 | ||
53b8873b NC |
6794 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
6795 | ||
f41e4712 NC |
6796 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
6797 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
6798 | { |
6799 | error (_("Invalid address size in %s section!\n"), | |
6800 | section->name); | |
6801 | break; | |
6802 | } | |
6803 | ||
53b8873b NC |
6804 | /* The DWARF spec does not require that the address size be a power |
6805 | of two, but we do. This will have to change if we ever encounter | |
6806 | an uneven architecture. */ | |
6807 | if ((address_size & (address_size - 1)) != 0) | |
6808 | { | |
6809 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
6810 | break; | |
6811 | } | |
cecf136e | 6812 | |
209c9a13 NC |
6813 | if (address_size > 4) |
6814 | printf (_("\n Address Length\n")); | |
6815 | else | |
6816 | printf (_("\n Address Length\n")); | |
19e6b90e | 6817 | |
91d6fa6a | 6818 | addr_ranges = hdrptr; |
19e6b90e | 6819 | |
53b8873b NC |
6820 | /* Must pad to an alignment boundary that is twice the address size. */ |
6821 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 6822 | if (excess) |
91d6fa6a | 6823 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 6824 | |
e98fdf1a | 6825 | start += arange.ar_length + initial_length_size; |
1617e571 | 6826 | |
91d6fa6a | 6827 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 6828 | { |
0c588247 NC |
6829 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
6830 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 6831 | |
80c35038 | 6832 | printf (" "); |
2d9472a2 NC |
6833 | print_dwarf_vma (address, address_size); |
6834 | print_dwarf_vma (length, address_size); | |
6835 | putchar ('\n'); | |
19e6b90e | 6836 | } |
19e6b90e L |
6837 | } |
6838 | ||
6839 | printf ("\n"); | |
6840 | ||
6841 | return 1; | |
6842 | } | |
6843 | ||
4723351a CC |
6844 | /* Comparison function for qsort. */ |
6845 | static int | |
6846 | comp_addr_base (const void * v0, const void * v1) | |
6847 | { | |
d367307b AM |
6848 | debug_info *info0 = *(debug_info **) v0; |
6849 | debug_info *info1 = *(debug_info **) v1; | |
4723351a CC |
6850 | return info0->addr_base - info1->addr_base; |
6851 | } | |
6852 | ||
6853 | /* Display the debug_addr section. */ | |
6854 | static int | |
6855 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 6856 | void *file) |
4723351a CC |
6857 | { |
6858 | debug_info **debug_addr_info; | |
6859 | unsigned char *entry; | |
6860 | unsigned char *end; | |
6861 | unsigned int i; | |
6862 | unsigned int count; | |
6863 | ||
6864 | if (section->size == 0) | |
6865 | { | |
6866 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6867 | return 0; | |
6868 | } | |
6869 | ||
6870 | if (load_debug_info (file) == 0) | |
6871 | { | |
6872 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6873 | section->name); | |
6874 | return 0; | |
6875 | } | |
6876 | ||
dda8d76d | 6877 | introduce (section, FALSE); |
4723351a | 6878 | |
1306a742 NC |
6879 | /* PR 17531: file: cf38d01b. |
6880 | We use xcalloc because a corrupt file may not have initialised all of the | |
6881 | fields in the debug_info structure, which means that the sort below might | |
6882 | try to move uninitialised data. */ | |
6883 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 6884 | sizeof (debug_info *)); |
4723351a CC |
6885 | |
6886 | count = 0; | |
6887 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 6888 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
6889 | { |
6890 | /* PR 17531: file: cf38d01b. */ | |
6891 | if (debug_information[i].addr_base >= section->size) | |
6892 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
6893 | (unsigned long) debug_information[i].addr_base, i); | |
6894 | else | |
6895 | debug_addr_info [count++] = debug_information + i; | |
6896 | } | |
4723351a CC |
6897 | |
6898 | /* Add a sentinel to make iteration convenient. */ | |
6899 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
6900 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 6901 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 6902 | |
4723351a CC |
6903 | for (i = 0; i < count; i++) |
6904 | { | |
6905 | unsigned int idx; | |
fab128ef | 6906 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
6907 | |
6908 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 6909 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 6910 | |
fab128ef | 6911 | printf (_("\tIndex\tAddress\n")); |
4723351a CC |
6912 | entry = section->start + debug_addr_info [i]->addr_base; |
6913 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
6914 | idx = 0; | |
6915 | while (entry < end) | |
b4eb7656 AM |
6916 | { |
6917 | dwarf_vma base = byte_get (entry, address_size); | |
6918 | printf (_("\t%d:\t"), idx); | |
6919 | print_dwarf_vma (base, address_size); | |
6920 | printf ("\n"); | |
6921 | entry += address_size; | |
6922 | idx++; | |
6923 | } | |
4723351a CC |
6924 | } |
6925 | printf ("\n"); | |
6926 | ||
6927 | free (debug_addr_info); | |
6928 | return 1; | |
6929 | } | |
6930 | ||
6931 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 6932 | |
4723351a CC |
6933 | static int |
6934 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 6935 | void *file ATTRIBUTE_UNUSED) |
4723351a | 6936 | { |
9f27c364 HPN |
6937 | unsigned long idx; |
6938 | ||
4723351a CC |
6939 | if (section->size == 0) |
6940 | { | |
6941 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6942 | return 0; | |
6943 | } | |
e4b7104b NC |
6944 | |
6945 | unsigned char *start = section->start; | |
6946 | unsigned char *end = start + section->size; | |
6947 | unsigned char *curr = start; | |
6948 | ||
39f381cb NC |
6949 | const char * suffix = strrchr (section->name, '.'); |
6950 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
6951 | ||
6952 | if (dwo) | |
6953 | load_debug_section_with_follow (str_dwo, file); | |
6954 | else | |
6955 | load_debug_section_with_follow (str, file); | |
e4b7104b NC |
6956 | |
6957 | introduce (section, FALSE); | |
6958 | ||
6959 | while (curr < end) | |
6960 | { | |
6961 | dwarf_vma length; | |
6962 | dwarf_vma entry_length; | |
6963 | ||
6964 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); | |
6965 | /* FIXME: We assume that this means 64-bit DWARF is being used. */ | |
6966 | if (length == 0xffffffff) | |
6967 | { | |
6968 | SAFE_BYTE_GET (length, curr, 8, end); | |
6969 | entry_length = 8; | |
6970 | } | |
6971 | else | |
6972 | entry_length = 4; | |
6973 | ||
39f381cb NC |
6974 | if (length == 0) |
6975 | { | |
6976 | /* This is probably an old style .debug_str_offset section which | |
6977 | just contains offsets and no header (and the first offset is 0). */ | |
6978 | length = section->size; | |
6979 | curr = section->start; | |
e4b7104b | 6980 | |
39f381cb NC |
6981 | printf (_(" Length: %#lx\n"), (unsigned long) length); |
6982 | printf (_(" Index Offset [String]\n")); | |
6983 | } | |
6984 | else | |
6985 | { | |
6986 | int version; | |
6987 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); | |
6988 | if (version != 5) | |
6989 | warn (_("Unexpected version number in str_offset header: %#x\n"), version); | |
6990 | ||
6991 | int padding; | |
6992 | SAFE_BYTE_GET_AND_INC (padding, curr, 2, end); | |
6993 | if (padding != 0) | |
6994 | warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding); | |
6995 | ||
6996 | printf (_(" Length: %#lx\n"), (unsigned long) length); | |
6997 | printf (_(" Version: %#lx\n"), (unsigned long) version); | |
6998 | printf (_(" Index Offset [String]\n")); | |
6999 | } | |
e4b7104b | 7000 | |
9f27c364 | 7001 | for (idx = 0; length >= entry_length && curr < end; idx++) |
e4b7104b NC |
7002 | { |
7003 | dwarf_vma offset; | |
7004 | const unsigned char * string; | |
7005 | ||
7006 | SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, end); | |
39f381cb NC |
7007 | if (dwo) |
7008 | string = (const unsigned char *) | |
9f27c364 | 7009 | fetch_indexed_string (idx, NULL, entry_length, dwo); |
39f381cb NC |
7010 | else |
7011 | string = fetch_indirect_string (offset); | |
7012 | ||
9f27c364 | 7013 | printf (" %8lu %8s %s\n", idx, dwarf_vmatoa ("x", offset), |
e4b7104b NC |
7014 | string); |
7015 | } | |
7016 | } | |
39f381cb | 7017 | |
4723351a CC |
7018 | return 1; |
7019 | } | |
7020 | ||
01a8f077 JK |
7021 | /* Each debug_information[x].range_lists[y] gets this representation for |
7022 | sorting purposes. */ | |
7023 | ||
7024 | struct range_entry | |
467c65bc NC |
7025 | { |
7026 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 7027 | dwarf_vma ranges_offset; |
01a8f077 | 7028 | |
467c65bc NC |
7029 | /* Original debug_information to find parameters of the data. */ |
7030 | debug_info *debug_info_p; | |
7031 | }; | |
01a8f077 JK |
7032 | |
7033 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
7034 | ||
7035 | static int | |
7036 | range_entry_compar (const void *ap, const void *bp) | |
7037 | { | |
3f5e193b NC |
7038 | const struct range_entry *a_re = (const struct range_entry *) ap; |
7039 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
7040 | const dwarf_vma a = a_re->ranges_offset; |
7041 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
7042 | |
7043 | return (a > b) - (b > a); | |
7044 | } | |
7045 | ||
77145576 JK |
7046 | static void |
7047 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
7048 | unsigned int pointer_size, unsigned long offset, | |
7049 | unsigned long base_address) | |
7050 | { | |
7051 | while (start < finish) | |
7052 | { | |
7053 | dwarf_vma begin; | |
7054 | dwarf_vma end; | |
7055 | ||
7056 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7057 | if (start >= finish) | |
7058 | break; | |
7059 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7060 | ||
d11ae95e | 7061 | |
77145576 JK |
7062 | printf (" %8.8lx ", offset); |
7063 | ||
7064 | if (begin == 0 && end == 0) | |
7065 | { | |
7066 | printf (_("<End of list>\n")); | |
7067 | break; | |
7068 | } | |
7069 | ||
7070 | /* Check base address specifiers. */ | |
7071 | if (is_max_address (begin, pointer_size) | |
7072 | && !is_max_address (end, pointer_size)) | |
7073 | { | |
7074 | base_address = end; | |
7075 | print_dwarf_vma (begin, pointer_size); | |
7076 | print_dwarf_vma (end, pointer_size); | |
7077 | printf ("(base address)\n"); | |
7078 | continue; | |
7079 | } | |
7080 | ||
7081 | print_dwarf_vma (begin + base_address, pointer_size); | |
7082 | print_dwarf_vma (end + base_address, pointer_size); | |
7083 | ||
7084 | if (begin == end) | |
7085 | fputs (_("(start == end)"), stdout); | |
7086 | else if (begin > end) | |
7087 | fputs (_("(start > end)"), stdout); | |
7088 | ||
7089 | putchar ('\n'); | |
7090 | } | |
7091 | } | |
7092 | ||
7093 | static void | |
7094 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
7095 | unsigned int pointer_size, unsigned long offset, | |
7096 | unsigned long base_address) | |
7097 | { | |
7098 | unsigned char *next = start; | |
7099 | ||
7100 | while (1) | |
7101 | { | |
7102 | unsigned long off = offset + (start - next); | |
7103 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
7104 | /* Initialize it due to a false compiler warning. */ |
7105 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
7106 | |
7107 | if (start + 1 > finish) | |
7108 | { | |
7109 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
7110 | offset); | |
7111 | break; | |
7112 | } | |
7113 | ||
7114 | printf (" %8.8lx ", off); | |
7115 | ||
7116 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
7117 | ||
7118 | switch (rlet) | |
7119 | { | |
7120 | case DW_RLE_end_of_list: | |
7121 | printf (_("<End of list>\n")); | |
7122 | break; | |
7123 | case DW_RLE_base_address: | |
7124 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
7125 | print_dwarf_vma (base_address, pointer_size); | |
7126 | printf (_("(base address)\n")); | |
7127 | break; | |
7128 | case DW_RLE_start_length: | |
7129 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
cd30bcef | 7130 | READ_ULEB (length, start, finish); |
77145576 JK |
7131 | end = begin + length; |
7132 | break; | |
7133 | case DW_RLE_offset_pair: | |
cd30bcef AM |
7134 | READ_ULEB (begin, start, finish); |
7135 | READ_ULEB (end, start, finish); | |
77145576 JK |
7136 | break; |
7137 | case DW_RLE_start_end: | |
7138 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7139 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7140 | break; | |
7141 | default: | |
7142 | error (_("Invalid range list entry type %d\n"), rlet); | |
7143 | rlet = DW_RLE_end_of_list; | |
7144 | break; | |
7145 | } | |
7146 | if (rlet == DW_RLE_end_of_list) | |
7147 | break; | |
7148 | if (rlet == DW_RLE_base_address) | |
7149 | continue; | |
7150 | ||
7151 | print_dwarf_vma (begin + base_address, pointer_size); | |
7152 | print_dwarf_vma (end + base_address, pointer_size); | |
7153 | ||
7154 | if (begin == end) | |
7155 | fputs (_("(start == end)"), stdout); | |
7156 | else if (begin > end) | |
7157 | fputs (_("(start > end)"), stdout); | |
7158 | ||
7159 | putchar ('\n'); | |
7160 | } | |
7161 | } | |
7162 | ||
19e6b90e L |
7163 | static int |
7164 | display_debug_ranges (struct dwarf_section *section, | |
7165 | void *file ATTRIBUTE_UNUSED) | |
7166 | { | |
7167 | unsigned char *start = section->start; | |
a2ff7a4b | 7168 | unsigned char *last_start = start; |
f6f0e17b | 7169 | unsigned long bytes = section->size; |
19e6b90e | 7170 | unsigned char *section_begin = start; |
f6f0e17b | 7171 | unsigned char *finish = start + bytes; |
01a8f077 JK |
7172 | unsigned int num_range_list, i; |
7173 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
7174 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
7175 | /* Initialize it due to a false compiler warning. */ | |
7176 | unsigned char address_size = 0; | |
cb4c35cf | 7177 | dwarf_vma last_offset = 0; |
19e6b90e | 7178 | |
19e6b90e L |
7179 | if (bytes == 0) |
7180 | { | |
7181 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7182 | return 0; | |
7183 | } | |
7184 | ||
77145576 JK |
7185 | if (is_rnglists) |
7186 | { | |
7187 | dwarf_vma initial_length; | |
7188 | unsigned int initial_length_size; | |
7189 | unsigned char segment_selector_size; | |
7190 | unsigned int offset_size, offset_entry_count; | |
7191 | unsigned short version; | |
7192 | ||
7193 | /* Get and check the length of the block. */ | |
7194 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
7195 | ||
7196 | if (initial_length == 0xffffffff) | |
7197 | { | |
7198 | /* This section is 64-bit DWARF 3. */ | |
7199 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
7200 | offset_size = 8; | |
7201 | initial_length_size = 12; | |
7202 | } | |
7203 | else | |
7204 | { | |
7205 | offset_size = 4; | |
7206 | initial_length_size = 4; | |
7207 | } | |
7208 | ||
7209 | if (initial_length + initial_length_size > section->size) | |
7210 | { | |
7211 | /* If the length field has a relocation against it, then we should | |
7212 | not complain if it is inaccurate (and probably negative). | |
7213 | It is copied from .debug_line handling code. */ | |
7214 | if (reloc_at (section, (start - section->start) - offset_size)) | |
7215 | { | |
7216 | initial_length = (finish - start) - initial_length_size; | |
7217 | } | |
7218 | else | |
7219 | { | |
7220 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
7221 | (long) initial_length); | |
7222 | return 0; | |
7223 | } | |
7224 | } | |
7225 | ||
7226 | /* Get and check the version number. */ | |
7227 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
7228 | ||
7229 | if (version != 5) | |
7230 | { | |
7231 | warn (_("Only DWARF version 5 debug_rnglists info " | |
7232 | "is currently supported.\n")); | |
7233 | return 0; | |
7234 | } | |
7235 | ||
7236 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
7237 | ||
7238 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
7239 | if (segment_selector_size != 0) | |
7240 | { | |
7241 | warn (_("The %s section contains " | |
7242 | "unsupported segment selector size: %d.\n"), | |
7243 | section->name, segment_selector_size); | |
7244 | return 0; | |
7245 | } | |
7246 | ||
7247 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
7248 | if (offset_entry_count != 0) | |
7249 | { | |
7250 | warn (_("The %s section contains " | |
7251 | "unsupported offset entry count: %u.\n"), | |
7252 | section->name, offset_entry_count); | |
7253 | return 0; | |
7254 | } | |
7255 | } | |
7256 | ||
1febe64d NC |
7257 | if (load_debug_info (file) == 0) |
7258 | { | |
7259 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7260 | section->name); | |
7261 | return 0; | |
7262 | } | |
19e6b90e | 7263 | |
01a8f077 | 7264 | num_range_list = 0; |
19e6b90e | 7265 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 7266 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 7267 | |
01a8f077 | 7268 | if (num_range_list == 0) |
4723351a CC |
7269 | { |
7270 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 7271 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
7272 | printf (_("No range lists in .debug_info section.\n")); |
7273 | return 1; | |
7274 | } | |
19e6b90e | 7275 | |
3f5e193b NC |
7276 | range_entries = (struct range_entry *) |
7277 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 7278 | range_entry_fill = range_entries; |
19e6b90e | 7279 | |
01a8f077 JK |
7280 | for (i = 0; i < num_debug_info_entries; i++) |
7281 | { | |
7282 | debug_info *debug_info_p = &debug_information[i]; | |
7283 | unsigned int j; | |
7284 | ||
7285 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
7286 | { | |
7287 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
7288 | range_entry_fill->debug_info_p = debug_info_p; | |
7289 | range_entry_fill++; | |
19e6b90e L |
7290 | } |
7291 | } | |
7292 | ||
01a8f077 JK |
7293 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
7294 | range_entry_compar); | |
19e6b90e | 7295 | |
d493b283 | 7296 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 7297 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 7298 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 7299 | |
dda8d76d NC |
7300 | introduce (section, FALSE); |
7301 | ||
19e6b90e L |
7302 | printf (_(" Offset Begin End\n")); |
7303 | ||
01a8f077 | 7304 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 7305 | { |
01a8f077 JK |
7306 | struct range_entry *range_entry = &range_entries[i]; |
7307 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 7308 | unsigned int pointer_size; |
359ca075 | 7309 | dwarf_vma offset; |
01a8f077 | 7310 | unsigned char *next; |
359ca075 | 7311 | dwarf_vma base_address; |
19e6b90e | 7312 | |
77145576 | 7313 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 7314 | offset = range_entry->ranges_offset; |
01a8f077 JK |
7315 | next = section_begin + offset; |
7316 | base_address = debug_info_p->base_address; | |
cecf136e | 7317 | |
f41e4712 NC |
7318 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
7319 | if (pointer_size < 2 || pointer_size > 8) | |
7320 | { | |
7321 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 7322 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
7323 | continue; |
7324 | } | |
b4eb7656 | 7325 | |
d11ae95e NC |
7326 | if (next < section_begin || next >= finish) |
7327 | { | |
7328 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
7329 | (unsigned long) offset, i); | |
7330 | continue; | |
7331 | } | |
7332 | ||
cb4c35cf AB |
7333 | /* If multiple DWARF entities reference the same range then we will |
7334 | have multiple entries in the `range_entries' list for the same | |
7335 | offset. Thanks to the sort above these will all be consecutive in | |
7336 | the `range_entries' list, so we can easily ignore duplicates | |
7337 | here. */ | |
7338 | if (i > 0 && last_offset == offset) | |
7339 | continue; | |
7340 | last_offset = offset; | |
7341 | ||
4723351a | 7342 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 7343 | { |
01a8f077 JK |
7344 | if (start < next) |
7345 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
7346 | (unsigned long) (start - section_begin), | |
7347 | (unsigned long) (next - section_begin), section->name); | |
7348 | else if (start > next) | |
a2ff7a4b AM |
7349 | { |
7350 | if (next == last_start) | |
7351 | continue; | |
7352 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
7353 | (unsigned long) (start - section_begin), | |
7354 | (unsigned long) (next - section_begin), section->name); | |
7355 | } | |
01a8f077 | 7356 | } |
d11ae95e | 7357 | |
01a8f077 | 7358 | start = next; |
a2ff7a4b | 7359 | last_start = next; |
19e6b90e | 7360 | |
77145576 JK |
7361 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
7362 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
7363 | } |
7364 | putchar ('\n'); | |
01a8f077 JK |
7365 | |
7366 | free (range_entries); | |
7367 | ||
19e6b90e L |
7368 | return 1; |
7369 | } | |
7370 | ||
7371 | typedef struct Frame_Chunk | |
7372 | { | |
7373 | struct Frame_Chunk *next; | |
7374 | unsigned char *chunk_start; | |
a1165289 | 7375 | unsigned int ncols; |
19e6b90e L |
7376 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
7377 | short int *col_type; | |
7378 | int *col_offset; | |
7379 | char *augmentation; | |
7380 | unsigned int code_factor; | |
7381 | int data_factor; | |
bf5117e3 NC |
7382 | dwarf_vma pc_begin; |
7383 | dwarf_vma pc_range; | |
32ef3000 | 7384 | unsigned int cfa_reg; |
c8071705 | 7385 | dwarf_vma cfa_offset; |
a1165289 | 7386 | unsigned int ra; |
19e6b90e L |
7387 | unsigned char fde_encoding; |
7388 | unsigned char cfa_exp; | |
604282a7 JJ |
7389 | unsigned char ptr_size; |
7390 | unsigned char segment_size; | |
19e6b90e L |
7391 | } |
7392 | Frame_Chunk; | |
7393 | ||
1296bc99 AB |
7394 | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); |
7395 | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; | |
665ce1f6 L |
7396 | static const char *const *dwarf_regnames; |
7397 | static unsigned int dwarf_regnames_count; | |
7398 | ||
1296bc99 | 7399 | |
19e6b90e L |
7400 | /* A marker for a col_type that means this column was never referenced |
7401 | in the frame info. */ | |
7402 | #define DW_CFA_unreferenced (-1) | |
7403 | ||
a1165289 | 7404 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
7405 | -1 for invalid reg. */ |
7406 | ||
7407 | static int | |
7408 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 7409 | { |
a1165289 | 7410 | unsigned int prev = fc->ncols; |
19e6b90e | 7411 | |
665ce1f6 L |
7412 | if (reg < (unsigned int) fc->ncols) |
7413 | return 0; | |
7414 | ||
d9acf707 | 7415 | if (dwarf_regnames_count > 0 |
665ce1f6 L |
7416 | && reg > dwarf_regnames_count) |
7417 | return -1; | |
19e6b90e L |
7418 | |
7419 | fc->ncols = reg + 1; | |
a1165289 NC |
7420 | /* PR 17512: file: 10450-2643-0.004. |
7421 | If reg == -1 then this can happen... */ | |
7422 | if (fc->ncols == 0) | |
7423 | return -1; | |
7424 | ||
06614111 | 7425 | /* PR 17512: file: 2844a11d. */ |
d9acf707 | 7426 | if (fc->ncols > 1024 && dwarf_regnames_count == 0) |
06614111 NC |
7427 | { |
7428 | error (_("Unfeasibly large register number: %u\n"), reg); | |
7429 | fc->ncols = 0; | |
7430 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
7431 | we ever encounter a valid binary that exceeds it. */ | |
7432 | return -1; | |
7433 | } | |
7434 | ||
3f5e193b | 7435 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 7436 | sizeof (short int)); |
3f5e193b | 7437 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 7438 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
7439 | if (fc->col_type == NULL || fc->col_offset == NULL) |
7440 | { | |
7441 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
7442 | fc->ncols); | |
7443 | fc->ncols = 0; | |
7444 | return -1; | |
7445 | } | |
19e6b90e L |
7446 | |
7447 | while (prev < fc->ncols) | |
7448 | { | |
7449 | fc->col_type[prev] = DW_CFA_unreferenced; | |
7450 | fc->col_offset[prev] = 0; | |
7451 | prev++; | |
7452 | } | |
665ce1f6 | 7453 | return 1; |
19e6b90e L |
7454 | } |
7455 | ||
2dc4cec1 L |
7456 | static const char *const dwarf_regnames_i386[] = |
7457 | { | |
43234a1e L |
7458 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
7459 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7460 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7461 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
7462 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
7463 | NULL, NULL, /* 19 - 20 */ | |
7464 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
7465 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
7466 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
7467 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
7468 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
7469 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7470 | "tr", "ldtr", /* 48 - 49 */ | |
7471 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7472 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7473 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7474 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7475 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7476 | NULL, NULL, NULL, /* 90 - 92 */ | |
7477 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
7478 | }; |
7479 | ||
3d875af5 L |
7480 | static const char *const dwarf_regnames_iamcu[] = |
7481 | { | |
7482 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
7483 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7484 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7485 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
7486 | NULL, NULL, /* 19 - 20 */ | |
7487 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
7488 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
7489 | NULL, NULL, NULL, /* 37 - 39 */ | |
7490 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7491 | "tr", "ldtr", /* 48 - 49 */ | |
7492 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7493 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7494 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7495 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7496 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7497 | NULL, NULL, NULL, /* 90 - 92 */ | |
7498 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
7499 | }; | |
7500 | ||
99f6fdd9 | 7501 | static void |
b129eb0e RH |
7502 | init_dwarf_regnames_i386 (void) |
7503 | { | |
7504 | dwarf_regnames = dwarf_regnames_i386; | |
7505 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
1296bc99 | 7506 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
7507 | } |
7508 | ||
99f6fdd9 | 7509 | static void |
3d875af5 L |
7510 | init_dwarf_regnames_iamcu (void) |
7511 | { | |
7512 | dwarf_regnames = dwarf_regnames_iamcu; | |
7513 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
1296bc99 | 7514 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
3d875af5 L |
7515 | } |
7516 | ||
2dc4cec1 L |
7517 | static const char *const dwarf_regnames_x86_64[] = |
7518 | { | |
7519 | "rax", "rdx", "rcx", "rbx", | |
7520 | "rsi", "rdi", "rbp", "rsp", | |
7521 | "r8", "r9", "r10", "r11", | |
7522 | "r12", "r13", "r14", "r15", | |
7523 | "rip", | |
7524 | "xmm0", "xmm1", "xmm2", "xmm3", | |
7525 | "xmm4", "xmm5", "xmm6", "xmm7", | |
7526 | "xmm8", "xmm9", "xmm10", "xmm11", | |
7527 | "xmm12", "xmm13", "xmm14", "xmm15", | |
7528 | "st0", "st1", "st2", "st3", | |
7529 | "st4", "st5", "st6", "st7", | |
7530 | "mm0", "mm1", "mm2", "mm3", | |
7531 | "mm4", "mm5", "mm6", "mm7", | |
7532 | "rflags", | |
7533 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
7534 | "fs.base", "gs.base", NULL, NULL, | |
7535 | "tr", "ldtr", | |
43234a1e L |
7536 | "mxcsr", "fcw", "fsw", |
7537 | "xmm16", "xmm17", "xmm18", "xmm19", | |
7538 | "xmm20", "xmm21", "xmm22", "xmm23", | |
7539 | "xmm24", "xmm25", "xmm26", "xmm27", | |
7540 | "xmm28", "xmm29", "xmm30", "xmm31", | |
7541 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
7542 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
7543 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
7544 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
7545 | NULL, NULL, NULL, /* 115 - 117 */ | |
7546 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
7547 | }; |
7548 | ||
99f6fdd9 | 7549 | static void |
b129eb0e RH |
7550 | init_dwarf_regnames_x86_64 (void) |
7551 | { | |
7552 | dwarf_regnames = dwarf_regnames_x86_64; | |
7553 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
1296bc99 | 7554 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
7555 | } |
7556 | ||
4ee22035 RH |
7557 | static const char *const dwarf_regnames_aarch64[] = |
7558 | { | |
b4eb7656 AM |
7559 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
7560 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
7561 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
7562 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
7563 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
fab7c86e TC |
7564 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
7565 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", | |
7566 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", | |
b4eb7656 AM |
7567 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
7568 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
7569 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
7570 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
fab7c86e TC |
7571 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
7572 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", | |
7573 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", | |
7574 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", | |
fa6ca5e2 SP |
7575 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
7576 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7577 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7578 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7579 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7580 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7581 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7582 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7583 | NULL, NULL, NULL, NULL, NULL, NULL, "c0", "c1", | |
7584 | "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", | |
7585 | "c10", "c11", "c12", "c13", "c14", "c15", "c16", "c17", | |
7586 | "c18", "c19", "c20", "c21", "c22", "c23", "c24", "c25", | |
7587 | "c26", "c27", "c28", "c29", "c30", "csp", NULL, "ddc", | |
4ee22035 RH |
7588 | }; |
7589 | ||
99f6fdd9 | 7590 | static void |
4ee22035 RH |
7591 | init_dwarf_regnames_aarch64 (void) |
7592 | { | |
7593 | dwarf_regnames = dwarf_regnames_aarch64; | |
7594 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
1296bc99 | 7595 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
4ee22035 RH |
7596 | } |
7597 | ||
d6bb17b0 AA |
7598 | static const char *const dwarf_regnames_s390[] = |
7599 | { | |
7600 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
7601 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7602 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7603 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
7604 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
7605 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
7606 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
7607 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
7608 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
7609 | "pswm", "pswa", | |
7610 | NULL, NULL, | |
7611 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
7612 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
7613 | }; | |
7614 | ||
99f6fdd9 | 7615 | static void |
d6bb17b0 AA |
7616 | init_dwarf_regnames_s390 (void) |
7617 | { | |
7618 | dwarf_regnames = dwarf_regnames_s390; | |
7619 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
1296bc99 | 7620 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
d6bb17b0 AA |
7621 | } |
7622 | ||
5bb0830d AB |
7623 | static const char *const dwarf_regnames_riscv[] = |
7624 | { | |
7625 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
7626 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
7627 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
7628 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
7629 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
7630 | "fs0", "fs1", /* 40 - 41 */ | |
7631 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
7632 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
7633 | "fs10", "fs11", /* 58 - 59 */ | |
7634 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
7635 | }; | |
7636 | ||
4762fe62 AB |
7637 | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles |
7638 | the large number of CSRs. */ | |
7639 | ||
7640 | static const char * | |
7641 | regname_internal_riscv (unsigned int regno) | |
7642 | { | |
7643 | const char *name = NULL; | |
7644 | ||
7645 | /* Lookup in the table first, this covers GPR and FPR. */ | |
7646 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) | |
7647 | name = dwarf_regnames_riscv [regno]; | |
7648 | else if (regno >= 4096 && regno <= 8191) | |
7649 | { | |
7650 | /* This might be a CSR, these live in a sparse number space from 4096 | |
7651 | to 8191 These numbers are defined in the RISC-V ELF ABI | |
7652 | document. */ | |
7653 | switch (regno) | |
7654 | { | |
8f595e9b NC |
7655 | #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \ |
7656 | case VALUE + 4096: name = #NAME; break; | |
4762fe62 AB |
7657 | #include "opcode/riscv-opc.h" |
7658 | #undef DECLARE_CSR | |
7659 | ||
7660 | default: | |
7661 | { | |
7662 | static char csr_name[10]; | |
7663 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); | |
7664 | name = csr_name; | |
7665 | } | |
7666 | break; | |
7667 | } | |
7668 | } | |
7669 | ||
7670 | return name; | |
7671 | } | |
7672 | ||
99f6fdd9 | 7673 | static void |
5bb0830d AB |
7674 | init_dwarf_regnames_riscv (void) |
7675 | { | |
4762fe62 AB |
7676 | dwarf_regnames = NULL; |
7677 | dwarf_regnames_count = 8192; | |
7678 | dwarf_regnames_lookup_func = regname_internal_riscv; | |
5bb0830d AB |
7679 | } |
7680 | ||
2dc4cec1 | 7681 | void |
955ff7fc | 7682 | init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) |
2dc4cec1 | 7683 | { |
1296bc99 AB |
7684 | dwarf_regnames_lookup_func = NULL; |
7685 | ||
2dc4cec1 L |
7686 | switch (e_machine) |
7687 | { | |
7688 | case EM_386: | |
b129eb0e | 7689 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
7690 | break; |
7691 | ||
3d875af5 L |
7692 | case EM_IAMCU: |
7693 | init_dwarf_regnames_iamcu (); | |
7694 | break; | |
7695 | ||
2dc4cec1 | 7696 | case EM_X86_64: |
7f502d6c | 7697 | case EM_L1OM: |
7a9068fe | 7698 | case EM_K1OM: |
b129eb0e | 7699 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
7700 | break; |
7701 | ||
4ee22035 RH |
7702 | case EM_AARCH64: |
7703 | init_dwarf_regnames_aarch64 (); | |
7704 | break; | |
7705 | ||
d6bb17b0 AA |
7706 | case EM_S390: |
7707 | init_dwarf_regnames_s390 (); | |
7708 | break; | |
7709 | ||
5bb0830d AB |
7710 | case EM_RISCV: |
7711 | init_dwarf_regnames_riscv (); | |
7712 | break; | |
7713 | ||
2dc4cec1 L |
7714 | default: |
7715 | break; | |
7716 | } | |
7717 | } | |
7718 | ||
229a22cf AB |
7719 | /* Initialize the DWARF register name lookup state based on the |
7720 | architecture and specific machine type of a BFD. */ | |
7721 | ||
7722 | void | |
7723 | init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, | |
7724 | unsigned long mach) | |
7725 | { | |
1296bc99 AB |
7726 | dwarf_regnames_lookup_func = NULL; |
7727 | ||
229a22cf AB |
7728 | switch (arch) |
7729 | { | |
7730 | case bfd_arch_i386: | |
7731 | switch (mach) | |
7732 | { | |
7733 | case bfd_mach_x86_64: | |
7734 | case bfd_mach_x86_64_intel_syntax: | |
229a22cf AB |
7735 | case bfd_mach_x64_32: |
7736 | case bfd_mach_x64_32_intel_syntax: | |
229a22cf AB |
7737 | init_dwarf_regnames_x86_64 (); |
7738 | break; | |
7739 | ||
7740 | default: | |
7741 | init_dwarf_regnames_i386 (); | |
7742 | break; | |
7743 | } | |
7744 | break; | |
7745 | ||
7746 | case bfd_arch_iamcu: | |
7747 | init_dwarf_regnames_iamcu (); | |
7748 | break; | |
7749 | ||
7750 | case bfd_arch_aarch64: | |
7751 | init_dwarf_regnames_aarch64(); | |
7752 | break; | |
7753 | ||
7754 | case bfd_arch_s390: | |
7755 | init_dwarf_regnames_s390 (); | |
7756 | break; | |
7757 | ||
7758 | case bfd_arch_riscv: | |
7759 | init_dwarf_regnames_riscv (); | |
7760 | break; | |
7761 | ||
7762 | default: | |
7763 | break; | |
7764 | } | |
7765 | } | |
7766 | ||
2dc4cec1 | 7767 | static const char * |
1296bc99 | 7768 | regname_internal_by_table_only (unsigned int regno) |
2dc4cec1 | 7769 | { |
1296bc99 | 7770 | if (dwarf_regnames != NULL |
2dc4cec1 L |
7771 | && regno < dwarf_regnames_count |
7772 | && dwarf_regnames [regno] != NULL) | |
1296bc99 AB |
7773 | return dwarf_regnames [regno]; |
7774 | ||
7775 | return NULL; | |
7776 | } | |
7777 | ||
7778 | static const char * | |
7779 | regname (unsigned int regno, int name_only_p) | |
7780 | { | |
7781 | static char reg[64]; | |
7782 | ||
7783 | const char *name = NULL; | |
7784 | ||
7785 | if (dwarf_regnames_lookup_func != NULL) | |
7786 | name = dwarf_regnames_lookup_func (regno); | |
7787 | ||
7788 | if (name != NULL) | |
2dc4cec1 | 7789 | { |
1296bc99 AB |
7790 | if (name_only_p) |
7791 | return name; | |
7792 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); | |
2dc4cec1 L |
7793 | } |
7794 | else | |
7795 | snprintf (reg, sizeof (reg), "r%d", regno); | |
7796 | return reg; | |
7797 | } | |
7798 | ||
19e6b90e | 7799 | static void |
a1165289 | 7800 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 7801 | { |
a1165289 | 7802 | unsigned int r; |
19e6b90e L |
7803 | char tmp[100]; |
7804 | ||
d8024a91 | 7805 | if (*max_regs != fc->ncols) |
19e6b90e L |
7806 | *max_regs = fc->ncols; |
7807 | ||
7808 | if (*need_col_headers) | |
7809 | { | |
91d6fa6a | 7810 | static const char *sloc = " LOC"; |
2dc4cec1 | 7811 | |
19e6b90e L |
7812 | *need_col_headers = 0; |
7813 | ||
91d6fa6a | 7814 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
7815 | |
7816 | for (r = 0; r < *max_regs; r++) | |
7817 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7818 | { | |
7819 | if (r == fc->ra) | |
50751e18 | 7820 | printf ("ra "); |
19e6b90e | 7821 | else |
2dc4cec1 | 7822 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
7823 | } |
7824 | ||
7825 | printf ("\n"); | |
7826 | } | |
7827 | ||
bf5117e3 | 7828 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
7829 | if (fc->cfa_exp) |
7830 | strcpy (tmp, "exp"); | |
7831 | else | |
c8071705 | 7832 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
7833 | printf ("%-8s ", tmp); |
7834 | ||
7835 | for (r = 0; r < fc->ncols; r++) | |
7836 | { | |
7837 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7838 | { | |
7839 | switch (fc->col_type[r]) | |
7840 | { | |
7841 | case DW_CFA_undefined: | |
7842 | strcpy (tmp, "u"); | |
7843 | break; | |
7844 | case DW_CFA_same_value: | |
7845 | strcpy (tmp, "s"); | |
7846 | break; | |
7847 | case DW_CFA_offset: | |
7848 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
7849 | break; | |
12eae2d3 JJ |
7850 | case DW_CFA_val_offset: |
7851 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
7852 | break; | |
19e6b90e | 7853 | case DW_CFA_register: |
2dc4cec1 | 7854 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
7855 | break; |
7856 | case DW_CFA_expression: | |
7857 | strcpy (tmp, "exp"); | |
7858 | break; | |
12eae2d3 JJ |
7859 | case DW_CFA_val_expression: |
7860 | strcpy (tmp, "vexp"); | |
7861 | break; | |
19e6b90e L |
7862 | default: |
7863 | strcpy (tmp, "n/a"); | |
7864 | break; | |
7865 | } | |
2dc4cec1 | 7866 | printf ("%-5s ", tmp); |
19e6b90e L |
7867 | } |
7868 | } | |
7869 | printf ("\n"); | |
7870 | } | |
7871 | ||
49727e46 | 7872 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 7873 | |
49727e46 AM |
7874 | static unsigned char * |
7875 | read_cie (unsigned char *start, unsigned char *end, | |
7876 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 7877 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
7878 | { |
7879 | int version; | |
7880 | Frame_Chunk *fc; | |
49727e46 | 7881 | unsigned char *augmentation_data = NULL; |
bf59c5d5 | 7882 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 7883 | |
041830e0 | 7884 | * p_cie = NULL; |
f41e4712 NC |
7885 | /* PR 17512: file: 001-228113-0.004. */ |
7886 | if (start >= end) | |
7887 | return end; | |
7888 | ||
49727e46 AM |
7889 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
7890 | memset (fc, 0, sizeof (Frame_Chunk)); | |
7891 | ||
7892 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
7893 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
7894 | ||
7895 | version = *start++; | |
7896 | ||
7897 | fc->augmentation = (char *) start; | |
f41e4712 NC |
7898 | /* PR 17512: file: 001-228113-0.004. |
7899 | Skip past augmentation name, but avoid running off the end of the data. */ | |
7900 | while (start < end) | |
7901 | if (* start ++ == '\0') | |
7902 | break; | |
7903 | if (start == end) | |
7904 | { | |
7905 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 7906 | goto fail; |
f41e4712 | 7907 | } |
49727e46 AM |
7908 | |
7909 | if (strcmp (fc->augmentation, "eh") == 0) | |
7910 | start += eh_addr_size; | |
7911 | ||
7912 | if (version >= 4) | |
7913 | { | |
7914 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
7915 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
7916 | { | |
7917 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 7918 | goto fail; |
77ef8654 NC |
7919 | } |
7920 | ||
49727e46 | 7921 | GET (fc->segment_size, 1); |
77ef8654 NC |
7922 | /* PR 17512: file: e99d2804. */ |
7923 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
7924 | { | |
7925 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 7926 | goto fail; |
77ef8654 NC |
7927 | } |
7928 | ||
49727e46 AM |
7929 | eh_addr_size = fc->ptr_size; |
7930 | } | |
7931 | else | |
7932 | { | |
7933 | fc->ptr_size = eh_addr_size; | |
7934 | fc->segment_size = 0; | |
7935 | } | |
442a6ce8 | 7936 | |
cd30bcef AM |
7937 | READ_ULEB (fc->code_factor, start, end); |
7938 | READ_SLEB (fc->data_factor, start, end); | |
442a6ce8 | 7939 | |
49727e46 AM |
7940 | if (version == 1) |
7941 | { | |
7942 | GET (fc->ra, 1); | |
7943 | } | |
7944 | else | |
7945 | { | |
cd30bcef | 7946 | READ_ULEB (fc->ra, start, end); |
49727e46 AM |
7947 | } |
7948 | ||
7949 | if (fc->augmentation[0] == 'z') | |
7950 | { | |
cd30bcef | 7951 | READ_ULEB (augmentation_data_len, start, end); |
49727e46 | 7952 | augmentation_data = start; |
a1165289 | 7953 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 7954 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 7955 | { |
bf59c5d5 NC |
7956 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
7957 | dwarf_vmatoa ("x", augmentation_data_len), | |
7958 | (unsigned long) (end - start)); | |
442a6ce8 | 7959 | goto fail; |
a1165289 | 7960 | } |
9c0f3d3f | 7961 | start += augmentation_data_len; |
49727e46 AM |
7962 | } |
7963 | ||
7964 | if (augmentation_data_len) | |
7965 | { | |
058037d3 NC |
7966 | unsigned char *p; |
7967 | unsigned char *q; | |
7968 | unsigned char *qend; | |
b4eb7656 | 7969 | |
49727e46 AM |
7970 | p = (unsigned char *) fc->augmentation + 1; |
7971 | q = augmentation_data; | |
058037d3 NC |
7972 | qend = q + augmentation_data_len; |
7973 | ||
9c0f3d3f | 7974 | while (p < end && q < qend) |
49727e46 AM |
7975 | { |
7976 | if (*p == 'L') | |
7977 | q++; | |
7978 | else if (*p == 'P') | |
7979 | q += 1 + size_of_encoded_value (*q); | |
7980 | else if (*p == 'R') | |
7981 | fc->fde_encoding = *q++; | |
7982 | else if (*p == 'S') | |
7983 | ; | |
09038062 ST |
7984 | else if (*p == 'B') |
7985 | ; | |
49727e46 AM |
7986 | else |
7987 | break; | |
7988 | p++; | |
7989 | } | |
c361b9ac NC |
7990 | /* Note - it is OK if this loop terminates with q < qend. |
7991 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
7992 | } |
7993 | ||
7994 | *p_cie = fc; | |
7995 | if (p_version) | |
7996 | *p_version = version; | |
7997 | if (p_aug_len) | |
7998 | { | |
7999 | *p_aug_len = augmentation_data_len; | |
8000 | *p_aug = augmentation_data; | |
8001 | } | |
8002 | return start; | |
442a6ce8 NC |
8003 | |
8004 | fail: | |
8005 | free (fc->col_offset); | |
8006 | free (fc->col_type); | |
8007 | free (fc); | |
8008 | return end; | |
49727e46 AM |
8009 | } |
8010 | ||
d85bf2ba NC |
8011 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
8012 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
8013 | PRINTED contains the number of characters already written to the current | |
8014 | output line. */ | |
bf59c5d5 NC |
8015 | |
8016 | static void | |
d85bf2ba NC |
8017 | display_data (bfd_size_type printed, |
8018 | const unsigned char * data, | |
8019 | const bfd_size_type len) | |
bf59c5d5 | 8020 | { |
d85bf2ba NC |
8021 | if (do_wide || len < ((80 - printed) / 3)) |
8022 | for (printed = 0; printed < len; ++printed) | |
8023 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
8024 | else |
8025 | { | |
d85bf2ba | 8026 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 8027 | { |
d85bf2ba | 8028 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 8029 | putchar ('\n'); |
d85bf2ba | 8030 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
8031 | } |
8032 | } | |
d85bf2ba NC |
8033 | } |
8034 | ||
8035 | /* Prints out the contents on the augmentation data array. | |
8036 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
8037 | ||
8038 | static void | |
8039 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
8040 | { | |
8041 | bfd_size_type i; | |
8042 | ||
8043 | i = printf (_(" Augmentation data: ")); | |
8044 | display_data (i, data, len); | |
bf59c5d5 NC |
8045 | } |
8046 | ||
19e6b90e L |
8047 | static int |
8048 | display_debug_frames (struct dwarf_section *section, | |
8049 | void *file ATTRIBUTE_UNUSED) | |
8050 | { | |
8051 | unsigned char *start = section->start; | |
8052 | unsigned char *end = start + section->size; | |
8053 | unsigned char *section_start = start; | |
3391569f NC |
8054 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
8055 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 8056 | Frame_Chunk *rs; |
3391569f | 8057 | bfd_boolean is_eh = strcmp (section->name, ".eh_frame") == 0; |
a1165289 | 8058 | unsigned int max_regs = 0; |
665ce1f6 | 8059 | const char *bad_reg = _("bad register: "); |
77ef8654 | 8060 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 8061 | |
dda8d76d | 8062 | introduce (section, FALSE); |
19e6b90e L |
8063 | |
8064 | while (start < end) | |
8065 | { | |
8066 | unsigned char *saved_start; | |
8067 | unsigned char *block_end; | |
bf5117e3 NC |
8068 | dwarf_vma length; |
8069 | dwarf_vma cie_id; | |
19e6b90e L |
8070 | Frame_Chunk *fc; |
8071 | Frame_Chunk *cie; | |
8072 | int need_col_headers = 1; | |
8073 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 8074 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
8075 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
8076 | unsigned int offset_size; | |
8077 | unsigned int initial_length_size; | |
5b6312fd | 8078 | bfd_boolean all_nops; |
a788aedd | 8079 | static Frame_Chunk fde_fc; |
19e6b90e L |
8080 | |
8081 | saved_start = start; | |
19e6b90e | 8082 | |
0c588247 | 8083 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 8084 | |
19e6b90e L |
8085 | if (length == 0) |
8086 | { | |
8087 | printf ("\n%08lx ZERO terminator\n\n", | |
8088 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
8089 | /* Skip any zero terminators that directly follow. |
8090 | A corrupt section size could have loaded a whole | |
8091 | slew of zero filled memory bytes. eg | |
8092 | PR 17512: file: 070-19381-0.004. */ | |
8093 | while (start < end && * start == 0) | |
8094 | ++ start; | |
b758e50f | 8095 | continue; |
19e6b90e L |
8096 | } |
8097 | ||
8098 | if (length == 0xffffffff) | |
8099 | { | |
0c588247 | 8100 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
8101 | offset_size = 8; |
8102 | initial_length_size = 12; | |
8103 | } | |
8104 | else | |
8105 | { | |
8106 | offset_size = 4; | |
8107 | initial_length_size = 4; | |
8108 | } | |
8109 | ||
8110 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 8111 | if (block_end > end || block_end < start) |
53b8873b | 8112 | { |
bf5117e3 NC |
8113 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
8114 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
8115 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
8116 | block_end = end; |
8117 | } | |
0c588247 NC |
8118 | |
8119 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 8120 | |
846a11e4 NC |
8121 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
8122 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
8123 | { |
8124 | int version; | |
a1165289 | 8125 | unsigned int mreg; |
19e6b90e | 8126 | |
49727e46 AM |
8127 | start = read_cie (start, end, &cie, &version, |
8128 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
8129 | /* PR 17512: file: 027-135133-0.005. */ |
8130 | if (cie == NULL) | |
8131 | break; | |
a1165289 | 8132 | |
49727e46 | 8133 | fc = cie; |
19e6b90e L |
8134 | fc->next = chunks; |
8135 | chunks = fc; | |
8136 | fc->chunk_start = saved_start; | |
a1165289 | 8137 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8138 | if (mreg < fc->ra) |
8139 | mreg = fc->ra; | |
06614111 NC |
8140 | if (frame_need_space (fc, mreg) < 0) |
8141 | break; | |
49727e46 AM |
8142 | if (fc->fde_encoding) |
8143 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 8144 | |
bf5117e3 NC |
8145 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
8146 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 8147 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 8148 | |
19e6b90e | 8149 | if (do_debug_frames_interp) |
bf5117e3 NC |
8150 | { |
8151 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
8152 | fc->code_factor, fc->data_factor, fc->ra); | |
8153 | } | |
19e6b90e L |
8154 | else |
8155 | { | |
bf5117e3 | 8156 | printf ("CIE\n"); |
19e6b90e L |
8157 | printf (" Version: %d\n", version); |
8158 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
8159 | if (version >= 4) |
8160 | { | |
8161 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
8162 | printf (" Segment Size: %u\n", fc->segment_size); | |
8163 | } | |
19e6b90e L |
8164 | printf (" Code alignment factor: %u\n", fc->code_factor); |
8165 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
8166 | printf (" Return address column: %d\n", fc->ra); | |
8167 | ||
8168 | if (augmentation_data_len) | |
bf59c5d5 | 8169 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 8170 | |
19e6b90e L |
8171 | putchar ('\n'); |
8172 | } | |
19e6b90e L |
8173 | } |
8174 | else | |
8175 | { | |
8176 | unsigned char *look_for; | |
604282a7 | 8177 | unsigned long segment_selector; |
19e6b90e | 8178 | |
49727e46 AM |
8179 | if (is_eh) |
8180 | { | |
8181 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
8182 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
8183 | } | |
8184 | else | |
8185 | look_for = section_start + cie_id; | |
19e6b90e | 8186 | |
49727e46 AM |
8187 | if (look_for <= saved_start) |
8188 | { | |
8189 | for (cie = chunks; cie ; cie = cie->next) | |
8190 | if (cie->chunk_start == look_for) | |
8191 | break; | |
8192 | } | |
8193 | else | |
8194 | { | |
8195 | for (cie = forward_refs; cie ; cie = cie->next) | |
8196 | if (cie->chunk_start == look_for) | |
8197 | break; | |
8198 | if (!cie) | |
8199 | { | |
8200 | unsigned int off_size; | |
8201 | unsigned char *cie_scan; | |
19e6b90e | 8202 | |
49727e46 AM |
8203 | cie_scan = look_for; |
8204 | off_size = 4; | |
8205 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
8206 | if (length == 0xffffffff) | |
8207 | { | |
8208 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
8209 | off_size = 8; | |
8210 | } | |
8211 | if (length != 0) | |
8212 | { | |
8213 | dwarf_vma c_id; | |
8214 | ||
8215 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
8216 | if (is_eh | |
8217 | ? c_id == 0 | |
8218 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
8219 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
8220 | { | |
8221 | int version; | |
a1165289 | 8222 | unsigned int mreg; |
49727e46 AM |
8223 | |
8224 | read_cie (cie_scan, end, &cie, &version, | |
8225 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
8226 | /* PR 17512: file: 3450-2098-0.004. */ |
8227 | if (cie == NULL) | |
8228 | { | |
8229 | warn (_("Failed to read CIE information\n")); | |
8230 | break; | |
8231 | } | |
49727e46 AM |
8232 | cie->next = forward_refs; |
8233 | forward_refs = cie; | |
8234 | cie->chunk_start = look_for; | |
a1165289 | 8235 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8236 | if (mreg < cie->ra) |
8237 | mreg = cie->ra; | |
06614111 NC |
8238 | if (frame_need_space (cie, mreg) < 0) |
8239 | { | |
8240 | warn (_("Invalid max register\n")); | |
8241 | break; | |
8242 | } | |
49727e46 AM |
8243 | if (cie->fde_encoding) |
8244 | encoded_ptr_size | |
8245 | = size_of_encoded_value (cie->fde_encoding); | |
8246 | } | |
8247 | } | |
8248 | } | |
8249 | } | |
8250 | ||
8251 | fc = &fde_fc; | |
8252 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
8253 | |
8254 | if (!cie) | |
8255 | { | |
bf5117e3 NC |
8256 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
8257 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
8258 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 8259 | fc->ncols = 0; |
3f5e193b NC |
8260 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
8261 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
8262 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
8263 | { | |
8264 | warn (_("Invalid max register\n")); | |
8265 | break; | |
8266 | } | |
19e6b90e L |
8267 | cie = fc; |
8268 | fc->augmentation = ""; | |
8269 | fc->fde_encoding = 0; | |
604282a7 JJ |
8270 | fc->ptr_size = eh_addr_size; |
8271 | fc->segment_size = 0; | |
19e6b90e L |
8272 | } |
8273 | else | |
8274 | { | |
8275 | fc->ncols = cie->ncols; | |
3f5e193b NC |
8276 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
8277 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
8278 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
8279 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
8280 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
8281 | fc->ptr_size = cie->ptr_size; |
8282 | eh_addr_size = cie->ptr_size; | |
8283 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
8284 | fc->code_factor = cie->code_factor; |
8285 | fc->data_factor = cie->data_factor; | |
8286 | fc->cfa_reg = cie->cfa_reg; | |
8287 | fc->cfa_offset = cie->cfa_offset; | |
8288 | fc->ra = cie->ra; | |
06614111 NC |
8289 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
8290 | { | |
8291 | warn (_("Invalid max register\n")); | |
8292 | break; | |
8293 | } | |
19e6b90e L |
8294 | fc->fde_encoding = cie->fde_encoding; |
8295 | } | |
8296 | ||
8297 | if (fc->fde_encoding) | |
8298 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
8299 | ||
604282a7 JJ |
8300 | segment_selector = 0; |
8301 | if (fc->segment_size) | |
c8071705 NC |
8302 | { |
8303 | if (fc->segment_size > sizeof (segment_selector)) | |
8304 | { | |
8305 | /* PR 17512: file: 9e196b3e. */ | |
8306 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
8307 | fc->segment_size = 4; | |
8308 | } | |
8309 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
8310 | } | |
041830e0 NC |
8311 | |
8312 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 8313 | |
0c588247 NC |
8314 | /* FIXME: It appears that sometimes the final pc_range value is |
8315 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
8316 | run of the "objcopy on compressed debug sections" test for an | |
8317 | example of this. */ | |
8318 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 8319 | |
19e6b90e L |
8320 | if (cie->augmentation[0] == 'z') |
8321 | { | |
cd30bcef | 8322 | READ_ULEB (augmentation_data_len, start, end); |
19e6b90e | 8323 | augmentation_data = start; |
bf59c5d5 | 8324 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
d292364e | 8325 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
0a9d414a | 8326 | { |
d292364e AM |
8327 | warn (_("Augmentation data too long: 0x%s, " |
8328 | "expected at most %#lx\n"), | |
8329 | dwarf_vmatoa ("x", augmentation_data_len), | |
8330 | (unsigned long) (end - start)); | |
0a9d414a NC |
8331 | start = end; |
8332 | augmentation_data = NULL; | |
8333 | augmentation_data_len = 0; | |
8334 | } | |
d292364e | 8335 | start += augmentation_data_len; |
19e6b90e L |
8336 | } |
8337 | ||
bf5117e3 NC |
8338 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
8339 | (unsigned long)(saved_start - section_start), | |
8340 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 8341 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 8342 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 8343 | |
604282a7 JJ |
8344 | if (fc->segment_size) |
8345 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
8346 | |
8347 | printf ("%s..%s\n", | |
8348 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
8349 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
8350 | ||
19e6b90e L |
8351 | if (! do_debug_frames_interp && augmentation_data_len) |
8352 | { | |
bf59c5d5 | 8353 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
8354 | putchar ('\n'); |
8355 | } | |
8356 | } | |
8357 | ||
8358 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
8359 | we're about to interpret instructions for the chunk. */ | |
8360 | /* ??? At present we need to do this always, since this sizes the | |
8361 | fc->col_type and fc->col_offset arrays, which we write into always. | |
8362 | We should probably split the interpreted and non-interpreted bits | |
8363 | into two different routines, since there's so much that doesn't | |
8364 | really overlap between them. */ | |
8365 | if (1 || do_debug_frames_interp) | |
8366 | { | |
8367 | /* Start by making a pass over the chunk, allocating storage | |
8368 | and taking note of what registers are used. */ | |
8369 | unsigned char *tmp = start; | |
8370 | ||
8371 | while (start < block_end) | |
8372 | { | |
041830e0 NC |
8373 | unsigned int reg, op, opa; |
8374 | unsigned long temp; | |
5929c344 | 8375 | unsigned char * new_start; |
19e6b90e L |
8376 | |
8377 | op = *start++; | |
8378 | opa = op & 0x3f; | |
8379 | if (op & 0xc0) | |
8380 | op &= 0xc0; | |
8381 | ||
8382 | /* Warning: if you add any more cases to this switch, be | |
8383 | sure to add them to the corresponding switch below. */ | |
8384 | switch (op) | |
8385 | { | |
8386 | case DW_CFA_advance_loc: | |
8387 | break; | |
8388 | case DW_CFA_offset: | |
cd30bcef | 8389 | SKIP_ULEB (start, end); |
665ce1f6 L |
8390 | if (frame_need_space (fc, opa) >= 0) |
8391 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8392 | break; |
8393 | case DW_CFA_restore: | |
665ce1f6 L |
8394 | if (frame_need_space (fc, opa) >= 0) |
8395 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8396 | break; |
8397 | case DW_CFA_set_loc: | |
8398 | start += encoded_ptr_size; | |
8399 | break; | |
8400 | case DW_CFA_advance_loc1: | |
8401 | start += 1; | |
8402 | break; | |
8403 | case DW_CFA_advance_loc2: | |
8404 | start += 2; | |
8405 | break; | |
8406 | case DW_CFA_advance_loc4: | |
8407 | start += 4; | |
8408 | break; | |
8409 | case DW_CFA_offset_extended: | |
12eae2d3 | 8410 | case DW_CFA_val_offset: |
cd30bcef AM |
8411 | READ_ULEB (reg, start, end); |
8412 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8413 | if (frame_need_space (fc, reg) >= 0) |
8414 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8415 | break; |
8416 | case DW_CFA_restore_extended: | |
cd30bcef | 8417 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8418 | if (frame_need_space (fc, reg) >= 0) |
8419 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8420 | break; |
8421 | case DW_CFA_undefined: | |
cd30bcef | 8422 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8423 | if (frame_need_space (fc, reg) >= 0) |
8424 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8425 | break; |
8426 | case DW_CFA_same_value: | |
cd30bcef | 8427 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8428 | if (frame_need_space (fc, reg) >= 0) |
8429 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8430 | break; |
8431 | case DW_CFA_register: | |
cd30bcef AM |
8432 | READ_ULEB (reg, start, end); |
8433 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8434 | if (frame_need_space (fc, reg) >= 0) |
8435 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8436 | break; |
8437 | case DW_CFA_def_cfa: | |
cd30bcef AM |
8438 | SKIP_ULEB (start, end); |
8439 | SKIP_ULEB (start, end); | |
19e6b90e L |
8440 | break; |
8441 | case DW_CFA_def_cfa_register: | |
cd30bcef | 8442 | SKIP_ULEB (start, end); |
19e6b90e L |
8443 | break; |
8444 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 8445 | SKIP_ULEB (start, end); |
19e6b90e L |
8446 | break; |
8447 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 8448 | READ_ULEB (temp, start, end); |
5929c344 NC |
8449 | new_start = start + temp; |
8450 | if (new_start < start) | |
041830e0 NC |
8451 | { |
8452 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
8453 | start = block_end; | |
8454 | } | |
8455 | else | |
5929c344 | 8456 | start = new_start; |
19e6b90e L |
8457 | break; |
8458 | case DW_CFA_expression: | |
12eae2d3 | 8459 | case DW_CFA_val_expression: |
cd30bcef AM |
8460 | READ_ULEB (reg, start, end); |
8461 | READ_ULEB (temp, start, end); | |
5929c344 NC |
8462 | new_start = start + temp; |
8463 | if (new_start < start) | |
041830e0 | 8464 | { |
b4eb7656 | 8465 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
8466 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
8467 | start = block_end; | |
8468 | } | |
8469 | else | |
5929c344 | 8470 | start = new_start; |
665ce1f6 L |
8471 | if (frame_need_space (fc, reg) >= 0) |
8472 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8473 | break; |
8474 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 8475 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
8476 | READ_ULEB (reg, start, end); |
8477 | SKIP_SLEB (start, end); | |
665ce1f6 L |
8478 | if (frame_need_space (fc, reg) >= 0) |
8479 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8480 | break; |
8481 | case DW_CFA_def_cfa_sf: | |
cd30bcef AM |
8482 | SKIP_ULEB (start, end); |
8483 | SKIP_SLEB (start, end); | |
19e6b90e L |
8484 | break; |
8485 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 8486 | SKIP_SLEB (start, end); |
19e6b90e L |
8487 | break; |
8488 | case DW_CFA_MIPS_advance_loc8: | |
8489 | start += 8; | |
8490 | break; | |
8491 | case DW_CFA_GNU_args_size: | |
cd30bcef | 8492 | SKIP_ULEB (start, end); |
19e6b90e L |
8493 | break; |
8494 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
8495 | READ_ULEB (reg, start, end); |
8496 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8497 | if (frame_need_space (fc, reg) >= 0) |
8498 | fc->col_type[reg] = DW_CFA_undefined; | |
8499 | break; | |
19e6b90e L |
8500 | default: |
8501 | break; | |
8502 | } | |
8503 | } | |
8504 | start = tmp; | |
8505 | } | |
8506 | ||
5b6312fd NC |
8507 | all_nops = TRUE; |
8508 | ||
19e6b90e L |
8509 | /* Now we know what registers are used, make a second pass over |
8510 | the chunk, this time actually printing out the info. */ | |
8511 | ||
8512 | while (start < block_end) | |
8513 | { | |
362beea4 | 8514 | unsigned char * tmp; |
19e6b90e | 8515 | unsigned op, opa; |
7f2c8a1d NC |
8516 | unsigned long ul, roffs; |
8517 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
8518 | are various functions, notably frame_space_needed() that assume that | |
8519 | reg is an unsigned int. */ | |
8520 | unsigned int reg; | |
8521 | dwarf_signed_vma l; | |
bf5117e3 | 8522 | dwarf_vma ofs; |
19e6b90e | 8523 | dwarf_vma vma; |
665ce1f6 | 8524 | const char *reg_prefix = ""; |
19e6b90e L |
8525 | |
8526 | op = *start++; | |
8527 | opa = op & 0x3f; | |
8528 | if (op & 0xc0) | |
8529 | op &= 0xc0; | |
8530 | ||
5b6312fd NC |
8531 | /* Make a note if something other than DW_CFA_nop happens. */ |
8532 | if (op != DW_CFA_nop) | |
8533 | all_nops = FALSE; | |
8534 | ||
19e6b90e L |
8535 | /* Warning: if you add any more cases to this switch, be |
8536 | sure to add them to the corresponding switch above. */ | |
8537 | switch (op) | |
8538 | { | |
8539 | case DW_CFA_advance_loc: | |
8540 | if (do_debug_frames_interp) | |
8541 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8542 | else | |
bf5117e3 | 8543 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 8544 | opa * fc->code_factor, |
b4eb7656 | 8545 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
8546 | fc->pc_begin + opa * fc->code_factor, |
8547 | fc->ptr_size)); | |
19e6b90e L |
8548 | fc->pc_begin += opa * fc->code_factor; |
8549 | break; | |
8550 | ||
8551 | case DW_CFA_offset: | |
cd30bcef | 8552 | READ_ULEB (roffs, start, end); |
665ce1f6 L |
8553 | if (opa >= (unsigned int) fc->ncols) |
8554 | reg_prefix = bad_reg; | |
8555 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8556 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
8557 | reg_prefix, regname (opa, 0), | |
8558 | roffs * fc->data_factor); | |
8559 | if (*reg_prefix == '\0') | |
8560 | { | |
8561 | fc->col_type[opa] = DW_CFA_offset; | |
8562 | fc->col_offset[opa] = roffs * fc->data_factor; | |
8563 | } | |
19e6b90e L |
8564 | break; |
8565 | ||
8566 | case DW_CFA_restore: | |
50751e18 | 8567 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
8568 | reg_prefix = bad_reg; |
8569 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8570 | printf (" DW_CFA_restore: %s%s\n", | |
8571 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
8572 | if (*reg_prefix != '\0') |
8573 | break; | |
8574 | ||
8575 | if (opa >= (unsigned int) cie->ncols | |
8576 | || (do_debug_frames_interp | |
8577 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
8578 | { | |
8579 | fc->col_type[opa] = DW_CFA_undefined; | |
8580 | fc->col_offset[opa] = 0; | |
8581 | } | |
8582 | else | |
665ce1f6 L |
8583 | { |
8584 | fc->col_type[opa] = cie->col_type[opa]; | |
8585 | fc->col_offset[opa] = cie->col_offset[opa]; | |
8586 | } | |
19e6b90e L |
8587 | break; |
8588 | ||
8589 | case DW_CFA_set_loc: | |
6937bb54 | 8590 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
8591 | if (do_debug_frames_interp) |
8592 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8593 | else | |
bf5117e3 NC |
8594 | printf (" DW_CFA_set_loc: %s\n", |
8595 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
8596 | fc->pc_begin = vma; |
8597 | break; | |
8598 | ||
8599 | case DW_CFA_advance_loc1: | |
0c588247 | 8600 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
8601 | if (do_debug_frames_interp) |
8602 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8603 | else | |
bf5117e3 NC |
8604 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
8605 | (unsigned long) (ofs * fc->code_factor), | |
8606 | dwarf_vmatoa_1 (NULL, | |
8607 | fc->pc_begin + ofs * fc->code_factor, | |
8608 | fc->ptr_size)); | |
19e6b90e L |
8609 | fc->pc_begin += ofs * fc->code_factor; |
8610 | break; | |
8611 | ||
8612 | case DW_CFA_advance_loc2: | |
6937bb54 | 8613 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
8614 | if (do_debug_frames_interp) |
8615 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8616 | else | |
bf5117e3 NC |
8617 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
8618 | (unsigned long) (ofs * fc->code_factor), | |
8619 | dwarf_vmatoa_1 (NULL, | |
8620 | fc->pc_begin + ofs * fc->code_factor, | |
8621 | fc->ptr_size)); | |
19e6b90e L |
8622 | fc->pc_begin += ofs * fc->code_factor; |
8623 | break; | |
8624 | ||
8625 | case DW_CFA_advance_loc4: | |
6937bb54 | 8626 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
8627 | if (do_debug_frames_interp) |
8628 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8629 | else | |
bf5117e3 NC |
8630 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
8631 | (unsigned long) (ofs * fc->code_factor), | |
8632 | dwarf_vmatoa_1 (NULL, | |
8633 | fc->pc_begin + ofs * fc->code_factor, | |
8634 | fc->ptr_size)); | |
19e6b90e L |
8635 | fc->pc_begin += ofs * fc->code_factor; |
8636 | break; | |
8637 | ||
8638 | case DW_CFA_offset_extended: | |
cd30bcef AM |
8639 | READ_ULEB (reg, start, end); |
8640 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
8641 | if (reg >= (unsigned int) fc->ncols) |
8642 | reg_prefix = bad_reg; | |
8643 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8644 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
8645 | reg_prefix, regname (reg, 0), | |
8646 | roffs * fc->data_factor); | |
8647 | if (*reg_prefix == '\0') | |
8648 | { | |
8649 | fc->col_type[reg] = DW_CFA_offset; | |
8650 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8651 | } | |
19e6b90e L |
8652 | break; |
8653 | ||
12eae2d3 | 8654 | case DW_CFA_val_offset: |
cd30bcef AM |
8655 | READ_ULEB (reg, start, end); |
8656 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
8657 | if (reg >= (unsigned int) fc->ncols) |
8658 | reg_prefix = bad_reg; | |
8659 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8660 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
8661 | reg_prefix, regname (reg, 0), |
8662 | roffs * fc->data_factor); | |
8663 | if (*reg_prefix == '\0') | |
8664 | { | |
8665 | fc->col_type[reg] = DW_CFA_val_offset; | |
8666 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8667 | } | |
12eae2d3 JJ |
8668 | break; |
8669 | ||
19e6b90e | 8670 | case DW_CFA_restore_extended: |
cd30bcef | 8671 | READ_ULEB (reg, start, end); |
50751e18 | 8672 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
8673 | reg_prefix = bad_reg; |
8674 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8675 | printf (" DW_CFA_restore_extended: %s%s\n", | |
8676 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
8677 | if (*reg_prefix != '\0') |
8678 | break; | |
8679 | ||
8680 | if (reg >= (unsigned int) cie->ncols) | |
8681 | { | |
8682 | fc->col_type[reg] = DW_CFA_undefined; | |
8683 | fc->col_offset[reg] = 0; | |
8684 | } | |
8685 | else | |
665ce1f6 L |
8686 | { |
8687 | fc->col_type[reg] = cie->col_type[reg]; | |
8688 | fc->col_offset[reg] = cie->col_offset[reg]; | |
8689 | } | |
19e6b90e L |
8690 | break; |
8691 | ||
8692 | case DW_CFA_undefined: | |
cd30bcef | 8693 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8694 | if (reg >= (unsigned int) fc->ncols) |
8695 | reg_prefix = bad_reg; | |
8696 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8697 | printf (" DW_CFA_undefined: %s%s\n", | |
8698 | reg_prefix, regname (reg, 0)); | |
8699 | if (*reg_prefix == '\0') | |
8700 | { | |
8701 | fc->col_type[reg] = DW_CFA_undefined; | |
8702 | fc->col_offset[reg] = 0; | |
8703 | } | |
19e6b90e L |
8704 | break; |
8705 | ||
8706 | case DW_CFA_same_value: | |
cd30bcef | 8707 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8708 | if (reg >= (unsigned int) fc->ncols) |
8709 | reg_prefix = bad_reg; | |
8710 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8711 | printf (" DW_CFA_same_value: %s%s\n", | |
8712 | reg_prefix, regname (reg, 0)); | |
8713 | if (*reg_prefix == '\0') | |
8714 | { | |
8715 | fc->col_type[reg] = DW_CFA_same_value; | |
8716 | fc->col_offset[reg] = 0; | |
8717 | } | |
19e6b90e L |
8718 | break; |
8719 | ||
8720 | case DW_CFA_register: | |
cd30bcef AM |
8721 | READ_ULEB (reg, start, end); |
8722 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
8723 | if (reg >= (unsigned int) fc->ncols) |
8724 | reg_prefix = bad_reg; | |
8725 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 8726 | { |
665ce1f6 L |
8727 | printf (" DW_CFA_register: %s%s in ", |
8728 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
8729 | puts (regname (roffs, 0)); |
8730 | } | |
665ce1f6 L |
8731 | if (*reg_prefix == '\0') |
8732 | { | |
8733 | fc->col_type[reg] = DW_CFA_register; | |
8734 | fc->col_offset[reg] = roffs; | |
8735 | } | |
19e6b90e L |
8736 | break; |
8737 | ||
8738 | case DW_CFA_remember_state: | |
8739 | if (! do_debug_frames_interp) | |
8740 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 8741 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 8742 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
8743 | rs->cfa_reg = fc->cfa_reg; |
8744 | rs->ra = fc->ra; | |
8745 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 8746 | rs->ncols = fc->ncols; |
3f5e193b | 8747 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 8748 | sizeof (* rs->col_type)); |
d71ad7fc RC |
8749 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
8750 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
8751 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
8752 | rs->next = remembered_state; |
8753 | remembered_state = rs; | |
8754 | break; | |
8755 | ||
8756 | case DW_CFA_restore_state: | |
8757 | if (! do_debug_frames_interp) | |
8758 | printf (" DW_CFA_restore_state\n"); | |
8759 | rs = remembered_state; | |
8760 | if (rs) | |
8761 | { | |
8762 | remembered_state = rs->next; | |
d71ad7fc RC |
8763 | fc->cfa_offset = rs->cfa_offset; |
8764 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
8765 | fc->ra = rs->ra; |
8766 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
8767 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
8768 | { | |
1306a742 | 8769 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
8770 | fc->ncols = 0; |
8771 | break; | |
8772 | } | |
d71ad7fc | 8773 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 8774 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 8775 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
8776 | free (rs->col_type); |
8777 | free (rs->col_offset); | |
8778 | free (rs); | |
8779 | } | |
8780 | else if (do_debug_frames_interp) | |
8781 | printf ("Mismatched DW_CFA_restore_state\n"); | |
8782 | break; | |
8783 | ||
8784 | case DW_CFA_def_cfa: | |
cd30bcef AM |
8785 | READ_ULEB (fc->cfa_reg, start, end); |
8786 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
8787 | fc->cfa_exp = 0; |
8788 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8789 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 8790 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8791 | break; |
8792 | ||
8793 | case DW_CFA_def_cfa_register: | |
cd30bcef | 8794 | READ_ULEB (fc->cfa_reg, start, end); |
19e6b90e L |
8795 | fc->cfa_exp = 0; |
8796 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
8797 | printf (" DW_CFA_def_cfa_register: %s\n", |
8798 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
8799 | break; |
8800 | ||
8801 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 8802 | READ_ULEB (fc->cfa_offset, start, end); |
19e6b90e | 8803 | if (! do_debug_frames_interp) |
c8071705 | 8804 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8805 | break; |
8806 | ||
8807 | case DW_CFA_nop: | |
8808 | if (! do_debug_frames_interp) | |
8809 | printf (" DW_CFA_nop\n"); | |
8810 | break; | |
8811 | ||
8812 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 8813 | READ_ULEB (ul, start, end); |
7460c0ab | 8814 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 8815 | { |
a1165289 | 8816 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8817 | break; |
8818 | } | |
19e6b90e L |
8819 | if (! do_debug_frames_interp) |
8820 | { | |
8821 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
8822 | decode_location_expression (start, eh_addr_size, 0, -1, |
8823 | ul, 0, section); | |
19e6b90e L |
8824 | printf (")\n"); |
8825 | } | |
8826 | fc->cfa_exp = 1; | |
8827 | start += ul; | |
8828 | break; | |
8829 | ||
8830 | case DW_CFA_expression: | |
cd30bcef AM |
8831 | READ_ULEB (reg, start, end); |
8832 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
8833 | if (reg >= (unsigned int) fc->ncols) |
8834 | reg_prefix = bad_reg; | |
6937bb54 | 8835 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 8836 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
8837 | tmp = start + ul; |
8838 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8839 | { |
a1165289 | 8840 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8841 | break; |
8842 | } | |
665ce1f6 | 8843 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 8844 | { |
665ce1f6 L |
8845 | printf (" DW_CFA_expression: %s%s (", |
8846 | reg_prefix, regname (reg, 0)); | |
b7807392 | 8847 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 8848 | ul, 0, section); |
19e6b90e L |
8849 | printf (")\n"); |
8850 | } | |
665ce1f6 L |
8851 | if (*reg_prefix == '\0') |
8852 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 8853 | start = tmp; |
19e6b90e L |
8854 | break; |
8855 | ||
12eae2d3 | 8856 | case DW_CFA_val_expression: |
cd30bcef AM |
8857 | READ_ULEB (reg, start, end); |
8858 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
8859 | if (reg >= (unsigned int) fc->ncols) |
8860 | reg_prefix = bad_reg; | |
362beea4 NC |
8861 | tmp = start + ul; |
8862 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8863 | { |
a1165289 | 8864 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
8865 | break; |
8866 | } | |
665ce1f6 | 8867 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 8868 | { |
665ce1f6 L |
8869 | printf (" DW_CFA_val_expression: %s%s (", |
8870 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
8871 | decode_location_expression (start, eh_addr_size, 0, -1, |
8872 | ul, 0, section); | |
12eae2d3 JJ |
8873 | printf (")\n"); |
8874 | } | |
665ce1f6 L |
8875 | if (*reg_prefix == '\0') |
8876 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 8877 | start = tmp; |
12eae2d3 JJ |
8878 | break; |
8879 | ||
19e6b90e | 8880 | case DW_CFA_offset_extended_sf: |
cd30bcef AM |
8881 | READ_ULEB (reg, start, end); |
8882 | READ_SLEB (l, start, end); | |
665ce1f6 L |
8883 | if (frame_need_space (fc, reg) < 0) |
8884 | reg_prefix = bad_reg; | |
8885 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8886 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
8887 | reg_prefix, regname (reg, 0), | |
c8071705 | 8888 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8889 | if (*reg_prefix == '\0') |
8890 | { | |
8891 | fc->col_type[reg] = DW_CFA_offset; | |
8892 | fc->col_offset[reg] = l * fc->data_factor; | |
8893 | } | |
19e6b90e L |
8894 | break; |
8895 | ||
12eae2d3 | 8896 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
8897 | READ_ULEB (reg, start, end); |
8898 | READ_SLEB (l, start, end); | |
665ce1f6 L |
8899 | if (frame_need_space (fc, reg) < 0) |
8900 | reg_prefix = bad_reg; | |
8901 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8902 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 8903 | reg_prefix, regname (reg, 0), |
c8071705 | 8904 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8905 | if (*reg_prefix == '\0') |
8906 | { | |
8907 | fc->col_type[reg] = DW_CFA_val_offset; | |
8908 | fc->col_offset[reg] = l * fc->data_factor; | |
8909 | } | |
12eae2d3 JJ |
8910 | break; |
8911 | ||
19e6b90e | 8912 | case DW_CFA_def_cfa_sf: |
cd30bcef AM |
8913 | READ_ULEB (fc->cfa_reg, start, end); |
8914 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
8915 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
8916 | fc->cfa_exp = 0; | |
8917 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8918 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 8919 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8920 | break; |
8921 | ||
8922 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 8923 | READ_ULEB (fc->cfa_offset, start, end); |
c8071705 | 8924 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 8925 | if (! do_debug_frames_interp) |
c8071705 | 8926 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8927 | break; |
8928 | ||
8929 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 8930 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
8931 | if (do_debug_frames_interp) |
8932 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8933 | else | |
bf5117e3 NC |
8934 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
8935 | (unsigned long) (ofs * fc->code_factor), | |
8936 | dwarf_vmatoa_1 (NULL, | |
8937 | fc->pc_begin + ofs * fc->code_factor, | |
8938 | fc->ptr_size)); | |
19e6b90e L |
8939 | fc->pc_begin += ofs * fc->code_factor; |
8940 | break; | |
8941 | ||
8942 | case DW_CFA_GNU_window_save: | |
8943 | if (! do_debug_frames_interp) | |
8944 | printf (" DW_CFA_GNU_window_save\n"); | |
8945 | break; | |
8946 | ||
8947 | case DW_CFA_GNU_args_size: | |
cd30bcef | 8948 | READ_ULEB (ul, start, end); |
19e6b90e L |
8949 | if (! do_debug_frames_interp) |
8950 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
8951 | break; | |
8952 | ||
8953 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
8954 | READ_ULEB (reg, start, end); |
8955 | READ_SLEB (l, start, end); | |
7f2c8a1d | 8956 | l = - l; |
665ce1f6 L |
8957 | if (frame_need_space (fc, reg) < 0) |
8958 | reg_prefix = bad_reg; | |
8959 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8960 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
8961 | reg_prefix, regname (reg, 0), | |
c8071705 | 8962 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8963 | if (*reg_prefix == '\0') |
8964 | { | |
8965 | fc->col_type[reg] = DW_CFA_offset; | |
8966 | fc->col_offset[reg] = l * fc->data_factor; | |
8967 | } | |
19e6b90e L |
8968 | break; |
8969 | ||
8970 | default: | |
53b8873b NC |
8971 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
8972 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
8973 | else | |
f41e4712 | 8974 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
8975 | start = block_end; |
8976 | } | |
8977 | } | |
8978 | ||
5b6312fd NC |
8979 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
8980 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
8981 | frame_display_row (fc, &need_col_headers, &max_regs); |
8982 | ||
a788aedd AM |
8983 | if (fde_fc.col_type != NULL) |
8984 | { | |
8985 | free (fde_fc.col_type); | |
8986 | fde_fc.col_type = NULL; | |
8987 | } | |
8988 | if (fde_fc.col_offset != NULL) | |
8989 | { | |
8990 | free (fde_fc.col_offset); | |
8991 | fde_fc.col_offset = NULL; | |
8992 | } | |
8993 | ||
19e6b90e | 8994 | start = block_end; |
604282a7 | 8995 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
8996 | } |
8997 | ||
8998 | printf ("\n"); | |
8999 | ||
3391569f NC |
9000 | while (remembered_state != NULL) |
9001 | { | |
9002 | rs = remembered_state; | |
9003 | remembered_state = rs->next; | |
9004 | free (rs->col_type); | |
9005 | free (rs->col_offset); | |
9006 | rs->next = NULL; /* Paranoia. */ | |
9007 | free (rs); | |
9008 | } | |
9009 | ||
9010 | while (chunks != NULL) | |
9011 | { | |
9012 | rs = chunks; | |
9013 | chunks = rs->next; | |
9014 | free (rs->col_type); | |
9015 | free (rs->col_offset); | |
9016 | rs->next = NULL; /* Paranoia. */ | |
9017 | free (rs); | |
9018 | } | |
9019 | ||
9020 | while (forward_refs != NULL) | |
9021 | { | |
9022 | rs = forward_refs; | |
9023 | forward_refs = rs->next; | |
9024 | free (rs->col_type); | |
9025 | free (rs->col_offset); | |
9026 | rs->next = NULL; /* Paranoia. */ | |
9027 | free (rs); | |
9028 | } | |
9029 | ||
19e6b90e L |
9030 | return 1; |
9031 | } | |
9032 | ||
9033 | #undef GET | |
19e6b90e | 9034 | |
61364358 JK |
9035 | static int |
9036 | display_debug_names (struct dwarf_section *section, void *file) | |
9037 | { | |
9038 | unsigned char *hdrptr = section->start; | |
9039 | dwarf_vma unit_length; | |
9040 | unsigned char *unit_start; | |
9041 | const unsigned char *const section_end = section->start + section->size; | |
9042 | unsigned char *unit_end; | |
9043 | ||
dda8d76d | 9044 | introduce (section, FALSE); |
61364358 | 9045 | |
dda8d76d | 9046 | load_debug_section_with_follow (str, file); |
61364358 JK |
9047 | |
9048 | for (; hdrptr < section_end; hdrptr = unit_end) | |
9049 | { | |
9050 | unsigned int offset_size; | |
9051 | uint16_t dwarf_version, padding; | |
9052 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
9053 | uint32_t bucket_count, name_count, abbrev_table_size; | |
9054 | uint32_t augmentation_string_size; | |
9055 | unsigned int i; | |
e98fdf1a | 9056 | unsigned long sec_off; |
48467cb9 TV |
9057 | bfd_boolean augmentation_printable; |
9058 | const char *augmentation_string; | |
61364358 JK |
9059 | |
9060 | unit_start = hdrptr; | |
9061 | ||
9062 | /* Get and check the length of the block. */ | |
9063 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
9064 | ||
9065 | if (unit_length == 0xffffffff) | |
9066 | { | |
9067 | /* This section is 64-bit DWARF. */ | |
9068 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
9069 | offset_size = 8; | |
9070 | } | |
9071 | else | |
9072 | offset_size = 4; | |
9073 | unit_end = hdrptr + unit_length; | |
9074 | ||
e98fdf1a AM |
9075 | sec_off = hdrptr - section->start; |
9076 | if (sec_off + unit_length < sec_off | |
9077 | || sec_off + unit_length > section->size) | |
61364358 | 9078 | { |
e98fdf1a AM |
9079 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
9080 | section->name, | |
9081 | (unsigned long) (unit_start - section->start), | |
9082 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
9083 | return 0; |
9084 | } | |
9085 | ||
9086 | /* Get and check the version number. */ | |
9087 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
9088 | printf (_("Version %ld\n"), (long) dwarf_version); | |
9089 | ||
9090 | /* Prior versions did not exist, and future versions may not be | |
9091 | backwards compatible. */ | |
9092 | if (dwarf_version != 5) | |
9093 | { | |
9094 | warn (_("Only DWARF version 5 .debug_names " | |
9095 | "is currently supported.\n")); | |
9096 | return 0; | |
9097 | } | |
9098 | ||
9099 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
9100 | if (padding != 0) | |
9101 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
9102 | padding); | |
9103 | ||
9104 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
9105 | if (comp_unit_count == 0) | |
9106 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
9107 | ||
9108 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
9109 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
9110 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
9111 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
9112 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
9113 | ||
9114 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
9115 | if (augmentation_string_size % 4 != 0) | |
9116 | { | |
9117 | warn (_("Augmentation string length %u must be rounded up " | |
9118 | "to a multiple of 4 in .debug_names.\n"), | |
9119 | augmentation_string_size); | |
9120 | augmentation_string_size += (-augmentation_string_size) & 3; | |
9121 | } | |
48467cb9 | 9122 | |
61364358 | 9123 | printf (_("Augmentation string:")); |
48467cb9 TV |
9124 | |
9125 | augmentation_printable = TRUE; | |
9126 | augmentation_string = (const char *) hdrptr; | |
9127 | ||
61364358 JK |
9128 | for (i = 0; i < augmentation_string_size; i++) |
9129 | { | |
9130 | unsigned char uc; | |
9131 | ||
9132 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
9133 | printf (" %02x", uc); | |
48467cb9 TV |
9134 | |
9135 | if (uc != 0 && !ISPRINT (uc)) | |
9136 | augmentation_printable = FALSE; | |
9137 | } | |
9138 | ||
9139 | if (augmentation_printable) | |
9140 | { | |
9141 | printf (" (\""); | |
9142 | for (i = 0; | |
9143 | i < augmentation_string_size && augmentation_string[i]; | |
9144 | ++i) | |
9145 | putchar (augmentation_string[i]); | |
9146 | printf ("\")"); | |
61364358 | 9147 | } |
61364358 JK |
9148 | putchar ('\n'); |
9149 | ||
9150 | printf (_("CU table:\n")); | |
9151 | for (i = 0; i < comp_unit_count; i++) | |
9152 | { | |
9153 | uint64_t cu_offset; | |
9154 | ||
9155 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
9156 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
9157 | } | |
9158 | putchar ('\n'); | |
9159 | ||
9160 | printf (_("TU table:\n")); | |
9161 | for (i = 0; i < local_type_unit_count; i++) | |
9162 | { | |
9163 | uint64_t tu_offset; | |
9164 | ||
9165 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
9166 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
9167 | } | |
9168 | putchar ('\n'); | |
9169 | ||
9170 | printf (_("Foreign TU table:\n")); | |
9171 | for (i = 0; i < foreign_type_unit_count; i++) | |
9172 | { | |
9173 | uint64_t signature; | |
9174 | ||
9175 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
9176 | printf (_("[%3u] "), i); | |
9177 | print_dwarf_vma (signature, 8); | |
9178 | putchar ('\n'); | |
9179 | } | |
9180 | putchar ('\n'); | |
9181 | ||
9182 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
9183 | hdrptr += bucket_count * sizeof (uint32_t); | |
9184 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
9185 | hdrptr += name_count * sizeof (uint32_t); | |
9186 | unsigned char *const name_table_string_offsets = hdrptr; | |
9187 | hdrptr += name_count * offset_size; | |
9188 | unsigned char *const name_table_entry_offsets = hdrptr; | |
9189 | hdrptr += name_count * offset_size; | |
9190 | unsigned char *const abbrev_table = hdrptr; | |
9191 | hdrptr += abbrev_table_size; | |
9192 | const unsigned char *const abbrev_table_end = hdrptr; | |
9193 | unsigned char *const entry_pool = hdrptr; | |
9194 | if (hdrptr > unit_end) | |
9195 | { | |
9196 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
9197 | "for unit 0x%lx in the debug_names\n"), | |
9198 | (long) (hdrptr - section->start), | |
9199 | (long) (unit_end - section->start), | |
9200 | (long) (unit_start - section->start)); | |
9201 | return 0; | |
9202 | } | |
9203 | ||
9204 | size_t buckets_filled = 0; | |
9205 | size_t bucketi; | |
9206 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
9207 | { | |
9208 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
9209 | ||
9210 | if (bucket != 0) | |
9211 | ++buckets_filled; | |
9212 | } | |
d3a49aa8 AM |
9213 | printf (ngettext ("Used %zu of %lu bucket.\n", |
9214 | "Used %zu of %lu buckets.\n", | |
9215 | bucket_count), | |
9216 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 9217 | |
0a79bef4 | 9218 | uint32_t hash_prev = 0; |
61364358 JK |
9219 | size_t hash_clash_count = 0; |
9220 | size_t longest_clash = 0; | |
9221 | size_t this_length = 0; | |
9222 | size_t hashi; | |
9223 | for (hashi = 0; hashi < name_count; hashi++) | |
9224 | { | |
9225 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
9226 | ||
9227 | if (hashi > 0) | |
9228 | { | |
9229 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
9230 | { | |
9231 | ++hash_clash_count; | |
9232 | ++this_length; | |
9233 | longest_clash = MAX (longest_clash, this_length); | |
9234 | } | |
9235 | else | |
9236 | this_length = 0; | |
9237 | } | |
9238 | hash_prev = hash_this; | |
9239 | } | |
9240 | printf (_("Out of %lu items there are %zu bucket clashes" | |
9241 | " (longest of %zu entries).\n"), | |
9242 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
9243 | assert (name_count == buckets_filled + hash_clash_count); | |
9244 | ||
9245 | struct abbrev_lookup_entry | |
9246 | { | |
9247 | dwarf_vma abbrev_tag; | |
9248 | unsigned char *abbrev_lookup_ptr; | |
9249 | }; | |
9250 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
9251 | size_t abbrev_lookup_used = 0; | |
9252 | size_t abbrev_lookup_allocated = 0; | |
9253 | ||
9254 | unsigned char *abbrevptr = abbrev_table; | |
9255 | for (;;) | |
9256 | { | |
cd30bcef AM |
9257 | dwarf_vma abbrev_tag; |
9258 | ||
9259 | READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end); | |
61364358 JK |
9260 | if (abbrev_tag == 0) |
9261 | break; | |
9262 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
9263 | { | |
9264 | abbrev_lookup_allocated = MAX (0x100, | |
9265 | abbrev_lookup_allocated * 2); | |
9266 | abbrev_lookup = xrealloc (abbrev_lookup, | |
9267 | (abbrev_lookup_allocated | |
9268 | * sizeof (*abbrev_lookup))); | |
9269 | } | |
9270 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
9271 | struct abbrev_lookup_entry *entry; | |
9272 | for (entry = abbrev_lookup; | |
9273 | entry < abbrev_lookup + abbrev_lookup_used; | |
9274 | entry++) | |
9275 | if (entry->abbrev_tag == abbrev_tag) | |
9276 | { | |
9277 | warn (_("Duplicate abbreviation tag %lu " | |
9278 | "in unit 0x%lx in the debug_names\n"), | |
9279 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
9280 | break; | |
9281 | } | |
9282 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
9283 | entry->abbrev_tag = abbrev_tag; | |
9284 | entry->abbrev_lookup_ptr = abbrevptr; | |
9285 | ||
9286 | /* Skip DWARF tag. */ | |
cd30bcef | 9287 | SKIP_ULEB (abbrevptr, abbrev_table_end); |
61364358 JK |
9288 | for (;;) |
9289 | { | |
cd30bcef AM |
9290 | dwarf_vma xindex, form; |
9291 | ||
9292 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9293 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9294 | if (xindex == 0 && form == 0) |
61364358 JK |
9295 | break; |
9296 | } | |
9297 | } | |
9298 | ||
9299 | printf (_("\nSymbol table:\n")); | |
9300 | uint32_t namei; | |
9301 | for (namei = 0; namei < name_count; ++namei) | |
9302 | { | |
9303 | uint64_t string_offset, entry_offset; | |
9304 | ||
9305 | SAFE_BYTE_GET (string_offset, | |
9306 | name_table_string_offsets + namei * offset_size, | |
9307 | offset_size, unit_end); | |
9308 | SAFE_BYTE_GET (entry_offset, | |
9309 | name_table_entry_offsets + namei * offset_size, | |
9310 | offset_size, unit_end); | |
9311 | ||
9312 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
9313 | fetch_indirect_string (string_offset)); | |
9314 | ||
9315 | unsigned char *entryptr = entry_pool + entry_offset; | |
9316 | ||
279edac5 AM |
9317 | /* We need to scan first whether there is a single or multiple |
9318 | entries. TAGNO is -2 for the first entry, it is -1 for the | |
9319 | initial tag read of the second entry, then it becomes 0 for the | |
9320 | first entry for real printing etc. */ | |
61364358 JK |
9321 | int tagno = -2; |
9322 | /* Initialize it due to a false compiler warning. */ | |
9323 | dwarf_vma second_abbrev_tag = -1; | |
9324 | for (;;) | |
9325 | { | |
cd30bcef AM |
9326 | dwarf_vma abbrev_tag; |
9327 | dwarf_vma dwarf_tag; | |
9328 | const struct abbrev_lookup_entry *entry; | |
9329 | ||
9330 | READ_ULEB (abbrev_tag, entryptr, unit_end); | |
61364358 JK |
9331 | if (tagno == -1) |
9332 | { | |
9333 | second_abbrev_tag = abbrev_tag; | |
9334 | tagno = 0; | |
9335 | entryptr = entry_pool + entry_offset; | |
9336 | continue; | |
9337 | } | |
9338 | if (abbrev_tag == 0) | |
9339 | break; | |
9340 | if (tagno >= 0) | |
9341 | printf ("%s<%lu>", | |
9342 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
9343 | (unsigned long) abbrev_tag); | |
9344 | ||
61364358 JK |
9345 | for (entry = abbrev_lookup; |
9346 | entry < abbrev_lookup + abbrev_lookup_used; | |
9347 | entry++) | |
9348 | if (entry->abbrev_tag == abbrev_tag) | |
9349 | break; | |
9350 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
9351 | { | |
9352 | warn (_("Undefined abbreviation tag %lu " | |
9353 | "in unit 0x%lx in the debug_names\n"), | |
9354 | (long) abbrev_tag, | |
9355 | (long) (unit_start - section->start)); | |
9356 | break; | |
9357 | } | |
9358 | abbrevptr = entry->abbrev_lookup_ptr; | |
cd30bcef | 9359 | READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end); |
61364358 JK |
9360 | if (tagno >= 0) |
9361 | printf (" %s", get_TAG_name (dwarf_tag)); | |
9362 | for (;;) | |
9363 | { | |
cd30bcef AM |
9364 | dwarf_vma xindex, form; |
9365 | ||
9366 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9367 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9368 | if (xindex == 0 && form == 0) |
61364358 JK |
9369 | break; |
9370 | ||
9371 | if (tagno >= 0) | |
1d827a72 | 9372 | printf (" %s", get_IDX_name (xindex)); |
ec1b0fbb NC |
9373 | entryptr = read_and_display_attr_value (0, form, 0, |
9374 | unit_start, entryptr, unit_end, | |
9375 | 0, 0, offset_size, | |
61364358 JK |
9376 | dwarf_version, NULL, |
9377 | (tagno < 0), NULL, | |
ec1b0fbb | 9378 | NULL, '=', -1); |
61364358 JK |
9379 | } |
9380 | ++tagno; | |
9381 | } | |
9382 | if (tagno <= 0) | |
9383 | printf (_(" <no entries>")); | |
9384 | putchar ('\n'); | |
9385 | } | |
9386 | ||
9387 | free (abbrev_lookup); | |
9388 | } | |
9389 | ||
9390 | return 1; | |
9391 | } | |
9392 | ||
dda8d76d | 9393 | static int |
d85bf2ba NC |
9394 | display_debug_links (struct dwarf_section * section, |
9395 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
9396 | { |
9397 | const unsigned char * filename; | |
9398 | unsigned int filelen; | |
9399 | ||
9400 | introduce (section, FALSE); | |
9401 | ||
9402 | /* The .gnu_debuglink section is formatted as: | |
9403 | (c-string) Filename. | |
9404 | (padding) If needed to reach a 4 byte boundary. | |
9405 | (uint32_t) CRC32 value. | |
9406 | ||
9407 | The .gun_debugaltlink section is formatted as: | |
9408 | (c-string) Filename. | |
9409 | (binary) Build-ID. */ | |
9410 | ||
9411 | filename = section->start; | |
9412 | filelen = strnlen ((const char *) filename, section->size); | |
9413 | if (filelen == section->size) | |
9414 | { | |
9415 | warn (_("The debuglink filename is corrupt/missing\n")); | |
9416 | return 0; | |
9417 | } | |
9418 | ||
9419 | printf (_(" Separate debug info file: %s\n"), filename); | |
9420 | ||
9421 | if (const_strneq (section->name, ".gnu_debuglink")) | |
9422 | { | |
9423 | unsigned int crc32; | |
9424 | unsigned int crc_offset; | |
9425 | ||
9426 | crc_offset = filelen + 1; | |
9427 | crc_offset = (crc_offset + 3) & ~3; | |
9428 | if (crc_offset + 4 > section->size) | |
9429 | { | |
9430 | warn (_("CRC offset missing/truncated\n")); | |
9431 | return 0; | |
9432 | } | |
9433 | ||
9434 | crc32 = byte_get (filename + crc_offset, 4); | |
9435 | ||
9436 | printf (_(" CRC value: %#x\n"), crc32); | |
9437 | ||
9438 | if (crc_offset + 4 < section->size) | |
9439 | { | |
9440 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
9441 | (long)(section->size - (crc_offset + 4))); | |
9442 | return 0; | |
9443 | } | |
9444 | } | |
9445 | else /* const_strneq (section->name, ".gnu_debugaltlink") */ | |
9446 | { | |
9447 | const unsigned char * build_id = section->start + filelen + 1; | |
9448 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
9449 | bfd_size_type printed; | |
9450 | ||
9451 | /* FIXME: Should we support smaller build-id notes ? */ | |
9452 | if (build_id_len < 0x14) | |
9453 | { | |
9454 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
9455 | return 0; | |
9456 | } | |
9457 | ||
9458 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 9459 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
9460 | putchar ('\n'); |
9461 | } | |
9462 | ||
9463 | putchar ('\n'); | |
9464 | return 1; | |
9465 | } | |
9466 | ||
5bbdf3d5 DE |
9467 | static int |
9468 | display_gdb_index (struct dwarf_section *section, | |
9469 | void *file ATTRIBUTE_UNUSED) | |
9470 | { | |
9471 | unsigned char *start = section->start; | |
9472 | uint32_t version; | |
9473 | uint32_t cu_list_offset, tu_list_offset; | |
9474 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
9475 | unsigned int cu_list_elements, tu_list_elements; | |
9476 | unsigned int address_table_size, symbol_table_slots; | |
9477 | unsigned char *cu_list, *tu_list; | |
9478 | unsigned char *address_table, *symbol_table, *constant_pool; | |
9479 | unsigned int i; | |
9480 | ||
9481 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
9482 | ||
dda8d76d | 9483 | introduce (section, FALSE); |
5bbdf3d5 DE |
9484 | |
9485 | if (section->size < 6 * sizeof (uint32_t)) | |
9486 | { | |
9487 | warn (_("Truncated header in the %s section.\n"), section->name); | |
9488 | return 0; | |
9489 | } | |
9490 | ||
9491 | version = byte_get_little_endian (start, 4); | |
da88a764 | 9492 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
9493 | |
9494 | /* Prior versions are obsolete, and future versions may not be | |
9495 | backwards compatible. */ | |
aa170720 | 9496 | if (version < 3 || version > 8) |
5bbdf3d5 | 9497 | { |
da88a764 | 9498 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
9499 | return 0; |
9500 | } | |
8d6eee87 TT |
9501 | if (version < 4) |
9502 | warn (_("The address table data in version 3 may be wrong.\n")); | |
9503 | if (version < 5) | |
9504 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
9505 | if (version < 6) | |
9506 | warn (_("Version 5 does not include inlined functions.\n")); | |
9507 | if (version < 7) | |
9508 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
9509 | /* Version 7 indices generated by Gold have bad type unit references, |
9510 | PR binutils/15021. But we don't know if the index was generated by | |
9511 | Gold or not, so to avoid worrying users with gdb-generated indices | |
9512 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
9513 | |
9514 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
9515 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
9516 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
9517 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
9518 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
9519 | ||
9520 | if (cu_list_offset > section->size | |
9521 | || tu_list_offset > section->size | |
9522 | || address_table_offset > section->size | |
9523 | || symbol_table_offset > section->size | |
9524 | || constant_pool_offset > section->size) | |
9525 | { | |
9526 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
9527 | return 0; | |
9528 | } | |
9529 | ||
53774b7e NC |
9530 | /* PR 17531: file: 418d0a8a. */ |
9531 | if (tu_list_offset < cu_list_offset) | |
9532 | { | |
9533 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
9534 | tu_list_offset, cu_list_offset); | |
9535 | return 0; | |
9536 | } | |
9537 | ||
5bbdf3d5 | 9538 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
9539 | |
9540 | if (address_table_offset < tu_list_offset) | |
9541 | { | |
9542 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
9543 | address_table_offset, tu_list_offset); | |
9544 | return 0; | |
9545 | } | |
9546 | ||
5bbdf3d5 | 9547 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
9548 | |
9549 | /* PR 17531: file: 18a47d3d. */ | |
9550 | if (symbol_table_offset < address_table_offset) | |
9551 | { | |
13bace4a | 9552 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
9553 | symbol_table_offset, address_table_offset); |
9554 | return 0; | |
9555 | } | |
9556 | ||
5bbdf3d5 | 9557 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
9558 | |
9559 | if (constant_pool_offset < symbol_table_offset) | |
9560 | { | |
9561 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
9562 | constant_pool_offset, symbol_table_offset); | |
9563 | return 0; | |
9564 | } | |
9565 | ||
5bbdf3d5 DE |
9566 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
9567 | ||
9568 | cu_list = start + cu_list_offset; | |
9569 | tu_list = start + tu_list_offset; | |
9570 | address_table = start + address_table_offset; | |
9571 | symbol_table = start + symbol_table_offset; | |
9572 | constant_pool = start + constant_pool_offset; | |
9573 | ||
28d909e5 | 9574 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 9575 | { |
1306a742 | 9576 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
9577 | return 0; |
9578 | } | |
b4eb7656 | 9579 | |
5bbdf3d5 DE |
9580 | printf (_("\nCU table:\n")); |
9581 | for (i = 0; i < cu_list_elements; i += 2) | |
9582 | { | |
9583 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
9584 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
9585 | ||
9586 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
9587 | (unsigned long) cu_offset, | |
9588 | (unsigned long) (cu_offset + cu_length - 1)); | |
9589 | } | |
9590 | ||
9591 | printf (_("\nTU table:\n")); | |
9592 | for (i = 0; i < tu_list_elements; i += 3) | |
9593 | { | |
9594 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
9595 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
9596 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
9597 | ||
9598 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
9599 | (unsigned long) tu_offset, | |
9600 | (unsigned long) type_offset); | |
9601 | print_dwarf_vma (signature, 8); | |
9602 | printf ("\n"); | |
9603 | } | |
9604 | ||
9605 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
9606 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
9607 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
9608 | { |
9609 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
9610 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
9611 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
9612 | ||
9613 | print_dwarf_vma (low, 8); | |
9614 | print_dwarf_vma (high, 8); | |
da88a764 | 9615 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
9616 | } |
9617 | ||
9618 | printf (_("\nSymbol table:\n")); | |
9619 | for (i = 0; i < symbol_table_slots; ++i) | |
9620 | { | |
9621 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
9622 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
9623 | uint32_t num_cus, cu; | |
9624 | ||
9625 | if (name_offset != 0 | |
9626 | || cu_vector_offset != 0) | |
9627 | { | |
9628 | unsigned int j; | |
362beea4 | 9629 | unsigned char * adr; |
5bbdf3d5 | 9630 | |
362beea4 | 9631 | adr = constant_pool + name_offset; |
53774b7e | 9632 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 9633 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
9634 | { |
9635 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
9636 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
9637 | name_offset, i); | |
9638 | } | |
9639 | else | |
acff9664 NC |
9640 | printf ("[%3u] %.*s:", i, |
9641 | (int) (section->size - (constant_pool_offset + name_offset)), | |
9642 | constant_pool + name_offset); | |
53774b7e | 9643 | |
362beea4 NC |
9644 | adr = constant_pool + cu_vector_offset; |
9645 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
9646 | { |
9647 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
9648 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
9649 | cu_vector_offset, i); | |
9650 | continue; | |
9651 | } | |
57028622 | 9652 | |
362beea4 | 9653 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 9654 | |
362beea4 | 9655 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 9656 | if (num_cus * 4 < num_cus |
362beea4 NC |
9657 | || adr >= section->start + section->size |
9658 | || adr < constant_pool) | |
53774b7e NC |
9659 | { |
9660 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 9661 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
9662 | num_cus, i); |
9663 | continue; | |
9664 | } | |
9665 | ||
8d6eee87 TT |
9666 | if (num_cus > 1) |
9667 | printf ("\n"); | |
f3853b34 | 9668 | |
5bbdf3d5 DE |
9669 | for (j = 0; j < num_cus; ++j) |
9670 | { | |
7c1cef97 | 9671 | int is_static; |
8d6eee87 TT |
9672 | gdb_index_symbol_kind kind; |
9673 | ||
5bbdf3d5 | 9674 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 9675 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
9676 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
9677 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 9678 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 9679 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
9680 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
9681 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 9682 | else |
8d6eee87 TT |
9683 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
9684 | ||
459d52c8 DE |
9685 | printf (" [%s, %s]", |
9686 | is_static ? _("static") : _("global"), | |
9687 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
9688 | if (num_cus > 1) |
9689 | printf ("\n"); | |
5bbdf3d5 | 9690 | } |
8d6eee87 TT |
9691 | if (num_cus <= 1) |
9692 | printf ("\n"); | |
5bbdf3d5 DE |
9693 | } |
9694 | } | |
9695 | ||
9696 | return 1; | |
9697 | } | |
9698 | ||
657d0d47 CC |
9699 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
9700 | ||
9701 | static void | |
9702 | prealloc_cu_tu_list (unsigned int nshndx) | |
9703 | { | |
9704 | if (shndx_pool == NULL) | |
9705 | { | |
9706 | shndx_pool_size = nshndx; | |
9707 | shndx_pool_used = 0; | |
9708 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
9709 | sizeof (unsigned int)); | |
9710 | } | |
9711 | else | |
9712 | { | |
9713 | shndx_pool_size = shndx_pool_used + nshndx; | |
9714 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
9715 | sizeof (unsigned int)); | |
9716 | } | |
9717 | } | |
9718 | ||
9719 | static void | |
9720 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
9721 | { | |
9722 | if (shndx_pool_used >= shndx_pool_size) | |
9723 | { | |
9724 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9725 | return; | |
9726 | } | |
9727 | shndx_pool [shndx_pool_used++] = shndx; | |
9728 | } | |
9729 | ||
9730 | static void | |
9731 | end_cu_tu_entry (void) | |
9732 | { | |
9733 | if (shndx_pool_used >= shndx_pool_size) | |
9734 | { | |
9735 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9736 | return; | |
9737 | } | |
9738 | shndx_pool [shndx_pool_used++] = 0; | |
9739 | } | |
9740 | ||
341f9135 CC |
9741 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
9742 | ||
9743 | static const char * | |
9744 | get_DW_SECT_short_name (unsigned int dw_sect) | |
9745 | { | |
9746 | static char buf[16]; | |
9747 | ||
9748 | switch (dw_sect) | |
9749 | { | |
9750 | case DW_SECT_INFO: | |
9751 | return "info"; | |
9752 | case DW_SECT_TYPES: | |
9753 | return "types"; | |
9754 | case DW_SECT_ABBREV: | |
9755 | return "abbrev"; | |
9756 | case DW_SECT_LINE: | |
9757 | return "line"; | |
9758 | case DW_SECT_LOC: | |
9759 | return "loc"; | |
9760 | case DW_SECT_STR_OFFSETS: | |
9761 | return "str_off"; | |
9762 | case DW_SECT_MACINFO: | |
9763 | return "macinfo"; | |
9764 | case DW_SECT_MACRO: | |
9765 | return "macro"; | |
9766 | default: | |
b4eb7656 | 9767 | break; |
341f9135 CC |
9768 | } |
9769 | ||
9770 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
9771 | return buf; | |
9772 | } | |
9773 | ||
9774 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
9775 | These sections are extensions for Fission. | |
9776 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
9777 | |
9778 | static int | |
9779 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
9780 | { | |
9781 | unsigned char *phdr = section->start; | |
9782 | unsigned char *limit = phdr + section->size; | |
9783 | unsigned char *phash; | |
9784 | unsigned char *pindex; | |
9785 | unsigned char *ppool; | |
9786 | unsigned int version; | |
341f9135 | 9787 | unsigned int ncols = 0; |
657d0d47 CC |
9788 | unsigned int nused; |
9789 | unsigned int nslots; | |
9790 | unsigned int i; | |
341f9135 CC |
9791 | unsigned int j; |
9792 | dwarf_vma signature_high; | |
9793 | dwarf_vma signature_low; | |
9794 | char buf[64]; | |
657d0d47 | 9795 | |
6937bb54 NC |
9796 | /* PR 17512: file: 002-168123-0.004. */ |
9797 | if (phdr == NULL) | |
9798 | { | |
9799 | warn (_("Section %s is empty\n"), section->name); | |
9800 | return 0; | |
9801 | } | |
9802 | /* PR 17512: file: 002-376-0.004. */ | |
9803 | if (section->size < 24) | |
9804 | { | |
72c61a0d | 9805 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
9806 | section->name); |
9807 | return 0; | |
9808 | } | |
9809 | ||
9810 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 9811 | if (version >= 2) |
6937bb54 NC |
9812 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
9813 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
9814 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
9815 | ||
657d0d47 | 9816 | phash = phdr + 16; |
8e2e3c6c AM |
9817 | pindex = phash + (size_t) nslots * 8; |
9818 | ppool = pindex + (size_t) nslots * 4; | |
57028622 | 9819 | |
657d0d47 CC |
9820 | if (do_display) |
9821 | { | |
dda8d76d NC |
9822 | introduce (section, FALSE); |
9823 | ||
8e2e3c6c | 9824 | printf (_(" Version: %u\n"), version); |
341f9135 | 9825 | if (version >= 2) |
8e2e3c6c AM |
9826 | printf (_(" Number of columns: %u\n"), ncols); |
9827 | printf (_(" Number of used entries: %u\n"), nused); | |
9828 | printf (_(" Number of slots: %u\n\n"), nslots); | |
657d0d47 CC |
9829 | } |
9830 | ||
8e2e3c6c AM |
9831 | /* PR 17531: file: 45d69832. */ |
9832 | if ((size_t) nslots * 8 / 8 != nslots | |
9833 | || phash < phdr || phash > limit | |
9834 | || pindex < phash || pindex > limit | |
9835 | || ppool < pindex || ppool > limit) | |
657d0d47 | 9836 | { |
8e2e3c6c AM |
9837 | warn (ngettext ("Section %s is too small for %u slot\n", |
9838 | "Section %s is too small for %u slots\n", | |
9839 | nslots), | |
657d0d47 CC |
9840 | section->name, nslots); |
9841 | return 0; | |
9842 | } | |
9843 | ||
341f9135 | 9844 | if (version == 1) |
657d0d47 | 9845 | { |
341f9135 CC |
9846 | if (!do_display) |
9847 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
9848 | for (i = 0; i < nslots; i++) | |
657d0d47 | 9849 | { |
341f9135 CC |
9850 | unsigned char *shndx_list; |
9851 | unsigned int shndx; | |
9852 | ||
6937bb54 | 9853 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 9854 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 9855 | { |
6937bb54 | 9856 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 9857 | shndx_list = ppool + j * 4; |
f3853b34 NC |
9858 | /* PR 17531: file: 705e010d. */ |
9859 | if (shndx_list < ppool) | |
9860 | { | |
9861 | warn (_("Section index pool located before start of section\n")); | |
9862 | return 0; | |
9863 | } | |
9864 | ||
341f9135 CC |
9865 | if (do_display) |
9866 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
9867 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9868 | buf, sizeof (buf))); | |
9869 | for (;;) | |
657d0d47 | 9870 | { |
341f9135 CC |
9871 | if (shndx_list >= limit) |
9872 | { | |
9873 | warn (_("Section %s too small for shndx pool\n"), | |
9874 | section->name); | |
9875 | return 0; | |
9876 | } | |
6937bb54 | 9877 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
9878 | if (shndx == 0) |
9879 | break; | |
9880 | if (do_display) | |
9881 | printf (" %d", shndx); | |
9882 | else | |
9883 | add_shndx_to_cu_tu_entry (shndx); | |
9884 | shndx_list += 4; | |
657d0d47 | 9885 | } |
657d0d47 | 9886 | if (do_display) |
341f9135 | 9887 | printf ("\n"); |
657d0d47 | 9888 | else |
341f9135 CC |
9889 | end_cu_tu_entry (); |
9890 | } | |
9891 | phash += 8; | |
9892 | pindex += 4; | |
9893 | } | |
9894 | } | |
9895 | else if (version == 2) | |
9896 | { | |
9897 | unsigned int val; | |
9898 | unsigned int dw_sect; | |
9899 | unsigned char *ph = phash; | |
9900 | unsigned char *pi = pindex; | |
8e2e3c6c AM |
9901 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
9902 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
9903 | unsigned char *pend = psizes + (size_t) nused * ncols * 4; | |
341f9135 CC |
9904 | bfd_boolean is_tu_index; |
9905 | struct cu_tu_set *this_set = NULL; | |
9906 | unsigned int row; | |
9907 | unsigned char *prow; | |
9908 | ||
9909 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
9910 | ||
362beea4 | 9911 | /* PR 17531: file: 0dd159bf. |
8e2e3c6c AM |
9912 | Check for integer overflow (can occur when size_t is 32-bit) |
9913 | with overlarge ncols or nused values. */ | |
4ac948a0 NC |
9914 | if (ncols > 0 |
9915 | && ((size_t) ncols * 4 / 4 != ncols | |
9916 | || (size_t) nused * ncols * 4 / ((size_t) ncols * 4) != nused | |
9917 | || poffsets < ppool || poffsets > limit | |
9918 | || psizes < poffsets || psizes > limit | |
9919 | || pend < psizes || pend > limit)) | |
341f9135 CC |
9920 | { |
9921 | warn (_("Section %s too small for offset and size tables\n"), | |
9922 | section->name); | |
9923 | return 0; | |
9924 | } | |
9925 | ||
9926 | if (do_display) | |
9927 | { | |
9928 | printf (_(" Offset table\n")); | |
9929 | printf (" slot %-16s ", | |
9930 | is_tu_index ? _("signature") : _("dwo_id")); | |
9931 | } | |
9932 | else | |
9933 | { | |
9934 | if (is_tu_index) | |
9935 | { | |
9936 | tu_count = nused; | |
72c61a0d | 9937 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 9938 | this_set = tu_sets; |
657d0d47 | 9939 | } |
657d0d47 | 9940 | else |
341f9135 CC |
9941 | { |
9942 | cu_count = nused; | |
72c61a0d | 9943 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
9944 | this_set = cu_sets; |
9945 | } | |
9946 | } | |
6937bb54 | 9947 | |
341f9135 CC |
9948 | if (do_display) |
9949 | { | |
9950 | for (j = 0; j < ncols; j++) | |
9951 | { | |
6937bb54 | 9952 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
9953 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
9954 | } | |
9955 | printf ("\n"); | |
9956 | } | |
6937bb54 | 9957 | |
341f9135 CC |
9958 | for (i = 0; i < nslots; i++) |
9959 | { | |
6937bb54 NC |
9960 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9961 | ||
9962 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9963 | if (row != 0) |
9964 | { | |
591f7597 | 9965 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 9966 | if (row > nused) |
591f7597 NC |
9967 | { |
9968 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
9969 | row, nused); | |
9970 | return 0; | |
9971 | } | |
9972 | ||
341f9135 | 9973 | if (!do_display) |
6aea08d9 NC |
9974 | { |
9975 | size_t num_copy = sizeof (uint64_t); | |
9976 | ||
9977 | /* PR 23064: Beware of buffer overflow. */ | |
9978 | if (ph + num_copy < limit) | |
9979 | memcpy (&this_set[row - 1].signature, ph, num_copy); | |
9980 | else | |
9981 | { | |
9982 | warn (_("Signature (%p) extends beyond end of space in section\n"), ph); | |
9983 | return 0; | |
9984 | } | |
9985 | } | |
6937bb54 | 9986 | |
341f9135 | 9987 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
9988 | /* PR 17531: file: b8ce60a8. */ |
9989 | if (prow < poffsets || prow > limit) | |
9990 | { | |
9991 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
9992 | row, ncols); | |
9993 | return 0; | |
9994 | } | |
3aade688 | 9995 | |
341f9135 CC |
9996 | if (do_display) |
9997 | printf (_(" [%3d] 0x%s"), | |
9998 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9999 | buf, sizeof (buf))); | |
10000 | for (j = 0; j < ncols; j++) | |
10001 | { | |
6937bb54 | 10002 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
10003 | if (do_display) |
10004 | printf (" %8d", val); | |
10005 | else | |
10006 | { | |
6937bb54 | 10007 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
10008 | |
10009 | /* PR 17531: file: 10796eb3. */ | |
10010 | if (dw_sect >= DW_SECT_MAX) | |
10011 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10012 | else | |
10013 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
10014 | } |
10015 | } | |
6937bb54 | 10016 | |
341f9135 CC |
10017 | if (do_display) |
10018 | printf ("\n"); | |
10019 | } | |
10020 | ph += 8; | |
10021 | pi += 4; | |
10022 | } | |
10023 | ||
10024 | ph = phash; | |
10025 | pi = pindex; | |
10026 | if (do_display) | |
b4eb7656 | 10027 | { |
341f9135 CC |
10028 | printf ("\n"); |
10029 | printf (_(" Size table\n")); | |
10030 | printf (" slot %-16s ", | |
10031 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 10032 | } |
6937bb54 | 10033 | |
341f9135 CC |
10034 | for (j = 0; j < ncols; j++) |
10035 | { | |
6937bb54 | 10036 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
10037 | if (do_display) |
10038 | printf (" %8s", get_DW_SECT_short_name (val)); | |
10039 | } | |
6937bb54 | 10040 | |
341f9135 CC |
10041 | if (do_display) |
10042 | printf ("\n"); | |
6937bb54 | 10043 | |
341f9135 CC |
10044 | for (i = 0; i < nslots; i++) |
10045 | { | |
6937bb54 NC |
10046 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
10047 | ||
10048 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10049 | if (row != 0) |
10050 | { | |
10051 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 10052 | |
341f9135 CC |
10053 | if (do_display) |
10054 | printf (_(" [%3d] 0x%s"), | |
10055 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10056 | buf, sizeof (buf))); | |
6937bb54 | 10057 | |
341f9135 CC |
10058 | for (j = 0; j < ncols; j++) |
10059 | { | |
6937bb54 | 10060 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
10061 | if (do_display) |
10062 | printf (" %8d", val); | |
10063 | else | |
10064 | { | |
6937bb54 | 10065 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
10066 | if (dw_sect >= DW_SECT_MAX) |
10067 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10068 | else | |
341f9135 CC |
10069 | this_set [row - 1].section_sizes [dw_sect] = val; |
10070 | } | |
10071 | } | |
6937bb54 | 10072 | |
341f9135 CC |
10073 | if (do_display) |
10074 | printf ("\n"); | |
10075 | } | |
6937bb54 | 10076 | |
341f9135 CC |
10077 | ph += 8; |
10078 | pi += 4; | |
657d0d47 | 10079 | } |
657d0d47 | 10080 | } |
341f9135 | 10081 | else if (do_display) |
6937bb54 | 10082 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
10083 | |
10084 | if (do_display) | |
10085 | printf ("\n"); | |
10086 | ||
10087 | return 1; | |
10088 | } | |
10089 | ||
10090 | /* Load the CU and TU indexes if present. This will build a list of | |
10091 | section sets that we can use to associate a .debug_info.dwo section | |
10092 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
10093 | ||
43a444f9 | 10094 | static bfd_boolean |
657d0d47 CC |
10095 | load_cu_tu_indexes (void *file) |
10096 | { | |
43a444f9 NC |
10097 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
10098 | ||
657d0d47 CC |
10099 | /* If we have already loaded (or tried to load) the CU and TU indexes |
10100 | then do not bother to repeat the task. */ | |
43a444f9 NC |
10101 | if (cu_tu_indexes_read == -1) |
10102 | { | |
10103 | cu_tu_indexes_read = TRUE; | |
10104 | ||
dda8d76d | 10105 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 NC |
10106 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
10107 | cu_tu_indexes_read = FALSE; | |
10108 | ||
dda8d76d | 10109 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 NC |
10110 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
10111 | cu_tu_indexes_read = FALSE; | |
10112 | } | |
657d0d47 | 10113 | |
43a444f9 | 10114 | return (bfd_boolean) cu_tu_indexes_read; |
657d0d47 CC |
10115 | } |
10116 | ||
10117 | /* Find the set of sections that includes section SHNDX. */ | |
10118 | ||
10119 | unsigned int * | |
10120 | find_cu_tu_set (void *file, unsigned int shndx) | |
10121 | { | |
10122 | unsigned int i; | |
10123 | ||
43a444f9 NC |
10124 | if (! load_cu_tu_indexes (file)) |
10125 | return NULL; | |
657d0d47 CC |
10126 | |
10127 | /* Find SHNDX in the shndx pool. */ | |
10128 | for (i = 0; i < shndx_pool_used; i++) | |
10129 | if (shndx_pool [i] == shndx) | |
10130 | break; | |
10131 | ||
10132 | if (i >= shndx_pool_used) | |
10133 | return NULL; | |
10134 | ||
10135 | /* Now backup to find the first entry in the set. */ | |
10136 | while (i > 0 && shndx_pool [i - 1] != 0) | |
10137 | i--; | |
10138 | ||
10139 | return shndx_pool + i; | |
10140 | } | |
10141 | ||
10142 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
10143 | ||
10144 | static int | |
10145 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
10146 | { | |
10147 | return process_cu_tu_index (section, 1); | |
10148 | } | |
10149 | ||
19e6b90e L |
10150 | static int |
10151 | display_debug_not_supported (struct dwarf_section *section, | |
10152 | void *file ATTRIBUTE_UNUSED) | |
10153 | { | |
10154 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
10155 | section->name); | |
10156 | ||
10157 | return 1; | |
10158 | } | |
10159 | ||
1306a742 NC |
10160 | /* Like malloc, but takes two parameters like calloc. |
10161 | Verifies that the first parameter is not too large. | |
82b1b41b | 10162 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 10163 | |
19e6b90e L |
10164 | void * |
10165 | cmalloc (size_t nmemb, size_t size) | |
10166 | { | |
10167 | /* Check for overflow. */ | |
10168 | if (nmemb >= ~(size_t) 0 / size) | |
10169 | return NULL; | |
82b1b41b NC |
10170 | |
10171 | return xmalloc (nmemb * size); | |
19e6b90e L |
10172 | } |
10173 | ||
1306a742 NC |
10174 | /* Like xmalloc, but takes two parameters like calloc. |
10175 | Verifies that the first parameter is not too large. | |
10176 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 10177 | |
72c61a0d | 10178 | void * |
1306a742 | 10179 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
10180 | { |
10181 | /* Check for overflow. */ | |
10182 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
10183 | { |
10184 | fprintf (stderr, | |
10185 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
10186 | (long) nmemb); | |
10187 | xexit (1); | |
10188 | } | |
72c61a0d | 10189 | |
1306a742 | 10190 | return xmalloc (nmemb * size); |
72c61a0d NC |
10191 | } |
10192 | ||
1306a742 NC |
10193 | /* Like xrealloc, but takes three parameters. |
10194 | Verifies that the second parameter is not too large. | |
10195 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 10196 | |
19e6b90e | 10197 | void * |
1306a742 | 10198 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
10199 | { |
10200 | /* Check for overflow. */ | |
10201 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10202 | { |
dda8d76d NC |
10203 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
10204 | (long) nmemb); | |
8490fb40 NC |
10205 | xexit (1); |
10206 | } | |
82b1b41b | 10207 | |
1306a742 | 10208 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
10209 | } |
10210 | ||
1306a742 | 10211 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 10212 | |
19e6b90e | 10213 | void * |
1306a742 | 10214 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
10215 | { |
10216 | /* Check for overflow. */ | |
10217 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10218 | { |
dda8d76d NC |
10219 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
10220 | (long) nmemb); | |
8490fb40 NC |
10221 | xexit (1); |
10222 | } | |
82b1b41b | 10223 | |
1306a742 | 10224 | return xcalloc (nmemb, size); |
19e6b90e L |
10225 | } |
10226 | ||
dda8d76d NC |
10227 | static unsigned long |
10228 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
10229 | const unsigned char * buf, | |
10230 | bfd_size_type len) | |
10231 | { | |
10232 | static const unsigned long crc32_table[256] = | |
10233 | { | |
10234 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
10235 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
10236 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
10237 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
10238 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
10239 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
10240 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
10241 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
10242 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
10243 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
10244 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
10245 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
10246 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
10247 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
10248 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
10249 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
10250 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
10251 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
10252 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
10253 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
10254 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
10255 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
10256 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
10257 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
10258 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
10259 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
10260 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
10261 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
10262 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
10263 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
10264 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
10265 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
10266 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
10267 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
10268 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
10269 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
10270 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
10271 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
10272 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
10273 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
10274 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
10275 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
10276 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
10277 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
10278 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
10279 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
10280 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
10281 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
10282 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
10283 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
10284 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
10285 | 0x2d02ef8d | |
10286 | }; | |
10287 | const unsigned char *end; | |
10288 | ||
10289 | crc = ~crc & 0xffffffff; | |
10290 | for (end = buf + len; buf < end; ++ buf) | |
10291 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
10292 | return ~crc & 0xffffffff; | |
10293 | } | |
10294 | ||
10295 | typedef bfd_boolean (* check_func_type) (const char *, void *); | |
10296 | typedef const char * (* parse_func_type) (struct dwarf_section *, void *); | |
10297 | ||
10298 | static bfd_boolean | |
10299 | check_gnu_debuglink (const char * pathname, void * crc_pointer) | |
10300 | { | |
10301 | static unsigned char buffer [8 * 1024]; | |
10302 | FILE * f; | |
10303 | bfd_size_type count; | |
10304 | unsigned long crc = 0; | |
10305 | void * sep_data; | |
10306 | ||
10307 | sep_data = open_debug_file (pathname); | |
10308 | if (sep_data == NULL) | |
10309 | return FALSE; | |
10310 | ||
10311 | /* Yes - we are opening the file twice... */ | |
10312 | f = fopen (pathname, "rb"); | |
10313 | if (f == NULL) | |
10314 | { | |
10315 | /* Paranoia: This should never happen. */ | |
10316 | close_debug_file (sep_data); | |
10317 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
10318 | return FALSE; | |
10319 | } | |
10320 | ||
10321 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
10322 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
10323 | ||
10324 | fclose (f); | |
10325 | ||
10326 | if (crc != * (unsigned long *) crc_pointer) | |
10327 | { | |
10328 | close_debug_file (sep_data); | |
10329 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
10330 | pathname); | |
10331 | return FALSE; | |
10332 | } | |
10333 | ||
10334 | return TRUE; | |
10335 | } | |
10336 | ||
10337 | static const char * | |
10338 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
10339 | { | |
10340 | const char * name; | |
10341 | unsigned int crc_offset; | |
10342 | unsigned long * crc32 = (unsigned long *) data; | |
10343 | ||
10344 | /* The name is first. | |
10345 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
10346 | name = (const char *) section->start; | |
10347 | ||
39f0547e | 10348 | |
dda8d76d NC |
10349 | crc_offset = strnlen (name, section->size) + 1; |
10350 | crc_offset = (crc_offset + 3) & ~3; | |
10351 | if (crc_offset + 4 > section->size) | |
10352 | return NULL; | |
10353 | ||
10354 | * crc32 = byte_get (section->start + crc_offset, 4); | |
10355 | return name; | |
10356 | } | |
10357 | ||
10358 | static bfd_boolean | |
10359 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) | |
10360 | { | |
10361 | void * sep_data = open_debug_file (filename); | |
10362 | ||
10363 | if (sep_data == NULL) | |
10364 | return FALSE; | |
10365 | ||
10366 | /* FIXME: We should now extract the build-id in the separate file | |
10367 | and check it... */ | |
10368 | ||
10369 | return TRUE; | |
10370 | } | |
10371 | ||
10372 | typedef struct build_id_data | |
10373 | { | |
10374 | bfd_size_type len; | |
10375 | const unsigned char * data; | |
10376 | } Build_id_data; | |
10377 | ||
10378 | static const char * | |
10379 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
10380 | { | |
10381 | const char * name; | |
10382 | bfd_size_type namelen; | |
10383 | bfd_size_type id_len; | |
10384 | Build_id_data * build_id_data; | |
10385 | ||
10386 | /* The name is first. | |
10387 | The build-id follows immediately, with no padding, up to the section's end. */ | |
10388 | ||
10389 | name = (const char *) section->start; | |
10390 | namelen = strnlen (name, section->size) + 1; | |
10391 | if (namelen >= section->size) | |
10392 | return NULL; | |
10393 | ||
10394 | id_len = section->size - namelen; | |
10395 | if (id_len < 0x14) | |
10396 | return NULL; | |
10397 | ||
dfbee680 | 10398 | build_id_data = (Build_id_data *) data; |
dda8d76d NC |
10399 | build_id_data->len = id_len; |
10400 | build_id_data->data = section->start + namelen; | |
10401 | ||
dda8d76d NC |
10402 | return name; |
10403 | } | |
10404 | ||
24841daa NC |
10405 | static void |
10406 | add_separate_debug_file (const char * filename, void * handle) | |
10407 | { | |
10408 | separate_info * i = xmalloc (sizeof * i); | |
10409 | ||
10410 | i->filename = filename; | |
10411 | i->handle = handle; | |
10412 | i->next = first_separate_info; | |
10413 | first_separate_info = i; | |
10414 | } | |
10415 | ||
301a9420 AM |
10416 | #if HAVE_LIBDEBUGINFOD |
10417 | /* Query debuginfod servers for the target debuglink or debugaltlink | |
10418 | file. If successful, store the path of the file in filename and | |
10419 | return TRUE, otherwise return FALSE. */ | |
10420 | ||
10421 | static bfd_boolean | |
10422 | debuginfod_fetch_separate_debug_info (struct dwarf_section * section, | |
10423 | char ** filename, | |
10424 | void * file) | |
10425 | { | |
10426 | size_t build_id_len; | |
10427 | unsigned char * build_id; | |
10428 | ||
10429 | if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0) | |
10430 | { | |
10431 | /* Get the build-id of file. */ | |
10432 | build_id = get_build_id (file); | |
10433 | build_id_len = 0; | |
10434 | } | |
10435 | else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0) | |
10436 | { | |
10437 | /* Get the build-id of the debugaltlink file. */ | |
10438 | unsigned int filelen; | |
10439 | ||
10440 | filelen = strnlen ((const char *)section->start, section->size); | |
10441 | if (filelen == section->size) | |
10442 | /* Corrupt debugaltlink. */ | |
10443 | return FALSE; | |
10444 | ||
10445 | build_id = section->start + filelen + 1; | |
10446 | build_id_len = section->size - (filelen + 1); | |
10447 | ||
10448 | if (build_id_len == 0) | |
10449 | return FALSE; | |
10450 | } | |
10451 | else | |
10452 | return FALSE; | |
10453 | ||
10454 | if (build_id) | |
10455 | { | |
10456 | int fd; | |
10457 | debuginfod_client * client; | |
10458 | ||
10459 | client = debuginfod_begin (); | |
10460 | if (client == NULL) | |
10461 | return FALSE; | |
10462 | ||
10463 | /* Query debuginfod servers for the target file. If found its path | |
10464 | will be stored in filename. */ | |
10465 | fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename); | |
10466 | debuginfod_end (client); | |
10467 | ||
10468 | /* Only free build_id if we allocated space for a hex string | |
10469 | in get_build_id (). */ | |
10470 | if (build_id_len == 0) | |
10471 | free (build_id); | |
10472 | ||
10473 | if (fd >= 0) | |
10474 | { | |
10475 | /* File successfully retrieved. Close fd since we want to | |
10476 | use open_debug_file () on filename instead. */ | |
10477 | close (fd); | |
10478 | return TRUE; | |
10479 | } | |
10480 | } | |
10481 | ||
10482 | return FALSE; | |
10483 | } | |
10484 | #endif | |
10485 | ||
dda8d76d NC |
10486 | static void * |
10487 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 10488 | struct dwarf_section * xlink, |
dda8d76d NC |
10489 | parse_func_type parse_func, |
10490 | check_func_type check_func, | |
301a9420 AM |
10491 | void * func_data, |
10492 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
10493 | { |
10494 | const char * separate_filename; | |
24841daa | 10495 | char * debug_filename; |
dda8d76d NC |
10496 | char * canon_dir; |
10497 | size_t canon_dirlen; | |
10498 | size_t dirlen; | |
10499 | ||
2b63c337 | 10500 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
10501 | { |
10502 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 10503 | xlink->name ? xlink->name : xlink->uncompressed_name); |
ce139cd5 | 10504 | return NULL; |
dda8d76d NC |
10505 | } |
10506 | ||
10507 | /* Attempt to locate the separate file. | |
10508 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
10509 | ||
10510 | canon_dir = lrealpath (main_filename); | |
10511 | ||
10512 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) | |
10513 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
10514 | break; | |
10515 | canon_dir[canon_dirlen] = '\0'; | |
10516 | ||
10517 | #ifndef DEBUGDIR | |
10518 | #define DEBUGDIR "/lib/debug" | |
10519 | #endif | |
10520 | #ifndef EXTRA_DEBUG_ROOT1 | |
10521 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
10522 | #endif | |
10523 | #ifndef EXTRA_DEBUG_ROOT2 | |
10524 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
10525 | #endif | |
10526 | ||
24841daa NC |
10527 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
10528 | + canon_dirlen | |
10529 | + strlen (".debug/") | |
dda8d76d | 10530 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 10531 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
10532 | #endif |
10533 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 10534 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 10535 | #endif |
24841daa NC |
10536 | + strlen (separate_filename) |
10537 | + 1); | |
10538 | if (debug_filename == NULL) | |
dda8d76d NC |
10539 | { |
10540 | warn (_("Out of memory")); | |
3391569f | 10541 | free (canon_dir); |
dda8d76d NC |
10542 | return NULL; |
10543 | } | |
10544 | ||
10545 | /* First try in the current directory. */ | |
24841daa NC |
10546 | sprintf (debug_filename, "%s", separate_filename); |
10547 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10548 | goto found; |
10549 | ||
10550 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
10551 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10552 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10553 | goto found; |
10554 | ||
10555 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
10556 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10557 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10558 | goto found; |
10559 | ||
10560 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
10561 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10562 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10563 | goto found; |
10564 | ||
10565 | #ifdef EXTRA_DEBUG_ROOT1 | |
10566 | /* Try the first extra debug file root. */ | |
24841daa NC |
10567 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10568 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 10569 | goto found; |
39f0547e NC |
10570 | |
10571 | /* Try the first extra debug file root. */ | |
10572 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
10573 | if (check_func (debug_filename, func_data)) | |
10574 | goto found; | |
dda8d76d NC |
10575 | #endif |
10576 | ||
10577 | #ifdef EXTRA_DEBUG_ROOT2 | |
10578 | /* Try the second extra debug file root. */ | |
24841daa NC |
10579 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10580 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10581 | goto found; |
10582 | #endif | |
10583 | ||
24841daa NC |
10584 | /* Then try in the global debug_filename directory. */ |
10585 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
10586 | dirlen = strlen (DEBUGDIR) - 1; |
10587 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
10588 | strcat (debug_filename, "/"); |
10589 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 10590 | |
24841daa | 10591 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
10592 | goto found; |
10593 | ||
301a9420 AM |
10594 | #if HAVE_LIBDEBUGINFOD |
10595 | { | |
10596 | char * tmp_filename; | |
10597 | ||
10598 | if (debuginfod_fetch_separate_debug_info (xlink, | |
10599 | & tmp_filename, | |
10600 | file)) | |
10601 | { | |
10602 | /* File successfully downloaded from server, replace | |
10603 | debug_filename with the file's path. */ | |
10604 | free (debug_filename); | |
10605 | debug_filename = tmp_filename; | |
10606 | goto found; | |
10607 | } | |
10608 | } | |
10609 | #endif | |
10610 | ||
dda8d76d NC |
10611 | /* Failed to find the file. */ |
10612 | warn (_("could not find separate debug file '%s'\n"), separate_filename); | |
24841daa | 10613 | warn (_("tried: %s\n"), debug_filename); |
dda8d76d NC |
10614 | |
10615 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa NC |
10616 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10617 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10618 | #endif |
10619 | ||
10620 | #ifdef EXTRA_DEBUG_ROOT1 | |
39f0547e NC |
10621 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); |
10622 | warn (_("tried: %s\n"), debug_filename); | |
10623 | ||
24841daa NC |
10624 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10625 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10626 | #endif |
10627 | ||
24841daa NC |
10628 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10629 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10630 | |
24841daa NC |
10631 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10632 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10633 | |
24841daa NC |
10634 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10635 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10636 | |
24841daa NC |
10637 | sprintf (debug_filename, "%s", separate_filename); |
10638 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10639 | |
301a9420 AM |
10640 | #if HAVE_LIBDEBUGINFOD |
10641 | { | |
10642 | char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR); | |
10643 | if (urls == NULL) | |
10644 | urls = ""; | |
10645 | ||
10646 | warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls); | |
10647 | } | |
10648 | #endif | |
10649 | ||
dda8d76d | 10650 | free (canon_dir); |
24841daa | 10651 | free (debug_filename); |
dda8d76d NC |
10652 | return NULL; |
10653 | ||
10654 | found: | |
10655 | free (canon_dir); | |
10656 | ||
24841daa NC |
10657 | void * debug_handle; |
10658 | ||
dda8d76d | 10659 | /* Now open the file.... */ |
24841daa | 10660 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 10661 | { |
24841daa NC |
10662 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
10663 | free (debug_filename); | |
ce139cd5 | 10664 | return NULL; |
dda8d76d NC |
10665 | } |
10666 | ||
10667 | /* FIXME: We do not check to see if there are any other separate debug info | |
10668 | files that would also match. */ | |
10669 | ||
24841daa NC |
10670 | printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debug_filename); |
10671 | add_separate_debug_file (debug_filename, debug_handle); | |
dda8d76d | 10672 | |
24841daa | 10673 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 10674 | the structure returned by open_debug_file(). */ |
24841daa | 10675 | return debug_handle; |
dda8d76d NC |
10676 | } |
10677 | ||
d85bf2ba NC |
10678 | /* Attempt to load a separate dwarf object file. */ |
10679 | ||
10680 | static void * | |
24841daa | 10681 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 10682 | { |
24841daa NC |
10683 | char * separate_filename; |
10684 | void * separate_handle; | |
d85bf2ba NC |
10685 | |
10686 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
24841daa NC |
10687 | separate_filename = concat (dir, "/", name, NULL); |
10688 | if (separate_filename == NULL) | |
d85bf2ba NC |
10689 | { |
10690 | warn (_("Out of memory allocating dwo filename\n")); | |
10691 | return NULL; | |
10692 | } | |
10693 | ||
24841daa | 10694 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 10695 | { |
24841daa NC |
10696 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
10697 | free (separate_filename); | |
d85bf2ba NC |
10698 | return NULL; |
10699 | } | |
10700 | ||
10701 | /* FIXME: We should check the dwo_id. */ | |
10702 | ||
24841daa NC |
10703 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
10704 | add_separate_debug_file (separate_filename, separate_handle); | |
10705 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
10706 | return separate_handle; | |
d85bf2ba NC |
10707 | } |
10708 | ||
ce139cd5 NC |
10709 | /* Load a debuglink section and/or a debugaltlink section, if either are present. |
10710 | Recursively check the loaded files for more of these sections. | |
10711 | FIXME: Should also check for DWO_* entries in the newlu loaded files. */ | |
10712 | ||
10713 | static void | |
10714 | check_for_and_load_links (void * file, const char * filename) | |
10715 | { | |
10716 | void * handle = NULL; | |
10717 | ||
10718 | if (load_debug_section (gnu_debugaltlink, file)) | |
10719 | { | |
10720 | Build_id_data build_id_data; | |
10721 | ||
10722 | handle = load_separate_debug_info (filename, | |
10723 | & debug_displays[gnu_debugaltlink].section, | |
10724 | parse_gnu_debugaltlink, | |
10725 | check_gnu_debugaltlink, | |
10726 | & build_id_data, | |
10727 | file); | |
10728 | if (handle) | |
10729 | { | |
10730 | assert (handle == first_separate_info->handle); | |
10731 | check_for_and_load_links (first_separate_info->handle, | |
10732 | first_separate_info->filename); | |
10733 | } | |
10734 | } | |
10735 | ||
10736 | if (load_debug_section (gnu_debuglink, file)) | |
10737 | { | |
10738 | unsigned long crc32; | |
10739 | ||
10740 | handle = load_separate_debug_info (filename, | |
10741 | & debug_displays[gnu_debuglink].section, | |
10742 | parse_gnu_debuglink, | |
10743 | check_gnu_debuglink, | |
10744 | & crc32, | |
10745 | file); | |
10746 | if (handle) | |
10747 | { | |
10748 | assert (handle == first_separate_info->handle); | |
10749 | check_for_and_load_links (first_separate_info->handle, | |
10750 | first_separate_info->filename); | |
10751 | } | |
10752 | } | |
10753 | } | |
10754 | ||
24841daa NC |
10755 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
10756 | Returns TRUE if any were found, FALSE otherwise. | |
10757 | If TRUE is returned then the linked list starting at first_separate_info | |
10758 | will be populated with open file handles. */ | |
dda8d76d | 10759 | |
24841daa NC |
10760 | bfd_boolean |
10761 | load_separate_debug_files (void * file, const char * filename) | |
dda8d76d | 10762 | { |
8de3a6e2 NC |
10763 | /* Skip this operation if we are not interested in debug links. */ |
10764 | if (! do_follow_links && ! do_debug_links) | |
24841daa | 10765 | return FALSE; |
8de3a6e2 | 10766 | |
24841daa | 10767 | /* See if there are any dwo links. */ |
d85bf2ba NC |
10768 | if (load_debug_section (str, file) |
10769 | && load_debug_section (abbrev, file) | |
10770 | && load_debug_section (info, file)) | |
10771 | { | |
24841daa | 10772 | free_dwo_info (); |
d85bf2ba NC |
10773 | |
10774 | if (process_debug_info (& debug_displays[info].section, file, abbrev, TRUE, FALSE)) | |
10775 | { | |
24841daa NC |
10776 | bfd_boolean introduced = FALSE; |
10777 | dwo_info * dwinfo; | |
10778 | const char * dir = NULL; | |
10779 | const char * id = NULL; | |
10780 | ||
10781 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 10782 | { |
24841daa | 10783 | switch (dwinfo->type) |
d85bf2ba | 10784 | { |
24841daa NC |
10785 | case DWO_NAME: |
10786 | if (do_debug_links) | |
10787 | { | |
10788 | if (! introduced) | |
10789 | { | |
10790 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
10791 | debug_displays [info].section.uncompressed_name); | |
10792 | introduced = TRUE; | |
10793 | } | |
d85bf2ba | 10794 | |
24841daa NC |
10795 | printf (_(" Name: %s\n"), dwinfo->value); |
10796 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); | |
10797 | if (id != NULL) | |
10798 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
10799 | else | |
10800 | printf (_(" ID: <unknown>\n")); | |
10801 | printf ("\n\n"); | |
10802 | } | |
10803 | ||
10804 | if (do_follow_links) | |
10805 | load_dwo_file (filename, dwinfo->value, dir, id); | |
10806 | break; | |
10807 | ||
10808 | case DWO_DIR: | |
10809 | dir = dwinfo->value; | |
10810 | break; | |
10811 | ||
10812 | case DWO_ID: | |
10813 | id = dwinfo->value; | |
10814 | break; | |
10815 | ||
10816 | default: | |
10817 | error (_("Unexpected DWO INFO type")); | |
10818 | break; | |
10819 | } | |
d85bf2ba NC |
10820 | } |
10821 | } | |
10822 | } | |
10823 | ||
dda8d76d | 10824 | if (! do_follow_links) |
8de3a6e2 NC |
10825 | /* The other debug links will be displayed by display_debug_links() |
10826 | so we do not need to do any further processing here. */ | |
24841daa | 10827 | return FALSE; |
dda8d76d NC |
10828 | |
10829 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
dda8d76d | 10830 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ |
d85bf2ba | 10831 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 10832 | |
ce139cd5 | 10833 | check_for_and_load_links (file, filename); |
24841daa NC |
10834 | if (first_separate_info != NULL) |
10835 | return TRUE; | |
10836 | ||
dda8d76d | 10837 | do_follow_links = 0; |
24841daa | 10838 | return FALSE; |
dda8d76d NC |
10839 | } |
10840 | ||
19e6b90e L |
10841 | void |
10842 | free_debug_memory (void) | |
10843 | { | |
3f5e193b | 10844 | unsigned int i; |
19e6b90e L |
10845 | |
10846 | free_abbrevs (); | |
10847 | ||
10848 | for (i = 0; i < max; i++) | |
3f5e193b | 10849 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 10850 | |
cc86f28f | 10851 | if (debug_information != NULL) |
19e6b90e | 10852 | { |
82fcdb39 | 10853 | for (i = 0; i < alloc_num_debug_info_entries; i++) |
19e6b90e | 10854 | { |
82fcdb39 | 10855 | if (debug_information [i].max_loc_offsets) |
19e6b90e | 10856 | { |
82fcdb39 AM |
10857 | free (debug_information [i].loc_offsets); |
10858 | free (debug_information [i].have_frame_base); | |
19e6b90e | 10859 | } |
82fcdb39 AM |
10860 | if (debug_information [i].max_range_lists) |
10861 | free (debug_information [i].range_lists); | |
19e6b90e L |
10862 | } |
10863 | free (debug_information); | |
10864 | debug_information = NULL; | |
82b1b41b | 10865 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 10866 | } |
dda8d76d | 10867 | |
24841daa NC |
10868 | separate_info * d; |
10869 | separate_info * next; | |
dda8d76d | 10870 | |
24841daa NC |
10871 | for (d = first_separate_info; d != NULL; d = next) |
10872 | { | |
10873 | close_debug_file (d->handle); | |
10874 | free ((void *) d->filename); | |
10875 | next = d->next; | |
10876 | free ((void *) d); | |
dda8d76d | 10877 | } |
24841daa NC |
10878 | first_separate_info = NULL; |
10879 | ||
10880 | free_dwo_info (); | |
19e6b90e L |
10881 | } |
10882 | ||
4cb93e3b TG |
10883 | void |
10884 | dwarf_select_sections_by_names (const char *names) | |
10885 | { | |
10886 | typedef struct | |
10887 | { | |
10888 | const char * option; | |
10889 | int * variable; | |
f9f0e732 | 10890 | int val; |
4cb93e3b TG |
10891 | } |
10892 | debug_dump_long_opts; | |
10893 | ||
10894 | static const debug_dump_long_opts opts_table [] = | |
10895 | { | |
10896 | /* Please keep this table alpha- sorted. */ | |
10897 | { "Ranges", & do_debug_ranges, 1 }, | |
10898 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 10899 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 10900 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
10901 | { "cu_index", & do_debug_cu_index, 1 }, |
10902 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 10903 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
10904 | { "frames", & do_debug_frames, 1 }, |
10905 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
10906 | /* The special .gdb_index section. */ |
10907 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
10908 | { "info", & do_debug_info, 1 }, |
10909 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 10910 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
10911 | { "loc", & do_debug_loc, 1 }, |
10912 | { "macro", & do_debug_macinfo, 1 }, | |
10913 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 10914 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 10915 | /* This entry is for compatibility |
4cb93e3b TG |
10916 | with earlier versions of readelf. */ |
10917 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 10918 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 10919 | { "str", & do_debug_str, 1 }, |
e4b7104b | 10920 | { "str-offsets", & do_debug_str_offsets, 1 }, |
6f875884 TG |
10921 | /* These trace_* sections are used by Itanium VMS. */ |
10922 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
10923 | { "trace_aranges", & do_trace_aranges, 1 }, | |
10924 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
10925 | { NULL, NULL, 0 } |
10926 | }; | |
10927 | ||
10928 | const char *p; | |
467c65bc | 10929 | |
4cb93e3b TG |
10930 | p = names; |
10931 | while (*p) | |
10932 | { | |
10933 | const debug_dump_long_opts * entry; | |
467c65bc | 10934 | |
4cb93e3b TG |
10935 | for (entry = opts_table; entry->option; entry++) |
10936 | { | |
10937 | size_t len = strlen (entry->option); | |
467c65bc | 10938 | |
4cb93e3b TG |
10939 | if (strncmp (p, entry->option, len) == 0 |
10940 | && (p[len] == ',' || p[len] == '\0')) | |
10941 | { | |
10942 | * entry->variable |= entry->val; | |
467c65bc | 10943 | |
4cb93e3b TG |
10944 | /* The --debug-dump=frames-interp option also |
10945 | enables the --debug-dump=frames option. */ | |
10946 | if (do_debug_frames_interp) | |
10947 | do_debug_frames = 1; | |
10948 | ||
10949 | p += len; | |
10950 | break; | |
10951 | } | |
10952 | } | |
467c65bc | 10953 | |
4cb93e3b TG |
10954 | if (entry->option == NULL) |
10955 | { | |
10956 | warn (_("Unrecognized debug option '%s'\n"), p); | |
10957 | p = strchr (p, ','); | |
10958 | if (p == NULL) | |
10959 | break; | |
10960 | } | |
467c65bc | 10961 | |
4cb93e3b TG |
10962 | if (*p == ',') |
10963 | p++; | |
10964 | } | |
10965 | } | |
10966 | ||
10967 | void | |
10968 | dwarf_select_sections_by_letters (const char *letters) | |
10969 | { | |
91d6fa6a | 10970 | unsigned int lindex = 0; |
4cb93e3b | 10971 | |
91d6fa6a NC |
10972 | while (letters[lindex]) |
10973 | switch (letters[lindex++]) | |
4cb93e3b | 10974 | { |
dda8d76d NC |
10975 | case 'A': do_debug_addr = 1; break; |
10976 | case 'a': do_debug_abbrevs = 1; break; | |
10977 | case 'c': do_debug_cu_index = 1; break; | |
10978 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
10979 | case 'f': do_debug_frames = 1; break; | |
10980 | case 'g': do_gdb_index = 1; break; | |
10981 | case 'i': do_debug_info = 1; break; | |
10982 | case 'K': do_follow_links = 1; break; | |
10983 | case 'k': do_debug_links = 1; break; | |
10984 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
10985 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
10986 | case 'm': do_debug_macinfo = 1; break; | |
e4b7104b | 10987 | case 'O': do_debug_str_offsets = 1; break; |
dda8d76d NC |
10988 | case 'o': do_debug_loc = 1; break; |
10989 | case 'p': do_debug_pubnames = 1; break; | |
10990 | case 'R': do_debug_ranges = 1; break; | |
10991 | case 'r': do_debug_aranges = 1; break; | |
10992 | case 's': do_debug_str = 1; break; | |
10993 | case 'T': do_trace_aranges = 1; break; | |
10994 | case 't': do_debug_pubtypes = 1; break; | |
10995 | case 'U': do_trace_info = 1; break; | |
10996 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 10997 | |
4cb93e3b | 10998 | default: |
7cc78d07 | 10999 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
11000 | break; |
11001 | } | |
11002 | } | |
11003 | ||
11004 | void | |
11005 | dwarf_select_sections_all (void) | |
11006 | { | |
11007 | do_debug_info = 1; | |
11008 | do_debug_abbrevs = 1; | |
11009 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
11010 | do_debug_pubnames = 1; | |
f9f0e732 | 11011 | do_debug_pubtypes = 1; |
4cb93e3b TG |
11012 | do_debug_aranges = 1; |
11013 | do_debug_ranges = 1; | |
11014 | do_debug_frames = 1; | |
11015 | do_debug_macinfo = 1; | |
11016 | do_debug_str = 1; | |
11017 | do_debug_loc = 1; | |
5bbdf3d5 | 11018 | do_gdb_index = 1; |
6f875884 TG |
11019 | do_trace_info = 1; |
11020 | do_trace_abbrevs = 1; | |
11021 | do_trace_aranges = 1; | |
657d0d47 CC |
11022 | do_debug_addr = 1; |
11023 | do_debug_cu_index = 1; | |
dda8d76d NC |
11024 | do_follow_links = 1; |
11025 | do_debug_links = 1; | |
e4b7104b | 11026 | do_debug_str_offsets = 1; |
4cb93e3b TG |
11027 | } |
11028 | ||
dda8d76d NC |
11029 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL |
11030 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL | |
11031 | ||
11032 | /* N.B. The order here must match the order in section_display_enum. */ | |
11033 | ||
19e6b90e L |
11034 | struct dwarf_section_display debug_displays[] = |
11035 | { | |
dda8d76d NC |
11036 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, |
11037 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE }, | |
11038 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
11039 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE }, | |
11040 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
11041 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE }, | |
11042 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, | |
11043 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
11044 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
11045 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
11046 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
11047 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
11048 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
11049 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
11050 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE }, | |
11051 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, | |
11052 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
11053 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
11054 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
11055 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
11056 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE }, | |
11057 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
11058 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE }, | |
11059 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE }, | |
11060 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE }, | |
11061 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE }, | |
11062 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE }, | |
11063 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE }, | |
11064 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
11065 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE }, | |
11066 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
11067 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
11068 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
11069 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
11070 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE }, | |
e4b7104b NC |
11071 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, TRUE }, |
11072 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, TRUE }, | |
dda8d76d NC |
11073 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE }, |
11074 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
11075 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
11076 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
11077 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
11078 | /* Separate debug info files can containt their own .debug_str section, | |
11079 | and this might be in *addition* to a .debug_str section already present | |
11080 | in the main file. Hence we need to have two entries for .debug_str. */ | |
11081 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
19e6b90e | 11082 | }; |
b451e98a JK |
11083 | |
11084 | /* A static assertion. */ | |
11085 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |