Commit | Line | Data |
---|---|---|
19e6b90e | 1 | /* dwarf.c -- display DWARF contents of a BFD binary file |
250d07de | 2 | Copyright (C) 2005-2021 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; | |
50ea0877 | 70 | dwarf_vma cu_offset; |
24841daa NC |
71 | struct dwo_info * next; |
72 | } dwo_info; | |
73 | ||
74 | static dwo_info * first_dwo_info = NULL; | |
75 | static bfd_boolean need_dwo_info; | |
76 | ||
77 | separate_info * first_separate_info = NULL; | |
d85bf2ba | 78 | |
77ef8654 | 79 | unsigned int eh_addr_size; |
19e6b90e L |
80 | |
81 | int do_debug_info; | |
82 | int do_debug_abbrevs; | |
83 | int do_debug_lines; | |
84 | int do_debug_pubnames; | |
f9f0e732 | 85 | int do_debug_pubtypes; |
19e6b90e L |
86 | int do_debug_aranges; |
87 | int do_debug_ranges; | |
88 | int do_debug_frames; | |
89 | int do_debug_frames_interp; | |
90 | int do_debug_macinfo; | |
91 | int do_debug_str; | |
e4b7104b | 92 | int do_debug_str_offsets; |
19e6b90e | 93 | int do_debug_loc; |
5bbdf3d5 | 94 | int do_gdb_index; |
6f875884 TG |
95 | int do_trace_info; |
96 | int do_trace_abbrevs; | |
97 | int do_trace_aranges; | |
657d0d47 CC |
98 | int do_debug_addr; |
99 | int do_debug_cu_index; | |
a262ae96 | 100 | int do_wide; |
dda8d76d NC |
101 | int do_debug_links; |
102 | int do_follow_links; | |
546cb2d8 | 103 | bfd_boolean do_checks; |
19e6b90e | 104 | |
fd2f0033 TT |
105 | int dwarf_cutoff_level = -1; |
106 | unsigned long dwarf_start_die; | |
107 | ||
4723351a CC |
108 | int dwarf_check = 0; |
109 | ||
9f272209 AO |
110 | /* Convenient constant, to avoid having to cast -1 to dwarf_vma when |
111 | testing whether e.g. a locview list is present. */ | |
112 | static const dwarf_vma vm1 = -1; | |
113 | ||
341f9135 CC |
114 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
115 | sections. For version 1 package files, each set is stored in SHNDX_POOL | |
116 | as a zero-terminated list of section indexes comprising one set of debug | |
117 | sections from a .dwo file. */ | |
118 | ||
341f9135 CC |
119 | static unsigned int *shndx_pool = NULL; |
120 | static unsigned int shndx_pool_size = 0; | |
121 | static unsigned int shndx_pool_used = 0; | |
122 | ||
123 | /* For version 2 package files, each set contains an array of section offsets | |
124 | and an array of section sizes, giving the offset and size of the | |
125 | contribution from a CU or TU within one of the debug sections. | |
126 | When displaying debug info from a package file, we need to use these | |
127 | tables to locate the corresponding contributions to each section. */ | |
128 | ||
129 | struct cu_tu_set | |
130 | { | |
ec1b0fbb NC |
131 | uint64_t signature; |
132 | dwarf_vma section_offsets[DW_SECT_MAX]; | |
133 | size_t section_sizes[DW_SECT_MAX]; | |
341f9135 CC |
134 | }; |
135 | ||
136 | static int cu_count = 0; | |
137 | static int tu_count = 0; | |
138 | static struct cu_tu_set *cu_sets = NULL; | |
139 | static struct cu_tu_set *tu_sets = NULL; | |
140 | ||
43a444f9 | 141 | static bfd_boolean load_cu_tu_indexes (void *); |
341f9135 | 142 | |
ec1b0fbb NC |
143 | /* An array that indicates for a given level of CU nesting whether |
144 | the latest DW_AT_type seen for that level was a signed type or | |
145 | an unsigned type. */ | |
146 | #define MAX_CU_NESTING (1 << 8) | |
147 | static bfd_boolean level_type_signed[MAX_CU_NESTING]; | |
148 | ||
4cb93e3b TG |
149 | /* Values for do_debug_lines. */ |
150 | #define FLAG_DEBUG_LINES_RAW 1 | |
151 | #define FLAG_DEBUG_LINES_DECODED 2 | |
152 | ||
77ef8654 | 153 | static unsigned int |
f1c4cc75 RH |
154 | size_of_encoded_value (int encoding) |
155 | { | |
156 | switch (encoding & 0x7) | |
157 | { | |
158 | default: /* ??? */ | |
159 | case 0: return eh_addr_size; | |
160 | case 2: return 2; | |
161 | case 3: return 4; | |
162 | case 4: return 8; | |
163 | } | |
164 | } | |
165 | ||
166 | static dwarf_vma | |
041830e0 | 167 | get_encoded_value (unsigned char **pdata, |
bad62cf5 | 168 | int encoding, |
041830e0 NC |
169 | struct dwarf_section *section, |
170 | unsigned char * end) | |
f1c4cc75 | 171 | { |
041830e0 | 172 | unsigned char * data = * pdata; |
6937bb54 | 173 | unsigned int size = size_of_encoded_value (encoding); |
bad62cf5 | 174 | dwarf_vma val; |
f1c4cc75 | 175 | |
041830e0 NC |
176 | if (data + size >= end) |
177 | { | |
178 | warn (_("Encoded value extends past end of section\n")); | |
179 | * pdata = end; | |
180 | return 0; | |
181 | } | |
182 | ||
6937bb54 NC |
183 | /* PR 17512: file: 002-829853-0.004. */ |
184 | if (size > 8) | |
185 | { | |
186 | warn (_("Encoded size of %d is too large to read\n"), size); | |
187 | * pdata = end; | |
188 | return 0; | |
189 | } | |
190 | ||
0a9d414a NC |
191 | /* PR 17512: file: 1085-5603-0.004. */ |
192 | if (size == 0) | |
193 | { | |
194 | warn (_("Encoded size of 0 is too small to read\n")); | |
195 | * pdata = end; | |
196 | return 0; | |
197 | } | |
198 | ||
f1c4cc75 | 199 | if (encoding & DW_EH_PE_signed) |
bad62cf5 | 200 | val = byte_get_signed (data, size); |
f1c4cc75 | 201 | else |
bad62cf5 AM |
202 | val = byte_get (data, size); |
203 | ||
204 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
205 | val += section->address + (data - section->start); | |
041830e0 NC |
206 | |
207 | * pdata = data + size; | |
bad62cf5 | 208 | return val; |
f1c4cc75 RH |
209 | } |
210 | ||
4c219c2e AM |
211 | #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG |
212 | # ifndef __MINGW32__ | |
213 | # define DWARF_VMA_FMT "ll" | |
214 | # define DWARF_VMA_FMT_LONG "%16.16llx" | |
215 | # else | |
216 | # define DWARF_VMA_FMT "I64" | |
217 | # define DWARF_VMA_FMT_LONG "%016I64x" | |
218 | # endif | |
2e14fae2 | 219 | #else |
4c219c2e AM |
220 | # define DWARF_VMA_FMT "l" |
221 | # define DWARF_VMA_FMT_LONG "%16.16lx" | |
2d9472a2 NC |
222 | #endif |
223 | ||
bf5117e3 NC |
224 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
225 | buffer containing the converted VALUE. The value is converted according | |
226 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then | |
227 | it specifies the maximum number of bytes to be displayed in the converted | |
228 | value and FMTCH is ignored - hex is always used. */ | |
467c65bc | 229 | |
47704ddf | 230 | static const char * |
bf5117e3 | 231 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
47704ddf KT |
232 | { |
233 | /* As dwarf_vmatoa is used more then once in a printf call | |
234 | for output, we are cycling through an fixed array of pointers | |
235 | for return address. */ | |
236 | static int buf_pos = 0; | |
467c65bc NC |
237 | static struct dwarf_vmatoa_buf |
238 | { | |
47704ddf KT |
239 | char place[64]; |
240 | } buf[16]; | |
47704ddf KT |
241 | char *ret; |
242 | ||
47704ddf | 243 | ret = buf[buf_pos++].place; |
467c65bc | 244 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf | 245 | |
bf5117e3 NC |
246 | if (num_bytes) |
247 | { | |
222c2bf0 | 248 | /* Printf does not have a way of specifying a maximum field width for an |
bf5117e3 NC |
249 | integer value, so we print the full value into a buffer and then select |
250 | the precision we need. */ | |
251 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); | |
252 | if (num_bytes > 8) | |
253 | num_bytes = 8; | |
254 | return ret + (16 - 2 * num_bytes); | |
255 | } | |
256 | else | |
257 | { | |
258 | char fmt[32]; | |
259 | ||
0bae9e9e NC |
260 | if (fmtch) |
261 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); | |
262 | else | |
263 | sprintf (fmt, "%%%s", DWARF_VMA_FMT); | |
bf5117e3 NC |
264 | snprintf (ret, sizeof (buf[0].place), fmt, value); |
265 | return ret; | |
266 | } | |
267 | } | |
47704ddf | 268 | |
bf5117e3 NC |
269 | static inline const char * |
270 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) | |
271 | { | |
272 | return dwarf_vmatoa_1 (fmtch, value, 0); | |
273 | } | |
274 | ||
275 | /* Print a dwarf_vma value (typically an address, offset or length) in | |
276 | hexadecimal format, followed by a space. The length of the VALUE (and | |
277 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ | |
278 | ||
279 | static void | |
280 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) | |
281 | { | |
282 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); | |
47704ddf KT |
283 | } |
284 | ||
9f272209 AO |
285 | /* Print a view number in hexadecimal value, with the same width |
286 | print_dwarf_vma would have printed it with the same num_bytes. | |
287 | Print blanks for zero view, unless force is nonzero. */ | |
288 | ||
289 | static void | |
290 | print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force) | |
291 | { | |
292 | int len; | |
293 | if (!num_bytes) | |
294 | len = 4; | |
295 | else | |
296 | len = num_bytes * 2; | |
297 | ||
298 | assert (value == (unsigned long) value); | |
299 | if (value || force) | |
300 | printf ("v%0*lx ", len - 1, (unsigned long) value); | |
301 | else | |
302 | printf ("%*s", len + 1, ""); | |
303 | } | |
304 | ||
74bc6052 CC |
305 | /* Format a 64-bit value, given as two 32-bit values, in hex. |
306 | For reentrancy, this uses a buffer provided by the caller. */ | |
307 | ||
308 | static const char * | |
309 | dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, | |
310 | unsigned int buf_len) | |
311 | { | |
312 | int len = 0; | |
313 | ||
314 | if (hvalue == 0) | |
315 | snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); | |
316 | else | |
317 | { | |
318 | len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); | |
319 | snprintf (buf + len, buf_len - len, | |
320 | "%08" DWARF_VMA_FMT "x", lvalue); | |
321 | } | |
322 | ||
323 | return buf; | |
324 | } | |
325 | ||
f6f0e17b NC |
326 | /* Read in a LEB128 encoded value starting at address DATA. |
327 | If SIGN is true, return a signed LEB128 value. | |
328 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
cd30bcef AM |
329 | If STATUS_RETURN in not NULL, return with bit 0 (LSB) set if the |
330 | terminating byte was not found and with bit 1 set if the value | |
331 | overflows a dwarf_vma. | |
f6f0e17b NC |
332 | No bytes will be read at address END or beyond. */ |
333 | ||
467c65bc | 334 | dwarf_vma |
f6f0e17b | 335 | read_leb128 (unsigned char *data, |
cd30bcef | 336 | const unsigned char *const end, |
f6f0e17b | 337 | bfd_boolean sign, |
cd30bcef AM |
338 | unsigned int *length_return, |
339 | int *status_return) | |
19e6b90e | 340 | { |
467c65bc | 341 | dwarf_vma result = 0; |
19e6b90e L |
342 | unsigned int num_read = 0; |
343 | unsigned int shift = 0; | |
cd30bcef | 344 | int status = 1; |
19e6b90e | 345 | |
f6f0e17b | 346 | while (data < end) |
19e6b90e | 347 | { |
cd30bcef | 348 | unsigned char byte = *data++; |
08d7da7d NC |
349 | bfd_boolean cont = (byte & 0x80) ? TRUE : FALSE; |
350 | ||
351 | byte &= 0x7f; | |
19e6b90e L |
352 | num_read++; |
353 | ||
cd30bcef AM |
354 | if (shift < sizeof (result) * 8) |
355 | { | |
08d7da7d NC |
356 | result |= ((dwarf_vma) byte) << shift; |
357 | if (sign) | |
358 | { | |
359 | if ((((dwarf_signed_vma) result >> shift) & 0x7f) != byte) | |
360 | /* Overflow. */ | |
361 | status |= 2; | |
362 | } | |
363 | else if ((result >> shift) != byte) | |
364 | { | |
365 | /* Overflow. */ | |
366 | status |= 2; | |
367 | } | |
368 | ||
cd30bcef AM |
369 | shift += 7; |
370 | } | |
08d7da7d NC |
371 | else if (byte != 0) |
372 | { | |
373 | status |= 2; | |
374 | } | |
19e6b90e | 375 | |
08d7da7d | 376 | if (!cont) |
cd30bcef AM |
377 | { |
378 | status &= ~1; | |
379 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) | |
380 | result |= -((dwarf_vma) 1 << shift); | |
381 | break; | |
382 | } | |
19e6b90e | 383 | } |
19e6b90e L |
384 | |
385 | if (length_return != NULL) | |
386 | *length_return = num_read; | |
cd30bcef AM |
387 | if (status_return != NULL) |
388 | *status_return = status; | |
19e6b90e L |
389 | |
390 | return result; | |
391 | } | |
392 | ||
d11ae95e NC |
393 | /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value. |
394 | Checks to make sure that the read will not reach or pass END | |
395 | and that VAL is big enough to hold AMOUNT bytes. */ | |
0c588247 NC |
396 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
397 | do \ | |
398 | { \ | |
399 | unsigned int amount = (AMOUNT); \ | |
34b9f729 NC |
400 | if (sizeof (VAL) < amount) \ |
401 | { \ | |
d3a49aa8 AM |
402 | error (ngettext ("internal error: attempt to read %d byte " \ |
403 | "of data in to %d sized variable", \ | |
404 | "internal error: attempt to read %d bytes " \ | |
405 | "of data in to %d sized variable", \ | |
406 | amount), \ | |
34b9f729 NC |
407 | amount, (int) sizeof (VAL)); \ |
408 | amount = sizeof (VAL); \ | |
409 | } \ | |
0c588247 NC |
410 | if (((PTR) + amount) >= (END)) \ |
411 | { \ | |
412 | if ((PTR) < (END)) \ | |
413 | amount = (END) - (PTR); \ | |
414 | else \ | |
415 | amount = 0; \ | |
416 | } \ | |
6937bb54 | 417 | if (amount == 0 || amount > 8) \ |
0c588247 | 418 | VAL = 0; \ |
6937bb54 NC |
419 | else \ |
420 | VAL = byte_get ((PTR), amount); \ | |
0c588247 NC |
421 | } \ |
422 | while (0) | |
423 | ||
d11ae95e | 424 | /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
425 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
426 | do \ | |
427 | { \ | |
428 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
429 | PTR += AMOUNT; \ | |
430 | } \ | |
431 | while (0) | |
432 | ||
d11ae95e | 433 | /* Like SAFE_BYTE_GET, but reads a signed value. */ |
0c588247 NC |
434 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
435 | do \ | |
436 | { \ | |
437 | unsigned int amount = (AMOUNT); \ | |
438 | if (((PTR) + amount) >= (END)) \ | |
439 | { \ | |
440 | if ((PTR) < (END)) \ | |
441 | amount = (END) - (PTR); \ | |
442 | else \ | |
443 | amount = 0; \ | |
444 | } \ | |
445 | if (amount) \ | |
446 | VAL = byte_get_signed ((PTR), amount); \ | |
447 | else \ | |
448 | VAL = 0; \ | |
449 | } \ | |
450 | while (0) | |
451 | ||
d11ae95e | 452 | /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
453 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
454 | do \ | |
455 | { \ | |
456 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
457 | PTR += AMOUNT; \ | |
458 | } \ | |
459 | while (0) | |
460 | ||
461 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ | |
462 | do \ | |
463 | { \ | |
87bc83b3 | 464 | if (((PTR) + 8) <= (END)) \ |
0c588247 NC |
465 | { \ |
466 | byte_get_64 ((PTR), (HIGH), (LOW)); \ | |
467 | } \ | |
468 | else \ | |
469 | { \ | |
0c588247 NC |
470 | * (LOW) = * (HIGH) = 0; \ |
471 | } \ | |
472 | } \ | |
473 | while (0) | |
474 | ||
19e6b90e L |
475 | typedef struct State_Machine_Registers |
476 | { | |
467c65bc | 477 | dwarf_vma address; |
ba8826a8 | 478 | unsigned int view; |
19e6b90e L |
479 | unsigned int file; |
480 | unsigned int line; | |
481 | unsigned int column; | |
482 | int is_stmt; | |
483 | int basic_block; | |
a233b20c JJ |
484 | unsigned char op_index; |
485 | unsigned char end_sequence; | |
ba8826a8 AO |
486 | /* This variable hold the number of the last entry seen |
487 | in the File Table. */ | |
19e6b90e L |
488 | unsigned int last_file_entry; |
489 | } SMR; | |
490 | ||
491 | static SMR state_machine_regs; | |
492 | ||
493 | static void | |
494 | reset_state_machine (int is_stmt) | |
495 | { | |
496 | state_machine_regs.address = 0; | |
ba8826a8 | 497 | state_machine_regs.view = 0; |
a233b20c | 498 | state_machine_regs.op_index = 0; |
19e6b90e L |
499 | state_machine_regs.file = 1; |
500 | state_machine_regs.line = 1; | |
501 | state_machine_regs.column = 0; | |
502 | state_machine_regs.is_stmt = is_stmt; | |
503 | state_machine_regs.basic_block = 0; | |
504 | state_machine_regs.end_sequence = 0; | |
505 | state_machine_regs.last_file_entry = 0; | |
506 | } | |
507 | ||
508 | /* Handled an extend line op. | |
509 | Returns the number of bytes read. */ | |
510 | ||
cd30bcef | 511 | static size_t |
f6f0e17b NC |
512 | process_extended_line_op (unsigned char * data, |
513 | int is_stmt, | |
514 | unsigned char * end) | |
19e6b90e L |
515 | { |
516 | unsigned char op_code; | |
cd30bcef | 517 | size_t len, header_len; |
19e6b90e | 518 | unsigned char *name; |
143a3db0 | 519 | unsigned char *orig_data = data; |
cd30bcef | 520 | dwarf_vma adr, val; |
19e6b90e | 521 | |
cd30bcef AM |
522 | READ_ULEB (len, data, end); |
523 | header_len = data - orig_data; | |
19e6b90e | 524 | |
cd30bcef | 525 | if (len == 0 || data == end || len > (size_t) (end - data)) |
19e6b90e | 526 | { |
f41e4712 | 527 | warn (_("Badly formed extended line op encountered!\n")); |
cd30bcef | 528 | return header_len; |
19e6b90e L |
529 | } |
530 | ||
19e6b90e L |
531 | op_code = *data++; |
532 | ||
533 | printf (_(" Extended opcode %d: "), op_code); | |
534 | ||
535 | switch (op_code) | |
536 | { | |
537 | case DW_LNE_end_sequence: | |
538 | printf (_("End of Sequence\n\n")); | |
539 | reset_state_machine (is_stmt); | |
540 | break; | |
541 | ||
542 | case DW_LNE_set_address: | |
6937bb54 | 543 | /* PR 17512: file: 002-100480-0.004. */ |
cd30bcef | 544 | if (len - 1 > 8) |
77ef8654 | 545 | { |
cd30bcef AM |
546 | warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"), |
547 | (unsigned long) len - 1); | |
77ef8654 NC |
548 | adr = 0; |
549 | } | |
550 | else | |
cd30bcef | 551 | SAFE_BYTE_GET (adr, data, len - 1, end); |
47704ddf | 552 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 553 | state_machine_regs.address = adr; |
ba8826a8 | 554 | state_machine_regs.view = 0; |
a233b20c | 555 | state_machine_regs.op_index = 0; |
19e6b90e L |
556 | break; |
557 | ||
558 | case DW_LNE_define_file: | |
143a3db0 | 559 | printf (_("define new File Table entry\n")); |
19e6b90e | 560 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 561 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 562 | |
d949ff56 NC |
563 | { |
564 | size_t l; | |
565 | ||
566 | name = data; | |
567 | l = strnlen ((char *) data, end - data); | |
cd30bcef AM |
568 | data += l + 1; |
569 | READ_ULEB (val, data, end); | |
570 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
571 | READ_ULEB (val, data, end); | |
572 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
573 | READ_ULEB (val, data, end); | |
574 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
d949ff56 NC |
575 | printf ("%.*s\n\n", (int) l, name); |
576 | } | |
f6f0e17b | 577 | |
cd30bcef | 578 | if (((size_t) (data - orig_data) != len + header_len) || data == end) |
b4eb7656 | 579 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
580 | break; |
581 | ||
ed4a4bdf | 582 | case DW_LNE_set_discriminator: |
cd30bcef AM |
583 | READ_ULEB (val, data, end); |
584 | printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val)); | |
ed4a4bdf CC |
585 | break; |
586 | ||
e2a0d921 NC |
587 | /* HP extensions. */ |
588 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 589 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
590 | break; |
591 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 592 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
593 | break; |
594 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 595 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
596 | break; |
597 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 598 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
599 | break; |
600 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 601 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
602 | break; |
603 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 604 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
605 | break; |
606 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 607 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
608 | break; |
609 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 610 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
611 | break; |
612 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 613 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
614 | break; |
615 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 616 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 617 | break; |
43294ab7 TG |
618 | case DW_LNE_HP_source_file_correlation: |
619 | { | |
cd30bcef | 620 | unsigned char *edata = data + len - 1; |
b4eb7656 AM |
621 | |
622 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
623 | ||
624 | while (data < edata) | |
625 | { | |
626 | unsigned int opc; | |
627 | ||
cd30bcef | 628 | READ_ULEB (opc, data, edata); |
b4eb7656 AM |
629 | |
630 | switch (opc) | |
631 | { | |
632 | case DW_LNE_HP_SFC_formfeed: | |
633 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
634 | break; | |
635 | case DW_LNE_HP_SFC_set_listing_line: | |
cd30bcef | 636 | READ_ULEB (val, data, edata); |
b4eb7656 | 637 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", |
cd30bcef | 638 | dwarf_vmatoa ("u", val)); |
b4eb7656 AM |
639 | break; |
640 | case DW_LNE_HP_SFC_associate: | |
641 | printf (" DW_LNE_HP_SFC_associate "); | |
cd30bcef AM |
642 | READ_ULEB (val, data, edata); |
643 | printf ("(%s", dwarf_vmatoa ("u", val)); | |
644 | READ_ULEB (val, data, edata); | |
645 | printf (",%s", dwarf_vmatoa ("u", val)); | |
646 | READ_ULEB (val, data, edata); | |
647 | printf (",%s)\n", dwarf_vmatoa ("u", val)); | |
b4eb7656 AM |
648 | break; |
649 | default: | |
650 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
651 | data = edata; | |
652 | break; | |
653 | } | |
654 | } | |
43294ab7 TG |
655 | } |
656 | break; | |
cecf136e | 657 | |
19e6b90e | 658 | default: |
7e665af3 | 659 | { |
cd30bcef | 660 | unsigned int rlen = len - 1; |
b4eb7656 AM |
661 | |
662 | if (op_code >= DW_LNE_lo_user | |
663 | /* The test against DW_LNW_hi_user is redundant due to | |
664 | the limited range of the unsigned char data type used | |
665 | for op_code. */ | |
666 | /*&& op_code <= DW_LNE_hi_user*/) | |
667 | printf (_("user defined: ")); | |
668 | else | |
669 | printf (_("UNKNOWN: ")); | |
670 | printf (_("length %d ["), rlen); | |
671 | for (; rlen; rlen--) | |
672 | printf (" %02x", *data++); | |
673 | printf ("]\n"); | |
7e665af3 | 674 | } |
19e6b90e L |
675 | break; |
676 | } | |
677 | ||
cd30bcef | 678 | return len + header_len; |
19e6b90e L |
679 | } |
680 | ||
0c588247 | 681 | static const unsigned char * |
467c65bc | 682 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
683 | { |
684 | struct dwarf_section *section = &debug_displays [str].section; | |
d949ff56 | 685 | const unsigned char * ret; |
19e6b90e L |
686 | |
687 | if (section->start == NULL) | |
0c588247 | 688 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e | 689 | |
d949ff56 | 690 | if (offset >= section->size) |
19e6b90e | 691 | { |
467c65bc NC |
692 | warn (_("DW_FORM_strp offset too big: %s\n"), |
693 | dwarf_vmatoa ("x", offset)); | |
0c588247 | 694 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
695 | } |
696 | ||
d949ff56 NC |
697 | ret = section->start + offset; |
698 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
699 | NUL byte. Since our caller is expecting to receive a well formed C | |
700 | string we test for the lack of a terminating byte here. */ | |
701 | if (strnlen ((const char *) ret, section->size - offset) | |
702 | == section->size - offset) | |
703 | ret = (const unsigned char *) | |
704 | _("<no NUL byte at end of .debug_str section>"); | |
705 | ||
521d4b19 | 706 | return ret; |
19e6b90e L |
707 | } |
708 | ||
77145576 JK |
709 | static const unsigned char * |
710 | fetch_indirect_line_string (dwarf_vma offset) | |
711 | { | |
712 | struct dwarf_section *section = &debug_displays [line_str].section; | |
d949ff56 | 713 | const unsigned char * ret; |
77145576 JK |
714 | |
715 | if (section->start == NULL) | |
716 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
717 | ||
d949ff56 | 718 | if (offset >= section->size) |
77145576 JK |
719 | { |
720 | warn (_("DW_FORM_line_strp offset too big: %s\n"), | |
721 | dwarf_vmatoa ("x", offset)); | |
722 | return (const unsigned char *) _("<offset is too big>"); | |
723 | } | |
724 | ||
d949ff56 NC |
725 | ret = section->start + offset; |
726 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
727 | with a NUL byte. Since our caller is expecting to receive a well formed | |
728 | C string we test for the lack of a terminating byte here. */ | |
729 | if (strnlen ((const char *) ret, section->size - offset) | |
730 | == section->size - offset) | |
731 | ret = (const unsigned char *) | |
732 | _("<no NUL byte at end of .debug_line_str section>"); | |
733 | ||
734 | return ret; | |
77145576 JK |
735 | } |
736 | ||
4723351a | 737 | static const char * |
341f9135 | 738 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
d85bf2ba | 739 | dwarf_vma offset_size, bfd_boolean dwo) |
4723351a CC |
740 | { |
741 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
742 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
743 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
744 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
e4b7104b | 745 | dwarf_vma index_offset; |
4723351a | 746 | dwarf_vma str_offset; |
d949ff56 | 747 | const char * ret; |
e4b7104b NC |
748 | unsigned char *curr = index_section->start; |
749 | const unsigned char *end = curr + index_section->size; | |
750 | dwarf_vma length; | |
4723351a CC |
751 | |
752 | if (index_section->start == NULL) | |
753 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
754 | : _("<no .debug_str_offsets section>")); | |
755 | ||
e4b7104b NC |
756 | if (str_section->start == NULL) |
757 | return (dwo ? _("<no .debug_str.dwo section>") | |
758 | : _("<no .debug_str section>")); | |
759 | ||
760 | /* FIXME: We should cache the length... */ | |
761 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); | |
762 | if (length == 0xffffffff) | |
763 | { | |
764 | if (offset_size != 8) | |
39f381cb | 765 | warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size)); |
e4b7104b NC |
766 | SAFE_BYTE_GET_AND_INC (length, curr, 8, end); |
767 | } | |
768 | else if (offset_size != 4) | |
769 | { | |
39f381cb | 770 | warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size)); |
e4b7104b NC |
771 | } |
772 | ||
39f381cb | 773 | if (length == 0) |
e4b7104b | 774 | { |
39f381cb NC |
775 | /* This is probably an old style .debug_str_offset section which |
776 | just contains offsets and no header (and the first offset is 0). */ | |
777 | curr = index_section->start; | |
778 | length = index_section->size; | |
779 | } | |
780 | else | |
781 | { | |
782 | /* Skip the version and padding bytes. | |
783 | We assume that they are correct. */ | |
784 | curr += 4; | |
785 | ||
786 | /* FIXME: The code below assumes that there is only one table | |
787 | in the .debug_str_offsets section, so check that now. */ | |
788 | if ((offset_size == 4 && curr + length < (end - 8)) | |
789 | || (offset_size == 8 && curr + length < (end - 16))) | |
790 | { | |
791 | warn (_("index table size is too small %s vs %s\n"), | |
792 | dwarf_vmatoa ("x", length), | |
793 | dwarf_vmatoa ("x", index_section->size)); | |
794 | return _("<table too small>"); | |
795 | } | |
e4b7104b NC |
796 | } |
797 | ||
798 | index_offset = idx * offset_size; | |
521d4b19 | 799 | |
341f9135 CC |
800 | if (this_set != NULL) |
801 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
e4b7104b NC |
802 | |
803 | if (index_offset >= length) | |
4723351a | 804 | { |
e4b7104b NC |
805 | warn (_("DW_FORM_GNU_str_index offset too big: %s vs %s\n"), |
806 | dwarf_vmatoa ("x", index_offset), | |
807 | dwarf_vmatoa ("x", length)); | |
4723351a CC |
808 | return _("<index offset is too big>"); |
809 | } | |
810 | ||
e4b7104b | 811 | str_offset = byte_get (curr + index_offset, offset_size); |
4723351a | 812 | str_offset -= str_section->address; |
d949ff56 | 813 | if (str_offset >= str_section->size) |
4723351a CC |
814 | { |
815 | warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), | |
816 | dwarf_vmatoa ("x", str_offset)); | |
817 | return _("<indirect index offset is too big>"); | |
818 | } | |
819 | ||
d949ff56 NC |
820 | ret = (const char *) str_section->start + str_offset; |
821 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. | |
822 | Since our caller is expecting to receive a well formed C string we test | |
823 | for the lack of a terminating byte here. */ | |
824 | if (strnlen (ret, str_section->size - str_offset) | |
825 | == str_section->size - str_offset) | |
826 | ret = (const char *) _("<no NUL byte at end of section>"); | |
827 | ||
828 | return ret; | |
4723351a CC |
829 | } |
830 | ||
831 | static const char * | |
832 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
833 | { | |
834 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
835 | ||
836 | if (section->start == NULL) | |
837 | return (_("<no .debug_addr section>")); | |
838 | ||
839 | if (offset + bytes > section->size) | |
840 | { | |
841 | warn (_("Offset into section %s too big: %s\n"), | |
b4eb7656 | 842 | section->name, dwarf_vmatoa ("x", offset)); |
4723351a CC |
843 | return "<offset too big>"; |
844 | } | |
845 | ||
846 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
847 | } | |
848 | ||
849 | ||
19e6b90e L |
850 | /* FIXME: There are better and more efficient ways to handle |
851 | these structures. For now though, I just want something that | |
852 | is simple to implement. */ | |
bcd213b2 | 853 | /* Records a single attribute in an abbrev. */ |
19e6b90e L |
854 | typedef struct abbrev_attr |
855 | { | |
bcd213b2 NC |
856 | unsigned long attribute; |
857 | unsigned long form; | |
858 | bfd_signed_vma implicit_const; | |
859 | struct abbrev_attr * next; | |
19e6b90e L |
860 | } |
861 | abbrev_attr; | |
862 | ||
bcd213b2 | 863 | /* Records a single abbrev. */ |
19e6b90e L |
864 | typedef struct abbrev_entry |
865 | { | |
bcd213b2 NC |
866 | unsigned long number; |
867 | unsigned long tag; | |
868 | int children; | |
869 | struct abbrev_attr * first_attr; | |
870 | struct abbrev_attr * last_attr; | |
871 | struct abbrev_entry * next; | |
19e6b90e L |
872 | } |
873 | abbrev_entry; | |
874 | ||
bcd213b2 NC |
875 | /* Records a set of abbreviations. */ |
876 | typedef struct abbrev_list | |
877 | { | |
878 | abbrev_entry * first_abbrev; | |
879 | abbrev_entry * last_abbrev; | |
76868f36 | 880 | dwarf_vma abbrev_base; |
bcd213b2 NC |
881 | dwarf_vma abbrev_offset; |
882 | struct abbrev_list * next; | |
883 | unsigned char * start_of_next_abbrevs; | |
884 | } | |
885 | abbrev_list; | |
886 | ||
887 | /* Records all the abbrevs found so far. */ | |
888 | static struct abbrev_list * abbrev_lists = NULL; | |
889 | ||
890 | typedef struct abbrev_map | |
891 | { | |
892 | dwarf_vma start; | |
893 | dwarf_vma end; | |
894 | abbrev_list * list; | |
895 | } abbrev_map; | |
896 | ||
897 | /* Maps between CU offsets and abbrev sets. */ | |
898 | static abbrev_map * cu_abbrev_map = NULL; | |
899 | static unsigned long num_abbrev_map_entries = 0; | |
900 | static unsigned long next_free_abbrev_map_entry = 0; | |
901 | ||
902 | #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8 | |
903 | #define ABBREV_MAP_ENTRIES_INCREMENT 8 | |
904 | ||
905 | static void | |
906 | record_abbrev_list_for_cu (dwarf_vma start, dwarf_vma end, abbrev_list * list) | |
907 | { | |
908 | if (cu_abbrev_map == NULL) | |
909 | { | |
910 | num_abbrev_map_entries = INITIAL_NUM_ABBREV_MAP_ENTRIES; | |
911 | cu_abbrev_map = xmalloc (num_abbrev_map_entries * sizeof (* cu_abbrev_map)); | |
912 | } | |
913 | else if (next_free_abbrev_map_entry == num_abbrev_map_entries) | |
914 | { | |
915 | num_abbrev_map_entries += ABBREV_MAP_ENTRIES_INCREMENT; | |
916 | cu_abbrev_map = xrealloc (cu_abbrev_map, num_abbrev_map_entries * sizeof (* cu_abbrev_map)); | |
917 | } | |
918 | ||
919 | cu_abbrev_map[next_free_abbrev_map_entry].start = start; | |
920 | cu_abbrev_map[next_free_abbrev_map_entry].end = end; | |
921 | cu_abbrev_map[next_free_abbrev_map_entry].list = list; | |
922 | next_free_abbrev_map_entry ++; | |
923 | } | |
19e6b90e L |
924 | |
925 | static void | |
bcd213b2 | 926 | free_all_abbrevs (void) |
19e6b90e | 927 | { |
bcd213b2 | 928 | abbrev_list * list; |
19e6b90e | 929 | |
bcd213b2 | 930 | for (list = abbrev_lists; list != NULL;) |
19e6b90e | 931 | { |
bcd213b2 NC |
932 | abbrev_list * next = list->next; |
933 | abbrev_entry * abbrv; | |
19e6b90e | 934 | |
bcd213b2 | 935 | for (abbrv = list->first_abbrev; abbrv != NULL;) |
19e6b90e | 936 | { |
bcd213b2 NC |
937 | abbrev_entry * next_abbrev = abbrv->next; |
938 | abbrev_attr * attr; | |
939 | ||
940 | for (attr = abbrv->first_attr; attr;) | |
941 | { | |
942 | abbrev_attr *next_attr = attr->next; | |
19e6b90e | 943 | |
bcd213b2 NC |
944 | free (attr); |
945 | attr = next_attr; | |
946 | } | |
947 | ||
948 | free (abbrv); | |
949 | abbrv = next_abbrev; | |
19e6b90e L |
950 | } |
951 | ||
bcd213b2 NC |
952 | free (list); |
953 | list = next; | |
19e6b90e L |
954 | } |
955 | ||
bcd213b2 NC |
956 | abbrev_lists = NULL; |
957 | } | |
958 | ||
959 | static abbrev_list * | |
76868f36 | 960 | new_abbrev_list (dwarf_vma abbrev_base, dwarf_vma abbrev_offset) |
bcd213b2 NC |
961 | { |
962 | abbrev_list * list = (abbrev_list *) xcalloc (sizeof * list, 1); | |
963 | ||
76868f36 | 964 | list->abbrev_base = abbrev_base; |
bcd213b2 NC |
965 | list->abbrev_offset = abbrev_offset; |
966 | ||
967 | list->next = abbrev_lists; | |
968 | abbrev_lists = list; | |
969 | ||
970 | return list; | |
971 | } | |
972 | ||
973 | static abbrev_list * | |
76868f36 L |
974 | find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base, |
975 | dwarf_vma abbrev_offset) | |
bcd213b2 NC |
976 | { |
977 | abbrev_list * list; | |
978 | ||
979 | for (list = abbrev_lists; list != NULL; list = list->next) | |
76868f36 L |
980 | if (list->abbrev_base == abbrev_base |
981 | && list->abbrev_offset == abbrev_offset) | |
bcd213b2 NC |
982 | return list; |
983 | ||
984 | return NULL; | |
985 | } | |
986 | ||
987 | /* Find the abbreviation map for the CU that includes OFFSET. | |
988 | OFFSET is an absolute offset from the start of the .debug_info section. */ | |
989 | /* FIXME: This function is going to slow down readelf & objdump. | |
990 | Consider using a better algorithm to mitigate this effect. */ | |
991 | ||
992 | static abbrev_map * | |
993 | find_abbrev_map_by_offset (dwarf_vma offset) | |
994 | { | |
995 | unsigned long i; | |
996 | ||
997 | for (i = 0; i < next_free_abbrev_map_entry; i++) | |
998 | if (cu_abbrev_map[i].start <= offset | |
999 | && cu_abbrev_map[i].end > offset) | |
1000 | return cu_abbrev_map + i; | |
1001 | ||
1002 | return NULL; | |
19e6b90e L |
1003 | } |
1004 | ||
1005 | static void | |
bcd213b2 NC |
1006 | add_abbrev (unsigned long number, |
1007 | unsigned long tag, | |
1008 | int children, | |
1009 | abbrev_list * list) | |
19e6b90e | 1010 | { |
bcd213b2 | 1011 | abbrev_entry * entry; |
19e6b90e | 1012 | |
bcd213b2 | 1013 | entry = (abbrev_entry *) xmalloc (sizeof (*entry)); |
19e6b90e | 1014 | |
bcd213b2 | 1015 | entry->number = number; |
19e6b90e L |
1016 | entry->tag = tag; |
1017 | entry->children = children; | |
1018 | entry->first_attr = NULL; | |
1019 | entry->last_attr = NULL; | |
1020 | entry->next = NULL; | |
1021 | ||
bcd213b2 NC |
1022 | assert (list != NULL); |
1023 | ||
1024 | if (list->first_abbrev == NULL) | |
1025 | list->first_abbrev = entry; | |
19e6b90e | 1026 | else |
bcd213b2 | 1027 | list->last_abbrev->next = entry; |
19e6b90e | 1028 | |
bcd213b2 | 1029 | list->last_abbrev = entry; |
19e6b90e L |
1030 | } |
1031 | ||
1032 | static void | |
bcd213b2 NC |
1033 | add_abbrev_attr (unsigned long attribute, |
1034 | unsigned long form, | |
1035 | bfd_signed_vma implicit_const, | |
1036 | abbrev_list * list) | |
19e6b90e L |
1037 | { |
1038 | abbrev_attr *attr; | |
1039 | ||
bcd213b2 | 1040 | attr = (abbrev_attr *) xmalloc (sizeof (*attr)); |
19e6b90e L |
1041 | |
1042 | attr->attribute = attribute; | |
1043 | attr->form = form; | |
77145576 | 1044 | attr->implicit_const = implicit_const; |
19e6b90e L |
1045 | attr->next = NULL; |
1046 | ||
bcd213b2 NC |
1047 | assert (list != NULL && list->last_abbrev != NULL); |
1048 | ||
1049 | if (list->last_abbrev->first_attr == NULL) | |
1050 | list->last_abbrev->first_attr = attr; | |
19e6b90e | 1051 | else |
bcd213b2 | 1052 | list->last_abbrev->last_attr->next = attr; |
19e6b90e | 1053 | |
bcd213b2 | 1054 | list->last_abbrev->last_attr = attr; |
19e6b90e L |
1055 | } |
1056 | ||
1057 | /* Processes the (partial) contents of a .debug_abbrev section. | |
1058 | Returns NULL if the end of the section was encountered. | |
1059 | Returns the address after the last byte read if the end of | |
1060 | an abbreviation set was found. */ | |
1061 | ||
1062 | static unsigned char * | |
bcd213b2 NC |
1063 | process_abbrev_set (unsigned char * start, |
1064 | const unsigned char * end, | |
1065 | abbrev_list * list) | |
19e6b90e | 1066 | { |
19e6b90e L |
1067 | while (start < end) |
1068 | { | |
19e6b90e L |
1069 | unsigned long entry; |
1070 | unsigned long tag; | |
1071 | unsigned long attribute; | |
1072 | int children; | |
1073 | ||
cd30bcef | 1074 | READ_ULEB (entry, start, end); |
19e6b90e | 1075 | |
bcd213b2 | 1076 | /* A single zero is supposed to end the set according |
19e6b90e L |
1077 | to the standard. If there's more, then signal that to |
1078 | the caller. */ | |
f6f0e17b NC |
1079 | if (start == end) |
1080 | return NULL; | |
19e6b90e | 1081 | if (entry == 0) |
f6f0e17b | 1082 | return start; |
19e6b90e | 1083 | |
cd30bcef | 1084 | READ_ULEB (tag, start, end); |
f6f0e17b NC |
1085 | if (start == end) |
1086 | return NULL; | |
19e6b90e L |
1087 | |
1088 | children = *start++; | |
1089 | ||
bcd213b2 | 1090 | add_abbrev (entry, tag, children, list); |
19e6b90e L |
1091 | |
1092 | do | |
1093 | { | |
1094 | unsigned long form; | |
77145576 JK |
1095 | /* Initialize it due to a false compiler warning. */ |
1096 | bfd_signed_vma implicit_const = -1; | |
19e6b90e | 1097 | |
cd30bcef | 1098 | READ_ULEB (attribute, start, end); |
f6f0e17b NC |
1099 | if (start == end) |
1100 | break; | |
19e6b90e | 1101 | |
cd30bcef | 1102 | READ_ULEB (form, start, end); |
f6f0e17b NC |
1103 | if (start == end) |
1104 | break; | |
19e6b90e | 1105 | |
77145576 JK |
1106 | if (form == DW_FORM_implicit_const) |
1107 | { | |
cd30bcef | 1108 | READ_SLEB (implicit_const, start, end); |
77145576 JK |
1109 | if (start == end) |
1110 | break; | |
1111 | } | |
1112 | ||
bcd213b2 | 1113 | add_abbrev_attr (attribute, form, implicit_const, list); |
19e6b90e L |
1114 | } |
1115 | while (attribute != 0); | |
1116 | } | |
1117 | ||
399c99f7 L |
1118 | /* Report the missing single zero which ends the section. */ |
1119 | error (_(".debug_abbrev section not zero terminated\n")); | |
1120 | ||
19e6b90e L |
1121 | return NULL; |
1122 | } | |
1123 | ||
a19c41a7 | 1124 | static const char * |
19e6b90e L |
1125 | get_TAG_name (unsigned long tag) |
1126 | { | |
04914e37 | 1127 | const char *name = get_DW_TAG_name ((unsigned int) tag); |
a19c41a7 TT |
1128 | |
1129 | if (name == NULL) | |
19e6b90e | 1130 | { |
a19c41a7 | 1131 | static char buffer[100]; |
19e6b90e | 1132 | |
04914e37 NC |
1133 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
1134 | snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag); | |
1135 | else | |
1136 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag); | |
a19c41a7 | 1137 | return buffer; |
19e6b90e | 1138 | } |
a19c41a7 TT |
1139 | |
1140 | return name; | |
19e6b90e L |
1141 | } |
1142 | ||
a19c41a7 | 1143 | static const char * |
19e6b90e L |
1144 | get_FORM_name (unsigned long form) |
1145 | { | |
399c99f7 | 1146 | const char *name; |
bf5117e3 | 1147 | |
399c99f7 L |
1148 | if (form == 0) |
1149 | return "DW_FORM value: 0"; | |
a19c41a7 | 1150 | |
399c99f7 | 1151 | name = get_DW_FORM_name (form); |
a19c41a7 | 1152 | if (name == NULL) |
19e6b90e | 1153 | { |
a19c41a7 | 1154 | static char buffer[100]; |
19e6b90e | 1155 | |
a19c41a7 TT |
1156 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
1157 | return buffer; | |
19e6b90e | 1158 | } |
a19c41a7 TT |
1159 | |
1160 | return name; | |
19e6b90e L |
1161 | } |
1162 | ||
61364358 JK |
1163 | static const char * |
1164 | get_IDX_name (unsigned long idx) | |
1165 | { | |
1166 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
1167 | ||
1168 | if (name == NULL) | |
1169 | { | |
1170 | static char buffer[100]; | |
1171 | ||
1172 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1173 | return buffer; | |
1174 | } | |
1175 | ||
1176 | return name; | |
1177 | } | |
1178 | ||
19e6b90e | 1179 | static unsigned char * |
0c588247 NC |
1180 | display_block (unsigned char *data, |
1181 | dwarf_vma length, | |
ef0b5f1c | 1182 | const unsigned char * const end, char delimiter) |
19e6b90e | 1183 | { |
0c588247 NC |
1184 | dwarf_vma maxlen; |
1185 | ||
ef0b5f1c | 1186 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
1187 | if (data > end) |
1188 | return (unsigned char *) end; | |
19e6b90e | 1189 | |
0c588247 NC |
1190 | maxlen = (dwarf_vma) (end - data); |
1191 | length = length > maxlen ? maxlen : length; | |
1192 | ||
19e6b90e L |
1193 | while (length --) |
1194 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1195 | ||
1196 | return data; | |
1197 | } | |
1198 | ||
1199 | static int | |
1200 | decode_location_expression (unsigned char * data, | |
1201 | unsigned int pointer_size, | |
b7807392 JJ |
1202 | unsigned int offset_size, |
1203 | int dwarf_version, | |
467c65bc NC |
1204 | dwarf_vma length, |
1205 | dwarf_vma cu_offset, | |
f1c4cc75 | 1206 | struct dwarf_section * section) |
19e6b90e L |
1207 | { |
1208 | unsigned op; | |
467c65bc | 1209 | dwarf_vma uvalue; |
0c588247 | 1210 | dwarf_signed_vma svalue; |
19e6b90e L |
1211 | unsigned char *end = data + length; |
1212 | int need_frame_base = 0; | |
1213 | ||
1214 | while (data < end) | |
1215 | { | |
1216 | op = *data++; | |
1217 | ||
1218 | switch (op) | |
1219 | { | |
1220 | case DW_OP_addr: | |
0c588247 NC |
1221 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1222 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1223 | break; |
1224 | case DW_OP_deref: | |
1225 | printf ("DW_OP_deref"); | |
1226 | break; | |
1227 | case DW_OP_const1u: | |
0c588247 NC |
1228 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1229 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1230 | break; |
1231 | case DW_OP_const1s: | |
0c588247 NC |
1232 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1233 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1234 | break; |
1235 | case DW_OP_const2u: | |
87bc83b3 | 1236 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1237 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1238 | break; |
1239 | case DW_OP_const2s: | |
0c588247 NC |
1240 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1241 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1242 | break; |
1243 | case DW_OP_const4u: | |
0c588247 NC |
1244 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1245 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1246 | break; |
1247 | case DW_OP_const4s: | |
0c588247 NC |
1248 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1249 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1250 | break; |
1251 | case DW_OP_const8u: | |
0c588247 NC |
1252 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1253 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1254 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1255 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1256 | break; |
1257 | case DW_OP_const8s: | |
0c588247 NC |
1258 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1259 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1260 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1261 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1262 | break; |
1263 | case DW_OP_constu: | |
cd30bcef AM |
1264 | READ_ULEB (uvalue, data, end); |
1265 | printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1266 | break; |
1267 | case DW_OP_consts: | |
cd30bcef AM |
1268 | READ_SLEB (svalue, data, end); |
1269 | printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1270 | break; |
1271 | case DW_OP_dup: | |
1272 | printf ("DW_OP_dup"); | |
1273 | break; | |
1274 | case DW_OP_drop: | |
1275 | printf ("DW_OP_drop"); | |
1276 | break; | |
1277 | case DW_OP_over: | |
1278 | printf ("DW_OP_over"); | |
1279 | break; | |
1280 | case DW_OP_pick: | |
0c588247 NC |
1281 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1282 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1283 | break; |
1284 | case DW_OP_swap: | |
1285 | printf ("DW_OP_swap"); | |
1286 | break; | |
1287 | case DW_OP_rot: | |
1288 | printf ("DW_OP_rot"); | |
1289 | break; | |
1290 | case DW_OP_xderef: | |
1291 | printf ("DW_OP_xderef"); | |
1292 | break; | |
1293 | case DW_OP_abs: | |
1294 | printf ("DW_OP_abs"); | |
1295 | break; | |
1296 | case DW_OP_and: | |
1297 | printf ("DW_OP_and"); | |
1298 | break; | |
1299 | case DW_OP_div: | |
1300 | printf ("DW_OP_div"); | |
1301 | break; | |
1302 | case DW_OP_minus: | |
1303 | printf ("DW_OP_minus"); | |
1304 | break; | |
1305 | case DW_OP_mod: | |
1306 | printf ("DW_OP_mod"); | |
1307 | break; | |
1308 | case DW_OP_mul: | |
1309 | printf ("DW_OP_mul"); | |
1310 | break; | |
1311 | case DW_OP_neg: | |
1312 | printf ("DW_OP_neg"); | |
1313 | break; | |
1314 | case DW_OP_not: | |
1315 | printf ("DW_OP_not"); | |
1316 | break; | |
1317 | case DW_OP_or: | |
1318 | printf ("DW_OP_or"); | |
1319 | break; | |
1320 | case DW_OP_plus: | |
1321 | printf ("DW_OP_plus"); | |
1322 | break; | |
1323 | case DW_OP_plus_uconst: | |
cd30bcef AM |
1324 | READ_ULEB (uvalue, data, end); |
1325 | printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1326 | break; |
1327 | case DW_OP_shl: | |
1328 | printf ("DW_OP_shl"); | |
1329 | break; | |
1330 | case DW_OP_shr: | |
1331 | printf ("DW_OP_shr"); | |
1332 | break; | |
1333 | case DW_OP_shra: | |
1334 | printf ("DW_OP_shra"); | |
1335 | break; | |
1336 | case DW_OP_xor: | |
1337 | printf ("DW_OP_xor"); | |
1338 | break; | |
1339 | case DW_OP_bra: | |
0c588247 NC |
1340 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1341 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1342 | break; |
1343 | case DW_OP_eq: | |
1344 | printf ("DW_OP_eq"); | |
1345 | break; | |
1346 | case DW_OP_ge: | |
1347 | printf ("DW_OP_ge"); | |
1348 | break; | |
1349 | case DW_OP_gt: | |
1350 | printf ("DW_OP_gt"); | |
1351 | break; | |
1352 | case DW_OP_le: | |
1353 | printf ("DW_OP_le"); | |
1354 | break; | |
1355 | case DW_OP_lt: | |
1356 | printf ("DW_OP_lt"); | |
1357 | break; | |
1358 | case DW_OP_ne: | |
1359 | printf ("DW_OP_ne"); | |
1360 | break; | |
1361 | case DW_OP_skip: | |
0c588247 NC |
1362 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1363 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1364 | break; |
1365 | ||
1366 | case DW_OP_lit0: | |
1367 | case DW_OP_lit1: | |
1368 | case DW_OP_lit2: | |
1369 | case DW_OP_lit3: | |
1370 | case DW_OP_lit4: | |
1371 | case DW_OP_lit5: | |
1372 | case DW_OP_lit6: | |
1373 | case DW_OP_lit7: | |
1374 | case DW_OP_lit8: | |
1375 | case DW_OP_lit9: | |
1376 | case DW_OP_lit10: | |
1377 | case DW_OP_lit11: | |
1378 | case DW_OP_lit12: | |
1379 | case DW_OP_lit13: | |
1380 | case DW_OP_lit14: | |
1381 | case DW_OP_lit15: | |
1382 | case DW_OP_lit16: | |
1383 | case DW_OP_lit17: | |
1384 | case DW_OP_lit18: | |
1385 | case DW_OP_lit19: | |
1386 | case DW_OP_lit20: | |
1387 | case DW_OP_lit21: | |
1388 | case DW_OP_lit22: | |
1389 | case DW_OP_lit23: | |
1390 | case DW_OP_lit24: | |
1391 | case DW_OP_lit25: | |
1392 | case DW_OP_lit26: | |
1393 | case DW_OP_lit27: | |
1394 | case DW_OP_lit28: | |
1395 | case DW_OP_lit29: | |
1396 | case DW_OP_lit30: | |
1397 | case DW_OP_lit31: | |
1398 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1399 | break; | |
1400 | ||
1401 | case DW_OP_reg0: | |
1402 | case DW_OP_reg1: | |
1403 | case DW_OP_reg2: | |
1404 | case DW_OP_reg3: | |
1405 | case DW_OP_reg4: | |
1406 | case DW_OP_reg5: | |
1407 | case DW_OP_reg6: | |
1408 | case DW_OP_reg7: | |
1409 | case DW_OP_reg8: | |
1410 | case DW_OP_reg9: | |
1411 | case DW_OP_reg10: | |
1412 | case DW_OP_reg11: | |
1413 | case DW_OP_reg12: | |
1414 | case DW_OP_reg13: | |
1415 | case DW_OP_reg14: | |
1416 | case DW_OP_reg15: | |
1417 | case DW_OP_reg16: | |
1418 | case DW_OP_reg17: | |
1419 | case DW_OP_reg18: | |
1420 | case DW_OP_reg19: | |
1421 | case DW_OP_reg20: | |
1422 | case DW_OP_reg21: | |
1423 | case DW_OP_reg22: | |
1424 | case DW_OP_reg23: | |
1425 | case DW_OP_reg24: | |
1426 | case DW_OP_reg25: | |
1427 | case DW_OP_reg26: | |
1428 | case DW_OP_reg27: | |
1429 | case DW_OP_reg28: | |
1430 | case DW_OP_reg29: | |
1431 | case DW_OP_reg30: | |
1432 | case DW_OP_reg31: | |
18464d4d JK |
1433 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1434 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1435 | break; |
1436 | ||
1437 | case DW_OP_breg0: | |
1438 | case DW_OP_breg1: | |
1439 | case DW_OP_breg2: | |
1440 | case DW_OP_breg3: | |
1441 | case DW_OP_breg4: | |
1442 | case DW_OP_breg5: | |
1443 | case DW_OP_breg6: | |
1444 | case DW_OP_breg7: | |
1445 | case DW_OP_breg8: | |
1446 | case DW_OP_breg9: | |
1447 | case DW_OP_breg10: | |
1448 | case DW_OP_breg11: | |
1449 | case DW_OP_breg12: | |
1450 | case DW_OP_breg13: | |
1451 | case DW_OP_breg14: | |
1452 | case DW_OP_breg15: | |
1453 | case DW_OP_breg16: | |
1454 | case DW_OP_breg17: | |
1455 | case DW_OP_breg18: | |
1456 | case DW_OP_breg19: | |
1457 | case DW_OP_breg20: | |
1458 | case DW_OP_breg21: | |
1459 | case DW_OP_breg22: | |
1460 | case DW_OP_breg23: | |
1461 | case DW_OP_breg24: | |
1462 | case DW_OP_breg25: | |
1463 | case DW_OP_breg26: | |
1464 | case DW_OP_breg27: | |
1465 | case DW_OP_breg28: | |
1466 | case DW_OP_breg29: | |
1467 | case DW_OP_breg30: | |
1468 | case DW_OP_breg31: | |
cd30bcef AM |
1469 | READ_SLEB (svalue, data, end); |
1470 | printf ("DW_OP_breg%d (%s): %s", op - DW_OP_breg0, | |
1471 | regname (op - DW_OP_breg0, 1), dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1472 | break; |
1473 | ||
1474 | case DW_OP_regx: | |
cd30bcef | 1475 | READ_ULEB (uvalue, data, end); |
467c65bc NC |
1476 | printf ("DW_OP_regx: %s (%s)", |
1477 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1478 | break; |
1479 | case DW_OP_fbreg: | |
1480 | need_frame_base = 1; | |
cd30bcef AM |
1481 | READ_SLEB (svalue, data, end); |
1482 | printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1483 | break; |
1484 | case DW_OP_bregx: | |
cd30bcef AM |
1485 | READ_ULEB (uvalue, data, end); |
1486 | READ_SLEB (svalue, data, end); | |
467c65bc NC |
1487 | printf ("DW_OP_bregx: %s (%s) %s", |
1488 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
cd30bcef | 1489 | dwarf_vmatoa ("d", svalue)); |
19e6b90e L |
1490 | break; |
1491 | case DW_OP_piece: | |
cd30bcef AM |
1492 | READ_ULEB (uvalue, data, end); |
1493 | printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1494 | break; |
1495 | case DW_OP_deref_size: | |
0c588247 NC |
1496 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1497 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1498 | break; |
1499 | case DW_OP_xderef_size: | |
0c588247 NC |
1500 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1501 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1502 | break; |
1503 | case DW_OP_nop: | |
1504 | printf ("DW_OP_nop"); | |
1505 | break; | |
1506 | ||
1507 | /* DWARF 3 extensions. */ | |
1508 | case DW_OP_push_object_address: | |
1509 | printf ("DW_OP_push_object_address"); | |
1510 | break; | |
1511 | case DW_OP_call2: | |
d85bf2ba | 1512 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1513 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1514 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1515 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1516 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1517 | break; |
1518 | case DW_OP_call4: | |
d85bf2ba | 1519 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1520 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1521 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1522 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1523 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1524 | break; |
1525 | case DW_OP_call_ref: | |
d85bf2ba | 1526 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
e2a0d921 | 1527 | this ought to be an 8-byte wide computation. */ |
b7807392 JJ |
1528 | if (dwarf_version == -1) |
1529 | { | |
1530 | printf (_("(DW_OP_call_ref in frame info)")); | |
1531 | /* No way to tell where the next op is, so just bail. */ | |
1532 | return need_frame_base; | |
1533 | } | |
1534 | if (dwarf_version == 2) | |
1535 | { | |
0c588247 | 1536 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1537 | } |
1538 | else | |
1539 | { | |
0c588247 | 1540 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1541 | } |
0c588247 | 1542 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1543 | break; |
a87b0a59 NS |
1544 | case DW_OP_form_tls_address: |
1545 | printf ("DW_OP_form_tls_address"); | |
1546 | break; | |
e2a0d921 NC |
1547 | case DW_OP_call_frame_cfa: |
1548 | printf ("DW_OP_call_frame_cfa"); | |
1549 | break; | |
1550 | case DW_OP_bit_piece: | |
1551 | printf ("DW_OP_bit_piece: "); | |
cd30bcef AM |
1552 | READ_ULEB (uvalue, data, end); |
1553 | printf (_("size: %s "), dwarf_vmatoa ("u", uvalue)); | |
1554 | READ_ULEB (uvalue, data, end); | |
1555 | printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue)); | |
e2a0d921 | 1556 | break; |
19e6b90e | 1557 | |
3244e8f5 JJ |
1558 | /* DWARF 4 extensions. */ |
1559 | case DW_OP_stack_value: | |
1560 | printf ("DW_OP_stack_value"); | |
1561 | break; | |
1562 | ||
1563 | case DW_OP_implicit_value: | |
1564 | printf ("DW_OP_implicit_value"); | |
cd30bcef | 1565 | READ_ULEB (uvalue, data, end); |
ef0b5f1c | 1566 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1567 | break; |
1568 | ||
19e6b90e L |
1569 | /* GNU extensions. */ |
1570 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1571 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1572 | break; |
1573 | case DW_OP_GNU_uninit: | |
1574 | printf ("DW_OP_GNU_uninit"); | |
1575 | /* FIXME: Is there data associated with this OP ? */ | |
1576 | break; | |
f1c4cc75 RH |
1577 | case DW_OP_GNU_encoded_addr: |
1578 | { | |
6937bb54 | 1579 | int encoding = 0; |
f1c4cc75 | 1580 | dwarf_vma addr; |
467c65bc | 1581 | |
6937bb54 NC |
1582 | if (data < end) |
1583 | encoding = *data++; | |
041830e0 | 1584 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1585 | |
1586 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1587 | print_dwarf_vma (addr, pointer_size); | |
1588 | } | |
1589 | break; | |
bc0a77d2 | 1590 | case DW_OP_implicit_pointer: |
b7807392 | 1591 | case DW_OP_GNU_implicit_pointer: |
d85bf2ba | 1592 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
b7807392 JJ |
1593 | this ought to be an 8-byte wide computation. */ |
1594 | if (dwarf_version == -1) | |
1595 | { | |
bc0a77d2 JK |
1596 | printf (_("(%s in frame info)"), |
1597 | (op == DW_OP_implicit_pointer | |
1598 | ? "DW_OP_implicit_pointer" | |
1599 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1600 | /* No way to tell where the next op is, so just bail. */ |
1601 | return need_frame_base; | |
1602 | } | |
1603 | if (dwarf_version == 2) | |
1604 | { | |
0c588247 | 1605 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1606 | } |
1607 | else | |
1608 | { | |
0c588247 | 1609 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1610 | } |
cd30bcef | 1611 | READ_SLEB (svalue, data, end); |
bc0a77d2 JK |
1612 | printf ("%s: <0x%s> %s", |
1613 | (op == DW_OP_implicit_pointer | |
1614 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 | 1615 | dwarf_vmatoa ("x", uvalue), |
cd30bcef | 1616 | dwarf_vmatoa ("d", svalue)); |
b7807392 | 1617 | break; |
77145576 | 1618 | case DW_OP_entry_value: |
0892011d | 1619 | case DW_OP_GNU_entry_value: |
cd30bcef | 1620 | READ_ULEB (uvalue, data, end); |
058037d3 NC |
1621 | /* PR 17531: file: 0cc9cd00. */ |
1622 | if (uvalue > (dwarf_vma) (end - data)) | |
1623 | uvalue = end - data; | |
77145576 JK |
1624 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1625 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1626 | if (decode_location_expression (data, pointer_size, offset_size, |
1627 | dwarf_version, uvalue, | |
1628 | cu_offset, section)) | |
1629 | need_frame_base = 1; | |
1630 | putchar (')'); | |
1631 | data += uvalue; | |
6937bb54 NC |
1632 | if (data > end) |
1633 | data = end; | |
0892011d | 1634 | break; |
bc0a77d2 | 1635 | case DW_OP_const_type: |
0892011d | 1636 | case DW_OP_GNU_const_type: |
cd30bcef | 1637 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1638 | printf ("%s: <0x%s> ", |
1639 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1640 | : "DW_OP_GNU_const_type"), | |
0892011d | 1641 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1642 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1643 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1644 | break; |
bc0a77d2 | 1645 | case DW_OP_regval_type: |
0892011d | 1646 | case DW_OP_GNU_regval_type: |
cd30bcef | 1647 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1648 | printf ("%s: %s (%s)", |
1649 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1650 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1651 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
cd30bcef | 1652 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1653 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1654 | break; | |
bc0a77d2 | 1655 | case DW_OP_deref_type: |
0892011d | 1656 | case DW_OP_GNU_deref_type: |
0c588247 | 1657 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1658 | printf ("%s: %ld", |
1659 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1660 | : "DW_OP_GNU_deref_type"), | |
1661 | (long) uvalue); | |
cd30bcef | 1662 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1663 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1664 | break; | |
bc0a77d2 | 1665 | case DW_OP_convert: |
0892011d | 1666 | case DW_OP_GNU_convert: |
cd30bcef | 1667 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1668 | printf ("%s <0x%s>", |
1669 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1670 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1671 | break; |
bc0a77d2 | 1672 | case DW_OP_reinterpret: |
0892011d | 1673 | case DW_OP_GNU_reinterpret: |
cd30bcef | 1674 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1675 | printf ("%s <0x%s>", |
1676 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1677 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1678 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1679 | break; | |
1680 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1681 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1682 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1683 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1684 | break; |
b4eb7656 | 1685 | case DW_OP_GNU_addr_index: |
cd30bcef | 1686 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1687 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1688 | break; | |
1689 | case DW_OP_GNU_const_index: | |
cd30bcef | 1690 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1691 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1692 | break; | |
f384a1f0 KB |
1693 | case DW_OP_GNU_variable_value: |
1694 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1695 | this ought to be an 8-byte wide computation. */ | |
1696 | if (dwarf_version == -1) | |
1697 | { | |
1698 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1699 | /* No way to tell where the next op is, so just bail. */ | |
1700 | return need_frame_base; | |
1701 | } | |
1702 | if (dwarf_version == 2) | |
1703 | { | |
1704 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1705 | } | |
1706 | else | |
1707 | { | |
1708 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1709 | } | |
1710 | printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1711 | break; | |
e2a0d921 NC |
1712 | |
1713 | /* HP extensions. */ | |
1714 | case DW_OP_HP_is_value: | |
1715 | printf ("DW_OP_HP_is_value"); | |
1716 | /* FIXME: Is there data associated with this OP ? */ | |
1717 | break; | |
1718 | case DW_OP_HP_fltconst4: | |
1719 | printf ("DW_OP_HP_fltconst4"); | |
1720 | /* FIXME: Is there data associated with this OP ? */ | |
1721 | break; | |
1722 | case DW_OP_HP_fltconst8: | |
1723 | printf ("DW_OP_HP_fltconst8"); | |
1724 | /* FIXME: Is there data associated with this OP ? */ | |
1725 | break; | |
1726 | case DW_OP_HP_mod_range: | |
1727 | printf ("DW_OP_HP_mod_range"); | |
1728 | /* FIXME: Is there data associated with this OP ? */ | |
1729 | break; | |
1730 | case DW_OP_HP_unmod_range: | |
1731 | printf ("DW_OP_HP_unmod_range"); | |
1732 | /* FIXME: Is there data associated with this OP ? */ | |
1733 | break; | |
1734 | case DW_OP_HP_tls: | |
1735 | printf ("DW_OP_HP_tls"); | |
1736 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1737 | break; |
1738 | ||
35d60fe4 NC |
1739 | /* PGI (STMicroelectronics) extensions. */ |
1740 | case DW_OP_PGI_omp_thread_num: | |
1741 | /* Pushes the thread number for the current thread as it would be | |
1742 | returned by the standard OpenMP library function: | |
1743 | omp_get_thread_num(). The "current thread" is the thread for | |
1744 | which the expression is being evaluated. */ | |
1745 | printf ("DW_OP_PGI_omp_thread_num"); | |
1746 | break; | |
1747 | ||
19e6b90e L |
1748 | default: |
1749 | if (op >= DW_OP_lo_user | |
1750 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1751 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1752 | else |
0502a2b4 | 1753 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1754 | /* No way to tell where the next op is, so just bail. */ |
1755 | return need_frame_base; | |
1756 | } | |
1757 | ||
1758 | /* Separate the ops. */ | |
1759 | if (data < end) | |
1760 | printf ("; "); | |
1761 | } | |
1762 | ||
1763 | return need_frame_base; | |
1764 | } | |
1765 | ||
341f9135 CC |
1766 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1767 | This is used for DWARF package files. */ | |
1768 | ||
1769 | static struct cu_tu_set * | |
1770 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1771 | { | |
1772 | struct cu_tu_set *p; | |
1773 | unsigned int nsets; | |
1774 | unsigned int dw_sect; | |
1775 | ||
1776 | if (do_types) | |
1777 | { | |
1778 | p = tu_sets; | |
1779 | nsets = tu_count; | |
1780 | dw_sect = DW_SECT_TYPES; | |
1781 | } | |
1782 | else | |
1783 | { | |
1784 | p = cu_sets; | |
1785 | nsets = cu_count; | |
1786 | dw_sect = DW_SECT_INFO; | |
1787 | } | |
1788 | while (nsets > 0) | |
1789 | { | |
1790 | if (p->section_offsets [dw_sect] == cu_offset) | |
1791 | return p; | |
1792 | p++; | |
1793 | nsets--; | |
1794 | } | |
1795 | return NULL; | |
1796 | } | |
1797 | ||
a69c4772 NC |
1798 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1799 | static void | |
1800 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1801 | { | |
1802 | dwarf_vma tmp = * low_bits; | |
1803 | ||
1804 | tmp += inc; | |
1805 | ||
1806 | /* FIXME: There is probably a better way of handling this: | |
1807 | ||
1808 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1809 | type. Plus regardless of its size LOW_BITS is meant to | |
1810 | only hold 32-bits, so if there is overflow or wrap around | |
1811 | we must propagate into HIGH_BITS. */ | |
1812 | if (tmp < * low_bits) | |
1813 | { | |
1814 | ++ * high_bits; | |
1815 | } | |
1816 | else if (sizeof (tmp) > 8 | |
1817 | && (tmp >> 31) > 1) | |
1818 | { | |
1819 | ++ * high_bits; | |
1820 | tmp &= 0xFFFFFFFF; | |
1821 | } | |
1822 | ||
1823 | * low_bits = tmp; | |
1824 | } | |
1825 | ||
dda8d76d NC |
1826 | static const char * |
1827 | fetch_alt_indirect_string (dwarf_vma offset) | |
1828 | { | |
24841daa | 1829 | separate_info * i; |
dda8d76d NC |
1830 | |
1831 | if (! do_follow_links) | |
1832 | return ""; | |
1833 | ||
24841daa NC |
1834 | if (first_separate_info == NULL) |
1835 | return _("<no links available>"); | |
dda8d76d | 1836 | |
24841daa NC |
1837 | for (i = first_separate_info; i != NULL; i = i->next) |
1838 | { | |
1839 | struct dwarf_section * section; | |
1840 | const char * ret; | |
dda8d76d | 1841 | |
24841daa NC |
1842 | if (! load_debug_section (separate_debug_str, i->handle)) |
1843 | continue; | |
dda8d76d | 1844 | |
24841daa | 1845 | section = &debug_displays [separate_debug_str].section; |
dda8d76d | 1846 | |
24841daa NC |
1847 | if (section->start == NULL) |
1848 | continue; | |
dda8d76d | 1849 | |
24841daa NC |
1850 | if (offset >= section->size) |
1851 | continue; | |
1852 | ||
1853 | ret = (const char *) (section->start + offset); | |
1854 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1855 | NUL byte. Since our caller is expecting to receive a well formed C | |
1856 | string we test for the lack of a terminating byte here. */ | |
1857 | if (strnlen ((const char *) ret, section->size - offset) | |
1858 | == section->size - offset) | |
1859 | return _("<no NUL byte at end of alt .debug_str section>"); | |
1860 | ||
1861 | return ret; | |
1862 | } | |
521d4b19 | 1863 | |
24841daa NC |
1864 | warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"), |
1865 | dwarf_vmatoa ("x", offset)); | |
1866 | return _("<offset is too big>"); | |
dda8d76d NC |
1867 | } |
1868 | ||
d85bf2ba NC |
1869 | static const char * |
1870 | get_AT_name (unsigned long attribute) | |
1871 | { | |
1872 | const char *name; | |
1873 | ||
1874 | if (attribute == 0) | |
1875 | return "DW_AT value: 0"; | |
1876 | ||
1877 | /* One value is shared by the MIPS and HP extensions: */ | |
1878 | if (attribute == DW_AT_MIPS_fde) | |
1879 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1880 | ||
1881 | name = get_DW_AT_name (attribute); | |
1882 | ||
1883 | if (name == NULL) | |
1884 | { | |
1885 | static char buffer[100]; | |
1886 | ||
1887 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1888 | attribute); | |
1889 | return buffer; | |
1890 | } | |
1891 | ||
1892 | return name; | |
1893 | } | |
1894 | ||
24841daa | 1895 | static void |
50ea0877 | 1896 | add_dwo_info (const char * value, dwarf_vma cu_offset, dwo_type type) |
24841daa NC |
1897 | { |
1898 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); | |
1899 | ||
50ea0877 NC |
1900 | dwinfo->type = type; |
1901 | dwinfo->value = value; | |
1902 | dwinfo->cu_offset = cu_offset; | |
1903 | dwinfo->next = first_dwo_info; | |
24841daa NC |
1904 | first_dwo_info = dwinfo; |
1905 | } | |
1906 | ||
1907 | static void | |
50ea0877 | 1908 | add_dwo_name (const char * name, dwarf_vma cu_offset) |
24841daa | 1909 | { |
50ea0877 | 1910 | add_dwo_info (name, cu_offset, DWO_NAME); |
24841daa NC |
1911 | } |
1912 | ||
1913 | static void | |
50ea0877 | 1914 | add_dwo_dir (const char * dir, dwarf_vma cu_offset) |
24841daa | 1915 | { |
50ea0877 | 1916 | add_dwo_info (dir, cu_offset, DWO_DIR); |
24841daa NC |
1917 | } |
1918 | ||
1919 | static void | |
50ea0877 | 1920 | add_dwo_id (const char * id, dwarf_vma cu_offset) |
24841daa | 1921 | { |
50ea0877 | 1922 | add_dwo_info (id, cu_offset, DWO_ID); |
24841daa NC |
1923 | } |
1924 | ||
1925 | static void | |
1926 | free_dwo_info (void) | |
1927 | { | |
1928 | dwo_info * dwinfo; | |
1929 | dwo_info * next; | |
1930 | ||
1931 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) | |
1932 | { | |
1933 | next = dwinfo->next; | |
1934 | free (dwinfo); | |
1935 | } | |
1936 | first_dwo_info = NULL; | |
1937 | } | |
1938 | ||
afc72f15 NC |
1939 | /* Ensure that START + UVALUE is less than END. |
1940 | Return an adjusted UVALUE if necessary to ensure this relationship. */ | |
1941 | ||
1942 | static inline dwarf_vma | |
1943 | check_uvalue (const unsigned char * start, | |
1944 | dwarf_vma uvalue, | |
1945 | const unsigned char * end) | |
1946 | { | |
1947 | dwarf_vma max_uvalue = end - start; | |
1948 | ||
afc72f15 NC |
1949 | /* See PR 17512: file: 008-103549-0.001:0.1. |
1950 | and PR 24829 for examples of where these tests are triggered. */ | |
a85eba51 | 1951 | if (uvalue > max_uvalue) |
afc72f15 NC |
1952 | { |
1953 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1954 | uvalue = max_uvalue; | |
1955 | } | |
1956 | ||
1957 | return uvalue; | |
1958 | } | |
1959 | ||
ec1b0fbb NC |
1960 | static unsigned char * |
1961 | skip_attr_bytes (unsigned long form, | |
1962 | unsigned char * data, | |
1963 | unsigned const char * end, | |
1964 | dwarf_vma pointer_size, | |
1965 | dwarf_vma offset_size, | |
1966 | int dwarf_version, | |
1967 | dwarf_vma * value_return) | |
1968 | { | |
cd30bcef AM |
1969 | dwarf_signed_vma svalue; |
1970 | dwarf_vma uvalue = 0; | |
ec1b0fbb NC |
1971 | |
1972 | * value_return = 0; | |
1973 | ||
1974 | switch (form) | |
1975 | { | |
1976 | case DW_FORM_ref_addr: | |
1977 | if (dwarf_version == 2) | |
1978 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
59624513 | 1979 | else if (dwarf_version > 2) |
ec1b0fbb NC |
1980 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
1981 | else | |
1982 | return NULL; | |
1983 | break; | |
1984 | ||
1985 | case DW_FORM_addr: | |
1986 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1987 | break; | |
1988 | ||
1989 | case DW_FORM_strp: | |
1990 | case DW_FORM_line_strp: | |
1991 | case DW_FORM_sec_offset: | |
1992 | case DW_FORM_GNU_ref_alt: | |
1993 | case DW_FORM_GNU_strp_alt: | |
1994 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1995 | break; | |
1996 | ||
1997 | case DW_FORM_flag_present: | |
1998 | uvalue = 1; | |
1999 | break; | |
2000 | ||
2001 | case DW_FORM_ref1: | |
2002 | case DW_FORM_flag: | |
2003 | case DW_FORM_data1: | |
2004 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
2005 | break; | |
2006 | ||
2007 | case DW_FORM_ref2: | |
2008 | case DW_FORM_data2: | |
2009 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); | |
2010 | break; | |
2011 | ||
2012 | case DW_FORM_ref4: | |
2013 | case DW_FORM_data4: | |
2014 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
2015 | break; | |
2016 | ||
2017 | case DW_FORM_sdata: | |
cd30bcef AM |
2018 | READ_SLEB (svalue, data, end); |
2019 | uvalue = svalue; | |
ec1b0fbb NC |
2020 | break; |
2021 | ||
2022 | case DW_FORM_ref_udata: | |
2023 | case DW_FORM_udata: | |
2024 | case DW_FORM_GNU_str_index: | |
2025 | case DW_FORM_GNU_addr_index: | |
cd30bcef | 2026 | READ_ULEB (uvalue, data, end); |
ec1b0fbb NC |
2027 | break; |
2028 | ||
2029 | case DW_FORM_ref8: | |
1f573141 NC |
2030 | { |
2031 | dwarf_vma high_bits; | |
2032 | ||
2033 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); | |
2034 | data += 8; | |
2035 | if (sizeof (uvalue) > 4) | |
2036 | uvalue += high_bits << 32; | |
2037 | else if (high_bits != 0) | |
2038 | { | |
2039 | /* FIXME: What to do ? */ | |
2040 | return NULL; | |
2041 | } | |
2042 | break; | |
2043 | } | |
2044 | ||
ec1b0fbb | 2045 | case DW_FORM_data8: |
59624513 | 2046 | case DW_FORM_ref_sig8: |
ec1b0fbb NC |
2047 | data += 8; |
2048 | break; | |
2049 | ||
2050 | case DW_FORM_data16: | |
2051 | data += 16; | |
2052 | break; | |
2053 | ||
2054 | case DW_FORM_string: | |
2055 | data += strnlen ((char *) data, end - data) + 1; | |
2056 | break; | |
2057 | ||
2058 | case DW_FORM_block: | |
2059 | case DW_FORM_exprloc: | |
cd30bcef | 2060 | READ_ULEB (uvalue, data, end); |
59624513 | 2061 | data += uvalue; |
ec1b0fbb NC |
2062 | break; |
2063 | ||
2064 | case DW_FORM_block1: | |
2065 | SAFE_BYTE_GET (uvalue, data, 1, end); | |
2066 | data += 1 + uvalue; | |
2067 | break; | |
2068 | ||
2069 | case DW_FORM_block2: | |
2070 | SAFE_BYTE_GET (uvalue, data, 2, end); | |
2071 | data += 2 + uvalue; | |
2072 | break; | |
2073 | ||
2074 | case DW_FORM_block4: | |
2075 | SAFE_BYTE_GET (uvalue, data, 4, end); | |
2076 | data += 4 + uvalue; | |
2077 | break; | |
2078 | ||
ec1b0fbb | 2079 | case DW_FORM_indirect: |
59624513 NC |
2080 | READ_ULEB (form, data, end); |
2081 | if (form == DW_FORM_implicit_const) | |
2082 | SKIP_ULEB (data, end); | |
2083 | return skip_attr_bytes (form, data, end, pointer_size, offset_size, dwarf_version, value_return); | |
2084 | ||
ec1b0fbb NC |
2085 | default: |
2086 | return NULL; | |
2087 | } | |
2088 | ||
2089 | * value_return = uvalue; | |
2090 | if (data > end) | |
2091 | data = (unsigned char *) end; | |
2092 | return data; | |
2093 | } | |
2094 | ||
bcd213b2 NC |
2095 | /* Given form FORM with value UVALUE, locate and return the abbreviation |
2096 | associated with it. */ | |
2097 | ||
2098 | static abbrev_entry * | |
2099 | get_type_abbrev_from_form (unsigned long form, | |
2100 | unsigned long uvalue, | |
2101 | dwarf_vma cu_offset, | |
2102 | const struct dwarf_section * section, | |
2103 | unsigned long * abbrev_num_return, | |
2104 | unsigned char ** data_return, | |
2105 | unsigned long * cu_offset_return) | |
2106 | { | |
2107 | unsigned long abbrev_number; | |
2108 | abbrev_map * map; | |
2109 | abbrev_entry * entry; | |
2110 | unsigned char * data; | |
2111 | ||
2112 | if (abbrev_num_return != NULL) | |
2113 | * abbrev_num_return = 0; | |
2114 | if (data_return != NULL) | |
2115 | * data_return = NULL; | |
2116 | ||
2117 | switch (form) | |
2118 | { | |
2119 | case DW_FORM_GNU_ref_alt: | |
2120 | /* FIXME: We are unable to handle this form at the moment. */ | |
2121 | return NULL; | |
2122 | ||
2123 | case DW_FORM_ref_addr: | |
2124 | if (uvalue >= section->size) | |
2125 | { | |
2126 | warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"), | |
2127 | uvalue, (long) section->size, section->name); | |
2128 | return NULL; | |
2129 | } | |
2130 | break; | |
2131 | ||
2132 | case DW_FORM_ref1: | |
2133 | case DW_FORM_ref2: | |
2134 | case DW_FORM_ref4: | |
1f573141 | 2135 | case DW_FORM_ref8: |
bcd213b2 NC |
2136 | case DW_FORM_ref_udata: |
2137 | if (uvalue + cu_offset > section->size) | |
2138 | { | |
2139 | warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > section size %lx\n"), | |
2140 | uvalue, (long) cu_offset, (long) section->size); | |
2141 | return NULL; | |
2142 | } | |
2143 | uvalue += cu_offset; | |
2144 | break; | |
2145 | ||
2146 | /* FIXME: Are there other DW_FORMs that can be used by types ? */ | |
2147 | ||
2148 | default: | |
2149 | warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form); | |
2150 | return NULL; | |
2151 | } | |
2152 | ||
2153 | data = (unsigned char *) section->start + uvalue; | |
2154 | map = find_abbrev_map_by_offset (uvalue); | |
521d4b19 | 2155 | |
bcd213b2 NC |
2156 | if (map == NULL) |
2157 | { | |
2158 | warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue); | |
2159 | return NULL; | |
2160 | } | |
2161 | if (map->list == NULL) | |
2162 | { | |
2163 | warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue); | |
2164 | return NULL; | |
2165 | } | |
2166 | ||
2167 | if (cu_offset_return != NULL) | |
2168 | { | |
2169 | if (form == DW_FORM_ref_addr) | |
2170 | * cu_offset_return = map->start; | |
2171 | else | |
2172 | * cu_offset_return = cu_offset; | |
2173 | } | |
2174 | ||
2175 | READ_ULEB (abbrev_number, data, section->start + section->size); | |
2176 | ||
2177 | for (entry = map->list->first_abbrev; entry != NULL; entry = entry->next) | |
2178 | if (entry->number == abbrev_number) | |
2179 | break; | |
521d4b19 | 2180 | |
bcd213b2 NC |
2181 | if (abbrev_num_return != NULL) |
2182 | * abbrev_num_return = abbrev_number; | |
2183 | ||
2184 | if (data_return != NULL) | |
2185 | * data_return = data; | |
2186 | ||
2187 | if (entry == NULL) | |
2188 | warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number); | |
2189 | ||
2190 | return entry; | |
2191 | } | |
2192 | ||
2193 | /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY | |
2194 | can be determined to be a signed type. The data for ENTRY can be | |
2195 | found starting at DATA. */ | |
ec1b0fbb NC |
2196 | |
2197 | static void | |
bcd213b2 NC |
2198 | get_type_signedness (abbrev_entry * entry, |
2199 | const struct dwarf_section * section, | |
ec1b0fbb NC |
2200 | unsigned char * data, |
2201 | unsigned const char * end, | |
bcd213b2 | 2202 | dwarf_vma cu_offset, |
ec1b0fbb NC |
2203 | dwarf_vma pointer_size, |
2204 | dwarf_vma offset_size, | |
2205 | int dwarf_version, | |
2206 | bfd_boolean * is_signed, | |
59624513 | 2207 | unsigned int nesting) |
ec1b0fbb | 2208 | { |
ec1b0fbb NC |
2209 | abbrev_attr * attr; |
2210 | ||
2211 | * is_signed = FALSE; | |
2212 | ||
59624513 NC |
2213 | #define MAX_NESTING 20 |
2214 | if (nesting > MAX_NESTING) | |
2215 | { | |
2216 | /* FIXME: Warn - or is this expected ? | |
2217 | NB/ We need to avoid infinite recursion. */ | |
2218 | return; | |
2219 | } | |
2220 | ||
ec1b0fbb NC |
2221 | for (attr = entry->first_attr; |
2222 | attr != NULL && attr->attribute; | |
2223 | attr = attr->next) | |
2224 | { | |
bcd213b2 | 2225 | unsigned char * orig_data = data; |
ec1b0fbb NC |
2226 | dwarf_vma uvalue = 0; |
2227 | ||
2228 | data = skip_attr_bytes (attr->form, data, end, pointer_size, | |
2229 | offset_size, dwarf_version, & uvalue); | |
2230 | if (data == NULL) | |
2231 | return; | |
2232 | ||
2233 | switch (attr->attribute) | |
2234 | { | |
bcd213b2 | 2235 | case DW_AT_linkage_name: |
ec1b0fbb | 2236 | case DW_AT_name: |
bcd213b2 NC |
2237 | if (do_wide) |
2238 | { | |
2239 | if (attr->form == DW_FORM_strp) | |
2240 | printf (", %s", fetch_indirect_string (uvalue)); | |
2241 | else if (attr->form == DW_FORM_string) | |
2242 | printf (", %s", orig_data); | |
2243 | } | |
ec1b0fbb | 2244 | break; |
bcd213b2 | 2245 | |
ec1b0fbb NC |
2246 | case DW_AT_type: |
2247 | /* Recurse. */ | |
bcd213b2 NC |
2248 | { |
2249 | abbrev_entry * type_abbrev; | |
2250 | unsigned char * type_data; | |
2251 | unsigned long type_cu_offset; | |
2252 | ||
2253 | type_abbrev = get_type_abbrev_from_form (attr->form, | |
2254 | uvalue, | |
2255 | cu_offset, | |
2256 | section, | |
2257 | NULL /* abbrev num return */, | |
2258 | & type_data, | |
2259 | & type_cu_offset); | |
2260 | if (type_abbrev == NULL) | |
2261 | break; | |
2262 | ||
2263 | get_type_signedness (type_abbrev, section, type_data, end, type_cu_offset, | |
2264 | pointer_size, offset_size, dwarf_version, | |
2265 | is_signed, nesting + 1); | |
2266 | } | |
ec1b0fbb NC |
2267 | break; |
2268 | ||
2269 | case DW_AT_encoding: | |
2270 | /* Determine signness. */ | |
2271 | switch (uvalue) | |
2272 | { | |
2273 | case DW_ATE_address: | |
2274 | /* FIXME - some architectures have signed addresses. */ | |
2275 | case DW_ATE_boolean: | |
2276 | case DW_ATE_unsigned: | |
2277 | case DW_ATE_unsigned_char: | |
2278 | case DW_ATE_unsigned_fixed: | |
2279 | * is_signed = FALSE; | |
2280 | break; | |
2281 | ||
2282 | default: | |
2283 | case DW_ATE_complex_float: | |
2284 | case DW_ATE_float: | |
2285 | case DW_ATE_signed: | |
2286 | case DW_ATE_signed_char: | |
2287 | case DW_ATE_imaginary_float: | |
2288 | case DW_ATE_decimal_float: | |
2289 | case DW_ATE_signed_fixed: | |
2290 | * is_signed = TRUE; | |
2291 | break; | |
2292 | } | |
2293 | break; | |
2294 | } | |
2295 | } | |
2296 | } | |
2297 | ||
2298 | static void | |
2299 | read_and_print_leb128 (unsigned char * data, | |
2300 | unsigned int * bytes_read, | |
2301 | unsigned const char * end, | |
2302 | bfd_boolean is_signed) | |
2303 | { | |
cd30bcef AM |
2304 | int status; |
2305 | dwarf_vma val = read_leb128 (data, end, is_signed, bytes_read, &status); | |
2306 | if (status != 0) | |
1b513401 | 2307 | report_leb_status (status, __FILE__, __LINE__); |
ec1b0fbb | 2308 | else |
cd30bcef | 2309 | printf ("%s", dwarf_vmatoa (is_signed ? "d" : "u", val)); |
ec1b0fbb NC |
2310 | } |
2311 | ||
2312 | static void | |
2313 | display_discr_list (unsigned long form, | |
2314 | dwarf_vma uvalue, | |
2315 | unsigned char * data, | |
2316 | unsigned const char * end, | |
2317 | int level) | |
2318 | { | |
2319 | if (uvalue == 0) | |
2320 | { | |
2321 | printf ("[default]"); | |
2322 | return; | |
2323 | } | |
521d4b19 | 2324 | |
ec1b0fbb NC |
2325 | switch (form) |
2326 | { | |
2327 | case DW_FORM_block: | |
2328 | case DW_FORM_block1: | |
2329 | case DW_FORM_block2: | |
2330 | case DW_FORM_block4: | |
2331 | /* Move data pointer back to the start of the byte array. */ | |
2332 | data -= uvalue; | |
2333 | break; | |
2334 | default: | |
2335 | printf ("<corrupt>\n"); | |
2336 | warn (_("corrupt discr_list - not using a block form\n")); | |
2337 | return; | |
2338 | } | |
2339 | ||
2340 | if (uvalue < 2) | |
2341 | { | |
2342 | printf ("<corrupt>\n"); | |
2343 | warn (_("corrupt discr_list - block not long enough\n")); | |
2344 | return; | |
2345 | } | |
2346 | ||
2347 | bfd_boolean is_signed = | |
2348 | (level > 0 && level <= MAX_CU_NESTING) | |
2349 | ? level_type_signed [level - 1] : FALSE; | |
521d4b19 | 2350 | |
ec1b0fbb NC |
2351 | printf ("("); |
2352 | while (uvalue) | |
2353 | { | |
2354 | unsigned char discriminant; | |
2355 | unsigned int bytes_read; | |
2356 | ||
2357 | SAFE_BYTE_GET (discriminant, data, 1, end); | |
2358 | -- uvalue; | |
2359 | data ++; | |
2360 | ||
2361 | assert (uvalue > 0); | |
2362 | switch (discriminant) | |
2363 | { | |
2364 | case DW_DSC_label: | |
2365 | printf ("label "); | |
2366 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2367 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2368 | uvalue -= bytes_read; | |
2369 | data += bytes_read; | |
2370 | break; | |
2371 | ||
2372 | case DW_DSC_range: | |
2373 | printf ("range "); | |
2374 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2375 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2376 | uvalue -= bytes_read; | |
2377 | data += bytes_read; | |
2378 | ||
2379 | printf (".."); | |
2380 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2381 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2382 | uvalue -= bytes_read; | |
2383 | data += bytes_read; | |
2384 | break; | |
2385 | ||
2386 | default: | |
2387 | printf ("<corrupt>\n"); | |
2388 | warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"), | |
2389 | discriminant); | |
2390 | return; | |
2391 | } | |
2392 | ||
2393 | if (uvalue) | |
2394 | printf (", "); | |
2395 | } | |
2396 | ||
2397 | if (is_signed) | |
2398 | printf (")(signed)"); | |
2399 | else | |
2400 | printf (")(unsigned)"); | |
2401 | } | |
2402 | ||
19e6b90e | 2403 | static unsigned char * |
dda8d76d NC |
2404 | read_and_display_attr_value (unsigned long attribute, |
2405 | unsigned long form, | |
2406 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 2407 | unsigned char * start, |
dda8d76d NC |
2408 | unsigned char * data, |
2409 | unsigned char * end, | |
2410 | dwarf_vma cu_offset, | |
2411 | dwarf_vma pointer_size, | |
2412 | dwarf_vma offset_size, | |
2413 | int dwarf_version, | |
2414 | debug_info * debug_info_p, | |
2415 | int do_loc, | |
2416 | struct dwarf_section * section, | |
2417 | struct cu_tu_set * this_set, | |
ec1b0fbb NC |
2418 | char delimiter, |
2419 | int level) | |
19e6b90e | 2420 | { |
cd30bcef | 2421 | dwarf_signed_vma svalue; |
ec1b0fbb NC |
2422 | dwarf_vma uvalue = 0; |
2423 | unsigned char * block_start = NULL; | |
2424 | unsigned char * orig_data = data; | |
19e6b90e | 2425 | |
f41e4712 | 2426 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 2427 | { |
f41e4712 | 2428 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
2429 | return data; |
2430 | } | |
2431 | ||
521d4b19 NC |
2432 | if (do_wide && ! do_loc) |
2433 | { | |
2434 | /* PR 26847: Display the name of the form. */ | |
2435 | const char * name = get_FORM_name (form); | |
2436 | ||
2437 | /* For convenience we skip the DW_FORM_ prefix to the name. */ | |
2438 | if (name[0] == 'D') | |
2439 | name += 8; /* strlen ("DW_FORM_") */ | |
2440 | printf ("%c(%s)", delimiter, name); | |
2441 | } | |
2442 | ||
19e6b90e L |
2443 | switch (form) |
2444 | { | |
2445 | default: | |
2446 | break; | |
2447 | ||
2448 | case DW_FORM_ref_addr: | |
2449 | if (dwarf_version == 2) | |
0c588247 | 2450 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
ec47b32a | 2451 | else if (dwarf_version > 2) |
0c588247 | 2452 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 2453 | else |
ec47b32a | 2454 | error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n")); |
19e6b90e L |
2455 | break; |
2456 | ||
2457 | case DW_FORM_addr: | |
0c588247 | 2458 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
2459 | break; |
2460 | ||
2461 | case DW_FORM_strp: | |
77145576 | 2462 | case DW_FORM_line_strp: |
932fd279 | 2463 | case DW_FORM_sec_offset: |
a081f3cd JJ |
2464 | case DW_FORM_GNU_ref_alt: |
2465 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 2466 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
2467 | break; |
2468 | ||
932fd279 JJ |
2469 | case DW_FORM_flag_present: |
2470 | uvalue = 1; | |
2471 | break; | |
2472 | ||
19e6b90e L |
2473 | case DW_FORM_ref1: |
2474 | case DW_FORM_flag: | |
2475 | case DW_FORM_data1: | |
0c588247 | 2476 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
2477 | break; |
2478 | ||
2479 | case DW_FORM_ref2: | |
2480 | case DW_FORM_data2: | |
0c588247 | 2481 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
2482 | break; |
2483 | ||
2484 | case DW_FORM_ref4: | |
2485 | case DW_FORM_data4: | |
0c588247 | 2486 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
2487 | break; |
2488 | ||
2489 | case DW_FORM_sdata: | |
cd30bcef AM |
2490 | READ_SLEB (svalue, data, end); |
2491 | uvalue = svalue; | |
19e6b90e L |
2492 | break; |
2493 | ||
4723351a | 2494 | case DW_FORM_GNU_str_index: |
19e6b90e L |
2495 | case DW_FORM_ref_udata: |
2496 | case DW_FORM_udata: | |
cd30bcef AM |
2497 | case DW_FORM_GNU_addr_index: |
2498 | READ_ULEB (uvalue, data, end); | |
19e6b90e L |
2499 | break; |
2500 | ||
2501 | case DW_FORM_indirect: | |
cd30bcef | 2502 | READ_ULEB (form, data, end); |
19e6b90e | 2503 | if (!do_loc) |
ef0b5f1c | 2504 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 | 2505 | if (form == DW_FORM_implicit_const) |
cd30bcef | 2506 | READ_SLEB (implicit_const, data, end); |
ec1b0fbb NC |
2507 | return read_and_display_attr_value (attribute, form, implicit_const, |
2508 | start, data, end, | |
2509 | cu_offset, pointer_size, | |
19e6b90e | 2510 | offset_size, dwarf_version, |
ec4d4525 | 2511 | debug_info_p, do_loc, |
ec1b0fbb | 2512 | section, this_set, delimiter, level); |
19e6b90e L |
2513 | } |
2514 | ||
2515 | switch (form) | |
2516 | { | |
2517 | case DW_FORM_ref_addr: | |
2518 | if (!do_loc) | |
bcd213b2 | 2519 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2520 | break; |
2521 | ||
a081f3cd JJ |
2522 | case DW_FORM_GNU_ref_alt: |
2523 | if (!do_loc) | |
521d4b19 NC |
2524 | { |
2525 | if (do_wide) | |
2526 | /* We have already printed the form name. */ | |
2527 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); | |
2528 | else | |
2529 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x", uvalue)); | |
2530 | } | |
dda8d76d | 2531 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
2532 | break; |
2533 | ||
19e6b90e L |
2534 | case DW_FORM_ref1: |
2535 | case DW_FORM_ref2: | |
2536 | case DW_FORM_ref4: | |
2537 | case DW_FORM_ref_udata: | |
2538 | if (!do_loc) | |
ef0b5f1c | 2539 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
2540 | break; |
2541 | ||
2542 | case DW_FORM_data4: | |
2543 | case DW_FORM_addr: | |
932fd279 | 2544 | case DW_FORM_sec_offset: |
19e6b90e | 2545 | if (!do_loc) |
ef0b5f1c | 2546 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2547 | break; |
2548 | ||
932fd279 | 2549 | case DW_FORM_flag_present: |
19e6b90e L |
2550 | case DW_FORM_flag: |
2551 | case DW_FORM_data1: | |
2552 | case DW_FORM_data2: | |
2553 | case DW_FORM_sdata: | |
2554 | case DW_FORM_udata: | |
2555 | if (!do_loc) | |
ef0b5f1c | 2556 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
2557 | break; |
2558 | ||
77145576 JK |
2559 | case DW_FORM_implicit_const: |
2560 | if (!do_loc) | |
2561 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
2562 | break; | |
2563 | ||
19e6b90e L |
2564 | case DW_FORM_ref8: |
2565 | case DW_FORM_data8: | |
2bc8690c | 2566 | if (!do_loc) |
19e6b90e | 2567 | { |
74bc6052 | 2568 | dwarf_vma high_bits; |
a69c4772 | 2569 | dwarf_vma utmp; |
74bc6052 CC |
2570 | char buf[64]; |
2571 | ||
0c588247 | 2572 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
2573 | utmp = uvalue; |
2574 | if (form == DW_FORM_ref8) | |
2575 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 2576 | printf ("%c0x%s", delimiter, |
a69c4772 | 2577 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 2578 | } |
0c588247 | 2579 | |
19e6b90e L |
2580 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2581 | && num_debug_info_entries == 0) | |
2582 | { | |
2583 | if (sizeof (uvalue) == 8) | |
0c588247 | 2584 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 2585 | else |
467c65bc | 2586 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 2587 | } |
0c588247 | 2588 | |
19e6b90e L |
2589 | data += 8; |
2590 | break; | |
2591 | ||
2f6cd591 JK |
2592 | case DW_FORM_data16: |
2593 | if (!do_loc) | |
2594 | { | |
2595 | dwarf_vma left_high_bits, left_low_bits; | |
2596 | dwarf_vma right_high_bits, right_low_bits; | |
2597 | ||
2598 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
2599 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
2600 | if (byte_get == byte_get_little_endian) | |
2601 | { | |
2602 | /* Swap them. */ | |
2603 | left_high_bits ^= right_high_bits; | |
2604 | right_high_bits ^= left_high_bits; | |
2605 | left_high_bits ^= right_high_bits; | |
2606 | left_low_bits ^= right_low_bits; | |
2607 | right_low_bits ^= left_low_bits; | |
2608 | left_low_bits ^= right_low_bits; | |
2609 | } | |
2610 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
2611 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
2612 | left_high_bits, left_low_bits, right_high_bits, | |
2613 | right_low_bits); | |
2614 | } | |
2615 | data += 16; | |
2616 | break; | |
2617 | ||
19e6b90e L |
2618 | case DW_FORM_string: |
2619 | if (!do_loc) | |
ef0b5f1c | 2620 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 2621 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
2622 | break; |
2623 | ||
2624 | case DW_FORM_block: | |
932fd279 | 2625 | case DW_FORM_exprloc: |
cd30bcef AM |
2626 | READ_ULEB (uvalue, data, end); |
2627 | do_block: | |
2628 | block_start = data; | |
a1165289 NC |
2629 | if (block_start >= end) |
2630 | { | |
2631 | warn (_("Block ends prematurely\n")); | |
2632 | uvalue = 0; | |
2633 | block_start = end; | |
2634 | } | |
afc72f15 NC |
2635 | |
2636 | uvalue = check_uvalue (block_start, uvalue, end); | |
2637 | ||
19e6b90e L |
2638 | if (do_loc) |
2639 | data = block_start + uvalue; | |
2640 | else | |
ef0b5f1c | 2641 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2642 | break; |
2643 | ||
2644 | case DW_FORM_block1: | |
cd30bcef AM |
2645 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2646 | goto do_block; | |
19e6b90e L |
2647 | |
2648 | case DW_FORM_block2: | |
cd30bcef AM |
2649 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2650 | goto do_block; | |
19e6b90e L |
2651 | |
2652 | case DW_FORM_block4: | |
cd30bcef AM |
2653 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2654 | goto do_block; | |
19e6b90e L |
2655 | |
2656 | case DW_FORM_strp: | |
2657 | if (!do_loc) | |
521d4b19 NC |
2658 | { |
2659 | if (do_wide) | |
2660 | /* We have already displayed the form name. */ | |
2661 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2662 | dwarf_vmatoa ("x", uvalue), | |
2663 | fetch_indirect_string (uvalue)); | |
2664 | else | |
2665 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, | |
2666 | dwarf_vmatoa ("x", uvalue), | |
2667 | fetch_indirect_string (uvalue)); | |
2668 | } | |
19e6b90e L |
2669 | break; |
2670 | ||
77145576 JK |
2671 | case DW_FORM_line_strp: |
2672 | if (!do_loc) | |
521d4b19 NC |
2673 | { |
2674 | if (do_wide) | |
2675 | /* We have already displayed the form name. */ | |
2676 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2677 | dwarf_vmatoa ("x", uvalue), | |
2678 | fetch_indirect_line_string (uvalue)); | |
2679 | else | |
2680 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2681 | dwarf_vmatoa ("x", uvalue), | |
2682 | fetch_indirect_line_string (uvalue)); | |
2683 | } | |
77145576 JK |
2684 | break; |
2685 | ||
4723351a CC |
2686 | case DW_FORM_GNU_str_index: |
2687 | if (!do_loc) | |
b4eb7656 | 2688 | { |
d85bf2ba NC |
2689 | const char * suffix = strrchr (section->name, '.'); |
2690 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
b4eb7656 | 2691 | |
521d4b19 NC |
2692 | if (do_wide) |
2693 | /* We have already displayed the form name. */ | |
2694 | printf (_("%c(offset: 0x%s): %s"), delimiter, | |
2695 | dwarf_vmatoa ("x", uvalue), | |
2696 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2697 | else | |
2698 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, | |
2699 | dwarf_vmatoa ("x", uvalue), | |
2700 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
b4eb7656 | 2701 | } |
4723351a CC |
2702 | break; |
2703 | ||
a081f3cd JJ |
2704 | case DW_FORM_GNU_strp_alt: |
2705 | if (!do_loc) | |
dda8d76d | 2706 | { |
521d4b19 NC |
2707 | if (do_wide) |
2708 | /* We have already displayed the form name. */ | |
2709 | printf (_("%c(offset: 0x%s) %s"), delimiter, | |
2710 | dwarf_vmatoa ("x", uvalue), | |
2711 | fetch_alt_indirect_string (uvalue)); | |
2712 | else | |
2713 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2714 | dwarf_vmatoa ("x", uvalue), | |
2715 | fetch_alt_indirect_string (uvalue)); | |
dda8d76d | 2716 | } |
a081f3cd JJ |
2717 | break; |
2718 | ||
19e6b90e L |
2719 | case DW_FORM_indirect: |
2720 | /* Handled above. */ | |
2721 | break; | |
2722 | ||
2b6f5997 CC |
2723 | case DW_FORM_ref_sig8: |
2724 | if (!do_loc) | |
2725 | { | |
74bc6052 CC |
2726 | dwarf_vma high_bits; |
2727 | char buf[64]; | |
2728 | ||
0c588247 | 2729 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
521d4b19 NC |
2730 | if (do_wide) |
2731 | /* We have already displayed the form name. */ | |
2732 | printf ("%c: 0x%s", delimiter, | |
2733 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); | |
2734 | else | |
2735 | printf ("%csignature: 0x%s", delimiter, | |
2736 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); | |
2b6f5997 | 2737 | } |
74bc6052 | 2738 | data += 8; |
2b6f5997 CC |
2739 | break; |
2740 | ||
4723351a CC |
2741 | case DW_FORM_GNU_addr_index: |
2742 | if (!do_loc) | |
521d4b19 NC |
2743 | { |
2744 | if (do_wide) | |
2745 | /* We have already displayed the form name. */ | |
2746 | printf (_("%c(index: 0x%s): %s"), delimiter, | |
2747 | dwarf_vmatoa ("x", uvalue), | |
2748 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
2749 | else | |
2750 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, | |
2751 | dwarf_vmatoa ("x", uvalue), | |
2752 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
2753 | } | |
4723351a CC |
2754 | break; |
2755 | ||
19e6b90e L |
2756 | default: |
2757 | warn (_("Unrecognized form: %lu\n"), form); | |
2758 | break; | |
2759 | } | |
2760 | ||
19e6b90e | 2761 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2762 | && num_debug_info_entries == 0 |
2763 | && debug_info_p != NULL) | |
19e6b90e L |
2764 | { |
2765 | switch (attribute) | |
2766 | { | |
2767 | case DW_AT_frame_base: | |
2768 | have_frame_base = 1; | |
1a0670f3 | 2769 | /* Fall through. */ |
19e6b90e | 2770 | case DW_AT_location: |
9f272209 | 2771 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2772 | case DW_AT_string_length: |
2773 | case DW_AT_return_addr: | |
19e6b90e L |
2774 | case DW_AT_data_member_location: |
2775 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2776 | case DW_AT_segment: |
2777 | case DW_AT_static_link: | |
2778 | case DW_AT_use_location: | |
bc0a77d2 | 2779 | case DW_AT_call_value: |
629e7ca8 | 2780 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2781 | case DW_AT_call_data_value: |
629e7ca8 | 2782 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2783 | case DW_AT_call_target: |
629e7ca8 | 2784 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2785 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2786 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2787 | if ((dwarf_version < 4 |
212b6063 | 2788 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2789 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2790 | { |
2791 | /* Process location list. */ | |
91d6fa6a | 2792 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2793 | unsigned int num = debug_info_p->num_loc_offsets; |
2794 | ||
91d6fa6a | 2795 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2796 | { |
91d6fa6a | 2797 | lmax += 1024; |
467c65bc | 2798 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2799 | xcrealloc (debug_info_p->loc_offsets, |
2800 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2801 | debug_info_p->loc_views = (dwarf_vma *) |
2802 | xcrealloc (debug_info_p->loc_views, | |
2803 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2804 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2805 | xcrealloc (debug_info_p->have_frame_base, |
2806 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2807 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2808 | } |
341f9135 | 2809 | if (this_set != NULL) |
b4eb7656 | 2810 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2811 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2812 | if (attribute != DW_AT_GNU_locviews) |
2813 | { | |
a7504f87 NC |
2814 | /* Corrupt DWARF info can produce more offsets than views. |
2815 | See PR 23062 for an example. */ | |
2816 | if (debug_info_p->num_loc_offsets | |
2817 | > debug_info_p->num_loc_views) | |
2818 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2819 | else | |
2820 | { | |
2821 | debug_info_p->loc_offsets [num] = uvalue; | |
2822 | debug_info_p->num_loc_offsets++; | |
2823 | } | |
9f272209 AO |
2824 | } |
2825 | else | |
2826 | { | |
2827 | assert (debug_info_p->num_loc_views <= num); | |
2828 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2829 | if (num > debug_info_p->num_loc_offsets) |
2830 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2831 | else | |
2832 | { | |
2833 | debug_info_p->loc_views [num] = uvalue; | |
2834 | debug_info_p->num_loc_views++; | |
2835 | } | |
9f272209 | 2836 | } |
19e6b90e L |
2837 | } |
2838 | break; | |
e2a0d921 | 2839 | |
19e6b90e L |
2840 | case DW_AT_low_pc: |
2841 | if (need_base_address) | |
2842 | debug_info_p->base_address = uvalue; | |
2843 | break; | |
2844 | ||
4723351a | 2845 | case DW_AT_GNU_addr_base: |
b4eb7656 | 2846 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2847 | break; |
2848 | ||
2849 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2850 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2851 | break; |
2852 | ||
19e6b90e | 2853 | case DW_AT_ranges: |
b4eb7656 | 2854 | if ((dwarf_version < 4 |
212b6063 | 2855 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2856 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2857 | { |
2858 | /* Process range list. */ | |
91d6fa6a | 2859 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2860 | unsigned int num = debug_info_p->num_range_lists; |
2861 | ||
91d6fa6a | 2862 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2863 | { |
91d6fa6a | 2864 | lmax += 1024; |
467c65bc | 2865 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2866 | xcrealloc (debug_info_p->range_lists, |
2867 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2868 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2869 | } |
2870 | debug_info_p->range_lists [num] = uvalue; | |
2871 | debug_info_p->num_range_lists++; | |
2872 | } | |
2873 | break; | |
2874 | ||
d85bf2ba NC |
2875 | case DW_AT_GNU_dwo_name: |
2876 | case DW_AT_dwo_name: | |
2877 | if (need_dwo_info) | |
2878 | switch (form) | |
2879 | { | |
2880 | case DW_FORM_strp: | |
50ea0877 | 2881 | add_dwo_name ((const char *) fetch_indirect_string (uvalue), cu_offset); |
d85bf2ba | 2882 | break; |
5568cc9e | 2883 | case DW_FORM_GNU_strp_alt: |
50ea0877 | 2884 | add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue), cu_offset); |
5568cc9e | 2885 | break; |
d85bf2ba | 2886 | case DW_FORM_GNU_str_index: |
50ea0877 | 2887 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, FALSE), cu_offset); |
d85bf2ba NC |
2888 | break; |
2889 | case DW_FORM_string: | |
50ea0877 | 2890 | add_dwo_name ((const char *) orig_data, cu_offset); |
d85bf2ba NC |
2891 | break; |
2892 | default: | |
2893 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2894 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2895 | break; |
2896 | } | |
2897 | break; | |
521d4b19 | 2898 | |
d85bf2ba NC |
2899 | case DW_AT_comp_dir: |
2900 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2901 | if (need_dwo_info) | |
2902 | switch (form) | |
2903 | { | |
2904 | case DW_FORM_strp: | |
50ea0877 | 2905 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue), cu_offset); |
d85bf2ba | 2906 | break; |
5568cc9e | 2907 | case DW_FORM_GNU_strp_alt: |
50ea0877 | 2908 | add_dwo_dir (fetch_alt_indirect_string (uvalue), cu_offset); |
5568cc9e | 2909 | break; |
d85bf2ba | 2910 | case DW_FORM_line_strp: |
50ea0877 | 2911 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue), cu_offset); |
d85bf2ba NC |
2912 | break; |
2913 | case DW_FORM_GNU_str_index: | |
50ea0877 | 2914 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, FALSE), cu_offset); |
d85bf2ba NC |
2915 | break; |
2916 | case DW_FORM_string: | |
50ea0877 | 2917 | add_dwo_dir ((const char *) orig_data, cu_offset); |
d85bf2ba NC |
2918 | break; |
2919 | default: | |
2920 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2921 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2922 | break; |
2923 | } | |
2924 | break; | |
521d4b19 | 2925 | |
d85bf2ba NC |
2926 | case DW_AT_GNU_dwo_id: |
2927 | if (need_dwo_info) | |
2928 | switch (form) | |
2929 | { | |
2930 | case DW_FORM_data8: | |
24841daa | 2931 | /* FIXME: Record the length of the ID as well ? */ |
50ea0877 | 2932 | add_dwo_id ((const char *) (data - 8), cu_offset); |
d85bf2ba NC |
2933 | break; |
2934 | default: | |
2935 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2936 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2937 | break; |
2938 | } | |
2939 | break; | |
521d4b19 | 2940 | |
19e6b90e L |
2941 | default: |
2942 | break; | |
2943 | } | |
2944 | } | |
2945 | ||
4ccf1e31 | 2946 | if (do_loc || attribute == 0) |
19e6b90e L |
2947 | return data; |
2948 | ||
ec4d4525 | 2949 | /* For some attributes we can display further information. */ |
19e6b90e L |
2950 | switch (attribute) |
2951 | { | |
ec1b0fbb | 2952 | case DW_AT_type: |
b3fe587e AM |
2953 | if (level >= 0 && level < MAX_CU_NESTING |
2954 | && uvalue < (size_t) (end - start)) | |
ec1b0fbb NC |
2955 | { |
2956 | bfd_boolean is_signed = FALSE; | |
bcd213b2 NC |
2957 | abbrev_entry * type_abbrev; |
2958 | unsigned char * type_data; | |
2959 | unsigned long type_cu_offset; | |
521d4b19 | 2960 | |
bcd213b2 NC |
2961 | type_abbrev = get_type_abbrev_from_form (form, uvalue, cu_offset, |
2962 | section, NULL, & type_data, & type_cu_offset); | |
2963 | if (type_abbrev != NULL) | |
2964 | { | |
2965 | get_type_signedness (type_abbrev, section, type_data, end, type_cu_offset, | |
2966 | pointer_size, offset_size, dwarf_version, | |
2967 | & is_signed, 0); | |
2968 | } | |
ec1b0fbb NC |
2969 | level_type_signed[level] = is_signed; |
2970 | } | |
2971 | break; | |
521d4b19 | 2972 | |
19e6b90e | 2973 | case DW_AT_inline: |
2e9e81a8 | 2974 | printf ("\t"); |
19e6b90e L |
2975 | switch (uvalue) |
2976 | { | |
2977 | case DW_INL_not_inlined: | |
2978 | printf (_("(not inlined)")); | |
2979 | break; | |
2980 | case DW_INL_inlined: | |
2981 | printf (_("(inlined)")); | |
2982 | break; | |
2983 | case DW_INL_declared_not_inlined: | |
2984 | printf (_("(declared as inline but ignored)")); | |
2985 | break; | |
2986 | case DW_INL_declared_inlined: | |
2987 | printf (_("(declared as inline and inlined)")); | |
2988 | break; | |
2989 | default: | |
47704ddf KT |
2990 | printf (_(" (Unknown inline attribute value: %s)"), |
2991 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
2992 | break; |
2993 | } | |
2994 | break; | |
2995 | ||
2996 | case DW_AT_language: | |
2e9e81a8 | 2997 | printf ("\t"); |
19e6b90e L |
2998 | switch (uvalue) |
2999 | { | |
4b78141a | 3000 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 3001 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
3002 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
3003 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 3004 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
3005 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
3006 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
3007 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
3008 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 3009 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 3010 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 3011 | /* DWARF 2.1 values. */ |
4b78141a | 3012 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
3013 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
3014 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
3015 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
3016 | /* DWARF 3 values. */ |
3017 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
3018 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
3019 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
3020 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
3021 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
3022 | /* DWARF 4 values. */ |
3023 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 3024 | /* DWARF 5 values. */ |
2008a0db | 3025 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 3026 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
3027 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
3028 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
3029 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 3030 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
3031 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
3032 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 3033 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
3034 | case DW_LANG_Swift: printf ("(Swift)"); break; |
3035 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
3036 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 3037 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
3038 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
3039 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 3040 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
3041 | /* MIPS extension. */ |
3042 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
3043 | /* UPC extension. */ | |
3044 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
3045 | default: | |
4b78141a | 3046 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 3047 | printf (_("(implementation defined: %s)"), |
467c65bc | 3048 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 3049 | else |
9cf03b7e | 3050 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
3051 | break; |
3052 | } | |
3053 | break; | |
3054 | ||
3055 | case DW_AT_encoding: | |
2e9e81a8 | 3056 | printf ("\t"); |
19e6b90e L |
3057 | switch (uvalue) |
3058 | { | |
3059 | case DW_ATE_void: printf ("(void)"); break; | |
3060 | case DW_ATE_address: printf ("(machine address)"); break; | |
3061 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
3062 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
3063 | case DW_ATE_float: printf ("(float)"); break; | |
3064 | case DW_ATE_signed: printf ("(signed)"); break; | |
3065 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
3066 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
3067 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 3068 | /* DWARF 2.1 values: */ |
19e6b90e L |
3069 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
3070 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
3071 | /* DWARF 3 values: */ |
3072 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
3073 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
3074 | case DW_ATE_edited: printf ("(edited)"); break; | |
3075 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
3076 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
3077 | /* DWARF 4 values: */ |
3078 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
3079 | /* DWARF 5 values: */ | |
3080 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
3081 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
3082 | ||
e2a0d921 NC |
3083 | /* HP extensions: */ |
3084 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
3085 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
3086 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
3087 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
3088 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
3089 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
3090 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
3091 | ||
19e6b90e L |
3092 | default: |
3093 | if (uvalue >= DW_ATE_lo_user | |
3094 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 3095 | printf (_("(user defined type)")); |
19e6b90e | 3096 | else |
9cf03b7e | 3097 | printf (_("(unknown type)")); |
19e6b90e L |
3098 | break; |
3099 | } | |
3100 | break; | |
3101 | ||
3102 | case DW_AT_accessibility: | |
2e9e81a8 | 3103 | printf ("\t"); |
19e6b90e L |
3104 | switch (uvalue) |
3105 | { | |
3106 | case DW_ACCESS_public: printf ("(public)"); break; | |
3107 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
3108 | case DW_ACCESS_private: printf ("(private)"); break; | |
3109 | default: | |
9cf03b7e | 3110 | printf (_("(unknown accessibility)")); |
19e6b90e L |
3111 | break; |
3112 | } | |
3113 | break; | |
3114 | ||
3115 | case DW_AT_visibility: | |
2e9e81a8 | 3116 | printf ("\t"); |
19e6b90e L |
3117 | switch (uvalue) |
3118 | { | |
3119 | case DW_VIS_local: printf ("(local)"); break; | |
3120 | case DW_VIS_exported: printf ("(exported)"); break; | |
3121 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 3122 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
3123 | } |
3124 | break; | |
3125 | ||
04914e37 NC |
3126 | case DW_AT_endianity: |
3127 | printf ("\t"); | |
3128 | switch (uvalue) | |
3129 | { | |
3130 | case DW_END_default: printf ("(default)"); break; | |
3131 | case DW_END_big: printf ("(big)"); break; | |
3132 | case DW_END_little: printf ("(little)"); break; | |
3133 | default: | |
3134 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
3135 | printf (_("(user specified)")); | |
3136 | else | |
3137 | printf (_("(unknown endianity)")); | |
3138 | break; | |
3139 | } | |
3140 | break; | |
3141 | ||
19e6b90e | 3142 | case DW_AT_virtuality: |
2e9e81a8 | 3143 | printf ("\t"); |
19e6b90e L |
3144 | switch (uvalue) |
3145 | { | |
3146 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
3147 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
3148 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 3149 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
3150 | } |
3151 | break; | |
3152 | ||
3153 | case DW_AT_identifier_case: | |
2e9e81a8 | 3154 | printf ("\t"); |
19e6b90e L |
3155 | switch (uvalue) |
3156 | { | |
3157 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
3158 | case DW_ID_up_case: printf ("(up_case)"); break; | |
3159 | case DW_ID_down_case: printf ("(down_case)"); break; | |
3160 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 3161 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
3162 | } |
3163 | break; | |
3164 | ||
3165 | case DW_AT_calling_convention: | |
2e9e81a8 | 3166 | printf ("\t"); |
19e6b90e L |
3167 | switch (uvalue) |
3168 | { | |
3169 | case DW_CC_normal: printf ("(normal)"); break; | |
3170 | case DW_CC_program: printf ("(program)"); break; | |
3171 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
3172 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
3173 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
3174 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
3175 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
3176 | default: |
3177 | if (uvalue >= DW_CC_lo_user | |
3178 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 3179 | printf (_("(user defined)")); |
19e6b90e | 3180 | else |
9cf03b7e | 3181 | printf (_("(unknown convention)")); |
19e6b90e L |
3182 | } |
3183 | break; | |
3184 | ||
3185 | case DW_AT_ordering: | |
2e9e81a8 | 3186 | printf ("\t"); |
19e6b90e L |
3187 | switch (uvalue) |
3188 | { | |
04914e37 | 3189 | case 255: |
9cf03b7e | 3190 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
3191 | case 0: printf ("(row major)"); break; |
3192 | case 1: printf ("(column major)"); break; | |
3193 | } | |
3194 | break; | |
3195 | ||
04914e37 NC |
3196 | case DW_AT_decimal_sign: |
3197 | printf ("\t"); | |
3198 | switch (uvalue) | |
3199 | { | |
3200 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
3201 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
3202 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
3203 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
3204 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
3205 | default: printf (_("(unrecognised)")); break; | |
3206 | } | |
3207 | break; | |
3208 | ||
3209 | case DW_AT_defaulted: | |
3210 | printf ("\t"); | |
3211 | switch (uvalue) | |
3212 | { | |
3213 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
3214 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
3215 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
3216 | default: printf (_("(unrecognised)")); break; | |
3217 | } | |
3218 | break; | |
3219 | ||
3220 | case DW_AT_discr_list: | |
3221 | printf ("\t"); | |
ec1b0fbb | 3222 | display_discr_list (form, uvalue, data, end, level); |
04914e37 | 3223 | break; |
521d4b19 | 3224 | |
19e6b90e L |
3225 | case DW_AT_frame_base: |
3226 | have_frame_base = 1; | |
1a0670f3 | 3227 | /* Fall through. */ |
19e6b90e | 3228 | case DW_AT_location: |
e2a0d921 NC |
3229 | case DW_AT_string_length: |
3230 | case DW_AT_return_addr: | |
19e6b90e L |
3231 | case DW_AT_data_member_location: |
3232 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
3233 | case DW_AT_segment: |
3234 | case DW_AT_static_link: | |
3235 | case DW_AT_use_location: | |
bc0a77d2 | 3236 | case DW_AT_call_value: |
629e7ca8 | 3237 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 3238 | case DW_AT_call_data_value: |
629e7ca8 | 3239 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 3240 | case DW_AT_call_target: |
629e7ca8 | 3241 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 3242 | case DW_AT_call_target_clobbered: |
629e7ca8 | 3243 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 3244 | if ((dwarf_version < 4 |
b4eb7656 | 3245 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 3246 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 3247 | printf (_(" (location list)")); |
e2a0d921 | 3248 | /* Fall through. */ |
19e6b90e L |
3249 | case DW_AT_allocated: |
3250 | case DW_AT_associated: | |
3251 | case DW_AT_data_location: | |
3252 | case DW_AT_stride: | |
3253 | case DW_AT_upper_bound: | |
cecf136e | 3254 | case DW_AT_lower_bound: |
19e6b90e L |
3255 | if (block_start) |
3256 | { | |
3257 | int need_frame_base; | |
3258 | ||
2e9e81a8 | 3259 | printf ("\t("); |
19e6b90e L |
3260 | need_frame_base = decode_location_expression (block_start, |
3261 | pointer_size, | |
b7807392 JJ |
3262 | offset_size, |
3263 | dwarf_version, | |
19e6b90e | 3264 | uvalue, |
f1c4cc75 | 3265 | cu_offset, section); |
19e6b90e L |
3266 | printf (")"); |
3267 | if (need_frame_base && !have_frame_base) | |
3268 | printf (_(" [without DW_AT_frame_base]")); | |
3269 | } | |
19e6b90e L |
3270 | break; |
3271 | ||
c54207d3 NC |
3272 | case DW_AT_data_bit_offset: |
3273 | case DW_AT_byte_size: | |
3274 | case DW_AT_bit_size: | |
3275 | case DW_AT_string_length_byte_size: | |
3276 | case DW_AT_string_length_bit_size: | |
3277 | case DW_AT_bit_stride: | |
3278 | if (form == DW_FORM_exprloc) | |
3279 | { | |
3280 | printf ("\t("); | |
3281 | (void) decode_location_expression (block_start, pointer_size, | |
3282 | offset_size, dwarf_version, | |
3283 | uvalue, cu_offset, section); | |
3284 | printf (")"); | |
3285 | } | |
3286 | break; | |
3287 | ||
ec4d4525 NC |
3288 | case DW_AT_import: |
3289 | { | |
bcd213b2 NC |
3290 | unsigned long abbrev_number; |
3291 | abbrev_entry *entry; | |
2b6f5997 | 3292 | |
bcd213b2 NC |
3293 | entry = get_type_abbrev_from_form (form, uvalue, cu_offset, |
3294 | section, & abbrev_number, NULL, NULL); | |
3295 | if (entry == NULL) | |
3296 | { | |
3297 | if (form != DW_FORM_GNU_ref_alt) | |
3298 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), | |
3299 | dwarf_vmatoa ("x", uvalue), | |
3300 | (unsigned long) (orig_data - section->start)); | |
3301 | } | |
6e3d6dc1 NC |
3302 | else |
3303 | { | |
2e9e81a8 | 3304 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
bcd213b2 | 3305 | printf (" (%s)", get_TAG_name (entry->tag)); |
6e3d6dc1 NC |
3306 | printf ("]"); |
3307 | } | |
ec4d4525 NC |
3308 | } |
3309 | break; | |
3310 | ||
19e6b90e L |
3311 | default: |
3312 | break; | |
3313 | } | |
3314 | ||
3315 | return data; | |
3316 | } | |
3317 | ||
19e6b90e | 3318 | static unsigned char * |
dda8d76d NC |
3319 | read_and_display_attr (unsigned long attribute, |
3320 | unsigned long form, | |
3321 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 3322 | unsigned char * start, |
dda8d76d NC |
3323 | unsigned char * data, |
3324 | unsigned char * end, | |
3325 | dwarf_vma cu_offset, | |
3326 | dwarf_vma pointer_size, | |
3327 | dwarf_vma offset_size, | |
3328 | int dwarf_version, | |
3329 | debug_info * debug_info_p, | |
3330 | int do_loc, | |
3331 | struct dwarf_section * section, | |
ec1b0fbb NC |
3332 | struct cu_tu_set * this_set, |
3333 | int level) | |
19e6b90e L |
3334 | { |
3335 | if (!do_loc) | |
750f03b7 | 3336 | printf (" %-18s:", get_AT_name (attribute)); |
ec1b0fbb NC |
3337 | data = read_and_display_attr_value (attribute, form, implicit_const, |
3338 | start, data, end, | |
f6f0e17b | 3339 | cu_offset, pointer_size, offset_size, |
19e6b90e | 3340 | dwarf_version, debug_info_p, |
ec1b0fbb | 3341 | do_loc, section, this_set, ' ', level); |
19e6b90e L |
3342 | if (!do_loc) |
3343 | printf ("\n"); | |
3344 | return data; | |
3345 | } | |
3346 | ||
dda8d76d | 3347 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
3348 | following debug links, then attempt to load the requested section |
3349 | from one of the separate debug info files. */ | |
dda8d76d NC |
3350 | |
3351 | static bfd_boolean | |
3352 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, | |
24841daa | 3353 | void * handle) |
dda8d76d | 3354 | { |
24841daa | 3355 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 3356 | { |
24841daa NC |
3357 | if (debug_displays[sec_enum].section.filename == NULL) |
3358 | { | |
3359 | /* See if we can associate a filename with this section. */ | |
3360 | separate_info * i; | |
3361 | ||
3362 | for (i = first_separate_info; i != NULL; i = i->next) | |
3363 | if (i->handle == handle) | |
3364 | { | |
3365 | debug_displays[sec_enum].section.filename = i->filename; | |
3366 | break; | |
3367 | } | |
3368 | } | |
3369 | ||
dda8d76d NC |
3370 | return TRUE; |
3371 | } | |
3372 | ||
24841daa NC |
3373 | if (do_follow_links) |
3374 | { | |
3375 | separate_info * i; | |
3376 | ||
3377 | for (i = first_separate_info; i != NULL; i = i->next) | |
3378 | { | |
3379 | if (load_debug_section (sec_enum, i->handle)) | |
3380 | { | |
3381 | debug_displays[sec_enum].section.filename = i->filename; | |
3382 | ||
3383 | /* FIXME: We should check to see if any of the remaining debug info | |
3384 | files also contain this section, and, umm, do something about it. */ | |
3385 | return TRUE; | |
3386 | } | |
3387 | } | |
3388 | } | |
dda8d76d NC |
3389 | |
3390 | return FALSE; | |
3391 | } | |
3392 | ||
3393 | static void | |
3394 | introduce (struct dwarf_section * section, bfd_boolean raw) | |
3395 | { | |
3396 | if (raw) | |
3397 | { | |
3398 | if (do_follow_links && section->filename) | |
3399 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
3400 | section->name, section->filename); | |
3401 | else | |
3402 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
3403 | } | |
3404 | else | |
3405 | { | |
3406 | if (do_follow_links && section->filename) | |
3407 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
3408 | section->name, section->filename); | |
3409 | else | |
3410 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3411 | } | |
3412 | } | |
521d4b19 | 3413 | |
d85bf2ba NC |
3414 | /* Process the contents of a .debug_info section. |
3415 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
3416 | and we do not want to display anything to the user. | |
3417 | If do_types is TRUE, we are processing a .debug_types section instead of | |
3418 | a .debug_info section. | |
3419 | The information displayed is restricted by the values in DWARF_START_DIE | |
3420 | and DWARF_CUTOFF_LEVEL. | |
3421 | Returns TRUE upon success. Otherwise an error or warning message is | |
3422 | printed and FALSE is returned. */ | |
19e6b90e | 3423 | |
d85bf2ba NC |
3424 | static bfd_boolean |
3425 | process_debug_info (struct dwarf_section * section, | |
3426 | void * file, | |
3427 | enum dwarf_section_display_enum abbrev_sec, | |
3428 | bfd_boolean do_loc, | |
3429 | bfd_boolean do_types) | |
19e6b90e L |
3430 | { |
3431 | unsigned char *start = section->start; | |
3432 | unsigned char *end = start + section->size; | |
3433 | unsigned char *section_begin; | |
3434 | unsigned int unit; | |
3435 | unsigned int num_units = 0; | |
3436 | ||
3437 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3438 | && num_debug_info_entries == 0 |
3439 | && ! do_types) | |
19e6b90e | 3440 | { |
767221a9 | 3441 | dwarf_vma length; |
19e6b90e L |
3442 | |
3443 | /* First scan the section to get the number of comp units. */ | |
3444 | for (section_begin = start, num_units = 0; section_begin < end; | |
3445 | num_units ++) | |
3446 | { | |
3447 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
3448 | will be the length. For a 64-bit DWARF section, it'll be | |
3449 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 3450 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
3451 | |
3452 | if (length == 0xffffffff) | |
3453 | { | |
0c588247 | 3454 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
3455 | section_begin += length + 12; |
3456 | } | |
ec4d4525 NC |
3457 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
3458 | { | |
767221a9 NC |
3459 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
3460 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3461 | return FALSE; |
ec4d4525 | 3462 | } |
19e6b90e L |
3463 | else |
3464 | section_begin += length + 4; | |
aca88567 NC |
3465 | |
3466 | /* Negative values are illegal, they may even cause infinite | |
3467 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
3468 | relocations to an object file, or if the file is corrupt. */ |
3469 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 3470 | { |
767221a9 NC |
3471 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
3472 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3473 | return FALSE; |
aca88567 | 3474 | } |
19e6b90e L |
3475 | } |
3476 | ||
3477 | if (num_units == 0) | |
3478 | { | |
f41e4712 | 3479 | error (_("No comp units in %s section ?\n"), section->name); |
d85bf2ba | 3480 | return FALSE; |
19e6b90e L |
3481 | } |
3482 | ||
3483 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 3484 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 3485 | sizeof (* debug_information)); |
19e6b90e L |
3486 | if (debug_information == NULL) |
3487 | { | |
f41e4712 | 3488 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 3489 | num_units); |
82b1b41b | 3490 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
d85bf2ba | 3491 | return FALSE; |
19e6b90e | 3492 | } |
d85bf2ba | 3493 | |
03a91817 NC |
3494 | /* PR 17531: file: 92ca3797. |
3495 | We cannot rely upon the debug_information array being initialised | |
3496 | before it is used. A corrupt file could easily contain references | |
3497 | to a unit for which information has not been made available. So | |
3498 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
3499 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
3500 | ||
82b1b41b | 3501 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
3502 | } |
3503 | ||
3504 | if (!do_loc) | |
3505 | { | |
dda8d76d NC |
3506 | load_debug_section_with_follow (str, file); |
3507 | load_debug_section_with_follow (line_str, file); | |
3508 | load_debug_section_with_follow (str_dwo, file); | |
3509 | load_debug_section_with_follow (str_index, file); | |
3510 | load_debug_section_with_follow (str_index_dwo, file); | |
3511 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e | 3512 | } |
521d4b19 | 3513 | |
dda8d76d | 3514 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 3515 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
3516 | { |
3517 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 3518 | debug_displays [abbrev_sec].section.uncompressed_name); |
d85bf2ba | 3519 | return FALSE; |
19e6b90e L |
3520 | } |
3521 | ||
dda8d76d NC |
3522 | if (!do_loc && dwarf_start_die == 0) |
3523 | introduce (section, FALSE); | |
bcd213b2 NC |
3524 | |
3525 | free_all_abbrevs (); | |
3526 | free (cu_abbrev_map); | |
3527 | cu_abbrev_map = NULL; | |
3528 | next_free_abbrev_map_entry = 0; | |
521d4b19 | 3529 | |
bcd213b2 NC |
3530 | /* In order to be able to resolve DW_FORM_ref_attr forms we need |
3531 | to load *all* of the abbrevs for all CUs in this .debug_info | |
3532 | section. This does effectively mean that we (partially) read | |
3533 | every CU header twice. */ | |
3534 | for (section_begin = start; start < end;) | |
3535 | { | |
3536 | DWARF2_Internal_CompUnit compunit; | |
3537 | unsigned char * hdrptr; | |
76868f36 L |
3538 | dwarf_vma abbrev_base; |
3539 | size_t abbrev_size; | |
bcd213b2 NC |
3540 | dwarf_vma cu_offset; |
3541 | unsigned int offset_size; | |
3542 | unsigned int initial_length_size; | |
3543 | struct cu_tu_set * this_set; | |
3544 | abbrev_list * list; | |
3545 | ||
3546 | hdrptr = start; | |
3547 | ||
3548 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); | |
3549 | ||
3550 | if (compunit.cu_length == 0xffffffff) | |
3551 | { | |
3552 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); | |
3553 | offset_size = 8; | |
3554 | initial_length_size = 12; | |
3555 | } | |
3556 | else | |
3557 | { | |
3558 | offset_size = 4; | |
3559 | initial_length_size = 4; | |
3560 | } | |
3561 | ||
3562 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); | |
3563 | ||
3564 | cu_offset = start - section_begin; | |
3565 | ||
3566 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); | |
3567 | ||
3568 | if (compunit.cu_version < 5) | |
3569 | { | |
3570 | compunit.cu_unit_type = DW_UT_compile; | |
3571 | /* Initialize it due to a false compiler warning. */ | |
3572 | compunit.cu_pointer_size = -1; | |
3573 | } | |
3574 | else | |
3575 | { | |
3576 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3577 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3578 | ||
3579 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3580 | } | |
3581 | ||
3582 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); | |
3583 | ||
76868f36 L |
3584 | if (this_set == NULL) |
3585 | { | |
3586 | abbrev_base = 0; | |
3587 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3588 | } | |
3589 | else | |
3590 | { | |
3591 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3592 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3593 | } | |
3594 | ||
3595 | list = find_abbrev_list_by_abbrev_offset (abbrev_base, | |
3596 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3597 | if (list == NULL) |
3598 | { | |
bcd213b2 NC |
3599 | unsigned char * next; |
3600 | ||
76868f36 L |
3601 | list = new_abbrev_list (abbrev_base, |
3602 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3603 | next = process_abbrev_set |
3604 | (((unsigned char *) debug_displays [abbrev_sec].section.start | |
3605 | + abbrev_base + compunit.cu_abbrev_offset), | |
3606 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3607 | + abbrev_base + abbrev_size), | |
3608 | list); | |
3609 | list->start_of_next_abbrevs = next; | |
3610 | } | |
521d4b19 | 3611 | |
bcd213b2 NC |
3612 | start = section_begin + cu_offset + compunit.cu_length |
3613 | + initial_length_size; | |
3614 | record_abbrev_list_for_cu (cu_offset, start - section_begin, list); | |
3615 | } | |
3616 | ||
3617 | for (start = section_begin, unit = 0; start < end; unit++) | |
19e6b90e L |
3618 | { |
3619 | DWARF2_Internal_CompUnit compunit; | |
3620 | unsigned char *hdrptr; | |
19e6b90e | 3621 | unsigned char *tags; |
fd2f0033 | 3622 | int level, last_level, saved_level; |
467c65bc | 3623 | dwarf_vma cu_offset; |
e98fdf1a | 3624 | unsigned long sec_off; |
bf5117e3 | 3625 | unsigned int offset_size; |
19485196 | 3626 | unsigned int initial_length_size; |
74bc6052 CC |
3627 | dwarf_vma signature_high = 0; |
3628 | dwarf_vma signature_low = 0; | |
767221a9 | 3629 | dwarf_vma type_offset = 0; |
341f9135 CC |
3630 | struct cu_tu_set *this_set; |
3631 | dwarf_vma abbrev_base; | |
3632 | size_t abbrev_size; | |
bcd213b2 | 3633 | abbrev_list * list = NULL; |
19e6b90e L |
3634 | |
3635 | hdrptr = start; | |
3636 | ||
0c588247 | 3637 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
3638 | |
3639 | if (compunit.cu_length == 0xffffffff) | |
3640 | { | |
0c588247 | 3641 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
3642 | offset_size = 8; |
3643 | initial_length_size = 12; | |
3644 | } | |
3645 | else | |
3646 | { | |
3647 | offset_size = 4; | |
3648 | initial_length_size = 4; | |
3649 | } | |
3650 | ||
0c588247 | 3651 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
3652 | |
3653 | cu_offset = start - section_begin; | |
19e6b90e | 3654 | |
341f9135 CC |
3655 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3656 | ||
77145576 JK |
3657 | if (compunit.cu_version < 5) |
3658 | { | |
3659 | compunit.cu_unit_type = DW_UT_compile; | |
3660 | /* Initialize it due to a false compiler warning. */ | |
3661 | compunit.cu_pointer_size = -1; | |
3662 | } | |
3663 | else | |
3664 | { | |
3665 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3666 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3667 | ||
3668 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3669 | } | |
3670 | ||
0c588247 | 3671 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 3672 | |
341f9135 CC |
3673 | if (this_set == NULL) |
3674 | { | |
3675 | abbrev_base = 0; | |
3676 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3677 | } | |
3678 | else | |
3679 | { | |
3680 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3681 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3682 | } | |
3683 | ||
77145576 JK |
3684 | if (compunit.cu_version < 5) |
3685 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3686 | ||
f41e4712 NC |
3687 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
3688 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
3689 | { | |
3690 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
3691 | compunit.cu_pointer_size, offset_size); | |
3692 | compunit.cu_pointer_size = offset_size; | |
3693 | } | |
2b6f5997 CC |
3694 | |
3695 | if (do_types) | |
b4eb7656 | 3696 | { |
0c588247 | 3697 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 3698 | hdrptr += 8; |
0c588247 | 3699 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 3700 | } |
2b6f5997 | 3701 | |
ae7e7825 NC |
3702 | if (dwarf_start_die > (cu_offset + compunit.cu_length |
3703 | + initial_length_size)) | |
3704 | { | |
3705 | start = section_begin + cu_offset + compunit.cu_length | |
3706 | + initial_length_size; | |
3707 | continue; | |
3708 | } | |
3709 | ||
19e6b90e | 3710 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 | 3711 | && num_debug_info_entries == 0 |
c4b2f181 | 3712 | && alloc_num_debug_info_entries > unit |
2b6f5997 | 3713 | && ! do_types) |
19e6b90e L |
3714 | { |
3715 | debug_information [unit].cu_offset = cu_offset; | |
3716 | debug_information [unit].pointer_size | |
3717 | = compunit.cu_pointer_size; | |
b7807392 JJ |
3718 | debug_information [unit].offset_size = offset_size; |
3719 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 3720 | debug_information [unit].base_address = 0; |
4723351a CC |
3721 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
3722 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
3723 | debug_information [unit].loc_offsets = NULL; |
3724 | debug_information [unit].have_frame_base = NULL; | |
3725 | debug_information [unit].max_loc_offsets = 0; | |
3726 | debug_information [unit].num_loc_offsets = 0; | |
3727 | debug_information [unit].range_lists = NULL; | |
3728 | debug_information [unit].max_range_lists= 0; | |
3729 | debug_information [unit].num_range_lists = 0; | |
3730 | } | |
3731 | ||
fd2f0033 | 3732 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 3733 | { |
47704ddf KT |
3734 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3735 | dwarf_vmatoa ("x", cu_offset)); | |
3736 | printf (_(" Length: 0x%s (%s)\n"), | |
3737 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3738 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3739 | printf (_(" Version: %d\n"), compunit.cu_version); |
debd1a62 MW |
3740 | if (compunit.cu_version >= 5) |
3741 | printf (_(" Unit Type: %s (%x)\n"), | |
3742 | get_DW_UT_name (compunit.cu_unit_type) ?: "???", | |
3743 | compunit.cu_unit_type); | |
7282333f AM |
3744 | printf (_(" Abbrev Offset: 0x%s\n"), |
3745 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3746 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3747 | if (do_types) |
3748 | { | |
74bc6052 CC |
3749 | char buf[64]; |
3750 | ||
3751 | printf (_(" Signature: 0x%s\n"), | |
3752 | dwarf_vmatoa64 (signature_high, signature_low, | |
3753 | buf, sizeof (buf))); | |
3754 | printf (_(" Type Offset: 0x%s\n"), | |
3755 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3756 | } |
341f9135 CC |
3757 | if (this_set != NULL) |
3758 | { | |
3759 | dwarf_vma *offsets = this_set->section_offsets; | |
3760 | size_t *sizes = this_set->section_sizes; | |
3761 | ||
3762 | printf (_(" Section contributions:\n")); | |
3763 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3764 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3765 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3766 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3767 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3768 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3769 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3770 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3771 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3772 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3773 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3774 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3775 | } | |
19e6b90e L |
3776 | } |
3777 | ||
e98fdf1a AM |
3778 | sec_off = cu_offset + initial_length_size; |
3779 | if (sec_off + compunit.cu_length < sec_off | |
3780 | || sec_off + compunit.cu_length > section->size) | |
460c89ff | 3781 | { |
e98fdf1a AM |
3782 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
3783 | section->name, | |
3784 | (unsigned long) cu_offset, | |
19485196 NC |
3785 | dwarf_vmatoa ("x", compunit.cu_length)); |
3786 | num_units = unit; | |
3787 | break; | |
3788 | } | |
3789 | ||
460c89ff NS |
3790 | tags = hdrptr; |
3791 | start += compunit.cu_length + initial_length_size; | |
3792 | ||
77145576 | 3793 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3794 | { |
47704ddf KT |
3795 | warn (_("CU at offset %s contains corrupt or " |
3796 | "unsupported version number: %d.\n"), | |
3797 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3798 | continue; |
3799 | } | |
3800 | ||
77145576 | 3801 | if (compunit.cu_unit_type != DW_UT_compile |
ec47b32a | 3802 | && compunit.cu_unit_type != DW_UT_partial |
77145576 JK |
3803 | && compunit.cu_unit_type != DW_UT_type) |
3804 | { | |
3805 | warn (_("CU at offset %s contains corrupt or " | |
3806 | "unsupported unit type: %d.\n"), | |
3807 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3808 | continue; | |
3809 | } | |
3810 | ||
d493b283 | 3811 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 3812 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
3813 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
3814 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 3815 | (unsigned long) abbrev_size); |
b4eb7656 | 3816 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
3817 | else if ((abbrev_base + abbrev_size) |
3818 | > debug_displays [abbrev_sec].section.size) | |
3819 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
3820 | (unsigned long) abbrev_base + abbrev_size, | |
3821 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff | 3822 | else |
bcd213b2 | 3823 | { |
76868f36 L |
3824 | list = find_abbrev_list_by_abbrev_offset (abbrev_base, |
3825 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3826 | if (list == NULL) |
3827 | { | |
3828 | unsigned char * next; | |
3829 | ||
76868f36 L |
3830 | list = new_abbrev_list (abbrev_base, |
3831 | compunit.cu_abbrev_offset); | |
bcd213b2 NC |
3832 | next = process_abbrev_set |
3833 | (((unsigned char *) debug_displays [abbrev_sec].section.start | |
3834 | + abbrev_base + compunit.cu_abbrev_offset), | |
3835 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3836 | + abbrev_base + abbrev_size), | |
3837 | list); | |
3838 | list->start_of_next_abbrevs = next; | |
3839 | } | |
3840 | } | |
19e6b90e L |
3841 | |
3842 | level = 0; | |
fd2f0033 TT |
3843 | last_level = level; |
3844 | saved_level = -1; | |
19e6b90e L |
3845 | while (tags < start) |
3846 | { | |
19e6b90e | 3847 | unsigned long abbrev_number; |
ec4d4525 | 3848 | unsigned long die_offset; |
19e6b90e L |
3849 | abbrev_entry *entry; |
3850 | abbrev_attr *attr; | |
fd2f0033 | 3851 | int do_printing = 1; |
19e6b90e | 3852 | |
ec4d4525 NC |
3853 | die_offset = tags - section_begin; |
3854 | ||
cd30bcef | 3855 | READ_ULEB (abbrev_number, tags, start); |
19e6b90e | 3856 | |
eb7cc021 JK |
3857 | /* A null DIE marks the end of a list of siblings or it may also be |
3858 | a section padding. */ | |
19e6b90e L |
3859 | if (abbrev_number == 0) |
3860 | { | |
eb7cc021 JK |
3861 | /* Check if it can be a section padding for the last CU. */ |
3862 | if (level == 0 && start == end) | |
3863 | { | |
3864 | unsigned char *chk; | |
3865 | ||
3866 | for (chk = tags; chk < start; chk++) | |
3867 | if (*chk != 0) | |
3868 | break; | |
3869 | if (chk == start) | |
3870 | break; | |
3871 | } | |
3872 | ||
4337774f TT |
3873 | if (!do_loc && die_offset >= dwarf_start_die |
3874 | && (dwarf_cutoff_level == -1 | |
3875 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3876 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3877 | level, die_offset); | |
3878 | ||
19e6b90e | 3879 | --level; |
ec4d4525 NC |
3880 | if (level < 0) |
3881 | { | |
3882 | static unsigned num_bogus_warns = 0; | |
3883 | ||
3884 | if (num_bogus_warns < 3) | |
3885 | { | |
4723351a CC |
3886 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3887 | die_offset, section->name); | |
ec4d4525 NC |
3888 | num_bogus_warns ++; |
3889 | if (num_bogus_warns == 3) | |
3890 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3891 | } | |
3892 | } | |
fd2f0033 | 3893 | if (dwarf_start_die != 0 && level < saved_level) |
d85bf2ba | 3894 | return TRUE; |
19e6b90e L |
3895 | continue; |
3896 | } | |
3897 | ||
4b78141a | 3898 | if (!do_loc) |
fd2f0033 TT |
3899 | { |
3900 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
3901 | do_printing = 0; | |
3902 | else | |
3903 | { | |
3904 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
3905 | saved_level = level; | |
3906 | do_printing = (dwarf_cutoff_level == -1 | |
3907 | || level < dwarf_cutoff_level); | |
3908 | if (do_printing) | |
3909 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
3910 | level, die_offset, abbrev_number); | |
3911 | else if (dwarf_cutoff_level == -1 | |
3912 | || last_level < dwarf_cutoff_level) | |
3913 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
3914 | last_level = level; | |
3915 | } | |
3916 | } | |
cecf136e | 3917 | |
19e6b90e L |
3918 | /* Scan through the abbreviation list until we reach the |
3919 | correct entry. */ | |
bcd213b2 | 3920 | if (list == NULL) |
19e6b90e L |
3921 | continue; |
3922 | ||
bcd213b2 NC |
3923 | for (entry = list->first_abbrev; entry != NULL; entry = entry->next) |
3924 | if (entry->number == abbrev_number) | |
3925 | break; | |
3926 | ||
19e6b90e L |
3927 | if (entry == NULL) |
3928 | { | |
fd2f0033 | 3929 | if (!do_loc && do_printing) |
4b78141a NC |
3930 | { |
3931 | printf ("\n"); | |
3932 | fflush (stdout); | |
3933 | } | |
f3853b34 | 3934 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 3935 | die_offset, abbrev_number); |
d85bf2ba | 3936 | return FALSE; |
19e6b90e L |
3937 | } |
3938 | ||
fd2f0033 | 3939 | if (!do_loc && do_printing) |
cc5914eb | 3940 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 3941 | |
19e6b90e L |
3942 | switch (entry->tag) |
3943 | { | |
3944 | default: | |
3945 | need_base_address = 0; | |
3946 | break; | |
3947 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
3948 | need_base_address = 1; |
3949 | need_dwo_info = do_loc; | |
19e6b90e L |
3950 | break; |
3951 | case DW_TAG_entry_point: | |
19e6b90e L |
3952 | case DW_TAG_subprogram: |
3953 | need_base_address = 0; | |
3954 | /* Assuming that there is no DW_AT_frame_base. */ | |
3955 | have_frame_base = 0; | |
3956 | break; | |
3957 | } | |
3958 | ||
9f272209 AO |
3959 | debug_info *debug_info_p = |
3960 | (debug_information && unit < alloc_num_debug_info_entries) | |
3961 | ? debug_information + unit : NULL; | |
3962 | ||
3963 | assert (!debug_info_p | |
3964 | || (debug_info_p->num_loc_offsets | |
3965 | == debug_info_p->num_loc_views)); | |
3966 | ||
399c99f7 L |
3967 | for (attr = entry->first_attr; |
3968 | attr && attr->attribute; | |
3969 | attr = attr->next) | |
4b78141a | 3970 | { |
fd2f0033 | 3971 | if (! do_loc && do_printing) |
4b78141a | 3972 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 | 3973 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
3974 | tags = read_and_display_attr (attr->attribute, |
3975 | attr->form, | |
77145576 | 3976 | attr->implicit_const, |
ec1b0fbb | 3977 | section_begin, |
341f9135 | 3978 | tags, |
f6f0e17b | 3979 | end, |
341f9135 | 3980 | cu_offset, |
4b78141a NC |
3981 | compunit.cu_pointer_size, |
3982 | offset_size, | |
3983 | compunit.cu_version, | |
9f272209 | 3984 | debug_info_p, |
341f9135 CC |
3985 | do_loc || ! do_printing, |
3986 | section, | |
ec1b0fbb NC |
3987 | this_set, |
3988 | level); | |
4b78141a | 3989 | } |
cecf136e | 3990 | |
9f272209 AO |
3991 | /* If a locview attribute appears before a location one, |
3992 | make sure we don't associate it with an earlier | |
3993 | loclist. */ | |
3994 | if (debug_info_p) | |
3995 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
3996 | { | |
3997 | case 1: | |
3998 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
3999 | debug_info_p->num_loc_views++; | |
4000 | assert (debug_info_p->num_loc_views | |
4001 | == debug_info_p->num_loc_offsets); | |
4002 | break; | |
4003 | ||
4004 | case 0: | |
4005 | break; | |
4006 | ||
4007 | case -1: | |
4008 | warn(_("DIE has locviews without loclist\n")); | |
4009 | debug_info_p->num_loc_views--; | |
4010 | break; | |
4011 | ||
4012 | default: | |
4013 | assert (0); | |
4014 | } | |
4015 | ||
b4eb7656 AM |
4016 | if (entry->children) |
4017 | ++level; | |
4018 | } | |
19e6b90e | 4019 | } |
cecf136e | 4020 | |
19e6b90e L |
4021 | /* Set num_debug_info_entries here so that it can be used to check if |
4022 | we need to process .debug_loc and .debug_ranges sections. */ | |
4023 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
4024 | && num_debug_info_entries == 0 |
4025 | && ! do_types) | |
82b1b41b | 4026 | { |
b4eb7656 | 4027 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
4028 | num_debug_info_entries = alloc_num_debug_info_entries; |
4029 | else | |
4030 | num_debug_info_entries = num_units; | |
4031 | } | |
cecf136e | 4032 | |
19e6b90e | 4033 | if (!do_loc) |
467c65bc | 4034 | printf ("\n"); |
cecf136e | 4035 | |
d85bf2ba | 4036 | return TRUE; |
19e6b90e L |
4037 | } |
4038 | ||
4039 | /* Locate and scan the .debug_info section in the file and record the pointer | |
4040 | sizes and offsets for the compilation units in it. Usually an executable | |
4041 | will have just one pointer size, but this is not guaranteed, and so we try | |
4042 | not to make any assumptions. Returns zero upon failure, or the number of | |
4043 | compilation units upon success. */ | |
4044 | ||
4045 | static unsigned int | |
4046 | load_debug_info (void * file) | |
4047 | { | |
1febe64d | 4048 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 4049 | section then do not bother to repeat the task. */ |
cc86f28f | 4050 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
4051 | return 0; |
4052 | ||
19e6b90e L |
4053 | /* If we already have the information there is nothing else to do. */ |
4054 | if (num_debug_info_entries > 0) | |
4055 | return num_debug_info_entries; | |
4056 | ||
341f9135 | 4057 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 4058 | (void) load_cu_tu_indexes (file); |
341f9135 | 4059 | |
dda8d76d | 4060 | if (load_debug_section_with_follow (info, file) |
d85bf2ba | 4061 | && process_debug_info (&debug_displays [info].section, file, abbrev, TRUE, FALSE)) |
19e6b90e | 4062 | return num_debug_info_entries; |
82b1b41b | 4063 | |
dda8d76d | 4064 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 4065 | && process_debug_info (&debug_displays [info_dwo].section, file, |
d85bf2ba | 4066 | abbrev_dwo, TRUE, FALSE)) |
4723351a | 4067 | return num_debug_info_entries; |
1febe64d | 4068 | |
cc86f28f | 4069 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 4070 | return 0; |
19e6b90e L |
4071 | } |
4072 | ||
b40bf0a2 NC |
4073 | /* Read a DWARF .debug_line section header starting at DATA. |
4074 | Upon success returns an updated DATA pointer and the LINFO | |
4075 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
4076 | Otherwise returns NULL. */ | |
19e6b90e | 4077 | |
b40bf0a2 NC |
4078 | static unsigned char * |
4079 | read_debug_line_header (struct dwarf_section * section, | |
4080 | unsigned char * data, | |
4081 | unsigned char * end, | |
4082 | DWARF2_Internal_LineInfo * linfo, | |
4083 | unsigned char ** end_of_sequence) | |
4084 | { | |
4085 | unsigned char *hdrptr; | |
b40bf0a2 | 4086 | unsigned int initial_length_size; |
19e6b90e | 4087 | |
b40bf0a2 NC |
4088 | /* Extract information from the Line Number Program Header. |
4089 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 4090 | hdrptr = data; |
19e6b90e | 4091 | |
b40bf0a2 NC |
4092 | /* Get and check the length of the block. */ |
4093 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 4094 | |
b40bf0a2 | 4095 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
4096 | { |
4097 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 4098 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 4099 | linfo->li_offset_size = 8; |
f41e4712 NC |
4100 | initial_length_size = 12; |
4101 | } | |
4102 | else | |
4103 | { | |
77145576 | 4104 | linfo->li_offset_size = 4; |
f41e4712 NC |
4105 | initial_length_size = 4; |
4106 | } | |
19e6b90e | 4107 | |
b40bf0a2 | 4108 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 4109 | { |
8fcc61b4 NC |
4110 | /* If the length field has a relocation against it, then we should |
4111 | not complain if it is inaccurate (and probably negative). This | |
4112 | happens in object files when the .debug_line section is actually | |
4113 | comprised of several different .debug_line.* sections, (some of | |
4114 | which may be removed by linker garbage collection), and a relocation | |
4115 | is used to compute the correct length once that is done. */ | |
77145576 | 4116 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 4117 | { |
8fcc61b4 | 4118 | linfo->li_length = (end - data) - initial_length_size; |
b40bf0a2 NC |
4119 | } |
4120 | else | |
4121 | { | |
8fcc61b4 NC |
4122 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
4123 | (long) linfo->li_length); | |
b40bf0a2 NC |
4124 | return NULL; |
4125 | } | |
f41e4712 | 4126 | } |
19e6b90e | 4127 | |
b40bf0a2 NC |
4128 | /* Get and check the version number. */ |
4129 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
4130 | ||
4131 | if (linfo->li_version != 2 | |
4132 | && linfo->li_version != 3 | |
77145576 JK |
4133 | && linfo->li_version != 4 |
4134 | && linfo->li_version != 5) | |
f41e4712 | 4135 | { |
77145576 JK |
4136 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
4137 | "is currently supported.\n")); | |
b40bf0a2 | 4138 | return NULL; |
f41e4712 | 4139 | } |
19e6b90e | 4140 | |
77145576 JK |
4141 | if (linfo->li_version >= 5) |
4142 | { | |
5496f3c6 | 4143 | SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end); |
77145576 | 4144 | |
5496f3c6 NC |
4145 | SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end); |
4146 | if (linfo->li_segment_size != 0) | |
77145576 JK |
4147 | { |
4148 | warn (_("The %s section contains " | |
4149 | "unsupported segment selector size: %d.\n"), | |
5496f3c6 NC |
4150 | section->name, linfo->li_segment_size); |
4151 | return NULL; | |
77145576 JK |
4152 | } |
4153 | } | |
4154 | ||
4155 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
4156 | linfo->li_offset_size, end); | |
b40bf0a2 | 4157 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 4158 | |
b40bf0a2 | 4159 | if (linfo->li_version >= 4) |
f41e4712 | 4160 | { |
b40bf0a2 | 4161 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 4162 | |
b40bf0a2 | 4163 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
4164 | { |
4165 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 4166 | return NULL; |
a233b20c | 4167 | } |
f41e4712 NC |
4168 | } |
4169 | else | |
b40bf0a2 | 4170 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 4171 | |
b40bf0a2 | 4172 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 4173 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
4174 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
4175 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 4176 | |
b40bf0a2 | 4177 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 4178 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
4179 | if (* end_of_sequence > end) |
4180 | { | |
4c219c2e AM |
4181 | warn (_("Line length %s extends beyond end of section\n"), |
4182 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
4183 | * end_of_sequence = end; |
4184 | return NULL; | |
4185 | } | |
4186 | ||
b40bf0a2 NC |
4187 | return hdrptr; |
4188 | } | |
19e6b90e | 4189 | |
77145576 | 4190 | static unsigned char * |
dda8d76d NC |
4191 | display_formatted_table (unsigned char * data, |
4192 | unsigned char * start, | |
4193 | unsigned char * end, | |
4194 | const DWARF2_Internal_LineInfo * linfo, | |
4195 | struct dwarf_section * section, | |
7b8d9e8c | 4196 | bfd_boolean is_dir) |
77145576 JK |
4197 | { |
4198 | unsigned char *format_start, format_count, *format, formati; | |
4199 | dwarf_vma data_count, datai; | |
cd30bcef | 4200 | unsigned int namepass, last_entry = 0; |
5496f3c6 | 4201 | const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table"); |
521d4b19 | 4202 | |
77145576 | 4203 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); |
546cb2d8 NC |
4204 | if (do_checks && format_count > 5) |
4205 | warn (_("Unexpectedly large number of columns in the %s (%u)\n"), | |
4206 | table_name, format_count); | |
4207 | ||
77145576 JK |
4208 | format_start = data; |
4209 | for (formati = 0; formati < format_count; formati++) | |
4210 | { | |
cd30bcef AM |
4211 | SKIP_ULEB (data, end); |
4212 | SKIP_ULEB (data, end); | |
77145576 JK |
4213 | if (data == end) |
4214 | { | |
5496f3c6 | 4215 | warn (_("%s: Corrupt format description entry\n"), table_name); |
77145576 JK |
4216 | return data; |
4217 | } | |
4218 | } | |
4219 | ||
cd30bcef | 4220 | READ_ULEB (data_count, data, end); |
546cb2d8 | 4221 | if (data_count == 0) |
77145576 | 4222 | { |
546cb2d8 | 4223 | printf (_("\n The %s is empty.\n"), table_name); |
77145576 JK |
4224 | return data; |
4225 | } | |
546cb2d8 | 4226 | else if (data == end) |
77145576 | 4227 | { |
546cb2d8 NC |
4228 | warn (_("%s: Corrupt entry count - expected %s but none found\n"), |
4229 | table_name, dwarf_vmatoa ("x", data_count)); | |
77145576 JK |
4230 | return data; |
4231 | } | |
546cb2d8 | 4232 | |
5496f3c6 NC |
4233 | else if (format_count == 0) |
4234 | { | |
4235 | warn (_("%s: format count is zero, but the table is not empty\n"), | |
4236 | table_name); | |
4237 | return end; | |
4238 | } | |
77145576 | 4239 | |
5496f3c6 NC |
4240 | printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"), |
4241 | table_name, (long) (data - start), dwarf_vmatoa ("u", data_count), | |
4242 | format_count); | |
77145576 JK |
4243 | |
4244 | printf (_(" Entry")); | |
521d4b19 | 4245 | /* Delay displaying name as the last entry for better screen layout. */ |
77145576 JK |
4246 | for (namepass = 0; namepass < 2; namepass++) |
4247 | { | |
4248 | format = format_start; | |
4249 | for (formati = 0; formati < format_count; formati++) | |
4250 | { | |
4251 | dwarf_vma content_type; | |
4252 | ||
cd30bcef | 4253 | READ_ULEB (content_type, format, end); |
77145576 JK |
4254 | if ((content_type == DW_LNCT_path) == (namepass == 1)) |
4255 | switch (content_type) | |
4256 | { | |
4257 | case DW_LNCT_path: | |
4258 | printf (_("\tName")); | |
4259 | break; | |
4260 | case DW_LNCT_directory_index: | |
4261 | printf (_("\tDir")); | |
4262 | break; | |
4263 | case DW_LNCT_timestamp: | |
4264 | printf (_("\tTime")); | |
4265 | break; | |
4266 | case DW_LNCT_size: | |
4267 | printf (_("\tSize")); | |
4268 | break; | |
4269 | case DW_LNCT_MD5: | |
5496f3c6 | 4270 | printf (_("\tMD5\t\t\t")); |
77145576 JK |
4271 | break; |
4272 | default: | |
4273 | printf (_("\t(Unknown format content type %s)"), | |
4274 | dwarf_vmatoa ("u", content_type)); | |
4275 | } | |
cd30bcef | 4276 | SKIP_ULEB (format, end); |
77145576 JK |
4277 | } |
4278 | } | |
4279 | putchar ('\n'); | |
4280 | ||
4281 | for (datai = 0; datai < data_count; datai++) | |
4282 | { | |
4283 | unsigned char *datapass = data; | |
4284 | ||
4285 | printf (" %d", last_entry++); | |
521d4b19 | 4286 | /* Delay displaying name as the last entry for better screen layout. */ |
77145576 JK |
4287 | for (namepass = 0; namepass < 2; namepass++) |
4288 | { | |
4289 | format = format_start; | |
4290 | data = datapass; | |
4291 | for (formati = 0; formati < format_count; formati++) | |
4292 | { | |
4293 | dwarf_vma content_type, form; | |
4294 | ||
cd30bcef AM |
4295 | READ_ULEB (content_type, format, end); |
4296 | READ_ULEB (form, format, end); | |
4297 | data = read_and_display_attr_value (0, form, 0, start, data, end, | |
4298 | 0, 0, linfo->li_offset_size, | |
77145576 JK |
4299 | linfo->li_version, NULL, |
4300 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
ec1b0fbb | 4301 | section, NULL, '\t', -1); |
77145576 JK |
4302 | } |
4303 | } | |
5496f3c6 NC |
4304 | |
4305 | if (data == end && (datai < data_count - 1)) | |
77145576 | 4306 | { |
5496f3c6 | 4307 | warn (_("\n%s: Corrupt entries list\n"), table_name); |
77145576 JK |
4308 | return data; |
4309 | } | |
4310 | putchar ('\n'); | |
4311 | } | |
4312 | return data; | |
4313 | } | |
4314 | ||
b40bf0a2 | 4315 | static int |
dda8d76d NC |
4316 | display_debug_lines_raw (struct dwarf_section * section, |
4317 | unsigned char * data, | |
4318 | unsigned char * end, | |
4319 | void * file) | |
b40bf0a2 NC |
4320 | { |
4321 | unsigned char *start = section->start; | |
ba8826a8 | 4322 | int verbose_view = 0; |
19e6b90e | 4323 | |
dda8d76d | 4324 | introduce (section, TRUE); |
19e6b90e | 4325 | |
b40bf0a2 NC |
4326 | while (data < end) |
4327 | { | |
4328 | static DWARF2_Internal_LineInfo saved_linfo; | |
4329 | DWARF2_Internal_LineInfo linfo; | |
4330 | unsigned char *standard_opcodes; | |
4331 | unsigned char *end_of_sequence; | |
fe59e83d | 4332 | int i; |
19e6b90e | 4333 | |
4925cdd7 NC |
4334 | if (const_strneq (section->name, ".debug_line.") |
4335 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4336 | These are full debug_line sections. */ | |
4337 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 4338 | { |
b40bf0a2 NC |
4339 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
4340 | section containing just the Line Number Statements. They are | |
4341 | created by the assembler and intended to be used alongside gcc's | |
4342 | -ffunction-sections command line option. When the linker's | |
4343 | garbage collection decides to discard a .text.<foo> section it | |
4344 | can then also discard the line number information in .debug_line.<foo>. | |
4345 | ||
4925cdd7 | 4346 | Since the section is a fragment it does not have the details |
b40bf0a2 | 4347 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 4348 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
4349 | end_of_sequence = end; |
4350 | standard_opcodes = NULL; | |
4351 | linfo = saved_linfo; | |
058037d3 NC |
4352 | /* PR 17531: file: 0522b371. */ |
4353 | if (linfo.li_line_range == 0) | |
4354 | { | |
1306a742 | 4355 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4356 | return 0; |
4357 | } | |
b40bf0a2 | 4358 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4359 | } |
19e6b90e L |
4360 | else |
4361 | { | |
b40bf0a2 | 4362 | unsigned char * hdrptr; |
19e6b90e | 4363 | |
b40bf0a2 NC |
4364 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4365 | & end_of_sequence)) == NULL) | |
4366 | return 0; | |
19e6b90e | 4367 | |
b40bf0a2 NC |
4368 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
4369 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
4370 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
5496f3c6 NC |
4371 | if (linfo.li_version >= 5) |
4372 | { | |
4373 | printf (_(" Address size (bytes): %d\n"), linfo.li_address_size); | |
4374 | printf (_(" Segment selector (bytes): %d\n"), linfo.li_segment_size); | |
4375 | } | |
77ef8654 | 4376 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
4377 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
4378 | if (linfo.li_version >= 4) | |
4379 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
4380 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
4381 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
4382 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
4383 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 4384 | |
0a9d414a NC |
4385 | /* PR 17512: file: 1665-6428-0.004. */ |
4386 | if (linfo.li_line_range == 0) | |
4387 | { | |
4388 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4389 | linfo.li_line_range = 1; | |
4390 | } | |
77ef8654 | 4391 | |
b40bf0a2 | 4392 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4393 | |
b40bf0a2 NC |
4394 | /* Display the contents of the Opcodes table. */ |
4395 | standard_opcodes = hdrptr; | |
19e6b90e | 4396 | |
6937bb54 NC |
4397 | /* PR 17512: file: 002-417945-0.004. */ |
4398 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
4399 | { | |
4400 | warn (_("Line Base extends beyond end of section\n")); | |
4401 | return 0; | |
4402 | } | |
4403 | ||
b40bf0a2 | 4404 | printf (_("\n Opcodes:\n")); |
19e6b90e | 4405 | |
b40bf0a2 | 4406 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
4407 | printf (ngettext (" Opcode %d has %d arg\n", |
4408 | " Opcode %d has %d args\n", | |
4409 | standard_opcodes[i - 1]), | |
4410 | i, standard_opcodes[i - 1]); | |
19e6b90e | 4411 | |
b40bf0a2 NC |
4412 | /* Display the contents of the Directory table. */ |
4413 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 4414 | |
77145576 | 4415 | if (linfo.li_version >= 5) |
b40bf0a2 | 4416 | { |
dda8d76d | 4417 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 4418 | |
77145576 | 4419 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 4420 | TRUE); |
77145576 | 4421 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 4422 | FALSE); |
77145576 JK |
4423 | } |
4424 | else | |
4425 | { | |
4426 | if (*data == 0) | |
4427 | printf (_("\n The Directory Table is empty.\n")); | |
4428 | else | |
a233b20c | 4429 | { |
77145576 | 4430 | unsigned int last_dir_entry = 0; |
6937bb54 | 4431 | |
77145576 JK |
4432 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
4433 | (long)(data - start)); | |
19e6b90e | 4434 | |
77145576 JK |
4435 | while (data < end && *data != 0) |
4436 | { | |
4437 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 4438 | |
77145576 JK |
4439 | data += strnlen ((char *) data, end - data) + 1; |
4440 | } | |
19e6b90e | 4441 | |
77145576 JK |
4442 | /* PR 17512: file: 002-132094-0.004. */ |
4443 | if (data >= end - 1) | |
4444 | break; | |
4445 | } | |
19e6b90e | 4446 | |
77145576 JK |
4447 | /* Skip the NUL at the end of the table. */ |
4448 | data++; | |
19e6b90e | 4449 | |
77145576 JK |
4450 | /* Display the contents of the File Name table. */ |
4451 | if (*data == 0) | |
4452 | printf (_("\n The File Name Table is empty.\n")); | |
4453 | else | |
4454 | { | |
4455 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
4456 | (long)(data - start)); | |
4457 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 4458 | |
77145576 | 4459 | while (data < end && *data != 0) |
b40bf0a2 | 4460 | { |
77145576 | 4461 | unsigned char *name; |
cd30bcef | 4462 | dwarf_vma val; |
77145576 JK |
4463 | |
4464 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
4465 | name = data; | |
4466 | data += strnlen ((char *) data, end - data) + 1; | |
4467 | ||
cd30bcef AM |
4468 | READ_ULEB (val, data, end); |
4469 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4470 | READ_ULEB (val, data, end); | |
4471 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4472 | READ_ULEB (val, data, end); | |
4473 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
77145576 JK |
4474 | printf ("%.*s\n", (int)(end - name), name); |
4475 | ||
4476 | if (data == end) | |
4477 | { | |
4478 | warn (_("Corrupt file name table entry\n")); | |
4479 | break; | |
4480 | } | |
b40bf0a2 | 4481 | } |
a233b20c | 4482 | } |
77145576 JK |
4483 | |
4484 | /* Skip the NUL at the end of the table. */ | |
4485 | data++; | |
b40bf0a2 | 4486 | } |
19e6b90e | 4487 | |
b40bf0a2 NC |
4488 | putchar ('\n'); |
4489 | saved_linfo = linfo; | |
4490 | } | |
19e6b90e | 4491 | |
b40bf0a2 NC |
4492 | /* Now display the statements. */ |
4493 | if (data >= end_of_sequence) | |
4494 | printf (_(" No Line Number Statements.\n")); | |
4495 | else | |
4496 | { | |
4497 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 4498 | |
b40bf0a2 NC |
4499 | while (data < end_of_sequence) |
4500 | { | |
4501 | unsigned char op_code; | |
4502 | dwarf_signed_vma adv; | |
4503 | dwarf_vma uladv; | |
19e6b90e | 4504 | |
fe59e83d CC |
4505 | printf (" [0x%08lx]", (long)(data - start)); |
4506 | ||
b40bf0a2 | 4507 | op_code = *data++; |
19e6b90e | 4508 | |
b40bf0a2 | 4509 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 4510 | { |
b40bf0a2 NC |
4511 | op_code -= linfo.li_opcode_base; |
4512 | uladv = (op_code / linfo.li_line_range); | |
4513 | if (linfo.li_max_ops_per_insn == 1) | |
4514 | { | |
4515 | uladv *= linfo.li_min_insn_length; | |
4516 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4517 | if (uladv) |
4518 | state_machine_regs.view = 0; | |
b40bf0a2 | 4519 | printf (_(" Special opcode %d: " |
ba8826a8 | 4520 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 4521 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4522 | dwarf_vmatoa ("x", state_machine_regs.address), |
4523 | verbose_view && uladv | |
4524 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4525 | } |
4526 | else | |
4527 | { | |
ba8826a8 AO |
4528 | unsigned addrdelta |
4529 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
4530 | / linfo.li_max_ops_per_insn) |
4531 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
4532 | |
4533 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
4534 | state_machine_regs.op_index |
4535 | = (state_machine_regs.op_index + uladv) | |
4536 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4537 | if (addrdelta) |
4538 | state_machine_regs.view = 0; | |
b40bf0a2 | 4539 | printf (_(" Special opcode %d: " |
ba8826a8 | 4540 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
4541 | op_code, dwarf_vmatoa ("u", uladv), |
4542 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4543 | state_machine_regs.op_index, |
4544 | verbose_view && addrdelta | |
4545 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4546 | } |
4547 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
4548 | state_machine_regs.line += adv; | |
ba8826a8 | 4549 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 4550 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
4551 | if (verbose_view || state_machine_regs.view) |
4552 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4553 | else | |
4554 | putchar ('\n'); | |
4555 | state_machine_regs.view++; | |
19e6b90e | 4556 | } |
cd30bcef AM |
4557 | else |
4558 | switch (op_code) | |
4559 | { | |
4560 | case DW_LNS_extended_op: | |
4561 | data += process_extended_line_op (data, | |
4562 | linfo.li_default_is_stmt, | |
4563 | end); | |
4564 | break; | |
4565 | ||
4566 | case DW_LNS_copy: | |
4567 | printf (_(" Copy")); | |
4568 | if (verbose_view || state_machine_regs.view) | |
4569 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4570 | else | |
4571 | putchar ('\n'); | |
4572 | state_machine_regs.view++; | |
4573 | break; | |
4574 | ||
4575 | case DW_LNS_advance_pc: | |
4576 | READ_ULEB (uladv, data, end); | |
4577 | if (linfo.li_max_ops_per_insn == 1) | |
4578 | { | |
4579 | uladv *= linfo.li_min_insn_length; | |
4580 | state_machine_regs.address += uladv; | |
4581 | if (uladv) | |
4582 | state_machine_regs.view = 0; | |
4583 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
4584 | dwarf_vmatoa ("u", uladv), | |
4585 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4586 | verbose_view && uladv | |
4587 | ? _(" (reset view)") : ""); | |
4588 | } | |
4589 | else | |
4590 | { | |
4591 | unsigned addrdelta | |
4592 | = ((state_machine_regs.op_index + uladv) | |
4593 | / linfo.li_max_ops_per_insn) | |
4594 | * linfo.li_min_insn_length; | |
4595 | state_machine_regs.address | |
4596 | += addrdelta; | |
4597 | state_machine_regs.op_index | |
4598 | = (state_machine_regs.op_index + uladv) | |
4599 | % linfo.li_max_ops_per_insn; | |
4600 | if (addrdelta) | |
4601 | state_machine_regs.view = 0; | |
4602 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
4603 | dwarf_vmatoa ("u", uladv), | |
4604 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4605 | state_machine_regs.op_index, | |
4606 | verbose_view && addrdelta | |
4607 | ? _(" (reset view)") : ""); | |
4608 | } | |
4609 | break; | |
4610 | ||
4611 | case DW_LNS_advance_line: | |
4612 | READ_SLEB (adv, data, end); | |
4613 | state_machine_regs.line += adv; | |
4614 | printf (_(" Advance Line by %s to %d\n"), | |
4615 | dwarf_vmatoa ("d", adv), | |
4616 | state_machine_regs.line); | |
4617 | break; | |
4618 | ||
4619 | case DW_LNS_set_file: | |
4620 | READ_ULEB (uladv, data, end); | |
4621 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
4622 | dwarf_vmatoa ("u", uladv)); | |
4623 | state_machine_regs.file = uladv; | |
4624 | break; | |
4625 | ||
4626 | case DW_LNS_set_column: | |
4627 | READ_ULEB (uladv, data, end); | |
4628 | printf (_(" Set column to %s\n"), | |
4629 | dwarf_vmatoa ("u", uladv)); | |
4630 | state_machine_regs.column = uladv; | |
4631 | break; | |
4632 | ||
4633 | case DW_LNS_negate_stmt: | |
4634 | adv = state_machine_regs.is_stmt; | |
4635 | adv = ! adv; | |
4636 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
4637 | state_machine_regs.is_stmt = adv; | |
4638 | break; | |
4639 | ||
4640 | case DW_LNS_set_basic_block: | |
4641 | printf (_(" Set basic block\n")); | |
4642 | state_machine_regs.basic_block = 1; | |
4643 | break; | |
4644 | ||
4645 | case DW_LNS_const_add_pc: | |
4646 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4647 | if (linfo.li_max_ops_per_insn) | |
4648 | { | |
4649 | uladv *= linfo.li_min_insn_length; | |
4650 | state_machine_regs.address += uladv; | |
4651 | if (uladv) | |
4652 | state_machine_regs.view = 0; | |
4653 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
4654 | dwarf_vmatoa ("u", uladv), | |
4655 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4656 | verbose_view && uladv | |
4657 | ? _(" (reset view)") : ""); | |
4658 | } | |
4659 | else | |
4660 | { | |
4661 | unsigned addrdelta | |
4662 | = ((state_machine_regs.op_index + uladv) | |
4663 | / linfo.li_max_ops_per_insn) | |
4664 | * linfo.li_min_insn_length; | |
4665 | state_machine_regs.address | |
4666 | += addrdelta; | |
4667 | state_machine_regs.op_index | |
4668 | = (state_machine_regs.op_index + uladv) | |
4669 | % linfo.li_max_ops_per_insn; | |
4670 | if (addrdelta) | |
4671 | state_machine_regs.view = 0; | |
4672 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
4673 | dwarf_vmatoa ("u", uladv), | |
4674 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4675 | state_machine_regs.op_index, | |
4676 | verbose_view && addrdelta | |
4677 | ? _(" (reset view)") : ""); | |
4678 | } | |
4679 | break; | |
4680 | ||
4681 | case DW_LNS_fixed_advance_pc: | |
4682 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4683 | state_machine_regs.address += uladv; | |
4684 | state_machine_regs.op_index = 0; | |
4685 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
4686 | dwarf_vmatoa ("u", uladv), | |
4687 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
4688 | /* Do NOT reset view. */ | |
4689 | break; | |
4690 | ||
4691 | case DW_LNS_set_prologue_end: | |
4692 | printf (_(" Set prologue_end to true\n")); | |
4693 | break; | |
4694 | ||
4695 | case DW_LNS_set_epilogue_begin: | |
4696 | printf (_(" Set epilogue_begin to true\n")); | |
4697 | break; | |
4698 | ||
4699 | case DW_LNS_set_isa: | |
4700 | READ_ULEB (uladv, data, end); | |
4701 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
4702 | break; | |
4703 | ||
4704 | default: | |
4705 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4706 | ||
4707 | if (standard_opcodes != NULL) | |
4708 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4709 | { | |
4710 | READ_ULEB (uladv, data, end); | |
4711 | printf ("0x%s%s", dwarf_vmatoa ("x", uladv), | |
4712 | i == 1 ? "" : ", "); | |
4713 | } | |
4714 | putchar ('\n'); | |
4715 | break; | |
4716 | } | |
19e6b90e | 4717 | } |
b40bf0a2 | 4718 | putchar ('\n'); |
19e6b90e | 4719 | } |
19e6b90e L |
4720 | } |
4721 | ||
4722 | return 1; | |
4723 | } | |
4724 | ||
a262ae96 NC |
4725 | typedef struct |
4726 | { | |
467c65bc NC |
4727 | unsigned char *name; |
4728 | unsigned int directory_index; | |
4729 | unsigned int modification_date; | |
4730 | unsigned int length; | |
a262ae96 NC |
4731 | } File_Entry; |
4732 | ||
4733 | /* Output a decoded representation of the .debug_line section. */ | |
4734 | ||
4735 | static int | |
dda8d76d | 4736 | display_debug_lines_decoded (struct dwarf_section * section, |
ec1b0fbb | 4737 | unsigned char * start, |
dda8d76d NC |
4738 | unsigned char * data, |
4739 | unsigned char * end, | |
4740 | void * fileptr) | |
a262ae96 | 4741 | { |
b40bf0a2 NC |
4742 | static DWARF2_Internal_LineInfo saved_linfo; |
4743 | ||
dda8d76d | 4744 | introduce (section, FALSE); |
a262ae96 NC |
4745 | |
4746 | while (data < end) | |
4747 | { | |
4748 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4749 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4750 | unsigned char *standard_opcodes; |
4751 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4752 | int i; |
4753 | File_Entry *file_table = NULL; | |
143a3db0 | 4754 | unsigned int n_files = 0; |
a262ae96 | 4755 | unsigned char **directory_table = NULL; |
77145576 | 4756 | dwarf_vma n_directories = 0; |
a262ae96 | 4757 | |
4925cdd7 NC |
4758 | if (const_strneq (section->name, ".debug_line.") |
4759 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4760 | These are full debug_line sections. */ | |
4761 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4762 | { |
4925cdd7 | 4763 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4764 | end_of_sequence = end; |
4765 | standard_opcodes = NULL; | |
4766 | linfo = saved_linfo; | |
058037d3 NC |
4767 | /* PR 17531: file: 0522b371. */ |
4768 | if (linfo.li_line_range == 0) | |
4769 | { | |
1306a742 | 4770 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4771 | return 0; |
4772 | } | |
b40bf0a2 | 4773 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4774 | } |
a262ae96 | 4775 | else |
b4eb7656 | 4776 | { |
b40bf0a2 | 4777 | unsigned char *hdrptr; |
a262ae96 | 4778 | |
b40bf0a2 NC |
4779 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4780 | & end_of_sequence)) == NULL) | |
a233b20c | 4781 | return 0; |
0c588247 | 4782 | |
058037d3 NC |
4783 | /* PR 17531: file: 0522b371. */ |
4784 | if (linfo.li_line_range == 0) | |
4785 | { | |
4786 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4787 | linfo.li_line_range = 1; | |
4788 | } | |
b40bf0a2 | 4789 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4790 | |
b40bf0a2 NC |
4791 | /* Save a pointer to the contents of the Opcodes table. */ |
4792 | standard_opcodes = hdrptr; | |
a262ae96 | 4793 | |
b40bf0a2 NC |
4794 | /* Traverse the Directory table just to count entries. */ |
4795 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4796 | /* PR 20440 */ |
4797 | if (data >= end) | |
4798 | { | |
4799 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4800 | linfo.li_opcode_base); | |
4801 | return 0; | |
4802 | } | |
4803 | ||
77145576 | 4804 | if (linfo.li_version >= 5) |
b40bf0a2 | 4805 | { |
77145576 JK |
4806 | unsigned char *format_start, format_count, *format; |
4807 | dwarf_vma formati, entryi; | |
a262ae96 | 4808 | |
dda8d76d | 4809 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4810 | |
4811 | /* Skip directories format. */ | |
4812 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4813 | if (do_checks && format_count > 1) |
4814 | warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"), | |
4815 | format_count); | |
77145576 JK |
4816 | format_start = data; |
4817 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4818 | { |
cd30bcef AM |
4819 | SKIP_ULEB (data, end); |
4820 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4821 | } |
a262ae96 | 4822 | |
cd30bcef | 4823 | READ_ULEB (n_directories, data, end); |
77145576 | 4824 | if (data == end) |
d8024a91 | 4825 | { |
77145576 | 4826 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
4827 | break; |
4828 | } | |
4829 | ||
070b775f NC |
4830 | if (n_directories == 0) |
4831 | directory_table = NULL; | |
4832 | else | |
4833 | directory_table = (unsigned char **) | |
4834 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 4835 | |
77145576 | 4836 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 4837 | { |
77145576 | 4838 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 4839 | |
77145576 JK |
4840 | format = format_start; |
4841 | for (formati = 0; formati < format_count; formati++) | |
4842 | { | |
4843 | dwarf_vma content_type, form; | |
4844 | dwarf_vma uvalue; | |
4845 | ||
cd30bcef AM |
4846 | READ_ULEB (content_type, format, end); |
4847 | READ_ULEB (form, format, end); | |
77145576 JK |
4848 | if (data == end) |
4849 | { | |
4850 | warn (_("Corrupt directories list\n")); | |
4851 | break; | |
4852 | } | |
4853 | switch (content_type) | |
4854 | { | |
4855 | case DW_LNCT_path: | |
4856 | switch (form) | |
4857 | { | |
4858 | case DW_FORM_string: | |
4859 | *pathp = data; | |
4860 | break; | |
4861 | case DW_FORM_line_strp: | |
4862 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4863 | end); | |
4864 | /* Remove const by the cast. */ | |
4865 | *pathp = (unsigned char *) | |
4866 | fetch_indirect_line_string (uvalue); | |
4867 | break; | |
4868 | } | |
4869 | break; | |
4870 | } | |
cd30bcef AM |
4871 | data = read_and_display_attr_value (0, form, 0, start, |
4872 | data, end, 0, 0, | |
77145576 JK |
4873 | linfo.li_offset_size, |
4874 | linfo.li_version, | |
4875 | NULL, 1, section, | |
ec1b0fbb | 4876 | NULL, '\t', -1); |
77145576 JK |
4877 | } |
4878 | if (data == end) | |
4879 | { | |
4880 | warn (_("Corrupt directories list\n")); | |
4881 | break; | |
4882 | } | |
4883 | } | |
a262ae96 | 4884 | |
77145576 JK |
4885 | /* Skip files format. */ |
4886 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
546cb2d8 NC |
4887 | if (do_checks && format_count > 5) |
4888 | warn (_("Unexpectedly large number of columns in the file name table (%u)\n"), | |
4889 | format_count); | |
77145576 JK |
4890 | format_start = data; |
4891 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4892 | { |
cd30bcef AM |
4893 | SKIP_ULEB (data, end); |
4894 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4895 | } |
a262ae96 | 4896 | |
cd30bcef | 4897 | READ_ULEB (n_files, data, end); |
070b775f | 4898 | if (data == end && n_files > 0) |
d8024a91 | 4899 | { |
77145576 | 4900 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
4901 | break; |
4902 | } | |
4903 | ||
070b775f NC |
4904 | if (n_files == 0) |
4905 | file_table = NULL; | |
4906 | else | |
4907 | file_table = (File_Entry *) xcalloc (1, n_files | |
4908 | * sizeof (File_Entry)); | |
a262ae96 | 4909 | |
77145576 | 4910 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 4911 | { |
77145576 | 4912 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 4913 | |
77145576 JK |
4914 | format = format_start; |
4915 | for (formati = 0; formati < format_count; formati++) | |
4916 | { | |
4917 | dwarf_vma content_type, form; | |
4918 | dwarf_vma uvalue; | |
cd30bcef | 4919 | unsigned char *tmp; |
77145576 | 4920 | |
cd30bcef AM |
4921 | READ_ULEB (content_type, format, end); |
4922 | READ_ULEB (form, format, end); | |
77145576 JK |
4923 | if (data == end) |
4924 | { | |
4925 | warn (_("Corrupt file name list\n")); | |
4926 | break; | |
4927 | } | |
4928 | switch (content_type) | |
4929 | { | |
4930 | case DW_LNCT_path: | |
4931 | switch (form) | |
4932 | { | |
4933 | case DW_FORM_string: | |
4934 | file->name = data; | |
4935 | break; | |
4936 | case DW_FORM_line_strp: | |
4937 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4938 | end); | |
4939 | /* Remove const by the cast. */ | |
4940 | file->name = (unsigned char *) | |
4941 | fetch_indirect_line_string (uvalue); | |
4942 | break; | |
4943 | } | |
4944 | break; | |
4945 | case DW_LNCT_directory_index: | |
4946 | switch (form) | |
4947 | { | |
4948 | case DW_FORM_data1: | |
4949 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
4950 | end); | |
4951 | break; | |
4952 | case DW_FORM_data2: | |
4953 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
4954 | end); | |
4955 | break; | |
4956 | case DW_FORM_udata: | |
cd30bcef AM |
4957 | tmp = data; |
4958 | READ_ULEB (file->directory_index, tmp, end); | |
77145576 JK |
4959 | break; |
4960 | } | |
4961 | break; | |
4962 | } | |
cd30bcef AM |
4963 | data = read_and_display_attr_value (0, form, 0, start, |
4964 | data, end, 0, 0, | |
77145576 JK |
4965 | linfo.li_offset_size, |
4966 | linfo.li_version, | |
4967 | NULL, 1, section, | |
ec1b0fbb | 4968 | NULL, '\t', -1); |
77145576 JK |
4969 | } |
4970 | if (data == end) | |
4971 | { | |
4972 | warn (_("Corrupt file name list\n")); | |
4973 | break; | |
4974 | } | |
4975 | } | |
4976 | } | |
4977 | else | |
4978 | { | |
4979 | if (*data != 0) | |
b40bf0a2 | 4980 | { |
77145576 JK |
4981 | unsigned char *ptr_directory_table = data; |
4982 | ||
4983 | while (data < end && *data != 0) | |
4984 | { | |
4985 | data += strnlen ((char *) data, end - data) + 1; | |
4986 | n_directories++; | |
4987 | } | |
4988 | ||
4989 | /* PR 20440 */ | |
4990 | if (data >= end) | |
4991 | { | |
4992 | warn (_("directory table ends unexpectedly\n")); | |
4993 | n_directories = 0; | |
4994 | break; | |
4995 | } | |
4996 | ||
4997 | /* Go through the directory table again to save the directories. */ | |
4998 | directory_table = (unsigned char **) | |
4999 | xmalloc (n_directories * sizeof (unsigned char *)); | |
5000 | ||
5001 | i = 0; | |
5002 | while (*ptr_directory_table != 0) | |
5003 | { | |
5004 | directory_table[i] = ptr_directory_table; | |
5005 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
5006 | ptr_directory_table - end) + 1; | |
5007 | i++; | |
5008 | } | |
b40bf0a2 | 5009 | } |
77145576 JK |
5010 | /* Skip the NUL at the end of the table. */ |
5011 | data++; | |
5012 | ||
5013 | /* Traverse the File Name table just to count the entries. */ | |
5014 | if (data < end && *data != 0) | |
b40bf0a2 | 5015 | { |
77145576 JK |
5016 | unsigned char *ptr_file_name_table = data; |
5017 | ||
5018 | while (data < end && *data != 0) | |
db9537d2 | 5019 | { |
cd30bcef AM |
5020 | /* Skip Name, directory index, last modification |
5021 | time and length of file. */ | |
77145576 | 5022 | data += strnlen ((char *) data, end - data) + 1; |
cd30bcef AM |
5023 | SKIP_ULEB (data, end); |
5024 | SKIP_ULEB (data, end); | |
5025 | SKIP_ULEB (data, end); | |
77145576 | 5026 | n_files++; |
db9537d2 | 5027 | } |
a262ae96 | 5028 | |
77145576 JK |
5029 | if (data >= end) |
5030 | { | |
5031 | warn (_("file table ends unexpectedly\n")); | |
5032 | n_files = 0; | |
5033 | break; | |
5034 | } | |
5035 | ||
5036 | /* Go through the file table again to save the strings. */ | |
5037 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 5038 | |
77145576 JK |
5039 | i = 0; |
5040 | while (*ptr_file_name_table != 0) | |
5041 | { | |
77145576 JK |
5042 | file_table[i].name = ptr_file_name_table; |
5043 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
5044 | end - ptr_file_name_table) + 1; | |
5045 | ||
5046 | /* We are not interested in directory, time or size. */ | |
cd30bcef AM |
5047 | READ_ULEB (file_table[i].directory_index, |
5048 | ptr_file_name_table, end); | |
5049 | READ_ULEB (file_table[i].modification_date, | |
5050 | ptr_file_name_table, end); | |
5051 | READ_ULEB (file_table[i].length, | |
5052 | ptr_file_name_table, end); | |
77145576 JK |
5053 | i++; |
5054 | } | |
5055 | i = 0; | |
b40bf0a2 | 5056 | } |
77145576 JK |
5057 | |
5058 | /* Skip the NUL at the end of the table. */ | |
5059 | data++; | |
b40bf0a2 | 5060 | } |
cc5914eb | 5061 | |
77145576 | 5062 | /* Print the Compilation Unit's name and a header. */ |
f082820d | 5063 | if (file_table == NULL) |
070b775f | 5064 | printf (_("CU: No directory table\n")); |
f082820d AM |
5065 | else if (directory_table == NULL) |
5066 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
5067 | else |
5068 | { | |
5069 | unsigned int ix = file_table[0].directory_index; | |
5070 | const char *directory; | |
5071 | ||
5072 | if (ix == 0) | |
5073 | directory = "."; | |
5074 | /* PR 20439 */ | |
5075 | else if (n_directories == 0) | |
5076 | directory = _("<unknown>"); | |
5077 | else if (ix > n_directories) | |
5078 | { | |
5079 | warn (_("directory index %u > number of directories %s\n"), | |
5080 | ix, dwarf_vmatoa ("u", n_directories)); | |
5081 | directory = _("<corrupt>"); | |
5082 | } | |
5083 | else | |
5084 | directory = (char *) directory_table[ix - 1]; | |
5085 | ||
5086 | if (do_wide || strlen (directory) < 76) | |
5087 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
5088 | else | |
5089 | printf ("%s:\n", file_table[0].name); | |
77145576 | 5090 | } |
a262ae96 | 5091 | |
070b775f NC |
5092 | if (n_files > 0) |
5093 | printf (_("File name Line number Starting address View Stmt\n")); | |
5094 | else | |
5095 | printf (_("CU: Empty file name table\n")); | |
b40bf0a2 NC |
5096 | saved_linfo = linfo; |
5097 | } | |
a262ae96 NC |
5098 | |
5099 | /* This loop iterates through the Dwarf Line Number Program. */ | |
5100 | while (data < end_of_sequence) | |
b4eb7656 | 5101 | { |
a262ae96 | 5102 | unsigned char op_code; |
ba8826a8 | 5103 | int xop; |
b4eb7656 AM |
5104 | int adv; |
5105 | unsigned long int uladv; | |
b4eb7656 | 5106 | int is_special_opcode = 0; |
a262ae96 | 5107 | |
b4eb7656 | 5108 | op_code = *data++; |
ba8826a8 | 5109 | xop = op_code; |
a262ae96 | 5110 | |
b4eb7656 | 5111 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 5112 | { |
91d6fa6a | 5113 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
5114 | uladv = (op_code / linfo.li_line_range); |
5115 | if (linfo.li_max_ops_per_insn == 1) | |
5116 | { | |
5117 | uladv *= linfo.li_min_insn_length; | |
5118 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
5119 | if (uladv) |
5120 | state_machine_regs.view = 0; | |
a233b20c JJ |
5121 | } |
5122 | else | |
5123 | { | |
ba8826a8 AO |
5124 | unsigned addrdelta |
5125 | = ((state_machine_regs.op_index + uladv) | |
5126 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 5127 | * linfo.li_min_insn_length; |
ba8826a8 AO |
5128 | state_machine_regs.address |
5129 | += addrdelta; | |
a233b20c JJ |
5130 | state_machine_regs.op_index |
5131 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 5132 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
5133 | if (addrdelta) |
5134 | state_machine_regs.view = 0; | |
a233b20c | 5135 | } |
a262ae96 | 5136 | |
b4eb7656 AM |
5137 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
5138 | state_machine_regs.line += adv; | |
5139 | is_special_opcode = 1; | |
ba8826a8 | 5140 | /* Increment view after printing this row. */ |
b4eb7656 | 5141 | } |
cd30bcef AM |
5142 | else |
5143 | switch (op_code) | |
5144 | { | |
5145 | case DW_LNS_extended_op: | |
5146 | { | |
5147 | unsigned int ext_op_code_len; | |
5148 | unsigned char ext_op_code; | |
5149 | unsigned char *op_code_end; | |
5150 | unsigned char *op_code_data = data; | |
5151 | ||
5152 | READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence); | |
5153 | op_code_end = op_code_data + ext_op_code_len; | |
5154 | if (ext_op_code_len == 0 || op_code_end > end_of_sequence) | |
5155 | { | |
5156 | warn (_("Badly formed extended line op encountered!\n")); | |
5157 | break; | |
5158 | } | |
5159 | ext_op_code = *op_code_data++; | |
5160 | xop = ext_op_code; | |
5161 | xop = -xop; | |
5162 | ||
5163 | switch (ext_op_code) | |
5164 | { | |
5165 | case DW_LNE_end_sequence: | |
5166 | /* Reset stuff after printing this row. */ | |
5167 | break; | |
5168 | case DW_LNE_set_address: | |
5169 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
5170 | op_code_data, | |
5171 | op_code_end - op_code_data, | |
5172 | op_code_end); | |
5173 | state_machine_regs.op_index = 0; | |
5174 | state_machine_regs.view = 0; | |
5175 | break; | |
5176 | case DW_LNE_define_file: | |
5177 | file_table = (File_Entry *) xrealloc | |
5178 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
5179 | ||
5180 | ++state_machine_regs.last_file_entry; | |
5181 | /* Source file name. */ | |
5182 | file_table[n_files].name = op_code_data; | |
5183 | op_code_data += strlen ((char *) op_code_data) + 1; | |
5184 | /* Directory index. */ | |
5185 | READ_ULEB (file_table[n_files].directory_index, | |
5186 | op_code_data, op_code_end); | |
5187 | /* Last modification time. */ | |
5188 | READ_ULEB (file_table[n_files].modification_date, | |
5189 | op_code_data, op_code_end); | |
5190 | /* File length. */ | |
5191 | READ_ULEB (file_table[n_files].length, | |
5192 | op_code_data, op_code_end); | |
5193 | n_files++; | |
5194 | break; | |
5195 | ||
5196 | case DW_LNE_set_discriminator: | |
5197 | case DW_LNE_HP_set_sequence: | |
5198 | /* Simply ignored. */ | |
5199 | break; | |
5200 | ||
5201 | default: | |
5202 | printf (_("UNKNOWN (%u): length %ld\n"), | |
27653fba | 5203 | ext_op_code, (long int) (op_code_data - data)); |
cd30bcef AM |
5204 | break; |
5205 | } | |
5206 | data = op_code_end; | |
5207 | break; | |
5208 | } | |
5209 | case DW_LNS_copy: | |
5210 | /* Increment view after printing this row. */ | |
5211 | break; | |
5212 | ||
5213 | case DW_LNS_advance_pc: | |
5214 | READ_ULEB (uladv, data, end); | |
5215 | if (linfo.li_max_ops_per_insn == 1) | |
5216 | { | |
5217 | uladv *= linfo.li_min_insn_length; | |
5218 | state_machine_regs.address += uladv; | |
5219 | if (uladv) | |
5220 | state_machine_regs.view = 0; | |
5221 | } | |
5222 | else | |
5223 | { | |
5224 | unsigned addrdelta | |
5225 | = ((state_machine_regs.op_index + uladv) | |
5226 | / linfo.li_max_ops_per_insn) | |
5227 | * linfo.li_min_insn_length; | |
5228 | state_machine_regs.address | |
5229 | += addrdelta; | |
5230 | state_machine_regs.op_index | |
5231 | = (state_machine_regs.op_index + uladv) | |
5232 | % linfo.li_max_ops_per_insn; | |
5233 | if (addrdelta) | |
5234 | state_machine_regs.view = 0; | |
5235 | } | |
5236 | break; | |
5237 | ||
5238 | case DW_LNS_advance_line: | |
5239 | READ_SLEB (adv, data, end); | |
5240 | state_machine_regs.line += adv; | |
5241 | break; | |
5242 | ||
5243 | case DW_LNS_set_file: | |
5244 | READ_ULEB (uladv, data, end); | |
5245 | state_machine_regs.file = uladv; | |
5246 | ||
5247 | { | |
5248 | unsigned file = state_machine_regs.file - 1; | |
5249 | unsigned dir; | |
5250 | ||
5251 | if (file_table == NULL || n_files == 0) | |
5252 | printf (_("\n [Use file table entry %d]\n"), file); | |
5253 | /* PR 20439 */ | |
5254 | else if (file >= n_files) | |
5255 | { | |
5256 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
5257 | printf (_("\n <over large file table index %u>"), file); | |
5258 | } | |
5259 | else if ((dir = file_table[file].directory_index) == 0) | |
5260 | /* If directory index is 0, that means current directory. */ | |
5261 | printf ("\n./%s:[++]\n", file_table[file].name); | |
5262 | else if (directory_table == NULL || n_directories == 0) | |
5263 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
5264 | file_table[file].name, dir); | |
5265 | /* PR 20439 */ | |
5266 | else if (dir > n_directories) | |
5267 | { | |
5268 | warn (_("directory index %u > number of directories %s\n"), | |
5269 | dir, dwarf_vmatoa ("u", n_directories)); | |
5270 | printf (_("\n <over large directory table entry %u>\n"), dir); | |
5271 | } | |
5272 | else | |
5273 | printf ("\n%s/%s:\n", | |
5274 | /* The directory index starts counting at 1. */ | |
5275 | directory_table[dir - 1], file_table[file].name); | |
5276 | } | |
5277 | break; | |
5278 | ||
5279 | case DW_LNS_set_column: | |
5280 | READ_ULEB (uladv, data, end); | |
5281 | state_machine_regs.column = uladv; | |
5282 | break; | |
5283 | ||
5284 | case DW_LNS_negate_stmt: | |
5285 | adv = state_machine_regs.is_stmt; | |
5286 | adv = ! adv; | |
5287 | state_machine_regs.is_stmt = adv; | |
5288 | break; | |
5289 | ||
5290 | case DW_LNS_set_basic_block: | |
5291 | state_machine_regs.basic_block = 1; | |
5292 | break; | |
5293 | ||
5294 | case DW_LNS_const_add_pc: | |
5295 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
5296 | if (linfo.li_max_ops_per_insn == 1) | |
5297 | { | |
5298 | uladv *= linfo.li_min_insn_length; | |
5299 | state_machine_regs.address += uladv; | |
5300 | if (uladv) | |
5301 | state_machine_regs.view = 0; | |
5302 | } | |
5303 | else | |
5304 | { | |
5305 | unsigned addrdelta | |
5306 | = ((state_machine_regs.op_index + uladv) | |
5307 | / linfo.li_max_ops_per_insn) | |
5308 | * linfo.li_min_insn_length; | |
5309 | state_machine_regs.address | |
5310 | += addrdelta; | |
5311 | state_machine_regs.op_index | |
5312 | = (state_machine_regs.op_index + uladv) | |
5313 | % linfo.li_max_ops_per_insn; | |
5314 | if (addrdelta) | |
5315 | state_machine_regs.view = 0; | |
5316 | } | |
5317 | break; | |
5318 | ||
5319 | case DW_LNS_fixed_advance_pc: | |
5320 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
5321 | state_machine_regs.address += uladv; | |
5322 | state_machine_regs.op_index = 0; | |
5323 | /* Do NOT reset view. */ | |
5324 | break; | |
5325 | ||
5326 | case DW_LNS_set_prologue_end: | |
5327 | break; | |
5328 | ||
5329 | case DW_LNS_set_epilogue_begin: | |
5330 | break; | |
5331 | ||
5332 | case DW_LNS_set_isa: | |
5333 | READ_ULEB (uladv, data, end); | |
5334 | printf (_(" Set ISA to %lu\n"), uladv); | |
5335 | break; | |
5336 | ||
5337 | default: | |
5338 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
5339 | ||
5340 | if (standard_opcodes != NULL) | |
5341 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
5342 | { | |
5343 | dwarf_vma val; | |
5344 | ||
5345 | READ_ULEB (val, data, end); | |
5346 | printf ("0x%s%s", dwarf_vmatoa ("x", val), | |
5347 | i == 1 ? "" : ", "); | |
5348 | } | |
5349 | putchar ('\n'); | |
5350 | break; | |
5351 | } | |
a262ae96 | 5352 | |
b4eb7656 AM |
5353 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
5354 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
5355 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
5356 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
5357 | { |
5358 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
5359 | char *fileName; | |
5360 | char *newFileName = NULL; | |
5361 | size_t fileNameLength; | |
b40bf0a2 NC |
5362 | |
5363 | if (file_table) | |
db9537d2 NC |
5364 | { |
5365 | unsigned indx = state_machine_regs.file - 1; | |
5366 | /* PR 20439 */ | |
5367 | if (indx >= n_files) | |
5368 | { | |
5369 | warn (_("corrupt file index %u encountered\n"), indx); | |
5370 | fileName = _("<corrupt>"); | |
5371 | } | |
5372 | else | |
5373 | fileName = (char *) file_table[indx].name; | |
5374 | } | |
b40bf0a2 | 5375 | else |
db9537d2 | 5376 | fileName = _("<unknown>"); |
b40bf0a2 NC |
5377 | |
5378 | fileNameLength = strlen (fileName); | |
a262ae96 | 5379 | |
b4eb7656 AM |
5380 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
5381 | { | |
5382 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
5383 | /* Truncate file name */ | |
5384 | strncpy (newFileName, | |
5385 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
5386 | MAX_FILENAME_LENGTH + 1); | |
e1104d08 NC |
5387 | /* FIXME: This is to pacify gcc-10 which can warn that the |
5388 | strncpy above might leave a non-NUL terminated string | |
5389 | in newFileName. It won't, but gcc's analysis doesn't | |
5390 | quite go far enough to discover this. */ | |
5391 | newFileName[MAX_FILENAME_LENGTH] = 0; | |
b4eb7656 AM |
5392 | } |
5393 | else | |
5394 | { | |
5395 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
5396 | strncpy (newFileName, fileName, fileNameLength + 1); | |
5397 | } | |
5398 | ||
af2b3186 TV |
5399 | /* A row with end_seq set to true has a meaningful address, but |
5400 | the other information in the same row is not significant. | |
5401 | In such a row, print line as "-", and don't print | |
5402 | view/is_stmt. */ | |
b4eb7656 AM |
5403 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) |
5404 | { | |
a233b20c | 5405 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5406 | { |
5407 | if (xop == -DW_LNE_end_sequence) | |
5408 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x", | |
5409 | newFileName, "-", | |
5410 | state_machine_regs.address); | |
5411 | else | |
5412 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", | |
5413 | newFileName, state_machine_regs.line, | |
5414 | state_machine_regs.address); | |
5415 | } | |
a233b20c | 5416 | else |
af2b3186 TV |
5417 | { |
5418 | if (xop == -DW_LNE_end_sequence) | |
5419 | printf ("%-35s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5420 | newFileName, "-", | |
5421 | state_machine_regs.address, | |
5422 | state_machine_regs.op_index); | |
5423 | else | |
5424 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5425 | newFileName, state_machine_regs.line, | |
5426 | state_machine_regs.address, | |
5427 | state_machine_regs.op_index); | |
5428 | } | |
b4eb7656 AM |
5429 | } |
5430 | else | |
5431 | { | |
a233b20c | 5432 | if (linfo.li_max_ops_per_insn == 1) |
af2b3186 TV |
5433 | { |
5434 | if (xop == -DW_LNE_end_sequence) | |
5435 | printf ("%s %11s %#18" DWARF_VMA_FMT "x", | |
5436 | newFileName, "-", | |
5437 | state_machine_regs.address); | |
5438 | else | |
5439 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", | |
5440 | newFileName, state_machine_regs.line, | |
5441 | state_machine_regs.address); | |
5442 | } | |
a233b20c | 5443 | else |
af2b3186 TV |
5444 | { |
5445 | if (xop == -DW_LNE_end_sequence) | |
5446 | printf ("%s %11s %#18" DWARF_VMA_FMT "x[%d]", | |
5447 | newFileName, "-", | |
5448 | state_machine_regs.address, | |
5449 | state_machine_regs.op_index); | |
5450 | else | |
5451 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", | |
5452 | newFileName, state_machine_regs.line, | |
5453 | state_machine_regs.address, | |
5454 | state_machine_regs.op_index); | |
5455 | } | |
b4eb7656 | 5456 | } |
a262ae96 | 5457 | |
af2b3186 TV |
5458 | if (xop != -DW_LNE_end_sequence) |
5459 | { | |
5460 | if (state_machine_regs.view) | |
5461 | printf (" %6u", state_machine_regs.view); | |
5462 | else | |
5463 | printf (" "); | |
17f6ade2 | 5464 | |
af2b3186 TV |
5465 | if (state_machine_regs.is_stmt) |
5466 | printf (" x"); | |
5467 | } | |
17f6ade2 JD |
5468 | |
5469 | putchar ('\n'); | |
ba8826a8 AO |
5470 | state_machine_regs.view++; |
5471 | ||
5472 | if (xop == -DW_LNE_end_sequence) | |
5473 | { | |
5474 | reset_state_machine (linfo.li_default_is_stmt); | |
5475 | putchar ('\n'); | |
5476 | } | |
a262ae96 | 5477 | |
b4eb7656 AM |
5478 | free (newFileName); |
5479 | } | |
5480 | } | |
b40bf0a2 NC |
5481 | |
5482 | if (file_table) | |
5483 | { | |
5484 | free (file_table); | |
5485 | file_table = NULL; | |
5486 | n_files = 0; | |
5487 | } | |
5488 | ||
5489 | if (directory_table) | |
5490 | { | |
5491 | free (directory_table); | |
5492 | directory_table = NULL; | |
5493 | n_directories = 0; | |
5494 | } | |
5495 | ||
a262ae96 NC |
5496 | putchar ('\n'); |
5497 | } | |
5498 | ||
5499 | return 1; | |
5500 | } | |
5501 | ||
5502 | static int | |
77145576 | 5503 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
5504 | { |
5505 | unsigned char *data = section->start; | |
5506 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
5507 | int retValRaw = 1; |
5508 | int retValDecoded = 1; | |
a262ae96 | 5509 | |
008f4c78 NC |
5510 | if (do_debug_lines == 0) |
5511 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
5512 | ||
4cb93e3b | 5513 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 5514 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 5515 | |
4cb93e3b | 5516 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
ec1b0fbb | 5517 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
a262ae96 | 5518 | |
4cb93e3b | 5519 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
5520 | return 0; |
5521 | ||
5522 | return 1; | |
5523 | } | |
5524 | ||
6e3d6dc1 NC |
5525 | static debug_info * |
5526 | find_debug_info_for_offset (unsigned long offset) | |
5527 | { | |
5528 | unsigned int i; | |
5529 | ||
5530 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
5531 | return NULL; | |
5532 | ||
5533 | for (i = 0; i < num_debug_info_entries; i++) | |
5534 | if (debug_information[i].cu_offset == offset) | |
5535 | return debug_information + i; | |
5536 | ||
5537 | return NULL; | |
5538 | } | |
5539 | ||
459d52c8 DE |
5540 | static const char * |
5541 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
5542 | { | |
5543 | /* See gdb/gdb-index.h. */ | |
5544 | static const char * const kinds[] = | |
5545 | { | |
5546 | N_ ("no info"), | |
5547 | N_ ("type"), | |
5548 | N_ ("variable"), | |
5549 | N_ ("function"), | |
5550 | N_ ("other"), | |
5551 | N_ ("unused5"), | |
5552 | N_ ("unused6"), | |
5553 | N_ ("unused7") | |
5554 | }; | |
5555 | ||
5556 | return _ (kinds[kind]); | |
5557 | } | |
5558 | ||
19e6b90e | 5559 | static int |
459d52c8 DE |
5560 | display_debug_pubnames_worker (struct dwarf_section *section, |
5561 | void *file ATTRIBUTE_UNUSED, | |
5562 | int is_gnu) | |
19e6b90e | 5563 | { |
91d6fa6a | 5564 | DWARF2_Internal_PubNames names; |
19e6b90e L |
5565 | unsigned char *start = section->start; |
5566 | unsigned char *end = start + section->size; | |
5567 | ||
6e3d6dc1 NC |
5568 | /* It does not matter if this load fails, |
5569 | we test for that later on. */ | |
5570 | load_debug_info (file); | |
5571 | ||
dda8d76d | 5572 | introduce (section, FALSE); |
19e6b90e L |
5573 | |
5574 | while (start < end) | |
5575 | { | |
5576 | unsigned char *data; | |
e98fdf1a | 5577 | unsigned long sec_off; |
bf5117e3 | 5578 | unsigned int offset_size, initial_length_size; |
19e6b90e | 5579 | |
e98fdf1a | 5580 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 5581 | if (names.pn_length == 0xffffffff) |
19e6b90e | 5582 | { |
e98fdf1a | 5583 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e L |
5584 | offset_size = 8; |
5585 | initial_length_size = 12; | |
5586 | } | |
5587 | else | |
5588 | { | |
5589 | offset_size = 4; | |
5590 | initial_length_size = 4; | |
5591 | } | |
5592 | ||
e98fdf1a AM |
5593 | sec_off = start - section->start; |
5594 | if (sec_off + names.pn_length < sec_off | |
5595 | || sec_off + names.pn_length > section->size) | |
5596 | { | |
5597 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
5598 | section->name, | |
5599 | sec_off - initial_length_size, | |
5600 | dwarf_vmatoa ("x", names.pn_length)); | |
5601 | break; | |
5602 | } | |
5603 | ||
5604 | data = start; | |
5605 | start += names.pn_length; | |
5606 | ||
0c588247 NC |
5607 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
5608 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
5609 | |
5610 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
5611 | && num_debug_info_entries > 0 | |
91d6fa6a | 5612 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 5613 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 5614 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 5615 | |
0c588247 | 5616 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 5617 | |
058037d3 NC |
5618 | printf (_(" Length: %ld\n"), |
5619 | (long) names.pn_length); | |
5620 | printf (_(" Version: %d\n"), | |
5621 | names.pn_version); | |
5622 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
5623 | (unsigned long) names.pn_offset); | |
5624 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
5625 | (long) names.pn_size); | |
19e6b90e | 5626 | |
91d6fa6a | 5627 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
5628 | { |
5629 | static int warned = 0; | |
5630 | ||
5631 | if (! warned) | |
5632 | { | |
5633 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
5634 | warned = 1; | |
5635 | } | |
5636 | ||
5637 | continue; | |
5638 | } | |
5639 | ||
459d52c8 DE |
5640 | if (is_gnu) |
5641 | printf (_("\n Offset Kind Name\n")); | |
5642 | else | |
5643 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 5644 | |
e98fdf1a | 5645 | while (1) |
19e6b90e | 5646 | { |
f41e4712 | 5647 | bfd_size_type maxprint; |
e98fdf1a | 5648 | dwarf_vma offset; |
f41e4712 | 5649 | |
0c588247 | 5650 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e | 5651 | |
e98fdf1a AM |
5652 | if (offset == 0) |
5653 | break; | |
b4eb7656 | 5654 | |
e98fdf1a AM |
5655 | data += offset_size; |
5656 | if (data >= end) | |
5657 | break; | |
5658 | maxprint = (end - data) - 1; | |
f41e4712 | 5659 | |
e98fdf1a AM |
5660 | if (is_gnu) |
5661 | { | |
5662 | unsigned int kind_data; | |
5663 | gdb_index_symbol_kind kind; | |
5664 | const char *kind_name; | |
5665 | int is_static; | |
5666 | ||
5667 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
5668 | data++; | |
5669 | maxprint --; | |
5670 | /* GCC computes the kind as the upper byte in the CU index | |
5671 | word, and then right shifts it by the CU index size. | |
5672 | Left shift KIND to where the gdb-index.h accessor macros | |
5673 | can use it. */ | |
5674 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
5675 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
5676 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
5677 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
5678 | printf (" %-6lx %s,%-10s %.*s\n", | |
5679 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
5680 | kind_name, (int) maxprint, data); | |
19e6b90e | 5681 | } |
e98fdf1a AM |
5682 | else |
5683 | printf (" %-6lx\t%.*s\n", | |
5684 | (unsigned long) offset, (int) maxprint, data); | |
5685 | ||
5686 | data += strnlen ((char *) data, maxprint) + 1; | |
5687 | if (data >= end) | |
5688 | break; | |
19e6b90e | 5689 | } |
19e6b90e L |
5690 | } |
5691 | ||
5692 | printf ("\n"); | |
5693 | return 1; | |
5694 | } | |
5695 | ||
459d52c8 DE |
5696 | static int |
5697 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
5698 | { | |
5699 | return display_debug_pubnames_worker (section, file, 0); | |
5700 | } | |
5701 | ||
5702 | static int | |
5703 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
5704 | { | |
5705 | return display_debug_pubnames_worker (section, file, 1); | |
5706 | } | |
5707 | ||
19e6b90e L |
5708 | static int |
5709 | display_debug_macinfo (struct dwarf_section *section, | |
5710 | void *file ATTRIBUTE_UNUSED) | |
5711 | { | |
5712 | unsigned char *start = section->start; | |
5713 | unsigned char *end = start + section->size; | |
5714 | unsigned char *curr = start; | |
19e6b90e L |
5715 | enum dwarf_macinfo_record_type op; |
5716 | ||
dda8d76d | 5717 | introduce (section, FALSE); |
19e6b90e L |
5718 | |
5719 | while (curr < end) | |
5720 | { | |
5721 | unsigned int lineno; | |
0c588247 | 5722 | const unsigned char *string; |
19e6b90e | 5723 | |
3f5e193b | 5724 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
5725 | curr++; |
5726 | ||
5727 | switch (op) | |
5728 | { | |
5729 | case DW_MACINFO_start_file: | |
5730 | { | |
5731 | unsigned int filenum; | |
5732 | ||
cd30bcef AM |
5733 | READ_ULEB (lineno, curr, end); |
5734 | READ_ULEB (filenum, curr, end); | |
19e6b90e L |
5735 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), |
5736 | lineno, filenum); | |
5737 | } | |
5738 | break; | |
5739 | ||
5740 | case DW_MACINFO_end_file: | |
5741 | printf (_(" DW_MACINFO_end_file\n")); | |
5742 | break; | |
5743 | ||
5744 | case DW_MACINFO_define: | |
cd30bcef | 5745 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5746 | string = curr; |
5747 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5748 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
5749 | lineno, string); | |
5750 | break; | |
5751 | ||
5752 | case DW_MACINFO_undef: | |
cd30bcef | 5753 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5754 | string = curr; |
5755 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5756 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
5757 | lineno, string); | |
5758 | break; | |
5759 | ||
5760 | case DW_MACINFO_vendor_ext: | |
5761 | { | |
5762 | unsigned int constant; | |
5763 | ||
cd30bcef | 5764 | READ_ULEB (constant, curr, end); |
0c588247 NC |
5765 | string = curr; |
5766 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5767 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
5768 | constant, string); | |
5769 | } | |
5770 | break; | |
5771 | } | |
5772 | } | |
5773 | ||
5774 | return 1; | |
5775 | } | |
5776 | ||
4ccf1e31 JJ |
5777 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5778 | filename and dirname corresponding to file name table entry with index | |
5779 | FILEIDX. Return NULL on failure. */ | |
5780 | ||
5781 | static unsigned char * | |
f6f0e17b NC |
5782 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5783 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5784 | unsigned char **dir_name) |
5785 | { | |
5786 | struct dwarf_section *section = &debug_displays [line].section; | |
5787 | unsigned char *hdrptr, *dirtable, *file_name; | |
5788 | unsigned int offset_size, initial_length_size; | |
cd30bcef | 5789 | unsigned int version, opcode_base; |
4ccf1e31 | 5790 | dwarf_vma length, diridx; |
f6f0e17b | 5791 | const unsigned char * end; |
4ccf1e31 JJ |
5792 | |
5793 | *dir_name = NULL; | |
5794 | if (section->start == NULL | |
5795 | || line_offset >= section->size | |
5796 | || fileidx == 0) | |
5797 | return NULL; | |
5798 | ||
5799 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5800 | end = section->start + section->size; |
0c588247 NC |
5801 | |
5802 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5803 | if (length == 0xffffffff) |
5804 | { | |
5805 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5806 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
5807 | offset_size = 8; |
5808 | initial_length_size = 12; | |
5809 | } | |
5810 | else | |
5811 | { | |
5812 | offset_size = 4; | |
5813 | initial_length_size = 4; | |
5814 | } | |
e98fdf1a AM |
5815 | if (length + initial_length_size < length |
5816 | || length + initial_length_size > section->size) | |
4ccf1e31 | 5817 | return NULL; |
0c588247 NC |
5818 | |
5819 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5820 | if (version != 2 && version != 3 && version != 4) |
5821 | return NULL; | |
5822 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5823 | if (version >= 4) | |
5824 | hdrptr++; /* Skip max_ops_per_insn. */ | |
5825 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
5826 | |
5827 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
5828 | if (opcode_base == 0) |
5829 | return NULL; | |
0c588247 | 5830 | |
4ccf1e31 | 5831 | hdrptr += opcode_base - 1; |
5c1c468d NC |
5832 | if (hdrptr >= end) |
5833 | return NULL; | |
5834 | ||
4ccf1e31 JJ |
5835 | dirtable = hdrptr; |
5836 | /* Skip over dirname table. */ | |
5837 | while (*hdrptr != '\0') | |
5c1c468d NC |
5838 | { |
5839 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; | |
5840 | if (hdrptr >= end) | |
5841 | return NULL; | |
5842 | } | |
4ccf1e31 | 5843 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 5844 | |
4ccf1e31 | 5845 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 5846 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 5847 | { |
0c588247 | 5848 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
cd30bcef AM |
5849 | SKIP_ULEB (hdrptr, end); |
5850 | SKIP_ULEB (hdrptr, end); | |
5851 | SKIP_ULEB (hdrptr, end); | |
4ccf1e31 | 5852 | } |
5c1c468d | 5853 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 5854 | return NULL; |
5c1c468d | 5855 | |
4ccf1e31 | 5856 | file_name = hdrptr; |
0c588247 | 5857 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
5c1c468d NC |
5858 | if (hdrptr >= end) |
5859 | return NULL; | |
cd30bcef | 5860 | READ_ULEB (diridx, hdrptr, end); |
4ccf1e31 JJ |
5861 | if (diridx == 0) |
5862 | return file_name; | |
5c1c468d | 5863 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
0c588247 | 5864 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
5c1c468d | 5865 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
5866 | return NULL; |
5867 | *dir_name = dirtable; | |
5868 | return file_name; | |
5869 | } | |
5870 | ||
5871 | static int | |
5872 | display_debug_macro (struct dwarf_section *section, | |
5873 | void *file) | |
5874 | { | |
5875 | unsigned char *start = section->start; | |
5876 | unsigned char *end = start + section->size; | |
5877 | unsigned char *curr = start; | |
5878 | unsigned char *extended_op_buf[256]; | |
4ccf1e31 | 5879 | |
dda8d76d NC |
5880 | load_debug_section_with_follow (str, file); |
5881 | load_debug_section_with_follow (line, file); | |
e4b7104b | 5882 | load_debug_section_with_follow (str_index, file); |
4ccf1e31 | 5883 | |
dda8d76d | 5884 | introduce (section, FALSE); |
4ccf1e31 JJ |
5885 | |
5886 | while (curr < end) | |
5887 | { | |
5888 | unsigned int lineno, version, flags; | |
5889 | unsigned int offset_size = 4; | |
0c588247 | 5890 | const unsigned char *string; |
4ccf1e31 JJ |
5891 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
5892 | unsigned char **extended_ops = NULL; | |
5893 | ||
0c588247 | 5894 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 5895 | if (version != 4 && version != 5) |
4ccf1e31 | 5896 | { |
7a7e1061 | 5897 | error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"), |
4ccf1e31 JJ |
5898 | section->name); |
5899 | return 0; | |
5900 | } | |
5901 | ||
0c588247 | 5902 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
4ccf1e31 JJ |
5903 | if (flags & 1) |
5904 | offset_size = 8; | |
5905 | printf (_(" Offset: 0x%lx\n"), | |
5906 | (unsigned long) sec_offset); | |
5907 | printf (_(" Version: %d\n"), version); | |
5908 | printf (_(" Offset size: %d\n"), offset_size); | |
5909 | if (flags & 2) | |
5910 | { | |
0c588247 | 5911 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
5912 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
5913 | (unsigned long) line_offset); | |
5914 | } | |
5915 | if (flags & 4) | |
5916 | { | |
0c588247 | 5917 | unsigned int i, count, op; |
4ccf1e31 | 5918 | dwarf_vma nargs, n; |
0c588247 NC |
5919 | |
5920 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 5921 | |
4ccf1e31 JJ |
5922 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
5923 | extended_ops = extended_op_buf; | |
5924 | if (count) | |
5925 | { | |
5926 | printf (_(" Extension opcode arguments:\n")); | |
5927 | for (i = 0; i < count; i++) | |
5928 | { | |
0c588247 | 5929 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 5930 | extended_ops[op] = curr; |
cd30bcef | 5931 | READ_ULEB (nargs, curr, end); |
4ccf1e31 | 5932 | if (nargs == 0) |
7a7e1061 | 5933 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
5934 | else |
5935 | { | |
7a7e1061 | 5936 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
5937 | for (n = 0; n < nargs; n++) |
5938 | { | |
0c588247 NC |
5939 | unsigned int form; |
5940 | ||
5941 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
5942 | printf ("%s%s", get_FORM_name (form), |
5943 | n == nargs - 1 ? "\n" : ", "); | |
5944 | switch (form) | |
5945 | { | |
5946 | case DW_FORM_data1: | |
5947 | case DW_FORM_data2: | |
5948 | case DW_FORM_data4: | |
5949 | case DW_FORM_data8: | |
5950 | case DW_FORM_sdata: | |
5951 | case DW_FORM_udata: | |
5952 | case DW_FORM_block: | |
5953 | case DW_FORM_block1: | |
5954 | case DW_FORM_block2: | |
5955 | case DW_FORM_block4: | |
5956 | case DW_FORM_flag: | |
5957 | case DW_FORM_string: | |
5958 | case DW_FORM_strp: | |
5959 | case DW_FORM_sec_offset: | |
5960 | break; | |
5961 | default: | |
5962 | error (_("Invalid extension opcode form %s\n"), | |
5963 | get_FORM_name (form)); | |
5964 | return 0; | |
5965 | } | |
5966 | } | |
5967 | } | |
5968 | } | |
5969 | } | |
5970 | } | |
5971 | printf ("\n"); | |
5972 | ||
5973 | while (1) | |
5974 | { | |
5975 | unsigned int op; | |
5976 | ||
5977 | if (curr >= end) | |
5978 | { | |
5979 | error (_(".debug_macro section not zero terminated\n")); | |
5980 | return 0; | |
5981 | } | |
5982 | ||
0c588247 | 5983 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
5984 | if (op == 0) |
5985 | break; | |
5986 | ||
5987 | switch (op) | |
5988 | { | |
e4b7104b NC |
5989 | case DW_MACRO_define: |
5990 | READ_ULEB (lineno, curr, end); | |
5991 | string = curr; | |
5992 | curr += strnlen ((char *) string, end - string) + 1; | |
5993 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), | |
5994 | lineno, string); | |
5995 | break; | |
5996 | ||
5997 | case DW_MACRO_undef: | |
5998 | READ_ULEB (lineno, curr, end); | |
5999 | string = curr; | |
6000 | curr += strnlen ((char *) string, end - string) + 1; | |
6001 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), | |
6002 | lineno, string); | |
6003 | break; | |
6004 | ||
7a7e1061 | 6005 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
6006 | { |
6007 | unsigned int filenum; | |
6008 | unsigned char *file_name = NULL, *dir_name = NULL; | |
6009 | ||
cd30bcef AM |
6010 | READ_ULEB (lineno, curr, end); |
6011 | READ_ULEB (filenum, curr, end); | |
4ccf1e31 JJ |
6012 | |
6013 | if ((flags & 2) == 0) | |
7a7e1061 | 6014 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
6015 | else |
6016 | file_name | |
6017 | = get_line_filename_and_dirname (line_offset, filenum, | |
6018 | &dir_name); | |
6019 | if (file_name == NULL) | |
7a7e1061 | 6020 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
6021 | lineno, filenum); |
6022 | else | |
7a7e1061 | 6023 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
6024 | lineno, filenum, |
6025 | dir_name != NULL ? (const char *) dir_name : "", | |
6026 | dir_name != NULL ? "/" : "", file_name); | |
6027 | } | |
6028 | break; | |
6029 | ||
7a7e1061 JK |
6030 | case DW_MACRO_end_file: |
6031 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
6032 | break; |
6033 | ||
7a7e1061 | 6034 | case DW_MACRO_define_strp: |
cd30bcef | 6035 | READ_ULEB (lineno, curr, end); |
0c588247 | 6036 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 6037 | string = fetch_indirect_string (offset); |
7a7e1061 | 6038 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
6039 | lineno, string); |
6040 | break; | |
6041 | ||
7a7e1061 | 6042 | case DW_MACRO_undef_strp: |
cd30bcef | 6043 | READ_ULEB (lineno, curr, end); |
0c588247 | 6044 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 6045 | string = fetch_indirect_string (offset); |
7a7e1061 | 6046 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
6047 | lineno, string); |
6048 | break; | |
6049 | ||
7a7e1061 | 6050 | case DW_MACRO_import: |
0c588247 | 6051 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6052 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
6053 | (unsigned long) offset); |
6054 | break; | |
6055 | ||
7a7e1061 | 6056 | case DW_MACRO_define_sup: |
cd30bcef | 6057 | READ_ULEB (lineno, curr, end); |
0c588247 | 6058 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6059 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
6060 | lineno, (unsigned long) offset); |
6061 | break; | |
6062 | ||
7a7e1061 | 6063 | case DW_MACRO_undef_sup: |
cd30bcef | 6064 | READ_ULEB (lineno, curr, end); |
0c588247 | 6065 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6066 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
6067 | lineno, (unsigned long) offset); |
6068 | break; | |
6069 | ||
7a7e1061 | 6070 | case DW_MACRO_import_sup: |
0c588247 | 6071 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 6072 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
6073 | (unsigned long) offset); |
6074 | break; | |
6075 | ||
e4b7104b NC |
6076 | case DW_MACRO_define_strx: |
6077 | case DW_MACRO_undef_strx: | |
6078 | READ_ULEB (lineno, curr, end); | |
6079 | READ_ULEB (offset, curr, end); | |
6080 | string = (const unsigned char *) | |
6081 | fetch_indexed_string (offset, NULL, offset_size, FALSE); | |
6082 | if (op == DW_MACRO_define_strx) | |
6083 | printf (" DW_MACRO_define_strx "); | |
6084 | else | |
6085 | printf (" DW_MACRO_undef_strx "); | |
6086 | if (do_wide) | |
39f381cb | 6087 | printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset)); |
e4b7104b NC |
6088 | printf (_("lineno : %d macro : %s\n"), |
6089 | lineno, string); | |
6090 | break; | |
6091 | ||
4ccf1e31 | 6092 | default: |
e4b7104b NC |
6093 | if (op >= DW_MACRO_lo_user && op <= DW_MACRO_hi_user) |
6094 | { | |
6095 | printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op); | |
6096 | break; | |
6097 | } | |
6098 | ||
4ccf1e31 JJ |
6099 | if (extended_ops == NULL || extended_ops[op] == NULL) |
6100 | { | |
6101 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
6102 | return 0; | |
6103 | } | |
6104 | else | |
6105 | { | |
6106 | /* Skip over unhandled opcodes. */ | |
6107 | dwarf_vma nargs, n; | |
6108 | unsigned char *desc = extended_ops[op]; | |
cd30bcef | 6109 | READ_ULEB (nargs, desc, end); |
4ccf1e31 JJ |
6110 | if (nargs == 0) |
6111 | { | |
7a7e1061 | 6112 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
6113 | break; |
6114 | } | |
7a7e1061 | 6115 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
6116 | for (n = 0; n < nargs; n++) |
6117 | { | |
0c588247 NC |
6118 | int val; |
6119 | ||
77145576 | 6120 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 6121 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 6122 | curr |
77145576 | 6123 | = read_and_display_attr_value (0, val, 0, |
ec1b0fbb | 6124 | start, curr, end, 0, 0, offset_size, |
341f9135 | 6125 | version, NULL, 0, NULL, |
ec1b0fbb | 6126 | NULL, ' ', -1); |
4ccf1e31 JJ |
6127 | if (n != nargs - 1) |
6128 | printf (","); | |
6129 | } | |
6130 | printf ("\n"); | |
6131 | } | |
6132 | break; | |
6133 | } | |
6134 | } | |
6135 | ||
6136 | printf ("\n"); | |
b4eb7656 | 6137 | } |
4ccf1e31 JJ |
6138 | |
6139 | return 1; | |
6140 | } | |
6141 | ||
19e6b90e L |
6142 | static int |
6143 | display_debug_abbrev (struct dwarf_section *section, | |
6144 | void *file ATTRIBUTE_UNUSED) | |
6145 | { | |
6146 | abbrev_entry *entry; | |
6147 | unsigned char *start = section->start; | |
bcd213b2 | 6148 | const unsigned char *end = start + section->size; |
19e6b90e | 6149 | |
dda8d76d | 6150 | introduce (section, FALSE); |
19e6b90e L |
6151 | |
6152 | do | |
6153 | { | |
bcd213b2 NC |
6154 | abbrev_list * list; |
6155 | dwarf_vma offset; | |
7282333f | 6156 | |
bcd213b2 | 6157 | offset = start - section->start; |
76868f36 | 6158 | list = find_abbrev_list_by_abbrev_offset (0, offset); |
bcd213b2 NC |
6159 | if (list == NULL) |
6160 | { | |
76868f36 | 6161 | list = new_abbrev_list (0, offset); |
bcd213b2 NC |
6162 | start = process_abbrev_set (start, end, list); |
6163 | list->start_of_next_abbrevs = start; | |
6164 | } | |
6165 | else | |
6166 | start = list->start_of_next_abbrevs; | |
19e6b90e | 6167 | |
bcd213b2 | 6168 | if (list->first_abbrev == NULL) |
19e6b90e L |
6169 | continue; |
6170 | ||
bcd213b2 | 6171 | printf (_(" Number TAG (0x%lx)\n"), (long) offset); |
19e6b90e | 6172 | |
bcd213b2 | 6173 | for (entry = list->first_abbrev; entry; entry = entry->next) |
19e6b90e L |
6174 | { |
6175 | abbrev_attr *attr; | |
6176 | ||
cc5914eb | 6177 | printf (" %ld %s [%s]\n", |
bcd213b2 | 6178 | entry->number, |
19e6b90e L |
6179 | get_TAG_name (entry->tag), |
6180 | entry->children ? _("has children") : _("no children")); | |
6181 | ||
6182 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
6183 | { |
6184 | printf (" %-18s %s", | |
6185 | get_AT_name (attr->attribute), | |
6186 | get_FORM_name (attr->form)); | |
6187 | if (attr->form == DW_FORM_implicit_const) | |
6188 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
6189 | putchar ('\n'); | |
6190 | } | |
19e6b90e L |
6191 | } |
6192 | } | |
6193 | while (start); | |
6194 | ||
6195 | printf ("\n"); | |
6196 | ||
6197 | return 1; | |
6198 | } | |
6199 | ||
42bcef4a AB |
6200 | /* Return true when ADDR is the maximum address, when addresses are |
6201 | POINTER_SIZE bytes long. */ | |
6202 | ||
6203 | static bfd_boolean | |
6204 | is_max_address (dwarf_vma addr, unsigned int pointer_size) | |
6205 | { | |
6206 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
6207 | return ((addr & mask) == mask); | |
6208 | } | |
6209 | ||
9f272209 AO |
6210 | /* Display a view pair list starting at *VSTART_PTR and ending at |
6211 | VLISTEND within SECTION. */ | |
6212 | ||
6213 | static void | |
6214 | display_view_pair_list (struct dwarf_section *section, | |
6215 | unsigned char **vstart_ptr, | |
6216 | unsigned int debug_info_entry, | |
6217 | unsigned char *vlistend) | |
6218 | { | |
6219 | unsigned char *vstart = *vstart_ptr; | |
6220 | unsigned char *section_end = section->start + section->size; | |
6221 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
6222 | ||
6223 | if (vlistend < section_end) | |
6224 | section_end = vlistend; | |
6225 | ||
6226 | putchar ('\n'); | |
6227 | ||
6228 | while (vstart < section_end) | |
6229 | { | |
6230 | dwarf_vma off = vstart - section->start; | |
6231 | dwarf_vma vbegin, vend; | |
6232 | ||
cd30bcef | 6233 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 | 6234 | if (vstart == section_end) |
cd30bcef | 6235 | break; |
9f272209 | 6236 | |
cd30bcef | 6237 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6238 | printf (" %8.8lx ", (unsigned long) off); |
6239 | ||
6240 | print_dwarf_view (vbegin, pointer_size, 1); | |
6241 | print_dwarf_view (vend, pointer_size, 1); | |
6242 | printf (_("location view pair\n")); | |
6243 | } | |
6244 | ||
6245 | putchar ('\n'); | |
6246 | *vstart_ptr = vstart; | |
6247 | } | |
6248 | ||
4723351a CC |
6249 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
6250 | ||
6251 | static void | |
6252 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
6253 | unsigned char **start_ptr, |
6254 | unsigned int debug_info_entry, | |
359ca075 JK |
6255 | dwarf_vma offset, |
6256 | dwarf_vma base_address, | |
9f272209 | 6257 | unsigned char **vstart_ptr, |
b4eb7656 | 6258 | int has_frame_base) |
4723351a | 6259 | { |
9f272209 | 6260 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6261 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6262 | unsigned long cu_offset; |
6263 | unsigned int pointer_size; | |
6264 | unsigned int offset_size; | |
6265 | int dwarf_version; | |
4723351a CC |
6266 | |
6267 | dwarf_vma begin; | |
6268 | dwarf_vma end; | |
6269 | unsigned short length; | |
6270 | int need_frame_base; | |
6271 | ||
82b1b41b NC |
6272 | if (debug_info_entry >= num_debug_info_entries) |
6273 | { | |
6274 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
6275 | debug_info_entry); | |
6276 | return; | |
6277 | } | |
b4eb7656 | 6278 | |
82b1b41b NC |
6279 | cu_offset = debug_information [debug_info_entry].cu_offset; |
6280 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6281 | offset_size = debug_information [debug_info_entry].offset_size; | |
6282 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 6283 | |
f41e4712 NC |
6284 | if (pointer_size < 2 || pointer_size > 8) |
6285 | { | |
6286 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6287 | pointer_size, debug_info_entry); | |
6288 | return; | |
6289 | } | |
6290 | ||
4723351a CC |
6291 | while (1) |
6292 | { | |
359ca075 | 6293 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 6294 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 6295 | |
4723351a | 6296 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
6297 | { |
6298 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6299 | (unsigned long) offset); |
b4eb7656 AM |
6300 | break; |
6301 | } | |
4723351a | 6302 | |
359ca075 | 6303 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 6304 | |
0c588247 NC |
6305 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
6306 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 6307 | |
4723351a | 6308 | if (begin == 0 && end == 0) |
b4eb7656 | 6309 | { |
d1c4b12b NC |
6310 | /* PR 18374: In a object file we can have a location list that |
6311 | starts with a begin and end of 0 because there are relocations | |
6312 | that need to be applied to the addresses. Actually applying | |
6313 | the relocations now does not help as they will probably resolve | |
6314 | to 0, since the object file has not been fully linked. Real | |
6315 | end of list markers will not have any relocations against them. */ | |
6316 | if (! reloc_at (section, off) | |
6317 | && ! reloc_at (section, off + pointer_size)) | |
6318 | { | |
6319 | printf (_("<End of list>\n")); | |
6320 | break; | |
6321 | } | |
b4eb7656 | 6322 | } |
4723351a CC |
6323 | |
6324 | /* Check base address specifiers. */ | |
42bcef4a AB |
6325 | if (is_max_address (begin, pointer_size) |
6326 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
6327 | { |
6328 | base_address = end; | |
6329 | print_dwarf_vma (begin, pointer_size); | |
6330 | print_dwarf_vma (end, pointer_size); | |
6331 | printf (_("(base address)\n")); | |
6332 | continue; | |
6333 | } | |
4723351a | 6334 | |
9f272209 AO |
6335 | if (vstart) |
6336 | { | |
9f272209 AO |
6337 | off = offset + (vstart - *start_ptr); |
6338 | ||
cd30bcef | 6339 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
6340 | print_dwarf_view (vbegin, pointer_size, 1); |
6341 | ||
cd30bcef | 6342 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6343 | print_dwarf_view (vend, pointer_size, 1); |
6344 | ||
6345 | printf (_("views at %8.8lx for:\n %*s "), | |
6346 | (unsigned long) off, 8, ""); | |
6347 | } | |
6348 | ||
4723351a | 6349 | if (start + 2 > section_end) |
b4eb7656 AM |
6350 | { |
6351 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6352 | (unsigned long) offset); |
b4eb7656 AM |
6353 | break; |
6354 | } | |
4723351a | 6355 | |
0c588247 | 6356 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
6357 | |
6358 | if (start + length > section_end) | |
b4eb7656 AM |
6359 | { |
6360 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6361 | (unsigned long) offset); |
b4eb7656 AM |
6362 | break; |
6363 | } | |
4723351a CC |
6364 | |
6365 | print_dwarf_vma (begin + base_address, pointer_size); | |
6366 | print_dwarf_vma (end + base_address, pointer_size); | |
6367 | ||
6368 | putchar ('('); | |
6369 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6370 | pointer_size, |
6371 | offset_size, | |
6372 | dwarf_version, | |
6373 | length, | |
6374 | cu_offset, section); | |
4723351a CC |
6375 | putchar (')'); |
6376 | ||
6377 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6378 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 6379 | |
9f272209 | 6380 | if (begin == end && vbegin == vend) |
b4eb7656 | 6381 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6382 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 6383 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
6384 | |
6385 | putchar ('\n'); | |
6386 | ||
6387 | start += length; | |
6388 | } | |
6389 | ||
6390 | *start_ptr = start; | |
9f272209 | 6391 | *vstart_ptr = vstart; |
4723351a CC |
6392 | } |
6393 | ||
77145576 JK |
6394 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
6395 | ||
6396 | static void | |
6397 | display_loclists_list (struct dwarf_section *section, | |
6398 | unsigned char **start_ptr, | |
6399 | unsigned int debug_info_entry, | |
6400 | dwarf_vma offset, | |
6401 | dwarf_vma base_address, | |
9f272209 | 6402 | unsigned char **vstart_ptr, |
77145576 JK |
6403 | int has_frame_base) |
6404 | { | |
9f272209 | 6405 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
6406 | unsigned char *section_end = section->start + section->size; |
6407 | unsigned long cu_offset; | |
6408 | unsigned int pointer_size; | |
6409 | unsigned int offset_size; | |
6410 | int dwarf_version; | |
77145576 | 6411 | |
9dfd0db9 | 6412 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
6413 | dwarf_vma begin = -1, vbegin = -1; |
6414 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
6415 | dwarf_vma length; |
6416 | int need_frame_base; | |
6417 | ||
6418 | if (debug_info_entry >= num_debug_info_entries) | |
6419 | { | |
6420 | warn (_("No debug information available for " | |
6421 | "loclists lists of entry: %u\n"), | |
6422 | debug_info_entry); | |
6423 | return; | |
6424 | } | |
6425 | ||
6426 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6427 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6428 | offset_size = debug_information [debug_info_entry].offset_size; | |
6429 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6430 | ||
6431 | if (pointer_size < 2 || pointer_size > 8) | |
6432 | { | |
6433 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6434 | pointer_size, debug_info_entry); | |
6435 | return; | |
6436 | } | |
6437 | ||
6438 | while (1) | |
6439 | { | |
6440 | dwarf_vma off = offset + (start - *start_ptr); | |
6441 | enum dwarf_location_list_entry_type llet; | |
6442 | ||
6443 | if (start + 1 > section_end) | |
6444 | { | |
6445 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6446 | (unsigned long) offset); | |
6447 | break; | |
6448 | } | |
6449 | ||
6450 | printf (" %8.8lx ", (unsigned long) off); | |
6451 | ||
6452 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
6453 | ||
1c9f770d MW |
6454 | if (vstart && (llet == DW_LLE_offset_pair |
6455 | || llet == DW_LLE_start_end | |
6456 | || llet == DW_LLE_start_length)) | |
9f272209 AO |
6457 | { |
6458 | off = offset + (vstart - *start_ptr); | |
6459 | ||
cd30bcef | 6460 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
6461 | print_dwarf_view (vbegin, pointer_size, 1); |
6462 | ||
cd30bcef | 6463 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
6464 | print_dwarf_view (vend, pointer_size, 1); |
6465 | ||
6466 | printf (_("views at %8.8lx for:\n %*s "), | |
6467 | (unsigned long) off, 8, ""); | |
6468 | } | |
6469 | ||
77145576 JK |
6470 | switch (llet) |
6471 | { | |
6472 | case DW_LLE_end_of_list: | |
6473 | printf (_("<End of list>\n")); | |
6474 | break; | |
6475 | case DW_LLE_offset_pair: | |
cd30bcef | 6476 | READ_ULEB (begin, start, section_end); |
1c9f770d | 6477 | begin += base_address; |
cd30bcef | 6478 | READ_ULEB (end, start, section_end); |
1c9f770d MW |
6479 | end += base_address; |
6480 | break; | |
6481 | case DW_LLE_start_end: | |
6482 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6483 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
6484 | break; | |
6485 | case DW_LLE_start_length: | |
6486 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); | |
6487 | READ_ULEB (end, start, section_end); | |
6488 | end += begin; | |
77145576 JK |
6489 | break; |
6490 | case DW_LLE_base_address: | |
6491 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
6492 | section_end); | |
6493 | print_dwarf_vma (base_address, pointer_size); | |
6494 | printf (_("(base address)\n")); | |
6495 | break; | |
9f272209 AO |
6496 | #ifdef DW_LLE_view_pair |
6497 | case DW_LLE_view_pair: | |
6498 | if (vstart) | |
6499 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
cd30bcef | 6500 | READ_ULEB (vbegin, start, section_end); |
9f272209 AO |
6501 | print_dwarf_view (vbegin, pointer_size, 1); |
6502 | ||
cd30bcef | 6503 | READ_ULEB (vend, start, section_end); |
9f272209 AO |
6504 | print_dwarf_view (vend, pointer_size, 1); |
6505 | ||
6506 | printf (_("views for:\n")); | |
6507 | continue; | |
6508 | #endif | |
77145576 JK |
6509 | default: |
6510 | error (_("Invalid location list entry type %d\n"), llet); | |
6511 | return; | |
6512 | } | |
6513 | if (llet == DW_LLE_end_of_list) | |
6514 | break; | |
1c9f770d MW |
6515 | if (llet != DW_LLE_offset_pair |
6516 | && llet != DW_LLE_start_end | |
6517 | && llet != DW_LLE_start_length) | |
77145576 JK |
6518 | continue; |
6519 | ||
6520 | if (start + 2 > section_end) | |
6521 | { | |
6522 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6523 | (unsigned long) offset); | |
6524 | break; | |
6525 | } | |
6526 | ||
cd30bcef | 6527 | READ_ULEB (length, start, section_end); |
77145576 | 6528 | |
1c9f770d MW |
6529 | print_dwarf_vma (begin, pointer_size); |
6530 | print_dwarf_vma (end, pointer_size); | |
77145576 JK |
6531 | |
6532 | putchar ('('); | |
6533 | need_frame_base = decode_location_expression (start, | |
6534 | pointer_size, | |
6535 | offset_size, | |
6536 | dwarf_version, | |
6537 | length, | |
6538 | cu_offset, section); | |
6539 | putchar (')'); | |
6540 | ||
6541 | if (need_frame_base && !has_frame_base) | |
6542 | printf (_(" [without DW_AT_frame_base]")); | |
6543 | ||
9f272209 | 6544 | if (begin == end && vbegin == vend) |
77145576 | 6545 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6546 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
6547 | fputs (_(" (start > end)"), stdout); |
6548 | ||
6549 | putchar ('\n'); | |
6550 | ||
6551 | start += length; | |
9f272209 | 6552 | vbegin = vend = -1; |
77145576 JK |
6553 | } |
6554 | ||
9f272209 AO |
6555 | if (vbegin != vm1 || vend != vm1) |
6556 | printf (_("Trailing view pair not used in a range")); | |
6557 | ||
77145576 | 6558 | *start_ptr = start; |
9f272209 | 6559 | *vstart_ptr = vstart; |
77145576 JK |
6560 | } |
6561 | ||
fab128ef CC |
6562 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
6563 | right-adjusted in a field of length LEN, and followed by a space. */ | |
6564 | ||
6565 | static void | |
6566 | print_addr_index (unsigned int idx, unsigned int len) | |
6567 | { | |
6568 | static char buf[15]; | |
6569 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 6570 | printf ("%*s ", len, buf); |
fab128ef CC |
6571 | } |
6572 | ||
4723351a CC |
6573 | /* Display a location list from a .dwo section. It uses address indexes rather |
6574 | than embedded addresses. This code closely follows display_loc_list, but the | |
6575 | two are sufficiently different that combining things is very ugly. */ | |
6576 | ||
6577 | static void | |
6578 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
6579 | unsigned char **start_ptr, |
6580 | unsigned int debug_info_entry, | |
359ca075 | 6581 | dwarf_vma offset, |
9f272209 | 6582 | unsigned char **vstart_ptr, |
b4eb7656 | 6583 | int has_frame_base) |
4723351a | 6584 | { |
9f272209 | 6585 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6586 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6587 | unsigned long cu_offset; |
6588 | unsigned int pointer_size; | |
6589 | unsigned int offset_size; | |
6590 | int dwarf_version; | |
4723351a CC |
6591 | int entry_type; |
6592 | unsigned short length; | |
6593 | int need_frame_base; | |
fab128ef | 6594 | unsigned int idx; |
4723351a | 6595 | |
82b1b41b NC |
6596 | if (debug_info_entry >= num_debug_info_entries) |
6597 | { | |
6598 | warn (_("No debug information for loc lists of entry: %u\n"), | |
6599 | debug_info_entry); | |
6600 | return; | |
6601 | } | |
6602 | ||
6603 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6604 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6605 | offset_size = debug_information [debug_info_entry].offset_size; | |
6606 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6607 | ||
f41e4712 NC |
6608 | if (pointer_size < 2 || pointer_size > 8) |
6609 | { | |
6610 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6611 | pointer_size, debug_info_entry); | |
6612 | return; | |
6613 | } | |
6614 | ||
4723351a CC |
6615 | while (1) |
6616 | { | |
359ca075 | 6617 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 6618 | |
fab128ef | 6619 | if (start >= section_end) |
b4eb7656 AM |
6620 | { |
6621 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6622 | (unsigned long) offset); |
b4eb7656 AM |
6623 | break; |
6624 | } | |
4723351a | 6625 | |
0c588247 | 6626 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
6627 | |
6628 | if (vstart) | |
6629 | switch (entry_type) | |
6630 | { | |
6631 | default: | |
6632 | break; | |
6633 | ||
6634 | case 2: | |
6635 | case 3: | |
6636 | case 4: | |
6637 | { | |
6638 | dwarf_vma view; | |
6639 | dwarf_vma off = offset + (vstart - *start_ptr); | |
6640 | ||
cd30bcef | 6641 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6642 | print_dwarf_view (view, 8, 1); |
6643 | ||
cd30bcef | 6644 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6645 | print_dwarf_view (view, 8, 1); |
6646 | ||
6647 | printf (_("views at %8.8lx for:\n %*s "), | |
6648 | (unsigned long) off, 8, ""); | |
6649 | ||
6650 | } | |
6651 | break; | |
6652 | } | |
6653 | ||
4723351a | 6654 | switch (entry_type) |
b4eb7656 AM |
6655 | { |
6656 | case 0: /* A terminating entry. */ | |
6657 | *start_ptr = start; | |
9f272209 | 6658 | *vstart_ptr = vstart; |
b4eb7656 AM |
6659 | printf (_("<End of list>\n")); |
6660 | return; | |
6661 | case 1: /* A base-address entry. */ | |
cd30bcef | 6662 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6663 | print_addr_index (idx, 8); |
9f272209 | 6664 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
6665 | printf (_("(base address selection entry)\n")); |
6666 | continue; | |
6667 | case 2: /* A start/end entry. */ | |
cd30bcef | 6668 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6669 | print_addr_index (idx, 8); |
cd30bcef | 6670 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6671 | print_addr_index (idx, 8); |
6672 | break; | |
6673 | case 3: /* A start/length entry. */ | |
cd30bcef | 6674 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6675 | print_addr_index (idx, 8); |
6676 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6677 | printf ("%08x ", idx); | |
6678 | break; | |
6679 | case 4: /* An offset pair entry. */ | |
6680 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6681 | printf ("%08x ", idx); | |
6682 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6683 | printf ("%08x ", idx); | |
6684 | break; | |
6685 | default: | |
6686 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
6687 | *start_ptr = start; | |
9f272209 | 6688 | *vstart_ptr = vstart; |
b4eb7656 AM |
6689 | return; |
6690 | } | |
4723351a CC |
6691 | |
6692 | if (start + 2 > section_end) | |
b4eb7656 AM |
6693 | { |
6694 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6695 | (unsigned long) offset); |
b4eb7656 AM |
6696 | break; |
6697 | } | |
4723351a | 6698 | |
0c588247 | 6699 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6700 | if (start + length > section_end) |
b4eb7656 AM |
6701 | { |
6702 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6703 | (unsigned long) offset); |
b4eb7656 AM |
6704 | break; |
6705 | } | |
4723351a CC |
6706 | |
6707 | putchar ('('); | |
6708 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6709 | pointer_size, |
6710 | offset_size, | |
6711 | dwarf_version, | |
6712 | length, | |
6713 | cu_offset, section); | |
4723351a CC |
6714 | putchar (')'); |
6715 | ||
6716 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6717 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
6718 | |
6719 | putchar ('\n'); | |
6720 | ||
6721 | start += length; | |
6722 | } | |
6723 | ||
6724 | *start_ptr = start; | |
9f272209 | 6725 | *vstart_ptr = vstart; |
4723351a CC |
6726 | } |
6727 | ||
9f272209 AO |
6728 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
6729 | loc_views. */ | |
51d0d03f | 6730 | |
9f272209 | 6731 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
6732 | |
6733 | static int | |
6734 | loc_offsets_compar (const void *ap, const void *bp) | |
6735 | { | |
6736 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
6737 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
6738 | ||
9f272209 AO |
6739 | int ret = (a > b) - (b > a); |
6740 | if (ret) | |
6741 | return ret; | |
6742 | ||
6743 | a = loc_views[*(const unsigned int *) ap]; | |
6744 | b = loc_views[*(const unsigned int *) bp]; | |
6745 | ||
6746 | ret = (a > b) - (b > a); | |
6747 | ||
6748 | return ret; | |
51d0d03f JJ |
6749 | } |
6750 | ||
19e6b90e L |
6751 | static int |
6752 | display_debug_loc (struct dwarf_section *section, void *file) | |
6753 | { | |
9f272209 | 6754 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
6755 | unsigned long bytes; |
6756 | unsigned char *section_begin = start; | |
6757 | unsigned int num_loc_list = 0; | |
6758 | unsigned long last_offset = 0; | |
9f272209 | 6759 | unsigned long last_view = 0; |
19e6b90e L |
6760 | unsigned int first = 0; |
6761 | unsigned int i; | |
6762 | unsigned int j; | |
6763 | int seen_first_offset = 0; | |
51d0d03f | 6764 | int locs_sorted = 1; |
9f272209 | 6765 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6766 | unsigned int *array = NULL; |
4723351a | 6767 | const char *suffix = strrchr (section->name, '.'); |
24841daa | 6768 | bfd_boolean is_dwo = FALSE; |
77145576 JK |
6769 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6770 | dwarf_vma expected_start = 0; | |
4723351a CC |
6771 | |
6772 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
24841daa | 6773 | is_dwo = TRUE; |
19e6b90e L |
6774 | |
6775 | bytes = section->size; | |
19e6b90e L |
6776 | |
6777 | if (bytes == 0) | |
6778 | { | |
6779 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6780 | return 0; | |
6781 | } | |
6782 | ||
77145576 JK |
6783 | if (is_loclists) |
6784 | { | |
6785 | unsigned char *hdrptr = section_begin; | |
6786 | dwarf_vma ll_length; | |
6787 | unsigned short ll_version; | |
6788 | unsigned char *end = section_begin + section->size; | |
6789 | unsigned char address_size, segment_selector_size; | |
6790 | uint32_t offset_entry_count; | |
6791 | ||
6792 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6793 | if (ll_length == 0xffffffff) | |
6794 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6795 | ||
6796 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6797 | if (ll_version != 5) | |
6798 | { | |
6799 | warn (_("The %s section contains corrupt or " | |
6800 | "unsupported version number: %d.\n"), | |
6801 | section->name, ll_version); | |
6802 | return 0; | |
6803 | } | |
6804 | ||
6805 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6806 | ||
6807 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6808 | if (segment_selector_size != 0) | |
6809 | { | |
6810 | warn (_("The %s section contains " | |
6811 | "unsupported segment selector size: %d.\n"), | |
6812 | section->name, segment_selector_size); | |
6813 | return 0; | |
6814 | } | |
6815 | ||
6816 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
6817 | if (offset_entry_count != 0) | |
6818 | { | |
6819 | warn (_("The %s section contains " | |
6820 | "unsupported offset entry count: %d.\n"), | |
6821 | section->name, offset_entry_count); | |
6822 | return 0; | |
6823 | } | |
6824 | ||
6825 | expected_start = hdrptr - section_begin; | |
6826 | } | |
6827 | ||
1febe64d NC |
6828 | if (load_debug_info (file) == 0) |
6829 | { | |
6830 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6831 | section->name); | |
6832 | return 0; | |
6833 | } | |
19e6b90e L |
6834 | |
6835 | /* Check the order of location list in .debug_info section. If | |
6836 | offsets of location lists are in the ascending order, we can | |
6837 | use `debug_information' directly. */ | |
6838 | for (i = 0; i < num_debug_info_entries; i++) | |
6839 | { | |
6840 | unsigned int num; | |
6841 | ||
6842 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
6843 | if (num > num_loc_list) |
6844 | num_loc_list = num; | |
19e6b90e L |
6845 | |
6846 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 6847 | if (locs_sorted && num != 0) |
19e6b90e L |
6848 | { |
6849 | if (!seen_first_offset) | |
6850 | { | |
6851 | /* This is the first location list. */ | |
6852 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 6853 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
6854 | first = i; |
6855 | seen_first_offset = 1; | |
6856 | j = 1; | |
6857 | } | |
6858 | else | |
6859 | j = 0; | |
6860 | ||
6861 | for (; j < num; j++) | |
6862 | { | |
6863 | if (last_offset > | |
9f272209 AO |
6864 | debug_information [i].loc_offsets [j] |
6865 | || (last_offset == debug_information [i].loc_offsets [j] | |
6866 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 6867 | { |
51d0d03f | 6868 | locs_sorted = 0; |
19e6b90e L |
6869 | break; |
6870 | } | |
6871 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 6872 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
6873 | } |
6874 | } | |
6875 | } | |
6876 | ||
19e6b90e L |
6877 | if (!seen_first_offset) |
6878 | error (_("No location lists in .debug_info section!\n")); | |
6879 | ||
d4bfc77b | 6880 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
6881 | && debug_information [first].loc_offsets [0] != expected_start |
6882 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
6883 | warn (_("Location lists in %s section start at 0x%s\n"), |
6884 | section->name, | |
6885 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 6886 | |
51d0d03f JJ |
6887 | if (!locs_sorted) |
6888 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d NC |
6889 | |
6890 | introduce (section, FALSE); | |
6891 | ||
d1c4b12b NC |
6892 | if (reloc_at (section, 0)) |
6893 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 6894 | |
d1c4b12b | 6895 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
6896 | |
6897 | seen_first_offset = 0; | |
6898 | for (i = first; i < num_debug_info_entries; i++) | |
6899 | { | |
9f272209 | 6900 | dwarf_vma offset, voffset; |
359ca075 | 6901 | dwarf_vma base_address; |
d1c4b12b | 6902 | unsigned int k; |
19e6b90e L |
6903 | int has_frame_base; |
6904 | ||
51d0d03f JJ |
6905 | if (!locs_sorted) |
6906 | { | |
6907 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
6908 | array[k] = k; | |
6909 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 6910 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
6911 | qsort (array, debug_information [i].num_loc_offsets, |
6912 | sizeof (*array), loc_offsets_compar); | |
6913 | } | |
19e6b90e | 6914 | |
9f272209 | 6915 | int adjacent_view_loclists = 1; |
51d0d03f | 6916 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 6917 | { |
51d0d03f JJ |
6918 | j = locs_sorted ? k : array[k]; |
6919 | if (k | |
9f272209 | 6920 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 6921 | ? k - 1 : array [k - 1]] |
9f272209 AO |
6922 | == debug_information [i].loc_offsets [j]) |
6923 | && (debug_information [i].loc_views [locs_sorted | |
6924 | ? k - 1 : array [k - 1]] | |
6925 | == debug_information [i].loc_views [j])) | |
51d0d03f | 6926 | continue; |
19e6b90e | 6927 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 6928 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 6929 | next = section_begin + offset; |
9f272209 AO |
6930 | voffset = debug_information [i].loc_views [j]; |
6931 | if (voffset != vm1) | |
6932 | vnext = section_begin + voffset; | |
6933 | else | |
6934 | vnext = NULL; | |
19e6b90e L |
6935 | base_address = debug_information [i].base_address; |
6936 | ||
9f272209 AO |
6937 | if (vnext && vnext < next) |
6938 | { | |
6939 | vstart = vnext; | |
6940 | display_view_pair_list (section, &vstart, i, next); | |
6941 | if (start == vnext) | |
6942 | start = vstart; | |
6943 | } | |
6944 | ||
6945 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
6946 | seen_first_offset = 1; |
6947 | else | |
6948 | { | |
6949 | if (start < next) | |
6950 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6951 | (unsigned long) (start - section_begin), |
c8071705 | 6952 | (unsigned long) offset); |
19e6b90e L |
6953 | else if (start > next) |
6954 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6955 | (unsigned long) (start - section_begin), |
c8071705 | 6956 | (unsigned long) offset); |
19e6b90e L |
6957 | } |
6958 | start = next; | |
9f272209 | 6959 | vstart = vnext; |
19e6b90e L |
6960 | |
6961 | if (offset >= bytes) | |
6962 | { | |
6963 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 6964 | (unsigned long) offset); |
19e6b90e L |
6965 | continue; |
6966 | } | |
6967 | ||
9f272209 AO |
6968 | if (vnext && voffset >= bytes) |
6969 | { | |
6970 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
6971 | (unsigned long) voffset); | |
6972 | continue; | |
6973 | } | |
6974 | ||
77145576 JK |
6975 | if (!is_loclists) |
6976 | { | |
6977 | if (is_dwo) | |
6978 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 6979 | &vstart, has_frame_base); |
77145576 JK |
6980 | else |
6981 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 6982 | &vstart, has_frame_base); |
77145576 | 6983 | } |
b4eb7656 | 6984 | else |
77145576 JK |
6985 | { |
6986 | if (is_dwo) | |
6987 | warn (_("DWO is not yet supported.\n")); | |
6988 | else | |
6989 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
6990 | &vstart, has_frame_base); |
6991 | } | |
6992 | ||
6993 | /* FIXME: this arrangement is quite simplistic. Nothing | |
6994 | requires locview lists to be adjacent to corresponding | |
6995 | loclists, and a single loclist could be augmented by | |
6996 | different locview lists, and vice-versa, unlikely as it | |
6997 | is that it would make sense to do so. Hopefully we'll | |
6998 | have view pair support built into loclists before we ever | |
6999 | need to address all these possibilities. */ | |
7000 | if (adjacent_view_loclists && vnext | |
7001 | && vnext != start && vstart != next) | |
7002 | { | |
7003 | adjacent_view_loclists = 0; | |
7004 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 7005 | } |
9f272209 AO |
7006 | |
7007 | if (vnext && vnext == start) | |
7008 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
7009 | } |
7010 | } | |
031cd65f | 7011 | |
4723351a | 7012 | if (start < section->start + section->size) |
d3a49aa8 AM |
7013 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
7014 | "There are %ld unused bytes at the end of section %s\n", | |
7015 | (long) (section->start + section->size - start)), | |
4723351a | 7016 | (long) (section->start + section->size - start), section->name); |
98fb390a | 7017 | putchar ('\n'); |
51d0d03f | 7018 | free (array); |
19e6b90e L |
7019 | return 1; |
7020 | } | |
7021 | ||
7022 | static int | |
7023 | display_debug_str (struct dwarf_section *section, | |
7024 | void *file ATTRIBUTE_UNUSED) | |
7025 | { | |
7026 | unsigned char *start = section->start; | |
7027 | unsigned long bytes = section->size; | |
7028 | dwarf_vma addr = section->address; | |
7029 | ||
7030 | if (bytes == 0) | |
7031 | { | |
7032 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7033 | return 0; | |
7034 | } | |
7035 | ||
dda8d76d | 7036 | introduce (section, FALSE); |
19e6b90e L |
7037 | |
7038 | while (bytes) | |
7039 | { | |
7040 | int j; | |
7041 | int k; | |
7042 | int lbytes; | |
7043 | ||
7044 | lbytes = (bytes > 16 ? 16 : bytes); | |
7045 | ||
7046 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
7047 | ||
7048 | for (j = 0; j < 16; j++) | |
7049 | { | |
7050 | if (j < lbytes) | |
7051 | printf ("%2.2x", start[j]); | |
7052 | else | |
7053 | printf (" "); | |
7054 | ||
7055 | if ((j & 3) == 3) | |
7056 | printf (" "); | |
7057 | } | |
7058 | ||
7059 | for (j = 0; j < lbytes; j++) | |
7060 | { | |
7061 | k = start[j]; | |
7062 | if (k >= ' ' && k < 0x80) | |
7063 | printf ("%c", k); | |
7064 | else | |
7065 | printf ("."); | |
7066 | } | |
7067 | ||
7068 | putchar ('\n'); | |
7069 | ||
7070 | start += lbytes; | |
7071 | addr += lbytes; | |
7072 | bytes -= lbytes; | |
7073 | } | |
7074 | ||
7075 | putchar ('\n'); | |
7076 | ||
7077 | return 1; | |
7078 | } | |
7079 | ||
19e6b90e L |
7080 | static int |
7081 | display_debug_info (struct dwarf_section *section, void *file) | |
7082 | { | |
d85bf2ba | 7083 | return process_debug_info (section, file, section->abbrev_sec, FALSE, FALSE); |
19e6b90e L |
7084 | } |
7085 | ||
2b6f5997 CC |
7086 | static int |
7087 | display_debug_types (struct dwarf_section *section, void *file) | |
7088 | { | |
d85bf2ba | 7089 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
6f875884 TG |
7090 | } |
7091 | ||
7092 | static int | |
7093 | display_trace_info (struct dwarf_section *section, void *file) | |
7094 | { | |
d85bf2ba | 7095 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
2b6f5997 | 7096 | } |
19e6b90e L |
7097 | |
7098 | static int | |
7099 | display_debug_aranges (struct dwarf_section *section, | |
7100 | void *file ATTRIBUTE_UNUSED) | |
7101 | { | |
7102 | unsigned char *start = section->start; | |
7103 | unsigned char *end = start + section->size; | |
7104 | ||
dda8d76d | 7105 | introduce (section, FALSE); |
19e6b90e | 7106 | |
6e3d6dc1 NC |
7107 | /* It does not matter if this load fails, |
7108 | we test for that later on. */ | |
7109 | load_debug_info (file); | |
7110 | ||
19e6b90e L |
7111 | while (start < end) |
7112 | { | |
7113 | unsigned char *hdrptr; | |
7114 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 7115 | unsigned char *addr_ranges; |
2d9472a2 NC |
7116 | dwarf_vma length; |
7117 | dwarf_vma address; | |
e98fdf1a | 7118 | unsigned long sec_off; |
53b8873b | 7119 | unsigned char address_size; |
19e6b90e | 7120 | int excess; |
bf5117e3 NC |
7121 | unsigned int offset_size; |
7122 | unsigned int initial_length_size; | |
19e6b90e L |
7123 | |
7124 | hdrptr = start; | |
7125 | ||
0c588247 | 7126 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
7127 | if (arange.ar_length == 0xffffffff) |
7128 | { | |
0c588247 | 7129 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
7130 | offset_size = 8; |
7131 | initial_length_size = 12; | |
7132 | } | |
7133 | else | |
7134 | { | |
7135 | offset_size = 4; | |
7136 | initial_length_size = 4; | |
7137 | } | |
7138 | ||
e98fdf1a AM |
7139 | sec_off = hdrptr - section->start; |
7140 | if (sec_off + arange.ar_length < sec_off | |
7141 | || sec_off + arange.ar_length > section->size) | |
7142 | { | |
7143 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
7144 | section->name, | |
7145 | sec_off - initial_length_size, | |
7146 | dwarf_vmatoa ("x", arange.ar_length)); | |
7147 | break; | |
7148 | } | |
7149 | ||
0c588247 NC |
7150 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
7151 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 7152 | |
6e3d6dc1 NC |
7153 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
7154 | && num_debug_info_entries > 0 | |
7155 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
7156 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 7157 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 7158 | |
0c588247 NC |
7159 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
7160 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
7161 | |
7162 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
7163 | { | |
67f101ee NC |
7164 | /* PR 19872: A version number of 0 probably means that there is |
7165 | padding at the end of the .debug_aranges section. Gold puts | |
7166 | it there when performing an incremental link, for example. | |
7167 | So do not generate a warning in this case. */ | |
7168 | if (arange.ar_version) | |
7169 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
7170 | break; |
7171 | } | |
7172 | ||
47704ddf KT |
7173 | printf (_(" Length: %ld\n"), |
7174 | (long) arange.ar_length); | |
19e6b90e | 7175 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
7176 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
7177 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
7178 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
7179 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
7180 | ||
53b8873b NC |
7181 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
7182 | ||
f41e4712 NC |
7183 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
7184 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
7185 | { |
7186 | error (_("Invalid address size in %s section!\n"), | |
7187 | section->name); | |
7188 | break; | |
7189 | } | |
7190 | ||
53b8873b NC |
7191 | /* The DWARF spec does not require that the address size be a power |
7192 | of two, but we do. This will have to change if we ever encounter | |
7193 | an uneven architecture. */ | |
7194 | if ((address_size & (address_size - 1)) != 0) | |
7195 | { | |
7196 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
7197 | break; | |
7198 | } | |
cecf136e | 7199 | |
209c9a13 NC |
7200 | if (address_size > 4) |
7201 | printf (_("\n Address Length\n")); | |
7202 | else | |
7203 | printf (_("\n Address Length\n")); | |
19e6b90e | 7204 | |
91d6fa6a | 7205 | addr_ranges = hdrptr; |
19e6b90e | 7206 | |
53b8873b NC |
7207 | /* Must pad to an alignment boundary that is twice the address size. */ |
7208 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 7209 | if (excess) |
91d6fa6a | 7210 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 7211 | |
e98fdf1a | 7212 | start += arange.ar_length + initial_length_size; |
1617e571 | 7213 | |
91d6fa6a | 7214 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 7215 | { |
0c588247 NC |
7216 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
7217 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 7218 | |
80c35038 | 7219 | printf (" "); |
2d9472a2 NC |
7220 | print_dwarf_vma (address, address_size); |
7221 | print_dwarf_vma (length, address_size); | |
7222 | putchar ('\n'); | |
19e6b90e | 7223 | } |
19e6b90e L |
7224 | } |
7225 | ||
7226 | printf ("\n"); | |
7227 | ||
7228 | return 1; | |
7229 | } | |
7230 | ||
4723351a CC |
7231 | /* Comparison function for qsort. */ |
7232 | static int | |
7233 | comp_addr_base (const void * v0, const void * v1) | |
7234 | { | |
d367307b AM |
7235 | debug_info *info0 = *(debug_info **) v0; |
7236 | debug_info *info1 = *(debug_info **) v1; | |
4723351a CC |
7237 | return info0->addr_base - info1->addr_base; |
7238 | } | |
7239 | ||
7240 | /* Display the debug_addr section. */ | |
7241 | static int | |
7242 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 7243 | void *file) |
4723351a CC |
7244 | { |
7245 | debug_info **debug_addr_info; | |
7246 | unsigned char *entry; | |
7247 | unsigned char *end; | |
7248 | unsigned int i; | |
7249 | unsigned int count; | |
7250 | ||
7251 | if (section->size == 0) | |
7252 | { | |
7253 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7254 | return 0; | |
7255 | } | |
7256 | ||
7257 | if (load_debug_info (file) == 0) | |
7258 | { | |
7259 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7260 | section->name); | |
7261 | return 0; | |
7262 | } | |
7263 | ||
dda8d76d | 7264 | introduce (section, FALSE); |
4723351a | 7265 | |
1306a742 NC |
7266 | /* PR 17531: file: cf38d01b. |
7267 | We use xcalloc because a corrupt file may not have initialised all of the | |
7268 | fields in the debug_info structure, which means that the sort below might | |
7269 | try to move uninitialised data. */ | |
7270 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 7271 | sizeof (debug_info *)); |
4723351a CC |
7272 | |
7273 | count = 0; | |
7274 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 7275 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
7276 | { |
7277 | /* PR 17531: file: cf38d01b. */ | |
7278 | if (debug_information[i].addr_base >= section->size) | |
7279 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
7280 | (unsigned long) debug_information[i].addr_base, i); | |
7281 | else | |
7282 | debug_addr_info [count++] = debug_information + i; | |
7283 | } | |
4723351a CC |
7284 | |
7285 | /* Add a sentinel to make iteration convenient. */ | |
7286 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
7287 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 7288 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 7289 | |
4723351a CC |
7290 | for (i = 0; i < count; i++) |
7291 | { | |
7292 | unsigned int idx; | |
fab128ef | 7293 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
7294 | |
7295 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 7296 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 7297 | |
fab128ef | 7298 | printf (_("\tIndex\tAddress\n")); |
4723351a CC |
7299 | entry = section->start + debug_addr_info [i]->addr_base; |
7300 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
7301 | idx = 0; | |
7302 | while (entry < end) | |
b4eb7656 AM |
7303 | { |
7304 | dwarf_vma base = byte_get (entry, address_size); | |
7305 | printf (_("\t%d:\t"), idx); | |
7306 | print_dwarf_vma (base, address_size); | |
7307 | printf ("\n"); | |
7308 | entry += address_size; | |
7309 | idx++; | |
7310 | } | |
4723351a CC |
7311 | } |
7312 | printf ("\n"); | |
7313 | ||
7314 | free (debug_addr_info); | |
7315 | return 1; | |
7316 | } | |
7317 | ||
7318 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 7319 | |
4723351a CC |
7320 | static int |
7321 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 7322 | void *file ATTRIBUTE_UNUSED) |
4723351a | 7323 | { |
9f27c364 HPN |
7324 | unsigned long idx; |
7325 | ||
4723351a CC |
7326 | if (section->size == 0) |
7327 | { | |
7328 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7329 | return 0; | |
7330 | } | |
e4b7104b NC |
7331 | |
7332 | unsigned char *start = section->start; | |
7333 | unsigned char *end = start + section->size; | |
7334 | unsigned char *curr = start; | |
7335 | ||
39f381cb NC |
7336 | const char * suffix = strrchr (section->name, '.'); |
7337 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
7338 | ||
7339 | if (dwo) | |
7340 | load_debug_section_with_follow (str_dwo, file); | |
7341 | else | |
7342 | load_debug_section_with_follow (str, file); | |
e4b7104b NC |
7343 | |
7344 | introduce (section, FALSE); | |
7345 | ||
7346 | while (curr < end) | |
7347 | { | |
7348 | dwarf_vma length; | |
7349 | dwarf_vma entry_length; | |
7350 | ||
7351 | SAFE_BYTE_GET_AND_INC (length, curr, 4, end); | |
7352 | /* FIXME: We assume that this means 64-bit DWARF is being used. */ | |
7353 | if (length == 0xffffffff) | |
7354 | { | |
7355 | SAFE_BYTE_GET (length, curr, 8, end); | |
7356 | entry_length = 8; | |
7357 | } | |
7358 | else | |
7359 | entry_length = 4; | |
7360 | ||
39f381cb NC |
7361 | if (length == 0) |
7362 | { | |
7363 | /* This is probably an old style .debug_str_offset section which | |
7364 | just contains offsets and no header (and the first offset is 0). */ | |
7365 | length = section->size; | |
7366 | curr = section->start; | |
e4b7104b | 7367 | |
39f381cb NC |
7368 | printf (_(" Length: %#lx\n"), (unsigned long) length); |
7369 | printf (_(" Index Offset [String]\n")); | |
7370 | } | |
7371 | else | |
7372 | { | |
7373 | int version; | |
7374 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); | |
7375 | if (version != 5) | |
7376 | warn (_("Unexpected version number in str_offset header: %#x\n"), version); | |
7377 | ||
7378 | int padding; | |
7379 | SAFE_BYTE_GET_AND_INC (padding, curr, 2, end); | |
7380 | if (padding != 0) | |
7381 | warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding); | |
7382 | ||
7383 | printf (_(" Length: %#lx\n"), (unsigned long) length); | |
7384 | printf (_(" Version: %#lx\n"), (unsigned long) version); | |
7385 | printf (_(" Index Offset [String]\n")); | |
7386 | } | |
e4b7104b | 7387 | |
9f27c364 | 7388 | for (idx = 0; length >= entry_length && curr < end; idx++) |
e4b7104b NC |
7389 | { |
7390 | dwarf_vma offset; | |
7391 | const unsigned char * string; | |
7392 | ||
7393 | SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, end); | |
39f381cb NC |
7394 | if (dwo) |
7395 | string = (const unsigned char *) | |
9f27c364 | 7396 | fetch_indexed_string (idx, NULL, entry_length, dwo); |
39f381cb NC |
7397 | else |
7398 | string = fetch_indirect_string (offset); | |
7399 | ||
9f27c364 | 7400 | printf (" %8lu %8s %s\n", idx, dwarf_vmatoa ("x", offset), |
e4b7104b NC |
7401 | string); |
7402 | } | |
7403 | } | |
39f381cb | 7404 | |
4723351a CC |
7405 | return 1; |
7406 | } | |
7407 | ||
01a8f077 JK |
7408 | /* Each debug_information[x].range_lists[y] gets this representation for |
7409 | sorting purposes. */ | |
7410 | ||
7411 | struct range_entry | |
467c65bc NC |
7412 | { |
7413 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 7414 | dwarf_vma ranges_offset; |
01a8f077 | 7415 | |
467c65bc NC |
7416 | /* Original debug_information to find parameters of the data. */ |
7417 | debug_info *debug_info_p; | |
7418 | }; | |
01a8f077 JK |
7419 | |
7420 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
7421 | ||
7422 | static int | |
7423 | range_entry_compar (const void *ap, const void *bp) | |
7424 | { | |
3f5e193b NC |
7425 | const struct range_entry *a_re = (const struct range_entry *) ap; |
7426 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
7427 | const dwarf_vma a = a_re->ranges_offset; |
7428 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
7429 | |
7430 | return (a > b) - (b > a); | |
7431 | } | |
7432 | ||
77145576 JK |
7433 | static void |
7434 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
7435 | unsigned int pointer_size, unsigned long offset, | |
7436 | unsigned long base_address) | |
7437 | { | |
7438 | while (start < finish) | |
7439 | { | |
7440 | dwarf_vma begin; | |
7441 | dwarf_vma end; | |
7442 | ||
7443 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7444 | if (start >= finish) | |
7445 | break; | |
7446 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7447 | ||
7448 | printf (" %8.8lx ", offset); | |
7449 | ||
7450 | if (begin == 0 && end == 0) | |
7451 | { | |
7452 | printf (_("<End of list>\n")); | |
7453 | break; | |
7454 | } | |
7455 | ||
7456 | /* Check base address specifiers. */ | |
7457 | if (is_max_address (begin, pointer_size) | |
7458 | && !is_max_address (end, pointer_size)) | |
7459 | { | |
7460 | base_address = end; | |
7461 | print_dwarf_vma (begin, pointer_size); | |
7462 | print_dwarf_vma (end, pointer_size); | |
7463 | printf ("(base address)\n"); | |
7464 | continue; | |
7465 | } | |
7466 | ||
7467 | print_dwarf_vma (begin + base_address, pointer_size); | |
7468 | print_dwarf_vma (end + base_address, pointer_size); | |
7469 | ||
7470 | if (begin == end) | |
7471 | fputs (_("(start == end)"), stdout); | |
7472 | else if (begin > end) | |
7473 | fputs (_("(start > end)"), stdout); | |
7474 | ||
7475 | putchar ('\n'); | |
7476 | } | |
7477 | } | |
7478 | ||
7479 | static void | |
7480 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
7481 | unsigned int pointer_size, unsigned long offset, | |
7482 | unsigned long base_address) | |
7483 | { | |
7484 | unsigned char *next = start; | |
7485 | ||
7486 | while (1) | |
7487 | { | |
7488 | unsigned long off = offset + (start - next); | |
7489 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
7490 | /* Initialize it due to a false compiler warning. */ |
7491 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
7492 | |
7493 | if (start + 1 > finish) | |
7494 | { | |
7495 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
7496 | offset); | |
7497 | break; | |
7498 | } | |
7499 | ||
7500 | printf (" %8.8lx ", off); | |
7501 | ||
7502 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
7503 | ||
7504 | switch (rlet) | |
7505 | { | |
7506 | case DW_RLE_end_of_list: | |
7507 | printf (_("<End of list>\n")); | |
7508 | break; | |
7509 | case DW_RLE_base_address: | |
7510 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
7511 | print_dwarf_vma (base_address, pointer_size); | |
7512 | printf (_("(base address)\n")); | |
7513 | break; | |
7514 | case DW_RLE_start_length: | |
7515 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
cd30bcef | 7516 | READ_ULEB (length, start, finish); |
77145576 JK |
7517 | end = begin + length; |
7518 | break; | |
7519 | case DW_RLE_offset_pair: | |
cd30bcef AM |
7520 | READ_ULEB (begin, start, finish); |
7521 | READ_ULEB (end, start, finish); | |
77145576 JK |
7522 | break; |
7523 | case DW_RLE_start_end: | |
7524 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7525 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7526 | break; | |
7527 | default: | |
7528 | error (_("Invalid range list entry type %d\n"), rlet); | |
7529 | rlet = DW_RLE_end_of_list; | |
7530 | break; | |
7531 | } | |
7532 | if (rlet == DW_RLE_end_of_list) | |
7533 | break; | |
7534 | if (rlet == DW_RLE_base_address) | |
7535 | continue; | |
7536 | ||
4d932715 BE |
7537 | /* Only a DW_RLE_offset_pair needs the base address added. */ |
7538 | if (rlet == DW_RLE_offset_pair) | |
7539 | { | |
7540 | begin += base_address; | |
7541 | end += base_address; | |
7542 | } | |
7543 | ||
7544 | print_dwarf_vma (begin, pointer_size); | |
7545 | print_dwarf_vma (end, pointer_size); | |
77145576 JK |
7546 | |
7547 | if (begin == end) | |
7548 | fputs (_("(start == end)"), stdout); | |
7549 | else if (begin > end) | |
7550 | fputs (_("(start > end)"), stdout); | |
7551 | ||
7552 | putchar ('\n'); | |
7553 | } | |
7554 | } | |
7555 | ||
19e6b90e L |
7556 | static int |
7557 | display_debug_ranges (struct dwarf_section *section, | |
7558 | void *file ATTRIBUTE_UNUSED) | |
7559 | { | |
7560 | unsigned char *start = section->start; | |
a2ff7a4b | 7561 | unsigned char *last_start = start; |
f6f0e17b | 7562 | unsigned long bytes = section->size; |
19e6b90e | 7563 | unsigned char *section_begin = start; |
f6f0e17b | 7564 | unsigned char *finish = start + bytes; |
01a8f077 JK |
7565 | unsigned int num_range_list, i; |
7566 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
7567 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
7568 | /* Initialize it due to a false compiler warning. */ | |
7569 | unsigned char address_size = 0; | |
cb4c35cf | 7570 | dwarf_vma last_offset = 0; |
19e6b90e | 7571 | |
19e6b90e L |
7572 | if (bytes == 0) |
7573 | { | |
7574 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7575 | return 0; | |
7576 | } | |
7577 | ||
77145576 JK |
7578 | if (is_rnglists) |
7579 | { | |
7580 | dwarf_vma initial_length; | |
7581 | unsigned int initial_length_size; | |
7582 | unsigned char segment_selector_size; | |
7583 | unsigned int offset_size, offset_entry_count; | |
7584 | unsigned short version; | |
7585 | ||
7586 | /* Get and check the length of the block. */ | |
7587 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
7588 | ||
7589 | if (initial_length == 0xffffffff) | |
7590 | { | |
7591 | /* This section is 64-bit DWARF 3. */ | |
7592 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
7593 | offset_size = 8; | |
7594 | initial_length_size = 12; | |
7595 | } | |
7596 | else | |
7597 | { | |
7598 | offset_size = 4; | |
7599 | initial_length_size = 4; | |
7600 | } | |
7601 | ||
7602 | if (initial_length + initial_length_size > section->size) | |
7603 | { | |
7604 | /* If the length field has a relocation against it, then we should | |
7605 | not complain if it is inaccurate (and probably negative). | |
7606 | It is copied from .debug_line handling code. */ | |
7607 | if (reloc_at (section, (start - section->start) - offset_size)) | |
7608 | { | |
7609 | initial_length = (finish - start) - initial_length_size; | |
7610 | } | |
7611 | else | |
7612 | { | |
7613 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
7614 | (long) initial_length); | |
7615 | return 0; | |
7616 | } | |
7617 | } | |
7618 | ||
7619 | /* Get and check the version number. */ | |
7620 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
7621 | ||
7622 | if (version != 5) | |
7623 | { | |
7624 | warn (_("Only DWARF version 5 debug_rnglists info " | |
7625 | "is currently supported.\n")); | |
7626 | return 0; | |
7627 | } | |
7628 | ||
7629 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
7630 | ||
7631 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
7632 | if (segment_selector_size != 0) | |
7633 | { | |
7634 | warn (_("The %s section contains " | |
7635 | "unsupported segment selector size: %d.\n"), | |
7636 | section->name, segment_selector_size); | |
7637 | return 0; | |
7638 | } | |
7639 | ||
7640 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
7641 | if (offset_entry_count != 0) | |
7642 | { | |
7643 | warn (_("The %s section contains " | |
7644 | "unsupported offset entry count: %u.\n"), | |
7645 | section->name, offset_entry_count); | |
7646 | return 0; | |
7647 | } | |
7648 | } | |
7649 | ||
1febe64d NC |
7650 | if (load_debug_info (file) == 0) |
7651 | { | |
7652 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7653 | section->name); | |
7654 | return 0; | |
7655 | } | |
19e6b90e | 7656 | |
01a8f077 | 7657 | num_range_list = 0; |
19e6b90e | 7658 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 7659 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 7660 | |
01a8f077 | 7661 | if (num_range_list == 0) |
4723351a CC |
7662 | { |
7663 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 7664 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
7665 | printf (_("No range lists in .debug_info section.\n")); |
7666 | return 1; | |
7667 | } | |
19e6b90e | 7668 | |
3f5e193b NC |
7669 | range_entries = (struct range_entry *) |
7670 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 7671 | range_entry_fill = range_entries; |
19e6b90e | 7672 | |
01a8f077 JK |
7673 | for (i = 0; i < num_debug_info_entries; i++) |
7674 | { | |
7675 | debug_info *debug_info_p = &debug_information[i]; | |
7676 | unsigned int j; | |
7677 | ||
7678 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
7679 | { | |
7680 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
7681 | range_entry_fill->debug_info_p = debug_info_p; | |
7682 | range_entry_fill++; | |
19e6b90e L |
7683 | } |
7684 | } | |
7685 | ||
01a8f077 JK |
7686 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
7687 | range_entry_compar); | |
19e6b90e | 7688 | |
d493b283 | 7689 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 7690 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 7691 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 7692 | |
dda8d76d NC |
7693 | introduce (section, FALSE); |
7694 | ||
19e6b90e L |
7695 | printf (_(" Offset Begin End\n")); |
7696 | ||
01a8f077 | 7697 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 7698 | { |
01a8f077 JK |
7699 | struct range_entry *range_entry = &range_entries[i]; |
7700 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 7701 | unsigned int pointer_size; |
359ca075 | 7702 | dwarf_vma offset; |
01a8f077 | 7703 | unsigned char *next; |
359ca075 | 7704 | dwarf_vma base_address; |
19e6b90e | 7705 | |
77145576 | 7706 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 7707 | offset = range_entry->ranges_offset; |
01a8f077 JK |
7708 | next = section_begin + offset; |
7709 | base_address = debug_info_p->base_address; | |
cecf136e | 7710 | |
f41e4712 NC |
7711 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
7712 | if (pointer_size < 2 || pointer_size > 8) | |
7713 | { | |
7714 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 7715 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
7716 | continue; |
7717 | } | |
b4eb7656 | 7718 | |
d11ae95e NC |
7719 | if (next < section_begin || next >= finish) |
7720 | { | |
7721 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
7722 | (unsigned long) offset, i); | |
7723 | continue; | |
7724 | } | |
7725 | ||
cb4c35cf AB |
7726 | /* If multiple DWARF entities reference the same range then we will |
7727 | have multiple entries in the `range_entries' list for the same | |
7728 | offset. Thanks to the sort above these will all be consecutive in | |
7729 | the `range_entries' list, so we can easily ignore duplicates | |
7730 | here. */ | |
7731 | if (i > 0 && last_offset == offset) | |
7732 | continue; | |
7733 | last_offset = offset; | |
7734 | ||
4723351a | 7735 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 7736 | { |
01a8f077 JK |
7737 | if (start < next) |
7738 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
7739 | (unsigned long) (start - section_begin), | |
7740 | (unsigned long) (next - section_begin), section->name); | |
7741 | else if (start > next) | |
a2ff7a4b AM |
7742 | { |
7743 | if (next == last_start) | |
7744 | continue; | |
7745 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
7746 | (unsigned long) (start - section_begin), | |
7747 | (unsigned long) (next - section_begin), section->name); | |
7748 | } | |
01a8f077 | 7749 | } |
d11ae95e | 7750 | |
01a8f077 | 7751 | start = next; |
a2ff7a4b | 7752 | last_start = next; |
19e6b90e | 7753 | |
77145576 JK |
7754 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
7755 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
7756 | } |
7757 | putchar ('\n'); | |
01a8f077 JK |
7758 | |
7759 | free (range_entries); | |
7760 | ||
19e6b90e L |
7761 | return 1; |
7762 | } | |
7763 | ||
7764 | typedef struct Frame_Chunk | |
7765 | { | |
7766 | struct Frame_Chunk *next; | |
7767 | unsigned char *chunk_start; | |
a1165289 | 7768 | unsigned int ncols; |
19e6b90e L |
7769 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
7770 | short int *col_type; | |
7771 | int *col_offset; | |
7772 | char *augmentation; | |
7773 | unsigned int code_factor; | |
7774 | int data_factor; | |
bf5117e3 NC |
7775 | dwarf_vma pc_begin; |
7776 | dwarf_vma pc_range; | |
32ef3000 | 7777 | unsigned int cfa_reg; |
c8071705 | 7778 | dwarf_vma cfa_offset; |
a1165289 | 7779 | unsigned int ra; |
19e6b90e L |
7780 | unsigned char fde_encoding; |
7781 | unsigned char cfa_exp; | |
604282a7 JJ |
7782 | unsigned char ptr_size; |
7783 | unsigned char segment_size; | |
19e6b90e L |
7784 | } |
7785 | Frame_Chunk; | |
7786 | ||
1296bc99 AB |
7787 | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); |
7788 | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; | |
665ce1f6 L |
7789 | static const char *const *dwarf_regnames; |
7790 | static unsigned int dwarf_regnames_count; | |
7791 | ||
1296bc99 | 7792 | |
19e6b90e L |
7793 | /* A marker for a col_type that means this column was never referenced |
7794 | in the frame info. */ | |
7795 | #define DW_CFA_unreferenced (-1) | |
7796 | ||
a1165289 | 7797 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
7798 | -1 for invalid reg. */ |
7799 | ||
7800 | static int | |
7801 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 7802 | { |
a1165289 | 7803 | unsigned int prev = fc->ncols; |
19e6b90e | 7804 | |
665ce1f6 L |
7805 | if (reg < (unsigned int) fc->ncols) |
7806 | return 0; | |
7807 | ||
d9acf707 | 7808 | if (dwarf_regnames_count > 0 |
665ce1f6 L |
7809 | && reg > dwarf_regnames_count) |
7810 | return -1; | |
19e6b90e L |
7811 | |
7812 | fc->ncols = reg + 1; | |
a1165289 NC |
7813 | /* PR 17512: file: 10450-2643-0.004. |
7814 | If reg == -1 then this can happen... */ | |
7815 | if (fc->ncols == 0) | |
7816 | return -1; | |
7817 | ||
06614111 | 7818 | /* PR 17512: file: 2844a11d. */ |
d9acf707 | 7819 | if (fc->ncols > 1024 && dwarf_regnames_count == 0) |
06614111 NC |
7820 | { |
7821 | error (_("Unfeasibly large register number: %u\n"), reg); | |
7822 | fc->ncols = 0; | |
7823 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
7824 | we ever encounter a valid binary that exceeds it. */ | |
7825 | return -1; | |
7826 | } | |
7827 | ||
3f5e193b | 7828 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 7829 | sizeof (short int)); |
3f5e193b | 7830 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 7831 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
7832 | if (fc->col_type == NULL || fc->col_offset == NULL) |
7833 | { | |
7834 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
7835 | fc->ncols); | |
7836 | fc->ncols = 0; | |
7837 | return -1; | |
7838 | } | |
19e6b90e L |
7839 | |
7840 | while (prev < fc->ncols) | |
7841 | { | |
7842 | fc->col_type[prev] = DW_CFA_unreferenced; | |
7843 | fc->col_offset[prev] = 0; | |
7844 | prev++; | |
7845 | } | |
665ce1f6 | 7846 | return 1; |
19e6b90e L |
7847 | } |
7848 | ||
2dc4cec1 L |
7849 | static const char *const dwarf_regnames_i386[] = |
7850 | { | |
43234a1e L |
7851 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
7852 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7853 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7854 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
7855 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
7856 | NULL, NULL, /* 19 - 20 */ | |
7857 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
7858 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
7859 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
7860 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
7861 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
7862 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7863 | "tr", "ldtr", /* 48 - 49 */ | |
7864 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7865 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7866 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7867 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7868 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7869 | NULL, NULL, NULL, /* 90 - 92 */ | |
7870 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
7871 | }; |
7872 | ||
3d875af5 L |
7873 | static const char *const dwarf_regnames_iamcu[] = |
7874 | { | |
7875 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
7876 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7877 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7878 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
7879 | NULL, NULL, /* 19 - 20 */ | |
7880 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
7881 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
7882 | NULL, NULL, NULL, /* 37 - 39 */ | |
7883 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7884 | "tr", "ldtr", /* 48 - 49 */ | |
7885 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7886 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7887 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7888 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7889 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7890 | NULL, NULL, NULL, /* 90 - 92 */ | |
7891 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
7892 | }; | |
7893 | ||
99f6fdd9 | 7894 | static void |
b129eb0e RH |
7895 | init_dwarf_regnames_i386 (void) |
7896 | { | |
7897 | dwarf_regnames = dwarf_regnames_i386; | |
7898 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
1296bc99 | 7899 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
7900 | } |
7901 | ||
99f6fdd9 | 7902 | static void |
3d875af5 L |
7903 | init_dwarf_regnames_iamcu (void) |
7904 | { | |
7905 | dwarf_regnames = dwarf_regnames_iamcu; | |
7906 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
1296bc99 | 7907 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
3d875af5 L |
7908 | } |
7909 | ||
2dc4cec1 L |
7910 | static const char *const dwarf_regnames_x86_64[] = |
7911 | { | |
7912 | "rax", "rdx", "rcx", "rbx", | |
7913 | "rsi", "rdi", "rbp", "rsp", | |
7914 | "r8", "r9", "r10", "r11", | |
7915 | "r12", "r13", "r14", "r15", | |
7916 | "rip", | |
7917 | "xmm0", "xmm1", "xmm2", "xmm3", | |
7918 | "xmm4", "xmm5", "xmm6", "xmm7", | |
7919 | "xmm8", "xmm9", "xmm10", "xmm11", | |
7920 | "xmm12", "xmm13", "xmm14", "xmm15", | |
7921 | "st0", "st1", "st2", "st3", | |
7922 | "st4", "st5", "st6", "st7", | |
7923 | "mm0", "mm1", "mm2", "mm3", | |
7924 | "mm4", "mm5", "mm6", "mm7", | |
7925 | "rflags", | |
7926 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
7927 | "fs.base", "gs.base", NULL, NULL, | |
7928 | "tr", "ldtr", | |
43234a1e L |
7929 | "mxcsr", "fcw", "fsw", |
7930 | "xmm16", "xmm17", "xmm18", "xmm19", | |
7931 | "xmm20", "xmm21", "xmm22", "xmm23", | |
7932 | "xmm24", "xmm25", "xmm26", "xmm27", | |
7933 | "xmm28", "xmm29", "xmm30", "xmm31", | |
7934 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
7935 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
7936 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
7937 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
7938 | NULL, NULL, NULL, /* 115 - 117 */ | |
7939 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
7940 | }; |
7941 | ||
99f6fdd9 | 7942 | static void |
b129eb0e RH |
7943 | init_dwarf_regnames_x86_64 (void) |
7944 | { | |
7945 | dwarf_regnames = dwarf_regnames_x86_64; | |
7946 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
1296bc99 | 7947 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
7948 | } |
7949 | ||
4ee22035 RH |
7950 | static const char *const dwarf_regnames_aarch64[] = |
7951 | { | |
b4eb7656 AM |
7952 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
7953 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
7954 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
7955 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
7956 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
fab7c86e TC |
7957 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
7958 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", | |
7959 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", | |
b4eb7656 AM |
7960 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
7961 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
7962 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
7963 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
fab7c86e TC |
7964 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
7965 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", | |
7966 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", | |
7967 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", | |
4ee22035 RH |
7968 | }; |
7969 | ||
99f6fdd9 | 7970 | static void |
4ee22035 RH |
7971 | init_dwarf_regnames_aarch64 (void) |
7972 | { | |
7973 | dwarf_regnames = dwarf_regnames_aarch64; | |
7974 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
1296bc99 | 7975 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
4ee22035 RH |
7976 | } |
7977 | ||
d6bb17b0 AA |
7978 | static const char *const dwarf_regnames_s390[] = |
7979 | { | |
7980 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
7981 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7982 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7983 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
7984 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
7985 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
7986 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
7987 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
7988 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
7989 | "pswm", "pswa", | |
7990 | NULL, NULL, | |
7991 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
7992 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
7993 | }; | |
7994 | ||
99f6fdd9 | 7995 | static void |
d6bb17b0 AA |
7996 | init_dwarf_regnames_s390 (void) |
7997 | { | |
7998 | dwarf_regnames = dwarf_regnames_s390; | |
7999 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
1296bc99 | 8000 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
d6bb17b0 AA |
8001 | } |
8002 | ||
5bb0830d AB |
8003 | static const char *const dwarf_regnames_riscv[] = |
8004 | { | |
8005 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
8006 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
8007 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
8008 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
8009 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
8010 | "fs0", "fs1", /* 40 - 41 */ | |
8011 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
8012 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
8013 | "fs10", "fs11", /* 58 - 59 */ | |
8014 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
8015 | }; | |
8016 | ||
4762fe62 AB |
8017 | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles |
8018 | the large number of CSRs. */ | |
8019 | ||
8020 | static const char * | |
8021 | regname_internal_riscv (unsigned int regno) | |
8022 | { | |
8023 | const char *name = NULL; | |
8024 | ||
8025 | /* Lookup in the table first, this covers GPR and FPR. */ | |
8026 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) | |
8027 | name = dwarf_regnames_riscv [regno]; | |
8028 | else if (regno >= 4096 && regno <= 8191) | |
8029 | { | |
8030 | /* This might be a CSR, these live in a sparse number space from 4096 | |
8031 | to 8191 These numbers are defined in the RISC-V ELF ABI | |
8032 | document. */ | |
8033 | switch (regno) | |
8034 | { | |
8f595e9b NC |
8035 | #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \ |
8036 | case VALUE + 4096: name = #NAME; break; | |
4762fe62 AB |
8037 | #include "opcode/riscv-opc.h" |
8038 | #undef DECLARE_CSR | |
8039 | ||
8040 | default: | |
8041 | { | |
8042 | static char csr_name[10]; | |
8043 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); | |
8044 | name = csr_name; | |
8045 | } | |
8046 | break; | |
8047 | } | |
8048 | } | |
8049 | ||
8050 | return name; | |
8051 | } | |
8052 | ||
99f6fdd9 | 8053 | static void |
5bb0830d AB |
8054 | init_dwarf_regnames_riscv (void) |
8055 | { | |
4762fe62 AB |
8056 | dwarf_regnames = NULL; |
8057 | dwarf_regnames_count = 8192; | |
8058 | dwarf_regnames_lookup_func = regname_internal_riscv; | |
5bb0830d AB |
8059 | } |
8060 | ||
2dc4cec1 | 8061 | void |
955ff7fc | 8062 | init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) |
2dc4cec1 | 8063 | { |
1296bc99 AB |
8064 | dwarf_regnames_lookup_func = NULL; |
8065 | ||
2dc4cec1 L |
8066 | switch (e_machine) |
8067 | { | |
8068 | case EM_386: | |
b129eb0e | 8069 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
8070 | break; |
8071 | ||
3d875af5 L |
8072 | case EM_IAMCU: |
8073 | init_dwarf_regnames_iamcu (); | |
8074 | break; | |
8075 | ||
2dc4cec1 | 8076 | case EM_X86_64: |
7f502d6c | 8077 | case EM_L1OM: |
7a9068fe | 8078 | case EM_K1OM: |
b129eb0e | 8079 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
8080 | break; |
8081 | ||
4ee22035 RH |
8082 | case EM_AARCH64: |
8083 | init_dwarf_regnames_aarch64 (); | |
8084 | break; | |
8085 | ||
d6bb17b0 AA |
8086 | case EM_S390: |
8087 | init_dwarf_regnames_s390 (); | |
8088 | break; | |
8089 | ||
5bb0830d AB |
8090 | case EM_RISCV: |
8091 | init_dwarf_regnames_riscv (); | |
8092 | break; | |
8093 | ||
2dc4cec1 L |
8094 | default: |
8095 | break; | |
8096 | } | |
8097 | } | |
8098 | ||
229a22cf AB |
8099 | /* Initialize the DWARF register name lookup state based on the |
8100 | architecture and specific machine type of a BFD. */ | |
8101 | ||
8102 | void | |
8103 | init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, | |
8104 | unsigned long mach) | |
8105 | { | |
1296bc99 AB |
8106 | dwarf_regnames_lookup_func = NULL; |
8107 | ||
229a22cf AB |
8108 | switch (arch) |
8109 | { | |
8110 | case bfd_arch_i386: | |
8111 | switch (mach) | |
8112 | { | |
8113 | case bfd_mach_x86_64: | |
8114 | case bfd_mach_x86_64_intel_syntax: | |
229a22cf AB |
8115 | case bfd_mach_x64_32: |
8116 | case bfd_mach_x64_32_intel_syntax: | |
229a22cf AB |
8117 | init_dwarf_regnames_x86_64 (); |
8118 | break; | |
8119 | ||
8120 | default: | |
8121 | init_dwarf_regnames_i386 (); | |
8122 | break; | |
8123 | } | |
8124 | break; | |
8125 | ||
8126 | case bfd_arch_iamcu: | |
8127 | init_dwarf_regnames_iamcu (); | |
8128 | break; | |
8129 | ||
8130 | case bfd_arch_aarch64: | |
8131 | init_dwarf_regnames_aarch64(); | |
8132 | break; | |
8133 | ||
8134 | case bfd_arch_s390: | |
8135 | init_dwarf_regnames_s390 (); | |
8136 | break; | |
8137 | ||
8138 | case bfd_arch_riscv: | |
8139 | init_dwarf_regnames_riscv (); | |
8140 | break; | |
8141 | ||
8142 | default: | |
8143 | break; | |
8144 | } | |
8145 | } | |
8146 | ||
2dc4cec1 | 8147 | static const char * |
1296bc99 | 8148 | regname_internal_by_table_only (unsigned int regno) |
2dc4cec1 | 8149 | { |
1296bc99 | 8150 | if (dwarf_regnames != NULL |
2dc4cec1 L |
8151 | && regno < dwarf_regnames_count |
8152 | && dwarf_regnames [regno] != NULL) | |
1296bc99 AB |
8153 | return dwarf_regnames [regno]; |
8154 | ||
8155 | return NULL; | |
8156 | } | |
8157 | ||
8158 | static const char * | |
8159 | regname (unsigned int regno, int name_only_p) | |
8160 | { | |
8161 | static char reg[64]; | |
8162 | ||
8163 | const char *name = NULL; | |
8164 | ||
8165 | if (dwarf_regnames_lookup_func != NULL) | |
8166 | name = dwarf_regnames_lookup_func (regno); | |
8167 | ||
8168 | if (name != NULL) | |
2dc4cec1 | 8169 | { |
1296bc99 AB |
8170 | if (name_only_p) |
8171 | return name; | |
8172 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); | |
2dc4cec1 L |
8173 | } |
8174 | else | |
8175 | snprintf (reg, sizeof (reg), "r%d", regno); | |
8176 | return reg; | |
8177 | } | |
8178 | ||
19e6b90e | 8179 | static void |
a1165289 | 8180 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 8181 | { |
a1165289 | 8182 | unsigned int r; |
19e6b90e L |
8183 | char tmp[100]; |
8184 | ||
d8024a91 | 8185 | if (*max_regs != fc->ncols) |
19e6b90e L |
8186 | *max_regs = fc->ncols; |
8187 | ||
8188 | if (*need_col_headers) | |
8189 | { | |
8190 | *need_col_headers = 0; | |
8191 | ||
288f0ba2 | 8192 | printf ("%-*s CFA ", eh_addr_size * 2, " LOC"); |
19e6b90e L |
8193 | |
8194 | for (r = 0; r < *max_regs; r++) | |
8195 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
8196 | { | |
8197 | if (r == fc->ra) | |
50751e18 | 8198 | printf ("ra "); |
19e6b90e | 8199 | else |
2dc4cec1 | 8200 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
8201 | } |
8202 | ||
8203 | printf ("\n"); | |
8204 | } | |
8205 | ||
bf5117e3 | 8206 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
8207 | if (fc->cfa_exp) |
8208 | strcpy (tmp, "exp"); | |
8209 | else | |
c8071705 | 8210 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
8211 | printf ("%-8s ", tmp); |
8212 | ||
8213 | for (r = 0; r < fc->ncols; r++) | |
8214 | { | |
8215 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
8216 | { | |
8217 | switch (fc->col_type[r]) | |
8218 | { | |
8219 | case DW_CFA_undefined: | |
8220 | strcpy (tmp, "u"); | |
8221 | break; | |
8222 | case DW_CFA_same_value: | |
8223 | strcpy (tmp, "s"); | |
8224 | break; | |
8225 | case DW_CFA_offset: | |
8226 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
8227 | break; | |
12eae2d3 JJ |
8228 | case DW_CFA_val_offset: |
8229 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
8230 | break; | |
19e6b90e | 8231 | case DW_CFA_register: |
2dc4cec1 | 8232 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
8233 | break; |
8234 | case DW_CFA_expression: | |
8235 | strcpy (tmp, "exp"); | |
8236 | break; | |
12eae2d3 JJ |
8237 | case DW_CFA_val_expression: |
8238 | strcpy (tmp, "vexp"); | |
8239 | break; | |
19e6b90e L |
8240 | default: |
8241 | strcpy (tmp, "n/a"); | |
8242 | break; | |
8243 | } | |
2dc4cec1 | 8244 | printf ("%-5s ", tmp); |
19e6b90e L |
8245 | } |
8246 | } | |
8247 | printf ("\n"); | |
8248 | } | |
8249 | ||
49727e46 | 8250 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 8251 | |
49727e46 AM |
8252 | static unsigned char * |
8253 | read_cie (unsigned char *start, unsigned char *end, | |
8254 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 8255 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
8256 | { |
8257 | int version; | |
8258 | Frame_Chunk *fc; | |
49727e46 | 8259 | unsigned char *augmentation_data = NULL; |
bf59c5d5 | 8260 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 8261 | |
041830e0 | 8262 | * p_cie = NULL; |
f41e4712 NC |
8263 | /* PR 17512: file: 001-228113-0.004. */ |
8264 | if (start >= end) | |
8265 | return end; | |
8266 | ||
49727e46 AM |
8267 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
8268 | memset (fc, 0, sizeof (Frame_Chunk)); | |
8269 | ||
8270 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
8271 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
8272 | ||
8273 | version = *start++; | |
8274 | ||
8275 | fc->augmentation = (char *) start; | |
f41e4712 NC |
8276 | /* PR 17512: file: 001-228113-0.004. |
8277 | Skip past augmentation name, but avoid running off the end of the data. */ | |
8278 | while (start < end) | |
8279 | if (* start ++ == '\0') | |
8280 | break; | |
8281 | if (start == end) | |
8282 | { | |
8283 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 8284 | goto fail; |
f41e4712 | 8285 | } |
49727e46 AM |
8286 | |
8287 | if (strcmp (fc->augmentation, "eh") == 0) | |
8288 | start += eh_addr_size; | |
8289 | ||
8290 | if (version >= 4) | |
8291 | { | |
8292 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
8293 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
8294 | { | |
8295 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 8296 | goto fail; |
77ef8654 NC |
8297 | } |
8298 | ||
49727e46 | 8299 | GET (fc->segment_size, 1); |
77ef8654 NC |
8300 | /* PR 17512: file: e99d2804. */ |
8301 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
8302 | { | |
8303 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 8304 | goto fail; |
77ef8654 NC |
8305 | } |
8306 | ||
49727e46 AM |
8307 | eh_addr_size = fc->ptr_size; |
8308 | } | |
8309 | else | |
8310 | { | |
8311 | fc->ptr_size = eh_addr_size; | |
8312 | fc->segment_size = 0; | |
8313 | } | |
442a6ce8 | 8314 | |
cd30bcef AM |
8315 | READ_ULEB (fc->code_factor, start, end); |
8316 | READ_SLEB (fc->data_factor, start, end); | |
442a6ce8 | 8317 | |
49727e46 AM |
8318 | if (version == 1) |
8319 | { | |
8320 | GET (fc->ra, 1); | |
8321 | } | |
8322 | else | |
8323 | { | |
cd30bcef | 8324 | READ_ULEB (fc->ra, start, end); |
49727e46 AM |
8325 | } |
8326 | ||
8327 | if (fc->augmentation[0] == 'z') | |
8328 | { | |
cd30bcef | 8329 | READ_ULEB (augmentation_data_len, start, end); |
49727e46 | 8330 | augmentation_data = start; |
a1165289 | 8331 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 8332 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 8333 | { |
bf59c5d5 NC |
8334 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
8335 | dwarf_vmatoa ("x", augmentation_data_len), | |
8336 | (unsigned long) (end - start)); | |
442a6ce8 | 8337 | goto fail; |
a1165289 | 8338 | } |
9c0f3d3f | 8339 | start += augmentation_data_len; |
49727e46 AM |
8340 | } |
8341 | ||
8342 | if (augmentation_data_len) | |
8343 | { | |
058037d3 NC |
8344 | unsigned char *p; |
8345 | unsigned char *q; | |
8346 | unsigned char *qend; | |
b4eb7656 | 8347 | |
49727e46 AM |
8348 | p = (unsigned char *) fc->augmentation + 1; |
8349 | q = augmentation_data; | |
058037d3 NC |
8350 | qend = q + augmentation_data_len; |
8351 | ||
9c0f3d3f | 8352 | while (p < end && q < qend) |
49727e46 AM |
8353 | { |
8354 | if (*p == 'L') | |
8355 | q++; | |
8356 | else if (*p == 'P') | |
8357 | q += 1 + size_of_encoded_value (*q); | |
8358 | else if (*p == 'R') | |
8359 | fc->fde_encoding = *q++; | |
8360 | else if (*p == 'S') | |
8361 | ; | |
09038062 ST |
8362 | else if (*p == 'B') |
8363 | ; | |
49727e46 AM |
8364 | else |
8365 | break; | |
8366 | p++; | |
8367 | } | |
c361b9ac NC |
8368 | /* Note - it is OK if this loop terminates with q < qend. |
8369 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
8370 | } |
8371 | ||
8372 | *p_cie = fc; | |
8373 | if (p_version) | |
8374 | *p_version = version; | |
8375 | if (p_aug_len) | |
8376 | { | |
8377 | *p_aug_len = augmentation_data_len; | |
8378 | *p_aug = augmentation_data; | |
8379 | } | |
8380 | return start; | |
442a6ce8 NC |
8381 | |
8382 | fail: | |
8383 | free (fc->col_offset); | |
8384 | free (fc->col_type); | |
8385 | free (fc); | |
8386 | return end; | |
49727e46 AM |
8387 | } |
8388 | ||
d85bf2ba NC |
8389 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
8390 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
8391 | PRINTED contains the number of characters already written to the current | |
8392 | output line. */ | |
bf59c5d5 NC |
8393 | |
8394 | static void | |
d85bf2ba NC |
8395 | display_data (bfd_size_type printed, |
8396 | const unsigned char * data, | |
8397 | const bfd_size_type len) | |
bf59c5d5 | 8398 | { |
d85bf2ba NC |
8399 | if (do_wide || len < ((80 - printed) / 3)) |
8400 | for (printed = 0; printed < len; ++printed) | |
8401 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
8402 | else |
8403 | { | |
d85bf2ba | 8404 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 8405 | { |
d85bf2ba | 8406 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 8407 | putchar ('\n'); |
d85bf2ba | 8408 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
8409 | } |
8410 | } | |
d85bf2ba NC |
8411 | } |
8412 | ||
8413 | /* Prints out the contents on the augmentation data array. | |
8414 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
8415 | ||
8416 | static void | |
8417 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
8418 | { | |
8419 | bfd_size_type i; | |
8420 | ||
8421 | i = printf (_(" Augmentation data: ")); | |
8422 | display_data (i, data, len); | |
bf59c5d5 NC |
8423 | } |
8424 | ||
19e6b90e L |
8425 | static int |
8426 | display_debug_frames (struct dwarf_section *section, | |
8427 | void *file ATTRIBUTE_UNUSED) | |
8428 | { | |
8429 | unsigned char *start = section->start; | |
8430 | unsigned char *end = start + section->size; | |
8431 | unsigned char *section_start = start; | |
3391569f NC |
8432 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
8433 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 8434 | Frame_Chunk *rs; |
3391569f | 8435 | bfd_boolean is_eh = strcmp (section->name, ".eh_frame") == 0; |
a1165289 | 8436 | unsigned int max_regs = 0; |
665ce1f6 | 8437 | const char *bad_reg = _("bad register: "); |
77ef8654 | 8438 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 8439 | |
dda8d76d | 8440 | introduce (section, FALSE); |
19e6b90e L |
8441 | |
8442 | while (start < end) | |
8443 | { | |
8444 | unsigned char *saved_start; | |
8445 | unsigned char *block_end; | |
bf5117e3 NC |
8446 | dwarf_vma length; |
8447 | dwarf_vma cie_id; | |
19e6b90e L |
8448 | Frame_Chunk *fc; |
8449 | Frame_Chunk *cie; | |
8450 | int need_col_headers = 1; | |
8451 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 8452 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
8453 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
8454 | unsigned int offset_size; | |
8455 | unsigned int initial_length_size; | |
5b6312fd | 8456 | bfd_boolean all_nops; |
a788aedd | 8457 | static Frame_Chunk fde_fc; |
19e6b90e L |
8458 | |
8459 | saved_start = start; | |
19e6b90e | 8460 | |
0c588247 | 8461 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 8462 | |
19e6b90e L |
8463 | if (length == 0) |
8464 | { | |
8465 | printf ("\n%08lx ZERO terminator\n\n", | |
8466 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
8467 | /* Skip any zero terminators that directly follow. |
8468 | A corrupt section size could have loaded a whole | |
8469 | slew of zero filled memory bytes. eg | |
8470 | PR 17512: file: 070-19381-0.004. */ | |
8471 | while (start < end && * start == 0) | |
8472 | ++ start; | |
b758e50f | 8473 | continue; |
19e6b90e L |
8474 | } |
8475 | ||
8476 | if (length == 0xffffffff) | |
8477 | { | |
0c588247 | 8478 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
8479 | offset_size = 8; |
8480 | initial_length_size = 12; | |
8481 | } | |
8482 | else | |
8483 | { | |
8484 | offset_size = 4; | |
8485 | initial_length_size = 4; | |
8486 | } | |
8487 | ||
8488 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 8489 | if (block_end > end || block_end < start) |
53b8873b | 8490 | { |
bf5117e3 NC |
8491 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
8492 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
8493 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
8494 | block_end = end; |
8495 | } | |
0c588247 NC |
8496 | |
8497 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 8498 | |
846a11e4 NC |
8499 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
8500 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
8501 | { |
8502 | int version; | |
a1165289 | 8503 | unsigned int mreg; |
19e6b90e | 8504 | |
49727e46 AM |
8505 | start = read_cie (start, end, &cie, &version, |
8506 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
8507 | /* PR 17512: file: 027-135133-0.005. */ |
8508 | if (cie == NULL) | |
8509 | break; | |
a1165289 | 8510 | |
49727e46 | 8511 | fc = cie; |
19e6b90e L |
8512 | fc->next = chunks; |
8513 | chunks = fc; | |
8514 | fc->chunk_start = saved_start; | |
a1165289 | 8515 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8516 | if (mreg < fc->ra) |
8517 | mreg = fc->ra; | |
06614111 NC |
8518 | if (frame_need_space (fc, mreg) < 0) |
8519 | break; | |
49727e46 AM |
8520 | if (fc->fde_encoding) |
8521 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 8522 | |
bf5117e3 NC |
8523 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
8524 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 8525 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 8526 | |
19e6b90e | 8527 | if (do_debug_frames_interp) |
bf5117e3 NC |
8528 | { |
8529 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
8530 | fc->code_factor, fc->data_factor, fc->ra); | |
8531 | } | |
19e6b90e L |
8532 | else |
8533 | { | |
bf5117e3 | 8534 | printf ("CIE\n"); |
19e6b90e L |
8535 | printf (" Version: %d\n", version); |
8536 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
8537 | if (version >= 4) |
8538 | { | |
8539 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
8540 | printf (" Segment Size: %u\n", fc->segment_size); | |
8541 | } | |
19e6b90e L |
8542 | printf (" Code alignment factor: %u\n", fc->code_factor); |
8543 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
8544 | printf (" Return address column: %d\n", fc->ra); | |
8545 | ||
8546 | if (augmentation_data_len) | |
bf59c5d5 | 8547 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 8548 | |
19e6b90e L |
8549 | putchar ('\n'); |
8550 | } | |
19e6b90e L |
8551 | } |
8552 | else | |
8553 | { | |
8554 | unsigned char *look_for; | |
604282a7 | 8555 | unsigned long segment_selector; |
19e6b90e | 8556 | |
49727e46 AM |
8557 | if (is_eh) |
8558 | { | |
8559 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
8560 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
8561 | } | |
8562 | else | |
8563 | look_for = section_start + cie_id; | |
19e6b90e | 8564 | |
49727e46 AM |
8565 | if (look_for <= saved_start) |
8566 | { | |
8567 | for (cie = chunks; cie ; cie = cie->next) | |
8568 | if (cie->chunk_start == look_for) | |
8569 | break; | |
8570 | } | |
8571 | else | |
8572 | { | |
8573 | for (cie = forward_refs; cie ; cie = cie->next) | |
8574 | if (cie->chunk_start == look_for) | |
8575 | break; | |
8576 | if (!cie) | |
8577 | { | |
8578 | unsigned int off_size; | |
8579 | unsigned char *cie_scan; | |
19e6b90e | 8580 | |
49727e46 AM |
8581 | cie_scan = look_for; |
8582 | off_size = 4; | |
8583 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
8584 | if (length == 0xffffffff) | |
8585 | { | |
8586 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
8587 | off_size = 8; | |
8588 | } | |
8589 | if (length != 0) | |
8590 | { | |
8591 | dwarf_vma c_id; | |
8592 | ||
8593 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
8594 | if (is_eh | |
8595 | ? c_id == 0 | |
8596 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
8597 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
8598 | { | |
8599 | int version; | |
a1165289 | 8600 | unsigned int mreg; |
49727e46 AM |
8601 | |
8602 | read_cie (cie_scan, end, &cie, &version, | |
8603 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
8604 | /* PR 17512: file: 3450-2098-0.004. */ |
8605 | if (cie == NULL) | |
8606 | { | |
8607 | warn (_("Failed to read CIE information\n")); | |
8608 | break; | |
8609 | } | |
49727e46 AM |
8610 | cie->next = forward_refs; |
8611 | forward_refs = cie; | |
8612 | cie->chunk_start = look_for; | |
a1165289 | 8613 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8614 | if (mreg < cie->ra) |
8615 | mreg = cie->ra; | |
06614111 NC |
8616 | if (frame_need_space (cie, mreg) < 0) |
8617 | { | |
8618 | warn (_("Invalid max register\n")); | |
8619 | break; | |
8620 | } | |
49727e46 AM |
8621 | if (cie->fde_encoding) |
8622 | encoded_ptr_size | |
8623 | = size_of_encoded_value (cie->fde_encoding); | |
8624 | } | |
8625 | } | |
8626 | } | |
8627 | } | |
8628 | ||
8629 | fc = &fde_fc; | |
8630 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
8631 | |
8632 | if (!cie) | |
8633 | { | |
bf5117e3 NC |
8634 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
8635 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
8636 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 8637 | fc->ncols = 0; |
3f5e193b NC |
8638 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
8639 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
8640 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
8641 | { | |
8642 | warn (_("Invalid max register\n")); | |
8643 | break; | |
8644 | } | |
19e6b90e L |
8645 | cie = fc; |
8646 | fc->augmentation = ""; | |
8647 | fc->fde_encoding = 0; | |
604282a7 JJ |
8648 | fc->ptr_size = eh_addr_size; |
8649 | fc->segment_size = 0; | |
19e6b90e L |
8650 | } |
8651 | else | |
8652 | { | |
8653 | fc->ncols = cie->ncols; | |
3f5e193b NC |
8654 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
8655 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
8656 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
8657 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
8658 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
8659 | fc->ptr_size = cie->ptr_size; |
8660 | eh_addr_size = cie->ptr_size; | |
8661 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
8662 | fc->code_factor = cie->code_factor; |
8663 | fc->data_factor = cie->data_factor; | |
8664 | fc->cfa_reg = cie->cfa_reg; | |
8665 | fc->cfa_offset = cie->cfa_offset; | |
8666 | fc->ra = cie->ra; | |
06614111 NC |
8667 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
8668 | { | |
8669 | warn (_("Invalid max register\n")); | |
8670 | break; | |
8671 | } | |
19e6b90e L |
8672 | fc->fde_encoding = cie->fde_encoding; |
8673 | } | |
8674 | ||
8675 | if (fc->fde_encoding) | |
8676 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
8677 | ||
604282a7 JJ |
8678 | segment_selector = 0; |
8679 | if (fc->segment_size) | |
c8071705 NC |
8680 | { |
8681 | if (fc->segment_size > sizeof (segment_selector)) | |
8682 | { | |
8683 | /* PR 17512: file: 9e196b3e. */ | |
8684 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
8685 | fc->segment_size = 4; | |
8686 | } | |
8687 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
8688 | } | |
041830e0 NC |
8689 | |
8690 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 8691 | |
0c588247 NC |
8692 | /* FIXME: It appears that sometimes the final pc_range value is |
8693 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
8694 | run of the "objcopy on compressed debug sections" test for an | |
8695 | example of this. */ | |
8696 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 8697 | |
19e6b90e L |
8698 | if (cie->augmentation[0] == 'z') |
8699 | { | |
cd30bcef | 8700 | READ_ULEB (augmentation_data_len, start, end); |
19e6b90e | 8701 | augmentation_data = start; |
bf59c5d5 | 8702 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
d292364e | 8703 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
0a9d414a | 8704 | { |
d292364e AM |
8705 | warn (_("Augmentation data too long: 0x%s, " |
8706 | "expected at most %#lx\n"), | |
8707 | dwarf_vmatoa ("x", augmentation_data_len), | |
8708 | (unsigned long) (end - start)); | |
0a9d414a NC |
8709 | start = end; |
8710 | augmentation_data = NULL; | |
8711 | augmentation_data_len = 0; | |
8712 | } | |
d292364e | 8713 | start += augmentation_data_len; |
19e6b90e L |
8714 | } |
8715 | ||
bf5117e3 NC |
8716 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
8717 | (unsigned long)(saved_start - section_start), | |
8718 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 8719 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 8720 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 8721 | |
604282a7 JJ |
8722 | if (fc->segment_size) |
8723 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
8724 | |
8725 | printf ("%s..%s\n", | |
8726 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
8727 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
8728 | ||
19e6b90e L |
8729 | if (! do_debug_frames_interp && augmentation_data_len) |
8730 | { | |
bf59c5d5 | 8731 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
8732 | putchar ('\n'); |
8733 | } | |
8734 | } | |
8735 | ||
8736 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
8737 | we're about to interpret instructions for the chunk. */ | |
8738 | /* ??? At present we need to do this always, since this sizes the | |
8739 | fc->col_type and fc->col_offset arrays, which we write into always. | |
8740 | We should probably split the interpreted and non-interpreted bits | |
8741 | into two different routines, since there's so much that doesn't | |
8742 | really overlap between them. */ | |
8743 | if (1 || do_debug_frames_interp) | |
8744 | { | |
8745 | /* Start by making a pass over the chunk, allocating storage | |
8746 | and taking note of what registers are used. */ | |
8747 | unsigned char *tmp = start; | |
8748 | ||
8749 | while (start < block_end) | |
8750 | { | |
041830e0 NC |
8751 | unsigned int reg, op, opa; |
8752 | unsigned long temp; | |
5929c344 | 8753 | unsigned char * new_start; |
19e6b90e L |
8754 | |
8755 | op = *start++; | |
8756 | opa = op & 0x3f; | |
8757 | if (op & 0xc0) | |
8758 | op &= 0xc0; | |
8759 | ||
8760 | /* Warning: if you add any more cases to this switch, be | |
8761 | sure to add them to the corresponding switch below. */ | |
8762 | switch (op) | |
8763 | { | |
8764 | case DW_CFA_advance_loc: | |
8765 | break; | |
8766 | case DW_CFA_offset: | |
cd30bcef | 8767 | SKIP_ULEB (start, end); |
665ce1f6 L |
8768 | if (frame_need_space (fc, opa) >= 0) |
8769 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8770 | break; |
8771 | case DW_CFA_restore: | |
665ce1f6 L |
8772 | if (frame_need_space (fc, opa) >= 0) |
8773 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8774 | break; |
8775 | case DW_CFA_set_loc: | |
8776 | start += encoded_ptr_size; | |
8777 | break; | |
8778 | case DW_CFA_advance_loc1: | |
8779 | start += 1; | |
8780 | break; | |
8781 | case DW_CFA_advance_loc2: | |
8782 | start += 2; | |
8783 | break; | |
8784 | case DW_CFA_advance_loc4: | |
8785 | start += 4; | |
8786 | break; | |
8787 | case DW_CFA_offset_extended: | |
12eae2d3 | 8788 | case DW_CFA_val_offset: |
cd30bcef AM |
8789 | READ_ULEB (reg, start, end); |
8790 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8791 | if (frame_need_space (fc, reg) >= 0) |
8792 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8793 | break; |
8794 | case DW_CFA_restore_extended: | |
cd30bcef | 8795 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8796 | if (frame_need_space (fc, reg) >= 0) |
8797 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8798 | break; |
8799 | case DW_CFA_undefined: | |
cd30bcef | 8800 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8801 | if (frame_need_space (fc, reg) >= 0) |
8802 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8803 | break; |
8804 | case DW_CFA_same_value: | |
cd30bcef | 8805 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8806 | if (frame_need_space (fc, reg) >= 0) |
8807 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8808 | break; |
8809 | case DW_CFA_register: | |
cd30bcef AM |
8810 | READ_ULEB (reg, start, end); |
8811 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8812 | if (frame_need_space (fc, reg) >= 0) |
8813 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8814 | break; |
8815 | case DW_CFA_def_cfa: | |
cd30bcef AM |
8816 | SKIP_ULEB (start, end); |
8817 | SKIP_ULEB (start, end); | |
19e6b90e L |
8818 | break; |
8819 | case DW_CFA_def_cfa_register: | |
cd30bcef | 8820 | SKIP_ULEB (start, end); |
19e6b90e L |
8821 | break; |
8822 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 8823 | SKIP_ULEB (start, end); |
19e6b90e L |
8824 | break; |
8825 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 8826 | READ_ULEB (temp, start, end); |
5929c344 NC |
8827 | new_start = start + temp; |
8828 | if (new_start < start) | |
041830e0 NC |
8829 | { |
8830 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
8831 | start = block_end; | |
8832 | } | |
8833 | else | |
5929c344 | 8834 | start = new_start; |
19e6b90e L |
8835 | break; |
8836 | case DW_CFA_expression: | |
12eae2d3 | 8837 | case DW_CFA_val_expression: |
cd30bcef AM |
8838 | READ_ULEB (reg, start, end); |
8839 | READ_ULEB (temp, start, end); | |
5929c344 NC |
8840 | new_start = start + temp; |
8841 | if (new_start < start) | |
041830e0 | 8842 | { |
b4eb7656 | 8843 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
8844 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
8845 | start = block_end; | |
8846 | } | |
8847 | else | |
5929c344 | 8848 | start = new_start; |
665ce1f6 L |
8849 | if (frame_need_space (fc, reg) >= 0) |
8850 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8851 | break; |
8852 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 8853 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
8854 | READ_ULEB (reg, start, end); |
8855 | SKIP_SLEB (start, end); | |
665ce1f6 L |
8856 | if (frame_need_space (fc, reg) >= 0) |
8857 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8858 | break; |
8859 | case DW_CFA_def_cfa_sf: | |
cd30bcef AM |
8860 | SKIP_ULEB (start, end); |
8861 | SKIP_SLEB (start, end); | |
19e6b90e L |
8862 | break; |
8863 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 8864 | SKIP_SLEB (start, end); |
19e6b90e L |
8865 | break; |
8866 | case DW_CFA_MIPS_advance_loc8: | |
8867 | start += 8; | |
8868 | break; | |
8869 | case DW_CFA_GNU_args_size: | |
cd30bcef | 8870 | SKIP_ULEB (start, end); |
19e6b90e L |
8871 | break; |
8872 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
8873 | READ_ULEB (reg, start, end); |
8874 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8875 | if (frame_need_space (fc, reg) >= 0) |
8876 | fc->col_type[reg] = DW_CFA_undefined; | |
8877 | break; | |
19e6b90e L |
8878 | default: |
8879 | break; | |
8880 | } | |
8881 | } | |
8882 | start = tmp; | |
8883 | } | |
8884 | ||
5b6312fd NC |
8885 | all_nops = TRUE; |
8886 | ||
19e6b90e L |
8887 | /* Now we know what registers are used, make a second pass over |
8888 | the chunk, this time actually printing out the info. */ | |
8889 | ||
8890 | while (start < block_end) | |
8891 | { | |
362beea4 | 8892 | unsigned char * tmp; |
19e6b90e | 8893 | unsigned op, opa; |
7f2c8a1d NC |
8894 | unsigned long ul, roffs; |
8895 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
8896 | are various functions, notably frame_space_needed() that assume that | |
8897 | reg is an unsigned int. */ | |
8898 | unsigned int reg; | |
8899 | dwarf_signed_vma l; | |
bf5117e3 | 8900 | dwarf_vma ofs; |
19e6b90e | 8901 | dwarf_vma vma; |
665ce1f6 | 8902 | const char *reg_prefix = ""; |
19e6b90e L |
8903 | |
8904 | op = *start++; | |
8905 | opa = op & 0x3f; | |
8906 | if (op & 0xc0) | |
8907 | op &= 0xc0; | |
8908 | ||
5b6312fd NC |
8909 | /* Make a note if something other than DW_CFA_nop happens. */ |
8910 | if (op != DW_CFA_nop) | |
8911 | all_nops = FALSE; | |
8912 | ||
19e6b90e L |
8913 | /* Warning: if you add any more cases to this switch, be |
8914 | sure to add them to the corresponding switch above. */ | |
8915 | switch (op) | |
8916 | { | |
8917 | case DW_CFA_advance_loc: | |
8918 | if (do_debug_frames_interp) | |
8919 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8920 | else | |
bf5117e3 | 8921 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 8922 | opa * fc->code_factor, |
b4eb7656 | 8923 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
8924 | fc->pc_begin + opa * fc->code_factor, |
8925 | fc->ptr_size)); | |
19e6b90e L |
8926 | fc->pc_begin += opa * fc->code_factor; |
8927 | break; | |
8928 | ||
8929 | case DW_CFA_offset: | |
cd30bcef | 8930 | READ_ULEB (roffs, start, end); |
665ce1f6 L |
8931 | if (opa >= (unsigned int) fc->ncols) |
8932 | reg_prefix = bad_reg; | |
8933 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8934 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
8935 | reg_prefix, regname (opa, 0), | |
8936 | roffs * fc->data_factor); | |
8937 | if (*reg_prefix == '\0') | |
8938 | { | |
8939 | fc->col_type[opa] = DW_CFA_offset; | |
8940 | fc->col_offset[opa] = roffs * fc->data_factor; | |
8941 | } | |
19e6b90e L |
8942 | break; |
8943 | ||
8944 | case DW_CFA_restore: | |
50751e18 | 8945 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
8946 | reg_prefix = bad_reg; |
8947 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8948 | printf (" DW_CFA_restore: %s%s\n", | |
8949 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
8950 | if (*reg_prefix != '\0') |
8951 | break; | |
8952 | ||
8953 | if (opa >= (unsigned int) cie->ncols | |
8954 | || (do_debug_frames_interp | |
8955 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
8956 | { | |
8957 | fc->col_type[opa] = DW_CFA_undefined; | |
8958 | fc->col_offset[opa] = 0; | |
8959 | } | |
8960 | else | |
665ce1f6 L |
8961 | { |
8962 | fc->col_type[opa] = cie->col_type[opa]; | |
8963 | fc->col_offset[opa] = cie->col_offset[opa]; | |
8964 | } | |
19e6b90e L |
8965 | break; |
8966 | ||
8967 | case DW_CFA_set_loc: | |
6937bb54 | 8968 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
8969 | if (do_debug_frames_interp) |
8970 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8971 | else | |
bf5117e3 NC |
8972 | printf (" DW_CFA_set_loc: %s\n", |
8973 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
8974 | fc->pc_begin = vma; |
8975 | break; | |
8976 | ||
8977 | case DW_CFA_advance_loc1: | |
0c588247 | 8978 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
8979 | if (do_debug_frames_interp) |
8980 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8981 | else | |
bf5117e3 NC |
8982 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
8983 | (unsigned long) (ofs * fc->code_factor), | |
8984 | dwarf_vmatoa_1 (NULL, | |
8985 | fc->pc_begin + ofs * fc->code_factor, | |
8986 | fc->ptr_size)); | |
19e6b90e L |
8987 | fc->pc_begin += ofs * fc->code_factor; |
8988 | break; | |
8989 | ||
8990 | case DW_CFA_advance_loc2: | |
6937bb54 | 8991 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
8992 | if (do_debug_frames_interp) |
8993 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8994 | else | |
bf5117e3 NC |
8995 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
8996 | (unsigned long) (ofs * fc->code_factor), | |
8997 | dwarf_vmatoa_1 (NULL, | |
8998 | fc->pc_begin + ofs * fc->code_factor, | |
8999 | fc->ptr_size)); | |
19e6b90e L |
9000 | fc->pc_begin += ofs * fc->code_factor; |
9001 | break; | |
9002 | ||
9003 | case DW_CFA_advance_loc4: | |
6937bb54 | 9004 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
9005 | if (do_debug_frames_interp) |
9006 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9007 | else | |
bf5117e3 NC |
9008 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
9009 | (unsigned long) (ofs * fc->code_factor), | |
9010 | dwarf_vmatoa_1 (NULL, | |
9011 | fc->pc_begin + ofs * fc->code_factor, | |
9012 | fc->ptr_size)); | |
19e6b90e L |
9013 | fc->pc_begin += ofs * fc->code_factor; |
9014 | break; | |
9015 | ||
9016 | case DW_CFA_offset_extended: | |
cd30bcef AM |
9017 | READ_ULEB (reg, start, end); |
9018 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
9019 | if (reg >= (unsigned int) fc->ncols) |
9020 | reg_prefix = bad_reg; | |
9021 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9022 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
9023 | reg_prefix, regname (reg, 0), | |
9024 | roffs * fc->data_factor); | |
9025 | if (*reg_prefix == '\0') | |
9026 | { | |
9027 | fc->col_type[reg] = DW_CFA_offset; | |
9028 | fc->col_offset[reg] = roffs * fc->data_factor; | |
9029 | } | |
19e6b90e L |
9030 | break; |
9031 | ||
12eae2d3 | 9032 | case DW_CFA_val_offset: |
cd30bcef AM |
9033 | READ_ULEB (reg, start, end); |
9034 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
9035 | if (reg >= (unsigned int) fc->ncols) |
9036 | reg_prefix = bad_reg; | |
9037 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 9038 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
9039 | reg_prefix, regname (reg, 0), |
9040 | roffs * fc->data_factor); | |
9041 | if (*reg_prefix == '\0') | |
9042 | { | |
9043 | fc->col_type[reg] = DW_CFA_val_offset; | |
9044 | fc->col_offset[reg] = roffs * fc->data_factor; | |
9045 | } | |
12eae2d3 JJ |
9046 | break; |
9047 | ||
19e6b90e | 9048 | case DW_CFA_restore_extended: |
cd30bcef | 9049 | READ_ULEB (reg, start, end); |
50751e18 | 9050 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
9051 | reg_prefix = bad_reg; |
9052 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9053 | printf (" DW_CFA_restore_extended: %s%s\n", | |
9054 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
9055 | if (*reg_prefix != '\0') |
9056 | break; | |
9057 | ||
9058 | if (reg >= (unsigned int) cie->ncols) | |
9059 | { | |
9060 | fc->col_type[reg] = DW_CFA_undefined; | |
9061 | fc->col_offset[reg] = 0; | |
9062 | } | |
9063 | else | |
665ce1f6 L |
9064 | { |
9065 | fc->col_type[reg] = cie->col_type[reg]; | |
9066 | fc->col_offset[reg] = cie->col_offset[reg]; | |
9067 | } | |
19e6b90e L |
9068 | break; |
9069 | ||
9070 | case DW_CFA_undefined: | |
cd30bcef | 9071 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9072 | if (reg >= (unsigned int) fc->ncols) |
9073 | reg_prefix = bad_reg; | |
9074 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9075 | printf (" DW_CFA_undefined: %s%s\n", | |
9076 | reg_prefix, regname (reg, 0)); | |
9077 | if (*reg_prefix == '\0') | |
9078 | { | |
9079 | fc->col_type[reg] = DW_CFA_undefined; | |
9080 | fc->col_offset[reg] = 0; | |
9081 | } | |
19e6b90e L |
9082 | break; |
9083 | ||
9084 | case DW_CFA_same_value: | |
cd30bcef | 9085 | READ_ULEB (reg, start, end); |
665ce1f6 L |
9086 | if (reg >= (unsigned int) fc->ncols) |
9087 | reg_prefix = bad_reg; | |
9088 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9089 | printf (" DW_CFA_same_value: %s%s\n", | |
9090 | reg_prefix, regname (reg, 0)); | |
9091 | if (*reg_prefix == '\0') | |
9092 | { | |
9093 | fc->col_type[reg] = DW_CFA_same_value; | |
9094 | fc->col_offset[reg] = 0; | |
9095 | } | |
19e6b90e L |
9096 | break; |
9097 | ||
9098 | case DW_CFA_register: | |
cd30bcef AM |
9099 | READ_ULEB (reg, start, end); |
9100 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
9101 | if (reg >= (unsigned int) fc->ncols) |
9102 | reg_prefix = bad_reg; | |
9103 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 9104 | { |
665ce1f6 L |
9105 | printf (" DW_CFA_register: %s%s in ", |
9106 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
9107 | puts (regname (roffs, 0)); |
9108 | } | |
665ce1f6 L |
9109 | if (*reg_prefix == '\0') |
9110 | { | |
9111 | fc->col_type[reg] = DW_CFA_register; | |
9112 | fc->col_offset[reg] = roffs; | |
9113 | } | |
19e6b90e L |
9114 | break; |
9115 | ||
9116 | case DW_CFA_remember_state: | |
9117 | if (! do_debug_frames_interp) | |
9118 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 9119 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 9120 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
9121 | rs->cfa_reg = fc->cfa_reg; |
9122 | rs->ra = fc->ra; | |
9123 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 9124 | rs->ncols = fc->ncols; |
3f5e193b | 9125 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 9126 | sizeof (* rs->col_type)); |
d71ad7fc RC |
9127 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
9128 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
9129 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
9130 | rs->next = remembered_state; |
9131 | remembered_state = rs; | |
9132 | break; | |
9133 | ||
9134 | case DW_CFA_restore_state: | |
9135 | if (! do_debug_frames_interp) | |
9136 | printf (" DW_CFA_restore_state\n"); | |
9137 | rs = remembered_state; | |
9138 | if (rs) | |
9139 | { | |
9140 | remembered_state = rs->next; | |
d71ad7fc RC |
9141 | fc->cfa_offset = rs->cfa_offset; |
9142 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
9143 | fc->ra = rs->ra; |
9144 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
9145 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
9146 | { | |
1306a742 | 9147 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
9148 | fc->ncols = 0; |
9149 | break; | |
9150 | } | |
d71ad7fc | 9151 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 9152 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 9153 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
9154 | free (rs->col_type); |
9155 | free (rs->col_offset); | |
9156 | free (rs); | |
9157 | } | |
9158 | else if (do_debug_frames_interp) | |
9159 | printf ("Mismatched DW_CFA_restore_state\n"); | |
9160 | break; | |
9161 | ||
9162 | case DW_CFA_def_cfa: | |
cd30bcef AM |
9163 | READ_ULEB (fc->cfa_reg, start, end); |
9164 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
9165 | fc->cfa_exp = 0; |
9166 | if (! do_debug_frames_interp) | |
2dc4cec1 | 9167 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 9168 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
9169 | break; |
9170 | ||
9171 | case DW_CFA_def_cfa_register: | |
cd30bcef | 9172 | READ_ULEB (fc->cfa_reg, start, end); |
19e6b90e L |
9173 | fc->cfa_exp = 0; |
9174 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
9175 | printf (" DW_CFA_def_cfa_register: %s\n", |
9176 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
9177 | break; |
9178 | ||
9179 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 9180 | READ_ULEB (fc->cfa_offset, start, end); |
19e6b90e | 9181 | if (! do_debug_frames_interp) |
c8071705 | 9182 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
9183 | break; |
9184 | ||
9185 | case DW_CFA_nop: | |
9186 | if (! do_debug_frames_interp) | |
9187 | printf (" DW_CFA_nop\n"); | |
9188 | break; | |
9189 | ||
9190 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 9191 | READ_ULEB (ul, start, end); |
7460c0ab | 9192 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 9193 | { |
a1165289 | 9194 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
9195 | break; |
9196 | } | |
19e6b90e L |
9197 | if (! do_debug_frames_interp) |
9198 | { | |
9199 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
9200 | decode_location_expression (start, eh_addr_size, 0, -1, |
9201 | ul, 0, section); | |
19e6b90e L |
9202 | printf (")\n"); |
9203 | } | |
9204 | fc->cfa_exp = 1; | |
9205 | start += ul; | |
9206 | break; | |
9207 | ||
9208 | case DW_CFA_expression: | |
cd30bcef AM |
9209 | READ_ULEB (reg, start, end); |
9210 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
9211 | if (reg >= (unsigned int) fc->ncols) |
9212 | reg_prefix = bad_reg; | |
6937bb54 | 9213 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 9214 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
9215 | tmp = start + ul; |
9216 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 9217 | { |
a1165289 | 9218 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
9219 | break; |
9220 | } | |
665ce1f6 | 9221 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 9222 | { |
665ce1f6 L |
9223 | printf (" DW_CFA_expression: %s%s (", |
9224 | reg_prefix, regname (reg, 0)); | |
b7807392 | 9225 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 9226 | ul, 0, section); |
19e6b90e L |
9227 | printf (")\n"); |
9228 | } | |
665ce1f6 L |
9229 | if (*reg_prefix == '\0') |
9230 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 9231 | start = tmp; |
19e6b90e L |
9232 | break; |
9233 | ||
12eae2d3 | 9234 | case DW_CFA_val_expression: |
cd30bcef AM |
9235 | READ_ULEB (reg, start, end); |
9236 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
9237 | if (reg >= (unsigned int) fc->ncols) |
9238 | reg_prefix = bad_reg; | |
362beea4 NC |
9239 | tmp = start + ul; |
9240 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 9241 | { |
a1165289 | 9242 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
9243 | break; |
9244 | } | |
665ce1f6 | 9245 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 9246 | { |
665ce1f6 L |
9247 | printf (" DW_CFA_val_expression: %s%s (", |
9248 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
9249 | decode_location_expression (start, eh_addr_size, 0, -1, |
9250 | ul, 0, section); | |
12eae2d3 JJ |
9251 | printf (")\n"); |
9252 | } | |
665ce1f6 L |
9253 | if (*reg_prefix == '\0') |
9254 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 9255 | start = tmp; |
12eae2d3 JJ |
9256 | break; |
9257 | ||
19e6b90e | 9258 | case DW_CFA_offset_extended_sf: |
cd30bcef AM |
9259 | READ_ULEB (reg, start, end); |
9260 | READ_SLEB (l, start, end); | |
665ce1f6 L |
9261 | if (frame_need_space (fc, reg) < 0) |
9262 | reg_prefix = bad_reg; | |
9263 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9264 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
9265 | reg_prefix, regname (reg, 0), | |
c8071705 | 9266 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9267 | if (*reg_prefix == '\0') |
9268 | { | |
9269 | fc->col_type[reg] = DW_CFA_offset; | |
9270 | fc->col_offset[reg] = l * fc->data_factor; | |
9271 | } | |
19e6b90e L |
9272 | break; |
9273 | ||
12eae2d3 | 9274 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
9275 | READ_ULEB (reg, start, end); |
9276 | READ_SLEB (l, start, end); | |
665ce1f6 L |
9277 | if (frame_need_space (fc, reg) < 0) |
9278 | reg_prefix = bad_reg; | |
9279 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 9280 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 9281 | reg_prefix, regname (reg, 0), |
c8071705 | 9282 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9283 | if (*reg_prefix == '\0') |
9284 | { | |
9285 | fc->col_type[reg] = DW_CFA_val_offset; | |
9286 | fc->col_offset[reg] = l * fc->data_factor; | |
9287 | } | |
12eae2d3 JJ |
9288 | break; |
9289 | ||
19e6b90e | 9290 | case DW_CFA_def_cfa_sf: |
cd30bcef AM |
9291 | READ_ULEB (fc->cfa_reg, start, end); |
9292 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
9293 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
9294 | fc->cfa_exp = 0; | |
9295 | if (! do_debug_frames_interp) | |
2dc4cec1 | 9296 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 9297 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
9298 | break; |
9299 | ||
9300 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 9301 | READ_ULEB (fc->cfa_offset, start, end); |
c8071705 | 9302 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 9303 | if (! do_debug_frames_interp) |
c8071705 | 9304 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
9305 | break; |
9306 | ||
9307 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 9308 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
9309 | if (do_debug_frames_interp) |
9310 | frame_display_row (fc, &need_col_headers, &max_regs); | |
9311 | else | |
bf5117e3 NC |
9312 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
9313 | (unsigned long) (ofs * fc->code_factor), | |
9314 | dwarf_vmatoa_1 (NULL, | |
9315 | fc->pc_begin + ofs * fc->code_factor, | |
9316 | fc->ptr_size)); | |
19e6b90e L |
9317 | fc->pc_begin += ofs * fc->code_factor; |
9318 | break; | |
9319 | ||
9320 | case DW_CFA_GNU_window_save: | |
9321 | if (! do_debug_frames_interp) | |
9322 | printf (" DW_CFA_GNU_window_save\n"); | |
9323 | break; | |
9324 | ||
9325 | case DW_CFA_GNU_args_size: | |
cd30bcef | 9326 | READ_ULEB (ul, start, end); |
19e6b90e L |
9327 | if (! do_debug_frames_interp) |
9328 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
9329 | break; | |
9330 | ||
9331 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
9332 | READ_ULEB (reg, start, end); |
9333 | READ_SLEB (l, start, end); | |
7f2c8a1d | 9334 | l = - l; |
665ce1f6 L |
9335 | if (frame_need_space (fc, reg) < 0) |
9336 | reg_prefix = bad_reg; | |
9337 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
9338 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
9339 | reg_prefix, regname (reg, 0), | |
c8071705 | 9340 | (long)(l * fc->data_factor)); |
665ce1f6 L |
9341 | if (*reg_prefix == '\0') |
9342 | { | |
9343 | fc->col_type[reg] = DW_CFA_offset; | |
9344 | fc->col_offset[reg] = l * fc->data_factor; | |
9345 | } | |
19e6b90e L |
9346 | break; |
9347 | ||
9348 | default: | |
53b8873b NC |
9349 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
9350 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
9351 | else | |
f41e4712 | 9352 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
9353 | start = block_end; |
9354 | } | |
9355 | } | |
9356 | ||
5b6312fd NC |
9357 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
9358 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
9359 | frame_display_row (fc, &need_col_headers, &max_regs); |
9360 | ||
a788aedd AM |
9361 | if (fde_fc.col_type != NULL) |
9362 | { | |
9363 | free (fde_fc.col_type); | |
9364 | fde_fc.col_type = NULL; | |
9365 | } | |
9366 | if (fde_fc.col_offset != NULL) | |
9367 | { | |
9368 | free (fde_fc.col_offset); | |
9369 | fde_fc.col_offset = NULL; | |
9370 | } | |
9371 | ||
19e6b90e | 9372 | start = block_end; |
604282a7 | 9373 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
9374 | } |
9375 | ||
9376 | printf ("\n"); | |
9377 | ||
3391569f NC |
9378 | while (remembered_state != NULL) |
9379 | { | |
9380 | rs = remembered_state; | |
9381 | remembered_state = rs->next; | |
9382 | free (rs->col_type); | |
9383 | free (rs->col_offset); | |
9384 | rs->next = NULL; /* Paranoia. */ | |
9385 | free (rs); | |
9386 | } | |
9387 | ||
9388 | while (chunks != NULL) | |
9389 | { | |
9390 | rs = chunks; | |
9391 | chunks = rs->next; | |
9392 | free (rs->col_type); | |
9393 | free (rs->col_offset); | |
9394 | rs->next = NULL; /* Paranoia. */ | |
9395 | free (rs); | |
9396 | } | |
9397 | ||
9398 | while (forward_refs != NULL) | |
9399 | { | |
9400 | rs = forward_refs; | |
9401 | forward_refs = rs->next; | |
9402 | free (rs->col_type); | |
9403 | free (rs->col_offset); | |
9404 | rs->next = NULL; /* Paranoia. */ | |
9405 | free (rs); | |
9406 | } | |
9407 | ||
19e6b90e L |
9408 | return 1; |
9409 | } | |
9410 | ||
9411 | #undef GET | |
19e6b90e | 9412 | |
61364358 JK |
9413 | static int |
9414 | display_debug_names (struct dwarf_section *section, void *file) | |
9415 | { | |
9416 | unsigned char *hdrptr = section->start; | |
9417 | dwarf_vma unit_length; | |
9418 | unsigned char *unit_start; | |
9419 | const unsigned char *const section_end = section->start + section->size; | |
9420 | unsigned char *unit_end; | |
9421 | ||
dda8d76d | 9422 | introduce (section, FALSE); |
61364358 | 9423 | |
dda8d76d | 9424 | load_debug_section_with_follow (str, file); |
61364358 JK |
9425 | |
9426 | for (; hdrptr < section_end; hdrptr = unit_end) | |
9427 | { | |
9428 | unsigned int offset_size; | |
9429 | uint16_t dwarf_version, padding; | |
9430 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
9431 | uint32_t bucket_count, name_count, abbrev_table_size; | |
9432 | uint32_t augmentation_string_size; | |
9433 | unsigned int i; | |
e98fdf1a | 9434 | unsigned long sec_off; |
48467cb9 TV |
9435 | bfd_boolean augmentation_printable; |
9436 | const char *augmentation_string; | |
61364358 JK |
9437 | |
9438 | unit_start = hdrptr; | |
9439 | ||
9440 | /* Get and check the length of the block. */ | |
9441 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
9442 | ||
9443 | if (unit_length == 0xffffffff) | |
9444 | { | |
9445 | /* This section is 64-bit DWARF. */ | |
9446 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
9447 | offset_size = 8; | |
9448 | } | |
9449 | else | |
9450 | offset_size = 4; | |
9451 | unit_end = hdrptr + unit_length; | |
9452 | ||
e98fdf1a AM |
9453 | sec_off = hdrptr - section->start; |
9454 | if (sec_off + unit_length < sec_off | |
9455 | || sec_off + unit_length > section->size) | |
61364358 | 9456 | { |
e98fdf1a AM |
9457 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
9458 | section->name, | |
9459 | (unsigned long) (unit_start - section->start), | |
9460 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
9461 | return 0; |
9462 | } | |
9463 | ||
9464 | /* Get and check the version number. */ | |
9465 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
9466 | printf (_("Version %ld\n"), (long) dwarf_version); | |
9467 | ||
9468 | /* Prior versions did not exist, and future versions may not be | |
9469 | backwards compatible. */ | |
9470 | if (dwarf_version != 5) | |
9471 | { | |
9472 | warn (_("Only DWARF version 5 .debug_names " | |
9473 | "is currently supported.\n")); | |
9474 | return 0; | |
9475 | } | |
9476 | ||
9477 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
9478 | if (padding != 0) | |
9479 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
9480 | padding); | |
9481 | ||
9482 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
9483 | if (comp_unit_count == 0) | |
9484 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
9485 | ||
9486 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
9487 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
9488 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
9489 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
9490 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
9491 | ||
9492 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
9493 | if (augmentation_string_size % 4 != 0) | |
9494 | { | |
9495 | warn (_("Augmentation string length %u must be rounded up " | |
9496 | "to a multiple of 4 in .debug_names.\n"), | |
9497 | augmentation_string_size); | |
9498 | augmentation_string_size += (-augmentation_string_size) & 3; | |
9499 | } | |
48467cb9 | 9500 | |
61364358 | 9501 | printf (_("Augmentation string:")); |
48467cb9 TV |
9502 | |
9503 | augmentation_printable = TRUE; | |
9504 | augmentation_string = (const char *) hdrptr; | |
9505 | ||
61364358 JK |
9506 | for (i = 0; i < augmentation_string_size; i++) |
9507 | { | |
9508 | unsigned char uc; | |
9509 | ||
9510 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
9511 | printf (" %02x", uc); | |
48467cb9 TV |
9512 | |
9513 | if (uc != 0 && !ISPRINT (uc)) | |
9514 | augmentation_printable = FALSE; | |
9515 | } | |
9516 | ||
9517 | if (augmentation_printable) | |
9518 | { | |
9519 | printf (" (\""); | |
9520 | for (i = 0; | |
9521 | i < augmentation_string_size && augmentation_string[i]; | |
9522 | ++i) | |
9523 | putchar (augmentation_string[i]); | |
9524 | printf ("\")"); | |
61364358 | 9525 | } |
61364358 JK |
9526 | putchar ('\n'); |
9527 | ||
9528 | printf (_("CU table:\n")); | |
9529 | for (i = 0; i < comp_unit_count; i++) | |
9530 | { | |
9531 | uint64_t cu_offset; | |
9532 | ||
9533 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
9534 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
9535 | } | |
9536 | putchar ('\n'); | |
9537 | ||
9538 | printf (_("TU table:\n")); | |
9539 | for (i = 0; i < local_type_unit_count; i++) | |
9540 | { | |
9541 | uint64_t tu_offset; | |
9542 | ||
9543 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
9544 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
9545 | } | |
9546 | putchar ('\n'); | |
9547 | ||
9548 | printf (_("Foreign TU table:\n")); | |
9549 | for (i = 0; i < foreign_type_unit_count; i++) | |
9550 | { | |
9551 | uint64_t signature; | |
9552 | ||
9553 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
9554 | printf (_("[%3u] "), i); | |
9555 | print_dwarf_vma (signature, 8); | |
9556 | putchar ('\n'); | |
9557 | } | |
9558 | putchar ('\n'); | |
9559 | ||
9560 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
9561 | hdrptr += bucket_count * sizeof (uint32_t); | |
9562 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
9563 | hdrptr += name_count * sizeof (uint32_t); | |
9564 | unsigned char *const name_table_string_offsets = hdrptr; | |
9565 | hdrptr += name_count * offset_size; | |
9566 | unsigned char *const name_table_entry_offsets = hdrptr; | |
9567 | hdrptr += name_count * offset_size; | |
9568 | unsigned char *const abbrev_table = hdrptr; | |
9569 | hdrptr += abbrev_table_size; | |
9570 | const unsigned char *const abbrev_table_end = hdrptr; | |
9571 | unsigned char *const entry_pool = hdrptr; | |
9572 | if (hdrptr > unit_end) | |
9573 | { | |
9574 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
9575 | "for unit 0x%lx in the debug_names\n"), | |
9576 | (long) (hdrptr - section->start), | |
9577 | (long) (unit_end - section->start), | |
9578 | (long) (unit_start - section->start)); | |
9579 | return 0; | |
9580 | } | |
9581 | ||
9582 | size_t buckets_filled = 0; | |
9583 | size_t bucketi; | |
9584 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
9585 | { | |
9586 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
9587 | ||
9588 | if (bucket != 0) | |
9589 | ++buckets_filled; | |
9590 | } | |
d3a49aa8 AM |
9591 | printf (ngettext ("Used %zu of %lu bucket.\n", |
9592 | "Used %zu of %lu buckets.\n", | |
9593 | bucket_count), | |
9594 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 9595 | |
0a79bef4 | 9596 | uint32_t hash_prev = 0; |
61364358 JK |
9597 | size_t hash_clash_count = 0; |
9598 | size_t longest_clash = 0; | |
9599 | size_t this_length = 0; | |
9600 | size_t hashi; | |
9601 | for (hashi = 0; hashi < name_count; hashi++) | |
9602 | { | |
9603 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
9604 | ||
9605 | if (hashi > 0) | |
9606 | { | |
9607 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
9608 | { | |
9609 | ++hash_clash_count; | |
9610 | ++this_length; | |
9611 | longest_clash = MAX (longest_clash, this_length); | |
9612 | } | |
9613 | else | |
9614 | this_length = 0; | |
9615 | } | |
9616 | hash_prev = hash_this; | |
9617 | } | |
9618 | printf (_("Out of %lu items there are %zu bucket clashes" | |
9619 | " (longest of %zu entries).\n"), | |
9620 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
9621 | assert (name_count == buckets_filled + hash_clash_count); | |
9622 | ||
9623 | struct abbrev_lookup_entry | |
9624 | { | |
9625 | dwarf_vma abbrev_tag; | |
9626 | unsigned char *abbrev_lookup_ptr; | |
9627 | }; | |
9628 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
9629 | size_t abbrev_lookup_used = 0; | |
9630 | size_t abbrev_lookup_allocated = 0; | |
9631 | ||
9632 | unsigned char *abbrevptr = abbrev_table; | |
9633 | for (;;) | |
9634 | { | |
cd30bcef AM |
9635 | dwarf_vma abbrev_tag; |
9636 | ||
9637 | READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end); | |
61364358 JK |
9638 | if (abbrev_tag == 0) |
9639 | break; | |
9640 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
9641 | { | |
9642 | abbrev_lookup_allocated = MAX (0x100, | |
9643 | abbrev_lookup_allocated * 2); | |
9644 | abbrev_lookup = xrealloc (abbrev_lookup, | |
9645 | (abbrev_lookup_allocated | |
9646 | * sizeof (*abbrev_lookup))); | |
9647 | } | |
9648 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
9649 | struct abbrev_lookup_entry *entry; | |
9650 | for (entry = abbrev_lookup; | |
9651 | entry < abbrev_lookup + abbrev_lookup_used; | |
9652 | entry++) | |
9653 | if (entry->abbrev_tag == abbrev_tag) | |
9654 | { | |
9655 | warn (_("Duplicate abbreviation tag %lu " | |
9656 | "in unit 0x%lx in the debug_names\n"), | |
9657 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
9658 | break; | |
9659 | } | |
9660 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
9661 | entry->abbrev_tag = abbrev_tag; | |
9662 | entry->abbrev_lookup_ptr = abbrevptr; | |
9663 | ||
9664 | /* Skip DWARF tag. */ | |
cd30bcef | 9665 | SKIP_ULEB (abbrevptr, abbrev_table_end); |
61364358 JK |
9666 | for (;;) |
9667 | { | |
cd30bcef AM |
9668 | dwarf_vma xindex, form; |
9669 | ||
9670 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9671 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9672 | if (xindex == 0 && form == 0) |
61364358 JK |
9673 | break; |
9674 | } | |
9675 | } | |
9676 | ||
9677 | printf (_("\nSymbol table:\n")); | |
9678 | uint32_t namei; | |
9679 | for (namei = 0; namei < name_count; ++namei) | |
9680 | { | |
9681 | uint64_t string_offset, entry_offset; | |
9682 | ||
9683 | SAFE_BYTE_GET (string_offset, | |
9684 | name_table_string_offsets + namei * offset_size, | |
9685 | offset_size, unit_end); | |
9686 | SAFE_BYTE_GET (entry_offset, | |
9687 | name_table_entry_offsets + namei * offset_size, | |
9688 | offset_size, unit_end); | |
9689 | ||
9690 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
9691 | fetch_indirect_string (string_offset)); | |
9692 | ||
9693 | unsigned char *entryptr = entry_pool + entry_offset; | |
9694 | ||
279edac5 AM |
9695 | /* We need to scan first whether there is a single or multiple |
9696 | entries. TAGNO is -2 for the first entry, it is -1 for the | |
9697 | initial tag read of the second entry, then it becomes 0 for the | |
9698 | first entry for real printing etc. */ | |
61364358 JK |
9699 | int tagno = -2; |
9700 | /* Initialize it due to a false compiler warning. */ | |
9701 | dwarf_vma second_abbrev_tag = -1; | |
9702 | for (;;) | |
9703 | { | |
cd30bcef AM |
9704 | dwarf_vma abbrev_tag; |
9705 | dwarf_vma dwarf_tag; | |
9706 | const struct abbrev_lookup_entry *entry; | |
9707 | ||
9708 | READ_ULEB (abbrev_tag, entryptr, unit_end); | |
61364358 JK |
9709 | if (tagno == -1) |
9710 | { | |
9711 | second_abbrev_tag = abbrev_tag; | |
9712 | tagno = 0; | |
9713 | entryptr = entry_pool + entry_offset; | |
9714 | continue; | |
9715 | } | |
9716 | if (abbrev_tag == 0) | |
9717 | break; | |
9718 | if (tagno >= 0) | |
9719 | printf ("%s<%lu>", | |
9720 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
9721 | (unsigned long) abbrev_tag); | |
9722 | ||
61364358 JK |
9723 | for (entry = abbrev_lookup; |
9724 | entry < abbrev_lookup + abbrev_lookup_used; | |
9725 | entry++) | |
9726 | if (entry->abbrev_tag == abbrev_tag) | |
9727 | break; | |
9728 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
9729 | { | |
9730 | warn (_("Undefined abbreviation tag %lu " | |
9731 | "in unit 0x%lx in the debug_names\n"), | |
9732 | (long) abbrev_tag, | |
9733 | (long) (unit_start - section->start)); | |
9734 | break; | |
9735 | } | |
9736 | abbrevptr = entry->abbrev_lookup_ptr; | |
cd30bcef | 9737 | READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end); |
61364358 JK |
9738 | if (tagno >= 0) |
9739 | printf (" %s", get_TAG_name (dwarf_tag)); | |
9740 | for (;;) | |
9741 | { | |
cd30bcef AM |
9742 | dwarf_vma xindex, form; |
9743 | ||
9744 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9745 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9746 | if (xindex == 0 && form == 0) |
61364358 JK |
9747 | break; |
9748 | ||
9749 | if (tagno >= 0) | |
1d827a72 | 9750 | printf (" %s", get_IDX_name (xindex)); |
ec1b0fbb NC |
9751 | entryptr = read_and_display_attr_value (0, form, 0, |
9752 | unit_start, entryptr, unit_end, | |
9753 | 0, 0, offset_size, | |
61364358 JK |
9754 | dwarf_version, NULL, |
9755 | (tagno < 0), NULL, | |
ec1b0fbb | 9756 | NULL, '=', -1); |
61364358 JK |
9757 | } |
9758 | ++tagno; | |
9759 | } | |
9760 | if (tagno <= 0) | |
9761 | printf (_(" <no entries>")); | |
9762 | putchar ('\n'); | |
9763 | } | |
9764 | ||
9765 | free (abbrev_lookup); | |
9766 | } | |
9767 | ||
9768 | return 1; | |
9769 | } | |
9770 | ||
dda8d76d | 9771 | static int |
d85bf2ba NC |
9772 | display_debug_links (struct dwarf_section * section, |
9773 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
9774 | { |
9775 | const unsigned char * filename; | |
9776 | unsigned int filelen; | |
9777 | ||
9778 | introduce (section, FALSE); | |
9779 | ||
9780 | /* The .gnu_debuglink section is formatted as: | |
9781 | (c-string) Filename. | |
9782 | (padding) If needed to reach a 4 byte boundary. | |
9783 | (uint32_t) CRC32 value. | |
9784 | ||
9785 | The .gun_debugaltlink section is formatted as: | |
9786 | (c-string) Filename. | |
9787 | (binary) Build-ID. */ | |
521d4b19 | 9788 | |
dda8d76d NC |
9789 | filename = section->start; |
9790 | filelen = strnlen ((const char *) filename, section->size); | |
9791 | if (filelen == section->size) | |
9792 | { | |
9793 | warn (_("The debuglink filename is corrupt/missing\n")); | |
9794 | return 0; | |
9795 | } | |
9796 | ||
9797 | printf (_(" Separate debug info file: %s\n"), filename); | |
9798 | ||
9799 | if (const_strneq (section->name, ".gnu_debuglink")) | |
9800 | { | |
9801 | unsigned int crc32; | |
9802 | unsigned int crc_offset; | |
9803 | ||
9804 | crc_offset = filelen + 1; | |
9805 | crc_offset = (crc_offset + 3) & ~3; | |
9806 | if (crc_offset + 4 > section->size) | |
9807 | { | |
9808 | warn (_("CRC offset missing/truncated\n")); | |
9809 | return 0; | |
9810 | } | |
9811 | ||
9812 | crc32 = byte_get (filename + crc_offset, 4); | |
9813 | ||
9814 | printf (_(" CRC value: %#x\n"), crc32); | |
9815 | ||
9816 | if (crc_offset + 4 < section->size) | |
9817 | { | |
9818 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
9819 | (long)(section->size - (crc_offset + 4))); | |
9820 | return 0; | |
9821 | } | |
9822 | } | |
9823 | else /* const_strneq (section->name, ".gnu_debugaltlink") */ | |
9824 | { | |
9825 | const unsigned char * build_id = section->start + filelen + 1; | |
9826 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
9827 | bfd_size_type printed; | |
9828 | ||
9829 | /* FIXME: Should we support smaller build-id notes ? */ | |
9830 | if (build_id_len < 0x14) | |
9831 | { | |
9832 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
9833 | return 0; | |
9834 | } | |
9835 | ||
9836 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 9837 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
9838 | putchar ('\n'); |
9839 | } | |
9840 | ||
9841 | putchar ('\n'); | |
9842 | return 1; | |
9843 | } | |
9844 | ||
5bbdf3d5 DE |
9845 | static int |
9846 | display_gdb_index (struct dwarf_section *section, | |
9847 | void *file ATTRIBUTE_UNUSED) | |
9848 | { | |
9849 | unsigned char *start = section->start; | |
9850 | uint32_t version; | |
9851 | uint32_t cu_list_offset, tu_list_offset; | |
9852 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
9853 | unsigned int cu_list_elements, tu_list_elements; | |
9854 | unsigned int address_table_size, symbol_table_slots; | |
9855 | unsigned char *cu_list, *tu_list; | |
9856 | unsigned char *address_table, *symbol_table, *constant_pool; | |
9857 | unsigned int i; | |
9858 | ||
9859 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
9860 | ||
dda8d76d | 9861 | introduce (section, FALSE); |
5bbdf3d5 DE |
9862 | |
9863 | if (section->size < 6 * sizeof (uint32_t)) | |
9864 | { | |
9865 | warn (_("Truncated header in the %s section.\n"), section->name); | |
9866 | return 0; | |
9867 | } | |
9868 | ||
9869 | version = byte_get_little_endian (start, 4); | |
da88a764 | 9870 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
9871 | |
9872 | /* Prior versions are obsolete, and future versions may not be | |
9873 | backwards compatible. */ | |
aa170720 | 9874 | if (version < 3 || version > 8) |
5bbdf3d5 | 9875 | { |
da88a764 | 9876 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
9877 | return 0; |
9878 | } | |
8d6eee87 TT |
9879 | if (version < 4) |
9880 | warn (_("The address table data in version 3 may be wrong.\n")); | |
9881 | if (version < 5) | |
9882 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
9883 | if (version < 6) | |
9884 | warn (_("Version 5 does not include inlined functions.\n")); | |
9885 | if (version < 7) | |
9886 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
9887 | /* Version 7 indices generated by Gold have bad type unit references, |
9888 | PR binutils/15021. But we don't know if the index was generated by | |
9889 | Gold or not, so to avoid worrying users with gdb-generated indices | |
9890 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
9891 | |
9892 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
9893 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
9894 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
9895 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
9896 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
9897 | ||
9898 | if (cu_list_offset > section->size | |
9899 | || tu_list_offset > section->size | |
9900 | || address_table_offset > section->size | |
9901 | || symbol_table_offset > section->size | |
9902 | || constant_pool_offset > section->size) | |
9903 | { | |
9904 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
9905 | return 0; | |
9906 | } | |
9907 | ||
53774b7e NC |
9908 | /* PR 17531: file: 418d0a8a. */ |
9909 | if (tu_list_offset < cu_list_offset) | |
9910 | { | |
9911 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
9912 | tu_list_offset, cu_list_offset); | |
9913 | return 0; | |
9914 | } | |
9915 | ||
5bbdf3d5 | 9916 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
9917 | |
9918 | if (address_table_offset < tu_list_offset) | |
9919 | { | |
9920 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
9921 | address_table_offset, tu_list_offset); | |
9922 | return 0; | |
9923 | } | |
9924 | ||
5bbdf3d5 | 9925 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
9926 | |
9927 | /* PR 17531: file: 18a47d3d. */ | |
9928 | if (symbol_table_offset < address_table_offset) | |
9929 | { | |
13bace4a | 9930 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
9931 | symbol_table_offset, address_table_offset); |
9932 | return 0; | |
9933 | } | |
9934 | ||
5bbdf3d5 | 9935 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
9936 | |
9937 | if (constant_pool_offset < symbol_table_offset) | |
9938 | { | |
9939 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
9940 | constant_pool_offset, symbol_table_offset); | |
9941 | return 0; | |
9942 | } | |
9943 | ||
5bbdf3d5 DE |
9944 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
9945 | ||
9946 | cu_list = start + cu_list_offset; | |
9947 | tu_list = start + tu_list_offset; | |
9948 | address_table = start + address_table_offset; | |
9949 | symbol_table = start + symbol_table_offset; | |
9950 | constant_pool = start + constant_pool_offset; | |
9951 | ||
28d909e5 | 9952 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 9953 | { |
1306a742 | 9954 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
9955 | return 0; |
9956 | } | |
b4eb7656 | 9957 | |
5bbdf3d5 DE |
9958 | printf (_("\nCU table:\n")); |
9959 | for (i = 0; i < cu_list_elements; i += 2) | |
9960 | { | |
9961 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
9962 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
9963 | ||
9964 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
9965 | (unsigned long) cu_offset, | |
9966 | (unsigned long) (cu_offset + cu_length - 1)); | |
9967 | } | |
9968 | ||
9969 | printf (_("\nTU table:\n")); | |
9970 | for (i = 0; i < tu_list_elements; i += 3) | |
9971 | { | |
9972 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
9973 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
9974 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
9975 | ||
9976 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
9977 | (unsigned long) tu_offset, | |
9978 | (unsigned long) type_offset); | |
9979 | print_dwarf_vma (signature, 8); | |
9980 | printf ("\n"); | |
9981 | } | |
9982 | ||
9983 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
9984 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
9985 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
9986 | { |
9987 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
9988 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
9989 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
9990 | ||
9991 | print_dwarf_vma (low, 8); | |
9992 | print_dwarf_vma (high, 8); | |
da88a764 | 9993 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
9994 | } |
9995 | ||
9996 | printf (_("\nSymbol table:\n")); | |
9997 | for (i = 0; i < symbol_table_slots; ++i) | |
9998 | { | |
9999 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
10000 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
10001 | uint32_t num_cus, cu; | |
10002 | ||
10003 | if (name_offset != 0 | |
10004 | || cu_vector_offset != 0) | |
10005 | { | |
10006 | unsigned int j; | |
362beea4 | 10007 | unsigned char * adr; |
5bbdf3d5 | 10008 | |
362beea4 | 10009 | adr = constant_pool + name_offset; |
53774b7e | 10010 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 10011 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
10012 | { |
10013 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
10014 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
10015 | name_offset, i); | |
10016 | } | |
10017 | else | |
acff9664 NC |
10018 | printf ("[%3u] %.*s:", i, |
10019 | (int) (section->size - (constant_pool_offset + name_offset)), | |
10020 | constant_pool + name_offset); | |
53774b7e | 10021 | |
362beea4 NC |
10022 | adr = constant_pool + cu_vector_offset; |
10023 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
10024 | { |
10025 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
10026 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
10027 | cu_vector_offset, i); | |
10028 | continue; | |
10029 | } | |
57028622 | 10030 | |
362beea4 | 10031 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 10032 | |
362beea4 | 10033 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 10034 | if (num_cus * 4 < num_cus |
362beea4 NC |
10035 | || adr >= section->start + section->size |
10036 | || adr < constant_pool) | |
53774b7e NC |
10037 | { |
10038 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 10039 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
10040 | num_cus, i); |
10041 | continue; | |
10042 | } | |
10043 | ||
8d6eee87 TT |
10044 | if (num_cus > 1) |
10045 | printf ("\n"); | |
f3853b34 | 10046 | |
5bbdf3d5 DE |
10047 | for (j = 0; j < num_cus; ++j) |
10048 | { | |
7c1cef97 | 10049 | int is_static; |
8d6eee87 TT |
10050 | gdb_index_symbol_kind kind; |
10051 | ||
5bbdf3d5 | 10052 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 10053 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
10054 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
10055 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 10056 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 10057 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
10058 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
10059 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 10060 | else |
8d6eee87 TT |
10061 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
10062 | ||
459d52c8 DE |
10063 | printf (" [%s, %s]", |
10064 | is_static ? _("static") : _("global"), | |
10065 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
10066 | if (num_cus > 1) |
10067 | printf ("\n"); | |
5bbdf3d5 | 10068 | } |
8d6eee87 TT |
10069 | if (num_cus <= 1) |
10070 | printf ("\n"); | |
5bbdf3d5 DE |
10071 | } |
10072 | } | |
10073 | ||
10074 | return 1; | |
10075 | } | |
10076 | ||
657d0d47 CC |
10077 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
10078 | ||
10079 | static void | |
10080 | prealloc_cu_tu_list (unsigned int nshndx) | |
10081 | { | |
10082 | if (shndx_pool == NULL) | |
10083 | { | |
10084 | shndx_pool_size = nshndx; | |
10085 | shndx_pool_used = 0; | |
10086 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
10087 | sizeof (unsigned int)); | |
10088 | } | |
10089 | else | |
10090 | { | |
10091 | shndx_pool_size = shndx_pool_used + nshndx; | |
10092 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
10093 | sizeof (unsigned int)); | |
10094 | } | |
10095 | } | |
10096 | ||
10097 | static void | |
10098 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
10099 | { | |
10100 | if (shndx_pool_used >= shndx_pool_size) | |
10101 | { | |
10102 | error (_("Internal error: out of space in the shndx pool.\n")); | |
10103 | return; | |
10104 | } | |
10105 | shndx_pool [shndx_pool_used++] = shndx; | |
10106 | } | |
10107 | ||
10108 | static void | |
10109 | end_cu_tu_entry (void) | |
10110 | { | |
10111 | if (shndx_pool_used >= shndx_pool_size) | |
10112 | { | |
10113 | error (_("Internal error: out of space in the shndx pool.\n")); | |
10114 | return; | |
10115 | } | |
10116 | shndx_pool [shndx_pool_used++] = 0; | |
10117 | } | |
10118 | ||
341f9135 CC |
10119 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
10120 | ||
10121 | static const char * | |
10122 | get_DW_SECT_short_name (unsigned int dw_sect) | |
10123 | { | |
10124 | static char buf[16]; | |
10125 | ||
10126 | switch (dw_sect) | |
10127 | { | |
10128 | case DW_SECT_INFO: | |
10129 | return "info"; | |
10130 | case DW_SECT_TYPES: | |
10131 | return "types"; | |
10132 | case DW_SECT_ABBREV: | |
10133 | return "abbrev"; | |
10134 | case DW_SECT_LINE: | |
10135 | return "line"; | |
10136 | case DW_SECT_LOC: | |
10137 | return "loc"; | |
10138 | case DW_SECT_STR_OFFSETS: | |
10139 | return "str_off"; | |
10140 | case DW_SECT_MACINFO: | |
10141 | return "macinfo"; | |
10142 | case DW_SECT_MACRO: | |
10143 | return "macro"; | |
10144 | default: | |
b4eb7656 | 10145 | break; |
341f9135 CC |
10146 | } |
10147 | ||
10148 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
10149 | return buf; | |
10150 | } | |
10151 | ||
10152 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
10153 | These sections are extensions for Fission. | |
10154 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
10155 | |
10156 | static int | |
10157 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
10158 | { | |
10159 | unsigned char *phdr = section->start; | |
10160 | unsigned char *limit = phdr + section->size; | |
10161 | unsigned char *phash; | |
10162 | unsigned char *pindex; | |
10163 | unsigned char *ppool; | |
10164 | unsigned int version; | |
341f9135 | 10165 | unsigned int ncols = 0; |
657d0d47 CC |
10166 | unsigned int nused; |
10167 | unsigned int nslots; | |
10168 | unsigned int i; | |
341f9135 CC |
10169 | unsigned int j; |
10170 | dwarf_vma signature_high; | |
10171 | dwarf_vma signature_low; | |
10172 | char buf[64]; | |
657d0d47 | 10173 | |
6937bb54 NC |
10174 | /* PR 17512: file: 002-168123-0.004. */ |
10175 | if (phdr == NULL) | |
10176 | { | |
10177 | warn (_("Section %s is empty\n"), section->name); | |
10178 | return 0; | |
10179 | } | |
10180 | /* PR 17512: file: 002-376-0.004. */ | |
10181 | if (section->size < 24) | |
10182 | { | |
72c61a0d | 10183 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
10184 | section->name); |
10185 | return 0; | |
10186 | } | |
10187 | ||
10188 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 10189 | if (version >= 2) |
6937bb54 NC |
10190 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
10191 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
10192 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
10193 | ||
657d0d47 | 10194 | phash = phdr + 16; |
8e2e3c6c AM |
10195 | pindex = phash + (size_t) nslots * 8; |
10196 | ppool = pindex + (size_t) nslots * 4; | |
57028622 | 10197 | |
657d0d47 CC |
10198 | if (do_display) |
10199 | { | |
dda8d76d NC |
10200 | introduce (section, FALSE); |
10201 | ||
8e2e3c6c | 10202 | printf (_(" Version: %u\n"), version); |
341f9135 | 10203 | if (version >= 2) |
8e2e3c6c AM |
10204 | printf (_(" Number of columns: %u\n"), ncols); |
10205 | printf (_(" Number of used entries: %u\n"), nused); | |
10206 | printf (_(" Number of slots: %u\n\n"), nslots); | |
657d0d47 CC |
10207 | } |
10208 | ||
8e2e3c6c AM |
10209 | /* PR 17531: file: 45d69832. */ |
10210 | if ((size_t) nslots * 8 / 8 != nslots | |
10211 | || phash < phdr || phash > limit | |
10212 | || pindex < phash || pindex > limit | |
10213 | || ppool < pindex || ppool > limit) | |
657d0d47 | 10214 | { |
8e2e3c6c AM |
10215 | warn (ngettext ("Section %s is too small for %u slot\n", |
10216 | "Section %s is too small for %u slots\n", | |
10217 | nslots), | |
657d0d47 CC |
10218 | section->name, nslots); |
10219 | return 0; | |
10220 | } | |
10221 | ||
341f9135 | 10222 | if (version == 1) |
657d0d47 | 10223 | { |
341f9135 CC |
10224 | if (!do_display) |
10225 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
10226 | for (i = 0; i < nslots; i++) | |
657d0d47 | 10227 | { |
341f9135 CC |
10228 | unsigned char *shndx_list; |
10229 | unsigned int shndx; | |
10230 | ||
6937bb54 | 10231 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 10232 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 10233 | { |
6937bb54 | 10234 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 10235 | shndx_list = ppool + j * 4; |
f3853b34 NC |
10236 | /* PR 17531: file: 705e010d. */ |
10237 | if (shndx_list < ppool) | |
10238 | { | |
10239 | warn (_("Section index pool located before start of section\n")); | |
10240 | return 0; | |
10241 | } | |
10242 | ||
341f9135 CC |
10243 | if (do_display) |
10244 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
10245 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10246 | buf, sizeof (buf))); | |
10247 | for (;;) | |
657d0d47 | 10248 | { |
341f9135 CC |
10249 | if (shndx_list >= limit) |
10250 | { | |
10251 | warn (_("Section %s too small for shndx pool\n"), | |
10252 | section->name); | |
10253 | return 0; | |
10254 | } | |
6937bb54 | 10255 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
10256 | if (shndx == 0) |
10257 | break; | |
10258 | if (do_display) | |
10259 | printf (" %d", shndx); | |
10260 | else | |
10261 | add_shndx_to_cu_tu_entry (shndx); | |
10262 | shndx_list += 4; | |
657d0d47 | 10263 | } |
657d0d47 | 10264 | if (do_display) |
341f9135 | 10265 | printf ("\n"); |
657d0d47 | 10266 | else |
341f9135 CC |
10267 | end_cu_tu_entry (); |
10268 | } | |
10269 | phash += 8; | |
10270 | pindex += 4; | |
10271 | } | |
10272 | } | |
10273 | else if (version == 2) | |
10274 | { | |
10275 | unsigned int val; | |
10276 | unsigned int dw_sect; | |
10277 | unsigned char *ph = phash; | |
10278 | unsigned char *pi = pindex; | |
8e2e3c6c AM |
10279 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
10280 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
10281 | unsigned char *pend = psizes + (size_t) nused * ncols * 4; | |
341f9135 CC |
10282 | bfd_boolean is_tu_index; |
10283 | struct cu_tu_set *this_set = NULL; | |
10284 | unsigned int row; | |
10285 | unsigned char *prow; | |
10286 | ||
10287 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
10288 | ||
362beea4 | 10289 | /* PR 17531: file: 0dd159bf. |
8e2e3c6c AM |
10290 | Check for integer overflow (can occur when size_t is 32-bit) |
10291 | with overlarge ncols or nused values. */ | |
4ac948a0 NC |
10292 | if (ncols > 0 |
10293 | && ((size_t) ncols * 4 / 4 != ncols | |
10294 | || (size_t) nused * ncols * 4 / ((size_t) ncols * 4) != nused | |
10295 | || poffsets < ppool || poffsets > limit | |
10296 | || psizes < poffsets || psizes > limit | |
10297 | || pend < psizes || pend > limit)) | |
341f9135 CC |
10298 | { |
10299 | warn (_("Section %s too small for offset and size tables\n"), | |
10300 | section->name); | |
10301 | return 0; | |
10302 | } | |
10303 | ||
10304 | if (do_display) | |
10305 | { | |
10306 | printf (_(" Offset table\n")); | |
10307 | printf (" slot %-16s ", | |
10308 | is_tu_index ? _("signature") : _("dwo_id")); | |
10309 | } | |
10310 | else | |
10311 | { | |
10312 | if (is_tu_index) | |
10313 | { | |
10314 | tu_count = nused; | |
72c61a0d | 10315 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 10316 | this_set = tu_sets; |
657d0d47 | 10317 | } |
657d0d47 | 10318 | else |
341f9135 CC |
10319 | { |
10320 | cu_count = nused; | |
72c61a0d | 10321 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
10322 | this_set = cu_sets; |
10323 | } | |
10324 | } | |
6937bb54 | 10325 | |
341f9135 CC |
10326 | if (do_display) |
10327 | { | |
10328 | for (j = 0; j < ncols; j++) | |
10329 | { | |
6937bb54 | 10330 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
10331 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
10332 | } | |
10333 | printf ("\n"); | |
10334 | } | |
6937bb54 | 10335 | |
341f9135 CC |
10336 | for (i = 0; i < nslots; i++) |
10337 | { | |
6937bb54 NC |
10338 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
10339 | ||
10340 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10341 | if (row != 0) |
10342 | { | |
591f7597 | 10343 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 10344 | if (row > nused) |
591f7597 NC |
10345 | { |
10346 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
10347 | row, nused); | |
10348 | return 0; | |
10349 | } | |
10350 | ||
341f9135 | 10351 | if (!do_display) |
6aea08d9 NC |
10352 | { |
10353 | size_t num_copy = sizeof (uint64_t); | |
10354 | ||
10355 | /* PR 23064: Beware of buffer overflow. */ | |
10356 | if (ph + num_copy < limit) | |
10357 | memcpy (&this_set[row - 1].signature, ph, num_copy); | |
10358 | else | |
10359 | { | |
10360 | warn (_("Signature (%p) extends beyond end of space in section\n"), ph); | |
10361 | return 0; | |
10362 | } | |
10363 | } | |
6937bb54 | 10364 | |
341f9135 | 10365 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
10366 | /* PR 17531: file: b8ce60a8. */ |
10367 | if (prow < poffsets || prow > limit) | |
10368 | { | |
10369 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
10370 | row, ncols); | |
10371 | return 0; | |
10372 | } | |
3aade688 | 10373 | |
341f9135 CC |
10374 | if (do_display) |
10375 | printf (_(" [%3d] 0x%s"), | |
10376 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10377 | buf, sizeof (buf))); | |
10378 | for (j = 0; j < ncols; j++) | |
10379 | { | |
6937bb54 | 10380 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
10381 | if (do_display) |
10382 | printf (" %8d", val); | |
10383 | else | |
10384 | { | |
6937bb54 | 10385 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
10386 | |
10387 | /* PR 17531: file: 10796eb3. */ | |
10388 | if (dw_sect >= DW_SECT_MAX) | |
10389 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10390 | else | |
10391 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
10392 | } |
10393 | } | |
6937bb54 | 10394 | |
341f9135 CC |
10395 | if (do_display) |
10396 | printf ("\n"); | |
10397 | } | |
10398 | ph += 8; | |
10399 | pi += 4; | |
10400 | } | |
10401 | ||
10402 | ph = phash; | |
10403 | pi = pindex; | |
10404 | if (do_display) | |
b4eb7656 | 10405 | { |
341f9135 CC |
10406 | printf ("\n"); |
10407 | printf (_(" Size table\n")); | |
10408 | printf (" slot %-16s ", | |
10409 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 10410 | } |
6937bb54 | 10411 | |
341f9135 CC |
10412 | for (j = 0; j < ncols; j++) |
10413 | { | |
6937bb54 | 10414 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
10415 | if (do_display) |
10416 | printf (" %8s", get_DW_SECT_short_name (val)); | |
10417 | } | |
6937bb54 | 10418 | |
341f9135 CC |
10419 | if (do_display) |
10420 | printf ("\n"); | |
6937bb54 | 10421 | |
341f9135 CC |
10422 | for (i = 0; i < nslots; i++) |
10423 | { | |
6937bb54 NC |
10424 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
10425 | ||
10426 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10427 | if (row != 0) |
10428 | { | |
10429 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 10430 | |
341f9135 CC |
10431 | if (do_display) |
10432 | printf (_(" [%3d] 0x%s"), | |
10433 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10434 | buf, sizeof (buf))); | |
6937bb54 | 10435 | |
341f9135 CC |
10436 | for (j = 0; j < ncols; j++) |
10437 | { | |
6937bb54 | 10438 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
10439 | if (do_display) |
10440 | printf (" %8d", val); | |
10441 | else | |
10442 | { | |
6937bb54 | 10443 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
10444 | if (dw_sect >= DW_SECT_MAX) |
10445 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10446 | else | |
341f9135 CC |
10447 | this_set [row - 1].section_sizes [dw_sect] = val; |
10448 | } | |
10449 | } | |
6937bb54 | 10450 | |
341f9135 CC |
10451 | if (do_display) |
10452 | printf ("\n"); | |
10453 | } | |
6937bb54 | 10454 | |
341f9135 CC |
10455 | ph += 8; |
10456 | pi += 4; | |
657d0d47 | 10457 | } |
657d0d47 | 10458 | } |
341f9135 | 10459 | else if (do_display) |
6937bb54 | 10460 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
10461 | |
10462 | if (do_display) | |
10463 | printf ("\n"); | |
10464 | ||
10465 | return 1; | |
10466 | } | |
10467 | ||
288f0ba2 AM |
10468 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
10469 | ||
657d0d47 CC |
10470 | /* Load the CU and TU indexes if present. This will build a list of |
10471 | section sets that we can use to associate a .debug_info.dwo section | |
10472 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
10473 | ||
43a444f9 | 10474 | static bfd_boolean |
657d0d47 CC |
10475 | load_cu_tu_indexes (void *file) |
10476 | { | |
10477 | /* If we have already loaded (or tried to load) the CU and TU indexes | |
10478 | then do not bother to repeat the task. */ | |
43a444f9 NC |
10479 | if (cu_tu_indexes_read == -1) |
10480 | { | |
10481 | cu_tu_indexes_read = TRUE; | |
521d4b19 | 10482 | |
dda8d76d | 10483 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 NC |
10484 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
10485 | cu_tu_indexes_read = FALSE; | |
10486 | ||
dda8d76d | 10487 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 NC |
10488 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
10489 | cu_tu_indexes_read = FALSE; | |
10490 | } | |
657d0d47 | 10491 | |
43a444f9 | 10492 | return (bfd_boolean) cu_tu_indexes_read; |
657d0d47 CC |
10493 | } |
10494 | ||
10495 | /* Find the set of sections that includes section SHNDX. */ | |
10496 | ||
10497 | unsigned int * | |
10498 | find_cu_tu_set (void *file, unsigned int shndx) | |
10499 | { | |
10500 | unsigned int i; | |
10501 | ||
43a444f9 NC |
10502 | if (! load_cu_tu_indexes (file)) |
10503 | return NULL; | |
657d0d47 CC |
10504 | |
10505 | /* Find SHNDX in the shndx pool. */ | |
10506 | for (i = 0; i < shndx_pool_used; i++) | |
10507 | if (shndx_pool [i] == shndx) | |
10508 | break; | |
10509 | ||
10510 | if (i >= shndx_pool_used) | |
10511 | return NULL; | |
10512 | ||
10513 | /* Now backup to find the first entry in the set. */ | |
10514 | while (i > 0 && shndx_pool [i - 1] != 0) | |
10515 | i--; | |
10516 | ||
10517 | return shndx_pool + i; | |
10518 | } | |
10519 | ||
10520 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
10521 | ||
10522 | static int | |
10523 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
10524 | { | |
10525 | return process_cu_tu_index (section, 1); | |
10526 | } | |
10527 | ||
19e6b90e L |
10528 | static int |
10529 | display_debug_not_supported (struct dwarf_section *section, | |
10530 | void *file ATTRIBUTE_UNUSED) | |
10531 | { | |
10532 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
10533 | section->name); | |
10534 | ||
10535 | return 1; | |
10536 | } | |
10537 | ||
1306a742 NC |
10538 | /* Like malloc, but takes two parameters like calloc. |
10539 | Verifies that the first parameter is not too large. | |
82b1b41b | 10540 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 10541 | |
19e6b90e L |
10542 | void * |
10543 | cmalloc (size_t nmemb, size_t size) | |
10544 | { | |
10545 | /* Check for overflow. */ | |
10546 | if (nmemb >= ~(size_t) 0 / size) | |
10547 | return NULL; | |
82b1b41b NC |
10548 | |
10549 | return xmalloc (nmemb * size); | |
19e6b90e L |
10550 | } |
10551 | ||
1306a742 NC |
10552 | /* Like xmalloc, but takes two parameters like calloc. |
10553 | Verifies that the first parameter is not too large. | |
10554 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 10555 | |
72c61a0d | 10556 | void * |
1306a742 | 10557 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
10558 | { |
10559 | /* Check for overflow. */ | |
10560 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
10561 | { |
10562 | fprintf (stderr, | |
10563 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
10564 | (long) nmemb); | |
10565 | xexit (1); | |
10566 | } | |
72c61a0d | 10567 | |
1306a742 | 10568 | return xmalloc (nmemb * size); |
72c61a0d NC |
10569 | } |
10570 | ||
1306a742 NC |
10571 | /* Like xrealloc, but takes three parameters. |
10572 | Verifies that the second parameter is not too large. | |
10573 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 10574 | |
19e6b90e | 10575 | void * |
1306a742 | 10576 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
10577 | { |
10578 | /* Check for overflow. */ | |
10579 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10580 | { |
dda8d76d NC |
10581 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
10582 | (long) nmemb); | |
8490fb40 NC |
10583 | xexit (1); |
10584 | } | |
82b1b41b | 10585 | |
1306a742 | 10586 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
10587 | } |
10588 | ||
1306a742 | 10589 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 10590 | |
19e6b90e | 10591 | void * |
1306a742 | 10592 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
10593 | { |
10594 | /* Check for overflow. */ | |
10595 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10596 | { |
dda8d76d NC |
10597 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
10598 | (long) nmemb); | |
8490fb40 NC |
10599 | xexit (1); |
10600 | } | |
82b1b41b | 10601 | |
1306a742 | 10602 | return xcalloc (nmemb, size); |
19e6b90e L |
10603 | } |
10604 | ||
dda8d76d NC |
10605 | static unsigned long |
10606 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
10607 | const unsigned char * buf, | |
10608 | bfd_size_type len) | |
10609 | { | |
10610 | static const unsigned long crc32_table[256] = | |
10611 | { | |
10612 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
10613 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
10614 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
10615 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
10616 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
10617 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
10618 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
10619 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
10620 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
10621 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
10622 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
10623 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
10624 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
10625 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
10626 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
10627 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
10628 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
10629 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
10630 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
10631 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
10632 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
10633 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
10634 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
10635 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
10636 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
10637 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
10638 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
10639 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
10640 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
10641 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
10642 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
10643 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
10644 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
10645 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
10646 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
10647 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
10648 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
10649 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
10650 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
10651 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
10652 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
10653 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
10654 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
10655 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
10656 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
10657 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
10658 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
10659 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
10660 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
10661 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
10662 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
10663 | 0x2d02ef8d | |
10664 | }; | |
10665 | const unsigned char *end; | |
10666 | ||
10667 | crc = ~crc & 0xffffffff; | |
10668 | for (end = buf + len; buf < end; ++ buf) | |
10669 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
10670 | return ~crc & 0xffffffff; | |
10671 | } | |
10672 | ||
10673 | typedef bfd_boolean (* check_func_type) (const char *, void *); | |
10674 | typedef const char * (* parse_func_type) (struct dwarf_section *, void *); | |
10675 | ||
10676 | static bfd_boolean | |
10677 | check_gnu_debuglink (const char * pathname, void * crc_pointer) | |
10678 | { | |
10679 | static unsigned char buffer [8 * 1024]; | |
10680 | FILE * f; | |
10681 | bfd_size_type count; | |
10682 | unsigned long crc = 0; | |
10683 | void * sep_data; | |
10684 | ||
10685 | sep_data = open_debug_file (pathname); | |
10686 | if (sep_data == NULL) | |
10687 | return FALSE; | |
10688 | ||
10689 | /* Yes - we are opening the file twice... */ | |
10690 | f = fopen (pathname, "rb"); | |
10691 | if (f == NULL) | |
10692 | { | |
10693 | /* Paranoia: This should never happen. */ | |
10694 | close_debug_file (sep_data); | |
10695 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
10696 | return FALSE; | |
10697 | } | |
10698 | ||
10699 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
10700 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
10701 | ||
10702 | fclose (f); | |
10703 | ||
10704 | if (crc != * (unsigned long *) crc_pointer) | |
10705 | { | |
10706 | close_debug_file (sep_data); | |
10707 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
10708 | pathname); | |
10709 | return FALSE; | |
10710 | } | |
10711 | ||
10712 | return TRUE; | |
10713 | } | |
10714 | ||
10715 | static const char * | |
10716 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
10717 | { | |
10718 | const char * name; | |
10719 | unsigned int crc_offset; | |
10720 | unsigned long * crc32 = (unsigned long *) data; | |
10721 | ||
10722 | /* The name is first. | |
10723 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
10724 | name = (const char *) section->start; | |
10725 | ||
10726 | crc_offset = strnlen (name, section->size) + 1; | |
10727 | crc_offset = (crc_offset + 3) & ~3; | |
10728 | if (crc_offset + 4 > section->size) | |
10729 | return NULL; | |
10730 | ||
10731 | * crc32 = byte_get (section->start + crc_offset, 4); | |
10732 | return name; | |
10733 | } | |
10734 | ||
10735 | static bfd_boolean | |
10736 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) | |
10737 | { | |
10738 | void * sep_data = open_debug_file (filename); | |
10739 | ||
10740 | if (sep_data == NULL) | |
10741 | return FALSE; | |
10742 | ||
10743 | /* FIXME: We should now extract the build-id in the separate file | |
10744 | and check it... */ | |
10745 | ||
10746 | return TRUE; | |
10747 | } | |
10748 | ||
10749 | typedef struct build_id_data | |
10750 | { | |
10751 | bfd_size_type len; | |
10752 | const unsigned char * data; | |
10753 | } Build_id_data; | |
10754 | ||
10755 | static const char * | |
10756 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
10757 | { | |
10758 | const char * name; | |
10759 | bfd_size_type namelen; | |
10760 | bfd_size_type id_len; | |
10761 | Build_id_data * build_id_data; | |
10762 | ||
10763 | /* The name is first. | |
10764 | The build-id follows immediately, with no padding, up to the section's end. */ | |
10765 | ||
10766 | name = (const char *) section->start; | |
10767 | namelen = strnlen (name, section->size) + 1; | |
10768 | if (namelen >= section->size) | |
10769 | return NULL; | |
10770 | ||
10771 | id_len = section->size - namelen; | |
10772 | if (id_len < 0x14) | |
10773 | return NULL; | |
10774 | ||
dfbee680 | 10775 | build_id_data = (Build_id_data *) data; |
dda8d76d NC |
10776 | build_id_data->len = id_len; |
10777 | build_id_data->data = section->start + namelen; | |
10778 | ||
dda8d76d NC |
10779 | return name; |
10780 | } | |
10781 | ||
24841daa NC |
10782 | static void |
10783 | add_separate_debug_file (const char * filename, void * handle) | |
10784 | { | |
10785 | separate_info * i = xmalloc (sizeof * i); | |
10786 | ||
10787 | i->filename = filename; | |
10788 | i->handle = handle; | |
10789 | i->next = first_separate_info; | |
10790 | first_separate_info = i; | |
10791 | } | |
10792 | ||
301a9420 AM |
10793 | #if HAVE_LIBDEBUGINFOD |
10794 | /* Query debuginfod servers for the target debuglink or debugaltlink | |
10795 | file. If successful, store the path of the file in filename and | |
10796 | return TRUE, otherwise return FALSE. */ | |
10797 | ||
10798 | static bfd_boolean | |
10799 | debuginfod_fetch_separate_debug_info (struct dwarf_section * section, | |
10800 | char ** filename, | |
10801 | void * file) | |
10802 | { | |
10803 | size_t build_id_len; | |
10804 | unsigned char * build_id; | |
10805 | ||
10806 | if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0) | |
10807 | { | |
10808 | /* Get the build-id of file. */ | |
10809 | build_id = get_build_id (file); | |
10810 | build_id_len = 0; | |
10811 | } | |
10812 | else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0) | |
10813 | { | |
10814 | /* Get the build-id of the debugaltlink file. */ | |
10815 | unsigned int filelen; | |
10816 | ||
10817 | filelen = strnlen ((const char *)section->start, section->size); | |
10818 | if (filelen == section->size) | |
10819 | /* Corrupt debugaltlink. */ | |
10820 | return FALSE; | |
10821 | ||
10822 | build_id = section->start + filelen + 1; | |
10823 | build_id_len = section->size - (filelen + 1); | |
10824 | ||
10825 | if (build_id_len == 0) | |
10826 | return FALSE; | |
10827 | } | |
10828 | else | |
10829 | return FALSE; | |
10830 | ||
10831 | if (build_id) | |
10832 | { | |
10833 | int fd; | |
10834 | debuginfod_client * client; | |
10835 | ||
10836 | client = debuginfod_begin (); | |
10837 | if (client == NULL) | |
10838 | return FALSE; | |
10839 | ||
10840 | /* Query debuginfod servers for the target file. If found its path | |
10841 | will be stored in filename. */ | |
10842 | fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename); | |
10843 | debuginfod_end (client); | |
10844 | ||
10845 | /* Only free build_id if we allocated space for a hex string | |
10846 | in get_build_id (). */ | |
10847 | if (build_id_len == 0) | |
10848 | free (build_id); | |
10849 | ||
10850 | if (fd >= 0) | |
10851 | { | |
10852 | /* File successfully retrieved. Close fd since we want to | |
10853 | use open_debug_file () on filename instead. */ | |
10854 | close (fd); | |
10855 | return TRUE; | |
10856 | } | |
10857 | } | |
10858 | ||
10859 | return FALSE; | |
10860 | } | |
10861 | #endif | |
10862 | ||
dda8d76d NC |
10863 | static void * |
10864 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 10865 | struct dwarf_section * xlink, |
dda8d76d NC |
10866 | parse_func_type parse_func, |
10867 | check_func_type check_func, | |
301a9420 AM |
10868 | void * func_data, |
10869 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
10870 | { |
10871 | const char * separate_filename; | |
24841daa | 10872 | char * debug_filename; |
dda8d76d NC |
10873 | char * canon_dir; |
10874 | size_t canon_dirlen; | |
10875 | size_t dirlen; | |
10876 | ||
2b63c337 | 10877 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
10878 | { |
10879 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 10880 | xlink->name ? xlink->name : xlink->uncompressed_name); |
ce139cd5 | 10881 | return NULL; |
dda8d76d | 10882 | } |
521d4b19 | 10883 | |
dda8d76d NC |
10884 | /* Attempt to locate the separate file. |
10885 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
10886 | ||
10887 | canon_dir = lrealpath (main_filename); | |
521d4b19 | 10888 | |
dda8d76d NC |
10889 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) |
10890 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
10891 | break; | |
10892 | canon_dir[canon_dirlen] = '\0'; | |
10893 | ||
10894 | #ifndef DEBUGDIR | |
10895 | #define DEBUGDIR "/lib/debug" | |
10896 | #endif | |
10897 | #ifndef EXTRA_DEBUG_ROOT1 | |
10898 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
10899 | #endif | |
10900 | #ifndef EXTRA_DEBUG_ROOT2 | |
10901 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
10902 | #endif | |
10903 | ||
24841daa NC |
10904 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
10905 | + canon_dirlen | |
10906 | + strlen (".debug/") | |
dda8d76d | 10907 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 10908 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
10909 | #endif |
10910 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 10911 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 10912 | #endif |
24841daa NC |
10913 | + strlen (separate_filename) |
10914 | + 1); | |
10915 | if (debug_filename == NULL) | |
dda8d76d NC |
10916 | { |
10917 | warn (_("Out of memory")); | |
3391569f | 10918 | free (canon_dir); |
dda8d76d NC |
10919 | return NULL; |
10920 | } | |
10921 | ||
10922 | /* First try in the current directory. */ | |
24841daa NC |
10923 | sprintf (debug_filename, "%s", separate_filename); |
10924 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10925 | goto found; |
10926 | ||
10927 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
10928 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10929 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10930 | goto found; |
10931 | ||
10932 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
10933 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10934 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10935 | goto found; |
10936 | ||
10937 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
10938 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10939 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10940 | goto found; |
10941 | ||
10942 | #ifdef EXTRA_DEBUG_ROOT1 | |
10943 | /* Try the first extra debug file root. */ | |
24841daa NC |
10944 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10945 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 10946 | goto found; |
39f0547e NC |
10947 | |
10948 | /* Try the first extra debug file root. */ | |
10949 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
10950 | if (check_func (debug_filename, func_data)) | |
10951 | goto found; | |
dda8d76d NC |
10952 | #endif |
10953 | ||
10954 | #ifdef EXTRA_DEBUG_ROOT2 | |
10955 | /* Try the second extra debug file root. */ | |
24841daa NC |
10956 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10957 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10958 | goto found; |
10959 | #endif | |
10960 | ||
24841daa NC |
10961 | /* Then try in the global debug_filename directory. */ |
10962 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
10963 | dirlen = strlen (DEBUGDIR) - 1; |
10964 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
10965 | strcat (debug_filename, "/"); |
10966 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 10967 | |
24841daa | 10968 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
10969 | goto found; |
10970 | ||
301a9420 AM |
10971 | #if HAVE_LIBDEBUGINFOD |
10972 | { | |
10973 | char * tmp_filename; | |
10974 | ||
10975 | if (debuginfod_fetch_separate_debug_info (xlink, | |
10976 | & tmp_filename, | |
10977 | file)) | |
10978 | { | |
10979 | /* File successfully downloaded from server, replace | |
10980 | debug_filename with the file's path. */ | |
10981 | free (debug_filename); | |
10982 | debug_filename = tmp_filename; | |
10983 | goto found; | |
10984 | } | |
10985 | } | |
10986 | #endif | |
10987 | ||
dda8d76d NC |
10988 | /* Failed to find the file. */ |
10989 | warn (_("could not find separate debug file '%s'\n"), separate_filename); | |
24841daa | 10990 | warn (_("tried: %s\n"), debug_filename); |
dda8d76d NC |
10991 | |
10992 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa NC |
10993 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10994 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10995 | #endif |
10996 | ||
10997 | #ifdef EXTRA_DEBUG_ROOT1 | |
39f0547e NC |
10998 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); |
10999 | warn (_("tried: %s\n"), debug_filename); | |
11000 | ||
24841daa NC |
11001 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
11002 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
11003 | #endif |
11004 | ||
24841daa NC |
11005 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
11006 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11007 | |
24841daa NC |
11008 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
11009 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11010 | |
24841daa NC |
11011 | sprintf (debug_filename, ".debug/%s", separate_filename); |
11012 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11013 | |
24841daa NC |
11014 | sprintf (debug_filename, "%s", separate_filename); |
11015 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 11016 | |
301a9420 AM |
11017 | #if HAVE_LIBDEBUGINFOD |
11018 | { | |
11019 | char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR); | |
11020 | if (urls == NULL) | |
11021 | urls = ""; | |
11022 | ||
11023 | warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls); | |
11024 | } | |
11025 | #endif | |
11026 | ||
dda8d76d | 11027 | free (canon_dir); |
24841daa | 11028 | free (debug_filename); |
dda8d76d NC |
11029 | return NULL; |
11030 | ||
11031 | found: | |
11032 | free (canon_dir); | |
11033 | ||
24841daa NC |
11034 | void * debug_handle; |
11035 | ||
dda8d76d | 11036 | /* Now open the file.... */ |
24841daa | 11037 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 11038 | { |
24841daa NC |
11039 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
11040 | free (debug_filename); | |
ce139cd5 | 11041 | return NULL; |
dda8d76d NC |
11042 | } |
11043 | ||
11044 | /* FIXME: We do not check to see if there are any other separate debug info | |
11045 | files that would also match. */ | |
11046 | ||
24841daa NC |
11047 | printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debug_filename); |
11048 | add_separate_debug_file (debug_filename, debug_handle); | |
dda8d76d | 11049 | |
24841daa | 11050 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 11051 | the structure returned by open_debug_file(). */ |
24841daa | 11052 | return debug_handle; |
dda8d76d NC |
11053 | } |
11054 | ||
d85bf2ba NC |
11055 | /* Attempt to load a separate dwarf object file. */ |
11056 | ||
11057 | static void * | |
24841daa | 11058 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 11059 | { |
24841daa NC |
11060 | char * separate_filename; |
11061 | void * separate_handle; | |
d85bf2ba NC |
11062 | |
11063 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
24841daa NC |
11064 | separate_filename = concat (dir, "/", name, NULL); |
11065 | if (separate_filename == NULL) | |
d85bf2ba NC |
11066 | { |
11067 | warn (_("Out of memory allocating dwo filename\n")); | |
11068 | return NULL; | |
11069 | } | |
11070 | ||
24841daa | 11071 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 11072 | { |
24841daa NC |
11073 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
11074 | free (separate_filename); | |
d85bf2ba NC |
11075 | return NULL; |
11076 | } | |
11077 | ||
11078 | /* FIXME: We should check the dwo_id. */ | |
11079 | ||
24841daa NC |
11080 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
11081 | add_separate_debug_file (separate_filename, separate_handle); | |
11082 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
11083 | return separate_handle; | |
d85bf2ba NC |
11084 | } |
11085 | ||
ce139cd5 NC |
11086 | /* Load a debuglink section and/or a debugaltlink section, if either are present. |
11087 | Recursively check the loaded files for more of these sections. | |
11088 | FIXME: Should also check for DWO_* entries in the newlu loaded files. */ | |
11089 | ||
11090 | static void | |
11091 | check_for_and_load_links (void * file, const char * filename) | |
11092 | { | |
11093 | void * handle = NULL; | |
11094 | ||
11095 | if (load_debug_section (gnu_debugaltlink, file)) | |
11096 | { | |
11097 | Build_id_data build_id_data; | |
11098 | ||
11099 | handle = load_separate_debug_info (filename, | |
11100 | & debug_displays[gnu_debugaltlink].section, | |
11101 | parse_gnu_debugaltlink, | |
11102 | check_gnu_debugaltlink, | |
11103 | & build_id_data, | |
11104 | file); | |
11105 | if (handle) | |
11106 | { | |
11107 | assert (handle == first_separate_info->handle); | |
11108 | check_for_and_load_links (first_separate_info->handle, | |
11109 | first_separate_info->filename); | |
11110 | } | |
11111 | } | |
11112 | ||
11113 | if (load_debug_section (gnu_debuglink, file)) | |
11114 | { | |
11115 | unsigned long crc32; | |
11116 | ||
11117 | handle = load_separate_debug_info (filename, | |
11118 | & debug_displays[gnu_debuglink].section, | |
11119 | parse_gnu_debuglink, | |
11120 | check_gnu_debuglink, | |
11121 | & crc32, | |
11122 | file); | |
11123 | if (handle) | |
11124 | { | |
11125 | assert (handle == first_separate_info->handle); | |
11126 | check_for_and_load_links (first_separate_info->handle, | |
11127 | first_separate_info->filename); | |
11128 | } | |
11129 | } | |
11130 | } | |
11131 | ||
24841daa NC |
11132 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
11133 | Returns TRUE if any were found, FALSE otherwise. | |
11134 | If TRUE is returned then the linked list starting at first_separate_info | |
11135 | will be populated with open file handles. */ | |
dda8d76d | 11136 | |
24841daa NC |
11137 | bfd_boolean |
11138 | load_separate_debug_files (void * file, const char * filename) | |
dda8d76d | 11139 | { |
8de3a6e2 NC |
11140 | /* Skip this operation if we are not interested in debug links. */ |
11141 | if (! do_follow_links && ! do_debug_links) | |
24841daa | 11142 | return FALSE; |
8de3a6e2 | 11143 | |
24841daa | 11144 | /* See if there are any dwo links. */ |
d85bf2ba NC |
11145 | if (load_debug_section (str, file) |
11146 | && load_debug_section (abbrev, file) | |
11147 | && load_debug_section (info, file)) | |
11148 | { | |
24841daa | 11149 | free_dwo_info (); |
d85bf2ba | 11150 | |
50ea0877 NC |
11151 | if (process_debug_info (& debug_displays[info].section, file, abbrev, |
11152 | TRUE, FALSE)) | |
d85bf2ba | 11153 | { |
24841daa NC |
11154 | bfd_boolean introduced = FALSE; |
11155 | dwo_info * dwinfo; | |
11156 | const char * dir = NULL; | |
11157 | const char * id = NULL; | |
50ea0877 | 11158 | const char * name = NULL; |
24841daa NC |
11159 | |
11160 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 11161 | { |
50ea0877 | 11162 | /* Accumulate NAME, DIR and ID fields. */ |
24841daa | 11163 | switch (dwinfo->type) |
d85bf2ba | 11164 | { |
24841daa | 11165 | case DWO_NAME: |
50ea0877 NC |
11166 | if (name != NULL) |
11167 | warn (_("Multiple DWO_NAMEs encountered for the same CU\n")); | |
11168 | name = dwinfo->value; | |
11169 | break; | |
11170 | ||
11171 | case DWO_DIR: | |
11172 | /* There can be multiple DW_AT_comp_dir entries in a CU, | |
11173 | so do not complain. */ | |
11174 | dir = dwinfo->value; | |
11175 | break; | |
11176 | ||
11177 | case DWO_ID: | |
11178 | if (id != NULL) | |
11179 | warn (_("multiple DWO_IDs encountered for the same CU\n")); | |
11180 | id = dwinfo->value; | |
11181 | break; | |
11182 | ||
11183 | default: | |
11184 | error (_("Unexpected DWO INFO type")); | |
11185 | break; | |
11186 | } | |
11187 | ||
11188 | /* If we have reached the end of our list, or we are changing | |
11189 | CUs, then display the information that we have accumulated | |
11190 | so far. */ | |
11191 | if (name != NULL | |
11192 | && (dwinfo->next == NULL | |
11193 | || dwinfo->next->cu_offset != dwinfo->cu_offset)) | |
11194 | { | |
24841daa NC |
11195 | if (do_debug_links) |
11196 | { | |
11197 | if (! introduced) | |
11198 | { | |
11199 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
11200 | debug_displays [info].section.uncompressed_name); | |
11201 | introduced = TRUE; | |
11202 | } | |
d85bf2ba | 11203 | |
50ea0877 | 11204 | printf (_(" Name: %s\n"), name); |
24841daa NC |
11205 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); |
11206 | if (id != NULL) | |
11207 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
11208 | else | |
50ea0877 | 11209 | printf (_(" ID: <not specified>\n")); |
24841daa NC |
11210 | printf ("\n\n"); |
11211 | } | |
11212 | ||
11213 | if (do_follow_links) | |
50ea0877 | 11214 | load_dwo_file (filename, name, dir, id); |
24841daa | 11215 | |
50ea0877 | 11216 | name = dir = id = NULL; |
24841daa | 11217 | } |
d85bf2ba NC |
11218 | } |
11219 | } | |
11220 | } | |
11221 | ||
dda8d76d | 11222 | if (! do_follow_links) |
8de3a6e2 NC |
11223 | /* The other debug links will be displayed by display_debug_links() |
11224 | so we do not need to do any further processing here. */ | |
24841daa | 11225 | return FALSE; |
dda8d76d NC |
11226 | |
11227 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
dda8d76d | 11228 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ |
d85bf2ba | 11229 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 11230 | |
ce139cd5 | 11231 | check_for_and_load_links (file, filename); |
24841daa NC |
11232 | if (first_separate_info != NULL) |
11233 | return TRUE; | |
11234 | ||
dda8d76d | 11235 | do_follow_links = 0; |
24841daa | 11236 | return FALSE; |
521d4b19 | 11237 | } |
dda8d76d | 11238 | |
19e6b90e L |
11239 | void |
11240 | free_debug_memory (void) | |
11241 | { | |
3f5e193b | 11242 | unsigned int i; |
19e6b90e | 11243 | |
bcd213b2 | 11244 | free_all_abbrevs (); |
19e6b90e | 11245 | |
bcd213b2 NC |
11246 | free (cu_abbrev_map); |
11247 | cu_abbrev_map = NULL; | |
11248 | next_free_abbrev_map_entry = 0; | |
521d4b19 | 11249 | |
288f0ba2 AM |
11250 | free (shndx_pool); |
11251 | shndx_pool = NULL; | |
11252 | shndx_pool_size = 0; | |
11253 | shndx_pool_used = 0; | |
11254 | free (cu_sets); | |
11255 | cu_sets = NULL; | |
11256 | cu_count = 0; | |
11257 | free (tu_sets); | |
11258 | tu_sets = NULL; | |
11259 | tu_count = 0; | |
11260 | ||
11261 | memset (level_type_signed, 0, sizeof level_type_signed); | |
11262 | cu_tu_indexes_read = -1; | |
11263 | ||
19e6b90e | 11264 | for (i = 0; i < max; i++) |
3f5e193b | 11265 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 11266 | |
cc86f28f | 11267 | if (debug_information != NULL) |
19e6b90e | 11268 | { |
82fcdb39 | 11269 | for (i = 0; i < alloc_num_debug_info_entries; i++) |
19e6b90e | 11270 | { |
82fcdb39 | 11271 | if (debug_information [i].max_loc_offsets) |
19e6b90e | 11272 | { |
82fcdb39 AM |
11273 | free (debug_information [i].loc_offsets); |
11274 | free (debug_information [i].have_frame_base); | |
19e6b90e | 11275 | } |
82fcdb39 AM |
11276 | if (debug_information [i].max_range_lists) |
11277 | free (debug_information [i].range_lists); | |
19e6b90e L |
11278 | } |
11279 | free (debug_information); | |
11280 | debug_information = NULL; | |
82b1b41b | 11281 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 11282 | } |
dda8d76d | 11283 | |
24841daa NC |
11284 | separate_info * d; |
11285 | separate_info * next; | |
dda8d76d | 11286 | |
24841daa NC |
11287 | for (d = first_separate_info; d != NULL; d = next) |
11288 | { | |
11289 | close_debug_file (d->handle); | |
11290 | free ((void *) d->filename); | |
11291 | next = d->next; | |
11292 | free ((void *) d); | |
dda8d76d | 11293 | } |
24841daa | 11294 | first_separate_info = NULL; |
521d4b19 | 11295 | |
24841daa | 11296 | free_dwo_info (); |
19e6b90e L |
11297 | } |
11298 | ||
4cb93e3b TG |
11299 | void |
11300 | dwarf_select_sections_by_names (const char *names) | |
11301 | { | |
11302 | typedef struct | |
11303 | { | |
11304 | const char * option; | |
11305 | int * variable; | |
f9f0e732 | 11306 | int val; |
4cb93e3b TG |
11307 | } |
11308 | debug_dump_long_opts; | |
11309 | ||
11310 | static const debug_dump_long_opts opts_table [] = | |
11311 | { | |
11312 | /* Please keep this table alpha- sorted. */ | |
11313 | { "Ranges", & do_debug_ranges, 1 }, | |
11314 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 11315 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 11316 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
11317 | { "cu_index", & do_debug_cu_index, 1 }, |
11318 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 11319 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
11320 | { "frames", & do_debug_frames, 1 }, |
11321 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
11322 | /* The special .gdb_index section. */ |
11323 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
11324 | { "info", & do_debug_info, 1 }, |
11325 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 11326 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
11327 | { "loc", & do_debug_loc, 1 }, |
11328 | { "macro", & do_debug_macinfo, 1 }, | |
11329 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 11330 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 11331 | /* This entry is for compatibility |
4cb93e3b TG |
11332 | with earlier versions of readelf. */ |
11333 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 11334 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 11335 | { "str", & do_debug_str, 1 }, |
e4b7104b | 11336 | { "str-offsets", & do_debug_str_offsets, 1 }, |
6f875884 TG |
11337 | /* These trace_* sections are used by Itanium VMS. */ |
11338 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
11339 | { "trace_aranges", & do_trace_aranges, 1 }, | |
11340 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
11341 | { NULL, NULL, 0 } |
11342 | }; | |
11343 | ||
11344 | const char *p; | |
467c65bc | 11345 | |
4cb93e3b TG |
11346 | p = names; |
11347 | while (*p) | |
11348 | { | |
11349 | const debug_dump_long_opts * entry; | |
467c65bc | 11350 | |
4cb93e3b TG |
11351 | for (entry = opts_table; entry->option; entry++) |
11352 | { | |
11353 | size_t len = strlen (entry->option); | |
467c65bc | 11354 | |
4cb93e3b TG |
11355 | if (strncmp (p, entry->option, len) == 0 |
11356 | && (p[len] == ',' || p[len] == '\0')) | |
11357 | { | |
11358 | * entry->variable |= entry->val; | |
467c65bc | 11359 | |
4cb93e3b TG |
11360 | /* The --debug-dump=frames-interp option also |
11361 | enables the --debug-dump=frames option. */ | |
11362 | if (do_debug_frames_interp) | |
11363 | do_debug_frames = 1; | |
11364 | ||
11365 | p += len; | |
11366 | break; | |
11367 | } | |
11368 | } | |
467c65bc | 11369 | |
4cb93e3b TG |
11370 | if (entry->option == NULL) |
11371 | { | |
11372 | warn (_("Unrecognized debug option '%s'\n"), p); | |
11373 | p = strchr (p, ','); | |
11374 | if (p == NULL) | |
11375 | break; | |
11376 | } | |
467c65bc | 11377 | |
4cb93e3b TG |
11378 | if (*p == ',') |
11379 | p++; | |
11380 | } | |
11381 | } | |
11382 | ||
11383 | void | |
11384 | dwarf_select_sections_by_letters (const char *letters) | |
11385 | { | |
91d6fa6a | 11386 | unsigned int lindex = 0; |
4cb93e3b | 11387 | |
91d6fa6a NC |
11388 | while (letters[lindex]) |
11389 | switch (letters[lindex++]) | |
4cb93e3b | 11390 | { |
dda8d76d NC |
11391 | case 'A': do_debug_addr = 1; break; |
11392 | case 'a': do_debug_abbrevs = 1; break; | |
11393 | case 'c': do_debug_cu_index = 1; break; | |
11394 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
11395 | case 'f': do_debug_frames = 1; break; | |
11396 | case 'g': do_gdb_index = 1; break; | |
11397 | case 'i': do_debug_info = 1; break; | |
11398 | case 'K': do_follow_links = 1; break; | |
11399 | case 'k': do_debug_links = 1; break; | |
11400 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
11401 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
11402 | case 'm': do_debug_macinfo = 1; break; | |
e4b7104b | 11403 | case 'O': do_debug_str_offsets = 1; break; |
dda8d76d NC |
11404 | case 'o': do_debug_loc = 1; break; |
11405 | case 'p': do_debug_pubnames = 1; break; | |
11406 | case 'R': do_debug_ranges = 1; break; | |
11407 | case 'r': do_debug_aranges = 1; break; | |
11408 | case 's': do_debug_str = 1; break; | |
11409 | case 'T': do_trace_aranges = 1; break; | |
11410 | case 't': do_debug_pubtypes = 1; break; | |
11411 | case 'U': do_trace_info = 1; break; | |
11412 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 11413 | |
4cb93e3b | 11414 | default: |
7cc78d07 | 11415 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
11416 | break; |
11417 | } | |
11418 | } | |
11419 | ||
11420 | void | |
11421 | dwarf_select_sections_all (void) | |
11422 | { | |
11423 | do_debug_info = 1; | |
11424 | do_debug_abbrevs = 1; | |
11425 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
11426 | do_debug_pubnames = 1; | |
f9f0e732 | 11427 | do_debug_pubtypes = 1; |
4cb93e3b TG |
11428 | do_debug_aranges = 1; |
11429 | do_debug_ranges = 1; | |
11430 | do_debug_frames = 1; | |
11431 | do_debug_macinfo = 1; | |
11432 | do_debug_str = 1; | |
11433 | do_debug_loc = 1; | |
5bbdf3d5 | 11434 | do_gdb_index = 1; |
6f875884 TG |
11435 | do_trace_info = 1; |
11436 | do_trace_abbrevs = 1; | |
11437 | do_trace_aranges = 1; | |
657d0d47 CC |
11438 | do_debug_addr = 1; |
11439 | do_debug_cu_index = 1; | |
dda8d76d NC |
11440 | do_follow_links = 1; |
11441 | do_debug_links = 1; | |
e4b7104b | 11442 | do_debug_str_offsets = 1; |
4cb93e3b TG |
11443 | } |
11444 | ||
dda8d76d NC |
11445 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL |
11446 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL | |
11447 | ||
11448 | /* N.B. The order here must match the order in section_display_enum. */ | |
11449 | ||
19e6b90e L |
11450 | struct dwarf_section_display debug_displays[] = |
11451 | { | |
dda8d76d NC |
11452 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, |
11453 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE }, | |
11454 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
11455 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE }, | |
11456 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
11457 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE }, | |
11458 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, | |
11459 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
11460 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
11461 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
11462 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
11463 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
11464 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
11465 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
11466 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE }, | |
11467 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, | |
11468 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
11469 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
11470 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
11471 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
11472 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE }, | |
11473 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
11474 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE }, | |
11475 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE }, | |
11476 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE }, | |
11477 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE }, | |
11478 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE }, | |
11479 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE }, | |
11480 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
11481 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE }, | |
11482 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
11483 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
11484 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
11485 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
11486 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE }, | |
e4b7104b NC |
11487 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, TRUE }, |
11488 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, TRUE }, | |
dda8d76d NC |
11489 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE }, |
11490 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
11491 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
11492 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
11493 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
11494 | /* Separate debug info files can containt their own .debug_str section, | |
11495 | and this might be in *addition* to a .debug_str section already present | |
11496 | in the main file. Hence we need to have two entries for .debug_str. */ | |
11497 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
19e6b90e | 11498 | }; |
b451e98a JK |
11499 | |
11500 | /* A static assertion. */ | |
11501 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |