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; | |
546cb2d8 | 101 | bfd_boolean do_checks; |
19e6b90e | 102 | |
fd2f0033 TT |
103 | int dwarf_cutoff_level = -1; |
104 | unsigned long dwarf_start_die; | |
105 | ||
4723351a CC |
106 | int dwarf_check = 0; |
107 | ||
9f272209 AO |
108 | /* Convenient constant, to avoid having to cast -1 to dwarf_vma when |
109 | testing whether e.g. a locview list is present. */ | |
110 | static const dwarf_vma vm1 = -1; | |
111 | ||
341f9135 CC |
112 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
113 | sections. For version 1 package files, each set is stored in SHNDX_POOL | |
114 | as a zero-terminated list of section indexes comprising one set of debug | |
115 | sections from a .dwo file. */ | |
116 | ||
341f9135 CC |
117 | static unsigned int *shndx_pool = NULL; |
118 | static unsigned int shndx_pool_size = 0; | |
119 | static unsigned int shndx_pool_used = 0; | |
120 | ||
121 | /* For version 2 package files, each set contains an array of section offsets | |
122 | and an array of section sizes, giving the offset and size of the | |
123 | contribution from a CU or TU within one of the debug sections. | |
124 | When displaying debug info from a package file, we need to use these | |
125 | tables to locate the corresponding contributions to each section. */ | |
126 | ||
127 | struct cu_tu_set | |
128 | { | |
ec1b0fbb NC |
129 | uint64_t signature; |
130 | dwarf_vma section_offsets[DW_SECT_MAX]; | |
131 | size_t section_sizes[DW_SECT_MAX]; | |
341f9135 CC |
132 | }; |
133 | ||
134 | static int cu_count = 0; | |
135 | static int tu_count = 0; | |
136 | static struct cu_tu_set *cu_sets = NULL; | |
137 | static struct cu_tu_set *tu_sets = NULL; | |
138 | ||
43a444f9 | 139 | static bfd_boolean load_cu_tu_indexes (void *); |
341f9135 | 140 | |
ec1b0fbb NC |
141 | /* An array that indicates for a given level of CU nesting whether |
142 | the latest DW_AT_type seen for that level was a signed type or | |
143 | an unsigned type. */ | |
144 | #define MAX_CU_NESTING (1 << 8) | |
145 | static bfd_boolean level_type_signed[MAX_CU_NESTING]; | |
146 | ||
4cb93e3b TG |
147 | /* Values for do_debug_lines. */ |
148 | #define FLAG_DEBUG_LINES_RAW 1 | |
149 | #define FLAG_DEBUG_LINES_DECODED 2 | |
150 | ||
77ef8654 | 151 | static unsigned int |
f1c4cc75 RH |
152 | size_of_encoded_value (int encoding) |
153 | { | |
154 | switch (encoding & 0x7) | |
155 | { | |
156 | default: /* ??? */ | |
157 | case 0: return eh_addr_size; | |
158 | case 2: return 2; | |
159 | case 3: return 4; | |
160 | case 4: return 8; | |
161 | } | |
162 | } | |
163 | ||
164 | static dwarf_vma | |
041830e0 | 165 | get_encoded_value (unsigned char **pdata, |
bad62cf5 | 166 | int encoding, |
041830e0 NC |
167 | struct dwarf_section *section, |
168 | unsigned char * end) | |
f1c4cc75 | 169 | { |
041830e0 | 170 | unsigned char * data = * pdata; |
6937bb54 | 171 | unsigned int size = size_of_encoded_value (encoding); |
bad62cf5 | 172 | dwarf_vma val; |
f1c4cc75 | 173 | |
041830e0 NC |
174 | if (data + size >= end) |
175 | { | |
176 | warn (_("Encoded value extends past end of section\n")); | |
177 | * pdata = end; | |
178 | return 0; | |
179 | } | |
180 | ||
6937bb54 NC |
181 | /* PR 17512: file: 002-829853-0.004. */ |
182 | if (size > 8) | |
183 | { | |
184 | warn (_("Encoded size of %d is too large to read\n"), size); | |
185 | * pdata = end; | |
186 | return 0; | |
187 | } | |
188 | ||
0a9d414a NC |
189 | /* PR 17512: file: 1085-5603-0.004. */ |
190 | if (size == 0) | |
191 | { | |
192 | warn (_("Encoded size of 0 is too small to read\n")); | |
193 | * pdata = end; | |
194 | return 0; | |
195 | } | |
196 | ||
f1c4cc75 | 197 | if (encoding & DW_EH_PE_signed) |
bad62cf5 | 198 | val = byte_get_signed (data, size); |
f1c4cc75 | 199 | else |
bad62cf5 AM |
200 | val = byte_get (data, size); |
201 | ||
202 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
203 | val += section->address + (data - section->start); | |
041830e0 NC |
204 | |
205 | * pdata = data + size; | |
bad62cf5 | 206 | return val; |
f1c4cc75 RH |
207 | } |
208 | ||
4c219c2e AM |
209 | #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG |
210 | # ifndef __MINGW32__ | |
211 | # define DWARF_VMA_FMT "ll" | |
212 | # define DWARF_VMA_FMT_LONG "%16.16llx" | |
213 | # else | |
214 | # define DWARF_VMA_FMT "I64" | |
215 | # define DWARF_VMA_FMT_LONG "%016I64x" | |
216 | # endif | |
2e14fae2 | 217 | #else |
4c219c2e AM |
218 | # define DWARF_VMA_FMT "l" |
219 | # define DWARF_VMA_FMT_LONG "%16.16lx" | |
2d9472a2 NC |
220 | #endif |
221 | ||
bf5117e3 NC |
222 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
223 | buffer containing the converted VALUE. The value is converted according | |
224 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then | |
225 | it specifies the maximum number of bytes to be displayed in the converted | |
226 | value and FMTCH is ignored - hex is always used. */ | |
467c65bc | 227 | |
47704ddf | 228 | static const char * |
bf5117e3 | 229 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
47704ddf KT |
230 | { |
231 | /* As dwarf_vmatoa is used more then once in a printf call | |
232 | for output, we are cycling through an fixed array of pointers | |
233 | for return address. */ | |
234 | static int buf_pos = 0; | |
467c65bc NC |
235 | static struct dwarf_vmatoa_buf |
236 | { | |
47704ddf KT |
237 | char place[64]; |
238 | } buf[16]; | |
47704ddf KT |
239 | char *ret; |
240 | ||
47704ddf | 241 | ret = buf[buf_pos++].place; |
467c65bc | 242 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf | 243 | |
bf5117e3 NC |
244 | if (num_bytes) |
245 | { | |
222c2bf0 | 246 | /* Printf does not have a way of specifying a maximum field width for an |
bf5117e3 NC |
247 | integer value, so we print the full value into a buffer and then select |
248 | the precision we need. */ | |
249 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); | |
250 | if (num_bytes > 8) | |
251 | num_bytes = 8; | |
252 | return ret + (16 - 2 * num_bytes); | |
253 | } | |
254 | else | |
255 | { | |
256 | char fmt[32]; | |
257 | ||
0bae9e9e NC |
258 | if (fmtch) |
259 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); | |
260 | else | |
261 | sprintf (fmt, "%%%s", DWARF_VMA_FMT); | |
bf5117e3 NC |
262 | snprintf (ret, sizeof (buf[0].place), fmt, value); |
263 | return ret; | |
264 | } | |
265 | } | |
47704ddf | 266 | |
bf5117e3 NC |
267 | static inline const char * |
268 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) | |
269 | { | |
270 | return dwarf_vmatoa_1 (fmtch, value, 0); | |
271 | } | |
272 | ||
273 | /* Print a dwarf_vma value (typically an address, offset or length) in | |
274 | hexadecimal format, followed by a space. The length of the VALUE (and | |
275 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ | |
276 | ||
277 | static void | |
278 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) | |
279 | { | |
280 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); | |
47704ddf KT |
281 | } |
282 | ||
9f272209 AO |
283 | /* Print a view number in hexadecimal value, with the same width |
284 | print_dwarf_vma would have printed it with the same num_bytes. | |
285 | Print blanks for zero view, unless force is nonzero. */ | |
286 | ||
287 | static void | |
288 | print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force) | |
289 | { | |
290 | int len; | |
291 | if (!num_bytes) | |
292 | len = 4; | |
293 | else | |
294 | len = num_bytes * 2; | |
295 | ||
296 | assert (value == (unsigned long) value); | |
297 | if (value || force) | |
298 | printf ("v%0*lx ", len - 1, (unsigned long) value); | |
299 | else | |
300 | printf ("%*s", len + 1, ""); | |
301 | } | |
302 | ||
74bc6052 CC |
303 | /* Format a 64-bit value, given as two 32-bit values, in hex. |
304 | For reentrancy, this uses a buffer provided by the caller. */ | |
305 | ||
306 | static const char * | |
307 | dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, | |
308 | unsigned int buf_len) | |
309 | { | |
310 | int len = 0; | |
311 | ||
312 | if (hvalue == 0) | |
313 | snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); | |
314 | else | |
315 | { | |
316 | len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); | |
317 | snprintf (buf + len, buf_len - len, | |
318 | "%08" DWARF_VMA_FMT "x", lvalue); | |
319 | } | |
320 | ||
321 | return buf; | |
322 | } | |
323 | ||
f6f0e17b NC |
324 | /* Read in a LEB128 encoded value starting at address DATA. |
325 | If SIGN is true, return a signed LEB128 value. | |
326 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
cd30bcef AM |
327 | If STATUS_RETURN in not NULL, return with bit 0 (LSB) set if the |
328 | terminating byte was not found and with bit 1 set if the value | |
329 | overflows a dwarf_vma. | |
f6f0e17b NC |
330 | No bytes will be read at address END or beyond. */ |
331 | ||
467c65bc | 332 | dwarf_vma |
f6f0e17b | 333 | read_leb128 (unsigned char *data, |
cd30bcef | 334 | const unsigned char *const end, |
f6f0e17b | 335 | bfd_boolean sign, |
cd30bcef AM |
336 | unsigned int *length_return, |
337 | int *status_return) | |
19e6b90e | 338 | { |
467c65bc | 339 | dwarf_vma result = 0; |
19e6b90e L |
340 | unsigned int num_read = 0; |
341 | unsigned int shift = 0; | |
cd30bcef | 342 | int status = 1; |
19e6b90e | 343 | |
f6f0e17b | 344 | while (data < end) |
19e6b90e | 345 | { |
cd30bcef | 346 | unsigned char byte = *data++; |
19e6b90e L |
347 | num_read++; |
348 | ||
cd30bcef AM |
349 | if (shift < sizeof (result) * 8) |
350 | { | |
351 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; | |
352 | if ((result >> shift) != (byte & 0x7f)) | |
353 | /* Overflow. */ | |
354 | status |= 2; | |
355 | shift += 7; | |
356 | } | |
357 | else if ((byte & 0x7f) != 0) | |
358 | status |= 2; | |
19e6b90e | 359 | |
f6f0e17b | 360 | if ((byte & 0x80) == 0) |
cd30bcef AM |
361 | { |
362 | status &= ~1; | |
363 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) | |
364 | result |= -((dwarf_vma) 1 << shift); | |
365 | break; | |
366 | } | |
19e6b90e | 367 | } |
19e6b90e L |
368 | |
369 | if (length_return != NULL) | |
370 | *length_return = num_read; | |
cd30bcef AM |
371 | if (status_return != NULL) |
372 | *status_return = status; | |
19e6b90e L |
373 | |
374 | return result; | |
375 | } | |
376 | ||
d11ae95e NC |
377 | /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value. |
378 | Checks to make sure that the read will not reach or pass END | |
379 | and that VAL is big enough to hold AMOUNT bytes. */ | |
0c588247 NC |
380 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
381 | do \ | |
382 | { \ | |
383 | unsigned int amount = (AMOUNT); \ | |
34b9f729 NC |
384 | if (sizeof (VAL) < amount) \ |
385 | { \ | |
d3a49aa8 AM |
386 | error (ngettext ("internal error: attempt to read %d byte " \ |
387 | "of data in to %d sized variable", \ | |
388 | "internal error: attempt to read %d bytes " \ | |
389 | "of data in to %d sized variable", \ | |
390 | amount), \ | |
34b9f729 NC |
391 | amount, (int) sizeof (VAL)); \ |
392 | amount = sizeof (VAL); \ | |
393 | } \ | |
0c588247 NC |
394 | if (((PTR) + amount) >= (END)) \ |
395 | { \ | |
396 | if ((PTR) < (END)) \ | |
397 | amount = (END) - (PTR); \ | |
398 | else \ | |
399 | amount = 0; \ | |
400 | } \ | |
6937bb54 | 401 | if (amount == 0 || amount > 8) \ |
0c588247 | 402 | VAL = 0; \ |
6937bb54 NC |
403 | else \ |
404 | VAL = byte_get ((PTR), amount); \ | |
0c588247 NC |
405 | } \ |
406 | while (0) | |
407 | ||
d11ae95e | 408 | /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
409 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
410 | do \ | |
411 | { \ | |
412 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
413 | PTR += AMOUNT; \ | |
414 | } \ | |
415 | while (0) | |
416 | ||
d11ae95e | 417 | /* Like SAFE_BYTE_GET, but reads a signed value. */ |
0c588247 NC |
418 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
419 | do \ | |
420 | { \ | |
421 | unsigned int amount = (AMOUNT); \ | |
422 | if (((PTR) + amount) >= (END)) \ | |
423 | { \ | |
424 | if ((PTR) < (END)) \ | |
425 | amount = (END) - (PTR); \ | |
426 | else \ | |
427 | amount = 0; \ | |
428 | } \ | |
429 | if (amount) \ | |
430 | VAL = byte_get_signed ((PTR), amount); \ | |
431 | else \ | |
432 | VAL = 0; \ | |
433 | } \ | |
434 | while (0) | |
435 | ||
d11ae95e | 436 | /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
437 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
438 | do \ | |
439 | { \ | |
440 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
441 | PTR += AMOUNT; \ | |
442 | } \ | |
443 | while (0) | |
444 | ||
445 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ | |
446 | do \ | |
447 | { \ | |
87bc83b3 | 448 | if (((PTR) + 8) <= (END)) \ |
0c588247 NC |
449 | { \ |
450 | byte_get_64 ((PTR), (HIGH), (LOW)); \ | |
451 | } \ | |
452 | else \ | |
453 | { \ | |
0c588247 NC |
454 | * (LOW) = * (HIGH) = 0; \ |
455 | } \ | |
456 | } \ | |
457 | while (0) | |
458 | ||
19e6b90e L |
459 | typedef struct State_Machine_Registers |
460 | { | |
467c65bc | 461 | dwarf_vma address; |
ba8826a8 | 462 | unsigned int view; |
19e6b90e L |
463 | unsigned int file; |
464 | unsigned int line; | |
465 | unsigned int column; | |
466 | int is_stmt; | |
467 | int basic_block; | |
a233b20c JJ |
468 | unsigned char op_index; |
469 | unsigned char end_sequence; | |
ba8826a8 AO |
470 | /* This variable hold the number of the last entry seen |
471 | in the File Table. */ | |
19e6b90e L |
472 | unsigned int last_file_entry; |
473 | } SMR; | |
474 | ||
475 | static SMR state_machine_regs; | |
476 | ||
477 | static void | |
478 | reset_state_machine (int is_stmt) | |
479 | { | |
480 | state_machine_regs.address = 0; | |
ba8826a8 | 481 | state_machine_regs.view = 0; |
a233b20c | 482 | state_machine_regs.op_index = 0; |
19e6b90e L |
483 | state_machine_regs.file = 1; |
484 | state_machine_regs.line = 1; | |
485 | state_machine_regs.column = 0; | |
486 | state_machine_regs.is_stmt = is_stmt; | |
487 | state_machine_regs.basic_block = 0; | |
488 | state_machine_regs.end_sequence = 0; | |
489 | state_machine_regs.last_file_entry = 0; | |
490 | } | |
491 | ||
492 | /* Handled an extend line op. | |
493 | Returns the number of bytes read. */ | |
494 | ||
cd30bcef | 495 | static size_t |
f6f0e17b NC |
496 | process_extended_line_op (unsigned char * data, |
497 | int is_stmt, | |
498 | unsigned char * end) | |
19e6b90e L |
499 | { |
500 | unsigned char op_code; | |
cd30bcef | 501 | size_t len, header_len; |
19e6b90e | 502 | unsigned char *name; |
143a3db0 | 503 | unsigned char *orig_data = data; |
cd30bcef | 504 | dwarf_vma adr, val; |
19e6b90e | 505 | |
cd30bcef AM |
506 | READ_ULEB (len, data, end); |
507 | header_len = data - orig_data; | |
19e6b90e | 508 | |
cd30bcef | 509 | if (len == 0 || data == end || len > (size_t) (end - data)) |
19e6b90e | 510 | { |
f41e4712 | 511 | warn (_("Badly formed extended line op encountered!\n")); |
cd30bcef | 512 | return header_len; |
19e6b90e L |
513 | } |
514 | ||
19e6b90e L |
515 | op_code = *data++; |
516 | ||
517 | printf (_(" Extended opcode %d: "), op_code); | |
518 | ||
519 | switch (op_code) | |
520 | { | |
521 | case DW_LNE_end_sequence: | |
522 | printf (_("End of Sequence\n\n")); | |
523 | reset_state_machine (is_stmt); | |
524 | break; | |
525 | ||
526 | case DW_LNE_set_address: | |
6937bb54 | 527 | /* PR 17512: file: 002-100480-0.004. */ |
cd30bcef | 528 | if (len - 1 > 8) |
77ef8654 | 529 | { |
cd30bcef AM |
530 | warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"), |
531 | (unsigned long) len - 1); | |
77ef8654 NC |
532 | adr = 0; |
533 | } | |
534 | else | |
cd30bcef | 535 | SAFE_BYTE_GET (adr, data, len - 1, end); |
47704ddf | 536 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 537 | state_machine_regs.address = adr; |
ba8826a8 | 538 | state_machine_regs.view = 0; |
a233b20c | 539 | state_machine_regs.op_index = 0; |
19e6b90e L |
540 | break; |
541 | ||
542 | case DW_LNE_define_file: | |
143a3db0 | 543 | printf (_("define new File Table entry\n")); |
19e6b90e | 544 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 545 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 546 | |
d949ff56 NC |
547 | { |
548 | size_t l; | |
549 | ||
550 | name = data; | |
551 | l = strnlen ((char *) data, end - data); | |
cd30bcef AM |
552 | data += l + 1; |
553 | READ_ULEB (val, data, end); | |
554 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
555 | READ_ULEB (val, data, end); | |
556 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
557 | READ_ULEB (val, data, end); | |
558 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
d949ff56 NC |
559 | printf ("%.*s\n\n", (int) l, name); |
560 | } | |
f6f0e17b | 561 | |
cd30bcef | 562 | if (((size_t) (data - orig_data) != len + header_len) || data == end) |
b4eb7656 | 563 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
564 | break; |
565 | ||
ed4a4bdf | 566 | case DW_LNE_set_discriminator: |
cd30bcef AM |
567 | READ_ULEB (val, data, end); |
568 | printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val)); | |
ed4a4bdf CC |
569 | break; |
570 | ||
e2a0d921 NC |
571 | /* HP extensions. */ |
572 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 573 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
574 | break; |
575 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 576 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
577 | break; |
578 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 579 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
580 | break; |
581 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 582 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
583 | break; |
584 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 585 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
586 | break; |
587 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 588 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
589 | break; |
590 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 591 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
592 | break; |
593 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 594 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
595 | break; |
596 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 597 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
598 | break; |
599 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 600 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 601 | break; |
43294ab7 TG |
602 | case DW_LNE_HP_source_file_correlation: |
603 | { | |
cd30bcef | 604 | unsigned char *edata = data + len - 1; |
b4eb7656 AM |
605 | |
606 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
607 | ||
608 | while (data < edata) | |
609 | { | |
610 | unsigned int opc; | |
611 | ||
cd30bcef | 612 | READ_ULEB (opc, data, edata); |
b4eb7656 AM |
613 | |
614 | switch (opc) | |
615 | { | |
616 | case DW_LNE_HP_SFC_formfeed: | |
617 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
618 | break; | |
619 | case DW_LNE_HP_SFC_set_listing_line: | |
cd30bcef | 620 | READ_ULEB (val, data, edata); |
b4eb7656 | 621 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", |
cd30bcef | 622 | dwarf_vmatoa ("u", val)); |
b4eb7656 AM |
623 | break; |
624 | case DW_LNE_HP_SFC_associate: | |
625 | printf (" DW_LNE_HP_SFC_associate "); | |
cd30bcef AM |
626 | READ_ULEB (val, data, edata); |
627 | printf ("(%s", dwarf_vmatoa ("u", val)); | |
628 | READ_ULEB (val, data, edata); | |
629 | printf (",%s", dwarf_vmatoa ("u", val)); | |
630 | READ_ULEB (val, data, edata); | |
631 | printf (",%s)\n", dwarf_vmatoa ("u", val)); | |
b4eb7656 AM |
632 | break; |
633 | default: | |
634 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
635 | data = edata; | |
636 | break; | |
637 | } | |
638 | } | |
43294ab7 TG |
639 | } |
640 | break; | |
cecf136e | 641 | |
19e6b90e | 642 | default: |
7e665af3 | 643 | { |
cd30bcef | 644 | unsigned int rlen = len - 1; |
b4eb7656 AM |
645 | |
646 | if (op_code >= DW_LNE_lo_user | |
647 | /* The test against DW_LNW_hi_user is redundant due to | |
648 | the limited range of the unsigned char data type used | |
649 | for op_code. */ | |
650 | /*&& op_code <= DW_LNE_hi_user*/) | |
651 | printf (_("user defined: ")); | |
652 | else | |
653 | printf (_("UNKNOWN: ")); | |
654 | printf (_("length %d ["), rlen); | |
655 | for (; rlen; rlen--) | |
656 | printf (" %02x", *data++); | |
657 | printf ("]\n"); | |
7e665af3 | 658 | } |
19e6b90e L |
659 | break; |
660 | } | |
661 | ||
cd30bcef | 662 | return len + header_len; |
19e6b90e L |
663 | } |
664 | ||
0c588247 | 665 | static const unsigned char * |
467c65bc | 666 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
667 | { |
668 | struct dwarf_section *section = &debug_displays [str].section; | |
d949ff56 | 669 | const unsigned char * ret; |
19e6b90e L |
670 | |
671 | if (section->start == NULL) | |
0c588247 | 672 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e | 673 | |
d949ff56 | 674 | if (offset >= section->size) |
19e6b90e | 675 | { |
467c65bc NC |
676 | warn (_("DW_FORM_strp offset too big: %s\n"), |
677 | dwarf_vmatoa ("x", offset)); | |
0c588247 | 678 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
679 | } |
680 | ||
d949ff56 NC |
681 | ret = section->start + offset; |
682 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
683 | NUL byte. Since our caller is expecting to receive a well formed C | |
684 | string we test for the lack of a terminating byte here. */ | |
685 | if (strnlen ((const char *) ret, section->size - offset) | |
686 | == section->size - offset) | |
687 | ret = (const unsigned char *) | |
688 | _("<no NUL byte at end of .debug_str section>"); | |
689 | ||
690 | return ret; | |
19e6b90e L |
691 | } |
692 | ||
77145576 JK |
693 | static const unsigned char * |
694 | fetch_indirect_line_string (dwarf_vma offset) | |
695 | { | |
696 | struct dwarf_section *section = &debug_displays [line_str].section; | |
d949ff56 | 697 | const unsigned char * ret; |
77145576 JK |
698 | |
699 | if (section->start == NULL) | |
700 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
701 | ||
d949ff56 | 702 | if (offset >= section->size) |
77145576 JK |
703 | { |
704 | warn (_("DW_FORM_line_strp offset too big: %s\n"), | |
705 | dwarf_vmatoa ("x", offset)); | |
706 | return (const unsigned char *) _("<offset is too big>"); | |
707 | } | |
708 | ||
d949ff56 NC |
709 | ret = section->start + offset; |
710 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
711 | with a NUL byte. Since our caller is expecting to receive a well formed | |
712 | C string we test for the lack of a terminating byte here. */ | |
713 | if (strnlen ((const char *) ret, section->size - offset) | |
714 | == section->size - offset) | |
715 | ret = (const unsigned char *) | |
716 | _("<no NUL byte at end of .debug_line_str section>"); | |
717 | ||
718 | return ret; | |
77145576 JK |
719 | } |
720 | ||
4723351a | 721 | static const char * |
341f9135 | 722 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
d85bf2ba | 723 | dwarf_vma offset_size, bfd_boolean dwo) |
4723351a CC |
724 | { |
725 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
726 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
727 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
728 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
729 | dwarf_vma index_offset = idx * offset_size; | |
730 | dwarf_vma str_offset; | |
d949ff56 | 731 | const char * ret; |
4723351a CC |
732 | |
733 | if (index_section->start == NULL) | |
734 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
735 | : _("<no .debug_str_offsets section>")); | |
736 | ||
341f9135 CC |
737 | if (this_set != NULL) |
738 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
d949ff56 | 739 | if (index_offset >= index_section->size) |
4723351a CC |
740 | { |
741 | warn (_("DW_FORM_GNU_str_index offset too big: %s\n"), | |
742 | dwarf_vmatoa ("x", index_offset)); | |
743 | return _("<index offset is too big>"); | |
744 | } | |
745 | ||
746 | if (str_section->start == NULL) | |
747 | return (dwo ? _("<no .debug_str.dwo section>") | |
748 | : _("<no .debug_str section>")); | |
749 | ||
750 | str_offset = byte_get (index_section->start + index_offset, offset_size); | |
751 | str_offset -= str_section->address; | |
d949ff56 | 752 | if (str_offset >= str_section->size) |
4723351a CC |
753 | { |
754 | warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), | |
755 | dwarf_vmatoa ("x", str_offset)); | |
756 | return _("<indirect index offset is too big>"); | |
757 | } | |
758 | ||
d949ff56 NC |
759 | ret = (const char *) str_section->start + str_offset; |
760 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. | |
761 | Since our caller is expecting to receive a well formed C string we test | |
762 | for the lack of a terminating byte here. */ | |
763 | if (strnlen (ret, str_section->size - str_offset) | |
764 | == str_section->size - str_offset) | |
765 | ret = (const char *) _("<no NUL byte at end of section>"); | |
766 | ||
767 | return ret; | |
4723351a CC |
768 | } |
769 | ||
770 | static const char * | |
771 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
772 | { | |
773 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
774 | ||
775 | if (section->start == NULL) | |
776 | return (_("<no .debug_addr section>")); | |
777 | ||
778 | if (offset + bytes > section->size) | |
779 | { | |
780 | warn (_("Offset into section %s too big: %s\n"), | |
b4eb7656 | 781 | section->name, dwarf_vmatoa ("x", offset)); |
4723351a CC |
782 | return "<offset too big>"; |
783 | } | |
784 | ||
785 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
786 | } | |
787 | ||
788 | ||
19e6b90e L |
789 | /* FIXME: There are better and more efficient ways to handle |
790 | these structures. For now though, I just want something that | |
791 | is simple to implement. */ | |
792 | typedef struct abbrev_attr | |
793 | { | |
794 | unsigned long attribute; | |
795 | unsigned long form; | |
77145576 | 796 | bfd_signed_vma implicit_const; |
19e6b90e L |
797 | struct abbrev_attr *next; |
798 | } | |
799 | abbrev_attr; | |
800 | ||
801 | typedef struct abbrev_entry | |
802 | { | |
803 | unsigned long entry; | |
804 | unsigned long tag; | |
805 | int children; | |
806 | struct abbrev_attr *first_attr; | |
807 | struct abbrev_attr *last_attr; | |
808 | struct abbrev_entry *next; | |
809 | } | |
810 | abbrev_entry; | |
811 | ||
812 | static abbrev_entry *first_abbrev = NULL; | |
813 | static abbrev_entry *last_abbrev = NULL; | |
814 | ||
815 | static void | |
816 | free_abbrevs (void) | |
817 | { | |
91d6fa6a | 818 | abbrev_entry *abbrv; |
19e6b90e | 819 | |
91d6fa6a | 820 | for (abbrv = first_abbrev; abbrv;) |
19e6b90e | 821 | { |
91d6fa6a | 822 | abbrev_entry *next_abbrev = abbrv->next; |
19e6b90e L |
823 | abbrev_attr *attr; |
824 | ||
91d6fa6a | 825 | for (attr = abbrv->first_attr; attr;) |
19e6b90e | 826 | { |
91d6fa6a | 827 | abbrev_attr *next_attr = attr->next; |
19e6b90e L |
828 | |
829 | free (attr); | |
91d6fa6a | 830 | attr = next_attr; |
19e6b90e L |
831 | } |
832 | ||
91d6fa6a NC |
833 | free (abbrv); |
834 | abbrv = next_abbrev; | |
19e6b90e L |
835 | } |
836 | ||
837 | last_abbrev = first_abbrev = NULL; | |
838 | } | |
839 | ||
840 | static void | |
841 | add_abbrev (unsigned long number, unsigned long tag, int children) | |
842 | { | |
843 | abbrev_entry *entry; | |
844 | ||
3f5e193b | 845 | entry = (abbrev_entry *) malloc (sizeof (*entry)); |
19e6b90e L |
846 | if (entry == NULL) |
847 | /* ugg */ | |
848 | return; | |
849 | ||
850 | entry->entry = number; | |
851 | entry->tag = tag; | |
852 | entry->children = children; | |
853 | entry->first_attr = NULL; | |
854 | entry->last_attr = NULL; | |
855 | entry->next = NULL; | |
856 | ||
857 | if (first_abbrev == NULL) | |
858 | first_abbrev = entry; | |
859 | else | |
860 | last_abbrev->next = entry; | |
861 | ||
862 | last_abbrev = entry; | |
863 | } | |
864 | ||
865 | static void | |
77145576 JK |
866 | add_abbrev_attr (unsigned long attribute, unsigned long form, |
867 | bfd_signed_vma implicit_const) | |
19e6b90e L |
868 | { |
869 | abbrev_attr *attr; | |
870 | ||
3f5e193b | 871 | attr = (abbrev_attr *) malloc (sizeof (*attr)); |
19e6b90e L |
872 | if (attr == NULL) |
873 | /* ugg */ | |
874 | return; | |
875 | ||
876 | attr->attribute = attribute; | |
877 | attr->form = form; | |
77145576 | 878 | attr->implicit_const = implicit_const; |
19e6b90e L |
879 | attr->next = NULL; |
880 | ||
881 | if (last_abbrev->first_attr == NULL) | |
882 | last_abbrev->first_attr = attr; | |
883 | else | |
884 | last_abbrev->last_attr->next = attr; | |
885 | ||
886 | last_abbrev->last_attr = attr; | |
887 | } | |
888 | ||
889 | /* Processes the (partial) contents of a .debug_abbrev section. | |
890 | Returns NULL if the end of the section was encountered. | |
891 | Returns the address after the last byte read if the end of | |
892 | an abbreviation set was found. */ | |
893 | ||
894 | static unsigned char * | |
895 | process_abbrev_section (unsigned char *start, unsigned char *end) | |
896 | { | |
897 | if (first_abbrev != NULL) | |
898 | return NULL; | |
899 | ||
900 | while (start < end) | |
901 | { | |
19e6b90e L |
902 | unsigned long entry; |
903 | unsigned long tag; | |
904 | unsigned long attribute; | |
905 | int children; | |
906 | ||
cd30bcef | 907 | READ_ULEB (entry, start, end); |
19e6b90e L |
908 | |
909 | /* A single zero is supposed to end the section according | |
910 | to the standard. If there's more, then signal that to | |
911 | the caller. */ | |
f6f0e17b NC |
912 | if (start == end) |
913 | return NULL; | |
19e6b90e | 914 | if (entry == 0) |
f6f0e17b | 915 | return start; |
19e6b90e | 916 | |
cd30bcef | 917 | READ_ULEB (tag, start, end); |
f6f0e17b NC |
918 | if (start == end) |
919 | return NULL; | |
19e6b90e L |
920 | |
921 | children = *start++; | |
922 | ||
923 | add_abbrev (entry, tag, children); | |
924 | ||
925 | do | |
926 | { | |
927 | unsigned long form; | |
77145576 JK |
928 | /* Initialize it due to a false compiler warning. */ |
929 | bfd_signed_vma implicit_const = -1; | |
19e6b90e | 930 | |
cd30bcef | 931 | READ_ULEB (attribute, start, end); |
f6f0e17b NC |
932 | if (start == end) |
933 | break; | |
19e6b90e | 934 | |
cd30bcef | 935 | READ_ULEB (form, start, end); |
f6f0e17b NC |
936 | if (start == end) |
937 | break; | |
19e6b90e | 938 | |
77145576 JK |
939 | if (form == DW_FORM_implicit_const) |
940 | { | |
cd30bcef | 941 | READ_SLEB (implicit_const, start, end); |
77145576 JK |
942 | if (start == end) |
943 | break; | |
944 | } | |
945 | ||
946 | add_abbrev_attr (attribute, form, implicit_const); | |
19e6b90e L |
947 | } |
948 | while (attribute != 0); | |
949 | } | |
950 | ||
399c99f7 L |
951 | /* Report the missing single zero which ends the section. */ |
952 | error (_(".debug_abbrev section not zero terminated\n")); | |
953 | ||
19e6b90e L |
954 | return NULL; |
955 | } | |
956 | ||
a19c41a7 | 957 | static const char * |
19e6b90e L |
958 | get_TAG_name (unsigned long tag) |
959 | { | |
04914e37 | 960 | const char *name = get_DW_TAG_name ((unsigned int) tag); |
a19c41a7 TT |
961 | |
962 | if (name == NULL) | |
19e6b90e | 963 | { |
a19c41a7 | 964 | static char buffer[100]; |
19e6b90e | 965 | |
04914e37 NC |
966 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
967 | snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag); | |
968 | else | |
969 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag); | |
a19c41a7 | 970 | return buffer; |
19e6b90e | 971 | } |
a19c41a7 TT |
972 | |
973 | return name; | |
19e6b90e L |
974 | } |
975 | ||
a19c41a7 | 976 | static const char * |
19e6b90e L |
977 | get_FORM_name (unsigned long form) |
978 | { | |
399c99f7 | 979 | const char *name; |
bf5117e3 | 980 | |
399c99f7 L |
981 | if (form == 0) |
982 | return "DW_FORM value: 0"; | |
a19c41a7 | 983 | |
399c99f7 | 984 | name = get_DW_FORM_name (form); |
a19c41a7 | 985 | if (name == NULL) |
19e6b90e | 986 | { |
a19c41a7 | 987 | static char buffer[100]; |
19e6b90e | 988 | |
a19c41a7 TT |
989 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
990 | return buffer; | |
19e6b90e | 991 | } |
a19c41a7 TT |
992 | |
993 | return name; | |
19e6b90e L |
994 | } |
995 | ||
61364358 JK |
996 | static const char * |
997 | get_IDX_name (unsigned long idx) | |
998 | { | |
999 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
1000 | ||
1001 | if (name == NULL) | |
1002 | { | |
1003 | static char buffer[100]; | |
1004 | ||
1005 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1006 | return buffer; | |
1007 | } | |
1008 | ||
1009 | return name; | |
1010 | } | |
1011 | ||
19e6b90e | 1012 | static unsigned char * |
0c588247 NC |
1013 | display_block (unsigned char *data, |
1014 | dwarf_vma length, | |
ef0b5f1c | 1015 | const unsigned char * const end, char delimiter) |
19e6b90e | 1016 | { |
0c588247 NC |
1017 | dwarf_vma maxlen; |
1018 | ||
ef0b5f1c | 1019 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
1020 | if (data > end) |
1021 | return (unsigned char *) end; | |
19e6b90e | 1022 | |
0c588247 NC |
1023 | maxlen = (dwarf_vma) (end - data); |
1024 | length = length > maxlen ? maxlen : length; | |
1025 | ||
19e6b90e L |
1026 | while (length --) |
1027 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1028 | ||
1029 | return data; | |
1030 | } | |
1031 | ||
1032 | static int | |
1033 | decode_location_expression (unsigned char * data, | |
1034 | unsigned int pointer_size, | |
b7807392 JJ |
1035 | unsigned int offset_size, |
1036 | int dwarf_version, | |
467c65bc NC |
1037 | dwarf_vma length, |
1038 | dwarf_vma cu_offset, | |
f1c4cc75 | 1039 | struct dwarf_section * section) |
19e6b90e L |
1040 | { |
1041 | unsigned op; | |
467c65bc | 1042 | dwarf_vma uvalue; |
0c588247 | 1043 | dwarf_signed_vma svalue; |
19e6b90e L |
1044 | unsigned char *end = data + length; |
1045 | int need_frame_base = 0; | |
1046 | ||
1047 | while (data < end) | |
1048 | { | |
1049 | op = *data++; | |
1050 | ||
1051 | switch (op) | |
1052 | { | |
1053 | case DW_OP_addr: | |
0c588247 NC |
1054 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1055 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1056 | break; |
1057 | case DW_OP_deref: | |
1058 | printf ("DW_OP_deref"); | |
1059 | break; | |
1060 | case DW_OP_const1u: | |
0c588247 NC |
1061 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1062 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1063 | break; |
1064 | case DW_OP_const1s: | |
0c588247 NC |
1065 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1066 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1067 | break; |
1068 | case DW_OP_const2u: | |
87bc83b3 | 1069 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1070 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1071 | break; |
1072 | case DW_OP_const2s: | |
0c588247 NC |
1073 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1074 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1075 | break; |
1076 | case DW_OP_const4u: | |
0c588247 NC |
1077 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1078 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1079 | break; |
1080 | case DW_OP_const4s: | |
0c588247 NC |
1081 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1082 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1083 | break; |
1084 | case DW_OP_const8u: | |
0c588247 NC |
1085 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1086 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1087 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1088 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1089 | break; |
1090 | case DW_OP_const8s: | |
0c588247 NC |
1091 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1092 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1093 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1094 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1095 | break; |
1096 | case DW_OP_constu: | |
cd30bcef AM |
1097 | READ_ULEB (uvalue, data, end); |
1098 | printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1099 | break; |
1100 | case DW_OP_consts: | |
cd30bcef AM |
1101 | READ_SLEB (svalue, data, end); |
1102 | printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1103 | break; |
1104 | case DW_OP_dup: | |
1105 | printf ("DW_OP_dup"); | |
1106 | break; | |
1107 | case DW_OP_drop: | |
1108 | printf ("DW_OP_drop"); | |
1109 | break; | |
1110 | case DW_OP_over: | |
1111 | printf ("DW_OP_over"); | |
1112 | break; | |
1113 | case DW_OP_pick: | |
0c588247 NC |
1114 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1115 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1116 | break; |
1117 | case DW_OP_swap: | |
1118 | printf ("DW_OP_swap"); | |
1119 | break; | |
1120 | case DW_OP_rot: | |
1121 | printf ("DW_OP_rot"); | |
1122 | break; | |
1123 | case DW_OP_xderef: | |
1124 | printf ("DW_OP_xderef"); | |
1125 | break; | |
1126 | case DW_OP_abs: | |
1127 | printf ("DW_OP_abs"); | |
1128 | break; | |
1129 | case DW_OP_and: | |
1130 | printf ("DW_OP_and"); | |
1131 | break; | |
1132 | case DW_OP_div: | |
1133 | printf ("DW_OP_div"); | |
1134 | break; | |
1135 | case DW_OP_minus: | |
1136 | printf ("DW_OP_minus"); | |
1137 | break; | |
1138 | case DW_OP_mod: | |
1139 | printf ("DW_OP_mod"); | |
1140 | break; | |
1141 | case DW_OP_mul: | |
1142 | printf ("DW_OP_mul"); | |
1143 | break; | |
1144 | case DW_OP_neg: | |
1145 | printf ("DW_OP_neg"); | |
1146 | break; | |
1147 | case DW_OP_not: | |
1148 | printf ("DW_OP_not"); | |
1149 | break; | |
1150 | case DW_OP_or: | |
1151 | printf ("DW_OP_or"); | |
1152 | break; | |
1153 | case DW_OP_plus: | |
1154 | printf ("DW_OP_plus"); | |
1155 | break; | |
1156 | case DW_OP_plus_uconst: | |
cd30bcef AM |
1157 | READ_ULEB (uvalue, data, end); |
1158 | printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1159 | break; |
1160 | case DW_OP_shl: | |
1161 | printf ("DW_OP_shl"); | |
1162 | break; | |
1163 | case DW_OP_shr: | |
1164 | printf ("DW_OP_shr"); | |
1165 | break; | |
1166 | case DW_OP_shra: | |
1167 | printf ("DW_OP_shra"); | |
1168 | break; | |
1169 | case DW_OP_xor: | |
1170 | printf ("DW_OP_xor"); | |
1171 | break; | |
1172 | case DW_OP_bra: | |
0c588247 NC |
1173 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1174 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1175 | break; |
1176 | case DW_OP_eq: | |
1177 | printf ("DW_OP_eq"); | |
1178 | break; | |
1179 | case DW_OP_ge: | |
1180 | printf ("DW_OP_ge"); | |
1181 | break; | |
1182 | case DW_OP_gt: | |
1183 | printf ("DW_OP_gt"); | |
1184 | break; | |
1185 | case DW_OP_le: | |
1186 | printf ("DW_OP_le"); | |
1187 | break; | |
1188 | case DW_OP_lt: | |
1189 | printf ("DW_OP_lt"); | |
1190 | break; | |
1191 | case DW_OP_ne: | |
1192 | printf ("DW_OP_ne"); | |
1193 | break; | |
1194 | case DW_OP_skip: | |
0c588247 NC |
1195 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1196 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1197 | break; |
1198 | ||
1199 | case DW_OP_lit0: | |
1200 | case DW_OP_lit1: | |
1201 | case DW_OP_lit2: | |
1202 | case DW_OP_lit3: | |
1203 | case DW_OP_lit4: | |
1204 | case DW_OP_lit5: | |
1205 | case DW_OP_lit6: | |
1206 | case DW_OP_lit7: | |
1207 | case DW_OP_lit8: | |
1208 | case DW_OP_lit9: | |
1209 | case DW_OP_lit10: | |
1210 | case DW_OP_lit11: | |
1211 | case DW_OP_lit12: | |
1212 | case DW_OP_lit13: | |
1213 | case DW_OP_lit14: | |
1214 | case DW_OP_lit15: | |
1215 | case DW_OP_lit16: | |
1216 | case DW_OP_lit17: | |
1217 | case DW_OP_lit18: | |
1218 | case DW_OP_lit19: | |
1219 | case DW_OP_lit20: | |
1220 | case DW_OP_lit21: | |
1221 | case DW_OP_lit22: | |
1222 | case DW_OP_lit23: | |
1223 | case DW_OP_lit24: | |
1224 | case DW_OP_lit25: | |
1225 | case DW_OP_lit26: | |
1226 | case DW_OP_lit27: | |
1227 | case DW_OP_lit28: | |
1228 | case DW_OP_lit29: | |
1229 | case DW_OP_lit30: | |
1230 | case DW_OP_lit31: | |
1231 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1232 | break; | |
1233 | ||
1234 | case DW_OP_reg0: | |
1235 | case DW_OP_reg1: | |
1236 | case DW_OP_reg2: | |
1237 | case DW_OP_reg3: | |
1238 | case DW_OP_reg4: | |
1239 | case DW_OP_reg5: | |
1240 | case DW_OP_reg6: | |
1241 | case DW_OP_reg7: | |
1242 | case DW_OP_reg8: | |
1243 | case DW_OP_reg9: | |
1244 | case DW_OP_reg10: | |
1245 | case DW_OP_reg11: | |
1246 | case DW_OP_reg12: | |
1247 | case DW_OP_reg13: | |
1248 | case DW_OP_reg14: | |
1249 | case DW_OP_reg15: | |
1250 | case DW_OP_reg16: | |
1251 | case DW_OP_reg17: | |
1252 | case DW_OP_reg18: | |
1253 | case DW_OP_reg19: | |
1254 | case DW_OP_reg20: | |
1255 | case DW_OP_reg21: | |
1256 | case DW_OP_reg22: | |
1257 | case DW_OP_reg23: | |
1258 | case DW_OP_reg24: | |
1259 | case DW_OP_reg25: | |
1260 | case DW_OP_reg26: | |
1261 | case DW_OP_reg27: | |
1262 | case DW_OP_reg28: | |
1263 | case DW_OP_reg29: | |
1264 | case DW_OP_reg30: | |
1265 | case DW_OP_reg31: | |
18464d4d JK |
1266 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1267 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1268 | break; |
1269 | ||
1270 | case DW_OP_breg0: | |
1271 | case DW_OP_breg1: | |
1272 | case DW_OP_breg2: | |
1273 | case DW_OP_breg3: | |
1274 | case DW_OP_breg4: | |
1275 | case DW_OP_breg5: | |
1276 | case DW_OP_breg6: | |
1277 | case DW_OP_breg7: | |
1278 | case DW_OP_breg8: | |
1279 | case DW_OP_breg9: | |
1280 | case DW_OP_breg10: | |
1281 | case DW_OP_breg11: | |
1282 | case DW_OP_breg12: | |
1283 | case DW_OP_breg13: | |
1284 | case DW_OP_breg14: | |
1285 | case DW_OP_breg15: | |
1286 | case DW_OP_breg16: | |
1287 | case DW_OP_breg17: | |
1288 | case DW_OP_breg18: | |
1289 | case DW_OP_breg19: | |
1290 | case DW_OP_breg20: | |
1291 | case DW_OP_breg21: | |
1292 | case DW_OP_breg22: | |
1293 | case DW_OP_breg23: | |
1294 | case DW_OP_breg24: | |
1295 | case DW_OP_breg25: | |
1296 | case DW_OP_breg26: | |
1297 | case DW_OP_breg27: | |
1298 | case DW_OP_breg28: | |
1299 | case DW_OP_breg29: | |
1300 | case DW_OP_breg30: | |
1301 | case DW_OP_breg31: | |
cd30bcef AM |
1302 | READ_SLEB (svalue, data, end); |
1303 | printf ("DW_OP_breg%d (%s): %s", op - DW_OP_breg0, | |
1304 | regname (op - DW_OP_breg0, 1), dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1305 | break; |
1306 | ||
1307 | case DW_OP_regx: | |
cd30bcef | 1308 | READ_ULEB (uvalue, data, end); |
467c65bc NC |
1309 | printf ("DW_OP_regx: %s (%s)", |
1310 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1311 | break; |
1312 | case DW_OP_fbreg: | |
1313 | need_frame_base = 1; | |
cd30bcef AM |
1314 | READ_SLEB (svalue, data, end); |
1315 | printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1316 | break; |
1317 | case DW_OP_bregx: | |
cd30bcef AM |
1318 | READ_ULEB (uvalue, data, end); |
1319 | READ_SLEB (svalue, data, end); | |
467c65bc NC |
1320 | printf ("DW_OP_bregx: %s (%s) %s", |
1321 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
cd30bcef | 1322 | dwarf_vmatoa ("d", svalue)); |
19e6b90e L |
1323 | break; |
1324 | case DW_OP_piece: | |
cd30bcef AM |
1325 | READ_ULEB (uvalue, data, end); |
1326 | printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1327 | break; |
1328 | case DW_OP_deref_size: | |
0c588247 NC |
1329 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1330 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1331 | break; |
1332 | case DW_OP_xderef_size: | |
0c588247 NC |
1333 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1334 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1335 | break; |
1336 | case DW_OP_nop: | |
1337 | printf ("DW_OP_nop"); | |
1338 | break; | |
1339 | ||
1340 | /* DWARF 3 extensions. */ | |
1341 | case DW_OP_push_object_address: | |
1342 | printf ("DW_OP_push_object_address"); | |
1343 | break; | |
1344 | case DW_OP_call2: | |
d85bf2ba | 1345 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1346 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1347 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1348 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1349 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1350 | break; |
1351 | case DW_OP_call4: | |
d85bf2ba | 1352 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1353 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1354 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1355 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1356 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1357 | break; |
1358 | case DW_OP_call_ref: | |
d85bf2ba | 1359 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
e2a0d921 | 1360 | this ought to be an 8-byte wide computation. */ |
b7807392 JJ |
1361 | if (dwarf_version == -1) |
1362 | { | |
1363 | printf (_("(DW_OP_call_ref in frame info)")); | |
1364 | /* No way to tell where the next op is, so just bail. */ | |
1365 | return need_frame_base; | |
1366 | } | |
1367 | if (dwarf_version == 2) | |
1368 | { | |
0c588247 | 1369 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1370 | } |
1371 | else | |
1372 | { | |
0c588247 | 1373 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1374 | } |
0c588247 | 1375 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1376 | break; |
a87b0a59 NS |
1377 | case DW_OP_form_tls_address: |
1378 | printf ("DW_OP_form_tls_address"); | |
1379 | break; | |
e2a0d921 NC |
1380 | case DW_OP_call_frame_cfa: |
1381 | printf ("DW_OP_call_frame_cfa"); | |
1382 | break; | |
1383 | case DW_OP_bit_piece: | |
1384 | printf ("DW_OP_bit_piece: "); | |
cd30bcef AM |
1385 | READ_ULEB (uvalue, data, end); |
1386 | printf (_("size: %s "), dwarf_vmatoa ("u", uvalue)); | |
1387 | READ_ULEB (uvalue, data, end); | |
1388 | printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue)); | |
e2a0d921 | 1389 | break; |
19e6b90e | 1390 | |
3244e8f5 JJ |
1391 | /* DWARF 4 extensions. */ |
1392 | case DW_OP_stack_value: | |
1393 | printf ("DW_OP_stack_value"); | |
1394 | break; | |
1395 | ||
1396 | case DW_OP_implicit_value: | |
1397 | printf ("DW_OP_implicit_value"); | |
cd30bcef | 1398 | READ_ULEB (uvalue, data, end); |
ef0b5f1c | 1399 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1400 | break; |
1401 | ||
19e6b90e L |
1402 | /* GNU extensions. */ |
1403 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1404 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1405 | break; |
1406 | case DW_OP_GNU_uninit: | |
1407 | printf ("DW_OP_GNU_uninit"); | |
1408 | /* FIXME: Is there data associated with this OP ? */ | |
1409 | break; | |
f1c4cc75 RH |
1410 | case DW_OP_GNU_encoded_addr: |
1411 | { | |
6937bb54 | 1412 | int encoding = 0; |
f1c4cc75 | 1413 | dwarf_vma addr; |
467c65bc | 1414 | |
6937bb54 NC |
1415 | if (data < end) |
1416 | encoding = *data++; | |
041830e0 | 1417 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1418 | |
1419 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1420 | print_dwarf_vma (addr, pointer_size); | |
1421 | } | |
1422 | break; | |
bc0a77d2 | 1423 | case DW_OP_implicit_pointer: |
b7807392 | 1424 | case DW_OP_GNU_implicit_pointer: |
d85bf2ba | 1425 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
b7807392 JJ |
1426 | this ought to be an 8-byte wide computation. */ |
1427 | if (dwarf_version == -1) | |
1428 | { | |
bc0a77d2 JK |
1429 | printf (_("(%s in frame info)"), |
1430 | (op == DW_OP_implicit_pointer | |
1431 | ? "DW_OP_implicit_pointer" | |
1432 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1433 | /* No way to tell where the next op is, so just bail. */ |
1434 | return need_frame_base; | |
1435 | } | |
1436 | if (dwarf_version == 2) | |
1437 | { | |
0c588247 | 1438 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1439 | } |
1440 | else | |
1441 | { | |
0c588247 | 1442 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1443 | } |
cd30bcef | 1444 | READ_SLEB (svalue, data, end); |
bc0a77d2 JK |
1445 | printf ("%s: <0x%s> %s", |
1446 | (op == DW_OP_implicit_pointer | |
1447 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 | 1448 | dwarf_vmatoa ("x", uvalue), |
cd30bcef | 1449 | dwarf_vmatoa ("d", svalue)); |
b7807392 | 1450 | break; |
77145576 | 1451 | case DW_OP_entry_value: |
0892011d | 1452 | case DW_OP_GNU_entry_value: |
cd30bcef | 1453 | READ_ULEB (uvalue, data, end); |
058037d3 NC |
1454 | /* PR 17531: file: 0cc9cd00. */ |
1455 | if (uvalue > (dwarf_vma) (end - data)) | |
1456 | uvalue = end - data; | |
77145576 JK |
1457 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1458 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1459 | if (decode_location_expression (data, pointer_size, offset_size, |
1460 | dwarf_version, uvalue, | |
1461 | cu_offset, section)) | |
1462 | need_frame_base = 1; | |
1463 | putchar (')'); | |
1464 | data += uvalue; | |
6937bb54 NC |
1465 | if (data > end) |
1466 | data = end; | |
0892011d | 1467 | break; |
bc0a77d2 | 1468 | case DW_OP_const_type: |
0892011d | 1469 | case DW_OP_GNU_const_type: |
cd30bcef | 1470 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1471 | printf ("%s: <0x%s> ", |
1472 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1473 | : "DW_OP_GNU_const_type"), | |
0892011d | 1474 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1475 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1476 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1477 | break; |
bc0a77d2 | 1478 | case DW_OP_regval_type: |
0892011d | 1479 | case DW_OP_GNU_regval_type: |
cd30bcef | 1480 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1481 | printf ("%s: %s (%s)", |
1482 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1483 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1484 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
cd30bcef | 1485 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1486 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1487 | break; | |
bc0a77d2 | 1488 | case DW_OP_deref_type: |
0892011d | 1489 | case DW_OP_GNU_deref_type: |
0c588247 | 1490 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1491 | printf ("%s: %ld", |
1492 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1493 | : "DW_OP_GNU_deref_type"), | |
1494 | (long) uvalue); | |
cd30bcef | 1495 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1496 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1497 | break; | |
bc0a77d2 | 1498 | case DW_OP_convert: |
0892011d | 1499 | case DW_OP_GNU_convert: |
cd30bcef | 1500 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1501 | printf ("%s <0x%s>", |
1502 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1503 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1504 | break; |
bc0a77d2 | 1505 | case DW_OP_reinterpret: |
0892011d | 1506 | case DW_OP_GNU_reinterpret: |
cd30bcef | 1507 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1508 | printf ("%s <0x%s>", |
1509 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1510 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1511 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1512 | break; | |
1513 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1514 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1515 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1516 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1517 | break; |
b4eb7656 | 1518 | case DW_OP_GNU_addr_index: |
cd30bcef | 1519 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1520 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1521 | break; | |
1522 | case DW_OP_GNU_const_index: | |
cd30bcef | 1523 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1524 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1525 | break; | |
f384a1f0 KB |
1526 | case DW_OP_GNU_variable_value: |
1527 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1528 | this ought to be an 8-byte wide computation. */ | |
1529 | if (dwarf_version == -1) | |
1530 | { | |
1531 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1532 | /* No way to tell where the next op is, so just bail. */ | |
1533 | return need_frame_base; | |
1534 | } | |
1535 | if (dwarf_version == 2) | |
1536 | { | |
1537 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1538 | } | |
1539 | else | |
1540 | { | |
1541 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1542 | } | |
1543 | printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1544 | break; | |
e2a0d921 NC |
1545 | |
1546 | /* HP extensions. */ | |
1547 | case DW_OP_HP_is_value: | |
1548 | printf ("DW_OP_HP_is_value"); | |
1549 | /* FIXME: Is there data associated with this OP ? */ | |
1550 | break; | |
1551 | case DW_OP_HP_fltconst4: | |
1552 | printf ("DW_OP_HP_fltconst4"); | |
1553 | /* FIXME: Is there data associated with this OP ? */ | |
1554 | break; | |
1555 | case DW_OP_HP_fltconst8: | |
1556 | printf ("DW_OP_HP_fltconst8"); | |
1557 | /* FIXME: Is there data associated with this OP ? */ | |
1558 | break; | |
1559 | case DW_OP_HP_mod_range: | |
1560 | printf ("DW_OP_HP_mod_range"); | |
1561 | /* FIXME: Is there data associated with this OP ? */ | |
1562 | break; | |
1563 | case DW_OP_HP_unmod_range: | |
1564 | printf ("DW_OP_HP_unmod_range"); | |
1565 | /* FIXME: Is there data associated with this OP ? */ | |
1566 | break; | |
1567 | case DW_OP_HP_tls: | |
1568 | printf ("DW_OP_HP_tls"); | |
1569 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1570 | break; |
1571 | ||
35d60fe4 NC |
1572 | /* PGI (STMicroelectronics) extensions. */ |
1573 | case DW_OP_PGI_omp_thread_num: | |
1574 | /* Pushes the thread number for the current thread as it would be | |
1575 | returned by the standard OpenMP library function: | |
1576 | omp_get_thread_num(). The "current thread" is the thread for | |
1577 | which the expression is being evaluated. */ | |
1578 | printf ("DW_OP_PGI_omp_thread_num"); | |
1579 | break; | |
1580 | ||
19e6b90e L |
1581 | default: |
1582 | if (op >= DW_OP_lo_user | |
1583 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1584 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1585 | else |
0502a2b4 | 1586 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1587 | /* No way to tell where the next op is, so just bail. */ |
1588 | return need_frame_base; | |
1589 | } | |
1590 | ||
1591 | /* Separate the ops. */ | |
1592 | if (data < end) | |
1593 | printf ("; "); | |
1594 | } | |
1595 | ||
1596 | return need_frame_base; | |
1597 | } | |
1598 | ||
341f9135 CC |
1599 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1600 | This is used for DWARF package files. */ | |
1601 | ||
1602 | static struct cu_tu_set * | |
1603 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1604 | { | |
1605 | struct cu_tu_set *p; | |
1606 | unsigned int nsets; | |
1607 | unsigned int dw_sect; | |
1608 | ||
1609 | if (do_types) | |
1610 | { | |
1611 | p = tu_sets; | |
1612 | nsets = tu_count; | |
1613 | dw_sect = DW_SECT_TYPES; | |
1614 | } | |
1615 | else | |
1616 | { | |
1617 | p = cu_sets; | |
1618 | nsets = cu_count; | |
1619 | dw_sect = DW_SECT_INFO; | |
1620 | } | |
1621 | while (nsets > 0) | |
1622 | { | |
1623 | if (p->section_offsets [dw_sect] == cu_offset) | |
1624 | return p; | |
1625 | p++; | |
1626 | nsets--; | |
1627 | } | |
1628 | return NULL; | |
1629 | } | |
1630 | ||
a69c4772 NC |
1631 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1632 | static void | |
1633 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1634 | { | |
1635 | dwarf_vma tmp = * low_bits; | |
1636 | ||
1637 | tmp += inc; | |
1638 | ||
1639 | /* FIXME: There is probably a better way of handling this: | |
1640 | ||
1641 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1642 | type. Plus regardless of its size LOW_BITS is meant to | |
1643 | only hold 32-bits, so if there is overflow or wrap around | |
1644 | we must propagate into HIGH_BITS. */ | |
1645 | if (tmp < * low_bits) | |
1646 | { | |
1647 | ++ * high_bits; | |
1648 | } | |
1649 | else if (sizeof (tmp) > 8 | |
1650 | && (tmp >> 31) > 1) | |
1651 | { | |
1652 | ++ * high_bits; | |
1653 | tmp &= 0xFFFFFFFF; | |
1654 | } | |
1655 | ||
1656 | * low_bits = tmp; | |
1657 | } | |
1658 | ||
dda8d76d NC |
1659 | static const char * |
1660 | fetch_alt_indirect_string (dwarf_vma offset) | |
1661 | { | |
24841daa | 1662 | separate_info * i; |
dda8d76d NC |
1663 | |
1664 | if (! do_follow_links) | |
1665 | return ""; | |
1666 | ||
24841daa NC |
1667 | if (first_separate_info == NULL) |
1668 | return _("<no links available>"); | |
dda8d76d | 1669 | |
24841daa NC |
1670 | for (i = first_separate_info; i != NULL; i = i->next) |
1671 | { | |
1672 | struct dwarf_section * section; | |
1673 | const char * ret; | |
dda8d76d | 1674 | |
24841daa NC |
1675 | if (! load_debug_section (separate_debug_str, i->handle)) |
1676 | continue; | |
dda8d76d | 1677 | |
24841daa | 1678 | section = &debug_displays [separate_debug_str].section; |
dda8d76d | 1679 | |
24841daa NC |
1680 | if (section->start == NULL) |
1681 | continue; | |
dda8d76d | 1682 | |
24841daa NC |
1683 | if (offset >= section->size) |
1684 | continue; | |
1685 | ||
1686 | ret = (const char *) (section->start + offset); | |
1687 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1688 | NUL byte. Since our caller is expecting to receive a well formed C | |
1689 | string we test for the lack of a terminating byte here. */ | |
1690 | if (strnlen ((const char *) ret, section->size - offset) | |
1691 | == section->size - offset) | |
1692 | return _("<no NUL byte at end of alt .debug_str section>"); | |
1693 | ||
1694 | return ret; | |
1695 | } | |
1696 | ||
1697 | warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"), | |
1698 | dwarf_vmatoa ("x", offset)); | |
1699 | return _("<offset is too big>"); | |
dda8d76d NC |
1700 | } |
1701 | ||
d85bf2ba NC |
1702 | static const char * |
1703 | get_AT_name (unsigned long attribute) | |
1704 | { | |
1705 | const char *name; | |
1706 | ||
1707 | if (attribute == 0) | |
1708 | return "DW_AT value: 0"; | |
1709 | ||
1710 | /* One value is shared by the MIPS and HP extensions: */ | |
1711 | if (attribute == DW_AT_MIPS_fde) | |
1712 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1713 | ||
1714 | name = get_DW_AT_name (attribute); | |
1715 | ||
1716 | if (name == NULL) | |
1717 | { | |
1718 | static char buffer[100]; | |
1719 | ||
1720 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1721 | attribute); | |
1722 | return buffer; | |
1723 | } | |
1724 | ||
1725 | return name; | |
1726 | } | |
1727 | ||
24841daa NC |
1728 | static void |
1729 | add_dwo_info (const char * field, dwo_type type) | |
1730 | { | |
1731 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); | |
1732 | ||
1733 | dwinfo->type = type; | |
1734 | dwinfo->value = field; | |
1735 | dwinfo->next = first_dwo_info; | |
1736 | first_dwo_info = dwinfo; | |
1737 | } | |
1738 | ||
1739 | static void | |
1740 | add_dwo_name (const char * name) | |
1741 | { | |
1742 | add_dwo_info (name, DWO_NAME); | |
1743 | } | |
1744 | ||
1745 | static void | |
1746 | add_dwo_dir (const char * dir) | |
1747 | { | |
1748 | add_dwo_info (dir, DWO_DIR); | |
1749 | } | |
1750 | ||
1751 | static void | |
1752 | add_dwo_id (const char * id) | |
1753 | { | |
1754 | add_dwo_info (id, DWO_ID); | |
1755 | } | |
1756 | ||
1757 | static void | |
1758 | free_dwo_info (void) | |
1759 | { | |
1760 | dwo_info * dwinfo; | |
1761 | dwo_info * next; | |
1762 | ||
1763 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) | |
1764 | { | |
1765 | next = dwinfo->next; | |
1766 | free (dwinfo); | |
1767 | } | |
1768 | first_dwo_info = NULL; | |
1769 | } | |
1770 | ||
afc72f15 NC |
1771 | /* Ensure that START + UVALUE is less than END. |
1772 | Return an adjusted UVALUE if necessary to ensure this relationship. */ | |
1773 | ||
1774 | static inline dwarf_vma | |
1775 | check_uvalue (const unsigned char * start, | |
1776 | dwarf_vma uvalue, | |
1777 | const unsigned char * end) | |
1778 | { | |
1779 | dwarf_vma max_uvalue = end - start; | |
1780 | ||
afc72f15 NC |
1781 | /* See PR 17512: file: 008-103549-0.001:0.1. |
1782 | and PR 24829 for examples of where these tests are triggered. */ | |
a85eba51 | 1783 | if (uvalue > max_uvalue) |
afc72f15 NC |
1784 | { |
1785 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1786 | uvalue = max_uvalue; | |
1787 | } | |
1788 | ||
1789 | return uvalue; | |
1790 | } | |
1791 | ||
ec1b0fbb NC |
1792 | static unsigned char * |
1793 | skip_attr_bytes (unsigned long form, | |
1794 | unsigned char * data, | |
1795 | unsigned const char * end, | |
1796 | dwarf_vma pointer_size, | |
1797 | dwarf_vma offset_size, | |
1798 | int dwarf_version, | |
1799 | dwarf_vma * value_return) | |
1800 | { | |
cd30bcef AM |
1801 | dwarf_signed_vma svalue; |
1802 | dwarf_vma uvalue = 0; | |
ec1b0fbb NC |
1803 | |
1804 | * value_return = 0; | |
1805 | ||
1806 | switch (form) | |
1807 | { | |
1808 | case DW_FORM_ref_addr: | |
1809 | if (dwarf_version == 2) | |
1810 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1811 | else if (dwarf_version == 3 || dwarf_version == 4) | |
1812 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1813 | else | |
1814 | return NULL; | |
1815 | break; | |
1816 | ||
1817 | case DW_FORM_addr: | |
1818 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1819 | break; | |
1820 | ||
1821 | case DW_FORM_strp: | |
1822 | case DW_FORM_line_strp: | |
1823 | case DW_FORM_sec_offset: | |
1824 | case DW_FORM_GNU_ref_alt: | |
1825 | case DW_FORM_GNU_strp_alt: | |
1826 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1827 | break; | |
1828 | ||
1829 | case DW_FORM_flag_present: | |
1830 | uvalue = 1; | |
1831 | break; | |
1832 | ||
1833 | case DW_FORM_ref1: | |
1834 | case DW_FORM_flag: | |
1835 | case DW_FORM_data1: | |
1836 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
1837 | break; | |
1838 | ||
1839 | case DW_FORM_ref2: | |
1840 | case DW_FORM_data2: | |
1841 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); | |
1842 | break; | |
1843 | ||
1844 | case DW_FORM_ref4: | |
1845 | case DW_FORM_data4: | |
1846 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1847 | break; | |
1848 | ||
1849 | case DW_FORM_sdata: | |
cd30bcef AM |
1850 | READ_SLEB (svalue, data, end); |
1851 | uvalue = svalue; | |
ec1b0fbb NC |
1852 | break; |
1853 | ||
1854 | case DW_FORM_ref_udata: | |
1855 | case DW_FORM_udata: | |
1856 | case DW_FORM_GNU_str_index: | |
1857 | case DW_FORM_GNU_addr_index: | |
cd30bcef | 1858 | READ_ULEB (uvalue, data, end); |
ec1b0fbb NC |
1859 | break; |
1860 | ||
1861 | case DW_FORM_ref8: | |
1862 | case DW_FORM_data8: | |
1863 | data += 8; | |
1864 | break; | |
1865 | ||
1866 | case DW_FORM_data16: | |
1867 | data += 16; | |
1868 | break; | |
1869 | ||
1870 | case DW_FORM_string: | |
1871 | data += strnlen ((char *) data, end - data) + 1; | |
1872 | break; | |
1873 | ||
1874 | case DW_FORM_block: | |
1875 | case DW_FORM_exprloc: | |
cd30bcef | 1876 | READ_ULEB (uvalue, data, end); |
ec1b0fbb NC |
1877 | break; |
1878 | ||
1879 | case DW_FORM_block1: | |
1880 | SAFE_BYTE_GET (uvalue, data, 1, end); | |
1881 | data += 1 + uvalue; | |
1882 | break; | |
1883 | ||
1884 | case DW_FORM_block2: | |
1885 | SAFE_BYTE_GET (uvalue, data, 2, end); | |
1886 | data += 2 + uvalue; | |
1887 | break; | |
1888 | ||
1889 | case DW_FORM_block4: | |
1890 | SAFE_BYTE_GET (uvalue, data, 4, end); | |
1891 | data += 4 + uvalue; | |
1892 | break; | |
1893 | ||
1894 | case DW_FORM_ref_sig8: | |
1895 | data += 8; | |
1896 | break; | |
1897 | ||
1898 | case DW_FORM_indirect: | |
1899 | /* FIXME: Handle this form. */ | |
1900 | default: | |
1901 | return NULL; | |
1902 | } | |
1903 | ||
1904 | * value_return = uvalue; | |
1905 | if (data > end) | |
1906 | data = (unsigned char *) end; | |
1907 | return data; | |
1908 | } | |
1909 | ||
1910 | /* Return IS_SIGNED set to TRUE if the type at | |
1911 | DATA can be determined to be a signed type. */ | |
1912 | ||
1913 | static void | |
1914 | get_type_signedness (unsigned char * start, | |
1915 | unsigned char * data, | |
1916 | unsigned const char * end, | |
1917 | dwarf_vma pointer_size, | |
1918 | dwarf_vma offset_size, | |
1919 | int dwarf_version, | |
1920 | bfd_boolean * is_signed, | |
1921 | bfd_boolean is_nested) | |
1922 | { | |
1923 | unsigned long abbrev_number; | |
ec1b0fbb NC |
1924 | abbrev_entry * entry; |
1925 | abbrev_attr * attr; | |
1926 | ||
1927 | * is_signed = FALSE; | |
1928 | ||
cd30bcef | 1929 | READ_ULEB (abbrev_number, data, end); |
ec1b0fbb NC |
1930 | |
1931 | for (entry = first_abbrev; | |
1932 | entry != NULL && entry->entry != abbrev_number; | |
1933 | entry = entry->next) | |
1934 | continue; | |
1935 | ||
1936 | if (entry == NULL) | |
1937 | /* FIXME: Issue a warning ? */ | |
1938 | return; | |
1939 | ||
1940 | for (attr = entry->first_attr; | |
1941 | attr != NULL && attr->attribute; | |
1942 | attr = attr->next) | |
1943 | { | |
1944 | dwarf_vma uvalue = 0; | |
1945 | ||
1946 | data = skip_attr_bytes (attr->form, data, end, pointer_size, | |
1947 | offset_size, dwarf_version, & uvalue); | |
1948 | if (data == NULL) | |
1949 | return; | |
1950 | ||
1951 | switch (attr->attribute) | |
1952 | { | |
1953 | #if 0 /* FIXME: It would be nice to print the name of the type, | |
1954 | but this would mean updating a lot of binutils tests. */ | |
1955 | case DW_AT_name: | |
1956 | if (attr->form == DW_FORM_strp) | |
1957 | printf ("%s", fetch_indirect_string (uvalue)); | |
1958 | break; | |
1959 | #endif | |
1960 | case DW_AT_type: | |
1961 | /* Recurse. */ | |
1962 | if (is_nested) | |
1963 | { | |
1964 | /* FIXME: Warn - or is this expected ? | |
1965 | NB/ We need to avoid infinite recursion. */ | |
1966 | return; | |
1967 | } | |
b3fe587e AM |
1968 | if (uvalue >= (size_t) (end - start)) |
1969 | return; | |
ec1b0fbb NC |
1970 | get_type_signedness (start, start + uvalue, end, pointer_size, |
1971 | offset_size, dwarf_version, is_signed, TRUE); | |
1972 | break; | |
1973 | ||
1974 | case DW_AT_encoding: | |
1975 | /* Determine signness. */ | |
1976 | switch (uvalue) | |
1977 | { | |
1978 | case DW_ATE_address: | |
1979 | /* FIXME - some architectures have signed addresses. */ | |
1980 | case DW_ATE_boolean: | |
1981 | case DW_ATE_unsigned: | |
1982 | case DW_ATE_unsigned_char: | |
1983 | case DW_ATE_unsigned_fixed: | |
1984 | * is_signed = FALSE; | |
1985 | break; | |
1986 | ||
1987 | default: | |
1988 | case DW_ATE_complex_float: | |
1989 | case DW_ATE_float: | |
1990 | case DW_ATE_signed: | |
1991 | case DW_ATE_signed_char: | |
1992 | case DW_ATE_imaginary_float: | |
1993 | case DW_ATE_decimal_float: | |
1994 | case DW_ATE_signed_fixed: | |
1995 | * is_signed = TRUE; | |
1996 | break; | |
1997 | } | |
1998 | break; | |
1999 | } | |
2000 | } | |
2001 | } | |
2002 | ||
2003 | static void | |
2004 | read_and_print_leb128 (unsigned char * data, | |
2005 | unsigned int * bytes_read, | |
2006 | unsigned const char * end, | |
2007 | bfd_boolean is_signed) | |
2008 | { | |
cd30bcef AM |
2009 | int status; |
2010 | dwarf_vma val = read_leb128 (data, end, is_signed, bytes_read, &status); | |
2011 | if (status != 0) | |
1b513401 | 2012 | report_leb_status (status, __FILE__, __LINE__); |
ec1b0fbb | 2013 | else |
cd30bcef | 2014 | printf ("%s", dwarf_vmatoa (is_signed ? "d" : "u", val)); |
ec1b0fbb NC |
2015 | } |
2016 | ||
2017 | static void | |
2018 | display_discr_list (unsigned long form, | |
2019 | dwarf_vma uvalue, | |
2020 | unsigned char * data, | |
2021 | unsigned const char * end, | |
2022 | int level) | |
2023 | { | |
2024 | if (uvalue == 0) | |
2025 | { | |
2026 | printf ("[default]"); | |
2027 | return; | |
2028 | } | |
2029 | ||
2030 | switch (form) | |
2031 | { | |
2032 | case DW_FORM_block: | |
2033 | case DW_FORM_block1: | |
2034 | case DW_FORM_block2: | |
2035 | case DW_FORM_block4: | |
2036 | /* Move data pointer back to the start of the byte array. */ | |
2037 | data -= uvalue; | |
2038 | break; | |
2039 | default: | |
2040 | printf ("<corrupt>\n"); | |
2041 | warn (_("corrupt discr_list - not using a block form\n")); | |
2042 | return; | |
2043 | } | |
2044 | ||
2045 | if (uvalue < 2) | |
2046 | { | |
2047 | printf ("<corrupt>\n"); | |
2048 | warn (_("corrupt discr_list - block not long enough\n")); | |
2049 | return; | |
2050 | } | |
2051 | ||
2052 | bfd_boolean is_signed = | |
2053 | (level > 0 && level <= MAX_CU_NESTING) | |
2054 | ? level_type_signed [level - 1] : FALSE; | |
2055 | ||
2056 | printf ("("); | |
2057 | while (uvalue) | |
2058 | { | |
2059 | unsigned char discriminant; | |
2060 | unsigned int bytes_read; | |
2061 | ||
2062 | SAFE_BYTE_GET (discriminant, data, 1, end); | |
2063 | -- uvalue; | |
2064 | data ++; | |
2065 | ||
2066 | assert (uvalue > 0); | |
2067 | switch (discriminant) | |
2068 | { | |
2069 | case DW_DSC_label: | |
2070 | printf ("label "); | |
2071 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2072 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2073 | uvalue -= bytes_read; | |
2074 | data += bytes_read; | |
2075 | break; | |
2076 | ||
2077 | case DW_DSC_range: | |
2078 | printf ("range "); | |
2079 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2080 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2081 | uvalue -= bytes_read; | |
2082 | data += bytes_read; | |
2083 | ||
2084 | printf (".."); | |
2085 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2086 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2087 | uvalue -= bytes_read; | |
2088 | data += bytes_read; | |
2089 | break; | |
2090 | ||
2091 | default: | |
2092 | printf ("<corrupt>\n"); | |
2093 | warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"), | |
2094 | discriminant); | |
2095 | return; | |
2096 | } | |
2097 | ||
2098 | if (uvalue) | |
2099 | printf (", "); | |
2100 | } | |
2101 | ||
2102 | if (is_signed) | |
2103 | printf (")(signed)"); | |
2104 | else | |
2105 | printf (")(unsigned)"); | |
2106 | } | |
2107 | ||
19e6b90e | 2108 | static unsigned char * |
dda8d76d NC |
2109 | read_and_display_attr_value (unsigned long attribute, |
2110 | unsigned long form, | |
2111 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 2112 | unsigned char * start, |
dda8d76d NC |
2113 | unsigned char * data, |
2114 | unsigned char * end, | |
2115 | dwarf_vma cu_offset, | |
2116 | dwarf_vma pointer_size, | |
2117 | dwarf_vma offset_size, | |
2118 | int dwarf_version, | |
2119 | debug_info * debug_info_p, | |
2120 | int do_loc, | |
2121 | struct dwarf_section * section, | |
2122 | struct cu_tu_set * this_set, | |
ec1b0fbb NC |
2123 | char delimiter, |
2124 | int level) | |
19e6b90e | 2125 | { |
cd30bcef | 2126 | dwarf_signed_vma svalue; |
ec1b0fbb NC |
2127 | dwarf_vma uvalue = 0; |
2128 | unsigned char * block_start = NULL; | |
2129 | unsigned char * orig_data = data; | |
19e6b90e | 2130 | |
f41e4712 | 2131 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 2132 | { |
f41e4712 | 2133 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
2134 | return data; |
2135 | } | |
2136 | ||
19e6b90e L |
2137 | switch (form) |
2138 | { | |
2139 | default: | |
2140 | break; | |
2141 | ||
2142 | case DW_FORM_ref_addr: | |
2143 | if (dwarf_version == 2) | |
0c588247 | 2144 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
932fd279 | 2145 | else if (dwarf_version == 3 || dwarf_version == 4) |
0c588247 | 2146 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 2147 | else |
467c65bc NC |
2148 | error (_("Internal error: DWARF version is not 2, 3 or 4.\n")); |
2149 | ||
19e6b90e L |
2150 | break; |
2151 | ||
2152 | case DW_FORM_addr: | |
0c588247 | 2153 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
2154 | break; |
2155 | ||
2156 | case DW_FORM_strp: | |
77145576 | 2157 | case DW_FORM_line_strp: |
932fd279 | 2158 | case DW_FORM_sec_offset: |
a081f3cd JJ |
2159 | case DW_FORM_GNU_ref_alt: |
2160 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 2161 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
2162 | break; |
2163 | ||
932fd279 JJ |
2164 | case DW_FORM_flag_present: |
2165 | uvalue = 1; | |
2166 | break; | |
2167 | ||
19e6b90e L |
2168 | case DW_FORM_ref1: |
2169 | case DW_FORM_flag: | |
2170 | case DW_FORM_data1: | |
0c588247 | 2171 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
2172 | break; |
2173 | ||
2174 | case DW_FORM_ref2: | |
2175 | case DW_FORM_data2: | |
0c588247 | 2176 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
2177 | break; |
2178 | ||
2179 | case DW_FORM_ref4: | |
2180 | case DW_FORM_data4: | |
0c588247 | 2181 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
2182 | break; |
2183 | ||
2184 | case DW_FORM_sdata: | |
cd30bcef AM |
2185 | READ_SLEB (svalue, data, end); |
2186 | uvalue = svalue; | |
19e6b90e L |
2187 | break; |
2188 | ||
4723351a | 2189 | case DW_FORM_GNU_str_index: |
19e6b90e L |
2190 | case DW_FORM_ref_udata: |
2191 | case DW_FORM_udata: | |
cd30bcef AM |
2192 | case DW_FORM_GNU_addr_index: |
2193 | READ_ULEB (uvalue, data, end); | |
19e6b90e L |
2194 | break; |
2195 | ||
2196 | case DW_FORM_indirect: | |
cd30bcef | 2197 | READ_ULEB (form, data, end); |
19e6b90e | 2198 | if (!do_loc) |
ef0b5f1c | 2199 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 | 2200 | if (form == DW_FORM_implicit_const) |
cd30bcef | 2201 | READ_SLEB (implicit_const, data, end); |
ec1b0fbb NC |
2202 | return read_and_display_attr_value (attribute, form, implicit_const, |
2203 | start, data, end, | |
2204 | cu_offset, pointer_size, | |
19e6b90e | 2205 | offset_size, dwarf_version, |
ec4d4525 | 2206 | debug_info_p, do_loc, |
ec1b0fbb | 2207 | section, this_set, delimiter, level); |
19e6b90e L |
2208 | } |
2209 | ||
2210 | switch (form) | |
2211 | { | |
2212 | case DW_FORM_ref_addr: | |
2213 | if (!do_loc) | |
ef0b5f1c | 2214 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
19e6b90e L |
2215 | break; |
2216 | ||
a081f3cd JJ |
2217 | case DW_FORM_GNU_ref_alt: |
2218 | if (!do_loc) | |
ef0b5f1c | 2219 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
dda8d76d | 2220 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
2221 | break; |
2222 | ||
19e6b90e L |
2223 | case DW_FORM_ref1: |
2224 | case DW_FORM_ref2: | |
2225 | case DW_FORM_ref4: | |
2226 | case DW_FORM_ref_udata: | |
2227 | if (!do_loc) | |
ef0b5f1c | 2228 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
2229 | break; |
2230 | ||
2231 | case DW_FORM_data4: | |
2232 | case DW_FORM_addr: | |
932fd279 | 2233 | case DW_FORM_sec_offset: |
19e6b90e | 2234 | if (!do_loc) |
ef0b5f1c | 2235 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2236 | break; |
2237 | ||
932fd279 | 2238 | case DW_FORM_flag_present: |
19e6b90e L |
2239 | case DW_FORM_flag: |
2240 | case DW_FORM_data1: | |
2241 | case DW_FORM_data2: | |
2242 | case DW_FORM_sdata: | |
2243 | case DW_FORM_udata: | |
2244 | if (!do_loc) | |
ef0b5f1c | 2245 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
2246 | break; |
2247 | ||
77145576 JK |
2248 | case DW_FORM_implicit_const: |
2249 | if (!do_loc) | |
2250 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
2251 | break; | |
2252 | ||
19e6b90e L |
2253 | case DW_FORM_ref8: |
2254 | case DW_FORM_data8: | |
2bc8690c | 2255 | if (!do_loc) |
19e6b90e | 2256 | { |
74bc6052 | 2257 | dwarf_vma high_bits; |
a69c4772 | 2258 | dwarf_vma utmp; |
74bc6052 CC |
2259 | char buf[64]; |
2260 | ||
0c588247 | 2261 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
2262 | utmp = uvalue; |
2263 | if (form == DW_FORM_ref8) | |
2264 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 2265 | printf ("%c0x%s", delimiter, |
a69c4772 | 2266 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 2267 | } |
0c588247 | 2268 | |
19e6b90e L |
2269 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2270 | && num_debug_info_entries == 0) | |
2271 | { | |
2272 | if (sizeof (uvalue) == 8) | |
0c588247 | 2273 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 2274 | else |
467c65bc | 2275 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 2276 | } |
0c588247 | 2277 | |
19e6b90e L |
2278 | data += 8; |
2279 | break; | |
2280 | ||
2f6cd591 JK |
2281 | case DW_FORM_data16: |
2282 | if (!do_loc) | |
2283 | { | |
2284 | dwarf_vma left_high_bits, left_low_bits; | |
2285 | dwarf_vma right_high_bits, right_low_bits; | |
2286 | ||
2287 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
2288 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
2289 | if (byte_get == byte_get_little_endian) | |
2290 | { | |
2291 | /* Swap them. */ | |
2292 | left_high_bits ^= right_high_bits; | |
2293 | right_high_bits ^= left_high_bits; | |
2294 | left_high_bits ^= right_high_bits; | |
2295 | left_low_bits ^= right_low_bits; | |
2296 | right_low_bits ^= left_low_bits; | |
2297 | left_low_bits ^= right_low_bits; | |
2298 | } | |
2299 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
2300 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
2301 | left_high_bits, left_low_bits, right_high_bits, | |
2302 | right_low_bits); | |
2303 | } | |
2304 | data += 16; | |
2305 | break; | |
2306 | ||
19e6b90e L |
2307 | case DW_FORM_string: |
2308 | if (!do_loc) | |
ef0b5f1c | 2309 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 2310 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
2311 | break; |
2312 | ||
2313 | case DW_FORM_block: | |
932fd279 | 2314 | case DW_FORM_exprloc: |
cd30bcef AM |
2315 | READ_ULEB (uvalue, data, end); |
2316 | do_block: | |
2317 | block_start = data; | |
a1165289 NC |
2318 | if (block_start >= end) |
2319 | { | |
2320 | warn (_("Block ends prematurely\n")); | |
2321 | uvalue = 0; | |
2322 | block_start = end; | |
2323 | } | |
afc72f15 NC |
2324 | |
2325 | uvalue = check_uvalue (block_start, uvalue, end); | |
2326 | ||
19e6b90e L |
2327 | if (do_loc) |
2328 | data = block_start + uvalue; | |
2329 | else | |
ef0b5f1c | 2330 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2331 | break; |
2332 | ||
2333 | case DW_FORM_block1: | |
cd30bcef AM |
2334 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2335 | goto do_block; | |
19e6b90e L |
2336 | |
2337 | case DW_FORM_block2: | |
cd30bcef AM |
2338 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2339 | goto do_block; | |
19e6b90e L |
2340 | |
2341 | case DW_FORM_block4: | |
cd30bcef AM |
2342 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2343 | goto do_block; | |
19e6b90e L |
2344 | |
2345 | case DW_FORM_strp: | |
2346 | if (!do_loc) | |
ef0b5f1c | 2347 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, |
47704ddf KT |
2348 | dwarf_vmatoa ("x", uvalue), |
2349 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
2350 | break; |
2351 | ||
77145576 JK |
2352 | case DW_FORM_line_strp: |
2353 | if (!do_loc) | |
2354 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2355 | dwarf_vmatoa ("x", uvalue), | |
2356 | fetch_indirect_line_string (uvalue)); | |
2357 | break; | |
2358 | ||
4723351a CC |
2359 | case DW_FORM_GNU_str_index: |
2360 | if (!do_loc) | |
b4eb7656 | 2361 | { |
d85bf2ba NC |
2362 | const char * suffix = strrchr (section->name, '.'); |
2363 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
b4eb7656 | 2364 | |
ef0b5f1c | 2365 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2366 | dwarf_vmatoa ("x", uvalue), |
2367 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2368 | } | |
4723351a CC |
2369 | break; |
2370 | ||
a081f3cd JJ |
2371 | case DW_FORM_GNU_strp_alt: |
2372 | if (!do_loc) | |
dda8d76d NC |
2373 | { |
2374 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2375 | dwarf_vmatoa ("x", uvalue), | |
2376 | fetch_alt_indirect_string (uvalue)); | |
2377 | } | |
a081f3cd JJ |
2378 | break; |
2379 | ||
19e6b90e L |
2380 | case DW_FORM_indirect: |
2381 | /* Handled above. */ | |
2382 | break; | |
2383 | ||
2b6f5997 CC |
2384 | case DW_FORM_ref_sig8: |
2385 | if (!do_loc) | |
2386 | { | |
74bc6052 CC |
2387 | dwarf_vma high_bits; |
2388 | char buf[64]; | |
2389 | ||
0c588247 | 2390 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
ef0b5f1c | 2391 | printf ("%csignature: 0x%s", delimiter, |
74bc6052 | 2392 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); |
2b6f5997 | 2393 | } |
74bc6052 | 2394 | data += 8; |
2b6f5997 CC |
2395 | break; |
2396 | ||
4723351a CC |
2397 | case DW_FORM_GNU_addr_index: |
2398 | if (!do_loc) | |
ef0b5f1c | 2399 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2400 | dwarf_vmatoa ("x", uvalue), |
2401 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
4723351a CC |
2402 | break; |
2403 | ||
19e6b90e L |
2404 | default: |
2405 | warn (_("Unrecognized form: %lu\n"), form); | |
2406 | break; | |
2407 | } | |
2408 | ||
19e6b90e | 2409 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2410 | && num_debug_info_entries == 0 |
2411 | && debug_info_p != NULL) | |
19e6b90e L |
2412 | { |
2413 | switch (attribute) | |
2414 | { | |
2415 | case DW_AT_frame_base: | |
2416 | have_frame_base = 1; | |
1a0670f3 | 2417 | /* Fall through. */ |
19e6b90e | 2418 | case DW_AT_location: |
9f272209 | 2419 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2420 | case DW_AT_string_length: |
2421 | case DW_AT_return_addr: | |
19e6b90e L |
2422 | case DW_AT_data_member_location: |
2423 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2424 | case DW_AT_segment: |
2425 | case DW_AT_static_link: | |
2426 | case DW_AT_use_location: | |
bc0a77d2 | 2427 | case DW_AT_call_value: |
629e7ca8 | 2428 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2429 | case DW_AT_call_data_value: |
629e7ca8 | 2430 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2431 | case DW_AT_call_target: |
629e7ca8 | 2432 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2433 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2434 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2435 | if ((dwarf_version < 4 |
212b6063 | 2436 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2437 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2438 | { |
2439 | /* Process location list. */ | |
91d6fa6a | 2440 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2441 | unsigned int num = debug_info_p->num_loc_offsets; |
2442 | ||
91d6fa6a | 2443 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2444 | { |
91d6fa6a | 2445 | lmax += 1024; |
467c65bc | 2446 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2447 | xcrealloc (debug_info_p->loc_offsets, |
2448 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2449 | debug_info_p->loc_views = (dwarf_vma *) |
2450 | xcrealloc (debug_info_p->loc_views, | |
2451 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2452 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2453 | xcrealloc (debug_info_p->have_frame_base, |
2454 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2455 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2456 | } |
341f9135 | 2457 | if (this_set != NULL) |
b4eb7656 | 2458 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2459 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2460 | if (attribute != DW_AT_GNU_locviews) |
2461 | { | |
a7504f87 NC |
2462 | /* Corrupt DWARF info can produce more offsets than views. |
2463 | See PR 23062 for an example. */ | |
2464 | if (debug_info_p->num_loc_offsets | |
2465 | > debug_info_p->num_loc_views) | |
2466 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2467 | else | |
2468 | { | |
2469 | debug_info_p->loc_offsets [num] = uvalue; | |
2470 | debug_info_p->num_loc_offsets++; | |
2471 | } | |
9f272209 AO |
2472 | } |
2473 | else | |
2474 | { | |
2475 | assert (debug_info_p->num_loc_views <= num); | |
2476 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2477 | if (num > debug_info_p->num_loc_offsets) |
2478 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2479 | else | |
2480 | { | |
2481 | debug_info_p->loc_views [num] = uvalue; | |
2482 | debug_info_p->num_loc_views++; | |
2483 | } | |
9f272209 | 2484 | } |
19e6b90e L |
2485 | } |
2486 | break; | |
e2a0d921 | 2487 | |
19e6b90e L |
2488 | case DW_AT_low_pc: |
2489 | if (need_base_address) | |
2490 | debug_info_p->base_address = uvalue; | |
2491 | break; | |
2492 | ||
4723351a | 2493 | case DW_AT_GNU_addr_base: |
b4eb7656 | 2494 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2495 | break; |
2496 | ||
2497 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2498 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2499 | break; |
2500 | ||
19e6b90e | 2501 | case DW_AT_ranges: |
b4eb7656 | 2502 | if ((dwarf_version < 4 |
212b6063 | 2503 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2504 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2505 | { |
2506 | /* Process range list. */ | |
91d6fa6a | 2507 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2508 | unsigned int num = debug_info_p->num_range_lists; |
2509 | ||
91d6fa6a | 2510 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2511 | { |
91d6fa6a | 2512 | lmax += 1024; |
467c65bc | 2513 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2514 | xcrealloc (debug_info_p->range_lists, |
2515 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2516 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2517 | } |
2518 | debug_info_p->range_lists [num] = uvalue; | |
2519 | debug_info_p->num_range_lists++; | |
2520 | } | |
2521 | break; | |
2522 | ||
d85bf2ba NC |
2523 | case DW_AT_GNU_dwo_name: |
2524 | case DW_AT_dwo_name: | |
2525 | if (need_dwo_info) | |
2526 | switch (form) | |
2527 | { | |
2528 | case DW_FORM_strp: | |
24841daa | 2529 | add_dwo_name ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba NC |
2530 | break; |
2531 | case DW_FORM_GNU_str_index: | |
24841daa | 2532 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2533 | break; |
2534 | case DW_FORM_string: | |
24841daa | 2535 | add_dwo_name ((const char *) orig_data); |
d85bf2ba NC |
2536 | break; |
2537 | default: | |
2538 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2539 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2540 | break; |
2541 | } | |
2542 | break; | |
2543 | ||
2544 | case DW_AT_comp_dir: | |
2545 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2546 | if (need_dwo_info) | |
2547 | switch (form) | |
2548 | { | |
2549 | case DW_FORM_strp: | |
24841daa | 2550 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba NC |
2551 | break; |
2552 | case DW_FORM_line_strp: | |
24841daa | 2553 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue)); |
d85bf2ba NC |
2554 | break; |
2555 | case DW_FORM_GNU_str_index: | |
24841daa | 2556 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2557 | break; |
2558 | case DW_FORM_string: | |
24841daa | 2559 | add_dwo_dir ((const char *) orig_data); |
d85bf2ba NC |
2560 | break; |
2561 | default: | |
2562 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2563 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2564 | break; |
2565 | } | |
2566 | break; | |
2567 | ||
2568 | case DW_AT_GNU_dwo_id: | |
2569 | if (need_dwo_info) | |
2570 | switch (form) | |
2571 | { | |
2572 | case DW_FORM_data8: | |
24841daa NC |
2573 | /* FIXME: Record the length of the ID as well ? */ |
2574 | add_dwo_id ((const char *) (data - 8)); | |
d85bf2ba NC |
2575 | break; |
2576 | default: | |
2577 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2578 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2579 | break; |
2580 | } | |
2581 | break; | |
2582 | ||
19e6b90e L |
2583 | default: |
2584 | break; | |
2585 | } | |
2586 | } | |
2587 | ||
4ccf1e31 | 2588 | if (do_loc || attribute == 0) |
19e6b90e L |
2589 | return data; |
2590 | ||
ec4d4525 | 2591 | /* For some attributes we can display further information. */ |
19e6b90e L |
2592 | switch (attribute) |
2593 | { | |
ec1b0fbb | 2594 | case DW_AT_type: |
b3fe587e AM |
2595 | if (level >= 0 && level < MAX_CU_NESTING |
2596 | && uvalue < (size_t) (end - start)) | |
ec1b0fbb NC |
2597 | { |
2598 | bfd_boolean is_signed = FALSE; | |
2599 | ||
2600 | get_type_signedness (start, start + uvalue, end, pointer_size, | |
2601 | offset_size, dwarf_version, & is_signed, FALSE); | |
2602 | level_type_signed[level] = is_signed; | |
2603 | } | |
2604 | break; | |
2605 | ||
19e6b90e | 2606 | case DW_AT_inline: |
2e9e81a8 | 2607 | printf ("\t"); |
19e6b90e L |
2608 | switch (uvalue) |
2609 | { | |
2610 | case DW_INL_not_inlined: | |
2611 | printf (_("(not inlined)")); | |
2612 | break; | |
2613 | case DW_INL_inlined: | |
2614 | printf (_("(inlined)")); | |
2615 | break; | |
2616 | case DW_INL_declared_not_inlined: | |
2617 | printf (_("(declared as inline but ignored)")); | |
2618 | break; | |
2619 | case DW_INL_declared_inlined: | |
2620 | printf (_("(declared as inline and inlined)")); | |
2621 | break; | |
2622 | default: | |
47704ddf KT |
2623 | printf (_(" (Unknown inline attribute value: %s)"), |
2624 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
2625 | break; |
2626 | } | |
2627 | break; | |
2628 | ||
2629 | case DW_AT_language: | |
2e9e81a8 | 2630 | printf ("\t"); |
19e6b90e L |
2631 | switch (uvalue) |
2632 | { | |
4b78141a | 2633 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 2634 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
2635 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
2636 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 2637 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
2638 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
2639 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
2640 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
2641 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 2642 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 2643 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 2644 | /* DWARF 2.1 values. */ |
4b78141a | 2645 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
2646 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
2647 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
2648 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
2649 | /* DWARF 3 values. */ |
2650 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
2651 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
2652 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
2653 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
2654 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
2655 | /* DWARF 4 values. */ |
2656 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 2657 | /* DWARF 5 values. */ |
2008a0db | 2658 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 2659 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
2660 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
2661 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
2662 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 2663 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
2664 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
2665 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 2666 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
2667 | case DW_LANG_Swift: printf ("(Swift)"); break; |
2668 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
2669 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 2670 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
2671 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
2672 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 2673 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
2674 | /* MIPS extension. */ |
2675 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
2676 | /* UPC extension. */ | |
2677 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
2678 | default: | |
4b78141a | 2679 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 2680 | printf (_("(implementation defined: %s)"), |
467c65bc | 2681 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 2682 | else |
9cf03b7e | 2683 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2684 | break; |
2685 | } | |
2686 | break; | |
2687 | ||
2688 | case DW_AT_encoding: | |
2e9e81a8 | 2689 | printf ("\t"); |
19e6b90e L |
2690 | switch (uvalue) |
2691 | { | |
2692 | case DW_ATE_void: printf ("(void)"); break; | |
2693 | case DW_ATE_address: printf ("(machine address)"); break; | |
2694 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
2695 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
2696 | case DW_ATE_float: printf ("(float)"); break; | |
2697 | case DW_ATE_signed: printf ("(signed)"); break; | |
2698 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
2699 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
2700 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 2701 | /* DWARF 2.1 values: */ |
19e6b90e L |
2702 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
2703 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
2704 | /* DWARF 3 values: */ |
2705 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
2706 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
2707 | case DW_ATE_edited: printf ("(edited)"); break; | |
2708 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
2709 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
2710 | /* DWARF 4 values: */ |
2711 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
2712 | /* DWARF 5 values: */ | |
2713 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
2714 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
2715 | ||
e2a0d921 NC |
2716 | /* HP extensions: */ |
2717 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
2718 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
2719 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
2720 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
2721 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
2722 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
2723 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
2724 | ||
19e6b90e L |
2725 | default: |
2726 | if (uvalue >= DW_ATE_lo_user | |
2727 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 2728 | printf (_("(user defined type)")); |
19e6b90e | 2729 | else |
9cf03b7e | 2730 | printf (_("(unknown type)")); |
19e6b90e L |
2731 | break; |
2732 | } | |
2733 | break; | |
2734 | ||
2735 | case DW_AT_accessibility: | |
2e9e81a8 | 2736 | printf ("\t"); |
19e6b90e L |
2737 | switch (uvalue) |
2738 | { | |
2739 | case DW_ACCESS_public: printf ("(public)"); break; | |
2740 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
2741 | case DW_ACCESS_private: printf ("(private)"); break; | |
2742 | default: | |
9cf03b7e | 2743 | printf (_("(unknown accessibility)")); |
19e6b90e L |
2744 | break; |
2745 | } | |
2746 | break; | |
2747 | ||
2748 | case DW_AT_visibility: | |
2e9e81a8 | 2749 | printf ("\t"); |
19e6b90e L |
2750 | switch (uvalue) |
2751 | { | |
2752 | case DW_VIS_local: printf ("(local)"); break; | |
2753 | case DW_VIS_exported: printf ("(exported)"); break; | |
2754 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 2755 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
2756 | } |
2757 | break; | |
2758 | ||
04914e37 NC |
2759 | case DW_AT_endianity: |
2760 | printf ("\t"); | |
2761 | switch (uvalue) | |
2762 | { | |
2763 | case DW_END_default: printf ("(default)"); break; | |
2764 | case DW_END_big: printf ("(big)"); break; | |
2765 | case DW_END_little: printf ("(little)"); break; | |
2766 | default: | |
2767 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
2768 | printf (_("(user specified)")); | |
2769 | else | |
2770 | printf (_("(unknown endianity)")); | |
2771 | break; | |
2772 | } | |
2773 | break; | |
2774 | ||
19e6b90e | 2775 | case DW_AT_virtuality: |
2e9e81a8 | 2776 | printf ("\t"); |
19e6b90e L |
2777 | switch (uvalue) |
2778 | { | |
2779 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
2780 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
2781 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 2782 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
2783 | } |
2784 | break; | |
2785 | ||
2786 | case DW_AT_identifier_case: | |
2e9e81a8 | 2787 | printf ("\t"); |
19e6b90e L |
2788 | switch (uvalue) |
2789 | { | |
2790 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
2791 | case DW_ID_up_case: printf ("(up_case)"); break; | |
2792 | case DW_ID_down_case: printf ("(down_case)"); break; | |
2793 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 2794 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
2795 | } |
2796 | break; | |
2797 | ||
2798 | case DW_AT_calling_convention: | |
2e9e81a8 | 2799 | printf ("\t"); |
19e6b90e L |
2800 | switch (uvalue) |
2801 | { | |
2802 | case DW_CC_normal: printf ("(normal)"); break; | |
2803 | case DW_CC_program: printf ("(program)"); break; | |
2804 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
2805 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
2806 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
2807 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
2808 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
2809 | default: |
2810 | if (uvalue >= DW_CC_lo_user | |
2811 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 2812 | printf (_("(user defined)")); |
19e6b90e | 2813 | else |
9cf03b7e | 2814 | printf (_("(unknown convention)")); |
19e6b90e L |
2815 | } |
2816 | break; | |
2817 | ||
2818 | case DW_AT_ordering: | |
2e9e81a8 | 2819 | printf ("\t"); |
19e6b90e L |
2820 | switch (uvalue) |
2821 | { | |
04914e37 | 2822 | case 255: |
9cf03b7e | 2823 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
2824 | case 0: printf ("(row major)"); break; |
2825 | case 1: printf ("(column major)"); break; | |
2826 | } | |
2827 | break; | |
2828 | ||
04914e37 NC |
2829 | case DW_AT_decimal_sign: |
2830 | printf ("\t"); | |
2831 | switch (uvalue) | |
2832 | { | |
2833 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
2834 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
2835 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
2836 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
2837 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
2838 | default: printf (_("(unrecognised)")); break; | |
2839 | } | |
2840 | break; | |
2841 | ||
2842 | case DW_AT_defaulted: | |
2843 | printf ("\t"); | |
2844 | switch (uvalue) | |
2845 | { | |
2846 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
2847 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
2848 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
2849 | default: printf (_("(unrecognised)")); break; | |
2850 | } | |
2851 | break; | |
2852 | ||
2853 | case DW_AT_discr_list: | |
2854 | printf ("\t"); | |
ec1b0fbb | 2855 | display_discr_list (form, uvalue, data, end, level); |
04914e37 NC |
2856 | break; |
2857 | ||
19e6b90e L |
2858 | case DW_AT_frame_base: |
2859 | have_frame_base = 1; | |
1a0670f3 | 2860 | /* Fall through. */ |
19e6b90e | 2861 | case DW_AT_location: |
e2a0d921 NC |
2862 | case DW_AT_string_length: |
2863 | case DW_AT_return_addr: | |
19e6b90e L |
2864 | case DW_AT_data_member_location: |
2865 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2866 | case DW_AT_segment: |
2867 | case DW_AT_static_link: | |
2868 | case DW_AT_use_location: | |
bc0a77d2 | 2869 | case DW_AT_call_value: |
629e7ca8 | 2870 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2871 | case DW_AT_call_data_value: |
629e7ca8 | 2872 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2873 | case DW_AT_call_target: |
629e7ca8 | 2874 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2875 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2876 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 2877 | if ((dwarf_version < 4 |
b4eb7656 | 2878 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2879 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 2880 | printf (_(" (location list)")); |
e2a0d921 | 2881 | /* Fall through. */ |
19e6b90e L |
2882 | case DW_AT_allocated: |
2883 | case DW_AT_associated: | |
2884 | case DW_AT_data_location: | |
2885 | case DW_AT_stride: | |
2886 | case DW_AT_upper_bound: | |
cecf136e | 2887 | case DW_AT_lower_bound: |
19e6b90e L |
2888 | if (block_start) |
2889 | { | |
2890 | int need_frame_base; | |
2891 | ||
2e9e81a8 | 2892 | printf ("\t("); |
19e6b90e L |
2893 | need_frame_base = decode_location_expression (block_start, |
2894 | pointer_size, | |
b7807392 JJ |
2895 | offset_size, |
2896 | dwarf_version, | |
19e6b90e | 2897 | uvalue, |
f1c4cc75 | 2898 | cu_offset, section); |
19e6b90e L |
2899 | printf (")"); |
2900 | if (need_frame_base && !have_frame_base) | |
2901 | printf (_(" [without DW_AT_frame_base]")); | |
2902 | } | |
19e6b90e L |
2903 | break; |
2904 | ||
c54207d3 NC |
2905 | case DW_AT_data_bit_offset: |
2906 | case DW_AT_byte_size: | |
2907 | case DW_AT_bit_size: | |
2908 | case DW_AT_string_length_byte_size: | |
2909 | case DW_AT_string_length_bit_size: | |
2910 | case DW_AT_bit_stride: | |
2911 | if (form == DW_FORM_exprloc) | |
2912 | { | |
2913 | printf ("\t("); | |
2914 | (void) decode_location_expression (block_start, pointer_size, | |
2915 | offset_size, dwarf_version, | |
2916 | uvalue, cu_offset, section); | |
2917 | printf (")"); | |
2918 | } | |
2919 | break; | |
2920 | ||
ec4d4525 NC |
2921 | case DW_AT_import: |
2922 | { | |
a081f3cd JJ |
2923 | if (form == DW_FORM_ref_sig8 |
2924 | || form == DW_FORM_GNU_ref_alt) | |
b4eb7656 | 2925 | break; |
2b6f5997 | 2926 | |
ec4d4525 NC |
2927 | if (form == DW_FORM_ref1 |
2928 | || form == DW_FORM_ref2 | |
a7a0b6a5 JK |
2929 | || form == DW_FORM_ref4 |
2930 | || form == DW_FORM_ref_udata) | |
ec4d4525 NC |
2931 | uvalue += cu_offset; |
2932 | ||
6e3d6dc1 | 2933 | if (uvalue >= section->size) |
f3853b34 | 2934 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), |
47704ddf KT |
2935 | dwarf_vmatoa ("x", uvalue), |
2936 | (unsigned long) (orig_data - section->start)); | |
6e3d6dc1 NC |
2937 | else |
2938 | { | |
2939 | unsigned long abbrev_number; | |
cd30bcef AM |
2940 | abbrev_entry *entry; |
2941 | unsigned char *p = section->start + uvalue; | |
6e3d6dc1 | 2942 | |
cd30bcef | 2943 | READ_ULEB (abbrev_number, p, end); |
cecf136e | 2944 | |
2e9e81a8 | 2945 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
afd6e1ff JJ |
2946 | /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
2947 | use different abbrev table, and we don't track .debug_info chunks | |
2948 | yet. */ | |
2949 | if (form != DW_FORM_ref_addr) | |
2950 | { | |
2951 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
2952 | if (entry->entry == abbrev_number) | |
2953 | break; | |
2954 | if (entry != NULL) | |
2955 | printf (" (%s)", get_TAG_name (entry->tag)); | |
2956 | } | |
6e3d6dc1 NC |
2957 | printf ("]"); |
2958 | } | |
ec4d4525 NC |
2959 | } |
2960 | break; | |
2961 | ||
19e6b90e L |
2962 | default: |
2963 | break; | |
2964 | } | |
2965 | ||
2966 | return data; | |
2967 | } | |
2968 | ||
19e6b90e | 2969 | static unsigned char * |
dda8d76d NC |
2970 | read_and_display_attr (unsigned long attribute, |
2971 | unsigned long form, | |
2972 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 2973 | unsigned char * start, |
dda8d76d NC |
2974 | unsigned char * data, |
2975 | unsigned char * end, | |
2976 | dwarf_vma cu_offset, | |
2977 | dwarf_vma pointer_size, | |
2978 | dwarf_vma offset_size, | |
2979 | int dwarf_version, | |
2980 | debug_info * debug_info_p, | |
2981 | int do_loc, | |
2982 | struct dwarf_section * section, | |
ec1b0fbb NC |
2983 | struct cu_tu_set * this_set, |
2984 | int level) | |
19e6b90e L |
2985 | { |
2986 | if (!do_loc) | |
750f03b7 | 2987 | printf (" %-18s:", get_AT_name (attribute)); |
ec1b0fbb NC |
2988 | data = read_and_display_attr_value (attribute, form, implicit_const, |
2989 | start, data, end, | |
f6f0e17b | 2990 | cu_offset, pointer_size, offset_size, |
19e6b90e | 2991 | dwarf_version, debug_info_p, |
ec1b0fbb | 2992 | do_loc, section, this_set, ' ', level); |
19e6b90e L |
2993 | if (!do_loc) |
2994 | printf ("\n"); | |
2995 | return data; | |
2996 | } | |
2997 | ||
dda8d76d | 2998 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
2999 | following debug links, then attempt to load the requested section |
3000 | from one of the separate debug info files. */ | |
dda8d76d NC |
3001 | |
3002 | static bfd_boolean | |
3003 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, | |
24841daa | 3004 | void * handle) |
dda8d76d | 3005 | { |
24841daa | 3006 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 3007 | { |
24841daa NC |
3008 | if (debug_displays[sec_enum].section.filename == NULL) |
3009 | { | |
3010 | /* See if we can associate a filename with this section. */ | |
3011 | separate_info * i; | |
3012 | ||
3013 | for (i = first_separate_info; i != NULL; i = i->next) | |
3014 | if (i->handle == handle) | |
3015 | { | |
3016 | debug_displays[sec_enum].section.filename = i->filename; | |
3017 | break; | |
3018 | } | |
3019 | } | |
3020 | ||
dda8d76d NC |
3021 | return TRUE; |
3022 | } | |
3023 | ||
24841daa NC |
3024 | if (do_follow_links) |
3025 | { | |
3026 | separate_info * i; | |
3027 | ||
3028 | for (i = first_separate_info; i != NULL; i = i->next) | |
3029 | { | |
3030 | if (load_debug_section (sec_enum, i->handle)) | |
3031 | { | |
3032 | debug_displays[sec_enum].section.filename = i->filename; | |
3033 | ||
3034 | /* FIXME: We should check to see if any of the remaining debug info | |
3035 | files also contain this section, and, umm, do something about it. */ | |
3036 | return TRUE; | |
3037 | } | |
3038 | } | |
3039 | } | |
dda8d76d NC |
3040 | |
3041 | return FALSE; | |
3042 | } | |
3043 | ||
3044 | static void | |
3045 | introduce (struct dwarf_section * section, bfd_boolean raw) | |
3046 | { | |
3047 | if (raw) | |
3048 | { | |
3049 | if (do_follow_links && section->filename) | |
3050 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
3051 | section->name, section->filename); | |
3052 | else | |
3053 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
3054 | } | |
3055 | else | |
3056 | { | |
3057 | if (do_follow_links && section->filename) | |
3058 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
3059 | section->name, section->filename); | |
3060 | else | |
3061 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3062 | } | |
3063 | } | |
3064 | ||
d85bf2ba NC |
3065 | /* Process the contents of a .debug_info section. |
3066 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
3067 | and we do not want to display anything to the user. | |
3068 | If do_types is TRUE, we are processing a .debug_types section instead of | |
3069 | a .debug_info section. | |
3070 | The information displayed is restricted by the values in DWARF_START_DIE | |
3071 | and DWARF_CUTOFF_LEVEL. | |
3072 | Returns TRUE upon success. Otherwise an error or warning message is | |
3073 | printed and FALSE is returned. */ | |
19e6b90e | 3074 | |
d85bf2ba NC |
3075 | static bfd_boolean |
3076 | process_debug_info (struct dwarf_section * section, | |
3077 | void * file, | |
3078 | enum dwarf_section_display_enum abbrev_sec, | |
3079 | bfd_boolean do_loc, | |
3080 | bfd_boolean do_types) | |
19e6b90e L |
3081 | { |
3082 | unsigned char *start = section->start; | |
3083 | unsigned char *end = start + section->size; | |
3084 | unsigned char *section_begin; | |
3085 | unsigned int unit; | |
3086 | unsigned int num_units = 0; | |
3087 | ||
3088 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3089 | && num_debug_info_entries == 0 |
3090 | && ! do_types) | |
19e6b90e | 3091 | { |
767221a9 | 3092 | dwarf_vma length; |
19e6b90e L |
3093 | |
3094 | /* First scan the section to get the number of comp units. */ | |
3095 | for (section_begin = start, num_units = 0; section_begin < end; | |
3096 | num_units ++) | |
3097 | { | |
3098 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
3099 | will be the length. For a 64-bit DWARF section, it'll be | |
3100 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 3101 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
3102 | |
3103 | if (length == 0xffffffff) | |
3104 | { | |
0c588247 | 3105 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
3106 | section_begin += length + 12; |
3107 | } | |
ec4d4525 NC |
3108 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
3109 | { | |
767221a9 NC |
3110 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
3111 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3112 | return FALSE; |
ec4d4525 | 3113 | } |
19e6b90e L |
3114 | else |
3115 | section_begin += length + 4; | |
aca88567 NC |
3116 | |
3117 | /* Negative values are illegal, they may even cause infinite | |
3118 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
3119 | relocations to an object file, or if the file is corrupt. */ |
3120 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 3121 | { |
767221a9 NC |
3122 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
3123 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3124 | return FALSE; |
aca88567 | 3125 | } |
19e6b90e L |
3126 | } |
3127 | ||
3128 | if (num_units == 0) | |
3129 | { | |
f41e4712 | 3130 | error (_("No comp units in %s section ?\n"), section->name); |
d85bf2ba | 3131 | return FALSE; |
19e6b90e L |
3132 | } |
3133 | ||
3134 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 3135 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 3136 | sizeof (* debug_information)); |
19e6b90e L |
3137 | if (debug_information == NULL) |
3138 | { | |
f41e4712 | 3139 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 3140 | num_units); |
82b1b41b | 3141 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
d85bf2ba | 3142 | return FALSE; |
19e6b90e | 3143 | } |
d85bf2ba | 3144 | |
03a91817 NC |
3145 | /* PR 17531: file: 92ca3797. |
3146 | We cannot rely upon the debug_information array being initialised | |
3147 | before it is used. A corrupt file could easily contain references | |
3148 | to a unit for which information has not been made available. So | |
3149 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
3150 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
3151 | ||
82b1b41b | 3152 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
3153 | } |
3154 | ||
3155 | if (!do_loc) | |
3156 | { | |
dda8d76d NC |
3157 | load_debug_section_with_follow (str, file); |
3158 | load_debug_section_with_follow (line_str, file); | |
3159 | load_debug_section_with_follow (str_dwo, file); | |
3160 | load_debug_section_with_follow (str_index, file); | |
3161 | load_debug_section_with_follow (str_index_dwo, file); | |
3162 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e L |
3163 | } |
3164 | ||
dda8d76d | 3165 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 3166 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
3167 | { |
3168 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 3169 | debug_displays [abbrev_sec].section.uncompressed_name); |
d85bf2ba | 3170 | return FALSE; |
19e6b90e L |
3171 | } |
3172 | ||
dda8d76d NC |
3173 | if (!do_loc && dwarf_start_die == 0) |
3174 | introduce (section, FALSE); | |
3175 | ||
19e6b90e L |
3176 | for (section_begin = start, unit = 0; start < end; unit++) |
3177 | { | |
3178 | DWARF2_Internal_CompUnit compunit; | |
3179 | unsigned char *hdrptr; | |
19e6b90e | 3180 | unsigned char *tags; |
fd2f0033 | 3181 | int level, last_level, saved_level; |
467c65bc | 3182 | dwarf_vma cu_offset; |
e98fdf1a | 3183 | unsigned long sec_off; |
bf5117e3 | 3184 | unsigned int offset_size; |
19485196 | 3185 | unsigned int initial_length_size; |
74bc6052 CC |
3186 | dwarf_vma signature_high = 0; |
3187 | dwarf_vma signature_low = 0; | |
767221a9 | 3188 | dwarf_vma type_offset = 0; |
341f9135 CC |
3189 | struct cu_tu_set *this_set; |
3190 | dwarf_vma abbrev_base; | |
3191 | size_t abbrev_size; | |
19e6b90e L |
3192 | |
3193 | hdrptr = start; | |
3194 | ||
0c588247 | 3195 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
3196 | |
3197 | if (compunit.cu_length == 0xffffffff) | |
3198 | { | |
0c588247 | 3199 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
3200 | offset_size = 8; |
3201 | initial_length_size = 12; | |
3202 | } | |
3203 | else | |
3204 | { | |
3205 | offset_size = 4; | |
3206 | initial_length_size = 4; | |
3207 | } | |
3208 | ||
0c588247 | 3209 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
3210 | |
3211 | cu_offset = start - section_begin; | |
19e6b90e | 3212 | |
341f9135 CC |
3213 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3214 | ||
77145576 JK |
3215 | if (compunit.cu_version < 5) |
3216 | { | |
3217 | compunit.cu_unit_type = DW_UT_compile; | |
3218 | /* Initialize it due to a false compiler warning. */ | |
3219 | compunit.cu_pointer_size = -1; | |
3220 | } | |
3221 | else | |
3222 | { | |
3223 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3224 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3225 | ||
3226 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3227 | } | |
3228 | ||
0c588247 | 3229 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 3230 | |
341f9135 CC |
3231 | if (this_set == NULL) |
3232 | { | |
3233 | abbrev_base = 0; | |
3234 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3235 | } | |
3236 | else | |
3237 | { | |
3238 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3239 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3240 | } | |
3241 | ||
77145576 JK |
3242 | if (compunit.cu_version < 5) |
3243 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3244 | ||
f41e4712 NC |
3245 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
3246 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
3247 | { | |
3248 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
3249 | compunit.cu_pointer_size, offset_size); | |
3250 | compunit.cu_pointer_size = offset_size; | |
3251 | } | |
2b6f5997 CC |
3252 | |
3253 | if (do_types) | |
b4eb7656 | 3254 | { |
0c588247 | 3255 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 3256 | hdrptr += 8; |
0c588247 | 3257 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 3258 | } |
2b6f5997 | 3259 | |
ae7e7825 NC |
3260 | if (dwarf_start_die > (cu_offset + compunit.cu_length |
3261 | + initial_length_size)) | |
3262 | { | |
3263 | start = section_begin + cu_offset + compunit.cu_length | |
3264 | + initial_length_size; | |
3265 | continue; | |
3266 | } | |
3267 | ||
19e6b90e | 3268 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 CC |
3269 | && num_debug_info_entries == 0 |
3270 | && ! do_types) | |
19e6b90e L |
3271 | { |
3272 | debug_information [unit].cu_offset = cu_offset; | |
3273 | debug_information [unit].pointer_size | |
3274 | = compunit.cu_pointer_size; | |
b7807392 JJ |
3275 | debug_information [unit].offset_size = offset_size; |
3276 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 3277 | debug_information [unit].base_address = 0; |
4723351a CC |
3278 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
3279 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
3280 | debug_information [unit].loc_offsets = NULL; |
3281 | debug_information [unit].have_frame_base = NULL; | |
3282 | debug_information [unit].max_loc_offsets = 0; | |
3283 | debug_information [unit].num_loc_offsets = 0; | |
3284 | debug_information [unit].range_lists = NULL; | |
3285 | debug_information [unit].max_range_lists= 0; | |
3286 | debug_information [unit].num_range_lists = 0; | |
3287 | } | |
3288 | ||
fd2f0033 | 3289 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 3290 | { |
47704ddf KT |
3291 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3292 | dwarf_vmatoa ("x", cu_offset)); | |
3293 | printf (_(" Length: 0x%s (%s)\n"), | |
3294 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3295 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3296 | printf (_(" Version: %d\n"), compunit.cu_version); |
7282333f AM |
3297 | printf (_(" Abbrev Offset: 0x%s\n"), |
3298 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3299 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3300 | if (do_types) |
3301 | { | |
74bc6052 CC |
3302 | char buf[64]; |
3303 | ||
3304 | printf (_(" Signature: 0x%s\n"), | |
3305 | dwarf_vmatoa64 (signature_high, signature_low, | |
3306 | buf, sizeof (buf))); | |
3307 | printf (_(" Type Offset: 0x%s\n"), | |
3308 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3309 | } |
341f9135 CC |
3310 | if (this_set != NULL) |
3311 | { | |
3312 | dwarf_vma *offsets = this_set->section_offsets; | |
3313 | size_t *sizes = this_set->section_sizes; | |
3314 | ||
3315 | printf (_(" Section contributions:\n")); | |
3316 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3317 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3318 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3319 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3320 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3321 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3322 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3323 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3324 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3325 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3326 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3327 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3328 | } | |
19e6b90e L |
3329 | } |
3330 | ||
e98fdf1a AM |
3331 | sec_off = cu_offset + initial_length_size; |
3332 | if (sec_off + compunit.cu_length < sec_off | |
3333 | || sec_off + compunit.cu_length > section->size) | |
460c89ff | 3334 | { |
e98fdf1a AM |
3335 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
3336 | section->name, | |
3337 | (unsigned long) cu_offset, | |
19485196 NC |
3338 | dwarf_vmatoa ("x", compunit.cu_length)); |
3339 | num_units = unit; | |
3340 | break; | |
3341 | } | |
3342 | ||
460c89ff NS |
3343 | tags = hdrptr; |
3344 | start += compunit.cu_length + initial_length_size; | |
3345 | ||
77145576 | 3346 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3347 | { |
47704ddf KT |
3348 | warn (_("CU at offset %s contains corrupt or " |
3349 | "unsupported version number: %d.\n"), | |
3350 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3351 | continue; |
3352 | } | |
3353 | ||
77145576 JK |
3354 | if (compunit.cu_unit_type != DW_UT_compile |
3355 | && compunit.cu_unit_type != DW_UT_type) | |
3356 | { | |
3357 | warn (_("CU at offset %s contains corrupt or " | |
3358 | "unsupported unit type: %d.\n"), | |
3359 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3360 | continue; | |
3361 | } | |
3362 | ||
19e6b90e L |
3363 | free_abbrevs (); |
3364 | ||
d493b283 | 3365 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 3366 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
3367 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
3368 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 3369 | (unsigned long) abbrev_size); |
b4eb7656 | 3370 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
3371 | else if ((abbrev_base + abbrev_size) |
3372 | > debug_displays [abbrev_sec].section.size) | |
3373 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
3374 | (unsigned long) abbrev_base + abbrev_size, | |
3375 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff NS |
3376 | else |
3377 | process_abbrev_section | |
341f9135 CC |
3378 | (((unsigned char *) debug_displays [abbrev_sec].section.start |
3379 | + abbrev_base + compunit.cu_abbrev_offset), | |
3380 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3381 | + abbrev_base + abbrev_size)); | |
19e6b90e L |
3382 | |
3383 | level = 0; | |
fd2f0033 TT |
3384 | last_level = level; |
3385 | saved_level = -1; | |
19e6b90e L |
3386 | while (tags < start) |
3387 | { | |
19e6b90e | 3388 | unsigned long abbrev_number; |
ec4d4525 | 3389 | unsigned long die_offset; |
19e6b90e L |
3390 | abbrev_entry *entry; |
3391 | abbrev_attr *attr; | |
fd2f0033 | 3392 | int do_printing = 1; |
19e6b90e | 3393 | |
ec4d4525 NC |
3394 | die_offset = tags - section_begin; |
3395 | ||
cd30bcef | 3396 | READ_ULEB (abbrev_number, tags, start); |
19e6b90e | 3397 | |
eb7cc021 JK |
3398 | /* A null DIE marks the end of a list of siblings or it may also be |
3399 | a section padding. */ | |
19e6b90e L |
3400 | if (abbrev_number == 0) |
3401 | { | |
eb7cc021 JK |
3402 | /* Check if it can be a section padding for the last CU. */ |
3403 | if (level == 0 && start == end) | |
3404 | { | |
3405 | unsigned char *chk; | |
3406 | ||
3407 | for (chk = tags; chk < start; chk++) | |
3408 | if (*chk != 0) | |
3409 | break; | |
3410 | if (chk == start) | |
3411 | break; | |
3412 | } | |
3413 | ||
4337774f TT |
3414 | if (!do_loc && die_offset >= dwarf_start_die |
3415 | && (dwarf_cutoff_level == -1 | |
3416 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3417 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3418 | level, die_offset); | |
3419 | ||
19e6b90e | 3420 | --level; |
ec4d4525 NC |
3421 | if (level < 0) |
3422 | { | |
3423 | static unsigned num_bogus_warns = 0; | |
3424 | ||
3425 | if (num_bogus_warns < 3) | |
3426 | { | |
4723351a CC |
3427 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3428 | die_offset, section->name); | |
ec4d4525 NC |
3429 | num_bogus_warns ++; |
3430 | if (num_bogus_warns == 3) | |
3431 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3432 | } | |
3433 | } | |
fd2f0033 | 3434 | if (dwarf_start_die != 0 && level < saved_level) |
d85bf2ba | 3435 | return TRUE; |
19e6b90e L |
3436 | continue; |
3437 | } | |
3438 | ||
4b78141a | 3439 | if (!do_loc) |
fd2f0033 TT |
3440 | { |
3441 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
3442 | do_printing = 0; | |
3443 | else | |
3444 | { | |
3445 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
3446 | saved_level = level; | |
3447 | do_printing = (dwarf_cutoff_level == -1 | |
3448 | || level < dwarf_cutoff_level); | |
3449 | if (do_printing) | |
3450 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
3451 | level, die_offset, abbrev_number); | |
3452 | else if (dwarf_cutoff_level == -1 | |
3453 | || last_level < dwarf_cutoff_level) | |
3454 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
3455 | last_level = level; | |
3456 | } | |
3457 | } | |
cecf136e | 3458 | |
19e6b90e L |
3459 | /* Scan through the abbreviation list until we reach the |
3460 | correct entry. */ | |
3461 | for (entry = first_abbrev; | |
3462 | entry && entry->entry != abbrev_number; | |
3463 | entry = entry->next) | |
3464 | continue; | |
3465 | ||
3466 | if (entry == NULL) | |
3467 | { | |
fd2f0033 | 3468 | if (!do_loc && do_printing) |
4b78141a NC |
3469 | { |
3470 | printf ("\n"); | |
3471 | fflush (stdout); | |
3472 | } | |
f3853b34 | 3473 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 3474 | die_offset, abbrev_number); |
d85bf2ba | 3475 | return FALSE; |
19e6b90e L |
3476 | } |
3477 | ||
fd2f0033 | 3478 | if (!do_loc && do_printing) |
cc5914eb | 3479 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 3480 | |
19e6b90e L |
3481 | switch (entry->tag) |
3482 | { | |
3483 | default: | |
3484 | need_base_address = 0; | |
3485 | break; | |
3486 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
3487 | need_base_address = 1; |
3488 | need_dwo_info = do_loc; | |
19e6b90e L |
3489 | break; |
3490 | case DW_TAG_entry_point: | |
19e6b90e L |
3491 | case DW_TAG_subprogram: |
3492 | need_base_address = 0; | |
3493 | /* Assuming that there is no DW_AT_frame_base. */ | |
3494 | have_frame_base = 0; | |
3495 | break; | |
3496 | } | |
3497 | ||
9f272209 AO |
3498 | debug_info *debug_info_p = |
3499 | (debug_information && unit < alloc_num_debug_info_entries) | |
3500 | ? debug_information + unit : NULL; | |
3501 | ||
3502 | assert (!debug_info_p | |
3503 | || (debug_info_p->num_loc_offsets | |
3504 | == debug_info_p->num_loc_views)); | |
3505 | ||
399c99f7 L |
3506 | for (attr = entry->first_attr; |
3507 | attr && attr->attribute; | |
3508 | attr = attr->next) | |
4b78141a | 3509 | { |
fd2f0033 | 3510 | if (! do_loc && do_printing) |
4b78141a | 3511 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 | 3512 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
3513 | tags = read_and_display_attr (attr->attribute, |
3514 | attr->form, | |
77145576 | 3515 | attr->implicit_const, |
ec1b0fbb | 3516 | section_begin, |
341f9135 | 3517 | tags, |
f6f0e17b | 3518 | end, |
341f9135 | 3519 | cu_offset, |
4b78141a NC |
3520 | compunit.cu_pointer_size, |
3521 | offset_size, | |
3522 | compunit.cu_version, | |
9f272209 | 3523 | debug_info_p, |
341f9135 CC |
3524 | do_loc || ! do_printing, |
3525 | section, | |
ec1b0fbb NC |
3526 | this_set, |
3527 | level); | |
4b78141a | 3528 | } |
cecf136e | 3529 | |
9f272209 AO |
3530 | /* If a locview attribute appears before a location one, |
3531 | make sure we don't associate it with an earlier | |
3532 | loclist. */ | |
3533 | if (debug_info_p) | |
3534 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
3535 | { | |
3536 | case 1: | |
3537 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
3538 | debug_info_p->num_loc_views++; | |
3539 | assert (debug_info_p->num_loc_views | |
3540 | == debug_info_p->num_loc_offsets); | |
3541 | break; | |
3542 | ||
3543 | case 0: | |
3544 | break; | |
3545 | ||
3546 | case -1: | |
3547 | warn(_("DIE has locviews without loclist\n")); | |
3548 | debug_info_p->num_loc_views--; | |
3549 | break; | |
3550 | ||
3551 | default: | |
3552 | assert (0); | |
3553 | } | |
3554 | ||
b4eb7656 AM |
3555 | if (entry->children) |
3556 | ++level; | |
3557 | } | |
19e6b90e | 3558 | } |
cecf136e | 3559 | |
19e6b90e L |
3560 | /* Set num_debug_info_entries here so that it can be used to check if |
3561 | we need to process .debug_loc and .debug_ranges sections. */ | |
3562 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3563 | && num_debug_info_entries == 0 |
3564 | && ! do_types) | |
82b1b41b | 3565 | { |
b4eb7656 | 3566 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
3567 | num_debug_info_entries = alloc_num_debug_info_entries; |
3568 | else | |
3569 | num_debug_info_entries = num_units; | |
3570 | } | |
cecf136e | 3571 | |
19e6b90e | 3572 | if (!do_loc) |
467c65bc | 3573 | printf ("\n"); |
cecf136e | 3574 | |
d85bf2ba | 3575 | return TRUE; |
19e6b90e L |
3576 | } |
3577 | ||
3578 | /* Locate and scan the .debug_info section in the file and record the pointer | |
3579 | sizes and offsets for the compilation units in it. Usually an executable | |
3580 | will have just one pointer size, but this is not guaranteed, and so we try | |
3581 | not to make any assumptions. Returns zero upon failure, or the number of | |
3582 | compilation units upon success. */ | |
3583 | ||
3584 | static unsigned int | |
3585 | load_debug_info (void * file) | |
3586 | { | |
1febe64d | 3587 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 3588 | section then do not bother to repeat the task. */ |
cc86f28f | 3589 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
3590 | return 0; |
3591 | ||
19e6b90e L |
3592 | /* If we already have the information there is nothing else to do. */ |
3593 | if (num_debug_info_entries > 0) | |
3594 | return num_debug_info_entries; | |
3595 | ||
341f9135 | 3596 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 3597 | (void) load_cu_tu_indexes (file); |
341f9135 | 3598 | |
dda8d76d | 3599 | if (load_debug_section_with_follow (info, file) |
d85bf2ba | 3600 | && process_debug_info (&debug_displays [info].section, file, abbrev, TRUE, FALSE)) |
19e6b90e | 3601 | return num_debug_info_entries; |
82b1b41b | 3602 | |
dda8d76d | 3603 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 3604 | && process_debug_info (&debug_displays [info_dwo].section, file, |
d85bf2ba | 3605 | abbrev_dwo, TRUE, FALSE)) |
4723351a | 3606 | return num_debug_info_entries; |
1febe64d | 3607 | |
cc86f28f | 3608 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 3609 | return 0; |
19e6b90e L |
3610 | } |
3611 | ||
b40bf0a2 NC |
3612 | /* Read a DWARF .debug_line section header starting at DATA. |
3613 | Upon success returns an updated DATA pointer and the LINFO | |
3614 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
3615 | Otherwise returns NULL. */ | |
19e6b90e | 3616 | |
b40bf0a2 NC |
3617 | static unsigned char * |
3618 | read_debug_line_header (struct dwarf_section * section, | |
3619 | unsigned char * data, | |
3620 | unsigned char * end, | |
3621 | DWARF2_Internal_LineInfo * linfo, | |
3622 | unsigned char ** end_of_sequence) | |
3623 | { | |
3624 | unsigned char *hdrptr; | |
b40bf0a2 | 3625 | unsigned int initial_length_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 | { | |
5496f3c6 | 3682 | SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end); |
77145576 | 3683 | |
5496f3c6 NC |
3684 | SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end); |
3685 | if (linfo->li_segment_size != 0) | |
77145576 JK |
3686 | { |
3687 | warn (_("The %s section contains " | |
3688 | "unsupported segment selector size: %d.\n"), | |
5496f3c6 NC |
3689 | section->name, linfo->li_segment_size); |
3690 | return NULL; | |
77145576 JK |
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; |
5496f3c6 NC |
3740 | const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table"); |
3741 | ||
77145576 | 3742 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
546cb2d8 NC |
3743 | if (do_checks && format_count > 5) |
3744 | warn (_("Unexpectedly large number of columns in the %s (%u)\n"), | |
3745 | table_name, format_count); | |
3746 | ||
77145576 JK |
3747 | format_start = data; |
3748 | for (formati = 0; formati < format_count; formati++) | |
3749 | { | |
cd30bcef AM |
3750 | SKIP_ULEB (data, end); |
3751 | SKIP_ULEB (data, end); | |
77145576 JK |
3752 | if (data == end) |
3753 | { | |
5496f3c6 | 3754 | warn (_("%s: Corrupt format description entry\n"), table_name); |
77145576 JK |
3755 | return data; |
3756 | } | |
3757 | } | |
3758 | ||
cd30bcef | 3759 | READ_ULEB (data_count, data, end); |
546cb2d8 | 3760 | if (data_count == 0) |
77145576 | 3761 | { |
546cb2d8 | 3762 | printf (_("\n The %s is empty.\n"), table_name); |
77145576 JK |
3763 | return data; |
3764 | } | |
546cb2d8 | 3765 | else if (data == end) |
77145576 | 3766 | { |
546cb2d8 NC |
3767 | warn (_("%s: Corrupt entry count - expected %s but none found\n"), |
3768 | table_name, dwarf_vmatoa ("x", data_count)); | |
77145576 JK |
3769 | return data; |
3770 | } | |
546cb2d8 | 3771 | |
5496f3c6 NC |
3772 | else if (format_count == 0) |
3773 | { | |
3774 | warn (_("%s: format count is zero, but the table is not empty\n"), | |
3775 | table_name); | |
3776 | return end; | |
3777 | } | |
77145576 | 3778 | |
5496f3c6 NC |
3779 | printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"), |
3780 | table_name, (long) (data - start), dwarf_vmatoa ("u", data_count), | |
3781 | format_count); | |
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: | |
5496f3c6 | 3809 | printf (_("\tMD5\t\t\t")); |
77145576 JK |
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 | } | |
5496f3c6 NC |
3843 | |
3844 | if (data == end && (datai < data_count - 1)) | |
77145576 | 3845 | { |
5496f3c6 | 3846 | warn (_("\n%s: Corrupt entries list\n"), table_name); |
77145576 JK |
3847 | return data; |
3848 | } | |
3849 | putchar ('\n'); | |
3850 | } | |
3851 | return data; | |
3852 | } | |
3853 | ||
b40bf0a2 | 3854 | static int |
dda8d76d NC |
3855 | display_debug_lines_raw (struct dwarf_section * section, |
3856 | unsigned char * data, | |
3857 | unsigned char * end, | |
3858 | void * file) | |
b40bf0a2 NC |
3859 | { |
3860 | unsigned char *start = section->start; | |
ba8826a8 | 3861 | int verbose_view = 0; |
19e6b90e | 3862 | |
dda8d76d | 3863 | introduce (section, TRUE); |
19e6b90e | 3864 | |
b40bf0a2 NC |
3865 | while (data < end) |
3866 | { | |
3867 | static DWARF2_Internal_LineInfo saved_linfo; | |
3868 | DWARF2_Internal_LineInfo linfo; | |
3869 | unsigned char *standard_opcodes; | |
3870 | unsigned char *end_of_sequence; | |
fe59e83d | 3871 | int i; |
19e6b90e | 3872 | |
4925cdd7 NC |
3873 | if (const_strneq (section->name, ".debug_line.") |
3874 | /* Note: the following does not apply to .debug_line.dwo sections. | |
3875 | These are full debug_line sections. */ | |
3876 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 3877 | { |
b40bf0a2 NC |
3878 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
3879 | section containing just the Line Number Statements. They are | |
3880 | created by the assembler and intended to be used alongside gcc's | |
3881 | -ffunction-sections command line option. When the linker's | |
3882 | garbage collection decides to discard a .text.<foo> section it | |
3883 | can then also discard the line number information in .debug_line.<foo>. | |
3884 | ||
4925cdd7 | 3885 | Since the section is a fragment it does not have the details |
b40bf0a2 | 3886 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 3887 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
3888 | end_of_sequence = end; |
3889 | standard_opcodes = NULL; | |
3890 | linfo = saved_linfo; | |
058037d3 NC |
3891 | /* PR 17531: file: 0522b371. */ |
3892 | if (linfo.li_line_range == 0) | |
3893 | { | |
1306a742 | 3894 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
3895 | return 0; |
3896 | } | |
b40bf0a2 | 3897 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3898 | } |
19e6b90e L |
3899 | else |
3900 | { | |
b40bf0a2 | 3901 | unsigned char * hdrptr; |
19e6b90e | 3902 | |
b40bf0a2 NC |
3903 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
3904 | & end_of_sequence)) == NULL) | |
3905 | return 0; | |
19e6b90e | 3906 | |
b40bf0a2 NC |
3907 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
3908 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
3909 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
5496f3c6 NC |
3910 | if (linfo.li_version >= 5) |
3911 | { | |
3912 | printf (_(" Address size (bytes): %d\n"), linfo.li_address_size); | |
3913 | printf (_(" Segment selector (bytes): %d\n"), linfo.li_segment_size); | |
3914 | } | |
77ef8654 | 3915 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
3916 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
3917 | if (linfo.li_version >= 4) | |
3918 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
3919 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
3920 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
3921 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
3922 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 3923 | |
0a9d414a NC |
3924 | /* PR 17512: file: 1665-6428-0.004. */ |
3925 | if (linfo.li_line_range == 0) | |
3926 | { | |
3927 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
3928 | linfo.li_line_range = 1; | |
3929 | } | |
77ef8654 | 3930 | |
b40bf0a2 | 3931 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3932 | |
b40bf0a2 NC |
3933 | /* Display the contents of the Opcodes table. */ |
3934 | standard_opcodes = hdrptr; | |
19e6b90e | 3935 | |
6937bb54 NC |
3936 | /* PR 17512: file: 002-417945-0.004. */ |
3937 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
3938 | { | |
3939 | warn (_("Line Base extends beyond end of section\n")); | |
3940 | return 0; | |
3941 | } | |
3942 | ||
b40bf0a2 | 3943 | printf (_("\n Opcodes:\n")); |
19e6b90e | 3944 | |
b40bf0a2 | 3945 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
3946 | printf (ngettext (" Opcode %d has %d arg\n", |
3947 | " Opcode %d has %d args\n", | |
3948 | standard_opcodes[i - 1]), | |
3949 | i, standard_opcodes[i - 1]); | |
19e6b90e | 3950 | |
b40bf0a2 NC |
3951 | /* Display the contents of the Directory table. */ |
3952 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 3953 | |
77145576 | 3954 | if (linfo.li_version >= 5) |
b40bf0a2 | 3955 | { |
dda8d76d | 3956 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 3957 | |
77145576 | 3958 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 3959 | TRUE); |
77145576 | 3960 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 3961 | FALSE); |
77145576 JK |
3962 | } |
3963 | else | |
3964 | { | |
3965 | if (*data == 0) | |
3966 | printf (_("\n The Directory Table is empty.\n")); | |
3967 | else | |
a233b20c | 3968 | { |
77145576 | 3969 | unsigned int last_dir_entry = 0; |
6937bb54 | 3970 | |
77145576 JK |
3971 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
3972 | (long)(data - start)); | |
19e6b90e | 3973 | |
77145576 JK |
3974 | while (data < end && *data != 0) |
3975 | { | |
3976 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 3977 | |
77145576 JK |
3978 | data += strnlen ((char *) data, end - data) + 1; |
3979 | } | |
19e6b90e | 3980 | |
77145576 JK |
3981 | /* PR 17512: file: 002-132094-0.004. */ |
3982 | if (data >= end - 1) | |
3983 | break; | |
3984 | } | |
19e6b90e | 3985 | |
77145576 JK |
3986 | /* Skip the NUL at the end of the table. */ |
3987 | data++; | |
19e6b90e | 3988 | |
77145576 JK |
3989 | /* Display the contents of the File Name table. */ |
3990 | if (*data == 0) | |
3991 | printf (_("\n The File Name Table is empty.\n")); | |
3992 | else | |
3993 | { | |
3994 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
3995 | (long)(data - start)); | |
3996 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 3997 | |
77145576 | 3998 | while (data < end && *data != 0) |
b40bf0a2 | 3999 | { |
77145576 | 4000 | unsigned char *name; |
cd30bcef | 4001 | dwarf_vma val; |
77145576 JK |
4002 | |
4003 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
4004 | name = data; | |
4005 | data += strnlen ((char *) data, end - data) + 1; | |
4006 | ||
cd30bcef AM |
4007 | READ_ULEB (val, data, end); |
4008 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4009 | READ_ULEB (val, data, end); | |
4010 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4011 | READ_ULEB (val, data, end); | |
4012 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
77145576 JK |
4013 | printf ("%.*s\n", (int)(end - name), name); |
4014 | ||
4015 | if (data == end) | |
4016 | { | |
4017 | warn (_("Corrupt file name table entry\n")); | |
4018 | break; | |
4019 | } | |
b40bf0a2 | 4020 | } |
a233b20c | 4021 | } |
77145576 JK |
4022 | |
4023 | /* Skip the NUL at the end of the table. */ | |
4024 | data++; | |
b40bf0a2 | 4025 | } |
19e6b90e | 4026 | |
b40bf0a2 NC |
4027 | putchar ('\n'); |
4028 | saved_linfo = linfo; | |
4029 | } | |
19e6b90e | 4030 | |
b40bf0a2 NC |
4031 | /* Now display the statements. */ |
4032 | if (data >= end_of_sequence) | |
4033 | printf (_(" No Line Number Statements.\n")); | |
4034 | else | |
4035 | { | |
4036 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 4037 | |
b40bf0a2 NC |
4038 | while (data < end_of_sequence) |
4039 | { | |
4040 | unsigned char op_code; | |
4041 | dwarf_signed_vma adv; | |
4042 | dwarf_vma uladv; | |
19e6b90e | 4043 | |
fe59e83d CC |
4044 | printf (" [0x%08lx]", (long)(data - start)); |
4045 | ||
b40bf0a2 | 4046 | op_code = *data++; |
19e6b90e | 4047 | |
b40bf0a2 | 4048 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 4049 | { |
b40bf0a2 NC |
4050 | op_code -= linfo.li_opcode_base; |
4051 | uladv = (op_code / linfo.li_line_range); | |
4052 | if (linfo.li_max_ops_per_insn == 1) | |
4053 | { | |
4054 | uladv *= linfo.li_min_insn_length; | |
4055 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4056 | if (uladv) |
4057 | state_machine_regs.view = 0; | |
b40bf0a2 | 4058 | printf (_(" Special opcode %d: " |
ba8826a8 | 4059 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 4060 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4061 | dwarf_vmatoa ("x", state_machine_regs.address), |
4062 | verbose_view && uladv | |
4063 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4064 | } |
4065 | else | |
4066 | { | |
ba8826a8 AO |
4067 | unsigned addrdelta |
4068 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
4069 | / linfo.li_max_ops_per_insn) |
4070 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
4071 | |
4072 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
4073 | state_machine_regs.op_index |
4074 | = (state_machine_regs.op_index + uladv) | |
4075 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4076 | if (addrdelta) |
4077 | state_machine_regs.view = 0; | |
b40bf0a2 | 4078 | printf (_(" Special opcode %d: " |
ba8826a8 | 4079 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
4080 | op_code, dwarf_vmatoa ("u", uladv), |
4081 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4082 | state_machine_regs.op_index, |
4083 | verbose_view && addrdelta | |
4084 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4085 | } |
4086 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
4087 | state_machine_regs.line += adv; | |
ba8826a8 | 4088 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 4089 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
4090 | if (verbose_view || state_machine_regs.view) |
4091 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4092 | else | |
4093 | putchar ('\n'); | |
4094 | state_machine_regs.view++; | |
19e6b90e | 4095 | } |
cd30bcef AM |
4096 | else |
4097 | switch (op_code) | |
4098 | { | |
4099 | case DW_LNS_extended_op: | |
4100 | data += process_extended_line_op (data, | |
4101 | linfo.li_default_is_stmt, | |
4102 | end); | |
4103 | break; | |
4104 | ||
4105 | case DW_LNS_copy: | |
4106 | printf (_(" Copy")); | |
4107 | if (verbose_view || state_machine_regs.view) | |
4108 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4109 | else | |
4110 | putchar ('\n'); | |
4111 | state_machine_regs.view++; | |
4112 | break; | |
4113 | ||
4114 | case DW_LNS_advance_pc: | |
4115 | READ_ULEB (uladv, data, end); | |
4116 | if (linfo.li_max_ops_per_insn == 1) | |
4117 | { | |
4118 | uladv *= linfo.li_min_insn_length; | |
4119 | state_machine_regs.address += uladv; | |
4120 | if (uladv) | |
4121 | state_machine_regs.view = 0; | |
4122 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
4123 | dwarf_vmatoa ("u", uladv), | |
4124 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4125 | verbose_view && uladv | |
4126 | ? _(" (reset view)") : ""); | |
4127 | } | |
4128 | else | |
4129 | { | |
4130 | unsigned addrdelta | |
4131 | = ((state_machine_regs.op_index + uladv) | |
4132 | / linfo.li_max_ops_per_insn) | |
4133 | * linfo.li_min_insn_length; | |
4134 | state_machine_regs.address | |
4135 | += addrdelta; | |
4136 | state_machine_regs.op_index | |
4137 | = (state_machine_regs.op_index + uladv) | |
4138 | % linfo.li_max_ops_per_insn; | |
4139 | if (addrdelta) | |
4140 | state_machine_regs.view = 0; | |
4141 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
4142 | dwarf_vmatoa ("u", uladv), | |
4143 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4144 | state_machine_regs.op_index, | |
4145 | verbose_view && addrdelta | |
4146 | ? _(" (reset view)") : ""); | |
4147 | } | |
4148 | break; | |
4149 | ||
4150 | case DW_LNS_advance_line: | |
4151 | READ_SLEB (adv, data, end); | |
4152 | state_machine_regs.line += adv; | |
4153 | printf (_(" Advance Line by %s to %d\n"), | |
4154 | dwarf_vmatoa ("d", adv), | |
4155 | state_machine_regs.line); | |
4156 | break; | |
4157 | ||
4158 | case DW_LNS_set_file: | |
4159 | READ_ULEB (uladv, data, end); | |
4160 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
4161 | dwarf_vmatoa ("u", uladv)); | |
4162 | state_machine_regs.file = uladv; | |
4163 | break; | |
4164 | ||
4165 | case DW_LNS_set_column: | |
4166 | READ_ULEB (uladv, data, end); | |
4167 | printf (_(" Set column to %s\n"), | |
4168 | dwarf_vmatoa ("u", uladv)); | |
4169 | state_machine_regs.column = uladv; | |
4170 | break; | |
4171 | ||
4172 | case DW_LNS_negate_stmt: | |
4173 | adv = state_machine_regs.is_stmt; | |
4174 | adv = ! adv; | |
4175 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
4176 | state_machine_regs.is_stmt = adv; | |
4177 | break; | |
4178 | ||
4179 | case DW_LNS_set_basic_block: | |
4180 | printf (_(" Set basic block\n")); | |
4181 | state_machine_regs.basic_block = 1; | |
4182 | break; | |
4183 | ||
4184 | case DW_LNS_const_add_pc: | |
4185 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4186 | if (linfo.li_max_ops_per_insn) | |
4187 | { | |
4188 | uladv *= linfo.li_min_insn_length; | |
4189 | state_machine_regs.address += uladv; | |
4190 | if (uladv) | |
4191 | state_machine_regs.view = 0; | |
4192 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
4193 | dwarf_vmatoa ("u", uladv), | |
4194 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4195 | verbose_view && uladv | |
4196 | ? _(" (reset view)") : ""); | |
4197 | } | |
4198 | else | |
4199 | { | |
4200 | unsigned addrdelta | |
4201 | = ((state_machine_regs.op_index + uladv) | |
4202 | / linfo.li_max_ops_per_insn) | |
4203 | * linfo.li_min_insn_length; | |
4204 | state_machine_regs.address | |
4205 | += addrdelta; | |
4206 | state_machine_regs.op_index | |
4207 | = (state_machine_regs.op_index + uladv) | |
4208 | % linfo.li_max_ops_per_insn; | |
4209 | if (addrdelta) | |
4210 | state_machine_regs.view = 0; | |
4211 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
4212 | dwarf_vmatoa ("u", uladv), | |
4213 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4214 | state_machine_regs.op_index, | |
4215 | verbose_view && addrdelta | |
4216 | ? _(" (reset view)") : ""); | |
4217 | } | |
4218 | break; | |
4219 | ||
4220 | case DW_LNS_fixed_advance_pc: | |
4221 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4222 | state_machine_regs.address += uladv; | |
4223 | state_machine_regs.op_index = 0; | |
4224 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
4225 | dwarf_vmatoa ("u", uladv), | |
4226 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
4227 | /* Do NOT reset view. */ | |
4228 | break; | |
4229 | ||
4230 | case DW_LNS_set_prologue_end: | |
4231 | printf (_(" Set prologue_end to true\n")); | |
4232 | break; | |
4233 | ||
4234 | case DW_LNS_set_epilogue_begin: | |
4235 | printf (_(" Set epilogue_begin to true\n")); | |
4236 | break; | |
4237 | ||
4238 | case DW_LNS_set_isa: | |
4239 | READ_ULEB (uladv, data, end); | |
4240 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
4241 | break; | |
4242 | ||
4243 | default: | |
4244 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4245 | ||
4246 | if (standard_opcodes != NULL) | |
4247 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4248 | { | |
4249 | READ_ULEB (uladv, data, end); | |
4250 | printf ("0x%s%s", dwarf_vmatoa ("x", uladv), | |
4251 | i == 1 ? "" : ", "); | |
4252 | } | |
4253 | putchar ('\n'); | |
4254 | break; | |
4255 | } | |
19e6b90e | 4256 | } |
b40bf0a2 | 4257 | putchar ('\n'); |
19e6b90e | 4258 | } |
19e6b90e L |
4259 | } |
4260 | ||
4261 | return 1; | |
4262 | } | |
4263 | ||
a262ae96 NC |
4264 | typedef struct |
4265 | { | |
467c65bc NC |
4266 | unsigned char *name; |
4267 | unsigned int directory_index; | |
4268 | unsigned int modification_date; | |
4269 | unsigned int length; | |
a262ae96 NC |
4270 | } File_Entry; |
4271 | ||
4272 | /* Output a decoded representation of the .debug_line section. */ | |
4273 | ||
4274 | static int | |
dda8d76d | 4275 | display_debug_lines_decoded (struct dwarf_section * section, |
ec1b0fbb | 4276 | unsigned char * start, |
dda8d76d NC |
4277 | unsigned char * data, |
4278 | unsigned char * end, | |
4279 | void * fileptr) | |
a262ae96 | 4280 | { |
b40bf0a2 NC |
4281 | static DWARF2_Internal_LineInfo saved_linfo; |
4282 | ||
dda8d76d | 4283 | introduce (section, FALSE); |
a262ae96 NC |
4284 | |
4285 | while (data < end) | |
4286 | { | |
4287 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4288 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4289 | unsigned char *standard_opcodes; |
4290 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4291 | int i; |
4292 | File_Entry *file_table = NULL; | |
143a3db0 | 4293 | unsigned int n_files = 0; |
a262ae96 | 4294 | unsigned char **directory_table = NULL; |
77145576 | 4295 | dwarf_vma n_directories = 0; |
a262ae96 | 4296 | |
4925cdd7 NC |
4297 | if (const_strneq (section->name, ".debug_line.") |
4298 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4299 | These are full debug_line sections. */ | |
4300 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4301 | { |
4925cdd7 | 4302 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4303 | end_of_sequence = end; |
4304 | standard_opcodes = NULL; | |
4305 | linfo = saved_linfo; | |
058037d3 NC |
4306 | /* PR 17531: file: 0522b371. */ |
4307 | if (linfo.li_line_range == 0) | |
4308 | { | |
1306a742 | 4309 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4310 | return 0; |
4311 | } | |
b40bf0a2 | 4312 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4313 | } |
a262ae96 | 4314 | else |
b4eb7656 | 4315 | { |
b40bf0a2 | 4316 | unsigned char *hdrptr; |
a262ae96 | 4317 | |
b40bf0a2 NC |
4318 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4319 | & end_of_sequence)) == NULL) | |
a233b20c | 4320 | return 0; |
0c588247 | 4321 | |
058037d3 NC |
4322 | /* PR 17531: file: 0522b371. */ |
4323 | if (linfo.li_line_range == 0) | |
4324 | { | |
4325 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4326 | linfo.li_line_range = 1; | |
4327 | } | |
b40bf0a2 | 4328 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4329 | |
b40bf0a2 NC |
4330 | /* Save a pointer to the contents of the Opcodes table. */ |
4331 | standard_opcodes = hdrptr; | |
a262ae96 | 4332 | |
b40bf0a2 NC |
4333 | /* Traverse the Directory table just to count entries. */ |
4334 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4335 | /* PR 20440 */ |
4336 | if (data >= end) | |
4337 | { | |
4338 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4339 | linfo.li_opcode_base); | |
4340 | return 0; | |
4341 | } | |
4342 | ||
77145576 | 4343 | if (linfo.li_version >= 5) |
b40bf0a2 | 4344 | { |
77145576 JK |
4345 | unsigned char *format_start, format_count, *format; |
4346 | dwarf_vma formati, entryi; | |
a262ae96 | 4347 | |
dda8d76d | 4348 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4349 | |
4350 | /* Skip directories format. */ | |
4351 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4352 | if (do_checks && format_count > 1) |
4353 | warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"), | |
4354 | format_count); | |
77145576 JK |
4355 | format_start = data; |
4356 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4357 | { |
cd30bcef AM |
4358 | SKIP_ULEB (data, end); |
4359 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4360 | } |
a262ae96 | 4361 | |
cd30bcef | 4362 | READ_ULEB (n_directories, data, end); |
77145576 | 4363 | if (data == end) |
d8024a91 | 4364 | { |
77145576 | 4365 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
4366 | break; |
4367 | } | |
4368 | ||
070b775f NC |
4369 | if (n_directories == 0) |
4370 | directory_table = NULL; | |
4371 | else | |
4372 | directory_table = (unsigned char **) | |
4373 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 4374 | |
77145576 | 4375 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 4376 | { |
77145576 | 4377 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 4378 | |
77145576 JK |
4379 | format = format_start; |
4380 | for (formati = 0; formati < format_count; formati++) | |
4381 | { | |
4382 | dwarf_vma content_type, form; | |
4383 | dwarf_vma uvalue; | |
4384 | ||
cd30bcef AM |
4385 | READ_ULEB (content_type, format, end); |
4386 | READ_ULEB (form, format, end); | |
77145576 JK |
4387 | if (data == end) |
4388 | { | |
4389 | warn (_("Corrupt directories list\n")); | |
4390 | break; | |
4391 | } | |
4392 | switch (content_type) | |
4393 | { | |
4394 | case DW_LNCT_path: | |
4395 | switch (form) | |
4396 | { | |
4397 | case DW_FORM_string: | |
4398 | *pathp = data; | |
4399 | break; | |
4400 | case DW_FORM_line_strp: | |
4401 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4402 | end); | |
4403 | /* Remove const by the cast. */ | |
4404 | *pathp = (unsigned char *) | |
4405 | fetch_indirect_line_string (uvalue); | |
4406 | break; | |
4407 | } | |
4408 | break; | |
4409 | } | |
cd30bcef AM |
4410 | data = read_and_display_attr_value (0, form, 0, start, |
4411 | data, end, 0, 0, | |
77145576 JK |
4412 | linfo.li_offset_size, |
4413 | linfo.li_version, | |
4414 | NULL, 1, section, | |
ec1b0fbb | 4415 | NULL, '\t', -1); |
77145576 JK |
4416 | } |
4417 | if (data == end) | |
4418 | { | |
4419 | warn (_("Corrupt directories list\n")); | |
4420 | break; | |
4421 | } | |
4422 | } | |
a262ae96 | 4423 | |
77145576 JK |
4424 | /* Skip files format. */ |
4425 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4426 | if (do_checks && format_count > 5) |
4427 | warn (_("Unexpectedly large number of columns in the file name table (%u)\n"), | |
4428 | format_count); | |
77145576 JK |
4429 | format_start = data; |
4430 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4431 | { |
cd30bcef AM |
4432 | SKIP_ULEB (data, end); |
4433 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4434 | } |
a262ae96 | 4435 | |
cd30bcef | 4436 | READ_ULEB (n_files, data, end); |
070b775f | 4437 | if (data == end && n_files > 0) |
d8024a91 | 4438 | { |
77145576 | 4439 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
4440 | break; |
4441 | } | |
4442 | ||
070b775f NC |
4443 | if (n_files == 0) |
4444 | file_table = NULL; | |
4445 | else | |
4446 | file_table = (File_Entry *) xcalloc (1, n_files | |
4447 | * sizeof (File_Entry)); | |
a262ae96 | 4448 | |
77145576 | 4449 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 4450 | { |
77145576 | 4451 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 4452 | |
77145576 JK |
4453 | format = format_start; |
4454 | for (formati = 0; formati < format_count; formati++) | |
4455 | { | |
4456 | dwarf_vma content_type, form; | |
4457 | dwarf_vma uvalue; | |
cd30bcef | 4458 | unsigned char *tmp; |
77145576 | 4459 | |
cd30bcef AM |
4460 | READ_ULEB (content_type, format, end); |
4461 | READ_ULEB (form, format, end); | |
77145576 JK |
4462 | if (data == end) |
4463 | { | |
4464 | warn (_("Corrupt file name list\n")); | |
4465 | break; | |
4466 | } | |
4467 | switch (content_type) | |
4468 | { | |
4469 | case DW_LNCT_path: | |
4470 | switch (form) | |
4471 | { | |
4472 | case DW_FORM_string: | |
4473 | file->name = data; | |
4474 | break; | |
4475 | case DW_FORM_line_strp: | |
4476 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4477 | end); | |
4478 | /* Remove const by the cast. */ | |
4479 | file->name = (unsigned char *) | |
4480 | fetch_indirect_line_string (uvalue); | |
4481 | break; | |
4482 | } | |
4483 | break; | |
4484 | case DW_LNCT_directory_index: | |
4485 | switch (form) | |
4486 | { | |
4487 | case DW_FORM_data1: | |
4488 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
4489 | end); | |
4490 | break; | |
4491 | case DW_FORM_data2: | |
4492 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
4493 | end); | |
4494 | break; | |
4495 | case DW_FORM_udata: | |
cd30bcef AM |
4496 | tmp = data; |
4497 | READ_ULEB (file->directory_index, tmp, end); | |
77145576 JK |
4498 | break; |
4499 | } | |
4500 | break; | |
4501 | } | |
cd30bcef AM |
4502 | data = read_and_display_attr_value (0, form, 0, start, |
4503 | data, end, 0, 0, | |
77145576 JK |
4504 | linfo.li_offset_size, |
4505 | linfo.li_version, | |
4506 | NULL, 1, section, | |
ec1b0fbb | 4507 | NULL, '\t', -1); |
77145576 JK |
4508 | } |
4509 | if (data == end) | |
4510 | { | |
4511 | warn (_("Corrupt file name list\n")); | |
4512 | break; | |
4513 | } | |
4514 | } | |
4515 | } | |
4516 | else | |
4517 | { | |
4518 | if (*data != 0) | |
b40bf0a2 | 4519 | { |
77145576 JK |
4520 | unsigned char *ptr_directory_table = data; |
4521 | ||
4522 | while (data < end && *data != 0) | |
4523 | { | |
4524 | data += strnlen ((char *) data, end - data) + 1; | |
4525 | n_directories++; | |
4526 | } | |
4527 | ||
4528 | /* PR 20440 */ | |
4529 | if (data >= end) | |
4530 | { | |
4531 | warn (_("directory table ends unexpectedly\n")); | |
4532 | n_directories = 0; | |
4533 | break; | |
4534 | } | |
4535 | ||
4536 | /* Go through the directory table again to save the directories. */ | |
4537 | directory_table = (unsigned char **) | |
4538 | xmalloc (n_directories * sizeof (unsigned char *)); | |
4539 | ||
4540 | i = 0; | |
4541 | while (*ptr_directory_table != 0) | |
4542 | { | |
4543 | directory_table[i] = ptr_directory_table; | |
4544 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
4545 | ptr_directory_table - end) + 1; | |
4546 | i++; | |
4547 | } | |
b40bf0a2 | 4548 | } |
77145576 JK |
4549 | /* Skip the NUL at the end of the table. */ |
4550 | data++; | |
4551 | ||
4552 | /* Traverse the File Name table just to count the entries. */ | |
4553 | if (data < end && *data != 0) | |
b40bf0a2 | 4554 | { |
77145576 JK |
4555 | unsigned char *ptr_file_name_table = data; |
4556 | ||
4557 | while (data < end && *data != 0) | |
db9537d2 | 4558 | { |
cd30bcef AM |
4559 | /* Skip Name, directory index, last modification |
4560 | time and length of file. */ | |
77145576 | 4561 | data += strnlen ((char *) data, end - data) + 1; |
cd30bcef AM |
4562 | SKIP_ULEB (data, end); |
4563 | SKIP_ULEB (data, end); | |
4564 | SKIP_ULEB (data, end); | |
77145576 | 4565 | n_files++; |
db9537d2 | 4566 | } |
a262ae96 | 4567 | |
77145576 JK |
4568 | if (data >= end) |
4569 | { | |
4570 | warn (_("file table ends unexpectedly\n")); | |
4571 | n_files = 0; | |
4572 | break; | |
4573 | } | |
4574 | ||
4575 | /* Go through the file table again to save the strings. */ | |
4576 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 4577 | |
77145576 JK |
4578 | i = 0; |
4579 | while (*ptr_file_name_table != 0) | |
4580 | { | |
77145576 JK |
4581 | file_table[i].name = ptr_file_name_table; |
4582 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
4583 | end - ptr_file_name_table) + 1; | |
4584 | ||
4585 | /* We are not interested in directory, time or size. */ | |
cd30bcef AM |
4586 | READ_ULEB (file_table[i].directory_index, |
4587 | ptr_file_name_table, end); | |
4588 | READ_ULEB (file_table[i].modification_date, | |
4589 | ptr_file_name_table, end); | |
4590 | READ_ULEB (file_table[i].length, | |
4591 | ptr_file_name_table, end); | |
77145576 JK |
4592 | i++; |
4593 | } | |
4594 | i = 0; | |
b40bf0a2 | 4595 | } |
77145576 JK |
4596 | |
4597 | /* Skip the NUL at the end of the table. */ | |
4598 | data++; | |
b40bf0a2 | 4599 | } |
cc5914eb | 4600 | |
77145576 | 4601 | /* Print the Compilation Unit's name and a header. */ |
f082820d | 4602 | if (file_table == NULL) |
070b775f | 4603 | printf (_("CU: No directory table\n")); |
f082820d AM |
4604 | else if (directory_table == NULL) |
4605 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
4606 | else |
4607 | { | |
4608 | unsigned int ix = file_table[0].directory_index; | |
4609 | const char *directory; | |
4610 | ||
4611 | if (ix == 0) | |
4612 | directory = "."; | |
4613 | /* PR 20439 */ | |
4614 | else if (n_directories == 0) | |
4615 | directory = _("<unknown>"); | |
4616 | else if (ix > n_directories) | |
4617 | { | |
4618 | warn (_("directory index %u > number of directories %s\n"), | |
4619 | ix, dwarf_vmatoa ("u", n_directories)); | |
4620 | directory = _("<corrupt>"); | |
4621 | } | |
4622 | else | |
4623 | directory = (char *) directory_table[ix - 1]; | |
4624 | ||
4625 | if (do_wide || strlen (directory) < 76) | |
4626 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
4627 | else | |
4628 | printf ("%s:\n", file_table[0].name); | |
77145576 | 4629 | } |
a262ae96 | 4630 | |
070b775f NC |
4631 | if (n_files > 0) |
4632 | printf (_("File name Line number Starting address View Stmt\n")); | |
4633 | else | |
4634 | printf (_("CU: Empty file name table\n")); | |
b40bf0a2 NC |
4635 | saved_linfo = linfo; |
4636 | } | |
a262ae96 NC |
4637 | |
4638 | /* This loop iterates through the Dwarf Line Number Program. */ | |
4639 | while (data < end_of_sequence) | |
b4eb7656 | 4640 | { |
a262ae96 | 4641 | unsigned char op_code; |
ba8826a8 | 4642 | int xop; |
b4eb7656 AM |
4643 | int adv; |
4644 | unsigned long int uladv; | |
b4eb7656 | 4645 | int is_special_opcode = 0; |
a262ae96 | 4646 | |
b4eb7656 | 4647 | op_code = *data++; |
ba8826a8 | 4648 | xop = op_code; |
a262ae96 | 4649 | |
b4eb7656 | 4650 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 4651 | { |
91d6fa6a | 4652 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
4653 | uladv = (op_code / linfo.li_line_range); |
4654 | if (linfo.li_max_ops_per_insn == 1) | |
4655 | { | |
4656 | uladv *= linfo.li_min_insn_length; | |
4657 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4658 | if (uladv) |
4659 | state_machine_regs.view = 0; | |
a233b20c JJ |
4660 | } |
4661 | else | |
4662 | { | |
ba8826a8 AO |
4663 | unsigned addrdelta |
4664 | = ((state_machine_regs.op_index + uladv) | |
4665 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4666 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4667 | state_machine_regs.address |
4668 | += addrdelta; | |
a233b20c JJ |
4669 | state_machine_regs.op_index |
4670 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 4671 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
4672 | if (addrdelta) |
4673 | state_machine_regs.view = 0; | |
a233b20c | 4674 | } |
a262ae96 | 4675 | |
b4eb7656 AM |
4676 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
4677 | state_machine_regs.line += adv; | |
4678 | is_special_opcode = 1; | |
ba8826a8 | 4679 | /* Increment view after printing this row. */ |
b4eb7656 | 4680 | } |
cd30bcef AM |
4681 | else |
4682 | switch (op_code) | |
4683 | { | |
4684 | case DW_LNS_extended_op: | |
4685 | { | |
4686 | unsigned int ext_op_code_len; | |
4687 | unsigned char ext_op_code; | |
4688 | unsigned char *op_code_end; | |
4689 | unsigned char *op_code_data = data; | |
4690 | ||
4691 | READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence); | |
4692 | op_code_end = op_code_data + ext_op_code_len; | |
4693 | if (ext_op_code_len == 0 || op_code_end > end_of_sequence) | |
4694 | { | |
4695 | warn (_("Badly formed extended line op encountered!\n")); | |
4696 | break; | |
4697 | } | |
4698 | ext_op_code = *op_code_data++; | |
4699 | xop = ext_op_code; | |
4700 | xop = -xop; | |
4701 | ||
4702 | switch (ext_op_code) | |
4703 | { | |
4704 | case DW_LNE_end_sequence: | |
4705 | /* Reset stuff after printing this row. */ | |
4706 | break; | |
4707 | case DW_LNE_set_address: | |
4708 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
4709 | op_code_data, | |
4710 | op_code_end - op_code_data, | |
4711 | op_code_end); | |
4712 | state_machine_regs.op_index = 0; | |
4713 | state_machine_regs.view = 0; | |
4714 | break; | |
4715 | case DW_LNE_define_file: | |
4716 | file_table = (File_Entry *) xrealloc | |
4717 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
4718 | ||
4719 | ++state_machine_regs.last_file_entry; | |
4720 | /* Source file name. */ | |
4721 | file_table[n_files].name = op_code_data; | |
4722 | op_code_data += strlen ((char *) op_code_data) + 1; | |
4723 | /* Directory index. */ | |
4724 | READ_ULEB (file_table[n_files].directory_index, | |
4725 | op_code_data, op_code_end); | |
4726 | /* Last modification time. */ | |
4727 | READ_ULEB (file_table[n_files].modification_date, | |
4728 | op_code_data, op_code_end); | |
4729 | /* File length. */ | |
4730 | READ_ULEB (file_table[n_files].length, | |
4731 | op_code_data, op_code_end); | |
4732 | n_files++; | |
4733 | break; | |
4734 | ||
4735 | case DW_LNE_set_discriminator: | |
4736 | case DW_LNE_HP_set_sequence: | |
4737 | /* Simply ignored. */ | |
4738 | break; | |
4739 | ||
4740 | default: | |
4741 | printf (_("UNKNOWN (%u): length %ld\n"), | |
27653fba | 4742 | ext_op_code, (long int) (op_code_data - data)); |
cd30bcef AM |
4743 | break; |
4744 | } | |
4745 | data = op_code_end; | |
4746 | break; | |
4747 | } | |
4748 | case DW_LNS_copy: | |
4749 | /* Increment view after printing this row. */ | |
4750 | break; | |
4751 | ||
4752 | case DW_LNS_advance_pc: | |
4753 | READ_ULEB (uladv, data, end); | |
4754 | if (linfo.li_max_ops_per_insn == 1) | |
4755 | { | |
4756 | uladv *= linfo.li_min_insn_length; | |
4757 | state_machine_regs.address += uladv; | |
4758 | if (uladv) | |
4759 | state_machine_regs.view = 0; | |
4760 | } | |
4761 | else | |
4762 | { | |
4763 | unsigned addrdelta | |
4764 | = ((state_machine_regs.op_index + uladv) | |
4765 | / linfo.li_max_ops_per_insn) | |
4766 | * linfo.li_min_insn_length; | |
4767 | state_machine_regs.address | |
4768 | += addrdelta; | |
4769 | state_machine_regs.op_index | |
4770 | = (state_machine_regs.op_index + uladv) | |
4771 | % linfo.li_max_ops_per_insn; | |
4772 | if (addrdelta) | |
4773 | state_machine_regs.view = 0; | |
4774 | } | |
4775 | break; | |
4776 | ||
4777 | case DW_LNS_advance_line: | |
4778 | READ_SLEB (adv, data, end); | |
4779 | state_machine_regs.line += adv; | |
4780 | break; | |
4781 | ||
4782 | case DW_LNS_set_file: | |
4783 | READ_ULEB (uladv, data, end); | |
4784 | state_machine_regs.file = uladv; | |
4785 | ||
4786 | { | |
4787 | unsigned file = state_machine_regs.file - 1; | |
4788 | unsigned dir; | |
4789 | ||
4790 | if (file_table == NULL || n_files == 0) | |
4791 | printf (_("\n [Use file table entry %d]\n"), file); | |
4792 | /* PR 20439 */ | |
4793 | else if (file >= n_files) | |
4794 | { | |
4795 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
4796 | printf (_("\n <over large file table index %u>"), file); | |
4797 | } | |
4798 | else if ((dir = file_table[file].directory_index) == 0) | |
4799 | /* If directory index is 0, that means current directory. */ | |
4800 | printf ("\n./%s:[++]\n", file_table[file].name); | |
4801 | else if (directory_table == NULL || n_directories == 0) | |
4802 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
4803 | file_table[file].name, dir); | |
4804 | /* PR 20439 */ | |
4805 | else if (dir > n_directories) | |
4806 | { | |
4807 | warn (_("directory index %u > number of directories %s\n"), | |
4808 | dir, dwarf_vmatoa ("u", n_directories)); | |
4809 | printf (_("\n <over large directory table entry %u>\n"), dir); | |
4810 | } | |
4811 | else | |
4812 | printf ("\n%s/%s:\n", | |
4813 | /* The directory index starts counting at 1. */ | |
4814 | directory_table[dir - 1], file_table[file].name); | |
4815 | } | |
4816 | break; | |
4817 | ||
4818 | case DW_LNS_set_column: | |
4819 | READ_ULEB (uladv, data, end); | |
4820 | state_machine_regs.column = uladv; | |
4821 | break; | |
4822 | ||
4823 | case DW_LNS_negate_stmt: | |
4824 | adv = state_machine_regs.is_stmt; | |
4825 | adv = ! adv; | |
4826 | state_machine_regs.is_stmt = adv; | |
4827 | break; | |
4828 | ||
4829 | case DW_LNS_set_basic_block: | |
4830 | state_machine_regs.basic_block = 1; | |
4831 | break; | |
4832 | ||
4833 | case DW_LNS_const_add_pc: | |
4834 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4835 | if (linfo.li_max_ops_per_insn == 1) | |
4836 | { | |
4837 | uladv *= linfo.li_min_insn_length; | |
4838 | state_machine_regs.address += uladv; | |
4839 | if (uladv) | |
4840 | state_machine_regs.view = 0; | |
4841 | } | |
4842 | else | |
4843 | { | |
4844 | unsigned addrdelta | |
4845 | = ((state_machine_regs.op_index + uladv) | |
4846 | / linfo.li_max_ops_per_insn) | |
4847 | * linfo.li_min_insn_length; | |
4848 | state_machine_regs.address | |
4849 | += addrdelta; | |
4850 | state_machine_regs.op_index | |
4851 | = (state_machine_regs.op_index + uladv) | |
4852 | % linfo.li_max_ops_per_insn; | |
4853 | if (addrdelta) | |
4854 | state_machine_regs.view = 0; | |
4855 | } | |
4856 | break; | |
4857 | ||
4858 | case DW_LNS_fixed_advance_pc: | |
4859 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4860 | state_machine_regs.address += uladv; | |
4861 | state_machine_regs.op_index = 0; | |
4862 | /* Do NOT reset view. */ | |
4863 | break; | |
4864 | ||
4865 | case DW_LNS_set_prologue_end: | |
4866 | break; | |
4867 | ||
4868 | case DW_LNS_set_epilogue_begin: | |
4869 | break; | |
4870 | ||
4871 | case DW_LNS_set_isa: | |
4872 | READ_ULEB (uladv, data, end); | |
4873 | printf (_(" Set ISA to %lu\n"), uladv); | |
4874 | break; | |
4875 | ||
4876 | default: | |
4877 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4878 | ||
4879 | if (standard_opcodes != NULL) | |
4880 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4881 | { | |
4882 | dwarf_vma val; | |
4883 | ||
4884 | READ_ULEB (val, data, end); | |
4885 | printf ("0x%s%s", dwarf_vmatoa ("x", val), | |
4886 | i == 1 ? "" : ", "); | |
4887 | } | |
4888 | putchar ('\n'); | |
4889 | break; | |
4890 | } | |
a262ae96 | 4891 | |
b4eb7656 AM |
4892 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
4893 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
4894 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
4895 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
4896 | { |
4897 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
4898 | char *fileName; | |
4899 | char *newFileName = NULL; | |
4900 | size_t fileNameLength; | |
b40bf0a2 NC |
4901 | |
4902 | if (file_table) | |
db9537d2 NC |
4903 | { |
4904 | unsigned indx = state_machine_regs.file - 1; | |
4905 | /* PR 20439 */ | |
4906 | if (indx >= n_files) | |
4907 | { | |
4908 | warn (_("corrupt file index %u encountered\n"), indx); | |
4909 | fileName = _("<corrupt>"); | |
4910 | } | |
4911 | else | |
4912 | fileName = (char *) file_table[indx].name; | |
4913 | } | |
b40bf0a2 | 4914 | else |
db9537d2 | 4915 | fileName = _("<unknown>"); |
b40bf0a2 NC |
4916 | |
4917 | fileNameLength = strlen (fileName); | |
a262ae96 | 4918 | |
b4eb7656 AM |
4919 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
4920 | { | |
4921 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
4922 | /* Truncate file name */ | |
4923 | strncpy (newFileName, | |
4924 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
4925 | MAX_FILENAME_LENGTH + 1); | |
e1104d08 NC |
4926 | /* FIXME: This is to pacify gcc-10 which can warn that the |
4927 | strncpy above might leave a non-NUL terminated string | |
4928 | in newFileName. It won't, but gcc's analysis doesn't | |
4929 | quite go far enough to discover this. */ | |
4930 | newFileName[MAX_FILENAME_LENGTH] = 0; | |
b4eb7656 AM |
4931 | } |
4932 | else | |
4933 | { | |
4934 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
4935 | strncpy (newFileName, fileName, fileNameLength + 1); | |
4936 | } | |
4937 | ||
4938 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) | |
4939 | { | |
a233b20c | 4940 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 4941 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 4942 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4943 | state_machine_regs.address); |
4944 | else | |
ba8826a8 | 4945 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 4946 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4947 | state_machine_regs.address, |
4948 | state_machine_regs.op_index); | |
b4eb7656 AM |
4949 | } |
4950 | else | |
4951 | { | |
a233b20c | 4952 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 4953 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 4954 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4955 | state_machine_regs.address); |
4956 | else | |
ba8826a8 | 4957 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 4958 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4959 | state_machine_regs.address, |
4960 | state_machine_regs.op_index); | |
b4eb7656 | 4961 | } |
a262ae96 | 4962 | |
ba8826a8 | 4963 | if (state_machine_regs.view) |
17f6ade2 | 4964 | printf (" %6u", state_machine_regs.view); |
ba8826a8 | 4965 | else |
17f6ade2 JD |
4966 | printf (" "); |
4967 | ||
4968 | if (state_machine_regs.is_stmt) | |
4969 | printf (" x"); | |
4970 | ||
4971 | putchar ('\n'); | |
ba8826a8 AO |
4972 | state_machine_regs.view++; |
4973 | ||
4974 | if (xop == -DW_LNE_end_sequence) | |
4975 | { | |
4976 | reset_state_machine (linfo.li_default_is_stmt); | |
4977 | putchar ('\n'); | |
4978 | } | |
a262ae96 | 4979 | |
b4eb7656 AM |
4980 | free (newFileName); |
4981 | } | |
4982 | } | |
b40bf0a2 NC |
4983 | |
4984 | if (file_table) | |
4985 | { | |
4986 | free (file_table); | |
4987 | file_table = NULL; | |
4988 | n_files = 0; | |
4989 | } | |
4990 | ||
4991 | if (directory_table) | |
4992 | { | |
4993 | free (directory_table); | |
4994 | directory_table = NULL; | |
4995 | n_directories = 0; | |
4996 | } | |
4997 | ||
a262ae96 NC |
4998 | putchar ('\n'); |
4999 | } | |
5000 | ||
5001 | return 1; | |
5002 | } | |
5003 | ||
5004 | static int | |
77145576 | 5005 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
5006 | { |
5007 | unsigned char *data = section->start; | |
5008 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
5009 | int retValRaw = 1; |
5010 | int retValDecoded = 1; | |
a262ae96 | 5011 | |
008f4c78 NC |
5012 | if (do_debug_lines == 0) |
5013 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
5014 | ||
4cb93e3b | 5015 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 5016 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 5017 | |
4cb93e3b | 5018 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
ec1b0fbb | 5019 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
a262ae96 | 5020 | |
4cb93e3b | 5021 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
5022 | return 0; |
5023 | ||
5024 | return 1; | |
5025 | } | |
5026 | ||
6e3d6dc1 NC |
5027 | static debug_info * |
5028 | find_debug_info_for_offset (unsigned long offset) | |
5029 | { | |
5030 | unsigned int i; | |
5031 | ||
5032 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
5033 | return NULL; | |
5034 | ||
5035 | for (i = 0; i < num_debug_info_entries; i++) | |
5036 | if (debug_information[i].cu_offset == offset) | |
5037 | return debug_information + i; | |
5038 | ||
5039 | return NULL; | |
5040 | } | |
5041 | ||
459d52c8 DE |
5042 | static const char * |
5043 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
5044 | { | |
5045 | /* See gdb/gdb-index.h. */ | |
5046 | static const char * const kinds[] = | |
5047 | { | |
5048 | N_ ("no info"), | |
5049 | N_ ("type"), | |
5050 | N_ ("variable"), | |
5051 | N_ ("function"), | |
5052 | N_ ("other"), | |
5053 | N_ ("unused5"), | |
5054 | N_ ("unused6"), | |
5055 | N_ ("unused7") | |
5056 | }; | |
5057 | ||
5058 | return _ (kinds[kind]); | |
5059 | } | |
5060 | ||
19e6b90e | 5061 | static int |
459d52c8 DE |
5062 | display_debug_pubnames_worker (struct dwarf_section *section, |
5063 | void *file ATTRIBUTE_UNUSED, | |
5064 | int is_gnu) | |
19e6b90e | 5065 | { |
91d6fa6a | 5066 | DWARF2_Internal_PubNames names; |
19e6b90e L |
5067 | unsigned char *start = section->start; |
5068 | unsigned char *end = start + section->size; | |
5069 | ||
6e3d6dc1 NC |
5070 | /* It does not matter if this load fails, |
5071 | we test for that later on. */ | |
5072 | load_debug_info (file); | |
5073 | ||
dda8d76d | 5074 | introduce (section, FALSE); |
19e6b90e L |
5075 | |
5076 | while (start < end) | |
5077 | { | |
5078 | unsigned char *data; | |
e98fdf1a | 5079 | unsigned long sec_off; |
bf5117e3 | 5080 | unsigned int offset_size, initial_length_size; |
19e6b90e | 5081 | |
e98fdf1a | 5082 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 5083 | if (names.pn_length == 0xffffffff) |
19e6b90e | 5084 | { |
e98fdf1a | 5085 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e L |
5086 | offset_size = 8; |
5087 | initial_length_size = 12; | |
5088 | } | |
5089 | else | |
5090 | { | |
5091 | offset_size = 4; | |
5092 | initial_length_size = 4; | |
5093 | } | |
5094 | ||
e98fdf1a AM |
5095 | sec_off = start - section->start; |
5096 | if (sec_off + names.pn_length < sec_off | |
5097 | || sec_off + names.pn_length > section->size) | |
5098 | { | |
5099 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
5100 | section->name, | |
5101 | sec_off - initial_length_size, | |
5102 | dwarf_vmatoa ("x", names.pn_length)); | |
5103 | break; | |
5104 | } | |
5105 | ||
5106 | data = start; | |
5107 | start += names.pn_length; | |
5108 | ||
0c588247 NC |
5109 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
5110 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
5111 | |
5112 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
5113 | && num_debug_info_entries > 0 | |
91d6fa6a | 5114 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 5115 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 5116 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 5117 | |
0c588247 | 5118 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 5119 | |
058037d3 NC |
5120 | printf (_(" Length: %ld\n"), |
5121 | (long) names.pn_length); | |
5122 | printf (_(" Version: %d\n"), | |
5123 | names.pn_version); | |
5124 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
5125 | (unsigned long) names.pn_offset); | |
5126 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
5127 | (long) names.pn_size); | |
19e6b90e | 5128 | |
91d6fa6a | 5129 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
5130 | { |
5131 | static int warned = 0; | |
5132 | ||
5133 | if (! warned) | |
5134 | { | |
5135 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
5136 | warned = 1; | |
5137 | } | |
5138 | ||
5139 | continue; | |
5140 | } | |
5141 | ||
459d52c8 DE |
5142 | if (is_gnu) |
5143 | printf (_("\n Offset Kind Name\n")); | |
5144 | else | |
5145 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 5146 | |
e98fdf1a | 5147 | while (1) |
19e6b90e | 5148 | { |
f41e4712 | 5149 | bfd_size_type maxprint; |
e98fdf1a | 5150 | dwarf_vma offset; |
f41e4712 | 5151 | |
0c588247 | 5152 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e | 5153 | |
e98fdf1a AM |
5154 | if (offset == 0) |
5155 | break; | |
b4eb7656 | 5156 | |
e98fdf1a AM |
5157 | data += offset_size; |
5158 | if (data >= end) | |
5159 | break; | |
5160 | maxprint = (end - data) - 1; | |
f41e4712 | 5161 | |
e98fdf1a AM |
5162 | if (is_gnu) |
5163 | { | |
5164 | unsigned int kind_data; | |
5165 | gdb_index_symbol_kind kind; | |
5166 | const char *kind_name; | |
5167 | int is_static; | |
5168 | ||
5169 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
5170 | data++; | |
5171 | maxprint --; | |
5172 | /* GCC computes the kind as the upper byte in the CU index | |
5173 | word, and then right shifts it by the CU index size. | |
5174 | Left shift KIND to where the gdb-index.h accessor macros | |
5175 | can use it. */ | |
5176 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
5177 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
5178 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
5179 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
5180 | printf (" %-6lx %s,%-10s %.*s\n", | |
5181 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
5182 | kind_name, (int) maxprint, data); | |
19e6b90e | 5183 | } |
e98fdf1a AM |
5184 | else |
5185 | printf (" %-6lx\t%.*s\n", | |
5186 | (unsigned long) offset, (int) maxprint, data); | |
5187 | ||
5188 | data += strnlen ((char *) data, maxprint) + 1; | |
5189 | if (data >= end) | |
5190 | break; | |
19e6b90e | 5191 | } |
19e6b90e L |
5192 | } |
5193 | ||
5194 | printf ("\n"); | |
5195 | return 1; | |
5196 | } | |
5197 | ||
459d52c8 DE |
5198 | static int |
5199 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
5200 | { | |
5201 | return display_debug_pubnames_worker (section, file, 0); | |
5202 | } | |
5203 | ||
5204 | static int | |
5205 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
5206 | { | |
5207 | return display_debug_pubnames_worker (section, file, 1); | |
5208 | } | |
5209 | ||
19e6b90e L |
5210 | static int |
5211 | display_debug_macinfo (struct dwarf_section *section, | |
5212 | void *file ATTRIBUTE_UNUSED) | |
5213 | { | |
5214 | unsigned char *start = section->start; | |
5215 | unsigned char *end = start + section->size; | |
5216 | unsigned char *curr = start; | |
19e6b90e L |
5217 | enum dwarf_macinfo_record_type op; |
5218 | ||
dda8d76d | 5219 | introduce (section, FALSE); |
19e6b90e L |
5220 | |
5221 | while (curr < end) | |
5222 | { | |
5223 | unsigned int lineno; | |
0c588247 | 5224 | const unsigned char *string; |
19e6b90e | 5225 | |
3f5e193b | 5226 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
5227 | curr++; |
5228 | ||
5229 | switch (op) | |
5230 | { | |
5231 | case DW_MACINFO_start_file: | |
5232 | { | |
5233 | unsigned int filenum; | |
5234 | ||
cd30bcef AM |
5235 | READ_ULEB (lineno, curr, end); |
5236 | READ_ULEB (filenum, curr, end); | |
19e6b90e L |
5237 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), |
5238 | lineno, filenum); | |
5239 | } | |
5240 | break; | |
5241 | ||
5242 | case DW_MACINFO_end_file: | |
5243 | printf (_(" DW_MACINFO_end_file\n")); | |
5244 | break; | |
5245 | ||
5246 | case DW_MACINFO_define: | |
cd30bcef | 5247 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5248 | string = curr; |
5249 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5250 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
5251 | lineno, string); | |
5252 | break; | |
5253 | ||
5254 | case DW_MACINFO_undef: | |
cd30bcef | 5255 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5256 | string = curr; |
5257 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5258 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
5259 | lineno, string); | |
5260 | break; | |
5261 | ||
5262 | case DW_MACINFO_vendor_ext: | |
5263 | { | |
5264 | unsigned int constant; | |
5265 | ||
cd30bcef | 5266 | READ_ULEB (constant, curr, end); |
0c588247 NC |
5267 | string = curr; |
5268 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5269 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
5270 | constant, string); | |
5271 | } | |
5272 | break; | |
5273 | } | |
5274 | } | |
5275 | ||
5276 | return 1; | |
5277 | } | |
5278 | ||
4ccf1e31 JJ |
5279 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5280 | filename and dirname corresponding to file name table entry with index | |
5281 | FILEIDX. Return NULL on failure. */ | |
5282 | ||
5283 | static unsigned char * | |
f6f0e17b NC |
5284 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5285 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5286 | unsigned char **dir_name) |
5287 | { | |
5288 | struct dwarf_section *section = &debug_displays [line].section; | |
5289 | unsigned char *hdrptr, *dirtable, *file_name; | |
5290 | unsigned int offset_size, initial_length_size; | |
cd30bcef | 5291 | unsigned int version, opcode_base; |
4ccf1e31 | 5292 | dwarf_vma length, diridx; |
f6f0e17b | 5293 | const unsigned char * end; |
4ccf1e31 JJ |
5294 | |
5295 | *dir_name = NULL; | |
5296 | if (section->start == NULL | |
5297 | || line_offset >= section->size | |
5298 | || fileidx == 0) | |
5299 | return NULL; | |
5300 | ||
5301 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5302 | end = section->start + section->size; |
0c588247 NC |
5303 | |
5304 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5305 | if (length == 0xffffffff) |
5306 | { | |
5307 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5308 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
5309 | offset_size = 8; |
5310 | initial_length_size = 12; | |
5311 | } | |
5312 | else | |
5313 | { | |
5314 | offset_size = 4; | |
5315 | initial_length_size = 4; | |
5316 | } | |
e98fdf1a AM |
5317 | if (length + initial_length_size < length |
5318 | || length + initial_length_size > section->size) | |
4ccf1e31 | 5319 | return NULL; |
0c588247 NC |
5320 | |
5321 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5322 | if (version != 2 && version != 3 && version != 4) |
5323 | return NULL; | |
5324 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5325 | if (version >= 4) | |
5326 | hdrptr++; /* Skip max_ops_per_insn. */ | |
5327 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
5328 | |
5329 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
5330 | if (opcode_base == 0) |
5331 | return NULL; | |
0c588247 | 5332 | |
4ccf1e31 | 5333 | hdrptr += opcode_base - 1; |
5c1c468d NC |
5334 | if (hdrptr >= end) |
5335 | return NULL; | |
5336 | ||
4ccf1e31 JJ |
5337 | dirtable = hdrptr; |
5338 | /* Skip over dirname table. */ | |
5339 | while (*hdrptr != '\0') | |
5c1c468d NC |
5340 | { |
5341 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; | |
5342 | if (hdrptr >= end) | |
5343 | return NULL; | |
5344 | } | |
4ccf1e31 | 5345 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 5346 | |
4ccf1e31 | 5347 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 5348 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 5349 | { |
0c588247 | 5350 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
cd30bcef AM |
5351 | SKIP_ULEB (hdrptr, end); |
5352 | SKIP_ULEB (hdrptr, end); | |
5353 | SKIP_ULEB (hdrptr, end); | |
4ccf1e31 | 5354 | } |
5c1c468d | 5355 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 5356 | return NULL; |
5c1c468d | 5357 | |
4ccf1e31 | 5358 | file_name = hdrptr; |
0c588247 | 5359 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
5c1c468d NC |
5360 | if (hdrptr >= end) |
5361 | return NULL; | |
cd30bcef | 5362 | READ_ULEB (diridx, hdrptr, end); |
4ccf1e31 JJ |
5363 | if (diridx == 0) |
5364 | return file_name; | |
5c1c468d | 5365 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
0c588247 | 5366 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
5c1c468d | 5367 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
5368 | return NULL; |
5369 | *dir_name = dirtable; | |
5370 | return file_name; | |
5371 | } | |
5372 | ||
5373 | static int | |
5374 | display_debug_macro (struct dwarf_section *section, | |
5375 | void *file) | |
5376 | { | |
5377 | unsigned char *start = section->start; | |
5378 | unsigned char *end = start + section->size; | |
5379 | unsigned char *curr = start; | |
5380 | unsigned char *extended_op_buf[256]; | |
4ccf1e31 | 5381 | |
dda8d76d NC |
5382 | load_debug_section_with_follow (str, file); |
5383 | load_debug_section_with_follow (line, file); | |
4ccf1e31 | 5384 | |
dda8d76d | 5385 | introduce (section, FALSE); |
4ccf1e31 JJ |
5386 | |
5387 | while (curr < end) | |
5388 | { | |
5389 | unsigned int lineno, version, flags; | |
5390 | unsigned int offset_size = 4; | |
0c588247 | 5391 | const unsigned char *string; |
4ccf1e31 JJ |
5392 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
5393 | unsigned char **extended_ops = NULL; | |
5394 | ||
0c588247 | 5395 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 5396 | if (version != 4 && version != 5) |
4ccf1e31 | 5397 | { |
7a7e1061 | 5398 | error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"), |
4ccf1e31 JJ |
5399 | section->name); |
5400 | return 0; | |
5401 | } | |
5402 | ||
0c588247 | 5403 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
4ccf1e31 JJ |
5404 | if (flags & 1) |
5405 | offset_size = 8; | |
5406 | printf (_(" Offset: 0x%lx\n"), | |
5407 | (unsigned long) sec_offset); | |
5408 | printf (_(" Version: %d\n"), version); | |
5409 | printf (_(" Offset size: %d\n"), offset_size); | |
5410 | if (flags & 2) | |
5411 | { | |
0c588247 | 5412 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
5413 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
5414 | (unsigned long) line_offset); | |
5415 | } | |
5416 | if (flags & 4) | |
5417 | { | |
0c588247 | 5418 | unsigned int i, count, op; |
4ccf1e31 | 5419 | dwarf_vma nargs, n; |
0c588247 NC |
5420 | |
5421 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 5422 | |
4ccf1e31 JJ |
5423 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
5424 | extended_ops = extended_op_buf; | |
5425 | if (count) | |
5426 | { | |
5427 | printf (_(" Extension opcode arguments:\n")); | |
5428 | for (i = 0; i < count; i++) | |
5429 | { | |
0c588247 | 5430 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 5431 | extended_ops[op] = curr; |
cd30bcef | 5432 | READ_ULEB (nargs, curr, end); |
4ccf1e31 | 5433 | if (nargs == 0) |
7a7e1061 | 5434 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
5435 | else |
5436 | { | |
7a7e1061 | 5437 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
5438 | for (n = 0; n < nargs; n++) |
5439 | { | |
0c588247 NC |
5440 | unsigned int form; |
5441 | ||
5442 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
5443 | printf ("%s%s", get_FORM_name (form), |
5444 | n == nargs - 1 ? "\n" : ", "); | |
5445 | switch (form) | |
5446 | { | |
5447 | case DW_FORM_data1: | |
5448 | case DW_FORM_data2: | |
5449 | case DW_FORM_data4: | |
5450 | case DW_FORM_data8: | |
5451 | case DW_FORM_sdata: | |
5452 | case DW_FORM_udata: | |
5453 | case DW_FORM_block: | |
5454 | case DW_FORM_block1: | |
5455 | case DW_FORM_block2: | |
5456 | case DW_FORM_block4: | |
5457 | case DW_FORM_flag: | |
5458 | case DW_FORM_string: | |
5459 | case DW_FORM_strp: | |
5460 | case DW_FORM_sec_offset: | |
5461 | break; | |
5462 | default: | |
5463 | error (_("Invalid extension opcode form %s\n"), | |
5464 | get_FORM_name (form)); | |
5465 | return 0; | |
5466 | } | |
5467 | } | |
5468 | } | |
5469 | } | |
5470 | } | |
5471 | } | |
5472 | printf ("\n"); | |
5473 | ||
5474 | while (1) | |
5475 | { | |
5476 | unsigned int op; | |
5477 | ||
5478 | if (curr >= end) | |
5479 | { | |
5480 | error (_(".debug_macro section not zero terminated\n")); | |
5481 | return 0; | |
5482 | } | |
5483 | ||
0c588247 | 5484 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
5485 | if (op == 0) |
5486 | break; | |
5487 | ||
5488 | switch (op) | |
5489 | { | |
7a7e1061 | 5490 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
5491 | { |
5492 | unsigned int filenum; | |
5493 | unsigned char *file_name = NULL, *dir_name = NULL; | |
5494 | ||
cd30bcef AM |
5495 | READ_ULEB (lineno, curr, end); |
5496 | READ_ULEB (filenum, curr, end); | |
4ccf1e31 JJ |
5497 | |
5498 | if ((flags & 2) == 0) | |
7a7e1061 | 5499 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
5500 | else |
5501 | file_name | |
5502 | = get_line_filename_and_dirname (line_offset, filenum, | |
5503 | &dir_name); | |
5504 | if (file_name == NULL) | |
7a7e1061 | 5505 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
5506 | lineno, filenum); |
5507 | else | |
7a7e1061 | 5508 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
5509 | lineno, filenum, |
5510 | dir_name != NULL ? (const char *) dir_name : "", | |
5511 | dir_name != NULL ? "/" : "", file_name); | |
5512 | } | |
5513 | break; | |
5514 | ||
7a7e1061 JK |
5515 | case DW_MACRO_end_file: |
5516 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
5517 | break; |
5518 | ||
7a7e1061 | 5519 | case DW_MACRO_define: |
cd30bcef | 5520 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5521 | string = curr; |
5522 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 5523 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5524 | lineno, string); |
5525 | break; | |
5526 | ||
7a7e1061 | 5527 | case DW_MACRO_undef: |
cd30bcef | 5528 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5529 | string = curr; |
5530 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 5531 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5532 | lineno, string); |
5533 | break; | |
5534 | ||
7a7e1061 | 5535 | case DW_MACRO_define_strp: |
cd30bcef | 5536 | READ_ULEB (lineno, curr, end); |
0c588247 | 5537 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5538 | string = fetch_indirect_string (offset); |
7a7e1061 | 5539 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5540 | lineno, string); |
5541 | break; | |
5542 | ||
7a7e1061 | 5543 | case DW_MACRO_undef_strp: |
cd30bcef | 5544 | READ_ULEB (lineno, curr, end); |
0c588247 | 5545 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5546 | string = fetch_indirect_string (offset); |
7a7e1061 | 5547 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5548 | lineno, string); |
5549 | break; | |
5550 | ||
7a7e1061 | 5551 | case DW_MACRO_import: |
0c588247 | 5552 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5553 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
5554 | (unsigned long) offset); |
5555 | break; | |
5556 | ||
7a7e1061 | 5557 | case DW_MACRO_define_sup: |
cd30bcef | 5558 | READ_ULEB (lineno, curr, end); |
0c588247 | 5559 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5560 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5561 | lineno, (unsigned long) offset); |
5562 | break; | |
5563 | ||
7a7e1061 | 5564 | case DW_MACRO_undef_sup: |
cd30bcef | 5565 | READ_ULEB (lineno, curr, end); |
0c588247 | 5566 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5567 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5568 | lineno, (unsigned long) offset); |
5569 | break; | |
5570 | ||
7a7e1061 | 5571 | case DW_MACRO_import_sup: |
0c588247 | 5572 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5573 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
5574 | (unsigned long) offset); |
5575 | break; | |
5576 | ||
4ccf1e31 JJ |
5577 | default: |
5578 | if (extended_ops == NULL || extended_ops[op] == NULL) | |
5579 | { | |
5580 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
5581 | return 0; | |
5582 | } | |
5583 | else | |
5584 | { | |
5585 | /* Skip over unhandled opcodes. */ | |
5586 | dwarf_vma nargs, n; | |
5587 | unsigned char *desc = extended_ops[op]; | |
cd30bcef | 5588 | READ_ULEB (nargs, desc, end); |
4ccf1e31 JJ |
5589 | if (nargs == 0) |
5590 | { | |
7a7e1061 | 5591 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
5592 | break; |
5593 | } | |
7a7e1061 | 5594 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
5595 | for (n = 0; n < nargs; n++) |
5596 | { | |
0c588247 NC |
5597 | int val; |
5598 | ||
77145576 | 5599 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 5600 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 5601 | curr |
77145576 | 5602 | = read_and_display_attr_value (0, val, 0, |
ec1b0fbb | 5603 | start, curr, end, 0, 0, offset_size, |
341f9135 | 5604 | version, NULL, 0, NULL, |
ec1b0fbb | 5605 | NULL, ' ', -1); |
4ccf1e31 JJ |
5606 | if (n != nargs - 1) |
5607 | printf (","); | |
5608 | } | |
5609 | printf ("\n"); | |
5610 | } | |
5611 | break; | |
5612 | } | |
5613 | } | |
5614 | ||
5615 | printf ("\n"); | |
b4eb7656 | 5616 | } |
4ccf1e31 JJ |
5617 | |
5618 | return 1; | |
5619 | } | |
5620 | ||
19e6b90e L |
5621 | static int |
5622 | display_debug_abbrev (struct dwarf_section *section, | |
5623 | void *file ATTRIBUTE_UNUSED) | |
5624 | { | |
5625 | abbrev_entry *entry; | |
5626 | unsigned char *start = section->start; | |
5627 | unsigned char *end = start + section->size; | |
5628 | ||
dda8d76d | 5629 | introduce (section, FALSE); |
19e6b90e L |
5630 | |
5631 | do | |
5632 | { | |
7282333f AM |
5633 | unsigned char *last; |
5634 | ||
19e6b90e L |
5635 | free_abbrevs (); |
5636 | ||
7282333f | 5637 | last = start; |
19e6b90e L |
5638 | start = process_abbrev_section (start, end); |
5639 | ||
5640 | if (first_abbrev == NULL) | |
5641 | continue; | |
5642 | ||
7282333f | 5643 | printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start)); |
19e6b90e L |
5644 | |
5645 | for (entry = first_abbrev; entry; entry = entry->next) | |
5646 | { | |
5647 | abbrev_attr *attr; | |
5648 | ||
cc5914eb | 5649 | printf (" %ld %s [%s]\n", |
19e6b90e L |
5650 | entry->entry, |
5651 | get_TAG_name (entry->tag), | |
5652 | entry->children ? _("has children") : _("no children")); | |
5653 | ||
5654 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
5655 | { |
5656 | printf (" %-18s %s", | |
5657 | get_AT_name (attr->attribute), | |
5658 | get_FORM_name (attr->form)); | |
5659 | if (attr->form == DW_FORM_implicit_const) | |
5660 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
5661 | putchar ('\n'); | |
5662 | } | |
19e6b90e L |
5663 | } |
5664 | } | |
5665 | while (start); | |
5666 | ||
5667 | printf ("\n"); | |
5668 | ||
5669 | return 1; | |
5670 | } | |
5671 | ||
42bcef4a AB |
5672 | /* Return true when ADDR is the maximum address, when addresses are |
5673 | POINTER_SIZE bytes long. */ | |
5674 | ||
5675 | static bfd_boolean | |
5676 | is_max_address (dwarf_vma addr, unsigned int pointer_size) | |
5677 | { | |
5678 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
5679 | return ((addr & mask) == mask); | |
5680 | } | |
5681 | ||
9f272209 AO |
5682 | /* Display a view pair list starting at *VSTART_PTR and ending at |
5683 | VLISTEND within SECTION. */ | |
5684 | ||
5685 | static void | |
5686 | display_view_pair_list (struct dwarf_section *section, | |
5687 | unsigned char **vstart_ptr, | |
5688 | unsigned int debug_info_entry, | |
5689 | unsigned char *vlistend) | |
5690 | { | |
5691 | unsigned char *vstart = *vstart_ptr; | |
5692 | unsigned char *section_end = section->start + section->size; | |
5693 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
5694 | ||
5695 | if (vlistend < section_end) | |
5696 | section_end = vlistend; | |
5697 | ||
5698 | putchar ('\n'); | |
5699 | ||
5700 | while (vstart < section_end) | |
5701 | { | |
5702 | dwarf_vma off = vstart - section->start; | |
5703 | dwarf_vma vbegin, vend; | |
5704 | ||
cd30bcef | 5705 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 | 5706 | if (vstart == section_end) |
cd30bcef | 5707 | break; |
9f272209 | 5708 | |
cd30bcef | 5709 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
5710 | printf (" %8.8lx ", (unsigned long) off); |
5711 | ||
5712 | print_dwarf_view (vbegin, pointer_size, 1); | |
5713 | print_dwarf_view (vend, pointer_size, 1); | |
5714 | printf (_("location view pair\n")); | |
5715 | } | |
5716 | ||
5717 | putchar ('\n'); | |
5718 | *vstart_ptr = vstart; | |
5719 | } | |
5720 | ||
4723351a CC |
5721 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
5722 | ||
5723 | static void | |
5724 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
5725 | unsigned char **start_ptr, |
5726 | unsigned int debug_info_entry, | |
359ca075 JK |
5727 | dwarf_vma offset, |
5728 | dwarf_vma base_address, | |
9f272209 | 5729 | unsigned char **vstart_ptr, |
b4eb7656 | 5730 | int has_frame_base) |
4723351a | 5731 | { |
9f272209 | 5732 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 5733 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
5734 | unsigned long cu_offset; |
5735 | unsigned int pointer_size; | |
5736 | unsigned int offset_size; | |
5737 | int dwarf_version; | |
4723351a CC |
5738 | |
5739 | dwarf_vma begin; | |
5740 | dwarf_vma end; | |
5741 | unsigned short length; | |
5742 | int need_frame_base; | |
5743 | ||
82b1b41b NC |
5744 | if (debug_info_entry >= num_debug_info_entries) |
5745 | { | |
5746 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
5747 | debug_info_entry); | |
5748 | return; | |
5749 | } | |
b4eb7656 | 5750 | |
82b1b41b NC |
5751 | cu_offset = debug_information [debug_info_entry].cu_offset; |
5752 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5753 | offset_size = debug_information [debug_info_entry].offset_size; | |
5754 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 5755 | |
f41e4712 NC |
5756 | if (pointer_size < 2 || pointer_size > 8) |
5757 | { | |
5758 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5759 | pointer_size, debug_info_entry); | |
5760 | return; | |
5761 | } | |
5762 | ||
4723351a CC |
5763 | while (1) |
5764 | { | |
359ca075 | 5765 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 5766 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 5767 | |
4723351a | 5768 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
5769 | { |
5770 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5771 | (unsigned long) offset); |
b4eb7656 AM |
5772 | break; |
5773 | } | |
4723351a | 5774 | |
359ca075 | 5775 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 5776 | |
0c588247 NC |
5777 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
5778 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 5779 | |
4723351a | 5780 | if (begin == 0 && end == 0) |
b4eb7656 | 5781 | { |
d1c4b12b NC |
5782 | /* PR 18374: In a object file we can have a location list that |
5783 | starts with a begin and end of 0 because there are relocations | |
5784 | that need to be applied to the addresses. Actually applying | |
5785 | the relocations now does not help as they will probably resolve | |
5786 | to 0, since the object file has not been fully linked. Real | |
5787 | end of list markers will not have any relocations against them. */ | |
5788 | if (! reloc_at (section, off) | |
5789 | && ! reloc_at (section, off + pointer_size)) | |
5790 | { | |
5791 | printf (_("<End of list>\n")); | |
5792 | break; | |
5793 | } | |
b4eb7656 | 5794 | } |
4723351a CC |
5795 | |
5796 | /* Check base address specifiers. */ | |
42bcef4a AB |
5797 | if (is_max_address (begin, pointer_size) |
5798 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
5799 | { |
5800 | base_address = end; | |
5801 | print_dwarf_vma (begin, pointer_size); | |
5802 | print_dwarf_vma (end, pointer_size); | |
5803 | printf (_("(base address)\n")); | |
5804 | continue; | |
5805 | } | |
4723351a | 5806 | |
9f272209 AO |
5807 | if (vstart) |
5808 | { | |
9f272209 AO |
5809 | off = offset + (vstart - *start_ptr); |
5810 | ||
cd30bcef | 5811 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
5812 | print_dwarf_view (vbegin, pointer_size, 1); |
5813 | ||
cd30bcef | 5814 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
5815 | print_dwarf_view (vend, pointer_size, 1); |
5816 | ||
5817 | printf (_("views at %8.8lx for:\n %*s "), | |
5818 | (unsigned long) off, 8, ""); | |
5819 | } | |
5820 | ||
4723351a | 5821 | if (start + 2 > section_end) |
b4eb7656 AM |
5822 | { |
5823 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5824 | (unsigned long) offset); |
b4eb7656 AM |
5825 | break; |
5826 | } | |
4723351a | 5827 | |
0c588247 | 5828 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
5829 | |
5830 | if (start + length > section_end) | |
b4eb7656 AM |
5831 | { |
5832 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5833 | (unsigned long) offset); |
b4eb7656 AM |
5834 | break; |
5835 | } | |
4723351a CC |
5836 | |
5837 | print_dwarf_vma (begin + base_address, pointer_size); | |
5838 | print_dwarf_vma (end + base_address, pointer_size); | |
5839 | ||
5840 | putchar ('('); | |
5841 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
5842 | pointer_size, |
5843 | offset_size, | |
5844 | dwarf_version, | |
5845 | length, | |
5846 | cu_offset, section); | |
4723351a CC |
5847 | putchar (')'); |
5848 | ||
5849 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 5850 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 5851 | |
9f272209 | 5852 | if (begin == end && vbegin == vend) |
b4eb7656 | 5853 | fputs (_(" (start == end)"), stdout); |
9f272209 | 5854 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 5855 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
5856 | |
5857 | putchar ('\n'); | |
5858 | ||
5859 | start += length; | |
5860 | } | |
5861 | ||
5862 | *start_ptr = start; | |
9f272209 | 5863 | *vstart_ptr = vstart; |
4723351a CC |
5864 | } |
5865 | ||
77145576 JK |
5866 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
5867 | ||
5868 | static void | |
5869 | display_loclists_list (struct dwarf_section *section, | |
5870 | unsigned char **start_ptr, | |
5871 | unsigned int debug_info_entry, | |
5872 | dwarf_vma offset, | |
5873 | dwarf_vma base_address, | |
9f272209 | 5874 | unsigned char **vstart_ptr, |
77145576 JK |
5875 | int has_frame_base) |
5876 | { | |
9f272209 | 5877 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
5878 | unsigned char *section_end = section->start + section->size; |
5879 | unsigned long cu_offset; | |
5880 | unsigned int pointer_size; | |
5881 | unsigned int offset_size; | |
5882 | int dwarf_version; | |
77145576 | 5883 | |
9dfd0db9 | 5884 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
5885 | dwarf_vma begin = -1, vbegin = -1; |
5886 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
5887 | dwarf_vma length; |
5888 | int need_frame_base; | |
5889 | ||
5890 | if (debug_info_entry >= num_debug_info_entries) | |
5891 | { | |
5892 | warn (_("No debug information available for " | |
5893 | "loclists lists of entry: %u\n"), | |
5894 | debug_info_entry); | |
5895 | return; | |
5896 | } | |
5897 | ||
5898 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
5899 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5900 | offset_size = debug_information [debug_info_entry].offset_size; | |
5901 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
5902 | ||
5903 | if (pointer_size < 2 || pointer_size > 8) | |
5904 | { | |
5905 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5906 | pointer_size, debug_info_entry); | |
5907 | return; | |
5908 | } | |
5909 | ||
5910 | while (1) | |
5911 | { | |
5912 | dwarf_vma off = offset + (start - *start_ptr); | |
5913 | enum dwarf_location_list_entry_type llet; | |
5914 | ||
5915 | if (start + 1 > section_end) | |
5916 | { | |
5917 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
5918 | (unsigned long) offset); | |
5919 | break; | |
5920 | } | |
5921 | ||
5922 | printf (" %8.8lx ", (unsigned long) off); | |
5923 | ||
5924 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
5925 | ||
9f272209 AO |
5926 | if (vstart && llet == DW_LLE_offset_pair) |
5927 | { | |
5928 | off = offset + (vstart - *start_ptr); | |
5929 | ||
cd30bcef | 5930 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
5931 | print_dwarf_view (vbegin, pointer_size, 1); |
5932 | ||
cd30bcef | 5933 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
5934 | print_dwarf_view (vend, pointer_size, 1); |
5935 | ||
5936 | printf (_("views at %8.8lx for:\n %*s "), | |
5937 | (unsigned long) off, 8, ""); | |
5938 | } | |
5939 | ||
77145576 JK |
5940 | switch (llet) |
5941 | { | |
5942 | case DW_LLE_end_of_list: | |
5943 | printf (_("<End of list>\n")); | |
5944 | break; | |
5945 | case DW_LLE_offset_pair: | |
cd30bcef AM |
5946 | READ_ULEB (begin, start, section_end); |
5947 | READ_ULEB (end, start, section_end); | |
77145576 JK |
5948 | break; |
5949 | case DW_LLE_base_address: | |
5950 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
5951 | section_end); | |
5952 | print_dwarf_vma (base_address, pointer_size); | |
5953 | printf (_("(base address)\n")); | |
5954 | break; | |
9f272209 AO |
5955 | #ifdef DW_LLE_view_pair |
5956 | case DW_LLE_view_pair: | |
5957 | if (vstart) | |
5958 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
cd30bcef | 5959 | READ_ULEB (vbegin, start, section_end); |
9f272209 AO |
5960 | print_dwarf_view (vbegin, pointer_size, 1); |
5961 | ||
cd30bcef | 5962 | READ_ULEB (vend, start, section_end); |
9f272209 AO |
5963 | print_dwarf_view (vend, pointer_size, 1); |
5964 | ||
5965 | printf (_("views for:\n")); | |
5966 | continue; | |
5967 | #endif | |
77145576 JK |
5968 | default: |
5969 | error (_("Invalid location list entry type %d\n"), llet); | |
5970 | return; | |
5971 | } | |
5972 | if (llet == DW_LLE_end_of_list) | |
5973 | break; | |
5974 | if (llet != DW_LLE_offset_pair) | |
5975 | continue; | |
5976 | ||
5977 | if (start + 2 > section_end) | |
5978 | { | |
5979 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
5980 | (unsigned long) offset); | |
5981 | break; | |
5982 | } | |
5983 | ||
cd30bcef | 5984 | READ_ULEB (length, start, section_end); |
77145576 JK |
5985 | |
5986 | print_dwarf_vma (begin + base_address, pointer_size); | |
5987 | print_dwarf_vma (end + base_address, pointer_size); | |
5988 | ||
5989 | putchar ('('); | |
5990 | need_frame_base = decode_location_expression (start, | |
5991 | pointer_size, | |
5992 | offset_size, | |
5993 | dwarf_version, | |
5994 | length, | |
5995 | cu_offset, section); | |
5996 | putchar (')'); | |
5997 | ||
5998 | if (need_frame_base && !has_frame_base) | |
5999 | printf (_(" [without DW_AT_frame_base]")); | |
6000 | ||
9f272209 | 6001 | if (begin == end && vbegin == vend) |
77145576 | 6002 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6003 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
6004 | fputs (_(" (start > end)"), stdout); |
6005 | ||
6006 | putchar ('\n'); | |
6007 | ||
6008 | start += length; | |
9f272209 | 6009 | vbegin = vend = -1; |
77145576 JK |
6010 | } |
6011 | ||
9f272209 AO |
6012 | if (vbegin != vm1 || vend != vm1) |
6013 | printf (_("Trailing view pair not used in a range")); | |
6014 | ||
77145576 | 6015 | *start_ptr = start; |
9f272209 | 6016 | *vstart_ptr = vstart; |
77145576 JK |
6017 | } |
6018 | ||
fab128ef CC |
6019 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
6020 | right-adjusted in a field of length LEN, and followed by a space. */ | |
6021 | ||
6022 | static void | |
6023 | print_addr_index (unsigned int idx, unsigned int len) | |
6024 | { | |
6025 | static char buf[15]; | |
6026 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 6027 | printf ("%*s ", len, buf); |
fab128ef CC |
6028 | } |
6029 | ||
4723351a CC |
6030 | /* Display a location list from a .dwo section. It uses address indexes rather |
6031 | than embedded addresses. This code closely follows display_loc_list, but the | |
6032 | two are sufficiently different that combining things is very ugly. */ | |
6033 | ||
6034 | static void | |
6035 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
6036 | unsigned char **start_ptr, |
6037 | unsigned int debug_info_entry, | |
359ca075 | 6038 | dwarf_vma offset, |
9f272209 | 6039 | unsigned char **vstart_ptr, |
b4eb7656 | 6040 | int has_frame_base) |
4723351a | 6041 | { |
9f272209 | 6042 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6043 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6044 | unsigned long cu_offset; |
6045 | unsigned int pointer_size; | |
6046 | unsigned int offset_size; | |
6047 | int dwarf_version; | |
4723351a CC |
6048 | int entry_type; |
6049 | unsigned short length; | |
6050 | int need_frame_base; | |
fab128ef | 6051 | unsigned int idx; |
4723351a | 6052 | |
82b1b41b NC |
6053 | if (debug_info_entry >= num_debug_info_entries) |
6054 | { | |
6055 | warn (_("No debug information for loc lists of entry: %u\n"), | |
6056 | debug_info_entry); | |
6057 | return; | |
6058 | } | |
6059 | ||
6060 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6061 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6062 | offset_size = debug_information [debug_info_entry].offset_size; | |
6063 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6064 | ||
f41e4712 NC |
6065 | if (pointer_size < 2 || pointer_size > 8) |
6066 | { | |
6067 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6068 | pointer_size, debug_info_entry); | |
6069 | return; | |
6070 | } | |
6071 | ||
4723351a CC |
6072 | while (1) |
6073 | { | |
359ca075 | 6074 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 6075 | |
fab128ef | 6076 | if (start >= section_end) |
b4eb7656 AM |
6077 | { |
6078 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6079 | (unsigned long) offset); |
b4eb7656 AM |
6080 | break; |
6081 | } | |
4723351a | 6082 | |
0c588247 | 6083 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
6084 | |
6085 | if (vstart) | |
6086 | switch (entry_type) | |
6087 | { | |
6088 | default: | |
6089 | break; | |
6090 | ||
6091 | case 2: | |
6092 | case 3: | |
6093 | case 4: | |
6094 | { | |
6095 | dwarf_vma view; | |
6096 | dwarf_vma off = offset + (vstart - *start_ptr); | |
6097 | ||
cd30bcef | 6098 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6099 | print_dwarf_view (view, 8, 1); |
6100 | ||
cd30bcef | 6101 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6102 | print_dwarf_view (view, 8, 1); |
6103 | ||
6104 | printf (_("views at %8.8lx for:\n %*s "), | |
6105 | (unsigned long) off, 8, ""); | |
6106 | ||
6107 | } | |
6108 | break; | |
6109 | } | |
6110 | ||
4723351a | 6111 | switch (entry_type) |
b4eb7656 AM |
6112 | { |
6113 | case 0: /* A terminating entry. */ | |
6114 | *start_ptr = start; | |
9f272209 | 6115 | *vstart_ptr = vstart; |
b4eb7656 AM |
6116 | printf (_("<End of list>\n")); |
6117 | return; | |
6118 | case 1: /* A base-address entry. */ | |
cd30bcef | 6119 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6120 | print_addr_index (idx, 8); |
9f272209 | 6121 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
6122 | printf (_("(base address selection entry)\n")); |
6123 | continue; | |
6124 | case 2: /* A start/end entry. */ | |
cd30bcef | 6125 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6126 | print_addr_index (idx, 8); |
cd30bcef | 6127 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6128 | print_addr_index (idx, 8); |
6129 | break; | |
6130 | case 3: /* A start/length entry. */ | |
cd30bcef | 6131 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6132 | print_addr_index (idx, 8); |
6133 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6134 | printf ("%08x ", idx); | |
6135 | break; | |
6136 | case 4: /* An offset pair entry. */ | |
6137 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6138 | printf ("%08x ", idx); | |
6139 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6140 | printf ("%08x ", idx); | |
6141 | break; | |
6142 | default: | |
6143 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
6144 | *start_ptr = start; | |
9f272209 | 6145 | *vstart_ptr = vstart; |
b4eb7656 AM |
6146 | return; |
6147 | } | |
4723351a CC |
6148 | |
6149 | if (start + 2 > section_end) | |
b4eb7656 AM |
6150 | { |
6151 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6152 | (unsigned long) offset); |
b4eb7656 AM |
6153 | break; |
6154 | } | |
4723351a | 6155 | |
0c588247 | 6156 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6157 | if (start + length > section_end) |
b4eb7656 AM |
6158 | { |
6159 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6160 | (unsigned long) offset); |
b4eb7656 AM |
6161 | break; |
6162 | } | |
4723351a CC |
6163 | |
6164 | putchar ('('); | |
6165 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6166 | pointer_size, |
6167 | offset_size, | |
6168 | dwarf_version, | |
6169 | length, | |
6170 | cu_offset, section); | |
4723351a CC |
6171 | putchar (')'); |
6172 | ||
6173 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6174 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
6175 | |
6176 | putchar ('\n'); | |
6177 | ||
6178 | start += length; | |
6179 | } | |
6180 | ||
6181 | *start_ptr = start; | |
9f272209 | 6182 | *vstart_ptr = vstart; |
4723351a CC |
6183 | } |
6184 | ||
9f272209 AO |
6185 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
6186 | loc_views. */ | |
51d0d03f | 6187 | |
9f272209 | 6188 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
6189 | |
6190 | static int | |
6191 | loc_offsets_compar (const void *ap, const void *bp) | |
6192 | { | |
6193 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
6194 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
6195 | ||
9f272209 AO |
6196 | int ret = (a > b) - (b > a); |
6197 | if (ret) | |
6198 | return ret; | |
6199 | ||
6200 | a = loc_views[*(const unsigned int *) ap]; | |
6201 | b = loc_views[*(const unsigned int *) bp]; | |
6202 | ||
6203 | ret = (a > b) - (b > a); | |
6204 | ||
6205 | return ret; | |
51d0d03f JJ |
6206 | } |
6207 | ||
19e6b90e L |
6208 | static int |
6209 | display_debug_loc (struct dwarf_section *section, void *file) | |
6210 | { | |
9f272209 | 6211 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
6212 | unsigned long bytes; |
6213 | unsigned char *section_begin = start; | |
6214 | unsigned int num_loc_list = 0; | |
6215 | unsigned long last_offset = 0; | |
9f272209 | 6216 | unsigned long last_view = 0; |
19e6b90e L |
6217 | unsigned int first = 0; |
6218 | unsigned int i; | |
6219 | unsigned int j; | |
6220 | int seen_first_offset = 0; | |
51d0d03f | 6221 | int locs_sorted = 1; |
9f272209 | 6222 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6223 | unsigned int *array = NULL; |
4723351a | 6224 | const char *suffix = strrchr (section->name, '.'); |
24841daa | 6225 | bfd_boolean is_dwo = FALSE; |
77145576 JK |
6226 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6227 | dwarf_vma expected_start = 0; | |
4723351a CC |
6228 | |
6229 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
24841daa | 6230 | is_dwo = TRUE; |
19e6b90e L |
6231 | |
6232 | bytes = section->size; | |
19e6b90e L |
6233 | |
6234 | if (bytes == 0) | |
6235 | { | |
6236 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6237 | return 0; | |
6238 | } | |
6239 | ||
77145576 JK |
6240 | if (is_loclists) |
6241 | { | |
6242 | unsigned char *hdrptr = section_begin; | |
6243 | dwarf_vma ll_length; | |
6244 | unsigned short ll_version; | |
6245 | unsigned char *end = section_begin + section->size; | |
6246 | unsigned char address_size, segment_selector_size; | |
6247 | uint32_t offset_entry_count; | |
6248 | ||
6249 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6250 | if (ll_length == 0xffffffff) | |
6251 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6252 | ||
6253 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6254 | if (ll_version != 5) | |
6255 | { | |
6256 | warn (_("The %s section contains corrupt or " | |
6257 | "unsupported version number: %d.\n"), | |
6258 | section->name, ll_version); | |
6259 | return 0; | |
6260 | } | |
6261 | ||
6262 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6263 | ||
6264 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6265 | if (segment_selector_size != 0) | |
6266 | { | |
6267 | warn (_("The %s section contains " | |
6268 | "unsupported segment selector size: %d.\n"), | |
6269 | section->name, segment_selector_size); | |
6270 | return 0; | |
6271 | } | |
6272 | ||
6273 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
6274 | if (offset_entry_count != 0) | |
6275 | { | |
6276 | warn (_("The %s section contains " | |
6277 | "unsupported offset entry count: %d.\n"), | |
6278 | section->name, offset_entry_count); | |
6279 | return 0; | |
6280 | } | |
6281 | ||
6282 | expected_start = hdrptr - section_begin; | |
6283 | } | |
6284 | ||
1febe64d NC |
6285 | if (load_debug_info (file) == 0) |
6286 | { | |
6287 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6288 | section->name); | |
6289 | return 0; | |
6290 | } | |
19e6b90e L |
6291 | |
6292 | /* Check the order of location list in .debug_info section. If | |
6293 | offsets of location lists are in the ascending order, we can | |
6294 | use `debug_information' directly. */ | |
6295 | for (i = 0; i < num_debug_info_entries; i++) | |
6296 | { | |
6297 | unsigned int num; | |
6298 | ||
6299 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
6300 | if (num > num_loc_list) |
6301 | num_loc_list = num; | |
19e6b90e L |
6302 | |
6303 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 6304 | if (locs_sorted && num != 0) |
19e6b90e L |
6305 | { |
6306 | if (!seen_first_offset) | |
6307 | { | |
6308 | /* This is the first location list. */ | |
6309 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 6310 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
6311 | first = i; |
6312 | seen_first_offset = 1; | |
6313 | j = 1; | |
6314 | } | |
6315 | else | |
6316 | j = 0; | |
6317 | ||
6318 | for (; j < num; j++) | |
6319 | { | |
6320 | if (last_offset > | |
9f272209 AO |
6321 | debug_information [i].loc_offsets [j] |
6322 | || (last_offset == debug_information [i].loc_offsets [j] | |
6323 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 6324 | { |
51d0d03f | 6325 | locs_sorted = 0; |
19e6b90e L |
6326 | break; |
6327 | } | |
6328 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 6329 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
6330 | } |
6331 | } | |
6332 | } | |
6333 | ||
19e6b90e L |
6334 | if (!seen_first_offset) |
6335 | error (_("No location lists in .debug_info section!\n")); | |
6336 | ||
d4bfc77b | 6337 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
6338 | && debug_information [first].loc_offsets [0] != expected_start |
6339 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
6340 | warn (_("Location lists in %s section start at 0x%s\n"), |
6341 | section->name, | |
6342 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 6343 | |
51d0d03f JJ |
6344 | if (!locs_sorted) |
6345 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d NC |
6346 | |
6347 | introduce (section, FALSE); | |
6348 | ||
d1c4b12b NC |
6349 | if (reloc_at (section, 0)) |
6350 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 6351 | |
d1c4b12b | 6352 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
6353 | |
6354 | seen_first_offset = 0; | |
6355 | for (i = first; i < num_debug_info_entries; i++) | |
6356 | { | |
9f272209 | 6357 | dwarf_vma offset, voffset; |
359ca075 | 6358 | dwarf_vma base_address; |
d1c4b12b | 6359 | unsigned int k; |
19e6b90e L |
6360 | int has_frame_base; |
6361 | ||
51d0d03f JJ |
6362 | if (!locs_sorted) |
6363 | { | |
6364 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
6365 | array[k] = k; | |
6366 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 6367 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
6368 | qsort (array, debug_information [i].num_loc_offsets, |
6369 | sizeof (*array), loc_offsets_compar); | |
6370 | } | |
19e6b90e | 6371 | |
9f272209 | 6372 | int adjacent_view_loclists = 1; |
51d0d03f | 6373 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 6374 | { |
51d0d03f JJ |
6375 | j = locs_sorted ? k : array[k]; |
6376 | if (k | |
9f272209 | 6377 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 6378 | ? k - 1 : array [k - 1]] |
9f272209 AO |
6379 | == debug_information [i].loc_offsets [j]) |
6380 | && (debug_information [i].loc_views [locs_sorted | |
6381 | ? k - 1 : array [k - 1]] | |
6382 | == debug_information [i].loc_views [j])) | |
51d0d03f | 6383 | continue; |
19e6b90e | 6384 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 6385 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 6386 | next = section_begin + offset; |
9f272209 AO |
6387 | voffset = debug_information [i].loc_views [j]; |
6388 | if (voffset != vm1) | |
6389 | vnext = section_begin + voffset; | |
6390 | else | |
6391 | vnext = NULL; | |
19e6b90e L |
6392 | base_address = debug_information [i].base_address; |
6393 | ||
9f272209 AO |
6394 | if (vnext && vnext < next) |
6395 | { | |
6396 | vstart = vnext; | |
6397 | display_view_pair_list (section, &vstart, i, next); | |
6398 | if (start == vnext) | |
6399 | start = vstart; | |
6400 | } | |
6401 | ||
6402 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
6403 | seen_first_offset = 1; |
6404 | else | |
6405 | { | |
6406 | if (start < next) | |
6407 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6408 | (unsigned long) (start - section_begin), |
c8071705 | 6409 | (unsigned long) offset); |
19e6b90e L |
6410 | else if (start > next) |
6411 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6412 | (unsigned long) (start - section_begin), |
c8071705 | 6413 | (unsigned long) offset); |
19e6b90e L |
6414 | } |
6415 | start = next; | |
9f272209 | 6416 | vstart = vnext; |
19e6b90e L |
6417 | |
6418 | if (offset >= bytes) | |
6419 | { | |
6420 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 6421 | (unsigned long) offset); |
19e6b90e L |
6422 | continue; |
6423 | } | |
6424 | ||
9f272209 AO |
6425 | if (vnext && voffset >= bytes) |
6426 | { | |
6427 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
6428 | (unsigned long) voffset); | |
6429 | continue; | |
6430 | } | |
6431 | ||
77145576 JK |
6432 | if (!is_loclists) |
6433 | { | |
6434 | if (is_dwo) | |
6435 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 6436 | &vstart, has_frame_base); |
77145576 JK |
6437 | else |
6438 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 6439 | &vstart, has_frame_base); |
77145576 | 6440 | } |
b4eb7656 | 6441 | else |
77145576 JK |
6442 | { |
6443 | if (is_dwo) | |
6444 | warn (_("DWO is not yet supported.\n")); | |
6445 | else | |
6446 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
6447 | &vstart, has_frame_base); |
6448 | } | |
6449 | ||
6450 | /* FIXME: this arrangement is quite simplistic. Nothing | |
6451 | requires locview lists to be adjacent to corresponding | |
6452 | loclists, and a single loclist could be augmented by | |
6453 | different locview lists, and vice-versa, unlikely as it | |
6454 | is that it would make sense to do so. Hopefully we'll | |
6455 | have view pair support built into loclists before we ever | |
6456 | need to address all these possibilities. */ | |
6457 | if (adjacent_view_loclists && vnext | |
6458 | && vnext != start && vstart != next) | |
6459 | { | |
6460 | adjacent_view_loclists = 0; | |
6461 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 6462 | } |
9f272209 AO |
6463 | |
6464 | if (vnext && vnext == start) | |
6465 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
6466 | } |
6467 | } | |
031cd65f | 6468 | |
4723351a | 6469 | if (start < section->start + section->size) |
d3a49aa8 AM |
6470 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
6471 | "There are %ld unused bytes at the end of section %s\n", | |
6472 | (long) (section->start + section->size - start)), | |
4723351a | 6473 | (long) (section->start + section->size - start), section->name); |
98fb390a | 6474 | putchar ('\n'); |
51d0d03f | 6475 | free (array); |
19e6b90e L |
6476 | return 1; |
6477 | } | |
6478 | ||
6479 | static int | |
6480 | display_debug_str (struct dwarf_section *section, | |
6481 | void *file ATTRIBUTE_UNUSED) | |
6482 | { | |
6483 | unsigned char *start = section->start; | |
6484 | unsigned long bytes = section->size; | |
6485 | dwarf_vma addr = section->address; | |
6486 | ||
6487 | if (bytes == 0) | |
6488 | { | |
6489 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6490 | return 0; | |
6491 | } | |
6492 | ||
dda8d76d | 6493 | introduce (section, FALSE); |
19e6b90e L |
6494 | |
6495 | while (bytes) | |
6496 | { | |
6497 | int j; | |
6498 | int k; | |
6499 | int lbytes; | |
6500 | ||
6501 | lbytes = (bytes > 16 ? 16 : bytes); | |
6502 | ||
6503 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
6504 | ||
6505 | for (j = 0; j < 16; j++) | |
6506 | { | |
6507 | if (j < lbytes) | |
6508 | printf ("%2.2x", start[j]); | |
6509 | else | |
6510 | printf (" "); | |
6511 | ||
6512 | if ((j & 3) == 3) | |
6513 | printf (" "); | |
6514 | } | |
6515 | ||
6516 | for (j = 0; j < lbytes; j++) | |
6517 | { | |
6518 | k = start[j]; | |
6519 | if (k >= ' ' && k < 0x80) | |
6520 | printf ("%c", k); | |
6521 | else | |
6522 | printf ("."); | |
6523 | } | |
6524 | ||
6525 | putchar ('\n'); | |
6526 | ||
6527 | start += lbytes; | |
6528 | addr += lbytes; | |
6529 | bytes -= lbytes; | |
6530 | } | |
6531 | ||
6532 | putchar ('\n'); | |
6533 | ||
6534 | return 1; | |
6535 | } | |
6536 | ||
19e6b90e L |
6537 | static int |
6538 | display_debug_info (struct dwarf_section *section, void *file) | |
6539 | { | |
d85bf2ba | 6540 | return process_debug_info (section, file, section->abbrev_sec, FALSE, FALSE); |
19e6b90e L |
6541 | } |
6542 | ||
2b6f5997 CC |
6543 | static int |
6544 | display_debug_types (struct dwarf_section *section, void *file) | |
6545 | { | |
d85bf2ba | 6546 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
6f875884 TG |
6547 | } |
6548 | ||
6549 | static int | |
6550 | display_trace_info (struct dwarf_section *section, void *file) | |
6551 | { | |
d85bf2ba | 6552 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
2b6f5997 | 6553 | } |
19e6b90e L |
6554 | |
6555 | static int | |
6556 | display_debug_aranges (struct dwarf_section *section, | |
6557 | void *file ATTRIBUTE_UNUSED) | |
6558 | { | |
6559 | unsigned char *start = section->start; | |
6560 | unsigned char *end = start + section->size; | |
6561 | ||
dda8d76d | 6562 | introduce (section, FALSE); |
19e6b90e | 6563 | |
6e3d6dc1 NC |
6564 | /* It does not matter if this load fails, |
6565 | we test for that later on. */ | |
6566 | load_debug_info (file); | |
6567 | ||
19e6b90e L |
6568 | while (start < end) |
6569 | { | |
6570 | unsigned char *hdrptr; | |
6571 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 6572 | unsigned char *addr_ranges; |
2d9472a2 NC |
6573 | dwarf_vma length; |
6574 | dwarf_vma address; | |
e98fdf1a | 6575 | unsigned long sec_off; |
53b8873b | 6576 | unsigned char address_size; |
19e6b90e | 6577 | int excess; |
bf5117e3 NC |
6578 | unsigned int offset_size; |
6579 | unsigned int initial_length_size; | |
19e6b90e L |
6580 | |
6581 | hdrptr = start; | |
6582 | ||
0c588247 | 6583 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
6584 | if (arange.ar_length == 0xffffffff) |
6585 | { | |
0c588247 | 6586 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
6587 | offset_size = 8; |
6588 | initial_length_size = 12; | |
6589 | } | |
6590 | else | |
6591 | { | |
6592 | offset_size = 4; | |
6593 | initial_length_size = 4; | |
6594 | } | |
6595 | ||
e98fdf1a AM |
6596 | sec_off = hdrptr - section->start; |
6597 | if (sec_off + arange.ar_length < sec_off | |
6598 | || sec_off + arange.ar_length > section->size) | |
6599 | { | |
6600 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
6601 | section->name, | |
6602 | sec_off - initial_length_size, | |
6603 | dwarf_vmatoa ("x", arange.ar_length)); | |
6604 | break; | |
6605 | } | |
6606 | ||
0c588247 NC |
6607 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
6608 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 6609 | |
6e3d6dc1 NC |
6610 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
6611 | && num_debug_info_entries > 0 | |
6612 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
6613 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 6614 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 6615 | |
0c588247 NC |
6616 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
6617 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
6618 | |
6619 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
6620 | { | |
67f101ee NC |
6621 | /* PR 19872: A version number of 0 probably means that there is |
6622 | padding at the end of the .debug_aranges section. Gold puts | |
6623 | it there when performing an incremental link, for example. | |
6624 | So do not generate a warning in this case. */ | |
6625 | if (arange.ar_version) | |
6626 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
6627 | break; |
6628 | } | |
6629 | ||
47704ddf KT |
6630 | printf (_(" Length: %ld\n"), |
6631 | (long) arange.ar_length); | |
19e6b90e | 6632 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
6633 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
6634 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
6635 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
6636 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
6637 | ||
53b8873b NC |
6638 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
6639 | ||
f41e4712 NC |
6640 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
6641 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
6642 | { |
6643 | error (_("Invalid address size in %s section!\n"), | |
6644 | section->name); | |
6645 | break; | |
6646 | } | |
6647 | ||
53b8873b NC |
6648 | /* The DWARF spec does not require that the address size be a power |
6649 | of two, but we do. This will have to change if we ever encounter | |
6650 | an uneven architecture. */ | |
6651 | if ((address_size & (address_size - 1)) != 0) | |
6652 | { | |
6653 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
6654 | break; | |
6655 | } | |
cecf136e | 6656 | |
209c9a13 NC |
6657 | if (address_size > 4) |
6658 | printf (_("\n Address Length\n")); | |
6659 | else | |
6660 | printf (_("\n Address Length\n")); | |
19e6b90e | 6661 | |
91d6fa6a | 6662 | addr_ranges = hdrptr; |
19e6b90e | 6663 | |
53b8873b NC |
6664 | /* Must pad to an alignment boundary that is twice the address size. */ |
6665 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 6666 | if (excess) |
91d6fa6a | 6667 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 6668 | |
e98fdf1a | 6669 | start += arange.ar_length + initial_length_size; |
1617e571 | 6670 | |
91d6fa6a | 6671 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 6672 | { |
0c588247 NC |
6673 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
6674 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 6675 | |
80c35038 | 6676 | printf (" "); |
2d9472a2 NC |
6677 | print_dwarf_vma (address, address_size); |
6678 | print_dwarf_vma (length, address_size); | |
6679 | putchar ('\n'); | |
19e6b90e | 6680 | } |
19e6b90e L |
6681 | } |
6682 | ||
6683 | printf ("\n"); | |
6684 | ||
6685 | return 1; | |
6686 | } | |
6687 | ||
4723351a CC |
6688 | /* Comparison function for qsort. */ |
6689 | static int | |
6690 | comp_addr_base (const void * v0, const void * v1) | |
6691 | { | |
d367307b AM |
6692 | debug_info *info0 = *(debug_info **) v0; |
6693 | debug_info *info1 = *(debug_info **) v1; | |
4723351a CC |
6694 | return info0->addr_base - info1->addr_base; |
6695 | } | |
6696 | ||
6697 | /* Display the debug_addr section. */ | |
6698 | static int | |
6699 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 6700 | void *file) |
4723351a CC |
6701 | { |
6702 | debug_info **debug_addr_info; | |
6703 | unsigned char *entry; | |
6704 | unsigned char *end; | |
6705 | unsigned int i; | |
6706 | unsigned int count; | |
6707 | ||
6708 | if (section->size == 0) | |
6709 | { | |
6710 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6711 | return 0; | |
6712 | } | |
6713 | ||
6714 | if (load_debug_info (file) == 0) | |
6715 | { | |
6716 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6717 | section->name); | |
6718 | return 0; | |
6719 | } | |
6720 | ||
dda8d76d | 6721 | introduce (section, FALSE); |
4723351a | 6722 | |
1306a742 NC |
6723 | /* PR 17531: file: cf38d01b. |
6724 | We use xcalloc because a corrupt file may not have initialised all of the | |
6725 | fields in the debug_info structure, which means that the sort below might | |
6726 | try to move uninitialised data. */ | |
6727 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 6728 | sizeof (debug_info *)); |
4723351a CC |
6729 | |
6730 | count = 0; | |
6731 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 6732 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
6733 | { |
6734 | /* PR 17531: file: cf38d01b. */ | |
6735 | if (debug_information[i].addr_base >= section->size) | |
6736 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
6737 | (unsigned long) debug_information[i].addr_base, i); | |
6738 | else | |
6739 | debug_addr_info [count++] = debug_information + i; | |
6740 | } | |
4723351a CC |
6741 | |
6742 | /* Add a sentinel to make iteration convenient. */ | |
6743 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
6744 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 6745 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 6746 | |
4723351a CC |
6747 | for (i = 0; i < count; i++) |
6748 | { | |
6749 | unsigned int idx; | |
fab128ef | 6750 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
6751 | |
6752 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 6753 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 6754 | |
fab128ef | 6755 | printf (_("\tIndex\tAddress\n")); |
4723351a CC |
6756 | entry = section->start + debug_addr_info [i]->addr_base; |
6757 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
6758 | idx = 0; | |
6759 | while (entry < end) | |
b4eb7656 AM |
6760 | { |
6761 | dwarf_vma base = byte_get (entry, address_size); | |
6762 | printf (_("\t%d:\t"), idx); | |
6763 | print_dwarf_vma (base, address_size); | |
6764 | printf ("\n"); | |
6765 | entry += address_size; | |
6766 | idx++; | |
6767 | } | |
4723351a CC |
6768 | } |
6769 | printf ("\n"); | |
6770 | ||
6771 | free (debug_addr_info); | |
6772 | return 1; | |
6773 | } | |
6774 | ||
6775 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 6776 | |
4723351a CC |
6777 | static int |
6778 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 6779 | void *file ATTRIBUTE_UNUSED) |
4723351a CC |
6780 | { |
6781 | if (section->size == 0) | |
6782 | { | |
6783 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6784 | return 0; | |
6785 | } | |
6786 | /* TODO: Dump the contents. This is made somewhat difficult by not knowing | |
6787 | what the offset size is for this section. */ | |
6788 | return 1; | |
6789 | } | |
6790 | ||
01a8f077 JK |
6791 | /* Each debug_information[x].range_lists[y] gets this representation for |
6792 | sorting purposes. */ | |
6793 | ||
6794 | struct range_entry | |
467c65bc NC |
6795 | { |
6796 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 6797 | dwarf_vma ranges_offset; |
01a8f077 | 6798 | |
467c65bc NC |
6799 | /* Original debug_information to find parameters of the data. */ |
6800 | debug_info *debug_info_p; | |
6801 | }; | |
01a8f077 JK |
6802 | |
6803 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
6804 | ||
6805 | static int | |
6806 | range_entry_compar (const void *ap, const void *bp) | |
6807 | { | |
3f5e193b NC |
6808 | const struct range_entry *a_re = (const struct range_entry *) ap; |
6809 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
6810 | const dwarf_vma a = a_re->ranges_offset; |
6811 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
6812 | |
6813 | return (a > b) - (b > a); | |
6814 | } | |
6815 | ||
77145576 JK |
6816 | static void |
6817 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
6818 | unsigned int pointer_size, unsigned long offset, | |
6819 | unsigned long base_address) | |
6820 | { | |
6821 | while (start < finish) | |
6822 | { | |
6823 | dwarf_vma begin; | |
6824 | dwarf_vma end; | |
6825 | ||
6826 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6827 | if (start >= finish) | |
6828 | break; | |
6829 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
6830 | ||
d11ae95e | 6831 | |
77145576 JK |
6832 | printf (" %8.8lx ", offset); |
6833 | ||
6834 | if (begin == 0 && end == 0) | |
6835 | { | |
6836 | printf (_("<End of list>\n")); | |
6837 | break; | |
6838 | } | |
6839 | ||
6840 | /* Check base address specifiers. */ | |
6841 | if (is_max_address (begin, pointer_size) | |
6842 | && !is_max_address (end, pointer_size)) | |
6843 | { | |
6844 | base_address = end; | |
6845 | print_dwarf_vma (begin, pointer_size); | |
6846 | print_dwarf_vma (end, pointer_size); | |
6847 | printf ("(base address)\n"); | |
6848 | continue; | |
6849 | } | |
6850 | ||
6851 | print_dwarf_vma (begin + base_address, pointer_size); | |
6852 | print_dwarf_vma (end + base_address, pointer_size); | |
6853 | ||
6854 | if (begin == end) | |
6855 | fputs (_("(start == end)"), stdout); | |
6856 | else if (begin > end) | |
6857 | fputs (_("(start > end)"), stdout); | |
6858 | ||
6859 | putchar ('\n'); | |
6860 | } | |
6861 | } | |
6862 | ||
6863 | static void | |
6864 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
6865 | unsigned int pointer_size, unsigned long offset, | |
6866 | unsigned long base_address) | |
6867 | { | |
6868 | unsigned char *next = start; | |
6869 | ||
6870 | while (1) | |
6871 | { | |
6872 | unsigned long off = offset + (start - next); | |
6873 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
6874 | /* Initialize it due to a false compiler warning. */ |
6875 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
6876 | |
6877 | if (start + 1 > finish) | |
6878 | { | |
6879 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
6880 | offset); | |
6881 | break; | |
6882 | } | |
6883 | ||
6884 | printf (" %8.8lx ", off); | |
6885 | ||
6886 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
6887 | ||
6888 | switch (rlet) | |
6889 | { | |
6890 | case DW_RLE_end_of_list: | |
6891 | printf (_("<End of list>\n")); | |
6892 | break; | |
6893 | case DW_RLE_base_address: | |
6894 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
6895 | print_dwarf_vma (base_address, pointer_size); | |
6896 | printf (_("(base address)\n")); | |
6897 | break; | |
6898 | case DW_RLE_start_length: | |
6899 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
cd30bcef | 6900 | READ_ULEB (length, start, finish); |
77145576 JK |
6901 | end = begin + length; |
6902 | break; | |
6903 | case DW_RLE_offset_pair: | |
cd30bcef AM |
6904 | READ_ULEB (begin, start, finish); |
6905 | READ_ULEB (end, start, finish); | |
77145576 JK |
6906 | break; |
6907 | case DW_RLE_start_end: | |
6908 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6909 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
6910 | break; | |
6911 | default: | |
6912 | error (_("Invalid range list entry type %d\n"), rlet); | |
6913 | rlet = DW_RLE_end_of_list; | |
6914 | break; | |
6915 | } | |
6916 | if (rlet == DW_RLE_end_of_list) | |
6917 | break; | |
6918 | if (rlet == DW_RLE_base_address) | |
6919 | continue; | |
6920 | ||
6921 | print_dwarf_vma (begin + base_address, pointer_size); | |
6922 | print_dwarf_vma (end + base_address, pointer_size); | |
6923 | ||
6924 | if (begin == end) | |
6925 | fputs (_("(start == end)"), stdout); | |
6926 | else if (begin > end) | |
6927 | fputs (_("(start > end)"), stdout); | |
6928 | ||
6929 | putchar ('\n'); | |
6930 | } | |
6931 | } | |
6932 | ||
19e6b90e L |
6933 | static int |
6934 | display_debug_ranges (struct dwarf_section *section, | |
6935 | void *file ATTRIBUTE_UNUSED) | |
6936 | { | |
6937 | unsigned char *start = section->start; | |
a2ff7a4b | 6938 | unsigned char *last_start = start; |
f6f0e17b | 6939 | unsigned long bytes = section->size; |
19e6b90e | 6940 | unsigned char *section_begin = start; |
f6f0e17b | 6941 | unsigned char *finish = start + bytes; |
01a8f077 JK |
6942 | unsigned int num_range_list, i; |
6943 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
6944 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
6945 | /* Initialize it due to a false compiler warning. */ | |
6946 | unsigned char address_size = 0; | |
cb4c35cf | 6947 | dwarf_vma last_offset = 0; |
19e6b90e | 6948 | |
19e6b90e L |
6949 | if (bytes == 0) |
6950 | { | |
6951 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6952 | return 0; | |
6953 | } | |
6954 | ||
77145576 JK |
6955 | if (is_rnglists) |
6956 | { | |
6957 | dwarf_vma initial_length; | |
6958 | unsigned int initial_length_size; | |
6959 | unsigned char segment_selector_size; | |
6960 | unsigned int offset_size, offset_entry_count; | |
6961 | unsigned short version; | |
6962 | ||
6963 | /* Get and check the length of the block. */ | |
6964 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
6965 | ||
6966 | if (initial_length == 0xffffffff) | |
6967 | { | |
6968 | /* This section is 64-bit DWARF 3. */ | |
6969 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
6970 | offset_size = 8; | |
6971 | initial_length_size = 12; | |
6972 | } | |
6973 | else | |
6974 | { | |
6975 | offset_size = 4; | |
6976 | initial_length_size = 4; | |
6977 | } | |
6978 | ||
6979 | if (initial_length + initial_length_size > section->size) | |
6980 | { | |
6981 | /* If the length field has a relocation against it, then we should | |
6982 | not complain if it is inaccurate (and probably negative). | |
6983 | It is copied from .debug_line handling code. */ | |
6984 | if (reloc_at (section, (start - section->start) - offset_size)) | |
6985 | { | |
6986 | initial_length = (finish - start) - initial_length_size; | |
6987 | } | |
6988 | else | |
6989 | { | |
6990 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
6991 | (long) initial_length); | |
6992 | return 0; | |
6993 | } | |
6994 | } | |
6995 | ||
6996 | /* Get and check the version number. */ | |
6997 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
6998 | ||
6999 | if (version != 5) | |
7000 | { | |
7001 | warn (_("Only DWARF version 5 debug_rnglists info " | |
7002 | "is currently supported.\n")); | |
7003 | return 0; | |
7004 | } | |
7005 | ||
7006 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
7007 | ||
7008 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
7009 | if (segment_selector_size != 0) | |
7010 | { | |
7011 | warn (_("The %s section contains " | |
7012 | "unsupported segment selector size: %d.\n"), | |
7013 | section->name, segment_selector_size); | |
7014 | return 0; | |
7015 | } | |
7016 | ||
7017 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
7018 | if (offset_entry_count != 0) | |
7019 | { | |
7020 | warn (_("The %s section contains " | |
7021 | "unsupported offset entry count: %u.\n"), | |
7022 | section->name, offset_entry_count); | |
7023 | return 0; | |
7024 | } | |
7025 | } | |
7026 | ||
1febe64d NC |
7027 | if (load_debug_info (file) == 0) |
7028 | { | |
7029 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7030 | section->name); | |
7031 | return 0; | |
7032 | } | |
19e6b90e | 7033 | |
01a8f077 | 7034 | num_range_list = 0; |
19e6b90e | 7035 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 7036 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 7037 | |
01a8f077 | 7038 | if (num_range_list == 0) |
4723351a CC |
7039 | { |
7040 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 7041 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
7042 | printf (_("No range lists in .debug_info section.\n")); |
7043 | return 1; | |
7044 | } | |
19e6b90e | 7045 | |
3f5e193b NC |
7046 | range_entries = (struct range_entry *) |
7047 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 7048 | range_entry_fill = range_entries; |
19e6b90e | 7049 | |
01a8f077 JK |
7050 | for (i = 0; i < num_debug_info_entries; i++) |
7051 | { | |
7052 | debug_info *debug_info_p = &debug_information[i]; | |
7053 | unsigned int j; | |
7054 | ||
7055 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
7056 | { | |
7057 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
7058 | range_entry_fill->debug_info_p = debug_info_p; | |
7059 | range_entry_fill++; | |
19e6b90e L |
7060 | } |
7061 | } | |
7062 | ||
01a8f077 JK |
7063 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
7064 | range_entry_compar); | |
19e6b90e | 7065 | |
d493b283 | 7066 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 7067 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 7068 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 7069 | |
dda8d76d NC |
7070 | introduce (section, FALSE); |
7071 | ||
19e6b90e L |
7072 | printf (_(" Offset Begin End\n")); |
7073 | ||
01a8f077 | 7074 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 7075 | { |
01a8f077 JK |
7076 | struct range_entry *range_entry = &range_entries[i]; |
7077 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 7078 | unsigned int pointer_size; |
359ca075 | 7079 | dwarf_vma offset; |
01a8f077 | 7080 | unsigned char *next; |
359ca075 | 7081 | dwarf_vma base_address; |
19e6b90e | 7082 | |
77145576 | 7083 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 7084 | offset = range_entry->ranges_offset; |
01a8f077 JK |
7085 | next = section_begin + offset; |
7086 | base_address = debug_info_p->base_address; | |
cecf136e | 7087 | |
f41e4712 NC |
7088 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
7089 | if (pointer_size < 2 || pointer_size > 8) | |
7090 | { | |
7091 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 7092 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
7093 | continue; |
7094 | } | |
b4eb7656 | 7095 | |
d11ae95e NC |
7096 | if (next < section_begin || next >= finish) |
7097 | { | |
7098 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
7099 | (unsigned long) offset, i); | |
7100 | continue; | |
7101 | } | |
7102 | ||
cb4c35cf AB |
7103 | /* If multiple DWARF entities reference the same range then we will |
7104 | have multiple entries in the `range_entries' list for the same | |
7105 | offset. Thanks to the sort above these will all be consecutive in | |
7106 | the `range_entries' list, so we can easily ignore duplicates | |
7107 | here. */ | |
7108 | if (i > 0 && last_offset == offset) | |
7109 | continue; | |
7110 | last_offset = offset; | |
7111 | ||
4723351a | 7112 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 7113 | { |
01a8f077 JK |
7114 | if (start < next) |
7115 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
7116 | (unsigned long) (start - section_begin), | |
7117 | (unsigned long) (next - section_begin), section->name); | |
7118 | else if (start > next) | |
a2ff7a4b AM |
7119 | { |
7120 | if (next == last_start) | |
7121 | continue; | |
7122 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
7123 | (unsigned long) (start - section_begin), | |
7124 | (unsigned long) (next - section_begin), section->name); | |
7125 | } | |
01a8f077 | 7126 | } |
d11ae95e | 7127 | |
01a8f077 | 7128 | start = next; |
a2ff7a4b | 7129 | last_start = next; |
19e6b90e | 7130 | |
77145576 JK |
7131 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
7132 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
7133 | } |
7134 | putchar ('\n'); | |
01a8f077 JK |
7135 | |
7136 | free (range_entries); | |
7137 | ||
19e6b90e L |
7138 | return 1; |
7139 | } | |
7140 | ||
7141 | typedef struct Frame_Chunk | |
7142 | { | |
7143 | struct Frame_Chunk *next; | |
7144 | unsigned char *chunk_start; | |
a1165289 | 7145 | unsigned int ncols; |
19e6b90e L |
7146 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
7147 | short int *col_type; | |
7148 | int *col_offset; | |
7149 | char *augmentation; | |
7150 | unsigned int code_factor; | |
7151 | int data_factor; | |
bf5117e3 NC |
7152 | dwarf_vma pc_begin; |
7153 | dwarf_vma pc_range; | |
32ef3000 | 7154 | unsigned int cfa_reg; |
c8071705 | 7155 | dwarf_vma cfa_offset; |
a1165289 | 7156 | unsigned int ra; |
19e6b90e L |
7157 | unsigned char fde_encoding; |
7158 | unsigned char cfa_exp; | |
604282a7 JJ |
7159 | unsigned char ptr_size; |
7160 | unsigned char segment_size; | |
19e6b90e L |
7161 | } |
7162 | Frame_Chunk; | |
7163 | ||
1296bc99 AB |
7164 | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); |
7165 | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; | |
665ce1f6 L |
7166 | static const char *const *dwarf_regnames; |
7167 | static unsigned int dwarf_regnames_count; | |
7168 | ||
1296bc99 | 7169 | |
19e6b90e L |
7170 | /* A marker for a col_type that means this column was never referenced |
7171 | in the frame info. */ | |
7172 | #define DW_CFA_unreferenced (-1) | |
7173 | ||
a1165289 | 7174 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
7175 | -1 for invalid reg. */ |
7176 | ||
7177 | static int | |
7178 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 7179 | { |
a1165289 | 7180 | unsigned int prev = fc->ncols; |
19e6b90e | 7181 | |
665ce1f6 L |
7182 | if (reg < (unsigned int) fc->ncols) |
7183 | return 0; | |
7184 | ||
d9acf707 | 7185 | if (dwarf_regnames_count > 0 |
665ce1f6 L |
7186 | && reg > dwarf_regnames_count) |
7187 | return -1; | |
19e6b90e L |
7188 | |
7189 | fc->ncols = reg + 1; | |
a1165289 NC |
7190 | /* PR 17512: file: 10450-2643-0.004. |
7191 | If reg == -1 then this can happen... */ | |
7192 | if (fc->ncols == 0) | |
7193 | return -1; | |
7194 | ||
06614111 | 7195 | /* PR 17512: file: 2844a11d. */ |
d9acf707 | 7196 | if (fc->ncols > 1024 && dwarf_regnames_count == 0) |
06614111 NC |
7197 | { |
7198 | error (_("Unfeasibly large register number: %u\n"), reg); | |
7199 | fc->ncols = 0; | |
7200 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
7201 | we ever encounter a valid binary that exceeds it. */ | |
7202 | return -1; | |
7203 | } | |
7204 | ||
3f5e193b | 7205 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 7206 | sizeof (short int)); |
3f5e193b | 7207 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 7208 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
7209 | if (fc->col_type == NULL || fc->col_offset == NULL) |
7210 | { | |
7211 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
7212 | fc->ncols); | |
7213 | fc->ncols = 0; | |
7214 | return -1; | |
7215 | } | |
19e6b90e L |
7216 | |
7217 | while (prev < fc->ncols) | |
7218 | { | |
7219 | fc->col_type[prev] = DW_CFA_unreferenced; | |
7220 | fc->col_offset[prev] = 0; | |
7221 | prev++; | |
7222 | } | |
665ce1f6 | 7223 | return 1; |
19e6b90e L |
7224 | } |
7225 | ||
2dc4cec1 L |
7226 | static const char *const dwarf_regnames_i386[] = |
7227 | { | |
43234a1e L |
7228 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
7229 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7230 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7231 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
7232 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
7233 | NULL, NULL, /* 19 - 20 */ | |
7234 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
7235 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
7236 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
7237 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
7238 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
7239 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7240 | "tr", "ldtr", /* 48 - 49 */ | |
7241 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7242 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7243 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7244 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7245 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7246 | NULL, NULL, NULL, /* 90 - 92 */ | |
7247 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
7248 | }; |
7249 | ||
3d875af5 L |
7250 | static const char *const dwarf_regnames_iamcu[] = |
7251 | { | |
7252 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
7253 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7254 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7255 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
7256 | NULL, NULL, /* 19 - 20 */ | |
7257 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
7258 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
7259 | NULL, NULL, NULL, /* 37 - 39 */ | |
7260 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7261 | "tr", "ldtr", /* 48 - 49 */ | |
7262 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7263 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7264 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7265 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7266 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7267 | NULL, NULL, NULL, /* 90 - 92 */ | |
7268 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
7269 | }; | |
7270 | ||
99f6fdd9 | 7271 | static void |
b129eb0e RH |
7272 | init_dwarf_regnames_i386 (void) |
7273 | { | |
7274 | dwarf_regnames = dwarf_regnames_i386; | |
7275 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
1296bc99 | 7276 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
7277 | } |
7278 | ||
99f6fdd9 | 7279 | static void |
3d875af5 L |
7280 | init_dwarf_regnames_iamcu (void) |
7281 | { | |
7282 | dwarf_regnames = dwarf_regnames_iamcu; | |
7283 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
1296bc99 | 7284 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
3d875af5 L |
7285 | } |
7286 | ||
2dc4cec1 L |
7287 | static const char *const dwarf_regnames_x86_64[] = |
7288 | { | |
7289 | "rax", "rdx", "rcx", "rbx", | |
7290 | "rsi", "rdi", "rbp", "rsp", | |
7291 | "r8", "r9", "r10", "r11", | |
7292 | "r12", "r13", "r14", "r15", | |
7293 | "rip", | |
7294 | "xmm0", "xmm1", "xmm2", "xmm3", | |
7295 | "xmm4", "xmm5", "xmm6", "xmm7", | |
7296 | "xmm8", "xmm9", "xmm10", "xmm11", | |
7297 | "xmm12", "xmm13", "xmm14", "xmm15", | |
7298 | "st0", "st1", "st2", "st3", | |
7299 | "st4", "st5", "st6", "st7", | |
7300 | "mm0", "mm1", "mm2", "mm3", | |
7301 | "mm4", "mm5", "mm6", "mm7", | |
7302 | "rflags", | |
7303 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
7304 | "fs.base", "gs.base", NULL, NULL, | |
7305 | "tr", "ldtr", | |
43234a1e L |
7306 | "mxcsr", "fcw", "fsw", |
7307 | "xmm16", "xmm17", "xmm18", "xmm19", | |
7308 | "xmm20", "xmm21", "xmm22", "xmm23", | |
7309 | "xmm24", "xmm25", "xmm26", "xmm27", | |
7310 | "xmm28", "xmm29", "xmm30", "xmm31", | |
7311 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
7312 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
7313 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
7314 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
7315 | NULL, NULL, NULL, /* 115 - 117 */ | |
7316 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
7317 | }; |
7318 | ||
99f6fdd9 | 7319 | static void |
b129eb0e RH |
7320 | init_dwarf_regnames_x86_64 (void) |
7321 | { | |
7322 | dwarf_regnames = dwarf_regnames_x86_64; | |
7323 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
1296bc99 | 7324 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
7325 | } |
7326 | ||
4ee22035 RH |
7327 | static const char *const dwarf_regnames_aarch64[] = |
7328 | { | |
b4eb7656 AM |
7329 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
7330 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
7331 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
7332 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
7333 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
fab7c86e TC |
7334 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
7335 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", | |
7336 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", | |
b4eb7656 AM |
7337 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
7338 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
7339 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
7340 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
fab7c86e TC |
7341 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
7342 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", | |
7343 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", | |
7344 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", | |
4ee22035 RH |
7345 | }; |
7346 | ||
99f6fdd9 | 7347 | static void |
4ee22035 RH |
7348 | init_dwarf_regnames_aarch64 (void) |
7349 | { | |
7350 | dwarf_regnames = dwarf_regnames_aarch64; | |
7351 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
1296bc99 | 7352 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
4ee22035 RH |
7353 | } |
7354 | ||
d6bb17b0 AA |
7355 | static const char *const dwarf_regnames_s390[] = |
7356 | { | |
7357 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
7358 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7359 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7360 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
7361 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
7362 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
7363 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
7364 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
7365 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
7366 | "pswm", "pswa", | |
7367 | NULL, NULL, | |
7368 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
7369 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
7370 | }; | |
7371 | ||
99f6fdd9 | 7372 | static void |
d6bb17b0 AA |
7373 | init_dwarf_regnames_s390 (void) |
7374 | { | |
7375 | dwarf_regnames = dwarf_regnames_s390; | |
7376 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
1296bc99 | 7377 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
d6bb17b0 AA |
7378 | } |
7379 | ||
5bb0830d AB |
7380 | static const char *const dwarf_regnames_riscv[] = |
7381 | { | |
7382 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
7383 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
7384 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
7385 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
7386 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
7387 | "fs0", "fs1", /* 40 - 41 */ | |
7388 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
7389 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
7390 | "fs10", "fs11", /* 58 - 59 */ | |
7391 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
7392 | }; | |
7393 | ||
4762fe62 AB |
7394 | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles |
7395 | the large number of CSRs. */ | |
7396 | ||
7397 | static const char * | |
7398 | regname_internal_riscv (unsigned int regno) | |
7399 | { | |
7400 | const char *name = NULL; | |
7401 | ||
7402 | /* Lookup in the table first, this covers GPR and FPR. */ | |
7403 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) | |
7404 | name = dwarf_regnames_riscv [regno]; | |
7405 | else if (regno >= 4096 && regno <= 8191) | |
7406 | { | |
7407 | /* This might be a CSR, these live in a sparse number space from 4096 | |
7408 | to 8191 These numbers are defined in the RISC-V ELF ABI | |
7409 | document. */ | |
7410 | switch (regno) | |
7411 | { | |
8f595e9b NC |
7412 | #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \ |
7413 | case VALUE + 4096: name = #NAME; break; | |
4762fe62 AB |
7414 | #include "opcode/riscv-opc.h" |
7415 | #undef DECLARE_CSR | |
7416 | ||
7417 | default: | |
7418 | { | |
7419 | static char csr_name[10]; | |
7420 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); | |
7421 | name = csr_name; | |
7422 | } | |
7423 | break; | |
7424 | } | |
7425 | } | |
7426 | ||
7427 | return name; | |
7428 | } | |
7429 | ||
99f6fdd9 | 7430 | static void |
5bb0830d AB |
7431 | init_dwarf_regnames_riscv (void) |
7432 | { | |
4762fe62 AB |
7433 | dwarf_regnames = NULL; |
7434 | dwarf_regnames_count = 8192; | |
7435 | dwarf_regnames_lookup_func = regname_internal_riscv; | |
5bb0830d AB |
7436 | } |
7437 | ||
2dc4cec1 | 7438 | void |
955ff7fc | 7439 | init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) |
2dc4cec1 | 7440 | { |
1296bc99 AB |
7441 | dwarf_regnames_lookup_func = NULL; |
7442 | ||
2dc4cec1 L |
7443 | switch (e_machine) |
7444 | { | |
7445 | case EM_386: | |
b129eb0e | 7446 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
7447 | break; |
7448 | ||
3d875af5 L |
7449 | case EM_IAMCU: |
7450 | init_dwarf_regnames_iamcu (); | |
7451 | break; | |
7452 | ||
2dc4cec1 | 7453 | case EM_X86_64: |
7f502d6c | 7454 | case EM_L1OM: |
7a9068fe | 7455 | case EM_K1OM: |
b129eb0e | 7456 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
7457 | break; |
7458 | ||
4ee22035 RH |
7459 | case EM_AARCH64: |
7460 | init_dwarf_regnames_aarch64 (); | |
7461 | break; | |
7462 | ||
d6bb17b0 AA |
7463 | case EM_S390: |
7464 | init_dwarf_regnames_s390 (); | |
7465 | break; | |
7466 | ||
5bb0830d AB |
7467 | case EM_RISCV: |
7468 | init_dwarf_regnames_riscv (); | |
7469 | break; | |
7470 | ||
2dc4cec1 L |
7471 | default: |
7472 | break; | |
7473 | } | |
7474 | } | |
7475 | ||
229a22cf AB |
7476 | /* Initialize the DWARF register name lookup state based on the |
7477 | architecture and specific machine type of a BFD. */ | |
7478 | ||
7479 | void | |
7480 | init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, | |
7481 | unsigned long mach) | |
7482 | { | |
1296bc99 AB |
7483 | dwarf_regnames_lookup_func = NULL; |
7484 | ||
229a22cf AB |
7485 | switch (arch) |
7486 | { | |
7487 | case bfd_arch_i386: | |
7488 | switch (mach) | |
7489 | { | |
7490 | case bfd_mach_x86_64: | |
7491 | case bfd_mach_x86_64_intel_syntax: | |
7492 | case bfd_mach_x86_64_nacl: | |
7493 | case bfd_mach_x64_32: | |
7494 | case bfd_mach_x64_32_intel_syntax: | |
7495 | case bfd_mach_x64_32_nacl: | |
7496 | init_dwarf_regnames_x86_64 (); | |
7497 | break; | |
7498 | ||
7499 | default: | |
7500 | init_dwarf_regnames_i386 (); | |
7501 | break; | |
7502 | } | |
7503 | break; | |
7504 | ||
7505 | case bfd_arch_iamcu: | |
7506 | init_dwarf_regnames_iamcu (); | |
7507 | break; | |
7508 | ||
7509 | case bfd_arch_aarch64: | |
7510 | init_dwarf_regnames_aarch64(); | |
7511 | break; | |
7512 | ||
7513 | case bfd_arch_s390: | |
7514 | init_dwarf_regnames_s390 (); | |
7515 | break; | |
7516 | ||
7517 | case bfd_arch_riscv: | |
7518 | init_dwarf_regnames_riscv (); | |
7519 | break; | |
7520 | ||
7521 | default: | |
7522 | break; | |
7523 | } | |
7524 | } | |
7525 | ||
2dc4cec1 | 7526 | static const char * |
1296bc99 | 7527 | regname_internal_by_table_only (unsigned int regno) |
2dc4cec1 | 7528 | { |
1296bc99 | 7529 | if (dwarf_regnames != NULL |
2dc4cec1 L |
7530 | && regno < dwarf_regnames_count |
7531 | && dwarf_regnames [regno] != NULL) | |
1296bc99 AB |
7532 | return dwarf_regnames [regno]; |
7533 | ||
7534 | return NULL; | |
7535 | } | |
7536 | ||
7537 | static const char * | |
7538 | regname (unsigned int regno, int name_only_p) | |
7539 | { | |
7540 | static char reg[64]; | |
7541 | ||
7542 | const char *name = NULL; | |
7543 | ||
7544 | if (dwarf_regnames_lookup_func != NULL) | |
7545 | name = dwarf_regnames_lookup_func (regno); | |
7546 | ||
7547 | if (name != NULL) | |
2dc4cec1 | 7548 | { |
1296bc99 AB |
7549 | if (name_only_p) |
7550 | return name; | |
7551 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); | |
2dc4cec1 L |
7552 | } |
7553 | else | |
7554 | snprintf (reg, sizeof (reg), "r%d", regno); | |
7555 | return reg; | |
7556 | } | |
7557 | ||
19e6b90e | 7558 | static void |
a1165289 | 7559 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 7560 | { |
a1165289 | 7561 | unsigned int r; |
19e6b90e L |
7562 | char tmp[100]; |
7563 | ||
d8024a91 | 7564 | if (*max_regs != fc->ncols) |
19e6b90e L |
7565 | *max_regs = fc->ncols; |
7566 | ||
7567 | if (*need_col_headers) | |
7568 | { | |
91d6fa6a | 7569 | static const char *sloc = " LOC"; |
2dc4cec1 | 7570 | |
19e6b90e L |
7571 | *need_col_headers = 0; |
7572 | ||
91d6fa6a | 7573 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
7574 | |
7575 | for (r = 0; r < *max_regs; r++) | |
7576 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7577 | { | |
7578 | if (r == fc->ra) | |
50751e18 | 7579 | printf ("ra "); |
19e6b90e | 7580 | else |
2dc4cec1 | 7581 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
7582 | } |
7583 | ||
7584 | printf ("\n"); | |
7585 | } | |
7586 | ||
bf5117e3 | 7587 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
7588 | if (fc->cfa_exp) |
7589 | strcpy (tmp, "exp"); | |
7590 | else | |
c8071705 | 7591 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
7592 | printf ("%-8s ", tmp); |
7593 | ||
7594 | for (r = 0; r < fc->ncols; r++) | |
7595 | { | |
7596 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7597 | { | |
7598 | switch (fc->col_type[r]) | |
7599 | { | |
7600 | case DW_CFA_undefined: | |
7601 | strcpy (tmp, "u"); | |
7602 | break; | |
7603 | case DW_CFA_same_value: | |
7604 | strcpy (tmp, "s"); | |
7605 | break; | |
7606 | case DW_CFA_offset: | |
7607 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
7608 | break; | |
12eae2d3 JJ |
7609 | case DW_CFA_val_offset: |
7610 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
7611 | break; | |
19e6b90e | 7612 | case DW_CFA_register: |
2dc4cec1 | 7613 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
7614 | break; |
7615 | case DW_CFA_expression: | |
7616 | strcpy (tmp, "exp"); | |
7617 | break; | |
12eae2d3 JJ |
7618 | case DW_CFA_val_expression: |
7619 | strcpy (tmp, "vexp"); | |
7620 | break; | |
19e6b90e L |
7621 | default: |
7622 | strcpy (tmp, "n/a"); | |
7623 | break; | |
7624 | } | |
2dc4cec1 | 7625 | printf ("%-5s ", tmp); |
19e6b90e L |
7626 | } |
7627 | } | |
7628 | printf ("\n"); | |
7629 | } | |
7630 | ||
49727e46 | 7631 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 7632 | |
49727e46 AM |
7633 | static unsigned char * |
7634 | read_cie (unsigned char *start, unsigned char *end, | |
7635 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 7636 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
7637 | { |
7638 | int version; | |
7639 | Frame_Chunk *fc; | |
49727e46 | 7640 | unsigned char *augmentation_data = NULL; |
bf59c5d5 | 7641 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 7642 | |
041830e0 | 7643 | * p_cie = NULL; |
f41e4712 NC |
7644 | /* PR 17512: file: 001-228113-0.004. */ |
7645 | if (start >= end) | |
7646 | return end; | |
7647 | ||
49727e46 AM |
7648 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
7649 | memset (fc, 0, sizeof (Frame_Chunk)); | |
7650 | ||
7651 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
7652 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
7653 | ||
7654 | version = *start++; | |
7655 | ||
7656 | fc->augmentation = (char *) start; | |
f41e4712 NC |
7657 | /* PR 17512: file: 001-228113-0.004. |
7658 | Skip past augmentation name, but avoid running off the end of the data. */ | |
7659 | while (start < end) | |
7660 | if (* start ++ == '\0') | |
7661 | break; | |
7662 | if (start == end) | |
7663 | { | |
7664 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 7665 | goto fail; |
f41e4712 | 7666 | } |
49727e46 AM |
7667 | |
7668 | if (strcmp (fc->augmentation, "eh") == 0) | |
7669 | start += eh_addr_size; | |
7670 | ||
7671 | if (version >= 4) | |
7672 | { | |
7673 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
7674 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
7675 | { | |
7676 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 7677 | goto fail; |
77ef8654 NC |
7678 | } |
7679 | ||
49727e46 | 7680 | GET (fc->segment_size, 1); |
77ef8654 NC |
7681 | /* PR 17512: file: e99d2804. */ |
7682 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
7683 | { | |
7684 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 7685 | goto fail; |
77ef8654 NC |
7686 | } |
7687 | ||
49727e46 AM |
7688 | eh_addr_size = fc->ptr_size; |
7689 | } | |
7690 | else | |
7691 | { | |
7692 | fc->ptr_size = eh_addr_size; | |
7693 | fc->segment_size = 0; | |
7694 | } | |
442a6ce8 | 7695 | |
cd30bcef AM |
7696 | READ_ULEB (fc->code_factor, start, end); |
7697 | READ_SLEB (fc->data_factor, start, end); | |
442a6ce8 | 7698 | |
49727e46 AM |
7699 | if (version == 1) |
7700 | { | |
7701 | GET (fc->ra, 1); | |
7702 | } | |
7703 | else | |
7704 | { | |
cd30bcef | 7705 | READ_ULEB (fc->ra, start, end); |
49727e46 AM |
7706 | } |
7707 | ||
7708 | if (fc->augmentation[0] == 'z') | |
7709 | { | |
cd30bcef | 7710 | READ_ULEB (augmentation_data_len, start, end); |
49727e46 | 7711 | augmentation_data = start; |
a1165289 | 7712 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 7713 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 7714 | { |
bf59c5d5 NC |
7715 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
7716 | dwarf_vmatoa ("x", augmentation_data_len), | |
7717 | (unsigned long) (end - start)); | |
442a6ce8 | 7718 | goto fail; |
a1165289 | 7719 | } |
9c0f3d3f | 7720 | start += augmentation_data_len; |
49727e46 AM |
7721 | } |
7722 | ||
7723 | if (augmentation_data_len) | |
7724 | { | |
058037d3 NC |
7725 | unsigned char *p; |
7726 | unsigned char *q; | |
7727 | unsigned char *qend; | |
b4eb7656 | 7728 | |
49727e46 AM |
7729 | p = (unsigned char *) fc->augmentation + 1; |
7730 | q = augmentation_data; | |
058037d3 NC |
7731 | qend = q + augmentation_data_len; |
7732 | ||
9c0f3d3f | 7733 | while (p < end && q < qend) |
49727e46 AM |
7734 | { |
7735 | if (*p == 'L') | |
7736 | q++; | |
7737 | else if (*p == 'P') | |
7738 | q += 1 + size_of_encoded_value (*q); | |
7739 | else if (*p == 'R') | |
7740 | fc->fde_encoding = *q++; | |
7741 | else if (*p == 'S') | |
7742 | ; | |
09038062 ST |
7743 | else if (*p == 'B') |
7744 | ; | |
49727e46 AM |
7745 | else |
7746 | break; | |
7747 | p++; | |
7748 | } | |
c361b9ac NC |
7749 | /* Note - it is OK if this loop terminates with q < qend. |
7750 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
7751 | } |
7752 | ||
7753 | *p_cie = fc; | |
7754 | if (p_version) | |
7755 | *p_version = version; | |
7756 | if (p_aug_len) | |
7757 | { | |
7758 | *p_aug_len = augmentation_data_len; | |
7759 | *p_aug = augmentation_data; | |
7760 | } | |
7761 | return start; | |
442a6ce8 NC |
7762 | |
7763 | fail: | |
7764 | free (fc->col_offset); | |
7765 | free (fc->col_type); | |
7766 | free (fc); | |
7767 | return end; | |
49727e46 AM |
7768 | } |
7769 | ||
d85bf2ba NC |
7770 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
7771 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
7772 | PRINTED contains the number of characters already written to the current | |
7773 | output line. */ | |
bf59c5d5 NC |
7774 | |
7775 | static void | |
d85bf2ba NC |
7776 | display_data (bfd_size_type printed, |
7777 | const unsigned char * data, | |
7778 | const bfd_size_type len) | |
bf59c5d5 | 7779 | { |
d85bf2ba NC |
7780 | if (do_wide || len < ((80 - printed) / 3)) |
7781 | for (printed = 0; printed < len; ++printed) | |
7782 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
7783 | else |
7784 | { | |
d85bf2ba | 7785 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 7786 | { |
d85bf2ba | 7787 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 7788 | putchar ('\n'); |
d85bf2ba | 7789 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
7790 | } |
7791 | } | |
d85bf2ba NC |
7792 | } |
7793 | ||
7794 | /* Prints out the contents on the augmentation data array. | |
7795 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
7796 | ||
7797 | static void | |
7798 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
7799 | { | |
7800 | bfd_size_type i; | |
7801 | ||
7802 | i = printf (_(" Augmentation data: ")); | |
7803 | display_data (i, data, len); | |
bf59c5d5 NC |
7804 | } |
7805 | ||
19e6b90e L |
7806 | static int |
7807 | display_debug_frames (struct dwarf_section *section, | |
7808 | void *file ATTRIBUTE_UNUSED) | |
7809 | { | |
7810 | unsigned char *start = section->start; | |
7811 | unsigned char *end = start + section->size; | |
7812 | unsigned char *section_start = start; | |
3391569f NC |
7813 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
7814 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 7815 | Frame_Chunk *rs; |
3391569f | 7816 | bfd_boolean is_eh = strcmp (section->name, ".eh_frame") == 0; |
a1165289 | 7817 | unsigned int max_regs = 0; |
665ce1f6 | 7818 | const char *bad_reg = _("bad register: "); |
77ef8654 | 7819 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 7820 | |
dda8d76d | 7821 | introduce (section, FALSE); |
19e6b90e L |
7822 | |
7823 | while (start < end) | |
7824 | { | |
7825 | unsigned char *saved_start; | |
7826 | unsigned char *block_end; | |
bf5117e3 NC |
7827 | dwarf_vma length; |
7828 | dwarf_vma cie_id; | |
19e6b90e L |
7829 | Frame_Chunk *fc; |
7830 | Frame_Chunk *cie; | |
7831 | int need_col_headers = 1; | |
7832 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 7833 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
7834 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
7835 | unsigned int offset_size; | |
7836 | unsigned int initial_length_size; | |
5b6312fd | 7837 | bfd_boolean all_nops; |
a788aedd | 7838 | static Frame_Chunk fde_fc; |
19e6b90e L |
7839 | |
7840 | saved_start = start; | |
19e6b90e | 7841 | |
0c588247 | 7842 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 7843 | |
19e6b90e L |
7844 | if (length == 0) |
7845 | { | |
7846 | printf ("\n%08lx ZERO terminator\n\n", | |
7847 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
7848 | /* Skip any zero terminators that directly follow. |
7849 | A corrupt section size could have loaded a whole | |
7850 | slew of zero filled memory bytes. eg | |
7851 | PR 17512: file: 070-19381-0.004. */ | |
7852 | while (start < end && * start == 0) | |
7853 | ++ start; | |
b758e50f | 7854 | continue; |
19e6b90e L |
7855 | } |
7856 | ||
7857 | if (length == 0xffffffff) | |
7858 | { | |
0c588247 | 7859 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
7860 | offset_size = 8; |
7861 | initial_length_size = 12; | |
7862 | } | |
7863 | else | |
7864 | { | |
7865 | offset_size = 4; | |
7866 | initial_length_size = 4; | |
7867 | } | |
7868 | ||
7869 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 7870 | if (block_end > end || block_end < start) |
53b8873b | 7871 | { |
bf5117e3 NC |
7872 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
7873 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
7874 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
7875 | block_end = end; |
7876 | } | |
0c588247 NC |
7877 | |
7878 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 7879 | |
846a11e4 NC |
7880 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
7881 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
7882 | { |
7883 | int version; | |
a1165289 | 7884 | unsigned int mreg; |
19e6b90e | 7885 | |
49727e46 AM |
7886 | start = read_cie (start, end, &cie, &version, |
7887 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
7888 | /* PR 17512: file: 027-135133-0.005. */ |
7889 | if (cie == NULL) | |
7890 | break; | |
a1165289 | 7891 | |
49727e46 | 7892 | fc = cie; |
19e6b90e L |
7893 | fc->next = chunks; |
7894 | chunks = fc; | |
7895 | fc->chunk_start = saved_start; | |
a1165289 | 7896 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
7897 | if (mreg < fc->ra) |
7898 | mreg = fc->ra; | |
06614111 NC |
7899 | if (frame_need_space (fc, mreg) < 0) |
7900 | break; | |
49727e46 AM |
7901 | if (fc->fde_encoding) |
7902 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 7903 | |
bf5117e3 NC |
7904 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
7905 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 7906 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 7907 | |
19e6b90e | 7908 | if (do_debug_frames_interp) |
bf5117e3 NC |
7909 | { |
7910 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
7911 | fc->code_factor, fc->data_factor, fc->ra); | |
7912 | } | |
19e6b90e L |
7913 | else |
7914 | { | |
bf5117e3 | 7915 | printf ("CIE\n"); |
19e6b90e L |
7916 | printf (" Version: %d\n", version); |
7917 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
7918 | if (version >= 4) |
7919 | { | |
7920 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
7921 | printf (" Segment Size: %u\n", fc->segment_size); | |
7922 | } | |
19e6b90e L |
7923 | printf (" Code alignment factor: %u\n", fc->code_factor); |
7924 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
7925 | printf (" Return address column: %d\n", fc->ra); | |
7926 | ||
7927 | if (augmentation_data_len) | |
bf59c5d5 | 7928 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 7929 | |
19e6b90e L |
7930 | putchar ('\n'); |
7931 | } | |
19e6b90e L |
7932 | } |
7933 | else | |
7934 | { | |
7935 | unsigned char *look_for; | |
604282a7 | 7936 | unsigned long segment_selector; |
19e6b90e | 7937 | |
49727e46 AM |
7938 | if (is_eh) |
7939 | { | |
7940 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
7941 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
7942 | } | |
7943 | else | |
7944 | look_for = section_start + cie_id; | |
19e6b90e | 7945 | |
49727e46 AM |
7946 | if (look_for <= saved_start) |
7947 | { | |
7948 | for (cie = chunks; cie ; cie = cie->next) | |
7949 | if (cie->chunk_start == look_for) | |
7950 | break; | |
7951 | } | |
7952 | else | |
7953 | { | |
7954 | for (cie = forward_refs; cie ; cie = cie->next) | |
7955 | if (cie->chunk_start == look_for) | |
7956 | break; | |
7957 | if (!cie) | |
7958 | { | |
7959 | unsigned int off_size; | |
7960 | unsigned char *cie_scan; | |
19e6b90e | 7961 | |
49727e46 AM |
7962 | cie_scan = look_for; |
7963 | off_size = 4; | |
7964 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
7965 | if (length == 0xffffffff) | |
7966 | { | |
7967 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
7968 | off_size = 8; | |
7969 | } | |
7970 | if (length != 0) | |
7971 | { | |
7972 | dwarf_vma c_id; | |
7973 | ||
7974 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
7975 | if (is_eh | |
7976 | ? c_id == 0 | |
7977 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
7978 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
7979 | { | |
7980 | int version; | |
a1165289 | 7981 | unsigned int mreg; |
49727e46 AM |
7982 | |
7983 | read_cie (cie_scan, end, &cie, &version, | |
7984 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
7985 | /* PR 17512: file: 3450-2098-0.004. */ |
7986 | if (cie == NULL) | |
7987 | { | |
7988 | warn (_("Failed to read CIE information\n")); | |
7989 | break; | |
7990 | } | |
49727e46 AM |
7991 | cie->next = forward_refs; |
7992 | forward_refs = cie; | |
7993 | cie->chunk_start = look_for; | |
a1165289 | 7994 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
7995 | if (mreg < cie->ra) |
7996 | mreg = cie->ra; | |
06614111 NC |
7997 | if (frame_need_space (cie, mreg) < 0) |
7998 | { | |
7999 | warn (_("Invalid max register\n")); | |
8000 | break; | |
8001 | } | |
49727e46 AM |
8002 | if (cie->fde_encoding) |
8003 | encoded_ptr_size | |
8004 | = size_of_encoded_value (cie->fde_encoding); | |
8005 | } | |
8006 | } | |
8007 | } | |
8008 | } | |
8009 | ||
8010 | fc = &fde_fc; | |
8011 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
8012 | |
8013 | if (!cie) | |
8014 | { | |
bf5117e3 NC |
8015 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
8016 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
8017 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 8018 | fc->ncols = 0; |
3f5e193b NC |
8019 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
8020 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
8021 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
8022 | { | |
8023 | warn (_("Invalid max register\n")); | |
8024 | break; | |
8025 | } | |
19e6b90e L |
8026 | cie = fc; |
8027 | fc->augmentation = ""; | |
8028 | fc->fde_encoding = 0; | |
604282a7 JJ |
8029 | fc->ptr_size = eh_addr_size; |
8030 | fc->segment_size = 0; | |
19e6b90e L |
8031 | } |
8032 | else | |
8033 | { | |
8034 | fc->ncols = cie->ncols; | |
3f5e193b NC |
8035 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
8036 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
8037 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
8038 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
8039 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
8040 | fc->ptr_size = cie->ptr_size; |
8041 | eh_addr_size = cie->ptr_size; | |
8042 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
8043 | fc->code_factor = cie->code_factor; |
8044 | fc->data_factor = cie->data_factor; | |
8045 | fc->cfa_reg = cie->cfa_reg; | |
8046 | fc->cfa_offset = cie->cfa_offset; | |
8047 | fc->ra = cie->ra; | |
06614111 NC |
8048 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
8049 | { | |
8050 | warn (_("Invalid max register\n")); | |
8051 | break; | |
8052 | } | |
19e6b90e L |
8053 | fc->fde_encoding = cie->fde_encoding; |
8054 | } | |
8055 | ||
8056 | if (fc->fde_encoding) | |
8057 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
8058 | ||
604282a7 JJ |
8059 | segment_selector = 0; |
8060 | if (fc->segment_size) | |
c8071705 NC |
8061 | { |
8062 | if (fc->segment_size > sizeof (segment_selector)) | |
8063 | { | |
8064 | /* PR 17512: file: 9e196b3e. */ | |
8065 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
8066 | fc->segment_size = 4; | |
8067 | } | |
8068 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
8069 | } | |
041830e0 NC |
8070 | |
8071 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 8072 | |
0c588247 NC |
8073 | /* FIXME: It appears that sometimes the final pc_range value is |
8074 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
8075 | run of the "objcopy on compressed debug sections" test for an | |
8076 | example of this. */ | |
8077 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 8078 | |
19e6b90e L |
8079 | if (cie->augmentation[0] == 'z') |
8080 | { | |
cd30bcef | 8081 | READ_ULEB (augmentation_data_len, start, end); |
19e6b90e | 8082 | augmentation_data = start; |
bf59c5d5 | 8083 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
d292364e | 8084 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
0a9d414a | 8085 | { |
d292364e AM |
8086 | warn (_("Augmentation data too long: 0x%s, " |
8087 | "expected at most %#lx\n"), | |
8088 | dwarf_vmatoa ("x", augmentation_data_len), | |
8089 | (unsigned long) (end - start)); | |
0a9d414a NC |
8090 | start = end; |
8091 | augmentation_data = NULL; | |
8092 | augmentation_data_len = 0; | |
8093 | } | |
d292364e | 8094 | start += augmentation_data_len; |
19e6b90e L |
8095 | } |
8096 | ||
bf5117e3 NC |
8097 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
8098 | (unsigned long)(saved_start - section_start), | |
8099 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 8100 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 8101 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 8102 | |
604282a7 JJ |
8103 | if (fc->segment_size) |
8104 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
8105 | |
8106 | printf ("%s..%s\n", | |
8107 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
8108 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
8109 | ||
19e6b90e L |
8110 | if (! do_debug_frames_interp && augmentation_data_len) |
8111 | { | |
bf59c5d5 | 8112 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
8113 | putchar ('\n'); |
8114 | } | |
8115 | } | |
8116 | ||
8117 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
8118 | we're about to interpret instructions for the chunk. */ | |
8119 | /* ??? At present we need to do this always, since this sizes the | |
8120 | fc->col_type and fc->col_offset arrays, which we write into always. | |
8121 | We should probably split the interpreted and non-interpreted bits | |
8122 | into two different routines, since there's so much that doesn't | |
8123 | really overlap between them. */ | |
8124 | if (1 || do_debug_frames_interp) | |
8125 | { | |
8126 | /* Start by making a pass over the chunk, allocating storage | |
8127 | and taking note of what registers are used. */ | |
8128 | unsigned char *tmp = start; | |
8129 | ||
8130 | while (start < block_end) | |
8131 | { | |
041830e0 NC |
8132 | unsigned int reg, op, opa; |
8133 | unsigned long temp; | |
5929c344 | 8134 | unsigned char * new_start; |
19e6b90e L |
8135 | |
8136 | op = *start++; | |
8137 | opa = op & 0x3f; | |
8138 | if (op & 0xc0) | |
8139 | op &= 0xc0; | |
8140 | ||
8141 | /* Warning: if you add any more cases to this switch, be | |
8142 | sure to add them to the corresponding switch below. */ | |
8143 | switch (op) | |
8144 | { | |
8145 | case DW_CFA_advance_loc: | |
8146 | break; | |
8147 | case DW_CFA_offset: | |
cd30bcef | 8148 | SKIP_ULEB (start, end); |
665ce1f6 L |
8149 | if (frame_need_space (fc, opa) >= 0) |
8150 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8151 | break; |
8152 | case DW_CFA_restore: | |
665ce1f6 L |
8153 | if (frame_need_space (fc, opa) >= 0) |
8154 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8155 | break; |
8156 | case DW_CFA_set_loc: | |
8157 | start += encoded_ptr_size; | |
8158 | break; | |
8159 | case DW_CFA_advance_loc1: | |
8160 | start += 1; | |
8161 | break; | |
8162 | case DW_CFA_advance_loc2: | |
8163 | start += 2; | |
8164 | break; | |
8165 | case DW_CFA_advance_loc4: | |
8166 | start += 4; | |
8167 | break; | |
8168 | case DW_CFA_offset_extended: | |
12eae2d3 | 8169 | case DW_CFA_val_offset: |
cd30bcef AM |
8170 | READ_ULEB (reg, start, end); |
8171 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8172 | if (frame_need_space (fc, reg) >= 0) |
8173 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8174 | break; |
8175 | case DW_CFA_restore_extended: | |
cd30bcef | 8176 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8177 | if (frame_need_space (fc, reg) >= 0) |
8178 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8179 | break; |
8180 | case DW_CFA_undefined: | |
cd30bcef | 8181 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8182 | if (frame_need_space (fc, reg) >= 0) |
8183 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8184 | break; |
8185 | case DW_CFA_same_value: | |
cd30bcef | 8186 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8187 | if (frame_need_space (fc, reg) >= 0) |
8188 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8189 | break; |
8190 | case DW_CFA_register: | |
cd30bcef AM |
8191 | READ_ULEB (reg, start, end); |
8192 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8193 | if (frame_need_space (fc, reg) >= 0) |
8194 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8195 | break; |
8196 | case DW_CFA_def_cfa: | |
cd30bcef AM |
8197 | SKIP_ULEB (start, end); |
8198 | SKIP_ULEB (start, end); | |
19e6b90e L |
8199 | break; |
8200 | case DW_CFA_def_cfa_register: | |
cd30bcef | 8201 | SKIP_ULEB (start, end); |
19e6b90e L |
8202 | break; |
8203 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 8204 | SKIP_ULEB (start, end); |
19e6b90e L |
8205 | break; |
8206 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 8207 | READ_ULEB (temp, start, end); |
5929c344 NC |
8208 | new_start = start + temp; |
8209 | if (new_start < start) | |
041830e0 NC |
8210 | { |
8211 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
8212 | start = block_end; | |
8213 | } | |
8214 | else | |
5929c344 | 8215 | start = new_start; |
19e6b90e L |
8216 | break; |
8217 | case DW_CFA_expression: | |
12eae2d3 | 8218 | case DW_CFA_val_expression: |
cd30bcef AM |
8219 | READ_ULEB (reg, start, end); |
8220 | READ_ULEB (temp, start, end); | |
5929c344 NC |
8221 | new_start = start + temp; |
8222 | if (new_start < start) | |
041830e0 | 8223 | { |
b4eb7656 | 8224 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
8225 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
8226 | start = block_end; | |
8227 | } | |
8228 | else | |
5929c344 | 8229 | start = new_start; |
665ce1f6 L |
8230 | if (frame_need_space (fc, reg) >= 0) |
8231 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8232 | break; |
8233 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 8234 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
8235 | READ_ULEB (reg, start, end); |
8236 | SKIP_SLEB (start, end); | |
665ce1f6 L |
8237 | if (frame_need_space (fc, reg) >= 0) |
8238 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8239 | break; |
8240 | case DW_CFA_def_cfa_sf: | |
cd30bcef AM |
8241 | SKIP_ULEB (start, end); |
8242 | SKIP_SLEB (start, end); | |
19e6b90e L |
8243 | break; |
8244 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 8245 | SKIP_SLEB (start, end); |
19e6b90e L |
8246 | break; |
8247 | case DW_CFA_MIPS_advance_loc8: | |
8248 | start += 8; | |
8249 | break; | |
8250 | case DW_CFA_GNU_args_size: | |
cd30bcef | 8251 | SKIP_ULEB (start, end); |
19e6b90e L |
8252 | break; |
8253 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
8254 | READ_ULEB (reg, start, end); |
8255 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8256 | if (frame_need_space (fc, reg) >= 0) |
8257 | fc->col_type[reg] = DW_CFA_undefined; | |
8258 | break; | |
19e6b90e L |
8259 | default: |
8260 | break; | |
8261 | } | |
8262 | } | |
8263 | start = tmp; | |
8264 | } | |
8265 | ||
5b6312fd NC |
8266 | all_nops = TRUE; |
8267 | ||
19e6b90e L |
8268 | /* Now we know what registers are used, make a second pass over |
8269 | the chunk, this time actually printing out the info. */ | |
8270 | ||
8271 | while (start < block_end) | |
8272 | { | |
362beea4 | 8273 | unsigned char * tmp; |
19e6b90e | 8274 | unsigned op, opa; |
7f2c8a1d NC |
8275 | unsigned long ul, roffs; |
8276 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
8277 | are various functions, notably frame_space_needed() that assume that | |
8278 | reg is an unsigned int. */ | |
8279 | unsigned int reg; | |
8280 | dwarf_signed_vma l; | |
bf5117e3 | 8281 | dwarf_vma ofs; |
19e6b90e | 8282 | dwarf_vma vma; |
665ce1f6 | 8283 | const char *reg_prefix = ""; |
19e6b90e L |
8284 | |
8285 | op = *start++; | |
8286 | opa = op & 0x3f; | |
8287 | if (op & 0xc0) | |
8288 | op &= 0xc0; | |
8289 | ||
5b6312fd NC |
8290 | /* Make a note if something other than DW_CFA_nop happens. */ |
8291 | if (op != DW_CFA_nop) | |
8292 | all_nops = FALSE; | |
8293 | ||
19e6b90e L |
8294 | /* Warning: if you add any more cases to this switch, be |
8295 | sure to add them to the corresponding switch above. */ | |
8296 | switch (op) | |
8297 | { | |
8298 | case DW_CFA_advance_loc: | |
8299 | if (do_debug_frames_interp) | |
8300 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8301 | else | |
bf5117e3 | 8302 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 8303 | opa * fc->code_factor, |
b4eb7656 | 8304 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
8305 | fc->pc_begin + opa * fc->code_factor, |
8306 | fc->ptr_size)); | |
19e6b90e L |
8307 | fc->pc_begin += opa * fc->code_factor; |
8308 | break; | |
8309 | ||
8310 | case DW_CFA_offset: | |
cd30bcef | 8311 | READ_ULEB (roffs, start, end); |
665ce1f6 L |
8312 | if (opa >= (unsigned int) fc->ncols) |
8313 | reg_prefix = bad_reg; | |
8314 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8315 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
8316 | reg_prefix, regname (opa, 0), | |
8317 | roffs * fc->data_factor); | |
8318 | if (*reg_prefix == '\0') | |
8319 | { | |
8320 | fc->col_type[opa] = DW_CFA_offset; | |
8321 | fc->col_offset[opa] = roffs * fc->data_factor; | |
8322 | } | |
19e6b90e L |
8323 | break; |
8324 | ||
8325 | case DW_CFA_restore: | |
50751e18 | 8326 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
8327 | reg_prefix = bad_reg; |
8328 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8329 | printf (" DW_CFA_restore: %s%s\n", | |
8330 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
8331 | if (*reg_prefix != '\0') |
8332 | break; | |
8333 | ||
8334 | if (opa >= (unsigned int) cie->ncols | |
8335 | || (do_debug_frames_interp | |
8336 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
8337 | { | |
8338 | fc->col_type[opa] = DW_CFA_undefined; | |
8339 | fc->col_offset[opa] = 0; | |
8340 | } | |
8341 | else | |
665ce1f6 L |
8342 | { |
8343 | fc->col_type[opa] = cie->col_type[opa]; | |
8344 | fc->col_offset[opa] = cie->col_offset[opa]; | |
8345 | } | |
19e6b90e L |
8346 | break; |
8347 | ||
8348 | case DW_CFA_set_loc: | |
6937bb54 | 8349 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
8350 | if (do_debug_frames_interp) |
8351 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8352 | else | |
bf5117e3 NC |
8353 | printf (" DW_CFA_set_loc: %s\n", |
8354 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
8355 | fc->pc_begin = vma; |
8356 | break; | |
8357 | ||
8358 | case DW_CFA_advance_loc1: | |
0c588247 | 8359 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
8360 | if (do_debug_frames_interp) |
8361 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8362 | else | |
bf5117e3 NC |
8363 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
8364 | (unsigned long) (ofs * fc->code_factor), | |
8365 | dwarf_vmatoa_1 (NULL, | |
8366 | fc->pc_begin + ofs * fc->code_factor, | |
8367 | fc->ptr_size)); | |
19e6b90e L |
8368 | fc->pc_begin += ofs * fc->code_factor; |
8369 | break; | |
8370 | ||
8371 | case DW_CFA_advance_loc2: | |
6937bb54 | 8372 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
8373 | if (do_debug_frames_interp) |
8374 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8375 | else | |
bf5117e3 NC |
8376 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
8377 | (unsigned long) (ofs * fc->code_factor), | |
8378 | dwarf_vmatoa_1 (NULL, | |
8379 | fc->pc_begin + ofs * fc->code_factor, | |
8380 | fc->ptr_size)); | |
19e6b90e L |
8381 | fc->pc_begin += ofs * fc->code_factor; |
8382 | break; | |
8383 | ||
8384 | case DW_CFA_advance_loc4: | |
6937bb54 | 8385 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
8386 | if (do_debug_frames_interp) |
8387 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8388 | else | |
bf5117e3 NC |
8389 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
8390 | (unsigned long) (ofs * fc->code_factor), | |
8391 | dwarf_vmatoa_1 (NULL, | |
8392 | fc->pc_begin + ofs * fc->code_factor, | |
8393 | fc->ptr_size)); | |
19e6b90e L |
8394 | fc->pc_begin += ofs * fc->code_factor; |
8395 | break; | |
8396 | ||
8397 | case DW_CFA_offset_extended: | |
cd30bcef AM |
8398 | READ_ULEB (reg, start, end); |
8399 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
8400 | if (reg >= (unsigned int) fc->ncols) |
8401 | reg_prefix = bad_reg; | |
8402 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8403 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
8404 | reg_prefix, regname (reg, 0), | |
8405 | roffs * fc->data_factor); | |
8406 | if (*reg_prefix == '\0') | |
8407 | { | |
8408 | fc->col_type[reg] = DW_CFA_offset; | |
8409 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8410 | } | |
19e6b90e L |
8411 | break; |
8412 | ||
12eae2d3 | 8413 | case DW_CFA_val_offset: |
cd30bcef AM |
8414 | READ_ULEB (reg, start, end); |
8415 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
8416 | if (reg >= (unsigned int) fc->ncols) |
8417 | reg_prefix = bad_reg; | |
8418 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8419 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
8420 | reg_prefix, regname (reg, 0), |
8421 | roffs * fc->data_factor); | |
8422 | if (*reg_prefix == '\0') | |
8423 | { | |
8424 | fc->col_type[reg] = DW_CFA_val_offset; | |
8425 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8426 | } | |
12eae2d3 JJ |
8427 | break; |
8428 | ||
19e6b90e | 8429 | case DW_CFA_restore_extended: |
cd30bcef | 8430 | READ_ULEB (reg, start, end); |
50751e18 | 8431 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
8432 | reg_prefix = bad_reg; |
8433 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8434 | printf (" DW_CFA_restore_extended: %s%s\n", | |
8435 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
8436 | if (*reg_prefix != '\0') |
8437 | break; | |
8438 | ||
8439 | if (reg >= (unsigned int) cie->ncols) | |
8440 | { | |
8441 | fc->col_type[reg] = DW_CFA_undefined; | |
8442 | fc->col_offset[reg] = 0; | |
8443 | } | |
8444 | else | |
665ce1f6 L |
8445 | { |
8446 | fc->col_type[reg] = cie->col_type[reg]; | |
8447 | fc->col_offset[reg] = cie->col_offset[reg]; | |
8448 | } | |
19e6b90e L |
8449 | break; |
8450 | ||
8451 | case DW_CFA_undefined: | |
cd30bcef | 8452 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8453 | if (reg >= (unsigned int) fc->ncols) |
8454 | reg_prefix = bad_reg; | |
8455 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8456 | printf (" DW_CFA_undefined: %s%s\n", | |
8457 | reg_prefix, regname (reg, 0)); | |
8458 | if (*reg_prefix == '\0') | |
8459 | { | |
8460 | fc->col_type[reg] = DW_CFA_undefined; | |
8461 | fc->col_offset[reg] = 0; | |
8462 | } | |
19e6b90e L |
8463 | break; |
8464 | ||
8465 | case DW_CFA_same_value: | |
cd30bcef | 8466 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8467 | if (reg >= (unsigned int) fc->ncols) |
8468 | reg_prefix = bad_reg; | |
8469 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8470 | printf (" DW_CFA_same_value: %s%s\n", | |
8471 | reg_prefix, regname (reg, 0)); | |
8472 | if (*reg_prefix == '\0') | |
8473 | { | |
8474 | fc->col_type[reg] = DW_CFA_same_value; | |
8475 | fc->col_offset[reg] = 0; | |
8476 | } | |
19e6b90e L |
8477 | break; |
8478 | ||
8479 | case DW_CFA_register: | |
cd30bcef AM |
8480 | READ_ULEB (reg, start, end); |
8481 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
8482 | if (reg >= (unsigned int) fc->ncols) |
8483 | reg_prefix = bad_reg; | |
8484 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 8485 | { |
665ce1f6 L |
8486 | printf (" DW_CFA_register: %s%s in ", |
8487 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
8488 | puts (regname (roffs, 0)); |
8489 | } | |
665ce1f6 L |
8490 | if (*reg_prefix == '\0') |
8491 | { | |
8492 | fc->col_type[reg] = DW_CFA_register; | |
8493 | fc->col_offset[reg] = roffs; | |
8494 | } | |
19e6b90e L |
8495 | break; |
8496 | ||
8497 | case DW_CFA_remember_state: | |
8498 | if (! do_debug_frames_interp) | |
8499 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 8500 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 8501 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
8502 | rs->cfa_reg = fc->cfa_reg; |
8503 | rs->ra = fc->ra; | |
8504 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 8505 | rs->ncols = fc->ncols; |
3f5e193b | 8506 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 8507 | sizeof (* rs->col_type)); |
d71ad7fc RC |
8508 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
8509 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
8510 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
8511 | rs->next = remembered_state; |
8512 | remembered_state = rs; | |
8513 | break; | |
8514 | ||
8515 | case DW_CFA_restore_state: | |
8516 | if (! do_debug_frames_interp) | |
8517 | printf (" DW_CFA_restore_state\n"); | |
8518 | rs = remembered_state; | |
8519 | if (rs) | |
8520 | { | |
8521 | remembered_state = rs->next; | |
d71ad7fc RC |
8522 | fc->cfa_offset = rs->cfa_offset; |
8523 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
8524 | fc->ra = rs->ra; |
8525 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
8526 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
8527 | { | |
1306a742 | 8528 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
8529 | fc->ncols = 0; |
8530 | break; | |
8531 | } | |
d71ad7fc | 8532 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 8533 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 8534 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
8535 | free (rs->col_type); |
8536 | free (rs->col_offset); | |
8537 | free (rs); | |
8538 | } | |
8539 | else if (do_debug_frames_interp) | |
8540 | printf ("Mismatched DW_CFA_restore_state\n"); | |
8541 | break; | |
8542 | ||
8543 | case DW_CFA_def_cfa: | |
cd30bcef AM |
8544 | READ_ULEB (fc->cfa_reg, start, end); |
8545 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
8546 | fc->cfa_exp = 0; |
8547 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8548 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 8549 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8550 | break; |
8551 | ||
8552 | case DW_CFA_def_cfa_register: | |
cd30bcef | 8553 | READ_ULEB (fc->cfa_reg, start, end); |
19e6b90e L |
8554 | fc->cfa_exp = 0; |
8555 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
8556 | printf (" DW_CFA_def_cfa_register: %s\n", |
8557 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
8558 | break; |
8559 | ||
8560 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 8561 | READ_ULEB (fc->cfa_offset, start, end); |
19e6b90e | 8562 | if (! do_debug_frames_interp) |
c8071705 | 8563 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8564 | break; |
8565 | ||
8566 | case DW_CFA_nop: | |
8567 | if (! do_debug_frames_interp) | |
8568 | printf (" DW_CFA_nop\n"); | |
8569 | break; | |
8570 | ||
8571 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 8572 | READ_ULEB (ul, start, end); |
7460c0ab | 8573 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 8574 | { |
a1165289 | 8575 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8576 | break; |
8577 | } | |
19e6b90e L |
8578 | if (! do_debug_frames_interp) |
8579 | { | |
8580 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
8581 | decode_location_expression (start, eh_addr_size, 0, -1, |
8582 | ul, 0, section); | |
19e6b90e L |
8583 | printf (")\n"); |
8584 | } | |
8585 | fc->cfa_exp = 1; | |
8586 | start += ul; | |
8587 | break; | |
8588 | ||
8589 | case DW_CFA_expression: | |
cd30bcef AM |
8590 | READ_ULEB (reg, start, end); |
8591 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
8592 | if (reg >= (unsigned int) fc->ncols) |
8593 | reg_prefix = bad_reg; | |
6937bb54 | 8594 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 8595 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
8596 | tmp = start + ul; |
8597 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8598 | { |
a1165289 | 8599 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8600 | break; |
8601 | } | |
665ce1f6 | 8602 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 8603 | { |
665ce1f6 L |
8604 | printf (" DW_CFA_expression: %s%s (", |
8605 | reg_prefix, regname (reg, 0)); | |
b7807392 | 8606 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 8607 | ul, 0, section); |
19e6b90e L |
8608 | printf (")\n"); |
8609 | } | |
665ce1f6 L |
8610 | if (*reg_prefix == '\0') |
8611 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 8612 | start = tmp; |
19e6b90e L |
8613 | break; |
8614 | ||
12eae2d3 | 8615 | case DW_CFA_val_expression: |
cd30bcef AM |
8616 | READ_ULEB (reg, start, end); |
8617 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
8618 | if (reg >= (unsigned int) fc->ncols) |
8619 | reg_prefix = bad_reg; | |
362beea4 NC |
8620 | tmp = start + ul; |
8621 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8622 | { |
a1165289 | 8623 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
8624 | break; |
8625 | } | |
665ce1f6 | 8626 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 8627 | { |
665ce1f6 L |
8628 | printf (" DW_CFA_val_expression: %s%s (", |
8629 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
8630 | decode_location_expression (start, eh_addr_size, 0, -1, |
8631 | ul, 0, section); | |
12eae2d3 JJ |
8632 | printf (")\n"); |
8633 | } | |
665ce1f6 L |
8634 | if (*reg_prefix == '\0') |
8635 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 8636 | start = tmp; |
12eae2d3 JJ |
8637 | break; |
8638 | ||
19e6b90e | 8639 | case DW_CFA_offset_extended_sf: |
cd30bcef AM |
8640 | READ_ULEB (reg, start, end); |
8641 | READ_SLEB (l, start, end); | |
665ce1f6 L |
8642 | if (frame_need_space (fc, reg) < 0) |
8643 | reg_prefix = bad_reg; | |
8644 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8645 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
8646 | reg_prefix, regname (reg, 0), | |
c8071705 | 8647 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8648 | if (*reg_prefix == '\0') |
8649 | { | |
8650 | fc->col_type[reg] = DW_CFA_offset; | |
8651 | fc->col_offset[reg] = l * fc->data_factor; | |
8652 | } | |
19e6b90e L |
8653 | break; |
8654 | ||
12eae2d3 | 8655 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
8656 | READ_ULEB (reg, start, end); |
8657 | READ_SLEB (l, start, end); | |
665ce1f6 L |
8658 | if (frame_need_space (fc, reg) < 0) |
8659 | reg_prefix = bad_reg; | |
8660 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8661 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 8662 | reg_prefix, regname (reg, 0), |
c8071705 | 8663 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8664 | if (*reg_prefix == '\0') |
8665 | { | |
8666 | fc->col_type[reg] = DW_CFA_val_offset; | |
8667 | fc->col_offset[reg] = l * fc->data_factor; | |
8668 | } | |
12eae2d3 JJ |
8669 | break; |
8670 | ||
19e6b90e | 8671 | case DW_CFA_def_cfa_sf: |
cd30bcef AM |
8672 | READ_ULEB (fc->cfa_reg, start, end); |
8673 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
8674 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
8675 | fc->cfa_exp = 0; | |
8676 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8677 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 8678 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8679 | break; |
8680 | ||
8681 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 8682 | READ_ULEB (fc->cfa_offset, start, end); |
c8071705 | 8683 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 8684 | if (! do_debug_frames_interp) |
c8071705 | 8685 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8686 | break; |
8687 | ||
8688 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 8689 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
8690 | if (do_debug_frames_interp) |
8691 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8692 | else | |
bf5117e3 NC |
8693 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
8694 | (unsigned long) (ofs * fc->code_factor), | |
8695 | dwarf_vmatoa_1 (NULL, | |
8696 | fc->pc_begin + ofs * fc->code_factor, | |
8697 | fc->ptr_size)); | |
19e6b90e L |
8698 | fc->pc_begin += ofs * fc->code_factor; |
8699 | break; | |
8700 | ||
8701 | case DW_CFA_GNU_window_save: | |
8702 | if (! do_debug_frames_interp) | |
8703 | printf (" DW_CFA_GNU_window_save\n"); | |
8704 | break; | |
8705 | ||
8706 | case DW_CFA_GNU_args_size: | |
cd30bcef | 8707 | READ_ULEB (ul, start, end); |
19e6b90e L |
8708 | if (! do_debug_frames_interp) |
8709 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
8710 | break; | |
8711 | ||
8712 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
8713 | READ_ULEB (reg, start, end); |
8714 | READ_SLEB (l, start, end); | |
7f2c8a1d | 8715 | l = - l; |
665ce1f6 L |
8716 | if (frame_need_space (fc, reg) < 0) |
8717 | reg_prefix = bad_reg; | |
8718 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8719 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
8720 | reg_prefix, regname (reg, 0), | |
c8071705 | 8721 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8722 | if (*reg_prefix == '\0') |
8723 | { | |
8724 | fc->col_type[reg] = DW_CFA_offset; | |
8725 | fc->col_offset[reg] = l * fc->data_factor; | |
8726 | } | |
19e6b90e L |
8727 | break; |
8728 | ||
8729 | default: | |
53b8873b NC |
8730 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
8731 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
8732 | else | |
f41e4712 | 8733 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
8734 | start = block_end; |
8735 | } | |
8736 | } | |
8737 | ||
5b6312fd NC |
8738 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
8739 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
8740 | frame_display_row (fc, &need_col_headers, &max_regs); |
8741 | ||
a788aedd AM |
8742 | if (fde_fc.col_type != NULL) |
8743 | { | |
8744 | free (fde_fc.col_type); | |
8745 | fde_fc.col_type = NULL; | |
8746 | } | |
8747 | if (fde_fc.col_offset != NULL) | |
8748 | { | |
8749 | free (fde_fc.col_offset); | |
8750 | fde_fc.col_offset = NULL; | |
8751 | } | |
8752 | ||
19e6b90e | 8753 | start = block_end; |
604282a7 | 8754 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
8755 | } |
8756 | ||
8757 | printf ("\n"); | |
8758 | ||
3391569f NC |
8759 | while (remembered_state != NULL) |
8760 | { | |
8761 | rs = remembered_state; | |
8762 | remembered_state = rs->next; | |
8763 | free (rs->col_type); | |
8764 | free (rs->col_offset); | |
8765 | rs->next = NULL; /* Paranoia. */ | |
8766 | free (rs); | |
8767 | } | |
8768 | ||
8769 | while (chunks != NULL) | |
8770 | { | |
8771 | rs = chunks; | |
8772 | chunks = rs->next; | |
8773 | free (rs->col_type); | |
8774 | free (rs->col_offset); | |
8775 | rs->next = NULL; /* Paranoia. */ | |
8776 | free (rs); | |
8777 | } | |
8778 | ||
8779 | while (forward_refs != NULL) | |
8780 | { | |
8781 | rs = forward_refs; | |
8782 | forward_refs = rs->next; | |
8783 | free (rs->col_type); | |
8784 | free (rs->col_offset); | |
8785 | rs->next = NULL; /* Paranoia. */ | |
8786 | free (rs); | |
8787 | } | |
8788 | ||
19e6b90e L |
8789 | return 1; |
8790 | } | |
8791 | ||
8792 | #undef GET | |
19e6b90e | 8793 | |
61364358 JK |
8794 | static int |
8795 | display_debug_names (struct dwarf_section *section, void *file) | |
8796 | { | |
8797 | unsigned char *hdrptr = section->start; | |
8798 | dwarf_vma unit_length; | |
8799 | unsigned char *unit_start; | |
8800 | const unsigned char *const section_end = section->start + section->size; | |
8801 | unsigned char *unit_end; | |
8802 | ||
dda8d76d | 8803 | introduce (section, FALSE); |
61364358 | 8804 | |
dda8d76d | 8805 | load_debug_section_with_follow (str, file); |
61364358 JK |
8806 | |
8807 | for (; hdrptr < section_end; hdrptr = unit_end) | |
8808 | { | |
8809 | unsigned int offset_size; | |
8810 | uint16_t dwarf_version, padding; | |
8811 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
8812 | uint32_t bucket_count, name_count, abbrev_table_size; | |
8813 | uint32_t augmentation_string_size; | |
8814 | unsigned int i; | |
e98fdf1a | 8815 | unsigned long sec_off; |
48467cb9 TV |
8816 | bfd_boolean augmentation_printable; |
8817 | const char *augmentation_string; | |
61364358 JK |
8818 | |
8819 | unit_start = hdrptr; | |
8820 | ||
8821 | /* Get and check the length of the block. */ | |
8822 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
8823 | ||
8824 | if (unit_length == 0xffffffff) | |
8825 | { | |
8826 | /* This section is 64-bit DWARF. */ | |
8827 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
8828 | offset_size = 8; | |
8829 | } | |
8830 | else | |
8831 | offset_size = 4; | |
8832 | unit_end = hdrptr + unit_length; | |
8833 | ||
e98fdf1a AM |
8834 | sec_off = hdrptr - section->start; |
8835 | if (sec_off + unit_length < sec_off | |
8836 | || sec_off + unit_length > section->size) | |
61364358 | 8837 | { |
e98fdf1a AM |
8838 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
8839 | section->name, | |
8840 | (unsigned long) (unit_start - section->start), | |
8841 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
8842 | return 0; |
8843 | } | |
8844 | ||
8845 | /* Get and check the version number. */ | |
8846 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
8847 | printf (_("Version %ld\n"), (long) dwarf_version); | |
8848 | ||
8849 | /* Prior versions did not exist, and future versions may not be | |
8850 | backwards compatible. */ | |
8851 | if (dwarf_version != 5) | |
8852 | { | |
8853 | warn (_("Only DWARF version 5 .debug_names " | |
8854 | "is currently supported.\n")); | |
8855 | return 0; | |
8856 | } | |
8857 | ||
8858 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
8859 | if (padding != 0) | |
8860 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
8861 | padding); | |
8862 | ||
8863 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
8864 | if (comp_unit_count == 0) | |
8865 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
8866 | ||
8867 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
8868 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
8869 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
8870 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
8871 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
8872 | ||
8873 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
8874 | if (augmentation_string_size % 4 != 0) | |
8875 | { | |
8876 | warn (_("Augmentation string length %u must be rounded up " | |
8877 | "to a multiple of 4 in .debug_names.\n"), | |
8878 | augmentation_string_size); | |
8879 | augmentation_string_size += (-augmentation_string_size) & 3; | |
8880 | } | |
48467cb9 | 8881 | |
61364358 | 8882 | printf (_("Augmentation string:")); |
48467cb9 TV |
8883 | |
8884 | augmentation_printable = TRUE; | |
8885 | augmentation_string = (const char *) hdrptr; | |
8886 | ||
61364358 JK |
8887 | for (i = 0; i < augmentation_string_size; i++) |
8888 | { | |
8889 | unsigned char uc; | |
8890 | ||
8891 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
8892 | printf (" %02x", uc); | |
48467cb9 TV |
8893 | |
8894 | if (uc != 0 && !ISPRINT (uc)) | |
8895 | augmentation_printable = FALSE; | |
8896 | } | |
8897 | ||
8898 | if (augmentation_printable) | |
8899 | { | |
8900 | printf (" (\""); | |
8901 | for (i = 0; | |
8902 | i < augmentation_string_size && augmentation_string[i]; | |
8903 | ++i) | |
8904 | putchar (augmentation_string[i]); | |
8905 | printf ("\")"); | |
61364358 | 8906 | } |
61364358 JK |
8907 | putchar ('\n'); |
8908 | ||
8909 | printf (_("CU table:\n")); | |
8910 | for (i = 0; i < comp_unit_count; i++) | |
8911 | { | |
8912 | uint64_t cu_offset; | |
8913 | ||
8914 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
8915 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
8916 | } | |
8917 | putchar ('\n'); | |
8918 | ||
8919 | printf (_("TU table:\n")); | |
8920 | for (i = 0; i < local_type_unit_count; i++) | |
8921 | { | |
8922 | uint64_t tu_offset; | |
8923 | ||
8924 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
8925 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
8926 | } | |
8927 | putchar ('\n'); | |
8928 | ||
8929 | printf (_("Foreign TU table:\n")); | |
8930 | for (i = 0; i < foreign_type_unit_count; i++) | |
8931 | { | |
8932 | uint64_t signature; | |
8933 | ||
8934 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
8935 | printf (_("[%3u] "), i); | |
8936 | print_dwarf_vma (signature, 8); | |
8937 | putchar ('\n'); | |
8938 | } | |
8939 | putchar ('\n'); | |
8940 | ||
8941 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
8942 | hdrptr += bucket_count * sizeof (uint32_t); | |
8943 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
8944 | hdrptr += name_count * sizeof (uint32_t); | |
8945 | unsigned char *const name_table_string_offsets = hdrptr; | |
8946 | hdrptr += name_count * offset_size; | |
8947 | unsigned char *const name_table_entry_offsets = hdrptr; | |
8948 | hdrptr += name_count * offset_size; | |
8949 | unsigned char *const abbrev_table = hdrptr; | |
8950 | hdrptr += abbrev_table_size; | |
8951 | const unsigned char *const abbrev_table_end = hdrptr; | |
8952 | unsigned char *const entry_pool = hdrptr; | |
8953 | if (hdrptr > unit_end) | |
8954 | { | |
8955 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
8956 | "for unit 0x%lx in the debug_names\n"), | |
8957 | (long) (hdrptr - section->start), | |
8958 | (long) (unit_end - section->start), | |
8959 | (long) (unit_start - section->start)); | |
8960 | return 0; | |
8961 | } | |
8962 | ||
8963 | size_t buckets_filled = 0; | |
8964 | size_t bucketi; | |
8965 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
8966 | { | |
8967 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
8968 | ||
8969 | if (bucket != 0) | |
8970 | ++buckets_filled; | |
8971 | } | |
d3a49aa8 AM |
8972 | printf (ngettext ("Used %zu of %lu bucket.\n", |
8973 | "Used %zu of %lu buckets.\n", | |
8974 | bucket_count), | |
8975 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 8976 | |
0a79bef4 | 8977 | uint32_t hash_prev = 0; |
61364358 JK |
8978 | size_t hash_clash_count = 0; |
8979 | size_t longest_clash = 0; | |
8980 | size_t this_length = 0; | |
8981 | size_t hashi; | |
8982 | for (hashi = 0; hashi < name_count; hashi++) | |
8983 | { | |
8984 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
8985 | ||
8986 | if (hashi > 0) | |
8987 | { | |
8988 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
8989 | { | |
8990 | ++hash_clash_count; | |
8991 | ++this_length; | |
8992 | longest_clash = MAX (longest_clash, this_length); | |
8993 | } | |
8994 | else | |
8995 | this_length = 0; | |
8996 | } | |
8997 | hash_prev = hash_this; | |
8998 | } | |
8999 | printf (_("Out of %lu items there are %zu bucket clashes" | |
9000 | " (longest of %zu entries).\n"), | |
9001 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
9002 | assert (name_count == buckets_filled + hash_clash_count); | |
9003 | ||
9004 | struct abbrev_lookup_entry | |
9005 | { | |
9006 | dwarf_vma abbrev_tag; | |
9007 | unsigned char *abbrev_lookup_ptr; | |
9008 | }; | |
9009 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
9010 | size_t abbrev_lookup_used = 0; | |
9011 | size_t abbrev_lookup_allocated = 0; | |
9012 | ||
9013 | unsigned char *abbrevptr = abbrev_table; | |
9014 | for (;;) | |
9015 | { | |
cd30bcef AM |
9016 | dwarf_vma abbrev_tag; |
9017 | ||
9018 | READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end); | |
61364358 JK |
9019 | if (abbrev_tag == 0) |
9020 | break; | |
9021 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
9022 | { | |
9023 | abbrev_lookup_allocated = MAX (0x100, | |
9024 | abbrev_lookup_allocated * 2); | |
9025 | abbrev_lookup = xrealloc (abbrev_lookup, | |
9026 | (abbrev_lookup_allocated | |
9027 | * sizeof (*abbrev_lookup))); | |
9028 | } | |
9029 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
9030 | struct abbrev_lookup_entry *entry; | |
9031 | for (entry = abbrev_lookup; | |
9032 | entry < abbrev_lookup + abbrev_lookup_used; | |
9033 | entry++) | |
9034 | if (entry->abbrev_tag == abbrev_tag) | |
9035 | { | |
9036 | warn (_("Duplicate abbreviation tag %lu " | |
9037 | "in unit 0x%lx in the debug_names\n"), | |
9038 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
9039 | break; | |
9040 | } | |
9041 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
9042 | entry->abbrev_tag = abbrev_tag; | |
9043 | entry->abbrev_lookup_ptr = abbrevptr; | |
9044 | ||
9045 | /* Skip DWARF tag. */ | |
cd30bcef | 9046 | SKIP_ULEB (abbrevptr, abbrev_table_end); |
61364358 JK |
9047 | for (;;) |
9048 | { | |
cd30bcef AM |
9049 | dwarf_vma xindex, form; |
9050 | ||
9051 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9052 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9053 | if (xindex == 0 && form == 0) |
61364358 JK |
9054 | break; |
9055 | } | |
9056 | } | |
9057 | ||
9058 | printf (_("\nSymbol table:\n")); | |
9059 | uint32_t namei; | |
9060 | for (namei = 0; namei < name_count; ++namei) | |
9061 | { | |
9062 | uint64_t string_offset, entry_offset; | |
9063 | ||
9064 | SAFE_BYTE_GET (string_offset, | |
9065 | name_table_string_offsets + namei * offset_size, | |
9066 | offset_size, unit_end); | |
9067 | SAFE_BYTE_GET (entry_offset, | |
9068 | name_table_entry_offsets + namei * offset_size, | |
9069 | offset_size, unit_end); | |
9070 | ||
9071 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
9072 | fetch_indirect_string (string_offset)); | |
9073 | ||
9074 | unsigned char *entryptr = entry_pool + entry_offset; | |
9075 | ||
9076 | // We need to scan first whether there is a single or multiple | |
9077 | // entries. TAGNO is -2 for the first entry, it is -1 for the | |
9078 | // initial tag read of the second entry, then it becomes 0 for the | |
9079 | // first entry for real printing etc. | |
9080 | int tagno = -2; | |
9081 | /* Initialize it due to a false compiler warning. */ | |
9082 | dwarf_vma second_abbrev_tag = -1; | |
9083 | for (;;) | |
9084 | { | |
cd30bcef AM |
9085 | dwarf_vma abbrev_tag; |
9086 | dwarf_vma dwarf_tag; | |
9087 | const struct abbrev_lookup_entry *entry; | |
9088 | ||
9089 | READ_ULEB (abbrev_tag, entryptr, unit_end); | |
61364358 JK |
9090 | if (tagno == -1) |
9091 | { | |
9092 | second_abbrev_tag = abbrev_tag; | |
9093 | tagno = 0; | |
9094 | entryptr = entry_pool + entry_offset; | |
9095 | continue; | |
9096 | } | |
9097 | if (abbrev_tag == 0) | |
9098 | break; | |
9099 | if (tagno >= 0) | |
9100 | printf ("%s<%lu>", | |
9101 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
9102 | (unsigned long) abbrev_tag); | |
9103 | ||
61364358 JK |
9104 | for (entry = abbrev_lookup; |
9105 | entry < abbrev_lookup + abbrev_lookup_used; | |
9106 | entry++) | |
9107 | if (entry->abbrev_tag == abbrev_tag) | |
9108 | break; | |
9109 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
9110 | { | |
9111 | warn (_("Undefined abbreviation tag %lu " | |
9112 | "in unit 0x%lx in the debug_names\n"), | |
9113 | (long) abbrev_tag, | |
9114 | (long) (unit_start - section->start)); | |
9115 | break; | |
9116 | } | |
9117 | abbrevptr = entry->abbrev_lookup_ptr; | |
cd30bcef | 9118 | READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end); |
61364358 JK |
9119 | if (tagno >= 0) |
9120 | printf (" %s", get_TAG_name (dwarf_tag)); | |
9121 | for (;;) | |
9122 | { | |
cd30bcef AM |
9123 | dwarf_vma xindex, form; |
9124 | ||
9125 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9126 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9127 | if (xindex == 0 && form == 0) |
61364358 JK |
9128 | break; |
9129 | ||
9130 | if (tagno >= 0) | |
1d827a72 | 9131 | printf (" %s", get_IDX_name (xindex)); |
ec1b0fbb NC |
9132 | entryptr = read_and_display_attr_value (0, form, 0, |
9133 | unit_start, entryptr, unit_end, | |
9134 | 0, 0, offset_size, | |
61364358 JK |
9135 | dwarf_version, NULL, |
9136 | (tagno < 0), NULL, | |
ec1b0fbb | 9137 | NULL, '=', -1); |
61364358 JK |
9138 | } |
9139 | ++tagno; | |
9140 | } | |
9141 | if (tagno <= 0) | |
9142 | printf (_(" <no entries>")); | |
9143 | putchar ('\n'); | |
9144 | } | |
9145 | ||
9146 | free (abbrev_lookup); | |
9147 | } | |
9148 | ||
9149 | return 1; | |
9150 | } | |
9151 | ||
dda8d76d | 9152 | static int |
d85bf2ba NC |
9153 | display_debug_links (struct dwarf_section * section, |
9154 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
9155 | { |
9156 | const unsigned char * filename; | |
9157 | unsigned int filelen; | |
9158 | ||
9159 | introduce (section, FALSE); | |
9160 | ||
9161 | /* The .gnu_debuglink section is formatted as: | |
9162 | (c-string) Filename. | |
9163 | (padding) If needed to reach a 4 byte boundary. | |
9164 | (uint32_t) CRC32 value. | |
9165 | ||
9166 | The .gun_debugaltlink section is formatted as: | |
9167 | (c-string) Filename. | |
9168 | (binary) Build-ID. */ | |
9169 | ||
9170 | filename = section->start; | |
9171 | filelen = strnlen ((const char *) filename, section->size); | |
9172 | if (filelen == section->size) | |
9173 | { | |
9174 | warn (_("The debuglink filename is corrupt/missing\n")); | |
9175 | return 0; | |
9176 | } | |
9177 | ||
9178 | printf (_(" Separate debug info file: %s\n"), filename); | |
9179 | ||
9180 | if (const_strneq (section->name, ".gnu_debuglink")) | |
9181 | { | |
9182 | unsigned int crc32; | |
9183 | unsigned int crc_offset; | |
9184 | ||
9185 | crc_offset = filelen + 1; | |
9186 | crc_offset = (crc_offset + 3) & ~3; | |
9187 | if (crc_offset + 4 > section->size) | |
9188 | { | |
9189 | warn (_("CRC offset missing/truncated\n")); | |
9190 | return 0; | |
9191 | } | |
9192 | ||
9193 | crc32 = byte_get (filename + crc_offset, 4); | |
9194 | ||
9195 | printf (_(" CRC value: %#x\n"), crc32); | |
9196 | ||
9197 | if (crc_offset + 4 < section->size) | |
9198 | { | |
9199 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
9200 | (long)(section->size - (crc_offset + 4))); | |
9201 | return 0; | |
9202 | } | |
9203 | } | |
9204 | else /* const_strneq (section->name, ".gnu_debugaltlink") */ | |
9205 | { | |
9206 | const unsigned char * build_id = section->start + filelen + 1; | |
9207 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
9208 | bfd_size_type printed; | |
9209 | ||
9210 | /* FIXME: Should we support smaller build-id notes ? */ | |
9211 | if (build_id_len < 0x14) | |
9212 | { | |
9213 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
9214 | return 0; | |
9215 | } | |
9216 | ||
9217 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 9218 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
9219 | putchar ('\n'); |
9220 | } | |
9221 | ||
9222 | putchar ('\n'); | |
9223 | return 1; | |
9224 | } | |
9225 | ||
5bbdf3d5 DE |
9226 | static int |
9227 | display_gdb_index (struct dwarf_section *section, | |
9228 | void *file ATTRIBUTE_UNUSED) | |
9229 | { | |
9230 | unsigned char *start = section->start; | |
9231 | uint32_t version; | |
9232 | uint32_t cu_list_offset, tu_list_offset; | |
9233 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
9234 | unsigned int cu_list_elements, tu_list_elements; | |
9235 | unsigned int address_table_size, symbol_table_slots; | |
9236 | unsigned char *cu_list, *tu_list; | |
9237 | unsigned char *address_table, *symbol_table, *constant_pool; | |
9238 | unsigned int i; | |
9239 | ||
9240 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
9241 | ||
dda8d76d | 9242 | introduce (section, FALSE); |
5bbdf3d5 DE |
9243 | |
9244 | if (section->size < 6 * sizeof (uint32_t)) | |
9245 | { | |
9246 | warn (_("Truncated header in the %s section.\n"), section->name); | |
9247 | return 0; | |
9248 | } | |
9249 | ||
9250 | version = byte_get_little_endian (start, 4); | |
da88a764 | 9251 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
9252 | |
9253 | /* Prior versions are obsolete, and future versions may not be | |
9254 | backwards compatible. */ | |
aa170720 | 9255 | if (version < 3 || version > 8) |
5bbdf3d5 | 9256 | { |
da88a764 | 9257 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
9258 | return 0; |
9259 | } | |
8d6eee87 TT |
9260 | if (version < 4) |
9261 | warn (_("The address table data in version 3 may be wrong.\n")); | |
9262 | if (version < 5) | |
9263 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
9264 | if (version < 6) | |
9265 | warn (_("Version 5 does not include inlined functions.\n")); | |
9266 | if (version < 7) | |
9267 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
9268 | /* Version 7 indices generated by Gold have bad type unit references, |
9269 | PR binutils/15021. But we don't know if the index was generated by | |
9270 | Gold or not, so to avoid worrying users with gdb-generated indices | |
9271 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
9272 | |
9273 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
9274 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
9275 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
9276 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
9277 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
9278 | ||
9279 | if (cu_list_offset > section->size | |
9280 | || tu_list_offset > section->size | |
9281 | || address_table_offset > section->size | |
9282 | || symbol_table_offset > section->size | |
9283 | || constant_pool_offset > section->size) | |
9284 | { | |
9285 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
9286 | return 0; | |
9287 | } | |
9288 | ||
53774b7e NC |
9289 | /* PR 17531: file: 418d0a8a. */ |
9290 | if (tu_list_offset < cu_list_offset) | |
9291 | { | |
9292 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
9293 | tu_list_offset, cu_list_offset); | |
9294 | return 0; | |
9295 | } | |
9296 | ||
5bbdf3d5 | 9297 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
9298 | |
9299 | if (address_table_offset < tu_list_offset) | |
9300 | { | |
9301 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
9302 | address_table_offset, tu_list_offset); | |
9303 | return 0; | |
9304 | } | |
9305 | ||
5bbdf3d5 | 9306 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
9307 | |
9308 | /* PR 17531: file: 18a47d3d. */ | |
9309 | if (symbol_table_offset < address_table_offset) | |
9310 | { | |
13bace4a | 9311 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
9312 | symbol_table_offset, address_table_offset); |
9313 | return 0; | |
9314 | } | |
9315 | ||
5bbdf3d5 | 9316 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
9317 | |
9318 | if (constant_pool_offset < symbol_table_offset) | |
9319 | { | |
9320 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
9321 | constant_pool_offset, symbol_table_offset); | |
9322 | return 0; | |
9323 | } | |
9324 | ||
5bbdf3d5 DE |
9325 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
9326 | ||
9327 | cu_list = start + cu_list_offset; | |
9328 | tu_list = start + tu_list_offset; | |
9329 | address_table = start + address_table_offset; | |
9330 | symbol_table = start + symbol_table_offset; | |
9331 | constant_pool = start + constant_pool_offset; | |
9332 | ||
28d909e5 | 9333 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 9334 | { |
1306a742 | 9335 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
9336 | return 0; |
9337 | } | |
b4eb7656 | 9338 | |
5bbdf3d5 DE |
9339 | printf (_("\nCU table:\n")); |
9340 | for (i = 0; i < cu_list_elements; i += 2) | |
9341 | { | |
9342 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
9343 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
9344 | ||
9345 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
9346 | (unsigned long) cu_offset, | |
9347 | (unsigned long) (cu_offset + cu_length - 1)); | |
9348 | } | |
9349 | ||
9350 | printf (_("\nTU table:\n")); | |
9351 | for (i = 0; i < tu_list_elements; i += 3) | |
9352 | { | |
9353 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
9354 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
9355 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
9356 | ||
9357 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
9358 | (unsigned long) tu_offset, | |
9359 | (unsigned long) type_offset); | |
9360 | print_dwarf_vma (signature, 8); | |
9361 | printf ("\n"); | |
9362 | } | |
9363 | ||
9364 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
9365 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
9366 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
9367 | { |
9368 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
9369 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
9370 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
9371 | ||
9372 | print_dwarf_vma (low, 8); | |
9373 | print_dwarf_vma (high, 8); | |
da88a764 | 9374 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
9375 | } |
9376 | ||
9377 | printf (_("\nSymbol table:\n")); | |
9378 | for (i = 0; i < symbol_table_slots; ++i) | |
9379 | { | |
9380 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
9381 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
9382 | uint32_t num_cus, cu; | |
9383 | ||
9384 | if (name_offset != 0 | |
9385 | || cu_vector_offset != 0) | |
9386 | { | |
9387 | unsigned int j; | |
362beea4 | 9388 | unsigned char * adr; |
5bbdf3d5 | 9389 | |
362beea4 | 9390 | adr = constant_pool + name_offset; |
53774b7e | 9391 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 9392 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
9393 | { |
9394 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
9395 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
9396 | name_offset, i); | |
9397 | } | |
9398 | else | |
acff9664 NC |
9399 | printf ("[%3u] %.*s:", i, |
9400 | (int) (section->size - (constant_pool_offset + name_offset)), | |
9401 | constant_pool + name_offset); | |
53774b7e | 9402 | |
362beea4 NC |
9403 | adr = constant_pool + cu_vector_offset; |
9404 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
9405 | { |
9406 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
9407 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
9408 | cu_vector_offset, i); | |
9409 | continue; | |
9410 | } | |
57028622 | 9411 | |
362beea4 | 9412 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 9413 | |
362beea4 | 9414 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 9415 | if (num_cus * 4 < num_cus |
362beea4 NC |
9416 | || adr >= section->start + section->size |
9417 | || adr < constant_pool) | |
53774b7e NC |
9418 | { |
9419 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 9420 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
9421 | num_cus, i); |
9422 | continue; | |
9423 | } | |
9424 | ||
8d6eee87 TT |
9425 | if (num_cus > 1) |
9426 | printf ("\n"); | |
f3853b34 | 9427 | |
5bbdf3d5 DE |
9428 | for (j = 0; j < num_cus; ++j) |
9429 | { | |
7c1cef97 | 9430 | int is_static; |
8d6eee87 TT |
9431 | gdb_index_symbol_kind kind; |
9432 | ||
5bbdf3d5 | 9433 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 9434 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
9435 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
9436 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 9437 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 9438 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
9439 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
9440 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 9441 | else |
8d6eee87 TT |
9442 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
9443 | ||
459d52c8 DE |
9444 | printf (" [%s, %s]", |
9445 | is_static ? _("static") : _("global"), | |
9446 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
9447 | if (num_cus > 1) |
9448 | printf ("\n"); | |
5bbdf3d5 | 9449 | } |
8d6eee87 TT |
9450 | if (num_cus <= 1) |
9451 | printf ("\n"); | |
5bbdf3d5 DE |
9452 | } |
9453 | } | |
9454 | ||
9455 | return 1; | |
9456 | } | |
9457 | ||
657d0d47 CC |
9458 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
9459 | ||
9460 | static void | |
9461 | prealloc_cu_tu_list (unsigned int nshndx) | |
9462 | { | |
9463 | if (shndx_pool == NULL) | |
9464 | { | |
9465 | shndx_pool_size = nshndx; | |
9466 | shndx_pool_used = 0; | |
9467 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
9468 | sizeof (unsigned int)); | |
9469 | } | |
9470 | else | |
9471 | { | |
9472 | shndx_pool_size = shndx_pool_used + nshndx; | |
9473 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
9474 | sizeof (unsigned int)); | |
9475 | } | |
9476 | } | |
9477 | ||
9478 | static void | |
9479 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
9480 | { | |
9481 | if (shndx_pool_used >= shndx_pool_size) | |
9482 | { | |
9483 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9484 | return; | |
9485 | } | |
9486 | shndx_pool [shndx_pool_used++] = shndx; | |
9487 | } | |
9488 | ||
9489 | static void | |
9490 | end_cu_tu_entry (void) | |
9491 | { | |
9492 | if (shndx_pool_used >= shndx_pool_size) | |
9493 | { | |
9494 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9495 | return; | |
9496 | } | |
9497 | shndx_pool [shndx_pool_used++] = 0; | |
9498 | } | |
9499 | ||
341f9135 CC |
9500 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
9501 | ||
9502 | static const char * | |
9503 | get_DW_SECT_short_name (unsigned int dw_sect) | |
9504 | { | |
9505 | static char buf[16]; | |
9506 | ||
9507 | switch (dw_sect) | |
9508 | { | |
9509 | case DW_SECT_INFO: | |
9510 | return "info"; | |
9511 | case DW_SECT_TYPES: | |
9512 | return "types"; | |
9513 | case DW_SECT_ABBREV: | |
9514 | return "abbrev"; | |
9515 | case DW_SECT_LINE: | |
9516 | return "line"; | |
9517 | case DW_SECT_LOC: | |
9518 | return "loc"; | |
9519 | case DW_SECT_STR_OFFSETS: | |
9520 | return "str_off"; | |
9521 | case DW_SECT_MACINFO: | |
9522 | return "macinfo"; | |
9523 | case DW_SECT_MACRO: | |
9524 | return "macro"; | |
9525 | default: | |
b4eb7656 | 9526 | break; |
341f9135 CC |
9527 | } |
9528 | ||
9529 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
9530 | return buf; | |
9531 | } | |
9532 | ||
9533 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
9534 | These sections are extensions for Fission. | |
9535 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
9536 | |
9537 | static int | |
9538 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
9539 | { | |
9540 | unsigned char *phdr = section->start; | |
9541 | unsigned char *limit = phdr + section->size; | |
9542 | unsigned char *phash; | |
9543 | unsigned char *pindex; | |
9544 | unsigned char *ppool; | |
9545 | unsigned int version; | |
341f9135 | 9546 | unsigned int ncols = 0; |
657d0d47 CC |
9547 | unsigned int nused; |
9548 | unsigned int nslots; | |
9549 | unsigned int i; | |
341f9135 CC |
9550 | unsigned int j; |
9551 | dwarf_vma signature_high; | |
9552 | dwarf_vma signature_low; | |
9553 | char buf[64]; | |
657d0d47 | 9554 | |
6937bb54 NC |
9555 | /* PR 17512: file: 002-168123-0.004. */ |
9556 | if (phdr == NULL) | |
9557 | { | |
9558 | warn (_("Section %s is empty\n"), section->name); | |
9559 | return 0; | |
9560 | } | |
9561 | /* PR 17512: file: 002-376-0.004. */ | |
9562 | if (section->size < 24) | |
9563 | { | |
72c61a0d | 9564 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
9565 | section->name); |
9566 | return 0; | |
9567 | } | |
9568 | ||
9569 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 9570 | if (version >= 2) |
6937bb54 NC |
9571 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
9572 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
9573 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
9574 | ||
657d0d47 | 9575 | phash = phdr + 16; |
8e2e3c6c AM |
9576 | pindex = phash + (size_t) nslots * 8; |
9577 | ppool = pindex + (size_t) nslots * 4; | |
57028622 | 9578 | |
657d0d47 CC |
9579 | if (do_display) |
9580 | { | |
dda8d76d NC |
9581 | introduce (section, FALSE); |
9582 | ||
8e2e3c6c | 9583 | printf (_(" Version: %u\n"), version); |
341f9135 | 9584 | if (version >= 2) |
8e2e3c6c AM |
9585 | printf (_(" Number of columns: %u\n"), ncols); |
9586 | printf (_(" Number of used entries: %u\n"), nused); | |
9587 | printf (_(" Number of slots: %u\n\n"), nslots); | |
657d0d47 CC |
9588 | } |
9589 | ||
8e2e3c6c AM |
9590 | /* PR 17531: file: 45d69832. */ |
9591 | if ((size_t) nslots * 8 / 8 != nslots | |
9592 | || phash < phdr || phash > limit | |
9593 | || pindex < phash || pindex > limit | |
9594 | || ppool < pindex || ppool > limit) | |
657d0d47 | 9595 | { |
8e2e3c6c AM |
9596 | warn (ngettext ("Section %s is too small for %u slot\n", |
9597 | "Section %s is too small for %u slots\n", | |
9598 | nslots), | |
657d0d47 CC |
9599 | section->name, nslots); |
9600 | return 0; | |
9601 | } | |
9602 | ||
341f9135 | 9603 | if (version == 1) |
657d0d47 | 9604 | { |
341f9135 CC |
9605 | if (!do_display) |
9606 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
9607 | for (i = 0; i < nslots; i++) | |
657d0d47 | 9608 | { |
341f9135 CC |
9609 | unsigned char *shndx_list; |
9610 | unsigned int shndx; | |
9611 | ||
6937bb54 | 9612 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 9613 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 9614 | { |
6937bb54 | 9615 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 9616 | shndx_list = ppool + j * 4; |
f3853b34 NC |
9617 | /* PR 17531: file: 705e010d. */ |
9618 | if (shndx_list < ppool) | |
9619 | { | |
9620 | warn (_("Section index pool located before start of section\n")); | |
9621 | return 0; | |
9622 | } | |
9623 | ||
341f9135 CC |
9624 | if (do_display) |
9625 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
9626 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9627 | buf, sizeof (buf))); | |
9628 | for (;;) | |
657d0d47 | 9629 | { |
341f9135 CC |
9630 | if (shndx_list >= limit) |
9631 | { | |
9632 | warn (_("Section %s too small for shndx pool\n"), | |
9633 | section->name); | |
9634 | return 0; | |
9635 | } | |
6937bb54 | 9636 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
9637 | if (shndx == 0) |
9638 | break; | |
9639 | if (do_display) | |
9640 | printf (" %d", shndx); | |
9641 | else | |
9642 | add_shndx_to_cu_tu_entry (shndx); | |
9643 | shndx_list += 4; | |
657d0d47 | 9644 | } |
657d0d47 | 9645 | if (do_display) |
341f9135 | 9646 | printf ("\n"); |
657d0d47 | 9647 | else |
341f9135 CC |
9648 | end_cu_tu_entry (); |
9649 | } | |
9650 | phash += 8; | |
9651 | pindex += 4; | |
9652 | } | |
9653 | } | |
9654 | else if (version == 2) | |
9655 | { | |
9656 | unsigned int val; | |
9657 | unsigned int dw_sect; | |
9658 | unsigned char *ph = phash; | |
9659 | unsigned char *pi = pindex; | |
8e2e3c6c AM |
9660 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
9661 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
9662 | unsigned char *pend = psizes + (size_t) nused * ncols * 4; | |
341f9135 CC |
9663 | bfd_boolean is_tu_index; |
9664 | struct cu_tu_set *this_set = NULL; | |
9665 | unsigned int row; | |
9666 | unsigned char *prow; | |
9667 | ||
9668 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
9669 | ||
362beea4 | 9670 | /* PR 17531: file: 0dd159bf. |
8e2e3c6c AM |
9671 | Check for integer overflow (can occur when size_t is 32-bit) |
9672 | with overlarge ncols or nused values. */ | |
4ac948a0 NC |
9673 | if (ncols > 0 |
9674 | && ((size_t) ncols * 4 / 4 != ncols | |
9675 | || (size_t) nused * ncols * 4 / ((size_t) ncols * 4) != nused | |
9676 | || poffsets < ppool || poffsets > limit | |
9677 | || psizes < poffsets || psizes > limit | |
9678 | || pend < psizes || pend > limit)) | |
341f9135 CC |
9679 | { |
9680 | warn (_("Section %s too small for offset and size tables\n"), | |
9681 | section->name); | |
9682 | return 0; | |
9683 | } | |
9684 | ||
9685 | if (do_display) | |
9686 | { | |
9687 | printf (_(" Offset table\n")); | |
9688 | printf (" slot %-16s ", | |
9689 | is_tu_index ? _("signature") : _("dwo_id")); | |
9690 | } | |
9691 | else | |
9692 | { | |
9693 | if (is_tu_index) | |
9694 | { | |
9695 | tu_count = nused; | |
72c61a0d | 9696 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 9697 | this_set = tu_sets; |
657d0d47 | 9698 | } |
657d0d47 | 9699 | else |
341f9135 CC |
9700 | { |
9701 | cu_count = nused; | |
72c61a0d | 9702 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
9703 | this_set = cu_sets; |
9704 | } | |
9705 | } | |
6937bb54 | 9706 | |
341f9135 CC |
9707 | if (do_display) |
9708 | { | |
9709 | for (j = 0; j < ncols; j++) | |
9710 | { | |
6937bb54 | 9711 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
9712 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
9713 | } | |
9714 | printf ("\n"); | |
9715 | } | |
6937bb54 | 9716 | |
341f9135 CC |
9717 | for (i = 0; i < nslots; i++) |
9718 | { | |
6937bb54 NC |
9719 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9720 | ||
9721 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9722 | if (row != 0) |
9723 | { | |
591f7597 | 9724 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 9725 | if (row > nused) |
591f7597 NC |
9726 | { |
9727 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
9728 | row, nused); | |
9729 | return 0; | |
9730 | } | |
9731 | ||
341f9135 | 9732 | if (!do_display) |
6aea08d9 NC |
9733 | { |
9734 | size_t num_copy = sizeof (uint64_t); | |
9735 | ||
9736 | /* PR 23064: Beware of buffer overflow. */ | |
9737 | if (ph + num_copy < limit) | |
9738 | memcpy (&this_set[row - 1].signature, ph, num_copy); | |
9739 | else | |
9740 | { | |
9741 | warn (_("Signature (%p) extends beyond end of space in section\n"), ph); | |
9742 | return 0; | |
9743 | } | |
9744 | } | |
6937bb54 | 9745 | |
341f9135 | 9746 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
9747 | /* PR 17531: file: b8ce60a8. */ |
9748 | if (prow < poffsets || prow > limit) | |
9749 | { | |
9750 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
9751 | row, ncols); | |
9752 | return 0; | |
9753 | } | |
3aade688 | 9754 | |
341f9135 CC |
9755 | if (do_display) |
9756 | printf (_(" [%3d] 0x%s"), | |
9757 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9758 | buf, sizeof (buf))); | |
9759 | for (j = 0; j < ncols; j++) | |
9760 | { | |
6937bb54 | 9761 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
9762 | if (do_display) |
9763 | printf (" %8d", val); | |
9764 | else | |
9765 | { | |
6937bb54 | 9766 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
9767 | |
9768 | /* PR 17531: file: 10796eb3. */ | |
9769 | if (dw_sect >= DW_SECT_MAX) | |
9770 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
9771 | else | |
9772 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
9773 | } |
9774 | } | |
6937bb54 | 9775 | |
341f9135 CC |
9776 | if (do_display) |
9777 | printf ("\n"); | |
9778 | } | |
9779 | ph += 8; | |
9780 | pi += 4; | |
9781 | } | |
9782 | ||
9783 | ph = phash; | |
9784 | pi = pindex; | |
9785 | if (do_display) | |
b4eb7656 | 9786 | { |
341f9135 CC |
9787 | printf ("\n"); |
9788 | printf (_(" Size table\n")); | |
9789 | printf (" slot %-16s ", | |
9790 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 9791 | } |
6937bb54 | 9792 | |
341f9135 CC |
9793 | for (j = 0; j < ncols; j++) |
9794 | { | |
6937bb54 | 9795 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
9796 | if (do_display) |
9797 | printf (" %8s", get_DW_SECT_short_name (val)); | |
9798 | } | |
6937bb54 | 9799 | |
341f9135 CC |
9800 | if (do_display) |
9801 | printf ("\n"); | |
6937bb54 | 9802 | |
341f9135 CC |
9803 | for (i = 0; i < nslots; i++) |
9804 | { | |
6937bb54 NC |
9805 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9806 | ||
9807 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9808 | if (row != 0) |
9809 | { | |
9810 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 9811 | |
341f9135 CC |
9812 | if (do_display) |
9813 | printf (_(" [%3d] 0x%s"), | |
9814 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9815 | buf, sizeof (buf))); | |
6937bb54 | 9816 | |
341f9135 CC |
9817 | for (j = 0; j < ncols; j++) |
9818 | { | |
6937bb54 | 9819 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
9820 | if (do_display) |
9821 | printf (" %8d", val); | |
9822 | else | |
9823 | { | |
6937bb54 | 9824 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
9825 | if (dw_sect >= DW_SECT_MAX) |
9826 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
9827 | else | |
341f9135 CC |
9828 | this_set [row - 1].section_sizes [dw_sect] = val; |
9829 | } | |
9830 | } | |
6937bb54 | 9831 | |
341f9135 CC |
9832 | if (do_display) |
9833 | printf ("\n"); | |
9834 | } | |
6937bb54 | 9835 | |
341f9135 CC |
9836 | ph += 8; |
9837 | pi += 4; | |
657d0d47 | 9838 | } |
657d0d47 | 9839 | } |
341f9135 | 9840 | else if (do_display) |
6937bb54 | 9841 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
9842 | |
9843 | if (do_display) | |
9844 | printf ("\n"); | |
9845 | ||
9846 | return 1; | |
9847 | } | |
9848 | ||
9849 | /* Load the CU and TU indexes if present. This will build a list of | |
9850 | section sets that we can use to associate a .debug_info.dwo section | |
9851 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
9852 | ||
43a444f9 | 9853 | static bfd_boolean |
657d0d47 CC |
9854 | load_cu_tu_indexes (void *file) |
9855 | { | |
43a444f9 NC |
9856 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
9857 | ||
657d0d47 CC |
9858 | /* If we have already loaded (or tried to load) the CU and TU indexes |
9859 | then do not bother to repeat the task. */ | |
43a444f9 NC |
9860 | if (cu_tu_indexes_read == -1) |
9861 | { | |
9862 | cu_tu_indexes_read = TRUE; | |
9863 | ||
dda8d76d | 9864 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 NC |
9865 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
9866 | cu_tu_indexes_read = FALSE; | |
9867 | ||
dda8d76d | 9868 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 NC |
9869 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
9870 | cu_tu_indexes_read = FALSE; | |
9871 | } | |
657d0d47 | 9872 | |
43a444f9 | 9873 | return (bfd_boolean) cu_tu_indexes_read; |
657d0d47 CC |
9874 | } |
9875 | ||
9876 | /* Find the set of sections that includes section SHNDX. */ | |
9877 | ||
9878 | unsigned int * | |
9879 | find_cu_tu_set (void *file, unsigned int shndx) | |
9880 | { | |
9881 | unsigned int i; | |
9882 | ||
43a444f9 NC |
9883 | if (! load_cu_tu_indexes (file)) |
9884 | return NULL; | |
657d0d47 CC |
9885 | |
9886 | /* Find SHNDX in the shndx pool. */ | |
9887 | for (i = 0; i < shndx_pool_used; i++) | |
9888 | if (shndx_pool [i] == shndx) | |
9889 | break; | |
9890 | ||
9891 | if (i >= shndx_pool_used) | |
9892 | return NULL; | |
9893 | ||
9894 | /* Now backup to find the first entry in the set. */ | |
9895 | while (i > 0 && shndx_pool [i - 1] != 0) | |
9896 | i--; | |
9897 | ||
9898 | return shndx_pool + i; | |
9899 | } | |
9900 | ||
9901 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
9902 | ||
9903 | static int | |
9904 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
9905 | { | |
9906 | return process_cu_tu_index (section, 1); | |
9907 | } | |
9908 | ||
19e6b90e L |
9909 | static int |
9910 | display_debug_not_supported (struct dwarf_section *section, | |
9911 | void *file ATTRIBUTE_UNUSED) | |
9912 | { | |
9913 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
9914 | section->name); | |
9915 | ||
9916 | return 1; | |
9917 | } | |
9918 | ||
1306a742 NC |
9919 | /* Like malloc, but takes two parameters like calloc. |
9920 | Verifies that the first parameter is not too large. | |
82b1b41b | 9921 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 9922 | |
19e6b90e L |
9923 | void * |
9924 | cmalloc (size_t nmemb, size_t size) | |
9925 | { | |
9926 | /* Check for overflow. */ | |
9927 | if (nmemb >= ~(size_t) 0 / size) | |
9928 | return NULL; | |
82b1b41b NC |
9929 | |
9930 | return xmalloc (nmemb * size); | |
19e6b90e L |
9931 | } |
9932 | ||
1306a742 NC |
9933 | /* Like xmalloc, but takes two parameters like calloc. |
9934 | Verifies that the first parameter is not too large. | |
9935 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 9936 | |
72c61a0d | 9937 | void * |
1306a742 | 9938 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
9939 | { |
9940 | /* Check for overflow. */ | |
9941 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
9942 | { |
9943 | fprintf (stderr, | |
9944 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
9945 | (long) nmemb); | |
9946 | xexit (1); | |
9947 | } | |
72c61a0d | 9948 | |
1306a742 | 9949 | return xmalloc (nmemb * size); |
72c61a0d NC |
9950 | } |
9951 | ||
1306a742 NC |
9952 | /* Like xrealloc, but takes three parameters. |
9953 | Verifies that the second parameter is not too large. | |
9954 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 9955 | |
19e6b90e | 9956 | void * |
1306a742 | 9957 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
9958 | { |
9959 | /* Check for overflow. */ | |
9960 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 9961 | { |
dda8d76d NC |
9962 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
9963 | (long) nmemb); | |
8490fb40 NC |
9964 | xexit (1); |
9965 | } | |
82b1b41b | 9966 | |
1306a742 | 9967 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
9968 | } |
9969 | ||
1306a742 | 9970 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 9971 | |
19e6b90e | 9972 | void * |
1306a742 | 9973 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
9974 | { |
9975 | /* Check for overflow. */ | |
9976 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 9977 | { |
dda8d76d NC |
9978 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
9979 | (long) nmemb); | |
8490fb40 NC |
9980 | xexit (1); |
9981 | } | |
82b1b41b | 9982 | |
1306a742 | 9983 | return xcalloc (nmemb, size); |
19e6b90e L |
9984 | } |
9985 | ||
dda8d76d NC |
9986 | static unsigned long |
9987 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
9988 | const unsigned char * buf, | |
9989 | bfd_size_type len) | |
9990 | { | |
9991 | static const unsigned long crc32_table[256] = | |
9992 | { | |
9993 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
9994 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
9995 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
9996 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
9997 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
9998 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
9999 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
10000 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
10001 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
10002 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
10003 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
10004 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
10005 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
10006 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
10007 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
10008 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
10009 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
10010 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
10011 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
10012 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
10013 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
10014 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
10015 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
10016 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
10017 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
10018 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
10019 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
10020 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
10021 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
10022 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
10023 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
10024 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
10025 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
10026 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
10027 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
10028 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
10029 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
10030 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
10031 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
10032 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
10033 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
10034 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
10035 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
10036 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
10037 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
10038 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
10039 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
10040 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
10041 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
10042 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
10043 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
10044 | 0x2d02ef8d | |
10045 | }; | |
10046 | const unsigned char *end; | |
10047 | ||
10048 | crc = ~crc & 0xffffffff; | |
10049 | for (end = buf + len; buf < end; ++ buf) | |
10050 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
10051 | return ~crc & 0xffffffff; | |
10052 | } | |
10053 | ||
10054 | typedef bfd_boolean (* check_func_type) (const char *, void *); | |
10055 | typedef const char * (* parse_func_type) (struct dwarf_section *, void *); | |
10056 | ||
10057 | static bfd_boolean | |
10058 | check_gnu_debuglink (const char * pathname, void * crc_pointer) | |
10059 | { | |
10060 | static unsigned char buffer [8 * 1024]; | |
10061 | FILE * f; | |
10062 | bfd_size_type count; | |
10063 | unsigned long crc = 0; | |
10064 | void * sep_data; | |
10065 | ||
10066 | sep_data = open_debug_file (pathname); | |
10067 | if (sep_data == NULL) | |
10068 | return FALSE; | |
10069 | ||
10070 | /* Yes - we are opening the file twice... */ | |
10071 | f = fopen (pathname, "rb"); | |
10072 | if (f == NULL) | |
10073 | { | |
10074 | /* Paranoia: This should never happen. */ | |
10075 | close_debug_file (sep_data); | |
10076 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
10077 | return FALSE; | |
10078 | } | |
10079 | ||
10080 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
10081 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
10082 | ||
10083 | fclose (f); | |
10084 | ||
10085 | if (crc != * (unsigned long *) crc_pointer) | |
10086 | { | |
10087 | close_debug_file (sep_data); | |
10088 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
10089 | pathname); | |
10090 | return FALSE; | |
10091 | } | |
10092 | ||
10093 | return TRUE; | |
10094 | } | |
10095 | ||
10096 | static const char * | |
10097 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
10098 | { | |
10099 | const char * name; | |
10100 | unsigned int crc_offset; | |
10101 | unsigned long * crc32 = (unsigned long *) data; | |
10102 | ||
10103 | /* The name is first. | |
10104 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
10105 | name = (const char *) section->start; | |
10106 | ||
39f0547e | 10107 | |
dda8d76d NC |
10108 | crc_offset = strnlen (name, section->size) + 1; |
10109 | crc_offset = (crc_offset + 3) & ~3; | |
10110 | if (crc_offset + 4 > section->size) | |
10111 | return NULL; | |
10112 | ||
10113 | * crc32 = byte_get (section->start + crc_offset, 4); | |
10114 | return name; | |
10115 | } | |
10116 | ||
10117 | static bfd_boolean | |
10118 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) | |
10119 | { | |
10120 | void * sep_data = open_debug_file (filename); | |
10121 | ||
10122 | if (sep_data == NULL) | |
10123 | return FALSE; | |
10124 | ||
10125 | /* FIXME: We should now extract the build-id in the separate file | |
10126 | and check it... */ | |
10127 | ||
10128 | return TRUE; | |
10129 | } | |
10130 | ||
10131 | typedef struct build_id_data | |
10132 | { | |
10133 | bfd_size_type len; | |
10134 | const unsigned char * data; | |
10135 | } Build_id_data; | |
10136 | ||
10137 | static const char * | |
10138 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
10139 | { | |
10140 | const char * name; | |
10141 | bfd_size_type namelen; | |
10142 | bfd_size_type id_len; | |
10143 | Build_id_data * build_id_data; | |
10144 | ||
10145 | /* The name is first. | |
10146 | The build-id follows immediately, with no padding, up to the section's end. */ | |
10147 | ||
10148 | name = (const char *) section->start; | |
10149 | namelen = strnlen (name, section->size) + 1; | |
10150 | if (namelen >= section->size) | |
10151 | return NULL; | |
10152 | ||
10153 | id_len = section->size - namelen; | |
10154 | if (id_len < 0x14) | |
10155 | return NULL; | |
10156 | ||
10157 | build_id_data = calloc (1, sizeof * build_id_data); | |
10158 | if (build_id_data == NULL) | |
10159 | return NULL; | |
10160 | ||
10161 | build_id_data->len = id_len; | |
10162 | build_id_data->data = section->start + namelen; | |
10163 | ||
10164 | * (Build_id_data **) data = build_id_data; | |
10165 | ||
10166 | return name; | |
10167 | } | |
10168 | ||
24841daa NC |
10169 | static void |
10170 | add_separate_debug_file (const char * filename, void * handle) | |
10171 | { | |
10172 | separate_info * i = xmalloc (sizeof * i); | |
10173 | ||
10174 | i->filename = filename; | |
10175 | i->handle = handle; | |
10176 | i->next = first_separate_info; | |
10177 | first_separate_info = i; | |
10178 | } | |
10179 | ||
301a9420 AM |
10180 | #if HAVE_LIBDEBUGINFOD |
10181 | /* Query debuginfod servers for the target debuglink or debugaltlink | |
10182 | file. If successful, store the path of the file in filename and | |
10183 | return TRUE, otherwise return FALSE. */ | |
10184 | ||
10185 | static bfd_boolean | |
10186 | debuginfod_fetch_separate_debug_info (struct dwarf_section * section, | |
10187 | char ** filename, | |
10188 | void * file) | |
10189 | { | |
10190 | size_t build_id_len; | |
10191 | unsigned char * build_id; | |
10192 | ||
10193 | if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0) | |
10194 | { | |
10195 | /* Get the build-id of file. */ | |
10196 | build_id = get_build_id (file); | |
10197 | build_id_len = 0; | |
10198 | } | |
10199 | else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0) | |
10200 | { | |
10201 | /* Get the build-id of the debugaltlink file. */ | |
10202 | unsigned int filelen; | |
10203 | ||
10204 | filelen = strnlen ((const char *)section->start, section->size); | |
10205 | if (filelen == section->size) | |
10206 | /* Corrupt debugaltlink. */ | |
10207 | return FALSE; | |
10208 | ||
10209 | build_id = section->start + filelen + 1; | |
10210 | build_id_len = section->size - (filelen + 1); | |
10211 | ||
10212 | if (build_id_len == 0) | |
10213 | return FALSE; | |
10214 | } | |
10215 | else | |
10216 | return FALSE; | |
10217 | ||
10218 | if (build_id) | |
10219 | { | |
10220 | int fd; | |
10221 | debuginfod_client * client; | |
10222 | ||
10223 | client = debuginfod_begin (); | |
10224 | if (client == NULL) | |
10225 | return FALSE; | |
10226 | ||
10227 | /* Query debuginfod servers for the target file. If found its path | |
10228 | will be stored in filename. */ | |
10229 | fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename); | |
10230 | debuginfod_end (client); | |
10231 | ||
10232 | /* Only free build_id if we allocated space for a hex string | |
10233 | in get_build_id (). */ | |
10234 | if (build_id_len == 0) | |
10235 | free (build_id); | |
10236 | ||
10237 | if (fd >= 0) | |
10238 | { | |
10239 | /* File successfully retrieved. Close fd since we want to | |
10240 | use open_debug_file () on filename instead. */ | |
10241 | close (fd); | |
10242 | return TRUE; | |
10243 | } | |
10244 | } | |
10245 | ||
10246 | return FALSE; | |
10247 | } | |
10248 | #endif | |
10249 | ||
dda8d76d NC |
10250 | static void * |
10251 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 10252 | struct dwarf_section * xlink, |
dda8d76d NC |
10253 | parse_func_type parse_func, |
10254 | check_func_type check_func, | |
301a9420 AM |
10255 | void * func_data, |
10256 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
10257 | { |
10258 | const char * separate_filename; | |
24841daa | 10259 | char * debug_filename; |
dda8d76d NC |
10260 | char * canon_dir; |
10261 | size_t canon_dirlen; | |
10262 | size_t dirlen; | |
10263 | ||
2b63c337 | 10264 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
10265 | { |
10266 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 10267 | xlink->name ? xlink->name : xlink->uncompressed_name); |
dda8d76d NC |
10268 | return FALSE; |
10269 | } | |
10270 | ||
10271 | /* Attempt to locate the separate file. | |
10272 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
10273 | ||
10274 | canon_dir = lrealpath (main_filename); | |
10275 | ||
10276 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) | |
10277 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
10278 | break; | |
10279 | canon_dir[canon_dirlen] = '\0'; | |
10280 | ||
10281 | #ifndef DEBUGDIR | |
10282 | #define DEBUGDIR "/lib/debug" | |
10283 | #endif | |
10284 | #ifndef EXTRA_DEBUG_ROOT1 | |
10285 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
10286 | #endif | |
10287 | #ifndef EXTRA_DEBUG_ROOT2 | |
10288 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
10289 | #endif | |
10290 | ||
24841daa NC |
10291 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
10292 | + canon_dirlen | |
10293 | + strlen (".debug/") | |
dda8d76d | 10294 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 10295 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
10296 | #endif |
10297 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 10298 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 10299 | #endif |
24841daa NC |
10300 | + strlen (separate_filename) |
10301 | + 1); | |
10302 | if (debug_filename == NULL) | |
dda8d76d NC |
10303 | { |
10304 | warn (_("Out of memory")); | |
3391569f | 10305 | free (canon_dir); |
dda8d76d NC |
10306 | return NULL; |
10307 | } | |
10308 | ||
10309 | /* First try in the current directory. */ | |
24841daa NC |
10310 | sprintf (debug_filename, "%s", separate_filename); |
10311 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10312 | goto found; |
10313 | ||
10314 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
10315 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10316 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10317 | goto found; |
10318 | ||
10319 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
10320 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10321 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10322 | goto found; |
10323 | ||
10324 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
10325 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10326 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10327 | goto found; |
10328 | ||
10329 | #ifdef EXTRA_DEBUG_ROOT1 | |
10330 | /* Try the first extra debug file root. */ | |
24841daa NC |
10331 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10332 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 10333 | goto found; |
39f0547e NC |
10334 | |
10335 | /* Try the first extra debug file root. */ | |
10336 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
10337 | if (check_func (debug_filename, func_data)) | |
10338 | goto found; | |
dda8d76d NC |
10339 | #endif |
10340 | ||
10341 | #ifdef EXTRA_DEBUG_ROOT2 | |
10342 | /* Try the second extra debug file root. */ | |
24841daa NC |
10343 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10344 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10345 | goto found; |
10346 | #endif | |
10347 | ||
24841daa NC |
10348 | /* Then try in the global debug_filename directory. */ |
10349 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
10350 | dirlen = strlen (DEBUGDIR) - 1; |
10351 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
10352 | strcat (debug_filename, "/"); |
10353 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 10354 | |
24841daa | 10355 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
10356 | goto found; |
10357 | ||
301a9420 AM |
10358 | #if HAVE_LIBDEBUGINFOD |
10359 | { | |
10360 | char * tmp_filename; | |
10361 | ||
10362 | if (debuginfod_fetch_separate_debug_info (xlink, | |
10363 | & tmp_filename, | |
10364 | file)) | |
10365 | { | |
10366 | /* File successfully downloaded from server, replace | |
10367 | debug_filename with the file's path. */ | |
10368 | free (debug_filename); | |
10369 | debug_filename = tmp_filename; | |
10370 | goto found; | |
10371 | } | |
10372 | } | |
10373 | #endif | |
10374 | ||
dda8d76d NC |
10375 | /* Failed to find the file. */ |
10376 | warn (_("could not find separate debug file '%s'\n"), separate_filename); | |
24841daa | 10377 | warn (_("tried: %s\n"), debug_filename); |
dda8d76d NC |
10378 | |
10379 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa NC |
10380 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10381 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10382 | #endif |
10383 | ||
10384 | #ifdef EXTRA_DEBUG_ROOT1 | |
39f0547e NC |
10385 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); |
10386 | warn (_("tried: %s\n"), debug_filename); | |
10387 | ||
24841daa NC |
10388 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10389 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10390 | #endif |
10391 | ||
24841daa NC |
10392 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10393 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10394 | |
24841daa NC |
10395 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10396 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10397 | |
24841daa NC |
10398 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10399 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10400 | |
24841daa NC |
10401 | sprintf (debug_filename, "%s", separate_filename); |
10402 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10403 | |
301a9420 AM |
10404 | #if HAVE_LIBDEBUGINFOD |
10405 | { | |
10406 | char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR); | |
10407 | if (urls == NULL) | |
10408 | urls = ""; | |
10409 | ||
10410 | warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls); | |
10411 | } | |
10412 | #endif | |
10413 | ||
dda8d76d | 10414 | free (canon_dir); |
24841daa | 10415 | free (debug_filename); |
dda8d76d NC |
10416 | return NULL; |
10417 | ||
10418 | found: | |
10419 | free (canon_dir); | |
10420 | ||
24841daa NC |
10421 | void * debug_handle; |
10422 | ||
dda8d76d | 10423 | /* Now open the file.... */ |
24841daa | 10424 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 10425 | { |
24841daa NC |
10426 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
10427 | free (debug_filename); | |
dda8d76d NC |
10428 | return FALSE; |
10429 | } | |
10430 | ||
10431 | /* FIXME: We do not check to see if there are any other separate debug info | |
10432 | files that would also match. */ | |
10433 | ||
24841daa NC |
10434 | printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debug_filename); |
10435 | add_separate_debug_file (debug_filename, debug_handle); | |
dda8d76d | 10436 | |
24841daa | 10437 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 10438 | the structure returned by open_debug_file(). */ |
24841daa | 10439 | return debug_handle; |
dda8d76d NC |
10440 | } |
10441 | ||
d85bf2ba NC |
10442 | /* Attempt to load a separate dwarf object file. */ |
10443 | ||
10444 | static void * | |
24841daa | 10445 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 10446 | { |
24841daa NC |
10447 | char * separate_filename; |
10448 | void * separate_handle; | |
d85bf2ba NC |
10449 | |
10450 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
24841daa NC |
10451 | separate_filename = concat (dir, "/", name, NULL); |
10452 | if (separate_filename == NULL) | |
d85bf2ba NC |
10453 | { |
10454 | warn (_("Out of memory allocating dwo filename\n")); | |
10455 | return NULL; | |
10456 | } | |
10457 | ||
24841daa | 10458 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 10459 | { |
24841daa NC |
10460 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
10461 | free (separate_filename); | |
d85bf2ba NC |
10462 | return NULL; |
10463 | } | |
10464 | ||
10465 | /* FIXME: We should check the dwo_id. */ | |
10466 | ||
24841daa NC |
10467 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
10468 | add_separate_debug_file (separate_filename, separate_handle); | |
10469 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
10470 | return separate_handle; | |
d85bf2ba NC |
10471 | } |
10472 | ||
24841daa NC |
10473 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
10474 | Returns TRUE if any were found, FALSE otherwise. | |
10475 | If TRUE is returned then the linked list starting at first_separate_info | |
10476 | will be populated with open file handles. */ | |
dda8d76d | 10477 | |
24841daa NC |
10478 | bfd_boolean |
10479 | load_separate_debug_files (void * file, const char * filename) | |
dda8d76d | 10480 | { |
8de3a6e2 NC |
10481 | /* Skip this operation if we are not interested in debug links. */ |
10482 | if (! do_follow_links && ! do_debug_links) | |
24841daa | 10483 | return FALSE; |
8de3a6e2 | 10484 | |
24841daa | 10485 | /* See if there are any dwo links. */ |
d85bf2ba NC |
10486 | if (load_debug_section (str, file) |
10487 | && load_debug_section (abbrev, file) | |
10488 | && load_debug_section (info, file)) | |
10489 | { | |
24841daa | 10490 | free_dwo_info (); |
d85bf2ba NC |
10491 | |
10492 | if (process_debug_info (& debug_displays[info].section, file, abbrev, TRUE, FALSE)) | |
10493 | { | |
24841daa NC |
10494 | bfd_boolean introduced = FALSE; |
10495 | dwo_info * dwinfo; | |
10496 | const char * dir = NULL; | |
10497 | const char * id = NULL; | |
10498 | ||
10499 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 10500 | { |
24841daa | 10501 | switch (dwinfo->type) |
d85bf2ba | 10502 | { |
24841daa NC |
10503 | case DWO_NAME: |
10504 | if (do_debug_links) | |
10505 | { | |
10506 | if (! introduced) | |
10507 | { | |
10508 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
10509 | debug_displays [info].section.uncompressed_name); | |
10510 | introduced = TRUE; | |
10511 | } | |
d85bf2ba | 10512 | |
24841daa NC |
10513 | printf (_(" Name: %s\n"), dwinfo->value); |
10514 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); | |
10515 | if (id != NULL) | |
10516 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
10517 | else | |
10518 | printf (_(" ID: <unknown>\n")); | |
10519 | printf ("\n\n"); | |
10520 | } | |
10521 | ||
10522 | if (do_follow_links) | |
10523 | load_dwo_file (filename, dwinfo->value, dir, id); | |
10524 | break; | |
10525 | ||
10526 | case DWO_DIR: | |
10527 | dir = dwinfo->value; | |
10528 | break; | |
10529 | ||
10530 | case DWO_ID: | |
10531 | id = dwinfo->value; | |
10532 | break; | |
10533 | ||
10534 | default: | |
10535 | error (_("Unexpected DWO INFO type")); | |
10536 | break; | |
10537 | } | |
d85bf2ba NC |
10538 | } |
10539 | } | |
10540 | } | |
10541 | ||
dda8d76d | 10542 | if (! do_follow_links) |
8de3a6e2 NC |
10543 | /* The other debug links will be displayed by display_debug_links() |
10544 | so we do not need to do any further processing here. */ | |
24841daa | 10545 | return FALSE; |
dda8d76d NC |
10546 | |
10547 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
10548 | /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */ | |
10549 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ | |
d85bf2ba | 10550 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 10551 | |
dda8d76d NC |
10552 | if (load_debug_section (gnu_debugaltlink, file)) |
10553 | { | |
10554 | Build_id_data * build_id_data; | |
10555 | ||
24841daa NC |
10556 | load_separate_debug_info (filename, |
10557 | & debug_displays[gnu_debugaltlink].section, | |
10558 | parse_gnu_debugaltlink, | |
10559 | check_gnu_debugaltlink, | |
301a9420 AM |
10560 | & build_id_data, |
10561 | file); | |
dda8d76d NC |
10562 | } |
10563 | ||
10564 | if (load_debug_section (gnu_debuglink, file)) | |
10565 | { | |
10566 | unsigned long crc32; | |
10567 | ||
24841daa NC |
10568 | load_separate_debug_info (filename, |
10569 | & debug_displays[gnu_debuglink].section, | |
10570 | parse_gnu_debuglink, | |
10571 | check_gnu_debuglink, | |
301a9420 AM |
10572 | & crc32, |
10573 | file); | |
dda8d76d NC |
10574 | } |
10575 | ||
24841daa NC |
10576 | if (first_separate_info != NULL) |
10577 | return TRUE; | |
10578 | ||
dda8d76d | 10579 | do_follow_links = 0; |
24841daa | 10580 | return FALSE; |
dda8d76d NC |
10581 | } |
10582 | ||
19e6b90e L |
10583 | void |
10584 | free_debug_memory (void) | |
10585 | { | |
3f5e193b | 10586 | unsigned int i; |
19e6b90e L |
10587 | |
10588 | free_abbrevs (); | |
10589 | ||
10590 | for (i = 0; i < max; i++) | |
3f5e193b | 10591 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 10592 | |
cc86f28f | 10593 | if (debug_information != NULL) |
19e6b90e | 10594 | { |
cc86f28f | 10595 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) |
19e6b90e | 10596 | { |
cc86f28f | 10597 | for (i = 0; i < num_debug_info_entries; i++) |
19e6b90e | 10598 | { |
cc86f28f NC |
10599 | if (!debug_information [i].max_loc_offsets) |
10600 | { | |
10601 | free (debug_information [i].loc_offsets); | |
10602 | free (debug_information [i].have_frame_base); | |
10603 | } | |
10604 | if (!debug_information [i].max_range_lists) | |
10605 | free (debug_information [i].range_lists); | |
19e6b90e | 10606 | } |
19e6b90e L |
10607 | } |
10608 | free (debug_information); | |
10609 | debug_information = NULL; | |
82b1b41b | 10610 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 10611 | } |
dda8d76d | 10612 | |
24841daa NC |
10613 | separate_info * d; |
10614 | separate_info * next; | |
dda8d76d | 10615 | |
24841daa NC |
10616 | for (d = first_separate_info; d != NULL; d = next) |
10617 | { | |
10618 | close_debug_file (d->handle); | |
10619 | free ((void *) d->filename); | |
10620 | next = d->next; | |
10621 | free ((void *) d); | |
dda8d76d | 10622 | } |
24841daa NC |
10623 | first_separate_info = NULL; |
10624 | ||
10625 | free_dwo_info (); | |
19e6b90e L |
10626 | } |
10627 | ||
4cb93e3b TG |
10628 | void |
10629 | dwarf_select_sections_by_names (const char *names) | |
10630 | { | |
10631 | typedef struct | |
10632 | { | |
10633 | const char * option; | |
10634 | int * variable; | |
f9f0e732 | 10635 | int val; |
4cb93e3b TG |
10636 | } |
10637 | debug_dump_long_opts; | |
10638 | ||
10639 | static const debug_dump_long_opts opts_table [] = | |
10640 | { | |
10641 | /* Please keep this table alpha- sorted. */ | |
10642 | { "Ranges", & do_debug_ranges, 1 }, | |
10643 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 10644 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 10645 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
10646 | { "cu_index", & do_debug_cu_index, 1 }, |
10647 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 10648 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
10649 | { "frames", & do_debug_frames, 1 }, |
10650 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
10651 | /* The special .gdb_index section. */ |
10652 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
10653 | { "info", & do_debug_info, 1 }, |
10654 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 10655 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
10656 | { "loc", & do_debug_loc, 1 }, |
10657 | { "macro", & do_debug_macinfo, 1 }, | |
10658 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 10659 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 10660 | /* This entry is for compatibility |
4cb93e3b TG |
10661 | with earlier versions of readelf. */ |
10662 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 10663 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 10664 | { "str", & do_debug_str, 1 }, |
6f875884 TG |
10665 | /* These trace_* sections are used by Itanium VMS. */ |
10666 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
10667 | { "trace_aranges", & do_trace_aranges, 1 }, | |
10668 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
10669 | { NULL, NULL, 0 } |
10670 | }; | |
10671 | ||
10672 | const char *p; | |
467c65bc | 10673 | |
4cb93e3b TG |
10674 | p = names; |
10675 | while (*p) | |
10676 | { | |
10677 | const debug_dump_long_opts * entry; | |
467c65bc | 10678 | |
4cb93e3b TG |
10679 | for (entry = opts_table; entry->option; entry++) |
10680 | { | |
10681 | size_t len = strlen (entry->option); | |
467c65bc | 10682 | |
4cb93e3b TG |
10683 | if (strncmp (p, entry->option, len) == 0 |
10684 | && (p[len] == ',' || p[len] == '\0')) | |
10685 | { | |
10686 | * entry->variable |= entry->val; | |
467c65bc | 10687 | |
4cb93e3b TG |
10688 | /* The --debug-dump=frames-interp option also |
10689 | enables the --debug-dump=frames option. */ | |
10690 | if (do_debug_frames_interp) | |
10691 | do_debug_frames = 1; | |
10692 | ||
10693 | p += len; | |
10694 | break; | |
10695 | } | |
10696 | } | |
467c65bc | 10697 | |
4cb93e3b TG |
10698 | if (entry->option == NULL) |
10699 | { | |
10700 | warn (_("Unrecognized debug option '%s'\n"), p); | |
10701 | p = strchr (p, ','); | |
10702 | if (p == NULL) | |
10703 | break; | |
10704 | } | |
467c65bc | 10705 | |
4cb93e3b TG |
10706 | if (*p == ',') |
10707 | p++; | |
10708 | } | |
10709 | } | |
10710 | ||
10711 | void | |
10712 | dwarf_select_sections_by_letters (const char *letters) | |
10713 | { | |
91d6fa6a | 10714 | unsigned int lindex = 0; |
4cb93e3b | 10715 | |
91d6fa6a NC |
10716 | while (letters[lindex]) |
10717 | switch (letters[lindex++]) | |
4cb93e3b | 10718 | { |
dda8d76d NC |
10719 | case 'A': do_debug_addr = 1; break; |
10720 | case 'a': do_debug_abbrevs = 1; break; | |
10721 | case 'c': do_debug_cu_index = 1; break; | |
10722 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
10723 | case 'f': do_debug_frames = 1; break; | |
10724 | case 'g': do_gdb_index = 1; break; | |
10725 | case 'i': do_debug_info = 1; break; | |
10726 | case 'K': do_follow_links = 1; break; | |
10727 | case 'k': do_debug_links = 1; break; | |
10728 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
10729 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
10730 | case 'm': do_debug_macinfo = 1; break; | |
10731 | case 'o': do_debug_loc = 1; break; | |
10732 | case 'p': do_debug_pubnames = 1; break; | |
10733 | case 'R': do_debug_ranges = 1; break; | |
10734 | case 'r': do_debug_aranges = 1; break; | |
10735 | case 's': do_debug_str = 1; break; | |
10736 | case 'T': do_trace_aranges = 1; break; | |
10737 | case 't': do_debug_pubtypes = 1; break; | |
10738 | case 'U': do_trace_info = 1; break; | |
10739 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 10740 | |
4cb93e3b | 10741 | default: |
7cc78d07 | 10742 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
10743 | break; |
10744 | } | |
10745 | } | |
10746 | ||
10747 | void | |
10748 | dwarf_select_sections_all (void) | |
10749 | { | |
10750 | do_debug_info = 1; | |
10751 | do_debug_abbrevs = 1; | |
10752 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
10753 | do_debug_pubnames = 1; | |
f9f0e732 | 10754 | do_debug_pubtypes = 1; |
4cb93e3b TG |
10755 | do_debug_aranges = 1; |
10756 | do_debug_ranges = 1; | |
10757 | do_debug_frames = 1; | |
10758 | do_debug_macinfo = 1; | |
10759 | do_debug_str = 1; | |
10760 | do_debug_loc = 1; | |
5bbdf3d5 | 10761 | do_gdb_index = 1; |
6f875884 TG |
10762 | do_trace_info = 1; |
10763 | do_trace_abbrevs = 1; | |
10764 | do_trace_aranges = 1; | |
657d0d47 CC |
10765 | do_debug_addr = 1; |
10766 | do_debug_cu_index = 1; | |
dda8d76d NC |
10767 | do_follow_links = 1; |
10768 | do_debug_links = 1; | |
4cb93e3b TG |
10769 | } |
10770 | ||
dda8d76d NC |
10771 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL |
10772 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL | |
10773 | ||
10774 | /* N.B. The order here must match the order in section_display_enum. */ | |
10775 | ||
19e6b90e L |
10776 | struct dwarf_section_display debug_displays[] = |
10777 | { | |
dda8d76d NC |
10778 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, |
10779 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE }, | |
10780 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
10781 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE }, | |
10782 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
10783 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE }, | |
10784 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, | |
10785 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
10786 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
10787 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
10788 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
10789 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
10790 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10791 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10792 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE }, | |
10793 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, | |
10794 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
10795 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
10796 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10797 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10798 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE }, | |
10799 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10800 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE }, | |
10801 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE }, | |
10802 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE }, | |
10803 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE }, | |
10804 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE }, | |
10805 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE }, | |
10806 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
10807 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE }, | |
10808 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
10809 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10810 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
10811 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
10812 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE }, | |
10813 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, | |
10814 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, | |
10815 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE }, | |
10816 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
10817 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
10818 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
10819 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
10820 | /* Separate debug info files can containt their own .debug_str section, | |
10821 | and this might be in *addition* to a .debug_str section already present | |
10822 | in the main file. Hence we need to have two entries for .debug_str. */ | |
10823 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
19e6b90e | 10824 | }; |
b451e98a JK |
10825 | |
10826 | /* A static assertion. */ | |
10827 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |