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); | |
59624513 | 1871 | else if (dwarf_version > 2) |
ec1b0fbb NC |
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: | |
59624513 | 1923 | case DW_FORM_ref_sig8: |
ec1b0fbb NC |
1924 | data += 8; |
1925 | break; | |
1926 | ||
1927 | case DW_FORM_data16: | |
1928 | data += 16; | |
1929 | break; | |
1930 | ||
1931 | case DW_FORM_string: | |
1932 | data += strnlen ((char *) data, end - data) + 1; | |
1933 | break; | |
1934 | ||
1935 | case DW_FORM_block: | |
1936 | case DW_FORM_exprloc: | |
cd30bcef | 1937 | READ_ULEB (uvalue, data, end); |
59624513 | 1938 | data += uvalue; |
ec1b0fbb NC |
1939 | break; |
1940 | ||
1941 | case DW_FORM_block1: | |
1942 | SAFE_BYTE_GET (uvalue, data, 1, end); | |
1943 | data += 1 + uvalue; | |
1944 | break; | |
1945 | ||
1946 | case DW_FORM_block2: | |
1947 | SAFE_BYTE_GET (uvalue, data, 2, end); | |
1948 | data += 2 + uvalue; | |
1949 | break; | |
1950 | ||
1951 | case DW_FORM_block4: | |
1952 | SAFE_BYTE_GET (uvalue, data, 4, end); | |
1953 | data += 4 + uvalue; | |
1954 | break; | |
1955 | ||
ec1b0fbb | 1956 | case DW_FORM_indirect: |
59624513 NC |
1957 | READ_ULEB (form, data, end); |
1958 | if (form == DW_FORM_implicit_const) | |
1959 | SKIP_ULEB (data, end); | |
1960 | return skip_attr_bytes (form, data, end, pointer_size, offset_size, dwarf_version, value_return); | |
1961 | ||
ec1b0fbb NC |
1962 | default: |
1963 | return NULL; | |
1964 | } | |
1965 | ||
1966 | * value_return = uvalue; | |
1967 | if (data > end) | |
1968 | data = (unsigned char *) end; | |
1969 | return data; | |
1970 | } | |
1971 | ||
1972 | /* Return IS_SIGNED set to TRUE if the type at | |
1973 | DATA can be determined to be a signed type. */ | |
1974 | ||
1975 | static void | |
1976 | get_type_signedness (unsigned char * start, | |
1977 | unsigned char * data, | |
1978 | unsigned const char * end, | |
1979 | dwarf_vma pointer_size, | |
1980 | dwarf_vma offset_size, | |
1981 | int dwarf_version, | |
1982 | bfd_boolean * is_signed, | |
59624513 | 1983 | unsigned int nesting) |
ec1b0fbb NC |
1984 | { |
1985 | unsigned long abbrev_number; | |
ec1b0fbb NC |
1986 | abbrev_entry * entry; |
1987 | abbrev_attr * attr; | |
1988 | ||
1989 | * is_signed = FALSE; | |
1990 | ||
cd30bcef | 1991 | READ_ULEB (abbrev_number, data, end); |
ec1b0fbb NC |
1992 | |
1993 | for (entry = first_abbrev; | |
1994 | entry != NULL && entry->entry != abbrev_number; | |
1995 | entry = entry->next) | |
1996 | continue; | |
1997 | ||
1998 | if (entry == NULL) | |
1999 | /* FIXME: Issue a warning ? */ | |
2000 | return; | |
2001 | ||
59624513 NC |
2002 | #define MAX_NESTING 20 |
2003 | if (nesting > MAX_NESTING) | |
2004 | { | |
2005 | /* FIXME: Warn - or is this expected ? | |
2006 | NB/ We need to avoid infinite recursion. */ | |
2007 | return; | |
2008 | } | |
2009 | ||
ec1b0fbb NC |
2010 | for (attr = entry->first_attr; |
2011 | attr != NULL && attr->attribute; | |
2012 | attr = attr->next) | |
2013 | { | |
2014 | dwarf_vma uvalue = 0; | |
2015 | ||
2016 | data = skip_attr_bytes (attr->form, data, end, pointer_size, | |
2017 | offset_size, dwarf_version, & uvalue); | |
2018 | if (data == NULL) | |
2019 | return; | |
2020 | ||
2021 | switch (attr->attribute) | |
2022 | { | |
2023 | #if 0 /* FIXME: It would be nice to print the name of the type, | |
2024 | but this would mean updating a lot of binutils tests. */ | |
2025 | case DW_AT_name: | |
2026 | if (attr->form == DW_FORM_strp) | |
2027 | printf ("%s", fetch_indirect_string (uvalue)); | |
2028 | break; | |
2029 | #endif | |
2030 | case DW_AT_type: | |
2031 | /* Recurse. */ | |
b3fe587e AM |
2032 | if (uvalue >= (size_t) (end - start)) |
2033 | return; | |
59624513 NC |
2034 | /* We cannot correctly process DW_FORM_ref_addr at the moment. */ |
2035 | if (attr->form != DW_FORM_ref_addr) | |
2036 | get_type_signedness (start, start + uvalue, end, pointer_size, | |
2037 | offset_size, dwarf_version, is_signed, nesting + 1); | |
ec1b0fbb NC |
2038 | break; |
2039 | ||
2040 | case DW_AT_encoding: | |
2041 | /* Determine signness. */ | |
2042 | switch (uvalue) | |
2043 | { | |
2044 | case DW_ATE_address: | |
2045 | /* FIXME - some architectures have signed addresses. */ | |
2046 | case DW_ATE_boolean: | |
2047 | case DW_ATE_unsigned: | |
2048 | case DW_ATE_unsigned_char: | |
2049 | case DW_ATE_unsigned_fixed: | |
2050 | * is_signed = FALSE; | |
2051 | break; | |
2052 | ||
2053 | default: | |
2054 | case DW_ATE_complex_float: | |
2055 | case DW_ATE_float: | |
2056 | case DW_ATE_signed: | |
2057 | case DW_ATE_signed_char: | |
2058 | case DW_ATE_imaginary_float: | |
2059 | case DW_ATE_decimal_float: | |
2060 | case DW_ATE_signed_fixed: | |
2061 | * is_signed = TRUE; | |
2062 | break; | |
2063 | } | |
2064 | break; | |
2065 | } | |
2066 | } | |
2067 | } | |
2068 | ||
2069 | static void | |
2070 | read_and_print_leb128 (unsigned char * data, | |
2071 | unsigned int * bytes_read, | |
2072 | unsigned const char * end, | |
2073 | bfd_boolean is_signed) | |
2074 | { | |
cd30bcef AM |
2075 | int status; |
2076 | dwarf_vma val = read_leb128 (data, end, is_signed, bytes_read, &status); | |
2077 | if (status != 0) | |
1b513401 | 2078 | report_leb_status (status, __FILE__, __LINE__); |
ec1b0fbb | 2079 | else |
cd30bcef | 2080 | printf ("%s", dwarf_vmatoa (is_signed ? "d" : "u", val)); |
ec1b0fbb NC |
2081 | } |
2082 | ||
2083 | static void | |
2084 | display_discr_list (unsigned long form, | |
2085 | dwarf_vma uvalue, | |
2086 | unsigned char * data, | |
2087 | unsigned const char * end, | |
2088 | int level) | |
2089 | { | |
2090 | if (uvalue == 0) | |
2091 | { | |
2092 | printf ("[default]"); | |
2093 | return; | |
2094 | } | |
2095 | ||
2096 | switch (form) | |
2097 | { | |
2098 | case DW_FORM_block: | |
2099 | case DW_FORM_block1: | |
2100 | case DW_FORM_block2: | |
2101 | case DW_FORM_block4: | |
2102 | /* Move data pointer back to the start of the byte array. */ | |
2103 | data -= uvalue; | |
2104 | break; | |
2105 | default: | |
2106 | printf ("<corrupt>\n"); | |
2107 | warn (_("corrupt discr_list - not using a block form\n")); | |
2108 | return; | |
2109 | } | |
2110 | ||
2111 | if (uvalue < 2) | |
2112 | { | |
2113 | printf ("<corrupt>\n"); | |
2114 | warn (_("corrupt discr_list - block not long enough\n")); | |
2115 | return; | |
2116 | } | |
2117 | ||
2118 | bfd_boolean is_signed = | |
2119 | (level > 0 && level <= MAX_CU_NESTING) | |
2120 | ? level_type_signed [level - 1] : FALSE; | |
2121 | ||
2122 | printf ("("); | |
2123 | while (uvalue) | |
2124 | { | |
2125 | unsigned char discriminant; | |
2126 | unsigned int bytes_read; | |
2127 | ||
2128 | SAFE_BYTE_GET (discriminant, data, 1, end); | |
2129 | -- uvalue; | |
2130 | data ++; | |
2131 | ||
2132 | assert (uvalue > 0); | |
2133 | switch (discriminant) | |
2134 | { | |
2135 | case DW_DSC_label: | |
2136 | printf ("label "); | |
2137 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2138 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2139 | uvalue -= bytes_read; | |
2140 | data += bytes_read; | |
2141 | break; | |
2142 | ||
2143 | case DW_DSC_range: | |
2144 | printf ("range "); | |
2145 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2146 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2147 | uvalue -= bytes_read; | |
2148 | data += bytes_read; | |
2149 | ||
2150 | printf (".."); | |
2151 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2152 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2153 | uvalue -= bytes_read; | |
2154 | data += bytes_read; | |
2155 | break; | |
2156 | ||
2157 | default: | |
2158 | printf ("<corrupt>\n"); | |
2159 | warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"), | |
2160 | discriminant); | |
2161 | return; | |
2162 | } | |
2163 | ||
2164 | if (uvalue) | |
2165 | printf (", "); | |
2166 | } | |
2167 | ||
2168 | if (is_signed) | |
2169 | printf (")(signed)"); | |
2170 | else | |
2171 | printf (")(unsigned)"); | |
2172 | } | |
2173 | ||
19e6b90e | 2174 | static unsigned char * |
dda8d76d NC |
2175 | read_and_display_attr_value (unsigned long attribute, |
2176 | unsigned long form, | |
2177 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 2178 | unsigned char * start, |
dda8d76d NC |
2179 | unsigned char * data, |
2180 | unsigned char * end, | |
2181 | dwarf_vma cu_offset, | |
2182 | dwarf_vma pointer_size, | |
2183 | dwarf_vma offset_size, | |
2184 | int dwarf_version, | |
2185 | debug_info * debug_info_p, | |
2186 | int do_loc, | |
2187 | struct dwarf_section * section, | |
2188 | struct cu_tu_set * this_set, | |
ec1b0fbb NC |
2189 | char delimiter, |
2190 | int level) | |
19e6b90e | 2191 | { |
cd30bcef | 2192 | dwarf_signed_vma svalue; |
ec1b0fbb NC |
2193 | dwarf_vma uvalue = 0; |
2194 | unsigned char * block_start = NULL; | |
2195 | unsigned char * orig_data = data; | |
19e6b90e | 2196 | |
f41e4712 | 2197 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 2198 | { |
f41e4712 | 2199 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
2200 | return data; |
2201 | } | |
2202 | ||
19e6b90e L |
2203 | switch (form) |
2204 | { | |
2205 | default: | |
2206 | break; | |
2207 | ||
2208 | case DW_FORM_ref_addr: | |
2209 | if (dwarf_version == 2) | |
0c588247 | 2210 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
ec47b32a | 2211 | else if (dwarf_version > 2) |
0c588247 | 2212 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 2213 | else |
ec47b32a | 2214 | error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n")); |
19e6b90e L |
2215 | break; |
2216 | ||
2217 | case DW_FORM_addr: | |
0c588247 | 2218 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
2219 | break; |
2220 | ||
2221 | case DW_FORM_strp: | |
77145576 | 2222 | case DW_FORM_line_strp: |
932fd279 | 2223 | case DW_FORM_sec_offset: |
a081f3cd JJ |
2224 | case DW_FORM_GNU_ref_alt: |
2225 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 2226 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
2227 | break; |
2228 | ||
932fd279 JJ |
2229 | case DW_FORM_flag_present: |
2230 | uvalue = 1; | |
2231 | break; | |
2232 | ||
19e6b90e L |
2233 | case DW_FORM_ref1: |
2234 | case DW_FORM_flag: | |
2235 | case DW_FORM_data1: | |
0c588247 | 2236 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
2237 | break; |
2238 | ||
2239 | case DW_FORM_ref2: | |
2240 | case DW_FORM_data2: | |
0c588247 | 2241 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
2242 | break; |
2243 | ||
2244 | case DW_FORM_ref4: | |
2245 | case DW_FORM_data4: | |
0c588247 | 2246 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
2247 | break; |
2248 | ||
2249 | case DW_FORM_sdata: | |
cd30bcef AM |
2250 | READ_SLEB (svalue, data, end); |
2251 | uvalue = svalue; | |
19e6b90e L |
2252 | break; |
2253 | ||
4723351a | 2254 | case DW_FORM_GNU_str_index: |
19e6b90e L |
2255 | case DW_FORM_ref_udata: |
2256 | case DW_FORM_udata: | |
cd30bcef AM |
2257 | case DW_FORM_GNU_addr_index: |
2258 | READ_ULEB (uvalue, data, end); | |
19e6b90e L |
2259 | break; |
2260 | ||
2261 | case DW_FORM_indirect: | |
cd30bcef | 2262 | READ_ULEB (form, data, end); |
19e6b90e | 2263 | if (!do_loc) |
ef0b5f1c | 2264 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 | 2265 | if (form == DW_FORM_implicit_const) |
cd30bcef | 2266 | READ_SLEB (implicit_const, data, end); |
ec1b0fbb NC |
2267 | return read_and_display_attr_value (attribute, form, implicit_const, |
2268 | start, data, end, | |
2269 | cu_offset, pointer_size, | |
19e6b90e | 2270 | offset_size, dwarf_version, |
ec4d4525 | 2271 | debug_info_p, do_loc, |
ec1b0fbb | 2272 | section, this_set, delimiter, level); |
19e6b90e L |
2273 | } |
2274 | ||
2275 | switch (form) | |
2276 | { | |
2277 | case DW_FORM_ref_addr: | |
2278 | if (!do_loc) | |
ef0b5f1c | 2279 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
19e6b90e L |
2280 | break; |
2281 | ||
a081f3cd JJ |
2282 | case DW_FORM_GNU_ref_alt: |
2283 | if (!do_loc) | |
ef0b5f1c | 2284 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
dda8d76d | 2285 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
2286 | break; |
2287 | ||
19e6b90e L |
2288 | case DW_FORM_ref1: |
2289 | case DW_FORM_ref2: | |
2290 | case DW_FORM_ref4: | |
2291 | case DW_FORM_ref_udata: | |
2292 | if (!do_loc) | |
ef0b5f1c | 2293 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
2294 | break; |
2295 | ||
2296 | case DW_FORM_data4: | |
2297 | case DW_FORM_addr: | |
932fd279 | 2298 | case DW_FORM_sec_offset: |
19e6b90e | 2299 | if (!do_loc) |
ef0b5f1c | 2300 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2301 | break; |
2302 | ||
932fd279 | 2303 | case DW_FORM_flag_present: |
19e6b90e L |
2304 | case DW_FORM_flag: |
2305 | case DW_FORM_data1: | |
2306 | case DW_FORM_data2: | |
2307 | case DW_FORM_sdata: | |
2308 | case DW_FORM_udata: | |
2309 | if (!do_loc) | |
ef0b5f1c | 2310 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
2311 | break; |
2312 | ||
77145576 JK |
2313 | case DW_FORM_implicit_const: |
2314 | if (!do_loc) | |
2315 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
2316 | break; | |
2317 | ||
19e6b90e L |
2318 | case DW_FORM_ref8: |
2319 | case DW_FORM_data8: | |
2bc8690c | 2320 | if (!do_loc) |
19e6b90e | 2321 | { |
74bc6052 | 2322 | dwarf_vma high_bits; |
a69c4772 | 2323 | dwarf_vma utmp; |
74bc6052 CC |
2324 | char buf[64]; |
2325 | ||
0c588247 | 2326 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
2327 | utmp = uvalue; |
2328 | if (form == DW_FORM_ref8) | |
2329 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 2330 | printf ("%c0x%s", delimiter, |
a69c4772 | 2331 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 2332 | } |
0c588247 | 2333 | |
19e6b90e L |
2334 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2335 | && num_debug_info_entries == 0) | |
2336 | { | |
2337 | if (sizeof (uvalue) == 8) | |
0c588247 | 2338 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 2339 | else |
467c65bc | 2340 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 2341 | } |
0c588247 | 2342 | |
19e6b90e L |
2343 | data += 8; |
2344 | break; | |
2345 | ||
2f6cd591 JK |
2346 | case DW_FORM_data16: |
2347 | if (!do_loc) | |
2348 | { | |
2349 | dwarf_vma left_high_bits, left_low_bits; | |
2350 | dwarf_vma right_high_bits, right_low_bits; | |
2351 | ||
2352 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
2353 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
2354 | if (byte_get == byte_get_little_endian) | |
2355 | { | |
2356 | /* Swap them. */ | |
2357 | left_high_bits ^= right_high_bits; | |
2358 | right_high_bits ^= left_high_bits; | |
2359 | left_high_bits ^= right_high_bits; | |
2360 | left_low_bits ^= right_low_bits; | |
2361 | right_low_bits ^= left_low_bits; | |
2362 | left_low_bits ^= right_low_bits; | |
2363 | } | |
2364 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
2365 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
2366 | left_high_bits, left_low_bits, right_high_bits, | |
2367 | right_low_bits); | |
2368 | } | |
2369 | data += 16; | |
2370 | break; | |
2371 | ||
19e6b90e L |
2372 | case DW_FORM_string: |
2373 | if (!do_loc) | |
ef0b5f1c | 2374 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 2375 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
2376 | break; |
2377 | ||
2378 | case DW_FORM_block: | |
932fd279 | 2379 | case DW_FORM_exprloc: |
cd30bcef AM |
2380 | READ_ULEB (uvalue, data, end); |
2381 | do_block: | |
2382 | block_start = data; | |
a1165289 NC |
2383 | if (block_start >= end) |
2384 | { | |
2385 | warn (_("Block ends prematurely\n")); | |
2386 | uvalue = 0; | |
2387 | block_start = end; | |
2388 | } | |
afc72f15 NC |
2389 | |
2390 | uvalue = check_uvalue (block_start, uvalue, end); | |
2391 | ||
19e6b90e L |
2392 | if (do_loc) |
2393 | data = block_start + uvalue; | |
2394 | else | |
ef0b5f1c | 2395 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2396 | break; |
2397 | ||
2398 | case DW_FORM_block1: | |
cd30bcef AM |
2399 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2400 | goto do_block; | |
19e6b90e L |
2401 | |
2402 | case DW_FORM_block2: | |
cd30bcef AM |
2403 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2404 | goto do_block; | |
19e6b90e L |
2405 | |
2406 | case DW_FORM_block4: | |
cd30bcef AM |
2407 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2408 | goto do_block; | |
19e6b90e L |
2409 | |
2410 | case DW_FORM_strp: | |
2411 | if (!do_loc) | |
ef0b5f1c | 2412 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, |
47704ddf KT |
2413 | dwarf_vmatoa ("x", uvalue), |
2414 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
2415 | break; |
2416 | ||
77145576 JK |
2417 | case DW_FORM_line_strp: |
2418 | if (!do_loc) | |
2419 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2420 | dwarf_vmatoa ("x", uvalue), | |
2421 | fetch_indirect_line_string (uvalue)); | |
2422 | break; | |
2423 | ||
4723351a CC |
2424 | case DW_FORM_GNU_str_index: |
2425 | if (!do_loc) | |
b4eb7656 | 2426 | { |
d85bf2ba NC |
2427 | const char * suffix = strrchr (section->name, '.'); |
2428 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
b4eb7656 | 2429 | |
ef0b5f1c | 2430 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2431 | dwarf_vmatoa ("x", uvalue), |
2432 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2433 | } | |
4723351a CC |
2434 | break; |
2435 | ||
a081f3cd JJ |
2436 | case DW_FORM_GNU_strp_alt: |
2437 | if (!do_loc) | |
dda8d76d NC |
2438 | { |
2439 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2440 | dwarf_vmatoa ("x", uvalue), | |
2441 | fetch_alt_indirect_string (uvalue)); | |
2442 | } | |
a081f3cd JJ |
2443 | break; |
2444 | ||
19e6b90e L |
2445 | case DW_FORM_indirect: |
2446 | /* Handled above. */ | |
2447 | break; | |
2448 | ||
2b6f5997 CC |
2449 | case DW_FORM_ref_sig8: |
2450 | if (!do_loc) | |
2451 | { | |
74bc6052 CC |
2452 | dwarf_vma high_bits; |
2453 | char buf[64]; | |
2454 | ||
0c588247 | 2455 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
ef0b5f1c | 2456 | printf ("%csignature: 0x%s", delimiter, |
74bc6052 | 2457 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); |
2b6f5997 | 2458 | } |
74bc6052 | 2459 | data += 8; |
2b6f5997 CC |
2460 | break; |
2461 | ||
4723351a CC |
2462 | case DW_FORM_GNU_addr_index: |
2463 | if (!do_loc) | |
ef0b5f1c | 2464 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2465 | dwarf_vmatoa ("x", uvalue), |
2466 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
4723351a CC |
2467 | break; |
2468 | ||
19e6b90e L |
2469 | default: |
2470 | warn (_("Unrecognized form: %lu\n"), form); | |
2471 | break; | |
2472 | } | |
2473 | ||
19e6b90e | 2474 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2475 | && num_debug_info_entries == 0 |
2476 | && debug_info_p != NULL) | |
19e6b90e L |
2477 | { |
2478 | switch (attribute) | |
2479 | { | |
2480 | case DW_AT_frame_base: | |
2481 | have_frame_base = 1; | |
1a0670f3 | 2482 | /* Fall through. */ |
19e6b90e | 2483 | case DW_AT_location: |
9f272209 | 2484 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2485 | case DW_AT_string_length: |
2486 | case DW_AT_return_addr: | |
19e6b90e L |
2487 | case DW_AT_data_member_location: |
2488 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2489 | case DW_AT_segment: |
2490 | case DW_AT_static_link: | |
2491 | case DW_AT_use_location: | |
bc0a77d2 | 2492 | case DW_AT_call_value: |
629e7ca8 | 2493 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2494 | case DW_AT_call_data_value: |
629e7ca8 | 2495 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2496 | case DW_AT_call_target: |
629e7ca8 | 2497 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2498 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2499 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2500 | if ((dwarf_version < 4 |
212b6063 | 2501 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2502 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2503 | { |
2504 | /* Process location list. */ | |
91d6fa6a | 2505 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2506 | unsigned int num = debug_info_p->num_loc_offsets; |
2507 | ||
91d6fa6a | 2508 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2509 | { |
91d6fa6a | 2510 | lmax += 1024; |
467c65bc | 2511 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2512 | xcrealloc (debug_info_p->loc_offsets, |
2513 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2514 | debug_info_p->loc_views = (dwarf_vma *) |
2515 | xcrealloc (debug_info_p->loc_views, | |
2516 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2517 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2518 | xcrealloc (debug_info_p->have_frame_base, |
2519 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2520 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2521 | } |
341f9135 | 2522 | if (this_set != NULL) |
b4eb7656 | 2523 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2524 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2525 | if (attribute != DW_AT_GNU_locviews) |
2526 | { | |
a7504f87 NC |
2527 | /* Corrupt DWARF info can produce more offsets than views. |
2528 | See PR 23062 for an example. */ | |
2529 | if (debug_info_p->num_loc_offsets | |
2530 | > debug_info_p->num_loc_views) | |
2531 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2532 | else | |
2533 | { | |
2534 | debug_info_p->loc_offsets [num] = uvalue; | |
2535 | debug_info_p->num_loc_offsets++; | |
2536 | } | |
9f272209 AO |
2537 | } |
2538 | else | |
2539 | { | |
2540 | assert (debug_info_p->num_loc_views <= num); | |
2541 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2542 | if (num > debug_info_p->num_loc_offsets) |
2543 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2544 | else | |
2545 | { | |
2546 | debug_info_p->loc_views [num] = uvalue; | |
2547 | debug_info_p->num_loc_views++; | |
2548 | } | |
9f272209 | 2549 | } |
19e6b90e L |
2550 | } |
2551 | break; | |
e2a0d921 | 2552 | |
19e6b90e L |
2553 | case DW_AT_low_pc: |
2554 | if (need_base_address) | |
2555 | debug_info_p->base_address = uvalue; | |
2556 | break; | |
2557 | ||
4723351a | 2558 | case DW_AT_GNU_addr_base: |
b4eb7656 | 2559 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2560 | break; |
2561 | ||
2562 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2563 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2564 | break; |
2565 | ||
19e6b90e | 2566 | case DW_AT_ranges: |
b4eb7656 | 2567 | if ((dwarf_version < 4 |
212b6063 | 2568 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2569 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2570 | { |
2571 | /* Process range list. */ | |
91d6fa6a | 2572 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2573 | unsigned int num = debug_info_p->num_range_lists; |
2574 | ||
91d6fa6a | 2575 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2576 | { |
91d6fa6a | 2577 | lmax += 1024; |
467c65bc | 2578 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2579 | xcrealloc (debug_info_p->range_lists, |
2580 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2581 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2582 | } |
2583 | debug_info_p->range_lists [num] = uvalue; | |
2584 | debug_info_p->num_range_lists++; | |
2585 | } | |
2586 | break; | |
2587 | ||
d85bf2ba NC |
2588 | case DW_AT_GNU_dwo_name: |
2589 | case DW_AT_dwo_name: | |
2590 | if (need_dwo_info) | |
2591 | switch (form) | |
2592 | { | |
2593 | case DW_FORM_strp: | |
24841daa | 2594 | add_dwo_name ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba | 2595 | break; |
5568cc9e NC |
2596 | case DW_FORM_GNU_strp_alt: |
2597 | add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue)); | |
2598 | break; | |
d85bf2ba | 2599 | case DW_FORM_GNU_str_index: |
24841daa | 2600 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2601 | break; |
2602 | case DW_FORM_string: | |
24841daa | 2603 | add_dwo_name ((const char *) orig_data); |
d85bf2ba NC |
2604 | break; |
2605 | default: | |
2606 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2607 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2608 | break; |
2609 | } | |
2610 | break; | |
2611 | ||
2612 | case DW_AT_comp_dir: | |
2613 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2614 | if (need_dwo_info) | |
2615 | switch (form) | |
2616 | { | |
2617 | case DW_FORM_strp: | |
24841daa | 2618 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba | 2619 | break; |
5568cc9e NC |
2620 | case DW_FORM_GNU_strp_alt: |
2621 | add_dwo_dir (fetch_alt_indirect_string (uvalue)); | |
2622 | break; | |
d85bf2ba | 2623 | case DW_FORM_line_strp: |
24841daa | 2624 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue)); |
d85bf2ba NC |
2625 | break; |
2626 | case DW_FORM_GNU_str_index: | |
24841daa | 2627 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2628 | break; |
2629 | case DW_FORM_string: | |
24841daa | 2630 | add_dwo_dir ((const char *) orig_data); |
d85bf2ba NC |
2631 | break; |
2632 | default: | |
2633 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2634 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2635 | break; |
2636 | } | |
2637 | break; | |
2638 | ||
2639 | case DW_AT_GNU_dwo_id: | |
2640 | if (need_dwo_info) | |
2641 | switch (form) | |
2642 | { | |
2643 | case DW_FORM_data8: | |
24841daa NC |
2644 | /* FIXME: Record the length of the ID as well ? */ |
2645 | add_dwo_id ((const char *) (data - 8)); | |
d85bf2ba NC |
2646 | break; |
2647 | default: | |
2648 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2649 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2650 | break; |
2651 | } | |
2652 | break; | |
2653 | ||
19e6b90e L |
2654 | default: |
2655 | break; | |
2656 | } | |
2657 | } | |
2658 | ||
4ccf1e31 | 2659 | if (do_loc || attribute == 0) |
19e6b90e L |
2660 | return data; |
2661 | ||
ec4d4525 | 2662 | /* For some attributes we can display further information. */ |
19e6b90e L |
2663 | switch (attribute) |
2664 | { | |
ec1b0fbb | 2665 | case DW_AT_type: |
b3fe587e AM |
2666 | if (level >= 0 && level < MAX_CU_NESTING |
2667 | && uvalue < (size_t) (end - start)) | |
ec1b0fbb NC |
2668 | { |
2669 | bfd_boolean is_signed = FALSE; | |
2670 | ||
59624513 NC |
2671 | /* We cannot correctly process DW_FORM_ref_addr at the moment. */ |
2672 | if (form != DW_FORM_ref_addr) | |
2673 | get_type_signedness (start, start + uvalue, end, pointer_size, | |
2674 | offset_size, dwarf_version, & is_signed, 0); | |
ec1b0fbb NC |
2675 | level_type_signed[level] = is_signed; |
2676 | } | |
2677 | break; | |
2678 | ||
19e6b90e | 2679 | case DW_AT_inline: |
2e9e81a8 | 2680 | printf ("\t"); |
19e6b90e L |
2681 | switch (uvalue) |
2682 | { | |
2683 | case DW_INL_not_inlined: | |
2684 | printf (_("(not inlined)")); | |
2685 | break; | |
2686 | case DW_INL_inlined: | |
2687 | printf (_("(inlined)")); | |
2688 | break; | |
2689 | case DW_INL_declared_not_inlined: | |
2690 | printf (_("(declared as inline but ignored)")); | |
2691 | break; | |
2692 | case DW_INL_declared_inlined: | |
2693 | printf (_("(declared as inline and inlined)")); | |
2694 | break; | |
2695 | default: | |
47704ddf KT |
2696 | printf (_(" (Unknown inline attribute value: %s)"), |
2697 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
2698 | break; |
2699 | } | |
2700 | break; | |
2701 | ||
2702 | case DW_AT_language: | |
2e9e81a8 | 2703 | printf ("\t"); |
19e6b90e L |
2704 | switch (uvalue) |
2705 | { | |
4b78141a | 2706 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 2707 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
2708 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
2709 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 2710 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
2711 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
2712 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
2713 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
2714 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 2715 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 2716 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 2717 | /* DWARF 2.1 values. */ |
4b78141a | 2718 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
2719 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
2720 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
2721 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
2722 | /* DWARF 3 values. */ |
2723 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
2724 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
2725 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
2726 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
2727 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
2728 | /* DWARF 4 values. */ |
2729 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 2730 | /* DWARF 5 values. */ |
2008a0db | 2731 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 2732 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
2733 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
2734 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
2735 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 2736 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
2737 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
2738 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 2739 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
2740 | case DW_LANG_Swift: printf ("(Swift)"); break; |
2741 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
2742 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 2743 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
2744 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
2745 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 2746 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
2747 | /* MIPS extension. */ |
2748 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
2749 | /* UPC extension. */ | |
2750 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
2751 | default: | |
4b78141a | 2752 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 2753 | printf (_("(implementation defined: %s)"), |
467c65bc | 2754 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 2755 | else |
9cf03b7e | 2756 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2757 | break; |
2758 | } | |
2759 | break; | |
2760 | ||
2761 | case DW_AT_encoding: | |
2e9e81a8 | 2762 | printf ("\t"); |
19e6b90e L |
2763 | switch (uvalue) |
2764 | { | |
2765 | case DW_ATE_void: printf ("(void)"); break; | |
2766 | case DW_ATE_address: printf ("(machine address)"); break; | |
2767 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
2768 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
2769 | case DW_ATE_float: printf ("(float)"); break; | |
2770 | case DW_ATE_signed: printf ("(signed)"); break; | |
2771 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
2772 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
2773 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 2774 | /* DWARF 2.1 values: */ |
19e6b90e L |
2775 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
2776 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
2777 | /* DWARF 3 values: */ |
2778 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
2779 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
2780 | case DW_ATE_edited: printf ("(edited)"); break; | |
2781 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
2782 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
2783 | /* DWARF 4 values: */ |
2784 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
2785 | /* DWARF 5 values: */ | |
2786 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
2787 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
2788 | ||
e2a0d921 NC |
2789 | /* HP extensions: */ |
2790 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
2791 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
2792 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
2793 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
2794 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
2795 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
2796 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
2797 | ||
19e6b90e L |
2798 | default: |
2799 | if (uvalue >= DW_ATE_lo_user | |
2800 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 2801 | printf (_("(user defined type)")); |
19e6b90e | 2802 | else |
9cf03b7e | 2803 | printf (_("(unknown type)")); |
19e6b90e L |
2804 | break; |
2805 | } | |
2806 | break; | |
2807 | ||
2808 | case DW_AT_accessibility: | |
2e9e81a8 | 2809 | printf ("\t"); |
19e6b90e L |
2810 | switch (uvalue) |
2811 | { | |
2812 | case DW_ACCESS_public: printf ("(public)"); break; | |
2813 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
2814 | case DW_ACCESS_private: printf ("(private)"); break; | |
2815 | default: | |
9cf03b7e | 2816 | printf (_("(unknown accessibility)")); |
19e6b90e L |
2817 | break; |
2818 | } | |
2819 | break; | |
2820 | ||
2821 | case DW_AT_visibility: | |
2e9e81a8 | 2822 | printf ("\t"); |
19e6b90e L |
2823 | switch (uvalue) |
2824 | { | |
2825 | case DW_VIS_local: printf ("(local)"); break; | |
2826 | case DW_VIS_exported: printf ("(exported)"); break; | |
2827 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 2828 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
2829 | } |
2830 | break; | |
2831 | ||
04914e37 NC |
2832 | case DW_AT_endianity: |
2833 | printf ("\t"); | |
2834 | switch (uvalue) | |
2835 | { | |
2836 | case DW_END_default: printf ("(default)"); break; | |
2837 | case DW_END_big: printf ("(big)"); break; | |
2838 | case DW_END_little: printf ("(little)"); break; | |
2839 | default: | |
2840 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
2841 | printf (_("(user specified)")); | |
2842 | else | |
2843 | printf (_("(unknown endianity)")); | |
2844 | break; | |
2845 | } | |
2846 | break; | |
2847 | ||
19e6b90e | 2848 | case DW_AT_virtuality: |
2e9e81a8 | 2849 | printf ("\t"); |
19e6b90e L |
2850 | switch (uvalue) |
2851 | { | |
2852 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
2853 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
2854 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 2855 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
2856 | } |
2857 | break; | |
2858 | ||
2859 | case DW_AT_identifier_case: | |
2e9e81a8 | 2860 | printf ("\t"); |
19e6b90e L |
2861 | switch (uvalue) |
2862 | { | |
2863 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
2864 | case DW_ID_up_case: printf ("(up_case)"); break; | |
2865 | case DW_ID_down_case: printf ("(down_case)"); break; | |
2866 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 2867 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
2868 | } |
2869 | break; | |
2870 | ||
2871 | case DW_AT_calling_convention: | |
2e9e81a8 | 2872 | printf ("\t"); |
19e6b90e L |
2873 | switch (uvalue) |
2874 | { | |
2875 | case DW_CC_normal: printf ("(normal)"); break; | |
2876 | case DW_CC_program: printf ("(program)"); break; | |
2877 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
2878 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
2879 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
2880 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
2881 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
2882 | default: |
2883 | if (uvalue >= DW_CC_lo_user | |
2884 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 2885 | printf (_("(user defined)")); |
19e6b90e | 2886 | else |
9cf03b7e | 2887 | printf (_("(unknown convention)")); |
19e6b90e L |
2888 | } |
2889 | break; | |
2890 | ||
2891 | case DW_AT_ordering: | |
2e9e81a8 | 2892 | printf ("\t"); |
19e6b90e L |
2893 | switch (uvalue) |
2894 | { | |
04914e37 | 2895 | case 255: |
9cf03b7e | 2896 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
2897 | case 0: printf ("(row major)"); break; |
2898 | case 1: printf ("(column major)"); break; | |
2899 | } | |
2900 | break; | |
2901 | ||
04914e37 NC |
2902 | case DW_AT_decimal_sign: |
2903 | printf ("\t"); | |
2904 | switch (uvalue) | |
2905 | { | |
2906 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
2907 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
2908 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
2909 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
2910 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
2911 | default: printf (_("(unrecognised)")); break; | |
2912 | } | |
2913 | break; | |
2914 | ||
2915 | case DW_AT_defaulted: | |
2916 | printf ("\t"); | |
2917 | switch (uvalue) | |
2918 | { | |
2919 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
2920 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
2921 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
2922 | default: printf (_("(unrecognised)")); break; | |
2923 | } | |
2924 | break; | |
2925 | ||
2926 | case DW_AT_discr_list: | |
2927 | printf ("\t"); | |
ec1b0fbb | 2928 | display_discr_list (form, uvalue, data, end, level); |
04914e37 NC |
2929 | break; |
2930 | ||
19e6b90e L |
2931 | case DW_AT_frame_base: |
2932 | have_frame_base = 1; | |
1a0670f3 | 2933 | /* Fall through. */ |
19e6b90e | 2934 | case DW_AT_location: |
e2a0d921 NC |
2935 | case DW_AT_string_length: |
2936 | case DW_AT_return_addr: | |
19e6b90e L |
2937 | case DW_AT_data_member_location: |
2938 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2939 | case DW_AT_segment: |
2940 | case DW_AT_static_link: | |
2941 | case DW_AT_use_location: | |
bc0a77d2 | 2942 | case DW_AT_call_value: |
629e7ca8 | 2943 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2944 | case DW_AT_call_data_value: |
629e7ca8 | 2945 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2946 | case DW_AT_call_target: |
629e7ca8 | 2947 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2948 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2949 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 2950 | if ((dwarf_version < 4 |
b4eb7656 | 2951 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2952 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 2953 | printf (_(" (location list)")); |
e2a0d921 | 2954 | /* Fall through. */ |
19e6b90e L |
2955 | case DW_AT_allocated: |
2956 | case DW_AT_associated: | |
2957 | case DW_AT_data_location: | |
2958 | case DW_AT_stride: | |
2959 | case DW_AT_upper_bound: | |
cecf136e | 2960 | case DW_AT_lower_bound: |
19e6b90e L |
2961 | if (block_start) |
2962 | { | |
2963 | int need_frame_base; | |
2964 | ||
2e9e81a8 | 2965 | printf ("\t("); |
19e6b90e L |
2966 | need_frame_base = decode_location_expression (block_start, |
2967 | pointer_size, | |
b7807392 JJ |
2968 | offset_size, |
2969 | dwarf_version, | |
19e6b90e | 2970 | uvalue, |
f1c4cc75 | 2971 | cu_offset, section); |
19e6b90e L |
2972 | printf (")"); |
2973 | if (need_frame_base && !have_frame_base) | |
2974 | printf (_(" [without DW_AT_frame_base]")); | |
2975 | } | |
19e6b90e L |
2976 | break; |
2977 | ||
c54207d3 NC |
2978 | case DW_AT_data_bit_offset: |
2979 | case DW_AT_byte_size: | |
2980 | case DW_AT_bit_size: | |
2981 | case DW_AT_string_length_byte_size: | |
2982 | case DW_AT_string_length_bit_size: | |
2983 | case DW_AT_bit_stride: | |
2984 | if (form == DW_FORM_exprloc) | |
2985 | { | |
2986 | printf ("\t("); | |
2987 | (void) decode_location_expression (block_start, pointer_size, | |
2988 | offset_size, dwarf_version, | |
2989 | uvalue, cu_offset, section); | |
2990 | printf (")"); | |
2991 | } | |
2992 | break; | |
2993 | ||
ec4d4525 NC |
2994 | case DW_AT_import: |
2995 | { | |
a081f3cd JJ |
2996 | if (form == DW_FORM_ref_sig8 |
2997 | || form == DW_FORM_GNU_ref_alt) | |
b4eb7656 | 2998 | break; |
2b6f5997 | 2999 | |
ec4d4525 NC |
3000 | if (form == DW_FORM_ref1 |
3001 | || form == DW_FORM_ref2 | |
a7a0b6a5 JK |
3002 | || form == DW_FORM_ref4 |
3003 | || form == DW_FORM_ref_udata) | |
ec4d4525 NC |
3004 | uvalue += cu_offset; |
3005 | ||
6e3d6dc1 | 3006 | if (uvalue >= section->size) |
f3853b34 | 3007 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), |
47704ddf KT |
3008 | dwarf_vmatoa ("x", uvalue), |
3009 | (unsigned long) (orig_data - section->start)); | |
6e3d6dc1 NC |
3010 | else |
3011 | { | |
3012 | unsigned long abbrev_number; | |
cd30bcef AM |
3013 | abbrev_entry *entry; |
3014 | unsigned char *p = section->start + uvalue; | |
6e3d6dc1 | 3015 | |
cd30bcef | 3016 | READ_ULEB (abbrev_number, p, end); |
cecf136e | 3017 | |
2e9e81a8 | 3018 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
afd6e1ff JJ |
3019 | /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
3020 | use different abbrev table, and we don't track .debug_info chunks | |
3021 | yet. */ | |
3022 | if (form != DW_FORM_ref_addr) | |
3023 | { | |
3024 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
3025 | if (entry->entry == abbrev_number) | |
3026 | break; | |
3027 | if (entry != NULL) | |
3028 | printf (" (%s)", get_TAG_name (entry->tag)); | |
3029 | } | |
6e3d6dc1 NC |
3030 | printf ("]"); |
3031 | } | |
ec4d4525 NC |
3032 | } |
3033 | break; | |
3034 | ||
19e6b90e L |
3035 | default: |
3036 | break; | |
3037 | } | |
3038 | ||
3039 | return data; | |
3040 | } | |
3041 | ||
19e6b90e | 3042 | static unsigned char * |
dda8d76d NC |
3043 | read_and_display_attr (unsigned long attribute, |
3044 | unsigned long form, | |
3045 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 3046 | unsigned char * start, |
dda8d76d NC |
3047 | unsigned char * data, |
3048 | unsigned char * end, | |
3049 | dwarf_vma cu_offset, | |
3050 | dwarf_vma pointer_size, | |
3051 | dwarf_vma offset_size, | |
3052 | int dwarf_version, | |
3053 | debug_info * debug_info_p, | |
3054 | int do_loc, | |
3055 | struct dwarf_section * section, | |
ec1b0fbb NC |
3056 | struct cu_tu_set * this_set, |
3057 | int level) | |
19e6b90e L |
3058 | { |
3059 | if (!do_loc) | |
750f03b7 | 3060 | printf (" %-18s:", get_AT_name (attribute)); |
ec1b0fbb NC |
3061 | data = read_and_display_attr_value (attribute, form, implicit_const, |
3062 | start, data, end, | |
f6f0e17b | 3063 | cu_offset, pointer_size, offset_size, |
19e6b90e | 3064 | dwarf_version, debug_info_p, |
ec1b0fbb | 3065 | do_loc, section, this_set, ' ', level); |
19e6b90e L |
3066 | if (!do_loc) |
3067 | printf ("\n"); | |
3068 | return data; | |
3069 | } | |
3070 | ||
dda8d76d | 3071 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
3072 | following debug links, then attempt to load the requested section |
3073 | from one of the separate debug info files. */ | |
dda8d76d NC |
3074 | |
3075 | static bfd_boolean | |
3076 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, | |
24841daa | 3077 | void * handle) |
dda8d76d | 3078 | { |
24841daa | 3079 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 3080 | { |
24841daa NC |
3081 | if (debug_displays[sec_enum].section.filename == NULL) |
3082 | { | |
3083 | /* See if we can associate a filename with this section. */ | |
3084 | separate_info * i; | |
3085 | ||
3086 | for (i = first_separate_info; i != NULL; i = i->next) | |
3087 | if (i->handle == handle) | |
3088 | { | |
3089 | debug_displays[sec_enum].section.filename = i->filename; | |
3090 | break; | |
3091 | } | |
3092 | } | |
3093 | ||
dda8d76d NC |
3094 | return TRUE; |
3095 | } | |
3096 | ||
24841daa NC |
3097 | if (do_follow_links) |
3098 | { | |
3099 | separate_info * i; | |
3100 | ||
3101 | for (i = first_separate_info; i != NULL; i = i->next) | |
3102 | { | |
3103 | if (load_debug_section (sec_enum, i->handle)) | |
3104 | { | |
3105 | debug_displays[sec_enum].section.filename = i->filename; | |
3106 | ||
3107 | /* FIXME: We should check to see if any of the remaining debug info | |
3108 | files also contain this section, and, umm, do something about it. */ | |
3109 | return TRUE; | |
3110 | } | |
3111 | } | |
3112 | } | |
dda8d76d NC |
3113 | |
3114 | return FALSE; | |
3115 | } | |
3116 | ||
3117 | static void | |
3118 | introduce (struct dwarf_section * section, bfd_boolean raw) | |
3119 | { | |
3120 | if (raw) | |
3121 | { | |
3122 | if (do_follow_links && section->filename) | |
3123 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
3124 | section->name, section->filename); | |
3125 | else | |
3126 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
3127 | } | |
3128 | else | |
3129 | { | |
3130 | if (do_follow_links && section->filename) | |
3131 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
3132 | section->name, section->filename); | |
3133 | else | |
3134 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3135 | } | |
3136 | } | |
3137 | ||
d85bf2ba NC |
3138 | /* Process the contents of a .debug_info section. |
3139 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
3140 | and we do not want to display anything to the user. | |
3141 | If do_types is TRUE, we are processing a .debug_types section instead of | |
3142 | a .debug_info section. | |
3143 | The information displayed is restricted by the values in DWARF_START_DIE | |
3144 | and DWARF_CUTOFF_LEVEL. | |
3145 | Returns TRUE upon success. Otherwise an error or warning message is | |
3146 | printed and FALSE is returned. */ | |
19e6b90e | 3147 | |
d85bf2ba NC |
3148 | static bfd_boolean |
3149 | process_debug_info (struct dwarf_section * section, | |
3150 | void * file, | |
3151 | enum dwarf_section_display_enum abbrev_sec, | |
3152 | bfd_boolean do_loc, | |
3153 | bfd_boolean do_types) | |
19e6b90e L |
3154 | { |
3155 | unsigned char *start = section->start; | |
3156 | unsigned char *end = start + section->size; | |
3157 | unsigned char *section_begin; | |
3158 | unsigned int unit; | |
3159 | unsigned int num_units = 0; | |
3160 | ||
3161 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3162 | && num_debug_info_entries == 0 |
3163 | && ! do_types) | |
19e6b90e | 3164 | { |
767221a9 | 3165 | dwarf_vma length; |
19e6b90e L |
3166 | |
3167 | /* First scan the section to get the number of comp units. */ | |
3168 | for (section_begin = start, num_units = 0; section_begin < end; | |
3169 | num_units ++) | |
3170 | { | |
3171 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
3172 | will be the length. For a 64-bit DWARF section, it'll be | |
3173 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 3174 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
3175 | |
3176 | if (length == 0xffffffff) | |
3177 | { | |
0c588247 | 3178 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
3179 | section_begin += length + 12; |
3180 | } | |
ec4d4525 NC |
3181 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
3182 | { | |
767221a9 NC |
3183 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
3184 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3185 | return FALSE; |
ec4d4525 | 3186 | } |
19e6b90e L |
3187 | else |
3188 | section_begin += length + 4; | |
aca88567 NC |
3189 | |
3190 | /* Negative values are illegal, they may even cause infinite | |
3191 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
3192 | relocations to an object file, or if the file is corrupt. */ |
3193 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 3194 | { |
767221a9 NC |
3195 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
3196 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3197 | return FALSE; |
aca88567 | 3198 | } |
19e6b90e L |
3199 | } |
3200 | ||
3201 | if (num_units == 0) | |
3202 | { | |
f41e4712 | 3203 | error (_("No comp units in %s section ?\n"), section->name); |
d85bf2ba | 3204 | return FALSE; |
19e6b90e L |
3205 | } |
3206 | ||
3207 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 3208 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 3209 | sizeof (* debug_information)); |
19e6b90e L |
3210 | if (debug_information == NULL) |
3211 | { | |
f41e4712 | 3212 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 3213 | num_units); |
82b1b41b | 3214 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
d85bf2ba | 3215 | return FALSE; |
19e6b90e | 3216 | } |
d85bf2ba | 3217 | |
03a91817 NC |
3218 | /* PR 17531: file: 92ca3797. |
3219 | We cannot rely upon the debug_information array being initialised | |
3220 | before it is used. A corrupt file could easily contain references | |
3221 | to a unit for which information has not been made available. So | |
3222 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
3223 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
3224 | ||
82b1b41b | 3225 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
3226 | } |
3227 | ||
3228 | if (!do_loc) | |
3229 | { | |
dda8d76d NC |
3230 | load_debug_section_with_follow (str, file); |
3231 | load_debug_section_with_follow (line_str, file); | |
3232 | load_debug_section_with_follow (str_dwo, file); | |
3233 | load_debug_section_with_follow (str_index, file); | |
3234 | load_debug_section_with_follow (str_index_dwo, file); | |
3235 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e | 3236 | } |
e4b7104b | 3237 | |
dda8d76d | 3238 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 3239 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
3240 | { |
3241 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 3242 | debug_displays [abbrev_sec].section.uncompressed_name); |
d85bf2ba | 3243 | return FALSE; |
19e6b90e L |
3244 | } |
3245 | ||
dda8d76d NC |
3246 | if (!do_loc && dwarf_start_die == 0) |
3247 | introduce (section, FALSE); | |
3248 | ||
19e6b90e L |
3249 | for (section_begin = start, unit = 0; start < end; unit++) |
3250 | { | |
3251 | DWARF2_Internal_CompUnit compunit; | |
3252 | unsigned char *hdrptr; | |
19e6b90e | 3253 | unsigned char *tags; |
fd2f0033 | 3254 | int level, last_level, saved_level; |
467c65bc | 3255 | dwarf_vma cu_offset; |
e98fdf1a | 3256 | unsigned long sec_off; |
bf5117e3 | 3257 | unsigned int offset_size; |
19485196 | 3258 | unsigned int initial_length_size; |
74bc6052 CC |
3259 | dwarf_vma signature_high = 0; |
3260 | dwarf_vma signature_low = 0; | |
767221a9 | 3261 | dwarf_vma type_offset = 0; |
341f9135 CC |
3262 | struct cu_tu_set *this_set; |
3263 | dwarf_vma abbrev_base; | |
3264 | size_t abbrev_size; | |
19e6b90e L |
3265 | |
3266 | hdrptr = start; | |
3267 | ||
0c588247 | 3268 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
3269 | |
3270 | if (compunit.cu_length == 0xffffffff) | |
3271 | { | |
0c588247 | 3272 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
3273 | offset_size = 8; |
3274 | initial_length_size = 12; | |
3275 | } | |
3276 | else | |
3277 | { | |
3278 | offset_size = 4; | |
3279 | initial_length_size = 4; | |
3280 | } | |
3281 | ||
0c588247 | 3282 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
3283 | |
3284 | cu_offset = start - section_begin; | |
19e6b90e | 3285 | |
341f9135 CC |
3286 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3287 | ||
77145576 JK |
3288 | if (compunit.cu_version < 5) |
3289 | { | |
3290 | compunit.cu_unit_type = DW_UT_compile; | |
3291 | /* Initialize it due to a false compiler warning. */ | |
3292 | compunit.cu_pointer_size = -1; | |
3293 | } | |
3294 | else | |
3295 | { | |
3296 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3297 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3298 | ||
3299 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3300 | } | |
3301 | ||
0c588247 | 3302 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 3303 | |
341f9135 CC |
3304 | if (this_set == NULL) |
3305 | { | |
3306 | abbrev_base = 0; | |
3307 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3308 | } | |
3309 | else | |
3310 | { | |
3311 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3312 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3313 | } | |
3314 | ||
77145576 JK |
3315 | if (compunit.cu_version < 5) |
3316 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3317 | ||
f41e4712 NC |
3318 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
3319 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
3320 | { | |
3321 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
3322 | compunit.cu_pointer_size, offset_size); | |
3323 | compunit.cu_pointer_size = offset_size; | |
3324 | } | |
2b6f5997 CC |
3325 | |
3326 | if (do_types) | |
b4eb7656 | 3327 | { |
0c588247 | 3328 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 3329 | hdrptr += 8; |
0c588247 | 3330 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 3331 | } |
2b6f5997 | 3332 | |
ae7e7825 NC |
3333 | if (dwarf_start_die > (cu_offset + compunit.cu_length |
3334 | + initial_length_size)) | |
3335 | { | |
3336 | start = section_begin + cu_offset + compunit.cu_length | |
3337 | + initial_length_size; | |
3338 | continue; | |
3339 | } | |
3340 | ||
19e6b90e | 3341 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 | 3342 | && num_debug_info_entries == 0 |
c4b2f181 | 3343 | && alloc_num_debug_info_entries > unit |
2b6f5997 | 3344 | && ! do_types) |
19e6b90e L |
3345 | { |
3346 | debug_information [unit].cu_offset = cu_offset; | |
3347 | debug_information [unit].pointer_size | |
3348 | = compunit.cu_pointer_size; | |
b7807392 JJ |
3349 | debug_information [unit].offset_size = offset_size; |
3350 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 3351 | debug_information [unit].base_address = 0; |
4723351a CC |
3352 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
3353 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
3354 | debug_information [unit].loc_offsets = NULL; |
3355 | debug_information [unit].have_frame_base = NULL; | |
3356 | debug_information [unit].max_loc_offsets = 0; | |
3357 | debug_information [unit].num_loc_offsets = 0; | |
3358 | debug_information [unit].range_lists = NULL; | |
3359 | debug_information [unit].max_range_lists= 0; | |
3360 | debug_information [unit].num_range_lists = 0; | |
3361 | } | |
3362 | ||
fd2f0033 | 3363 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 3364 | { |
47704ddf KT |
3365 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3366 | dwarf_vmatoa ("x", cu_offset)); | |
3367 | printf (_(" Length: 0x%s (%s)\n"), | |
3368 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3369 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3370 | printf (_(" Version: %d\n"), compunit.cu_version); |
debd1a62 MW |
3371 | if (compunit.cu_version >= 5) |
3372 | printf (_(" Unit Type: %s (%x)\n"), | |
3373 | get_DW_UT_name (compunit.cu_unit_type) ?: "???", | |
3374 | compunit.cu_unit_type); | |
7282333f AM |
3375 | printf (_(" Abbrev Offset: 0x%s\n"), |
3376 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3377 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3378 | if (do_types) |
3379 | { | |
74bc6052 CC |
3380 | char buf[64]; |
3381 | ||
3382 | printf (_(" Signature: 0x%s\n"), | |
3383 | dwarf_vmatoa64 (signature_high, signature_low, | |
3384 | buf, sizeof (buf))); | |
3385 | printf (_(" Type Offset: 0x%s\n"), | |
3386 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3387 | } |
341f9135 CC |
3388 | if (this_set != NULL) |
3389 | { | |
3390 | dwarf_vma *offsets = this_set->section_offsets; | |
3391 | size_t *sizes = this_set->section_sizes; | |
3392 | ||
3393 | printf (_(" Section contributions:\n")); | |
3394 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3395 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3396 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3397 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3398 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3399 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3400 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3401 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3402 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3403 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3404 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3405 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3406 | } | |
19e6b90e L |
3407 | } |
3408 | ||
e98fdf1a AM |
3409 | sec_off = cu_offset + initial_length_size; |
3410 | if (sec_off + compunit.cu_length < sec_off | |
3411 | || sec_off + compunit.cu_length > section->size) | |
460c89ff | 3412 | { |
e98fdf1a AM |
3413 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
3414 | section->name, | |
3415 | (unsigned long) cu_offset, | |
19485196 NC |
3416 | dwarf_vmatoa ("x", compunit.cu_length)); |
3417 | num_units = unit; | |
3418 | break; | |
3419 | } | |
3420 | ||
460c89ff NS |
3421 | tags = hdrptr; |
3422 | start += compunit.cu_length + initial_length_size; | |
3423 | ||
77145576 | 3424 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3425 | { |
47704ddf KT |
3426 | warn (_("CU at offset %s contains corrupt or " |
3427 | "unsupported version number: %d.\n"), | |
3428 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3429 | continue; |
3430 | } | |
3431 | ||
77145576 | 3432 | if (compunit.cu_unit_type != DW_UT_compile |
ec47b32a | 3433 | && compunit.cu_unit_type != DW_UT_partial |
77145576 JK |
3434 | && compunit.cu_unit_type != DW_UT_type) |
3435 | { | |
3436 | warn (_("CU at offset %s contains corrupt or " | |
3437 | "unsupported unit type: %d.\n"), | |
3438 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3439 | continue; | |
3440 | } | |
3441 | ||
19e6b90e L |
3442 | free_abbrevs (); |
3443 | ||
d493b283 | 3444 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 3445 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
3446 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
3447 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 3448 | (unsigned long) abbrev_size); |
b4eb7656 | 3449 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
3450 | else if ((abbrev_base + abbrev_size) |
3451 | > debug_displays [abbrev_sec].section.size) | |
3452 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
3453 | (unsigned long) abbrev_base + abbrev_size, | |
3454 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff NS |
3455 | else |
3456 | process_abbrev_section | |
341f9135 CC |
3457 | (((unsigned char *) debug_displays [abbrev_sec].section.start |
3458 | + abbrev_base + compunit.cu_abbrev_offset), | |
3459 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3460 | + abbrev_base + abbrev_size)); | |
19e6b90e L |
3461 | |
3462 | level = 0; | |
fd2f0033 TT |
3463 | last_level = level; |
3464 | saved_level = -1; | |
19e6b90e L |
3465 | while (tags < start) |
3466 | { | |
19e6b90e | 3467 | unsigned long abbrev_number; |
ec4d4525 | 3468 | unsigned long die_offset; |
19e6b90e L |
3469 | abbrev_entry *entry; |
3470 | abbrev_attr *attr; | |
fd2f0033 | 3471 | int do_printing = 1; |
19e6b90e | 3472 | |
ec4d4525 NC |
3473 | die_offset = tags - section_begin; |
3474 | ||
cd30bcef | 3475 | READ_ULEB (abbrev_number, tags, start); |
19e6b90e | 3476 | |
eb7cc021 JK |
3477 | /* A null DIE marks the end of a list of siblings or it may also be |
3478 | a section padding. */ | |
19e6b90e L |
3479 | if (abbrev_number == 0) |
3480 | { | |
eb7cc021 JK |
3481 | /* Check if it can be a section padding for the last CU. */ |
3482 | if (level == 0 && start == end) | |
3483 | { | |
3484 | unsigned char *chk; | |
3485 | ||
3486 | for (chk = tags; chk < start; chk++) | |
3487 | if (*chk != 0) | |
3488 | break; | |
3489 | if (chk == start) | |
3490 | break; | |
3491 | } | |
3492 | ||
4337774f TT |
3493 | if (!do_loc && die_offset >= dwarf_start_die |
3494 | && (dwarf_cutoff_level == -1 | |
3495 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3496 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3497 | level, die_offset); | |
3498 | ||
19e6b90e | 3499 | --level; |
ec4d4525 NC |
3500 | if (level < 0) |
3501 | { | |
3502 | static unsigned num_bogus_warns = 0; | |
3503 | ||
3504 | if (num_bogus_warns < 3) | |
3505 | { | |
4723351a CC |
3506 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3507 | die_offset, section->name); | |
ec4d4525 NC |
3508 | num_bogus_warns ++; |
3509 | if (num_bogus_warns == 3) | |
3510 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3511 | } | |
3512 | } | |
fd2f0033 | 3513 | if (dwarf_start_die != 0 && level < saved_level) |
d85bf2ba | 3514 | return TRUE; |
19e6b90e L |
3515 | continue; |
3516 | } | |
3517 | ||
4b78141a | 3518 | if (!do_loc) |
fd2f0033 TT |
3519 | { |
3520 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
3521 | do_printing = 0; | |
3522 | else | |
3523 | { | |
3524 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
3525 | saved_level = level; | |
3526 | do_printing = (dwarf_cutoff_level == -1 | |
3527 | || level < dwarf_cutoff_level); | |
3528 | if (do_printing) | |
3529 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
3530 | level, die_offset, abbrev_number); | |
3531 | else if (dwarf_cutoff_level == -1 | |
3532 | || last_level < dwarf_cutoff_level) | |
3533 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
3534 | last_level = level; | |
3535 | } | |
3536 | } | |
cecf136e | 3537 | |
19e6b90e L |
3538 | /* Scan through the abbreviation list until we reach the |
3539 | correct entry. */ | |
3540 | for (entry = first_abbrev; | |
3541 | entry && entry->entry != abbrev_number; | |
3542 | entry = entry->next) | |
3543 | continue; | |
3544 | ||
3545 | if (entry == NULL) | |
3546 | { | |
fd2f0033 | 3547 | if (!do_loc && do_printing) |
4b78141a NC |
3548 | { |
3549 | printf ("\n"); | |
3550 | fflush (stdout); | |
3551 | } | |
f3853b34 | 3552 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 3553 | die_offset, abbrev_number); |
d85bf2ba | 3554 | return FALSE; |
19e6b90e L |
3555 | } |
3556 | ||
fd2f0033 | 3557 | if (!do_loc && do_printing) |
cc5914eb | 3558 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 3559 | |
19e6b90e L |
3560 | switch (entry->tag) |
3561 | { | |
3562 | default: | |
3563 | need_base_address = 0; | |
3564 | break; | |
3565 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
3566 | need_base_address = 1; |
3567 | need_dwo_info = do_loc; | |
19e6b90e L |
3568 | break; |
3569 | case DW_TAG_entry_point: | |
19e6b90e L |
3570 | case DW_TAG_subprogram: |
3571 | need_base_address = 0; | |
3572 | /* Assuming that there is no DW_AT_frame_base. */ | |
3573 | have_frame_base = 0; | |
3574 | break; | |
3575 | } | |
3576 | ||
9f272209 AO |
3577 | debug_info *debug_info_p = |
3578 | (debug_information && unit < alloc_num_debug_info_entries) | |
3579 | ? debug_information + unit : NULL; | |
3580 | ||
3581 | assert (!debug_info_p | |
3582 | || (debug_info_p->num_loc_offsets | |
3583 | == debug_info_p->num_loc_views)); | |
3584 | ||
399c99f7 L |
3585 | for (attr = entry->first_attr; |
3586 | attr && attr->attribute; | |
3587 | attr = attr->next) | |
4b78141a | 3588 | { |
fd2f0033 | 3589 | if (! do_loc && do_printing) |
4b78141a | 3590 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 | 3591 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
3592 | tags = read_and_display_attr (attr->attribute, |
3593 | attr->form, | |
77145576 | 3594 | attr->implicit_const, |
ec1b0fbb | 3595 | section_begin, |
341f9135 | 3596 | tags, |
f6f0e17b | 3597 | end, |
341f9135 | 3598 | cu_offset, |
4b78141a NC |
3599 | compunit.cu_pointer_size, |
3600 | offset_size, | |
3601 | compunit.cu_version, | |
9f272209 | 3602 | debug_info_p, |
341f9135 CC |
3603 | do_loc || ! do_printing, |
3604 | section, | |
ec1b0fbb NC |
3605 | this_set, |
3606 | level); | |
4b78141a | 3607 | } |
cecf136e | 3608 | |
9f272209 AO |
3609 | /* If a locview attribute appears before a location one, |
3610 | make sure we don't associate it with an earlier | |
3611 | loclist. */ | |
3612 | if (debug_info_p) | |
3613 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
3614 | { | |
3615 | case 1: | |
3616 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
3617 | debug_info_p->num_loc_views++; | |
3618 | assert (debug_info_p->num_loc_views | |
3619 | == debug_info_p->num_loc_offsets); | |
3620 | break; | |
3621 | ||
3622 | case 0: | |
3623 | break; | |
3624 | ||
3625 | case -1: | |
3626 | warn(_("DIE has locviews without loclist\n")); | |
3627 | debug_info_p->num_loc_views--; | |
3628 | break; | |
3629 | ||
3630 | default: | |
3631 | assert (0); | |
3632 | } | |
3633 | ||
b4eb7656 AM |
3634 | if (entry->children) |
3635 | ++level; | |
3636 | } | |
19e6b90e | 3637 | } |
cecf136e | 3638 | |
19e6b90e L |
3639 | /* Set num_debug_info_entries here so that it can be used to check if |
3640 | we need to process .debug_loc and .debug_ranges sections. */ | |
3641 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3642 | && num_debug_info_entries == 0 |
3643 | && ! do_types) | |
82b1b41b | 3644 | { |
b4eb7656 | 3645 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
3646 | num_debug_info_entries = alloc_num_debug_info_entries; |
3647 | else | |
3648 | num_debug_info_entries = num_units; | |
3649 | } | |
cecf136e | 3650 | |
19e6b90e | 3651 | if (!do_loc) |
467c65bc | 3652 | printf ("\n"); |
cecf136e | 3653 | |
d85bf2ba | 3654 | return TRUE; |
19e6b90e L |
3655 | } |
3656 | ||
3657 | /* Locate and scan the .debug_info section in the file and record the pointer | |
3658 | sizes and offsets for the compilation units in it. Usually an executable | |
3659 | will have just one pointer size, but this is not guaranteed, and so we try | |
3660 | not to make any assumptions. Returns zero upon failure, or the number of | |
3661 | compilation units upon success. */ | |
3662 | ||
3663 | static unsigned int | |
3664 | load_debug_info (void * file) | |
3665 | { | |
1febe64d | 3666 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 3667 | section then do not bother to repeat the task. */ |
cc86f28f | 3668 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
3669 | return 0; |
3670 | ||
19e6b90e L |
3671 | /* If we already have the information there is nothing else to do. */ |
3672 | if (num_debug_info_entries > 0) | |
3673 | return num_debug_info_entries; | |
3674 | ||
341f9135 | 3675 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 3676 | (void) load_cu_tu_indexes (file); |
341f9135 | 3677 | |
dda8d76d | 3678 | if (load_debug_section_with_follow (info, file) |
d85bf2ba | 3679 | && process_debug_info (&debug_displays [info].section, file, abbrev, TRUE, FALSE)) |
19e6b90e | 3680 | return num_debug_info_entries; |
82b1b41b | 3681 | |
dda8d76d | 3682 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 3683 | && process_debug_info (&debug_displays [info_dwo].section, file, |
d85bf2ba | 3684 | abbrev_dwo, TRUE, FALSE)) |
4723351a | 3685 | return num_debug_info_entries; |
1febe64d | 3686 | |
cc86f28f | 3687 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 3688 | return 0; |
19e6b90e L |
3689 | } |
3690 | ||
b40bf0a2 NC |
3691 | /* Read a DWARF .debug_line section header starting at DATA. |
3692 | Upon success returns an updated DATA pointer and the LINFO | |
3693 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
3694 | Otherwise returns NULL. */ | |
19e6b90e | 3695 | |
b40bf0a2 NC |
3696 | static unsigned char * |
3697 | read_debug_line_header (struct dwarf_section * section, | |
3698 | unsigned char * data, | |
3699 | unsigned char * end, | |
3700 | DWARF2_Internal_LineInfo * linfo, | |
3701 | unsigned char ** end_of_sequence) | |
3702 | { | |
3703 | unsigned char *hdrptr; | |
b40bf0a2 | 3704 | unsigned int initial_length_size; |
19e6b90e | 3705 | |
b40bf0a2 NC |
3706 | /* Extract information from the Line Number Program Header. |
3707 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 3708 | hdrptr = data; |
19e6b90e | 3709 | |
b40bf0a2 NC |
3710 | /* Get and check the length of the block. */ |
3711 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 3712 | |
b40bf0a2 | 3713 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
3714 | { |
3715 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 3716 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 3717 | linfo->li_offset_size = 8; |
f41e4712 NC |
3718 | initial_length_size = 12; |
3719 | } | |
3720 | else | |
3721 | { | |
77145576 | 3722 | linfo->li_offset_size = 4; |
f41e4712 NC |
3723 | initial_length_size = 4; |
3724 | } | |
19e6b90e | 3725 | |
b40bf0a2 | 3726 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 3727 | { |
8fcc61b4 NC |
3728 | /* If the length field has a relocation against it, then we should |
3729 | not complain if it is inaccurate (and probably negative). This | |
3730 | happens in object files when the .debug_line section is actually | |
3731 | comprised of several different .debug_line.* sections, (some of | |
3732 | which may be removed by linker garbage collection), and a relocation | |
3733 | is used to compute the correct length once that is done. */ | |
77145576 | 3734 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 3735 | { |
8fcc61b4 | 3736 | linfo->li_length = (end - data) - initial_length_size; |
b40bf0a2 NC |
3737 | } |
3738 | else | |
3739 | { | |
8fcc61b4 NC |
3740 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
3741 | (long) linfo->li_length); | |
b40bf0a2 NC |
3742 | return NULL; |
3743 | } | |
f41e4712 | 3744 | } |
19e6b90e | 3745 | |
b40bf0a2 NC |
3746 | /* Get and check the version number. */ |
3747 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
3748 | ||
3749 | if (linfo->li_version != 2 | |
3750 | && linfo->li_version != 3 | |
77145576 JK |
3751 | && linfo->li_version != 4 |
3752 | && linfo->li_version != 5) | |
f41e4712 | 3753 | { |
77145576 JK |
3754 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
3755 | "is currently supported.\n")); | |
b40bf0a2 | 3756 | return NULL; |
f41e4712 | 3757 | } |
19e6b90e | 3758 | |
77145576 JK |
3759 | if (linfo->li_version >= 5) |
3760 | { | |
5496f3c6 | 3761 | SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end); |
77145576 | 3762 | |
5496f3c6 NC |
3763 | SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end); |
3764 | if (linfo->li_segment_size != 0) | |
77145576 JK |
3765 | { |
3766 | warn (_("The %s section contains " | |
3767 | "unsupported segment selector size: %d.\n"), | |
5496f3c6 NC |
3768 | section->name, linfo->li_segment_size); |
3769 | return NULL; | |
77145576 JK |
3770 | } |
3771 | } | |
3772 | ||
3773 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
3774 | linfo->li_offset_size, end); | |
b40bf0a2 | 3775 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 3776 | |
b40bf0a2 | 3777 | if (linfo->li_version >= 4) |
f41e4712 | 3778 | { |
b40bf0a2 | 3779 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 3780 | |
b40bf0a2 | 3781 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
3782 | { |
3783 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 3784 | return NULL; |
a233b20c | 3785 | } |
f41e4712 NC |
3786 | } |
3787 | else | |
b40bf0a2 | 3788 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 3789 | |
b40bf0a2 | 3790 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 3791 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
3792 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
3793 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 3794 | |
b40bf0a2 | 3795 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 3796 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
3797 | if (* end_of_sequence > end) |
3798 | { | |
4c219c2e AM |
3799 | warn (_("Line length %s extends beyond end of section\n"), |
3800 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
3801 | * end_of_sequence = end; |
3802 | return NULL; | |
3803 | } | |
3804 | ||
b40bf0a2 NC |
3805 | return hdrptr; |
3806 | } | |
19e6b90e | 3807 | |
77145576 | 3808 | static unsigned char * |
dda8d76d NC |
3809 | display_formatted_table (unsigned char * data, |
3810 | unsigned char * start, | |
3811 | unsigned char * end, | |
3812 | const DWARF2_Internal_LineInfo * linfo, | |
3813 | struct dwarf_section * section, | |
7b8d9e8c | 3814 | bfd_boolean is_dir) |
77145576 JK |
3815 | { |
3816 | unsigned char *format_start, format_count, *format, formati; | |
3817 | dwarf_vma data_count, datai; | |
cd30bcef | 3818 | unsigned int namepass, last_entry = 0; |
5496f3c6 NC |
3819 | const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table"); |
3820 | ||
77145576 | 3821 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
546cb2d8 NC |
3822 | if (do_checks && format_count > 5) |
3823 | warn (_("Unexpectedly large number of columns in the %s (%u)\n"), | |
3824 | table_name, format_count); | |
3825 | ||
77145576 JK |
3826 | format_start = data; |
3827 | for (formati = 0; formati < format_count; formati++) | |
3828 | { | |
cd30bcef AM |
3829 | SKIP_ULEB (data, end); |
3830 | SKIP_ULEB (data, end); | |
77145576 JK |
3831 | if (data == end) |
3832 | { | |
5496f3c6 | 3833 | warn (_("%s: Corrupt format description entry\n"), table_name); |
77145576 JK |
3834 | return data; |
3835 | } | |
3836 | } | |
3837 | ||
cd30bcef | 3838 | READ_ULEB (data_count, data, end); |
546cb2d8 | 3839 | if (data_count == 0) |
77145576 | 3840 | { |
546cb2d8 | 3841 | printf (_("\n The %s is empty.\n"), table_name); |
77145576 JK |
3842 | return data; |
3843 | } | |
546cb2d8 | 3844 | else if (data == end) |
77145576 | 3845 | { |
546cb2d8 NC |
3846 | warn (_("%s: Corrupt entry count - expected %s but none found\n"), |
3847 | table_name, dwarf_vmatoa ("x", data_count)); | |
77145576 JK |
3848 | return data; |
3849 | } | |
546cb2d8 | 3850 | |
5496f3c6 NC |
3851 | else if (format_count == 0) |
3852 | { | |
3853 | warn (_("%s: format count is zero, but the table is not empty\n"), | |
3854 | table_name); | |
3855 | return end; | |
3856 | } | |
77145576 | 3857 | |
5496f3c6 NC |
3858 | printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"), |
3859 | table_name, (long) (data - start), dwarf_vmatoa ("u", data_count), | |
3860 | format_count); | |
77145576 JK |
3861 | |
3862 | printf (_(" Entry")); | |
3863 | /* Delay displaying name as the last entry for better screen layout. */ | |
3864 | for (namepass = 0; namepass < 2; namepass++) | |
3865 | { | |
3866 | format = format_start; | |
3867 | for (formati = 0; formati < format_count; formati++) | |
3868 | { | |
3869 | dwarf_vma content_type; | |
3870 | ||
cd30bcef | 3871 | READ_ULEB (content_type, format, end); |
77145576 JK |
3872 | if ((content_type == DW_LNCT_path) == (namepass == 1)) |
3873 | switch (content_type) | |
3874 | { | |
3875 | case DW_LNCT_path: | |
3876 | printf (_("\tName")); | |
3877 | break; | |
3878 | case DW_LNCT_directory_index: | |
3879 | printf (_("\tDir")); | |
3880 | break; | |
3881 | case DW_LNCT_timestamp: | |
3882 | printf (_("\tTime")); | |
3883 | break; | |
3884 | case DW_LNCT_size: | |
3885 | printf (_("\tSize")); | |
3886 | break; | |
3887 | case DW_LNCT_MD5: | |
5496f3c6 | 3888 | printf (_("\tMD5\t\t\t")); |
77145576 JK |
3889 | break; |
3890 | default: | |
3891 | printf (_("\t(Unknown format content type %s)"), | |
3892 | dwarf_vmatoa ("u", content_type)); | |
3893 | } | |
cd30bcef | 3894 | SKIP_ULEB (format, end); |
77145576 JK |
3895 | } |
3896 | } | |
3897 | putchar ('\n'); | |
3898 | ||
3899 | for (datai = 0; datai < data_count; datai++) | |
3900 | { | |
3901 | unsigned char *datapass = data; | |
3902 | ||
3903 | printf (" %d", last_entry++); | |
3904 | /* Delay displaying name as the last entry for better screen layout. */ | |
3905 | for (namepass = 0; namepass < 2; namepass++) | |
3906 | { | |
3907 | format = format_start; | |
3908 | data = datapass; | |
3909 | for (formati = 0; formati < format_count; formati++) | |
3910 | { | |
3911 | dwarf_vma content_type, form; | |
3912 | ||
cd30bcef AM |
3913 | READ_ULEB (content_type, format, end); |
3914 | READ_ULEB (form, format, end); | |
3915 | data = read_and_display_attr_value (0, form, 0, start, data, end, | |
3916 | 0, 0, linfo->li_offset_size, | |
77145576 JK |
3917 | linfo->li_version, NULL, |
3918 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
ec1b0fbb | 3919 | section, NULL, '\t', -1); |
77145576 JK |
3920 | } |
3921 | } | |
5496f3c6 NC |
3922 | |
3923 | if (data == end && (datai < data_count - 1)) | |
77145576 | 3924 | { |
5496f3c6 | 3925 | warn (_("\n%s: Corrupt entries list\n"), table_name); |
77145576 JK |
3926 | return data; |
3927 | } | |
3928 | putchar ('\n'); | |
3929 | } | |
3930 | return data; | |
3931 | } | |
3932 | ||
b40bf0a2 | 3933 | static int |
dda8d76d NC |
3934 | display_debug_lines_raw (struct dwarf_section * section, |
3935 | unsigned char * data, | |
3936 | unsigned char * end, | |
3937 | void * file) | |
b40bf0a2 NC |
3938 | { |
3939 | unsigned char *start = section->start; | |
ba8826a8 | 3940 | int verbose_view = 0; |
19e6b90e | 3941 | |
dda8d76d | 3942 | introduce (section, TRUE); |
19e6b90e | 3943 | |
b40bf0a2 NC |
3944 | while (data < end) |
3945 | { | |
3946 | static DWARF2_Internal_LineInfo saved_linfo; | |
3947 | DWARF2_Internal_LineInfo linfo; | |
3948 | unsigned char *standard_opcodes; | |
3949 | unsigned char *end_of_sequence; | |
fe59e83d | 3950 | int i; |
19e6b90e | 3951 | |
4925cdd7 NC |
3952 | if (const_strneq (section->name, ".debug_line.") |
3953 | /* Note: the following does not apply to .debug_line.dwo sections. | |
3954 | These are full debug_line sections. */ | |
3955 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 3956 | { |
b40bf0a2 NC |
3957 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
3958 | section containing just the Line Number Statements. They are | |
3959 | created by the assembler and intended to be used alongside gcc's | |
3960 | -ffunction-sections command line option. When the linker's | |
3961 | garbage collection decides to discard a .text.<foo> section it | |
3962 | can then also discard the line number information in .debug_line.<foo>. | |
3963 | ||
4925cdd7 | 3964 | Since the section is a fragment it does not have the details |
b40bf0a2 | 3965 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 3966 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
3967 | end_of_sequence = end; |
3968 | standard_opcodes = NULL; | |
3969 | linfo = saved_linfo; | |
058037d3 NC |
3970 | /* PR 17531: file: 0522b371. */ |
3971 | if (linfo.li_line_range == 0) | |
3972 | { | |
1306a742 | 3973 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
3974 | return 0; |
3975 | } | |
b40bf0a2 | 3976 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3977 | } |
19e6b90e L |
3978 | else |
3979 | { | |
b40bf0a2 | 3980 | unsigned char * hdrptr; |
19e6b90e | 3981 | |
b40bf0a2 NC |
3982 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
3983 | & end_of_sequence)) == NULL) | |
3984 | return 0; | |
19e6b90e | 3985 | |
b40bf0a2 NC |
3986 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
3987 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
3988 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
5496f3c6 NC |
3989 | if (linfo.li_version >= 5) |
3990 | { | |
3991 | printf (_(" Address size (bytes): %d\n"), linfo.li_address_size); | |
3992 | printf (_(" Segment selector (bytes): %d\n"), linfo.li_segment_size); | |
3993 | } | |
77ef8654 | 3994 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
3995 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
3996 | if (linfo.li_version >= 4) | |
3997 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
3998 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
3999 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
4000 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
4001 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 4002 | |
0a9d414a NC |
4003 | /* PR 17512: file: 1665-6428-0.004. */ |
4004 | if (linfo.li_line_range == 0) | |
4005 | { | |
4006 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4007 | linfo.li_line_range = 1; | |
4008 | } | |
77ef8654 | 4009 | |
b40bf0a2 | 4010 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4011 | |
b40bf0a2 NC |
4012 | /* Display the contents of the Opcodes table. */ |
4013 | standard_opcodes = hdrptr; | |
19e6b90e | 4014 | |
6937bb54 NC |
4015 | /* PR 17512: file: 002-417945-0.004. */ |
4016 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
4017 | { | |
4018 | warn (_("Line Base extends beyond end of section\n")); | |
4019 | return 0; | |
4020 | } | |
4021 | ||
b40bf0a2 | 4022 | printf (_("\n Opcodes:\n")); |
19e6b90e | 4023 | |
b40bf0a2 | 4024 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
4025 | printf (ngettext (" Opcode %d has %d arg\n", |
4026 | " Opcode %d has %d args\n", | |
4027 | standard_opcodes[i - 1]), | |
4028 | i, standard_opcodes[i - 1]); | |
19e6b90e | 4029 | |
b40bf0a2 NC |
4030 | /* Display the contents of the Directory table. */ |
4031 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 4032 | |
77145576 | 4033 | if (linfo.li_version >= 5) |
b40bf0a2 | 4034 | { |
dda8d76d | 4035 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 4036 | |
77145576 | 4037 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 4038 | TRUE); |
77145576 | 4039 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 4040 | FALSE); |
77145576 JK |
4041 | } |
4042 | else | |
4043 | { | |
4044 | if (*data == 0) | |
4045 | printf (_("\n The Directory Table is empty.\n")); | |
4046 | else | |
a233b20c | 4047 | { |
77145576 | 4048 | unsigned int last_dir_entry = 0; |
6937bb54 | 4049 | |
77145576 JK |
4050 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
4051 | (long)(data - start)); | |
19e6b90e | 4052 | |
77145576 JK |
4053 | while (data < end && *data != 0) |
4054 | { | |
4055 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 4056 | |
77145576 JK |
4057 | data += strnlen ((char *) data, end - data) + 1; |
4058 | } | |
19e6b90e | 4059 | |
77145576 JK |
4060 | /* PR 17512: file: 002-132094-0.004. */ |
4061 | if (data >= end - 1) | |
4062 | break; | |
4063 | } | |
19e6b90e | 4064 | |
77145576 JK |
4065 | /* Skip the NUL at the end of the table. */ |
4066 | data++; | |
19e6b90e | 4067 | |
77145576 JK |
4068 | /* Display the contents of the File Name table. */ |
4069 | if (*data == 0) | |
4070 | printf (_("\n The File Name Table is empty.\n")); | |
4071 | else | |
4072 | { | |
4073 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
4074 | (long)(data - start)); | |
4075 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 4076 | |
77145576 | 4077 | while (data < end && *data != 0) |
b40bf0a2 | 4078 | { |
77145576 | 4079 | unsigned char *name; |
cd30bcef | 4080 | dwarf_vma val; |
77145576 JK |
4081 | |
4082 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
4083 | name = data; | |
4084 | data += strnlen ((char *) data, end - data) + 1; | |
4085 | ||
cd30bcef AM |
4086 | READ_ULEB (val, data, end); |
4087 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
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)); | |
77145576 JK |
4092 | printf ("%.*s\n", (int)(end - name), name); |
4093 | ||
4094 | if (data == end) | |
4095 | { | |
4096 | warn (_("Corrupt file name table entry\n")); | |
4097 | break; | |
4098 | } | |
b40bf0a2 | 4099 | } |
a233b20c | 4100 | } |
77145576 JK |
4101 | |
4102 | /* Skip the NUL at the end of the table. */ | |
4103 | data++; | |
b40bf0a2 | 4104 | } |
19e6b90e | 4105 | |
b40bf0a2 NC |
4106 | putchar ('\n'); |
4107 | saved_linfo = linfo; | |
4108 | } | |
19e6b90e | 4109 | |
b40bf0a2 NC |
4110 | /* Now display the statements. */ |
4111 | if (data >= end_of_sequence) | |
4112 | printf (_(" No Line Number Statements.\n")); | |
4113 | else | |
4114 | { | |
4115 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 4116 | |
b40bf0a2 NC |
4117 | while (data < end_of_sequence) |
4118 | { | |
4119 | unsigned char op_code; | |
4120 | dwarf_signed_vma adv; | |
4121 | dwarf_vma uladv; | |
19e6b90e | 4122 | |
fe59e83d CC |
4123 | printf (" [0x%08lx]", (long)(data - start)); |
4124 | ||
b40bf0a2 | 4125 | op_code = *data++; |
19e6b90e | 4126 | |
b40bf0a2 | 4127 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 4128 | { |
b40bf0a2 NC |
4129 | op_code -= linfo.li_opcode_base; |
4130 | uladv = (op_code / linfo.li_line_range); | |
4131 | if (linfo.li_max_ops_per_insn == 1) | |
4132 | { | |
4133 | uladv *= linfo.li_min_insn_length; | |
4134 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4135 | if (uladv) |
4136 | state_machine_regs.view = 0; | |
b40bf0a2 | 4137 | printf (_(" Special opcode %d: " |
ba8826a8 | 4138 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 4139 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4140 | dwarf_vmatoa ("x", state_machine_regs.address), |
4141 | verbose_view && uladv | |
4142 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4143 | } |
4144 | else | |
4145 | { | |
ba8826a8 AO |
4146 | unsigned addrdelta |
4147 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
4148 | / linfo.li_max_ops_per_insn) |
4149 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
4150 | |
4151 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
4152 | state_machine_regs.op_index |
4153 | = (state_machine_regs.op_index + uladv) | |
4154 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4155 | if (addrdelta) |
4156 | state_machine_regs.view = 0; | |
b40bf0a2 | 4157 | printf (_(" Special opcode %d: " |
ba8826a8 | 4158 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
4159 | op_code, dwarf_vmatoa ("u", uladv), |
4160 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4161 | state_machine_regs.op_index, |
4162 | verbose_view && addrdelta | |
4163 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4164 | } |
4165 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
4166 | state_machine_regs.line += adv; | |
ba8826a8 | 4167 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 4168 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
4169 | if (verbose_view || state_machine_regs.view) |
4170 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4171 | else | |
4172 | putchar ('\n'); | |
4173 | state_machine_regs.view++; | |
19e6b90e | 4174 | } |
cd30bcef AM |
4175 | else |
4176 | switch (op_code) | |
4177 | { | |
4178 | case DW_LNS_extended_op: | |
4179 | data += process_extended_line_op (data, | |
4180 | linfo.li_default_is_stmt, | |
4181 | end); | |
4182 | break; | |
4183 | ||
4184 | case DW_LNS_copy: | |
4185 | printf (_(" Copy")); | |
4186 | if (verbose_view || state_machine_regs.view) | |
4187 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4188 | else | |
4189 | putchar ('\n'); | |
4190 | state_machine_regs.view++; | |
4191 | break; | |
4192 | ||
4193 | case DW_LNS_advance_pc: | |
4194 | READ_ULEB (uladv, data, end); | |
4195 | if (linfo.li_max_ops_per_insn == 1) | |
4196 | { | |
4197 | uladv *= linfo.li_min_insn_length; | |
4198 | state_machine_regs.address += uladv; | |
4199 | if (uladv) | |
4200 | state_machine_regs.view = 0; | |
4201 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
4202 | dwarf_vmatoa ("u", uladv), | |
4203 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4204 | verbose_view && uladv | |
4205 | ? _(" (reset view)") : ""); | |
4206 | } | |
4207 | else | |
4208 | { | |
4209 | unsigned addrdelta | |
4210 | = ((state_machine_regs.op_index + uladv) | |
4211 | / linfo.li_max_ops_per_insn) | |
4212 | * linfo.li_min_insn_length; | |
4213 | state_machine_regs.address | |
4214 | += addrdelta; | |
4215 | state_machine_regs.op_index | |
4216 | = (state_machine_regs.op_index + uladv) | |
4217 | % linfo.li_max_ops_per_insn; | |
4218 | if (addrdelta) | |
4219 | state_machine_regs.view = 0; | |
4220 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
4221 | dwarf_vmatoa ("u", uladv), | |
4222 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4223 | state_machine_regs.op_index, | |
4224 | verbose_view && addrdelta | |
4225 | ? _(" (reset view)") : ""); | |
4226 | } | |
4227 | break; | |
4228 | ||
4229 | case DW_LNS_advance_line: | |
4230 | READ_SLEB (adv, data, end); | |
4231 | state_machine_regs.line += adv; | |
4232 | printf (_(" Advance Line by %s to %d\n"), | |
4233 | dwarf_vmatoa ("d", adv), | |
4234 | state_machine_regs.line); | |
4235 | break; | |
4236 | ||
4237 | case DW_LNS_set_file: | |
4238 | READ_ULEB (uladv, data, end); | |
4239 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
4240 | dwarf_vmatoa ("u", uladv)); | |
4241 | state_machine_regs.file = uladv; | |
4242 | break; | |
4243 | ||
4244 | case DW_LNS_set_column: | |
4245 | READ_ULEB (uladv, data, end); | |
4246 | printf (_(" Set column to %s\n"), | |
4247 | dwarf_vmatoa ("u", uladv)); | |
4248 | state_machine_regs.column = uladv; | |
4249 | break; | |
4250 | ||
4251 | case DW_LNS_negate_stmt: | |
4252 | adv = state_machine_regs.is_stmt; | |
4253 | adv = ! adv; | |
4254 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
4255 | state_machine_regs.is_stmt = adv; | |
4256 | break; | |
4257 | ||
4258 | case DW_LNS_set_basic_block: | |
4259 | printf (_(" Set basic block\n")); | |
4260 | state_machine_regs.basic_block = 1; | |
4261 | break; | |
4262 | ||
4263 | case DW_LNS_const_add_pc: | |
4264 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4265 | if (linfo.li_max_ops_per_insn) | |
4266 | { | |
4267 | uladv *= linfo.li_min_insn_length; | |
4268 | state_machine_regs.address += uladv; | |
4269 | if (uladv) | |
4270 | state_machine_regs.view = 0; | |
4271 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
4272 | dwarf_vmatoa ("u", uladv), | |
4273 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4274 | verbose_view && uladv | |
4275 | ? _(" (reset view)") : ""); | |
4276 | } | |
4277 | else | |
4278 | { | |
4279 | unsigned addrdelta | |
4280 | = ((state_machine_regs.op_index + uladv) | |
4281 | / linfo.li_max_ops_per_insn) | |
4282 | * linfo.li_min_insn_length; | |
4283 | state_machine_regs.address | |
4284 | += addrdelta; | |
4285 | state_machine_regs.op_index | |
4286 | = (state_machine_regs.op_index + uladv) | |
4287 | % linfo.li_max_ops_per_insn; | |
4288 | if (addrdelta) | |
4289 | state_machine_regs.view = 0; | |
4290 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
4291 | dwarf_vmatoa ("u", uladv), | |
4292 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4293 | state_machine_regs.op_index, | |
4294 | verbose_view && addrdelta | |
4295 | ? _(" (reset view)") : ""); | |
4296 | } | |
4297 | break; | |
4298 | ||
4299 | case DW_LNS_fixed_advance_pc: | |
4300 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4301 | state_machine_regs.address += uladv; | |
4302 | state_machine_regs.op_index = 0; | |
4303 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
4304 | dwarf_vmatoa ("u", uladv), | |
4305 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
4306 | /* Do NOT reset view. */ | |
4307 | break; | |
4308 | ||
4309 | case DW_LNS_set_prologue_end: | |
4310 | printf (_(" Set prologue_end to true\n")); | |
4311 | break; | |
4312 | ||
4313 | case DW_LNS_set_epilogue_begin: | |
4314 | printf (_(" Set epilogue_begin to true\n")); | |
4315 | break; | |
4316 | ||
4317 | case DW_LNS_set_isa: | |
4318 | READ_ULEB (uladv, data, end); | |
4319 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
4320 | break; | |
4321 | ||
4322 | default: | |
4323 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4324 | ||
4325 | if (standard_opcodes != NULL) | |
4326 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4327 | { | |
4328 | READ_ULEB (uladv, data, end); | |
4329 | printf ("0x%s%s", dwarf_vmatoa ("x", uladv), | |
4330 | i == 1 ? "" : ", "); | |
4331 | } | |
4332 | putchar ('\n'); | |
4333 | break; | |
4334 | } | |
19e6b90e | 4335 | } |
b40bf0a2 | 4336 | putchar ('\n'); |
19e6b90e | 4337 | } |
19e6b90e L |
4338 | } |
4339 | ||
4340 | return 1; | |
4341 | } | |
4342 | ||
a262ae96 NC |
4343 | typedef struct |
4344 | { | |
467c65bc NC |
4345 | unsigned char *name; |
4346 | unsigned int directory_index; | |
4347 | unsigned int modification_date; | |
4348 | unsigned int length; | |
a262ae96 NC |
4349 | } File_Entry; |
4350 | ||
4351 | /* Output a decoded representation of the .debug_line section. */ | |
4352 | ||
4353 | static int | |
dda8d76d | 4354 | display_debug_lines_decoded (struct dwarf_section * section, |
ec1b0fbb | 4355 | unsigned char * start, |
dda8d76d NC |
4356 | unsigned char * data, |
4357 | unsigned char * end, | |
4358 | void * fileptr) | |
a262ae96 | 4359 | { |
b40bf0a2 NC |
4360 | static DWARF2_Internal_LineInfo saved_linfo; |
4361 | ||
dda8d76d | 4362 | introduce (section, FALSE); |
a262ae96 NC |
4363 | |
4364 | while (data < end) | |
4365 | { | |
4366 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4367 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4368 | unsigned char *standard_opcodes; |
4369 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4370 | int i; |
4371 | File_Entry *file_table = NULL; | |
143a3db0 | 4372 | unsigned int n_files = 0; |
a262ae96 | 4373 | unsigned char **directory_table = NULL; |
77145576 | 4374 | dwarf_vma n_directories = 0; |
a262ae96 | 4375 | |
4925cdd7 NC |
4376 | if (const_strneq (section->name, ".debug_line.") |
4377 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4378 | These are full debug_line sections. */ | |
4379 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4380 | { |
4925cdd7 | 4381 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4382 | end_of_sequence = end; |
4383 | standard_opcodes = NULL; | |
4384 | linfo = saved_linfo; | |
058037d3 NC |
4385 | /* PR 17531: file: 0522b371. */ |
4386 | if (linfo.li_line_range == 0) | |
4387 | { | |
1306a742 | 4388 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4389 | return 0; |
4390 | } | |
b40bf0a2 | 4391 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4392 | } |
a262ae96 | 4393 | else |
b4eb7656 | 4394 | { |
b40bf0a2 | 4395 | unsigned char *hdrptr; |
a262ae96 | 4396 | |
b40bf0a2 NC |
4397 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4398 | & end_of_sequence)) == NULL) | |
a233b20c | 4399 | return 0; |
0c588247 | 4400 | |
058037d3 NC |
4401 | /* PR 17531: file: 0522b371. */ |
4402 | if (linfo.li_line_range == 0) | |
4403 | { | |
4404 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4405 | linfo.li_line_range = 1; | |
4406 | } | |
b40bf0a2 | 4407 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4408 | |
b40bf0a2 NC |
4409 | /* Save a pointer to the contents of the Opcodes table. */ |
4410 | standard_opcodes = hdrptr; | |
a262ae96 | 4411 | |
b40bf0a2 NC |
4412 | /* Traverse the Directory table just to count entries. */ |
4413 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4414 | /* PR 20440 */ |
4415 | if (data >= end) | |
4416 | { | |
4417 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4418 | linfo.li_opcode_base); | |
4419 | return 0; | |
4420 | } | |
4421 | ||
77145576 | 4422 | if (linfo.li_version >= 5) |
b40bf0a2 | 4423 | { |
77145576 JK |
4424 | unsigned char *format_start, format_count, *format; |
4425 | dwarf_vma formati, entryi; | |
a262ae96 | 4426 | |
dda8d76d | 4427 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4428 | |
4429 | /* Skip directories format. */ | |
4430 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4431 | if (do_checks && format_count > 1) |
4432 | warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"), | |
4433 | format_count); | |
77145576 JK |
4434 | format_start = data; |
4435 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4436 | { |
cd30bcef AM |
4437 | SKIP_ULEB (data, end); |
4438 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4439 | } |
a262ae96 | 4440 | |
cd30bcef | 4441 | READ_ULEB (n_directories, data, end); |
77145576 | 4442 | if (data == end) |
d8024a91 | 4443 | { |
77145576 | 4444 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
4445 | break; |
4446 | } | |
4447 | ||
070b775f NC |
4448 | if (n_directories == 0) |
4449 | directory_table = NULL; | |
4450 | else | |
4451 | directory_table = (unsigned char **) | |
4452 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 4453 | |
77145576 | 4454 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 4455 | { |
77145576 | 4456 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 4457 | |
77145576 JK |
4458 | format = format_start; |
4459 | for (formati = 0; formati < format_count; formati++) | |
4460 | { | |
4461 | dwarf_vma content_type, form; | |
4462 | dwarf_vma uvalue; | |
4463 | ||
cd30bcef AM |
4464 | READ_ULEB (content_type, format, end); |
4465 | READ_ULEB (form, format, end); | |
77145576 JK |
4466 | if (data == end) |
4467 | { | |
4468 | warn (_("Corrupt directories list\n")); | |
4469 | break; | |
4470 | } | |
4471 | switch (content_type) | |
4472 | { | |
4473 | case DW_LNCT_path: | |
4474 | switch (form) | |
4475 | { | |
4476 | case DW_FORM_string: | |
4477 | *pathp = data; | |
4478 | break; | |
4479 | case DW_FORM_line_strp: | |
4480 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4481 | end); | |
4482 | /* Remove const by the cast. */ | |
4483 | *pathp = (unsigned char *) | |
4484 | fetch_indirect_line_string (uvalue); | |
4485 | break; | |
4486 | } | |
4487 | break; | |
4488 | } | |
cd30bcef AM |
4489 | data = read_and_display_attr_value (0, form, 0, start, |
4490 | data, end, 0, 0, | |
77145576 JK |
4491 | linfo.li_offset_size, |
4492 | linfo.li_version, | |
4493 | NULL, 1, section, | |
ec1b0fbb | 4494 | NULL, '\t', -1); |
77145576 JK |
4495 | } |
4496 | if (data == end) | |
4497 | { | |
4498 | warn (_("Corrupt directories list\n")); | |
4499 | break; | |
4500 | } | |
4501 | } | |
a262ae96 | 4502 | |
77145576 JK |
4503 | /* Skip files format. */ |
4504 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4505 | if (do_checks && format_count > 5) |
4506 | warn (_("Unexpectedly large number of columns in the file name table (%u)\n"), | |
4507 | format_count); | |
77145576 JK |
4508 | format_start = data; |
4509 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4510 | { |
cd30bcef AM |
4511 | SKIP_ULEB (data, end); |
4512 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4513 | } |
a262ae96 | 4514 | |
cd30bcef | 4515 | READ_ULEB (n_files, data, end); |
070b775f | 4516 | if (data == end && n_files > 0) |
d8024a91 | 4517 | { |
77145576 | 4518 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
4519 | break; |
4520 | } | |
4521 | ||
070b775f NC |
4522 | if (n_files == 0) |
4523 | file_table = NULL; | |
4524 | else | |
4525 | file_table = (File_Entry *) xcalloc (1, n_files | |
4526 | * sizeof (File_Entry)); | |
a262ae96 | 4527 | |
77145576 | 4528 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 4529 | { |
77145576 | 4530 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 4531 | |
77145576 JK |
4532 | format = format_start; |
4533 | for (formati = 0; formati < format_count; formati++) | |
4534 | { | |
4535 | dwarf_vma content_type, form; | |
4536 | dwarf_vma uvalue; | |
cd30bcef | 4537 | unsigned char *tmp; |
77145576 | 4538 | |
cd30bcef AM |
4539 | READ_ULEB (content_type, format, end); |
4540 | READ_ULEB (form, format, end); | |
77145576 JK |
4541 | if (data == end) |
4542 | { | |
4543 | warn (_("Corrupt file name list\n")); | |
4544 | break; | |
4545 | } | |
4546 | switch (content_type) | |
4547 | { | |
4548 | case DW_LNCT_path: | |
4549 | switch (form) | |
4550 | { | |
4551 | case DW_FORM_string: | |
4552 | file->name = data; | |
4553 | break; | |
4554 | case DW_FORM_line_strp: | |
4555 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4556 | end); | |
4557 | /* Remove const by the cast. */ | |
4558 | file->name = (unsigned char *) | |
4559 | fetch_indirect_line_string (uvalue); | |
4560 | break; | |
4561 | } | |
4562 | break; | |
4563 | case DW_LNCT_directory_index: | |
4564 | switch (form) | |
4565 | { | |
4566 | case DW_FORM_data1: | |
4567 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
4568 | end); | |
4569 | break; | |
4570 | case DW_FORM_data2: | |
4571 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
4572 | end); | |
4573 | break; | |
4574 | case DW_FORM_udata: | |
cd30bcef AM |
4575 | tmp = data; |
4576 | READ_ULEB (file->directory_index, tmp, end); | |
77145576 JK |
4577 | break; |
4578 | } | |
4579 | break; | |
4580 | } | |
cd30bcef AM |
4581 | data = read_and_display_attr_value (0, form, 0, start, |
4582 | data, end, 0, 0, | |
77145576 JK |
4583 | linfo.li_offset_size, |
4584 | linfo.li_version, | |
4585 | NULL, 1, section, | |
ec1b0fbb | 4586 | NULL, '\t', -1); |
77145576 JK |
4587 | } |
4588 | if (data == end) | |
4589 | { | |
4590 | warn (_("Corrupt file name list\n")); | |
4591 | break; | |
4592 | } | |
4593 | } | |
4594 | } | |
4595 | else | |
4596 | { | |
4597 | if (*data != 0) | |
b40bf0a2 | 4598 | { |
77145576 JK |
4599 | unsigned char *ptr_directory_table = data; |
4600 | ||
4601 | while (data < end && *data != 0) | |
4602 | { | |
4603 | data += strnlen ((char *) data, end - data) + 1; | |
4604 | n_directories++; | |
4605 | } | |
4606 | ||
4607 | /* PR 20440 */ | |
4608 | if (data >= end) | |
4609 | { | |
4610 | warn (_("directory table ends unexpectedly\n")); | |
4611 | n_directories = 0; | |
4612 | break; | |
4613 | } | |
4614 | ||
4615 | /* Go through the directory table again to save the directories. */ | |
4616 | directory_table = (unsigned char **) | |
4617 | xmalloc (n_directories * sizeof (unsigned char *)); | |
4618 | ||
4619 | i = 0; | |
4620 | while (*ptr_directory_table != 0) | |
4621 | { | |
4622 | directory_table[i] = ptr_directory_table; | |
4623 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
4624 | ptr_directory_table - end) + 1; | |
4625 | i++; | |
4626 | } | |
b40bf0a2 | 4627 | } |
77145576 JK |
4628 | /* Skip the NUL at the end of the table. */ |
4629 | data++; | |
4630 | ||
4631 | /* Traverse the File Name table just to count the entries. */ | |
4632 | if (data < end && *data != 0) | |
b40bf0a2 | 4633 | { |
77145576 JK |
4634 | unsigned char *ptr_file_name_table = data; |
4635 | ||
4636 | while (data < end && *data != 0) | |
db9537d2 | 4637 | { |
cd30bcef AM |
4638 | /* Skip Name, directory index, last modification |
4639 | time and length of file. */ | |
77145576 | 4640 | data += strnlen ((char *) data, end - data) + 1; |
cd30bcef AM |
4641 | SKIP_ULEB (data, end); |
4642 | SKIP_ULEB (data, end); | |
4643 | SKIP_ULEB (data, end); | |
77145576 | 4644 | n_files++; |
db9537d2 | 4645 | } |
a262ae96 | 4646 | |
77145576 JK |
4647 | if (data >= end) |
4648 | { | |
4649 | warn (_("file table ends unexpectedly\n")); | |
4650 | n_files = 0; | |
4651 | break; | |
4652 | } | |
4653 | ||
4654 | /* Go through the file table again to save the strings. */ | |
4655 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 4656 | |
77145576 JK |
4657 | i = 0; |
4658 | while (*ptr_file_name_table != 0) | |
4659 | { | |
77145576 JK |
4660 | file_table[i].name = ptr_file_name_table; |
4661 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
4662 | end - ptr_file_name_table) + 1; | |
4663 | ||
4664 | /* We are not interested in directory, time or size. */ | |
cd30bcef AM |
4665 | READ_ULEB (file_table[i].directory_index, |
4666 | ptr_file_name_table, end); | |
4667 | READ_ULEB (file_table[i].modification_date, | |
4668 | ptr_file_name_table, end); | |
4669 | READ_ULEB (file_table[i].length, | |
4670 | ptr_file_name_table, end); | |
77145576 JK |
4671 | i++; |
4672 | } | |
4673 | i = 0; | |
b40bf0a2 | 4674 | } |
77145576 JK |
4675 | |
4676 | /* Skip the NUL at the end of the table. */ | |
4677 | data++; | |
b40bf0a2 | 4678 | } |
cc5914eb | 4679 | |
77145576 | 4680 | /* Print the Compilation Unit's name and a header. */ |
f082820d | 4681 | if (file_table == NULL) |
070b775f | 4682 | printf (_("CU: No directory table\n")); |
f082820d AM |
4683 | else if (directory_table == NULL) |
4684 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
4685 | else |
4686 | { | |
4687 | unsigned int ix = file_table[0].directory_index; | |
4688 | const char *directory; | |
4689 | ||
4690 | if (ix == 0) | |
4691 | directory = "."; | |
4692 | /* PR 20439 */ | |
4693 | else if (n_directories == 0) | |
4694 | directory = _("<unknown>"); | |
4695 | else if (ix > n_directories) | |
4696 | { | |
4697 | warn (_("directory index %u > number of directories %s\n"), | |
4698 | ix, dwarf_vmatoa ("u", n_directories)); | |
4699 | directory = _("<corrupt>"); | |
4700 | } | |
4701 | else | |
4702 | directory = (char *) directory_table[ix - 1]; | |
4703 | ||
4704 | if (do_wide || strlen (directory) < 76) | |
4705 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
4706 | else | |
4707 | printf ("%s:\n", file_table[0].name); | |
77145576 | 4708 | } |
a262ae96 | 4709 | |
070b775f NC |
4710 | if (n_files > 0) |
4711 | printf (_("File name Line number Starting address View Stmt\n")); | |
4712 | else | |
4713 | printf (_("CU: Empty file name table\n")); | |
b40bf0a2 NC |
4714 | saved_linfo = linfo; |
4715 | } | |
a262ae96 NC |
4716 | |
4717 | /* This loop iterates through the Dwarf Line Number Program. */ | |
4718 | while (data < end_of_sequence) | |
b4eb7656 | 4719 | { |
a262ae96 | 4720 | unsigned char op_code; |
ba8826a8 | 4721 | int xop; |
b4eb7656 AM |
4722 | int adv; |
4723 | unsigned long int uladv; | |
b4eb7656 | 4724 | int is_special_opcode = 0; |
a262ae96 | 4725 | |
b4eb7656 | 4726 | op_code = *data++; |
ba8826a8 | 4727 | xop = op_code; |
a262ae96 | 4728 | |
b4eb7656 | 4729 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 4730 | { |
91d6fa6a | 4731 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
4732 | uladv = (op_code / linfo.li_line_range); |
4733 | if (linfo.li_max_ops_per_insn == 1) | |
4734 | { | |
4735 | uladv *= linfo.li_min_insn_length; | |
4736 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4737 | if (uladv) |
4738 | state_machine_regs.view = 0; | |
a233b20c JJ |
4739 | } |
4740 | else | |
4741 | { | |
ba8826a8 AO |
4742 | unsigned addrdelta |
4743 | = ((state_machine_regs.op_index + uladv) | |
4744 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4745 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4746 | state_machine_regs.address |
4747 | += addrdelta; | |
a233b20c JJ |
4748 | state_machine_regs.op_index |
4749 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 4750 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
4751 | if (addrdelta) |
4752 | state_machine_regs.view = 0; | |
a233b20c | 4753 | } |
a262ae96 | 4754 | |
b4eb7656 AM |
4755 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
4756 | state_machine_regs.line += adv; | |
4757 | is_special_opcode = 1; | |
ba8826a8 | 4758 | /* Increment view after printing this row. */ |
b4eb7656 | 4759 | } |
cd30bcef AM |
4760 | else |
4761 | switch (op_code) | |
4762 | { | |
4763 | case DW_LNS_extended_op: | |
4764 | { | |
4765 | unsigned int ext_op_code_len; | |
4766 | unsigned char ext_op_code; | |
4767 | unsigned char *op_code_end; | |
4768 | unsigned char *op_code_data = data; | |
4769 | ||
4770 | READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence); | |
4771 | op_code_end = op_code_data + ext_op_code_len; | |
4772 | if (ext_op_code_len == 0 || op_code_end > end_of_sequence) | |
4773 | { | |
4774 | warn (_("Badly formed extended line op encountered!\n")); | |
4775 | break; | |
4776 | } | |
4777 | ext_op_code = *op_code_data++; | |
4778 | xop = ext_op_code; | |
4779 | xop = -xop; | |
4780 | ||
4781 | switch (ext_op_code) | |
4782 | { | |
4783 | case DW_LNE_end_sequence: | |
4784 | /* Reset stuff after printing this row. */ | |
4785 | break; | |
4786 | case DW_LNE_set_address: | |
4787 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
4788 | op_code_data, | |
4789 | op_code_end - op_code_data, | |
4790 | op_code_end); | |
4791 | state_machine_regs.op_index = 0; | |
4792 | state_machine_regs.view = 0; | |
4793 | break; | |
4794 | case DW_LNE_define_file: | |
4795 | file_table = (File_Entry *) xrealloc | |
4796 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
4797 | ||
4798 | ++state_machine_regs.last_file_entry; | |
4799 | /* Source file name. */ | |
4800 | file_table[n_files].name = op_code_data; | |
4801 | op_code_data += strlen ((char *) op_code_data) + 1; | |
4802 | /* Directory index. */ | |
4803 | READ_ULEB (file_table[n_files].directory_index, | |
4804 | op_code_data, op_code_end); | |
4805 | /* Last modification time. */ | |
4806 | READ_ULEB (file_table[n_files].modification_date, | |
4807 | op_code_data, op_code_end); | |
4808 | /* File length. */ | |
4809 | READ_ULEB (file_table[n_files].length, | |
4810 | op_code_data, op_code_end); | |
4811 | n_files++; | |
4812 | break; | |
4813 | ||
4814 | case DW_LNE_set_discriminator: | |
4815 | case DW_LNE_HP_set_sequence: | |
4816 | /* Simply ignored. */ | |
4817 | break; | |
4818 | ||
4819 | default: | |
4820 | printf (_("UNKNOWN (%u): length %ld\n"), | |
27653fba | 4821 | ext_op_code, (long int) (op_code_data - data)); |
cd30bcef AM |
4822 | break; |
4823 | } | |
4824 | data = op_code_end; | |
4825 | break; | |
4826 | } | |
4827 | case DW_LNS_copy: | |
4828 | /* Increment view after printing this row. */ | |
4829 | break; | |
4830 | ||
4831 | case DW_LNS_advance_pc: | |
4832 | READ_ULEB (uladv, data, end); | |
4833 | if (linfo.li_max_ops_per_insn == 1) | |
4834 | { | |
4835 | uladv *= linfo.li_min_insn_length; | |
4836 | state_machine_regs.address += uladv; | |
4837 | if (uladv) | |
4838 | state_machine_regs.view = 0; | |
4839 | } | |
4840 | else | |
4841 | { | |
4842 | unsigned addrdelta | |
4843 | = ((state_machine_regs.op_index + uladv) | |
4844 | / linfo.li_max_ops_per_insn) | |
4845 | * linfo.li_min_insn_length; | |
4846 | state_machine_regs.address | |
4847 | += addrdelta; | |
4848 | state_machine_regs.op_index | |
4849 | = (state_machine_regs.op_index + uladv) | |
4850 | % linfo.li_max_ops_per_insn; | |
4851 | if (addrdelta) | |
4852 | state_machine_regs.view = 0; | |
4853 | } | |
4854 | break; | |
4855 | ||
4856 | case DW_LNS_advance_line: | |
4857 | READ_SLEB (adv, data, end); | |
4858 | state_machine_regs.line += adv; | |
4859 | break; | |
4860 | ||
4861 | case DW_LNS_set_file: | |
4862 | READ_ULEB (uladv, data, end); | |
4863 | state_machine_regs.file = uladv; | |
4864 | ||
4865 | { | |
4866 | unsigned file = state_machine_regs.file - 1; | |
4867 | unsigned dir; | |
4868 | ||
4869 | if (file_table == NULL || n_files == 0) | |
4870 | printf (_("\n [Use file table entry %d]\n"), file); | |
4871 | /* PR 20439 */ | |
4872 | else if (file >= n_files) | |
4873 | { | |
4874 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
4875 | printf (_("\n <over large file table index %u>"), file); | |
4876 | } | |
4877 | else if ((dir = file_table[file].directory_index) == 0) | |
4878 | /* If directory index is 0, that means current directory. */ | |
4879 | printf ("\n./%s:[++]\n", file_table[file].name); | |
4880 | else if (directory_table == NULL || n_directories == 0) | |
4881 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
4882 | file_table[file].name, dir); | |
4883 | /* PR 20439 */ | |
4884 | else if (dir > n_directories) | |
4885 | { | |
4886 | warn (_("directory index %u > number of directories %s\n"), | |
4887 | dir, dwarf_vmatoa ("u", n_directories)); | |
4888 | printf (_("\n <over large directory table entry %u>\n"), dir); | |
4889 | } | |
4890 | else | |
4891 | printf ("\n%s/%s:\n", | |
4892 | /* The directory index starts counting at 1. */ | |
4893 | directory_table[dir - 1], file_table[file].name); | |
4894 | } | |
4895 | break; | |
4896 | ||
4897 | case DW_LNS_set_column: | |
4898 | READ_ULEB (uladv, data, end); | |
4899 | state_machine_regs.column = uladv; | |
4900 | break; | |
4901 | ||
4902 | case DW_LNS_negate_stmt: | |
4903 | adv = state_machine_regs.is_stmt; | |
4904 | adv = ! adv; | |
4905 | state_machine_regs.is_stmt = adv; | |
4906 | break; | |
4907 | ||
4908 | case DW_LNS_set_basic_block: | |
4909 | state_machine_regs.basic_block = 1; | |
4910 | break; | |
4911 | ||
4912 | case DW_LNS_const_add_pc: | |
4913 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4914 | if (linfo.li_max_ops_per_insn == 1) | |
4915 | { | |
4916 | uladv *= linfo.li_min_insn_length; | |
4917 | state_machine_regs.address += uladv; | |
4918 | if (uladv) | |
4919 | state_machine_regs.view = 0; | |
4920 | } | |
4921 | else | |
4922 | { | |
4923 | unsigned addrdelta | |
4924 | = ((state_machine_regs.op_index + uladv) | |
4925 | / linfo.li_max_ops_per_insn) | |
4926 | * linfo.li_min_insn_length; | |
4927 | state_machine_regs.address | |
4928 | += addrdelta; | |
4929 | state_machine_regs.op_index | |
4930 | = (state_machine_regs.op_index + uladv) | |
4931 | % linfo.li_max_ops_per_insn; | |
4932 | if (addrdelta) | |
4933 | state_machine_regs.view = 0; | |
4934 | } | |
4935 | break; | |
4936 | ||
4937 | case DW_LNS_fixed_advance_pc: | |
4938 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4939 | state_machine_regs.address += uladv; | |
4940 | state_machine_regs.op_index = 0; | |
4941 | /* Do NOT reset view. */ | |
4942 | break; | |
4943 | ||
4944 | case DW_LNS_set_prologue_end: | |
4945 | break; | |
4946 | ||
4947 | case DW_LNS_set_epilogue_begin: | |
4948 | break; | |
4949 | ||
4950 | case DW_LNS_set_isa: | |
4951 | READ_ULEB (uladv, data, end); | |
4952 | printf (_(" Set ISA to %lu\n"), uladv); | |
4953 | break; | |
4954 | ||
4955 | default: | |
4956 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4957 | ||
4958 | if (standard_opcodes != NULL) | |
4959 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4960 | { | |
4961 | dwarf_vma val; | |
4962 | ||
4963 | READ_ULEB (val, data, end); | |
4964 | printf ("0x%s%s", dwarf_vmatoa ("x", val), | |
4965 | i == 1 ? "" : ", "); | |
4966 | } | |
4967 | putchar ('\n'); | |
4968 | break; | |
4969 | } | |
a262ae96 | 4970 | |
b4eb7656 AM |
4971 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
4972 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
4973 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
4974 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
4975 | { |
4976 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
4977 | char *fileName; | |
4978 | char *newFileName = NULL; | |
4979 | size_t fileNameLength; | |
b40bf0a2 NC |
4980 | |
4981 | if (file_table) | |
db9537d2 NC |
4982 | { |
4983 | unsigned indx = state_machine_regs.file - 1; | |
4984 | /* PR 20439 */ | |
4985 | if (indx >= n_files) | |
4986 | { | |
4987 | warn (_("corrupt file index %u encountered\n"), indx); | |
4988 | fileName = _("<corrupt>"); | |
4989 | } | |
4990 | else | |
4991 | fileName = (char *) file_table[indx].name; | |
4992 | } | |
b40bf0a2 | 4993 | else |
db9537d2 | 4994 | fileName = _("<unknown>"); |
b40bf0a2 NC |
4995 | |
4996 | fileNameLength = strlen (fileName); | |
a262ae96 | 4997 | |
b4eb7656 AM |
4998 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
4999 | { | |
5000 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
5001 | /* Truncate file name */ | |
5002 | strncpy (newFileName, | |
5003 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
5004 | MAX_FILENAME_LENGTH + 1); | |
e1104d08 NC |
5005 | /* FIXME: This is to pacify gcc-10 which can warn that the |
5006 | strncpy above might leave a non-NUL terminated string | |
5007 | in newFileName. It won't, but gcc's analysis doesn't | |
5008 | quite go far enough to discover this. */ | |
5009 | newFileName[MAX_FILENAME_LENGTH] = 0; | |
b4eb7656 AM |
5010 | } |
5011 | else | |
5012 | { | |
5013 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
5014 | strncpy (newFileName, fileName, fileNameLength + 1); | |
5015 | } | |
5016 | ||
af2b3186 TV |
5017 | /* A row with end_seq set to true has a meaningful address, but |
5018 | the other information in the same row is not significant. | |
5019 | In such a row, print line as "-", and don't print | |
5020 | view/is_stmt. */ | |
b4eb7656 AM |
5021 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) |
5022 | { | |
a233b20c | 5023 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5024 | { |
5025 | if (xop == -DW_LNE_end_sequence) | |
5026 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x", | |
5027 | newFileName, "-", | |
5028 | state_machine_regs.address); | |
5029 | else | |
5030 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", | |
5031 | newFileName, state_machine_regs.line, | |
5032 | state_machine_regs.address); | |
5033 | } | |
a233b20c | 5034 | else |
af2b3186 TV |
5035 | { |
5036 | if (xop == -DW_LNE_end_sequence) | |
5037 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5038 | newFileName, "-", | |
5039 | state_machine_regs.address, | |
5040 | state_machine_regs.op_index); | |
5041 | else | |
5042 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5043 | newFileName, state_machine_regs.line, | |
5044 | state_machine_regs.address, | |
5045 | state_machine_regs.op_index); | |
5046 | } | |
b4eb7656 AM |
5047 | } |
5048 | else | |
5049 | { | |
a233b20c | 5050 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5051 | { |
5052 | if (xop == -DW_LNE_end_sequence) | |
5053 | printf ("%s %11s %#18" DWARF_VMA_FMT "x", | |
5054 | newFileName, "-", | |
5055 | state_machine_regs.address); | |
5056 | else | |
5057 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", | |
5058 | newFileName, state_machine_regs.line, | |
5059 | state_machine_regs.address); | |
5060 | } | |
a233b20c | 5061 | else |
af2b3186 TV |
5062 | { |
5063 | if (xop == -DW_LNE_end_sequence) | |
5064 | printf ("%s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5065 | newFileName, "-", | |
5066 | state_machine_regs.address, | |
5067 | state_machine_regs.op_index); | |
5068 | else | |
5069 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5070 | newFileName, state_machine_regs.line, | |
5071 | state_machine_regs.address, | |
5072 | state_machine_regs.op_index); | |
5073 | } | |
b4eb7656 | 5074 | } |
a262ae96 | 5075 | |
af2b3186 TV |
5076 | if (xop != -DW_LNE_end_sequence) |
5077 | { | |
5078 | if (state_machine_regs.view) | |
5079 | printf (" %6u", state_machine_regs.view); | |
5080 | else | |
5081 | printf (" "); | |
17f6ade2 | 5082 | |
af2b3186 TV |
5083 | if (state_machine_regs.is_stmt) |
5084 | printf (" x"); | |
5085 | } | |
17f6ade2 JD |
5086 | |
5087 | putchar ('\n'); | |
ba8826a8 AO |
5088 | state_machine_regs.view++; |
5089 | ||
5090 | if (xop == -DW_LNE_end_sequence) | |
5091 | { | |
5092 | reset_state_machine (linfo.li_default_is_stmt); | |
5093 | putchar ('\n'); | |
5094 | } | |
a262ae96 | 5095 | |
b4eb7656 AM |
5096 | free (newFileName); |
5097 | } | |
5098 | } | |
b40bf0a2 NC |
5099 | |
5100 | if (file_table) | |
5101 | { | |
5102 | free (file_table); | |
5103 | file_table = NULL; | |
5104 | n_files = 0; | |
5105 | } | |
5106 | ||
5107 | if (directory_table) | |
5108 | { | |
5109 | free (directory_table); | |
5110 | directory_table = NULL; | |
5111 | n_directories = 0; | |
5112 | } | |
5113 | ||
a262ae96 NC |
5114 | putchar ('\n'); |
5115 | } | |
5116 | ||
5117 | return 1; | |
5118 | } | |
5119 | ||
5120 | static int | |
77145576 | 5121 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
5122 | { |
5123 | unsigned char *data = section->start; | |
5124 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
5125 | int retValRaw = 1; |
5126 | int retValDecoded = 1; | |
a262ae96 | 5127 | |
008f4c78 NC |
5128 | if (do_debug_lines == 0) |
5129 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
5130 | ||
4cb93e3b | 5131 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 5132 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 5133 | |
4cb93e3b | 5134 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
ec1b0fbb | 5135 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
a262ae96 | 5136 | |
4cb93e3b | 5137 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
5138 | return 0; |
5139 | ||
5140 | return 1; | |
5141 | } | |
5142 | ||
6e3d6dc1 NC |
5143 | static debug_info * |
5144 | find_debug_info_for_offset (unsigned long offset) | |
5145 | { | |
5146 | unsigned int i; | |
5147 | ||
5148 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
5149 | return NULL; | |
5150 | ||
5151 | for (i = 0; i < num_debug_info_entries; i++) | |
5152 | if (debug_information[i].cu_offset == offset) | |
5153 | return debug_information + i; | |
5154 | ||
5155 | return NULL; | |
5156 | } | |
5157 | ||
459d52c8 DE |
5158 | static const char * |
5159 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
5160 | { | |
5161 | /* See gdb/gdb-index.h. */ | |
5162 | static const char * const kinds[] = | |
5163 | { | |
5164 | N_ ("no info"), | |
5165 | N_ ("type"), | |
5166 | N_ ("variable"), | |
5167 | N_ ("function"), | |
5168 | N_ ("other"), | |
5169 | N_ ("unused5"), | |
5170 | N_ ("unused6"), | |
5171 | N_ ("unused7") | |
5172 | }; | |
5173 | ||
5174 | return _ (kinds[kind]); | |
5175 | } | |
5176 | ||
19e6b90e | 5177 | static int |
459d52c8 DE |
5178 | display_debug_pubnames_worker (struct dwarf_section *section, |
5179 | void *file ATTRIBUTE_UNUSED, | |
5180 | int is_gnu) | |
19e6b90e | 5181 | { |
91d6fa6a | 5182 | DWARF2_Internal_PubNames names; |
19e6b90e L |
5183 | unsigned char *start = section->start; |
5184 | unsigned char *end = start + section->size; | |
5185 | ||
6e3d6dc1 NC |
5186 | /* It does not matter if this load fails, |
5187 | we test for that later on. */ | |
5188 | load_debug_info (file); | |
5189 | ||
dda8d76d | 5190 | introduce (section, FALSE); |
19e6b90e L |
5191 | |
5192 | while (start < end) | |
5193 | { | |
5194 | unsigned char *data; | |
e98fdf1a | 5195 | unsigned long sec_off; |
bf5117e3 | 5196 | unsigned int offset_size, initial_length_size; |
19e6b90e | 5197 | |
e98fdf1a | 5198 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 5199 | if (names.pn_length == 0xffffffff) |
19e6b90e | 5200 | { |
e98fdf1a | 5201 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e L |
5202 | offset_size = 8; |
5203 | initial_length_size = 12; | |
5204 | } | |
5205 | else | |
5206 | { | |
5207 | offset_size = 4; | |
5208 | initial_length_size = 4; | |
5209 | } | |
5210 | ||
e98fdf1a AM |
5211 | sec_off = start - section->start; |
5212 | if (sec_off + names.pn_length < sec_off | |
5213 | || sec_off + names.pn_length > section->size) | |
5214 | { | |
5215 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
5216 | section->name, | |
5217 | sec_off - initial_length_size, | |
5218 | dwarf_vmatoa ("x", names.pn_length)); | |
5219 | break; | |
5220 | } | |
5221 | ||
5222 | data = start; | |
5223 | start += names.pn_length; | |
5224 | ||
0c588247 NC |
5225 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
5226 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
5227 | |
5228 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
5229 | && num_debug_info_entries > 0 | |
91d6fa6a | 5230 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 5231 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 5232 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 5233 | |
0c588247 | 5234 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 5235 | |
058037d3 NC |
5236 | printf (_(" Length: %ld\n"), |
5237 | (long) names.pn_length); | |
5238 | printf (_(" Version: %d\n"), | |
5239 | names.pn_version); | |
5240 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
5241 | (unsigned long) names.pn_offset); | |
5242 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
5243 | (long) names.pn_size); | |
19e6b90e | 5244 | |
91d6fa6a | 5245 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
5246 | { |
5247 | static int warned = 0; | |
5248 | ||
5249 | if (! warned) | |
5250 | { | |
5251 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
5252 | warned = 1; | |
5253 | } | |
5254 | ||
5255 | continue; | |
5256 | } | |
5257 | ||
459d52c8 DE |
5258 | if (is_gnu) |
5259 | printf (_("\n Offset Kind Name\n")); | |
5260 | else | |
5261 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 5262 | |
e98fdf1a | 5263 | while (1) |
19e6b90e | 5264 | { |
f41e4712 | 5265 | bfd_size_type maxprint; |
e98fdf1a | 5266 | dwarf_vma offset; |
f41e4712 | 5267 | |
0c588247 | 5268 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e | 5269 | |
e98fdf1a AM |
5270 | if (offset == 0) |
5271 | break; | |
b4eb7656 | 5272 | |
e98fdf1a AM |
5273 | data += offset_size; |
5274 | if (data >= end) | |
5275 | break; | |
5276 | maxprint = (end - data) - 1; | |
f41e4712 | 5277 | |
e98fdf1a AM |
5278 | if (is_gnu) |
5279 | { | |
5280 | unsigned int kind_data; | |
5281 | gdb_index_symbol_kind kind; | |
5282 | const char *kind_name; | |
5283 | int is_static; | |
5284 | ||
5285 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
5286 | data++; | |
5287 | maxprint --; | |
5288 | /* GCC computes the kind as the upper byte in the CU index | |
5289 | word, and then right shifts it by the CU index size. | |
5290 | Left shift KIND to where the gdb-index.h accessor macros | |
5291 | can use it. */ | |
5292 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
5293 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
5294 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
5295 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
5296 | printf (" %-6lx %s,%-10s %.*s\n", | |
5297 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
5298 | kind_name, (int) maxprint, data); | |
19e6b90e | 5299 | } |
e98fdf1a AM |
5300 | else |
5301 | printf (" %-6lx\t%.*s\n", | |
5302 | (unsigned long) offset, (int) maxprint, data); | |
5303 | ||
5304 | data += strnlen ((char *) data, maxprint) + 1; | |
5305 | if (data >= end) | |
5306 | break; | |
19e6b90e | 5307 | } |
19e6b90e L |
5308 | } |
5309 | ||
5310 | printf ("\n"); | |
5311 | return 1; | |
5312 | } | |
5313 | ||
459d52c8 DE |
5314 | static int |
5315 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
5316 | { | |
5317 | return display_debug_pubnames_worker (section, file, 0); | |
5318 | } | |
5319 | ||
5320 | static int | |
5321 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
5322 | { | |
5323 | return display_debug_pubnames_worker (section, file, 1); | |
5324 | } | |
5325 | ||
19e6b90e L |
5326 | static int |
5327 | display_debug_macinfo (struct dwarf_section *section, | |
5328 | void *file ATTRIBUTE_UNUSED) | |
5329 | { | |
5330 | unsigned char *start = section->start; | |
5331 | unsigned char *end = start + section->size; | |
5332 | unsigned char *curr = start; | |
19e6b90e L |
5333 | enum dwarf_macinfo_record_type op; |
5334 | ||
dda8d76d | 5335 | introduce (section, FALSE); |
19e6b90e L |
5336 | |
5337 | while (curr < end) | |
5338 | { | |
5339 | unsigned int lineno; | |
0c588247 | 5340 | const unsigned char *string; |
19e6b90e | 5341 | |
3f5e193b | 5342 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
5343 | curr++; |
5344 | ||
5345 | switch (op) | |
5346 | { | |
5347 | case DW_MACINFO_start_file: | |
5348 | { | |
5349 | unsigned int filenum; | |
5350 | ||
cd30bcef AM |
5351 | READ_ULEB (lineno, curr, end); |
5352 | READ_ULEB (filenum, curr, end); | |
19e6b90e L |
5353 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), |
5354 | lineno, filenum); | |
5355 | } | |
5356 | break; | |
5357 | ||
5358 | case DW_MACINFO_end_file: | |
5359 | printf (_(" DW_MACINFO_end_file\n")); | |
5360 | break; | |
5361 | ||
5362 | case DW_MACINFO_define: | |
cd30bcef | 5363 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5364 | string = curr; |
5365 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5366 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
5367 | lineno, string); | |
5368 | break; | |
5369 | ||
5370 | case DW_MACINFO_undef: | |
cd30bcef | 5371 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5372 | string = curr; |
5373 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5374 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
5375 | lineno, string); | |
5376 | break; | |
5377 | ||
5378 | case DW_MACINFO_vendor_ext: | |
5379 | { | |
5380 | unsigned int constant; | |
5381 | ||
cd30bcef | 5382 | READ_ULEB (constant, curr, end); |
0c588247 NC |
5383 | string = curr; |
5384 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5385 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
5386 | constant, string); | |
5387 | } | |
5388 | break; | |
5389 | } | |
5390 | } | |
5391 | ||
5392 | return 1; | |
5393 | } | |
5394 | ||
4ccf1e31 JJ |
5395 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5396 | filename and dirname corresponding to file name table entry with index | |
5397 | FILEIDX. Return NULL on failure. */ | |
5398 | ||
5399 | static unsigned char * | |
f6f0e17b NC |
5400 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5401 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5402 | unsigned char **dir_name) |
5403 | { | |
5404 | struct dwarf_section *section = &debug_displays [line].section; | |
5405 | unsigned char *hdrptr, *dirtable, *file_name; | |
5406 | unsigned int offset_size, initial_length_size; | |
cd30bcef | 5407 | unsigned int version, opcode_base; |
4ccf1e31 | 5408 | dwarf_vma length, diridx; |
f6f0e17b | 5409 | const unsigned char * end; |
4ccf1e31 JJ |
5410 | |
5411 | *dir_name = NULL; | |
5412 | if (section->start == NULL | |
5413 | || line_offset >= section->size | |
5414 | || fileidx == 0) | |
5415 | return NULL; | |
5416 | ||
5417 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5418 | end = section->start + section->size; |
0c588247 NC |
5419 | |
5420 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5421 | if (length == 0xffffffff) |
5422 | { | |
5423 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5424 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
5425 | offset_size = 8; |
5426 | initial_length_size = 12; | |
5427 | } | |
5428 | else | |
5429 | { | |
5430 | offset_size = 4; | |
5431 | initial_length_size = 4; | |
5432 | } | |
e98fdf1a AM |
5433 | if (length + initial_length_size < length |
5434 | || length + initial_length_size > section->size) | |
4ccf1e31 | 5435 | return NULL; |
0c588247 NC |
5436 | |
5437 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5438 | if (version != 2 && version != 3 && version != 4) |
5439 | return NULL; | |
5440 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5441 | if (version >= 4) | |
5442 | hdrptr++; /* Skip max_ops_per_insn. */ | |
5443 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
5444 | |
5445 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
5446 | if (opcode_base == 0) |
5447 | return NULL; | |
0c588247 | 5448 | |
4ccf1e31 | 5449 | hdrptr += opcode_base - 1; |
5c1c468d NC |
5450 | if (hdrptr >= end) |
5451 | return NULL; | |
5452 | ||
4ccf1e31 JJ |
5453 | dirtable = hdrptr; |
5454 | /* Skip over dirname table. */ | |
5455 | while (*hdrptr != '\0') | |
5c1c468d NC |
5456 | { |
5457 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; | |
5458 | if (hdrptr >= end) | |
5459 | return NULL; | |
5460 | } | |
4ccf1e31 | 5461 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 5462 | |
4ccf1e31 | 5463 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 5464 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 5465 | { |
0c588247 | 5466 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
cd30bcef AM |
5467 | SKIP_ULEB (hdrptr, end); |
5468 | SKIP_ULEB (hdrptr, end); | |
5469 | SKIP_ULEB (hdrptr, end); | |
4ccf1e31 | 5470 | } |
5c1c468d | 5471 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 5472 | return NULL; |
5c1c468d | 5473 | |
4ccf1e31 | 5474 | file_name = hdrptr; |
0c588247 | 5475 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
5c1c468d NC |
5476 | if (hdrptr >= end) |
5477 | return NULL; | |
cd30bcef | 5478 | READ_ULEB (diridx, hdrptr, end); |
4ccf1e31 JJ |
5479 | if (diridx == 0) |
5480 | return file_name; | |
5c1c468d | 5481 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
0c588247 | 5482 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
5c1c468d | 5483 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
5484 | return NULL; |
5485 | *dir_name = dirtable; | |
5486 | return file_name; | |
5487 | } | |
5488 | ||
5489 | static int | |
5490 | display_debug_macro (struct dwarf_section *section, | |
5491 | void *file) | |
5492 | { | |
5493 | unsigned char *start = section->start; | |
5494 | unsigned char *end = start + section->size; | |
5495 | unsigned char *curr = start; | |
5496 | unsigned char *extended_op_buf[256]; | |
4ccf1e31 | 5497 | |
dda8d76d NC |
5498 | load_debug_section_with_follow (str, file); |
5499 | load_debug_section_with_follow (line, file); | |
e4b7104b | 5500 | load_debug_section_with_follow (str_index, file); |
4ccf1e31 | 5501 | |
dda8d76d | 5502 | introduce (section, FALSE); |
4ccf1e31 JJ |
5503 | |
5504 | while (curr < end) | |
5505 | { | |
5506 | unsigned int lineno, version, flags; | |
5507 | unsigned int offset_size = 4; | |
0c588247 | 5508 | const unsigned char *string; |
4ccf1e31 JJ |
5509 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
5510 | unsigned char **extended_ops = NULL; | |
5511 | ||
0c588247 | 5512 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 5513 | if (version != 4 && version != 5) |
4ccf1e31 | 5514 | { |
7a7e1061 | 5515 | error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"), |
4ccf1e31 JJ |
5516 | section->name); |
5517 | return 0; | |
5518 | } | |
5519 | ||
0c588247 | 5520 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
4ccf1e31 JJ |
5521 | if (flags & 1) |
5522 | offset_size = 8; | |
5523 | printf (_(" Offset: 0x%lx\n"), | |
5524 | (unsigned long) sec_offset); | |
5525 | printf (_(" Version: %d\n"), version); | |
5526 | printf (_(" Offset size: %d\n"), offset_size); | |
5527 | if (flags & 2) | |
5528 | { | |
0c588247 | 5529 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
5530 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
5531 | (unsigned long) line_offset); | |
5532 | } | |
5533 | if (flags & 4) | |
5534 | { | |
0c588247 | 5535 | unsigned int i, count, op; |
4ccf1e31 | 5536 | dwarf_vma nargs, n; |
0c588247 NC |
5537 | |
5538 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 5539 | |
4ccf1e31 JJ |
5540 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
5541 | extended_ops = extended_op_buf; | |
5542 | if (count) | |
5543 | { | |
5544 | printf (_(" Extension opcode arguments:\n")); | |
5545 | for (i = 0; i < count; i++) | |
5546 | { | |
0c588247 | 5547 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 5548 | extended_ops[op] = curr; |
cd30bcef | 5549 | READ_ULEB (nargs, curr, end); |
4ccf1e31 | 5550 | if (nargs == 0) |
7a7e1061 | 5551 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
5552 | else |
5553 | { | |
7a7e1061 | 5554 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
5555 | for (n = 0; n < nargs; n++) |
5556 | { | |
0c588247 NC |
5557 | unsigned int form; |
5558 | ||
5559 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
5560 | printf ("%s%s", get_FORM_name (form), |
5561 | n == nargs - 1 ? "\n" : ", "); | |
5562 | switch (form) | |
5563 | { | |
5564 | case DW_FORM_data1: | |
5565 | case DW_FORM_data2: | |
5566 | case DW_FORM_data4: | |
5567 | case DW_FORM_data8: | |
5568 | case DW_FORM_sdata: | |
5569 | case DW_FORM_udata: | |
5570 | case DW_FORM_block: | |
5571 | case DW_FORM_block1: | |
5572 | case DW_FORM_block2: | |
5573 | case DW_FORM_block4: | |
5574 | case DW_FORM_flag: | |
5575 | case DW_FORM_string: | |
5576 | case DW_FORM_strp: | |
5577 | case DW_FORM_sec_offset: | |
5578 | break; | |
5579 | default: | |
5580 | error (_("Invalid extension opcode form %s\n"), | |
5581 | get_FORM_name (form)); | |
5582 | return 0; | |
5583 | } | |
5584 | } | |
5585 | } | |
5586 | } | |
5587 | } | |
5588 | } | |
5589 | printf ("\n"); | |
5590 | ||
5591 | while (1) | |
5592 | { | |
5593 | unsigned int op; | |
5594 | ||
5595 | if (curr >= end) | |
5596 | { | |
5597 | error (_(".debug_macro section not zero terminated\n")); | |
5598 | return 0; | |
5599 | } | |
5600 | ||
0c588247 | 5601 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
5602 | if (op == 0) |
5603 | break; | |
5604 | ||
5605 | switch (op) | |
5606 | { | |
e4b7104b NC |
5607 | case DW_MACRO_define: |
5608 | READ_ULEB (lineno, curr, end); | |
5609 | string = curr; | |
5610 | curr += strnlen ((char *) string, end - string) + 1; | |
5611 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), | |
5612 | lineno, string); | |
5613 | break; | |
5614 | ||
5615 | case DW_MACRO_undef: | |
5616 | READ_ULEB (lineno, curr, end); | |
5617 | string = curr; | |
5618 | curr += strnlen ((char *) string, end - string) + 1; | |
5619 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), | |
5620 | lineno, string); | |
5621 | break; | |
5622 | ||
7a7e1061 | 5623 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
5624 | { |
5625 | unsigned int filenum; | |
5626 | unsigned char *file_name = NULL, *dir_name = NULL; | |
5627 | ||
cd30bcef AM |
5628 | READ_ULEB (lineno, curr, end); |
5629 | READ_ULEB (filenum, curr, end); | |
4ccf1e31 JJ |
5630 | |
5631 | if ((flags & 2) == 0) | |
7a7e1061 | 5632 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
5633 | else |
5634 | file_name | |
5635 | = get_line_filename_and_dirname (line_offset, filenum, | |
5636 | &dir_name); | |
5637 | if (file_name == NULL) | |
7a7e1061 | 5638 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
5639 | lineno, filenum); |
5640 | else | |
7a7e1061 | 5641 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
5642 | lineno, filenum, |
5643 | dir_name != NULL ? (const char *) dir_name : "", | |
5644 | dir_name != NULL ? "/" : "", file_name); | |
5645 | } | |
5646 | break; | |
5647 | ||
7a7e1061 JK |
5648 | case DW_MACRO_end_file: |
5649 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
5650 | break; |
5651 | ||
7a7e1061 | 5652 | case DW_MACRO_define_strp: |
cd30bcef | 5653 | READ_ULEB (lineno, curr, end); |
0c588247 | 5654 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5655 | string = fetch_indirect_string (offset); |
7a7e1061 | 5656 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5657 | lineno, string); |
5658 | break; | |
5659 | ||
7a7e1061 | 5660 | case DW_MACRO_undef_strp: |
cd30bcef | 5661 | READ_ULEB (lineno, curr, end); |
0c588247 | 5662 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5663 | string = fetch_indirect_string (offset); |
7a7e1061 | 5664 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5665 | lineno, string); |
5666 | break; | |
5667 | ||
7a7e1061 | 5668 | case DW_MACRO_import: |
0c588247 | 5669 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5670 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
5671 | (unsigned long) offset); |
5672 | break; | |
5673 | ||
7a7e1061 | 5674 | case DW_MACRO_define_sup: |
cd30bcef | 5675 | READ_ULEB (lineno, curr, end); |
0c588247 | 5676 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5677 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5678 | lineno, (unsigned long) offset); |
5679 | break; | |
5680 | ||
7a7e1061 | 5681 | case DW_MACRO_undef_sup: |
cd30bcef | 5682 | READ_ULEB (lineno, curr, end); |
0c588247 | 5683 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5684 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5685 | lineno, (unsigned long) offset); |
5686 | break; | |
5687 | ||
7a7e1061 | 5688 | case DW_MACRO_import_sup: |
0c588247 | 5689 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5690 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
5691 | (unsigned long) offset); |
5692 | break; | |
5693 | ||
e4b7104b NC |
5694 | case DW_MACRO_define_strx: |
5695 | case DW_MACRO_undef_strx: | |
5696 | READ_ULEB (lineno, curr, end); | |
5697 | READ_ULEB (offset, curr, end); | |
5698 | string = (const unsigned char *) | |
5699 | fetch_indexed_string (offset, NULL, offset_size, FALSE); | |
5700 | if (op == DW_MACRO_define_strx) | |
5701 | printf (" DW_MACRO_define_strx "); | |
5702 | else | |
5703 | printf (" DW_MACRO_undef_strx "); | |
5704 | if (do_wide) | |
39f381cb | 5705 | printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset)); |
e4b7104b NC |
5706 | printf (_("lineno : %d macro : %s\n"), |
5707 | lineno, string); | |
5708 | break; | |
5709 | ||
4ccf1e31 | 5710 | default: |
e4b7104b NC |
5711 | if (op >= DW_MACRO_lo_user && op <= DW_MACRO_hi_user) |
5712 | { | |
5713 | printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op); | |
5714 | break; | |
5715 | } | |
5716 | ||
4ccf1e31 JJ |
5717 | if (extended_ops == NULL || extended_ops[op] == NULL) |
5718 | { | |
5719 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
5720 | return 0; | |
5721 | } | |
5722 | else | |
5723 | { | |
5724 | /* Skip over unhandled opcodes. */ | |
5725 | dwarf_vma nargs, n; | |
5726 | unsigned char *desc = extended_ops[op]; | |
cd30bcef | 5727 | READ_ULEB (nargs, desc, end); |
4ccf1e31 JJ |
5728 | if (nargs == 0) |
5729 | { | |
7a7e1061 | 5730 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
5731 | break; |
5732 | } | |
7a7e1061 | 5733 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
5734 | for (n = 0; n < nargs; n++) |
5735 | { | |
0c588247 NC |
5736 | int val; |
5737 | ||
77145576 | 5738 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 5739 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 5740 | curr |
77145576 | 5741 | = read_and_display_attr_value (0, val, 0, |
ec1b0fbb | 5742 | start, curr, end, 0, 0, offset_size, |
341f9135 | 5743 | version, NULL, 0, NULL, |
ec1b0fbb | 5744 | NULL, ' ', -1); |
4ccf1e31 JJ |
5745 | if (n != nargs - 1) |
5746 | printf (","); | |
5747 | } | |
5748 | printf ("\n"); | |
5749 | } | |
5750 | break; | |
5751 | } | |
5752 | } | |
5753 | ||
5754 | printf ("\n"); | |
b4eb7656 | 5755 | } |
4ccf1e31 JJ |
5756 | |
5757 | return 1; | |
5758 | } | |
5759 | ||
19e6b90e L |
5760 | static int |
5761 | display_debug_abbrev (struct dwarf_section *section, | |
5762 | void *file ATTRIBUTE_UNUSED) | |
5763 | { | |
5764 | abbrev_entry *entry; | |
5765 | unsigned char *start = section->start; | |
5766 | unsigned char *end = start + section->size; | |
5767 | ||
dda8d76d | 5768 | introduce (section, FALSE); |
19e6b90e L |
5769 | |
5770 | do | |
5771 | { | |
7282333f AM |
5772 | unsigned char *last; |
5773 | ||
19e6b90e L |
5774 | free_abbrevs (); |
5775 | ||
7282333f | 5776 | last = start; |
19e6b90e L |
5777 | start = process_abbrev_section (start, end); |
5778 | ||
5779 | if (first_abbrev == NULL) | |
5780 | continue; | |
5781 | ||
7282333f | 5782 | printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start)); |
19e6b90e L |
5783 | |
5784 | for (entry = first_abbrev; entry; entry = entry->next) | |
5785 | { | |
5786 | abbrev_attr *attr; | |
5787 | ||
cc5914eb | 5788 | printf (" %ld %s [%s]\n", |
19e6b90e L |
5789 | entry->entry, |
5790 | get_TAG_name (entry->tag), | |
5791 | entry->children ? _("has children") : _("no children")); | |
5792 | ||
5793 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
5794 | { |
5795 | printf (" %-18s %s", | |
5796 | get_AT_name (attr->attribute), | |
5797 | get_FORM_name (attr->form)); | |
5798 | if (attr->form == DW_FORM_implicit_const) | |
5799 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
5800 | putchar ('\n'); | |
5801 | } | |
19e6b90e L |
5802 | } |
5803 | } | |
5804 | while (start); | |
5805 | ||
5806 | printf ("\n"); | |
5807 | ||
5808 | return 1; | |
5809 | } | |
5810 | ||
42bcef4a AB |
5811 | /* Return true when ADDR is the maximum address, when addresses are |
5812 | POINTER_SIZE bytes long. */ | |
5813 | ||
5814 | static bfd_boolean | |
5815 | is_max_address (dwarf_vma addr, unsigned int pointer_size) | |
5816 | { | |
5817 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
5818 | return ((addr & mask) == mask); | |
5819 | } | |
5820 | ||
9f272209 AO |
5821 | /* Display a view pair list starting at *VSTART_PTR and ending at |
5822 | VLISTEND within SECTION. */ | |
5823 | ||
5824 | static void | |
5825 | display_view_pair_list (struct dwarf_section *section, | |
5826 | unsigned char **vstart_ptr, | |
5827 | unsigned int debug_info_entry, | |
5828 | unsigned char *vlistend) | |
5829 | { | |
5830 | unsigned char *vstart = *vstart_ptr; | |
5831 | unsigned char *section_end = section->start + section->size; | |
5832 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
5833 | ||
5834 | if (vlistend < section_end) | |
5835 | section_end = vlistend; | |
5836 | ||
5837 | putchar ('\n'); | |
5838 | ||
5839 | while (vstart < section_end) | |
5840 | { | |
5841 | dwarf_vma off = vstart - section->start; | |
5842 | dwarf_vma vbegin, vend; | |
5843 | ||
cd30bcef | 5844 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 | 5845 | if (vstart == section_end) |
cd30bcef | 5846 | break; |
9f272209 | 5847 | |
cd30bcef | 5848 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
5849 | printf (" %8.8lx ", (unsigned long) off); |
5850 | ||
5851 | print_dwarf_view (vbegin, pointer_size, 1); | |
5852 | print_dwarf_view (vend, pointer_size, 1); | |
5853 | printf (_("location view pair\n")); | |
5854 | } | |
5855 | ||
5856 | putchar ('\n'); | |
5857 | *vstart_ptr = vstart; | |
5858 | } | |
5859 | ||
4723351a CC |
5860 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
5861 | ||
5862 | static void | |
5863 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
5864 | unsigned char **start_ptr, |
5865 | unsigned int debug_info_entry, | |
359ca075 JK |
5866 | dwarf_vma offset, |
5867 | dwarf_vma base_address, | |
9f272209 | 5868 | unsigned char **vstart_ptr, |
b4eb7656 | 5869 | int has_frame_base) |
4723351a | 5870 | { |
9f272209 | 5871 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 5872 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
5873 | unsigned long cu_offset; |
5874 | unsigned int pointer_size; | |
5875 | unsigned int offset_size; | |
5876 | int dwarf_version; | |
4723351a CC |
5877 | |
5878 | dwarf_vma begin; | |
5879 | dwarf_vma end; | |
5880 | unsigned short length; | |
5881 | int need_frame_base; | |
5882 | ||
82b1b41b NC |
5883 | if (debug_info_entry >= num_debug_info_entries) |
5884 | { | |
5885 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
5886 | debug_info_entry); | |
5887 | return; | |
5888 | } | |
b4eb7656 | 5889 | |
82b1b41b NC |
5890 | cu_offset = debug_information [debug_info_entry].cu_offset; |
5891 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5892 | offset_size = debug_information [debug_info_entry].offset_size; | |
5893 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 5894 | |
f41e4712 NC |
5895 | if (pointer_size < 2 || pointer_size > 8) |
5896 | { | |
5897 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5898 | pointer_size, debug_info_entry); | |
5899 | return; | |
5900 | } | |
5901 | ||
4723351a CC |
5902 | while (1) |
5903 | { | |
359ca075 | 5904 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 5905 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 5906 | |
4723351a | 5907 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
5908 | { |
5909 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5910 | (unsigned long) offset); |
b4eb7656 AM |
5911 | break; |
5912 | } | |
4723351a | 5913 | |
359ca075 | 5914 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 5915 | |
0c588247 NC |
5916 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
5917 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 5918 | |
4723351a | 5919 | if (begin == 0 && end == 0) |
b4eb7656 | 5920 | { |
d1c4b12b NC |
5921 | /* PR 18374: In a object file we can have a location list that |
5922 | starts with a begin and end of 0 because there are relocations | |
5923 | that need to be applied to the addresses. Actually applying | |
5924 | the relocations now does not help as they will probably resolve | |
5925 | to 0, since the object file has not been fully linked. Real | |
5926 | end of list markers will not have any relocations against them. */ | |
5927 | if (! reloc_at (section, off) | |
5928 | && ! reloc_at (section, off + pointer_size)) | |
5929 | { | |
5930 | printf (_("<End of list>\n")); | |
5931 | break; | |
5932 | } | |
b4eb7656 | 5933 | } |
4723351a CC |
5934 | |
5935 | /* Check base address specifiers. */ | |
42bcef4a AB |
5936 | if (is_max_address (begin, pointer_size) |
5937 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
5938 | { |
5939 | base_address = end; | |
5940 | print_dwarf_vma (begin, pointer_size); | |
5941 | print_dwarf_vma (end, pointer_size); | |
5942 | printf (_("(base address)\n")); | |
5943 | continue; | |
5944 | } | |
4723351a | 5945 | |
9f272209 AO |
5946 | if (vstart) |
5947 | { | |
9f272209 AO |
5948 | off = offset + (vstart - *start_ptr); |
5949 | ||
cd30bcef | 5950 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
5951 | print_dwarf_view (vbegin, pointer_size, 1); |
5952 | ||
cd30bcef | 5953 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
5954 | print_dwarf_view (vend, pointer_size, 1); |
5955 | ||
5956 | printf (_("views at %8.8lx for:\n %*s "), | |
5957 | (unsigned long) off, 8, ""); | |
5958 | } | |
5959 | ||
4723351a | 5960 | if (start + 2 > section_end) |
b4eb7656 AM |
5961 | { |
5962 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5963 | (unsigned long) offset); |
b4eb7656 AM |
5964 | break; |
5965 | } | |
4723351a | 5966 | |
0c588247 | 5967 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
5968 | |
5969 | if (start + length > section_end) | |
b4eb7656 AM |
5970 | { |
5971 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5972 | (unsigned long) offset); |
b4eb7656 AM |
5973 | break; |
5974 | } | |
4723351a CC |
5975 | |
5976 | print_dwarf_vma (begin + base_address, pointer_size); | |
5977 | print_dwarf_vma (end + base_address, pointer_size); | |
5978 | ||
5979 | putchar ('('); | |
5980 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
5981 | pointer_size, |
5982 | offset_size, | |
5983 | dwarf_version, | |
5984 | length, | |
5985 | cu_offset, section); | |
4723351a CC |
5986 | putchar (')'); |
5987 | ||
5988 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 5989 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 5990 | |
9f272209 | 5991 | if (begin == end && vbegin == vend) |
b4eb7656 | 5992 | fputs (_(" (start == end)"), stdout); |
9f272209 | 5993 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 5994 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
5995 | |
5996 | putchar ('\n'); | |
5997 | ||
5998 | start += length; | |
5999 | } | |
6000 | ||
6001 | *start_ptr = start; | |
9f272209 | 6002 | *vstart_ptr = vstart; |
4723351a CC |
6003 | } |
6004 | ||
77145576 JK |
6005 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
6006 | ||
6007 | static void | |
6008 | display_loclists_list (struct dwarf_section *section, | |
6009 | unsigned char **start_ptr, | |
6010 | unsigned int debug_info_entry, | |
6011 | dwarf_vma offset, | |
6012 | dwarf_vma base_address, | |
9f272209 | 6013 | unsigned char **vstart_ptr, |
77145576 JK |
6014 | int has_frame_base) |
6015 | { | |
9f272209 | 6016 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
6017 | unsigned char *section_end = section->start + section->size; |
6018 | unsigned long cu_offset; | |
6019 | unsigned int pointer_size; | |
6020 | unsigned int offset_size; | |
6021 | int dwarf_version; | |
77145576 | 6022 | |
9dfd0db9 | 6023 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
6024 | dwarf_vma begin = -1, vbegin = -1; |
6025 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
6026 | dwarf_vma length; |
6027 | int need_frame_base; | |
6028 | ||
6029 | if (debug_info_entry >= num_debug_info_entries) | |
6030 | { | |
6031 | warn (_("No debug information available for " | |
6032 | "loclists lists of entry: %u\n"), | |
6033 | debug_info_entry); | |
6034 | return; | |
6035 | } | |
6036 | ||
6037 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6038 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6039 | offset_size = debug_information [debug_info_entry].offset_size; | |
6040 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6041 | ||
6042 | if (pointer_size < 2 || pointer_size > 8) | |
6043 | { | |
6044 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6045 | pointer_size, debug_info_entry); | |
6046 | return; | |
6047 | } | |
6048 | ||
6049 | while (1) | |
6050 | { | |
6051 | dwarf_vma off = offset + (start - *start_ptr); | |
6052 | enum dwarf_location_list_entry_type llet; | |
6053 | ||
6054 | if (start + 1 > section_end) | |
6055 | { | |
6056 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6057 | (unsigned long) offset); | |
6058 | break; | |
6059 | } | |
6060 | ||
6061 | printf (" %8.8lx ", (unsigned long) off); | |
6062 | ||
6063 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
6064 | ||
1c9f770d MW |
6065 | if (vstart && (llet == DW_LLE_offset_pair |
6066 | || llet == DW_LLE_start_end | |
6067 | || llet == DW_LLE_start_length)) | |
9f272209 AO |
6068 | { |
6069 | off = offset + (vstart - *start_ptr); | |
6070 | ||
cd30bcef | 6071 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
6072 | print_dwarf_view (vbegin, pointer_size, 1); |
6073 | ||
cd30bcef | 6074 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6075 | print_dwarf_view (vend, pointer_size, 1); |
6076 | ||
6077 | printf (_("views at %8.8lx for:\n %*s "), | |
6078 | (unsigned long) off, 8, ""); | |
6079 | } | |
6080 | ||
77145576 JK |
6081 | switch (llet) |
6082 | { | |
6083 | case DW_LLE_end_of_list: | |
6084 | printf (_("<End of list>\n")); | |
6085 | break; | |
6086 | case DW_LLE_offset_pair: | |
cd30bcef | 6087 | READ_ULEB (begin, start, section_end); |
1c9f770d | 6088 | begin += base_address; |
cd30bcef | 6089 | READ_ULEB (end, start, section_end); |
1c9f770d MW |
6090 | end += base_address; |
6091 | break; | |
6092 | case DW_LLE_start_end: | |
6093 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6094 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
6095 | break; | |
6096 | case DW_LLE_start_length: | |
6097 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6098 | READ_ULEB (end, start, section_end); | |
6099 | end += begin; | |
77145576 JK |
6100 | break; |
6101 | case DW_LLE_base_address: | |
6102 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
6103 | section_end); | |
6104 | print_dwarf_vma (base_address, pointer_size); | |
6105 | printf (_("(base address)\n")); | |
6106 | break; | |
9f272209 AO |
6107 | #ifdef DW_LLE_view_pair |
6108 | case DW_LLE_view_pair: | |
6109 | if (vstart) | |
6110 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
cd30bcef | 6111 | READ_ULEB (vbegin, start, section_end); |
9f272209 AO |
6112 | print_dwarf_view (vbegin, pointer_size, 1); |
6113 | ||
cd30bcef | 6114 | READ_ULEB (vend, start, section_end); |
9f272209 AO |
6115 | print_dwarf_view (vend, pointer_size, 1); |
6116 | ||
6117 | printf (_("views for:\n")); | |
6118 | continue; | |
6119 | #endif | |
77145576 JK |
6120 | default: |
6121 | error (_("Invalid location list entry type %d\n"), llet); | |
6122 | return; | |
6123 | } | |
6124 | if (llet == DW_LLE_end_of_list) | |
6125 | break; | |
1c9f770d MW |
6126 | if (llet != DW_LLE_offset_pair |
6127 | && llet != DW_LLE_start_end | |
6128 | && llet != DW_LLE_start_length) | |
77145576 JK |
6129 | continue; |
6130 | ||
6131 | if (start + 2 > section_end) | |
6132 | { | |
6133 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6134 | (unsigned long) offset); | |
6135 | break; | |
6136 | } | |
6137 | ||
cd30bcef | 6138 | READ_ULEB (length, start, section_end); |
77145576 | 6139 | |
1c9f770d MW |
6140 | print_dwarf_vma (begin, pointer_size); |
6141 | print_dwarf_vma (end, pointer_size); | |
77145576 JK |
6142 | |
6143 | putchar ('('); | |
6144 | need_frame_base = decode_location_expression (start, | |
6145 | pointer_size, | |
6146 | offset_size, | |
6147 | dwarf_version, | |
6148 | length, | |
6149 | cu_offset, section); | |
6150 | putchar (')'); | |
6151 | ||
6152 | if (need_frame_base && !has_frame_base) | |
6153 | printf (_(" [without DW_AT_frame_base]")); | |
6154 | ||
9f272209 | 6155 | if (begin == end && vbegin == vend) |
77145576 | 6156 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6157 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
6158 | fputs (_(" (start > end)"), stdout); |
6159 | ||
6160 | putchar ('\n'); | |
6161 | ||
6162 | start += length; | |
9f272209 | 6163 | vbegin = vend = -1; |
77145576 JK |
6164 | } |
6165 | ||
9f272209 AO |
6166 | if (vbegin != vm1 || vend != vm1) |
6167 | printf (_("Trailing view pair not used in a range")); | |
6168 | ||
77145576 | 6169 | *start_ptr = start; |
9f272209 | 6170 | *vstart_ptr = vstart; |
77145576 JK |
6171 | } |
6172 | ||
fab128ef CC |
6173 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
6174 | right-adjusted in a field of length LEN, and followed by a space. */ | |
6175 | ||
6176 | static void | |
6177 | print_addr_index (unsigned int idx, unsigned int len) | |
6178 | { | |
6179 | static char buf[15]; | |
6180 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 6181 | printf ("%*s ", len, buf); |
fab128ef CC |
6182 | } |
6183 | ||
4723351a CC |
6184 | /* Display a location list from a .dwo section. It uses address indexes rather |
6185 | than embedded addresses. This code closely follows display_loc_list, but the | |
6186 | two are sufficiently different that combining things is very ugly. */ | |
6187 | ||
6188 | static void | |
6189 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
6190 | unsigned char **start_ptr, |
6191 | unsigned int debug_info_entry, | |
359ca075 | 6192 | dwarf_vma offset, |
9f272209 | 6193 | unsigned char **vstart_ptr, |
b4eb7656 | 6194 | int has_frame_base) |
4723351a | 6195 | { |
9f272209 | 6196 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6197 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6198 | unsigned long cu_offset; |
6199 | unsigned int pointer_size; | |
6200 | unsigned int offset_size; | |
6201 | int dwarf_version; | |
4723351a CC |
6202 | int entry_type; |
6203 | unsigned short length; | |
6204 | int need_frame_base; | |
fab128ef | 6205 | unsigned int idx; |
4723351a | 6206 | |
82b1b41b NC |
6207 | if (debug_info_entry >= num_debug_info_entries) |
6208 | { | |
6209 | warn (_("No debug information for loc lists of entry: %u\n"), | |
6210 | debug_info_entry); | |
6211 | return; | |
6212 | } | |
6213 | ||
6214 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6215 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6216 | offset_size = debug_information [debug_info_entry].offset_size; | |
6217 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6218 | ||
f41e4712 NC |
6219 | if (pointer_size < 2 || pointer_size > 8) |
6220 | { | |
6221 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6222 | pointer_size, debug_info_entry); | |
6223 | return; | |
6224 | } | |
6225 | ||
4723351a CC |
6226 | while (1) |
6227 | { | |
359ca075 | 6228 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 6229 | |
fab128ef | 6230 | if (start >= section_end) |
b4eb7656 AM |
6231 | { |
6232 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6233 | (unsigned long) offset); |
b4eb7656 AM |
6234 | break; |
6235 | } | |
4723351a | 6236 | |
0c588247 | 6237 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
6238 | |
6239 | if (vstart) | |
6240 | switch (entry_type) | |
6241 | { | |
6242 | default: | |
6243 | break; | |
6244 | ||
6245 | case 2: | |
6246 | case 3: | |
6247 | case 4: | |
6248 | { | |
6249 | dwarf_vma view; | |
6250 | dwarf_vma off = offset + (vstart - *start_ptr); | |
6251 | ||
cd30bcef | 6252 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6253 | print_dwarf_view (view, 8, 1); |
6254 | ||
cd30bcef | 6255 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6256 | print_dwarf_view (view, 8, 1); |
6257 | ||
6258 | printf (_("views at %8.8lx for:\n %*s "), | |
6259 | (unsigned long) off, 8, ""); | |
6260 | ||
6261 | } | |
6262 | break; | |
6263 | } | |
6264 | ||
4723351a | 6265 | switch (entry_type) |
b4eb7656 AM |
6266 | { |
6267 | case 0: /* A terminating entry. */ | |
6268 | *start_ptr = start; | |
9f272209 | 6269 | *vstart_ptr = vstart; |
b4eb7656 AM |
6270 | printf (_("<End of list>\n")); |
6271 | return; | |
6272 | case 1: /* A base-address entry. */ | |
cd30bcef | 6273 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6274 | print_addr_index (idx, 8); |
9f272209 | 6275 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
6276 | printf (_("(base address selection entry)\n")); |
6277 | continue; | |
6278 | case 2: /* A start/end entry. */ | |
cd30bcef | 6279 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6280 | print_addr_index (idx, 8); |
cd30bcef | 6281 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6282 | print_addr_index (idx, 8); |
6283 | break; | |
6284 | case 3: /* A start/length entry. */ | |
cd30bcef | 6285 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6286 | print_addr_index (idx, 8); |
6287 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6288 | printf ("%08x ", idx); | |
6289 | break; | |
6290 | case 4: /* An offset pair entry. */ | |
6291 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6292 | printf ("%08x ", idx); | |
6293 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6294 | printf ("%08x ", idx); | |
6295 | break; | |
6296 | default: | |
6297 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
6298 | *start_ptr = start; | |
9f272209 | 6299 | *vstart_ptr = vstart; |
b4eb7656 AM |
6300 | return; |
6301 | } | |
4723351a CC |
6302 | |
6303 | if (start + 2 > section_end) | |
b4eb7656 AM |
6304 | { |
6305 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6306 | (unsigned long) offset); |
b4eb7656 AM |
6307 | break; |
6308 | } | |
4723351a | 6309 | |
0c588247 | 6310 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6311 | if (start + length > section_end) |
b4eb7656 AM |
6312 | { |
6313 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6314 | (unsigned long) offset); |
b4eb7656 AM |
6315 | break; |
6316 | } | |
4723351a CC |
6317 | |
6318 | putchar ('('); | |
6319 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6320 | pointer_size, |
6321 | offset_size, | |
6322 | dwarf_version, | |
6323 | length, | |
6324 | cu_offset, section); | |
4723351a CC |
6325 | putchar (')'); |
6326 | ||
6327 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6328 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
6329 | |
6330 | putchar ('\n'); | |
6331 | ||
6332 | start += length; | |
6333 | } | |
6334 | ||
6335 | *start_ptr = start; | |
9f272209 | 6336 | *vstart_ptr = vstart; |
4723351a CC |
6337 | } |
6338 | ||
9f272209 AO |
6339 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
6340 | loc_views. */ | |
51d0d03f | 6341 | |
9f272209 | 6342 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
6343 | |
6344 | static int | |
6345 | loc_offsets_compar (const void *ap, const void *bp) | |
6346 | { | |
6347 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
6348 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
6349 | ||
9f272209 AO |
6350 | int ret = (a > b) - (b > a); |
6351 | if (ret) | |
6352 | return ret; | |
6353 | ||
6354 | a = loc_views[*(const unsigned int *) ap]; | |
6355 | b = loc_views[*(const unsigned int *) bp]; | |
6356 | ||
6357 | ret = (a > b) - (b > a); | |
6358 | ||
6359 | return ret; | |
51d0d03f JJ |
6360 | } |
6361 | ||
19e6b90e L |
6362 | static int |
6363 | display_debug_loc (struct dwarf_section *section, void *file) | |
6364 | { | |
9f272209 | 6365 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
6366 | unsigned long bytes; |
6367 | unsigned char *section_begin = start; | |
6368 | unsigned int num_loc_list = 0; | |
6369 | unsigned long last_offset = 0; | |
9f272209 | 6370 | unsigned long last_view = 0; |
19e6b90e L |
6371 | unsigned int first = 0; |
6372 | unsigned int i; | |
6373 | unsigned int j; | |
6374 | int seen_first_offset = 0; | |
51d0d03f | 6375 | int locs_sorted = 1; |
9f272209 | 6376 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6377 | unsigned int *array = NULL; |
4723351a | 6378 | const char *suffix = strrchr (section->name, '.'); |
24841daa | 6379 | bfd_boolean is_dwo = FALSE; |
77145576 JK |
6380 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6381 | dwarf_vma expected_start = 0; | |
4723351a CC |
6382 | |
6383 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
24841daa | 6384 | is_dwo = TRUE; |
19e6b90e L |
6385 | |
6386 | bytes = section->size; | |
19e6b90e L |
6387 | |
6388 | if (bytes == 0) | |
6389 | { | |
6390 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6391 | return 0; | |
6392 | } | |
6393 | ||
77145576 JK |
6394 | if (is_loclists) |
6395 | { | |
6396 | unsigned char *hdrptr = section_begin; | |
6397 | dwarf_vma ll_length; | |
6398 | unsigned short ll_version; | |
6399 | unsigned char *end = section_begin + section->size; | |
6400 | unsigned char address_size, segment_selector_size; | |
6401 | uint32_t offset_entry_count; | |
6402 | ||
6403 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6404 | if (ll_length == 0xffffffff) | |
6405 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6406 | ||
6407 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6408 | if (ll_version != 5) | |
6409 | { | |
6410 | warn (_("The %s section contains corrupt or " | |
6411 | "unsupported version number: %d.\n"), | |
6412 | section->name, ll_version); | |
6413 | return 0; | |
6414 | } | |
6415 | ||
6416 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6417 | ||
6418 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6419 | if (segment_selector_size != 0) | |
6420 | { | |
6421 | warn (_("The %s section contains " | |
6422 | "unsupported segment selector size: %d.\n"), | |
6423 | section->name, segment_selector_size); | |
6424 | return 0; | |
6425 | } | |
6426 | ||
6427 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
6428 | if (offset_entry_count != 0) | |
6429 | { | |
6430 | warn (_("The %s section contains " | |
6431 | "unsupported offset entry count: %d.\n"), | |
6432 | section->name, offset_entry_count); | |
6433 | return 0; | |
6434 | } | |
6435 | ||
6436 | expected_start = hdrptr - section_begin; | |
6437 | } | |
6438 | ||
1febe64d NC |
6439 | if (load_debug_info (file) == 0) |
6440 | { | |
6441 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6442 | section->name); | |
6443 | return 0; | |
6444 | } | |
19e6b90e L |
6445 | |
6446 | /* Check the order of location list in .debug_info section. If | |
6447 | offsets of location lists are in the ascending order, we can | |
6448 | use `debug_information' directly. */ | |
6449 | for (i = 0; i < num_debug_info_entries; i++) | |
6450 | { | |
6451 | unsigned int num; | |
6452 | ||
6453 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
6454 | if (num > num_loc_list) |
6455 | num_loc_list = num; | |
19e6b90e L |
6456 | |
6457 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 6458 | if (locs_sorted && num != 0) |
19e6b90e L |
6459 | { |
6460 | if (!seen_first_offset) | |
6461 | { | |
6462 | /* This is the first location list. */ | |
6463 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 6464 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
6465 | first = i; |
6466 | seen_first_offset = 1; | |
6467 | j = 1; | |
6468 | } | |
6469 | else | |
6470 | j = 0; | |
6471 | ||
6472 | for (; j < num; j++) | |
6473 | { | |
6474 | if (last_offset > | |
9f272209 AO |
6475 | debug_information [i].loc_offsets [j] |
6476 | || (last_offset == debug_information [i].loc_offsets [j] | |
6477 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 6478 | { |
51d0d03f | 6479 | locs_sorted = 0; |
19e6b90e L |
6480 | break; |
6481 | } | |
6482 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 6483 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
6484 | } |
6485 | } | |
6486 | } | |
6487 | ||
19e6b90e L |
6488 | if (!seen_first_offset) |
6489 | error (_("No location lists in .debug_info section!\n")); | |
6490 | ||
d4bfc77b | 6491 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
6492 | && debug_information [first].loc_offsets [0] != expected_start |
6493 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
6494 | warn (_("Location lists in %s section start at 0x%s\n"), |
6495 | section->name, | |
6496 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 6497 | |
51d0d03f JJ |
6498 | if (!locs_sorted) |
6499 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d NC |
6500 | |
6501 | introduce (section, FALSE); | |
6502 | ||
d1c4b12b NC |
6503 | if (reloc_at (section, 0)) |
6504 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 6505 | |
d1c4b12b | 6506 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
6507 | |
6508 | seen_first_offset = 0; | |
6509 | for (i = first; i < num_debug_info_entries; i++) | |
6510 | { | |
9f272209 | 6511 | dwarf_vma offset, voffset; |
359ca075 | 6512 | dwarf_vma base_address; |
d1c4b12b | 6513 | unsigned int k; |
19e6b90e L |
6514 | int has_frame_base; |
6515 | ||
51d0d03f JJ |
6516 | if (!locs_sorted) |
6517 | { | |
6518 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
6519 | array[k] = k; | |
6520 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 6521 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
6522 | qsort (array, debug_information [i].num_loc_offsets, |
6523 | sizeof (*array), loc_offsets_compar); | |
6524 | } | |
19e6b90e | 6525 | |
9f272209 | 6526 | int adjacent_view_loclists = 1; |
51d0d03f | 6527 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 6528 | { |
51d0d03f JJ |
6529 | j = locs_sorted ? k : array[k]; |
6530 | if (k | |
9f272209 | 6531 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 6532 | ? k - 1 : array [k - 1]] |
9f272209 AO |
6533 | == debug_information [i].loc_offsets [j]) |
6534 | && (debug_information [i].loc_views [locs_sorted | |
6535 | ? k - 1 : array [k - 1]] | |
6536 | == debug_information [i].loc_views [j])) | |
51d0d03f | 6537 | continue; |
19e6b90e | 6538 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 6539 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 6540 | next = section_begin + offset; |
9f272209 AO |
6541 | voffset = debug_information [i].loc_views [j]; |
6542 | if (voffset != vm1) | |
6543 | vnext = section_begin + voffset; | |
6544 | else | |
6545 | vnext = NULL; | |
19e6b90e L |
6546 | base_address = debug_information [i].base_address; |
6547 | ||
9f272209 AO |
6548 | if (vnext && vnext < next) |
6549 | { | |
6550 | vstart = vnext; | |
6551 | display_view_pair_list (section, &vstart, i, next); | |
6552 | if (start == vnext) | |
6553 | start = vstart; | |
6554 | } | |
6555 | ||
6556 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
6557 | seen_first_offset = 1; |
6558 | else | |
6559 | { | |
6560 | if (start < next) | |
6561 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6562 | (unsigned long) (start - section_begin), |
c8071705 | 6563 | (unsigned long) offset); |
19e6b90e L |
6564 | else if (start > next) |
6565 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6566 | (unsigned long) (start - section_begin), |
c8071705 | 6567 | (unsigned long) offset); |
19e6b90e L |
6568 | } |
6569 | start = next; | |
9f272209 | 6570 | vstart = vnext; |
19e6b90e L |
6571 | |
6572 | if (offset >= bytes) | |
6573 | { | |
6574 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 6575 | (unsigned long) offset); |
19e6b90e L |
6576 | continue; |
6577 | } | |
6578 | ||
9f272209 AO |
6579 | if (vnext && voffset >= bytes) |
6580 | { | |
6581 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
6582 | (unsigned long) voffset); | |
6583 | continue; | |
6584 | } | |
6585 | ||
77145576 JK |
6586 | if (!is_loclists) |
6587 | { | |
6588 | if (is_dwo) | |
6589 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 6590 | &vstart, has_frame_base); |
77145576 JK |
6591 | else |
6592 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 6593 | &vstart, has_frame_base); |
77145576 | 6594 | } |
b4eb7656 | 6595 | else |
77145576 JK |
6596 | { |
6597 | if (is_dwo) | |
6598 | warn (_("DWO is not yet supported.\n")); | |
6599 | else | |
6600 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
6601 | &vstart, has_frame_base); |
6602 | } | |
6603 | ||
6604 | /* FIXME: this arrangement is quite simplistic. Nothing | |
6605 | requires locview lists to be adjacent to corresponding | |
6606 | loclists, and a single loclist could be augmented by | |
6607 | different locview lists, and vice-versa, unlikely as it | |
6608 | is that it would make sense to do so. Hopefully we'll | |
6609 | have view pair support built into loclists before we ever | |
6610 | need to address all these possibilities. */ | |
6611 | if (adjacent_view_loclists && vnext | |
6612 | && vnext != start && vstart != next) | |
6613 | { | |
6614 | adjacent_view_loclists = 0; | |
6615 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 6616 | } |
9f272209 AO |
6617 | |
6618 | if (vnext && vnext == start) | |
6619 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
6620 | } |
6621 | } | |
031cd65f | 6622 | |
4723351a | 6623 | if (start < section->start + section->size) |
d3a49aa8 AM |
6624 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
6625 | "There are %ld unused bytes at the end of section %s\n", | |
6626 | (long) (section->start + section->size - start)), | |
4723351a | 6627 | (long) (section->start + section->size - start), section->name); |
98fb390a | 6628 | putchar ('\n'); |
51d0d03f | 6629 | free (array); |
19e6b90e L |
6630 | return 1; |
6631 | } | |
6632 | ||
6633 | static int | |
6634 | display_debug_str (struct dwarf_section *section, | |
6635 | void *file ATTRIBUTE_UNUSED) | |
6636 | { | |
6637 | unsigned char *start = section->start; | |
6638 | unsigned long bytes = section->size; | |
6639 | dwarf_vma addr = section->address; | |
6640 | ||
6641 | if (bytes == 0) | |
6642 | { | |
6643 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6644 | return 0; | |
6645 | } | |
6646 | ||
dda8d76d | 6647 | introduce (section, FALSE); |
19e6b90e L |
6648 | |
6649 | while (bytes) | |
6650 | { | |
6651 | int j; | |
6652 | int k; | |
6653 | int lbytes; | |
6654 | ||
6655 | lbytes = (bytes > 16 ? 16 : bytes); | |
6656 | ||
6657 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
6658 | ||
6659 | for (j = 0; j < 16; j++) | |
6660 | { | |
6661 | if (j < lbytes) | |
6662 | printf ("%2.2x", start[j]); | |
6663 | else | |
6664 | printf (" "); | |
6665 | ||
6666 | if ((j & 3) == 3) | |
6667 | printf (" "); | |
6668 | } | |
6669 | ||
6670 | for (j = 0; j < lbytes; j++) | |
6671 | { | |
6672 | k = start[j]; | |
6673 | if (k >= ' ' && k < 0x80) | |
6674 | printf ("%c", k); | |
6675 | else | |
6676 | printf ("."); | |
6677 | } | |
6678 | ||
6679 | putchar ('\n'); | |
6680 | ||
6681 | start += lbytes; | |
6682 | addr += lbytes; | |
6683 | bytes -= lbytes; | |
6684 | } | |
6685 | ||
6686 | putchar ('\n'); | |
6687 | ||
6688 | return 1; | |
6689 | } | |
6690 | ||
19e6b90e L |
6691 | static int |
6692 | display_debug_info (struct dwarf_section *section, void *file) | |
6693 | { | |
d85bf2ba | 6694 | return process_debug_info (section, file, section->abbrev_sec, FALSE, FALSE); |
19e6b90e L |
6695 | } |
6696 | ||
2b6f5997 CC |
6697 | static int |
6698 | display_debug_types (struct dwarf_section *section, void *file) | |
6699 | { | |
d85bf2ba | 6700 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
6f875884 TG |
6701 | } |
6702 | ||
6703 | static int | |
6704 | display_trace_info (struct dwarf_section *section, void *file) | |
6705 | { | |
d85bf2ba | 6706 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
2b6f5997 | 6707 | } |
19e6b90e L |
6708 | |
6709 | static int | |
6710 | display_debug_aranges (struct dwarf_section *section, | |
6711 | void *file ATTRIBUTE_UNUSED) | |
6712 | { | |
6713 | unsigned char *start = section->start; | |
6714 | unsigned char *end = start + section->size; | |
6715 | ||
dda8d76d | 6716 | introduce (section, FALSE); |
19e6b90e | 6717 | |
6e3d6dc1 NC |
6718 | /* It does not matter if this load fails, |
6719 | we test for that later on. */ | |
6720 | load_debug_info (file); | |
6721 | ||
19e6b90e L |
6722 | while (start < end) |
6723 | { | |
6724 | unsigned char *hdrptr; | |
6725 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 6726 | unsigned char *addr_ranges; |
2d9472a2 NC |
6727 | dwarf_vma length; |
6728 | dwarf_vma address; | |
e98fdf1a | 6729 | unsigned long sec_off; |
53b8873b | 6730 | unsigned char address_size; |
19e6b90e | 6731 | int excess; |
bf5117e3 NC |
6732 | unsigned int offset_size; |
6733 | unsigned int initial_length_size; | |
19e6b90e L |
6734 | |
6735 | hdrptr = start; | |
6736 | ||
0c588247 | 6737 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
6738 | if (arange.ar_length == 0xffffffff) |
6739 | { | |
0c588247 | 6740 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
6741 | offset_size = 8; |
6742 | initial_length_size = 12; | |
6743 | } | |
6744 | else | |
6745 | { | |
6746 | offset_size = 4; | |
6747 | initial_length_size = 4; | |
6748 | } | |
6749 | ||
e98fdf1a AM |
6750 | sec_off = hdrptr - section->start; |
6751 | if (sec_off + arange.ar_length < sec_off | |
6752 | || sec_off + arange.ar_length > section->size) | |
6753 | { | |
6754 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
6755 | section->name, | |
6756 | sec_off - initial_length_size, | |
6757 | dwarf_vmatoa ("x", arange.ar_length)); | |
6758 | break; | |
6759 | } | |
6760 | ||
0c588247 NC |
6761 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
6762 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 6763 | |
6e3d6dc1 NC |
6764 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
6765 | && num_debug_info_entries > 0 | |
6766 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
6767 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 6768 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 6769 | |
0c588247 NC |
6770 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
6771 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
6772 | |
6773 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
6774 | { | |
67f101ee NC |
6775 | /* PR 19872: A version number of 0 probably means that there is |
6776 | padding at the end of the .debug_aranges section. Gold puts | |
6777 | it there when performing an incremental link, for example. | |
6778 | So do not generate a warning in this case. */ | |
6779 | if (arange.ar_version) | |
6780 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
6781 | break; |
6782 | } | |
6783 | ||
47704ddf KT |
6784 | printf (_(" Length: %ld\n"), |
6785 | (long) arange.ar_length); | |
19e6b90e | 6786 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
6787 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
6788 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
6789 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
6790 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
6791 | ||
53b8873b NC |
6792 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
6793 | ||
f41e4712 NC |
6794 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
6795 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
6796 | { |
6797 | error (_("Invalid address size in %s section!\n"), | |
6798 | section->name); | |
6799 | break; | |
6800 | } | |
6801 | ||
53b8873b NC |
6802 | /* The DWARF spec does not require that the address size be a power |
6803 | of two, but we do. This will have to change if we ever encounter | |
6804 | an uneven architecture. */ | |
6805 | if ((address_size & (address_size - 1)) != 0) | |
6806 | { | |
6807 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
6808 | break; | |
6809 | } | |
cecf136e | 6810 | |
209c9a13 NC |
6811 | if (address_size > 4) |
6812 | printf (_("\n Address Length\n")); | |
6813 | else | |
6814 | printf (_("\n Address Length\n")); | |
19e6b90e | 6815 | |
91d6fa6a | 6816 | addr_ranges = hdrptr; |
19e6b90e | 6817 | |
53b8873b NC |
6818 | /* Must pad to an alignment boundary that is twice the address size. */ |
6819 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 6820 | if (excess) |
91d6fa6a | 6821 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 6822 | |
e98fdf1a | 6823 | start += arange.ar_length + initial_length_size; |
1617e571 | 6824 | |
91d6fa6a | 6825 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 6826 | { |
0c588247 NC |
6827 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
6828 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 6829 | |
80c35038 | 6830 | printf (" "); |
2d9472a2 NC |
6831 | print_dwarf_vma (address, address_size); |
6832 | print_dwarf_vma (length, address_size); | |
6833 | putchar ('\n'); | |
19e6b90e | 6834 | } |
19e6b90e L |
6835 | } |
6836 | ||
6837 | printf ("\n"); | |
6838 | ||
6839 | return 1; | |
6840 | } | |
6841 | ||
4723351a CC |
6842 | /* Comparison function for qsort. */ |
6843 | static int | |
6844 | comp_addr_base (const void * v0, const void * v1) | |
6845 | { | |
d367307b AM |
6846 | debug_info *info0 = *(debug_info **) v0; |
6847 | debug_info *info1 = *(debug_info **) v1; | |
4723351a CC |
6848 | return info0->addr_base - info1->addr_base; |
6849 | } | |
6850 | ||
6851 | /* Display the debug_addr section. */ | |
6852 | static int | |
6853 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 6854 | void *file) |
4723351a CC |
6855 | { |
6856 | debug_info **debug_addr_info; | |
6857 | unsigned char *entry; | |
6858 | unsigned char *end; | |
6859 | unsigned int i; | |
6860 | unsigned int count; | |
6861 | ||
6862 | if (section->size == 0) | |
6863 | { | |
6864 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6865 | return 0; | |
6866 | } | |
6867 | ||
6868 | if (load_debug_info (file) == 0) | |
6869 | { | |
6870 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6871 | section->name); | |
6872 | return 0; | |
6873 | } | |
6874 | ||
dda8d76d | 6875 | introduce (section, FALSE); |
4723351a | 6876 | |
1306a742 NC |
6877 | /* PR 17531: file: cf38d01b. |
6878 | We use xcalloc because a corrupt file may not have initialised all of the | |
6879 | fields in the debug_info structure, which means that the sort below might | |
6880 | try to move uninitialised data. */ | |
6881 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 6882 | sizeof (debug_info *)); |
4723351a CC |
6883 | |
6884 | count = 0; | |
6885 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 6886 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
6887 | { |
6888 | /* PR 17531: file: cf38d01b. */ | |
6889 | if (debug_information[i].addr_base >= section->size) | |
6890 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
6891 | (unsigned long) debug_information[i].addr_base, i); | |
6892 | else | |
6893 | debug_addr_info [count++] = debug_information + i; | |
6894 | } | |
4723351a CC |
6895 | |
6896 | /* Add a sentinel to make iteration convenient. */ | |
6897 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
6898 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 6899 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 6900 | |
4723351a CC |
6901 | for (i = 0; i < count; i++) |
6902 | { | |
6903 | unsigned int idx; | |
fab128ef | 6904 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
6905 | |
6906 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 6907 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 6908 | |
fab128ef | 6909 | printf (_("\tIndex\tAddress\n")); |
4723351a CC |
6910 | entry = section->start + debug_addr_info [i]->addr_base; |
6911 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
6912 | idx = 0; | |
6913 | while (entry < end) | |
b4eb7656 AM |
6914 | { |
6915 | dwarf_vma base = byte_get (entry, address_size); | |
6916 | printf (_("\t%d:\t"), idx); | |
6917 | print_dwarf_vma (base, address_size); | |
6918 | printf ("\n"); | |
6919 | entry += address_size; | |
6920 | idx++; | |
6921 | } | |
4723351a CC |
6922 | } |
6923 | printf ("\n"); | |
6924 | ||
6925 | free (debug_addr_info); | |
6926 | return 1; | |
6927 | } | |
6928 | ||
6929 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 6930 | |
4723351a CC |
6931 | static int |
6932 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 6933 | void *file ATTRIBUTE_UNUSED) |
4723351a | 6934 | { |
9f27c364 HPN |
6935 | unsigned long idx; |
6936 | ||
4723351a CC |
6937 | if (section->size == 0) |
6938 | { | |
6939 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6940 | return 0; | |
6941 | } | |
e4b7104b NC |
6942 | |
6943 | unsigned char *start = section->start; | |
6944 | unsigned char *end = start + section->size; | |
6945 | unsigned char *curr = start; | |
6946 | ||
39f381cb NC |
6947 | const char * suffix = strrchr (section->name, '.'); |
6948 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
6949 | ||
6950 | if (dwo) | |
6951 | load_debug_section_with_follow (str_dwo, file); | |
6952 | else | |
6953 | load_debug_section_with_follow (str, file); | |
e4b7104b NC |
6954 | |
6955 | introduce (section, FALSE); | |
6956 | ||
6957 | while (curr < end) | |
6958 | { | |
6959 | dwarf_vma length; | |
6960 | dwarf_vma entry_length; | |
6961 | ||
6962 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); | |
6963 | /* FIXME: We assume that this means 64-bit DWARF is being used. */ | |
6964 | if (length == 0xffffffff) | |
6965 | { | |
6966 | SAFE_BYTE_GET (length, curr, 8, end); | |
6967 | entry_length = 8; | |
6968 | } | |
6969 | else | |
6970 | entry_length = 4; | |
6971 | ||
39f381cb NC |
6972 | if (length == 0) |
6973 | { | |
6974 | /* This is probably an old style .debug_str_offset section which | |
6975 | just contains offsets and no header (and the first offset is 0). */ | |
6976 | length = section->size; | |
6977 | curr = section->start; | |
e4b7104b | 6978 | |
39f381cb NC |
6979 | printf (_(" Length: %#lx\n"), (unsigned long) length); |
6980 | printf (_(" Index Offset [String]\n")); | |
6981 | } | |
6982 | else | |
6983 | { | |
6984 | int version; | |
6985 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); | |
6986 | if (version != 5) | |
6987 | warn (_("Unexpected version number in str_offset header: %#x\n"), version); | |
6988 | ||
6989 | int padding; | |
6990 | SAFE_BYTE_GET_AND_INC (padding, curr, 2, end); | |
6991 | if (padding != 0) | |
6992 | warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding); | |
6993 | ||
6994 | printf (_(" Length: %#lx\n"), (unsigned long) length); | |
6995 | printf (_(" Version: %#lx\n"), (unsigned long) version); | |
6996 | printf (_(" Index Offset [String]\n")); | |
6997 | } | |
e4b7104b | 6998 | |
9f27c364 | 6999 | for (idx = 0; length >= entry_length && curr < end; idx++) |
e4b7104b NC |
7000 | { |
7001 | dwarf_vma offset; | |
7002 | const unsigned char * string; | |
7003 | ||
7004 | SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, end); | |
39f381cb NC |
7005 | if (dwo) |
7006 | string = (const unsigned char *) | |
9f27c364 | 7007 | fetch_indexed_string (idx, NULL, entry_length, dwo); |
39f381cb NC |
7008 | else |
7009 | string = fetch_indirect_string (offset); | |
7010 | ||
9f27c364 | 7011 | printf (" %8lu %8s %s\n", idx, dwarf_vmatoa ("x", offset), |
e4b7104b NC |
7012 | string); |
7013 | } | |
7014 | } | |
39f381cb | 7015 | |
4723351a CC |
7016 | return 1; |
7017 | } | |
7018 | ||
01a8f077 JK |
7019 | /* Each debug_information[x].range_lists[y] gets this representation for |
7020 | sorting purposes. */ | |
7021 | ||
7022 | struct range_entry | |
467c65bc NC |
7023 | { |
7024 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 7025 | dwarf_vma ranges_offset; |
01a8f077 | 7026 | |
467c65bc NC |
7027 | /* Original debug_information to find parameters of the data. */ |
7028 | debug_info *debug_info_p; | |
7029 | }; | |
01a8f077 JK |
7030 | |
7031 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
7032 | ||
7033 | static int | |
7034 | range_entry_compar (const void *ap, const void *bp) | |
7035 | { | |
3f5e193b NC |
7036 | const struct range_entry *a_re = (const struct range_entry *) ap; |
7037 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
7038 | const dwarf_vma a = a_re->ranges_offset; |
7039 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
7040 | |
7041 | return (a > b) - (b > a); | |
7042 | } | |
7043 | ||
77145576 JK |
7044 | static void |
7045 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
7046 | unsigned int pointer_size, unsigned long offset, | |
7047 | unsigned long base_address) | |
7048 | { | |
7049 | while (start < finish) | |
7050 | { | |
7051 | dwarf_vma begin; | |
7052 | dwarf_vma end; | |
7053 | ||
7054 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7055 | if (start >= finish) | |
7056 | break; | |
7057 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7058 | ||
d11ae95e | 7059 | |
77145576 JK |
7060 | printf (" %8.8lx ", offset); |
7061 | ||
7062 | if (begin == 0 && end == 0) | |
7063 | { | |
7064 | printf (_("<End of list>\n")); | |
7065 | break; | |
7066 | } | |
7067 | ||
7068 | /* Check base address specifiers. */ | |
7069 | if (is_max_address (begin, pointer_size) | |
7070 | && !is_max_address (end, pointer_size)) | |
7071 | { | |
7072 | base_address = end; | |
7073 | print_dwarf_vma (begin, pointer_size); | |
7074 | print_dwarf_vma (end, pointer_size); | |
7075 | printf ("(base address)\n"); | |
7076 | continue; | |
7077 | } | |
7078 | ||
7079 | print_dwarf_vma (begin + base_address, pointer_size); | |
7080 | print_dwarf_vma (end + base_address, pointer_size); | |
7081 | ||
7082 | if (begin == end) | |
7083 | fputs (_("(start == end)"), stdout); | |
7084 | else if (begin > end) | |
7085 | fputs (_("(start > end)"), stdout); | |
7086 | ||
7087 | putchar ('\n'); | |
7088 | } | |
7089 | } | |
7090 | ||
7091 | static void | |
7092 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
7093 | unsigned int pointer_size, unsigned long offset, | |
7094 | unsigned long base_address) | |
7095 | { | |
7096 | unsigned char *next = start; | |
7097 | ||
7098 | while (1) | |
7099 | { | |
7100 | unsigned long off = offset + (start - next); | |
7101 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
7102 | /* Initialize it due to a false compiler warning. */ |
7103 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
7104 | |
7105 | if (start + 1 > finish) | |
7106 | { | |
7107 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
7108 | offset); | |
7109 | break; | |
7110 | } | |
7111 | ||
7112 | printf (" %8.8lx ", off); | |
7113 | ||
7114 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
7115 | ||
7116 | switch (rlet) | |
7117 | { | |
7118 | case DW_RLE_end_of_list: | |
7119 | printf (_("<End of list>\n")); | |
7120 | break; | |
7121 | case DW_RLE_base_address: | |
7122 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
7123 | print_dwarf_vma (base_address, pointer_size); | |
7124 | printf (_("(base address)\n")); | |
7125 | break; | |
7126 | case DW_RLE_start_length: | |
7127 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
cd30bcef | 7128 | READ_ULEB (length, start, finish); |
77145576 JK |
7129 | end = begin + length; |
7130 | break; | |
7131 | case DW_RLE_offset_pair: | |
cd30bcef AM |
7132 | READ_ULEB (begin, start, finish); |
7133 | READ_ULEB (end, start, finish); | |
77145576 JK |
7134 | break; |
7135 | case DW_RLE_start_end: | |
7136 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7137 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7138 | break; | |
7139 | default: | |
7140 | error (_("Invalid range list entry type %d\n"), rlet); | |
7141 | rlet = DW_RLE_end_of_list; | |
7142 | break; | |
7143 | } | |
7144 | if (rlet == DW_RLE_end_of_list) | |
7145 | break; | |
7146 | if (rlet == DW_RLE_base_address) | |
7147 | continue; | |
7148 | ||
7149 | print_dwarf_vma (begin + base_address, pointer_size); | |
7150 | print_dwarf_vma (end + base_address, pointer_size); | |
7151 | ||
7152 | if (begin == end) | |
7153 | fputs (_("(start == end)"), stdout); | |
7154 | else if (begin > end) | |
7155 | fputs (_("(start > end)"), stdout); | |
7156 | ||
7157 | putchar ('\n'); | |
7158 | } | |
7159 | } | |
7160 | ||
19e6b90e L |
7161 | static int |
7162 | display_debug_ranges (struct dwarf_section *section, | |
7163 | void *file ATTRIBUTE_UNUSED) | |
7164 | { | |
7165 | unsigned char *start = section->start; | |
a2ff7a4b | 7166 | unsigned char *last_start = start; |
f6f0e17b | 7167 | unsigned long bytes = section->size; |
19e6b90e | 7168 | unsigned char *section_begin = start; |
f6f0e17b | 7169 | unsigned char *finish = start + bytes; |
01a8f077 JK |
7170 | unsigned int num_range_list, i; |
7171 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
7172 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
7173 | /* Initialize it due to a false compiler warning. */ | |
7174 | unsigned char address_size = 0; | |
cb4c35cf | 7175 | dwarf_vma last_offset = 0; |
19e6b90e | 7176 | |
19e6b90e L |
7177 | if (bytes == 0) |
7178 | { | |
7179 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7180 | return 0; | |
7181 | } | |
7182 | ||
77145576 JK |
7183 | if (is_rnglists) |
7184 | { | |
7185 | dwarf_vma initial_length; | |
7186 | unsigned int initial_length_size; | |
7187 | unsigned char segment_selector_size; | |
7188 | unsigned int offset_size, offset_entry_count; | |
7189 | unsigned short version; | |
7190 | ||
7191 | /* Get and check the length of the block. */ | |
7192 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
7193 | ||
7194 | if (initial_length == 0xffffffff) | |
7195 | { | |
7196 | /* This section is 64-bit DWARF 3. */ | |
7197 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
7198 | offset_size = 8; | |
7199 | initial_length_size = 12; | |
7200 | } | |
7201 | else | |
7202 | { | |
7203 | offset_size = 4; | |
7204 | initial_length_size = 4; | |
7205 | } | |
7206 | ||
7207 | if (initial_length + initial_length_size > section->size) | |
7208 | { | |
7209 | /* If the length field has a relocation against it, then we should | |
7210 | not complain if it is inaccurate (and probably negative). | |
7211 | It is copied from .debug_line handling code. */ | |
7212 | if (reloc_at (section, (start - section->start) - offset_size)) | |
7213 | { | |
7214 | initial_length = (finish - start) - initial_length_size; | |
7215 | } | |
7216 | else | |
7217 | { | |
7218 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
7219 | (long) initial_length); | |
7220 | return 0; | |
7221 | } | |
7222 | } | |
7223 | ||
7224 | /* Get and check the version number. */ | |
7225 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
7226 | ||
7227 | if (version != 5) | |
7228 | { | |
7229 | warn (_("Only DWARF version 5 debug_rnglists info " | |
7230 | "is currently supported.\n")); | |
7231 | return 0; | |
7232 | } | |
7233 | ||
7234 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
7235 | ||
7236 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
7237 | if (segment_selector_size != 0) | |
7238 | { | |
7239 | warn (_("The %s section contains " | |
7240 | "unsupported segment selector size: %d.\n"), | |
7241 | section->name, segment_selector_size); | |
7242 | return 0; | |
7243 | } | |
7244 | ||
7245 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
7246 | if (offset_entry_count != 0) | |
7247 | { | |
7248 | warn (_("The %s section contains " | |
7249 | "unsupported offset entry count: %u.\n"), | |
7250 | section->name, offset_entry_count); | |
7251 | return 0; | |
7252 | } | |
7253 | } | |
7254 | ||
1febe64d NC |
7255 | if (load_debug_info (file) == 0) |
7256 | { | |
7257 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7258 | section->name); | |
7259 | return 0; | |
7260 | } | |
19e6b90e | 7261 | |
01a8f077 | 7262 | num_range_list = 0; |
19e6b90e | 7263 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 7264 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 7265 | |
01a8f077 | 7266 | if (num_range_list == 0) |
4723351a CC |
7267 | { |
7268 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 7269 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
7270 | printf (_("No range lists in .debug_info section.\n")); |
7271 | return 1; | |
7272 | } | |
19e6b90e | 7273 | |
3f5e193b NC |
7274 | range_entries = (struct range_entry *) |
7275 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 7276 | range_entry_fill = range_entries; |
19e6b90e | 7277 | |
01a8f077 JK |
7278 | for (i = 0; i < num_debug_info_entries; i++) |
7279 | { | |
7280 | debug_info *debug_info_p = &debug_information[i]; | |
7281 | unsigned int j; | |
7282 | ||
7283 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
7284 | { | |
7285 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
7286 | range_entry_fill->debug_info_p = debug_info_p; | |
7287 | range_entry_fill++; | |
19e6b90e L |
7288 | } |
7289 | } | |
7290 | ||
01a8f077 JK |
7291 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
7292 | range_entry_compar); | |
19e6b90e | 7293 | |
d493b283 | 7294 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 7295 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 7296 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 7297 | |
dda8d76d NC |
7298 | introduce (section, FALSE); |
7299 | ||
19e6b90e L |
7300 | printf (_(" Offset Begin End\n")); |
7301 | ||
01a8f077 | 7302 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 7303 | { |
01a8f077 JK |
7304 | struct range_entry *range_entry = &range_entries[i]; |
7305 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 7306 | unsigned int pointer_size; |
359ca075 | 7307 | dwarf_vma offset; |
01a8f077 | 7308 | unsigned char *next; |
359ca075 | 7309 | dwarf_vma base_address; |
19e6b90e | 7310 | |
77145576 | 7311 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 7312 | offset = range_entry->ranges_offset; |
01a8f077 JK |
7313 | next = section_begin + offset; |
7314 | base_address = debug_info_p->base_address; | |
cecf136e | 7315 | |
f41e4712 NC |
7316 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
7317 | if (pointer_size < 2 || pointer_size > 8) | |
7318 | { | |
7319 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 7320 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
7321 | continue; |
7322 | } | |
b4eb7656 | 7323 | |
d11ae95e NC |
7324 | if (next < section_begin || next >= finish) |
7325 | { | |
7326 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
7327 | (unsigned long) offset, i); | |
7328 | continue; | |
7329 | } | |
7330 | ||
cb4c35cf AB |
7331 | /* If multiple DWARF entities reference the same range then we will |
7332 | have multiple entries in the `range_entries' list for the same | |
7333 | offset. Thanks to the sort above these will all be consecutive in | |
7334 | the `range_entries' list, so we can easily ignore duplicates | |
7335 | here. */ | |
7336 | if (i > 0 && last_offset == offset) | |
7337 | continue; | |
7338 | last_offset = offset; | |
7339 | ||
4723351a | 7340 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 7341 | { |
01a8f077 JK |
7342 | if (start < next) |
7343 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
7344 | (unsigned long) (start - section_begin), | |
7345 | (unsigned long) (next - section_begin), section->name); | |
7346 | else if (start > next) | |
a2ff7a4b AM |
7347 | { |
7348 | if (next == last_start) | |
7349 | continue; | |
7350 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
7351 | (unsigned long) (start - section_begin), | |
7352 | (unsigned long) (next - section_begin), section->name); | |
7353 | } | |
01a8f077 | 7354 | } |
d11ae95e | 7355 | |
01a8f077 | 7356 | start = next; |
a2ff7a4b | 7357 | last_start = next; |
19e6b90e | 7358 | |
77145576 JK |
7359 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
7360 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
7361 | } |
7362 | putchar ('\n'); | |
01a8f077 JK |
7363 | |
7364 | free (range_entries); | |
7365 | ||
19e6b90e L |
7366 | return 1; |
7367 | } | |
7368 | ||
7369 | typedef struct Frame_Chunk | |
7370 | { | |
7371 | struct Frame_Chunk *next; | |
7372 | unsigned char *chunk_start; | |
a1165289 | 7373 | unsigned int ncols; |
19e6b90e L |
7374 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
7375 | short int *col_type; | |
7376 | int *col_offset; | |
7377 | char *augmentation; | |
7378 | unsigned int code_factor; | |
7379 | int data_factor; | |
bf5117e3 NC |
7380 | dwarf_vma pc_begin; |
7381 | dwarf_vma pc_range; | |
32ef3000 | 7382 | unsigned int cfa_reg; |
c8071705 | 7383 | dwarf_vma cfa_offset; |
a1165289 | 7384 | unsigned int ra; |
19e6b90e L |
7385 | unsigned char fde_encoding; |
7386 | unsigned char cfa_exp; | |
604282a7 JJ |
7387 | unsigned char ptr_size; |
7388 | unsigned char segment_size; | |
19e6b90e L |
7389 | } |
7390 | Frame_Chunk; | |
7391 | ||
1296bc99 AB |
7392 | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); |
7393 | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; | |
665ce1f6 L |
7394 | static const char *const *dwarf_regnames; |
7395 | static unsigned int dwarf_regnames_count; | |
7396 | ||
1296bc99 | 7397 | |
19e6b90e L |
7398 | /* A marker for a col_type that means this column was never referenced |
7399 | in the frame info. */ | |
7400 | #define DW_CFA_unreferenced (-1) | |
7401 | ||
a1165289 | 7402 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
7403 | -1 for invalid reg. */ |
7404 | ||
7405 | static int | |
7406 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 7407 | { |
a1165289 | 7408 | unsigned int prev = fc->ncols; |
19e6b90e | 7409 | |
665ce1f6 L |
7410 | if (reg < (unsigned int) fc->ncols) |
7411 | return 0; | |
7412 | ||
d9acf707 | 7413 | if (dwarf_regnames_count > 0 |
665ce1f6 L |
7414 | && reg > dwarf_regnames_count) |
7415 | return -1; | |
19e6b90e L |
7416 | |
7417 | fc->ncols = reg + 1; | |
a1165289 NC |
7418 | /* PR 17512: file: 10450-2643-0.004. |
7419 | If reg == -1 then this can happen... */ | |
7420 | if (fc->ncols == 0) | |
7421 | return -1; | |
7422 | ||
06614111 | 7423 | /* PR 17512: file: 2844a11d. */ |
d9acf707 | 7424 | if (fc->ncols > 1024 && dwarf_regnames_count == 0) |
06614111 NC |
7425 | { |
7426 | error (_("Unfeasibly large register number: %u\n"), reg); | |
7427 | fc->ncols = 0; | |
7428 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
7429 | we ever encounter a valid binary that exceeds it. */ | |
7430 | return -1; | |
7431 | } | |
7432 | ||
3f5e193b | 7433 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 7434 | sizeof (short int)); |
3f5e193b | 7435 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 7436 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
7437 | if (fc->col_type == NULL || fc->col_offset == NULL) |
7438 | { | |
7439 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
7440 | fc->ncols); | |
7441 | fc->ncols = 0; | |
7442 | return -1; | |
7443 | } | |
19e6b90e L |
7444 | |
7445 | while (prev < fc->ncols) | |
7446 | { | |
7447 | fc->col_type[prev] = DW_CFA_unreferenced; | |
7448 | fc->col_offset[prev] = 0; | |
7449 | prev++; | |
7450 | } | |
665ce1f6 | 7451 | return 1; |
19e6b90e L |
7452 | } |
7453 | ||
2dc4cec1 L |
7454 | static const char *const dwarf_regnames_i386[] = |
7455 | { | |
43234a1e L |
7456 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
7457 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7458 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7459 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
7460 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
7461 | NULL, NULL, /* 19 - 20 */ | |
7462 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
7463 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
7464 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
7465 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
7466 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
7467 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7468 | "tr", "ldtr", /* 48 - 49 */ | |
7469 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7470 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7471 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7472 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7473 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7474 | NULL, NULL, NULL, /* 90 - 92 */ | |
7475 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
7476 | }; |
7477 | ||
3d875af5 L |
7478 | static const char *const dwarf_regnames_iamcu[] = |
7479 | { | |
7480 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
7481 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7482 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7483 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
7484 | NULL, NULL, /* 19 - 20 */ | |
7485 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
7486 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
7487 | NULL, NULL, NULL, /* 37 - 39 */ | |
7488 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7489 | "tr", "ldtr", /* 48 - 49 */ | |
7490 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7491 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7492 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7493 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7494 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7495 | NULL, NULL, NULL, /* 90 - 92 */ | |
7496 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
7497 | }; | |
7498 | ||
99f6fdd9 | 7499 | static void |
b129eb0e RH |
7500 | init_dwarf_regnames_i386 (void) |
7501 | { | |
7502 | dwarf_regnames = dwarf_regnames_i386; | |
7503 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
1296bc99 | 7504 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
7505 | } |
7506 | ||
99f6fdd9 | 7507 | static void |
3d875af5 L |
7508 | init_dwarf_regnames_iamcu (void) |
7509 | { | |
7510 | dwarf_regnames = dwarf_regnames_iamcu; | |
7511 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
1296bc99 | 7512 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
3d875af5 L |
7513 | } |
7514 | ||
2dc4cec1 L |
7515 | static const char *const dwarf_regnames_x86_64[] = |
7516 | { | |
7517 | "rax", "rdx", "rcx", "rbx", | |
7518 | "rsi", "rdi", "rbp", "rsp", | |
7519 | "r8", "r9", "r10", "r11", | |
7520 | "r12", "r13", "r14", "r15", | |
7521 | "rip", | |
7522 | "xmm0", "xmm1", "xmm2", "xmm3", | |
7523 | "xmm4", "xmm5", "xmm6", "xmm7", | |
7524 | "xmm8", "xmm9", "xmm10", "xmm11", | |
7525 | "xmm12", "xmm13", "xmm14", "xmm15", | |
7526 | "st0", "st1", "st2", "st3", | |
7527 | "st4", "st5", "st6", "st7", | |
7528 | "mm0", "mm1", "mm2", "mm3", | |
7529 | "mm4", "mm5", "mm6", "mm7", | |
7530 | "rflags", | |
7531 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
7532 | "fs.base", "gs.base", NULL, NULL, | |
7533 | "tr", "ldtr", | |
43234a1e L |
7534 | "mxcsr", "fcw", "fsw", |
7535 | "xmm16", "xmm17", "xmm18", "xmm19", | |
7536 | "xmm20", "xmm21", "xmm22", "xmm23", | |
7537 | "xmm24", "xmm25", "xmm26", "xmm27", | |
7538 | "xmm28", "xmm29", "xmm30", "xmm31", | |
7539 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
7540 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
7541 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
7542 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
7543 | NULL, NULL, NULL, /* 115 - 117 */ | |
7544 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
7545 | }; |
7546 | ||
99f6fdd9 | 7547 | static void |
b129eb0e RH |
7548 | init_dwarf_regnames_x86_64 (void) |
7549 | { | |
7550 | dwarf_regnames = dwarf_regnames_x86_64; | |
7551 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
1296bc99 | 7552 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
7553 | } |
7554 | ||
4ee22035 RH |
7555 | static const char *const dwarf_regnames_aarch64[] = |
7556 | { | |
b4eb7656 AM |
7557 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
7558 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
7559 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
7560 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
7561 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
fab7c86e TC |
7562 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
7563 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", | |
7564 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", | |
b4eb7656 AM |
7565 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
7566 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
7567 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
7568 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
fab7c86e TC |
7569 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
7570 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", | |
7571 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", | |
7572 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", | |
4ee22035 RH |
7573 | }; |
7574 | ||
99f6fdd9 | 7575 | static void |
4ee22035 RH |
7576 | init_dwarf_regnames_aarch64 (void) |
7577 | { | |
7578 | dwarf_regnames = dwarf_regnames_aarch64; | |
7579 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
1296bc99 | 7580 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
4ee22035 RH |
7581 | } |
7582 | ||
d6bb17b0 AA |
7583 | static const char *const dwarf_regnames_s390[] = |
7584 | { | |
7585 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
7586 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7587 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7588 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
7589 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
7590 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
7591 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
7592 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
7593 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
7594 | "pswm", "pswa", | |
7595 | NULL, NULL, | |
7596 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
7597 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
7598 | }; | |
7599 | ||
99f6fdd9 | 7600 | static void |
d6bb17b0 AA |
7601 | init_dwarf_regnames_s390 (void) |
7602 | { | |
7603 | dwarf_regnames = dwarf_regnames_s390; | |
7604 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
1296bc99 | 7605 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
d6bb17b0 AA |
7606 | } |
7607 | ||
5bb0830d AB |
7608 | static const char *const dwarf_regnames_riscv[] = |
7609 | { | |
7610 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
7611 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
7612 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
7613 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
7614 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
7615 | "fs0", "fs1", /* 40 - 41 */ | |
7616 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
7617 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
7618 | "fs10", "fs11", /* 58 - 59 */ | |
7619 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
7620 | }; | |
7621 | ||
4762fe62 AB |
7622 | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles |
7623 | the large number of CSRs. */ | |
7624 | ||
7625 | static const char * | |
7626 | regname_internal_riscv (unsigned int regno) | |
7627 | { | |
7628 | const char *name = NULL; | |
7629 | ||
7630 | /* Lookup in the table first, this covers GPR and FPR. */ | |
7631 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) | |
7632 | name = dwarf_regnames_riscv [regno]; | |
7633 | else if (regno >= 4096 && regno <= 8191) | |
7634 | { | |
7635 | /* This might be a CSR, these live in a sparse number space from 4096 | |
7636 | to 8191 These numbers are defined in the RISC-V ELF ABI | |
7637 | document. */ | |
7638 | switch (regno) | |
7639 | { | |
8f595e9b NC |
7640 | #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \ |
7641 | case VALUE + 4096: name = #NAME; break; | |
4762fe62 AB |
7642 | #include "opcode/riscv-opc.h" |
7643 | #undef DECLARE_CSR | |
7644 | ||
7645 | default: | |
7646 | { | |
7647 | static char csr_name[10]; | |
7648 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); | |
7649 | name = csr_name; | |
7650 | } | |
7651 | break; | |
7652 | } | |
7653 | } | |
7654 | ||
7655 | return name; | |
7656 | } | |
7657 | ||
99f6fdd9 | 7658 | static void |
5bb0830d AB |
7659 | init_dwarf_regnames_riscv (void) |
7660 | { | |
4762fe62 AB |
7661 | dwarf_regnames = NULL; |
7662 | dwarf_regnames_count = 8192; | |
7663 | dwarf_regnames_lookup_func = regname_internal_riscv; | |
5bb0830d AB |
7664 | } |
7665 | ||
2dc4cec1 | 7666 | void |
955ff7fc | 7667 | init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) |
2dc4cec1 | 7668 | { |
1296bc99 AB |
7669 | dwarf_regnames_lookup_func = NULL; |
7670 | ||
2dc4cec1 L |
7671 | switch (e_machine) |
7672 | { | |
7673 | case EM_386: | |
b129eb0e | 7674 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
7675 | break; |
7676 | ||
3d875af5 L |
7677 | case EM_IAMCU: |
7678 | init_dwarf_regnames_iamcu (); | |
7679 | break; | |
7680 | ||
2dc4cec1 | 7681 | case EM_X86_64: |
7f502d6c | 7682 | case EM_L1OM: |
7a9068fe | 7683 | case EM_K1OM: |
b129eb0e | 7684 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
7685 | break; |
7686 | ||
4ee22035 RH |
7687 | case EM_AARCH64: |
7688 | init_dwarf_regnames_aarch64 (); | |
7689 | break; | |
7690 | ||
d6bb17b0 AA |
7691 | case EM_S390: |
7692 | init_dwarf_regnames_s390 (); | |
7693 | break; | |
7694 | ||
5bb0830d AB |
7695 | case EM_RISCV: |
7696 | init_dwarf_regnames_riscv (); | |
7697 | break; | |
7698 | ||
2dc4cec1 L |
7699 | default: |
7700 | break; | |
7701 | } | |
7702 | } | |
7703 | ||
229a22cf AB |
7704 | /* Initialize the DWARF register name lookup state based on the |
7705 | architecture and specific machine type of a BFD. */ | |
7706 | ||
7707 | void | |
7708 | init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, | |
7709 | unsigned long mach) | |
7710 | { | |
1296bc99 AB |
7711 | dwarf_regnames_lookup_func = NULL; |
7712 | ||
229a22cf AB |
7713 | switch (arch) |
7714 | { | |
7715 | case bfd_arch_i386: | |
7716 | switch (mach) | |
7717 | { | |
7718 | case bfd_mach_x86_64: | |
7719 | case bfd_mach_x86_64_intel_syntax: | |
229a22cf AB |
7720 | case bfd_mach_x64_32: |
7721 | case bfd_mach_x64_32_intel_syntax: | |
229a22cf AB |
7722 | init_dwarf_regnames_x86_64 (); |
7723 | break; | |
7724 | ||
7725 | default: | |
7726 | init_dwarf_regnames_i386 (); | |
7727 | break; | |
7728 | } | |
7729 | break; | |
7730 | ||
7731 | case bfd_arch_iamcu: | |
7732 | init_dwarf_regnames_iamcu (); | |
7733 | break; | |
7734 | ||
7735 | case bfd_arch_aarch64: | |
7736 | init_dwarf_regnames_aarch64(); | |
7737 | break; | |
7738 | ||
7739 | case bfd_arch_s390: | |
7740 | init_dwarf_regnames_s390 (); | |
7741 | break; | |
7742 | ||
7743 | case bfd_arch_riscv: | |
7744 | init_dwarf_regnames_riscv (); | |
7745 | break; | |
7746 | ||
7747 | default: | |
7748 | break; | |
7749 | } | |
7750 | } | |
7751 | ||
2dc4cec1 | 7752 | static const char * |
1296bc99 | 7753 | regname_internal_by_table_only (unsigned int regno) |
2dc4cec1 | 7754 | { |
1296bc99 | 7755 | if (dwarf_regnames != NULL |
2dc4cec1 L |
7756 | && regno < dwarf_regnames_count |
7757 | && dwarf_regnames [regno] != NULL) | |
1296bc99 AB |
7758 | return dwarf_regnames [regno]; |
7759 | ||
7760 | return NULL; | |
7761 | } | |
7762 | ||
7763 | static const char * | |
7764 | regname (unsigned int regno, int name_only_p) | |
7765 | { | |
7766 | static char reg[64]; | |
7767 | ||
7768 | const char *name = NULL; | |
7769 | ||
7770 | if (dwarf_regnames_lookup_func != NULL) | |
7771 | name = dwarf_regnames_lookup_func (regno); | |
7772 | ||
7773 | if (name != NULL) | |
2dc4cec1 | 7774 | { |
1296bc99 AB |
7775 | if (name_only_p) |
7776 | return name; | |
7777 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); | |
2dc4cec1 L |
7778 | } |
7779 | else | |
7780 | snprintf (reg, sizeof (reg), "r%d", regno); | |
7781 | return reg; | |
7782 | } | |
7783 | ||
19e6b90e | 7784 | static void |
a1165289 | 7785 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 7786 | { |
a1165289 | 7787 | unsigned int r; |
19e6b90e L |
7788 | char tmp[100]; |
7789 | ||
d8024a91 | 7790 | if (*max_regs != fc->ncols) |
19e6b90e L |
7791 | *max_regs = fc->ncols; |
7792 | ||
7793 | if (*need_col_headers) | |
7794 | { | |
91d6fa6a | 7795 | static const char *sloc = " LOC"; |
2dc4cec1 | 7796 | |
19e6b90e L |
7797 | *need_col_headers = 0; |
7798 | ||
91d6fa6a | 7799 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
7800 | |
7801 | for (r = 0; r < *max_regs; r++) | |
7802 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7803 | { | |
7804 | if (r == fc->ra) | |
50751e18 | 7805 | printf ("ra "); |
19e6b90e | 7806 | else |
2dc4cec1 | 7807 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
7808 | } |
7809 | ||
7810 | printf ("\n"); | |
7811 | } | |
7812 | ||
bf5117e3 | 7813 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
7814 | if (fc->cfa_exp) |
7815 | strcpy (tmp, "exp"); | |
7816 | else | |
c8071705 | 7817 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
7818 | printf ("%-8s ", tmp); |
7819 | ||
7820 | for (r = 0; r < fc->ncols; r++) | |
7821 | { | |
7822 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7823 | { | |
7824 | switch (fc->col_type[r]) | |
7825 | { | |
7826 | case DW_CFA_undefined: | |
7827 | strcpy (tmp, "u"); | |
7828 | break; | |
7829 | case DW_CFA_same_value: | |
7830 | strcpy (tmp, "s"); | |
7831 | break; | |
7832 | case DW_CFA_offset: | |
7833 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
7834 | break; | |
12eae2d3 JJ |
7835 | case DW_CFA_val_offset: |
7836 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
7837 | break; | |
19e6b90e | 7838 | case DW_CFA_register: |
2dc4cec1 | 7839 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
7840 | break; |
7841 | case DW_CFA_expression: | |
7842 | strcpy (tmp, "exp"); | |
7843 | break; | |
12eae2d3 JJ |
7844 | case DW_CFA_val_expression: |
7845 | strcpy (tmp, "vexp"); | |
7846 | break; | |
19e6b90e L |
7847 | default: |
7848 | strcpy (tmp, "n/a"); | |
7849 | break; | |
7850 | } | |
2dc4cec1 | 7851 | printf ("%-5s ", tmp); |
19e6b90e L |
7852 | } |
7853 | } | |
7854 | printf ("\n"); | |
7855 | } | |
7856 | ||
49727e46 | 7857 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 7858 | |
49727e46 AM |
7859 | static unsigned char * |
7860 | read_cie (unsigned char *start, unsigned char *end, | |
7861 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 7862 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
7863 | { |
7864 | int version; | |
7865 | Frame_Chunk *fc; | |
49727e46 | 7866 | unsigned char *augmentation_data = NULL; |
bf59c5d5 | 7867 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 7868 | |
041830e0 | 7869 | * p_cie = NULL; |
f41e4712 NC |
7870 | /* PR 17512: file: 001-228113-0.004. */ |
7871 | if (start >= end) | |
7872 | return end; | |
7873 | ||
49727e46 AM |
7874 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
7875 | memset (fc, 0, sizeof (Frame_Chunk)); | |
7876 | ||
7877 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
7878 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
7879 | ||
7880 | version = *start++; | |
7881 | ||
7882 | fc->augmentation = (char *) start; | |
f41e4712 NC |
7883 | /* PR 17512: file: 001-228113-0.004. |
7884 | Skip past augmentation name, but avoid running off the end of the data. */ | |
7885 | while (start < end) | |
7886 | if (* start ++ == '\0') | |
7887 | break; | |
7888 | if (start == end) | |
7889 | { | |
7890 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 7891 | goto fail; |
f41e4712 | 7892 | } |
49727e46 AM |
7893 | |
7894 | if (strcmp (fc->augmentation, "eh") == 0) | |
7895 | start += eh_addr_size; | |
7896 | ||
7897 | if (version >= 4) | |
7898 | { | |
7899 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
7900 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
7901 | { | |
7902 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 7903 | goto fail; |
77ef8654 NC |
7904 | } |
7905 | ||
49727e46 | 7906 | GET (fc->segment_size, 1); |
77ef8654 NC |
7907 | /* PR 17512: file: e99d2804. */ |
7908 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
7909 | { | |
7910 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 7911 | goto fail; |
77ef8654 NC |
7912 | } |
7913 | ||
49727e46 AM |
7914 | eh_addr_size = fc->ptr_size; |
7915 | } | |
7916 | else | |
7917 | { | |
7918 | fc->ptr_size = eh_addr_size; | |
7919 | fc->segment_size = 0; | |
7920 | } | |
442a6ce8 | 7921 | |
cd30bcef AM |
7922 | READ_ULEB (fc->code_factor, start, end); |
7923 | READ_SLEB (fc->data_factor, start, end); | |
442a6ce8 | 7924 | |
49727e46 AM |
7925 | if (version == 1) |
7926 | { | |
7927 | GET (fc->ra, 1); | |
7928 | } | |
7929 | else | |
7930 | { | |
cd30bcef | 7931 | READ_ULEB (fc->ra, start, end); |
49727e46 AM |
7932 | } |
7933 | ||
7934 | if (fc->augmentation[0] == 'z') | |
7935 | { | |
cd30bcef | 7936 | READ_ULEB (augmentation_data_len, start, end); |
49727e46 | 7937 | augmentation_data = start; |
a1165289 | 7938 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 7939 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 7940 | { |
bf59c5d5 NC |
7941 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
7942 | dwarf_vmatoa ("x", augmentation_data_len), | |
7943 | (unsigned long) (end - start)); | |
442a6ce8 | 7944 | goto fail; |
a1165289 | 7945 | } |
9c0f3d3f | 7946 | start += augmentation_data_len; |
49727e46 AM |
7947 | } |
7948 | ||
7949 | if (augmentation_data_len) | |
7950 | { | |
058037d3 NC |
7951 | unsigned char *p; |
7952 | unsigned char *q; | |
7953 | unsigned char *qend; | |
b4eb7656 | 7954 | |
49727e46 AM |
7955 | p = (unsigned char *) fc->augmentation + 1; |
7956 | q = augmentation_data; | |
058037d3 NC |
7957 | qend = q + augmentation_data_len; |
7958 | ||
9c0f3d3f | 7959 | while (p < end && q < qend) |
49727e46 AM |
7960 | { |
7961 | if (*p == 'L') | |
7962 | q++; | |
7963 | else if (*p == 'P') | |
7964 | q += 1 + size_of_encoded_value (*q); | |
7965 | else if (*p == 'R') | |
7966 | fc->fde_encoding = *q++; | |
7967 | else if (*p == 'S') | |
7968 | ; | |
09038062 ST |
7969 | else if (*p == 'B') |
7970 | ; | |
49727e46 AM |
7971 | else |
7972 | break; | |
7973 | p++; | |
7974 | } | |
c361b9ac NC |
7975 | /* Note - it is OK if this loop terminates with q < qend. |
7976 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
7977 | } |
7978 | ||
7979 | *p_cie = fc; | |
7980 | if (p_version) | |
7981 | *p_version = version; | |
7982 | if (p_aug_len) | |
7983 | { | |
7984 | *p_aug_len = augmentation_data_len; | |
7985 | *p_aug = augmentation_data; | |
7986 | } | |
7987 | return start; | |
442a6ce8 NC |
7988 | |
7989 | fail: | |
7990 | free (fc->col_offset); | |
7991 | free (fc->col_type); | |
7992 | free (fc); | |
7993 | return end; | |
49727e46 AM |
7994 | } |
7995 | ||
d85bf2ba NC |
7996 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
7997 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
7998 | PRINTED contains the number of characters already written to the current | |
7999 | output line. */ | |
bf59c5d5 NC |
8000 | |
8001 | static void | |
d85bf2ba NC |
8002 | display_data (bfd_size_type printed, |
8003 | const unsigned char * data, | |
8004 | const bfd_size_type len) | |
bf59c5d5 | 8005 | { |
d85bf2ba NC |
8006 | if (do_wide || len < ((80 - printed) / 3)) |
8007 | for (printed = 0; printed < len; ++printed) | |
8008 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
8009 | else |
8010 | { | |
d85bf2ba | 8011 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 8012 | { |
d85bf2ba | 8013 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 8014 | putchar ('\n'); |
d85bf2ba | 8015 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
8016 | } |
8017 | } | |
d85bf2ba NC |
8018 | } |
8019 | ||
8020 | /* Prints out the contents on the augmentation data array. | |
8021 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
8022 | ||
8023 | static void | |
8024 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
8025 | { | |
8026 | bfd_size_type i; | |
8027 | ||
8028 | i = printf (_(" Augmentation data: ")); | |
8029 | display_data (i, data, len); | |
bf59c5d5 NC |
8030 | } |
8031 | ||
19e6b90e L |
8032 | static int |
8033 | display_debug_frames (struct dwarf_section *section, | |
8034 | void *file ATTRIBUTE_UNUSED) | |
8035 | { | |
8036 | unsigned char *start = section->start; | |
8037 | unsigned char *end = start + section->size; | |
8038 | unsigned char *section_start = start; | |
3391569f NC |
8039 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
8040 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 8041 | Frame_Chunk *rs; |
3391569f | 8042 | bfd_boolean is_eh = strcmp (section->name, ".eh_frame") == 0; |
a1165289 | 8043 | unsigned int max_regs = 0; |
665ce1f6 | 8044 | const char *bad_reg = _("bad register: "); |
77ef8654 | 8045 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 8046 | |
dda8d76d | 8047 | introduce (section, FALSE); |
19e6b90e L |
8048 | |
8049 | while (start < end) | |
8050 | { | |
8051 | unsigned char *saved_start; | |
8052 | unsigned char *block_end; | |
bf5117e3 NC |
8053 | dwarf_vma length; |
8054 | dwarf_vma cie_id; | |
19e6b90e L |
8055 | Frame_Chunk *fc; |
8056 | Frame_Chunk *cie; | |
8057 | int need_col_headers = 1; | |
8058 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 8059 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
8060 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
8061 | unsigned int offset_size; | |
8062 | unsigned int initial_length_size; | |
5b6312fd | 8063 | bfd_boolean all_nops; |
a788aedd | 8064 | static Frame_Chunk fde_fc; |
19e6b90e L |
8065 | |
8066 | saved_start = start; | |
19e6b90e | 8067 | |
0c588247 | 8068 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 8069 | |
19e6b90e L |
8070 | if (length == 0) |
8071 | { | |
8072 | printf ("\n%08lx ZERO terminator\n\n", | |
8073 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
8074 | /* Skip any zero terminators that directly follow. |
8075 | A corrupt section size could have loaded a whole | |
8076 | slew of zero filled memory bytes. eg | |
8077 | PR 17512: file: 070-19381-0.004. */ | |
8078 | while (start < end && * start == 0) | |
8079 | ++ start; | |
b758e50f | 8080 | continue; |
19e6b90e L |
8081 | } |
8082 | ||
8083 | if (length == 0xffffffff) | |
8084 | { | |
0c588247 | 8085 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
8086 | offset_size = 8; |
8087 | initial_length_size = 12; | |
8088 | } | |
8089 | else | |
8090 | { | |
8091 | offset_size = 4; | |
8092 | initial_length_size = 4; | |
8093 | } | |
8094 | ||
8095 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 8096 | if (block_end > end || block_end < start) |
53b8873b | 8097 | { |
bf5117e3 NC |
8098 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
8099 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
8100 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
8101 | block_end = end; |
8102 | } | |
0c588247 NC |
8103 | |
8104 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 8105 | |
846a11e4 NC |
8106 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
8107 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
8108 | { |
8109 | int version; | |
a1165289 | 8110 | unsigned int mreg; |
19e6b90e | 8111 | |
49727e46 AM |
8112 | start = read_cie (start, end, &cie, &version, |
8113 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
8114 | /* PR 17512: file: 027-135133-0.005. */ |
8115 | if (cie == NULL) | |
8116 | break; | |
a1165289 | 8117 | |
49727e46 | 8118 | fc = cie; |
19e6b90e L |
8119 | fc->next = chunks; |
8120 | chunks = fc; | |
8121 | fc->chunk_start = saved_start; | |
a1165289 | 8122 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8123 | if (mreg < fc->ra) |
8124 | mreg = fc->ra; | |
06614111 NC |
8125 | if (frame_need_space (fc, mreg) < 0) |
8126 | break; | |
49727e46 AM |
8127 | if (fc->fde_encoding) |
8128 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 8129 | |
bf5117e3 NC |
8130 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
8131 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 8132 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 8133 | |
19e6b90e | 8134 | if (do_debug_frames_interp) |
bf5117e3 NC |
8135 | { |
8136 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
8137 | fc->code_factor, fc->data_factor, fc->ra); | |
8138 | } | |
19e6b90e L |
8139 | else |
8140 | { | |
bf5117e3 | 8141 | printf ("CIE\n"); |
19e6b90e L |
8142 | printf (" Version: %d\n", version); |
8143 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
8144 | if (version >= 4) |
8145 | { | |
8146 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
8147 | printf (" Segment Size: %u\n", fc->segment_size); | |
8148 | } | |
19e6b90e L |
8149 | printf (" Code alignment factor: %u\n", fc->code_factor); |
8150 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
8151 | printf (" Return address column: %d\n", fc->ra); | |
8152 | ||
8153 | if (augmentation_data_len) | |
bf59c5d5 | 8154 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 8155 | |
19e6b90e L |
8156 | putchar ('\n'); |
8157 | } | |
19e6b90e L |
8158 | } |
8159 | else | |
8160 | { | |
8161 | unsigned char *look_for; | |
604282a7 | 8162 | unsigned long segment_selector; |
19e6b90e | 8163 | |
49727e46 AM |
8164 | if (is_eh) |
8165 | { | |
8166 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
8167 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
8168 | } | |
8169 | else | |
8170 | look_for = section_start + cie_id; | |
19e6b90e | 8171 | |
49727e46 AM |
8172 | if (look_for <= saved_start) |
8173 | { | |
8174 | for (cie = chunks; cie ; cie = cie->next) | |
8175 | if (cie->chunk_start == look_for) | |
8176 | break; | |
8177 | } | |
8178 | else | |
8179 | { | |
8180 | for (cie = forward_refs; cie ; cie = cie->next) | |
8181 | if (cie->chunk_start == look_for) | |
8182 | break; | |
8183 | if (!cie) | |
8184 | { | |
8185 | unsigned int off_size; | |
8186 | unsigned char *cie_scan; | |
19e6b90e | 8187 | |
49727e46 AM |
8188 | cie_scan = look_for; |
8189 | off_size = 4; | |
8190 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
8191 | if (length == 0xffffffff) | |
8192 | { | |
8193 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
8194 | off_size = 8; | |
8195 | } | |
8196 | if (length != 0) | |
8197 | { | |
8198 | dwarf_vma c_id; | |
8199 | ||
8200 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
8201 | if (is_eh | |
8202 | ? c_id == 0 | |
8203 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
8204 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
8205 | { | |
8206 | int version; | |
a1165289 | 8207 | unsigned int mreg; |
49727e46 AM |
8208 | |
8209 | read_cie (cie_scan, end, &cie, &version, | |
8210 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
8211 | /* PR 17512: file: 3450-2098-0.004. */ |
8212 | if (cie == NULL) | |
8213 | { | |
8214 | warn (_("Failed to read CIE information\n")); | |
8215 | break; | |
8216 | } | |
49727e46 AM |
8217 | cie->next = forward_refs; |
8218 | forward_refs = cie; | |
8219 | cie->chunk_start = look_for; | |
a1165289 | 8220 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8221 | if (mreg < cie->ra) |
8222 | mreg = cie->ra; | |
06614111 NC |
8223 | if (frame_need_space (cie, mreg) < 0) |
8224 | { | |
8225 | warn (_("Invalid max register\n")); | |
8226 | break; | |
8227 | } | |
49727e46 AM |
8228 | if (cie->fde_encoding) |
8229 | encoded_ptr_size | |
8230 | = size_of_encoded_value (cie->fde_encoding); | |
8231 | } | |
8232 | } | |
8233 | } | |
8234 | } | |
8235 | ||
8236 | fc = &fde_fc; | |
8237 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
8238 | |
8239 | if (!cie) | |
8240 | { | |
bf5117e3 NC |
8241 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
8242 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
8243 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 8244 | fc->ncols = 0; |
3f5e193b NC |
8245 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
8246 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
8247 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
8248 | { | |
8249 | warn (_("Invalid max register\n")); | |
8250 | break; | |
8251 | } | |
19e6b90e L |
8252 | cie = fc; |
8253 | fc->augmentation = ""; | |
8254 | fc->fde_encoding = 0; | |
604282a7 JJ |
8255 | fc->ptr_size = eh_addr_size; |
8256 | fc->segment_size = 0; | |
19e6b90e L |
8257 | } |
8258 | else | |
8259 | { | |
8260 | fc->ncols = cie->ncols; | |
3f5e193b NC |
8261 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
8262 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
8263 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
8264 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
8265 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
8266 | fc->ptr_size = cie->ptr_size; |
8267 | eh_addr_size = cie->ptr_size; | |
8268 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
8269 | fc->code_factor = cie->code_factor; |
8270 | fc->data_factor = cie->data_factor; | |
8271 | fc->cfa_reg = cie->cfa_reg; | |
8272 | fc->cfa_offset = cie->cfa_offset; | |
8273 | fc->ra = cie->ra; | |
06614111 NC |
8274 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
8275 | { | |
8276 | warn (_("Invalid max register\n")); | |
8277 | break; | |
8278 | } | |
19e6b90e L |
8279 | fc->fde_encoding = cie->fde_encoding; |
8280 | } | |
8281 | ||
8282 | if (fc->fde_encoding) | |
8283 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
8284 | ||
604282a7 JJ |
8285 | segment_selector = 0; |
8286 | if (fc->segment_size) | |
c8071705 NC |
8287 | { |
8288 | if (fc->segment_size > sizeof (segment_selector)) | |
8289 | { | |
8290 | /* PR 17512: file: 9e196b3e. */ | |
8291 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
8292 | fc->segment_size = 4; | |
8293 | } | |
8294 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
8295 | } | |
041830e0 NC |
8296 | |
8297 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 8298 | |
0c588247 NC |
8299 | /* FIXME: It appears that sometimes the final pc_range value is |
8300 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
8301 | run of the "objcopy on compressed debug sections" test for an | |
8302 | example of this. */ | |
8303 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 8304 | |
19e6b90e L |
8305 | if (cie->augmentation[0] == 'z') |
8306 | { | |
cd30bcef | 8307 | READ_ULEB (augmentation_data_len, start, end); |
19e6b90e | 8308 | augmentation_data = start; |
bf59c5d5 | 8309 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
d292364e | 8310 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
0a9d414a | 8311 | { |
d292364e AM |
8312 | warn (_("Augmentation data too long: 0x%s, " |
8313 | "expected at most %#lx\n"), | |
8314 | dwarf_vmatoa ("x", augmentation_data_len), | |
8315 | (unsigned long) (end - start)); | |
0a9d414a NC |
8316 | start = end; |
8317 | augmentation_data = NULL; | |
8318 | augmentation_data_len = 0; | |
8319 | } | |
d292364e | 8320 | start += augmentation_data_len; |
19e6b90e L |
8321 | } |
8322 | ||
bf5117e3 NC |
8323 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
8324 | (unsigned long)(saved_start - section_start), | |
8325 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 8326 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 8327 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 8328 | |
604282a7 JJ |
8329 | if (fc->segment_size) |
8330 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
8331 | |
8332 | printf ("%s..%s\n", | |
8333 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
8334 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
8335 | ||
19e6b90e L |
8336 | if (! do_debug_frames_interp && augmentation_data_len) |
8337 | { | |
bf59c5d5 | 8338 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
8339 | putchar ('\n'); |
8340 | } | |
8341 | } | |
8342 | ||
8343 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
8344 | we're about to interpret instructions for the chunk. */ | |
8345 | /* ??? At present we need to do this always, since this sizes the | |
8346 | fc->col_type and fc->col_offset arrays, which we write into always. | |
8347 | We should probably split the interpreted and non-interpreted bits | |
8348 | into two different routines, since there's so much that doesn't | |
8349 | really overlap between them. */ | |
8350 | if (1 || do_debug_frames_interp) | |
8351 | { | |
8352 | /* Start by making a pass over the chunk, allocating storage | |
8353 | and taking note of what registers are used. */ | |
8354 | unsigned char *tmp = start; | |
8355 | ||
8356 | while (start < block_end) | |
8357 | { | |
041830e0 NC |
8358 | unsigned int reg, op, opa; |
8359 | unsigned long temp; | |
5929c344 | 8360 | unsigned char * new_start; |
19e6b90e L |
8361 | |
8362 | op = *start++; | |
8363 | opa = op & 0x3f; | |
8364 | if (op & 0xc0) | |
8365 | op &= 0xc0; | |
8366 | ||
8367 | /* Warning: if you add any more cases to this switch, be | |
8368 | sure to add them to the corresponding switch below. */ | |
8369 | switch (op) | |
8370 | { | |
8371 | case DW_CFA_advance_loc: | |
8372 | break; | |
8373 | case DW_CFA_offset: | |
cd30bcef | 8374 | SKIP_ULEB (start, end); |
665ce1f6 L |
8375 | if (frame_need_space (fc, opa) >= 0) |
8376 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8377 | break; |
8378 | case DW_CFA_restore: | |
665ce1f6 L |
8379 | if (frame_need_space (fc, opa) >= 0) |
8380 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8381 | break; |
8382 | case DW_CFA_set_loc: | |
8383 | start += encoded_ptr_size; | |
8384 | break; | |
8385 | case DW_CFA_advance_loc1: | |
8386 | start += 1; | |
8387 | break; | |
8388 | case DW_CFA_advance_loc2: | |
8389 | start += 2; | |
8390 | break; | |
8391 | case DW_CFA_advance_loc4: | |
8392 | start += 4; | |
8393 | break; | |
8394 | case DW_CFA_offset_extended: | |
12eae2d3 | 8395 | case DW_CFA_val_offset: |
cd30bcef AM |
8396 | READ_ULEB (reg, start, end); |
8397 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8398 | if (frame_need_space (fc, reg) >= 0) |
8399 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8400 | break; |
8401 | case DW_CFA_restore_extended: | |
cd30bcef | 8402 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8403 | if (frame_need_space (fc, reg) >= 0) |
8404 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8405 | break; |
8406 | case DW_CFA_undefined: | |
cd30bcef | 8407 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8408 | if (frame_need_space (fc, reg) >= 0) |
8409 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8410 | break; |
8411 | case DW_CFA_same_value: | |
cd30bcef | 8412 | READ_ULEB (reg, 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_register: | |
cd30bcef AM |
8417 | READ_ULEB (reg, start, end); |
8418 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8419 | if (frame_need_space (fc, reg) >= 0) |
8420 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8421 | break; |
8422 | case DW_CFA_def_cfa: | |
cd30bcef AM |
8423 | SKIP_ULEB (start, end); |
8424 | SKIP_ULEB (start, end); | |
19e6b90e L |
8425 | break; |
8426 | case DW_CFA_def_cfa_register: | |
cd30bcef | 8427 | SKIP_ULEB (start, end); |
19e6b90e L |
8428 | break; |
8429 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 8430 | SKIP_ULEB (start, end); |
19e6b90e L |
8431 | break; |
8432 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 8433 | READ_ULEB (temp, start, end); |
5929c344 NC |
8434 | new_start = start + temp; |
8435 | if (new_start < start) | |
041830e0 NC |
8436 | { |
8437 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
8438 | start = block_end; | |
8439 | } | |
8440 | else | |
5929c344 | 8441 | start = new_start; |
19e6b90e L |
8442 | break; |
8443 | case DW_CFA_expression: | |
12eae2d3 | 8444 | case DW_CFA_val_expression: |
cd30bcef AM |
8445 | READ_ULEB (reg, start, end); |
8446 | READ_ULEB (temp, start, end); | |
5929c344 NC |
8447 | new_start = start + temp; |
8448 | if (new_start < start) | |
041830e0 | 8449 | { |
b4eb7656 | 8450 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
8451 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
8452 | start = block_end; | |
8453 | } | |
8454 | else | |
5929c344 | 8455 | start = new_start; |
665ce1f6 L |
8456 | if (frame_need_space (fc, reg) >= 0) |
8457 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8458 | break; |
8459 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 8460 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
8461 | READ_ULEB (reg, start, end); |
8462 | SKIP_SLEB (start, end); | |
665ce1f6 L |
8463 | if (frame_need_space (fc, reg) >= 0) |
8464 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8465 | break; |
8466 | case DW_CFA_def_cfa_sf: | |
cd30bcef AM |
8467 | SKIP_ULEB (start, end); |
8468 | SKIP_SLEB (start, end); | |
19e6b90e L |
8469 | break; |
8470 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 8471 | SKIP_SLEB (start, end); |
19e6b90e L |
8472 | break; |
8473 | case DW_CFA_MIPS_advance_loc8: | |
8474 | start += 8; | |
8475 | break; | |
8476 | case DW_CFA_GNU_args_size: | |
cd30bcef | 8477 | SKIP_ULEB (start, end); |
19e6b90e L |
8478 | break; |
8479 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
8480 | READ_ULEB (reg, start, end); |
8481 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8482 | if (frame_need_space (fc, reg) >= 0) |
8483 | fc->col_type[reg] = DW_CFA_undefined; | |
8484 | break; | |
19e6b90e L |
8485 | default: |
8486 | break; | |
8487 | } | |
8488 | } | |
8489 | start = tmp; | |
8490 | } | |
8491 | ||
5b6312fd NC |
8492 | all_nops = TRUE; |
8493 | ||
19e6b90e L |
8494 | /* Now we know what registers are used, make a second pass over |
8495 | the chunk, this time actually printing out the info. */ | |
8496 | ||
8497 | while (start < block_end) | |
8498 | { | |
362beea4 | 8499 | unsigned char * tmp; |
19e6b90e | 8500 | unsigned op, opa; |
7f2c8a1d NC |
8501 | unsigned long ul, roffs; |
8502 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
8503 | are various functions, notably frame_space_needed() that assume that | |
8504 | reg is an unsigned int. */ | |
8505 | unsigned int reg; | |
8506 | dwarf_signed_vma l; | |
bf5117e3 | 8507 | dwarf_vma ofs; |
19e6b90e | 8508 | dwarf_vma vma; |
665ce1f6 | 8509 | const char *reg_prefix = ""; |
19e6b90e L |
8510 | |
8511 | op = *start++; | |
8512 | opa = op & 0x3f; | |
8513 | if (op & 0xc0) | |
8514 | op &= 0xc0; | |
8515 | ||
5b6312fd NC |
8516 | /* Make a note if something other than DW_CFA_nop happens. */ |
8517 | if (op != DW_CFA_nop) | |
8518 | all_nops = FALSE; | |
8519 | ||
19e6b90e L |
8520 | /* Warning: if you add any more cases to this switch, be |
8521 | sure to add them to the corresponding switch above. */ | |
8522 | switch (op) | |
8523 | { | |
8524 | case DW_CFA_advance_loc: | |
8525 | if (do_debug_frames_interp) | |
8526 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8527 | else | |
bf5117e3 | 8528 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 8529 | opa * fc->code_factor, |
b4eb7656 | 8530 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
8531 | fc->pc_begin + opa * fc->code_factor, |
8532 | fc->ptr_size)); | |
19e6b90e L |
8533 | fc->pc_begin += opa * fc->code_factor; |
8534 | break; | |
8535 | ||
8536 | case DW_CFA_offset: | |
cd30bcef | 8537 | READ_ULEB (roffs, start, end); |
665ce1f6 L |
8538 | if (opa >= (unsigned int) fc->ncols) |
8539 | reg_prefix = bad_reg; | |
8540 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8541 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
8542 | reg_prefix, regname (opa, 0), | |
8543 | roffs * fc->data_factor); | |
8544 | if (*reg_prefix == '\0') | |
8545 | { | |
8546 | fc->col_type[opa] = DW_CFA_offset; | |
8547 | fc->col_offset[opa] = roffs * fc->data_factor; | |
8548 | } | |
19e6b90e L |
8549 | break; |
8550 | ||
8551 | case DW_CFA_restore: | |
50751e18 | 8552 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
8553 | reg_prefix = bad_reg; |
8554 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8555 | printf (" DW_CFA_restore: %s%s\n", | |
8556 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
8557 | if (*reg_prefix != '\0') |
8558 | break; | |
8559 | ||
8560 | if (opa >= (unsigned int) cie->ncols | |
8561 | || (do_debug_frames_interp | |
8562 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
8563 | { | |
8564 | fc->col_type[opa] = DW_CFA_undefined; | |
8565 | fc->col_offset[opa] = 0; | |
8566 | } | |
8567 | else | |
665ce1f6 L |
8568 | { |
8569 | fc->col_type[opa] = cie->col_type[opa]; | |
8570 | fc->col_offset[opa] = cie->col_offset[opa]; | |
8571 | } | |
19e6b90e L |
8572 | break; |
8573 | ||
8574 | case DW_CFA_set_loc: | |
6937bb54 | 8575 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
8576 | if (do_debug_frames_interp) |
8577 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8578 | else | |
bf5117e3 NC |
8579 | printf (" DW_CFA_set_loc: %s\n", |
8580 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
8581 | fc->pc_begin = vma; |
8582 | break; | |
8583 | ||
8584 | case DW_CFA_advance_loc1: | |
0c588247 | 8585 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
8586 | if (do_debug_frames_interp) |
8587 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8588 | else | |
bf5117e3 NC |
8589 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
8590 | (unsigned long) (ofs * fc->code_factor), | |
8591 | dwarf_vmatoa_1 (NULL, | |
8592 | fc->pc_begin + ofs * fc->code_factor, | |
8593 | fc->ptr_size)); | |
19e6b90e L |
8594 | fc->pc_begin += ofs * fc->code_factor; |
8595 | break; | |
8596 | ||
8597 | case DW_CFA_advance_loc2: | |
6937bb54 | 8598 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
8599 | if (do_debug_frames_interp) |
8600 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8601 | else | |
bf5117e3 NC |
8602 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
8603 | (unsigned long) (ofs * fc->code_factor), | |
8604 | dwarf_vmatoa_1 (NULL, | |
8605 | fc->pc_begin + ofs * fc->code_factor, | |
8606 | fc->ptr_size)); | |
19e6b90e L |
8607 | fc->pc_begin += ofs * fc->code_factor; |
8608 | break; | |
8609 | ||
8610 | case DW_CFA_advance_loc4: | |
6937bb54 | 8611 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
8612 | if (do_debug_frames_interp) |
8613 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8614 | else | |
bf5117e3 NC |
8615 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
8616 | (unsigned long) (ofs * fc->code_factor), | |
8617 | dwarf_vmatoa_1 (NULL, | |
8618 | fc->pc_begin + ofs * fc->code_factor, | |
8619 | fc->ptr_size)); | |
19e6b90e L |
8620 | fc->pc_begin += ofs * fc->code_factor; |
8621 | break; | |
8622 | ||
8623 | case DW_CFA_offset_extended: | |
cd30bcef AM |
8624 | READ_ULEB (reg, start, end); |
8625 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
8626 | if (reg >= (unsigned int) fc->ncols) |
8627 | reg_prefix = bad_reg; | |
8628 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8629 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
8630 | reg_prefix, regname (reg, 0), | |
8631 | roffs * fc->data_factor); | |
8632 | if (*reg_prefix == '\0') | |
8633 | { | |
8634 | fc->col_type[reg] = DW_CFA_offset; | |
8635 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8636 | } | |
19e6b90e L |
8637 | break; |
8638 | ||
12eae2d3 | 8639 | case DW_CFA_val_offset: |
cd30bcef AM |
8640 | READ_ULEB (reg, start, end); |
8641 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
8642 | if (reg >= (unsigned int) fc->ncols) |
8643 | reg_prefix = bad_reg; | |
8644 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8645 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
8646 | reg_prefix, regname (reg, 0), |
8647 | roffs * fc->data_factor); | |
8648 | if (*reg_prefix == '\0') | |
8649 | { | |
8650 | fc->col_type[reg] = DW_CFA_val_offset; | |
8651 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8652 | } | |
12eae2d3 JJ |
8653 | break; |
8654 | ||
19e6b90e | 8655 | case DW_CFA_restore_extended: |
cd30bcef | 8656 | READ_ULEB (reg, start, end); |
50751e18 | 8657 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
8658 | reg_prefix = bad_reg; |
8659 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8660 | printf (" DW_CFA_restore_extended: %s%s\n", | |
8661 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
8662 | if (*reg_prefix != '\0') |
8663 | break; | |
8664 | ||
8665 | if (reg >= (unsigned int) cie->ncols) | |
8666 | { | |
8667 | fc->col_type[reg] = DW_CFA_undefined; | |
8668 | fc->col_offset[reg] = 0; | |
8669 | } | |
8670 | else | |
665ce1f6 L |
8671 | { |
8672 | fc->col_type[reg] = cie->col_type[reg]; | |
8673 | fc->col_offset[reg] = cie->col_offset[reg]; | |
8674 | } | |
19e6b90e L |
8675 | break; |
8676 | ||
8677 | case DW_CFA_undefined: | |
cd30bcef | 8678 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8679 | if (reg >= (unsigned int) fc->ncols) |
8680 | reg_prefix = bad_reg; | |
8681 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8682 | printf (" DW_CFA_undefined: %s%s\n", | |
8683 | reg_prefix, regname (reg, 0)); | |
8684 | if (*reg_prefix == '\0') | |
8685 | { | |
8686 | fc->col_type[reg] = DW_CFA_undefined; | |
8687 | fc->col_offset[reg] = 0; | |
8688 | } | |
19e6b90e L |
8689 | break; |
8690 | ||
8691 | case DW_CFA_same_value: | |
cd30bcef | 8692 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8693 | if (reg >= (unsigned int) fc->ncols) |
8694 | reg_prefix = bad_reg; | |
8695 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8696 | printf (" DW_CFA_same_value: %s%s\n", | |
8697 | reg_prefix, regname (reg, 0)); | |
8698 | if (*reg_prefix == '\0') | |
8699 | { | |
8700 | fc->col_type[reg] = DW_CFA_same_value; | |
8701 | fc->col_offset[reg] = 0; | |
8702 | } | |
19e6b90e L |
8703 | break; |
8704 | ||
8705 | case DW_CFA_register: | |
cd30bcef AM |
8706 | READ_ULEB (reg, start, end); |
8707 | READ_ULEB (roffs, 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') | |
2dc4cec1 | 8711 | { |
665ce1f6 L |
8712 | printf (" DW_CFA_register: %s%s in ", |
8713 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
8714 | puts (regname (roffs, 0)); |
8715 | } | |
665ce1f6 L |
8716 | if (*reg_prefix == '\0') |
8717 | { | |
8718 | fc->col_type[reg] = DW_CFA_register; | |
8719 | fc->col_offset[reg] = roffs; | |
8720 | } | |
19e6b90e L |
8721 | break; |
8722 | ||
8723 | case DW_CFA_remember_state: | |
8724 | if (! do_debug_frames_interp) | |
8725 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 8726 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 8727 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
8728 | rs->cfa_reg = fc->cfa_reg; |
8729 | rs->ra = fc->ra; | |
8730 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 8731 | rs->ncols = fc->ncols; |
3f5e193b | 8732 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 8733 | sizeof (* rs->col_type)); |
d71ad7fc RC |
8734 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
8735 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
8736 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
8737 | rs->next = remembered_state; |
8738 | remembered_state = rs; | |
8739 | break; | |
8740 | ||
8741 | case DW_CFA_restore_state: | |
8742 | if (! do_debug_frames_interp) | |
8743 | printf (" DW_CFA_restore_state\n"); | |
8744 | rs = remembered_state; | |
8745 | if (rs) | |
8746 | { | |
8747 | remembered_state = rs->next; | |
d71ad7fc RC |
8748 | fc->cfa_offset = rs->cfa_offset; |
8749 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
8750 | fc->ra = rs->ra; |
8751 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
8752 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
8753 | { | |
1306a742 | 8754 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
8755 | fc->ncols = 0; |
8756 | break; | |
8757 | } | |
d71ad7fc | 8758 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 8759 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 8760 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
8761 | free (rs->col_type); |
8762 | free (rs->col_offset); | |
8763 | free (rs); | |
8764 | } | |
8765 | else if (do_debug_frames_interp) | |
8766 | printf ("Mismatched DW_CFA_restore_state\n"); | |
8767 | break; | |
8768 | ||
8769 | case DW_CFA_def_cfa: | |
cd30bcef AM |
8770 | READ_ULEB (fc->cfa_reg, start, end); |
8771 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
8772 | fc->cfa_exp = 0; |
8773 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8774 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 8775 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8776 | break; |
8777 | ||
8778 | case DW_CFA_def_cfa_register: | |
cd30bcef | 8779 | READ_ULEB (fc->cfa_reg, start, end); |
19e6b90e L |
8780 | fc->cfa_exp = 0; |
8781 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
8782 | printf (" DW_CFA_def_cfa_register: %s\n", |
8783 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
8784 | break; |
8785 | ||
8786 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 8787 | READ_ULEB (fc->cfa_offset, start, end); |
19e6b90e | 8788 | if (! do_debug_frames_interp) |
c8071705 | 8789 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8790 | break; |
8791 | ||
8792 | case DW_CFA_nop: | |
8793 | if (! do_debug_frames_interp) | |
8794 | printf (" DW_CFA_nop\n"); | |
8795 | break; | |
8796 | ||
8797 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 8798 | READ_ULEB (ul, start, end); |
7460c0ab | 8799 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 8800 | { |
a1165289 | 8801 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8802 | break; |
8803 | } | |
19e6b90e L |
8804 | if (! do_debug_frames_interp) |
8805 | { | |
8806 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
8807 | decode_location_expression (start, eh_addr_size, 0, -1, |
8808 | ul, 0, section); | |
19e6b90e L |
8809 | printf (")\n"); |
8810 | } | |
8811 | fc->cfa_exp = 1; | |
8812 | start += ul; | |
8813 | break; | |
8814 | ||
8815 | case DW_CFA_expression: | |
cd30bcef AM |
8816 | READ_ULEB (reg, start, end); |
8817 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
8818 | if (reg >= (unsigned int) fc->ncols) |
8819 | reg_prefix = bad_reg; | |
6937bb54 | 8820 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 8821 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
8822 | tmp = start + ul; |
8823 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8824 | { |
a1165289 | 8825 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8826 | break; |
8827 | } | |
665ce1f6 | 8828 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 8829 | { |
665ce1f6 L |
8830 | printf (" DW_CFA_expression: %s%s (", |
8831 | reg_prefix, regname (reg, 0)); | |
b7807392 | 8832 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 8833 | ul, 0, section); |
19e6b90e L |
8834 | printf (")\n"); |
8835 | } | |
665ce1f6 L |
8836 | if (*reg_prefix == '\0') |
8837 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 8838 | start = tmp; |
19e6b90e L |
8839 | break; |
8840 | ||
12eae2d3 | 8841 | case DW_CFA_val_expression: |
cd30bcef AM |
8842 | READ_ULEB (reg, start, end); |
8843 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
8844 | if (reg >= (unsigned int) fc->ncols) |
8845 | reg_prefix = bad_reg; | |
362beea4 NC |
8846 | tmp = start + ul; |
8847 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8848 | { |
a1165289 | 8849 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
8850 | break; |
8851 | } | |
665ce1f6 | 8852 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 8853 | { |
665ce1f6 L |
8854 | printf (" DW_CFA_val_expression: %s%s (", |
8855 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
8856 | decode_location_expression (start, eh_addr_size, 0, -1, |
8857 | ul, 0, section); | |
12eae2d3 JJ |
8858 | printf (")\n"); |
8859 | } | |
665ce1f6 L |
8860 | if (*reg_prefix == '\0') |
8861 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 8862 | start = tmp; |
12eae2d3 JJ |
8863 | break; |
8864 | ||
19e6b90e | 8865 | case DW_CFA_offset_extended_sf: |
cd30bcef AM |
8866 | READ_ULEB (reg, start, end); |
8867 | READ_SLEB (l, start, end); | |
665ce1f6 L |
8868 | if (frame_need_space (fc, reg) < 0) |
8869 | reg_prefix = bad_reg; | |
8870 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8871 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
8872 | reg_prefix, regname (reg, 0), | |
c8071705 | 8873 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8874 | if (*reg_prefix == '\0') |
8875 | { | |
8876 | fc->col_type[reg] = DW_CFA_offset; | |
8877 | fc->col_offset[reg] = l * fc->data_factor; | |
8878 | } | |
19e6b90e L |
8879 | break; |
8880 | ||
12eae2d3 | 8881 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
8882 | READ_ULEB (reg, start, end); |
8883 | READ_SLEB (l, start, end); | |
665ce1f6 L |
8884 | if (frame_need_space (fc, reg) < 0) |
8885 | reg_prefix = bad_reg; | |
8886 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8887 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 8888 | reg_prefix, regname (reg, 0), |
c8071705 | 8889 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8890 | if (*reg_prefix == '\0') |
8891 | { | |
8892 | fc->col_type[reg] = DW_CFA_val_offset; | |
8893 | fc->col_offset[reg] = l * fc->data_factor; | |
8894 | } | |
12eae2d3 JJ |
8895 | break; |
8896 | ||
19e6b90e | 8897 | case DW_CFA_def_cfa_sf: |
cd30bcef AM |
8898 | READ_ULEB (fc->cfa_reg, start, end); |
8899 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
8900 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
8901 | fc->cfa_exp = 0; | |
8902 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8903 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 8904 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8905 | break; |
8906 | ||
8907 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 8908 | READ_ULEB (fc->cfa_offset, start, end); |
c8071705 | 8909 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 8910 | if (! do_debug_frames_interp) |
c8071705 | 8911 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8912 | break; |
8913 | ||
8914 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 8915 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
8916 | if (do_debug_frames_interp) |
8917 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8918 | else | |
bf5117e3 NC |
8919 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
8920 | (unsigned long) (ofs * fc->code_factor), | |
8921 | dwarf_vmatoa_1 (NULL, | |
8922 | fc->pc_begin + ofs * fc->code_factor, | |
8923 | fc->ptr_size)); | |
19e6b90e L |
8924 | fc->pc_begin += ofs * fc->code_factor; |
8925 | break; | |
8926 | ||
8927 | case DW_CFA_GNU_window_save: | |
8928 | if (! do_debug_frames_interp) | |
8929 | printf (" DW_CFA_GNU_window_save\n"); | |
8930 | break; | |
8931 | ||
8932 | case DW_CFA_GNU_args_size: | |
cd30bcef | 8933 | READ_ULEB (ul, start, end); |
19e6b90e L |
8934 | if (! do_debug_frames_interp) |
8935 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
8936 | break; | |
8937 | ||
8938 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
8939 | READ_ULEB (reg, start, end); |
8940 | READ_SLEB (l, start, end); | |
7f2c8a1d | 8941 | l = - l; |
665ce1f6 L |
8942 | if (frame_need_space (fc, reg) < 0) |
8943 | reg_prefix = bad_reg; | |
8944 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8945 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
8946 | reg_prefix, regname (reg, 0), | |
c8071705 | 8947 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8948 | if (*reg_prefix == '\0') |
8949 | { | |
8950 | fc->col_type[reg] = DW_CFA_offset; | |
8951 | fc->col_offset[reg] = l * fc->data_factor; | |
8952 | } | |
19e6b90e L |
8953 | break; |
8954 | ||
8955 | default: | |
53b8873b NC |
8956 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
8957 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
8958 | else | |
f41e4712 | 8959 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
8960 | start = block_end; |
8961 | } | |
8962 | } | |
8963 | ||
5b6312fd NC |
8964 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
8965 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
8966 | frame_display_row (fc, &need_col_headers, &max_regs); |
8967 | ||
a788aedd AM |
8968 | if (fde_fc.col_type != NULL) |
8969 | { | |
8970 | free (fde_fc.col_type); | |
8971 | fde_fc.col_type = NULL; | |
8972 | } | |
8973 | if (fde_fc.col_offset != NULL) | |
8974 | { | |
8975 | free (fde_fc.col_offset); | |
8976 | fde_fc.col_offset = NULL; | |
8977 | } | |
8978 | ||
19e6b90e | 8979 | start = block_end; |
604282a7 | 8980 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
8981 | } |
8982 | ||
8983 | printf ("\n"); | |
8984 | ||
3391569f NC |
8985 | while (remembered_state != NULL) |
8986 | { | |
8987 | rs = remembered_state; | |
8988 | remembered_state = rs->next; | |
8989 | free (rs->col_type); | |
8990 | free (rs->col_offset); | |
8991 | rs->next = NULL; /* Paranoia. */ | |
8992 | free (rs); | |
8993 | } | |
8994 | ||
8995 | while (chunks != NULL) | |
8996 | { | |
8997 | rs = chunks; | |
8998 | chunks = rs->next; | |
8999 | free (rs->col_type); | |
9000 | free (rs->col_offset); | |
9001 | rs->next = NULL; /* Paranoia. */ | |
9002 | free (rs); | |
9003 | } | |
9004 | ||
9005 | while (forward_refs != NULL) | |
9006 | { | |
9007 | rs = forward_refs; | |
9008 | forward_refs = rs->next; | |
9009 | free (rs->col_type); | |
9010 | free (rs->col_offset); | |
9011 | rs->next = NULL; /* Paranoia. */ | |
9012 | free (rs); | |
9013 | } | |
9014 | ||
19e6b90e L |
9015 | return 1; |
9016 | } | |
9017 | ||
9018 | #undef GET | |
19e6b90e | 9019 | |
61364358 JK |
9020 | static int |
9021 | display_debug_names (struct dwarf_section *section, void *file) | |
9022 | { | |
9023 | unsigned char *hdrptr = section->start; | |
9024 | dwarf_vma unit_length; | |
9025 | unsigned char *unit_start; | |
9026 | const unsigned char *const section_end = section->start + section->size; | |
9027 | unsigned char *unit_end; | |
9028 | ||
dda8d76d | 9029 | introduce (section, FALSE); |
61364358 | 9030 | |
dda8d76d | 9031 | load_debug_section_with_follow (str, file); |
61364358 JK |
9032 | |
9033 | for (; hdrptr < section_end; hdrptr = unit_end) | |
9034 | { | |
9035 | unsigned int offset_size; | |
9036 | uint16_t dwarf_version, padding; | |
9037 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
9038 | uint32_t bucket_count, name_count, abbrev_table_size; | |
9039 | uint32_t augmentation_string_size; | |
9040 | unsigned int i; | |
e98fdf1a | 9041 | unsigned long sec_off; |
48467cb9 TV |
9042 | bfd_boolean augmentation_printable; |
9043 | const char *augmentation_string; | |
61364358 JK |
9044 | |
9045 | unit_start = hdrptr; | |
9046 | ||
9047 | /* Get and check the length of the block. */ | |
9048 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
9049 | ||
9050 | if (unit_length == 0xffffffff) | |
9051 | { | |
9052 | /* This section is 64-bit DWARF. */ | |
9053 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
9054 | offset_size = 8; | |
9055 | } | |
9056 | else | |
9057 | offset_size = 4; | |
9058 | unit_end = hdrptr + unit_length; | |
9059 | ||
e98fdf1a AM |
9060 | sec_off = hdrptr - section->start; |
9061 | if (sec_off + unit_length < sec_off | |
9062 | || sec_off + unit_length > section->size) | |
61364358 | 9063 | { |
e98fdf1a AM |
9064 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
9065 | section->name, | |
9066 | (unsigned long) (unit_start - section->start), | |
9067 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
9068 | return 0; |
9069 | } | |
9070 | ||
9071 | /* Get and check the version number. */ | |
9072 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
9073 | printf (_("Version %ld\n"), (long) dwarf_version); | |
9074 | ||
9075 | /* Prior versions did not exist, and future versions may not be | |
9076 | backwards compatible. */ | |
9077 | if (dwarf_version != 5) | |
9078 | { | |
9079 | warn (_("Only DWARF version 5 .debug_names " | |
9080 | "is currently supported.\n")); | |
9081 | return 0; | |
9082 | } | |
9083 | ||
9084 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
9085 | if (padding != 0) | |
9086 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
9087 | padding); | |
9088 | ||
9089 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
9090 | if (comp_unit_count == 0) | |
9091 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
9092 | ||
9093 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
9094 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
9095 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
9096 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
9097 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
9098 | ||
9099 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
9100 | if (augmentation_string_size % 4 != 0) | |
9101 | { | |
9102 | warn (_("Augmentation string length %u must be rounded up " | |
9103 | "to a multiple of 4 in .debug_names.\n"), | |
9104 | augmentation_string_size); | |
9105 | augmentation_string_size += (-augmentation_string_size) & 3; | |
9106 | } | |
48467cb9 | 9107 | |
61364358 | 9108 | printf (_("Augmentation string:")); |
48467cb9 TV |
9109 | |
9110 | augmentation_printable = TRUE; | |
9111 | augmentation_string = (const char *) hdrptr; | |
9112 | ||
61364358 JK |
9113 | for (i = 0; i < augmentation_string_size; i++) |
9114 | { | |
9115 | unsigned char uc; | |
9116 | ||
9117 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
9118 | printf (" %02x", uc); | |
48467cb9 TV |
9119 | |
9120 | if (uc != 0 && !ISPRINT (uc)) | |
9121 | augmentation_printable = FALSE; | |
9122 | } | |
9123 | ||
9124 | if (augmentation_printable) | |
9125 | { | |
9126 | printf (" (\""); | |
9127 | for (i = 0; | |
9128 | i < augmentation_string_size && augmentation_string[i]; | |
9129 | ++i) | |
9130 | putchar (augmentation_string[i]); | |
9131 | printf ("\")"); | |
61364358 | 9132 | } |
61364358 JK |
9133 | putchar ('\n'); |
9134 | ||
9135 | printf (_("CU table:\n")); | |
9136 | for (i = 0; i < comp_unit_count; i++) | |
9137 | { | |
9138 | uint64_t cu_offset; | |
9139 | ||
9140 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
9141 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
9142 | } | |
9143 | putchar ('\n'); | |
9144 | ||
9145 | printf (_("TU table:\n")); | |
9146 | for (i = 0; i < local_type_unit_count; i++) | |
9147 | { | |
9148 | uint64_t tu_offset; | |
9149 | ||
9150 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
9151 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
9152 | } | |
9153 | putchar ('\n'); | |
9154 | ||
9155 | printf (_("Foreign TU table:\n")); | |
9156 | for (i = 0; i < foreign_type_unit_count; i++) | |
9157 | { | |
9158 | uint64_t signature; | |
9159 | ||
9160 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
9161 | printf (_("[%3u] "), i); | |
9162 | print_dwarf_vma (signature, 8); | |
9163 | putchar ('\n'); | |
9164 | } | |
9165 | putchar ('\n'); | |
9166 | ||
9167 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
9168 | hdrptr += bucket_count * sizeof (uint32_t); | |
9169 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
9170 | hdrptr += name_count * sizeof (uint32_t); | |
9171 | unsigned char *const name_table_string_offsets = hdrptr; | |
9172 | hdrptr += name_count * offset_size; | |
9173 | unsigned char *const name_table_entry_offsets = hdrptr; | |
9174 | hdrptr += name_count * offset_size; | |
9175 | unsigned char *const abbrev_table = hdrptr; | |
9176 | hdrptr += abbrev_table_size; | |
9177 | const unsigned char *const abbrev_table_end = hdrptr; | |
9178 | unsigned char *const entry_pool = hdrptr; | |
9179 | if (hdrptr > unit_end) | |
9180 | { | |
9181 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
9182 | "for unit 0x%lx in the debug_names\n"), | |
9183 | (long) (hdrptr - section->start), | |
9184 | (long) (unit_end - section->start), | |
9185 | (long) (unit_start - section->start)); | |
9186 | return 0; | |
9187 | } | |
9188 | ||
9189 | size_t buckets_filled = 0; | |
9190 | size_t bucketi; | |
9191 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
9192 | { | |
9193 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
9194 | ||
9195 | if (bucket != 0) | |
9196 | ++buckets_filled; | |
9197 | } | |
d3a49aa8 AM |
9198 | printf (ngettext ("Used %zu of %lu bucket.\n", |
9199 | "Used %zu of %lu buckets.\n", | |
9200 | bucket_count), | |
9201 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 9202 | |
0a79bef4 | 9203 | uint32_t hash_prev = 0; |
61364358 JK |
9204 | size_t hash_clash_count = 0; |
9205 | size_t longest_clash = 0; | |
9206 | size_t this_length = 0; | |
9207 | size_t hashi; | |
9208 | for (hashi = 0; hashi < name_count; hashi++) | |
9209 | { | |
9210 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
9211 | ||
9212 | if (hashi > 0) | |
9213 | { | |
9214 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
9215 | { | |
9216 | ++hash_clash_count; | |
9217 | ++this_length; | |
9218 | longest_clash = MAX (longest_clash, this_length); | |
9219 | } | |
9220 | else | |
9221 | this_length = 0; | |
9222 | } | |
9223 | hash_prev = hash_this; | |
9224 | } | |
9225 | printf (_("Out of %lu items there are %zu bucket clashes" | |
9226 | " (longest of %zu entries).\n"), | |
9227 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
9228 | assert (name_count == buckets_filled + hash_clash_count); | |
9229 | ||
9230 | struct abbrev_lookup_entry | |
9231 | { | |
9232 | dwarf_vma abbrev_tag; | |
9233 | unsigned char *abbrev_lookup_ptr; | |
9234 | }; | |
9235 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
9236 | size_t abbrev_lookup_used = 0; | |
9237 | size_t abbrev_lookup_allocated = 0; | |
9238 | ||
9239 | unsigned char *abbrevptr = abbrev_table; | |
9240 | for (;;) | |
9241 | { | |
cd30bcef AM |
9242 | dwarf_vma abbrev_tag; |
9243 | ||
9244 | READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end); | |
61364358 JK |
9245 | if (abbrev_tag == 0) |
9246 | break; | |
9247 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
9248 | { | |
9249 | abbrev_lookup_allocated = MAX (0x100, | |
9250 | abbrev_lookup_allocated * 2); | |
9251 | abbrev_lookup = xrealloc (abbrev_lookup, | |
9252 | (abbrev_lookup_allocated | |
9253 | * sizeof (*abbrev_lookup))); | |
9254 | } | |
9255 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
9256 | struct abbrev_lookup_entry *entry; | |
9257 | for (entry = abbrev_lookup; | |
9258 | entry < abbrev_lookup + abbrev_lookup_used; | |
9259 | entry++) | |
9260 | if (entry->abbrev_tag == abbrev_tag) | |
9261 | { | |
9262 | warn (_("Duplicate abbreviation tag %lu " | |
9263 | "in unit 0x%lx in the debug_names\n"), | |
9264 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
9265 | break; | |
9266 | } | |
9267 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
9268 | entry->abbrev_tag = abbrev_tag; | |
9269 | entry->abbrev_lookup_ptr = abbrevptr; | |
9270 | ||
9271 | /* Skip DWARF tag. */ | |
cd30bcef | 9272 | SKIP_ULEB (abbrevptr, abbrev_table_end); |
61364358 JK |
9273 | for (;;) |
9274 | { | |
cd30bcef AM |
9275 | dwarf_vma xindex, form; |
9276 | ||
9277 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9278 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9279 | if (xindex == 0 && form == 0) |
61364358 JK |
9280 | break; |
9281 | } | |
9282 | } | |
9283 | ||
9284 | printf (_("\nSymbol table:\n")); | |
9285 | uint32_t namei; | |
9286 | for (namei = 0; namei < name_count; ++namei) | |
9287 | { | |
9288 | uint64_t string_offset, entry_offset; | |
9289 | ||
9290 | SAFE_BYTE_GET (string_offset, | |
9291 | name_table_string_offsets + namei * offset_size, | |
9292 | offset_size, unit_end); | |
9293 | SAFE_BYTE_GET (entry_offset, | |
9294 | name_table_entry_offsets + namei * offset_size, | |
9295 | offset_size, unit_end); | |
9296 | ||
9297 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
9298 | fetch_indirect_string (string_offset)); | |
9299 | ||
9300 | unsigned char *entryptr = entry_pool + entry_offset; | |
9301 | ||
279edac5 AM |
9302 | /* We need to scan first whether there is a single or multiple |
9303 | entries. TAGNO is -2 for the first entry, it is -1 for the | |
9304 | initial tag read of the second entry, then it becomes 0 for the | |
9305 | first entry for real printing etc. */ | |
61364358 JK |
9306 | int tagno = -2; |
9307 | /* Initialize it due to a false compiler warning. */ | |
9308 | dwarf_vma second_abbrev_tag = -1; | |
9309 | for (;;) | |
9310 | { | |
cd30bcef AM |
9311 | dwarf_vma abbrev_tag; |
9312 | dwarf_vma dwarf_tag; | |
9313 | const struct abbrev_lookup_entry *entry; | |
9314 | ||
9315 | READ_ULEB (abbrev_tag, entryptr, unit_end); | |
61364358 JK |
9316 | if (tagno == -1) |
9317 | { | |
9318 | second_abbrev_tag = abbrev_tag; | |
9319 | tagno = 0; | |
9320 | entryptr = entry_pool + entry_offset; | |
9321 | continue; | |
9322 | } | |
9323 | if (abbrev_tag == 0) | |
9324 | break; | |
9325 | if (tagno >= 0) | |
9326 | printf ("%s<%lu>", | |
9327 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
9328 | (unsigned long) abbrev_tag); | |
9329 | ||
61364358 JK |
9330 | for (entry = abbrev_lookup; |
9331 | entry < abbrev_lookup + abbrev_lookup_used; | |
9332 | entry++) | |
9333 | if (entry->abbrev_tag == abbrev_tag) | |
9334 | break; | |
9335 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
9336 | { | |
9337 | warn (_("Undefined abbreviation tag %lu " | |
9338 | "in unit 0x%lx in the debug_names\n"), | |
9339 | (long) abbrev_tag, | |
9340 | (long) (unit_start - section->start)); | |
9341 | break; | |
9342 | } | |
9343 | abbrevptr = entry->abbrev_lookup_ptr; | |
cd30bcef | 9344 | READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end); |
61364358 JK |
9345 | if (tagno >= 0) |
9346 | printf (" %s", get_TAG_name (dwarf_tag)); | |
9347 | for (;;) | |
9348 | { | |
cd30bcef AM |
9349 | dwarf_vma xindex, form; |
9350 | ||
9351 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9352 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9353 | if (xindex == 0 && form == 0) |
61364358 JK |
9354 | break; |
9355 | ||
9356 | if (tagno >= 0) | |
1d827a72 | 9357 | printf (" %s", get_IDX_name (xindex)); |
ec1b0fbb NC |
9358 | entryptr = read_and_display_attr_value (0, form, 0, |
9359 | unit_start, entryptr, unit_end, | |
9360 | 0, 0, offset_size, | |
61364358 JK |
9361 | dwarf_version, NULL, |
9362 | (tagno < 0), NULL, | |
ec1b0fbb | 9363 | NULL, '=', -1); |
61364358 JK |
9364 | } |
9365 | ++tagno; | |
9366 | } | |
9367 | if (tagno <= 0) | |
9368 | printf (_(" <no entries>")); | |
9369 | putchar ('\n'); | |
9370 | } | |
9371 | ||
9372 | free (abbrev_lookup); | |
9373 | } | |
9374 | ||
9375 | return 1; | |
9376 | } | |
9377 | ||
dda8d76d | 9378 | static int |
d85bf2ba NC |
9379 | display_debug_links (struct dwarf_section * section, |
9380 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
9381 | { |
9382 | const unsigned char * filename; | |
9383 | unsigned int filelen; | |
9384 | ||
9385 | introduce (section, FALSE); | |
9386 | ||
9387 | /* The .gnu_debuglink section is formatted as: | |
9388 | (c-string) Filename. | |
9389 | (padding) If needed to reach a 4 byte boundary. | |
9390 | (uint32_t) CRC32 value. | |
9391 | ||
9392 | The .gun_debugaltlink section is formatted as: | |
9393 | (c-string) Filename. | |
9394 | (binary) Build-ID. */ | |
9395 | ||
9396 | filename = section->start; | |
9397 | filelen = strnlen ((const char *) filename, section->size); | |
9398 | if (filelen == section->size) | |
9399 | { | |
9400 | warn (_("The debuglink filename is corrupt/missing\n")); | |
9401 | return 0; | |
9402 | } | |
9403 | ||
9404 | printf (_(" Separate debug info file: %s\n"), filename); | |
9405 | ||
9406 | if (const_strneq (section->name, ".gnu_debuglink")) | |
9407 | { | |
9408 | unsigned int crc32; | |
9409 | unsigned int crc_offset; | |
9410 | ||
9411 | crc_offset = filelen + 1; | |
9412 | crc_offset = (crc_offset + 3) & ~3; | |
9413 | if (crc_offset + 4 > section->size) | |
9414 | { | |
9415 | warn (_("CRC offset missing/truncated\n")); | |
9416 | return 0; | |
9417 | } | |
9418 | ||
9419 | crc32 = byte_get (filename + crc_offset, 4); | |
9420 | ||
9421 | printf (_(" CRC value: %#x\n"), crc32); | |
9422 | ||
9423 | if (crc_offset + 4 < section->size) | |
9424 | { | |
9425 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
9426 | (long)(section->size - (crc_offset + 4))); | |
9427 | return 0; | |
9428 | } | |
9429 | } | |
9430 | else /* const_strneq (section->name, ".gnu_debugaltlink") */ | |
9431 | { | |
9432 | const unsigned char * build_id = section->start + filelen + 1; | |
9433 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
9434 | bfd_size_type printed; | |
9435 | ||
9436 | /* FIXME: Should we support smaller build-id notes ? */ | |
9437 | if (build_id_len < 0x14) | |
9438 | { | |
9439 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
9440 | return 0; | |
9441 | } | |
9442 | ||
9443 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 9444 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
9445 | putchar ('\n'); |
9446 | } | |
9447 | ||
9448 | putchar ('\n'); | |
9449 | return 1; | |
9450 | } | |
9451 | ||
5bbdf3d5 DE |
9452 | static int |
9453 | display_gdb_index (struct dwarf_section *section, | |
9454 | void *file ATTRIBUTE_UNUSED) | |
9455 | { | |
9456 | unsigned char *start = section->start; | |
9457 | uint32_t version; | |
9458 | uint32_t cu_list_offset, tu_list_offset; | |
9459 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
9460 | unsigned int cu_list_elements, tu_list_elements; | |
9461 | unsigned int address_table_size, symbol_table_slots; | |
9462 | unsigned char *cu_list, *tu_list; | |
9463 | unsigned char *address_table, *symbol_table, *constant_pool; | |
9464 | unsigned int i; | |
9465 | ||
9466 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
9467 | ||
dda8d76d | 9468 | introduce (section, FALSE); |
5bbdf3d5 DE |
9469 | |
9470 | if (section->size < 6 * sizeof (uint32_t)) | |
9471 | { | |
9472 | warn (_("Truncated header in the %s section.\n"), section->name); | |
9473 | return 0; | |
9474 | } | |
9475 | ||
9476 | version = byte_get_little_endian (start, 4); | |
da88a764 | 9477 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
9478 | |
9479 | /* Prior versions are obsolete, and future versions may not be | |
9480 | backwards compatible. */ | |
aa170720 | 9481 | if (version < 3 || version > 8) |
5bbdf3d5 | 9482 | { |
da88a764 | 9483 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
9484 | return 0; |
9485 | } | |
8d6eee87 TT |
9486 | if (version < 4) |
9487 | warn (_("The address table data in version 3 may be wrong.\n")); | |
9488 | if (version < 5) | |
9489 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
9490 | if (version < 6) | |
9491 | warn (_("Version 5 does not include inlined functions.\n")); | |
9492 | if (version < 7) | |
9493 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
9494 | /* Version 7 indices generated by Gold have bad type unit references, |
9495 | PR binutils/15021. But we don't know if the index was generated by | |
9496 | Gold or not, so to avoid worrying users with gdb-generated indices | |
9497 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
9498 | |
9499 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
9500 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
9501 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
9502 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
9503 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
9504 | ||
9505 | if (cu_list_offset > section->size | |
9506 | || tu_list_offset > section->size | |
9507 | || address_table_offset > section->size | |
9508 | || symbol_table_offset > section->size | |
9509 | || constant_pool_offset > section->size) | |
9510 | { | |
9511 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
9512 | return 0; | |
9513 | } | |
9514 | ||
53774b7e NC |
9515 | /* PR 17531: file: 418d0a8a. */ |
9516 | if (tu_list_offset < cu_list_offset) | |
9517 | { | |
9518 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
9519 | tu_list_offset, cu_list_offset); | |
9520 | return 0; | |
9521 | } | |
9522 | ||
5bbdf3d5 | 9523 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
9524 | |
9525 | if (address_table_offset < tu_list_offset) | |
9526 | { | |
9527 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
9528 | address_table_offset, tu_list_offset); | |
9529 | return 0; | |
9530 | } | |
9531 | ||
5bbdf3d5 | 9532 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
9533 | |
9534 | /* PR 17531: file: 18a47d3d. */ | |
9535 | if (symbol_table_offset < address_table_offset) | |
9536 | { | |
13bace4a | 9537 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
9538 | symbol_table_offset, address_table_offset); |
9539 | return 0; | |
9540 | } | |
9541 | ||
5bbdf3d5 | 9542 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
9543 | |
9544 | if (constant_pool_offset < symbol_table_offset) | |
9545 | { | |
9546 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
9547 | constant_pool_offset, symbol_table_offset); | |
9548 | return 0; | |
9549 | } | |
9550 | ||
5bbdf3d5 DE |
9551 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
9552 | ||
9553 | cu_list = start + cu_list_offset; | |
9554 | tu_list = start + tu_list_offset; | |
9555 | address_table = start + address_table_offset; | |
9556 | symbol_table = start + symbol_table_offset; | |
9557 | constant_pool = start + constant_pool_offset; | |
9558 | ||
28d909e5 | 9559 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 9560 | { |
1306a742 | 9561 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
9562 | return 0; |
9563 | } | |
b4eb7656 | 9564 | |
5bbdf3d5 DE |
9565 | printf (_("\nCU table:\n")); |
9566 | for (i = 0; i < cu_list_elements; i += 2) | |
9567 | { | |
9568 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
9569 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
9570 | ||
9571 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
9572 | (unsigned long) cu_offset, | |
9573 | (unsigned long) (cu_offset + cu_length - 1)); | |
9574 | } | |
9575 | ||
9576 | printf (_("\nTU table:\n")); | |
9577 | for (i = 0; i < tu_list_elements; i += 3) | |
9578 | { | |
9579 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
9580 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
9581 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
9582 | ||
9583 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
9584 | (unsigned long) tu_offset, | |
9585 | (unsigned long) type_offset); | |
9586 | print_dwarf_vma (signature, 8); | |
9587 | printf ("\n"); | |
9588 | } | |
9589 | ||
9590 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
9591 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
9592 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
9593 | { |
9594 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
9595 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
9596 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
9597 | ||
9598 | print_dwarf_vma (low, 8); | |
9599 | print_dwarf_vma (high, 8); | |
da88a764 | 9600 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
9601 | } |
9602 | ||
9603 | printf (_("\nSymbol table:\n")); | |
9604 | for (i = 0; i < symbol_table_slots; ++i) | |
9605 | { | |
9606 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
9607 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
9608 | uint32_t num_cus, cu; | |
9609 | ||
9610 | if (name_offset != 0 | |
9611 | || cu_vector_offset != 0) | |
9612 | { | |
9613 | unsigned int j; | |
362beea4 | 9614 | unsigned char * adr; |
5bbdf3d5 | 9615 | |
362beea4 | 9616 | adr = constant_pool + name_offset; |
53774b7e | 9617 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 9618 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
9619 | { |
9620 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
9621 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
9622 | name_offset, i); | |
9623 | } | |
9624 | else | |
acff9664 NC |
9625 | printf ("[%3u] %.*s:", i, |
9626 | (int) (section->size - (constant_pool_offset + name_offset)), | |
9627 | constant_pool + name_offset); | |
53774b7e | 9628 | |
362beea4 NC |
9629 | adr = constant_pool + cu_vector_offset; |
9630 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
9631 | { |
9632 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
9633 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
9634 | cu_vector_offset, i); | |
9635 | continue; | |
9636 | } | |
57028622 | 9637 | |
362beea4 | 9638 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 9639 | |
362beea4 | 9640 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 9641 | if (num_cus * 4 < num_cus |
362beea4 NC |
9642 | || adr >= section->start + section->size |
9643 | || adr < constant_pool) | |
53774b7e NC |
9644 | { |
9645 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 9646 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
9647 | num_cus, i); |
9648 | continue; | |
9649 | } | |
9650 | ||
8d6eee87 TT |
9651 | if (num_cus > 1) |
9652 | printf ("\n"); | |
f3853b34 | 9653 | |
5bbdf3d5 DE |
9654 | for (j = 0; j < num_cus; ++j) |
9655 | { | |
7c1cef97 | 9656 | int is_static; |
8d6eee87 TT |
9657 | gdb_index_symbol_kind kind; |
9658 | ||
5bbdf3d5 | 9659 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 9660 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
9661 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
9662 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 9663 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 9664 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
9665 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
9666 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 9667 | else |
8d6eee87 TT |
9668 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
9669 | ||
459d52c8 DE |
9670 | printf (" [%s, %s]", |
9671 | is_static ? _("static") : _("global"), | |
9672 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
9673 | if (num_cus > 1) |
9674 | printf ("\n"); | |
5bbdf3d5 | 9675 | } |
8d6eee87 TT |
9676 | if (num_cus <= 1) |
9677 | printf ("\n"); | |
5bbdf3d5 DE |
9678 | } |
9679 | } | |
9680 | ||
9681 | return 1; | |
9682 | } | |
9683 | ||
657d0d47 CC |
9684 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
9685 | ||
9686 | static void | |
9687 | prealloc_cu_tu_list (unsigned int nshndx) | |
9688 | { | |
9689 | if (shndx_pool == NULL) | |
9690 | { | |
9691 | shndx_pool_size = nshndx; | |
9692 | shndx_pool_used = 0; | |
9693 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
9694 | sizeof (unsigned int)); | |
9695 | } | |
9696 | else | |
9697 | { | |
9698 | shndx_pool_size = shndx_pool_used + nshndx; | |
9699 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
9700 | sizeof (unsigned int)); | |
9701 | } | |
9702 | } | |
9703 | ||
9704 | static void | |
9705 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
9706 | { | |
9707 | if (shndx_pool_used >= shndx_pool_size) | |
9708 | { | |
9709 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9710 | return; | |
9711 | } | |
9712 | shndx_pool [shndx_pool_used++] = shndx; | |
9713 | } | |
9714 | ||
9715 | static void | |
9716 | end_cu_tu_entry (void) | |
9717 | { | |
9718 | if (shndx_pool_used >= shndx_pool_size) | |
9719 | { | |
9720 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9721 | return; | |
9722 | } | |
9723 | shndx_pool [shndx_pool_used++] = 0; | |
9724 | } | |
9725 | ||
341f9135 CC |
9726 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
9727 | ||
9728 | static const char * | |
9729 | get_DW_SECT_short_name (unsigned int dw_sect) | |
9730 | { | |
9731 | static char buf[16]; | |
9732 | ||
9733 | switch (dw_sect) | |
9734 | { | |
9735 | case DW_SECT_INFO: | |
9736 | return "info"; | |
9737 | case DW_SECT_TYPES: | |
9738 | return "types"; | |
9739 | case DW_SECT_ABBREV: | |
9740 | return "abbrev"; | |
9741 | case DW_SECT_LINE: | |
9742 | return "line"; | |
9743 | case DW_SECT_LOC: | |
9744 | return "loc"; | |
9745 | case DW_SECT_STR_OFFSETS: | |
9746 | return "str_off"; | |
9747 | case DW_SECT_MACINFO: | |
9748 | return "macinfo"; | |
9749 | case DW_SECT_MACRO: | |
9750 | return "macro"; | |
9751 | default: | |
b4eb7656 | 9752 | break; |
341f9135 CC |
9753 | } |
9754 | ||
9755 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
9756 | return buf; | |
9757 | } | |
9758 | ||
9759 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
9760 | These sections are extensions for Fission. | |
9761 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
9762 | |
9763 | static int | |
9764 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
9765 | { | |
9766 | unsigned char *phdr = section->start; | |
9767 | unsigned char *limit = phdr + section->size; | |
9768 | unsigned char *phash; | |
9769 | unsigned char *pindex; | |
9770 | unsigned char *ppool; | |
9771 | unsigned int version; | |
341f9135 | 9772 | unsigned int ncols = 0; |
657d0d47 CC |
9773 | unsigned int nused; |
9774 | unsigned int nslots; | |
9775 | unsigned int i; | |
341f9135 CC |
9776 | unsigned int j; |
9777 | dwarf_vma signature_high; | |
9778 | dwarf_vma signature_low; | |
9779 | char buf[64]; | |
657d0d47 | 9780 | |
6937bb54 NC |
9781 | /* PR 17512: file: 002-168123-0.004. */ |
9782 | if (phdr == NULL) | |
9783 | { | |
9784 | warn (_("Section %s is empty\n"), section->name); | |
9785 | return 0; | |
9786 | } | |
9787 | /* PR 17512: file: 002-376-0.004. */ | |
9788 | if (section->size < 24) | |
9789 | { | |
72c61a0d | 9790 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
9791 | section->name); |
9792 | return 0; | |
9793 | } | |
9794 | ||
9795 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 9796 | if (version >= 2) |
6937bb54 NC |
9797 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
9798 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
9799 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
9800 | ||
657d0d47 | 9801 | phash = phdr + 16; |
8e2e3c6c AM |
9802 | pindex = phash + (size_t) nslots * 8; |
9803 | ppool = pindex + (size_t) nslots * 4; | |
57028622 | 9804 | |
657d0d47 CC |
9805 | if (do_display) |
9806 | { | |
dda8d76d NC |
9807 | introduce (section, FALSE); |
9808 | ||
8e2e3c6c | 9809 | printf (_(" Version: %u\n"), version); |
341f9135 | 9810 | if (version >= 2) |
8e2e3c6c AM |
9811 | printf (_(" Number of columns: %u\n"), ncols); |
9812 | printf (_(" Number of used entries: %u\n"), nused); | |
9813 | printf (_(" Number of slots: %u\n\n"), nslots); | |
657d0d47 CC |
9814 | } |
9815 | ||
8e2e3c6c AM |
9816 | /* PR 17531: file: 45d69832. */ |
9817 | if ((size_t) nslots * 8 / 8 != nslots | |
9818 | || phash < phdr || phash > limit | |
9819 | || pindex < phash || pindex > limit | |
9820 | || ppool < pindex || ppool > limit) | |
657d0d47 | 9821 | { |
8e2e3c6c AM |
9822 | warn (ngettext ("Section %s is too small for %u slot\n", |
9823 | "Section %s is too small for %u slots\n", | |
9824 | nslots), | |
657d0d47 CC |
9825 | section->name, nslots); |
9826 | return 0; | |
9827 | } | |
9828 | ||
341f9135 | 9829 | if (version == 1) |
657d0d47 | 9830 | { |
341f9135 CC |
9831 | if (!do_display) |
9832 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
9833 | for (i = 0; i < nslots; i++) | |
657d0d47 | 9834 | { |
341f9135 CC |
9835 | unsigned char *shndx_list; |
9836 | unsigned int shndx; | |
9837 | ||
6937bb54 | 9838 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 9839 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 9840 | { |
6937bb54 | 9841 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 9842 | shndx_list = ppool + j * 4; |
f3853b34 NC |
9843 | /* PR 17531: file: 705e010d. */ |
9844 | if (shndx_list < ppool) | |
9845 | { | |
9846 | warn (_("Section index pool located before start of section\n")); | |
9847 | return 0; | |
9848 | } | |
9849 | ||
341f9135 CC |
9850 | if (do_display) |
9851 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
9852 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9853 | buf, sizeof (buf))); | |
9854 | for (;;) | |
657d0d47 | 9855 | { |
341f9135 CC |
9856 | if (shndx_list >= limit) |
9857 | { | |
9858 | warn (_("Section %s too small for shndx pool\n"), | |
9859 | section->name); | |
9860 | return 0; | |
9861 | } | |
6937bb54 | 9862 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
9863 | if (shndx == 0) |
9864 | break; | |
9865 | if (do_display) | |
9866 | printf (" %d", shndx); | |
9867 | else | |
9868 | add_shndx_to_cu_tu_entry (shndx); | |
9869 | shndx_list += 4; | |
657d0d47 | 9870 | } |
657d0d47 | 9871 | if (do_display) |
341f9135 | 9872 | printf ("\n"); |
657d0d47 | 9873 | else |
341f9135 CC |
9874 | end_cu_tu_entry (); |
9875 | } | |
9876 | phash += 8; | |
9877 | pindex += 4; | |
9878 | } | |
9879 | } | |
9880 | else if (version == 2) | |
9881 | { | |
9882 | unsigned int val; | |
9883 | unsigned int dw_sect; | |
9884 | unsigned char *ph = phash; | |
9885 | unsigned char *pi = pindex; | |
8e2e3c6c AM |
9886 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
9887 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
9888 | unsigned char *pend = psizes + (size_t) nused * ncols * 4; | |
341f9135 CC |
9889 | bfd_boolean is_tu_index; |
9890 | struct cu_tu_set *this_set = NULL; | |
9891 | unsigned int row; | |
9892 | unsigned char *prow; | |
9893 | ||
9894 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
9895 | ||
362beea4 | 9896 | /* PR 17531: file: 0dd159bf. |
8e2e3c6c AM |
9897 | Check for integer overflow (can occur when size_t is 32-bit) |
9898 | with overlarge ncols or nused values. */ | |
4ac948a0 NC |
9899 | if (ncols > 0 |
9900 | && ((size_t) ncols * 4 / 4 != ncols | |
9901 | || (size_t) nused * ncols * 4 / ((size_t) ncols * 4) != nused | |
9902 | || poffsets < ppool || poffsets > limit | |
9903 | || psizes < poffsets || psizes > limit | |
9904 | || pend < psizes || pend > limit)) | |
341f9135 CC |
9905 | { |
9906 | warn (_("Section %s too small for offset and size tables\n"), | |
9907 | section->name); | |
9908 | return 0; | |
9909 | } | |
9910 | ||
9911 | if (do_display) | |
9912 | { | |
9913 | printf (_(" Offset table\n")); | |
9914 | printf (" slot %-16s ", | |
9915 | is_tu_index ? _("signature") : _("dwo_id")); | |
9916 | } | |
9917 | else | |
9918 | { | |
9919 | if (is_tu_index) | |
9920 | { | |
9921 | tu_count = nused; | |
72c61a0d | 9922 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 9923 | this_set = tu_sets; |
657d0d47 | 9924 | } |
657d0d47 | 9925 | else |
341f9135 CC |
9926 | { |
9927 | cu_count = nused; | |
72c61a0d | 9928 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
9929 | this_set = cu_sets; |
9930 | } | |
9931 | } | |
6937bb54 | 9932 | |
341f9135 CC |
9933 | if (do_display) |
9934 | { | |
9935 | for (j = 0; j < ncols; j++) | |
9936 | { | |
6937bb54 | 9937 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
9938 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
9939 | } | |
9940 | printf ("\n"); | |
9941 | } | |
6937bb54 | 9942 | |
341f9135 CC |
9943 | for (i = 0; i < nslots; i++) |
9944 | { | |
6937bb54 NC |
9945 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9946 | ||
9947 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9948 | if (row != 0) |
9949 | { | |
591f7597 | 9950 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 9951 | if (row > nused) |
591f7597 NC |
9952 | { |
9953 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
9954 | row, nused); | |
9955 | return 0; | |
9956 | } | |
9957 | ||
341f9135 | 9958 | if (!do_display) |
6aea08d9 NC |
9959 | { |
9960 | size_t num_copy = sizeof (uint64_t); | |
9961 | ||
9962 | /* PR 23064: Beware of buffer overflow. */ | |
9963 | if (ph + num_copy < limit) | |
9964 | memcpy (&this_set[row - 1].signature, ph, num_copy); | |
9965 | else | |
9966 | { | |
9967 | warn (_("Signature (%p) extends beyond end of space in section\n"), ph); | |
9968 | return 0; | |
9969 | } | |
9970 | } | |
6937bb54 | 9971 | |
341f9135 | 9972 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
9973 | /* PR 17531: file: b8ce60a8. */ |
9974 | if (prow < poffsets || prow > limit) | |
9975 | { | |
9976 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
9977 | row, ncols); | |
9978 | return 0; | |
9979 | } | |
3aade688 | 9980 | |
341f9135 CC |
9981 | if (do_display) |
9982 | printf (_(" [%3d] 0x%s"), | |
9983 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9984 | buf, sizeof (buf))); | |
9985 | for (j = 0; j < ncols; j++) | |
9986 | { | |
6937bb54 | 9987 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
9988 | if (do_display) |
9989 | printf (" %8d", val); | |
9990 | else | |
9991 | { | |
6937bb54 | 9992 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
9993 | |
9994 | /* PR 17531: file: 10796eb3. */ | |
9995 | if (dw_sect >= DW_SECT_MAX) | |
9996 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
9997 | else | |
9998 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
9999 | } |
10000 | } | |
6937bb54 | 10001 | |
341f9135 CC |
10002 | if (do_display) |
10003 | printf ("\n"); | |
10004 | } | |
10005 | ph += 8; | |
10006 | pi += 4; | |
10007 | } | |
10008 | ||
10009 | ph = phash; | |
10010 | pi = pindex; | |
10011 | if (do_display) | |
b4eb7656 | 10012 | { |
341f9135 CC |
10013 | printf ("\n"); |
10014 | printf (_(" Size table\n")); | |
10015 | printf (" slot %-16s ", | |
10016 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 10017 | } |
6937bb54 | 10018 | |
341f9135 CC |
10019 | for (j = 0; j < ncols; j++) |
10020 | { | |
6937bb54 | 10021 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
10022 | if (do_display) |
10023 | printf (" %8s", get_DW_SECT_short_name (val)); | |
10024 | } | |
6937bb54 | 10025 | |
341f9135 CC |
10026 | if (do_display) |
10027 | printf ("\n"); | |
6937bb54 | 10028 | |
341f9135 CC |
10029 | for (i = 0; i < nslots; i++) |
10030 | { | |
6937bb54 NC |
10031 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
10032 | ||
10033 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10034 | if (row != 0) |
10035 | { | |
10036 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 10037 | |
341f9135 CC |
10038 | if (do_display) |
10039 | printf (_(" [%3d] 0x%s"), | |
10040 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10041 | buf, sizeof (buf))); | |
6937bb54 | 10042 | |
341f9135 CC |
10043 | for (j = 0; j < ncols; j++) |
10044 | { | |
6937bb54 | 10045 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
10046 | if (do_display) |
10047 | printf (" %8d", val); | |
10048 | else | |
10049 | { | |
6937bb54 | 10050 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
10051 | if (dw_sect >= DW_SECT_MAX) |
10052 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10053 | else | |
341f9135 CC |
10054 | this_set [row - 1].section_sizes [dw_sect] = val; |
10055 | } | |
10056 | } | |
6937bb54 | 10057 | |
341f9135 CC |
10058 | if (do_display) |
10059 | printf ("\n"); | |
10060 | } | |
6937bb54 | 10061 | |
341f9135 CC |
10062 | ph += 8; |
10063 | pi += 4; | |
657d0d47 | 10064 | } |
657d0d47 | 10065 | } |
341f9135 | 10066 | else if (do_display) |
6937bb54 | 10067 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
10068 | |
10069 | if (do_display) | |
10070 | printf ("\n"); | |
10071 | ||
10072 | return 1; | |
10073 | } | |
10074 | ||
10075 | /* Load the CU and TU indexes if present. This will build a list of | |
10076 | section sets that we can use to associate a .debug_info.dwo section | |
10077 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
10078 | ||
43a444f9 | 10079 | static bfd_boolean |
657d0d47 CC |
10080 | load_cu_tu_indexes (void *file) |
10081 | { | |
43a444f9 NC |
10082 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
10083 | ||
657d0d47 CC |
10084 | /* If we have already loaded (or tried to load) the CU and TU indexes |
10085 | then do not bother to repeat the task. */ | |
43a444f9 NC |
10086 | if (cu_tu_indexes_read == -1) |
10087 | { | |
10088 | cu_tu_indexes_read = TRUE; | |
10089 | ||
dda8d76d | 10090 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 NC |
10091 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
10092 | cu_tu_indexes_read = FALSE; | |
10093 | ||
dda8d76d | 10094 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 NC |
10095 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
10096 | cu_tu_indexes_read = FALSE; | |
10097 | } | |
657d0d47 | 10098 | |
43a444f9 | 10099 | return (bfd_boolean) cu_tu_indexes_read; |
657d0d47 CC |
10100 | } |
10101 | ||
10102 | /* Find the set of sections that includes section SHNDX. */ | |
10103 | ||
10104 | unsigned int * | |
10105 | find_cu_tu_set (void *file, unsigned int shndx) | |
10106 | { | |
10107 | unsigned int i; | |
10108 | ||
43a444f9 NC |
10109 | if (! load_cu_tu_indexes (file)) |
10110 | return NULL; | |
657d0d47 CC |
10111 | |
10112 | /* Find SHNDX in the shndx pool. */ | |
10113 | for (i = 0; i < shndx_pool_used; i++) | |
10114 | if (shndx_pool [i] == shndx) | |
10115 | break; | |
10116 | ||
10117 | if (i >= shndx_pool_used) | |
10118 | return NULL; | |
10119 | ||
10120 | /* Now backup to find the first entry in the set. */ | |
10121 | while (i > 0 && shndx_pool [i - 1] != 0) | |
10122 | i--; | |
10123 | ||
10124 | return shndx_pool + i; | |
10125 | } | |
10126 | ||
10127 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
10128 | ||
10129 | static int | |
10130 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
10131 | { | |
10132 | return process_cu_tu_index (section, 1); | |
10133 | } | |
10134 | ||
19e6b90e L |
10135 | static int |
10136 | display_debug_not_supported (struct dwarf_section *section, | |
10137 | void *file ATTRIBUTE_UNUSED) | |
10138 | { | |
10139 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
10140 | section->name); | |
10141 | ||
10142 | return 1; | |
10143 | } | |
10144 | ||
1306a742 NC |
10145 | /* Like malloc, but takes two parameters like calloc. |
10146 | Verifies that the first parameter is not too large. | |
82b1b41b | 10147 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 10148 | |
19e6b90e L |
10149 | void * |
10150 | cmalloc (size_t nmemb, size_t size) | |
10151 | { | |
10152 | /* Check for overflow. */ | |
10153 | if (nmemb >= ~(size_t) 0 / size) | |
10154 | return NULL; | |
82b1b41b NC |
10155 | |
10156 | return xmalloc (nmemb * size); | |
19e6b90e L |
10157 | } |
10158 | ||
1306a742 NC |
10159 | /* Like xmalloc, but takes two parameters like calloc. |
10160 | Verifies that the first parameter is not too large. | |
10161 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 10162 | |
72c61a0d | 10163 | void * |
1306a742 | 10164 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
10165 | { |
10166 | /* Check for overflow. */ | |
10167 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
10168 | { |
10169 | fprintf (stderr, | |
10170 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
10171 | (long) nmemb); | |
10172 | xexit (1); | |
10173 | } | |
72c61a0d | 10174 | |
1306a742 | 10175 | return xmalloc (nmemb * size); |
72c61a0d NC |
10176 | } |
10177 | ||
1306a742 NC |
10178 | /* Like xrealloc, but takes three parameters. |
10179 | Verifies that the second parameter is not too large. | |
10180 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 10181 | |
19e6b90e | 10182 | void * |
1306a742 | 10183 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
10184 | { |
10185 | /* Check for overflow. */ | |
10186 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10187 | { |
dda8d76d NC |
10188 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
10189 | (long) nmemb); | |
8490fb40 NC |
10190 | xexit (1); |
10191 | } | |
82b1b41b | 10192 | |
1306a742 | 10193 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
10194 | } |
10195 | ||
1306a742 | 10196 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 10197 | |
19e6b90e | 10198 | void * |
1306a742 | 10199 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
10200 | { |
10201 | /* Check for overflow. */ | |
10202 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10203 | { |
dda8d76d NC |
10204 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
10205 | (long) nmemb); | |
8490fb40 NC |
10206 | xexit (1); |
10207 | } | |
82b1b41b | 10208 | |
1306a742 | 10209 | return xcalloc (nmemb, size); |
19e6b90e L |
10210 | } |
10211 | ||
dda8d76d NC |
10212 | static unsigned long |
10213 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
10214 | const unsigned char * buf, | |
10215 | bfd_size_type len) | |
10216 | { | |
10217 | static const unsigned long crc32_table[256] = | |
10218 | { | |
10219 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
10220 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
10221 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
10222 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
10223 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
10224 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
10225 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
10226 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
10227 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
10228 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
10229 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
10230 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
10231 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
10232 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
10233 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
10234 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
10235 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
10236 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
10237 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
10238 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
10239 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
10240 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
10241 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
10242 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
10243 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
10244 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
10245 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
10246 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
10247 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
10248 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
10249 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
10250 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
10251 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
10252 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
10253 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
10254 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
10255 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
10256 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
10257 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
10258 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
10259 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
10260 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
10261 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
10262 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
10263 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
10264 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
10265 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
10266 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
10267 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
10268 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
10269 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
10270 | 0x2d02ef8d | |
10271 | }; | |
10272 | const unsigned char *end; | |
10273 | ||
10274 | crc = ~crc & 0xffffffff; | |
10275 | for (end = buf + len; buf < end; ++ buf) | |
10276 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
10277 | return ~crc & 0xffffffff; | |
10278 | } | |
10279 | ||
10280 | typedef bfd_boolean (* check_func_type) (const char *, void *); | |
10281 | typedef const char * (* parse_func_type) (struct dwarf_section *, void *); | |
10282 | ||
10283 | static bfd_boolean | |
10284 | check_gnu_debuglink (const char * pathname, void * crc_pointer) | |
10285 | { | |
10286 | static unsigned char buffer [8 * 1024]; | |
10287 | FILE * f; | |
10288 | bfd_size_type count; | |
10289 | unsigned long crc = 0; | |
10290 | void * sep_data; | |
10291 | ||
10292 | sep_data = open_debug_file (pathname); | |
10293 | if (sep_data == NULL) | |
10294 | return FALSE; | |
10295 | ||
10296 | /* Yes - we are opening the file twice... */ | |
10297 | f = fopen (pathname, "rb"); | |
10298 | if (f == NULL) | |
10299 | { | |
10300 | /* Paranoia: This should never happen. */ | |
10301 | close_debug_file (sep_data); | |
10302 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
10303 | return FALSE; | |
10304 | } | |
10305 | ||
10306 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
10307 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
10308 | ||
10309 | fclose (f); | |
10310 | ||
10311 | if (crc != * (unsigned long *) crc_pointer) | |
10312 | { | |
10313 | close_debug_file (sep_data); | |
10314 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
10315 | pathname); | |
10316 | return FALSE; | |
10317 | } | |
10318 | ||
10319 | return TRUE; | |
10320 | } | |
10321 | ||
10322 | static const char * | |
10323 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
10324 | { | |
10325 | const char * name; | |
10326 | unsigned int crc_offset; | |
10327 | unsigned long * crc32 = (unsigned long *) data; | |
10328 | ||
10329 | /* The name is first. | |
10330 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
10331 | name = (const char *) section->start; | |
10332 | ||
39f0547e | 10333 | |
dda8d76d NC |
10334 | crc_offset = strnlen (name, section->size) + 1; |
10335 | crc_offset = (crc_offset + 3) & ~3; | |
10336 | if (crc_offset + 4 > section->size) | |
10337 | return NULL; | |
10338 | ||
10339 | * crc32 = byte_get (section->start + crc_offset, 4); | |
10340 | return name; | |
10341 | } | |
10342 | ||
10343 | static bfd_boolean | |
10344 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) | |
10345 | { | |
10346 | void * sep_data = open_debug_file (filename); | |
10347 | ||
10348 | if (sep_data == NULL) | |
10349 | return FALSE; | |
10350 | ||
10351 | /* FIXME: We should now extract the build-id in the separate file | |
10352 | and check it... */ | |
10353 | ||
10354 | return TRUE; | |
10355 | } | |
10356 | ||
10357 | typedef struct build_id_data | |
10358 | { | |
10359 | bfd_size_type len; | |
10360 | const unsigned char * data; | |
10361 | } Build_id_data; | |
10362 | ||
10363 | static const char * | |
10364 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
10365 | { | |
10366 | const char * name; | |
10367 | bfd_size_type namelen; | |
10368 | bfd_size_type id_len; | |
10369 | Build_id_data * build_id_data; | |
10370 | ||
10371 | /* The name is first. | |
10372 | The build-id follows immediately, with no padding, up to the section's end. */ | |
10373 | ||
10374 | name = (const char *) section->start; | |
10375 | namelen = strnlen (name, section->size) + 1; | |
10376 | if (namelen >= section->size) | |
10377 | return NULL; | |
10378 | ||
10379 | id_len = section->size - namelen; | |
10380 | if (id_len < 0x14) | |
10381 | return NULL; | |
10382 | ||
dfbee680 | 10383 | build_id_data = (Build_id_data *) data; |
dda8d76d NC |
10384 | build_id_data->len = id_len; |
10385 | build_id_data->data = section->start + namelen; | |
10386 | ||
dda8d76d NC |
10387 | return name; |
10388 | } | |
10389 | ||
24841daa NC |
10390 | static void |
10391 | add_separate_debug_file (const char * filename, void * handle) | |
10392 | { | |
10393 | separate_info * i = xmalloc (sizeof * i); | |
10394 | ||
10395 | i->filename = filename; | |
10396 | i->handle = handle; | |
10397 | i->next = first_separate_info; | |
10398 | first_separate_info = i; | |
10399 | } | |
10400 | ||
301a9420 AM |
10401 | #if HAVE_LIBDEBUGINFOD |
10402 | /* Query debuginfod servers for the target debuglink or debugaltlink | |
10403 | file. If successful, store the path of the file in filename and | |
10404 | return TRUE, otherwise return FALSE. */ | |
10405 | ||
10406 | static bfd_boolean | |
10407 | debuginfod_fetch_separate_debug_info (struct dwarf_section * section, | |
10408 | char ** filename, | |
10409 | void * file) | |
10410 | { | |
10411 | size_t build_id_len; | |
10412 | unsigned char * build_id; | |
10413 | ||
10414 | if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0) | |
10415 | { | |
10416 | /* Get the build-id of file. */ | |
10417 | build_id = get_build_id (file); | |
10418 | build_id_len = 0; | |
10419 | } | |
10420 | else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0) | |
10421 | { | |
10422 | /* Get the build-id of the debugaltlink file. */ | |
10423 | unsigned int filelen; | |
10424 | ||
10425 | filelen = strnlen ((const char *)section->start, section->size); | |
10426 | if (filelen == section->size) | |
10427 | /* Corrupt debugaltlink. */ | |
10428 | return FALSE; | |
10429 | ||
10430 | build_id = section->start + filelen + 1; | |
10431 | build_id_len = section->size - (filelen + 1); | |
10432 | ||
10433 | if (build_id_len == 0) | |
10434 | return FALSE; | |
10435 | } | |
10436 | else | |
10437 | return FALSE; | |
10438 | ||
10439 | if (build_id) | |
10440 | { | |
10441 | int fd; | |
10442 | debuginfod_client * client; | |
10443 | ||
10444 | client = debuginfod_begin (); | |
10445 | if (client == NULL) | |
10446 | return FALSE; | |
10447 | ||
10448 | /* Query debuginfod servers for the target file. If found its path | |
10449 | will be stored in filename. */ | |
10450 | fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename); | |
10451 | debuginfod_end (client); | |
10452 | ||
10453 | /* Only free build_id if we allocated space for a hex string | |
10454 | in get_build_id (). */ | |
10455 | if (build_id_len == 0) | |
10456 | free (build_id); | |
10457 | ||
10458 | if (fd >= 0) | |
10459 | { | |
10460 | /* File successfully retrieved. Close fd since we want to | |
10461 | use open_debug_file () on filename instead. */ | |
10462 | close (fd); | |
10463 | return TRUE; | |
10464 | } | |
10465 | } | |
10466 | ||
10467 | return FALSE; | |
10468 | } | |
10469 | #endif | |
10470 | ||
dda8d76d NC |
10471 | static void * |
10472 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 10473 | struct dwarf_section * xlink, |
dda8d76d NC |
10474 | parse_func_type parse_func, |
10475 | check_func_type check_func, | |
301a9420 AM |
10476 | void * func_data, |
10477 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
10478 | { |
10479 | const char * separate_filename; | |
24841daa | 10480 | char * debug_filename; |
dda8d76d NC |
10481 | char * canon_dir; |
10482 | size_t canon_dirlen; | |
10483 | size_t dirlen; | |
10484 | ||
2b63c337 | 10485 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
10486 | { |
10487 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 10488 | xlink->name ? xlink->name : xlink->uncompressed_name); |
ce139cd5 | 10489 | return NULL; |
dda8d76d NC |
10490 | } |
10491 | ||
10492 | /* Attempt to locate the separate file. | |
10493 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
10494 | ||
10495 | canon_dir = lrealpath (main_filename); | |
10496 | ||
10497 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) | |
10498 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
10499 | break; | |
10500 | canon_dir[canon_dirlen] = '\0'; | |
10501 | ||
10502 | #ifndef DEBUGDIR | |
10503 | #define DEBUGDIR "/lib/debug" | |
10504 | #endif | |
10505 | #ifndef EXTRA_DEBUG_ROOT1 | |
10506 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
10507 | #endif | |
10508 | #ifndef EXTRA_DEBUG_ROOT2 | |
10509 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
10510 | #endif | |
10511 | ||
24841daa NC |
10512 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
10513 | + canon_dirlen | |
10514 | + strlen (".debug/") | |
dda8d76d | 10515 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 10516 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
10517 | #endif |
10518 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 10519 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 10520 | #endif |
24841daa NC |
10521 | + strlen (separate_filename) |
10522 | + 1); | |
10523 | if (debug_filename == NULL) | |
dda8d76d NC |
10524 | { |
10525 | warn (_("Out of memory")); | |
3391569f | 10526 | free (canon_dir); |
dda8d76d NC |
10527 | return NULL; |
10528 | } | |
10529 | ||
10530 | /* First try in the current directory. */ | |
24841daa NC |
10531 | sprintf (debug_filename, "%s", separate_filename); |
10532 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10533 | goto found; |
10534 | ||
10535 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
10536 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10537 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10538 | goto found; |
10539 | ||
10540 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
10541 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10542 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10543 | goto found; |
10544 | ||
10545 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
10546 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10547 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10548 | goto found; |
10549 | ||
10550 | #ifdef EXTRA_DEBUG_ROOT1 | |
10551 | /* Try the first extra debug file root. */ | |
24841daa NC |
10552 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10553 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 10554 | goto found; |
39f0547e NC |
10555 | |
10556 | /* Try the first extra debug file root. */ | |
10557 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
10558 | if (check_func (debug_filename, func_data)) | |
10559 | goto found; | |
dda8d76d NC |
10560 | #endif |
10561 | ||
10562 | #ifdef EXTRA_DEBUG_ROOT2 | |
10563 | /* Try the second extra debug file root. */ | |
24841daa NC |
10564 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10565 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10566 | goto found; |
10567 | #endif | |
10568 | ||
24841daa NC |
10569 | /* Then try in the global debug_filename directory. */ |
10570 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
10571 | dirlen = strlen (DEBUGDIR) - 1; |
10572 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
10573 | strcat (debug_filename, "/"); |
10574 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 10575 | |
24841daa | 10576 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
10577 | goto found; |
10578 | ||
301a9420 AM |
10579 | #if HAVE_LIBDEBUGINFOD |
10580 | { | |
10581 | char * tmp_filename; | |
10582 | ||
10583 | if (debuginfod_fetch_separate_debug_info (xlink, | |
10584 | & tmp_filename, | |
10585 | file)) | |
10586 | { | |
10587 | /* File successfully downloaded from server, replace | |
10588 | debug_filename with the file's path. */ | |
10589 | free (debug_filename); | |
10590 | debug_filename = tmp_filename; | |
10591 | goto found; | |
10592 | } | |
10593 | } | |
10594 | #endif | |
10595 | ||
dda8d76d NC |
10596 | /* Failed to find the file. */ |
10597 | warn (_("could not find separate debug file '%s'\n"), separate_filename); | |
24841daa | 10598 | warn (_("tried: %s\n"), debug_filename); |
dda8d76d NC |
10599 | |
10600 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa NC |
10601 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10602 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10603 | #endif |
10604 | ||
10605 | #ifdef EXTRA_DEBUG_ROOT1 | |
39f0547e NC |
10606 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); |
10607 | warn (_("tried: %s\n"), debug_filename); | |
10608 | ||
24841daa NC |
10609 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10610 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10611 | #endif |
10612 | ||
24841daa NC |
10613 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10614 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10615 | |
24841daa NC |
10616 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10617 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10618 | |
24841daa NC |
10619 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10620 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10621 | |
24841daa NC |
10622 | sprintf (debug_filename, "%s", separate_filename); |
10623 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10624 | |
301a9420 AM |
10625 | #if HAVE_LIBDEBUGINFOD |
10626 | { | |
10627 | char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR); | |
10628 | if (urls == NULL) | |
10629 | urls = ""; | |
10630 | ||
10631 | warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls); | |
10632 | } | |
10633 | #endif | |
10634 | ||
dda8d76d | 10635 | free (canon_dir); |
24841daa | 10636 | free (debug_filename); |
dda8d76d NC |
10637 | return NULL; |
10638 | ||
10639 | found: | |
10640 | free (canon_dir); | |
10641 | ||
24841daa NC |
10642 | void * debug_handle; |
10643 | ||
dda8d76d | 10644 | /* Now open the file.... */ |
24841daa | 10645 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 10646 | { |
24841daa NC |
10647 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
10648 | free (debug_filename); | |
ce139cd5 | 10649 | return NULL; |
dda8d76d NC |
10650 | } |
10651 | ||
10652 | /* FIXME: We do not check to see if there are any other separate debug info | |
10653 | files that would also match. */ | |
10654 | ||
24841daa NC |
10655 | printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debug_filename); |
10656 | add_separate_debug_file (debug_filename, debug_handle); | |
dda8d76d | 10657 | |
24841daa | 10658 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 10659 | the structure returned by open_debug_file(). */ |
24841daa | 10660 | return debug_handle; |
dda8d76d NC |
10661 | } |
10662 | ||
d85bf2ba NC |
10663 | /* Attempt to load a separate dwarf object file. */ |
10664 | ||
10665 | static void * | |
24841daa | 10666 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 10667 | { |
24841daa NC |
10668 | char * separate_filename; |
10669 | void * separate_handle; | |
d85bf2ba NC |
10670 | |
10671 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
24841daa NC |
10672 | separate_filename = concat (dir, "/", name, NULL); |
10673 | if (separate_filename == NULL) | |
d85bf2ba NC |
10674 | { |
10675 | warn (_("Out of memory allocating dwo filename\n")); | |
10676 | return NULL; | |
10677 | } | |
10678 | ||
24841daa | 10679 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 10680 | { |
24841daa NC |
10681 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
10682 | free (separate_filename); | |
d85bf2ba NC |
10683 | return NULL; |
10684 | } | |
10685 | ||
10686 | /* FIXME: We should check the dwo_id. */ | |
10687 | ||
24841daa NC |
10688 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
10689 | add_separate_debug_file (separate_filename, separate_handle); | |
10690 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
10691 | return separate_handle; | |
d85bf2ba NC |
10692 | } |
10693 | ||
ce139cd5 NC |
10694 | /* Load a debuglink section and/or a debugaltlink section, if either are present. |
10695 | Recursively check the loaded files for more of these sections. | |
10696 | FIXME: Should also check for DWO_* entries in the newlu loaded files. */ | |
10697 | ||
10698 | static void | |
10699 | check_for_and_load_links (void * file, const char * filename) | |
10700 | { | |
10701 | void * handle = NULL; | |
10702 | ||
10703 | if (load_debug_section (gnu_debugaltlink, file)) | |
10704 | { | |
10705 | Build_id_data build_id_data; | |
10706 | ||
10707 | handle = load_separate_debug_info (filename, | |
10708 | & debug_displays[gnu_debugaltlink].section, | |
10709 | parse_gnu_debugaltlink, | |
10710 | check_gnu_debugaltlink, | |
10711 | & build_id_data, | |
10712 | file); | |
10713 | if (handle) | |
10714 | { | |
10715 | assert (handle == first_separate_info->handle); | |
10716 | check_for_and_load_links (first_separate_info->handle, | |
10717 | first_separate_info->filename); | |
10718 | } | |
10719 | } | |
10720 | ||
10721 | if (load_debug_section (gnu_debuglink, file)) | |
10722 | { | |
10723 | unsigned long crc32; | |
10724 | ||
10725 | handle = load_separate_debug_info (filename, | |
10726 | & debug_displays[gnu_debuglink].section, | |
10727 | parse_gnu_debuglink, | |
10728 | check_gnu_debuglink, | |
10729 | & crc32, | |
10730 | file); | |
10731 | if (handle) | |
10732 | { | |
10733 | assert (handle == first_separate_info->handle); | |
10734 | check_for_and_load_links (first_separate_info->handle, | |
10735 | first_separate_info->filename); | |
10736 | } | |
10737 | } | |
10738 | } | |
10739 | ||
24841daa NC |
10740 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
10741 | Returns TRUE if any were found, FALSE otherwise. | |
10742 | If TRUE is returned then the linked list starting at first_separate_info | |
10743 | will be populated with open file handles. */ | |
dda8d76d | 10744 | |
24841daa NC |
10745 | bfd_boolean |
10746 | load_separate_debug_files (void * file, const char * filename) | |
dda8d76d | 10747 | { |
8de3a6e2 NC |
10748 | /* Skip this operation if we are not interested in debug links. */ |
10749 | if (! do_follow_links && ! do_debug_links) | |
24841daa | 10750 | return FALSE; |
8de3a6e2 | 10751 | |
24841daa | 10752 | /* See if there are any dwo links. */ |
d85bf2ba NC |
10753 | if (load_debug_section (str, file) |
10754 | && load_debug_section (abbrev, file) | |
10755 | && load_debug_section (info, file)) | |
10756 | { | |
24841daa | 10757 | free_dwo_info (); |
d85bf2ba NC |
10758 | |
10759 | if (process_debug_info (& debug_displays[info].section, file, abbrev, TRUE, FALSE)) | |
10760 | { | |
24841daa NC |
10761 | bfd_boolean introduced = FALSE; |
10762 | dwo_info * dwinfo; | |
10763 | const char * dir = NULL; | |
10764 | const char * id = NULL; | |
10765 | ||
10766 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 10767 | { |
24841daa | 10768 | switch (dwinfo->type) |
d85bf2ba | 10769 | { |
24841daa NC |
10770 | case DWO_NAME: |
10771 | if (do_debug_links) | |
10772 | { | |
10773 | if (! introduced) | |
10774 | { | |
10775 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
10776 | debug_displays [info].section.uncompressed_name); | |
10777 | introduced = TRUE; | |
10778 | } | |
d85bf2ba | 10779 | |
24841daa NC |
10780 | printf (_(" Name: %s\n"), dwinfo->value); |
10781 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); | |
10782 | if (id != NULL) | |
10783 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
10784 | else | |
10785 | printf (_(" ID: <unknown>\n")); | |
10786 | printf ("\n\n"); | |
10787 | } | |
10788 | ||
10789 | if (do_follow_links) | |
10790 | load_dwo_file (filename, dwinfo->value, dir, id); | |
10791 | break; | |
10792 | ||
10793 | case DWO_DIR: | |
10794 | dir = dwinfo->value; | |
10795 | break; | |
10796 | ||
10797 | case DWO_ID: | |
10798 | id = dwinfo->value; | |
10799 | break; | |
10800 | ||
10801 | default: | |
10802 | error (_("Unexpected DWO INFO type")); | |
10803 | break; | |
10804 | } | |
d85bf2ba NC |
10805 | } |
10806 | } | |
10807 | } | |
10808 | ||
dda8d76d | 10809 | if (! do_follow_links) |
8de3a6e2 NC |
10810 | /* The other debug links will be displayed by display_debug_links() |
10811 | so we do not need to do any further processing here. */ | |
24841daa | 10812 | return FALSE; |
dda8d76d NC |
10813 | |
10814 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
dda8d76d | 10815 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ |
d85bf2ba | 10816 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 10817 | |
ce139cd5 | 10818 | check_for_and_load_links (file, filename); |
24841daa NC |
10819 | if (first_separate_info != NULL) |
10820 | return TRUE; | |
10821 | ||
dda8d76d | 10822 | do_follow_links = 0; |
24841daa | 10823 | return FALSE; |
dda8d76d NC |
10824 | } |
10825 | ||
19e6b90e L |
10826 | void |
10827 | free_debug_memory (void) | |
10828 | { | |
3f5e193b | 10829 | unsigned int i; |
19e6b90e L |
10830 | |
10831 | free_abbrevs (); | |
10832 | ||
10833 | for (i = 0; i < max; i++) | |
3f5e193b | 10834 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 10835 | |
cc86f28f | 10836 | if (debug_information != NULL) |
19e6b90e | 10837 | { |
82fcdb39 | 10838 | for (i = 0; i < alloc_num_debug_info_entries; i++) |
19e6b90e | 10839 | { |
82fcdb39 | 10840 | if (debug_information [i].max_loc_offsets) |
19e6b90e | 10841 | { |
82fcdb39 AM |
10842 | free (debug_information [i].loc_offsets); |
10843 | free (debug_information [i].have_frame_base); | |
19e6b90e | 10844 | } |
82fcdb39 AM |
10845 | if (debug_information [i].max_range_lists) |
10846 | free (debug_information [i].range_lists); | |
19e6b90e L |
10847 | } |
10848 | free (debug_information); | |
10849 | debug_information = NULL; | |
82b1b41b | 10850 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 10851 | } |
dda8d76d | 10852 | |
24841daa NC |
10853 | separate_info * d; |
10854 | separate_info * next; | |
dda8d76d | 10855 | |
24841daa NC |
10856 | for (d = first_separate_info; d != NULL; d = next) |
10857 | { | |
10858 | close_debug_file (d->handle); | |
10859 | free ((void *) d->filename); | |
10860 | next = d->next; | |
10861 | free ((void *) d); | |
dda8d76d | 10862 | } |
24841daa NC |
10863 | first_separate_info = NULL; |
10864 | ||
10865 | free_dwo_info (); | |
19e6b90e L |
10866 | } |
10867 | ||
4cb93e3b TG |
10868 | void |
10869 | dwarf_select_sections_by_names (const char *names) | |
10870 | { | |
10871 | typedef struct | |
10872 | { | |
10873 | const char * option; | |
10874 | int * variable; | |
f9f0e732 | 10875 | int val; |
4cb93e3b TG |
10876 | } |
10877 | debug_dump_long_opts; | |
10878 | ||
10879 | static const debug_dump_long_opts opts_table [] = | |
10880 | { | |
10881 | /* Please keep this table alpha- sorted. */ | |
10882 | { "Ranges", & do_debug_ranges, 1 }, | |
10883 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 10884 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 10885 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
10886 | { "cu_index", & do_debug_cu_index, 1 }, |
10887 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 10888 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
10889 | { "frames", & do_debug_frames, 1 }, |
10890 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
10891 | /* The special .gdb_index section. */ |
10892 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
10893 | { "info", & do_debug_info, 1 }, |
10894 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 10895 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
10896 | { "loc", & do_debug_loc, 1 }, |
10897 | { "macro", & do_debug_macinfo, 1 }, | |
10898 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 10899 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 10900 | /* This entry is for compatibility |
4cb93e3b TG |
10901 | with earlier versions of readelf. */ |
10902 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 10903 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 10904 | { "str", & do_debug_str, 1 }, |
e4b7104b | 10905 | { "str-offsets", & do_debug_str_offsets, 1 }, |
6f875884 TG |
10906 | /* These trace_* sections are used by Itanium VMS. */ |
10907 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
10908 | { "trace_aranges", & do_trace_aranges, 1 }, | |
10909 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
10910 | { NULL, NULL, 0 } |
10911 | }; | |
10912 | ||
10913 | const char *p; | |
467c65bc | 10914 | |
4cb93e3b TG |
10915 | p = names; |
10916 | while (*p) | |
10917 | { | |
10918 | const debug_dump_long_opts * entry; | |
467c65bc | 10919 | |
4cb93e3b TG |
10920 | for (entry = opts_table; entry->option; entry++) |
10921 | { | |
10922 | size_t len = strlen (entry->option); | |
467c65bc | 10923 | |
4cb93e3b TG |
10924 | if (strncmp (p, entry->option, len) == 0 |
10925 | && (p[len] == ',' || p[len] == '\0')) | |
10926 | { | |
10927 | * entry->variable |= entry->val; | |
467c65bc | 10928 | |
4cb93e3b TG |
10929 | /* The --debug-dump=frames-interp option also |
10930 | enables the --debug-dump=frames option. */ | |
10931 | if (do_debug_frames_interp) | |
10932 | do_debug_frames = 1; | |
10933 | ||
10934 | p += len; | |
10935 | break; | |
10936 | } | |
10937 | } | |
467c65bc | 10938 | |
4cb93e3b TG |
10939 | if (entry->option == NULL) |
10940 | { | |
10941 | warn (_("Unrecognized debug option '%s'\n"), p); | |
10942 | p = strchr (p, ','); | |
10943 | if (p == NULL) | |
10944 | break; | |
10945 | } | |
467c65bc | 10946 | |
4cb93e3b TG |
10947 | if (*p == ',') |
10948 | p++; | |
10949 | } | |
10950 | } | |
10951 | ||
10952 | void | |
10953 | dwarf_select_sections_by_letters (const char *letters) | |
10954 | { | |
91d6fa6a | 10955 | unsigned int lindex = 0; |
4cb93e3b | 10956 | |
91d6fa6a NC |
10957 | while (letters[lindex]) |
10958 | switch (letters[lindex++]) | |
4cb93e3b | 10959 | { |
dda8d76d NC |
10960 | case 'A': do_debug_addr = 1; break; |
10961 | case 'a': do_debug_abbrevs = 1; break; | |
10962 | case 'c': do_debug_cu_index = 1; break; | |
10963 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
10964 | case 'f': do_debug_frames = 1; break; | |
10965 | case 'g': do_gdb_index = 1; break; | |
10966 | case 'i': do_debug_info = 1; break; | |
10967 | case 'K': do_follow_links = 1; break; | |
10968 | case 'k': do_debug_links = 1; break; | |
10969 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
10970 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
10971 | case 'm': do_debug_macinfo = 1; break; | |
e4b7104b | 10972 | case 'O': do_debug_str_offsets = 1; break; |
dda8d76d NC |
10973 | case 'o': do_debug_loc = 1; break; |
10974 | case 'p': do_debug_pubnames = 1; break; | |
10975 | case 'R': do_debug_ranges = 1; break; | |
10976 | case 'r': do_debug_aranges = 1; break; | |
10977 | case 's': do_debug_str = 1; break; | |
10978 | case 'T': do_trace_aranges = 1; break; | |
10979 | case 't': do_debug_pubtypes = 1; break; | |
10980 | case 'U': do_trace_info = 1; break; | |
10981 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 10982 | |
4cb93e3b | 10983 | default: |
7cc78d07 | 10984 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
10985 | break; |
10986 | } | |
10987 | } | |
10988 | ||
10989 | void | |
10990 | dwarf_select_sections_all (void) | |
10991 | { | |
10992 | do_debug_info = 1; | |
10993 | do_debug_abbrevs = 1; | |
10994 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
10995 | do_debug_pubnames = 1; | |
f9f0e732 | 10996 | do_debug_pubtypes = 1; |
4cb93e3b TG |
10997 | do_debug_aranges = 1; |
10998 | do_debug_ranges = 1; | |
10999 | do_debug_frames = 1; | |
11000 | do_debug_macinfo = 1; | |
11001 | do_debug_str = 1; | |
11002 | do_debug_loc = 1; | |
5bbdf3d5 | 11003 | do_gdb_index = 1; |
6f875884 TG |
11004 | do_trace_info = 1; |
11005 | do_trace_abbrevs = 1; | |
11006 | do_trace_aranges = 1; | |
657d0d47 CC |
11007 | do_debug_addr = 1; |
11008 | do_debug_cu_index = 1; | |
dda8d76d NC |
11009 | do_follow_links = 1; |
11010 | do_debug_links = 1; | |
e4b7104b | 11011 | do_debug_str_offsets = 1; |
4cb93e3b TG |
11012 | } |
11013 | ||
dda8d76d NC |
11014 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL |
11015 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL | |
11016 | ||
11017 | /* N.B. The order here must match the order in section_display_enum. */ | |
11018 | ||
19e6b90e L |
11019 | struct dwarf_section_display debug_displays[] = |
11020 | { | |
dda8d76d NC |
11021 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, |
11022 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE }, | |
11023 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
11024 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE }, | |
11025 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
11026 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE }, | |
11027 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, | |
11028 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
11029 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
11030 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
11031 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
11032 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
11033 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
11034 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
11035 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE }, | |
11036 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, | |
11037 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
11038 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
11039 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
11040 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
11041 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE }, | |
11042 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
11043 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE }, | |
11044 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE }, | |
11045 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE }, | |
11046 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE }, | |
11047 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE }, | |
11048 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE }, | |
11049 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
11050 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE }, | |
11051 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
11052 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
11053 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
11054 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
11055 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE }, | |
e4b7104b NC |
11056 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, TRUE }, |
11057 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, TRUE }, | |
dda8d76d NC |
11058 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE }, |
11059 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
11060 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
11061 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
11062 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
11063 | /* Separate debug info files can containt their own .debug_str section, | |
11064 | and this might be in *addition* to a .debug_str section already present | |
11065 | in the main file. Hence we need to have two entries for .debug_str. */ | |
11066 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
19e6b90e | 11067 | }; |
b451e98a JK |
11068 | |
11069 | /* A static assertion. */ | |
11070 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |