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; | |
91 | int do_debug_loc; | |
5bbdf3d5 | 92 | int do_gdb_index; |
6f875884 TG |
93 | int do_trace_info; |
94 | int do_trace_abbrevs; | |
95 | int do_trace_aranges; | |
657d0d47 CC |
96 | int do_debug_addr; |
97 | int do_debug_cu_index; | |
a262ae96 | 98 | int do_wide; |
dda8d76d NC |
99 | int do_debug_links; |
100 | int do_follow_links; | |
19e6b90e | 101 | |
fd2f0033 TT |
102 | int dwarf_cutoff_level = -1; |
103 | unsigned long dwarf_start_die; | |
104 | ||
4723351a CC |
105 | int dwarf_check = 0; |
106 | ||
9f272209 AO |
107 | /* Convenient constant, to avoid having to cast -1 to dwarf_vma when |
108 | testing whether e.g. a locview list is present. */ | |
109 | static const dwarf_vma vm1 = -1; | |
110 | ||
341f9135 CC |
111 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
112 | sections. For version 1 package files, each set is stored in SHNDX_POOL | |
113 | as a zero-terminated list of section indexes comprising one set of debug | |
114 | sections from a .dwo file. */ | |
115 | ||
341f9135 CC |
116 | static unsigned int *shndx_pool = NULL; |
117 | static unsigned int shndx_pool_size = 0; | |
118 | static unsigned int shndx_pool_used = 0; | |
119 | ||
120 | /* For version 2 package files, each set contains an array of section offsets | |
121 | and an array of section sizes, giving the offset and size of the | |
122 | contribution from a CU or TU within one of the debug sections. | |
123 | When displaying debug info from a package file, we need to use these | |
124 | tables to locate the corresponding contributions to each section. */ | |
125 | ||
126 | struct cu_tu_set | |
127 | { | |
ec1b0fbb NC |
128 | uint64_t signature; |
129 | dwarf_vma section_offsets[DW_SECT_MAX]; | |
130 | size_t section_sizes[DW_SECT_MAX]; | |
341f9135 CC |
131 | }; |
132 | ||
133 | static int cu_count = 0; | |
134 | static int tu_count = 0; | |
135 | static struct cu_tu_set *cu_sets = NULL; | |
136 | static struct cu_tu_set *tu_sets = NULL; | |
137 | ||
43a444f9 | 138 | static bfd_boolean load_cu_tu_indexes (void *); |
341f9135 | 139 | |
ec1b0fbb NC |
140 | /* An array that indicates for a given level of CU nesting whether |
141 | the latest DW_AT_type seen for that level was a signed type or | |
142 | an unsigned type. */ | |
143 | #define MAX_CU_NESTING (1 << 8) | |
144 | static bfd_boolean level_type_signed[MAX_CU_NESTING]; | |
145 | ||
4cb93e3b TG |
146 | /* Values for do_debug_lines. */ |
147 | #define FLAG_DEBUG_LINES_RAW 1 | |
148 | #define FLAG_DEBUG_LINES_DECODED 2 | |
149 | ||
77ef8654 | 150 | static unsigned int |
f1c4cc75 RH |
151 | size_of_encoded_value (int encoding) |
152 | { | |
153 | switch (encoding & 0x7) | |
154 | { | |
155 | default: /* ??? */ | |
156 | case 0: return eh_addr_size; | |
157 | case 2: return 2; | |
158 | case 3: return 4; | |
159 | case 4: return 8; | |
160 | } | |
161 | } | |
162 | ||
163 | static dwarf_vma | |
041830e0 | 164 | get_encoded_value (unsigned char **pdata, |
bad62cf5 | 165 | int encoding, |
041830e0 NC |
166 | struct dwarf_section *section, |
167 | unsigned char * end) | |
f1c4cc75 | 168 | { |
041830e0 | 169 | unsigned char * data = * pdata; |
6937bb54 | 170 | unsigned int size = size_of_encoded_value (encoding); |
bad62cf5 | 171 | dwarf_vma val; |
f1c4cc75 | 172 | |
041830e0 NC |
173 | if (data + size >= end) |
174 | { | |
175 | warn (_("Encoded value extends past end of section\n")); | |
176 | * pdata = end; | |
177 | return 0; | |
178 | } | |
179 | ||
6937bb54 NC |
180 | /* PR 17512: file: 002-829853-0.004. */ |
181 | if (size > 8) | |
182 | { | |
183 | warn (_("Encoded size of %d is too large to read\n"), size); | |
184 | * pdata = end; | |
185 | return 0; | |
186 | } | |
187 | ||
0a9d414a NC |
188 | /* PR 17512: file: 1085-5603-0.004. */ |
189 | if (size == 0) | |
190 | { | |
191 | warn (_("Encoded size of 0 is too small to read\n")); | |
192 | * pdata = end; | |
193 | return 0; | |
194 | } | |
195 | ||
f1c4cc75 | 196 | if (encoding & DW_EH_PE_signed) |
bad62cf5 | 197 | val = byte_get_signed (data, size); |
f1c4cc75 | 198 | else |
bad62cf5 AM |
199 | val = byte_get (data, size); |
200 | ||
201 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
202 | val += section->address + (data - section->start); | |
041830e0 NC |
203 | |
204 | * pdata = data + size; | |
bad62cf5 | 205 | return val; |
f1c4cc75 RH |
206 | } |
207 | ||
4c219c2e AM |
208 | #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG |
209 | # ifndef __MINGW32__ | |
210 | # define DWARF_VMA_FMT "ll" | |
211 | # define DWARF_VMA_FMT_LONG "%16.16llx" | |
212 | # else | |
213 | # define DWARF_VMA_FMT "I64" | |
214 | # define DWARF_VMA_FMT_LONG "%016I64x" | |
215 | # endif | |
2e14fae2 | 216 | #else |
4c219c2e AM |
217 | # define DWARF_VMA_FMT "l" |
218 | # define DWARF_VMA_FMT_LONG "%16.16lx" | |
2d9472a2 NC |
219 | #endif |
220 | ||
bf5117e3 NC |
221 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
222 | buffer containing the converted VALUE. The value is converted according | |
223 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then | |
224 | it specifies the maximum number of bytes to be displayed in the converted | |
225 | value and FMTCH is ignored - hex is always used. */ | |
467c65bc | 226 | |
47704ddf | 227 | static const char * |
bf5117e3 | 228 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
47704ddf KT |
229 | { |
230 | /* As dwarf_vmatoa is used more then once in a printf call | |
231 | for output, we are cycling through an fixed array of pointers | |
232 | for return address. */ | |
233 | static int buf_pos = 0; | |
467c65bc NC |
234 | static struct dwarf_vmatoa_buf |
235 | { | |
47704ddf KT |
236 | char place[64]; |
237 | } buf[16]; | |
47704ddf KT |
238 | char *ret; |
239 | ||
47704ddf | 240 | ret = buf[buf_pos++].place; |
467c65bc | 241 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf | 242 | |
bf5117e3 NC |
243 | if (num_bytes) |
244 | { | |
222c2bf0 | 245 | /* Printf does not have a way of specifying a maximum field width for an |
bf5117e3 NC |
246 | integer value, so we print the full value into a buffer and then select |
247 | the precision we need. */ | |
248 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); | |
249 | if (num_bytes > 8) | |
250 | num_bytes = 8; | |
251 | return ret + (16 - 2 * num_bytes); | |
252 | } | |
253 | else | |
254 | { | |
255 | char fmt[32]; | |
256 | ||
0bae9e9e NC |
257 | if (fmtch) |
258 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); | |
259 | else | |
260 | sprintf (fmt, "%%%s", DWARF_VMA_FMT); | |
bf5117e3 NC |
261 | snprintf (ret, sizeof (buf[0].place), fmt, value); |
262 | return ret; | |
263 | } | |
264 | } | |
47704ddf | 265 | |
bf5117e3 NC |
266 | static inline const char * |
267 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) | |
268 | { | |
269 | return dwarf_vmatoa_1 (fmtch, value, 0); | |
270 | } | |
271 | ||
272 | /* Print a dwarf_vma value (typically an address, offset or length) in | |
273 | hexadecimal format, followed by a space. The length of the VALUE (and | |
274 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ | |
275 | ||
276 | static void | |
277 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) | |
278 | { | |
279 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); | |
47704ddf KT |
280 | } |
281 | ||
9f272209 AO |
282 | /* Print a view number in hexadecimal value, with the same width |
283 | print_dwarf_vma would have printed it with the same num_bytes. | |
284 | Print blanks for zero view, unless force is nonzero. */ | |
285 | ||
286 | static void | |
287 | print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force) | |
288 | { | |
289 | int len; | |
290 | if (!num_bytes) | |
291 | len = 4; | |
292 | else | |
293 | len = num_bytes * 2; | |
294 | ||
295 | assert (value == (unsigned long) value); | |
296 | if (value || force) | |
297 | printf ("v%0*lx ", len - 1, (unsigned long) value); | |
298 | else | |
299 | printf ("%*s", len + 1, ""); | |
300 | } | |
301 | ||
74bc6052 CC |
302 | /* Format a 64-bit value, given as two 32-bit values, in hex. |
303 | For reentrancy, this uses a buffer provided by the caller. */ | |
304 | ||
305 | static const char * | |
306 | dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, | |
307 | unsigned int buf_len) | |
308 | { | |
309 | int len = 0; | |
310 | ||
311 | if (hvalue == 0) | |
312 | snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); | |
313 | else | |
314 | { | |
315 | len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); | |
316 | snprintf (buf + len, buf_len - len, | |
317 | "%08" DWARF_VMA_FMT "x", lvalue); | |
318 | } | |
319 | ||
320 | return buf; | |
321 | } | |
322 | ||
f6f0e17b NC |
323 | /* Read in a LEB128 encoded value starting at address DATA. |
324 | If SIGN is true, return a signed LEB128 value. | |
325 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
cd30bcef AM |
326 | If STATUS_RETURN in not NULL, return with bit 0 (LSB) set if the |
327 | terminating byte was not found and with bit 1 set if the value | |
328 | overflows a dwarf_vma. | |
f6f0e17b NC |
329 | No bytes will be read at address END or beyond. */ |
330 | ||
467c65bc | 331 | dwarf_vma |
f6f0e17b | 332 | read_leb128 (unsigned char *data, |
cd30bcef | 333 | const unsigned char *const end, |
f6f0e17b | 334 | bfd_boolean sign, |
cd30bcef AM |
335 | unsigned int *length_return, |
336 | int *status_return) | |
19e6b90e | 337 | { |
467c65bc | 338 | dwarf_vma result = 0; |
19e6b90e L |
339 | unsigned int num_read = 0; |
340 | unsigned int shift = 0; | |
cd30bcef | 341 | int status = 1; |
19e6b90e | 342 | |
f6f0e17b | 343 | while (data < end) |
19e6b90e | 344 | { |
cd30bcef | 345 | unsigned char byte = *data++; |
19e6b90e L |
346 | num_read++; |
347 | ||
cd30bcef AM |
348 | if (shift < sizeof (result) * 8) |
349 | { | |
350 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; | |
351 | if ((result >> shift) != (byte & 0x7f)) | |
352 | /* Overflow. */ | |
353 | status |= 2; | |
354 | shift += 7; | |
355 | } | |
356 | else if ((byte & 0x7f) != 0) | |
357 | status |= 2; | |
19e6b90e | 358 | |
f6f0e17b | 359 | if ((byte & 0x80) == 0) |
cd30bcef AM |
360 | { |
361 | status &= ~1; | |
362 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) | |
363 | result |= -((dwarf_vma) 1 << shift); | |
364 | break; | |
365 | } | |
19e6b90e | 366 | } |
19e6b90e L |
367 | |
368 | if (length_return != NULL) | |
369 | *length_return = num_read; | |
cd30bcef AM |
370 | if (status_return != NULL) |
371 | *status_return = status; | |
19e6b90e L |
372 | |
373 | return result; | |
374 | } | |
375 | ||
d11ae95e NC |
376 | /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value. |
377 | Checks to make sure that the read will not reach or pass END | |
378 | and that VAL is big enough to hold AMOUNT bytes. */ | |
0c588247 NC |
379 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
380 | do \ | |
381 | { \ | |
382 | unsigned int amount = (AMOUNT); \ | |
34b9f729 NC |
383 | if (sizeof (VAL) < amount) \ |
384 | { \ | |
d3a49aa8 AM |
385 | error (ngettext ("internal error: attempt to read %d byte " \ |
386 | "of data in to %d sized variable", \ | |
387 | "internal error: attempt to read %d bytes " \ | |
388 | "of data in to %d sized variable", \ | |
389 | amount), \ | |
34b9f729 NC |
390 | amount, (int) sizeof (VAL)); \ |
391 | amount = sizeof (VAL); \ | |
392 | } \ | |
0c588247 NC |
393 | if (((PTR) + amount) >= (END)) \ |
394 | { \ | |
395 | if ((PTR) < (END)) \ | |
396 | amount = (END) - (PTR); \ | |
397 | else \ | |
398 | amount = 0; \ | |
399 | } \ | |
6937bb54 | 400 | if (amount == 0 || amount > 8) \ |
0c588247 | 401 | VAL = 0; \ |
6937bb54 NC |
402 | else \ |
403 | VAL = byte_get ((PTR), amount); \ | |
0c588247 NC |
404 | } \ |
405 | while (0) | |
406 | ||
d11ae95e | 407 | /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
408 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
409 | do \ | |
410 | { \ | |
411 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
412 | PTR += AMOUNT; \ | |
413 | } \ | |
414 | while (0) | |
415 | ||
d11ae95e | 416 | /* Like SAFE_BYTE_GET, but reads a signed value. */ |
0c588247 NC |
417 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
418 | do \ | |
419 | { \ | |
420 | unsigned int amount = (AMOUNT); \ | |
421 | if (((PTR) + amount) >= (END)) \ | |
422 | { \ | |
423 | if ((PTR) < (END)) \ | |
424 | amount = (END) - (PTR); \ | |
425 | else \ | |
426 | amount = 0; \ | |
427 | } \ | |
428 | if (amount) \ | |
429 | VAL = byte_get_signed ((PTR), amount); \ | |
430 | else \ | |
431 | VAL = 0; \ | |
432 | } \ | |
433 | while (0) | |
434 | ||
d11ae95e | 435 | /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
436 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
437 | do \ | |
438 | { \ | |
439 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
440 | PTR += AMOUNT; \ | |
441 | } \ | |
442 | while (0) | |
443 | ||
444 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ | |
445 | do \ | |
446 | { \ | |
87bc83b3 | 447 | if (((PTR) + 8) <= (END)) \ |
0c588247 NC |
448 | { \ |
449 | byte_get_64 ((PTR), (HIGH), (LOW)); \ | |
450 | } \ | |
451 | else \ | |
452 | { \ | |
0c588247 NC |
453 | * (LOW) = * (HIGH) = 0; \ |
454 | } \ | |
455 | } \ | |
456 | while (0) | |
457 | ||
19e6b90e L |
458 | typedef struct State_Machine_Registers |
459 | { | |
467c65bc | 460 | dwarf_vma address; |
ba8826a8 | 461 | unsigned int view; |
19e6b90e L |
462 | unsigned int file; |
463 | unsigned int line; | |
464 | unsigned int column; | |
465 | int is_stmt; | |
466 | int basic_block; | |
a233b20c JJ |
467 | unsigned char op_index; |
468 | unsigned char end_sequence; | |
ba8826a8 AO |
469 | /* This variable hold the number of the last entry seen |
470 | in the File Table. */ | |
19e6b90e L |
471 | unsigned int last_file_entry; |
472 | } SMR; | |
473 | ||
474 | static SMR state_machine_regs; | |
475 | ||
476 | static void | |
477 | reset_state_machine (int is_stmt) | |
478 | { | |
479 | state_machine_regs.address = 0; | |
ba8826a8 | 480 | state_machine_regs.view = 0; |
a233b20c | 481 | state_machine_regs.op_index = 0; |
19e6b90e L |
482 | state_machine_regs.file = 1; |
483 | state_machine_regs.line = 1; | |
484 | state_machine_regs.column = 0; | |
485 | state_machine_regs.is_stmt = is_stmt; | |
486 | state_machine_regs.basic_block = 0; | |
487 | state_machine_regs.end_sequence = 0; | |
488 | state_machine_regs.last_file_entry = 0; | |
489 | } | |
490 | ||
491 | /* Handled an extend line op. | |
492 | Returns the number of bytes read. */ | |
493 | ||
cd30bcef | 494 | static size_t |
f6f0e17b NC |
495 | process_extended_line_op (unsigned char * data, |
496 | int is_stmt, | |
497 | unsigned char * end) | |
19e6b90e L |
498 | { |
499 | unsigned char op_code; | |
cd30bcef | 500 | size_t len, header_len; |
19e6b90e | 501 | unsigned char *name; |
143a3db0 | 502 | unsigned char *orig_data = data; |
cd30bcef | 503 | dwarf_vma adr, val; |
19e6b90e | 504 | |
cd30bcef AM |
505 | READ_ULEB (len, data, end); |
506 | header_len = data - orig_data; | |
19e6b90e | 507 | |
cd30bcef | 508 | if (len == 0 || data == end || len > (size_t) (end - data)) |
19e6b90e | 509 | { |
f41e4712 | 510 | warn (_("Badly formed extended line op encountered!\n")); |
cd30bcef | 511 | return header_len; |
19e6b90e L |
512 | } |
513 | ||
19e6b90e L |
514 | op_code = *data++; |
515 | ||
516 | printf (_(" Extended opcode %d: "), op_code); | |
517 | ||
518 | switch (op_code) | |
519 | { | |
520 | case DW_LNE_end_sequence: | |
521 | printf (_("End of Sequence\n\n")); | |
522 | reset_state_machine (is_stmt); | |
523 | break; | |
524 | ||
525 | case DW_LNE_set_address: | |
6937bb54 | 526 | /* PR 17512: file: 002-100480-0.004. */ |
cd30bcef | 527 | if (len - 1 > 8) |
77ef8654 | 528 | { |
cd30bcef AM |
529 | warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"), |
530 | (unsigned long) len - 1); | |
77ef8654 NC |
531 | adr = 0; |
532 | } | |
533 | else | |
cd30bcef | 534 | SAFE_BYTE_GET (adr, data, len - 1, end); |
47704ddf | 535 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 536 | state_machine_regs.address = adr; |
ba8826a8 | 537 | state_machine_regs.view = 0; |
a233b20c | 538 | state_machine_regs.op_index = 0; |
19e6b90e L |
539 | break; |
540 | ||
541 | case DW_LNE_define_file: | |
143a3db0 | 542 | printf (_("define new File Table entry\n")); |
19e6b90e | 543 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 544 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 545 | |
d949ff56 NC |
546 | { |
547 | size_t l; | |
548 | ||
549 | name = data; | |
550 | l = strnlen ((char *) data, end - data); | |
cd30bcef AM |
551 | data += l + 1; |
552 | READ_ULEB (val, data, end); | |
553 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
554 | READ_ULEB (val, data, end); | |
555 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
556 | READ_ULEB (val, data, end); | |
557 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
d949ff56 NC |
558 | printf ("%.*s\n\n", (int) l, name); |
559 | } | |
f6f0e17b | 560 | |
cd30bcef | 561 | if (((size_t) (data - orig_data) != len + header_len) || data == end) |
b4eb7656 | 562 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
563 | break; |
564 | ||
ed4a4bdf | 565 | case DW_LNE_set_discriminator: |
cd30bcef AM |
566 | READ_ULEB (val, data, end); |
567 | printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val)); | |
ed4a4bdf CC |
568 | break; |
569 | ||
e2a0d921 NC |
570 | /* HP extensions. */ |
571 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 572 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
573 | break; |
574 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 575 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
576 | break; |
577 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 578 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
579 | break; |
580 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 581 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
582 | break; |
583 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 584 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
585 | break; |
586 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 587 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
588 | break; |
589 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 590 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
591 | break; |
592 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 593 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
594 | break; |
595 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 596 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
597 | break; |
598 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 599 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 600 | break; |
43294ab7 TG |
601 | case DW_LNE_HP_source_file_correlation: |
602 | { | |
cd30bcef | 603 | unsigned char *edata = data + len - 1; |
b4eb7656 AM |
604 | |
605 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
606 | ||
607 | while (data < edata) | |
608 | { | |
609 | unsigned int opc; | |
610 | ||
cd30bcef | 611 | READ_ULEB (opc, data, edata); |
b4eb7656 AM |
612 | |
613 | switch (opc) | |
614 | { | |
615 | case DW_LNE_HP_SFC_formfeed: | |
616 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
617 | break; | |
618 | case DW_LNE_HP_SFC_set_listing_line: | |
cd30bcef | 619 | READ_ULEB (val, data, edata); |
b4eb7656 | 620 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", |
cd30bcef | 621 | dwarf_vmatoa ("u", val)); |
b4eb7656 AM |
622 | break; |
623 | case DW_LNE_HP_SFC_associate: | |
624 | printf (" DW_LNE_HP_SFC_associate "); | |
cd30bcef AM |
625 | READ_ULEB (val, data, edata); |
626 | printf ("(%s", dwarf_vmatoa ("u", val)); | |
627 | READ_ULEB (val, data, edata); | |
628 | printf (",%s", dwarf_vmatoa ("u", val)); | |
629 | READ_ULEB (val, data, edata); | |
630 | printf (",%s)\n", dwarf_vmatoa ("u", val)); | |
b4eb7656 AM |
631 | break; |
632 | default: | |
633 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
634 | data = edata; | |
635 | break; | |
636 | } | |
637 | } | |
43294ab7 TG |
638 | } |
639 | break; | |
cecf136e | 640 | |
19e6b90e | 641 | default: |
7e665af3 | 642 | { |
cd30bcef | 643 | unsigned int rlen = len - 1; |
b4eb7656 AM |
644 | |
645 | if (op_code >= DW_LNE_lo_user | |
646 | /* The test against DW_LNW_hi_user is redundant due to | |
647 | the limited range of the unsigned char data type used | |
648 | for op_code. */ | |
649 | /*&& op_code <= DW_LNE_hi_user*/) | |
650 | printf (_("user defined: ")); | |
651 | else | |
652 | printf (_("UNKNOWN: ")); | |
653 | printf (_("length %d ["), rlen); | |
654 | for (; rlen; rlen--) | |
655 | printf (" %02x", *data++); | |
656 | printf ("]\n"); | |
7e665af3 | 657 | } |
19e6b90e L |
658 | break; |
659 | } | |
660 | ||
cd30bcef | 661 | return len + header_len; |
19e6b90e L |
662 | } |
663 | ||
0c588247 | 664 | static const unsigned char * |
467c65bc | 665 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
666 | { |
667 | struct dwarf_section *section = &debug_displays [str].section; | |
d949ff56 | 668 | const unsigned char * ret; |
19e6b90e L |
669 | |
670 | if (section->start == NULL) | |
0c588247 | 671 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e | 672 | |
d949ff56 | 673 | if (offset >= section->size) |
19e6b90e | 674 | { |
467c65bc NC |
675 | warn (_("DW_FORM_strp offset too big: %s\n"), |
676 | dwarf_vmatoa ("x", offset)); | |
0c588247 | 677 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
678 | } |
679 | ||
d949ff56 NC |
680 | ret = section->start + offset; |
681 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
682 | NUL byte. Since our caller is expecting to receive a well formed C | |
683 | string we test for the lack of a terminating byte here. */ | |
684 | if (strnlen ((const char *) ret, section->size - offset) | |
685 | == section->size - offset) | |
686 | ret = (const unsigned char *) | |
687 | _("<no NUL byte at end of .debug_str section>"); | |
688 | ||
689 | return ret; | |
19e6b90e L |
690 | } |
691 | ||
77145576 JK |
692 | static const unsigned char * |
693 | fetch_indirect_line_string (dwarf_vma offset) | |
694 | { | |
695 | struct dwarf_section *section = &debug_displays [line_str].section; | |
d949ff56 | 696 | const unsigned char * ret; |
77145576 JK |
697 | |
698 | if (section->start == NULL) | |
699 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
700 | ||
d949ff56 | 701 | if (offset >= section->size) |
77145576 JK |
702 | { |
703 | warn (_("DW_FORM_line_strp offset too big: %s\n"), | |
704 | dwarf_vmatoa ("x", offset)); | |
705 | return (const unsigned char *) _("<offset is too big>"); | |
706 | } | |
707 | ||
d949ff56 NC |
708 | ret = section->start + offset; |
709 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
710 | with a NUL byte. Since our caller is expecting to receive a well formed | |
711 | C string we test for the lack of a terminating byte here. */ | |
712 | if (strnlen ((const char *) ret, section->size - offset) | |
713 | == section->size - offset) | |
714 | ret = (const unsigned char *) | |
715 | _("<no NUL byte at end of .debug_line_str section>"); | |
716 | ||
717 | return ret; | |
77145576 JK |
718 | } |
719 | ||
4723351a | 720 | static const char * |
341f9135 | 721 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
d85bf2ba | 722 | dwarf_vma offset_size, bfd_boolean dwo) |
4723351a CC |
723 | { |
724 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
725 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
726 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
727 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
728 | dwarf_vma index_offset = idx * offset_size; | |
729 | dwarf_vma str_offset; | |
d949ff56 | 730 | const char * ret; |
4723351a CC |
731 | |
732 | if (index_section->start == NULL) | |
733 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
734 | : _("<no .debug_str_offsets section>")); | |
735 | ||
341f9135 CC |
736 | if (this_set != NULL) |
737 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
d949ff56 | 738 | if (index_offset >= index_section->size) |
4723351a CC |
739 | { |
740 | warn (_("DW_FORM_GNU_str_index offset too big: %s\n"), | |
741 | dwarf_vmatoa ("x", index_offset)); | |
742 | return _("<index offset is too big>"); | |
743 | } | |
744 | ||
745 | if (str_section->start == NULL) | |
746 | return (dwo ? _("<no .debug_str.dwo section>") | |
747 | : _("<no .debug_str section>")); | |
748 | ||
749 | str_offset = byte_get (index_section->start + index_offset, offset_size); | |
750 | str_offset -= str_section->address; | |
d949ff56 | 751 | if (str_offset >= str_section->size) |
4723351a CC |
752 | { |
753 | warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), | |
754 | dwarf_vmatoa ("x", str_offset)); | |
755 | return _("<indirect index offset is too big>"); | |
756 | } | |
757 | ||
d949ff56 NC |
758 | ret = (const char *) str_section->start + str_offset; |
759 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. | |
760 | Since our caller is expecting to receive a well formed C string we test | |
761 | for the lack of a terminating byte here. */ | |
762 | if (strnlen (ret, str_section->size - str_offset) | |
763 | == str_section->size - str_offset) | |
764 | ret = (const char *) _("<no NUL byte at end of section>"); | |
765 | ||
766 | return ret; | |
4723351a CC |
767 | } |
768 | ||
769 | static const char * | |
770 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
771 | { | |
772 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
773 | ||
774 | if (section->start == NULL) | |
775 | return (_("<no .debug_addr section>")); | |
776 | ||
777 | if (offset + bytes > section->size) | |
778 | { | |
779 | warn (_("Offset into section %s too big: %s\n"), | |
b4eb7656 | 780 | section->name, dwarf_vmatoa ("x", offset)); |
4723351a CC |
781 | return "<offset too big>"; |
782 | } | |
783 | ||
784 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
785 | } | |
786 | ||
787 | ||
19e6b90e L |
788 | /* FIXME: There are better and more efficient ways to handle |
789 | these structures. For now though, I just want something that | |
790 | is simple to implement. */ | |
791 | typedef struct abbrev_attr | |
792 | { | |
793 | unsigned long attribute; | |
794 | unsigned long form; | |
77145576 | 795 | bfd_signed_vma implicit_const; |
19e6b90e L |
796 | struct abbrev_attr *next; |
797 | } | |
798 | abbrev_attr; | |
799 | ||
800 | typedef struct abbrev_entry | |
801 | { | |
802 | unsigned long entry; | |
803 | unsigned long tag; | |
804 | int children; | |
805 | struct abbrev_attr *first_attr; | |
806 | struct abbrev_attr *last_attr; | |
807 | struct abbrev_entry *next; | |
808 | } | |
809 | abbrev_entry; | |
810 | ||
811 | static abbrev_entry *first_abbrev = NULL; | |
812 | static abbrev_entry *last_abbrev = NULL; | |
813 | ||
814 | static void | |
815 | free_abbrevs (void) | |
816 | { | |
91d6fa6a | 817 | abbrev_entry *abbrv; |
19e6b90e | 818 | |
91d6fa6a | 819 | for (abbrv = first_abbrev; abbrv;) |
19e6b90e | 820 | { |
91d6fa6a | 821 | abbrev_entry *next_abbrev = abbrv->next; |
19e6b90e L |
822 | abbrev_attr *attr; |
823 | ||
91d6fa6a | 824 | for (attr = abbrv->first_attr; attr;) |
19e6b90e | 825 | { |
91d6fa6a | 826 | abbrev_attr *next_attr = attr->next; |
19e6b90e L |
827 | |
828 | free (attr); | |
91d6fa6a | 829 | attr = next_attr; |
19e6b90e L |
830 | } |
831 | ||
91d6fa6a NC |
832 | free (abbrv); |
833 | abbrv = next_abbrev; | |
19e6b90e L |
834 | } |
835 | ||
836 | last_abbrev = first_abbrev = NULL; | |
837 | } | |
838 | ||
839 | static void | |
840 | add_abbrev (unsigned long number, unsigned long tag, int children) | |
841 | { | |
842 | abbrev_entry *entry; | |
843 | ||
3f5e193b | 844 | entry = (abbrev_entry *) malloc (sizeof (*entry)); |
19e6b90e L |
845 | if (entry == NULL) |
846 | /* ugg */ | |
847 | return; | |
848 | ||
849 | entry->entry = number; | |
850 | entry->tag = tag; | |
851 | entry->children = children; | |
852 | entry->first_attr = NULL; | |
853 | entry->last_attr = NULL; | |
854 | entry->next = NULL; | |
855 | ||
856 | if (first_abbrev == NULL) | |
857 | first_abbrev = entry; | |
858 | else | |
859 | last_abbrev->next = entry; | |
860 | ||
861 | last_abbrev = entry; | |
862 | } | |
863 | ||
864 | static void | |
77145576 JK |
865 | add_abbrev_attr (unsigned long attribute, unsigned long form, |
866 | bfd_signed_vma implicit_const) | |
19e6b90e L |
867 | { |
868 | abbrev_attr *attr; | |
869 | ||
3f5e193b | 870 | attr = (abbrev_attr *) malloc (sizeof (*attr)); |
19e6b90e L |
871 | if (attr == NULL) |
872 | /* ugg */ | |
873 | return; | |
874 | ||
875 | attr->attribute = attribute; | |
876 | attr->form = form; | |
77145576 | 877 | attr->implicit_const = implicit_const; |
19e6b90e L |
878 | attr->next = NULL; |
879 | ||
880 | if (last_abbrev->first_attr == NULL) | |
881 | last_abbrev->first_attr = attr; | |
882 | else | |
883 | last_abbrev->last_attr->next = attr; | |
884 | ||
885 | last_abbrev->last_attr = attr; | |
886 | } | |
887 | ||
888 | /* Processes the (partial) contents of a .debug_abbrev section. | |
889 | Returns NULL if the end of the section was encountered. | |
890 | Returns the address after the last byte read if the end of | |
891 | an abbreviation set was found. */ | |
892 | ||
893 | static unsigned char * | |
894 | process_abbrev_section (unsigned char *start, unsigned char *end) | |
895 | { | |
896 | if (first_abbrev != NULL) | |
897 | return NULL; | |
898 | ||
899 | while (start < end) | |
900 | { | |
19e6b90e L |
901 | unsigned long entry; |
902 | unsigned long tag; | |
903 | unsigned long attribute; | |
904 | int children; | |
905 | ||
cd30bcef | 906 | READ_ULEB (entry, start, end); |
19e6b90e L |
907 | |
908 | /* A single zero is supposed to end the section according | |
909 | to the standard. If there's more, then signal that to | |
910 | the caller. */ | |
f6f0e17b NC |
911 | if (start == end) |
912 | return NULL; | |
19e6b90e | 913 | if (entry == 0) |
f6f0e17b | 914 | return start; |
19e6b90e | 915 | |
cd30bcef | 916 | READ_ULEB (tag, start, end); |
f6f0e17b NC |
917 | if (start == end) |
918 | return NULL; | |
19e6b90e L |
919 | |
920 | children = *start++; | |
921 | ||
922 | add_abbrev (entry, tag, children); | |
923 | ||
924 | do | |
925 | { | |
926 | unsigned long form; | |
77145576 JK |
927 | /* Initialize it due to a false compiler warning. */ |
928 | bfd_signed_vma implicit_const = -1; | |
19e6b90e | 929 | |
cd30bcef | 930 | READ_ULEB (attribute, start, end); |
f6f0e17b NC |
931 | if (start == end) |
932 | break; | |
19e6b90e | 933 | |
cd30bcef | 934 | READ_ULEB (form, start, end); |
f6f0e17b NC |
935 | if (start == end) |
936 | break; | |
19e6b90e | 937 | |
77145576 JK |
938 | if (form == DW_FORM_implicit_const) |
939 | { | |
cd30bcef | 940 | READ_SLEB (implicit_const, start, end); |
77145576 JK |
941 | if (start == end) |
942 | break; | |
943 | } | |
944 | ||
945 | add_abbrev_attr (attribute, form, implicit_const); | |
19e6b90e L |
946 | } |
947 | while (attribute != 0); | |
948 | } | |
949 | ||
399c99f7 L |
950 | /* Report the missing single zero which ends the section. */ |
951 | error (_(".debug_abbrev section not zero terminated\n")); | |
952 | ||
19e6b90e L |
953 | return NULL; |
954 | } | |
955 | ||
a19c41a7 | 956 | static const char * |
19e6b90e L |
957 | get_TAG_name (unsigned long tag) |
958 | { | |
04914e37 | 959 | const char *name = get_DW_TAG_name ((unsigned int) tag); |
a19c41a7 TT |
960 | |
961 | if (name == NULL) | |
19e6b90e | 962 | { |
a19c41a7 | 963 | static char buffer[100]; |
19e6b90e | 964 | |
04914e37 NC |
965 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
966 | snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag); | |
967 | else | |
968 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag); | |
a19c41a7 | 969 | return buffer; |
19e6b90e | 970 | } |
a19c41a7 TT |
971 | |
972 | return name; | |
19e6b90e L |
973 | } |
974 | ||
a19c41a7 | 975 | static const char * |
19e6b90e L |
976 | get_FORM_name (unsigned long form) |
977 | { | |
399c99f7 | 978 | const char *name; |
bf5117e3 | 979 | |
399c99f7 L |
980 | if (form == 0) |
981 | return "DW_FORM value: 0"; | |
a19c41a7 | 982 | |
399c99f7 | 983 | name = get_DW_FORM_name (form); |
a19c41a7 | 984 | if (name == NULL) |
19e6b90e | 985 | { |
a19c41a7 | 986 | static char buffer[100]; |
19e6b90e | 987 | |
a19c41a7 TT |
988 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
989 | return buffer; | |
19e6b90e | 990 | } |
a19c41a7 TT |
991 | |
992 | return name; | |
19e6b90e L |
993 | } |
994 | ||
61364358 JK |
995 | static const char * |
996 | get_IDX_name (unsigned long idx) | |
997 | { | |
998 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
999 | ||
1000 | if (name == NULL) | |
1001 | { | |
1002 | static char buffer[100]; | |
1003 | ||
1004 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1005 | return buffer; | |
1006 | } | |
1007 | ||
1008 | return name; | |
1009 | } | |
1010 | ||
19e6b90e | 1011 | static unsigned char * |
0c588247 NC |
1012 | display_block (unsigned char *data, |
1013 | dwarf_vma length, | |
ef0b5f1c | 1014 | const unsigned char * const end, char delimiter) |
19e6b90e | 1015 | { |
0c588247 NC |
1016 | dwarf_vma maxlen; |
1017 | ||
ef0b5f1c | 1018 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
1019 | if (data > end) |
1020 | return (unsigned char *) end; | |
19e6b90e | 1021 | |
0c588247 NC |
1022 | maxlen = (dwarf_vma) (end - data); |
1023 | length = length > maxlen ? maxlen : length; | |
1024 | ||
19e6b90e L |
1025 | while (length --) |
1026 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1027 | ||
1028 | return data; | |
1029 | } | |
1030 | ||
1031 | static int | |
1032 | decode_location_expression (unsigned char * data, | |
1033 | unsigned int pointer_size, | |
b7807392 JJ |
1034 | unsigned int offset_size, |
1035 | int dwarf_version, | |
467c65bc NC |
1036 | dwarf_vma length, |
1037 | dwarf_vma cu_offset, | |
f1c4cc75 | 1038 | struct dwarf_section * section) |
19e6b90e L |
1039 | { |
1040 | unsigned op; | |
467c65bc | 1041 | dwarf_vma uvalue; |
0c588247 | 1042 | dwarf_signed_vma svalue; |
19e6b90e L |
1043 | unsigned char *end = data + length; |
1044 | int need_frame_base = 0; | |
1045 | ||
1046 | while (data < end) | |
1047 | { | |
1048 | op = *data++; | |
1049 | ||
1050 | switch (op) | |
1051 | { | |
1052 | case DW_OP_addr: | |
0c588247 NC |
1053 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1054 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1055 | break; |
1056 | case DW_OP_deref: | |
1057 | printf ("DW_OP_deref"); | |
1058 | break; | |
1059 | case DW_OP_const1u: | |
0c588247 NC |
1060 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1061 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1062 | break; |
1063 | case DW_OP_const1s: | |
0c588247 NC |
1064 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1065 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1066 | break; |
1067 | case DW_OP_const2u: | |
87bc83b3 | 1068 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1069 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1070 | break; |
1071 | case DW_OP_const2s: | |
0c588247 NC |
1072 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1073 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1074 | break; |
1075 | case DW_OP_const4u: | |
0c588247 NC |
1076 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1077 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1078 | break; |
1079 | case DW_OP_const4s: | |
0c588247 NC |
1080 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1081 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1082 | break; |
1083 | case DW_OP_const8u: | |
0c588247 NC |
1084 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1085 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1086 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1087 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1088 | break; |
1089 | case DW_OP_const8s: | |
0c588247 NC |
1090 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1091 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1092 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1093 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1094 | break; |
1095 | case DW_OP_constu: | |
cd30bcef AM |
1096 | READ_ULEB (uvalue, data, end); |
1097 | printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1098 | break; |
1099 | case DW_OP_consts: | |
cd30bcef AM |
1100 | READ_SLEB (svalue, data, end); |
1101 | printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1102 | break; |
1103 | case DW_OP_dup: | |
1104 | printf ("DW_OP_dup"); | |
1105 | break; | |
1106 | case DW_OP_drop: | |
1107 | printf ("DW_OP_drop"); | |
1108 | break; | |
1109 | case DW_OP_over: | |
1110 | printf ("DW_OP_over"); | |
1111 | break; | |
1112 | case DW_OP_pick: | |
0c588247 NC |
1113 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1114 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1115 | break; |
1116 | case DW_OP_swap: | |
1117 | printf ("DW_OP_swap"); | |
1118 | break; | |
1119 | case DW_OP_rot: | |
1120 | printf ("DW_OP_rot"); | |
1121 | break; | |
1122 | case DW_OP_xderef: | |
1123 | printf ("DW_OP_xderef"); | |
1124 | break; | |
1125 | case DW_OP_abs: | |
1126 | printf ("DW_OP_abs"); | |
1127 | break; | |
1128 | case DW_OP_and: | |
1129 | printf ("DW_OP_and"); | |
1130 | break; | |
1131 | case DW_OP_div: | |
1132 | printf ("DW_OP_div"); | |
1133 | break; | |
1134 | case DW_OP_minus: | |
1135 | printf ("DW_OP_minus"); | |
1136 | break; | |
1137 | case DW_OP_mod: | |
1138 | printf ("DW_OP_mod"); | |
1139 | break; | |
1140 | case DW_OP_mul: | |
1141 | printf ("DW_OP_mul"); | |
1142 | break; | |
1143 | case DW_OP_neg: | |
1144 | printf ("DW_OP_neg"); | |
1145 | break; | |
1146 | case DW_OP_not: | |
1147 | printf ("DW_OP_not"); | |
1148 | break; | |
1149 | case DW_OP_or: | |
1150 | printf ("DW_OP_or"); | |
1151 | break; | |
1152 | case DW_OP_plus: | |
1153 | printf ("DW_OP_plus"); | |
1154 | break; | |
1155 | case DW_OP_plus_uconst: | |
cd30bcef AM |
1156 | READ_ULEB (uvalue, data, end); |
1157 | printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1158 | break; |
1159 | case DW_OP_shl: | |
1160 | printf ("DW_OP_shl"); | |
1161 | break; | |
1162 | case DW_OP_shr: | |
1163 | printf ("DW_OP_shr"); | |
1164 | break; | |
1165 | case DW_OP_shra: | |
1166 | printf ("DW_OP_shra"); | |
1167 | break; | |
1168 | case DW_OP_xor: | |
1169 | printf ("DW_OP_xor"); | |
1170 | break; | |
1171 | case DW_OP_bra: | |
0c588247 NC |
1172 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1173 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1174 | break; |
1175 | case DW_OP_eq: | |
1176 | printf ("DW_OP_eq"); | |
1177 | break; | |
1178 | case DW_OP_ge: | |
1179 | printf ("DW_OP_ge"); | |
1180 | break; | |
1181 | case DW_OP_gt: | |
1182 | printf ("DW_OP_gt"); | |
1183 | break; | |
1184 | case DW_OP_le: | |
1185 | printf ("DW_OP_le"); | |
1186 | break; | |
1187 | case DW_OP_lt: | |
1188 | printf ("DW_OP_lt"); | |
1189 | break; | |
1190 | case DW_OP_ne: | |
1191 | printf ("DW_OP_ne"); | |
1192 | break; | |
1193 | case DW_OP_skip: | |
0c588247 NC |
1194 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1195 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1196 | break; |
1197 | ||
1198 | case DW_OP_lit0: | |
1199 | case DW_OP_lit1: | |
1200 | case DW_OP_lit2: | |
1201 | case DW_OP_lit3: | |
1202 | case DW_OP_lit4: | |
1203 | case DW_OP_lit5: | |
1204 | case DW_OP_lit6: | |
1205 | case DW_OP_lit7: | |
1206 | case DW_OP_lit8: | |
1207 | case DW_OP_lit9: | |
1208 | case DW_OP_lit10: | |
1209 | case DW_OP_lit11: | |
1210 | case DW_OP_lit12: | |
1211 | case DW_OP_lit13: | |
1212 | case DW_OP_lit14: | |
1213 | case DW_OP_lit15: | |
1214 | case DW_OP_lit16: | |
1215 | case DW_OP_lit17: | |
1216 | case DW_OP_lit18: | |
1217 | case DW_OP_lit19: | |
1218 | case DW_OP_lit20: | |
1219 | case DW_OP_lit21: | |
1220 | case DW_OP_lit22: | |
1221 | case DW_OP_lit23: | |
1222 | case DW_OP_lit24: | |
1223 | case DW_OP_lit25: | |
1224 | case DW_OP_lit26: | |
1225 | case DW_OP_lit27: | |
1226 | case DW_OP_lit28: | |
1227 | case DW_OP_lit29: | |
1228 | case DW_OP_lit30: | |
1229 | case DW_OP_lit31: | |
1230 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1231 | break; | |
1232 | ||
1233 | case DW_OP_reg0: | |
1234 | case DW_OP_reg1: | |
1235 | case DW_OP_reg2: | |
1236 | case DW_OP_reg3: | |
1237 | case DW_OP_reg4: | |
1238 | case DW_OP_reg5: | |
1239 | case DW_OP_reg6: | |
1240 | case DW_OP_reg7: | |
1241 | case DW_OP_reg8: | |
1242 | case DW_OP_reg9: | |
1243 | case DW_OP_reg10: | |
1244 | case DW_OP_reg11: | |
1245 | case DW_OP_reg12: | |
1246 | case DW_OP_reg13: | |
1247 | case DW_OP_reg14: | |
1248 | case DW_OP_reg15: | |
1249 | case DW_OP_reg16: | |
1250 | case DW_OP_reg17: | |
1251 | case DW_OP_reg18: | |
1252 | case DW_OP_reg19: | |
1253 | case DW_OP_reg20: | |
1254 | case DW_OP_reg21: | |
1255 | case DW_OP_reg22: | |
1256 | case DW_OP_reg23: | |
1257 | case DW_OP_reg24: | |
1258 | case DW_OP_reg25: | |
1259 | case DW_OP_reg26: | |
1260 | case DW_OP_reg27: | |
1261 | case DW_OP_reg28: | |
1262 | case DW_OP_reg29: | |
1263 | case DW_OP_reg30: | |
1264 | case DW_OP_reg31: | |
18464d4d JK |
1265 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1266 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1267 | break; |
1268 | ||
1269 | case DW_OP_breg0: | |
1270 | case DW_OP_breg1: | |
1271 | case DW_OP_breg2: | |
1272 | case DW_OP_breg3: | |
1273 | case DW_OP_breg4: | |
1274 | case DW_OP_breg5: | |
1275 | case DW_OP_breg6: | |
1276 | case DW_OP_breg7: | |
1277 | case DW_OP_breg8: | |
1278 | case DW_OP_breg9: | |
1279 | case DW_OP_breg10: | |
1280 | case DW_OP_breg11: | |
1281 | case DW_OP_breg12: | |
1282 | case DW_OP_breg13: | |
1283 | case DW_OP_breg14: | |
1284 | case DW_OP_breg15: | |
1285 | case DW_OP_breg16: | |
1286 | case DW_OP_breg17: | |
1287 | case DW_OP_breg18: | |
1288 | case DW_OP_breg19: | |
1289 | case DW_OP_breg20: | |
1290 | case DW_OP_breg21: | |
1291 | case DW_OP_breg22: | |
1292 | case DW_OP_breg23: | |
1293 | case DW_OP_breg24: | |
1294 | case DW_OP_breg25: | |
1295 | case DW_OP_breg26: | |
1296 | case DW_OP_breg27: | |
1297 | case DW_OP_breg28: | |
1298 | case DW_OP_breg29: | |
1299 | case DW_OP_breg30: | |
1300 | case DW_OP_breg31: | |
cd30bcef AM |
1301 | READ_SLEB (svalue, data, end); |
1302 | printf ("DW_OP_breg%d (%s): %s", op - DW_OP_breg0, | |
1303 | regname (op - DW_OP_breg0, 1), dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1304 | break; |
1305 | ||
1306 | case DW_OP_regx: | |
cd30bcef | 1307 | READ_ULEB (uvalue, data, end); |
467c65bc NC |
1308 | printf ("DW_OP_regx: %s (%s)", |
1309 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1310 | break; |
1311 | case DW_OP_fbreg: | |
1312 | need_frame_base = 1; | |
cd30bcef AM |
1313 | READ_SLEB (svalue, data, end); |
1314 | printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1315 | break; |
1316 | case DW_OP_bregx: | |
cd30bcef AM |
1317 | READ_ULEB (uvalue, data, end); |
1318 | READ_SLEB (svalue, data, end); | |
467c65bc NC |
1319 | printf ("DW_OP_bregx: %s (%s) %s", |
1320 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
cd30bcef | 1321 | dwarf_vmatoa ("d", svalue)); |
19e6b90e L |
1322 | break; |
1323 | case DW_OP_piece: | |
cd30bcef AM |
1324 | READ_ULEB (uvalue, data, end); |
1325 | printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1326 | break; |
1327 | case DW_OP_deref_size: | |
0c588247 NC |
1328 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1329 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1330 | break; |
1331 | case DW_OP_xderef_size: | |
0c588247 NC |
1332 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1333 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1334 | break; |
1335 | case DW_OP_nop: | |
1336 | printf ("DW_OP_nop"); | |
1337 | break; | |
1338 | ||
1339 | /* DWARF 3 extensions. */ | |
1340 | case DW_OP_push_object_address: | |
1341 | printf ("DW_OP_push_object_address"); | |
1342 | break; | |
1343 | case DW_OP_call2: | |
d85bf2ba | 1344 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1345 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1346 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1347 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1348 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1349 | break; |
1350 | case DW_OP_call4: | |
d85bf2ba | 1351 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1352 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1353 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1354 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1355 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1356 | break; |
1357 | case DW_OP_call_ref: | |
d85bf2ba | 1358 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
e2a0d921 | 1359 | this ought to be an 8-byte wide computation. */ |
b7807392 JJ |
1360 | if (dwarf_version == -1) |
1361 | { | |
1362 | printf (_("(DW_OP_call_ref in frame info)")); | |
1363 | /* No way to tell where the next op is, so just bail. */ | |
1364 | return need_frame_base; | |
1365 | } | |
1366 | if (dwarf_version == 2) | |
1367 | { | |
0c588247 | 1368 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1369 | } |
1370 | else | |
1371 | { | |
0c588247 | 1372 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1373 | } |
0c588247 | 1374 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1375 | break; |
a87b0a59 NS |
1376 | case DW_OP_form_tls_address: |
1377 | printf ("DW_OP_form_tls_address"); | |
1378 | break; | |
e2a0d921 NC |
1379 | case DW_OP_call_frame_cfa: |
1380 | printf ("DW_OP_call_frame_cfa"); | |
1381 | break; | |
1382 | case DW_OP_bit_piece: | |
1383 | printf ("DW_OP_bit_piece: "); | |
cd30bcef AM |
1384 | READ_ULEB (uvalue, data, end); |
1385 | printf (_("size: %s "), dwarf_vmatoa ("u", uvalue)); | |
1386 | READ_ULEB (uvalue, data, end); | |
1387 | printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue)); | |
e2a0d921 | 1388 | break; |
19e6b90e | 1389 | |
3244e8f5 JJ |
1390 | /* DWARF 4 extensions. */ |
1391 | case DW_OP_stack_value: | |
1392 | printf ("DW_OP_stack_value"); | |
1393 | break; | |
1394 | ||
1395 | case DW_OP_implicit_value: | |
1396 | printf ("DW_OP_implicit_value"); | |
cd30bcef | 1397 | READ_ULEB (uvalue, data, end); |
ef0b5f1c | 1398 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1399 | break; |
1400 | ||
19e6b90e L |
1401 | /* GNU extensions. */ |
1402 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1403 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1404 | break; |
1405 | case DW_OP_GNU_uninit: | |
1406 | printf ("DW_OP_GNU_uninit"); | |
1407 | /* FIXME: Is there data associated with this OP ? */ | |
1408 | break; | |
f1c4cc75 RH |
1409 | case DW_OP_GNU_encoded_addr: |
1410 | { | |
6937bb54 | 1411 | int encoding = 0; |
f1c4cc75 | 1412 | dwarf_vma addr; |
467c65bc | 1413 | |
6937bb54 NC |
1414 | if (data < end) |
1415 | encoding = *data++; | |
041830e0 | 1416 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1417 | |
1418 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1419 | print_dwarf_vma (addr, pointer_size); | |
1420 | } | |
1421 | break; | |
bc0a77d2 | 1422 | case DW_OP_implicit_pointer: |
b7807392 | 1423 | case DW_OP_GNU_implicit_pointer: |
d85bf2ba | 1424 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
b7807392 JJ |
1425 | this ought to be an 8-byte wide computation. */ |
1426 | if (dwarf_version == -1) | |
1427 | { | |
bc0a77d2 JK |
1428 | printf (_("(%s in frame info)"), |
1429 | (op == DW_OP_implicit_pointer | |
1430 | ? "DW_OP_implicit_pointer" | |
1431 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1432 | /* No way to tell where the next op is, so just bail. */ |
1433 | return need_frame_base; | |
1434 | } | |
1435 | if (dwarf_version == 2) | |
1436 | { | |
0c588247 | 1437 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1438 | } |
1439 | else | |
1440 | { | |
0c588247 | 1441 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1442 | } |
cd30bcef | 1443 | READ_SLEB (svalue, data, end); |
bc0a77d2 JK |
1444 | printf ("%s: <0x%s> %s", |
1445 | (op == DW_OP_implicit_pointer | |
1446 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 | 1447 | dwarf_vmatoa ("x", uvalue), |
cd30bcef | 1448 | dwarf_vmatoa ("d", svalue)); |
b7807392 | 1449 | break; |
77145576 | 1450 | case DW_OP_entry_value: |
0892011d | 1451 | case DW_OP_GNU_entry_value: |
cd30bcef | 1452 | READ_ULEB (uvalue, data, end); |
058037d3 NC |
1453 | /* PR 17531: file: 0cc9cd00. */ |
1454 | if (uvalue > (dwarf_vma) (end - data)) | |
1455 | uvalue = end - data; | |
77145576 JK |
1456 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1457 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1458 | if (decode_location_expression (data, pointer_size, offset_size, |
1459 | dwarf_version, uvalue, | |
1460 | cu_offset, section)) | |
1461 | need_frame_base = 1; | |
1462 | putchar (')'); | |
1463 | data += uvalue; | |
6937bb54 NC |
1464 | if (data > end) |
1465 | data = end; | |
0892011d | 1466 | break; |
bc0a77d2 | 1467 | case DW_OP_const_type: |
0892011d | 1468 | case DW_OP_GNU_const_type: |
cd30bcef | 1469 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1470 | printf ("%s: <0x%s> ", |
1471 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1472 | : "DW_OP_GNU_const_type"), | |
0892011d | 1473 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1474 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1475 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1476 | break; |
bc0a77d2 | 1477 | case DW_OP_regval_type: |
0892011d | 1478 | case DW_OP_GNU_regval_type: |
cd30bcef | 1479 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1480 | printf ("%s: %s (%s)", |
1481 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1482 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1483 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
cd30bcef | 1484 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1485 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1486 | break; | |
bc0a77d2 | 1487 | case DW_OP_deref_type: |
0892011d | 1488 | case DW_OP_GNU_deref_type: |
0c588247 | 1489 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1490 | printf ("%s: %ld", |
1491 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1492 | : "DW_OP_GNU_deref_type"), | |
1493 | (long) uvalue); | |
cd30bcef | 1494 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1495 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1496 | break; | |
bc0a77d2 | 1497 | case DW_OP_convert: |
0892011d | 1498 | case DW_OP_GNU_convert: |
cd30bcef | 1499 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1500 | printf ("%s <0x%s>", |
1501 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1502 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1503 | break; |
bc0a77d2 | 1504 | case DW_OP_reinterpret: |
0892011d | 1505 | case DW_OP_GNU_reinterpret: |
cd30bcef | 1506 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1507 | printf ("%s <0x%s>", |
1508 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1509 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1510 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1511 | break; | |
1512 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1513 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1514 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1515 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1516 | break; |
b4eb7656 | 1517 | case DW_OP_GNU_addr_index: |
cd30bcef | 1518 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1519 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1520 | break; | |
1521 | case DW_OP_GNU_const_index: | |
cd30bcef | 1522 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1523 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1524 | break; | |
f384a1f0 KB |
1525 | case DW_OP_GNU_variable_value: |
1526 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1527 | this ought to be an 8-byte wide computation. */ | |
1528 | if (dwarf_version == -1) | |
1529 | { | |
1530 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1531 | /* No way to tell where the next op is, so just bail. */ | |
1532 | return need_frame_base; | |
1533 | } | |
1534 | if (dwarf_version == 2) | |
1535 | { | |
1536 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1537 | } | |
1538 | else | |
1539 | { | |
1540 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1541 | } | |
1542 | printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1543 | break; | |
e2a0d921 NC |
1544 | |
1545 | /* HP extensions. */ | |
1546 | case DW_OP_HP_is_value: | |
1547 | printf ("DW_OP_HP_is_value"); | |
1548 | /* FIXME: Is there data associated with this OP ? */ | |
1549 | break; | |
1550 | case DW_OP_HP_fltconst4: | |
1551 | printf ("DW_OP_HP_fltconst4"); | |
1552 | /* FIXME: Is there data associated with this OP ? */ | |
1553 | break; | |
1554 | case DW_OP_HP_fltconst8: | |
1555 | printf ("DW_OP_HP_fltconst8"); | |
1556 | /* FIXME: Is there data associated with this OP ? */ | |
1557 | break; | |
1558 | case DW_OP_HP_mod_range: | |
1559 | printf ("DW_OP_HP_mod_range"); | |
1560 | /* FIXME: Is there data associated with this OP ? */ | |
1561 | break; | |
1562 | case DW_OP_HP_unmod_range: | |
1563 | printf ("DW_OP_HP_unmod_range"); | |
1564 | /* FIXME: Is there data associated with this OP ? */ | |
1565 | break; | |
1566 | case DW_OP_HP_tls: | |
1567 | printf ("DW_OP_HP_tls"); | |
1568 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1569 | break; |
1570 | ||
35d60fe4 NC |
1571 | /* PGI (STMicroelectronics) extensions. */ |
1572 | case DW_OP_PGI_omp_thread_num: | |
1573 | /* Pushes the thread number for the current thread as it would be | |
1574 | returned by the standard OpenMP library function: | |
1575 | omp_get_thread_num(). The "current thread" is the thread for | |
1576 | which the expression is being evaluated. */ | |
1577 | printf ("DW_OP_PGI_omp_thread_num"); | |
1578 | break; | |
1579 | ||
19e6b90e L |
1580 | default: |
1581 | if (op >= DW_OP_lo_user | |
1582 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1583 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1584 | else |
0502a2b4 | 1585 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1586 | /* No way to tell where the next op is, so just bail. */ |
1587 | return need_frame_base; | |
1588 | } | |
1589 | ||
1590 | /* Separate the ops. */ | |
1591 | if (data < end) | |
1592 | printf ("; "); | |
1593 | } | |
1594 | ||
1595 | return need_frame_base; | |
1596 | } | |
1597 | ||
341f9135 CC |
1598 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1599 | This is used for DWARF package files. */ | |
1600 | ||
1601 | static struct cu_tu_set * | |
1602 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1603 | { | |
1604 | struct cu_tu_set *p; | |
1605 | unsigned int nsets; | |
1606 | unsigned int dw_sect; | |
1607 | ||
1608 | if (do_types) | |
1609 | { | |
1610 | p = tu_sets; | |
1611 | nsets = tu_count; | |
1612 | dw_sect = DW_SECT_TYPES; | |
1613 | } | |
1614 | else | |
1615 | { | |
1616 | p = cu_sets; | |
1617 | nsets = cu_count; | |
1618 | dw_sect = DW_SECT_INFO; | |
1619 | } | |
1620 | while (nsets > 0) | |
1621 | { | |
1622 | if (p->section_offsets [dw_sect] == cu_offset) | |
1623 | return p; | |
1624 | p++; | |
1625 | nsets--; | |
1626 | } | |
1627 | return NULL; | |
1628 | } | |
1629 | ||
a69c4772 NC |
1630 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1631 | static void | |
1632 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1633 | { | |
1634 | dwarf_vma tmp = * low_bits; | |
1635 | ||
1636 | tmp += inc; | |
1637 | ||
1638 | /* FIXME: There is probably a better way of handling this: | |
1639 | ||
1640 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1641 | type. Plus regardless of its size LOW_BITS is meant to | |
1642 | only hold 32-bits, so if there is overflow or wrap around | |
1643 | we must propagate into HIGH_BITS. */ | |
1644 | if (tmp < * low_bits) | |
1645 | { | |
1646 | ++ * high_bits; | |
1647 | } | |
1648 | else if (sizeof (tmp) > 8 | |
1649 | && (tmp >> 31) > 1) | |
1650 | { | |
1651 | ++ * high_bits; | |
1652 | tmp &= 0xFFFFFFFF; | |
1653 | } | |
1654 | ||
1655 | * low_bits = tmp; | |
1656 | } | |
1657 | ||
dda8d76d NC |
1658 | static const char * |
1659 | fetch_alt_indirect_string (dwarf_vma offset) | |
1660 | { | |
24841daa | 1661 | separate_info * i; |
dda8d76d NC |
1662 | |
1663 | if (! do_follow_links) | |
1664 | return ""; | |
1665 | ||
24841daa NC |
1666 | if (first_separate_info == NULL) |
1667 | return _("<no links available>"); | |
dda8d76d | 1668 | |
24841daa NC |
1669 | for (i = first_separate_info; i != NULL; i = i->next) |
1670 | { | |
1671 | struct dwarf_section * section; | |
1672 | const char * ret; | |
dda8d76d | 1673 | |
24841daa NC |
1674 | if (! load_debug_section (separate_debug_str, i->handle)) |
1675 | continue; | |
dda8d76d | 1676 | |
24841daa | 1677 | section = &debug_displays [separate_debug_str].section; |
dda8d76d | 1678 | |
24841daa NC |
1679 | if (section->start == NULL) |
1680 | continue; | |
dda8d76d | 1681 | |
24841daa NC |
1682 | if (offset >= section->size) |
1683 | continue; | |
1684 | ||
1685 | ret = (const char *) (section->start + offset); | |
1686 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1687 | NUL byte. Since our caller is expecting to receive a well formed C | |
1688 | string we test for the lack of a terminating byte here. */ | |
1689 | if (strnlen ((const char *) ret, section->size - offset) | |
1690 | == section->size - offset) | |
1691 | return _("<no NUL byte at end of alt .debug_str section>"); | |
1692 | ||
1693 | return ret; | |
1694 | } | |
1695 | ||
1696 | warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"), | |
1697 | dwarf_vmatoa ("x", offset)); | |
1698 | return _("<offset is too big>"); | |
dda8d76d NC |
1699 | } |
1700 | ||
d85bf2ba NC |
1701 | static const char * |
1702 | get_AT_name (unsigned long attribute) | |
1703 | { | |
1704 | const char *name; | |
1705 | ||
1706 | if (attribute == 0) | |
1707 | return "DW_AT value: 0"; | |
1708 | ||
1709 | /* One value is shared by the MIPS and HP extensions: */ | |
1710 | if (attribute == DW_AT_MIPS_fde) | |
1711 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1712 | ||
1713 | name = get_DW_AT_name (attribute); | |
1714 | ||
1715 | if (name == NULL) | |
1716 | { | |
1717 | static char buffer[100]; | |
1718 | ||
1719 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1720 | attribute); | |
1721 | return buffer; | |
1722 | } | |
1723 | ||
1724 | return name; | |
1725 | } | |
1726 | ||
24841daa NC |
1727 | static void |
1728 | add_dwo_info (const char * field, dwo_type type) | |
1729 | { | |
1730 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); | |
1731 | ||
1732 | dwinfo->type = type; | |
1733 | dwinfo->value = field; | |
1734 | dwinfo->next = first_dwo_info; | |
1735 | first_dwo_info = dwinfo; | |
1736 | } | |
1737 | ||
1738 | static void | |
1739 | add_dwo_name (const char * name) | |
1740 | { | |
1741 | add_dwo_info (name, DWO_NAME); | |
1742 | } | |
1743 | ||
1744 | static void | |
1745 | add_dwo_dir (const char * dir) | |
1746 | { | |
1747 | add_dwo_info (dir, DWO_DIR); | |
1748 | } | |
1749 | ||
1750 | static void | |
1751 | add_dwo_id (const char * id) | |
1752 | { | |
1753 | add_dwo_info (id, DWO_ID); | |
1754 | } | |
1755 | ||
1756 | static void | |
1757 | free_dwo_info (void) | |
1758 | { | |
1759 | dwo_info * dwinfo; | |
1760 | dwo_info * next; | |
1761 | ||
1762 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) | |
1763 | { | |
1764 | next = dwinfo->next; | |
1765 | free (dwinfo); | |
1766 | } | |
1767 | first_dwo_info = NULL; | |
1768 | } | |
1769 | ||
afc72f15 NC |
1770 | /* Ensure that START + UVALUE is less than END. |
1771 | Return an adjusted UVALUE if necessary to ensure this relationship. */ | |
1772 | ||
1773 | static inline dwarf_vma | |
1774 | check_uvalue (const unsigned char * start, | |
1775 | dwarf_vma uvalue, | |
1776 | const unsigned char * end) | |
1777 | { | |
1778 | dwarf_vma max_uvalue = end - start; | |
1779 | ||
afc72f15 NC |
1780 | /* See PR 17512: file: 008-103549-0.001:0.1. |
1781 | and PR 24829 for examples of where these tests are triggered. */ | |
a85eba51 | 1782 | if (uvalue > max_uvalue) |
afc72f15 NC |
1783 | { |
1784 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1785 | uvalue = max_uvalue; | |
1786 | } | |
1787 | ||
1788 | return uvalue; | |
1789 | } | |
1790 | ||
ec1b0fbb NC |
1791 | static unsigned char * |
1792 | skip_attr_bytes (unsigned long form, | |
1793 | unsigned char * data, | |
1794 | unsigned const char * end, | |
1795 | dwarf_vma pointer_size, | |
1796 | dwarf_vma offset_size, | |
1797 | int dwarf_version, | |
1798 | dwarf_vma * value_return) | |
1799 | { | |
cd30bcef AM |
1800 | dwarf_signed_vma svalue; |
1801 | dwarf_vma uvalue = 0; | |
ec1b0fbb NC |
1802 | |
1803 | * value_return = 0; | |
1804 | ||
1805 | switch (form) | |
1806 | { | |
1807 | case DW_FORM_ref_addr: | |
1808 | if (dwarf_version == 2) | |
1809 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1810 | else if (dwarf_version == 3 || dwarf_version == 4) | |
1811 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1812 | else | |
1813 | return NULL; | |
1814 | break; | |
1815 | ||
1816 | case DW_FORM_addr: | |
1817 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1818 | break; | |
1819 | ||
1820 | case DW_FORM_strp: | |
1821 | case DW_FORM_line_strp: | |
1822 | case DW_FORM_sec_offset: | |
1823 | case DW_FORM_GNU_ref_alt: | |
1824 | case DW_FORM_GNU_strp_alt: | |
1825 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1826 | break; | |
1827 | ||
1828 | case DW_FORM_flag_present: | |
1829 | uvalue = 1; | |
1830 | break; | |
1831 | ||
1832 | case DW_FORM_ref1: | |
1833 | case DW_FORM_flag: | |
1834 | case DW_FORM_data1: | |
1835 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
1836 | break; | |
1837 | ||
1838 | case DW_FORM_ref2: | |
1839 | case DW_FORM_data2: | |
1840 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); | |
1841 | break; | |
1842 | ||
1843 | case DW_FORM_ref4: | |
1844 | case DW_FORM_data4: | |
1845 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1846 | break; | |
1847 | ||
1848 | case DW_FORM_sdata: | |
cd30bcef AM |
1849 | READ_SLEB (svalue, data, end); |
1850 | uvalue = svalue; | |
ec1b0fbb NC |
1851 | break; |
1852 | ||
1853 | case DW_FORM_ref_udata: | |
1854 | case DW_FORM_udata: | |
1855 | case DW_FORM_GNU_str_index: | |
1856 | case DW_FORM_GNU_addr_index: | |
cd30bcef | 1857 | READ_ULEB (uvalue, data, end); |
ec1b0fbb NC |
1858 | break; |
1859 | ||
1860 | case DW_FORM_ref8: | |
1861 | case DW_FORM_data8: | |
1862 | data += 8; | |
1863 | break; | |
1864 | ||
1865 | case DW_FORM_data16: | |
1866 | data += 16; | |
1867 | break; | |
1868 | ||
1869 | case DW_FORM_string: | |
1870 | data += strnlen ((char *) data, end - data) + 1; | |
1871 | break; | |
1872 | ||
1873 | case DW_FORM_block: | |
1874 | case DW_FORM_exprloc: | |
cd30bcef | 1875 | READ_ULEB (uvalue, data, end); |
ec1b0fbb NC |
1876 | break; |
1877 | ||
1878 | case DW_FORM_block1: | |
1879 | SAFE_BYTE_GET (uvalue, data, 1, end); | |
1880 | data += 1 + uvalue; | |
1881 | break; | |
1882 | ||
1883 | case DW_FORM_block2: | |
1884 | SAFE_BYTE_GET (uvalue, data, 2, end); | |
1885 | data += 2 + uvalue; | |
1886 | break; | |
1887 | ||
1888 | case DW_FORM_block4: | |
1889 | SAFE_BYTE_GET (uvalue, data, 4, end); | |
1890 | data += 4 + uvalue; | |
1891 | break; | |
1892 | ||
1893 | case DW_FORM_ref_sig8: | |
1894 | data += 8; | |
1895 | break; | |
1896 | ||
1897 | case DW_FORM_indirect: | |
1898 | /* FIXME: Handle this form. */ | |
1899 | default: | |
1900 | return NULL; | |
1901 | } | |
1902 | ||
1903 | * value_return = uvalue; | |
1904 | if (data > end) | |
1905 | data = (unsigned char *) end; | |
1906 | return data; | |
1907 | } | |
1908 | ||
1909 | /* Return IS_SIGNED set to TRUE if the type at | |
1910 | DATA can be determined to be a signed type. */ | |
1911 | ||
1912 | static void | |
1913 | get_type_signedness (unsigned char * start, | |
1914 | unsigned char * data, | |
1915 | unsigned const char * end, | |
1916 | dwarf_vma pointer_size, | |
1917 | dwarf_vma offset_size, | |
1918 | int dwarf_version, | |
1919 | bfd_boolean * is_signed, | |
1920 | bfd_boolean is_nested) | |
1921 | { | |
1922 | unsigned long abbrev_number; | |
ec1b0fbb NC |
1923 | abbrev_entry * entry; |
1924 | abbrev_attr * attr; | |
1925 | ||
1926 | * is_signed = FALSE; | |
1927 | ||
cd30bcef | 1928 | READ_ULEB (abbrev_number, data, end); |
ec1b0fbb NC |
1929 | |
1930 | for (entry = first_abbrev; | |
1931 | entry != NULL && entry->entry != abbrev_number; | |
1932 | entry = entry->next) | |
1933 | continue; | |
1934 | ||
1935 | if (entry == NULL) | |
1936 | /* FIXME: Issue a warning ? */ | |
1937 | return; | |
1938 | ||
1939 | for (attr = entry->first_attr; | |
1940 | attr != NULL && attr->attribute; | |
1941 | attr = attr->next) | |
1942 | { | |
1943 | dwarf_vma uvalue = 0; | |
1944 | ||
1945 | data = skip_attr_bytes (attr->form, data, end, pointer_size, | |
1946 | offset_size, dwarf_version, & uvalue); | |
1947 | if (data == NULL) | |
1948 | return; | |
1949 | ||
1950 | switch (attr->attribute) | |
1951 | { | |
1952 | #if 0 /* FIXME: It would be nice to print the name of the type, | |
1953 | but this would mean updating a lot of binutils tests. */ | |
1954 | case DW_AT_name: | |
1955 | if (attr->form == DW_FORM_strp) | |
1956 | printf ("%s", fetch_indirect_string (uvalue)); | |
1957 | break; | |
1958 | #endif | |
1959 | case DW_AT_type: | |
1960 | /* Recurse. */ | |
1961 | if (is_nested) | |
1962 | { | |
1963 | /* FIXME: Warn - or is this expected ? | |
1964 | NB/ We need to avoid infinite recursion. */ | |
1965 | return; | |
1966 | } | |
b3fe587e AM |
1967 | if (uvalue >= (size_t) (end - start)) |
1968 | return; | |
ec1b0fbb NC |
1969 | get_type_signedness (start, start + uvalue, end, pointer_size, |
1970 | offset_size, dwarf_version, is_signed, TRUE); | |
1971 | break; | |
1972 | ||
1973 | case DW_AT_encoding: | |
1974 | /* Determine signness. */ | |
1975 | switch (uvalue) | |
1976 | { | |
1977 | case DW_ATE_address: | |
1978 | /* FIXME - some architectures have signed addresses. */ | |
1979 | case DW_ATE_boolean: | |
1980 | case DW_ATE_unsigned: | |
1981 | case DW_ATE_unsigned_char: | |
1982 | case DW_ATE_unsigned_fixed: | |
1983 | * is_signed = FALSE; | |
1984 | break; | |
1985 | ||
1986 | default: | |
1987 | case DW_ATE_complex_float: | |
1988 | case DW_ATE_float: | |
1989 | case DW_ATE_signed: | |
1990 | case DW_ATE_signed_char: | |
1991 | case DW_ATE_imaginary_float: | |
1992 | case DW_ATE_decimal_float: | |
1993 | case DW_ATE_signed_fixed: | |
1994 | * is_signed = TRUE; | |
1995 | break; | |
1996 | } | |
1997 | break; | |
1998 | } | |
1999 | } | |
2000 | } | |
2001 | ||
2002 | static void | |
2003 | read_and_print_leb128 (unsigned char * data, | |
2004 | unsigned int * bytes_read, | |
2005 | unsigned const char * end, | |
2006 | bfd_boolean is_signed) | |
2007 | { | |
cd30bcef AM |
2008 | int status; |
2009 | dwarf_vma val = read_leb128 (data, end, is_signed, bytes_read, &status); | |
2010 | if (status != 0) | |
2011 | report_leb_status (status); | |
ec1b0fbb | 2012 | else |
cd30bcef | 2013 | printf ("%s", dwarf_vmatoa (is_signed ? "d" : "u", val)); |
ec1b0fbb NC |
2014 | } |
2015 | ||
2016 | static void | |
2017 | display_discr_list (unsigned long form, | |
2018 | dwarf_vma uvalue, | |
2019 | unsigned char * data, | |
2020 | unsigned const char * end, | |
2021 | int level) | |
2022 | { | |
2023 | if (uvalue == 0) | |
2024 | { | |
2025 | printf ("[default]"); | |
2026 | return; | |
2027 | } | |
2028 | ||
2029 | switch (form) | |
2030 | { | |
2031 | case DW_FORM_block: | |
2032 | case DW_FORM_block1: | |
2033 | case DW_FORM_block2: | |
2034 | case DW_FORM_block4: | |
2035 | /* Move data pointer back to the start of the byte array. */ | |
2036 | data -= uvalue; | |
2037 | break; | |
2038 | default: | |
2039 | printf ("<corrupt>\n"); | |
2040 | warn (_("corrupt discr_list - not using a block form\n")); | |
2041 | return; | |
2042 | } | |
2043 | ||
2044 | if (uvalue < 2) | |
2045 | { | |
2046 | printf ("<corrupt>\n"); | |
2047 | warn (_("corrupt discr_list - block not long enough\n")); | |
2048 | return; | |
2049 | } | |
2050 | ||
2051 | bfd_boolean is_signed = | |
2052 | (level > 0 && level <= MAX_CU_NESTING) | |
2053 | ? level_type_signed [level - 1] : FALSE; | |
2054 | ||
2055 | printf ("("); | |
2056 | while (uvalue) | |
2057 | { | |
2058 | unsigned char discriminant; | |
2059 | unsigned int bytes_read; | |
2060 | ||
2061 | SAFE_BYTE_GET (discriminant, data, 1, end); | |
2062 | -- uvalue; | |
2063 | data ++; | |
2064 | ||
2065 | assert (uvalue > 0); | |
2066 | switch (discriminant) | |
2067 | { | |
2068 | case DW_DSC_label: | |
2069 | printf ("label "); | |
2070 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2071 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2072 | uvalue -= bytes_read; | |
2073 | data += bytes_read; | |
2074 | break; | |
2075 | ||
2076 | case DW_DSC_range: | |
2077 | printf ("range "); | |
2078 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2079 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2080 | uvalue -= bytes_read; | |
2081 | data += bytes_read; | |
2082 | ||
2083 | printf (".."); | |
2084 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2085 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2086 | uvalue -= bytes_read; | |
2087 | data += bytes_read; | |
2088 | break; | |
2089 | ||
2090 | default: | |
2091 | printf ("<corrupt>\n"); | |
2092 | warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"), | |
2093 | discriminant); | |
2094 | return; | |
2095 | } | |
2096 | ||
2097 | if (uvalue) | |
2098 | printf (", "); | |
2099 | } | |
2100 | ||
2101 | if (is_signed) | |
2102 | printf (")(signed)"); | |
2103 | else | |
2104 | printf (")(unsigned)"); | |
2105 | } | |
2106 | ||
19e6b90e | 2107 | static unsigned char * |
dda8d76d NC |
2108 | read_and_display_attr_value (unsigned long attribute, |
2109 | unsigned long form, | |
2110 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 2111 | unsigned char * start, |
dda8d76d NC |
2112 | unsigned char * data, |
2113 | unsigned char * end, | |
2114 | dwarf_vma cu_offset, | |
2115 | dwarf_vma pointer_size, | |
2116 | dwarf_vma offset_size, | |
2117 | int dwarf_version, | |
2118 | debug_info * debug_info_p, | |
2119 | int do_loc, | |
2120 | struct dwarf_section * section, | |
2121 | struct cu_tu_set * this_set, | |
ec1b0fbb NC |
2122 | char delimiter, |
2123 | int level) | |
19e6b90e | 2124 | { |
cd30bcef | 2125 | dwarf_signed_vma svalue; |
ec1b0fbb NC |
2126 | dwarf_vma uvalue = 0; |
2127 | unsigned char * block_start = NULL; | |
2128 | unsigned char * orig_data = data; | |
19e6b90e | 2129 | |
f41e4712 | 2130 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 2131 | { |
f41e4712 | 2132 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
2133 | return data; |
2134 | } | |
2135 | ||
19e6b90e L |
2136 | switch (form) |
2137 | { | |
2138 | default: | |
2139 | break; | |
2140 | ||
2141 | case DW_FORM_ref_addr: | |
2142 | if (dwarf_version == 2) | |
0c588247 | 2143 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
932fd279 | 2144 | else if (dwarf_version == 3 || dwarf_version == 4) |
0c588247 | 2145 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 2146 | else |
467c65bc NC |
2147 | error (_("Internal error: DWARF version is not 2, 3 or 4.\n")); |
2148 | ||
19e6b90e L |
2149 | break; |
2150 | ||
2151 | case DW_FORM_addr: | |
0c588247 | 2152 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
2153 | break; |
2154 | ||
2155 | case DW_FORM_strp: | |
77145576 | 2156 | case DW_FORM_line_strp: |
932fd279 | 2157 | case DW_FORM_sec_offset: |
a081f3cd JJ |
2158 | case DW_FORM_GNU_ref_alt: |
2159 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 2160 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
2161 | break; |
2162 | ||
932fd279 JJ |
2163 | case DW_FORM_flag_present: |
2164 | uvalue = 1; | |
2165 | break; | |
2166 | ||
19e6b90e L |
2167 | case DW_FORM_ref1: |
2168 | case DW_FORM_flag: | |
2169 | case DW_FORM_data1: | |
0c588247 | 2170 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
2171 | break; |
2172 | ||
2173 | case DW_FORM_ref2: | |
2174 | case DW_FORM_data2: | |
0c588247 | 2175 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
2176 | break; |
2177 | ||
2178 | case DW_FORM_ref4: | |
2179 | case DW_FORM_data4: | |
0c588247 | 2180 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
2181 | break; |
2182 | ||
2183 | case DW_FORM_sdata: | |
cd30bcef AM |
2184 | READ_SLEB (svalue, data, end); |
2185 | uvalue = svalue; | |
19e6b90e L |
2186 | break; |
2187 | ||
4723351a | 2188 | case DW_FORM_GNU_str_index: |
19e6b90e L |
2189 | case DW_FORM_ref_udata: |
2190 | case DW_FORM_udata: | |
cd30bcef AM |
2191 | case DW_FORM_GNU_addr_index: |
2192 | READ_ULEB (uvalue, data, end); | |
19e6b90e L |
2193 | break; |
2194 | ||
2195 | case DW_FORM_indirect: | |
cd30bcef | 2196 | READ_ULEB (form, data, end); |
19e6b90e | 2197 | if (!do_loc) |
ef0b5f1c | 2198 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 | 2199 | if (form == DW_FORM_implicit_const) |
cd30bcef | 2200 | READ_SLEB (implicit_const, data, end); |
ec1b0fbb NC |
2201 | return read_and_display_attr_value (attribute, form, implicit_const, |
2202 | start, data, end, | |
2203 | cu_offset, pointer_size, | |
19e6b90e | 2204 | offset_size, dwarf_version, |
ec4d4525 | 2205 | debug_info_p, do_loc, |
ec1b0fbb | 2206 | section, this_set, delimiter, level); |
19e6b90e L |
2207 | } |
2208 | ||
2209 | switch (form) | |
2210 | { | |
2211 | case DW_FORM_ref_addr: | |
2212 | if (!do_loc) | |
ef0b5f1c | 2213 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
19e6b90e L |
2214 | break; |
2215 | ||
a081f3cd JJ |
2216 | case DW_FORM_GNU_ref_alt: |
2217 | if (!do_loc) | |
ef0b5f1c | 2218 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
dda8d76d | 2219 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
2220 | break; |
2221 | ||
19e6b90e L |
2222 | case DW_FORM_ref1: |
2223 | case DW_FORM_ref2: | |
2224 | case DW_FORM_ref4: | |
2225 | case DW_FORM_ref_udata: | |
2226 | if (!do_loc) | |
ef0b5f1c | 2227 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
2228 | break; |
2229 | ||
2230 | case DW_FORM_data4: | |
2231 | case DW_FORM_addr: | |
932fd279 | 2232 | case DW_FORM_sec_offset: |
19e6b90e | 2233 | if (!do_loc) |
ef0b5f1c | 2234 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2235 | break; |
2236 | ||
932fd279 | 2237 | case DW_FORM_flag_present: |
19e6b90e L |
2238 | case DW_FORM_flag: |
2239 | case DW_FORM_data1: | |
2240 | case DW_FORM_data2: | |
2241 | case DW_FORM_sdata: | |
2242 | case DW_FORM_udata: | |
2243 | if (!do_loc) | |
ef0b5f1c | 2244 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
2245 | break; |
2246 | ||
77145576 JK |
2247 | case DW_FORM_implicit_const: |
2248 | if (!do_loc) | |
2249 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
2250 | break; | |
2251 | ||
19e6b90e L |
2252 | case DW_FORM_ref8: |
2253 | case DW_FORM_data8: | |
2bc8690c | 2254 | if (!do_loc) |
19e6b90e | 2255 | { |
74bc6052 | 2256 | dwarf_vma high_bits; |
a69c4772 | 2257 | dwarf_vma utmp; |
74bc6052 CC |
2258 | char buf[64]; |
2259 | ||
0c588247 | 2260 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
2261 | utmp = uvalue; |
2262 | if (form == DW_FORM_ref8) | |
2263 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 2264 | printf ("%c0x%s", delimiter, |
a69c4772 | 2265 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 2266 | } |
0c588247 | 2267 | |
19e6b90e L |
2268 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2269 | && num_debug_info_entries == 0) | |
2270 | { | |
2271 | if (sizeof (uvalue) == 8) | |
0c588247 | 2272 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 2273 | else |
467c65bc | 2274 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 2275 | } |
0c588247 | 2276 | |
19e6b90e L |
2277 | data += 8; |
2278 | break; | |
2279 | ||
2f6cd591 JK |
2280 | case DW_FORM_data16: |
2281 | if (!do_loc) | |
2282 | { | |
2283 | dwarf_vma left_high_bits, left_low_bits; | |
2284 | dwarf_vma right_high_bits, right_low_bits; | |
2285 | ||
2286 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
2287 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
2288 | if (byte_get == byte_get_little_endian) | |
2289 | { | |
2290 | /* Swap them. */ | |
2291 | left_high_bits ^= right_high_bits; | |
2292 | right_high_bits ^= left_high_bits; | |
2293 | left_high_bits ^= right_high_bits; | |
2294 | left_low_bits ^= right_low_bits; | |
2295 | right_low_bits ^= left_low_bits; | |
2296 | left_low_bits ^= right_low_bits; | |
2297 | } | |
2298 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
2299 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
2300 | left_high_bits, left_low_bits, right_high_bits, | |
2301 | right_low_bits); | |
2302 | } | |
2303 | data += 16; | |
2304 | break; | |
2305 | ||
19e6b90e L |
2306 | case DW_FORM_string: |
2307 | if (!do_loc) | |
ef0b5f1c | 2308 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 2309 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
2310 | break; |
2311 | ||
2312 | case DW_FORM_block: | |
932fd279 | 2313 | case DW_FORM_exprloc: |
cd30bcef AM |
2314 | READ_ULEB (uvalue, data, end); |
2315 | do_block: | |
2316 | block_start = data; | |
a1165289 NC |
2317 | if (block_start >= end) |
2318 | { | |
2319 | warn (_("Block ends prematurely\n")); | |
2320 | uvalue = 0; | |
2321 | block_start = end; | |
2322 | } | |
afc72f15 NC |
2323 | |
2324 | uvalue = check_uvalue (block_start, uvalue, end); | |
2325 | ||
19e6b90e L |
2326 | if (do_loc) |
2327 | data = block_start + uvalue; | |
2328 | else | |
ef0b5f1c | 2329 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2330 | break; |
2331 | ||
2332 | case DW_FORM_block1: | |
cd30bcef AM |
2333 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2334 | goto do_block; | |
19e6b90e L |
2335 | |
2336 | case DW_FORM_block2: | |
cd30bcef AM |
2337 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2338 | goto do_block; | |
19e6b90e L |
2339 | |
2340 | case DW_FORM_block4: | |
cd30bcef AM |
2341 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2342 | goto do_block; | |
19e6b90e L |
2343 | |
2344 | case DW_FORM_strp: | |
2345 | if (!do_loc) | |
ef0b5f1c | 2346 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, |
47704ddf KT |
2347 | dwarf_vmatoa ("x", uvalue), |
2348 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
2349 | break; |
2350 | ||
77145576 JK |
2351 | case DW_FORM_line_strp: |
2352 | if (!do_loc) | |
2353 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2354 | dwarf_vmatoa ("x", uvalue), | |
2355 | fetch_indirect_line_string (uvalue)); | |
2356 | break; | |
2357 | ||
4723351a CC |
2358 | case DW_FORM_GNU_str_index: |
2359 | if (!do_loc) | |
b4eb7656 | 2360 | { |
d85bf2ba NC |
2361 | const char * suffix = strrchr (section->name, '.'); |
2362 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
b4eb7656 | 2363 | |
ef0b5f1c | 2364 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2365 | dwarf_vmatoa ("x", uvalue), |
2366 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2367 | } | |
4723351a CC |
2368 | break; |
2369 | ||
a081f3cd JJ |
2370 | case DW_FORM_GNU_strp_alt: |
2371 | if (!do_loc) | |
dda8d76d NC |
2372 | { |
2373 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2374 | dwarf_vmatoa ("x", uvalue), | |
2375 | fetch_alt_indirect_string (uvalue)); | |
2376 | } | |
a081f3cd JJ |
2377 | break; |
2378 | ||
19e6b90e L |
2379 | case DW_FORM_indirect: |
2380 | /* Handled above. */ | |
2381 | break; | |
2382 | ||
2b6f5997 CC |
2383 | case DW_FORM_ref_sig8: |
2384 | if (!do_loc) | |
2385 | { | |
74bc6052 CC |
2386 | dwarf_vma high_bits; |
2387 | char buf[64]; | |
2388 | ||
0c588247 | 2389 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
ef0b5f1c | 2390 | printf ("%csignature: 0x%s", delimiter, |
74bc6052 | 2391 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); |
2b6f5997 | 2392 | } |
74bc6052 | 2393 | data += 8; |
2b6f5997 CC |
2394 | break; |
2395 | ||
4723351a CC |
2396 | case DW_FORM_GNU_addr_index: |
2397 | if (!do_loc) | |
ef0b5f1c | 2398 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2399 | dwarf_vmatoa ("x", uvalue), |
2400 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
4723351a CC |
2401 | break; |
2402 | ||
19e6b90e L |
2403 | default: |
2404 | warn (_("Unrecognized form: %lu\n"), form); | |
2405 | break; | |
2406 | } | |
2407 | ||
19e6b90e | 2408 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2409 | && num_debug_info_entries == 0 |
2410 | && debug_info_p != NULL) | |
19e6b90e L |
2411 | { |
2412 | switch (attribute) | |
2413 | { | |
2414 | case DW_AT_frame_base: | |
2415 | have_frame_base = 1; | |
1a0670f3 | 2416 | /* Fall through. */ |
19e6b90e | 2417 | case DW_AT_location: |
9f272209 | 2418 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2419 | case DW_AT_string_length: |
2420 | case DW_AT_return_addr: | |
19e6b90e L |
2421 | case DW_AT_data_member_location: |
2422 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2423 | case DW_AT_segment: |
2424 | case DW_AT_static_link: | |
2425 | case DW_AT_use_location: | |
bc0a77d2 | 2426 | case DW_AT_call_value: |
629e7ca8 | 2427 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2428 | case DW_AT_call_data_value: |
629e7ca8 | 2429 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2430 | case DW_AT_call_target: |
629e7ca8 | 2431 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2432 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2433 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2434 | if ((dwarf_version < 4 |
212b6063 | 2435 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2436 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2437 | { |
2438 | /* Process location list. */ | |
91d6fa6a | 2439 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2440 | unsigned int num = debug_info_p->num_loc_offsets; |
2441 | ||
91d6fa6a | 2442 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2443 | { |
91d6fa6a | 2444 | lmax += 1024; |
467c65bc | 2445 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2446 | xcrealloc (debug_info_p->loc_offsets, |
2447 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2448 | debug_info_p->loc_views = (dwarf_vma *) |
2449 | xcrealloc (debug_info_p->loc_views, | |
2450 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2451 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2452 | xcrealloc (debug_info_p->have_frame_base, |
2453 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2454 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2455 | } |
341f9135 | 2456 | if (this_set != NULL) |
b4eb7656 | 2457 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2458 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2459 | if (attribute != DW_AT_GNU_locviews) |
2460 | { | |
a7504f87 NC |
2461 | /* Corrupt DWARF info can produce more offsets than views. |
2462 | See PR 23062 for an example. */ | |
2463 | if (debug_info_p->num_loc_offsets | |
2464 | > debug_info_p->num_loc_views) | |
2465 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2466 | else | |
2467 | { | |
2468 | debug_info_p->loc_offsets [num] = uvalue; | |
2469 | debug_info_p->num_loc_offsets++; | |
2470 | } | |
9f272209 AO |
2471 | } |
2472 | else | |
2473 | { | |
2474 | assert (debug_info_p->num_loc_views <= num); | |
2475 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2476 | if (num > debug_info_p->num_loc_offsets) |
2477 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2478 | else | |
2479 | { | |
2480 | debug_info_p->loc_views [num] = uvalue; | |
2481 | debug_info_p->num_loc_views++; | |
2482 | } | |
9f272209 | 2483 | } |
19e6b90e L |
2484 | } |
2485 | break; | |
e2a0d921 | 2486 | |
19e6b90e L |
2487 | case DW_AT_low_pc: |
2488 | if (need_base_address) | |
2489 | debug_info_p->base_address = uvalue; | |
2490 | break; | |
2491 | ||
4723351a | 2492 | case DW_AT_GNU_addr_base: |
b4eb7656 | 2493 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2494 | break; |
2495 | ||
2496 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2497 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2498 | break; |
2499 | ||
19e6b90e | 2500 | case DW_AT_ranges: |
b4eb7656 | 2501 | if ((dwarf_version < 4 |
212b6063 | 2502 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2503 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2504 | { |
2505 | /* Process range list. */ | |
91d6fa6a | 2506 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2507 | unsigned int num = debug_info_p->num_range_lists; |
2508 | ||
91d6fa6a | 2509 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2510 | { |
91d6fa6a | 2511 | lmax += 1024; |
467c65bc | 2512 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2513 | xcrealloc (debug_info_p->range_lists, |
2514 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2515 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2516 | } |
2517 | debug_info_p->range_lists [num] = uvalue; | |
2518 | debug_info_p->num_range_lists++; | |
2519 | } | |
2520 | break; | |
2521 | ||
d85bf2ba NC |
2522 | case DW_AT_GNU_dwo_name: |
2523 | case DW_AT_dwo_name: | |
2524 | if (need_dwo_info) | |
2525 | switch (form) | |
2526 | { | |
2527 | case DW_FORM_strp: | |
24841daa | 2528 | add_dwo_name ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba NC |
2529 | break; |
2530 | case DW_FORM_GNU_str_index: | |
24841daa | 2531 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2532 | break; |
2533 | case DW_FORM_string: | |
24841daa | 2534 | add_dwo_name ((const char *) orig_data); |
d85bf2ba NC |
2535 | break; |
2536 | default: | |
2537 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2538 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2539 | break; |
2540 | } | |
2541 | break; | |
2542 | ||
2543 | case DW_AT_comp_dir: | |
2544 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2545 | if (need_dwo_info) | |
2546 | switch (form) | |
2547 | { | |
2548 | case DW_FORM_strp: | |
24841daa | 2549 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba NC |
2550 | break; |
2551 | case DW_FORM_line_strp: | |
24841daa | 2552 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue)); |
d85bf2ba NC |
2553 | break; |
2554 | case DW_FORM_GNU_str_index: | |
24841daa | 2555 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2556 | break; |
2557 | case DW_FORM_string: | |
24841daa | 2558 | add_dwo_dir ((const char *) orig_data); |
d85bf2ba NC |
2559 | break; |
2560 | default: | |
2561 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2562 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2563 | break; |
2564 | } | |
2565 | break; | |
2566 | ||
2567 | case DW_AT_GNU_dwo_id: | |
2568 | if (need_dwo_info) | |
2569 | switch (form) | |
2570 | { | |
2571 | case DW_FORM_data8: | |
24841daa NC |
2572 | /* FIXME: Record the length of the ID as well ? */ |
2573 | add_dwo_id ((const char *) (data - 8)); | |
d85bf2ba NC |
2574 | break; |
2575 | default: | |
2576 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2577 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2578 | break; |
2579 | } | |
2580 | break; | |
2581 | ||
19e6b90e L |
2582 | default: |
2583 | break; | |
2584 | } | |
2585 | } | |
2586 | ||
4ccf1e31 | 2587 | if (do_loc || attribute == 0) |
19e6b90e L |
2588 | return data; |
2589 | ||
ec4d4525 | 2590 | /* For some attributes we can display further information. */ |
19e6b90e L |
2591 | switch (attribute) |
2592 | { | |
ec1b0fbb | 2593 | case DW_AT_type: |
b3fe587e AM |
2594 | if (level >= 0 && level < MAX_CU_NESTING |
2595 | && uvalue < (size_t) (end - start)) | |
ec1b0fbb NC |
2596 | { |
2597 | bfd_boolean is_signed = FALSE; | |
2598 | ||
2599 | get_type_signedness (start, start + uvalue, end, pointer_size, | |
2600 | offset_size, dwarf_version, & is_signed, FALSE); | |
2601 | level_type_signed[level] = is_signed; | |
2602 | } | |
2603 | break; | |
2604 | ||
19e6b90e | 2605 | case DW_AT_inline: |
2e9e81a8 | 2606 | printf ("\t"); |
19e6b90e L |
2607 | switch (uvalue) |
2608 | { | |
2609 | case DW_INL_not_inlined: | |
2610 | printf (_("(not inlined)")); | |
2611 | break; | |
2612 | case DW_INL_inlined: | |
2613 | printf (_("(inlined)")); | |
2614 | break; | |
2615 | case DW_INL_declared_not_inlined: | |
2616 | printf (_("(declared as inline but ignored)")); | |
2617 | break; | |
2618 | case DW_INL_declared_inlined: | |
2619 | printf (_("(declared as inline and inlined)")); | |
2620 | break; | |
2621 | default: | |
47704ddf KT |
2622 | printf (_(" (Unknown inline attribute value: %s)"), |
2623 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
2624 | break; |
2625 | } | |
2626 | break; | |
2627 | ||
2628 | case DW_AT_language: | |
2e9e81a8 | 2629 | printf ("\t"); |
19e6b90e L |
2630 | switch (uvalue) |
2631 | { | |
4b78141a | 2632 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 2633 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
2634 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
2635 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 2636 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
2637 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
2638 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
2639 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
2640 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 2641 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 2642 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 2643 | /* DWARF 2.1 values. */ |
4b78141a | 2644 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
2645 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
2646 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
2647 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
2648 | /* DWARF 3 values. */ |
2649 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
2650 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
2651 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
2652 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
2653 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
2654 | /* DWARF 4 values. */ |
2655 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 2656 | /* DWARF 5 values. */ |
2008a0db | 2657 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 2658 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
2659 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
2660 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
2661 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 2662 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
2663 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
2664 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 2665 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
2666 | case DW_LANG_Swift: printf ("(Swift)"); break; |
2667 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
2668 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 2669 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
2670 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
2671 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 2672 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
2673 | /* MIPS extension. */ |
2674 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
2675 | /* UPC extension. */ | |
2676 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
2677 | default: | |
4b78141a | 2678 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 2679 | printf (_("(implementation defined: %s)"), |
467c65bc | 2680 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 2681 | else |
9cf03b7e | 2682 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2683 | break; |
2684 | } | |
2685 | break; | |
2686 | ||
2687 | case DW_AT_encoding: | |
2e9e81a8 | 2688 | printf ("\t"); |
19e6b90e L |
2689 | switch (uvalue) |
2690 | { | |
2691 | case DW_ATE_void: printf ("(void)"); break; | |
2692 | case DW_ATE_address: printf ("(machine address)"); break; | |
2693 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
2694 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
2695 | case DW_ATE_float: printf ("(float)"); break; | |
2696 | case DW_ATE_signed: printf ("(signed)"); break; | |
2697 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
2698 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
2699 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 2700 | /* DWARF 2.1 values: */ |
19e6b90e L |
2701 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
2702 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
2703 | /* DWARF 3 values: */ |
2704 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
2705 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
2706 | case DW_ATE_edited: printf ("(edited)"); break; | |
2707 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
2708 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
2709 | /* DWARF 4 values: */ |
2710 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
2711 | /* DWARF 5 values: */ | |
2712 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
2713 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
2714 | ||
e2a0d921 NC |
2715 | /* HP extensions: */ |
2716 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
2717 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
2718 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
2719 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
2720 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
2721 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
2722 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
2723 | ||
19e6b90e L |
2724 | default: |
2725 | if (uvalue >= DW_ATE_lo_user | |
2726 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 2727 | printf (_("(user defined type)")); |
19e6b90e | 2728 | else |
9cf03b7e | 2729 | printf (_("(unknown type)")); |
19e6b90e L |
2730 | break; |
2731 | } | |
2732 | break; | |
2733 | ||
2734 | case DW_AT_accessibility: | |
2e9e81a8 | 2735 | printf ("\t"); |
19e6b90e L |
2736 | switch (uvalue) |
2737 | { | |
2738 | case DW_ACCESS_public: printf ("(public)"); break; | |
2739 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
2740 | case DW_ACCESS_private: printf ("(private)"); break; | |
2741 | default: | |
9cf03b7e | 2742 | printf (_("(unknown accessibility)")); |
19e6b90e L |
2743 | break; |
2744 | } | |
2745 | break; | |
2746 | ||
2747 | case DW_AT_visibility: | |
2e9e81a8 | 2748 | printf ("\t"); |
19e6b90e L |
2749 | switch (uvalue) |
2750 | { | |
2751 | case DW_VIS_local: printf ("(local)"); break; | |
2752 | case DW_VIS_exported: printf ("(exported)"); break; | |
2753 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 2754 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
2755 | } |
2756 | break; | |
2757 | ||
04914e37 NC |
2758 | case DW_AT_endianity: |
2759 | printf ("\t"); | |
2760 | switch (uvalue) | |
2761 | { | |
2762 | case DW_END_default: printf ("(default)"); break; | |
2763 | case DW_END_big: printf ("(big)"); break; | |
2764 | case DW_END_little: printf ("(little)"); break; | |
2765 | default: | |
2766 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
2767 | printf (_("(user specified)")); | |
2768 | else | |
2769 | printf (_("(unknown endianity)")); | |
2770 | break; | |
2771 | } | |
2772 | break; | |
2773 | ||
19e6b90e | 2774 | case DW_AT_virtuality: |
2e9e81a8 | 2775 | printf ("\t"); |
19e6b90e L |
2776 | switch (uvalue) |
2777 | { | |
2778 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
2779 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
2780 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 2781 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
2782 | } |
2783 | break; | |
2784 | ||
2785 | case DW_AT_identifier_case: | |
2e9e81a8 | 2786 | printf ("\t"); |
19e6b90e L |
2787 | switch (uvalue) |
2788 | { | |
2789 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
2790 | case DW_ID_up_case: printf ("(up_case)"); break; | |
2791 | case DW_ID_down_case: printf ("(down_case)"); break; | |
2792 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 2793 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
2794 | } |
2795 | break; | |
2796 | ||
2797 | case DW_AT_calling_convention: | |
2e9e81a8 | 2798 | printf ("\t"); |
19e6b90e L |
2799 | switch (uvalue) |
2800 | { | |
2801 | case DW_CC_normal: printf ("(normal)"); break; | |
2802 | case DW_CC_program: printf ("(program)"); break; | |
2803 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
2804 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
2805 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
2806 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
2807 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
2808 | default: |
2809 | if (uvalue >= DW_CC_lo_user | |
2810 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 2811 | printf (_("(user defined)")); |
19e6b90e | 2812 | else |
9cf03b7e | 2813 | printf (_("(unknown convention)")); |
19e6b90e L |
2814 | } |
2815 | break; | |
2816 | ||
2817 | case DW_AT_ordering: | |
2e9e81a8 | 2818 | printf ("\t"); |
19e6b90e L |
2819 | switch (uvalue) |
2820 | { | |
04914e37 | 2821 | case 255: |
9cf03b7e | 2822 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
2823 | case 0: printf ("(row major)"); break; |
2824 | case 1: printf ("(column major)"); break; | |
2825 | } | |
2826 | break; | |
2827 | ||
04914e37 NC |
2828 | case DW_AT_decimal_sign: |
2829 | printf ("\t"); | |
2830 | switch (uvalue) | |
2831 | { | |
2832 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
2833 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
2834 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
2835 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
2836 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
2837 | default: printf (_("(unrecognised)")); break; | |
2838 | } | |
2839 | break; | |
2840 | ||
2841 | case DW_AT_defaulted: | |
2842 | printf ("\t"); | |
2843 | switch (uvalue) | |
2844 | { | |
2845 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
2846 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
2847 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
2848 | default: printf (_("(unrecognised)")); break; | |
2849 | } | |
2850 | break; | |
2851 | ||
2852 | case DW_AT_discr_list: | |
2853 | printf ("\t"); | |
ec1b0fbb | 2854 | display_discr_list (form, uvalue, data, end, level); |
04914e37 NC |
2855 | break; |
2856 | ||
19e6b90e L |
2857 | case DW_AT_frame_base: |
2858 | have_frame_base = 1; | |
1a0670f3 | 2859 | /* Fall through. */ |
19e6b90e | 2860 | case DW_AT_location: |
e2a0d921 NC |
2861 | case DW_AT_string_length: |
2862 | case DW_AT_return_addr: | |
19e6b90e L |
2863 | case DW_AT_data_member_location: |
2864 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2865 | case DW_AT_segment: |
2866 | case DW_AT_static_link: | |
2867 | case DW_AT_use_location: | |
bc0a77d2 | 2868 | case DW_AT_call_value: |
629e7ca8 | 2869 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2870 | case DW_AT_call_data_value: |
629e7ca8 | 2871 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2872 | case DW_AT_call_target: |
629e7ca8 | 2873 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2874 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2875 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 2876 | if ((dwarf_version < 4 |
b4eb7656 | 2877 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2878 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 2879 | printf (_(" (location list)")); |
e2a0d921 | 2880 | /* Fall through. */ |
19e6b90e L |
2881 | case DW_AT_allocated: |
2882 | case DW_AT_associated: | |
2883 | case DW_AT_data_location: | |
2884 | case DW_AT_stride: | |
2885 | case DW_AT_upper_bound: | |
cecf136e | 2886 | case DW_AT_lower_bound: |
19e6b90e L |
2887 | if (block_start) |
2888 | { | |
2889 | int need_frame_base; | |
2890 | ||
2e9e81a8 | 2891 | printf ("\t("); |
19e6b90e L |
2892 | need_frame_base = decode_location_expression (block_start, |
2893 | pointer_size, | |
b7807392 JJ |
2894 | offset_size, |
2895 | dwarf_version, | |
19e6b90e | 2896 | uvalue, |
f1c4cc75 | 2897 | cu_offset, section); |
19e6b90e L |
2898 | printf (")"); |
2899 | if (need_frame_base && !have_frame_base) | |
2900 | printf (_(" [without DW_AT_frame_base]")); | |
2901 | } | |
19e6b90e L |
2902 | break; |
2903 | ||
c54207d3 NC |
2904 | case DW_AT_data_bit_offset: |
2905 | case DW_AT_byte_size: | |
2906 | case DW_AT_bit_size: | |
2907 | case DW_AT_string_length_byte_size: | |
2908 | case DW_AT_string_length_bit_size: | |
2909 | case DW_AT_bit_stride: | |
2910 | if (form == DW_FORM_exprloc) | |
2911 | { | |
2912 | printf ("\t("); | |
2913 | (void) decode_location_expression (block_start, pointer_size, | |
2914 | offset_size, dwarf_version, | |
2915 | uvalue, cu_offset, section); | |
2916 | printf (")"); | |
2917 | } | |
2918 | break; | |
2919 | ||
ec4d4525 NC |
2920 | case DW_AT_import: |
2921 | { | |
a081f3cd JJ |
2922 | if (form == DW_FORM_ref_sig8 |
2923 | || form == DW_FORM_GNU_ref_alt) | |
b4eb7656 | 2924 | break; |
2b6f5997 | 2925 | |
ec4d4525 NC |
2926 | if (form == DW_FORM_ref1 |
2927 | || form == DW_FORM_ref2 | |
a7a0b6a5 JK |
2928 | || form == DW_FORM_ref4 |
2929 | || form == DW_FORM_ref_udata) | |
ec4d4525 NC |
2930 | uvalue += cu_offset; |
2931 | ||
6e3d6dc1 | 2932 | if (uvalue >= section->size) |
f3853b34 | 2933 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), |
47704ddf KT |
2934 | dwarf_vmatoa ("x", uvalue), |
2935 | (unsigned long) (orig_data - section->start)); | |
6e3d6dc1 NC |
2936 | else |
2937 | { | |
2938 | unsigned long abbrev_number; | |
cd30bcef AM |
2939 | abbrev_entry *entry; |
2940 | unsigned char *p = section->start + uvalue; | |
6e3d6dc1 | 2941 | |
cd30bcef | 2942 | READ_ULEB (abbrev_number, p, end); |
cecf136e | 2943 | |
2e9e81a8 | 2944 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
afd6e1ff JJ |
2945 | /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
2946 | use different abbrev table, and we don't track .debug_info chunks | |
2947 | yet. */ | |
2948 | if (form != DW_FORM_ref_addr) | |
2949 | { | |
2950 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
2951 | if (entry->entry == abbrev_number) | |
2952 | break; | |
2953 | if (entry != NULL) | |
2954 | printf (" (%s)", get_TAG_name (entry->tag)); | |
2955 | } | |
6e3d6dc1 NC |
2956 | printf ("]"); |
2957 | } | |
ec4d4525 NC |
2958 | } |
2959 | break; | |
2960 | ||
19e6b90e L |
2961 | default: |
2962 | break; | |
2963 | } | |
2964 | ||
2965 | return data; | |
2966 | } | |
2967 | ||
19e6b90e | 2968 | static unsigned char * |
dda8d76d NC |
2969 | read_and_display_attr (unsigned long attribute, |
2970 | unsigned long form, | |
2971 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 2972 | unsigned char * start, |
dda8d76d NC |
2973 | unsigned char * data, |
2974 | unsigned char * end, | |
2975 | dwarf_vma cu_offset, | |
2976 | dwarf_vma pointer_size, | |
2977 | dwarf_vma offset_size, | |
2978 | int dwarf_version, | |
2979 | debug_info * debug_info_p, | |
2980 | int do_loc, | |
2981 | struct dwarf_section * section, | |
ec1b0fbb NC |
2982 | struct cu_tu_set * this_set, |
2983 | int level) | |
19e6b90e L |
2984 | { |
2985 | if (!do_loc) | |
750f03b7 | 2986 | printf (" %-18s:", get_AT_name (attribute)); |
ec1b0fbb NC |
2987 | data = read_and_display_attr_value (attribute, form, implicit_const, |
2988 | start, data, end, | |
f6f0e17b | 2989 | cu_offset, pointer_size, offset_size, |
19e6b90e | 2990 | dwarf_version, debug_info_p, |
ec1b0fbb | 2991 | do_loc, section, this_set, ' ', level); |
19e6b90e L |
2992 | if (!do_loc) |
2993 | printf ("\n"); | |
2994 | return data; | |
2995 | } | |
2996 | ||
dda8d76d | 2997 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
2998 | following debug links, then attempt to load the requested section |
2999 | from one of the separate debug info files. */ | |
dda8d76d NC |
3000 | |
3001 | static bfd_boolean | |
3002 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, | |
24841daa | 3003 | void * handle) |
dda8d76d | 3004 | { |
24841daa | 3005 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 3006 | { |
24841daa NC |
3007 | if (debug_displays[sec_enum].section.filename == NULL) |
3008 | { | |
3009 | /* See if we can associate a filename with this section. */ | |
3010 | separate_info * i; | |
3011 | ||
3012 | for (i = first_separate_info; i != NULL; i = i->next) | |
3013 | if (i->handle == handle) | |
3014 | { | |
3015 | debug_displays[sec_enum].section.filename = i->filename; | |
3016 | break; | |
3017 | } | |
3018 | } | |
3019 | ||
dda8d76d NC |
3020 | return TRUE; |
3021 | } | |
3022 | ||
24841daa NC |
3023 | if (do_follow_links) |
3024 | { | |
3025 | separate_info * i; | |
3026 | ||
3027 | for (i = first_separate_info; i != NULL; i = i->next) | |
3028 | { | |
3029 | if (load_debug_section (sec_enum, i->handle)) | |
3030 | { | |
3031 | debug_displays[sec_enum].section.filename = i->filename; | |
3032 | ||
3033 | /* FIXME: We should check to see if any of the remaining debug info | |
3034 | files also contain this section, and, umm, do something about it. */ | |
3035 | return TRUE; | |
3036 | } | |
3037 | } | |
3038 | } | |
dda8d76d NC |
3039 | |
3040 | return FALSE; | |
3041 | } | |
3042 | ||
3043 | static void | |
3044 | introduce (struct dwarf_section * section, bfd_boolean raw) | |
3045 | { | |
3046 | if (raw) | |
3047 | { | |
3048 | if (do_follow_links && section->filename) | |
3049 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
3050 | section->name, section->filename); | |
3051 | else | |
3052 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
3053 | } | |
3054 | else | |
3055 | { | |
3056 | if (do_follow_links && section->filename) | |
3057 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
3058 | section->name, section->filename); | |
3059 | else | |
3060 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3061 | } | |
3062 | } | |
3063 | ||
d85bf2ba NC |
3064 | /* Process the contents of a .debug_info section. |
3065 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
3066 | and we do not want to display anything to the user. | |
3067 | If do_types is TRUE, we are processing a .debug_types section instead of | |
3068 | a .debug_info section. | |
3069 | The information displayed is restricted by the values in DWARF_START_DIE | |
3070 | and DWARF_CUTOFF_LEVEL. | |
3071 | Returns TRUE upon success. Otherwise an error or warning message is | |
3072 | printed and FALSE is returned. */ | |
19e6b90e | 3073 | |
d85bf2ba NC |
3074 | static bfd_boolean |
3075 | process_debug_info (struct dwarf_section * section, | |
3076 | void * file, | |
3077 | enum dwarf_section_display_enum abbrev_sec, | |
3078 | bfd_boolean do_loc, | |
3079 | bfd_boolean do_types) | |
19e6b90e L |
3080 | { |
3081 | unsigned char *start = section->start; | |
3082 | unsigned char *end = start + section->size; | |
3083 | unsigned char *section_begin; | |
3084 | unsigned int unit; | |
3085 | unsigned int num_units = 0; | |
3086 | ||
3087 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3088 | && num_debug_info_entries == 0 |
3089 | && ! do_types) | |
19e6b90e | 3090 | { |
767221a9 | 3091 | dwarf_vma length; |
19e6b90e L |
3092 | |
3093 | /* First scan the section to get the number of comp units. */ | |
3094 | for (section_begin = start, num_units = 0; section_begin < end; | |
3095 | num_units ++) | |
3096 | { | |
3097 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
3098 | will be the length. For a 64-bit DWARF section, it'll be | |
3099 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 3100 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
3101 | |
3102 | if (length == 0xffffffff) | |
3103 | { | |
0c588247 | 3104 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
3105 | section_begin += length + 12; |
3106 | } | |
ec4d4525 NC |
3107 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
3108 | { | |
767221a9 NC |
3109 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
3110 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3111 | return FALSE; |
ec4d4525 | 3112 | } |
19e6b90e L |
3113 | else |
3114 | section_begin += length + 4; | |
aca88567 NC |
3115 | |
3116 | /* Negative values are illegal, they may even cause infinite | |
3117 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
3118 | relocations to an object file, or if the file is corrupt. */ |
3119 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 3120 | { |
767221a9 NC |
3121 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
3122 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3123 | return FALSE; |
aca88567 | 3124 | } |
19e6b90e L |
3125 | } |
3126 | ||
3127 | if (num_units == 0) | |
3128 | { | |
f41e4712 | 3129 | error (_("No comp units in %s section ?\n"), section->name); |
d85bf2ba | 3130 | return FALSE; |
19e6b90e L |
3131 | } |
3132 | ||
3133 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 3134 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 3135 | sizeof (* debug_information)); |
19e6b90e L |
3136 | if (debug_information == NULL) |
3137 | { | |
f41e4712 | 3138 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 3139 | num_units); |
82b1b41b | 3140 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
d85bf2ba | 3141 | return FALSE; |
19e6b90e | 3142 | } |
d85bf2ba | 3143 | |
03a91817 NC |
3144 | /* PR 17531: file: 92ca3797. |
3145 | We cannot rely upon the debug_information array being initialised | |
3146 | before it is used. A corrupt file could easily contain references | |
3147 | to a unit for which information has not been made available. So | |
3148 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
3149 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
3150 | ||
82b1b41b | 3151 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
3152 | } |
3153 | ||
3154 | if (!do_loc) | |
3155 | { | |
dda8d76d NC |
3156 | load_debug_section_with_follow (str, file); |
3157 | load_debug_section_with_follow (line_str, file); | |
3158 | load_debug_section_with_follow (str_dwo, file); | |
3159 | load_debug_section_with_follow (str_index, file); | |
3160 | load_debug_section_with_follow (str_index_dwo, file); | |
3161 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e L |
3162 | } |
3163 | ||
dda8d76d | 3164 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 3165 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
3166 | { |
3167 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 3168 | debug_displays [abbrev_sec].section.uncompressed_name); |
d85bf2ba | 3169 | return FALSE; |
19e6b90e L |
3170 | } |
3171 | ||
dda8d76d NC |
3172 | if (!do_loc && dwarf_start_die == 0) |
3173 | introduce (section, FALSE); | |
3174 | ||
19e6b90e L |
3175 | for (section_begin = start, unit = 0; start < end; unit++) |
3176 | { | |
3177 | DWARF2_Internal_CompUnit compunit; | |
3178 | unsigned char *hdrptr; | |
19e6b90e | 3179 | unsigned char *tags; |
fd2f0033 | 3180 | int level, last_level, saved_level; |
467c65bc | 3181 | dwarf_vma cu_offset; |
e98fdf1a | 3182 | unsigned long sec_off; |
bf5117e3 | 3183 | unsigned int offset_size; |
19485196 | 3184 | unsigned int initial_length_size; |
74bc6052 CC |
3185 | dwarf_vma signature_high = 0; |
3186 | dwarf_vma signature_low = 0; | |
767221a9 | 3187 | dwarf_vma type_offset = 0; |
341f9135 CC |
3188 | struct cu_tu_set *this_set; |
3189 | dwarf_vma abbrev_base; | |
3190 | size_t abbrev_size; | |
19e6b90e L |
3191 | |
3192 | hdrptr = start; | |
3193 | ||
0c588247 | 3194 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
3195 | |
3196 | if (compunit.cu_length == 0xffffffff) | |
3197 | { | |
0c588247 | 3198 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
3199 | offset_size = 8; |
3200 | initial_length_size = 12; | |
3201 | } | |
3202 | else | |
3203 | { | |
3204 | offset_size = 4; | |
3205 | initial_length_size = 4; | |
3206 | } | |
3207 | ||
0c588247 | 3208 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
3209 | |
3210 | cu_offset = start - section_begin; | |
19e6b90e | 3211 | |
341f9135 CC |
3212 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3213 | ||
77145576 JK |
3214 | if (compunit.cu_version < 5) |
3215 | { | |
3216 | compunit.cu_unit_type = DW_UT_compile; | |
3217 | /* Initialize it due to a false compiler warning. */ | |
3218 | compunit.cu_pointer_size = -1; | |
3219 | } | |
3220 | else | |
3221 | { | |
3222 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3223 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3224 | ||
3225 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3226 | } | |
3227 | ||
0c588247 | 3228 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 3229 | |
341f9135 CC |
3230 | if (this_set == NULL) |
3231 | { | |
3232 | abbrev_base = 0; | |
3233 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3234 | } | |
3235 | else | |
3236 | { | |
3237 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3238 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3239 | } | |
3240 | ||
77145576 JK |
3241 | if (compunit.cu_version < 5) |
3242 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3243 | ||
f41e4712 NC |
3244 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
3245 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
3246 | { | |
3247 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
3248 | compunit.cu_pointer_size, offset_size); | |
3249 | compunit.cu_pointer_size = offset_size; | |
3250 | } | |
2b6f5997 CC |
3251 | |
3252 | if (do_types) | |
b4eb7656 | 3253 | { |
0c588247 | 3254 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 3255 | hdrptr += 8; |
0c588247 | 3256 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 3257 | } |
2b6f5997 | 3258 | |
ae7e7825 NC |
3259 | if (dwarf_start_die > (cu_offset + compunit.cu_length |
3260 | + initial_length_size)) | |
3261 | { | |
3262 | start = section_begin + cu_offset + compunit.cu_length | |
3263 | + initial_length_size; | |
3264 | continue; | |
3265 | } | |
3266 | ||
19e6b90e | 3267 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 CC |
3268 | && num_debug_info_entries == 0 |
3269 | && ! do_types) | |
19e6b90e L |
3270 | { |
3271 | debug_information [unit].cu_offset = cu_offset; | |
3272 | debug_information [unit].pointer_size | |
3273 | = compunit.cu_pointer_size; | |
b7807392 JJ |
3274 | debug_information [unit].offset_size = offset_size; |
3275 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 3276 | debug_information [unit].base_address = 0; |
4723351a CC |
3277 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
3278 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
3279 | debug_information [unit].loc_offsets = NULL; |
3280 | debug_information [unit].have_frame_base = NULL; | |
3281 | debug_information [unit].max_loc_offsets = 0; | |
3282 | debug_information [unit].num_loc_offsets = 0; | |
3283 | debug_information [unit].range_lists = NULL; | |
3284 | debug_information [unit].max_range_lists= 0; | |
3285 | debug_information [unit].num_range_lists = 0; | |
3286 | } | |
3287 | ||
fd2f0033 | 3288 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 3289 | { |
47704ddf KT |
3290 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3291 | dwarf_vmatoa ("x", cu_offset)); | |
3292 | printf (_(" Length: 0x%s (%s)\n"), | |
3293 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3294 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3295 | printf (_(" Version: %d\n"), compunit.cu_version); |
7282333f AM |
3296 | printf (_(" Abbrev Offset: 0x%s\n"), |
3297 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3298 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3299 | if (do_types) |
3300 | { | |
74bc6052 CC |
3301 | char buf[64]; |
3302 | ||
3303 | printf (_(" Signature: 0x%s\n"), | |
3304 | dwarf_vmatoa64 (signature_high, signature_low, | |
3305 | buf, sizeof (buf))); | |
3306 | printf (_(" Type Offset: 0x%s\n"), | |
3307 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3308 | } |
341f9135 CC |
3309 | if (this_set != NULL) |
3310 | { | |
3311 | dwarf_vma *offsets = this_set->section_offsets; | |
3312 | size_t *sizes = this_set->section_sizes; | |
3313 | ||
3314 | printf (_(" Section contributions:\n")); | |
3315 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3316 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3317 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3318 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3319 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3320 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3321 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3322 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3323 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3324 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3325 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3326 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3327 | } | |
19e6b90e L |
3328 | } |
3329 | ||
e98fdf1a AM |
3330 | sec_off = cu_offset + initial_length_size; |
3331 | if (sec_off + compunit.cu_length < sec_off | |
3332 | || sec_off + compunit.cu_length > section->size) | |
460c89ff | 3333 | { |
e98fdf1a AM |
3334 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
3335 | section->name, | |
3336 | (unsigned long) cu_offset, | |
19485196 NC |
3337 | dwarf_vmatoa ("x", compunit.cu_length)); |
3338 | num_units = unit; | |
3339 | break; | |
3340 | } | |
3341 | ||
460c89ff NS |
3342 | tags = hdrptr; |
3343 | start += compunit.cu_length + initial_length_size; | |
3344 | ||
77145576 | 3345 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3346 | { |
47704ddf KT |
3347 | warn (_("CU at offset %s contains corrupt or " |
3348 | "unsupported version number: %d.\n"), | |
3349 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3350 | continue; |
3351 | } | |
3352 | ||
77145576 JK |
3353 | if (compunit.cu_unit_type != DW_UT_compile |
3354 | && compunit.cu_unit_type != DW_UT_type) | |
3355 | { | |
3356 | warn (_("CU at offset %s contains corrupt or " | |
3357 | "unsupported unit type: %d.\n"), | |
3358 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3359 | continue; | |
3360 | } | |
3361 | ||
19e6b90e L |
3362 | free_abbrevs (); |
3363 | ||
d493b283 | 3364 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 3365 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
3366 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
3367 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 3368 | (unsigned long) abbrev_size); |
b4eb7656 | 3369 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
3370 | else if ((abbrev_base + abbrev_size) |
3371 | > debug_displays [abbrev_sec].section.size) | |
3372 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
3373 | (unsigned long) abbrev_base + abbrev_size, | |
3374 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff NS |
3375 | else |
3376 | process_abbrev_section | |
341f9135 CC |
3377 | (((unsigned char *) debug_displays [abbrev_sec].section.start |
3378 | + abbrev_base + compunit.cu_abbrev_offset), | |
3379 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3380 | + abbrev_base + abbrev_size)); | |
19e6b90e L |
3381 | |
3382 | level = 0; | |
fd2f0033 TT |
3383 | last_level = level; |
3384 | saved_level = -1; | |
19e6b90e L |
3385 | while (tags < start) |
3386 | { | |
19e6b90e | 3387 | unsigned long abbrev_number; |
ec4d4525 | 3388 | unsigned long die_offset; |
19e6b90e L |
3389 | abbrev_entry *entry; |
3390 | abbrev_attr *attr; | |
fd2f0033 | 3391 | int do_printing = 1; |
19e6b90e | 3392 | |
ec4d4525 NC |
3393 | die_offset = tags - section_begin; |
3394 | ||
cd30bcef | 3395 | READ_ULEB (abbrev_number, tags, start); |
19e6b90e | 3396 | |
eb7cc021 JK |
3397 | /* A null DIE marks the end of a list of siblings or it may also be |
3398 | a section padding. */ | |
19e6b90e L |
3399 | if (abbrev_number == 0) |
3400 | { | |
eb7cc021 JK |
3401 | /* Check if it can be a section padding for the last CU. */ |
3402 | if (level == 0 && start == end) | |
3403 | { | |
3404 | unsigned char *chk; | |
3405 | ||
3406 | for (chk = tags; chk < start; chk++) | |
3407 | if (*chk != 0) | |
3408 | break; | |
3409 | if (chk == start) | |
3410 | break; | |
3411 | } | |
3412 | ||
4337774f TT |
3413 | if (!do_loc && die_offset >= dwarf_start_die |
3414 | && (dwarf_cutoff_level == -1 | |
3415 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3416 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3417 | level, die_offset); | |
3418 | ||
19e6b90e | 3419 | --level; |
ec4d4525 NC |
3420 | if (level < 0) |
3421 | { | |
3422 | static unsigned num_bogus_warns = 0; | |
3423 | ||
3424 | if (num_bogus_warns < 3) | |
3425 | { | |
4723351a CC |
3426 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3427 | die_offset, section->name); | |
ec4d4525 NC |
3428 | num_bogus_warns ++; |
3429 | if (num_bogus_warns == 3) | |
3430 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3431 | } | |
3432 | } | |
fd2f0033 | 3433 | if (dwarf_start_die != 0 && level < saved_level) |
d85bf2ba | 3434 | return TRUE; |
19e6b90e L |
3435 | continue; |
3436 | } | |
3437 | ||
4b78141a | 3438 | if (!do_loc) |
fd2f0033 TT |
3439 | { |
3440 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
3441 | do_printing = 0; | |
3442 | else | |
3443 | { | |
3444 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
3445 | saved_level = level; | |
3446 | do_printing = (dwarf_cutoff_level == -1 | |
3447 | || level < dwarf_cutoff_level); | |
3448 | if (do_printing) | |
3449 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
3450 | level, die_offset, abbrev_number); | |
3451 | else if (dwarf_cutoff_level == -1 | |
3452 | || last_level < dwarf_cutoff_level) | |
3453 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
3454 | last_level = level; | |
3455 | } | |
3456 | } | |
cecf136e | 3457 | |
19e6b90e L |
3458 | /* Scan through the abbreviation list until we reach the |
3459 | correct entry. */ | |
3460 | for (entry = first_abbrev; | |
3461 | entry && entry->entry != abbrev_number; | |
3462 | entry = entry->next) | |
3463 | continue; | |
3464 | ||
3465 | if (entry == NULL) | |
3466 | { | |
fd2f0033 | 3467 | if (!do_loc && do_printing) |
4b78141a NC |
3468 | { |
3469 | printf ("\n"); | |
3470 | fflush (stdout); | |
3471 | } | |
f3853b34 | 3472 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 3473 | die_offset, abbrev_number); |
d85bf2ba | 3474 | return FALSE; |
19e6b90e L |
3475 | } |
3476 | ||
fd2f0033 | 3477 | if (!do_loc && do_printing) |
cc5914eb | 3478 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 3479 | |
19e6b90e L |
3480 | switch (entry->tag) |
3481 | { | |
3482 | default: | |
3483 | need_base_address = 0; | |
3484 | break; | |
3485 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
3486 | need_base_address = 1; |
3487 | need_dwo_info = do_loc; | |
19e6b90e L |
3488 | break; |
3489 | case DW_TAG_entry_point: | |
19e6b90e L |
3490 | case DW_TAG_subprogram: |
3491 | need_base_address = 0; | |
3492 | /* Assuming that there is no DW_AT_frame_base. */ | |
3493 | have_frame_base = 0; | |
3494 | break; | |
3495 | } | |
3496 | ||
9f272209 AO |
3497 | debug_info *debug_info_p = |
3498 | (debug_information && unit < alloc_num_debug_info_entries) | |
3499 | ? debug_information + unit : NULL; | |
3500 | ||
3501 | assert (!debug_info_p | |
3502 | || (debug_info_p->num_loc_offsets | |
3503 | == debug_info_p->num_loc_views)); | |
3504 | ||
399c99f7 L |
3505 | for (attr = entry->first_attr; |
3506 | attr && attr->attribute; | |
3507 | attr = attr->next) | |
4b78141a | 3508 | { |
fd2f0033 | 3509 | if (! do_loc && do_printing) |
4b78141a | 3510 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 | 3511 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
3512 | tags = read_and_display_attr (attr->attribute, |
3513 | attr->form, | |
77145576 | 3514 | attr->implicit_const, |
ec1b0fbb | 3515 | section_begin, |
341f9135 | 3516 | tags, |
f6f0e17b | 3517 | end, |
341f9135 | 3518 | cu_offset, |
4b78141a NC |
3519 | compunit.cu_pointer_size, |
3520 | offset_size, | |
3521 | compunit.cu_version, | |
9f272209 | 3522 | debug_info_p, |
341f9135 CC |
3523 | do_loc || ! do_printing, |
3524 | section, | |
ec1b0fbb NC |
3525 | this_set, |
3526 | level); | |
4b78141a | 3527 | } |
cecf136e | 3528 | |
9f272209 AO |
3529 | /* If a locview attribute appears before a location one, |
3530 | make sure we don't associate it with an earlier | |
3531 | loclist. */ | |
3532 | if (debug_info_p) | |
3533 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
3534 | { | |
3535 | case 1: | |
3536 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
3537 | debug_info_p->num_loc_views++; | |
3538 | assert (debug_info_p->num_loc_views | |
3539 | == debug_info_p->num_loc_offsets); | |
3540 | break; | |
3541 | ||
3542 | case 0: | |
3543 | break; | |
3544 | ||
3545 | case -1: | |
3546 | warn(_("DIE has locviews without loclist\n")); | |
3547 | debug_info_p->num_loc_views--; | |
3548 | break; | |
3549 | ||
3550 | default: | |
3551 | assert (0); | |
3552 | } | |
3553 | ||
b4eb7656 AM |
3554 | if (entry->children) |
3555 | ++level; | |
3556 | } | |
19e6b90e | 3557 | } |
cecf136e | 3558 | |
19e6b90e L |
3559 | /* Set num_debug_info_entries here so that it can be used to check if |
3560 | we need to process .debug_loc and .debug_ranges sections. */ | |
3561 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3562 | && num_debug_info_entries == 0 |
3563 | && ! do_types) | |
82b1b41b | 3564 | { |
b4eb7656 | 3565 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
3566 | num_debug_info_entries = alloc_num_debug_info_entries; |
3567 | else | |
3568 | num_debug_info_entries = num_units; | |
3569 | } | |
cecf136e | 3570 | |
19e6b90e | 3571 | if (!do_loc) |
467c65bc | 3572 | printf ("\n"); |
cecf136e | 3573 | |
d85bf2ba | 3574 | return TRUE; |
19e6b90e L |
3575 | } |
3576 | ||
3577 | /* Locate and scan the .debug_info section in the file and record the pointer | |
3578 | sizes and offsets for the compilation units in it. Usually an executable | |
3579 | will have just one pointer size, but this is not guaranteed, and so we try | |
3580 | not to make any assumptions. Returns zero upon failure, or the number of | |
3581 | compilation units upon success. */ | |
3582 | ||
3583 | static unsigned int | |
3584 | load_debug_info (void * file) | |
3585 | { | |
1febe64d | 3586 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 3587 | section then do not bother to repeat the task. */ |
cc86f28f | 3588 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
3589 | return 0; |
3590 | ||
19e6b90e L |
3591 | /* If we already have the information there is nothing else to do. */ |
3592 | if (num_debug_info_entries > 0) | |
3593 | return num_debug_info_entries; | |
3594 | ||
341f9135 | 3595 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 3596 | (void) load_cu_tu_indexes (file); |
341f9135 | 3597 | |
dda8d76d | 3598 | if (load_debug_section_with_follow (info, file) |
d85bf2ba | 3599 | && process_debug_info (&debug_displays [info].section, file, abbrev, TRUE, FALSE)) |
19e6b90e | 3600 | return num_debug_info_entries; |
82b1b41b | 3601 | |
dda8d76d | 3602 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 3603 | && process_debug_info (&debug_displays [info_dwo].section, file, |
d85bf2ba | 3604 | abbrev_dwo, TRUE, FALSE)) |
4723351a | 3605 | return num_debug_info_entries; |
1febe64d | 3606 | |
cc86f28f | 3607 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 3608 | return 0; |
19e6b90e L |
3609 | } |
3610 | ||
b40bf0a2 NC |
3611 | /* Read a DWARF .debug_line section header starting at DATA. |
3612 | Upon success returns an updated DATA pointer and the LINFO | |
3613 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
3614 | Otherwise returns NULL. */ | |
19e6b90e | 3615 | |
b40bf0a2 NC |
3616 | static unsigned char * |
3617 | read_debug_line_header (struct dwarf_section * section, | |
3618 | unsigned char * data, | |
3619 | unsigned char * end, | |
3620 | DWARF2_Internal_LineInfo * linfo, | |
3621 | unsigned char ** end_of_sequence) | |
3622 | { | |
3623 | unsigned char *hdrptr; | |
b40bf0a2 | 3624 | unsigned int initial_length_size; |
77145576 | 3625 | unsigned char address_size, segment_selector_size; |
19e6b90e | 3626 | |
b40bf0a2 NC |
3627 | /* Extract information from the Line Number Program Header. |
3628 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 3629 | hdrptr = data; |
19e6b90e | 3630 | |
b40bf0a2 NC |
3631 | /* Get and check the length of the block. */ |
3632 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 3633 | |
b40bf0a2 | 3634 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
3635 | { |
3636 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 3637 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 3638 | linfo->li_offset_size = 8; |
f41e4712 NC |
3639 | initial_length_size = 12; |
3640 | } | |
3641 | else | |
3642 | { | |
77145576 | 3643 | linfo->li_offset_size = 4; |
f41e4712 NC |
3644 | initial_length_size = 4; |
3645 | } | |
19e6b90e | 3646 | |
b40bf0a2 | 3647 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 3648 | { |
8fcc61b4 NC |
3649 | /* If the length field has a relocation against it, then we should |
3650 | not complain if it is inaccurate (and probably negative). This | |
3651 | happens in object files when the .debug_line section is actually | |
3652 | comprised of several different .debug_line.* sections, (some of | |
3653 | which may be removed by linker garbage collection), and a relocation | |
3654 | is used to compute the correct length once that is done. */ | |
77145576 | 3655 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 3656 | { |
8fcc61b4 | 3657 | linfo->li_length = (end - data) - initial_length_size; |
b40bf0a2 NC |
3658 | } |
3659 | else | |
3660 | { | |
8fcc61b4 NC |
3661 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
3662 | (long) linfo->li_length); | |
b40bf0a2 NC |
3663 | return NULL; |
3664 | } | |
f41e4712 | 3665 | } |
19e6b90e | 3666 | |
b40bf0a2 NC |
3667 | /* Get and check the version number. */ |
3668 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
3669 | ||
3670 | if (linfo->li_version != 2 | |
3671 | && linfo->li_version != 3 | |
77145576 JK |
3672 | && linfo->li_version != 4 |
3673 | && linfo->li_version != 5) | |
f41e4712 | 3674 | { |
77145576 JK |
3675 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
3676 | "is currently supported.\n")); | |
b40bf0a2 | 3677 | return NULL; |
f41e4712 | 3678 | } |
19e6b90e | 3679 | |
77145576 JK |
3680 | if (linfo->li_version >= 5) |
3681 | { | |
3682 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
3683 | ||
3684 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
3685 | if (segment_selector_size != 0) | |
3686 | { | |
3687 | warn (_("The %s section contains " | |
3688 | "unsupported segment selector size: %d.\n"), | |
3689 | section->name, segment_selector_size); | |
3690 | return 0; | |
3691 | } | |
3692 | } | |
3693 | ||
3694 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
3695 | linfo->li_offset_size, end); | |
b40bf0a2 | 3696 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 3697 | |
b40bf0a2 | 3698 | if (linfo->li_version >= 4) |
f41e4712 | 3699 | { |
b40bf0a2 | 3700 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 3701 | |
b40bf0a2 | 3702 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
3703 | { |
3704 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 3705 | return NULL; |
a233b20c | 3706 | } |
f41e4712 NC |
3707 | } |
3708 | else | |
b40bf0a2 | 3709 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 3710 | |
b40bf0a2 | 3711 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 3712 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
3713 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
3714 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 3715 | |
b40bf0a2 | 3716 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 3717 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
3718 | if (* end_of_sequence > end) |
3719 | { | |
4c219c2e AM |
3720 | warn (_("Line length %s extends beyond end of section\n"), |
3721 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
3722 | * end_of_sequence = end; |
3723 | return NULL; | |
3724 | } | |
3725 | ||
b40bf0a2 NC |
3726 | return hdrptr; |
3727 | } | |
19e6b90e | 3728 | |
77145576 | 3729 | static unsigned char * |
dda8d76d NC |
3730 | display_formatted_table (unsigned char * data, |
3731 | unsigned char * start, | |
3732 | unsigned char * end, | |
3733 | const DWARF2_Internal_LineInfo * linfo, | |
3734 | struct dwarf_section * section, | |
7b8d9e8c | 3735 | bfd_boolean is_dir) |
77145576 JK |
3736 | { |
3737 | unsigned char *format_start, format_count, *format, formati; | |
3738 | dwarf_vma data_count, datai; | |
cd30bcef | 3739 | unsigned int namepass, last_entry = 0; |
77145576 JK |
3740 | |
3741 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
3742 | format_start = data; | |
3743 | for (formati = 0; formati < format_count; formati++) | |
3744 | { | |
cd30bcef AM |
3745 | SKIP_ULEB (data, end); |
3746 | SKIP_ULEB (data, end); | |
77145576 JK |
3747 | if (data == end) |
3748 | { | |
7b8d9e8c AM |
3749 | if (is_dir) |
3750 | warn (_("Corrupt directory format table entry\n")); | |
3751 | else | |
3752 | warn (_("Corrupt file name format table entry\n")); | |
77145576 JK |
3753 | return data; |
3754 | } | |
3755 | } | |
3756 | ||
cd30bcef | 3757 | READ_ULEB (data_count, data, end); |
77145576 JK |
3758 | if (data == end) |
3759 | { | |
7b8d9e8c AM |
3760 | if (is_dir) |
3761 | warn (_("Corrupt directory list\n")); | |
3762 | else | |
3763 | warn (_("Corrupt file name list\n")); | |
77145576 JK |
3764 | return data; |
3765 | } | |
3766 | ||
3767 | if (data_count == 0) | |
3768 | { | |
7b8d9e8c AM |
3769 | if (is_dir) |
3770 | printf (_("\n The Directory Table is empty.\n")); | |
3771 | else | |
3772 | printf (_("\n The File Name Table is empty.\n")); | |
77145576 JK |
3773 | return data; |
3774 | } | |
3775 | ||
7b8d9e8c AM |
3776 | if (is_dir) |
3777 | printf (_("\n The Directory Table (offset 0x%lx):\n"), | |
3778 | (long) (data - start)); | |
3779 | else | |
3780 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
3781 | (long) (data - start)); | |
77145576 JK |
3782 | |
3783 | printf (_(" Entry")); | |
3784 | /* Delay displaying name as the last entry for better screen layout. */ | |
3785 | for (namepass = 0; namepass < 2; namepass++) | |
3786 | { | |
3787 | format = format_start; | |
3788 | for (formati = 0; formati < format_count; formati++) | |
3789 | { | |
3790 | dwarf_vma content_type; | |
3791 | ||
cd30bcef | 3792 | READ_ULEB (content_type, format, end); |
77145576 JK |
3793 | if ((content_type == DW_LNCT_path) == (namepass == 1)) |
3794 | switch (content_type) | |
3795 | { | |
3796 | case DW_LNCT_path: | |
3797 | printf (_("\tName")); | |
3798 | break; | |
3799 | case DW_LNCT_directory_index: | |
3800 | printf (_("\tDir")); | |
3801 | break; | |
3802 | case DW_LNCT_timestamp: | |
3803 | printf (_("\tTime")); | |
3804 | break; | |
3805 | case DW_LNCT_size: | |
3806 | printf (_("\tSize")); | |
3807 | break; | |
3808 | case DW_LNCT_MD5: | |
3809 | printf (_("\tMD5")); | |
3810 | break; | |
3811 | default: | |
3812 | printf (_("\t(Unknown format content type %s)"), | |
3813 | dwarf_vmatoa ("u", content_type)); | |
3814 | } | |
cd30bcef | 3815 | SKIP_ULEB (format, end); |
77145576 JK |
3816 | } |
3817 | } | |
3818 | putchar ('\n'); | |
3819 | ||
3820 | for (datai = 0; datai < data_count; datai++) | |
3821 | { | |
3822 | unsigned char *datapass = data; | |
3823 | ||
3824 | printf (" %d", last_entry++); | |
3825 | /* Delay displaying name as the last entry for better screen layout. */ | |
3826 | for (namepass = 0; namepass < 2; namepass++) | |
3827 | { | |
3828 | format = format_start; | |
3829 | data = datapass; | |
3830 | for (formati = 0; formati < format_count; formati++) | |
3831 | { | |
3832 | dwarf_vma content_type, form; | |
3833 | ||
cd30bcef AM |
3834 | READ_ULEB (content_type, format, end); |
3835 | READ_ULEB (form, format, end); | |
3836 | data = read_and_display_attr_value (0, form, 0, start, data, end, | |
3837 | 0, 0, linfo->li_offset_size, | |
77145576 JK |
3838 | linfo->li_version, NULL, |
3839 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
ec1b0fbb | 3840 | section, NULL, '\t', -1); |
77145576 JK |
3841 | } |
3842 | } | |
3843 | if (data == end) | |
3844 | { | |
7b8d9e8c AM |
3845 | if (is_dir) |
3846 | warn (_("Corrupt directory entries list\n")); | |
3847 | else | |
3848 | warn (_("Corrupt file name entries list\n")); | |
77145576 JK |
3849 | return data; |
3850 | } | |
3851 | putchar ('\n'); | |
3852 | } | |
3853 | return data; | |
3854 | } | |
3855 | ||
b40bf0a2 | 3856 | static int |
dda8d76d NC |
3857 | display_debug_lines_raw (struct dwarf_section * section, |
3858 | unsigned char * data, | |
3859 | unsigned char * end, | |
3860 | void * file) | |
b40bf0a2 NC |
3861 | { |
3862 | unsigned char *start = section->start; | |
ba8826a8 | 3863 | int verbose_view = 0; |
19e6b90e | 3864 | |
dda8d76d | 3865 | introduce (section, TRUE); |
19e6b90e | 3866 | |
b40bf0a2 NC |
3867 | while (data < end) |
3868 | { | |
3869 | static DWARF2_Internal_LineInfo saved_linfo; | |
3870 | DWARF2_Internal_LineInfo linfo; | |
3871 | unsigned char *standard_opcodes; | |
3872 | unsigned char *end_of_sequence; | |
fe59e83d | 3873 | int i; |
19e6b90e | 3874 | |
4925cdd7 NC |
3875 | if (const_strneq (section->name, ".debug_line.") |
3876 | /* Note: the following does not apply to .debug_line.dwo sections. | |
3877 | These are full debug_line sections. */ | |
3878 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 3879 | { |
b40bf0a2 NC |
3880 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
3881 | section containing just the Line Number Statements. They are | |
3882 | created by the assembler and intended to be used alongside gcc's | |
3883 | -ffunction-sections command line option. When the linker's | |
3884 | garbage collection decides to discard a .text.<foo> section it | |
3885 | can then also discard the line number information in .debug_line.<foo>. | |
3886 | ||
4925cdd7 | 3887 | Since the section is a fragment it does not have the details |
b40bf0a2 | 3888 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 3889 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
3890 | end_of_sequence = end; |
3891 | standard_opcodes = NULL; | |
3892 | linfo = saved_linfo; | |
058037d3 NC |
3893 | /* PR 17531: file: 0522b371. */ |
3894 | if (linfo.li_line_range == 0) | |
3895 | { | |
1306a742 | 3896 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
3897 | return 0; |
3898 | } | |
b40bf0a2 | 3899 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3900 | } |
19e6b90e L |
3901 | else |
3902 | { | |
b40bf0a2 | 3903 | unsigned char * hdrptr; |
19e6b90e | 3904 | |
b40bf0a2 NC |
3905 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
3906 | & end_of_sequence)) == NULL) | |
3907 | return 0; | |
19e6b90e | 3908 | |
b40bf0a2 NC |
3909 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
3910 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
3911 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
77ef8654 | 3912 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
3913 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
3914 | if (linfo.li_version >= 4) | |
3915 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
3916 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
3917 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
3918 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
3919 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 3920 | |
0a9d414a NC |
3921 | /* PR 17512: file: 1665-6428-0.004. */ |
3922 | if (linfo.li_line_range == 0) | |
3923 | { | |
3924 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
3925 | linfo.li_line_range = 1; | |
3926 | } | |
77ef8654 | 3927 | |
b40bf0a2 | 3928 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3929 | |
b40bf0a2 NC |
3930 | /* Display the contents of the Opcodes table. */ |
3931 | standard_opcodes = hdrptr; | |
19e6b90e | 3932 | |
6937bb54 NC |
3933 | /* PR 17512: file: 002-417945-0.004. */ |
3934 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
3935 | { | |
3936 | warn (_("Line Base extends beyond end of section\n")); | |
3937 | return 0; | |
3938 | } | |
3939 | ||
b40bf0a2 | 3940 | printf (_("\n Opcodes:\n")); |
19e6b90e | 3941 | |
b40bf0a2 | 3942 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
3943 | printf (ngettext (" Opcode %d has %d arg\n", |
3944 | " Opcode %d has %d args\n", | |
3945 | standard_opcodes[i - 1]), | |
3946 | i, standard_opcodes[i - 1]); | |
19e6b90e | 3947 | |
b40bf0a2 NC |
3948 | /* Display the contents of the Directory table. */ |
3949 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 3950 | |
77145576 | 3951 | if (linfo.li_version >= 5) |
b40bf0a2 | 3952 | { |
dda8d76d | 3953 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 3954 | |
77145576 | 3955 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 3956 | TRUE); |
77145576 | 3957 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 3958 | FALSE); |
77145576 JK |
3959 | } |
3960 | else | |
3961 | { | |
3962 | if (*data == 0) | |
3963 | printf (_("\n The Directory Table is empty.\n")); | |
3964 | else | |
a233b20c | 3965 | { |
77145576 | 3966 | unsigned int last_dir_entry = 0; |
6937bb54 | 3967 | |
77145576 JK |
3968 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
3969 | (long)(data - start)); | |
19e6b90e | 3970 | |
77145576 JK |
3971 | while (data < end && *data != 0) |
3972 | { | |
3973 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 3974 | |
77145576 JK |
3975 | data += strnlen ((char *) data, end - data) + 1; |
3976 | } | |
19e6b90e | 3977 | |
77145576 JK |
3978 | /* PR 17512: file: 002-132094-0.004. */ |
3979 | if (data >= end - 1) | |
3980 | break; | |
3981 | } | |
19e6b90e | 3982 | |
77145576 JK |
3983 | /* Skip the NUL at the end of the table. */ |
3984 | data++; | |
19e6b90e | 3985 | |
77145576 JK |
3986 | /* Display the contents of the File Name table. */ |
3987 | if (*data == 0) | |
3988 | printf (_("\n The File Name Table is empty.\n")); | |
3989 | else | |
3990 | { | |
3991 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
3992 | (long)(data - start)); | |
3993 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 3994 | |
77145576 | 3995 | while (data < end && *data != 0) |
b40bf0a2 | 3996 | { |
77145576 | 3997 | unsigned char *name; |
cd30bcef | 3998 | dwarf_vma val; |
77145576 JK |
3999 | |
4000 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
4001 | name = data; | |
4002 | data += strnlen ((char *) data, end - data) + 1; | |
4003 | ||
cd30bcef AM |
4004 | READ_ULEB (val, data, end); |
4005 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4006 | READ_ULEB (val, data, end); | |
4007 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4008 | READ_ULEB (val, data, end); | |
4009 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
77145576 JK |
4010 | printf ("%.*s\n", (int)(end - name), name); |
4011 | ||
4012 | if (data == end) | |
4013 | { | |
4014 | warn (_("Corrupt file name table entry\n")); | |
4015 | break; | |
4016 | } | |
b40bf0a2 | 4017 | } |
a233b20c | 4018 | } |
77145576 JK |
4019 | |
4020 | /* Skip the NUL at the end of the table. */ | |
4021 | data++; | |
b40bf0a2 | 4022 | } |
19e6b90e | 4023 | |
b40bf0a2 NC |
4024 | putchar ('\n'); |
4025 | saved_linfo = linfo; | |
4026 | } | |
19e6b90e | 4027 | |
b40bf0a2 NC |
4028 | /* Now display the statements. */ |
4029 | if (data >= end_of_sequence) | |
4030 | printf (_(" No Line Number Statements.\n")); | |
4031 | else | |
4032 | { | |
4033 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 4034 | |
b40bf0a2 NC |
4035 | while (data < end_of_sequence) |
4036 | { | |
4037 | unsigned char op_code; | |
4038 | dwarf_signed_vma adv; | |
4039 | dwarf_vma uladv; | |
19e6b90e | 4040 | |
fe59e83d CC |
4041 | printf (" [0x%08lx]", (long)(data - start)); |
4042 | ||
b40bf0a2 | 4043 | op_code = *data++; |
19e6b90e | 4044 | |
b40bf0a2 | 4045 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 4046 | { |
b40bf0a2 NC |
4047 | op_code -= linfo.li_opcode_base; |
4048 | uladv = (op_code / linfo.li_line_range); | |
4049 | if (linfo.li_max_ops_per_insn == 1) | |
4050 | { | |
4051 | uladv *= linfo.li_min_insn_length; | |
4052 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4053 | if (uladv) |
4054 | state_machine_regs.view = 0; | |
b40bf0a2 | 4055 | printf (_(" Special opcode %d: " |
ba8826a8 | 4056 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 4057 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4058 | dwarf_vmatoa ("x", state_machine_regs.address), |
4059 | verbose_view && uladv | |
4060 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4061 | } |
4062 | else | |
4063 | { | |
ba8826a8 AO |
4064 | unsigned addrdelta |
4065 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
4066 | / linfo.li_max_ops_per_insn) |
4067 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
4068 | |
4069 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
4070 | state_machine_regs.op_index |
4071 | = (state_machine_regs.op_index + uladv) | |
4072 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4073 | if (addrdelta) |
4074 | state_machine_regs.view = 0; | |
b40bf0a2 | 4075 | printf (_(" Special opcode %d: " |
ba8826a8 | 4076 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
4077 | op_code, dwarf_vmatoa ("u", uladv), |
4078 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4079 | state_machine_regs.op_index, |
4080 | verbose_view && addrdelta | |
4081 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4082 | } |
4083 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
4084 | state_machine_regs.line += adv; | |
ba8826a8 | 4085 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 4086 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
4087 | if (verbose_view || state_machine_regs.view) |
4088 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4089 | else | |
4090 | putchar ('\n'); | |
4091 | state_machine_regs.view++; | |
19e6b90e | 4092 | } |
cd30bcef AM |
4093 | else |
4094 | switch (op_code) | |
4095 | { | |
4096 | case DW_LNS_extended_op: | |
4097 | data += process_extended_line_op (data, | |
4098 | linfo.li_default_is_stmt, | |
4099 | end); | |
4100 | break; | |
4101 | ||
4102 | case DW_LNS_copy: | |
4103 | printf (_(" Copy")); | |
4104 | if (verbose_view || state_machine_regs.view) | |
4105 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4106 | else | |
4107 | putchar ('\n'); | |
4108 | state_machine_regs.view++; | |
4109 | break; | |
4110 | ||
4111 | case DW_LNS_advance_pc: | |
4112 | READ_ULEB (uladv, data, end); | |
4113 | if (linfo.li_max_ops_per_insn == 1) | |
4114 | { | |
4115 | uladv *= linfo.li_min_insn_length; | |
4116 | state_machine_regs.address += uladv; | |
4117 | if (uladv) | |
4118 | state_machine_regs.view = 0; | |
4119 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
4120 | dwarf_vmatoa ("u", uladv), | |
4121 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4122 | verbose_view && uladv | |
4123 | ? _(" (reset view)") : ""); | |
4124 | } | |
4125 | else | |
4126 | { | |
4127 | unsigned addrdelta | |
4128 | = ((state_machine_regs.op_index + uladv) | |
4129 | / linfo.li_max_ops_per_insn) | |
4130 | * linfo.li_min_insn_length; | |
4131 | state_machine_regs.address | |
4132 | += addrdelta; | |
4133 | state_machine_regs.op_index | |
4134 | = (state_machine_regs.op_index + uladv) | |
4135 | % linfo.li_max_ops_per_insn; | |
4136 | if (addrdelta) | |
4137 | state_machine_regs.view = 0; | |
4138 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
4139 | dwarf_vmatoa ("u", uladv), | |
4140 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4141 | state_machine_regs.op_index, | |
4142 | verbose_view && addrdelta | |
4143 | ? _(" (reset view)") : ""); | |
4144 | } | |
4145 | break; | |
4146 | ||
4147 | case DW_LNS_advance_line: | |
4148 | READ_SLEB (adv, data, end); | |
4149 | state_machine_regs.line += adv; | |
4150 | printf (_(" Advance Line by %s to %d\n"), | |
4151 | dwarf_vmatoa ("d", adv), | |
4152 | state_machine_regs.line); | |
4153 | break; | |
4154 | ||
4155 | case DW_LNS_set_file: | |
4156 | READ_ULEB (uladv, data, end); | |
4157 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
4158 | dwarf_vmatoa ("u", uladv)); | |
4159 | state_machine_regs.file = uladv; | |
4160 | break; | |
4161 | ||
4162 | case DW_LNS_set_column: | |
4163 | READ_ULEB (uladv, data, end); | |
4164 | printf (_(" Set column to %s\n"), | |
4165 | dwarf_vmatoa ("u", uladv)); | |
4166 | state_machine_regs.column = uladv; | |
4167 | break; | |
4168 | ||
4169 | case DW_LNS_negate_stmt: | |
4170 | adv = state_machine_regs.is_stmt; | |
4171 | adv = ! adv; | |
4172 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
4173 | state_machine_regs.is_stmt = adv; | |
4174 | break; | |
4175 | ||
4176 | case DW_LNS_set_basic_block: | |
4177 | printf (_(" Set basic block\n")); | |
4178 | state_machine_regs.basic_block = 1; | |
4179 | break; | |
4180 | ||
4181 | case DW_LNS_const_add_pc: | |
4182 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4183 | if (linfo.li_max_ops_per_insn) | |
4184 | { | |
4185 | uladv *= linfo.li_min_insn_length; | |
4186 | state_machine_regs.address += uladv; | |
4187 | if (uladv) | |
4188 | state_machine_regs.view = 0; | |
4189 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
4190 | dwarf_vmatoa ("u", uladv), | |
4191 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4192 | verbose_view && uladv | |
4193 | ? _(" (reset view)") : ""); | |
4194 | } | |
4195 | else | |
4196 | { | |
4197 | unsigned addrdelta | |
4198 | = ((state_machine_regs.op_index + uladv) | |
4199 | / linfo.li_max_ops_per_insn) | |
4200 | * linfo.li_min_insn_length; | |
4201 | state_machine_regs.address | |
4202 | += addrdelta; | |
4203 | state_machine_regs.op_index | |
4204 | = (state_machine_regs.op_index + uladv) | |
4205 | % linfo.li_max_ops_per_insn; | |
4206 | if (addrdelta) | |
4207 | state_machine_regs.view = 0; | |
4208 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
4209 | dwarf_vmatoa ("u", uladv), | |
4210 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4211 | state_machine_regs.op_index, | |
4212 | verbose_view && addrdelta | |
4213 | ? _(" (reset view)") : ""); | |
4214 | } | |
4215 | break; | |
4216 | ||
4217 | case DW_LNS_fixed_advance_pc: | |
4218 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4219 | state_machine_regs.address += uladv; | |
4220 | state_machine_regs.op_index = 0; | |
4221 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
4222 | dwarf_vmatoa ("u", uladv), | |
4223 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
4224 | /* Do NOT reset view. */ | |
4225 | break; | |
4226 | ||
4227 | case DW_LNS_set_prologue_end: | |
4228 | printf (_(" Set prologue_end to true\n")); | |
4229 | break; | |
4230 | ||
4231 | case DW_LNS_set_epilogue_begin: | |
4232 | printf (_(" Set epilogue_begin to true\n")); | |
4233 | break; | |
4234 | ||
4235 | case DW_LNS_set_isa: | |
4236 | READ_ULEB (uladv, data, end); | |
4237 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
4238 | break; | |
4239 | ||
4240 | default: | |
4241 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4242 | ||
4243 | if (standard_opcodes != NULL) | |
4244 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4245 | { | |
4246 | READ_ULEB (uladv, data, end); | |
4247 | printf ("0x%s%s", dwarf_vmatoa ("x", uladv), | |
4248 | i == 1 ? "" : ", "); | |
4249 | } | |
4250 | putchar ('\n'); | |
4251 | break; | |
4252 | } | |
19e6b90e | 4253 | } |
b40bf0a2 | 4254 | putchar ('\n'); |
19e6b90e | 4255 | } |
19e6b90e L |
4256 | } |
4257 | ||
4258 | return 1; | |
4259 | } | |
4260 | ||
a262ae96 NC |
4261 | typedef struct |
4262 | { | |
467c65bc NC |
4263 | unsigned char *name; |
4264 | unsigned int directory_index; | |
4265 | unsigned int modification_date; | |
4266 | unsigned int length; | |
a262ae96 NC |
4267 | } File_Entry; |
4268 | ||
4269 | /* Output a decoded representation of the .debug_line section. */ | |
4270 | ||
4271 | static int | |
dda8d76d | 4272 | display_debug_lines_decoded (struct dwarf_section * section, |
ec1b0fbb | 4273 | unsigned char * start, |
dda8d76d NC |
4274 | unsigned char * data, |
4275 | unsigned char * end, | |
4276 | void * fileptr) | |
a262ae96 | 4277 | { |
b40bf0a2 NC |
4278 | static DWARF2_Internal_LineInfo saved_linfo; |
4279 | ||
dda8d76d | 4280 | introduce (section, FALSE); |
a262ae96 NC |
4281 | |
4282 | while (data < end) | |
4283 | { | |
4284 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4285 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4286 | unsigned char *standard_opcodes; |
4287 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4288 | int i; |
4289 | File_Entry *file_table = NULL; | |
143a3db0 | 4290 | unsigned int n_files = 0; |
a262ae96 | 4291 | unsigned char **directory_table = NULL; |
77145576 | 4292 | dwarf_vma n_directories = 0; |
a262ae96 | 4293 | |
4925cdd7 NC |
4294 | if (const_strneq (section->name, ".debug_line.") |
4295 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4296 | These are full debug_line sections. */ | |
4297 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4298 | { |
4925cdd7 | 4299 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4300 | end_of_sequence = end; |
4301 | standard_opcodes = NULL; | |
4302 | linfo = saved_linfo; | |
058037d3 NC |
4303 | /* PR 17531: file: 0522b371. */ |
4304 | if (linfo.li_line_range == 0) | |
4305 | { | |
1306a742 | 4306 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4307 | return 0; |
4308 | } | |
b40bf0a2 | 4309 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4310 | } |
a262ae96 | 4311 | else |
b4eb7656 | 4312 | { |
b40bf0a2 | 4313 | unsigned char *hdrptr; |
a262ae96 | 4314 | |
b40bf0a2 NC |
4315 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4316 | & end_of_sequence)) == NULL) | |
a233b20c | 4317 | return 0; |
0c588247 | 4318 | |
058037d3 NC |
4319 | /* PR 17531: file: 0522b371. */ |
4320 | if (linfo.li_line_range == 0) | |
4321 | { | |
4322 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4323 | linfo.li_line_range = 1; | |
4324 | } | |
b40bf0a2 | 4325 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4326 | |
b40bf0a2 NC |
4327 | /* Save a pointer to the contents of the Opcodes table. */ |
4328 | standard_opcodes = hdrptr; | |
a262ae96 | 4329 | |
b40bf0a2 NC |
4330 | /* Traverse the Directory table just to count entries. */ |
4331 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4332 | /* PR 20440 */ |
4333 | if (data >= end) | |
4334 | { | |
4335 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4336 | linfo.li_opcode_base); | |
4337 | return 0; | |
4338 | } | |
4339 | ||
77145576 | 4340 | if (linfo.li_version >= 5) |
b40bf0a2 | 4341 | { |
77145576 JK |
4342 | unsigned char *format_start, format_count, *format; |
4343 | dwarf_vma formati, entryi; | |
a262ae96 | 4344 | |
dda8d76d | 4345 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4346 | |
4347 | /* Skip directories format. */ | |
4348 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
4349 | format_start = data; | |
4350 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4351 | { |
cd30bcef AM |
4352 | SKIP_ULEB (data, end); |
4353 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4354 | } |
a262ae96 | 4355 | |
cd30bcef | 4356 | READ_ULEB (n_directories, data, end); |
77145576 | 4357 | if (data == end) |
d8024a91 | 4358 | { |
77145576 | 4359 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
4360 | break; |
4361 | } | |
4362 | ||
b40bf0a2 NC |
4363 | directory_table = (unsigned char **) |
4364 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 4365 | |
77145576 | 4366 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 4367 | { |
77145576 | 4368 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 4369 | |
77145576 JK |
4370 | format = format_start; |
4371 | for (formati = 0; formati < format_count; formati++) | |
4372 | { | |
4373 | dwarf_vma content_type, form; | |
4374 | dwarf_vma uvalue; | |
4375 | ||
cd30bcef AM |
4376 | READ_ULEB (content_type, format, end); |
4377 | READ_ULEB (form, format, end); | |
77145576 JK |
4378 | if (data == end) |
4379 | { | |
4380 | warn (_("Corrupt directories list\n")); | |
4381 | break; | |
4382 | } | |
4383 | switch (content_type) | |
4384 | { | |
4385 | case DW_LNCT_path: | |
4386 | switch (form) | |
4387 | { | |
4388 | case DW_FORM_string: | |
4389 | *pathp = data; | |
4390 | break; | |
4391 | case DW_FORM_line_strp: | |
4392 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4393 | end); | |
4394 | /* Remove const by the cast. */ | |
4395 | *pathp = (unsigned char *) | |
4396 | fetch_indirect_line_string (uvalue); | |
4397 | break; | |
4398 | } | |
4399 | break; | |
4400 | } | |
cd30bcef AM |
4401 | data = read_and_display_attr_value (0, form, 0, start, |
4402 | data, end, 0, 0, | |
77145576 JK |
4403 | linfo.li_offset_size, |
4404 | linfo.li_version, | |
4405 | NULL, 1, section, | |
ec1b0fbb | 4406 | NULL, '\t', -1); |
77145576 JK |
4407 | } |
4408 | if (data == end) | |
4409 | { | |
4410 | warn (_("Corrupt directories list\n")); | |
4411 | break; | |
4412 | } | |
4413 | } | |
a262ae96 | 4414 | |
77145576 JK |
4415 | /* Skip files format. */ |
4416 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
4417 | format_start = data; | |
4418 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4419 | { |
cd30bcef AM |
4420 | SKIP_ULEB (data, end); |
4421 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4422 | } |
a262ae96 | 4423 | |
cd30bcef | 4424 | READ_ULEB (n_files, data, end); |
77145576 | 4425 | if (data == end) |
d8024a91 | 4426 | { |
77145576 | 4427 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
4428 | break; |
4429 | } | |
4430 | ||
77145576 JK |
4431 | file_table = (File_Entry *) xcalloc (1, n_files |
4432 | * sizeof (File_Entry)); | |
a262ae96 | 4433 | |
77145576 | 4434 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 4435 | { |
77145576 | 4436 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 4437 | |
77145576 JK |
4438 | format = format_start; |
4439 | for (formati = 0; formati < format_count; formati++) | |
4440 | { | |
4441 | dwarf_vma content_type, form; | |
4442 | dwarf_vma uvalue; | |
cd30bcef | 4443 | unsigned char *tmp; |
77145576 | 4444 | |
cd30bcef AM |
4445 | READ_ULEB (content_type, format, end); |
4446 | READ_ULEB (form, format, end); | |
77145576 JK |
4447 | if (data == end) |
4448 | { | |
4449 | warn (_("Corrupt file name list\n")); | |
4450 | break; | |
4451 | } | |
4452 | switch (content_type) | |
4453 | { | |
4454 | case DW_LNCT_path: | |
4455 | switch (form) | |
4456 | { | |
4457 | case DW_FORM_string: | |
4458 | file->name = data; | |
4459 | break; | |
4460 | case DW_FORM_line_strp: | |
4461 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4462 | end); | |
4463 | /* Remove const by the cast. */ | |
4464 | file->name = (unsigned char *) | |
4465 | fetch_indirect_line_string (uvalue); | |
4466 | break; | |
4467 | } | |
4468 | break; | |
4469 | case DW_LNCT_directory_index: | |
4470 | switch (form) | |
4471 | { | |
4472 | case DW_FORM_data1: | |
4473 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
4474 | end); | |
4475 | break; | |
4476 | case DW_FORM_data2: | |
4477 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
4478 | end); | |
4479 | break; | |
4480 | case DW_FORM_udata: | |
cd30bcef AM |
4481 | tmp = data; |
4482 | READ_ULEB (file->directory_index, tmp, end); | |
77145576 JK |
4483 | break; |
4484 | } | |
4485 | break; | |
4486 | } | |
cd30bcef AM |
4487 | data = read_and_display_attr_value (0, form, 0, start, |
4488 | data, end, 0, 0, | |
77145576 JK |
4489 | linfo.li_offset_size, |
4490 | linfo.li_version, | |
4491 | NULL, 1, section, | |
ec1b0fbb | 4492 | NULL, '\t', -1); |
77145576 JK |
4493 | } |
4494 | if (data == end) | |
4495 | { | |
4496 | warn (_("Corrupt file name list\n")); | |
4497 | break; | |
4498 | } | |
4499 | } | |
4500 | } | |
4501 | else | |
4502 | { | |
4503 | if (*data != 0) | |
b40bf0a2 | 4504 | { |
77145576 JK |
4505 | unsigned char *ptr_directory_table = data; |
4506 | ||
4507 | while (data < end && *data != 0) | |
4508 | { | |
4509 | data += strnlen ((char *) data, end - data) + 1; | |
4510 | n_directories++; | |
4511 | } | |
4512 | ||
4513 | /* PR 20440 */ | |
4514 | if (data >= end) | |
4515 | { | |
4516 | warn (_("directory table ends unexpectedly\n")); | |
4517 | n_directories = 0; | |
4518 | break; | |
4519 | } | |
4520 | ||
4521 | /* Go through the directory table again to save the directories. */ | |
4522 | directory_table = (unsigned char **) | |
4523 | xmalloc (n_directories * sizeof (unsigned char *)); | |
4524 | ||
4525 | i = 0; | |
4526 | while (*ptr_directory_table != 0) | |
4527 | { | |
4528 | directory_table[i] = ptr_directory_table; | |
4529 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
4530 | ptr_directory_table - end) + 1; | |
4531 | i++; | |
4532 | } | |
b40bf0a2 | 4533 | } |
77145576 JK |
4534 | /* Skip the NUL at the end of the table. */ |
4535 | data++; | |
4536 | ||
4537 | /* Traverse the File Name table just to count the entries. */ | |
4538 | if (data < end && *data != 0) | |
b40bf0a2 | 4539 | { |
77145576 JK |
4540 | unsigned char *ptr_file_name_table = data; |
4541 | ||
4542 | while (data < end && *data != 0) | |
db9537d2 | 4543 | { |
cd30bcef AM |
4544 | /* Skip Name, directory index, last modification |
4545 | time and length of file. */ | |
77145576 | 4546 | data += strnlen ((char *) data, end - data) + 1; |
cd30bcef AM |
4547 | SKIP_ULEB (data, end); |
4548 | SKIP_ULEB (data, end); | |
4549 | SKIP_ULEB (data, end); | |
77145576 | 4550 | n_files++; |
db9537d2 | 4551 | } |
a262ae96 | 4552 | |
77145576 JK |
4553 | if (data >= end) |
4554 | { | |
4555 | warn (_("file table ends unexpectedly\n")); | |
4556 | n_files = 0; | |
4557 | break; | |
4558 | } | |
4559 | ||
4560 | /* Go through the file table again to save the strings. */ | |
4561 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 4562 | |
77145576 JK |
4563 | i = 0; |
4564 | while (*ptr_file_name_table != 0) | |
4565 | { | |
77145576 JK |
4566 | file_table[i].name = ptr_file_name_table; |
4567 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
4568 | end - ptr_file_name_table) + 1; | |
4569 | ||
4570 | /* We are not interested in directory, time or size. */ | |
cd30bcef AM |
4571 | READ_ULEB (file_table[i].directory_index, |
4572 | ptr_file_name_table, end); | |
4573 | READ_ULEB (file_table[i].modification_date, | |
4574 | ptr_file_name_table, end); | |
4575 | READ_ULEB (file_table[i].length, | |
4576 | ptr_file_name_table, end); | |
77145576 JK |
4577 | i++; |
4578 | } | |
4579 | i = 0; | |
b40bf0a2 | 4580 | } |
77145576 JK |
4581 | |
4582 | /* Skip the NUL at the end of the table. */ | |
4583 | data++; | |
b40bf0a2 | 4584 | } |
cc5914eb | 4585 | |
77145576 | 4586 | /* Print the Compilation Unit's name and a header. */ |
f082820d AM |
4587 | if (file_table == NULL) |
4588 | ; | |
4589 | else if (directory_table == NULL) | |
4590 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
4591 | else |
4592 | { | |
4593 | unsigned int ix = file_table[0].directory_index; | |
4594 | const char *directory; | |
4595 | ||
4596 | if (ix == 0) | |
4597 | directory = "."; | |
4598 | /* PR 20439 */ | |
4599 | else if (n_directories == 0) | |
4600 | directory = _("<unknown>"); | |
4601 | else if (ix > n_directories) | |
4602 | { | |
4603 | warn (_("directory index %u > number of directories %s\n"), | |
4604 | ix, dwarf_vmatoa ("u", n_directories)); | |
4605 | directory = _("<corrupt>"); | |
4606 | } | |
4607 | else | |
4608 | directory = (char *) directory_table[ix - 1]; | |
4609 | ||
4610 | if (do_wide || strlen (directory) < 76) | |
4611 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
4612 | else | |
4613 | printf ("%s:\n", file_table[0].name); | |
77145576 | 4614 | } |
a262ae96 | 4615 | |
17f6ade2 | 4616 | printf (_("File name Line number Starting address View Stmt\n")); |
b40bf0a2 NC |
4617 | saved_linfo = linfo; |
4618 | } | |
a262ae96 NC |
4619 | |
4620 | /* This loop iterates through the Dwarf Line Number Program. */ | |
4621 | while (data < end_of_sequence) | |
b4eb7656 | 4622 | { |
a262ae96 | 4623 | unsigned char op_code; |
ba8826a8 | 4624 | int xop; |
b4eb7656 AM |
4625 | int adv; |
4626 | unsigned long int uladv; | |
b4eb7656 | 4627 | int is_special_opcode = 0; |
a262ae96 | 4628 | |
b4eb7656 | 4629 | op_code = *data++; |
ba8826a8 | 4630 | xop = op_code; |
a262ae96 | 4631 | |
b4eb7656 | 4632 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 4633 | { |
91d6fa6a | 4634 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
4635 | uladv = (op_code / linfo.li_line_range); |
4636 | if (linfo.li_max_ops_per_insn == 1) | |
4637 | { | |
4638 | uladv *= linfo.li_min_insn_length; | |
4639 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4640 | if (uladv) |
4641 | state_machine_regs.view = 0; | |
a233b20c JJ |
4642 | } |
4643 | else | |
4644 | { | |
ba8826a8 AO |
4645 | unsigned addrdelta |
4646 | = ((state_machine_regs.op_index + uladv) | |
4647 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4648 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4649 | state_machine_regs.address |
4650 | += addrdelta; | |
a233b20c JJ |
4651 | state_machine_regs.op_index |
4652 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 4653 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
4654 | if (addrdelta) |
4655 | state_machine_regs.view = 0; | |
a233b20c | 4656 | } |
a262ae96 | 4657 | |
b4eb7656 AM |
4658 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
4659 | state_machine_regs.line += adv; | |
4660 | is_special_opcode = 1; | |
ba8826a8 | 4661 | /* Increment view after printing this row. */ |
b4eb7656 | 4662 | } |
cd30bcef AM |
4663 | else |
4664 | switch (op_code) | |
4665 | { | |
4666 | case DW_LNS_extended_op: | |
4667 | { | |
4668 | unsigned int ext_op_code_len; | |
4669 | unsigned char ext_op_code; | |
4670 | unsigned char *op_code_end; | |
4671 | unsigned char *op_code_data = data; | |
4672 | ||
4673 | READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence); | |
4674 | op_code_end = op_code_data + ext_op_code_len; | |
4675 | if (ext_op_code_len == 0 || op_code_end > end_of_sequence) | |
4676 | { | |
4677 | warn (_("Badly formed extended line op encountered!\n")); | |
4678 | break; | |
4679 | } | |
4680 | ext_op_code = *op_code_data++; | |
4681 | xop = ext_op_code; | |
4682 | xop = -xop; | |
4683 | ||
4684 | switch (ext_op_code) | |
4685 | { | |
4686 | case DW_LNE_end_sequence: | |
4687 | /* Reset stuff after printing this row. */ | |
4688 | break; | |
4689 | case DW_LNE_set_address: | |
4690 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
4691 | op_code_data, | |
4692 | op_code_end - op_code_data, | |
4693 | op_code_end); | |
4694 | state_machine_regs.op_index = 0; | |
4695 | state_machine_regs.view = 0; | |
4696 | break; | |
4697 | case DW_LNE_define_file: | |
4698 | file_table = (File_Entry *) xrealloc | |
4699 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
4700 | ||
4701 | ++state_machine_regs.last_file_entry; | |
4702 | /* Source file name. */ | |
4703 | file_table[n_files].name = op_code_data; | |
4704 | op_code_data += strlen ((char *) op_code_data) + 1; | |
4705 | /* Directory index. */ | |
4706 | READ_ULEB (file_table[n_files].directory_index, | |
4707 | op_code_data, op_code_end); | |
4708 | /* Last modification time. */ | |
4709 | READ_ULEB (file_table[n_files].modification_date, | |
4710 | op_code_data, op_code_end); | |
4711 | /* File length. */ | |
4712 | READ_ULEB (file_table[n_files].length, | |
4713 | op_code_data, op_code_end); | |
4714 | n_files++; | |
4715 | break; | |
4716 | ||
4717 | case DW_LNE_set_discriminator: | |
4718 | case DW_LNE_HP_set_sequence: | |
4719 | /* Simply ignored. */ | |
4720 | break; | |
4721 | ||
4722 | default: | |
4723 | printf (_("UNKNOWN (%u): length %ld\n"), | |
27653fba | 4724 | ext_op_code, (long int) (op_code_data - data)); |
cd30bcef AM |
4725 | break; |
4726 | } | |
4727 | data = op_code_end; | |
4728 | break; | |
4729 | } | |
4730 | case DW_LNS_copy: | |
4731 | /* Increment view after printing this row. */ | |
4732 | break; | |
4733 | ||
4734 | case DW_LNS_advance_pc: | |
4735 | READ_ULEB (uladv, data, end); | |
4736 | if (linfo.li_max_ops_per_insn == 1) | |
4737 | { | |
4738 | uladv *= linfo.li_min_insn_length; | |
4739 | state_machine_regs.address += uladv; | |
4740 | if (uladv) | |
4741 | state_machine_regs.view = 0; | |
4742 | } | |
4743 | else | |
4744 | { | |
4745 | unsigned addrdelta | |
4746 | = ((state_machine_regs.op_index + uladv) | |
4747 | / linfo.li_max_ops_per_insn) | |
4748 | * linfo.li_min_insn_length; | |
4749 | state_machine_regs.address | |
4750 | += addrdelta; | |
4751 | state_machine_regs.op_index | |
4752 | = (state_machine_regs.op_index + uladv) | |
4753 | % linfo.li_max_ops_per_insn; | |
4754 | if (addrdelta) | |
4755 | state_machine_regs.view = 0; | |
4756 | } | |
4757 | break; | |
4758 | ||
4759 | case DW_LNS_advance_line: | |
4760 | READ_SLEB (adv, data, end); | |
4761 | state_machine_regs.line += adv; | |
4762 | break; | |
4763 | ||
4764 | case DW_LNS_set_file: | |
4765 | READ_ULEB (uladv, data, end); | |
4766 | state_machine_regs.file = uladv; | |
4767 | ||
4768 | { | |
4769 | unsigned file = state_machine_regs.file - 1; | |
4770 | unsigned dir; | |
4771 | ||
4772 | if (file_table == NULL || n_files == 0) | |
4773 | printf (_("\n [Use file table entry %d]\n"), file); | |
4774 | /* PR 20439 */ | |
4775 | else if (file >= n_files) | |
4776 | { | |
4777 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
4778 | printf (_("\n <over large file table index %u>"), file); | |
4779 | } | |
4780 | else if ((dir = file_table[file].directory_index) == 0) | |
4781 | /* If directory index is 0, that means current directory. */ | |
4782 | printf ("\n./%s:[++]\n", file_table[file].name); | |
4783 | else if (directory_table == NULL || n_directories == 0) | |
4784 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
4785 | file_table[file].name, dir); | |
4786 | /* PR 20439 */ | |
4787 | else if (dir > n_directories) | |
4788 | { | |
4789 | warn (_("directory index %u > number of directories %s\n"), | |
4790 | dir, dwarf_vmatoa ("u", n_directories)); | |
4791 | printf (_("\n <over large directory table entry %u>\n"), dir); | |
4792 | } | |
4793 | else | |
4794 | printf ("\n%s/%s:\n", | |
4795 | /* The directory index starts counting at 1. */ | |
4796 | directory_table[dir - 1], file_table[file].name); | |
4797 | } | |
4798 | break; | |
4799 | ||
4800 | case DW_LNS_set_column: | |
4801 | READ_ULEB (uladv, data, end); | |
4802 | state_machine_regs.column = uladv; | |
4803 | break; | |
4804 | ||
4805 | case DW_LNS_negate_stmt: | |
4806 | adv = state_machine_regs.is_stmt; | |
4807 | adv = ! adv; | |
4808 | state_machine_regs.is_stmt = adv; | |
4809 | break; | |
4810 | ||
4811 | case DW_LNS_set_basic_block: | |
4812 | state_machine_regs.basic_block = 1; | |
4813 | break; | |
4814 | ||
4815 | case DW_LNS_const_add_pc: | |
4816 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4817 | if (linfo.li_max_ops_per_insn == 1) | |
4818 | { | |
4819 | uladv *= linfo.li_min_insn_length; | |
4820 | state_machine_regs.address += uladv; | |
4821 | if (uladv) | |
4822 | state_machine_regs.view = 0; | |
4823 | } | |
4824 | else | |
4825 | { | |
4826 | unsigned addrdelta | |
4827 | = ((state_machine_regs.op_index + uladv) | |
4828 | / linfo.li_max_ops_per_insn) | |
4829 | * linfo.li_min_insn_length; | |
4830 | state_machine_regs.address | |
4831 | += addrdelta; | |
4832 | state_machine_regs.op_index | |
4833 | = (state_machine_regs.op_index + uladv) | |
4834 | % linfo.li_max_ops_per_insn; | |
4835 | if (addrdelta) | |
4836 | state_machine_regs.view = 0; | |
4837 | } | |
4838 | break; | |
4839 | ||
4840 | case DW_LNS_fixed_advance_pc: | |
4841 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4842 | state_machine_regs.address += uladv; | |
4843 | state_machine_regs.op_index = 0; | |
4844 | /* Do NOT reset view. */ | |
4845 | break; | |
4846 | ||
4847 | case DW_LNS_set_prologue_end: | |
4848 | break; | |
4849 | ||
4850 | case DW_LNS_set_epilogue_begin: | |
4851 | break; | |
4852 | ||
4853 | case DW_LNS_set_isa: | |
4854 | READ_ULEB (uladv, data, end); | |
4855 | printf (_(" Set ISA to %lu\n"), uladv); | |
4856 | break; | |
4857 | ||
4858 | default: | |
4859 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4860 | ||
4861 | if (standard_opcodes != NULL) | |
4862 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4863 | { | |
4864 | dwarf_vma val; | |
4865 | ||
4866 | READ_ULEB (val, data, end); | |
4867 | printf ("0x%s%s", dwarf_vmatoa ("x", val), | |
4868 | i == 1 ? "" : ", "); | |
4869 | } | |
4870 | putchar ('\n'); | |
4871 | break; | |
4872 | } | |
a262ae96 | 4873 | |
b4eb7656 AM |
4874 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
4875 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
4876 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
4877 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
4878 | { |
4879 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
4880 | char *fileName; | |
4881 | char *newFileName = NULL; | |
4882 | size_t fileNameLength; | |
b40bf0a2 NC |
4883 | |
4884 | if (file_table) | |
db9537d2 NC |
4885 | { |
4886 | unsigned indx = state_machine_regs.file - 1; | |
4887 | /* PR 20439 */ | |
4888 | if (indx >= n_files) | |
4889 | { | |
4890 | warn (_("corrupt file index %u encountered\n"), indx); | |
4891 | fileName = _("<corrupt>"); | |
4892 | } | |
4893 | else | |
4894 | fileName = (char *) file_table[indx].name; | |
4895 | } | |
b40bf0a2 | 4896 | else |
db9537d2 | 4897 | fileName = _("<unknown>"); |
b40bf0a2 NC |
4898 | |
4899 | fileNameLength = strlen (fileName); | |
a262ae96 | 4900 | |
b4eb7656 AM |
4901 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
4902 | { | |
4903 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
4904 | /* Truncate file name */ | |
4905 | strncpy (newFileName, | |
4906 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
4907 | MAX_FILENAME_LENGTH + 1); | |
4908 | } | |
4909 | else | |
4910 | { | |
4911 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
4912 | strncpy (newFileName, fileName, fileNameLength + 1); | |
4913 | } | |
4914 | ||
4915 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) | |
4916 | { | |
a233b20c | 4917 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 4918 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 4919 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4920 | state_machine_regs.address); |
4921 | else | |
ba8826a8 | 4922 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 4923 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4924 | state_machine_regs.address, |
4925 | state_machine_regs.op_index); | |
b4eb7656 AM |
4926 | } |
4927 | else | |
4928 | { | |
a233b20c | 4929 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 4930 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 4931 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4932 | state_machine_regs.address); |
4933 | else | |
ba8826a8 | 4934 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 4935 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4936 | state_machine_regs.address, |
4937 | state_machine_regs.op_index); | |
b4eb7656 | 4938 | } |
a262ae96 | 4939 | |
ba8826a8 | 4940 | if (state_machine_regs.view) |
17f6ade2 | 4941 | printf (" %6u", state_machine_regs.view); |
ba8826a8 | 4942 | else |
17f6ade2 JD |
4943 | printf (" "); |
4944 | ||
4945 | if (state_machine_regs.is_stmt) | |
4946 | printf (" x"); | |
4947 | ||
4948 | putchar ('\n'); | |
ba8826a8 AO |
4949 | state_machine_regs.view++; |
4950 | ||
4951 | if (xop == -DW_LNE_end_sequence) | |
4952 | { | |
4953 | reset_state_machine (linfo.li_default_is_stmt); | |
4954 | putchar ('\n'); | |
4955 | } | |
a262ae96 | 4956 | |
b4eb7656 AM |
4957 | free (newFileName); |
4958 | } | |
4959 | } | |
b40bf0a2 NC |
4960 | |
4961 | if (file_table) | |
4962 | { | |
4963 | free (file_table); | |
4964 | file_table = NULL; | |
4965 | n_files = 0; | |
4966 | } | |
4967 | ||
4968 | if (directory_table) | |
4969 | { | |
4970 | free (directory_table); | |
4971 | directory_table = NULL; | |
4972 | n_directories = 0; | |
4973 | } | |
4974 | ||
a262ae96 NC |
4975 | putchar ('\n'); |
4976 | } | |
4977 | ||
4978 | return 1; | |
4979 | } | |
4980 | ||
4981 | static int | |
77145576 | 4982 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
4983 | { |
4984 | unsigned char *data = section->start; | |
4985 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
4986 | int retValRaw = 1; |
4987 | int retValDecoded = 1; | |
a262ae96 | 4988 | |
008f4c78 NC |
4989 | if (do_debug_lines == 0) |
4990 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
4991 | ||
4cb93e3b | 4992 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 4993 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 4994 | |
4cb93e3b | 4995 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
ec1b0fbb | 4996 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
a262ae96 | 4997 | |
4cb93e3b | 4998 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
4999 | return 0; |
5000 | ||
5001 | return 1; | |
5002 | } | |
5003 | ||
6e3d6dc1 NC |
5004 | static debug_info * |
5005 | find_debug_info_for_offset (unsigned long offset) | |
5006 | { | |
5007 | unsigned int i; | |
5008 | ||
5009 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
5010 | return NULL; | |
5011 | ||
5012 | for (i = 0; i < num_debug_info_entries; i++) | |
5013 | if (debug_information[i].cu_offset == offset) | |
5014 | return debug_information + i; | |
5015 | ||
5016 | return NULL; | |
5017 | } | |
5018 | ||
459d52c8 DE |
5019 | static const char * |
5020 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
5021 | { | |
5022 | /* See gdb/gdb-index.h. */ | |
5023 | static const char * const kinds[] = | |
5024 | { | |
5025 | N_ ("no info"), | |
5026 | N_ ("type"), | |
5027 | N_ ("variable"), | |
5028 | N_ ("function"), | |
5029 | N_ ("other"), | |
5030 | N_ ("unused5"), | |
5031 | N_ ("unused6"), | |
5032 | N_ ("unused7") | |
5033 | }; | |
5034 | ||
5035 | return _ (kinds[kind]); | |
5036 | } | |
5037 | ||
19e6b90e | 5038 | static int |
459d52c8 DE |
5039 | display_debug_pubnames_worker (struct dwarf_section *section, |
5040 | void *file ATTRIBUTE_UNUSED, | |
5041 | int is_gnu) | |
19e6b90e | 5042 | { |
91d6fa6a | 5043 | DWARF2_Internal_PubNames names; |
19e6b90e L |
5044 | unsigned char *start = section->start; |
5045 | unsigned char *end = start + section->size; | |
5046 | ||
6e3d6dc1 NC |
5047 | /* It does not matter if this load fails, |
5048 | we test for that later on. */ | |
5049 | load_debug_info (file); | |
5050 | ||
dda8d76d | 5051 | introduce (section, FALSE); |
19e6b90e L |
5052 | |
5053 | while (start < end) | |
5054 | { | |
5055 | unsigned char *data; | |
e98fdf1a | 5056 | unsigned long sec_off; |
bf5117e3 | 5057 | unsigned int offset_size, initial_length_size; |
19e6b90e | 5058 | |
e98fdf1a | 5059 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 5060 | if (names.pn_length == 0xffffffff) |
19e6b90e | 5061 | { |
e98fdf1a | 5062 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e L |
5063 | offset_size = 8; |
5064 | initial_length_size = 12; | |
5065 | } | |
5066 | else | |
5067 | { | |
5068 | offset_size = 4; | |
5069 | initial_length_size = 4; | |
5070 | } | |
5071 | ||
e98fdf1a AM |
5072 | sec_off = start - section->start; |
5073 | if (sec_off + names.pn_length < sec_off | |
5074 | || sec_off + names.pn_length > section->size) | |
5075 | { | |
5076 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
5077 | section->name, | |
5078 | sec_off - initial_length_size, | |
5079 | dwarf_vmatoa ("x", names.pn_length)); | |
5080 | break; | |
5081 | } | |
5082 | ||
5083 | data = start; | |
5084 | start += names.pn_length; | |
5085 | ||
0c588247 NC |
5086 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
5087 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
5088 | |
5089 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
5090 | && num_debug_info_entries > 0 | |
91d6fa6a | 5091 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 5092 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 5093 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 5094 | |
0c588247 | 5095 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 5096 | |
058037d3 NC |
5097 | printf (_(" Length: %ld\n"), |
5098 | (long) names.pn_length); | |
5099 | printf (_(" Version: %d\n"), | |
5100 | names.pn_version); | |
5101 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
5102 | (unsigned long) names.pn_offset); | |
5103 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
5104 | (long) names.pn_size); | |
19e6b90e | 5105 | |
91d6fa6a | 5106 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
5107 | { |
5108 | static int warned = 0; | |
5109 | ||
5110 | if (! warned) | |
5111 | { | |
5112 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
5113 | warned = 1; | |
5114 | } | |
5115 | ||
5116 | continue; | |
5117 | } | |
5118 | ||
459d52c8 DE |
5119 | if (is_gnu) |
5120 | printf (_("\n Offset Kind Name\n")); | |
5121 | else | |
5122 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 5123 | |
e98fdf1a | 5124 | while (1) |
19e6b90e | 5125 | { |
f41e4712 | 5126 | bfd_size_type maxprint; |
e98fdf1a | 5127 | dwarf_vma offset; |
f41e4712 | 5128 | |
0c588247 | 5129 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e | 5130 | |
e98fdf1a AM |
5131 | if (offset == 0) |
5132 | break; | |
b4eb7656 | 5133 | |
e98fdf1a AM |
5134 | data += offset_size; |
5135 | if (data >= end) | |
5136 | break; | |
5137 | maxprint = (end - data) - 1; | |
f41e4712 | 5138 | |
e98fdf1a AM |
5139 | if (is_gnu) |
5140 | { | |
5141 | unsigned int kind_data; | |
5142 | gdb_index_symbol_kind kind; | |
5143 | const char *kind_name; | |
5144 | int is_static; | |
5145 | ||
5146 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
5147 | data++; | |
5148 | maxprint --; | |
5149 | /* GCC computes the kind as the upper byte in the CU index | |
5150 | word, and then right shifts it by the CU index size. | |
5151 | Left shift KIND to where the gdb-index.h accessor macros | |
5152 | can use it. */ | |
5153 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
5154 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
5155 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
5156 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
5157 | printf (" %-6lx %s,%-10s %.*s\n", | |
5158 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
5159 | kind_name, (int) maxprint, data); | |
19e6b90e | 5160 | } |
e98fdf1a AM |
5161 | else |
5162 | printf (" %-6lx\t%.*s\n", | |
5163 | (unsigned long) offset, (int) maxprint, data); | |
5164 | ||
5165 | data += strnlen ((char *) data, maxprint) + 1; | |
5166 | if (data >= end) | |
5167 | break; | |
19e6b90e | 5168 | } |
19e6b90e L |
5169 | } |
5170 | ||
5171 | printf ("\n"); | |
5172 | return 1; | |
5173 | } | |
5174 | ||
459d52c8 DE |
5175 | static int |
5176 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
5177 | { | |
5178 | return display_debug_pubnames_worker (section, file, 0); | |
5179 | } | |
5180 | ||
5181 | static int | |
5182 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
5183 | { | |
5184 | return display_debug_pubnames_worker (section, file, 1); | |
5185 | } | |
5186 | ||
19e6b90e L |
5187 | static int |
5188 | display_debug_macinfo (struct dwarf_section *section, | |
5189 | void *file ATTRIBUTE_UNUSED) | |
5190 | { | |
5191 | unsigned char *start = section->start; | |
5192 | unsigned char *end = start + section->size; | |
5193 | unsigned char *curr = start; | |
19e6b90e L |
5194 | enum dwarf_macinfo_record_type op; |
5195 | ||
dda8d76d | 5196 | introduce (section, FALSE); |
19e6b90e L |
5197 | |
5198 | while (curr < end) | |
5199 | { | |
5200 | unsigned int lineno; | |
0c588247 | 5201 | const unsigned char *string; |
19e6b90e | 5202 | |
3f5e193b | 5203 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
5204 | curr++; |
5205 | ||
5206 | switch (op) | |
5207 | { | |
5208 | case DW_MACINFO_start_file: | |
5209 | { | |
5210 | unsigned int filenum; | |
5211 | ||
cd30bcef AM |
5212 | READ_ULEB (lineno, curr, end); |
5213 | READ_ULEB (filenum, curr, end); | |
19e6b90e L |
5214 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), |
5215 | lineno, filenum); | |
5216 | } | |
5217 | break; | |
5218 | ||
5219 | case DW_MACINFO_end_file: | |
5220 | printf (_(" DW_MACINFO_end_file\n")); | |
5221 | break; | |
5222 | ||
5223 | case DW_MACINFO_define: | |
cd30bcef | 5224 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5225 | string = curr; |
5226 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5227 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
5228 | lineno, string); | |
5229 | break; | |
5230 | ||
5231 | case DW_MACINFO_undef: | |
cd30bcef | 5232 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5233 | string = curr; |
5234 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5235 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
5236 | lineno, string); | |
5237 | break; | |
5238 | ||
5239 | case DW_MACINFO_vendor_ext: | |
5240 | { | |
5241 | unsigned int constant; | |
5242 | ||
cd30bcef | 5243 | READ_ULEB (constant, curr, end); |
0c588247 NC |
5244 | string = curr; |
5245 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5246 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
5247 | constant, string); | |
5248 | } | |
5249 | break; | |
5250 | } | |
5251 | } | |
5252 | ||
5253 | return 1; | |
5254 | } | |
5255 | ||
4ccf1e31 JJ |
5256 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5257 | filename and dirname corresponding to file name table entry with index | |
5258 | FILEIDX. Return NULL on failure. */ | |
5259 | ||
5260 | static unsigned char * | |
f6f0e17b NC |
5261 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5262 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5263 | unsigned char **dir_name) |
5264 | { | |
5265 | struct dwarf_section *section = &debug_displays [line].section; | |
5266 | unsigned char *hdrptr, *dirtable, *file_name; | |
5267 | unsigned int offset_size, initial_length_size; | |
cd30bcef | 5268 | unsigned int version, opcode_base; |
4ccf1e31 | 5269 | dwarf_vma length, diridx; |
f6f0e17b | 5270 | const unsigned char * end; |
4ccf1e31 JJ |
5271 | |
5272 | *dir_name = NULL; | |
5273 | if (section->start == NULL | |
5274 | || line_offset >= section->size | |
5275 | || fileidx == 0) | |
5276 | return NULL; | |
5277 | ||
5278 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5279 | end = section->start + section->size; |
0c588247 NC |
5280 | |
5281 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5282 | if (length == 0xffffffff) |
5283 | { | |
5284 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5285 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
5286 | offset_size = 8; |
5287 | initial_length_size = 12; | |
5288 | } | |
5289 | else | |
5290 | { | |
5291 | offset_size = 4; | |
5292 | initial_length_size = 4; | |
5293 | } | |
e98fdf1a AM |
5294 | if (length + initial_length_size < length |
5295 | || length + initial_length_size > section->size) | |
4ccf1e31 | 5296 | return NULL; |
0c588247 NC |
5297 | |
5298 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5299 | if (version != 2 && version != 3 && version != 4) |
5300 | return NULL; | |
5301 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5302 | if (version >= 4) | |
5303 | hdrptr++; /* Skip max_ops_per_insn. */ | |
5304 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
5305 | |
5306 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
5307 | if (opcode_base == 0) |
5308 | return NULL; | |
0c588247 | 5309 | |
4ccf1e31 | 5310 | hdrptr += opcode_base - 1; |
5c1c468d NC |
5311 | if (hdrptr >= end) |
5312 | return NULL; | |
5313 | ||
4ccf1e31 JJ |
5314 | dirtable = hdrptr; |
5315 | /* Skip over dirname table. */ | |
5316 | while (*hdrptr != '\0') | |
5c1c468d NC |
5317 | { |
5318 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; | |
5319 | if (hdrptr >= end) | |
5320 | return NULL; | |
5321 | } | |
4ccf1e31 | 5322 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 5323 | |
4ccf1e31 | 5324 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 5325 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 5326 | { |
0c588247 | 5327 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
cd30bcef AM |
5328 | SKIP_ULEB (hdrptr, end); |
5329 | SKIP_ULEB (hdrptr, end); | |
5330 | SKIP_ULEB (hdrptr, end); | |
4ccf1e31 | 5331 | } |
5c1c468d | 5332 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 5333 | return NULL; |
5c1c468d | 5334 | |
4ccf1e31 | 5335 | file_name = hdrptr; |
0c588247 | 5336 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
5c1c468d NC |
5337 | if (hdrptr >= end) |
5338 | return NULL; | |
cd30bcef | 5339 | READ_ULEB (diridx, hdrptr, end); |
4ccf1e31 JJ |
5340 | if (diridx == 0) |
5341 | return file_name; | |
5c1c468d | 5342 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
0c588247 | 5343 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
5c1c468d | 5344 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
5345 | return NULL; |
5346 | *dir_name = dirtable; | |
5347 | return file_name; | |
5348 | } | |
5349 | ||
5350 | static int | |
5351 | display_debug_macro (struct dwarf_section *section, | |
5352 | void *file) | |
5353 | { | |
5354 | unsigned char *start = section->start; | |
5355 | unsigned char *end = start + section->size; | |
5356 | unsigned char *curr = start; | |
5357 | unsigned char *extended_op_buf[256]; | |
4ccf1e31 | 5358 | |
dda8d76d NC |
5359 | load_debug_section_with_follow (str, file); |
5360 | load_debug_section_with_follow (line, file); | |
4ccf1e31 | 5361 | |
dda8d76d | 5362 | introduce (section, FALSE); |
4ccf1e31 JJ |
5363 | |
5364 | while (curr < end) | |
5365 | { | |
5366 | unsigned int lineno, version, flags; | |
5367 | unsigned int offset_size = 4; | |
0c588247 | 5368 | const unsigned char *string; |
4ccf1e31 JJ |
5369 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
5370 | unsigned char **extended_ops = NULL; | |
5371 | ||
0c588247 | 5372 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 5373 | if (version != 4 && version != 5) |
4ccf1e31 | 5374 | { |
7a7e1061 | 5375 | error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"), |
4ccf1e31 JJ |
5376 | section->name); |
5377 | return 0; | |
5378 | } | |
5379 | ||
0c588247 | 5380 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
4ccf1e31 JJ |
5381 | if (flags & 1) |
5382 | offset_size = 8; | |
5383 | printf (_(" Offset: 0x%lx\n"), | |
5384 | (unsigned long) sec_offset); | |
5385 | printf (_(" Version: %d\n"), version); | |
5386 | printf (_(" Offset size: %d\n"), offset_size); | |
5387 | if (flags & 2) | |
5388 | { | |
0c588247 | 5389 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
5390 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
5391 | (unsigned long) line_offset); | |
5392 | } | |
5393 | if (flags & 4) | |
5394 | { | |
0c588247 | 5395 | unsigned int i, count, op; |
4ccf1e31 | 5396 | dwarf_vma nargs, n; |
0c588247 NC |
5397 | |
5398 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 5399 | |
4ccf1e31 JJ |
5400 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
5401 | extended_ops = extended_op_buf; | |
5402 | if (count) | |
5403 | { | |
5404 | printf (_(" Extension opcode arguments:\n")); | |
5405 | for (i = 0; i < count; i++) | |
5406 | { | |
0c588247 | 5407 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 5408 | extended_ops[op] = curr; |
cd30bcef | 5409 | READ_ULEB (nargs, curr, end); |
4ccf1e31 | 5410 | if (nargs == 0) |
7a7e1061 | 5411 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
5412 | else |
5413 | { | |
7a7e1061 | 5414 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
5415 | for (n = 0; n < nargs; n++) |
5416 | { | |
0c588247 NC |
5417 | unsigned int form; |
5418 | ||
5419 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
5420 | printf ("%s%s", get_FORM_name (form), |
5421 | n == nargs - 1 ? "\n" : ", "); | |
5422 | switch (form) | |
5423 | { | |
5424 | case DW_FORM_data1: | |
5425 | case DW_FORM_data2: | |
5426 | case DW_FORM_data4: | |
5427 | case DW_FORM_data8: | |
5428 | case DW_FORM_sdata: | |
5429 | case DW_FORM_udata: | |
5430 | case DW_FORM_block: | |
5431 | case DW_FORM_block1: | |
5432 | case DW_FORM_block2: | |
5433 | case DW_FORM_block4: | |
5434 | case DW_FORM_flag: | |
5435 | case DW_FORM_string: | |
5436 | case DW_FORM_strp: | |
5437 | case DW_FORM_sec_offset: | |
5438 | break; | |
5439 | default: | |
5440 | error (_("Invalid extension opcode form %s\n"), | |
5441 | get_FORM_name (form)); | |
5442 | return 0; | |
5443 | } | |
5444 | } | |
5445 | } | |
5446 | } | |
5447 | } | |
5448 | } | |
5449 | printf ("\n"); | |
5450 | ||
5451 | while (1) | |
5452 | { | |
5453 | unsigned int op; | |
5454 | ||
5455 | if (curr >= end) | |
5456 | { | |
5457 | error (_(".debug_macro section not zero terminated\n")); | |
5458 | return 0; | |
5459 | } | |
5460 | ||
0c588247 | 5461 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
5462 | if (op == 0) |
5463 | break; | |
5464 | ||
5465 | switch (op) | |
5466 | { | |
7a7e1061 | 5467 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
5468 | { |
5469 | unsigned int filenum; | |
5470 | unsigned char *file_name = NULL, *dir_name = NULL; | |
5471 | ||
cd30bcef AM |
5472 | READ_ULEB (lineno, curr, end); |
5473 | READ_ULEB (filenum, curr, end); | |
4ccf1e31 JJ |
5474 | |
5475 | if ((flags & 2) == 0) | |
7a7e1061 | 5476 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
5477 | else |
5478 | file_name | |
5479 | = get_line_filename_and_dirname (line_offset, filenum, | |
5480 | &dir_name); | |
5481 | if (file_name == NULL) | |
7a7e1061 | 5482 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
5483 | lineno, filenum); |
5484 | else | |
7a7e1061 | 5485 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
5486 | lineno, filenum, |
5487 | dir_name != NULL ? (const char *) dir_name : "", | |
5488 | dir_name != NULL ? "/" : "", file_name); | |
5489 | } | |
5490 | break; | |
5491 | ||
7a7e1061 JK |
5492 | case DW_MACRO_end_file: |
5493 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
5494 | break; |
5495 | ||
7a7e1061 | 5496 | case DW_MACRO_define: |
cd30bcef | 5497 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5498 | string = curr; |
5499 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 5500 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5501 | lineno, string); |
5502 | break; | |
5503 | ||
7a7e1061 | 5504 | case DW_MACRO_undef: |
cd30bcef | 5505 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5506 | string = curr; |
5507 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 5508 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5509 | lineno, string); |
5510 | break; | |
5511 | ||
7a7e1061 | 5512 | case DW_MACRO_define_strp: |
cd30bcef | 5513 | READ_ULEB (lineno, curr, end); |
0c588247 | 5514 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5515 | string = fetch_indirect_string (offset); |
7a7e1061 | 5516 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5517 | lineno, string); |
5518 | break; | |
5519 | ||
7a7e1061 | 5520 | case DW_MACRO_undef_strp: |
cd30bcef | 5521 | READ_ULEB (lineno, curr, end); |
0c588247 | 5522 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5523 | string = fetch_indirect_string (offset); |
7a7e1061 | 5524 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5525 | lineno, string); |
5526 | break; | |
5527 | ||
7a7e1061 | 5528 | case DW_MACRO_import: |
0c588247 | 5529 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5530 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
5531 | (unsigned long) offset); |
5532 | break; | |
5533 | ||
7a7e1061 | 5534 | case DW_MACRO_define_sup: |
cd30bcef | 5535 | READ_ULEB (lineno, curr, end); |
0c588247 | 5536 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5537 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5538 | lineno, (unsigned long) offset); |
5539 | break; | |
5540 | ||
7a7e1061 | 5541 | case DW_MACRO_undef_sup: |
cd30bcef | 5542 | READ_ULEB (lineno, curr, end); |
0c588247 | 5543 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5544 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5545 | lineno, (unsigned long) offset); |
5546 | break; | |
5547 | ||
7a7e1061 | 5548 | case DW_MACRO_import_sup: |
0c588247 | 5549 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5550 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
5551 | (unsigned long) offset); |
5552 | break; | |
5553 | ||
4ccf1e31 JJ |
5554 | default: |
5555 | if (extended_ops == NULL || extended_ops[op] == NULL) | |
5556 | { | |
5557 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
5558 | return 0; | |
5559 | } | |
5560 | else | |
5561 | { | |
5562 | /* Skip over unhandled opcodes. */ | |
5563 | dwarf_vma nargs, n; | |
5564 | unsigned char *desc = extended_ops[op]; | |
cd30bcef | 5565 | READ_ULEB (nargs, desc, end); |
4ccf1e31 JJ |
5566 | if (nargs == 0) |
5567 | { | |
7a7e1061 | 5568 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
5569 | break; |
5570 | } | |
7a7e1061 | 5571 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
5572 | for (n = 0; n < nargs; n++) |
5573 | { | |
0c588247 NC |
5574 | int val; |
5575 | ||
77145576 | 5576 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 5577 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 5578 | curr |
77145576 | 5579 | = read_and_display_attr_value (0, val, 0, |
ec1b0fbb | 5580 | start, curr, end, 0, 0, offset_size, |
341f9135 | 5581 | version, NULL, 0, NULL, |
ec1b0fbb | 5582 | NULL, ' ', -1); |
4ccf1e31 JJ |
5583 | if (n != nargs - 1) |
5584 | printf (","); | |
5585 | } | |
5586 | printf ("\n"); | |
5587 | } | |
5588 | break; | |
5589 | } | |
5590 | } | |
5591 | ||
5592 | printf ("\n"); | |
b4eb7656 | 5593 | } |
4ccf1e31 JJ |
5594 | |
5595 | return 1; | |
5596 | } | |
5597 | ||
19e6b90e L |
5598 | static int |
5599 | display_debug_abbrev (struct dwarf_section *section, | |
5600 | void *file ATTRIBUTE_UNUSED) | |
5601 | { | |
5602 | abbrev_entry *entry; | |
5603 | unsigned char *start = section->start; | |
5604 | unsigned char *end = start + section->size; | |
5605 | ||
dda8d76d | 5606 | introduce (section, FALSE); |
19e6b90e L |
5607 | |
5608 | do | |
5609 | { | |
7282333f AM |
5610 | unsigned char *last; |
5611 | ||
19e6b90e L |
5612 | free_abbrevs (); |
5613 | ||
7282333f | 5614 | last = start; |
19e6b90e L |
5615 | start = process_abbrev_section (start, end); |
5616 | ||
5617 | if (first_abbrev == NULL) | |
5618 | continue; | |
5619 | ||
7282333f | 5620 | printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start)); |
19e6b90e L |
5621 | |
5622 | for (entry = first_abbrev; entry; entry = entry->next) | |
5623 | { | |
5624 | abbrev_attr *attr; | |
5625 | ||
cc5914eb | 5626 | printf (" %ld %s [%s]\n", |
19e6b90e L |
5627 | entry->entry, |
5628 | get_TAG_name (entry->tag), | |
5629 | entry->children ? _("has children") : _("no children")); | |
5630 | ||
5631 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
5632 | { |
5633 | printf (" %-18s %s", | |
5634 | get_AT_name (attr->attribute), | |
5635 | get_FORM_name (attr->form)); | |
5636 | if (attr->form == DW_FORM_implicit_const) | |
5637 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
5638 | putchar ('\n'); | |
5639 | } | |
19e6b90e L |
5640 | } |
5641 | } | |
5642 | while (start); | |
5643 | ||
5644 | printf ("\n"); | |
5645 | ||
5646 | return 1; | |
5647 | } | |
5648 | ||
42bcef4a AB |
5649 | /* Return true when ADDR is the maximum address, when addresses are |
5650 | POINTER_SIZE bytes long. */ | |
5651 | ||
5652 | static bfd_boolean | |
5653 | is_max_address (dwarf_vma addr, unsigned int pointer_size) | |
5654 | { | |
5655 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
5656 | return ((addr & mask) == mask); | |
5657 | } | |
5658 | ||
9f272209 AO |
5659 | /* Display a view pair list starting at *VSTART_PTR and ending at |
5660 | VLISTEND within SECTION. */ | |
5661 | ||
5662 | static void | |
5663 | display_view_pair_list (struct dwarf_section *section, | |
5664 | unsigned char **vstart_ptr, | |
5665 | unsigned int debug_info_entry, | |
5666 | unsigned char *vlistend) | |
5667 | { | |
5668 | unsigned char *vstart = *vstart_ptr; | |
5669 | unsigned char *section_end = section->start + section->size; | |
5670 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
5671 | ||
5672 | if (vlistend < section_end) | |
5673 | section_end = vlistend; | |
5674 | ||
5675 | putchar ('\n'); | |
5676 | ||
5677 | while (vstart < section_end) | |
5678 | { | |
5679 | dwarf_vma off = vstart - section->start; | |
5680 | dwarf_vma vbegin, vend; | |
5681 | ||
cd30bcef | 5682 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 | 5683 | if (vstart == section_end) |
cd30bcef | 5684 | break; |
9f272209 | 5685 | |
cd30bcef | 5686 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
5687 | printf (" %8.8lx ", (unsigned long) off); |
5688 | ||
5689 | print_dwarf_view (vbegin, pointer_size, 1); | |
5690 | print_dwarf_view (vend, pointer_size, 1); | |
5691 | printf (_("location view pair\n")); | |
5692 | } | |
5693 | ||
5694 | putchar ('\n'); | |
5695 | *vstart_ptr = vstart; | |
5696 | } | |
5697 | ||
4723351a CC |
5698 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
5699 | ||
5700 | static void | |
5701 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
5702 | unsigned char **start_ptr, |
5703 | unsigned int debug_info_entry, | |
359ca075 JK |
5704 | dwarf_vma offset, |
5705 | dwarf_vma base_address, | |
9f272209 | 5706 | unsigned char **vstart_ptr, |
b4eb7656 | 5707 | int has_frame_base) |
4723351a | 5708 | { |
9f272209 | 5709 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 5710 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
5711 | unsigned long cu_offset; |
5712 | unsigned int pointer_size; | |
5713 | unsigned int offset_size; | |
5714 | int dwarf_version; | |
4723351a CC |
5715 | |
5716 | dwarf_vma begin; | |
5717 | dwarf_vma end; | |
5718 | unsigned short length; | |
5719 | int need_frame_base; | |
5720 | ||
82b1b41b NC |
5721 | if (debug_info_entry >= num_debug_info_entries) |
5722 | { | |
5723 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
5724 | debug_info_entry); | |
5725 | return; | |
5726 | } | |
b4eb7656 | 5727 | |
82b1b41b NC |
5728 | cu_offset = debug_information [debug_info_entry].cu_offset; |
5729 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5730 | offset_size = debug_information [debug_info_entry].offset_size; | |
5731 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 5732 | |
f41e4712 NC |
5733 | if (pointer_size < 2 || pointer_size > 8) |
5734 | { | |
5735 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5736 | pointer_size, debug_info_entry); | |
5737 | return; | |
5738 | } | |
5739 | ||
4723351a CC |
5740 | while (1) |
5741 | { | |
359ca075 | 5742 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 5743 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 5744 | |
4723351a | 5745 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
5746 | { |
5747 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5748 | (unsigned long) offset); |
b4eb7656 AM |
5749 | break; |
5750 | } | |
4723351a | 5751 | |
359ca075 | 5752 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 5753 | |
0c588247 NC |
5754 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
5755 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 5756 | |
4723351a | 5757 | if (begin == 0 && end == 0) |
b4eb7656 | 5758 | { |
d1c4b12b NC |
5759 | /* PR 18374: In a object file we can have a location list that |
5760 | starts with a begin and end of 0 because there are relocations | |
5761 | that need to be applied to the addresses. Actually applying | |
5762 | the relocations now does not help as they will probably resolve | |
5763 | to 0, since the object file has not been fully linked. Real | |
5764 | end of list markers will not have any relocations against them. */ | |
5765 | if (! reloc_at (section, off) | |
5766 | && ! reloc_at (section, off + pointer_size)) | |
5767 | { | |
5768 | printf (_("<End of list>\n")); | |
5769 | break; | |
5770 | } | |
b4eb7656 | 5771 | } |
4723351a CC |
5772 | |
5773 | /* Check base address specifiers. */ | |
42bcef4a AB |
5774 | if (is_max_address (begin, pointer_size) |
5775 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
5776 | { |
5777 | base_address = end; | |
5778 | print_dwarf_vma (begin, pointer_size); | |
5779 | print_dwarf_vma (end, pointer_size); | |
5780 | printf (_("(base address)\n")); | |
5781 | continue; | |
5782 | } | |
4723351a | 5783 | |
9f272209 AO |
5784 | if (vstart) |
5785 | { | |
9f272209 AO |
5786 | off = offset + (vstart - *start_ptr); |
5787 | ||
cd30bcef | 5788 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
5789 | print_dwarf_view (vbegin, pointer_size, 1); |
5790 | ||
cd30bcef | 5791 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
5792 | print_dwarf_view (vend, pointer_size, 1); |
5793 | ||
5794 | printf (_("views at %8.8lx for:\n %*s "), | |
5795 | (unsigned long) off, 8, ""); | |
5796 | } | |
5797 | ||
4723351a | 5798 | if (start + 2 > section_end) |
b4eb7656 AM |
5799 | { |
5800 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5801 | (unsigned long) offset); |
b4eb7656 AM |
5802 | break; |
5803 | } | |
4723351a | 5804 | |
0c588247 | 5805 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
5806 | |
5807 | if (start + length > section_end) | |
b4eb7656 AM |
5808 | { |
5809 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5810 | (unsigned long) offset); |
b4eb7656 AM |
5811 | break; |
5812 | } | |
4723351a CC |
5813 | |
5814 | print_dwarf_vma (begin + base_address, pointer_size); | |
5815 | print_dwarf_vma (end + base_address, pointer_size); | |
5816 | ||
5817 | putchar ('('); | |
5818 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
5819 | pointer_size, |
5820 | offset_size, | |
5821 | dwarf_version, | |
5822 | length, | |
5823 | cu_offset, section); | |
4723351a CC |
5824 | putchar (')'); |
5825 | ||
5826 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 5827 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 5828 | |
9f272209 | 5829 | if (begin == end && vbegin == vend) |
b4eb7656 | 5830 | fputs (_(" (start == end)"), stdout); |
9f272209 | 5831 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 5832 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
5833 | |
5834 | putchar ('\n'); | |
5835 | ||
5836 | start += length; | |
5837 | } | |
5838 | ||
5839 | *start_ptr = start; | |
9f272209 | 5840 | *vstart_ptr = vstart; |
4723351a CC |
5841 | } |
5842 | ||
77145576 JK |
5843 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
5844 | ||
5845 | static void | |
5846 | display_loclists_list (struct dwarf_section *section, | |
5847 | unsigned char **start_ptr, | |
5848 | unsigned int debug_info_entry, | |
5849 | dwarf_vma offset, | |
5850 | dwarf_vma base_address, | |
9f272209 | 5851 | unsigned char **vstart_ptr, |
77145576 JK |
5852 | int has_frame_base) |
5853 | { | |
9f272209 | 5854 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
5855 | unsigned char *section_end = section->start + section->size; |
5856 | unsigned long cu_offset; | |
5857 | unsigned int pointer_size; | |
5858 | unsigned int offset_size; | |
5859 | int dwarf_version; | |
77145576 | 5860 | |
9dfd0db9 | 5861 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
5862 | dwarf_vma begin = -1, vbegin = -1; |
5863 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
5864 | dwarf_vma length; |
5865 | int need_frame_base; | |
5866 | ||
5867 | if (debug_info_entry >= num_debug_info_entries) | |
5868 | { | |
5869 | warn (_("No debug information available for " | |
5870 | "loclists lists of entry: %u\n"), | |
5871 | debug_info_entry); | |
5872 | return; | |
5873 | } | |
5874 | ||
5875 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
5876 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5877 | offset_size = debug_information [debug_info_entry].offset_size; | |
5878 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
5879 | ||
5880 | if (pointer_size < 2 || pointer_size > 8) | |
5881 | { | |
5882 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5883 | pointer_size, debug_info_entry); | |
5884 | return; | |
5885 | } | |
5886 | ||
5887 | while (1) | |
5888 | { | |
5889 | dwarf_vma off = offset + (start - *start_ptr); | |
5890 | enum dwarf_location_list_entry_type llet; | |
5891 | ||
5892 | if (start + 1 > section_end) | |
5893 | { | |
5894 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
5895 | (unsigned long) offset); | |
5896 | break; | |
5897 | } | |
5898 | ||
5899 | printf (" %8.8lx ", (unsigned long) off); | |
5900 | ||
5901 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
5902 | ||
9f272209 AO |
5903 | if (vstart && llet == DW_LLE_offset_pair) |
5904 | { | |
5905 | off = offset + (vstart - *start_ptr); | |
5906 | ||
cd30bcef | 5907 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
5908 | print_dwarf_view (vbegin, pointer_size, 1); |
5909 | ||
cd30bcef | 5910 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
5911 | print_dwarf_view (vend, pointer_size, 1); |
5912 | ||
5913 | printf (_("views at %8.8lx for:\n %*s "), | |
5914 | (unsigned long) off, 8, ""); | |
5915 | } | |
5916 | ||
77145576 JK |
5917 | switch (llet) |
5918 | { | |
5919 | case DW_LLE_end_of_list: | |
5920 | printf (_("<End of list>\n")); | |
5921 | break; | |
5922 | case DW_LLE_offset_pair: | |
cd30bcef AM |
5923 | READ_ULEB (begin, start, section_end); |
5924 | READ_ULEB (end, start, section_end); | |
77145576 JK |
5925 | break; |
5926 | case DW_LLE_base_address: | |
5927 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
5928 | section_end); | |
5929 | print_dwarf_vma (base_address, pointer_size); | |
5930 | printf (_("(base address)\n")); | |
5931 | break; | |
9f272209 AO |
5932 | #ifdef DW_LLE_view_pair |
5933 | case DW_LLE_view_pair: | |
5934 | if (vstart) | |
5935 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
cd30bcef | 5936 | READ_ULEB (vbegin, start, section_end); |
9f272209 AO |
5937 | print_dwarf_view (vbegin, pointer_size, 1); |
5938 | ||
cd30bcef | 5939 | READ_ULEB (vend, start, section_end); |
9f272209 AO |
5940 | print_dwarf_view (vend, pointer_size, 1); |
5941 | ||
5942 | printf (_("views for:\n")); | |
5943 | continue; | |
5944 | #endif | |
77145576 JK |
5945 | default: |
5946 | error (_("Invalid location list entry type %d\n"), llet); | |
5947 | return; | |
5948 | } | |
5949 | if (llet == DW_LLE_end_of_list) | |
5950 | break; | |
5951 | if (llet != DW_LLE_offset_pair) | |
5952 | continue; | |
5953 | ||
5954 | if (start + 2 > section_end) | |
5955 | { | |
5956 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
5957 | (unsigned long) offset); | |
5958 | break; | |
5959 | } | |
5960 | ||
cd30bcef | 5961 | READ_ULEB (length, start, section_end); |
77145576 JK |
5962 | |
5963 | print_dwarf_vma (begin + base_address, pointer_size); | |
5964 | print_dwarf_vma (end + base_address, pointer_size); | |
5965 | ||
5966 | putchar ('('); | |
5967 | need_frame_base = decode_location_expression (start, | |
5968 | pointer_size, | |
5969 | offset_size, | |
5970 | dwarf_version, | |
5971 | length, | |
5972 | cu_offset, section); | |
5973 | putchar (')'); | |
5974 | ||
5975 | if (need_frame_base && !has_frame_base) | |
5976 | printf (_(" [without DW_AT_frame_base]")); | |
5977 | ||
9f272209 | 5978 | if (begin == end && vbegin == vend) |
77145576 | 5979 | fputs (_(" (start == end)"), stdout); |
9f272209 | 5980 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
5981 | fputs (_(" (start > end)"), stdout); |
5982 | ||
5983 | putchar ('\n'); | |
5984 | ||
5985 | start += length; | |
9f272209 | 5986 | vbegin = vend = -1; |
77145576 JK |
5987 | } |
5988 | ||
9f272209 AO |
5989 | if (vbegin != vm1 || vend != vm1) |
5990 | printf (_("Trailing view pair not used in a range")); | |
5991 | ||
77145576 | 5992 | *start_ptr = start; |
9f272209 | 5993 | *vstart_ptr = vstart; |
77145576 JK |
5994 | } |
5995 | ||
fab128ef CC |
5996 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
5997 | right-adjusted in a field of length LEN, and followed by a space. */ | |
5998 | ||
5999 | static void | |
6000 | print_addr_index (unsigned int idx, unsigned int len) | |
6001 | { | |
6002 | static char buf[15]; | |
6003 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 6004 | printf ("%*s ", len, buf); |
fab128ef CC |
6005 | } |
6006 | ||
4723351a CC |
6007 | /* Display a location list from a .dwo section. It uses address indexes rather |
6008 | than embedded addresses. This code closely follows display_loc_list, but the | |
6009 | two are sufficiently different that combining things is very ugly. */ | |
6010 | ||
6011 | static void | |
6012 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
6013 | unsigned char **start_ptr, |
6014 | unsigned int debug_info_entry, | |
359ca075 | 6015 | dwarf_vma offset, |
9f272209 | 6016 | unsigned char **vstart_ptr, |
b4eb7656 | 6017 | int has_frame_base) |
4723351a | 6018 | { |
9f272209 | 6019 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6020 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6021 | unsigned long cu_offset; |
6022 | unsigned int pointer_size; | |
6023 | unsigned int offset_size; | |
6024 | int dwarf_version; | |
4723351a CC |
6025 | int entry_type; |
6026 | unsigned short length; | |
6027 | int need_frame_base; | |
fab128ef | 6028 | unsigned int idx; |
4723351a | 6029 | |
82b1b41b NC |
6030 | if (debug_info_entry >= num_debug_info_entries) |
6031 | { | |
6032 | warn (_("No debug information for loc 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 | ||
f41e4712 NC |
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 | ||
4723351a CC |
6049 | while (1) |
6050 | { | |
359ca075 | 6051 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 6052 | |
fab128ef | 6053 | if (start >= section_end) |
b4eb7656 AM |
6054 | { |
6055 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6056 | (unsigned long) offset); |
b4eb7656 AM |
6057 | break; |
6058 | } | |
4723351a | 6059 | |
0c588247 | 6060 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
6061 | |
6062 | if (vstart) | |
6063 | switch (entry_type) | |
6064 | { | |
6065 | default: | |
6066 | break; | |
6067 | ||
6068 | case 2: | |
6069 | case 3: | |
6070 | case 4: | |
6071 | { | |
6072 | dwarf_vma view; | |
6073 | dwarf_vma off = offset + (vstart - *start_ptr); | |
6074 | ||
cd30bcef | 6075 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6076 | print_dwarf_view (view, 8, 1); |
6077 | ||
cd30bcef | 6078 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6079 | print_dwarf_view (view, 8, 1); |
6080 | ||
6081 | printf (_("views at %8.8lx for:\n %*s "), | |
6082 | (unsigned long) off, 8, ""); | |
6083 | ||
6084 | } | |
6085 | break; | |
6086 | } | |
6087 | ||
4723351a | 6088 | switch (entry_type) |
b4eb7656 AM |
6089 | { |
6090 | case 0: /* A terminating entry. */ | |
6091 | *start_ptr = start; | |
9f272209 | 6092 | *vstart_ptr = vstart; |
b4eb7656 AM |
6093 | printf (_("<End of list>\n")); |
6094 | return; | |
6095 | case 1: /* A base-address entry. */ | |
cd30bcef | 6096 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6097 | print_addr_index (idx, 8); |
9f272209 | 6098 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
6099 | printf (_("(base address selection entry)\n")); |
6100 | continue; | |
6101 | case 2: /* A start/end entry. */ | |
cd30bcef | 6102 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6103 | print_addr_index (idx, 8); |
cd30bcef | 6104 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6105 | print_addr_index (idx, 8); |
6106 | break; | |
6107 | case 3: /* A start/length entry. */ | |
cd30bcef | 6108 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6109 | print_addr_index (idx, 8); |
6110 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6111 | printf ("%08x ", idx); | |
6112 | break; | |
6113 | case 4: /* An offset pair entry. */ | |
6114 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6115 | printf ("%08x ", idx); | |
6116 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6117 | printf ("%08x ", idx); | |
6118 | break; | |
6119 | default: | |
6120 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
6121 | *start_ptr = start; | |
9f272209 | 6122 | *vstart_ptr = vstart; |
b4eb7656 AM |
6123 | return; |
6124 | } | |
4723351a CC |
6125 | |
6126 | if (start + 2 > section_end) | |
b4eb7656 AM |
6127 | { |
6128 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6129 | (unsigned long) offset); |
b4eb7656 AM |
6130 | break; |
6131 | } | |
4723351a | 6132 | |
0c588247 | 6133 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6134 | if (start + length > section_end) |
b4eb7656 AM |
6135 | { |
6136 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6137 | (unsigned long) offset); |
b4eb7656 AM |
6138 | break; |
6139 | } | |
4723351a CC |
6140 | |
6141 | putchar ('('); | |
6142 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6143 | pointer_size, |
6144 | offset_size, | |
6145 | dwarf_version, | |
6146 | length, | |
6147 | cu_offset, section); | |
4723351a CC |
6148 | putchar (')'); |
6149 | ||
6150 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6151 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
6152 | |
6153 | putchar ('\n'); | |
6154 | ||
6155 | start += length; | |
6156 | } | |
6157 | ||
6158 | *start_ptr = start; | |
9f272209 | 6159 | *vstart_ptr = vstart; |
4723351a CC |
6160 | } |
6161 | ||
9f272209 AO |
6162 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
6163 | loc_views. */ | |
51d0d03f | 6164 | |
9f272209 | 6165 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
6166 | |
6167 | static int | |
6168 | loc_offsets_compar (const void *ap, const void *bp) | |
6169 | { | |
6170 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
6171 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
6172 | ||
9f272209 AO |
6173 | int ret = (a > b) - (b > a); |
6174 | if (ret) | |
6175 | return ret; | |
6176 | ||
6177 | a = loc_views[*(const unsigned int *) ap]; | |
6178 | b = loc_views[*(const unsigned int *) bp]; | |
6179 | ||
6180 | ret = (a > b) - (b > a); | |
6181 | ||
6182 | return ret; | |
51d0d03f JJ |
6183 | } |
6184 | ||
19e6b90e L |
6185 | static int |
6186 | display_debug_loc (struct dwarf_section *section, void *file) | |
6187 | { | |
9f272209 | 6188 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
6189 | unsigned long bytes; |
6190 | unsigned char *section_begin = start; | |
6191 | unsigned int num_loc_list = 0; | |
6192 | unsigned long last_offset = 0; | |
9f272209 | 6193 | unsigned long last_view = 0; |
19e6b90e L |
6194 | unsigned int first = 0; |
6195 | unsigned int i; | |
6196 | unsigned int j; | |
6197 | int seen_first_offset = 0; | |
51d0d03f | 6198 | int locs_sorted = 1; |
9f272209 | 6199 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6200 | unsigned int *array = NULL; |
4723351a | 6201 | const char *suffix = strrchr (section->name, '.'); |
24841daa | 6202 | bfd_boolean is_dwo = FALSE; |
77145576 JK |
6203 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6204 | dwarf_vma expected_start = 0; | |
4723351a CC |
6205 | |
6206 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
24841daa | 6207 | is_dwo = TRUE; |
19e6b90e L |
6208 | |
6209 | bytes = section->size; | |
19e6b90e L |
6210 | |
6211 | if (bytes == 0) | |
6212 | { | |
6213 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6214 | return 0; | |
6215 | } | |
6216 | ||
77145576 JK |
6217 | if (is_loclists) |
6218 | { | |
6219 | unsigned char *hdrptr = section_begin; | |
6220 | dwarf_vma ll_length; | |
6221 | unsigned short ll_version; | |
6222 | unsigned char *end = section_begin + section->size; | |
6223 | unsigned char address_size, segment_selector_size; | |
6224 | uint32_t offset_entry_count; | |
6225 | ||
6226 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6227 | if (ll_length == 0xffffffff) | |
6228 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6229 | ||
6230 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6231 | if (ll_version != 5) | |
6232 | { | |
6233 | warn (_("The %s section contains corrupt or " | |
6234 | "unsupported version number: %d.\n"), | |
6235 | section->name, ll_version); | |
6236 | return 0; | |
6237 | } | |
6238 | ||
6239 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6240 | ||
6241 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6242 | if (segment_selector_size != 0) | |
6243 | { | |
6244 | warn (_("The %s section contains " | |
6245 | "unsupported segment selector size: %d.\n"), | |
6246 | section->name, segment_selector_size); | |
6247 | return 0; | |
6248 | } | |
6249 | ||
6250 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
6251 | if (offset_entry_count != 0) | |
6252 | { | |
6253 | warn (_("The %s section contains " | |
6254 | "unsupported offset entry count: %d.\n"), | |
6255 | section->name, offset_entry_count); | |
6256 | return 0; | |
6257 | } | |
6258 | ||
6259 | expected_start = hdrptr - section_begin; | |
6260 | } | |
6261 | ||
1febe64d NC |
6262 | if (load_debug_info (file) == 0) |
6263 | { | |
6264 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6265 | section->name); | |
6266 | return 0; | |
6267 | } | |
19e6b90e L |
6268 | |
6269 | /* Check the order of location list in .debug_info section. If | |
6270 | offsets of location lists are in the ascending order, we can | |
6271 | use `debug_information' directly. */ | |
6272 | for (i = 0; i < num_debug_info_entries; i++) | |
6273 | { | |
6274 | unsigned int num; | |
6275 | ||
6276 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
6277 | if (num > num_loc_list) |
6278 | num_loc_list = num; | |
19e6b90e L |
6279 | |
6280 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 6281 | if (locs_sorted && num != 0) |
19e6b90e L |
6282 | { |
6283 | if (!seen_first_offset) | |
6284 | { | |
6285 | /* This is the first location list. */ | |
6286 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 6287 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
6288 | first = i; |
6289 | seen_first_offset = 1; | |
6290 | j = 1; | |
6291 | } | |
6292 | else | |
6293 | j = 0; | |
6294 | ||
6295 | for (; j < num; j++) | |
6296 | { | |
6297 | if (last_offset > | |
9f272209 AO |
6298 | debug_information [i].loc_offsets [j] |
6299 | || (last_offset == debug_information [i].loc_offsets [j] | |
6300 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 6301 | { |
51d0d03f | 6302 | locs_sorted = 0; |
19e6b90e L |
6303 | break; |
6304 | } | |
6305 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 6306 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
6307 | } |
6308 | } | |
6309 | } | |
6310 | ||
19e6b90e L |
6311 | if (!seen_first_offset) |
6312 | error (_("No location lists in .debug_info section!\n")); | |
6313 | ||
d4bfc77b | 6314 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
6315 | && debug_information [first].loc_offsets [0] != expected_start |
6316 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
6317 | warn (_("Location lists in %s section start at 0x%s\n"), |
6318 | section->name, | |
6319 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 6320 | |
51d0d03f JJ |
6321 | if (!locs_sorted) |
6322 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d NC |
6323 | |
6324 | introduce (section, FALSE); | |
6325 | ||
d1c4b12b NC |
6326 | if (reloc_at (section, 0)) |
6327 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 6328 | |
d1c4b12b | 6329 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
6330 | |
6331 | seen_first_offset = 0; | |
6332 | for (i = first; i < num_debug_info_entries; i++) | |
6333 | { | |
9f272209 | 6334 | dwarf_vma offset, voffset; |
359ca075 | 6335 | dwarf_vma base_address; |
d1c4b12b | 6336 | unsigned int k; |
19e6b90e L |
6337 | int has_frame_base; |
6338 | ||
51d0d03f JJ |
6339 | if (!locs_sorted) |
6340 | { | |
6341 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
6342 | array[k] = k; | |
6343 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 6344 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
6345 | qsort (array, debug_information [i].num_loc_offsets, |
6346 | sizeof (*array), loc_offsets_compar); | |
6347 | } | |
19e6b90e | 6348 | |
9f272209 | 6349 | int adjacent_view_loclists = 1; |
51d0d03f | 6350 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 6351 | { |
51d0d03f JJ |
6352 | j = locs_sorted ? k : array[k]; |
6353 | if (k | |
9f272209 | 6354 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 6355 | ? k - 1 : array [k - 1]] |
9f272209 AO |
6356 | == debug_information [i].loc_offsets [j]) |
6357 | && (debug_information [i].loc_views [locs_sorted | |
6358 | ? k - 1 : array [k - 1]] | |
6359 | == debug_information [i].loc_views [j])) | |
51d0d03f | 6360 | continue; |
19e6b90e | 6361 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 6362 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 6363 | next = section_begin + offset; |
9f272209 AO |
6364 | voffset = debug_information [i].loc_views [j]; |
6365 | if (voffset != vm1) | |
6366 | vnext = section_begin + voffset; | |
6367 | else | |
6368 | vnext = NULL; | |
19e6b90e L |
6369 | base_address = debug_information [i].base_address; |
6370 | ||
9f272209 AO |
6371 | if (vnext && vnext < next) |
6372 | { | |
6373 | vstart = vnext; | |
6374 | display_view_pair_list (section, &vstart, i, next); | |
6375 | if (start == vnext) | |
6376 | start = vstart; | |
6377 | } | |
6378 | ||
6379 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
6380 | seen_first_offset = 1; |
6381 | else | |
6382 | { | |
6383 | if (start < next) | |
6384 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6385 | (unsigned long) (start - section_begin), |
c8071705 | 6386 | (unsigned long) offset); |
19e6b90e L |
6387 | else if (start > next) |
6388 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6389 | (unsigned long) (start - section_begin), |
c8071705 | 6390 | (unsigned long) offset); |
19e6b90e L |
6391 | } |
6392 | start = next; | |
9f272209 | 6393 | vstart = vnext; |
19e6b90e L |
6394 | |
6395 | if (offset >= bytes) | |
6396 | { | |
6397 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 6398 | (unsigned long) offset); |
19e6b90e L |
6399 | continue; |
6400 | } | |
6401 | ||
9f272209 AO |
6402 | if (vnext && voffset >= bytes) |
6403 | { | |
6404 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
6405 | (unsigned long) voffset); | |
6406 | continue; | |
6407 | } | |
6408 | ||
77145576 JK |
6409 | if (!is_loclists) |
6410 | { | |
6411 | if (is_dwo) | |
6412 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 6413 | &vstart, has_frame_base); |
77145576 JK |
6414 | else |
6415 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 6416 | &vstart, has_frame_base); |
77145576 | 6417 | } |
b4eb7656 | 6418 | else |
77145576 JK |
6419 | { |
6420 | if (is_dwo) | |
6421 | warn (_("DWO is not yet supported.\n")); | |
6422 | else | |
6423 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
6424 | &vstart, has_frame_base); |
6425 | } | |
6426 | ||
6427 | /* FIXME: this arrangement is quite simplistic. Nothing | |
6428 | requires locview lists to be adjacent to corresponding | |
6429 | loclists, and a single loclist could be augmented by | |
6430 | different locview lists, and vice-versa, unlikely as it | |
6431 | is that it would make sense to do so. Hopefully we'll | |
6432 | have view pair support built into loclists before we ever | |
6433 | need to address all these possibilities. */ | |
6434 | if (adjacent_view_loclists && vnext | |
6435 | && vnext != start && vstart != next) | |
6436 | { | |
6437 | adjacent_view_loclists = 0; | |
6438 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 6439 | } |
9f272209 AO |
6440 | |
6441 | if (vnext && vnext == start) | |
6442 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
6443 | } |
6444 | } | |
031cd65f | 6445 | |
4723351a | 6446 | if (start < section->start + section->size) |
d3a49aa8 AM |
6447 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
6448 | "There are %ld unused bytes at the end of section %s\n", | |
6449 | (long) (section->start + section->size - start)), | |
4723351a | 6450 | (long) (section->start + section->size - start), section->name); |
98fb390a | 6451 | putchar ('\n'); |
51d0d03f | 6452 | free (array); |
19e6b90e L |
6453 | return 1; |
6454 | } | |
6455 | ||
6456 | static int | |
6457 | display_debug_str (struct dwarf_section *section, | |
6458 | void *file ATTRIBUTE_UNUSED) | |
6459 | { | |
6460 | unsigned char *start = section->start; | |
6461 | unsigned long bytes = section->size; | |
6462 | dwarf_vma addr = section->address; | |
6463 | ||
6464 | if (bytes == 0) | |
6465 | { | |
6466 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6467 | return 0; | |
6468 | } | |
6469 | ||
dda8d76d | 6470 | introduce (section, FALSE); |
19e6b90e L |
6471 | |
6472 | while (bytes) | |
6473 | { | |
6474 | int j; | |
6475 | int k; | |
6476 | int lbytes; | |
6477 | ||
6478 | lbytes = (bytes > 16 ? 16 : bytes); | |
6479 | ||
6480 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
6481 | ||
6482 | for (j = 0; j < 16; j++) | |
6483 | { | |
6484 | if (j < lbytes) | |
6485 | printf ("%2.2x", start[j]); | |
6486 | else | |
6487 | printf (" "); | |
6488 | ||
6489 | if ((j & 3) == 3) | |
6490 | printf (" "); | |
6491 | } | |
6492 | ||
6493 | for (j = 0; j < lbytes; j++) | |
6494 | { | |
6495 | k = start[j]; | |
6496 | if (k >= ' ' && k < 0x80) | |
6497 | printf ("%c", k); | |
6498 | else | |
6499 | printf ("."); | |
6500 | } | |
6501 | ||
6502 | putchar ('\n'); | |
6503 | ||
6504 | start += lbytes; | |
6505 | addr += lbytes; | |
6506 | bytes -= lbytes; | |
6507 | } | |
6508 | ||
6509 | putchar ('\n'); | |
6510 | ||
6511 | return 1; | |
6512 | } | |
6513 | ||
19e6b90e L |
6514 | static int |
6515 | display_debug_info (struct dwarf_section *section, void *file) | |
6516 | { | |
d85bf2ba | 6517 | return process_debug_info (section, file, section->abbrev_sec, FALSE, FALSE); |
19e6b90e L |
6518 | } |
6519 | ||
2b6f5997 CC |
6520 | static int |
6521 | display_debug_types (struct dwarf_section *section, void *file) | |
6522 | { | |
d85bf2ba | 6523 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
6f875884 TG |
6524 | } |
6525 | ||
6526 | static int | |
6527 | display_trace_info (struct dwarf_section *section, void *file) | |
6528 | { | |
d85bf2ba | 6529 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
2b6f5997 | 6530 | } |
19e6b90e L |
6531 | |
6532 | static int | |
6533 | display_debug_aranges (struct dwarf_section *section, | |
6534 | void *file ATTRIBUTE_UNUSED) | |
6535 | { | |
6536 | unsigned char *start = section->start; | |
6537 | unsigned char *end = start + section->size; | |
6538 | ||
dda8d76d | 6539 | introduce (section, FALSE); |
19e6b90e | 6540 | |
6e3d6dc1 NC |
6541 | /* It does not matter if this load fails, |
6542 | we test for that later on. */ | |
6543 | load_debug_info (file); | |
6544 | ||
19e6b90e L |
6545 | while (start < end) |
6546 | { | |
6547 | unsigned char *hdrptr; | |
6548 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 6549 | unsigned char *addr_ranges; |
2d9472a2 NC |
6550 | dwarf_vma length; |
6551 | dwarf_vma address; | |
e98fdf1a | 6552 | unsigned long sec_off; |
53b8873b | 6553 | unsigned char address_size; |
19e6b90e | 6554 | int excess; |
bf5117e3 NC |
6555 | unsigned int offset_size; |
6556 | unsigned int initial_length_size; | |
19e6b90e L |
6557 | |
6558 | hdrptr = start; | |
6559 | ||
0c588247 | 6560 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
6561 | if (arange.ar_length == 0xffffffff) |
6562 | { | |
0c588247 | 6563 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
6564 | offset_size = 8; |
6565 | initial_length_size = 12; | |
6566 | } | |
6567 | else | |
6568 | { | |
6569 | offset_size = 4; | |
6570 | initial_length_size = 4; | |
6571 | } | |
6572 | ||
e98fdf1a AM |
6573 | sec_off = hdrptr - section->start; |
6574 | if (sec_off + arange.ar_length < sec_off | |
6575 | || sec_off + arange.ar_length > section->size) | |
6576 | { | |
6577 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
6578 | section->name, | |
6579 | sec_off - initial_length_size, | |
6580 | dwarf_vmatoa ("x", arange.ar_length)); | |
6581 | break; | |
6582 | } | |
6583 | ||
0c588247 NC |
6584 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
6585 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 6586 | |
6e3d6dc1 NC |
6587 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
6588 | && num_debug_info_entries > 0 | |
6589 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
6590 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 6591 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 6592 | |
0c588247 NC |
6593 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
6594 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
6595 | |
6596 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
6597 | { | |
67f101ee NC |
6598 | /* PR 19872: A version number of 0 probably means that there is |
6599 | padding at the end of the .debug_aranges section. Gold puts | |
6600 | it there when performing an incremental link, for example. | |
6601 | So do not generate a warning in this case. */ | |
6602 | if (arange.ar_version) | |
6603 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
6604 | break; |
6605 | } | |
6606 | ||
47704ddf KT |
6607 | printf (_(" Length: %ld\n"), |
6608 | (long) arange.ar_length); | |
19e6b90e | 6609 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
6610 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
6611 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
6612 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
6613 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
6614 | ||
53b8873b NC |
6615 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
6616 | ||
f41e4712 NC |
6617 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
6618 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
6619 | { |
6620 | error (_("Invalid address size in %s section!\n"), | |
6621 | section->name); | |
6622 | break; | |
6623 | } | |
6624 | ||
53b8873b NC |
6625 | /* The DWARF spec does not require that the address size be a power |
6626 | of two, but we do. This will have to change if we ever encounter | |
6627 | an uneven architecture. */ | |
6628 | if ((address_size & (address_size - 1)) != 0) | |
6629 | { | |
6630 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
6631 | break; | |
6632 | } | |
cecf136e | 6633 | |
209c9a13 NC |
6634 | if (address_size > 4) |
6635 | printf (_("\n Address Length\n")); | |
6636 | else | |
6637 | printf (_("\n Address Length\n")); | |
19e6b90e | 6638 | |
91d6fa6a | 6639 | addr_ranges = hdrptr; |
19e6b90e | 6640 | |
53b8873b NC |
6641 | /* Must pad to an alignment boundary that is twice the address size. */ |
6642 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 6643 | if (excess) |
91d6fa6a | 6644 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 6645 | |
e98fdf1a | 6646 | start += arange.ar_length + initial_length_size; |
1617e571 | 6647 | |
91d6fa6a | 6648 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 6649 | { |
0c588247 NC |
6650 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
6651 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 6652 | |
80c35038 | 6653 | printf (" "); |
2d9472a2 NC |
6654 | print_dwarf_vma (address, address_size); |
6655 | print_dwarf_vma (length, address_size); | |
6656 | putchar ('\n'); | |
19e6b90e | 6657 | } |
19e6b90e L |
6658 | } |
6659 | ||
6660 | printf ("\n"); | |
6661 | ||
6662 | return 1; | |
6663 | } | |
6664 | ||
4723351a CC |
6665 | /* Comparison function for qsort. */ |
6666 | static int | |
6667 | comp_addr_base (const void * v0, const void * v1) | |
6668 | { | |
d367307b AM |
6669 | debug_info *info0 = *(debug_info **) v0; |
6670 | debug_info *info1 = *(debug_info **) v1; | |
4723351a CC |
6671 | return info0->addr_base - info1->addr_base; |
6672 | } | |
6673 | ||
6674 | /* Display the debug_addr section. */ | |
6675 | static int | |
6676 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 6677 | void *file) |
4723351a CC |
6678 | { |
6679 | debug_info **debug_addr_info; | |
6680 | unsigned char *entry; | |
6681 | unsigned char *end; | |
6682 | unsigned int i; | |
6683 | unsigned int count; | |
6684 | ||
6685 | if (section->size == 0) | |
6686 | { | |
6687 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6688 | return 0; | |
6689 | } | |
6690 | ||
6691 | if (load_debug_info (file) == 0) | |
6692 | { | |
6693 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6694 | section->name); | |
6695 | return 0; | |
6696 | } | |
6697 | ||
dda8d76d | 6698 | introduce (section, FALSE); |
4723351a | 6699 | |
1306a742 NC |
6700 | /* PR 17531: file: cf38d01b. |
6701 | We use xcalloc because a corrupt file may not have initialised all of the | |
6702 | fields in the debug_info structure, which means that the sort below might | |
6703 | try to move uninitialised data. */ | |
6704 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 6705 | sizeof (debug_info *)); |
4723351a CC |
6706 | |
6707 | count = 0; | |
6708 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 6709 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
6710 | { |
6711 | /* PR 17531: file: cf38d01b. */ | |
6712 | if (debug_information[i].addr_base >= section->size) | |
6713 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
6714 | (unsigned long) debug_information[i].addr_base, i); | |
6715 | else | |
6716 | debug_addr_info [count++] = debug_information + i; | |
6717 | } | |
4723351a CC |
6718 | |
6719 | /* Add a sentinel to make iteration convenient. */ | |
6720 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
6721 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 6722 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 6723 | |
4723351a CC |
6724 | for (i = 0; i < count; i++) |
6725 | { | |
6726 | unsigned int idx; | |
fab128ef | 6727 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
6728 | |
6729 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 6730 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 6731 | |
fab128ef | 6732 | printf (_("\tIndex\tAddress\n")); |
4723351a CC |
6733 | entry = section->start + debug_addr_info [i]->addr_base; |
6734 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
6735 | idx = 0; | |
6736 | while (entry < end) | |
b4eb7656 AM |
6737 | { |
6738 | dwarf_vma base = byte_get (entry, address_size); | |
6739 | printf (_("\t%d:\t"), idx); | |
6740 | print_dwarf_vma (base, address_size); | |
6741 | printf ("\n"); | |
6742 | entry += address_size; | |
6743 | idx++; | |
6744 | } | |
4723351a CC |
6745 | } |
6746 | printf ("\n"); | |
6747 | ||
6748 | free (debug_addr_info); | |
6749 | return 1; | |
6750 | } | |
6751 | ||
6752 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 6753 | |
4723351a CC |
6754 | static int |
6755 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 6756 | void *file ATTRIBUTE_UNUSED) |
4723351a CC |
6757 | { |
6758 | if (section->size == 0) | |
6759 | { | |
6760 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6761 | return 0; | |
6762 | } | |
6763 | /* TODO: Dump the contents. This is made somewhat difficult by not knowing | |
6764 | what the offset size is for this section. */ | |
6765 | return 1; | |
6766 | } | |
6767 | ||
01a8f077 JK |
6768 | /* Each debug_information[x].range_lists[y] gets this representation for |
6769 | sorting purposes. */ | |
6770 | ||
6771 | struct range_entry | |
467c65bc NC |
6772 | { |
6773 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 6774 | dwarf_vma ranges_offset; |
01a8f077 | 6775 | |
467c65bc NC |
6776 | /* Original debug_information to find parameters of the data. */ |
6777 | debug_info *debug_info_p; | |
6778 | }; | |
01a8f077 JK |
6779 | |
6780 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
6781 | ||
6782 | static int | |
6783 | range_entry_compar (const void *ap, const void *bp) | |
6784 | { | |
3f5e193b NC |
6785 | const struct range_entry *a_re = (const struct range_entry *) ap; |
6786 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
6787 | const dwarf_vma a = a_re->ranges_offset; |
6788 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
6789 | |
6790 | return (a > b) - (b > a); | |
6791 | } | |
6792 | ||
77145576 JK |
6793 | static void |
6794 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
6795 | unsigned int pointer_size, unsigned long offset, | |
6796 | unsigned long base_address) | |
6797 | { | |
6798 | while (start < finish) | |
6799 | { | |
6800 | dwarf_vma begin; | |
6801 | dwarf_vma end; | |
6802 | ||
6803 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6804 | if (start >= finish) | |
6805 | break; | |
6806 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
6807 | ||
d11ae95e | 6808 | |
77145576 JK |
6809 | printf (" %8.8lx ", offset); |
6810 | ||
6811 | if (begin == 0 && end == 0) | |
6812 | { | |
6813 | printf (_("<End of list>\n")); | |
6814 | break; | |
6815 | } | |
6816 | ||
6817 | /* Check base address specifiers. */ | |
6818 | if (is_max_address (begin, pointer_size) | |
6819 | && !is_max_address (end, pointer_size)) | |
6820 | { | |
6821 | base_address = end; | |
6822 | print_dwarf_vma (begin, pointer_size); | |
6823 | print_dwarf_vma (end, pointer_size); | |
6824 | printf ("(base address)\n"); | |
6825 | continue; | |
6826 | } | |
6827 | ||
6828 | print_dwarf_vma (begin + base_address, pointer_size); | |
6829 | print_dwarf_vma (end + base_address, pointer_size); | |
6830 | ||
6831 | if (begin == end) | |
6832 | fputs (_("(start == end)"), stdout); | |
6833 | else if (begin > end) | |
6834 | fputs (_("(start > end)"), stdout); | |
6835 | ||
6836 | putchar ('\n'); | |
6837 | } | |
6838 | } | |
6839 | ||
6840 | static void | |
6841 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
6842 | unsigned int pointer_size, unsigned long offset, | |
6843 | unsigned long base_address) | |
6844 | { | |
6845 | unsigned char *next = start; | |
6846 | ||
6847 | while (1) | |
6848 | { | |
6849 | unsigned long off = offset + (start - next); | |
6850 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
6851 | /* Initialize it due to a false compiler warning. */ |
6852 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
6853 | |
6854 | if (start + 1 > finish) | |
6855 | { | |
6856 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
6857 | offset); | |
6858 | break; | |
6859 | } | |
6860 | ||
6861 | printf (" %8.8lx ", off); | |
6862 | ||
6863 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
6864 | ||
6865 | switch (rlet) | |
6866 | { | |
6867 | case DW_RLE_end_of_list: | |
6868 | printf (_("<End of list>\n")); | |
6869 | break; | |
6870 | case DW_RLE_base_address: | |
6871 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
6872 | print_dwarf_vma (base_address, pointer_size); | |
6873 | printf (_("(base address)\n")); | |
6874 | break; | |
6875 | case DW_RLE_start_length: | |
6876 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
cd30bcef | 6877 | READ_ULEB (length, start, finish); |
77145576 JK |
6878 | end = begin + length; |
6879 | break; | |
6880 | case DW_RLE_offset_pair: | |
cd30bcef AM |
6881 | READ_ULEB (begin, start, finish); |
6882 | READ_ULEB (end, start, finish); | |
77145576 JK |
6883 | break; |
6884 | case DW_RLE_start_end: | |
6885 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6886 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
6887 | break; | |
6888 | default: | |
6889 | error (_("Invalid range list entry type %d\n"), rlet); | |
6890 | rlet = DW_RLE_end_of_list; | |
6891 | break; | |
6892 | } | |
6893 | if (rlet == DW_RLE_end_of_list) | |
6894 | break; | |
6895 | if (rlet == DW_RLE_base_address) | |
6896 | continue; | |
6897 | ||
6898 | print_dwarf_vma (begin + base_address, pointer_size); | |
6899 | print_dwarf_vma (end + base_address, pointer_size); | |
6900 | ||
6901 | if (begin == end) | |
6902 | fputs (_("(start == end)"), stdout); | |
6903 | else if (begin > end) | |
6904 | fputs (_("(start > end)"), stdout); | |
6905 | ||
6906 | putchar ('\n'); | |
6907 | } | |
6908 | } | |
6909 | ||
19e6b90e L |
6910 | static int |
6911 | display_debug_ranges (struct dwarf_section *section, | |
6912 | void *file ATTRIBUTE_UNUSED) | |
6913 | { | |
6914 | unsigned char *start = section->start; | |
a2ff7a4b | 6915 | unsigned char *last_start = start; |
f6f0e17b | 6916 | unsigned long bytes = section->size; |
19e6b90e | 6917 | unsigned char *section_begin = start; |
f6f0e17b | 6918 | unsigned char *finish = start + bytes; |
01a8f077 JK |
6919 | unsigned int num_range_list, i; |
6920 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
6921 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
6922 | /* Initialize it due to a false compiler warning. */ | |
6923 | unsigned char address_size = 0; | |
19e6b90e | 6924 | |
19e6b90e L |
6925 | if (bytes == 0) |
6926 | { | |
6927 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6928 | return 0; | |
6929 | } | |
6930 | ||
77145576 JK |
6931 | if (is_rnglists) |
6932 | { | |
6933 | dwarf_vma initial_length; | |
6934 | unsigned int initial_length_size; | |
6935 | unsigned char segment_selector_size; | |
6936 | unsigned int offset_size, offset_entry_count; | |
6937 | unsigned short version; | |
6938 | ||
6939 | /* Get and check the length of the block. */ | |
6940 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
6941 | ||
6942 | if (initial_length == 0xffffffff) | |
6943 | { | |
6944 | /* This section is 64-bit DWARF 3. */ | |
6945 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
6946 | offset_size = 8; | |
6947 | initial_length_size = 12; | |
6948 | } | |
6949 | else | |
6950 | { | |
6951 | offset_size = 4; | |
6952 | initial_length_size = 4; | |
6953 | } | |
6954 | ||
6955 | if (initial_length + initial_length_size > section->size) | |
6956 | { | |
6957 | /* If the length field has a relocation against it, then we should | |
6958 | not complain if it is inaccurate (and probably negative). | |
6959 | It is copied from .debug_line handling code. */ | |
6960 | if (reloc_at (section, (start - section->start) - offset_size)) | |
6961 | { | |
6962 | initial_length = (finish - start) - initial_length_size; | |
6963 | } | |
6964 | else | |
6965 | { | |
6966 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
6967 | (long) initial_length); | |
6968 | return 0; | |
6969 | } | |
6970 | } | |
6971 | ||
6972 | /* Get and check the version number. */ | |
6973 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
6974 | ||
6975 | if (version != 5) | |
6976 | { | |
6977 | warn (_("Only DWARF version 5 debug_rnglists info " | |
6978 | "is currently supported.\n")); | |
6979 | return 0; | |
6980 | } | |
6981 | ||
6982 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
6983 | ||
6984 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
6985 | if (segment_selector_size != 0) | |
6986 | { | |
6987 | warn (_("The %s section contains " | |
6988 | "unsupported segment selector size: %d.\n"), | |
6989 | section->name, segment_selector_size); | |
6990 | return 0; | |
6991 | } | |
6992 | ||
6993 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
6994 | if (offset_entry_count != 0) | |
6995 | { | |
6996 | warn (_("The %s section contains " | |
6997 | "unsupported offset entry count: %u.\n"), | |
6998 | section->name, offset_entry_count); | |
6999 | return 0; | |
7000 | } | |
7001 | } | |
7002 | ||
1febe64d NC |
7003 | if (load_debug_info (file) == 0) |
7004 | { | |
7005 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7006 | section->name); | |
7007 | return 0; | |
7008 | } | |
19e6b90e | 7009 | |
01a8f077 | 7010 | num_range_list = 0; |
19e6b90e | 7011 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 7012 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 7013 | |
01a8f077 | 7014 | if (num_range_list == 0) |
4723351a CC |
7015 | { |
7016 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 7017 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
7018 | printf (_("No range lists in .debug_info section.\n")); |
7019 | return 1; | |
7020 | } | |
19e6b90e | 7021 | |
3f5e193b NC |
7022 | range_entries = (struct range_entry *) |
7023 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 7024 | range_entry_fill = range_entries; |
19e6b90e | 7025 | |
01a8f077 JK |
7026 | for (i = 0; i < num_debug_info_entries; i++) |
7027 | { | |
7028 | debug_info *debug_info_p = &debug_information[i]; | |
7029 | unsigned int j; | |
7030 | ||
7031 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
7032 | { | |
7033 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
7034 | range_entry_fill->debug_info_p = debug_info_p; | |
7035 | range_entry_fill++; | |
19e6b90e L |
7036 | } |
7037 | } | |
7038 | ||
01a8f077 JK |
7039 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
7040 | range_entry_compar); | |
19e6b90e | 7041 | |
d493b283 | 7042 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 7043 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 7044 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 7045 | |
dda8d76d NC |
7046 | introduce (section, FALSE); |
7047 | ||
19e6b90e L |
7048 | printf (_(" Offset Begin End\n")); |
7049 | ||
01a8f077 | 7050 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 7051 | { |
01a8f077 JK |
7052 | struct range_entry *range_entry = &range_entries[i]; |
7053 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 7054 | unsigned int pointer_size; |
359ca075 | 7055 | dwarf_vma offset; |
01a8f077 | 7056 | unsigned char *next; |
359ca075 | 7057 | dwarf_vma base_address; |
19e6b90e | 7058 | |
77145576 | 7059 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 7060 | offset = range_entry->ranges_offset; |
01a8f077 JK |
7061 | next = section_begin + offset; |
7062 | base_address = debug_info_p->base_address; | |
cecf136e | 7063 | |
f41e4712 NC |
7064 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
7065 | if (pointer_size < 2 || pointer_size > 8) | |
7066 | { | |
7067 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 7068 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
7069 | continue; |
7070 | } | |
b4eb7656 | 7071 | |
d11ae95e NC |
7072 | if (next < section_begin || next >= finish) |
7073 | { | |
7074 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
7075 | (unsigned long) offset, i); | |
7076 | continue; | |
7077 | } | |
7078 | ||
4723351a | 7079 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 7080 | { |
01a8f077 JK |
7081 | if (start < next) |
7082 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
7083 | (unsigned long) (start - section_begin), | |
7084 | (unsigned long) (next - section_begin), section->name); | |
7085 | else if (start > next) | |
a2ff7a4b AM |
7086 | { |
7087 | if (next == last_start) | |
7088 | continue; | |
7089 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
7090 | (unsigned long) (start - section_begin), | |
7091 | (unsigned long) (next - section_begin), section->name); | |
7092 | } | |
01a8f077 | 7093 | } |
d11ae95e | 7094 | |
01a8f077 | 7095 | start = next; |
a2ff7a4b | 7096 | last_start = next; |
19e6b90e | 7097 | |
77145576 JK |
7098 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
7099 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
7100 | } |
7101 | putchar ('\n'); | |
01a8f077 JK |
7102 | |
7103 | free (range_entries); | |
7104 | ||
19e6b90e L |
7105 | return 1; |
7106 | } | |
7107 | ||
7108 | typedef struct Frame_Chunk | |
7109 | { | |
7110 | struct Frame_Chunk *next; | |
7111 | unsigned char *chunk_start; | |
a1165289 | 7112 | unsigned int ncols; |
19e6b90e L |
7113 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
7114 | short int *col_type; | |
7115 | int *col_offset; | |
7116 | char *augmentation; | |
7117 | unsigned int code_factor; | |
7118 | int data_factor; | |
bf5117e3 NC |
7119 | dwarf_vma pc_begin; |
7120 | dwarf_vma pc_range; | |
32ef3000 | 7121 | unsigned int cfa_reg; |
c8071705 | 7122 | dwarf_vma cfa_offset; |
a1165289 | 7123 | unsigned int ra; |
19e6b90e L |
7124 | unsigned char fde_encoding; |
7125 | unsigned char cfa_exp; | |
604282a7 JJ |
7126 | unsigned char ptr_size; |
7127 | unsigned char segment_size; | |
19e6b90e L |
7128 | } |
7129 | Frame_Chunk; | |
7130 | ||
1296bc99 AB |
7131 | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); |
7132 | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; | |
665ce1f6 L |
7133 | static const char *const *dwarf_regnames; |
7134 | static unsigned int dwarf_regnames_count; | |
7135 | ||
1296bc99 | 7136 | |
19e6b90e L |
7137 | /* A marker for a col_type that means this column was never referenced |
7138 | in the frame info. */ | |
7139 | #define DW_CFA_unreferenced (-1) | |
7140 | ||
a1165289 | 7141 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
7142 | -1 for invalid reg. */ |
7143 | ||
7144 | static int | |
7145 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 7146 | { |
a1165289 | 7147 | unsigned int prev = fc->ncols; |
19e6b90e | 7148 | |
665ce1f6 L |
7149 | if (reg < (unsigned int) fc->ncols) |
7150 | return 0; | |
7151 | ||
d9acf707 | 7152 | if (dwarf_regnames_count > 0 |
665ce1f6 L |
7153 | && reg > dwarf_regnames_count) |
7154 | return -1; | |
19e6b90e L |
7155 | |
7156 | fc->ncols = reg + 1; | |
a1165289 NC |
7157 | /* PR 17512: file: 10450-2643-0.004. |
7158 | If reg == -1 then this can happen... */ | |
7159 | if (fc->ncols == 0) | |
7160 | return -1; | |
7161 | ||
06614111 | 7162 | /* PR 17512: file: 2844a11d. */ |
d9acf707 | 7163 | if (fc->ncols > 1024 && dwarf_regnames_count == 0) |
06614111 NC |
7164 | { |
7165 | error (_("Unfeasibly large register number: %u\n"), reg); | |
7166 | fc->ncols = 0; | |
7167 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
7168 | we ever encounter a valid binary that exceeds it. */ | |
7169 | return -1; | |
7170 | } | |
7171 | ||
3f5e193b | 7172 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 7173 | sizeof (short int)); |
3f5e193b | 7174 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 7175 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
7176 | if (fc->col_type == NULL || fc->col_offset == NULL) |
7177 | { | |
7178 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
7179 | fc->ncols); | |
7180 | fc->ncols = 0; | |
7181 | return -1; | |
7182 | } | |
19e6b90e L |
7183 | |
7184 | while (prev < fc->ncols) | |
7185 | { | |
7186 | fc->col_type[prev] = DW_CFA_unreferenced; | |
7187 | fc->col_offset[prev] = 0; | |
7188 | prev++; | |
7189 | } | |
665ce1f6 | 7190 | return 1; |
19e6b90e L |
7191 | } |
7192 | ||
2dc4cec1 L |
7193 | static const char *const dwarf_regnames_i386[] = |
7194 | { | |
43234a1e L |
7195 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
7196 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7197 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7198 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
7199 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
7200 | NULL, NULL, /* 19 - 20 */ | |
7201 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
7202 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
7203 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
7204 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
7205 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
7206 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7207 | "tr", "ldtr", /* 48 - 49 */ | |
7208 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7209 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7210 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7211 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7212 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7213 | NULL, NULL, NULL, /* 90 - 92 */ | |
7214 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
7215 | }; |
7216 | ||
3d875af5 L |
7217 | static const char *const dwarf_regnames_iamcu[] = |
7218 | { | |
7219 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
7220 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7221 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7222 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
7223 | NULL, NULL, /* 19 - 20 */ | |
7224 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
7225 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
7226 | NULL, NULL, NULL, /* 37 - 39 */ | |
7227 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7228 | "tr", "ldtr", /* 48 - 49 */ | |
7229 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7230 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7231 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7232 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7233 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7234 | NULL, NULL, NULL, /* 90 - 92 */ | |
7235 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
7236 | }; | |
7237 | ||
99f6fdd9 | 7238 | static void |
b129eb0e RH |
7239 | init_dwarf_regnames_i386 (void) |
7240 | { | |
7241 | dwarf_regnames = dwarf_regnames_i386; | |
7242 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
1296bc99 | 7243 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
7244 | } |
7245 | ||
99f6fdd9 | 7246 | static void |
3d875af5 L |
7247 | init_dwarf_regnames_iamcu (void) |
7248 | { | |
7249 | dwarf_regnames = dwarf_regnames_iamcu; | |
7250 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
1296bc99 | 7251 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
3d875af5 L |
7252 | } |
7253 | ||
2dc4cec1 L |
7254 | static const char *const dwarf_regnames_x86_64[] = |
7255 | { | |
7256 | "rax", "rdx", "rcx", "rbx", | |
7257 | "rsi", "rdi", "rbp", "rsp", | |
7258 | "r8", "r9", "r10", "r11", | |
7259 | "r12", "r13", "r14", "r15", | |
7260 | "rip", | |
7261 | "xmm0", "xmm1", "xmm2", "xmm3", | |
7262 | "xmm4", "xmm5", "xmm6", "xmm7", | |
7263 | "xmm8", "xmm9", "xmm10", "xmm11", | |
7264 | "xmm12", "xmm13", "xmm14", "xmm15", | |
7265 | "st0", "st1", "st2", "st3", | |
7266 | "st4", "st5", "st6", "st7", | |
7267 | "mm0", "mm1", "mm2", "mm3", | |
7268 | "mm4", "mm5", "mm6", "mm7", | |
7269 | "rflags", | |
7270 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
7271 | "fs.base", "gs.base", NULL, NULL, | |
7272 | "tr", "ldtr", | |
43234a1e L |
7273 | "mxcsr", "fcw", "fsw", |
7274 | "xmm16", "xmm17", "xmm18", "xmm19", | |
7275 | "xmm20", "xmm21", "xmm22", "xmm23", | |
7276 | "xmm24", "xmm25", "xmm26", "xmm27", | |
7277 | "xmm28", "xmm29", "xmm30", "xmm31", | |
7278 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
7279 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
7280 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
7281 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
7282 | NULL, NULL, NULL, /* 115 - 117 */ | |
7283 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
7284 | }; |
7285 | ||
99f6fdd9 | 7286 | static void |
b129eb0e RH |
7287 | init_dwarf_regnames_x86_64 (void) |
7288 | { | |
7289 | dwarf_regnames = dwarf_regnames_x86_64; | |
7290 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
1296bc99 | 7291 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
7292 | } |
7293 | ||
4ee22035 RH |
7294 | static const char *const dwarf_regnames_aarch64[] = |
7295 | { | |
b4eb7656 AM |
7296 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
7297 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
7298 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
7299 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
7300 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
fab7c86e TC |
7301 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
7302 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", | |
7303 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", | |
b4eb7656 AM |
7304 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
7305 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
7306 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
7307 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
fab7c86e TC |
7308 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
7309 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", | |
7310 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", | |
7311 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", | |
4ee22035 RH |
7312 | }; |
7313 | ||
99f6fdd9 | 7314 | static void |
4ee22035 RH |
7315 | init_dwarf_regnames_aarch64 (void) |
7316 | { | |
7317 | dwarf_regnames = dwarf_regnames_aarch64; | |
7318 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
1296bc99 | 7319 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
4ee22035 RH |
7320 | } |
7321 | ||
d6bb17b0 AA |
7322 | static const char *const dwarf_regnames_s390[] = |
7323 | { | |
7324 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
7325 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7326 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7327 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
7328 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
7329 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
7330 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
7331 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
7332 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
7333 | "pswm", "pswa", | |
7334 | NULL, NULL, | |
7335 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
7336 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
7337 | }; | |
7338 | ||
99f6fdd9 | 7339 | static void |
d6bb17b0 AA |
7340 | init_dwarf_regnames_s390 (void) |
7341 | { | |
7342 | dwarf_regnames = dwarf_regnames_s390; | |
7343 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
1296bc99 | 7344 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
d6bb17b0 AA |
7345 | } |
7346 | ||
5bb0830d AB |
7347 | static const char *const dwarf_regnames_riscv[] = |
7348 | { | |
7349 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
7350 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
7351 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
7352 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
7353 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
7354 | "fs0", "fs1", /* 40 - 41 */ | |
7355 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
7356 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
7357 | "fs10", "fs11", /* 58 - 59 */ | |
7358 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
7359 | }; | |
7360 | ||
4762fe62 AB |
7361 | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles |
7362 | the large number of CSRs. */ | |
7363 | ||
7364 | static const char * | |
7365 | regname_internal_riscv (unsigned int regno) | |
7366 | { | |
7367 | const char *name = NULL; | |
7368 | ||
7369 | /* Lookup in the table first, this covers GPR and FPR. */ | |
7370 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) | |
7371 | name = dwarf_regnames_riscv [regno]; | |
7372 | else if (regno >= 4096 && regno <= 8191) | |
7373 | { | |
7374 | /* This might be a CSR, these live in a sparse number space from 4096 | |
7375 | to 8191 These numbers are defined in the RISC-V ELF ABI | |
7376 | document. */ | |
7377 | switch (regno) | |
7378 | { | |
7379 | #define DECLARE_CSR(NAME,VALUE) case VALUE + 4096: name = #NAME; break; | |
7380 | #include "opcode/riscv-opc.h" | |
7381 | #undef DECLARE_CSR | |
7382 | ||
7383 | default: | |
7384 | { | |
7385 | static char csr_name[10]; | |
7386 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); | |
7387 | name = csr_name; | |
7388 | } | |
7389 | break; | |
7390 | } | |
7391 | } | |
7392 | ||
7393 | return name; | |
7394 | } | |
7395 | ||
99f6fdd9 | 7396 | static void |
5bb0830d AB |
7397 | init_dwarf_regnames_riscv (void) |
7398 | { | |
4762fe62 AB |
7399 | dwarf_regnames = NULL; |
7400 | dwarf_regnames_count = 8192; | |
7401 | dwarf_regnames_lookup_func = regname_internal_riscv; | |
5bb0830d AB |
7402 | } |
7403 | ||
2dc4cec1 | 7404 | void |
955ff7fc | 7405 | init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) |
2dc4cec1 | 7406 | { |
1296bc99 AB |
7407 | dwarf_regnames_lookup_func = NULL; |
7408 | ||
2dc4cec1 L |
7409 | switch (e_machine) |
7410 | { | |
7411 | case EM_386: | |
b129eb0e | 7412 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
7413 | break; |
7414 | ||
3d875af5 L |
7415 | case EM_IAMCU: |
7416 | init_dwarf_regnames_iamcu (); | |
7417 | break; | |
7418 | ||
2dc4cec1 | 7419 | case EM_X86_64: |
7f502d6c | 7420 | case EM_L1OM: |
7a9068fe | 7421 | case EM_K1OM: |
b129eb0e | 7422 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
7423 | break; |
7424 | ||
4ee22035 RH |
7425 | case EM_AARCH64: |
7426 | init_dwarf_regnames_aarch64 (); | |
7427 | break; | |
7428 | ||
d6bb17b0 AA |
7429 | case EM_S390: |
7430 | init_dwarf_regnames_s390 (); | |
7431 | break; | |
7432 | ||
5bb0830d AB |
7433 | case EM_RISCV: |
7434 | init_dwarf_regnames_riscv (); | |
7435 | break; | |
7436 | ||
2dc4cec1 L |
7437 | default: |
7438 | break; | |
7439 | } | |
7440 | } | |
7441 | ||
229a22cf AB |
7442 | /* Initialize the DWARF register name lookup state based on the |
7443 | architecture and specific machine type of a BFD. */ | |
7444 | ||
7445 | void | |
7446 | init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, | |
7447 | unsigned long mach) | |
7448 | { | |
1296bc99 AB |
7449 | dwarf_regnames_lookup_func = NULL; |
7450 | ||
229a22cf AB |
7451 | switch (arch) |
7452 | { | |
7453 | case bfd_arch_i386: | |
7454 | switch (mach) | |
7455 | { | |
7456 | case bfd_mach_x86_64: | |
7457 | case bfd_mach_x86_64_intel_syntax: | |
7458 | case bfd_mach_x86_64_nacl: | |
7459 | case bfd_mach_x64_32: | |
7460 | case bfd_mach_x64_32_intel_syntax: | |
7461 | case bfd_mach_x64_32_nacl: | |
7462 | init_dwarf_regnames_x86_64 (); | |
7463 | break; | |
7464 | ||
7465 | default: | |
7466 | init_dwarf_regnames_i386 (); | |
7467 | break; | |
7468 | } | |
7469 | break; | |
7470 | ||
7471 | case bfd_arch_iamcu: | |
7472 | init_dwarf_regnames_iamcu (); | |
7473 | break; | |
7474 | ||
7475 | case bfd_arch_aarch64: | |
7476 | init_dwarf_regnames_aarch64(); | |
7477 | break; | |
7478 | ||
7479 | case bfd_arch_s390: | |
7480 | init_dwarf_regnames_s390 (); | |
7481 | break; | |
7482 | ||
7483 | case bfd_arch_riscv: | |
7484 | init_dwarf_regnames_riscv (); | |
7485 | break; | |
7486 | ||
7487 | default: | |
7488 | break; | |
7489 | } | |
7490 | } | |
7491 | ||
2dc4cec1 | 7492 | static const char * |
1296bc99 | 7493 | regname_internal_by_table_only (unsigned int regno) |
2dc4cec1 | 7494 | { |
1296bc99 | 7495 | if (dwarf_regnames != NULL |
2dc4cec1 L |
7496 | && regno < dwarf_regnames_count |
7497 | && dwarf_regnames [regno] != NULL) | |
1296bc99 AB |
7498 | return dwarf_regnames [regno]; |
7499 | ||
7500 | return NULL; | |
7501 | } | |
7502 | ||
7503 | static const char * | |
7504 | regname (unsigned int regno, int name_only_p) | |
7505 | { | |
7506 | static char reg[64]; | |
7507 | ||
7508 | const char *name = NULL; | |
7509 | ||
7510 | if (dwarf_regnames_lookup_func != NULL) | |
7511 | name = dwarf_regnames_lookup_func (regno); | |
7512 | ||
7513 | if (name != NULL) | |
2dc4cec1 | 7514 | { |
1296bc99 AB |
7515 | if (name_only_p) |
7516 | return name; | |
7517 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); | |
2dc4cec1 L |
7518 | } |
7519 | else | |
7520 | snprintf (reg, sizeof (reg), "r%d", regno); | |
7521 | return reg; | |
7522 | } | |
7523 | ||
19e6b90e | 7524 | static void |
a1165289 | 7525 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 7526 | { |
a1165289 | 7527 | unsigned int r; |
19e6b90e L |
7528 | char tmp[100]; |
7529 | ||
d8024a91 | 7530 | if (*max_regs != fc->ncols) |
19e6b90e L |
7531 | *max_regs = fc->ncols; |
7532 | ||
7533 | if (*need_col_headers) | |
7534 | { | |
91d6fa6a | 7535 | static const char *sloc = " LOC"; |
2dc4cec1 | 7536 | |
19e6b90e L |
7537 | *need_col_headers = 0; |
7538 | ||
91d6fa6a | 7539 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
7540 | |
7541 | for (r = 0; r < *max_regs; r++) | |
7542 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7543 | { | |
7544 | if (r == fc->ra) | |
50751e18 | 7545 | printf ("ra "); |
19e6b90e | 7546 | else |
2dc4cec1 | 7547 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
7548 | } |
7549 | ||
7550 | printf ("\n"); | |
7551 | } | |
7552 | ||
bf5117e3 | 7553 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
7554 | if (fc->cfa_exp) |
7555 | strcpy (tmp, "exp"); | |
7556 | else | |
c8071705 | 7557 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
7558 | printf ("%-8s ", tmp); |
7559 | ||
7560 | for (r = 0; r < fc->ncols; r++) | |
7561 | { | |
7562 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7563 | { | |
7564 | switch (fc->col_type[r]) | |
7565 | { | |
7566 | case DW_CFA_undefined: | |
7567 | strcpy (tmp, "u"); | |
7568 | break; | |
7569 | case DW_CFA_same_value: | |
7570 | strcpy (tmp, "s"); | |
7571 | break; | |
7572 | case DW_CFA_offset: | |
7573 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
7574 | break; | |
12eae2d3 JJ |
7575 | case DW_CFA_val_offset: |
7576 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
7577 | break; | |
19e6b90e | 7578 | case DW_CFA_register: |
2dc4cec1 | 7579 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
7580 | break; |
7581 | case DW_CFA_expression: | |
7582 | strcpy (tmp, "exp"); | |
7583 | break; | |
12eae2d3 JJ |
7584 | case DW_CFA_val_expression: |
7585 | strcpy (tmp, "vexp"); | |
7586 | break; | |
19e6b90e L |
7587 | default: |
7588 | strcpy (tmp, "n/a"); | |
7589 | break; | |
7590 | } | |
2dc4cec1 | 7591 | printf ("%-5s ", tmp); |
19e6b90e L |
7592 | } |
7593 | } | |
7594 | printf ("\n"); | |
7595 | } | |
7596 | ||
49727e46 | 7597 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 7598 | |
49727e46 AM |
7599 | static unsigned char * |
7600 | read_cie (unsigned char *start, unsigned char *end, | |
7601 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 7602 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
7603 | { |
7604 | int version; | |
7605 | Frame_Chunk *fc; | |
49727e46 | 7606 | unsigned char *augmentation_data = NULL; |
bf59c5d5 | 7607 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 7608 | |
041830e0 | 7609 | * p_cie = NULL; |
f41e4712 NC |
7610 | /* PR 17512: file: 001-228113-0.004. */ |
7611 | if (start >= end) | |
7612 | return end; | |
7613 | ||
49727e46 AM |
7614 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
7615 | memset (fc, 0, sizeof (Frame_Chunk)); | |
7616 | ||
7617 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
7618 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
7619 | ||
7620 | version = *start++; | |
7621 | ||
7622 | fc->augmentation = (char *) start; | |
f41e4712 NC |
7623 | /* PR 17512: file: 001-228113-0.004. |
7624 | Skip past augmentation name, but avoid running off the end of the data. */ | |
7625 | while (start < end) | |
7626 | if (* start ++ == '\0') | |
7627 | break; | |
7628 | if (start == end) | |
7629 | { | |
7630 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 7631 | goto fail; |
f41e4712 | 7632 | } |
49727e46 AM |
7633 | |
7634 | if (strcmp (fc->augmentation, "eh") == 0) | |
7635 | start += eh_addr_size; | |
7636 | ||
7637 | if (version >= 4) | |
7638 | { | |
7639 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
7640 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
7641 | { | |
7642 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 7643 | goto fail; |
77ef8654 NC |
7644 | } |
7645 | ||
49727e46 | 7646 | GET (fc->segment_size, 1); |
77ef8654 NC |
7647 | /* PR 17512: file: e99d2804. */ |
7648 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
7649 | { | |
7650 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 7651 | goto fail; |
77ef8654 NC |
7652 | } |
7653 | ||
49727e46 AM |
7654 | eh_addr_size = fc->ptr_size; |
7655 | } | |
7656 | else | |
7657 | { | |
7658 | fc->ptr_size = eh_addr_size; | |
7659 | fc->segment_size = 0; | |
7660 | } | |
442a6ce8 | 7661 | |
cd30bcef AM |
7662 | READ_ULEB (fc->code_factor, start, end); |
7663 | READ_SLEB (fc->data_factor, start, end); | |
442a6ce8 | 7664 | |
49727e46 AM |
7665 | if (version == 1) |
7666 | { | |
7667 | GET (fc->ra, 1); | |
7668 | } | |
7669 | else | |
7670 | { | |
cd30bcef | 7671 | READ_ULEB (fc->ra, start, end); |
49727e46 AM |
7672 | } |
7673 | ||
7674 | if (fc->augmentation[0] == 'z') | |
7675 | { | |
cd30bcef | 7676 | READ_ULEB (augmentation_data_len, start, end); |
49727e46 | 7677 | augmentation_data = start; |
a1165289 | 7678 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 7679 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 7680 | { |
bf59c5d5 NC |
7681 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
7682 | dwarf_vmatoa ("x", augmentation_data_len), | |
7683 | (unsigned long) (end - start)); | |
442a6ce8 | 7684 | goto fail; |
a1165289 | 7685 | } |
9c0f3d3f | 7686 | start += augmentation_data_len; |
49727e46 AM |
7687 | } |
7688 | ||
7689 | if (augmentation_data_len) | |
7690 | { | |
058037d3 NC |
7691 | unsigned char *p; |
7692 | unsigned char *q; | |
7693 | unsigned char *qend; | |
b4eb7656 | 7694 | |
49727e46 AM |
7695 | p = (unsigned char *) fc->augmentation + 1; |
7696 | q = augmentation_data; | |
058037d3 NC |
7697 | qend = q + augmentation_data_len; |
7698 | ||
9c0f3d3f | 7699 | while (p < end && q < qend) |
49727e46 AM |
7700 | { |
7701 | if (*p == 'L') | |
7702 | q++; | |
7703 | else if (*p == 'P') | |
7704 | q += 1 + size_of_encoded_value (*q); | |
7705 | else if (*p == 'R') | |
7706 | fc->fde_encoding = *q++; | |
7707 | else if (*p == 'S') | |
7708 | ; | |
09038062 ST |
7709 | else if (*p == 'B') |
7710 | ; | |
49727e46 AM |
7711 | else |
7712 | break; | |
7713 | p++; | |
7714 | } | |
c361b9ac NC |
7715 | /* Note - it is OK if this loop terminates with q < qend. |
7716 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
7717 | } |
7718 | ||
7719 | *p_cie = fc; | |
7720 | if (p_version) | |
7721 | *p_version = version; | |
7722 | if (p_aug_len) | |
7723 | { | |
7724 | *p_aug_len = augmentation_data_len; | |
7725 | *p_aug = augmentation_data; | |
7726 | } | |
7727 | return start; | |
442a6ce8 NC |
7728 | |
7729 | fail: | |
7730 | free (fc->col_offset); | |
7731 | free (fc->col_type); | |
7732 | free (fc); | |
7733 | return end; | |
49727e46 AM |
7734 | } |
7735 | ||
d85bf2ba NC |
7736 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
7737 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
7738 | PRINTED contains the number of characters already written to the current | |
7739 | output line. */ | |
bf59c5d5 NC |
7740 | |
7741 | static void | |
d85bf2ba NC |
7742 | display_data (bfd_size_type printed, |
7743 | const unsigned char * data, | |
7744 | const bfd_size_type len) | |
bf59c5d5 | 7745 | { |
d85bf2ba NC |
7746 | if (do_wide || len < ((80 - printed) / 3)) |
7747 | for (printed = 0; printed < len; ++printed) | |
7748 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
7749 | else |
7750 | { | |
d85bf2ba | 7751 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 7752 | { |
d85bf2ba | 7753 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 7754 | putchar ('\n'); |
d85bf2ba | 7755 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
7756 | } |
7757 | } | |
d85bf2ba NC |
7758 | } |
7759 | ||
7760 | /* Prints out the contents on the augmentation data array. | |
7761 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
7762 | ||
7763 | static void | |
7764 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
7765 | { | |
7766 | bfd_size_type i; | |
7767 | ||
7768 | i = printf (_(" Augmentation data: ")); | |
7769 | display_data (i, data, len); | |
bf59c5d5 NC |
7770 | } |
7771 | ||
19e6b90e L |
7772 | static int |
7773 | display_debug_frames (struct dwarf_section *section, | |
7774 | void *file ATTRIBUTE_UNUSED) | |
7775 | { | |
7776 | unsigned char *start = section->start; | |
7777 | unsigned char *end = start + section->size; | |
7778 | unsigned char *section_start = start; | |
3391569f NC |
7779 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
7780 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 7781 | Frame_Chunk *rs; |
3391569f | 7782 | bfd_boolean is_eh = strcmp (section->name, ".eh_frame") == 0; |
a1165289 | 7783 | unsigned int max_regs = 0; |
665ce1f6 | 7784 | const char *bad_reg = _("bad register: "); |
77ef8654 | 7785 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 7786 | |
dda8d76d | 7787 | introduce (section, FALSE); |
19e6b90e L |
7788 | |
7789 | while (start < end) | |
7790 | { | |
7791 | unsigned char *saved_start; | |
7792 | unsigned char *block_end; | |
bf5117e3 NC |
7793 | dwarf_vma length; |
7794 | dwarf_vma cie_id; | |
19e6b90e L |
7795 | Frame_Chunk *fc; |
7796 | Frame_Chunk *cie; | |
7797 | int need_col_headers = 1; | |
7798 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 7799 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
7800 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
7801 | unsigned int offset_size; | |
7802 | unsigned int initial_length_size; | |
5b6312fd | 7803 | bfd_boolean all_nops; |
19e6b90e L |
7804 | |
7805 | saved_start = start; | |
19e6b90e | 7806 | |
0c588247 | 7807 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 7808 | |
19e6b90e L |
7809 | if (length == 0) |
7810 | { | |
7811 | printf ("\n%08lx ZERO terminator\n\n", | |
7812 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
7813 | /* Skip any zero terminators that directly follow. |
7814 | A corrupt section size could have loaded a whole | |
7815 | slew of zero filled memory bytes. eg | |
7816 | PR 17512: file: 070-19381-0.004. */ | |
7817 | while (start < end && * start == 0) | |
7818 | ++ start; | |
b758e50f | 7819 | continue; |
19e6b90e L |
7820 | } |
7821 | ||
7822 | if (length == 0xffffffff) | |
7823 | { | |
0c588247 | 7824 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
7825 | offset_size = 8; |
7826 | initial_length_size = 12; | |
7827 | } | |
7828 | else | |
7829 | { | |
7830 | offset_size = 4; | |
7831 | initial_length_size = 4; | |
7832 | } | |
7833 | ||
7834 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 7835 | if (block_end > end || block_end < start) |
53b8873b | 7836 | { |
bf5117e3 NC |
7837 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
7838 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
7839 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
7840 | block_end = end; |
7841 | } | |
0c588247 NC |
7842 | |
7843 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 7844 | |
846a11e4 NC |
7845 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
7846 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
7847 | { |
7848 | int version; | |
a1165289 | 7849 | unsigned int mreg; |
19e6b90e | 7850 | |
49727e46 AM |
7851 | start = read_cie (start, end, &cie, &version, |
7852 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
7853 | /* PR 17512: file: 027-135133-0.005. */ |
7854 | if (cie == NULL) | |
7855 | break; | |
a1165289 | 7856 | |
49727e46 | 7857 | fc = cie; |
19e6b90e L |
7858 | fc->next = chunks; |
7859 | chunks = fc; | |
7860 | fc->chunk_start = saved_start; | |
a1165289 | 7861 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
7862 | if (mreg < fc->ra) |
7863 | mreg = fc->ra; | |
06614111 NC |
7864 | if (frame_need_space (fc, mreg) < 0) |
7865 | break; | |
49727e46 AM |
7866 | if (fc->fde_encoding) |
7867 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 7868 | |
bf5117e3 NC |
7869 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
7870 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 7871 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 7872 | |
19e6b90e | 7873 | if (do_debug_frames_interp) |
bf5117e3 NC |
7874 | { |
7875 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
7876 | fc->code_factor, fc->data_factor, fc->ra); | |
7877 | } | |
19e6b90e L |
7878 | else |
7879 | { | |
bf5117e3 | 7880 | printf ("CIE\n"); |
19e6b90e L |
7881 | printf (" Version: %d\n", version); |
7882 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
7883 | if (version >= 4) |
7884 | { | |
7885 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
7886 | printf (" Segment Size: %u\n", fc->segment_size); | |
7887 | } | |
19e6b90e L |
7888 | printf (" Code alignment factor: %u\n", fc->code_factor); |
7889 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
7890 | printf (" Return address column: %d\n", fc->ra); | |
7891 | ||
7892 | if (augmentation_data_len) | |
bf59c5d5 | 7893 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 7894 | |
19e6b90e L |
7895 | putchar ('\n'); |
7896 | } | |
19e6b90e L |
7897 | } |
7898 | else | |
7899 | { | |
7900 | unsigned char *look_for; | |
7901 | static Frame_Chunk fde_fc; | |
604282a7 | 7902 | unsigned long segment_selector; |
19e6b90e | 7903 | |
49727e46 AM |
7904 | if (is_eh) |
7905 | { | |
7906 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
7907 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
7908 | } | |
7909 | else | |
7910 | look_for = section_start + cie_id; | |
19e6b90e | 7911 | |
49727e46 AM |
7912 | if (look_for <= saved_start) |
7913 | { | |
7914 | for (cie = chunks; cie ; cie = cie->next) | |
7915 | if (cie->chunk_start == look_for) | |
7916 | break; | |
7917 | } | |
7918 | else | |
7919 | { | |
7920 | for (cie = forward_refs; cie ; cie = cie->next) | |
7921 | if (cie->chunk_start == look_for) | |
7922 | break; | |
7923 | if (!cie) | |
7924 | { | |
7925 | unsigned int off_size; | |
7926 | unsigned char *cie_scan; | |
19e6b90e | 7927 | |
49727e46 AM |
7928 | cie_scan = look_for; |
7929 | off_size = 4; | |
7930 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
7931 | if (length == 0xffffffff) | |
7932 | { | |
7933 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
7934 | off_size = 8; | |
7935 | } | |
7936 | if (length != 0) | |
7937 | { | |
7938 | dwarf_vma c_id; | |
7939 | ||
7940 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
7941 | if (is_eh | |
7942 | ? c_id == 0 | |
7943 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
7944 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
7945 | { | |
7946 | int version; | |
a1165289 | 7947 | unsigned int mreg; |
49727e46 AM |
7948 | |
7949 | read_cie (cie_scan, end, &cie, &version, | |
7950 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
7951 | /* PR 17512: file: 3450-2098-0.004. */ |
7952 | if (cie == NULL) | |
7953 | { | |
7954 | warn (_("Failed to read CIE information\n")); | |
7955 | break; | |
7956 | } | |
49727e46 AM |
7957 | cie->next = forward_refs; |
7958 | forward_refs = cie; | |
7959 | cie->chunk_start = look_for; | |
a1165289 | 7960 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
7961 | if (mreg < cie->ra) |
7962 | mreg = cie->ra; | |
06614111 NC |
7963 | if (frame_need_space (cie, mreg) < 0) |
7964 | { | |
7965 | warn (_("Invalid max register\n")); | |
7966 | break; | |
7967 | } | |
49727e46 AM |
7968 | if (cie->fde_encoding) |
7969 | encoded_ptr_size | |
7970 | = size_of_encoded_value (cie->fde_encoding); | |
7971 | } | |
7972 | } | |
7973 | } | |
7974 | } | |
7975 | ||
7976 | fc = &fde_fc; | |
7977 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
7978 | |
7979 | if (!cie) | |
7980 | { | |
bf5117e3 NC |
7981 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
7982 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
7983 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 7984 | fc->ncols = 0; |
3f5e193b NC |
7985 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
7986 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
7987 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
7988 | { | |
7989 | warn (_("Invalid max register\n")); | |
7990 | break; | |
7991 | } | |
19e6b90e L |
7992 | cie = fc; |
7993 | fc->augmentation = ""; | |
7994 | fc->fde_encoding = 0; | |
604282a7 JJ |
7995 | fc->ptr_size = eh_addr_size; |
7996 | fc->segment_size = 0; | |
19e6b90e L |
7997 | } |
7998 | else | |
7999 | { | |
8000 | fc->ncols = cie->ncols; | |
3f5e193b NC |
8001 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
8002 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
8003 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
8004 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
8005 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
8006 | fc->ptr_size = cie->ptr_size; |
8007 | eh_addr_size = cie->ptr_size; | |
8008 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
8009 | fc->code_factor = cie->code_factor; |
8010 | fc->data_factor = cie->data_factor; | |
8011 | fc->cfa_reg = cie->cfa_reg; | |
8012 | fc->cfa_offset = cie->cfa_offset; | |
8013 | fc->ra = cie->ra; | |
06614111 NC |
8014 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
8015 | { | |
8016 | warn (_("Invalid max register\n")); | |
8017 | break; | |
8018 | } | |
19e6b90e L |
8019 | fc->fde_encoding = cie->fde_encoding; |
8020 | } | |
8021 | ||
8022 | if (fc->fde_encoding) | |
8023 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
8024 | ||
604282a7 JJ |
8025 | segment_selector = 0; |
8026 | if (fc->segment_size) | |
c8071705 NC |
8027 | { |
8028 | if (fc->segment_size > sizeof (segment_selector)) | |
8029 | { | |
8030 | /* PR 17512: file: 9e196b3e. */ | |
8031 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
8032 | fc->segment_size = 4; | |
8033 | } | |
8034 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
8035 | } | |
041830e0 NC |
8036 | |
8037 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 8038 | |
0c588247 NC |
8039 | /* FIXME: It appears that sometimes the final pc_range value is |
8040 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
8041 | run of the "objcopy on compressed debug sections" test for an | |
8042 | example of this. */ | |
8043 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 8044 | |
19e6b90e L |
8045 | if (cie->augmentation[0] == 'z') |
8046 | { | |
cd30bcef | 8047 | READ_ULEB (augmentation_data_len, start, end); |
19e6b90e | 8048 | augmentation_data = start; |
bf59c5d5 | 8049 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
d292364e | 8050 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
0a9d414a | 8051 | { |
d292364e AM |
8052 | warn (_("Augmentation data too long: 0x%s, " |
8053 | "expected at most %#lx\n"), | |
8054 | dwarf_vmatoa ("x", augmentation_data_len), | |
8055 | (unsigned long) (end - start)); | |
0a9d414a NC |
8056 | start = end; |
8057 | augmentation_data = NULL; | |
8058 | augmentation_data_len = 0; | |
8059 | } | |
d292364e | 8060 | start += augmentation_data_len; |
19e6b90e L |
8061 | } |
8062 | ||
bf5117e3 NC |
8063 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
8064 | (unsigned long)(saved_start - section_start), | |
8065 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 8066 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 8067 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 8068 | |
604282a7 JJ |
8069 | if (fc->segment_size) |
8070 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
8071 | |
8072 | printf ("%s..%s\n", | |
8073 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
8074 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
8075 | ||
19e6b90e L |
8076 | if (! do_debug_frames_interp && augmentation_data_len) |
8077 | { | |
bf59c5d5 | 8078 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
8079 | putchar ('\n'); |
8080 | } | |
8081 | } | |
8082 | ||
8083 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
8084 | we're about to interpret instructions for the chunk. */ | |
8085 | /* ??? At present we need to do this always, since this sizes the | |
8086 | fc->col_type and fc->col_offset arrays, which we write into always. | |
8087 | We should probably split the interpreted and non-interpreted bits | |
8088 | into two different routines, since there's so much that doesn't | |
8089 | really overlap between them. */ | |
8090 | if (1 || do_debug_frames_interp) | |
8091 | { | |
8092 | /* Start by making a pass over the chunk, allocating storage | |
8093 | and taking note of what registers are used. */ | |
8094 | unsigned char *tmp = start; | |
8095 | ||
8096 | while (start < block_end) | |
8097 | { | |
041830e0 NC |
8098 | unsigned int reg, op, opa; |
8099 | unsigned long temp; | |
5929c344 | 8100 | unsigned char * new_start; |
19e6b90e L |
8101 | |
8102 | op = *start++; | |
8103 | opa = op & 0x3f; | |
8104 | if (op & 0xc0) | |
8105 | op &= 0xc0; | |
8106 | ||
8107 | /* Warning: if you add any more cases to this switch, be | |
8108 | sure to add them to the corresponding switch below. */ | |
8109 | switch (op) | |
8110 | { | |
8111 | case DW_CFA_advance_loc: | |
8112 | break; | |
8113 | case DW_CFA_offset: | |
cd30bcef | 8114 | SKIP_ULEB (start, end); |
665ce1f6 L |
8115 | if (frame_need_space (fc, opa) >= 0) |
8116 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8117 | break; |
8118 | case DW_CFA_restore: | |
665ce1f6 L |
8119 | if (frame_need_space (fc, opa) >= 0) |
8120 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8121 | break; |
8122 | case DW_CFA_set_loc: | |
8123 | start += encoded_ptr_size; | |
8124 | break; | |
8125 | case DW_CFA_advance_loc1: | |
8126 | start += 1; | |
8127 | break; | |
8128 | case DW_CFA_advance_loc2: | |
8129 | start += 2; | |
8130 | break; | |
8131 | case DW_CFA_advance_loc4: | |
8132 | start += 4; | |
8133 | break; | |
8134 | case DW_CFA_offset_extended: | |
12eae2d3 | 8135 | case DW_CFA_val_offset: |
cd30bcef AM |
8136 | READ_ULEB (reg, start, end); |
8137 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8138 | if (frame_need_space (fc, reg) >= 0) |
8139 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8140 | break; |
8141 | case DW_CFA_restore_extended: | |
cd30bcef | 8142 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8143 | if (frame_need_space (fc, reg) >= 0) |
8144 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8145 | break; |
8146 | case DW_CFA_undefined: | |
cd30bcef | 8147 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8148 | if (frame_need_space (fc, reg) >= 0) |
8149 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8150 | break; |
8151 | case DW_CFA_same_value: | |
cd30bcef | 8152 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8153 | if (frame_need_space (fc, reg) >= 0) |
8154 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8155 | break; |
8156 | case DW_CFA_register: | |
cd30bcef AM |
8157 | READ_ULEB (reg, start, end); |
8158 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8159 | if (frame_need_space (fc, reg) >= 0) |
8160 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8161 | break; |
8162 | case DW_CFA_def_cfa: | |
cd30bcef AM |
8163 | SKIP_ULEB (start, end); |
8164 | SKIP_ULEB (start, end); | |
19e6b90e L |
8165 | break; |
8166 | case DW_CFA_def_cfa_register: | |
cd30bcef | 8167 | SKIP_ULEB (start, end); |
19e6b90e L |
8168 | break; |
8169 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 8170 | SKIP_ULEB (start, end); |
19e6b90e L |
8171 | break; |
8172 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 8173 | READ_ULEB (temp, start, end); |
5929c344 NC |
8174 | new_start = start + temp; |
8175 | if (new_start < start) | |
041830e0 NC |
8176 | { |
8177 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
8178 | start = block_end; | |
8179 | } | |
8180 | else | |
5929c344 | 8181 | start = new_start; |
19e6b90e L |
8182 | break; |
8183 | case DW_CFA_expression: | |
12eae2d3 | 8184 | case DW_CFA_val_expression: |
cd30bcef AM |
8185 | READ_ULEB (reg, start, end); |
8186 | READ_ULEB (temp, start, end); | |
5929c344 NC |
8187 | new_start = start + temp; |
8188 | if (new_start < start) | |
041830e0 | 8189 | { |
b4eb7656 | 8190 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
8191 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
8192 | start = block_end; | |
8193 | } | |
8194 | else | |
5929c344 | 8195 | start = new_start; |
665ce1f6 L |
8196 | if (frame_need_space (fc, reg) >= 0) |
8197 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8198 | break; |
8199 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 8200 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
8201 | READ_ULEB (reg, start, end); |
8202 | SKIP_SLEB (start, end); | |
665ce1f6 L |
8203 | if (frame_need_space (fc, reg) >= 0) |
8204 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8205 | break; |
8206 | case DW_CFA_def_cfa_sf: | |
cd30bcef AM |
8207 | SKIP_ULEB (start, end); |
8208 | SKIP_SLEB (start, end); | |
19e6b90e L |
8209 | break; |
8210 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 8211 | SKIP_SLEB (start, end); |
19e6b90e L |
8212 | break; |
8213 | case DW_CFA_MIPS_advance_loc8: | |
8214 | start += 8; | |
8215 | break; | |
8216 | case DW_CFA_GNU_args_size: | |
cd30bcef | 8217 | SKIP_ULEB (start, end); |
19e6b90e L |
8218 | break; |
8219 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
8220 | READ_ULEB (reg, start, end); |
8221 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8222 | if (frame_need_space (fc, reg) >= 0) |
8223 | fc->col_type[reg] = DW_CFA_undefined; | |
8224 | break; | |
19e6b90e L |
8225 | default: |
8226 | break; | |
8227 | } | |
8228 | } | |
8229 | start = tmp; | |
8230 | } | |
8231 | ||
5b6312fd NC |
8232 | all_nops = TRUE; |
8233 | ||
19e6b90e L |
8234 | /* Now we know what registers are used, make a second pass over |
8235 | the chunk, this time actually printing out the info. */ | |
8236 | ||
8237 | while (start < block_end) | |
8238 | { | |
362beea4 | 8239 | unsigned char * tmp; |
19e6b90e | 8240 | unsigned op, opa; |
7f2c8a1d NC |
8241 | unsigned long ul, roffs; |
8242 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
8243 | are various functions, notably frame_space_needed() that assume that | |
8244 | reg is an unsigned int. */ | |
8245 | unsigned int reg; | |
8246 | dwarf_signed_vma l; | |
bf5117e3 | 8247 | dwarf_vma ofs; |
19e6b90e | 8248 | dwarf_vma vma; |
665ce1f6 | 8249 | const char *reg_prefix = ""; |
19e6b90e L |
8250 | |
8251 | op = *start++; | |
8252 | opa = op & 0x3f; | |
8253 | if (op & 0xc0) | |
8254 | op &= 0xc0; | |
8255 | ||
5b6312fd NC |
8256 | /* Make a note if something other than DW_CFA_nop happens. */ |
8257 | if (op != DW_CFA_nop) | |
8258 | all_nops = FALSE; | |
8259 | ||
19e6b90e L |
8260 | /* Warning: if you add any more cases to this switch, be |
8261 | sure to add them to the corresponding switch above. */ | |
8262 | switch (op) | |
8263 | { | |
8264 | case DW_CFA_advance_loc: | |
8265 | if (do_debug_frames_interp) | |
8266 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8267 | else | |
bf5117e3 | 8268 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 8269 | opa * fc->code_factor, |
b4eb7656 | 8270 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
8271 | fc->pc_begin + opa * fc->code_factor, |
8272 | fc->ptr_size)); | |
19e6b90e L |
8273 | fc->pc_begin += opa * fc->code_factor; |
8274 | break; | |
8275 | ||
8276 | case DW_CFA_offset: | |
cd30bcef | 8277 | READ_ULEB (roffs, start, end); |
665ce1f6 L |
8278 | if (opa >= (unsigned int) fc->ncols) |
8279 | reg_prefix = bad_reg; | |
8280 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8281 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
8282 | reg_prefix, regname (opa, 0), | |
8283 | roffs * fc->data_factor); | |
8284 | if (*reg_prefix == '\0') | |
8285 | { | |
8286 | fc->col_type[opa] = DW_CFA_offset; | |
8287 | fc->col_offset[opa] = roffs * fc->data_factor; | |
8288 | } | |
19e6b90e L |
8289 | break; |
8290 | ||
8291 | case DW_CFA_restore: | |
50751e18 | 8292 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
8293 | reg_prefix = bad_reg; |
8294 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8295 | printf (" DW_CFA_restore: %s%s\n", | |
8296 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
8297 | if (*reg_prefix != '\0') |
8298 | break; | |
8299 | ||
8300 | if (opa >= (unsigned int) cie->ncols | |
8301 | || (do_debug_frames_interp | |
8302 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
8303 | { | |
8304 | fc->col_type[opa] = DW_CFA_undefined; | |
8305 | fc->col_offset[opa] = 0; | |
8306 | } | |
8307 | else | |
665ce1f6 L |
8308 | { |
8309 | fc->col_type[opa] = cie->col_type[opa]; | |
8310 | fc->col_offset[opa] = cie->col_offset[opa]; | |
8311 | } | |
19e6b90e L |
8312 | break; |
8313 | ||
8314 | case DW_CFA_set_loc: | |
6937bb54 | 8315 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
8316 | if (do_debug_frames_interp) |
8317 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8318 | else | |
bf5117e3 NC |
8319 | printf (" DW_CFA_set_loc: %s\n", |
8320 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
8321 | fc->pc_begin = vma; |
8322 | break; | |
8323 | ||
8324 | case DW_CFA_advance_loc1: | |
0c588247 | 8325 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
8326 | if (do_debug_frames_interp) |
8327 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8328 | else | |
bf5117e3 NC |
8329 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
8330 | (unsigned long) (ofs * fc->code_factor), | |
8331 | dwarf_vmatoa_1 (NULL, | |
8332 | fc->pc_begin + ofs * fc->code_factor, | |
8333 | fc->ptr_size)); | |
19e6b90e L |
8334 | fc->pc_begin += ofs * fc->code_factor; |
8335 | break; | |
8336 | ||
8337 | case DW_CFA_advance_loc2: | |
6937bb54 | 8338 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
8339 | if (do_debug_frames_interp) |
8340 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8341 | else | |
bf5117e3 NC |
8342 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
8343 | (unsigned long) (ofs * fc->code_factor), | |
8344 | dwarf_vmatoa_1 (NULL, | |
8345 | fc->pc_begin + ofs * fc->code_factor, | |
8346 | fc->ptr_size)); | |
19e6b90e L |
8347 | fc->pc_begin += ofs * fc->code_factor; |
8348 | break; | |
8349 | ||
8350 | case DW_CFA_advance_loc4: | |
6937bb54 | 8351 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
8352 | if (do_debug_frames_interp) |
8353 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8354 | else | |
bf5117e3 NC |
8355 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
8356 | (unsigned long) (ofs * fc->code_factor), | |
8357 | dwarf_vmatoa_1 (NULL, | |
8358 | fc->pc_begin + ofs * fc->code_factor, | |
8359 | fc->ptr_size)); | |
19e6b90e L |
8360 | fc->pc_begin += ofs * fc->code_factor; |
8361 | break; | |
8362 | ||
8363 | case DW_CFA_offset_extended: | |
cd30bcef AM |
8364 | READ_ULEB (reg, start, end); |
8365 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
8366 | if (reg >= (unsigned int) fc->ncols) |
8367 | reg_prefix = bad_reg; | |
8368 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8369 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
8370 | reg_prefix, regname (reg, 0), | |
8371 | roffs * fc->data_factor); | |
8372 | if (*reg_prefix == '\0') | |
8373 | { | |
8374 | fc->col_type[reg] = DW_CFA_offset; | |
8375 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8376 | } | |
19e6b90e L |
8377 | break; |
8378 | ||
12eae2d3 | 8379 | case DW_CFA_val_offset: |
cd30bcef AM |
8380 | READ_ULEB (reg, start, end); |
8381 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
8382 | if (reg >= (unsigned int) fc->ncols) |
8383 | reg_prefix = bad_reg; | |
8384 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8385 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
8386 | reg_prefix, regname (reg, 0), |
8387 | roffs * fc->data_factor); | |
8388 | if (*reg_prefix == '\0') | |
8389 | { | |
8390 | fc->col_type[reg] = DW_CFA_val_offset; | |
8391 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8392 | } | |
12eae2d3 JJ |
8393 | break; |
8394 | ||
19e6b90e | 8395 | case DW_CFA_restore_extended: |
cd30bcef | 8396 | READ_ULEB (reg, start, end); |
50751e18 | 8397 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
8398 | reg_prefix = bad_reg; |
8399 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8400 | printf (" DW_CFA_restore_extended: %s%s\n", | |
8401 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
8402 | if (*reg_prefix != '\0') |
8403 | break; | |
8404 | ||
8405 | if (reg >= (unsigned int) cie->ncols) | |
8406 | { | |
8407 | fc->col_type[reg] = DW_CFA_undefined; | |
8408 | fc->col_offset[reg] = 0; | |
8409 | } | |
8410 | else | |
665ce1f6 L |
8411 | { |
8412 | fc->col_type[reg] = cie->col_type[reg]; | |
8413 | fc->col_offset[reg] = cie->col_offset[reg]; | |
8414 | } | |
19e6b90e L |
8415 | break; |
8416 | ||
8417 | case DW_CFA_undefined: | |
cd30bcef | 8418 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8419 | if (reg >= (unsigned int) fc->ncols) |
8420 | reg_prefix = bad_reg; | |
8421 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8422 | printf (" DW_CFA_undefined: %s%s\n", | |
8423 | reg_prefix, regname (reg, 0)); | |
8424 | if (*reg_prefix == '\0') | |
8425 | { | |
8426 | fc->col_type[reg] = DW_CFA_undefined; | |
8427 | fc->col_offset[reg] = 0; | |
8428 | } | |
19e6b90e L |
8429 | break; |
8430 | ||
8431 | case DW_CFA_same_value: | |
cd30bcef | 8432 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8433 | if (reg >= (unsigned int) fc->ncols) |
8434 | reg_prefix = bad_reg; | |
8435 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8436 | printf (" DW_CFA_same_value: %s%s\n", | |
8437 | reg_prefix, regname (reg, 0)); | |
8438 | if (*reg_prefix == '\0') | |
8439 | { | |
8440 | fc->col_type[reg] = DW_CFA_same_value; | |
8441 | fc->col_offset[reg] = 0; | |
8442 | } | |
19e6b90e L |
8443 | break; |
8444 | ||
8445 | case DW_CFA_register: | |
cd30bcef AM |
8446 | READ_ULEB (reg, start, end); |
8447 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
8448 | if (reg >= (unsigned int) fc->ncols) |
8449 | reg_prefix = bad_reg; | |
8450 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 8451 | { |
665ce1f6 L |
8452 | printf (" DW_CFA_register: %s%s in ", |
8453 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
8454 | puts (regname (roffs, 0)); |
8455 | } | |
665ce1f6 L |
8456 | if (*reg_prefix == '\0') |
8457 | { | |
8458 | fc->col_type[reg] = DW_CFA_register; | |
8459 | fc->col_offset[reg] = roffs; | |
8460 | } | |
19e6b90e L |
8461 | break; |
8462 | ||
8463 | case DW_CFA_remember_state: | |
8464 | if (! do_debug_frames_interp) | |
8465 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 8466 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 8467 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
8468 | rs->cfa_reg = fc->cfa_reg; |
8469 | rs->ra = fc->ra; | |
8470 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 8471 | rs->ncols = fc->ncols; |
3f5e193b | 8472 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 8473 | sizeof (* rs->col_type)); |
d71ad7fc RC |
8474 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
8475 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
8476 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
8477 | rs->next = remembered_state; |
8478 | remembered_state = rs; | |
8479 | break; | |
8480 | ||
8481 | case DW_CFA_restore_state: | |
8482 | if (! do_debug_frames_interp) | |
8483 | printf (" DW_CFA_restore_state\n"); | |
8484 | rs = remembered_state; | |
8485 | if (rs) | |
8486 | { | |
8487 | remembered_state = rs->next; | |
d71ad7fc RC |
8488 | fc->cfa_offset = rs->cfa_offset; |
8489 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
8490 | fc->ra = rs->ra; |
8491 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
8492 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
8493 | { | |
1306a742 | 8494 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
8495 | fc->ncols = 0; |
8496 | break; | |
8497 | } | |
d71ad7fc | 8498 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 8499 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 8500 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
8501 | free (rs->col_type); |
8502 | free (rs->col_offset); | |
8503 | free (rs); | |
8504 | } | |
8505 | else if (do_debug_frames_interp) | |
8506 | printf ("Mismatched DW_CFA_restore_state\n"); | |
8507 | break; | |
8508 | ||
8509 | case DW_CFA_def_cfa: | |
cd30bcef AM |
8510 | READ_ULEB (fc->cfa_reg, start, end); |
8511 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
8512 | fc->cfa_exp = 0; |
8513 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8514 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 8515 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8516 | break; |
8517 | ||
8518 | case DW_CFA_def_cfa_register: | |
cd30bcef | 8519 | READ_ULEB (fc->cfa_reg, start, end); |
19e6b90e L |
8520 | fc->cfa_exp = 0; |
8521 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
8522 | printf (" DW_CFA_def_cfa_register: %s\n", |
8523 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
8524 | break; |
8525 | ||
8526 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 8527 | READ_ULEB (fc->cfa_offset, start, end); |
19e6b90e | 8528 | if (! do_debug_frames_interp) |
c8071705 | 8529 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8530 | break; |
8531 | ||
8532 | case DW_CFA_nop: | |
8533 | if (! do_debug_frames_interp) | |
8534 | printf (" DW_CFA_nop\n"); | |
8535 | break; | |
8536 | ||
8537 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 8538 | READ_ULEB (ul, start, end); |
7460c0ab | 8539 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 8540 | { |
a1165289 | 8541 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8542 | break; |
8543 | } | |
19e6b90e L |
8544 | if (! do_debug_frames_interp) |
8545 | { | |
8546 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
8547 | decode_location_expression (start, eh_addr_size, 0, -1, |
8548 | ul, 0, section); | |
19e6b90e L |
8549 | printf (")\n"); |
8550 | } | |
8551 | fc->cfa_exp = 1; | |
8552 | start += ul; | |
8553 | break; | |
8554 | ||
8555 | case DW_CFA_expression: | |
cd30bcef AM |
8556 | READ_ULEB (reg, start, end); |
8557 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
8558 | if (reg >= (unsigned int) fc->ncols) |
8559 | reg_prefix = bad_reg; | |
6937bb54 | 8560 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 8561 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
8562 | tmp = start + ul; |
8563 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8564 | { |
a1165289 | 8565 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8566 | break; |
8567 | } | |
665ce1f6 | 8568 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 8569 | { |
665ce1f6 L |
8570 | printf (" DW_CFA_expression: %s%s (", |
8571 | reg_prefix, regname (reg, 0)); | |
b7807392 | 8572 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 8573 | ul, 0, section); |
19e6b90e L |
8574 | printf (")\n"); |
8575 | } | |
665ce1f6 L |
8576 | if (*reg_prefix == '\0') |
8577 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 8578 | start = tmp; |
19e6b90e L |
8579 | break; |
8580 | ||
12eae2d3 | 8581 | case DW_CFA_val_expression: |
cd30bcef AM |
8582 | READ_ULEB (reg, start, end); |
8583 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
8584 | if (reg >= (unsigned int) fc->ncols) |
8585 | reg_prefix = bad_reg; | |
362beea4 NC |
8586 | tmp = start + ul; |
8587 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8588 | { |
a1165289 | 8589 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
8590 | break; |
8591 | } | |
665ce1f6 | 8592 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 8593 | { |
665ce1f6 L |
8594 | printf (" DW_CFA_val_expression: %s%s (", |
8595 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
8596 | decode_location_expression (start, eh_addr_size, 0, -1, |
8597 | ul, 0, section); | |
12eae2d3 JJ |
8598 | printf (")\n"); |
8599 | } | |
665ce1f6 L |
8600 | if (*reg_prefix == '\0') |
8601 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 8602 | start = tmp; |
12eae2d3 JJ |
8603 | break; |
8604 | ||
19e6b90e | 8605 | case DW_CFA_offset_extended_sf: |
cd30bcef AM |
8606 | READ_ULEB (reg, start, end); |
8607 | READ_SLEB (l, start, end); | |
665ce1f6 L |
8608 | if (frame_need_space (fc, reg) < 0) |
8609 | reg_prefix = bad_reg; | |
8610 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8611 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
8612 | reg_prefix, regname (reg, 0), | |
c8071705 | 8613 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8614 | if (*reg_prefix == '\0') |
8615 | { | |
8616 | fc->col_type[reg] = DW_CFA_offset; | |
8617 | fc->col_offset[reg] = l * fc->data_factor; | |
8618 | } | |
19e6b90e L |
8619 | break; |
8620 | ||
12eae2d3 | 8621 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
8622 | READ_ULEB (reg, start, end); |
8623 | READ_SLEB (l, start, end); | |
665ce1f6 L |
8624 | if (frame_need_space (fc, reg) < 0) |
8625 | reg_prefix = bad_reg; | |
8626 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8627 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 8628 | reg_prefix, regname (reg, 0), |
c8071705 | 8629 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8630 | if (*reg_prefix == '\0') |
8631 | { | |
8632 | fc->col_type[reg] = DW_CFA_val_offset; | |
8633 | fc->col_offset[reg] = l * fc->data_factor; | |
8634 | } | |
12eae2d3 JJ |
8635 | break; |
8636 | ||
19e6b90e | 8637 | case DW_CFA_def_cfa_sf: |
cd30bcef AM |
8638 | READ_ULEB (fc->cfa_reg, start, end); |
8639 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
8640 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
8641 | fc->cfa_exp = 0; | |
8642 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8643 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 8644 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8645 | break; |
8646 | ||
8647 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 8648 | READ_ULEB (fc->cfa_offset, start, end); |
c8071705 | 8649 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 8650 | if (! do_debug_frames_interp) |
c8071705 | 8651 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8652 | break; |
8653 | ||
8654 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 8655 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
8656 | if (do_debug_frames_interp) |
8657 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8658 | else | |
bf5117e3 NC |
8659 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
8660 | (unsigned long) (ofs * fc->code_factor), | |
8661 | dwarf_vmatoa_1 (NULL, | |
8662 | fc->pc_begin + ofs * fc->code_factor, | |
8663 | fc->ptr_size)); | |
19e6b90e L |
8664 | fc->pc_begin += ofs * fc->code_factor; |
8665 | break; | |
8666 | ||
8667 | case DW_CFA_GNU_window_save: | |
8668 | if (! do_debug_frames_interp) | |
8669 | printf (" DW_CFA_GNU_window_save\n"); | |
8670 | break; | |
8671 | ||
8672 | case DW_CFA_GNU_args_size: | |
cd30bcef | 8673 | READ_ULEB (ul, start, end); |
19e6b90e L |
8674 | if (! do_debug_frames_interp) |
8675 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
8676 | break; | |
8677 | ||
8678 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
8679 | READ_ULEB (reg, start, end); |
8680 | READ_SLEB (l, start, end); | |
7f2c8a1d | 8681 | l = - l; |
665ce1f6 L |
8682 | if (frame_need_space (fc, reg) < 0) |
8683 | reg_prefix = bad_reg; | |
8684 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8685 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
8686 | reg_prefix, regname (reg, 0), | |
c8071705 | 8687 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8688 | if (*reg_prefix == '\0') |
8689 | { | |
8690 | fc->col_type[reg] = DW_CFA_offset; | |
8691 | fc->col_offset[reg] = l * fc->data_factor; | |
8692 | } | |
19e6b90e L |
8693 | break; |
8694 | ||
8695 | default: | |
53b8873b NC |
8696 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
8697 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
8698 | else | |
f41e4712 | 8699 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
8700 | start = block_end; |
8701 | } | |
8702 | } | |
8703 | ||
5b6312fd NC |
8704 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
8705 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
8706 | frame_display_row (fc, &need_col_headers, &max_regs); |
8707 | ||
8708 | start = block_end; | |
604282a7 | 8709 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
8710 | } |
8711 | ||
8712 | printf ("\n"); | |
8713 | ||
3391569f NC |
8714 | while (remembered_state != NULL) |
8715 | { | |
8716 | rs = remembered_state; | |
8717 | remembered_state = rs->next; | |
8718 | free (rs->col_type); | |
8719 | free (rs->col_offset); | |
8720 | rs->next = NULL; /* Paranoia. */ | |
8721 | free (rs); | |
8722 | } | |
8723 | ||
8724 | while (chunks != NULL) | |
8725 | { | |
8726 | rs = chunks; | |
8727 | chunks = rs->next; | |
8728 | free (rs->col_type); | |
8729 | free (rs->col_offset); | |
8730 | rs->next = NULL; /* Paranoia. */ | |
8731 | free (rs); | |
8732 | } | |
8733 | ||
8734 | while (forward_refs != NULL) | |
8735 | { | |
8736 | rs = forward_refs; | |
8737 | forward_refs = rs->next; | |
8738 | free (rs->col_type); | |
8739 | free (rs->col_offset); | |
8740 | rs->next = NULL; /* Paranoia. */ | |
8741 | free (rs); | |
8742 | } | |
8743 | ||
19e6b90e L |
8744 | return 1; |
8745 | } | |
8746 | ||
8747 | #undef GET | |
19e6b90e | 8748 | |
61364358 JK |
8749 | static int |
8750 | display_debug_names (struct dwarf_section *section, void *file) | |
8751 | { | |
8752 | unsigned char *hdrptr = section->start; | |
8753 | dwarf_vma unit_length; | |
8754 | unsigned char *unit_start; | |
8755 | const unsigned char *const section_end = section->start + section->size; | |
8756 | unsigned char *unit_end; | |
8757 | ||
dda8d76d | 8758 | introduce (section, FALSE); |
61364358 | 8759 | |
dda8d76d | 8760 | load_debug_section_with_follow (str, file); |
61364358 JK |
8761 | |
8762 | for (; hdrptr < section_end; hdrptr = unit_end) | |
8763 | { | |
8764 | unsigned int offset_size; | |
8765 | uint16_t dwarf_version, padding; | |
8766 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
8767 | uint32_t bucket_count, name_count, abbrev_table_size; | |
8768 | uint32_t augmentation_string_size; | |
8769 | unsigned int i; | |
e98fdf1a | 8770 | unsigned long sec_off; |
48467cb9 TV |
8771 | bfd_boolean augmentation_printable; |
8772 | const char *augmentation_string; | |
61364358 JK |
8773 | |
8774 | unit_start = hdrptr; | |
8775 | ||
8776 | /* Get and check the length of the block. */ | |
8777 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
8778 | ||
8779 | if (unit_length == 0xffffffff) | |
8780 | { | |
8781 | /* This section is 64-bit DWARF. */ | |
8782 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
8783 | offset_size = 8; | |
8784 | } | |
8785 | else | |
8786 | offset_size = 4; | |
8787 | unit_end = hdrptr + unit_length; | |
8788 | ||
e98fdf1a AM |
8789 | sec_off = hdrptr - section->start; |
8790 | if (sec_off + unit_length < sec_off | |
8791 | || sec_off + unit_length > section->size) | |
61364358 | 8792 | { |
e98fdf1a AM |
8793 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
8794 | section->name, | |
8795 | (unsigned long) (unit_start - section->start), | |
8796 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
8797 | return 0; |
8798 | } | |
8799 | ||
8800 | /* Get and check the version number. */ | |
8801 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
8802 | printf (_("Version %ld\n"), (long) dwarf_version); | |
8803 | ||
8804 | /* Prior versions did not exist, and future versions may not be | |
8805 | backwards compatible. */ | |
8806 | if (dwarf_version != 5) | |
8807 | { | |
8808 | warn (_("Only DWARF version 5 .debug_names " | |
8809 | "is currently supported.\n")); | |
8810 | return 0; | |
8811 | } | |
8812 | ||
8813 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
8814 | if (padding != 0) | |
8815 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
8816 | padding); | |
8817 | ||
8818 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
8819 | if (comp_unit_count == 0) | |
8820 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
8821 | ||
8822 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
8823 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
8824 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
8825 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
8826 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
8827 | ||
8828 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
8829 | if (augmentation_string_size % 4 != 0) | |
8830 | { | |
8831 | warn (_("Augmentation string length %u must be rounded up " | |
8832 | "to a multiple of 4 in .debug_names.\n"), | |
8833 | augmentation_string_size); | |
8834 | augmentation_string_size += (-augmentation_string_size) & 3; | |
8835 | } | |
48467cb9 | 8836 | |
61364358 | 8837 | printf (_("Augmentation string:")); |
48467cb9 TV |
8838 | |
8839 | augmentation_printable = TRUE; | |
8840 | augmentation_string = (const char *) hdrptr; | |
8841 | ||
61364358 JK |
8842 | for (i = 0; i < augmentation_string_size; i++) |
8843 | { | |
8844 | unsigned char uc; | |
8845 | ||
8846 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
8847 | printf (" %02x", uc); | |
48467cb9 TV |
8848 | |
8849 | if (uc != 0 && !ISPRINT (uc)) | |
8850 | augmentation_printable = FALSE; | |
8851 | } | |
8852 | ||
8853 | if (augmentation_printable) | |
8854 | { | |
8855 | printf (" (\""); | |
8856 | for (i = 0; | |
8857 | i < augmentation_string_size && augmentation_string[i]; | |
8858 | ++i) | |
8859 | putchar (augmentation_string[i]); | |
8860 | printf ("\")"); | |
61364358 | 8861 | } |
61364358 JK |
8862 | putchar ('\n'); |
8863 | ||
8864 | printf (_("CU table:\n")); | |
8865 | for (i = 0; i < comp_unit_count; i++) | |
8866 | { | |
8867 | uint64_t cu_offset; | |
8868 | ||
8869 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
8870 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
8871 | } | |
8872 | putchar ('\n'); | |
8873 | ||
8874 | printf (_("TU table:\n")); | |
8875 | for (i = 0; i < local_type_unit_count; i++) | |
8876 | { | |
8877 | uint64_t tu_offset; | |
8878 | ||
8879 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
8880 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
8881 | } | |
8882 | putchar ('\n'); | |
8883 | ||
8884 | printf (_("Foreign TU table:\n")); | |
8885 | for (i = 0; i < foreign_type_unit_count; i++) | |
8886 | { | |
8887 | uint64_t signature; | |
8888 | ||
8889 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
8890 | printf (_("[%3u] "), i); | |
8891 | print_dwarf_vma (signature, 8); | |
8892 | putchar ('\n'); | |
8893 | } | |
8894 | putchar ('\n'); | |
8895 | ||
8896 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
8897 | hdrptr += bucket_count * sizeof (uint32_t); | |
8898 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
8899 | hdrptr += name_count * sizeof (uint32_t); | |
8900 | unsigned char *const name_table_string_offsets = hdrptr; | |
8901 | hdrptr += name_count * offset_size; | |
8902 | unsigned char *const name_table_entry_offsets = hdrptr; | |
8903 | hdrptr += name_count * offset_size; | |
8904 | unsigned char *const abbrev_table = hdrptr; | |
8905 | hdrptr += abbrev_table_size; | |
8906 | const unsigned char *const abbrev_table_end = hdrptr; | |
8907 | unsigned char *const entry_pool = hdrptr; | |
8908 | if (hdrptr > unit_end) | |
8909 | { | |
8910 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
8911 | "for unit 0x%lx in the debug_names\n"), | |
8912 | (long) (hdrptr - section->start), | |
8913 | (long) (unit_end - section->start), | |
8914 | (long) (unit_start - section->start)); | |
8915 | return 0; | |
8916 | } | |
8917 | ||
8918 | size_t buckets_filled = 0; | |
8919 | size_t bucketi; | |
8920 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
8921 | { | |
8922 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
8923 | ||
8924 | if (bucket != 0) | |
8925 | ++buckets_filled; | |
8926 | } | |
d3a49aa8 AM |
8927 | printf (ngettext ("Used %zu of %lu bucket.\n", |
8928 | "Used %zu of %lu buckets.\n", | |
8929 | bucket_count), | |
8930 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 8931 | |
0a79bef4 | 8932 | uint32_t hash_prev = 0; |
61364358 JK |
8933 | size_t hash_clash_count = 0; |
8934 | size_t longest_clash = 0; | |
8935 | size_t this_length = 0; | |
8936 | size_t hashi; | |
8937 | for (hashi = 0; hashi < name_count; hashi++) | |
8938 | { | |
8939 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
8940 | ||
8941 | if (hashi > 0) | |
8942 | { | |
8943 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
8944 | { | |
8945 | ++hash_clash_count; | |
8946 | ++this_length; | |
8947 | longest_clash = MAX (longest_clash, this_length); | |
8948 | } | |
8949 | else | |
8950 | this_length = 0; | |
8951 | } | |
8952 | hash_prev = hash_this; | |
8953 | } | |
8954 | printf (_("Out of %lu items there are %zu bucket clashes" | |
8955 | " (longest of %zu entries).\n"), | |
8956 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
8957 | assert (name_count == buckets_filled + hash_clash_count); | |
8958 | ||
8959 | struct abbrev_lookup_entry | |
8960 | { | |
8961 | dwarf_vma abbrev_tag; | |
8962 | unsigned char *abbrev_lookup_ptr; | |
8963 | }; | |
8964 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
8965 | size_t abbrev_lookup_used = 0; | |
8966 | size_t abbrev_lookup_allocated = 0; | |
8967 | ||
8968 | unsigned char *abbrevptr = abbrev_table; | |
8969 | for (;;) | |
8970 | { | |
cd30bcef AM |
8971 | dwarf_vma abbrev_tag; |
8972 | ||
8973 | READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end); | |
61364358 JK |
8974 | if (abbrev_tag == 0) |
8975 | break; | |
8976 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
8977 | { | |
8978 | abbrev_lookup_allocated = MAX (0x100, | |
8979 | abbrev_lookup_allocated * 2); | |
8980 | abbrev_lookup = xrealloc (abbrev_lookup, | |
8981 | (abbrev_lookup_allocated | |
8982 | * sizeof (*abbrev_lookup))); | |
8983 | } | |
8984 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
8985 | struct abbrev_lookup_entry *entry; | |
8986 | for (entry = abbrev_lookup; | |
8987 | entry < abbrev_lookup + abbrev_lookup_used; | |
8988 | entry++) | |
8989 | if (entry->abbrev_tag == abbrev_tag) | |
8990 | { | |
8991 | warn (_("Duplicate abbreviation tag %lu " | |
8992 | "in unit 0x%lx in the debug_names\n"), | |
8993 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
8994 | break; | |
8995 | } | |
8996 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
8997 | entry->abbrev_tag = abbrev_tag; | |
8998 | entry->abbrev_lookup_ptr = abbrevptr; | |
8999 | ||
9000 | /* Skip DWARF tag. */ | |
cd30bcef | 9001 | SKIP_ULEB (abbrevptr, abbrev_table_end); |
61364358 JK |
9002 | for (;;) |
9003 | { | |
cd30bcef AM |
9004 | dwarf_vma xindex, form; |
9005 | ||
9006 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9007 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9008 | if (xindex == 0 && form == 0) |
61364358 JK |
9009 | break; |
9010 | } | |
9011 | } | |
9012 | ||
9013 | printf (_("\nSymbol table:\n")); | |
9014 | uint32_t namei; | |
9015 | for (namei = 0; namei < name_count; ++namei) | |
9016 | { | |
9017 | uint64_t string_offset, entry_offset; | |
9018 | ||
9019 | SAFE_BYTE_GET (string_offset, | |
9020 | name_table_string_offsets + namei * offset_size, | |
9021 | offset_size, unit_end); | |
9022 | SAFE_BYTE_GET (entry_offset, | |
9023 | name_table_entry_offsets + namei * offset_size, | |
9024 | offset_size, unit_end); | |
9025 | ||
9026 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
9027 | fetch_indirect_string (string_offset)); | |
9028 | ||
9029 | unsigned char *entryptr = entry_pool + entry_offset; | |
9030 | ||
9031 | // We need to scan first whether there is a single or multiple | |
9032 | // entries. TAGNO is -2 for the first entry, it is -1 for the | |
9033 | // initial tag read of the second entry, then it becomes 0 for the | |
9034 | // first entry for real printing etc. | |
9035 | int tagno = -2; | |
9036 | /* Initialize it due to a false compiler warning. */ | |
9037 | dwarf_vma second_abbrev_tag = -1; | |
9038 | for (;;) | |
9039 | { | |
cd30bcef AM |
9040 | dwarf_vma abbrev_tag; |
9041 | dwarf_vma dwarf_tag; | |
9042 | const struct abbrev_lookup_entry *entry; | |
9043 | ||
9044 | READ_ULEB (abbrev_tag, entryptr, unit_end); | |
61364358 JK |
9045 | if (tagno == -1) |
9046 | { | |
9047 | second_abbrev_tag = abbrev_tag; | |
9048 | tagno = 0; | |
9049 | entryptr = entry_pool + entry_offset; | |
9050 | continue; | |
9051 | } | |
9052 | if (abbrev_tag == 0) | |
9053 | break; | |
9054 | if (tagno >= 0) | |
9055 | printf ("%s<%lu>", | |
9056 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
9057 | (unsigned long) abbrev_tag); | |
9058 | ||
61364358 JK |
9059 | for (entry = abbrev_lookup; |
9060 | entry < abbrev_lookup + abbrev_lookup_used; | |
9061 | entry++) | |
9062 | if (entry->abbrev_tag == abbrev_tag) | |
9063 | break; | |
9064 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
9065 | { | |
9066 | warn (_("Undefined abbreviation tag %lu " | |
9067 | "in unit 0x%lx in the debug_names\n"), | |
9068 | (long) abbrev_tag, | |
9069 | (long) (unit_start - section->start)); | |
9070 | break; | |
9071 | } | |
9072 | abbrevptr = entry->abbrev_lookup_ptr; | |
cd30bcef | 9073 | READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end); |
61364358 JK |
9074 | if (tagno >= 0) |
9075 | printf (" %s", get_TAG_name (dwarf_tag)); | |
9076 | for (;;) | |
9077 | { | |
cd30bcef AM |
9078 | dwarf_vma xindex, form; |
9079 | ||
9080 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9081 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9082 | if (xindex == 0 && form == 0) |
61364358 JK |
9083 | break; |
9084 | ||
9085 | if (tagno >= 0) | |
1d827a72 | 9086 | printf (" %s", get_IDX_name (xindex)); |
ec1b0fbb NC |
9087 | entryptr = read_and_display_attr_value (0, form, 0, |
9088 | unit_start, entryptr, unit_end, | |
9089 | 0, 0, offset_size, | |
61364358 JK |
9090 | dwarf_version, NULL, |
9091 | (tagno < 0), NULL, | |
ec1b0fbb | 9092 | NULL, '=', -1); |
61364358 JK |
9093 | } |
9094 | ++tagno; | |
9095 | } | |
9096 | if (tagno <= 0) | |
9097 | printf (_(" <no entries>")); | |
9098 | putchar ('\n'); | |
9099 | } | |
9100 | ||
9101 | free (abbrev_lookup); | |
9102 | } | |
9103 | ||
9104 | return 1; | |
9105 | } | |
9106 | ||
dda8d76d | 9107 | static int |
d85bf2ba NC |
9108 | display_debug_links (struct dwarf_section * section, |
9109 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
9110 | { |
9111 | const unsigned char * filename; | |
9112 | unsigned int filelen; | |
9113 | ||
9114 | introduce (section, FALSE); | |
9115 | ||
9116 | /* The .gnu_debuglink section is formatted as: | |
9117 | (c-string) Filename. | |
9118 | (padding) If needed to reach a 4 byte boundary. | |
9119 | (uint32_t) CRC32 value. | |
9120 | ||
9121 | The .gun_debugaltlink section is formatted as: | |
9122 | (c-string) Filename. | |
9123 | (binary) Build-ID. */ | |
9124 | ||
9125 | filename = section->start; | |
9126 | filelen = strnlen ((const char *) filename, section->size); | |
9127 | if (filelen == section->size) | |
9128 | { | |
9129 | warn (_("The debuglink filename is corrupt/missing\n")); | |
9130 | return 0; | |
9131 | } | |
9132 | ||
9133 | printf (_(" Separate debug info file: %s\n"), filename); | |
9134 | ||
9135 | if (const_strneq (section->name, ".gnu_debuglink")) | |
9136 | { | |
9137 | unsigned int crc32; | |
9138 | unsigned int crc_offset; | |
9139 | ||
9140 | crc_offset = filelen + 1; | |
9141 | crc_offset = (crc_offset + 3) & ~3; | |
9142 | if (crc_offset + 4 > section->size) | |
9143 | { | |
9144 | warn (_("CRC offset missing/truncated\n")); | |
9145 | return 0; | |
9146 | } | |
9147 | ||
9148 | crc32 = byte_get (filename + crc_offset, 4); | |
9149 | ||
9150 | printf (_(" CRC value: %#x\n"), crc32); | |
9151 | ||
9152 | if (crc_offset + 4 < section->size) | |
9153 | { | |
9154 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
9155 | (long)(section->size - (crc_offset + 4))); | |
9156 | return 0; | |
9157 | } | |
9158 | } | |
9159 | else /* const_strneq (section->name, ".gnu_debugaltlink") */ | |
9160 | { | |
9161 | const unsigned char * build_id = section->start + filelen + 1; | |
9162 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
9163 | bfd_size_type printed; | |
9164 | ||
9165 | /* FIXME: Should we support smaller build-id notes ? */ | |
9166 | if (build_id_len < 0x14) | |
9167 | { | |
9168 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
9169 | return 0; | |
9170 | } | |
9171 | ||
9172 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 9173 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
9174 | putchar ('\n'); |
9175 | } | |
9176 | ||
9177 | putchar ('\n'); | |
9178 | return 1; | |
9179 | } | |
9180 | ||
5bbdf3d5 DE |
9181 | static int |
9182 | display_gdb_index (struct dwarf_section *section, | |
9183 | void *file ATTRIBUTE_UNUSED) | |
9184 | { | |
9185 | unsigned char *start = section->start; | |
9186 | uint32_t version; | |
9187 | uint32_t cu_list_offset, tu_list_offset; | |
9188 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
9189 | unsigned int cu_list_elements, tu_list_elements; | |
9190 | unsigned int address_table_size, symbol_table_slots; | |
9191 | unsigned char *cu_list, *tu_list; | |
9192 | unsigned char *address_table, *symbol_table, *constant_pool; | |
9193 | unsigned int i; | |
9194 | ||
9195 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
9196 | ||
dda8d76d | 9197 | introduce (section, FALSE); |
5bbdf3d5 DE |
9198 | |
9199 | if (section->size < 6 * sizeof (uint32_t)) | |
9200 | { | |
9201 | warn (_("Truncated header in the %s section.\n"), section->name); | |
9202 | return 0; | |
9203 | } | |
9204 | ||
9205 | version = byte_get_little_endian (start, 4); | |
da88a764 | 9206 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
9207 | |
9208 | /* Prior versions are obsolete, and future versions may not be | |
9209 | backwards compatible. */ | |
aa170720 | 9210 | if (version < 3 || version > 8) |
5bbdf3d5 | 9211 | { |
da88a764 | 9212 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
9213 | return 0; |
9214 | } | |
8d6eee87 TT |
9215 | if (version < 4) |
9216 | warn (_("The address table data in version 3 may be wrong.\n")); | |
9217 | if (version < 5) | |
9218 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
9219 | if (version < 6) | |
9220 | warn (_("Version 5 does not include inlined functions.\n")); | |
9221 | if (version < 7) | |
9222 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
9223 | /* Version 7 indices generated by Gold have bad type unit references, |
9224 | PR binutils/15021. But we don't know if the index was generated by | |
9225 | Gold or not, so to avoid worrying users with gdb-generated indices | |
9226 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
9227 | |
9228 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
9229 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
9230 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
9231 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
9232 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
9233 | ||
9234 | if (cu_list_offset > section->size | |
9235 | || tu_list_offset > section->size | |
9236 | || address_table_offset > section->size | |
9237 | || symbol_table_offset > section->size | |
9238 | || constant_pool_offset > section->size) | |
9239 | { | |
9240 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
9241 | return 0; | |
9242 | } | |
9243 | ||
53774b7e NC |
9244 | /* PR 17531: file: 418d0a8a. */ |
9245 | if (tu_list_offset < cu_list_offset) | |
9246 | { | |
9247 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
9248 | tu_list_offset, cu_list_offset); | |
9249 | return 0; | |
9250 | } | |
9251 | ||
5bbdf3d5 | 9252 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
9253 | |
9254 | if (address_table_offset < tu_list_offset) | |
9255 | { | |
9256 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
9257 | address_table_offset, tu_list_offset); | |
9258 | return 0; | |
9259 | } | |
9260 | ||
5bbdf3d5 | 9261 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
9262 | |
9263 | /* PR 17531: file: 18a47d3d. */ | |
9264 | if (symbol_table_offset < address_table_offset) | |
9265 | { | |
13bace4a | 9266 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
9267 | symbol_table_offset, address_table_offset); |
9268 | return 0; | |
9269 | } | |
9270 | ||
5bbdf3d5 | 9271 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
9272 | |
9273 | if (constant_pool_offset < symbol_table_offset) | |
9274 | { | |
9275 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
9276 | constant_pool_offset, symbol_table_offset); | |
9277 | return 0; | |
9278 | } | |
9279 | ||
5bbdf3d5 DE |
9280 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
9281 | ||
9282 | cu_list = start + cu_list_offset; | |
9283 | tu_list = start + tu_list_offset; | |
9284 | address_table = start + address_table_offset; | |
9285 | symbol_table = start + symbol_table_offset; | |
9286 | constant_pool = start + constant_pool_offset; | |
9287 | ||
28d909e5 | 9288 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 9289 | { |
1306a742 | 9290 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
9291 | return 0; |
9292 | } | |
b4eb7656 | 9293 | |
5bbdf3d5 DE |
9294 | printf (_("\nCU table:\n")); |
9295 | for (i = 0; i < cu_list_elements; i += 2) | |
9296 | { | |
9297 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
9298 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
9299 | ||
9300 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
9301 | (unsigned long) cu_offset, | |
9302 | (unsigned long) (cu_offset + cu_length - 1)); | |
9303 | } | |
9304 | ||
9305 | printf (_("\nTU table:\n")); | |
9306 | for (i = 0; i < tu_list_elements; i += 3) | |
9307 | { | |
9308 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
9309 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
9310 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
9311 | ||
9312 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
9313 | (unsigned long) tu_offset, | |
9314 | (unsigned long) type_offset); | |
9315 | print_dwarf_vma (signature, 8); | |
9316 | printf ("\n"); | |
9317 | } | |
9318 | ||
9319 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
9320 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
9321 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
9322 | { |
9323 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
9324 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
9325 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
9326 | ||
9327 | print_dwarf_vma (low, 8); | |
9328 | print_dwarf_vma (high, 8); | |
da88a764 | 9329 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
9330 | } |
9331 | ||
9332 | printf (_("\nSymbol table:\n")); | |
9333 | for (i = 0; i < symbol_table_slots; ++i) | |
9334 | { | |
9335 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
9336 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
9337 | uint32_t num_cus, cu; | |
9338 | ||
9339 | if (name_offset != 0 | |
9340 | || cu_vector_offset != 0) | |
9341 | { | |
9342 | unsigned int j; | |
362beea4 | 9343 | unsigned char * adr; |
5bbdf3d5 | 9344 | |
362beea4 | 9345 | adr = constant_pool + name_offset; |
53774b7e | 9346 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 9347 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
9348 | { |
9349 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
9350 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
9351 | name_offset, i); | |
9352 | } | |
9353 | else | |
acff9664 NC |
9354 | printf ("[%3u] %.*s:", i, |
9355 | (int) (section->size - (constant_pool_offset + name_offset)), | |
9356 | constant_pool + name_offset); | |
53774b7e | 9357 | |
362beea4 NC |
9358 | adr = constant_pool + cu_vector_offset; |
9359 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
9360 | { |
9361 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
9362 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
9363 | cu_vector_offset, i); | |
9364 | continue; | |
9365 | } | |
57028622 | 9366 | |
362beea4 | 9367 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 9368 | |
362beea4 | 9369 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 9370 | if (num_cus * 4 < num_cus |
362beea4 NC |
9371 | || adr >= section->start + section->size |
9372 | || adr < constant_pool) | |
53774b7e NC |
9373 | { |
9374 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 9375 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
9376 | num_cus, i); |
9377 | continue; | |
9378 | } | |
9379 | ||
8d6eee87 TT |
9380 | if (num_cus > 1) |
9381 | printf ("\n"); | |
f3853b34 | 9382 | |
5bbdf3d5 DE |
9383 | for (j = 0; j < num_cus; ++j) |
9384 | { | |
7c1cef97 | 9385 | int is_static; |
8d6eee87 TT |
9386 | gdb_index_symbol_kind kind; |
9387 | ||
5bbdf3d5 | 9388 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 9389 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
9390 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
9391 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 9392 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 9393 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
9394 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
9395 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 9396 | else |
8d6eee87 TT |
9397 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
9398 | ||
459d52c8 DE |
9399 | printf (" [%s, %s]", |
9400 | is_static ? _("static") : _("global"), | |
9401 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
9402 | if (num_cus > 1) |
9403 | printf ("\n"); | |
5bbdf3d5 | 9404 | } |
8d6eee87 TT |
9405 | if (num_cus <= 1) |
9406 | printf ("\n"); | |
5bbdf3d5 DE |
9407 | } |
9408 | } | |
9409 | ||
9410 | return 1; | |
9411 | } | |
9412 | ||
657d0d47 CC |
9413 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
9414 | ||
9415 | static void | |
9416 | prealloc_cu_tu_list (unsigned int nshndx) | |
9417 | { | |
9418 | if (shndx_pool == NULL) | |
9419 | { | |
9420 | shndx_pool_size = nshndx; | |
9421 | shndx_pool_used = 0; | |
9422 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
9423 | sizeof (unsigned int)); | |
9424 | } | |
9425 | else | |
9426 | { | |
9427 | shndx_pool_size = shndx_pool_used + nshndx; | |
9428 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
9429 | sizeof (unsigned int)); | |
9430 | } | |
9431 | } | |
9432 | ||
9433 | static void | |
9434 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
9435 | { | |
9436 | if (shndx_pool_used >= shndx_pool_size) | |
9437 | { | |
9438 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9439 | return; | |
9440 | } | |
9441 | shndx_pool [shndx_pool_used++] = shndx; | |
9442 | } | |
9443 | ||
9444 | static void | |
9445 | end_cu_tu_entry (void) | |
9446 | { | |
9447 | if (shndx_pool_used >= shndx_pool_size) | |
9448 | { | |
9449 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9450 | return; | |
9451 | } | |
9452 | shndx_pool [shndx_pool_used++] = 0; | |
9453 | } | |
9454 | ||
341f9135 CC |
9455 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
9456 | ||
9457 | static const char * | |
9458 | get_DW_SECT_short_name (unsigned int dw_sect) | |
9459 | { | |
9460 | static char buf[16]; | |
9461 | ||
9462 | switch (dw_sect) | |
9463 | { | |
9464 | case DW_SECT_INFO: | |
9465 | return "info"; | |
9466 | case DW_SECT_TYPES: | |
9467 | return "types"; | |
9468 | case DW_SECT_ABBREV: | |
9469 | return "abbrev"; | |
9470 | case DW_SECT_LINE: | |
9471 | return "line"; | |
9472 | case DW_SECT_LOC: | |
9473 | return "loc"; | |
9474 | case DW_SECT_STR_OFFSETS: | |
9475 | return "str_off"; | |
9476 | case DW_SECT_MACINFO: | |
9477 | return "macinfo"; | |
9478 | case DW_SECT_MACRO: | |
9479 | return "macro"; | |
9480 | default: | |
b4eb7656 | 9481 | break; |
341f9135 CC |
9482 | } |
9483 | ||
9484 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
9485 | return buf; | |
9486 | } | |
9487 | ||
9488 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
9489 | These sections are extensions for Fission. | |
9490 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
9491 | |
9492 | static int | |
9493 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
9494 | { | |
9495 | unsigned char *phdr = section->start; | |
9496 | unsigned char *limit = phdr + section->size; | |
9497 | unsigned char *phash; | |
9498 | unsigned char *pindex; | |
9499 | unsigned char *ppool; | |
9500 | unsigned int version; | |
341f9135 | 9501 | unsigned int ncols = 0; |
657d0d47 CC |
9502 | unsigned int nused; |
9503 | unsigned int nslots; | |
9504 | unsigned int i; | |
341f9135 CC |
9505 | unsigned int j; |
9506 | dwarf_vma signature_high; | |
9507 | dwarf_vma signature_low; | |
9508 | char buf[64]; | |
657d0d47 | 9509 | |
6937bb54 NC |
9510 | /* PR 17512: file: 002-168123-0.004. */ |
9511 | if (phdr == NULL) | |
9512 | { | |
9513 | warn (_("Section %s is empty\n"), section->name); | |
9514 | return 0; | |
9515 | } | |
9516 | /* PR 17512: file: 002-376-0.004. */ | |
9517 | if (section->size < 24) | |
9518 | { | |
72c61a0d | 9519 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
9520 | section->name); |
9521 | return 0; | |
9522 | } | |
9523 | ||
9524 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 9525 | if (version >= 2) |
6937bb54 NC |
9526 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
9527 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
9528 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
9529 | ||
657d0d47 | 9530 | phash = phdr + 16; |
8e2e3c6c AM |
9531 | pindex = phash + (size_t) nslots * 8; |
9532 | ppool = pindex + (size_t) nslots * 4; | |
57028622 | 9533 | |
657d0d47 CC |
9534 | if (do_display) |
9535 | { | |
dda8d76d NC |
9536 | introduce (section, FALSE); |
9537 | ||
8e2e3c6c | 9538 | printf (_(" Version: %u\n"), version); |
341f9135 | 9539 | if (version >= 2) |
8e2e3c6c AM |
9540 | printf (_(" Number of columns: %u\n"), ncols); |
9541 | printf (_(" Number of used entries: %u\n"), nused); | |
9542 | printf (_(" Number of slots: %u\n\n"), nslots); | |
657d0d47 CC |
9543 | } |
9544 | ||
8e2e3c6c AM |
9545 | /* PR 17531: file: 45d69832. */ |
9546 | if ((size_t) nslots * 8 / 8 != nslots | |
9547 | || phash < phdr || phash > limit | |
9548 | || pindex < phash || pindex > limit | |
9549 | || ppool < pindex || ppool > limit) | |
657d0d47 | 9550 | { |
8e2e3c6c AM |
9551 | warn (ngettext ("Section %s is too small for %u slot\n", |
9552 | "Section %s is too small for %u slots\n", | |
9553 | nslots), | |
657d0d47 CC |
9554 | section->name, nslots); |
9555 | return 0; | |
9556 | } | |
9557 | ||
341f9135 | 9558 | if (version == 1) |
657d0d47 | 9559 | { |
341f9135 CC |
9560 | if (!do_display) |
9561 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
9562 | for (i = 0; i < nslots; i++) | |
657d0d47 | 9563 | { |
341f9135 CC |
9564 | unsigned char *shndx_list; |
9565 | unsigned int shndx; | |
9566 | ||
6937bb54 | 9567 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 9568 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 9569 | { |
6937bb54 | 9570 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 9571 | shndx_list = ppool + j * 4; |
f3853b34 NC |
9572 | /* PR 17531: file: 705e010d. */ |
9573 | if (shndx_list < ppool) | |
9574 | { | |
9575 | warn (_("Section index pool located before start of section\n")); | |
9576 | return 0; | |
9577 | } | |
9578 | ||
341f9135 CC |
9579 | if (do_display) |
9580 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
9581 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9582 | buf, sizeof (buf))); | |
9583 | for (;;) | |
657d0d47 | 9584 | { |
341f9135 CC |
9585 | if (shndx_list >= limit) |
9586 | { | |
9587 | warn (_("Section %s too small for shndx pool\n"), | |
9588 | section->name); | |
9589 | return 0; | |
9590 | } | |
6937bb54 | 9591 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
9592 | if (shndx == 0) |
9593 | break; | |
9594 | if (do_display) | |
9595 | printf (" %d", shndx); | |
9596 | else | |
9597 | add_shndx_to_cu_tu_entry (shndx); | |
9598 | shndx_list += 4; | |
657d0d47 | 9599 | } |
657d0d47 | 9600 | if (do_display) |
341f9135 | 9601 | printf ("\n"); |
657d0d47 | 9602 | else |
341f9135 CC |
9603 | end_cu_tu_entry (); |
9604 | } | |
9605 | phash += 8; | |
9606 | pindex += 4; | |
9607 | } | |
9608 | } | |
9609 | else if (version == 2) | |
9610 | { | |
9611 | unsigned int val; | |
9612 | unsigned int dw_sect; | |
9613 | unsigned char *ph = phash; | |
9614 | unsigned char *pi = pindex; | |
8e2e3c6c AM |
9615 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
9616 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
9617 | unsigned char *pend = psizes + (size_t) nused * ncols * 4; | |
341f9135 CC |
9618 | bfd_boolean is_tu_index; |
9619 | struct cu_tu_set *this_set = NULL; | |
9620 | unsigned int row; | |
9621 | unsigned char *prow; | |
9622 | ||
9623 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
9624 | ||
362beea4 | 9625 | /* PR 17531: file: 0dd159bf. |
8e2e3c6c AM |
9626 | Check for integer overflow (can occur when size_t is 32-bit) |
9627 | with overlarge ncols or nused values. */ | |
4ac948a0 NC |
9628 | if (ncols > 0 |
9629 | && ((size_t) ncols * 4 / 4 != ncols | |
9630 | || (size_t) nused * ncols * 4 / ((size_t) ncols * 4) != nused | |
9631 | || poffsets < ppool || poffsets > limit | |
9632 | || psizes < poffsets || psizes > limit | |
9633 | || pend < psizes || pend > limit)) | |
341f9135 CC |
9634 | { |
9635 | warn (_("Section %s too small for offset and size tables\n"), | |
9636 | section->name); | |
9637 | return 0; | |
9638 | } | |
9639 | ||
9640 | if (do_display) | |
9641 | { | |
9642 | printf (_(" Offset table\n")); | |
9643 | printf (" slot %-16s ", | |
9644 | is_tu_index ? _("signature") : _("dwo_id")); | |
9645 | } | |
9646 | else | |
9647 | { | |
9648 | if (is_tu_index) | |
9649 | { | |
9650 | tu_count = nused; | |
72c61a0d | 9651 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 9652 | this_set = tu_sets; |
657d0d47 | 9653 | } |
657d0d47 | 9654 | else |
341f9135 CC |
9655 | { |
9656 | cu_count = nused; | |
72c61a0d | 9657 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
9658 | this_set = cu_sets; |
9659 | } | |
9660 | } | |
6937bb54 | 9661 | |
341f9135 CC |
9662 | if (do_display) |
9663 | { | |
9664 | for (j = 0; j < ncols; j++) | |
9665 | { | |
6937bb54 | 9666 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
9667 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
9668 | } | |
9669 | printf ("\n"); | |
9670 | } | |
6937bb54 | 9671 | |
341f9135 CC |
9672 | for (i = 0; i < nslots; i++) |
9673 | { | |
6937bb54 NC |
9674 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9675 | ||
9676 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9677 | if (row != 0) |
9678 | { | |
591f7597 | 9679 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 9680 | if (row > nused) |
591f7597 NC |
9681 | { |
9682 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
9683 | row, nused); | |
9684 | return 0; | |
9685 | } | |
9686 | ||
341f9135 | 9687 | if (!do_display) |
6aea08d9 NC |
9688 | { |
9689 | size_t num_copy = sizeof (uint64_t); | |
9690 | ||
9691 | /* PR 23064: Beware of buffer overflow. */ | |
9692 | if (ph + num_copy < limit) | |
9693 | memcpy (&this_set[row - 1].signature, ph, num_copy); | |
9694 | else | |
9695 | { | |
9696 | warn (_("Signature (%p) extends beyond end of space in section\n"), ph); | |
9697 | return 0; | |
9698 | } | |
9699 | } | |
6937bb54 | 9700 | |
341f9135 | 9701 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
9702 | /* PR 17531: file: b8ce60a8. */ |
9703 | if (prow < poffsets || prow > limit) | |
9704 | { | |
9705 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
9706 | row, ncols); | |
9707 | return 0; | |
9708 | } | |
3aade688 | 9709 | |
341f9135 CC |
9710 | if (do_display) |
9711 | printf (_(" [%3d] 0x%s"), | |
9712 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9713 | buf, sizeof (buf))); | |
9714 | for (j = 0; j < ncols; j++) | |
9715 | { | |
6937bb54 | 9716 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
9717 | if (do_display) |
9718 | printf (" %8d", val); | |
9719 | else | |
9720 | { | |
6937bb54 | 9721 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
9722 | |
9723 | /* PR 17531: file: 10796eb3. */ | |
9724 | if (dw_sect >= DW_SECT_MAX) | |
9725 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
9726 | else | |
9727 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
9728 | } |
9729 | } | |
6937bb54 | 9730 | |
341f9135 CC |
9731 | if (do_display) |
9732 | printf ("\n"); | |
9733 | } | |
9734 | ph += 8; | |
9735 | pi += 4; | |
9736 | } | |
9737 | ||
9738 | ph = phash; | |
9739 | pi = pindex; | |
9740 | if (do_display) | |
b4eb7656 | 9741 | { |
341f9135 CC |
9742 | printf ("\n"); |
9743 | printf (_(" Size table\n")); | |
9744 | printf (" slot %-16s ", | |
9745 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 9746 | } |
6937bb54 | 9747 | |
341f9135 CC |
9748 | for (j = 0; j < ncols; j++) |
9749 | { | |
6937bb54 | 9750 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
9751 | if (do_display) |
9752 | printf (" %8s", get_DW_SECT_short_name (val)); | |
9753 | } | |
6937bb54 | 9754 | |
341f9135 CC |
9755 | if (do_display) |
9756 | printf ("\n"); | |
6937bb54 | 9757 | |
341f9135 CC |
9758 | for (i = 0; i < nslots; i++) |
9759 | { | |
6937bb54 NC |
9760 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9761 | ||
9762 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9763 | if (row != 0) |
9764 | { | |
9765 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 9766 | |
341f9135 CC |
9767 | if (do_display) |
9768 | printf (_(" [%3d] 0x%s"), | |
9769 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9770 | buf, sizeof (buf))); | |
6937bb54 | 9771 | |
341f9135 CC |
9772 | for (j = 0; j < ncols; j++) |
9773 | { | |
6937bb54 | 9774 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
9775 | if (do_display) |
9776 | printf (" %8d", val); | |
9777 | else | |
9778 | { | |
6937bb54 | 9779 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
9780 | if (dw_sect >= DW_SECT_MAX) |
9781 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
9782 | else | |
341f9135 CC |
9783 | this_set [row - 1].section_sizes [dw_sect] = val; |
9784 | } | |
9785 | } | |
6937bb54 | 9786 | |
341f9135 CC |
9787 | if (do_display) |
9788 | printf ("\n"); | |
9789 | } | |
6937bb54 | 9790 | |
341f9135 CC |
9791 | ph += 8; |
9792 | pi += 4; | |
657d0d47 | 9793 | } |
657d0d47 | 9794 | } |
341f9135 | 9795 | else if (do_display) |
6937bb54 | 9796 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
9797 | |
9798 | if (do_display) | |
9799 | printf ("\n"); | |
9800 | ||
9801 | return 1; | |
9802 | } | |
9803 | ||
9804 | /* Load the CU and TU indexes if present. This will build a list of | |
9805 | section sets that we can use to associate a .debug_info.dwo section | |
9806 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
9807 | ||
43a444f9 | 9808 | static bfd_boolean |
657d0d47 CC |
9809 | load_cu_tu_indexes (void *file) |
9810 | { | |
43a444f9 NC |
9811 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
9812 | ||
657d0d47 CC |
9813 | /* If we have already loaded (or tried to load) the CU and TU indexes |
9814 | then do not bother to repeat the task. */ | |
43a444f9 NC |
9815 | if (cu_tu_indexes_read == -1) |
9816 | { | |
9817 | cu_tu_indexes_read = TRUE; | |
9818 | ||
dda8d76d | 9819 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 NC |
9820 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
9821 | cu_tu_indexes_read = FALSE; | |
9822 | ||
dda8d76d | 9823 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 NC |
9824 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
9825 | cu_tu_indexes_read = FALSE; | |
9826 | } | |
657d0d47 | 9827 | |
43a444f9 | 9828 | return (bfd_boolean) cu_tu_indexes_read; |
657d0d47 CC |
9829 | } |
9830 | ||
9831 | /* Find the set of sections that includes section SHNDX. */ | |
9832 | ||
9833 | unsigned int * | |
9834 | find_cu_tu_set (void *file, unsigned int shndx) | |
9835 | { | |
9836 | unsigned int i; | |
9837 | ||
43a444f9 NC |
9838 | if (! load_cu_tu_indexes (file)) |
9839 | return NULL; | |
657d0d47 CC |
9840 | |
9841 | /* Find SHNDX in the shndx pool. */ | |
9842 | for (i = 0; i < shndx_pool_used; i++) | |
9843 | if (shndx_pool [i] == shndx) | |
9844 | break; | |
9845 | ||
9846 | if (i >= shndx_pool_used) | |
9847 | return NULL; | |
9848 | ||
9849 | /* Now backup to find the first entry in the set. */ | |
9850 | while (i > 0 && shndx_pool [i - 1] != 0) | |
9851 | i--; | |
9852 | ||
9853 | return shndx_pool + i; | |
9854 | } | |
9855 | ||
9856 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
9857 | ||
9858 | static int | |
9859 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
9860 | { | |
9861 | return process_cu_tu_index (section, 1); | |
9862 | } | |
9863 | ||
19e6b90e L |
9864 | static int |
9865 | display_debug_not_supported (struct dwarf_section *section, | |
9866 | void *file ATTRIBUTE_UNUSED) | |
9867 | { | |
9868 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
9869 | section->name); | |
9870 | ||
9871 | return 1; | |
9872 | } | |
9873 | ||
1306a742 NC |
9874 | /* Like malloc, but takes two parameters like calloc. |
9875 | Verifies that the first parameter is not too large. | |
82b1b41b | 9876 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 9877 | |
19e6b90e L |
9878 | void * |
9879 | cmalloc (size_t nmemb, size_t size) | |
9880 | { | |
9881 | /* Check for overflow. */ | |
9882 | if (nmemb >= ~(size_t) 0 / size) | |
9883 | return NULL; | |
82b1b41b NC |
9884 | |
9885 | return xmalloc (nmemb * size); | |
19e6b90e L |
9886 | } |
9887 | ||
1306a742 NC |
9888 | /* Like xmalloc, but takes two parameters like calloc. |
9889 | Verifies that the first parameter is not too large. | |
9890 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 9891 | |
72c61a0d | 9892 | void * |
1306a742 | 9893 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
9894 | { |
9895 | /* Check for overflow. */ | |
9896 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
9897 | { |
9898 | fprintf (stderr, | |
9899 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
9900 | (long) nmemb); | |
9901 | xexit (1); | |
9902 | } | |
72c61a0d | 9903 | |
1306a742 | 9904 | return xmalloc (nmemb * size); |
72c61a0d NC |
9905 | } |
9906 | ||
1306a742 NC |
9907 | /* Like xrealloc, but takes three parameters. |
9908 | Verifies that the second parameter is not too large. | |
9909 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 9910 | |
19e6b90e | 9911 | void * |
1306a742 | 9912 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
9913 | { |
9914 | /* Check for overflow. */ | |
9915 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 9916 | { |
dda8d76d NC |
9917 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
9918 | (long) nmemb); | |
8490fb40 NC |
9919 | xexit (1); |
9920 | } | |
82b1b41b | 9921 | |
1306a742 | 9922 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
9923 | } |
9924 | ||
1306a742 | 9925 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 9926 | |
19e6b90e | 9927 | void * |
1306a742 | 9928 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
9929 | { |
9930 | /* Check for overflow. */ | |
9931 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 9932 | { |
dda8d76d NC |
9933 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
9934 | (long) nmemb); | |
8490fb40 NC |
9935 | xexit (1); |
9936 | } | |
82b1b41b | 9937 | |
1306a742 | 9938 | return xcalloc (nmemb, size); |
19e6b90e L |
9939 | } |
9940 | ||
dda8d76d NC |
9941 | static unsigned long |
9942 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
9943 | const unsigned char * buf, | |
9944 | bfd_size_type len) | |
9945 | { | |
9946 | static const unsigned long crc32_table[256] = | |
9947 | { | |
9948 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
9949 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
9950 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
9951 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
9952 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
9953 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
9954 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
9955 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
9956 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
9957 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
9958 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
9959 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
9960 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
9961 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
9962 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
9963 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
9964 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
9965 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
9966 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
9967 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
9968 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
9969 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
9970 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
9971 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
9972 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
9973 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
9974 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
9975 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
9976 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
9977 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
9978 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
9979 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
9980 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
9981 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
9982 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
9983 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
9984 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
9985 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
9986 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
9987 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
9988 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
9989 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
9990 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
9991 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
9992 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
9993 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
9994 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
9995 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
9996 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
9997 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
9998 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
9999 | 0x2d02ef8d | |
10000 | }; | |
10001 | const unsigned char *end; | |
10002 | ||
10003 | crc = ~crc & 0xffffffff; | |
10004 | for (end = buf + len; buf < end; ++ buf) | |
10005 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
10006 | return ~crc & 0xffffffff; | |
10007 | } | |
10008 | ||
10009 | typedef bfd_boolean (* check_func_type) (const char *, void *); | |
10010 | typedef const char * (* parse_func_type) (struct dwarf_section *, void *); | |
10011 | ||
10012 | static bfd_boolean | |
10013 | check_gnu_debuglink (const char * pathname, void * crc_pointer) | |
10014 | { | |
10015 | static unsigned char buffer [8 * 1024]; | |
10016 | FILE * f; | |
10017 | bfd_size_type count; | |
10018 | unsigned long crc = 0; | |
10019 | void * sep_data; | |
10020 | ||
10021 | sep_data = open_debug_file (pathname); | |
10022 | if (sep_data == NULL) | |
10023 | return FALSE; | |
10024 | ||
10025 | /* Yes - we are opening the file twice... */ | |
10026 | f = fopen (pathname, "rb"); | |
10027 | if (f == NULL) | |
10028 | { | |
10029 | /* Paranoia: This should never happen. */ | |
10030 | close_debug_file (sep_data); | |
10031 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
10032 | return FALSE; | |
10033 | } | |
10034 | ||
10035 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
10036 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
10037 | ||
10038 | fclose (f); | |
10039 | ||
10040 | if (crc != * (unsigned long *) crc_pointer) | |
10041 | { | |
10042 | close_debug_file (sep_data); | |
10043 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
10044 | pathname); | |
10045 | return FALSE; | |
10046 | } | |
10047 | ||
10048 | return TRUE; | |
10049 | } | |
10050 | ||
10051 | static const char * | |
10052 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
10053 | { | |
10054 | const char * name; | |
10055 | unsigned int crc_offset; | |
10056 | unsigned long * crc32 = (unsigned long *) data; | |
10057 | ||
10058 | /* The name is first. | |
10059 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
10060 | name = (const char *) section->start; | |
10061 | ||
39f0547e | 10062 | |
dda8d76d NC |
10063 | crc_offset = strnlen (name, section->size) + 1; |
10064 | crc_offset = (crc_offset + 3) & ~3; | |
10065 | if (crc_offset + 4 > section->size) | |
10066 | return NULL; | |
10067 | ||
10068 | * crc32 = byte_get (section->start + crc_offset, 4); | |
10069 | return name; | |
10070 | } | |
10071 | ||
10072 | static bfd_boolean | |
10073 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) | |
10074 | { | |
10075 | void * sep_data = open_debug_file (filename); | |
10076 | ||
10077 | if (sep_data == NULL) | |
10078 | return FALSE; | |
10079 | ||
10080 | /* FIXME: We should now extract the build-id in the separate file | |
10081 | and check it... */ | |
10082 | ||
10083 | return TRUE; | |
10084 | } | |
10085 | ||
10086 | typedef struct build_id_data | |
10087 | { | |
10088 | bfd_size_type len; | |
10089 | const unsigned char * data; | |
10090 | } Build_id_data; | |
10091 | ||
10092 | static const char * | |
10093 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
10094 | { | |
10095 | const char * name; | |
10096 | bfd_size_type namelen; | |
10097 | bfd_size_type id_len; | |
10098 | Build_id_data * build_id_data; | |
10099 | ||
10100 | /* The name is first. | |
10101 | The build-id follows immediately, with no padding, up to the section's end. */ | |
10102 | ||
10103 | name = (const char *) section->start; | |
10104 | namelen = strnlen (name, section->size) + 1; | |
10105 | if (namelen >= section->size) | |
10106 | return NULL; | |
10107 | ||
10108 | id_len = section->size - namelen; | |
10109 | if (id_len < 0x14) | |
10110 | return NULL; | |
10111 | ||
10112 | build_id_data = calloc (1, sizeof * build_id_data); | |
10113 | if (build_id_data == NULL) | |
10114 | return NULL; | |
10115 | ||
10116 | build_id_data->len = id_len; | |
10117 | build_id_data->data = section->start + namelen; | |
10118 | ||
10119 | * (Build_id_data **) data = build_id_data; | |
10120 | ||
10121 | return name; | |
10122 | } | |
10123 | ||
24841daa NC |
10124 | static void |
10125 | add_separate_debug_file (const char * filename, void * handle) | |
10126 | { | |
10127 | separate_info * i = xmalloc (sizeof * i); | |
10128 | ||
10129 | i->filename = filename; | |
10130 | i->handle = handle; | |
10131 | i->next = first_separate_info; | |
10132 | first_separate_info = i; | |
10133 | } | |
10134 | ||
301a9420 AM |
10135 | #if HAVE_LIBDEBUGINFOD |
10136 | /* Query debuginfod servers for the target debuglink or debugaltlink | |
10137 | file. If successful, store the path of the file in filename and | |
10138 | return TRUE, otherwise return FALSE. */ | |
10139 | ||
10140 | static bfd_boolean | |
10141 | debuginfod_fetch_separate_debug_info (struct dwarf_section * section, | |
10142 | char ** filename, | |
10143 | void * file) | |
10144 | { | |
10145 | size_t build_id_len; | |
10146 | unsigned char * build_id; | |
10147 | ||
10148 | if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0) | |
10149 | { | |
10150 | /* Get the build-id of file. */ | |
10151 | build_id = get_build_id (file); | |
10152 | build_id_len = 0; | |
10153 | } | |
10154 | else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0) | |
10155 | { | |
10156 | /* Get the build-id of the debugaltlink file. */ | |
10157 | unsigned int filelen; | |
10158 | ||
10159 | filelen = strnlen ((const char *)section->start, section->size); | |
10160 | if (filelen == section->size) | |
10161 | /* Corrupt debugaltlink. */ | |
10162 | return FALSE; | |
10163 | ||
10164 | build_id = section->start + filelen + 1; | |
10165 | build_id_len = section->size - (filelen + 1); | |
10166 | ||
10167 | if (build_id_len == 0) | |
10168 | return FALSE; | |
10169 | } | |
10170 | else | |
10171 | return FALSE; | |
10172 | ||
10173 | if (build_id) | |
10174 | { | |
10175 | int fd; | |
10176 | debuginfod_client * client; | |
10177 | ||
10178 | client = debuginfod_begin (); | |
10179 | if (client == NULL) | |
10180 | return FALSE; | |
10181 | ||
10182 | /* Query debuginfod servers for the target file. If found its path | |
10183 | will be stored in filename. */ | |
10184 | fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename); | |
10185 | debuginfod_end (client); | |
10186 | ||
10187 | /* Only free build_id if we allocated space for a hex string | |
10188 | in get_build_id (). */ | |
10189 | if (build_id_len == 0) | |
10190 | free (build_id); | |
10191 | ||
10192 | if (fd >= 0) | |
10193 | { | |
10194 | /* File successfully retrieved. Close fd since we want to | |
10195 | use open_debug_file () on filename instead. */ | |
10196 | close (fd); | |
10197 | return TRUE; | |
10198 | } | |
10199 | } | |
10200 | ||
10201 | return FALSE; | |
10202 | } | |
10203 | #endif | |
10204 | ||
dda8d76d NC |
10205 | static void * |
10206 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 10207 | struct dwarf_section * xlink, |
dda8d76d NC |
10208 | parse_func_type parse_func, |
10209 | check_func_type check_func, | |
301a9420 AM |
10210 | void * func_data, |
10211 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
10212 | { |
10213 | const char * separate_filename; | |
24841daa | 10214 | char * debug_filename; |
dda8d76d NC |
10215 | char * canon_dir; |
10216 | size_t canon_dirlen; | |
10217 | size_t dirlen; | |
10218 | ||
2b63c337 | 10219 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
10220 | { |
10221 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 10222 | xlink->name ? xlink->name : xlink->uncompressed_name); |
dda8d76d NC |
10223 | return FALSE; |
10224 | } | |
10225 | ||
10226 | /* Attempt to locate the separate file. | |
10227 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
10228 | ||
10229 | canon_dir = lrealpath (main_filename); | |
10230 | ||
10231 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) | |
10232 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
10233 | break; | |
10234 | canon_dir[canon_dirlen] = '\0'; | |
10235 | ||
10236 | #ifndef DEBUGDIR | |
10237 | #define DEBUGDIR "/lib/debug" | |
10238 | #endif | |
10239 | #ifndef EXTRA_DEBUG_ROOT1 | |
10240 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
10241 | #endif | |
10242 | #ifndef EXTRA_DEBUG_ROOT2 | |
10243 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
10244 | #endif | |
10245 | ||
24841daa NC |
10246 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
10247 | + canon_dirlen | |
10248 | + strlen (".debug/") | |
dda8d76d | 10249 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 10250 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
10251 | #endif |
10252 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 10253 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 10254 | #endif |
24841daa NC |
10255 | + strlen (separate_filename) |
10256 | + 1); | |
10257 | if (debug_filename == NULL) | |
dda8d76d NC |
10258 | { |
10259 | warn (_("Out of memory")); | |
3391569f | 10260 | free (canon_dir); |
dda8d76d NC |
10261 | return NULL; |
10262 | } | |
10263 | ||
10264 | /* First try in the current directory. */ | |
24841daa NC |
10265 | sprintf (debug_filename, "%s", separate_filename); |
10266 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10267 | goto found; |
10268 | ||
10269 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
10270 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10271 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10272 | goto found; |
10273 | ||
10274 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
10275 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10276 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10277 | goto found; |
10278 | ||
10279 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
10280 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10281 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10282 | goto found; |
10283 | ||
10284 | #ifdef EXTRA_DEBUG_ROOT1 | |
10285 | /* Try the first extra debug file root. */ | |
24841daa NC |
10286 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10287 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 10288 | goto found; |
39f0547e NC |
10289 | |
10290 | /* Try the first extra debug file root. */ | |
10291 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
10292 | if (check_func (debug_filename, func_data)) | |
10293 | goto found; | |
dda8d76d NC |
10294 | #endif |
10295 | ||
10296 | #ifdef EXTRA_DEBUG_ROOT2 | |
10297 | /* Try the second extra debug file root. */ | |
24841daa NC |
10298 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10299 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10300 | goto found; |
10301 | #endif | |
10302 | ||
24841daa NC |
10303 | /* Then try in the global debug_filename directory. */ |
10304 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
10305 | dirlen = strlen (DEBUGDIR) - 1; |
10306 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
10307 | strcat (debug_filename, "/"); |
10308 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 10309 | |
24841daa | 10310 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
10311 | goto found; |
10312 | ||
301a9420 AM |
10313 | #if HAVE_LIBDEBUGINFOD |
10314 | { | |
10315 | char * tmp_filename; | |
10316 | ||
10317 | if (debuginfod_fetch_separate_debug_info (xlink, | |
10318 | & tmp_filename, | |
10319 | file)) | |
10320 | { | |
10321 | /* File successfully downloaded from server, replace | |
10322 | debug_filename with the file's path. */ | |
10323 | free (debug_filename); | |
10324 | debug_filename = tmp_filename; | |
10325 | goto found; | |
10326 | } | |
10327 | } | |
10328 | #endif | |
10329 | ||
dda8d76d NC |
10330 | /* Failed to find the file. */ |
10331 | warn (_("could not find separate debug file '%s'\n"), separate_filename); | |
24841daa | 10332 | warn (_("tried: %s\n"), debug_filename); |
dda8d76d NC |
10333 | |
10334 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa NC |
10335 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10336 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10337 | #endif |
10338 | ||
10339 | #ifdef EXTRA_DEBUG_ROOT1 | |
39f0547e NC |
10340 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); |
10341 | warn (_("tried: %s\n"), debug_filename); | |
10342 | ||
24841daa NC |
10343 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10344 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10345 | #endif |
10346 | ||
24841daa NC |
10347 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10348 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10349 | |
24841daa NC |
10350 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10351 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10352 | |
24841daa NC |
10353 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10354 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10355 | |
24841daa NC |
10356 | sprintf (debug_filename, "%s", separate_filename); |
10357 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10358 | |
301a9420 AM |
10359 | #if HAVE_LIBDEBUGINFOD |
10360 | { | |
10361 | char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR); | |
10362 | if (urls == NULL) | |
10363 | urls = ""; | |
10364 | ||
10365 | warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls); | |
10366 | } | |
10367 | #endif | |
10368 | ||
dda8d76d | 10369 | free (canon_dir); |
24841daa | 10370 | free (debug_filename); |
dda8d76d NC |
10371 | return NULL; |
10372 | ||
10373 | found: | |
10374 | free (canon_dir); | |
10375 | ||
24841daa NC |
10376 | void * debug_handle; |
10377 | ||
dda8d76d | 10378 | /* Now open the file.... */ |
24841daa | 10379 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 10380 | { |
24841daa NC |
10381 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
10382 | free (debug_filename); | |
dda8d76d NC |
10383 | return FALSE; |
10384 | } | |
10385 | ||
10386 | /* FIXME: We do not check to see if there are any other separate debug info | |
10387 | files that would also match. */ | |
10388 | ||
24841daa NC |
10389 | printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debug_filename); |
10390 | add_separate_debug_file (debug_filename, debug_handle); | |
dda8d76d | 10391 | |
24841daa | 10392 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 10393 | the structure returned by open_debug_file(). */ |
24841daa | 10394 | return debug_handle; |
dda8d76d NC |
10395 | } |
10396 | ||
d85bf2ba NC |
10397 | /* Attempt to load a separate dwarf object file. */ |
10398 | ||
10399 | static void * | |
24841daa | 10400 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 10401 | { |
24841daa NC |
10402 | char * separate_filename; |
10403 | void * separate_handle; | |
d85bf2ba NC |
10404 | |
10405 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
24841daa NC |
10406 | separate_filename = concat (dir, "/", name, NULL); |
10407 | if (separate_filename == NULL) | |
d85bf2ba NC |
10408 | { |
10409 | warn (_("Out of memory allocating dwo filename\n")); | |
10410 | return NULL; | |
10411 | } | |
10412 | ||
24841daa | 10413 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 10414 | { |
24841daa NC |
10415 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
10416 | free (separate_filename); | |
d85bf2ba NC |
10417 | return NULL; |
10418 | } | |
10419 | ||
10420 | /* FIXME: We should check the dwo_id. */ | |
10421 | ||
24841daa NC |
10422 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
10423 | add_separate_debug_file (separate_filename, separate_handle); | |
10424 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
10425 | return separate_handle; | |
d85bf2ba NC |
10426 | } |
10427 | ||
24841daa NC |
10428 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
10429 | Returns TRUE if any were found, FALSE otherwise. | |
10430 | If TRUE is returned then the linked list starting at first_separate_info | |
10431 | will be populated with open file handles. */ | |
dda8d76d | 10432 | |
24841daa NC |
10433 | bfd_boolean |
10434 | load_separate_debug_files (void * file, const char * filename) | |
dda8d76d | 10435 | { |
8de3a6e2 NC |
10436 | /* Skip this operation if we are not interested in debug links. */ |
10437 | if (! do_follow_links && ! do_debug_links) | |
24841daa | 10438 | return FALSE; |
8de3a6e2 | 10439 | |
24841daa | 10440 | /* See if there are any dwo links. */ |
d85bf2ba NC |
10441 | if (load_debug_section (str, file) |
10442 | && load_debug_section (abbrev, file) | |
10443 | && load_debug_section (info, file)) | |
10444 | { | |
24841daa | 10445 | free_dwo_info (); |
d85bf2ba NC |
10446 | |
10447 | if (process_debug_info (& debug_displays[info].section, file, abbrev, TRUE, FALSE)) | |
10448 | { | |
24841daa NC |
10449 | bfd_boolean introduced = FALSE; |
10450 | dwo_info * dwinfo; | |
10451 | const char * dir = NULL; | |
10452 | const char * id = NULL; | |
10453 | ||
10454 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 10455 | { |
24841daa | 10456 | switch (dwinfo->type) |
d85bf2ba | 10457 | { |
24841daa NC |
10458 | case DWO_NAME: |
10459 | if (do_debug_links) | |
10460 | { | |
10461 | if (! introduced) | |
10462 | { | |
10463 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
10464 | debug_displays [info].section.uncompressed_name); | |
10465 | introduced = TRUE; | |
10466 | } | |
d85bf2ba | 10467 | |
24841daa NC |
10468 | printf (_(" Name: %s\n"), dwinfo->value); |
10469 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); | |
10470 | if (id != NULL) | |
10471 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
10472 | else | |
10473 | printf (_(" ID: <unknown>\n")); | |
10474 | printf ("\n\n"); | |
10475 | } | |
10476 | ||
10477 | if (do_follow_links) | |
10478 | load_dwo_file (filename, dwinfo->value, dir, id); | |
10479 | break; | |
10480 | ||
10481 | case DWO_DIR: | |
10482 | dir = dwinfo->value; | |
10483 | break; | |
10484 | ||
10485 | case DWO_ID: | |
10486 | id = dwinfo->value; | |
10487 | break; | |
10488 | ||
10489 | default: | |
10490 | error (_("Unexpected DWO INFO type")); | |
10491 | break; | |
10492 | } | |
d85bf2ba NC |
10493 | } |
10494 | } | |
10495 | } | |
10496 | ||
dda8d76d | 10497 | if (! do_follow_links) |
8de3a6e2 NC |
10498 | /* The other debug links will be displayed by display_debug_links() |
10499 | so we do not need to do any further processing here. */ | |
24841daa | 10500 | return FALSE; |
dda8d76d NC |
10501 | |
10502 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
10503 | /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */ | |
10504 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ | |
d85bf2ba | 10505 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 10506 | |
dda8d76d NC |
10507 | if (load_debug_section (gnu_debugaltlink, file)) |
10508 | { | |
10509 | Build_id_data * build_id_data; | |
10510 | ||
24841daa NC |
10511 | load_separate_debug_info (filename, |
10512 | & debug_displays[gnu_debugaltlink].section, | |
10513 | parse_gnu_debugaltlink, | |
10514 | check_gnu_debugaltlink, | |
301a9420 AM |
10515 | & build_id_data, |
10516 | file); | |
dda8d76d NC |
10517 | } |
10518 | ||
10519 | if (load_debug_section (gnu_debuglink, file)) | |
10520 | { | |
10521 | unsigned long crc32; | |
10522 | ||
24841daa NC |
10523 | load_separate_debug_info (filename, |
10524 | & debug_displays[gnu_debuglink].section, | |
10525 | parse_gnu_debuglink, | |
10526 | check_gnu_debuglink, | |
301a9420 AM |
10527 | & crc32, |
10528 | file); | |
dda8d76d NC |
10529 | } |
10530 | ||
24841daa NC |
10531 | if (first_separate_info != NULL) |
10532 | return TRUE; | |
10533 | ||
dda8d76d | 10534 | do_follow_links = 0; |
24841daa | 10535 | return FALSE; |
dda8d76d NC |
10536 | } |
10537 | ||
19e6b90e L |
10538 | void |
10539 | free_debug_memory (void) | |
10540 | { | |
3f5e193b | 10541 | unsigned int i; |
19e6b90e L |
10542 | |
10543 | free_abbrevs (); | |
10544 | ||
10545 | for (i = 0; i < max; i++) | |
3f5e193b | 10546 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 10547 | |
cc86f28f | 10548 | if (debug_information != NULL) |
19e6b90e | 10549 | { |
cc86f28f | 10550 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) |
19e6b90e | 10551 | { |
cc86f28f | 10552 | for (i = 0; i < num_debug_info_entries; i++) |
19e6b90e | 10553 | { |
cc86f28f NC |
10554 | if (!debug_information [i].max_loc_offsets) |
10555 | { | |
10556 | free (debug_information [i].loc_offsets); | |
10557 | free (debug_information [i].have_frame_base); | |
10558 | } | |
10559 | if (!debug_information [i].max_range_lists) | |
10560 | free (debug_information [i].range_lists); | |
19e6b90e | 10561 | } |
19e6b90e L |
10562 | } |
10563 | free (debug_information); | |
10564 | debug_information = NULL; | |
82b1b41b | 10565 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 10566 | } |
dda8d76d | 10567 | |
24841daa NC |
10568 | separate_info * d; |
10569 | separate_info * next; | |
dda8d76d | 10570 | |
24841daa NC |
10571 | for (d = first_separate_info; d != NULL; d = next) |
10572 | { | |
10573 | close_debug_file (d->handle); | |
10574 | free ((void *) d->filename); | |
10575 | next = d->next; | |
10576 | free ((void *) d); | |
dda8d76d | 10577 | } |
24841daa NC |
10578 | first_separate_info = NULL; |
10579 | ||
10580 | free_dwo_info (); | |
19e6b90e L |
10581 | } |
10582 | ||
4cb93e3b TG |
10583 | void |
10584 | dwarf_select_sections_by_names (const char *names) | |
10585 | { | |
10586 | typedef struct | |
10587 | { | |
10588 | const char * option; | |
10589 | int * variable; | |
f9f0e732 | 10590 | int val; |
4cb93e3b TG |
10591 | } |
10592 | debug_dump_long_opts; | |
10593 | ||
10594 | static const debug_dump_long_opts opts_table [] = | |
10595 | { | |
10596 | /* Please keep this table alpha- sorted. */ | |
10597 | { "Ranges", & do_debug_ranges, 1 }, | |
10598 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 10599 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 10600 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
10601 | { "cu_index", & do_debug_cu_index, 1 }, |
10602 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 10603 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
10604 | { "frames", & do_debug_frames, 1 }, |
10605 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
10606 | /* The special .gdb_index section. */ |
10607 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
10608 | { "info", & do_debug_info, 1 }, |
10609 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 10610 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
10611 | { "loc", & do_debug_loc, 1 }, |
10612 | { "macro", & do_debug_macinfo, 1 }, | |
10613 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 10614 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 10615 | /* This entry is for compatibility |
4cb93e3b TG |
10616 | with earlier versions of readelf. */ |
10617 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 10618 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 10619 | { "str", & do_debug_str, 1 }, |
6f875884 TG |
10620 | /* These trace_* sections are used by Itanium VMS. */ |
10621 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
10622 | { "trace_aranges", & do_trace_aranges, 1 }, | |
10623 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
10624 | { NULL, NULL, 0 } |
10625 | }; | |
10626 | ||
10627 | const char *p; | |
467c65bc | 10628 | |
4cb93e3b TG |
10629 | p = names; |
10630 | while (*p) | |
10631 | { | |
10632 | const debug_dump_long_opts * entry; | |
467c65bc | 10633 | |
4cb93e3b TG |
10634 | for (entry = opts_table; entry->option; entry++) |
10635 | { | |
10636 | size_t len = strlen (entry->option); | |
467c65bc | 10637 | |
4cb93e3b TG |
10638 | if (strncmp (p, entry->option, len) == 0 |
10639 | && (p[len] == ',' || p[len] == '\0')) | |
10640 | { | |
10641 | * entry->variable |= entry->val; | |
467c65bc | 10642 | |
4cb93e3b TG |
10643 | /* The --debug-dump=frames-interp option also |
10644 | enables the --debug-dump=frames option. */ | |
10645 | if (do_debug_frames_interp) | |
10646 | do_debug_frames = 1; | |
10647 | ||
10648 | p += len; | |
10649 | break; | |
10650 | } | |
10651 | } | |
467c65bc | 10652 | |
4cb93e3b TG |
10653 | if (entry->option == NULL) |
10654 | { | |
10655 | warn (_("Unrecognized debug option '%s'\n"), p); | |
10656 | p = strchr (p, ','); | |
10657 | if (p == NULL) | |
10658 | break; | |
10659 | } | |
467c65bc | 10660 | |
4cb93e3b TG |
10661 | if (*p == ',') |
10662 | p++; | |
10663 | } | |
10664 | } | |
10665 | ||
10666 | void | |
10667 | dwarf_select_sections_by_letters (const char *letters) | |
10668 | { | |
91d6fa6a | 10669 | unsigned int lindex = 0; |
4cb93e3b | 10670 | |
91d6fa6a NC |
10671 | while (letters[lindex]) |
10672 | switch (letters[lindex++]) | |
4cb93e3b | 10673 | { |
dda8d76d NC |
10674 | case 'A': do_debug_addr = 1; break; |
10675 | case 'a': do_debug_abbrevs = 1; break; | |
10676 | case 'c': do_debug_cu_index = 1; break; | |
10677 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
10678 | case 'f': do_debug_frames = 1; break; | |
10679 | case 'g': do_gdb_index = 1; break; | |
10680 | case 'i': do_debug_info = 1; break; | |
10681 | case 'K': do_follow_links = 1; break; | |
10682 | case 'k': do_debug_links = 1; break; | |
10683 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
10684 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
10685 | case 'm': do_debug_macinfo = 1; break; | |
10686 | case 'o': do_debug_loc = 1; break; | |
10687 | case 'p': do_debug_pubnames = 1; break; | |
10688 | case 'R': do_debug_ranges = 1; break; | |
10689 | case 'r': do_debug_aranges = 1; break; | |
10690 | case 's': do_debug_str = 1; break; | |
10691 | case 'T': do_trace_aranges = 1; break; | |
10692 | case 't': do_debug_pubtypes = 1; break; | |
10693 | case 'U': do_trace_info = 1; break; | |
10694 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 10695 | |
4cb93e3b | 10696 | default: |
7cc78d07 | 10697 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
10698 | break; |
10699 | } | |
10700 | } | |
10701 | ||
10702 | void | |
10703 | dwarf_select_sections_all (void) | |
10704 | { | |
10705 | do_debug_info = 1; | |
10706 | do_debug_abbrevs = 1; | |
10707 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
10708 | do_debug_pubnames = 1; | |
f9f0e732 | 10709 | do_debug_pubtypes = 1; |
4cb93e3b TG |
10710 | do_debug_aranges = 1; |
10711 | do_debug_ranges = 1; | |
10712 | do_debug_frames = 1; | |
10713 | do_debug_macinfo = 1; | |
10714 | do_debug_str = 1; | |
10715 | do_debug_loc = 1; | |
5bbdf3d5 | 10716 | do_gdb_index = 1; |
6f875884 TG |
10717 | do_trace_info = 1; |
10718 | do_trace_abbrevs = 1; | |
10719 | do_trace_aranges = 1; | |
657d0d47 CC |
10720 | do_debug_addr = 1; |
10721 | do_debug_cu_index = 1; | |
dda8d76d NC |
10722 | do_follow_links = 1; |
10723 | do_debug_links = 1; | |
4cb93e3b TG |
10724 | } |
10725 | ||
dda8d76d NC |
10726 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL |
10727 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL | |
10728 | ||
10729 | /* N.B. The order here must match the order in section_display_enum. */ | |
10730 | ||
19e6b90e L |
10731 | struct dwarf_section_display debug_displays[] = |
10732 | { | |
dda8d76d NC |
10733 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, |
10734 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE }, | |
10735 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
10736 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE }, | |
10737 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
10738 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE }, | |
10739 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, | |
10740 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
10741 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
10742 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
10743 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
10744 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
10745 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10746 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10747 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE }, | |
10748 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, | |
10749 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
10750 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
10751 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10752 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10753 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE }, | |
10754 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10755 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE }, | |
10756 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE }, | |
10757 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE }, | |
10758 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE }, | |
10759 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE }, | |
10760 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE }, | |
10761 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
10762 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE }, | |
10763 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
10764 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10765 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
10766 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
10767 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE }, | |
10768 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, | |
10769 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, | |
10770 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE }, | |
10771 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
10772 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
10773 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
10774 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
10775 | /* Separate debug info files can containt their own .debug_str section, | |
10776 | and this might be in *addition* to a .debug_str section already present | |
10777 | in the main file. Hence we need to have two entries for .debug_str. */ | |
10778 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
19e6b90e | 10779 | }; |
b451e98a JK |
10780 | |
10781 | /* A static assertion. */ | |
10782 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |