Commit | Line | Data |
---|---|---|
19e6b90e | 1 | /* dwarf.c -- display DWARF contents of a BFD binary file |
b3adc24a | 2 | Copyright (C) 2005-2020 Free Software Foundation, Inc. |
19e6b90e L |
3 | |
4 | This file is part of GNU Binutils. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
32866df7 | 8 | the Free Software Foundation; either version 3 of the License, or |
19e6b90e L |
9 | (at your option) any later version. |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA | |
19 | 02110-1301, USA. */ | |
20 | ||
3db64b00 | 21 | #include "sysdep.h" |
19e6b90e | 22 | #include "libiberty.h" |
3db64b00 | 23 | #include "bfd.h" |
5bbdf3d5 | 24 | #include "bfd_stdint.h" |
3db64b00 | 25 | #include "bucomm.h" |
3284fe0c | 26 | #include "elfcomm.h" |
2dc4cec1 | 27 | #include "elf/common.h" |
fa8f86ff | 28 | #include "dwarf2.h" |
3db64b00 | 29 | #include "dwarf.h" |
8d6eee87 | 30 | #include "gdb/gdb-index.h" |
dda8d76d | 31 | #include "filenames.h" |
48467cb9 | 32 | #include "safe-ctype.h" |
61364358 JK |
33 | #include <assert.h> |
34 | ||
35 | #undef MAX | |
36 | #undef MIN | |
37 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) | |
38 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | |
19e6b90e | 39 | |
18464d4d | 40 | static const char *regname (unsigned int regno, int row); |
1296bc99 | 41 | static const char *regname_internal_by_table_only (unsigned int regno); |
18464d4d | 42 | |
19e6b90e L |
43 | static int have_frame_base; |
44 | static int need_base_address; | |
45 | ||
19e6b90e | 46 | static unsigned int num_debug_info_entries = 0; |
82b1b41b | 47 | static unsigned int alloc_num_debug_info_entries = 0; |
19e6b90e | 48 | static debug_info *debug_information = NULL; |
cc86f28f NC |
49 | /* Special value for num_debug_info_entries to indicate |
50 | that the .debug_info section could not be loaded/parsed. */ | |
51 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 | |
19e6b90e | 52 | |
24841daa NC |
53 | /* A .debug_info section can contain multiple links to separate |
54 | DWO object files. We use these structures to record these links. */ | |
55 | typedef enum dwo_type | |
56 | { | |
57 | DWO_NAME, | |
58 | DWO_DIR, | |
59 | DWO_ID | |
60 | } dwo_type; | |
61 | ||
62 | typedef struct dwo_info | |
63 | { | |
64 | dwo_type type; | |
65 | const char * value; | |
66 | struct dwo_info * next; | |
67 | } dwo_info; | |
68 | ||
69 | static dwo_info * first_dwo_info = NULL; | |
70 | static bfd_boolean need_dwo_info; | |
71 | ||
72 | separate_info * first_separate_info = NULL; | |
d85bf2ba | 73 | |
77ef8654 | 74 | unsigned int eh_addr_size; |
19e6b90e L |
75 | |
76 | int do_debug_info; | |
77 | int do_debug_abbrevs; | |
78 | int do_debug_lines; | |
79 | int do_debug_pubnames; | |
f9f0e732 | 80 | int do_debug_pubtypes; |
19e6b90e L |
81 | int do_debug_aranges; |
82 | int do_debug_ranges; | |
83 | int do_debug_frames; | |
84 | int do_debug_frames_interp; | |
85 | int do_debug_macinfo; | |
86 | int do_debug_str; | |
87 | int do_debug_loc; | |
5bbdf3d5 | 88 | int do_gdb_index; |
6f875884 TG |
89 | int do_trace_info; |
90 | int do_trace_abbrevs; | |
91 | int do_trace_aranges; | |
657d0d47 CC |
92 | int do_debug_addr; |
93 | int do_debug_cu_index; | |
a262ae96 | 94 | int do_wide; |
dda8d76d NC |
95 | int do_debug_links; |
96 | int do_follow_links; | |
19e6b90e | 97 | |
fd2f0033 TT |
98 | int dwarf_cutoff_level = -1; |
99 | unsigned long dwarf_start_die; | |
100 | ||
4723351a CC |
101 | int dwarf_check = 0; |
102 | ||
9f272209 AO |
103 | /* Convenient constant, to avoid having to cast -1 to dwarf_vma when |
104 | testing whether e.g. a locview list is present. */ | |
105 | static const dwarf_vma vm1 = -1; | |
106 | ||
341f9135 CC |
107 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
108 | sections. For version 1 package files, each set is stored in SHNDX_POOL | |
109 | as a zero-terminated list of section indexes comprising one set of debug | |
110 | sections from a .dwo file. */ | |
111 | ||
341f9135 CC |
112 | static unsigned int *shndx_pool = NULL; |
113 | static unsigned int shndx_pool_size = 0; | |
114 | static unsigned int shndx_pool_used = 0; | |
115 | ||
116 | /* For version 2 package files, each set contains an array of section offsets | |
117 | and an array of section sizes, giving the offset and size of the | |
118 | contribution from a CU or TU within one of the debug sections. | |
119 | When displaying debug info from a package file, we need to use these | |
120 | tables to locate the corresponding contributions to each section. */ | |
121 | ||
122 | struct cu_tu_set | |
123 | { | |
ec1b0fbb NC |
124 | uint64_t signature; |
125 | dwarf_vma section_offsets[DW_SECT_MAX]; | |
126 | size_t section_sizes[DW_SECT_MAX]; | |
341f9135 CC |
127 | }; |
128 | ||
129 | static int cu_count = 0; | |
130 | static int tu_count = 0; | |
131 | static struct cu_tu_set *cu_sets = NULL; | |
132 | static struct cu_tu_set *tu_sets = NULL; | |
133 | ||
43a444f9 | 134 | static bfd_boolean load_cu_tu_indexes (void *); |
341f9135 | 135 | |
ec1b0fbb NC |
136 | /* An array that indicates for a given level of CU nesting whether |
137 | the latest DW_AT_type seen for that level was a signed type or | |
138 | an unsigned type. */ | |
139 | #define MAX_CU_NESTING (1 << 8) | |
140 | static bfd_boolean level_type_signed[MAX_CU_NESTING]; | |
141 | ||
4cb93e3b TG |
142 | /* Values for do_debug_lines. */ |
143 | #define FLAG_DEBUG_LINES_RAW 1 | |
144 | #define FLAG_DEBUG_LINES_DECODED 2 | |
145 | ||
77ef8654 | 146 | static unsigned int |
f1c4cc75 RH |
147 | size_of_encoded_value (int encoding) |
148 | { | |
149 | switch (encoding & 0x7) | |
150 | { | |
151 | default: /* ??? */ | |
152 | case 0: return eh_addr_size; | |
153 | case 2: return 2; | |
154 | case 3: return 4; | |
155 | case 4: return 8; | |
156 | } | |
157 | } | |
158 | ||
159 | static dwarf_vma | |
041830e0 | 160 | get_encoded_value (unsigned char **pdata, |
bad62cf5 | 161 | int encoding, |
041830e0 NC |
162 | struct dwarf_section *section, |
163 | unsigned char * end) | |
f1c4cc75 | 164 | { |
041830e0 | 165 | unsigned char * data = * pdata; |
6937bb54 | 166 | unsigned int size = size_of_encoded_value (encoding); |
bad62cf5 | 167 | dwarf_vma val; |
f1c4cc75 | 168 | |
041830e0 NC |
169 | if (data + size >= end) |
170 | { | |
171 | warn (_("Encoded value extends past end of section\n")); | |
172 | * pdata = end; | |
173 | return 0; | |
174 | } | |
175 | ||
6937bb54 NC |
176 | /* PR 17512: file: 002-829853-0.004. */ |
177 | if (size > 8) | |
178 | { | |
179 | warn (_("Encoded size of %d is too large to read\n"), size); | |
180 | * pdata = end; | |
181 | return 0; | |
182 | } | |
183 | ||
0a9d414a NC |
184 | /* PR 17512: file: 1085-5603-0.004. */ |
185 | if (size == 0) | |
186 | { | |
187 | warn (_("Encoded size of 0 is too small to read\n")); | |
188 | * pdata = end; | |
189 | return 0; | |
190 | } | |
191 | ||
f1c4cc75 | 192 | if (encoding & DW_EH_PE_signed) |
bad62cf5 | 193 | val = byte_get_signed (data, size); |
f1c4cc75 | 194 | else |
bad62cf5 AM |
195 | val = byte_get (data, size); |
196 | ||
197 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
198 | val += section->address + (data - section->start); | |
041830e0 NC |
199 | |
200 | * pdata = data + size; | |
bad62cf5 | 201 | return val; |
f1c4cc75 RH |
202 | } |
203 | ||
4c219c2e AM |
204 | #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG |
205 | # ifndef __MINGW32__ | |
206 | # define DWARF_VMA_FMT "ll" | |
207 | # define DWARF_VMA_FMT_LONG "%16.16llx" | |
208 | # else | |
209 | # define DWARF_VMA_FMT "I64" | |
210 | # define DWARF_VMA_FMT_LONG "%016I64x" | |
211 | # endif | |
2e14fae2 | 212 | #else |
4c219c2e AM |
213 | # define DWARF_VMA_FMT "l" |
214 | # define DWARF_VMA_FMT_LONG "%16.16lx" | |
2d9472a2 NC |
215 | #endif |
216 | ||
bf5117e3 NC |
217 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
218 | buffer containing the converted VALUE. The value is converted according | |
219 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then | |
220 | it specifies the maximum number of bytes to be displayed in the converted | |
221 | value and FMTCH is ignored - hex is always used. */ | |
467c65bc | 222 | |
47704ddf | 223 | static const char * |
bf5117e3 | 224 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
47704ddf KT |
225 | { |
226 | /* As dwarf_vmatoa is used more then once in a printf call | |
227 | for output, we are cycling through an fixed array of pointers | |
228 | for return address. */ | |
229 | static int buf_pos = 0; | |
467c65bc NC |
230 | static struct dwarf_vmatoa_buf |
231 | { | |
47704ddf KT |
232 | char place[64]; |
233 | } buf[16]; | |
47704ddf KT |
234 | char *ret; |
235 | ||
47704ddf | 236 | ret = buf[buf_pos++].place; |
467c65bc | 237 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf | 238 | |
bf5117e3 NC |
239 | if (num_bytes) |
240 | { | |
222c2bf0 | 241 | /* Printf does not have a way of specifying a maximum field width for an |
bf5117e3 NC |
242 | integer value, so we print the full value into a buffer and then select |
243 | the precision we need. */ | |
244 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); | |
245 | if (num_bytes > 8) | |
246 | num_bytes = 8; | |
247 | return ret + (16 - 2 * num_bytes); | |
248 | } | |
249 | else | |
250 | { | |
251 | char fmt[32]; | |
252 | ||
0bae9e9e NC |
253 | if (fmtch) |
254 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); | |
255 | else | |
256 | sprintf (fmt, "%%%s", DWARF_VMA_FMT); | |
bf5117e3 NC |
257 | snprintf (ret, sizeof (buf[0].place), fmt, value); |
258 | return ret; | |
259 | } | |
260 | } | |
47704ddf | 261 | |
bf5117e3 NC |
262 | static inline const char * |
263 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) | |
264 | { | |
265 | return dwarf_vmatoa_1 (fmtch, value, 0); | |
266 | } | |
267 | ||
268 | /* Print a dwarf_vma value (typically an address, offset or length) in | |
269 | hexadecimal format, followed by a space. The length of the VALUE (and | |
270 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ | |
271 | ||
272 | static void | |
273 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) | |
274 | { | |
275 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); | |
47704ddf KT |
276 | } |
277 | ||
9f272209 AO |
278 | /* Print a view number in hexadecimal value, with the same width |
279 | print_dwarf_vma would have printed it with the same num_bytes. | |
280 | Print blanks for zero view, unless force is nonzero. */ | |
281 | ||
282 | static void | |
283 | print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force) | |
284 | { | |
285 | int len; | |
286 | if (!num_bytes) | |
287 | len = 4; | |
288 | else | |
289 | len = num_bytes * 2; | |
290 | ||
291 | assert (value == (unsigned long) value); | |
292 | if (value || force) | |
293 | printf ("v%0*lx ", len - 1, (unsigned long) value); | |
294 | else | |
295 | printf ("%*s", len + 1, ""); | |
296 | } | |
297 | ||
74bc6052 CC |
298 | /* Format a 64-bit value, given as two 32-bit values, in hex. |
299 | For reentrancy, this uses a buffer provided by the caller. */ | |
300 | ||
301 | static const char * | |
302 | dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, | |
303 | unsigned int buf_len) | |
304 | { | |
305 | int len = 0; | |
306 | ||
307 | if (hvalue == 0) | |
308 | snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); | |
309 | else | |
310 | { | |
311 | len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); | |
312 | snprintf (buf + len, buf_len - len, | |
313 | "%08" DWARF_VMA_FMT "x", lvalue); | |
314 | } | |
315 | ||
316 | return buf; | |
317 | } | |
318 | ||
f6f0e17b NC |
319 | /* Read in a LEB128 encoded value starting at address DATA. |
320 | If SIGN is true, return a signed LEB128 value. | |
321 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
cd30bcef AM |
322 | If STATUS_RETURN in not NULL, return with bit 0 (LSB) set if the |
323 | terminating byte was not found and with bit 1 set if the value | |
324 | overflows a dwarf_vma. | |
f6f0e17b NC |
325 | No bytes will be read at address END or beyond. */ |
326 | ||
467c65bc | 327 | dwarf_vma |
f6f0e17b | 328 | read_leb128 (unsigned char *data, |
cd30bcef | 329 | const unsigned char *const end, |
f6f0e17b | 330 | bfd_boolean sign, |
cd30bcef AM |
331 | unsigned int *length_return, |
332 | int *status_return) | |
19e6b90e | 333 | { |
467c65bc | 334 | dwarf_vma result = 0; |
19e6b90e L |
335 | unsigned int num_read = 0; |
336 | unsigned int shift = 0; | |
cd30bcef | 337 | int status = 1; |
19e6b90e | 338 | |
f6f0e17b | 339 | while (data < end) |
19e6b90e | 340 | { |
cd30bcef | 341 | unsigned char byte = *data++; |
19e6b90e L |
342 | num_read++; |
343 | ||
cd30bcef AM |
344 | if (shift < sizeof (result) * 8) |
345 | { | |
346 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; | |
347 | if ((result >> shift) != (byte & 0x7f)) | |
348 | /* Overflow. */ | |
349 | status |= 2; | |
350 | shift += 7; | |
351 | } | |
352 | else if ((byte & 0x7f) != 0) | |
353 | status |= 2; | |
19e6b90e | 354 | |
f6f0e17b | 355 | if ((byte & 0x80) == 0) |
cd30bcef AM |
356 | { |
357 | status &= ~1; | |
358 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) | |
359 | result |= -((dwarf_vma) 1 << shift); | |
360 | break; | |
361 | } | |
19e6b90e | 362 | } |
19e6b90e L |
363 | |
364 | if (length_return != NULL) | |
365 | *length_return = num_read; | |
cd30bcef AM |
366 | if (status_return != NULL) |
367 | *status_return = status; | |
19e6b90e L |
368 | |
369 | return result; | |
370 | } | |
371 | ||
d11ae95e NC |
372 | /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value. |
373 | Checks to make sure that the read will not reach or pass END | |
374 | and that VAL is big enough to hold AMOUNT bytes. */ | |
0c588247 NC |
375 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
376 | do \ | |
377 | { \ | |
378 | unsigned int amount = (AMOUNT); \ | |
34b9f729 NC |
379 | if (sizeof (VAL) < amount) \ |
380 | { \ | |
d3a49aa8 AM |
381 | error (ngettext ("internal error: attempt to read %d byte " \ |
382 | "of data in to %d sized variable", \ | |
383 | "internal error: attempt to read %d bytes " \ | |
384 | "of data in to %d sized variable", \ | |
385 | amount), \ | |
34b9f729 NC |
386 | amount, (int) sizeof (VAL)); \ |
387 | amount = sizeof (VAL); \ | |
388 | } \ | |
0c588247 NC |
389 | if (((PTR) + amount) >= (END)) \ |
390 | { \ | |
391 | if ((PTR) < (END)) \ | |
392 | amount = (END) - (PTR); \ | |
393 | else \ | |
394 | amount = 0; \ | |
395 | } \ | |
6937bb54 | 396 | if (amount == 0 || amount > 8) \ |
0c588247 | 397 | VAL = 0; \ |
6937bb54 NC |
398 | else \ |
399 | VAL = byte_get ((PTR), amount); \ | |
0c588247 NC |
400 | } \ |
401 | while (0) | |
402 | ||
d11ae95e | 403 | /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
404 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
405 | do \ | |
406 | { \ | |
407 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
408 | PTR += AMOUNT; \ | |
409 | } \ | |
410 | while (0) | |
411 | ||
d11ae95e | 412 | /* Like SAFE_BYTE_GET, but reads a signed value. */ |
0c588247 NC |
413 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
414 | do \ | |
415 | { \ | |
416 | unsigned int amount = (AMOUNT); \ | |
417 | if (((PTR) + amount) >= (END)) \ | |
418 | { \ | |
419 | if ((PTR) < (END)) \ | |
420 | amount = (END) - (PTR); \ | |
421 | else \ | |
422 | amount = 0; \ | |
423 | } \ | |
424 | if (amount) \ | |
425 | VAL = byte_get_signed ((PTR), amount); \ | |
426 | else \ | |
427 | VAL = 0; \ | |
428 | } \ | |
429 | while (0) | |
430 | ||
d11ae95e | 431 | /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
432 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
433 | do \ | |
434 | { \ | |
435 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
436 | PTR += AMOUNT; \ | |
437 | } \ | |
438 | while (0) | |
439 | ||
440 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ | |
441 | do \ | |
442 | { \ | |
87bc83b3 | 443 | if (((PTR) + 8) <= (END)) \ |
0c588247 NC |
444 | { \ |
445 | byte_get_64 ((PTR), (HIGH), (LOW)); \ | |
446 | } \ | |
447 | else \ | |
448 | { \ | |
0c588247 NC |
449 | * (LOW) = * (HIGH) = 0; \ |
450 | } \ | |
451 | } \ | |
452 | while (0) | |
453 | ||
19e6b90e L |
454 | typedef struct State_Machine_Registers |
455 | { | |
467c65bc | 456 | dwarf_vma address; |
ba8826a8 | 457 | unsigned int view; |
19e6b90e L |
458 | unsigned int file; |
459 | unsigned int line; | |
460 | unsigned int column; | |
461 | int is_stmt; | |
462 | int basic_block; | |
a233b20c JJ |
463 | unsigned char op_index; |
464 | unsigned char end_sequence; | |
ba8826a8 AO |
465 | /* This variable hold the number of the last entry seen |
466 | in the File Table. */ | |
19e6b90e L |
467 | unsigned int last_file_entry; |
468 | } SMR; | |
469 | ||
470 | static SMR state_machine_regs; | |
471 | ||
472 | static void | |
473 | reset_state_machine (int is_stmt) | |
474 | { | |
475 | state_machine_regs.address = 0; | |
ba8826a8 | 476 | state_machine_regs.view = 0; |
a233b20c | 477 | state_machine_regs.op_index = 0; |
19e6b90e L |
478 | state_machine_regs.file = 1; |
479 | state_machine_regs.line = 1; | |
480 | state_machine_regs.column = 0; | |
481 | state_machine_regs.is_stmt = is_stmt; | |
482 | state_machine_regs.basic_block = 0; | |
483 | state_machine_regs.end_sequence = 0; | |
484 | state_machine_regs.last_file_entry = 0; | |
485 | } | |
486 | ||
487 | /* Handled an extend line op. | |
488 | Returns the number of bytes read. */ | |
489 | ||
cd30bcef | 490 | static size_t |
f6f0e17b NC |
491 | process_extended_line_op (unsigned char * data, |
492 | int is_stmt, | |
493 | unsigned char * end) | |
19e6b90e L |
494 | { |
495 | unsigned char op_code; | |
cd30bcef | 496 | size_t len, header_len; |
19e6b90e | 497 | unsigned char *name; |
143a3db0 | 498 | unsigned char *orig_data = data; |
cd30bcef | 499 | dwarf_vma adr, val; |
19e6b90e | 500 | |
cd30bcef AM |
501 | READ_ULEB (len, data, end); |
502 | header_len = data - orig_data; | |
19e6b90e | 503 | |
cd30bcef | 504 | if (len == 0 || data == end || len > (size_t) (end - data)) |
19e6b90e | 505 | { |
f41e4712 | 506 | warn (_("Badly formed extended line op encountered!\n")); |
cd30bcef | 507 | return header_len; |
19e6b90e L |
508 | } |
509 | ||
19e6b90e L |
510 | op_code = *data++; |
511 | ||
512 | printf (_(" Extended opcode %d: "), op_code); | |
513 | ||
514 | switch (op_code) | |
515 | { | |
516 | case DW_LNE_end_sequence: | |
517 | printf (_("End of Sequence\n\n")); | |
518 | reset_state_machine (is_stmt); | |
519 | break; | |
520 | ||
521 | case DW_LNE_set_address: | |
6937bb54 | 522 | /* PR 17512: file: 002-100480-0.004. */ |
cd30bcef | 523 | if (len - 1 > 8) |
77ef8654 | 524 | { |
cd30bcef AM |
525 | warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"), |
526 | (unsigned long) len - 1); | |
77ef8654 NC |
527 | adr = 0; |
528 | } | |
529 | else | |
cd30bcef | 530 | SAFE_BYTE_GET (adr, data, len - 1, end); |
47704ddf | 531 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 532 | state_machine_regs.address = adr; |
ba8826a8 | 533 | state_machine_regs.view = 0; |
a233b20c | 534 | state_machine_regs.op_index = 0; |
19e6b90e L |
535 | break; |
536 | ||
537 | case DW_LNE_define_file: | |
143a3db0 | 538 | printf (_("define new File Table entry\n")); |
19e6b90e | 539 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 540 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 541 | |
d949ff56 NC |
542 | { |
543 | size_t l; | |
544 | ||
545 | name = data; | |
546 | l = strnlen ((char *) data, end - data); | |
cd30bcef AM |
547 | data += l + 1; |
548 | READ_ULEB (val, data, end); | |
549 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
550 | READ_ULEB (val, data, end); | |
551 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
552 | READ_ULEB (val, data, end); | |
553 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
d949ff56 NC |
554 | printf ("%.*s\n\n", (int) l, name); |
555 | } | |
f6f0e17b | 556 | |
cd30bcef | 557 | if (((size_t) (data - orig_data) != len + header_len) || data == end) |
b4eb7656 | 558 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
559 | break; |
560 | ||
ed4a4bdf | 561 | case DW_LNE_set_discriminator: |
cd30bcef AM |
562 | READ_ULEB (val, data, end); |
563 | printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val)); | |
ed4a4bdf CC |
564 | break; |
565 | ||
e2a0d921 NC |
566 | /* HP extensions. */ |
567 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 568 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
569 | break; |
570 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 571 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
572 | break; |
573 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 574 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
575 | break; |
576 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 577 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
578 | break; |
579 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 580 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
581 | break; |
582 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 583 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
584 | break; |
585 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 586 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
587 | break; |
588 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 589 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
590 | break; |
591 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 592 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
593 | break; |
594 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 595 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 596 | break; |
43294ab7 TG |
597 | case DW_LNE_HP_source_file_correlation: |
598 | { | |
cd30bcef | 599 | unsigned char *edata = data + len - 1; |
b4eb7656 AM |
600 | |
601 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
602 | ||
603 | while (data < edata) | |
604 | { | |
605 | unsigned int opc; | |
606 | ||
cd30bcef | 607 | READ_ULEB (opc, data, edata); |
b4eb7656 AM |
608 | |
609 | switch (opc) | |
610 | { | |
611 | case DW_LNE_HP_SFC_formfeed: | |
612 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
613 | break; | |
614 | case DW_LNE_HP_SFC_set_listing_line: | |
cd30bcef | 615 | READ_ULEB (val, data, edata); |
b4eb7656 | 616 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", |
cd30bcef | 617 | dwarf_vmatoa ("u", val)); |
b4eb7656 AM |
618 | break; |
619 | case DW_LNE_HP_SFC_associate: | |
620 | printf (" DW_LNE_HP_SFC_associate "); | |
cd30bcef AM |
621 | READ_ULEB (val, data, edata); |
622 | printf ("(%s", dwarf_vmatoa ("u", val)); | |
623 | READ_ULEB (val, data, edata); | |
624 | printf (",%s", dwarf_vmatoa ("u", val)); | |
625 | READ_ULEB (val, data, edata); | |
626 | printf (",%s)\n", dwarf_vmatoa ("u", val)); | |
b4eb7656 AM |
627 | break; |
628 | default: | |
629 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
630 | data = edata; | |
631 | break; | |
632 | } | |
633 | } | |
43294ab7 TG |
634 | } |
635 | break; | |
cecf136e | 636 | |
19e6b90e | 637 | default: |
7e665af3 | 638 | { |
cd30bcef | 639 | unsigned int rlen = len - 1; |
b4eb7656 AM |
640 | |
641 | if (op_code >= DW_LNE_lo_user | |
642 | /* The test against DW_LNW_hi_user is redundant due to | |
643 | the limited range of the unsigned char data type used | |
644 | for op_code. */ | |
645 | /*&& op_code <= DW_LNE_hi_user*/) | |
646 | printf (_("user defined: ")); | |
647 | else | |
648 | printf (_("UNKNOWN: ")); | |
649 | printf (_("length %d ["), rlen); | |
650 | for (; rlen; rlen--) | |
651 | printf (" %02x", *data++); | |
652 | printf ("]\n"); | |
7e665af3 | 653 | } |
19e6b90e L |
654 | break; |
655 | } | |
656 | ||
cd30bcef | 657 | return len + header_len; |
19e6b90e L |
658 | } |
659 | ||
0c588247 | 660 | static const unsigned char * |
467c65bc | 661 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
662 | { |
663 | struct dwarf_section *section = &debug_displays [str].section; | |
d949ff56 | 664 | const unsigned char * ret; |
19e6b90e L |
665 | |
666 | if (section->start == NULL) | |
0c588247 | 667 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e | 668 | |
d949ff56 | 669 | if (offset >= section->size) |
19e6b90e | 670 | { |
467c65bc NC |
671 | warn (_("DW_FORM_strp offset too big: %s\n"), |
672 | dwarf_vmatoa ("x", offset)); | |
0c588247 | 673 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
674 | } |
675 | ||
d949ff56 NC |
676 | ret = section->start + offset; |
677 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
678 | NUL byte. Since our caller is expecting to receive a well formed C | |
679 | string we test for the lack of a terminating byte here. */ | |
680 | if (strnlen ((const char *) ret, section->size - offset) | |
681 | == section->size - offset) | |
682 | ret = (const unsigned char *) | |
683 | _("<no NUL byte at end of .debug_str section>"); | |
684 | ||
685 | return ret; | |
19e6b90e L |
686 | } |
687 | ||
77145576 JK |
688 | static const unsigned char * |
689 | fetch_indirect_line_string (dwarf_vma offset) | |
690 | { | |
691 | struct dwarf_section *section = &debug_displays [line_str].section; | |
d949ff56 | 692 | const unsigned char * ret; |
77145576 JK |
693 | |
694 | if (section->start == NULL) | |
695 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
696 | ||
d949ff56 | 697 | if (offset >= section->size) |
77145576 JK |
698 | { |
699 | warn (_("DW_FORM_line_strp offset too big: %s\n"), | |
700 | dwarf_vmatoa ("x", offset)); | |
701 | return (const unsigned char *) _("<offset is too big>"); | |
702 | } | |
703 | ||
d949ff56 NC |
704 | ret = section->start + offset; |
705 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
706 | with a NUL byte. Since our caller is expecting to receive a well formed | |
707 | C string we test for the lack of a terminating byte here. */ | |
708 | if (strnlen ((const char *) ret, section->size - offset) | |
709 | == section->size - offset) | |
710 | ret = (const unsigned char *) | |
711 | _("<no NUL byte at end of .debug_line_str section>"); | |
712 | ||
713 | return ret; | |
77145576 JK |
714 | } |
715 | ||
4723351a | 716 | static const char * |
341f9135 | 717 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
d85bf2ba | 718 | dwarf_vma offset_size, bfd_boolean dwo) |
4723351a CC |
719 | { |
720 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
721 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
722 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
723 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
724 | dwarf_vma index_offset = idx * offset_size; | |
725 | dwarf_vma str_offset; | |
d949ff56 | 726 | const char * ret; |
4723351a CC |
727 | |
728 | if (index_section->start == NULL) | |
729 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
730 | : _("<no .debug_str_offsets section>")); | |
731 | ||
341f9135 CC |
732 | if (this_set != NULL) |
733 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
d949ff56 | 734 | if (index_offset >= index_section->size) |
4723351a CC |
735 | { |
736 | warn (_("DW_FORM_GNU_str_index offset too big: %s\n"), | |
737 | dwarf_vmatoa ("x", index_offset)); | |
738 | return _("<index offset is too big>"); | |
739 | } | |
740 | ||
741 | if (str_section->start == NULL) | |
742 | return (dwo ? _("<no .debug_str.dwo section>") | |
743 | : _("<no .debug_str section>")); | |
744 | ||
745 | str_offset = byte_get (index_section->start + index_offset, offset_size); | |
746 | str_offset -= str_section->address; | |
d949ff56 | 747 | if (str_offset >= str_section->size) |
4723351a CC |
748 | { |
749 | warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), | |
750 | dwarf_vmatoa ("x", str_offset)); | |
751 | return _("<indirect index offset is too big>"); | |
752 | } | |
753 | ||
d949ff56 NC |
754 | ret = (const char *) str_section->start + str_offset; |
755 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. | |
756 | Since our caller is expecting to receive a well formed C string we test | |
757 | for the lack of a terminating byte here. */ | |
758 | if (strnlen (ret, str_section->size - str_offset) | |
759 | == str_section->size - str_offset) | |
760 | ret = (const char *) _("<no NUL byte at end of section>"); | |
761 | ||
762 | return ret; | |
4723351a CC |
763 | } |
764 | ||
765 | static const char * | |
766 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
767 | { | |
768 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
769 | ||
770 | if (section->start == NULL) | |
771 | return (_("<no .debug_addr section>")); | |
772 | ||
773 | if (offset + bytes > section->size) | |
774 | { | |
775 | warn (_("Offset into section %s too big: %s\n"), | |
b4eb7656 | 776 | section->name, dwarf_vmatoa ("x", offset)); |
4723351a CC |
777 | return "<offset too big>"; |
778 | } | |
779 | ||
780 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
781 | } | |
782 | ||
783 | ||
19e6b90e L |
784 | /* FIXME: There are better and more efficient ways to handle |
785 | these structures. For now though, I just want something that | |
786 | is simple to implement. */ | |
787 | typedef struct abbrev_attr | |
788 | { | |
789 | unsigned long attribute; | |
790 | unsigned long form; | |
77145576 | 791 | bfd_signed_vma implicit_const; |
19e6b90e L |
792 | struct abbrev_attr *next; |
793 | } | |
794 | abbrev_attr; | |
795 | ||
796 | typedef struct abbrev_entry | |
797 | { | |
798 | unsigned long entry; | |
799 | unsigned long tag; | |
800 | int children; | |
801 | struct abbrev_attr *first_attr; | |
802 | struct abbrev_attr *last_attr; | |
803 | struct abbrev_entry *next; | |
804 | } | |
805 | abbrev_entry; | |
806 | ||
807 | static abbrev_entry *first_abbrev = NULL; | |
808 | static abbrev_entry *last_abbrev = NULL; | |
809 | ||
810 | static void | |
811 | free_abbrevs (void) | |
812 | { | |
91d6fa6a | 813 | abbrev_entry *abbrv; |
19e6b90e | 814 | |
91d6fa6a | 815 | for (abbrv = first_abbrev; abbrv;) |
19e6b90e | 816 | { |
91d6fa6a | 817 | abbrev_entry *next_abbrev = abbrv->next; |
19e6b90e L |
818 | abbrev_attr *attr; |
819 | ||
91d6fa6a | 820 | for (attr = abbrv->first_attr; attr;) |
19e6b90e | 821 | { |
91d6fa6a | 822 | abbrev_attr *next_attr = attr->next; |
19e6b90e L |
823 | |
824 | free (attr); | |
91d6fa6a | 825 | attr = next_attr; |
19e6b90e L |
826 | } |
827 | ||
91d6fa6a NC |
828 | free (abbrv); |
829 | abbrv = next_abbrev; | |
19e6b90e L |
830 | } |
831 | ||
832 | last_abbrev = first_abbrev = NULL; | |
833 | } | |
834 | ||
835 | static void | |
836 | add_abbrev (unsigned long number, unsigned long tag, int children) | |
837 | { | |
838 | abbrev_entry *entry; | |
839 | ||
3f5e193b | 840 | entry = (abbrev_entry *) malloc (sizeof (*entry)); |
19e6b90e L |
841 | if (entry == NULL) |
842 | /* ugg */ | |
843 | return; | |
844 | ||
845 | entry->entry = number; | |
846 | entry->tag = tag; | |
847 | entry->children = children; | |
848 | entry->first_attr = NULL; | |
849 | entry->last_attr = NULL; | |
850 | entry->next = NULL; | |
851 | ||
852 | if (first_abbrev == NULL) | |
853 | first_abbrev = entry; | |
854 | else | |
855 | last_abbrev->next = entry; | |
856 | ||
857 | last_abbrev = entry; | |
858 | } | |
859 | ||
860 | static void | |
77145576 JK |
861 | add_abbrev_attr (unsigned long attribute, unsigned long form, |
862 | bfd_signed_vma implicit_const) | |
19e6b90e L |
863 | { |
864 | abbrev_attr *attr; | |
865 | ||
3f5e193b | 866 | attr = (abbrev_attr *) malloc (sizeof (*attr)); |
19e6b90e L |
867 | if (attr == NULL) |
868 | /* ugg */ | |
869 | return; | |
870 | ||
871 | attr->attribute = attribute; | |
872 | attr->form = form; | |
77145576 | 873 | attr->implicit_const = implicit_const; |
19e6b90e L |
874 | attr->next = NULL; |
875 | ||
876 | if (last_abbrev->first_attr == NULL) | |
877 | last_abbrev->first_attr = attr; | |
878 | else | |
879 | last_abbrev->last_attr->next = attr; | |
880 | ||
881 | last_abbrev->last_attr = attr; | |
882 | } | |
883 | ||
884 | /* Processes the (partial) contents of a .debug_abbrev section. | |
885 | Returns NULL if the end of the section was encountered. | |
886 | Returns the address after the last byte read if the end of | |
887 | an abbreviation set was found. */ | |
888 | ||
889 | static unsigned char * | |
890 | process_abbrev_section (unsigned char *start, unsigned char *end) | |
891 | { | |
892 | if (first_abbrev != NULL) | |
893 | return NULL; | |
894 | ||
895 | while (start < end) | |
896 | { | |
19e6b90e L |
897 | unsigned long entry; |
898 | unsigned long tag; | |
899 | unsigned long attribute; | |
900 | int children; | |
901 | ||
cd30bcef | 902 | READ_ULEB (entry, start, end); |
19e6b90e L |
903 | |
904 | /* A single zero is supposed to end the section according | |
905 | to the standard. If there's more, then signal that to | |
906 | the caller. */ | |
f6f0e17b NC |
907 | if (start == end) |
908 | return NULL; | |
19e6b90e | 909 | if (entry == 0) |
f6f0e17b | 910 | return start; |
19e6b90e | 911 | |
cd30bcef | 912 | READ_ULEB (tag, start, end); |
f6f0e17b NC |
913 | if (start == end) |
914 | return NULL; | |
19e6b90e L |
915 | |
916 | children = *start++; | |
917 | ||
918 | add_abbrev (entry, tag, children); | |
919 | ||
920 | do | |
921 | { | |
922 | unsigned long form; | |
77145576 JK |
923 | /* Initialize it due to a false compiler warning. */ |
924 | bfd_signed_vma implicit_const = -1; | |
19e6b90e | 925 | |
cd30bcef | 926 | READ_ULEB (attribute, start, end); |
f6f0e17b NC |
927 | if (start == end) |
928 | break; | |
19e6b90e | 929 | |
cd30bcef | 930 | READ_ULEB (form, start, end); |
f6f0e17b NC |
931 | if (start == end) |
932 | break; | |
19e6b90e | 933 | |
77145576 JK |
934 | if (form == DW_FORM_implicit_const) |
935 | { | |
cd30bcef | 936 | READ_SLEB (implicit_const, start, end); |
77145576 JK |
937 | if (start == end) |
938 | break; | |
939 | } | |
940 | ||
941 | add_abbrev_attr (attribute, form, implicit_const); | |
19e6b90e L |
942 | } |
943 | while (attribute != 0); | |
944 | } | |
945 | ||
399c99f7 L |
946 | /* Report the missing single zero which ends the section. */ |
947 | error (_(".debug_abbrev section not zero terminated\n")); | |
948 | ||
19e6b90e L |
949 | return NULL; |
950 | } | |
951 | ||
a19c41a7 | 952 | static const char * |
19e6b90e L |
953 | get_TAG_name (unsigned long tag) |
954 | { | |
04914e37 | 955 | const char *name = get_DW_TAG_name ((unsigned int) tag); |
a19c41a7 TT |
956 | |
957 | if (name == NULL) | |
19e6b90e | 958 | { |
a19c41a7 | 959 | static char buffer[100]; |
19e6b90e | 960 | |
04914e37 NC |
961 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
962 | snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag); | |
963 | else | |
964 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag); | |
a19c41a7 | 965 | return buffer; |
19e6b90e | 966 | } |
a19c41a7 TT |
967 | |
968 | return name; | |
19e6b90e L |
969 | } |
970 | ||
a19c41a7 | 971 | static const char * |
19e6b90e L |
972 | get_FORM_name (unsigned long form) |
973 | { | |
399c99f7 | 974 | const char *name; |
bf5117e3 | 975 | |
399c99f7 L |
976 | if (form == 0) |
977 | return "DW_FORM value: 0"; | |
a19c41a7 | 978 | |
399c99f7 | 979 | name = get_DW_FORM_name (form); |
a19c41a7 | 980 | if (name == NULL) |
19e6b90e | 981 | { |
a19c41a7 | 982 | static char buffer[100]; |
19e6b90e | 983 | |
a19c41a7 TT |
984 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
985 | return buffer; | |
19e6b90e | 986 | } |
a19c41a7 TT |
987 | |
988 | return name; | |
19e6b90e L |
989 | } |
990 | ||
61364358 JK |
991 | static const char * |
992 | get_IDX_name (unsigned long idx) | |
993 | { | |
994 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
995 | ||
996 | if (name == NULL) | |
997 | { | |
998 | static char buffer[100]; | |
999 | ||
1000 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1001 | return buffer; | |
1002 | } | |
1003 | ||
1004 | return name; | |
1005 | } | |
1006 | ||
19e6b90e | 1007 | static unsigned char * |
0c588247 NC |
1008 | display_block (unsigned char *data, |
1009 | dwarf_vma length, | |
ef0b5f1c | 1010 | const unsigned char * const end, char delimiter) |
19e6b90e | 1011 | { |
0c588247 NC |
1012 | dwarf_vma maxlen; |
1013 | ||
ef0b5f1c | 1014 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
1015 | if (data > end) |
1016 | return (unsigned char *) end; | |
19e6b90e | 1017 | |
0c588247 NC |
1018 | maxlen = (dwarf_vma) (end - data); |
1019 | length = length > maxlen ? maxlen : length; | |
1020 | ||
19e6b90e L |
1021 | while (length --) |
1022 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1023 | ||
1024 | return data; | |
1025 | } | |
1026 | ||
1027 | static int | |
1028 | decode_location_expression (unsigned char * data, | |
1029 | unsigned int pointer_size, | |
b7807392 JJ |
1030 | unsigned int offset_size, |
1031 | int dwarf_version, | |
467c65bc NC |
1032 | dwarf_vma length, |
1033 | dwarf_vma cu_offset, | |
f1c4cc75 | 1034 | struct dwarf_section * section) |
19e6b90e L |
1035 | { |
1036 | unsigned op; | |
467c65bc | 1037 | dwarf_vma uvalue; |
0c588247 | 1038 | dwarf_signed_vma svalue; |
19e6b90e L |
1039 | unsigned char *end = data + length; |
1040 | int need_frame_base = 0; | |
1041 | ||
1042 | while (data < end) | |
1043 | { | |
1044 | op = *data++; | |
1045 | ||
1046 | switch (op) | |
1047 | { | |
1048 | case DW_OP_addr: | |
0c588247 NC |
1049 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1050 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1051 | break; |
1052 | case DW_OP_deref: | |
1053 | printf ("DW_OP_deref"); | |
1054 | break; | |
1055 | case DW_OP_const1u: | |
0c588247 NC |
1056 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1057 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1058 | break; |
1059 | case DW_OP_const1s: | |
0c588247 NC |
1060 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1061 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1062 | break; |
1063 | case DW_OP_const2u: | |
87bc83b3 | 1064 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1065 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1066 | break; |
1067 | case DW_OP_const2s: | |
0c588247 NC |
1068 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1069 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1070 | break; |
1071 | case DW_OP_const4u: | |
0c588247 NC |
1072 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1073 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1074 | break; |
1075 | case DW_OP_const4s: | |
0c588247 NC |
1076 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1077 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1078 | break; |
1079 | case DW_OP_const8u: | |
0c588247 NC |
1080 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1081 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1082 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1083 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1084 | break; |
1085 | case DW_OP_const8s: | |
0c588247 NC |
1086 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1087 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1088 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1089 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1090 | break; |
1091 | case DW_OP_constu: | |
cd30bcef AM |
1092 | READ_ULEB (uvalue, data, end); |
1093 | printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1094 | break; |
1095 | case DW_OP_consts: | |
cd30bcef AM |
1096 | READ_SLEB (svalue, data, end); |
1097 | printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1098 | break; |
1099 | case DW_OP_dup: | |
1100 | printf ("DW_OP_dup"); | |
1101 | break; | |
1102 | case DW_OP_drop: | |
1103 | printf ("DW_OP_drop"); | |
1104 | break; | |
1105 | case DW_OP_over: | |
1106 | printf ("DW_OP_over"); | |
1107 | break; | |
1108 | case DW_OP_pick: | |
0c588247 NC |
1109 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1110 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1111 | break; |
1112 | case DW_OP_swap: | |
1113 | printf ("DW_OP_swap"); | |
1114 | break; | |
1115 | case DW_OP_rot: | |
1116 | printf ("DW_OP_rot"); | |
1117 | break; | |
1118 | case DW_OP_xderef: | |
1119 | printf ("DW_OP_xderef"); | |
1120 | break; | |
1121 | case DW_OP_abs: | |
1122 | printf ("DW_OP_abs"); | |
1123 | break; | |
1124 | case DW_OP_and: | |
1125 | printf ("DW_OP_and"); | |
1126 | break; | |
1127 | case DW_OP_div: | |
1128 | printf ("DW_OP_div"); | |
1129 | break; | |
1130 | case DW_OP_minus: | |
1131 | printf ("DW_OP_minus"); | |
1132 | break; | |
1133 | case DW_OP_mod: | |
1134 | printf ("DW_OP_mod"); | |
1135 | break; | |
1136 | case DW_OP_mul: | |
1137 | printf ("DW_OP_mul"); | |
1138 | break; | |
1139 | case DW_OP_neg: | |
1140 | printf ("DW_OP_neg"); | |
1141 | break; | |
1142 | case DW_OP_not: | |
1143 | printf ("DW_OP_not"); | |
1144 | break; | |
1145 | case DW_OP_or: | |
1146 | printf ("DW_OP_or"); | |
1147 | break; | |
1148 | case DW_OP_plus: | |
1149 | printf ("DW_OP_plus"); | |
1150 | break; | |
1151 | case DW_OP_plus_uconst: | |
cd30bcef AM |
1152 | READ_ULEB (uvalue, data, end); |
1153 | printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1154 | break; |
1155 | case DW_OP_shl: | |
1156 | printf ("DW_OP_shl"); | |
1157 | break; | |
1158 | case DW_OP_shr: | |
1159 | printf ("DW_OP_shr"); | |
1160 | break; | |
1161 | case DW_OP_shra: | |
1162 | printf ("DW_OP_shra"); | |
1163 | break; | |
1164 | case DW_OP_xor: | |
1165 | printf ("DW_OP_xor"); | |
1166 | break; | |
1167 | case DW_OP_bra: | |
0c588247 NC |
1168 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1169 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1170 | break; |
1171 | case DW_OP_eq: | |
1172 | printf ("DW_OP_eq"); | |
1173 | break; | |
1174 | case DW_OP_ge: | |
1175 | printf ("DW_OP_ge"); | |
1176 | break; | |
1177 | case DW_OP_gt: | |
1178 | printf ("DW_OP_gt"); | |
1179 | break; | |
1180 | case DW_OP_le: | |
1181 | printf ("DW_OP_le"); | |
1182 | break; | |
1183 | case DW_OP_lt: | |
1184 | printf ("DW_OP_lt"); | |
1185 | break; | |
1186 | case DW_OP_ne: | |
1187 | printf ("DW_OP_ne"); | |
1188 | break; | |
1189 | case DW_OP_skip: | |
0c588247 NC |
1190 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1191 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1192 | break; |
1193 | ||
1194 | case DW_OP_lit0: | |
1195 | case DW_OP_lit1: | |
1196 | case DW_OP_lit2: | |
1197 | case DW_OP_lit3: | |
1198 | case DW_OP_lit4: | |
1199 | case DW_OP_lit5: | |
1200 | case DW_OP_lit6: | |
1201 | case DW_OP_lit7: | |
1202 | case DW_OP_lit8: | |
1203 | case DW_OP_lit9: | |
1204 | case DW_OP_lit10: | |
1205 | case DW_OP_lit11: | |
1206 | case DW_OP_lit12: | |
1207 | case DW_OP_lit13: | |
1208 | case DW_OP_lit14: | |
1209 | case DW_OP_lit15: | |
1210 | case DW_OP_lit16: | |
1211 | case DW_OP_lit17: | |
1212 | case DW_OP_lit18: | |
1213 | case DW_OP_lit19: | |
1214 | case DW_OP_lit20: | |
1215 | case DW_OP_lit21: | |
1216 | case DW_OP_lit22: | |
1217 | case DW_OP_lit23: | |
1218 | case DW_OP_lit24: | |
1219 | case DW_OP_lit25: | |
1220 | case DW_OP_lit26: | |
1221 | case DW_OP_lit27: | |
1222 | case DW_OP_lit28: | |
1223 | case DW_OP_lit29: | |
1224 | case DW_OP_lit30: | |
1225 | case DW_OP_lit31: | |
1226 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1227 | break; | |
1228 | ||
1229 | case DW_OP_reg0: | |
1230 | case DW_OP_reg1: | |
1231 | case DW_OP_reg2: | |
1232 | case DW_OP_reg3: | |
1233 | case DW_OP_reg4: | |
1234 | case DW_OP_reg5: | |
1235 | case DW_OP_reg6: | |
1236 | case DW_OP_reg7: | |
1237 | case DW_OP_reg8: | |
1238 | case DW_OP_reg9: | |
1239 | case DW_OP_reg10: | |
1240 | case DW_OP_reg11: | |
1241 | case DW_OP_reg12: | |
1242 | case DW_OP_reg13: | |
1243 | case DW_OP_reg14: | |
1244 | case DW_OP_reg15: | |
1245 | case DW_OP_reg16: | |
1246 | case DW_OP_reg17: | |
1247 | case DW_OP_reg18: | |
1248 | case DW_OP_reg19: | |
1249 | case DW_OP_reg20: | |
1250 | case DW_OP_reg21: | |
1251 | case DW_OP_reg22: | |
1252 | case DW_OP_reg23: | |
1253 | case DW_OP_reg24: | |
1254 | case DW_OP_reg25: | |
1255 | case DW_OP_reg26: | |
1256 | case DW_OP_reg27: | |
1257 | case DW_OP_reg28: | |
1258 | case DW_OP_reg29: | |
1259 | case DW_OP_reg30: | |
1260 | case DW_OP_reg31: | |
18464d4d JK |
1261 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1262 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1263 | break; |
1264 | ||
1265 | case DW_OP_breg0: | |
1266 | case DW_OP_breg1: | |
1267 | case DW_OP_breg2: | |
1268 | case DW_OP_breg3: | |
1269 | case DW_OP_breg4: | |
1270 | case DW_OP_breg5: | |
1271 | case DW_OP_breg6: | |
1272 | case DW_OP_breg7: | |
1273 | case DW_OP_breg8: | |
1274 | case DW_OP_breg9: | |
1275 | case DW_OP_breg10: | |
1276 | case DW_OP_breg11: | |
1277 | case DW_OP_breg12: | |
1278 | case DW_OP_breg13: | |
1279 | case DW_OP_breg14: | |
1280 | case DW_OP_breg15: | |
1281 | case DW_OP_breg16: | |
1282 | case DW_OP_breg17: | |
1283 | case DW_OP_breg18: | |
1284 | case DW_OP_breg19: | |
1285 | case DW_OP_breg20: | |
1286 | case DW_OP_breg21: | |
1287 | case DW_OP_breg22: | |
1288 | case DW_OP_breg23: | |
1289 | case DW_OP_breg24: | |
1290 | case DW_OP_breg25: | |
1291 | case DW_OP_breg26: | |
1292 | case DW_OP_breg27: | |
1293 | case DW_OP_breg28: | |
1294 | case DW_OP_breg29: | |
1295 | case DW_OP_breg30: | |
1296 | case DW_OP_breg31: | |
cd30bcef AM |
1297 | READ_SLEB (svalue, data, end); |
1298 | printf ("DW_OP_breg%d (%s): %s", op - DW_OP_breg0, | |
1299 | regname (op - DW_OP_breg0, 1), dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1300 | break; |
1301 | ||
1302 | case DW_OP_regx: | |
cd30bcef | 1303 | READ_ULEB (uvalue, data, end); |
467c65bc NC |
1304 | printf ("DW_OP_regx: %s (%s)", |
1305 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1306 | break; |
1307 | case DW_OP_fbreg: | |
1308 | need_frame_base = 1; | |
cd30bcef AM |
1309 | READ_SLEB (svalue, data, end); |
1310 | printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue)); | |
19e6b90e L |
1311 | break; |
1312 | case DW_OP_bregx: | |
cd30bcef AM |
1313 | READ_ULEB (uvalue, data, end); |
1314 | READ_SLEB (svalue, data, end); | |
467c65bc NC |
1315 | printf ("DW_OP_bregx: %s (%s) %s", |
1316 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
cd30bcef | 1317 | dwarf_vmatoa ("d", svalue)); |
19e6b90e L |
1318 | break; |
1319 | case DW_OP_piece: | |
cd30bcef AM |
1320 | READ_ULEB (uvalue, data, end); |
1321 | printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue)); | |
19e6b90e L |
1322 | break; |
1323 | case DW_OP_deref_size: | |
0c588247 NC |
1324 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1325 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1326 | break; |
1327 | case DW_OP_xderef_size: | |
0c588247 NC |
1328 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1329 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1330 | break; |
1331 | case DW_OP_nop: | |
1332 | printf ("DW_OP_nop"); | |
1333 | break; | |
1334 | ||
1335 | /* DWARF 3 extensions. */ | |
1336 | case DW_OP_push_object_address: | |
1337 | printf ("DW_OP_push_object_address"); | |
1338 | break; | |
1339 | case DW_OP_call2: | |
d85bf2ba | 1340 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1341 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1342 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1343 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1344 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1345 | break; |
1346 | case DW_OP_call4: | |
d85bf2ba | 1347 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1348 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1349 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1350 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1351 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1352 | break; |
1353 | case DW_OP_call_ref: | |
d85bf2ba | 1354 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
e2a0d921 | 1355 | this ought to be an 8-byte wide computation. */ |
b7807392 JJ |
1356 | if (dwarf_version == -1) |
1357 | { | |
1358 | printf (_("(DW_OP_call_ref in frame info)")); | |
1359 | /* No way to tell where the next op is, so just bail. */ | |
1360 | return need_frame_base; | |
1361 | } | |
1362 | if (dwarf_version == 2) | |
1363 | { | |
0c588247 | 1364 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1365 | } |
1366 | else | |
1367 | { | |
0c588247 | 1368 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1369 | } |
0c588247 | 1370 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1371 | break; |
a87b0a59 NS |
1372 | case DW_OP_form_tls_address: |
1373 | printf ("DW_OP_form_tls_address"); | |
1374 | break; | |
e2a0d921 NC |
1375 | case DW_OP_call_frame_cfa: |
1376 | printf ("DW_OP_call_frame_cfa"); | |
1377 | break; | |
1378 | case DW_OP_bit_piece: | |
1379 | printf ("DW_OP_bit_piece: "); | |
cd30bcef AM |
1380 | READ_ULEB (uvalue, data, end); |
1381 | printf (_("size: %s "), dwarf_vmatoa ("u", uvalue)); | |
1382 | READ_ULEB (uvalue, data, end); | |
1383 | printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue)); | |
e2a0d921 | 1384 | break; |
19e6b90e | 1385 | |
3244e8f5 JJ |
1386 | /* DWARF 4 extensions. */ |
1387 | case DW_OP_stack_value: | |
1388 | printf ("DW_OP_stack_value"); | |
1389 | break; | |
1390 | ||
1391 | case DW_OP_implicit_value: | |
1392 | printf ("DW_OP_implicit_value"); | |
cd30bcef | 1393 | READ_ULEB (uvalue, data, end); |
ef0b5f1c | 1394 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1395 | break; |
1396 | ||
19e6b90e L |
1397 | /* GNU extensions. */ |
1398 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1399 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1400 | break; |
1401 | case DW_OP_GNU_uninit: | |
1402 | printf ("DW_OP_GNU_uninit"); | |
1403 | /* FIXME: Is there data associated with this OP ? */ | |
1404 | break; | |
f1c4cc75 RH |
1405 | case DW_OP_GNU_encoded_addr: |
1406 | { | |
6937bb54 | 1407 | int encoding = 0; |
f1c4cc75 | 1408 | dwarf_vma addr; |
467c65bc | 1409 | |
6937bb54 NC |
1410 | if (data < end) |
1411 | encoding = *data++; | |
041830e0 | 1412 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1413 | |
1414 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1415 | print_dwarf_vma (addr, pointer_size); | |
1416 | } | |
1417 | break; | |
bc0a77d2 | 1418 | case DW_OP_implicit_pointer: |
b7807392 | 1419 | case DW_OP_GNU_implicit_pointer: |
d85bf2ba | 1420 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
b7807392 JJ |
1421 | this ought to be an 8-byte wide computation. */ |
1422 | if (dwarf_version == -1) | |
1423 | { | |
bc0a77d2 JK |
1424 | printf (_("(%s in frame info)"), |
1425 | (op == DW_OP_implicit_pointer | |
1426 | ? "DW_OP_implicit_pointer" | |
1427 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1428 | /* No way to tell where the next op is, so just bail. */ |
1429 | return need_frame_base; | |
1430 | } | |
1431 | if (dwarf_version == 2) | |
1432 | { | |
0c588247 | 1433 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1434 | } |
1435 | else | |
1436 | { | |
0c588247 | 1437 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1438 | } |
cd30bcef | 1439 | READ_SLEB (svalue, data, end); |
bc0a77d2 JK |
1440 | printf ("%s: <0x%s> %s", |
1441 | (op == DW_OP_implicit_pointer | |
1442 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 | 1443 | dwarf_vmatoa ("x", uvalue), |
cd30bcef | 1444 | dwarf_vmatoa ("d", svalue)); |
b7807392 | 1445 | break; |
77145576 | 1446 | case DW_OP_entry_value: |
0892011d | 1447 | case DW_OP_GNU_entry_value: |
cd30bcef | 1448 | READ_ULEB (uvalue, data, end); |
058037d3 NC |
1449 | /* PR 17531: file: 0cc9cd00. */ |
1450 | if (uvalue > (dwarf_vma) (end - data)) | |
1451 | uvalue = end - data; | |
77145576 JK |
1452 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1453 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1454 | if (decode_location_expression (data, pointer_size, offset_size, |
1455 | dwarf_version, uvalue, | |
1456 | cu_offset, section)) | |
1457 | need_frame_base = 1; | |
1458 | putchar (')'); | |
1459 | data += uvalue; | |
6937bb54 NC |
1460 | if (data > end) |
1461 | data = end; | |
0892011d | 1462 | break; |
bc0a77d2 | 1463 | case DW_OP_const_type: |
0892011d | 1464 | case DW_OP_GNU_const_type: |
cd30bcef | 1465 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1466 | printf ("%s: <0x%s> ", |
1467 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1468 | : "DW_OP_GNU_const_type"), | |
0892011d | 1469 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1470 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1471 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1472 | break; |
bc0a77d2 | 1473 | case DW_OP_regval_type: |
0892011d | 1474 | case DW_OP_GNU_regval_type: |
cd30bcef | 1475 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1476 | printf ("%s: %s (%s)", |
1477 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1478 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1479 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
cd30bcef | 1480 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1481 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1482 | break; | |
bc0a77d2 | 1483 | case DW_OP_deref_type: |
0892011d | 1484 | case DW_OP_GNU_deref_type: |
0c588247 | 1485 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1486 | printf ("%s: %ld", |
1487 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1488 | : "DW_OP_GNU_deref_type"), | |
1489 | (long) uvalue); | |
cd30bcef | 1490 | READ_ULEB (uvalue, data, end); |
0892011d JJ |
1491 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
1492 | break; | |
bc0a77d2 | 1493 | case DW_OP_convert: |
0892011d | 1494 | case DW_OP_GNU_convert: |
cd30bcef | 1495 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1496 | printf ("%s <0x%s>", |
1497 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1498 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1499 | break; |
bc0a77d2 | 1500 | case DW_OP_reinterpret: |
0892011d | 1501 | case DW_OP_GNU_reinterpret: |
cd30bcef | 1502 | READ_ULEB (uvalue, data, end); |
bc0a77d2 JK |
1503 | printf ("%s <0x%s>", |
1504 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1505 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1506 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1507 | break; | |
1508 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1509 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1510 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1511 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1512 | break; |
b4eb7656 | 1513 | case DW_OP_GNU_addr_index: |
cd30bcef | 1514 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1515 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1516 | break; | |
1517 | case DW_OP_GNU_const_index: | |
cd30bcef | 1518 | READ_ULEB (uvalue, data, end); |
b4eb7656 AM |
1519 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
1520 | break; | |
f384a1f0 KB |
1521 | case DW_OP_GNU_variable_value: |
1522 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1523 | this ought to be an 8-byte wide computation. */ | |
1524 | if (dwarf_version == -1) | |
1525 | { | |
1526 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1527 | /* No way to tell where the next op is, so just bail. */ | |
1528 | return need_frame_base; | |
1529 | } | |
1530 | if (dwarf_version == 2) | |
1531 | { | |
1532 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1533 | } | |
1534 | else | |
1535 | { | |
1536 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1537 | } | |
1538 | printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1539 | break; | |
e2a0d921 NC |
1540 | |
1541 | /* HP extensions. */ | |
1542 | case DW_OP_HP_is_value: | |
1543 | printf ("DW_OP_HP_is_value"); | |
1544 | /* FIXME: Is there data associated with this OP ? */ | |
1545 | break; | |
1546 | case DW_OP_HP_fltconst4: | |
1547 | printf ("DW_OP_HP_fltconst4"); | |
1548 | /* FIXME: Is there data associated with this OP ? */ | |
1549 | break; | |
1550 | case DW_OP_HP_fltconst8: | |
1551 | printf ("DW_OP_HP_fltconst8"); | |
1552 | /* FIXME: Is there data associated with this OP ? */ | |
1553 | break; | |
1554 | case DW_OP_HP_mod_range: | |
1555 | printf ("DW_OP_HP_mod_range"); | |
1556 | /* FIXME: Is there data associated with this OP ? */ | |
1557 | break; | |
1558 | case DW_OP_HP_unmod_range: | |
1559 | printf ("DW_OP_HP_unmod_range"); | |
1560 | /* FIXME: Is there data associated with this OP ? */ | |
1561 | break; | |
1562 | case DW_OP_HP_tls: | |
1563 | printf ("DW_OP_HP_tls"); | |
1564 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1565 | break; |
1566 | ||
35d60fe4 NC |
1567 | /* PGI (STMicroelectronics) extensions. */ |
1568 | case DW_OP_PGI_omp_thread_num: | |
1569 | /* Pushes the thread number for the current thread as it would be | |
1570 | returned by the standard OpenMP library function: | |
1571 | omp_get_thread_num(). The "current thread" is the thread for | |
1572 | which the expression is being evaluated. */ | |
1573 | printf ("DW_OP_PGI_omp_thread_num"); | |
1574 | break; | |
1575 | ||
19e6b90e L |
1576 | default: |
1577 | if (op >= DW_OP_lo_user | |
1578 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1579 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1580 | else |
0502a2b4 | 1581 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1582 | /* No way to tell where the next op is, so just bail. */ |
1583 | return need_frame_base; | |
1584 | } | |
1585 | ||
1586 | /* Separate the ops. */ | |
1587 | if (data < end) | |
1588 | printf ("; "); | |
1589 | } | |
1590 | ||
1591 | return need_frame_base; | |
1592 | } | |
1593 | ||
341f9135 CC |
1594 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1595 | This is used for DWARF package files. */ | |
1596 | ||
1597 | static struct cu_tu_set * | |
1598 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1599 | { | |
1600 | struct cu_tu_set *p; | |
1601 | unsigned int nsets; | |
1602 | unsigned int dw_sect; | |
1603 | ||
1604 | if (do_types) | |
1605 | { | |
1606 | p = tu_sets; | |
1607 | nsets = tu_count; | |
1608 | dw_sect = DW_SECT_TYPES; | |
1609 | } | |
1610 | else | |
1611 | { | |
1612 | p = cu_sets; | |
1613 | nsets = cu_count; | |
1614 | dw_sect = DW_SECT_INFO; | |
1615 | } | |
1616 | while (nsets > 0) | |
1617 | { | |
1618 | if (p->section_offsets [dw_sect] == cu_offset) | |
1619 | return p; | |
1620 | p++; | |
1621 | nsets--; | |
1622 | } | |
1623 | return NULL; | |
1624 | } | |
1625 | ||
a69c4772 NC |
1626 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1627 | static void | |
1628 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1629 | { | |
1630 | dwarf_vma tmp = * low_bits; | |
1631 | ||
1632 | tmp += inc; | |
1633 | ||
1634 | /* FIXME: There is probably a better way of handling this: | |
1635 | ||
1636 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1637 | type. Plus regardless of its size LOW_BITS is meant to | |
1638 | only hold 32-bits, so if there is overflow or wrap around | |
1639 | we must propagate into HIGH_BITS. */ | |
1640 | if (tmp < * low_bits) | |
1641 | { | |
1642 | ++ * high_bits; | |
1643 | } | |
1644 | else if (sizeof (tmp) > 8 | |
1645 | && (tmp >> 31) > 1) | |
1646 | { | |
1647 | ++ * high_bits; | |
1648 | tmp &= 0xFFFFFFFF; | |
1649 | } | |
1650 | ||
1651 | * low_bits = tmp; | |
1652 | } | |
1653 | ||
dda8d76d NC |
1654 | static const char * |
1655 | fetch_alt_indirect_string (dwarf_vma offset) | |
1656 | { | |
24841daa | 1657 | separate_info * i; |
dda8d76d NC |
1658 | |
1659 | if (! do_follow_links) | |
1660 | return ""; | |
1661 | ||
24841daa NC |
1662 | if (first_separate_info == NULL) |
1663 | return _("<no links available>"); | |
dda8d76d | 1664 | |
24841daa NC |
1665 | for (i = first_separate_info; i != NULL; i = i->next) |
1666 | { | |
1667 | struct dwarf_section * section; | |
1668 | const char * ret; | |
dda8d76d | 1669 | |
24841daa NC |
1670 | if (! load_debug_section (separate_debug_str, i->handle)) |
1671 | continue; | |
dda8d76d | 1672 | |
24841daa | 1673 | section = &debug_displays [separate_debug_str].section; |
dda8d76d | 1674 | |
24841daa NC |
1675 | if (section->start == NULL) |
1676 | continue; | |
dda8d76d | 1677 | |
24841daa NC |
1678 | if (offset >= section->size) |
1679 | continue; | |
1680 | ||
1681 | ret = (const char *) (section->start + offset); | |
1682 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1683 | NUL byte. Since our caller is expecting to receive a well formed C | |
1684 | string we test for the lack of a terminating byte here. */ | |
1685 | if (strnlen ((const char *) ret, section->size - offset) | |
1686 | == section->size - offset) | |
1687 | return _("<no NUL byte at end of alt .debug_str section>"); | |
1688 | ||
1689 | return ret; | |
1690 | } | |
1691 | ||
1692 | warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"), | |
1693 | dwarf_vmatoa ("x", offset)); | |
1694 | return _("<offset is too big>"); | |
dda8d76d NC |
1695 | } |
1696 | ||
d85bf2ba NC |
1697 | static const char * |
1698 | get_AT_name (unsigned long attribute) | |
1699 | { | |
1700 | const char *name; | |
1701 | ||
1702 | if (attribute == 0) | |
1703 | return "DW_AT value: 0"; | |
1704 | ||
1705 | /* One value is shared by the MIPS and HP extensions: */ | |
1706 | if (attribute == DW_AT_MIPS_fde) | |
1707 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1708 | ||
1709 | name = get_DW_AT_name (attribute); | |
1710 | ||
1711 | if (name == NULL) | |
1712 | { | |
1713 | static char buffer[100]; | |
1714 | ||
1715 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1716 | attribute); | |
1717 | return buffer; | |
1718 | } | |
1719 | ||
1720 | return name; | |
1721 | } | |
1722 | ||
24841daa NC |
1723 | static void |
1724 | add_dwo_info (const char * field, dwo_type type) | |
1725 | { | |
1726 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); | |
1727 | ||
1728 | dwinfo->type = type; | |
1729 | dwinfo->value = field; | |
1730 | dwinfo->next = first_dwo_info; | |
1731 | first_dwo_info = dwinfo; | |
1732 | } | |
1733 | ||
1734 | static void | |
1735 | add_dwo_name (const char * name) | |
1736 | { | |
1737 | add_dwo_info (name, DWO_NAME); | |
1738 | } | |
1739 | ||
1740 | static void | |
1741 | add_dwo_dir (const char * dir) | |
1742 | { | |
1743 | add_dwo_info (dir, DWO_DIR); | |
1744 | } | |
1745 | ||
1746 | static void | |
1747 | add_dwo_id (const char * id) | |
1748 | { | |
1749 | add_dwo_info (id, DWO_ID); | |
1750 | } | |
1751 | ||
1752 | static void | |
1753 | free_dwo_info (void) | |
1754 | { | |
1755 | dwo_info * dwinfo; | |
1756 | dwo_info * next; | |
1757 | ||
1758 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) | |
1759 | { | |
1760 | next = dwinfo->next; | |
1761 | free (dwinfo); | |
1762 | } | |
1763 | first_dwo_info = NULL; | |
1764 | } | |
1765 | ||
afc72f15 NC |
1766 | /* Ensure that START + UVALUE is less than END. |
1767 | Return an adjusted UVALUE if necessary to ensure this relationship. */ | |
1768 | ||
1769 | static inline dwarf_vma | |
1770 | check_uvalue (const unsigned char * start, | |
1771 | dwarf_vma uvalue, | |
1772 | const unsigned char * end) | |
1773 | { | |
1774 | dwarf_vma max_uvalue = end - start; | |
1775 | ||
afc72f15 NC |
1776 | /* See PR 17512: file: 008-103549-0.001:0.1. |
1777 | and PR 24829 for examples of where these tests are triggered. */ | |
a85eba51 | 1778 | if (uvalue > max_uvalue) |
afc72f15 NC |
1779 | { |
1780 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1781 | uvalue = max_uvalue; | |
1782 | } | |
1783 | ||
1784 | return uvalue; | |
1785 | } | |
1786 | ||
ec1b0fbb NC |
1787 | static unsigned char * |
1788 | skip_attr_bytes (unsigned long form, | |
1789 | unsigned char * data, | |
1790 | unsigned const char * end, | |
1791 | dwarf_vma pointer_size, | |
1792 | dwarf_vma offset_size, | |
1793 | int dwarf_version, | |
1794 | dwarf_vma * value_return) | |
1795 | { | |
cd30bcef AM |
1796 | dwarf_signed_vma svalue; |
1797 | dwarf_vma uvalue = 0; | |
ec1b0fbb NC |
1798 | |
1799 | * value_return = 0; | |
1800 | ||
1801 | switch (form) | |
1802 | { | |
1803 | case DW_FORM_ref_addr: | |
1804 | if (dwarf_version == 2) | |
1805 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1806 | else if (dwarf_version == 3 || dwarf_version == 4) | |
1807 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1808 | else | |
1809 | return NULL; | |
1810 | break; | |
1811 | ||
1812 | case DW_FORM_addr: | |
1813 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1814 | break; | |
1815 | ||
1816 | case DW_FORM_strp: | |
1817 | case DW_FORM_line_strp: | |
1818 | case DW_FORM_sec_offset: | |
1819 | case DW_FORM_GNU_ref_alt: | |
1820 | case DW_FORM_GNU_strp_alt: | |
1821 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1822 | break; | |
1823 | ||
1824 | case DW_FORM_flag_present: | |
1825 | uvalue = 1; | |
1826 | break; | |
1827 | ||
1828 | case DW_FORM_ref1: | |
1829 | case DW_FORM_flag: | |
1830 | case DW_FORM_data1: | |
1831 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
1832 | break; | |
1833 | ||
1834 | case DW_FORM_ref2: | |
1835 | case DW_FORM_data2: | |
1836 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); | |
1837 | break; | |
1838 | ||
1839 | case DW_FORM_ref4: | |
1840 | case DW_FORM_data4: | |
1841 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1842 | break; | |
1843 | ||
1844 | case DW_FORM_sdata: | |
cd30bcef AM |
1845 | READ_SLEB (svalue, data, end); |
1846 | uvalue = svalue; | |
ec1b0fbb NC |
1847 | break; |
1848 | ||
1849 | case DW_FORM_ref_udata: | |
1850 | case DW_FORM_udata: | |
1851 | case DW_FORM_GNU_str_index: | |
1852 | case DW_FORM_GNU_addr_index: | |
cd30bcef | 1853 | READ_ULEB (uvalue, data, end); |
ec1b0fbb NC |
1854 | break; |
1855 | ||
1856 | case DW_FORM_ref8: | |
1857 | case DW_FORM_data8: | |
1858 | data += 8; | |
1859 | break; | |
1860 | ||
1861 | case DW_FORM_data16: | |
1862 | data += 16; | |
1863 | break; | |
1864 | ||
1865 | case DW_FORM_string: | |
1866 | data += strnlen ((char *) data, end - data) + 1; | |
1867 | break; | |
1868 | ||
1869 | case DW_FORM_block: | |
1870 | case DW_FORM_exprloc: | |
cd30bcef | 1871 | READ_ULEB (uvalue, data, end); |
ec1b0fbb NC |
1872 | break; |
1873 | ||
1874 | case DW_FORM_block1: | |
1875 | SAFE_BYTE_GET (uvalue, data, 1, end); | |
1876 | data += 1 + uvalue; | |
1877 | break; | |
1878 | ||
1879 | case DW_FORM_block2: | |
1880 | SAFE_BYTE_GET (uvalue, data, 2, end); | |
1881 | data += 2 + uvalue; | |
1882 | break; | |
1883 | ||
1884 | case DW_FORM_block4: | |
1885 | SAFE_BYTE_GET (uvalue, data, 4, end); | |
1886 | data += 4 + uvalue; | |
1887 | break; | |
1888 | ||
1889 | case DW_FORM_ref_sig8: | |
1890 | data += 8; | |
1891 | break; | |
1892 | ||
1893 | case DW_FORM_indirect: | |
1894 | /* FIXME: Handle this form. */ | |
1895 | default: | |
1896 | return NULL; | |
1897 | } | |
1898 | ||
1899 | * value_return = uvalue; | |
1900 | if (data > end) | |
1901 | data = (unsigned char *) end; | |
1902 | return data; | |
1903 | } | |
1904 | ||
1905 | /* Return IS_SIGNED set to TRUE if the type at | |
1906 | DATA can be determined to be a signed type. */ | |
1907 | ||
1908 | static void | |
1909 | get_type_signedness (unsigned char * start, | |
1910 | unsigned char * data, | |
1911 | unsigned const char * end, | |
1912 | dwarf_vma pointer_size, | |
1913 | dwarf_vma offset_size, | |
1914 | int dwarf_version, | |
1915 | bfd_boolean * is_signed, | |
1916 | bfd_boolean is_nested) | |
1917 | { | |
1918 | unsigned long abbrev_number; | |
ec1b0fbb NC |
1919 | abbrev_entry * entry; |
1920 | abbrev_attr * attr; | |
1921 | ||
1922 | * is_signed = FALSE; | |
1923 | ||
cd30bcef | 1924 | READ_ULEB (abbrev_number, data, end); |
ec1b0fbb NC |
1925 | |
1926 | for (entry = first_abbrev; | |
1927 | entry != NULL && entry->entry != abbrev_number; | |
1928 | entry = entry->next) | |
1929 | continue; | |
1930 | ||
1931 | if (entry == NULL) | |
1932 | /* FIXME: Issue a warning ? */ | |
1933 | return; | |
1934 | ||
1935 | for (attr = entry->first_attr; | |
1936 | attr != NULL && attr->attribute; | |
1937 | attr = attr->next) | |
1938 | { | |
1939 | dwarf_vma uvalue = 0; | |
1940 | ||
1941 | data = skip_attr_bytes (attr->form, data, end, pointer_size, | |
1942 | offset_size, dwarf_version, & uvalue); | |
1943 | if (data == NULL) | |
1944 | return; | |
1945 | ||
1946 | switch (attr->attribute) | |
1947 | { | |
1948 | #if 0 /* FIXME: It would be nice to print the name of the type, | |
1949 | but this would mean updating a lot of binutils tests. */ | |
1950 | case DW_AT_name: | |
1951 | if (attr->form == DW_FORM_strp) | |
1952 | printf ("%s", fetch_indirect_string (uvalue)); | |
1953 | break; | |
1954 | #endif | |
1955 | case DW_AT_type: | |
1956 | /* Recurse. */ | |
1957 | if (is_nested) | |
1958 | { | |
1959 | /* FIXME: Warn - or is this expected ? | |
1960 | NB/ We need to avoid infinite recursion. */ | |
1961 | return; | |
1962 | } | |
b3fe587e AM |
1963 | if (uvalue >= (size_t) (end - start)) |
1964 | return; | |
ec1b0fbb NC |
1965 | get_type_signedness (start, start + uvalue, end, pointer_size, |
1966 | offset_size, dwarf_version, is_signed, TRUE); | |
1967 | break; | |
1968 | ||
1969 | case DW_AT_encoding: | |
1970 | /* Determine signness. */ | |
1971 | switch (uvalue) | |
1972 | { | |
1973 | case DW_ATE_address: | |
1974 | /* FIXME - some architectures have signed addresses. */ | |
1975 | case DW_ATE_boolean: | |
1976 | case DW_ATE_unsigned: | |
1977 | case DW_ATE_unsigned_char: | |
1978 | case DW_ATE_unsigned_fixed: | |
1979 | * is_signed = FALSE; | |
1980 | break; | |
1981 | ||
1982 | default: | |
1983 | case DW_ATE_complex_float: | |
1984 | case DW_ATE_float: | |
1985 | case DW_ATE_signed: | |
1986 | case DW_ATE_signed_char: | |
1987 | case DW_ATE_imaginary_float: | |
1988 | case DW_ATE_decimal_float: | |
1989 | case DW_ATE_signed_fixed: | |
1990 | * is_signed = TRUE; | |
1991 | break; | |
1992 | } | |
1993 | break; | |
1994 | } | |
1995 | } | |
1996 | } | |
1997 | ||
1998 | static void | |
1999 | read_and_print_leb128 (unsigned char * data, | |
2000 | unsigned int * bytes_read, | |
2001 | unsigned const char * end, | |
2002 | bfd_boolean is_signed) | |
2003 | { | |
cd30bcef AM |
2004 | int status; |
2005 | dwarf_vma val = read_leb128 (data, end, is_signed, bytes_read, &status); | |
2006 | if (status != 0) | |
2007 | report_leb_status (status); | |
ec1b0fbb | 2008 | else |
cd30bcef | 2009 | printf ("%s", dwarf_vmatoa (is_signed ? "d" : "u", val)); |
ec1b0fbb NC |
2010 | } |
2011 | ||
2012 | static void | |
2013 | display_discr_list (unsigned long form, | |
2014 | dwarf_vma uvalue, | |
2015 | unsigned char * data, | |
2016 | unsigned const char * end, | |
2017 | int level) | |
2018 | { | |
2019 | if (uvalue == 0) | |
2020 | { | |
2021 | printf ("[default]"); | |
2022 | return; | |
2023 | } | |
2024 | ||
2025 | switch (form) | |
2026 | { | |
2027 | case DW_FORM_block: | |
2028 | case DW_FORM_block1: | |
2029 | case DW_FORM_block2: | |
2030 | case DW_FORM_block4: | |
2031 | /* Move data pointer back to the start of the byte array. */ | |
2032 | data -= uvalue; | |
2033 | break; | |
2034 | default: | |
2035 | printf ("<corrupt>\n"); | |
2036 | warn (_("corrupt discr_list - not using a block form\n")); | |
2037 | return; | |
2038 | } | |
2039 | ||
2040 | if (uvalue < 2) | |
2041 | { | |
2042 | printf ("<corrupt>\n"); | |
2043 | warn (_("corrupt discr_list - block not long enough\n")); | |
2044 | return; | |
2045 | } | |
2046 | ||
2047 | bfd_boolean is_signed = | |
2048 | (level > 0 && level <= MAX_CU_NESTING) | |
2049 | ? level_type_signed [level - 1] : FALSE; | |
2050 | ||
2051 | printf ("("); | |
2052 | while (uvalue) | |
2053 | { | |
2054 | unsigned char discriminant; | |
2055 | unsigned int bytes_read; | |
2056 | ||
2057 | SAFE_BYTE_GET (discriminant, data, 1, end); | |
2058 | -- uvalue; | |
2059 | data ++; | |
2060 | ||
2061 | assert (uvalue > 0); | |
2062 | switch (discriminant) | |
2063 | { | |
2064 | case DW_DSC_label: | |
2065 | printf ("label "); | |
2066 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2067 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2068 | uvalue -= bytes_read; | |
2069 | data += bytes_read; | |
2070 | break; | |
2071 | ||
2072 | case DW_DSC_range: | |
2073 | printf ("range "); | |
2074 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2075 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2076 | uvalue -= bytes_read; | |
2077 | data += bytes_read; | |
2078 | ||
2079 | printf (".."); | |
2080 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2081 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2082 | uvalue -= bytes_read; | |
2083 | data += bytes_read; | |
2084 | break; | |
2085 | ||
2086 | default: | |
2087 | printf ("<corrupt>\n"); | |
2088 | warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"), | |
2089 | discriminant); | |
2090 | return; | |
2091 | } | |
2092 | ||
2093 | if (uvalue) | |
2094 | printf (", "); | |
2095 | } | |
2096 | ||
2097 | if (is_signed) | |
2098 | printf (")(signed)"); | |
2099 | else | |
2100 | printf (")(unsigned)"); | |
2101 | } | |
2102 | ||
19e6b90e | 2103 | static unsigned char * |
dda8d76d NC |
2104 | read_and_display_attr_value (unsigned long attribute, |
2105 | unsigned long form, | |
2106 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 2107 | unsigned char * start, |
dda8d76d NC |
2108 | unsigned char * data, |
2109 | unsigned char * end, | |
2110 | dwarf_vma cu_offset, | |
2111 | dwarf_vma pointer_size, | |
2112 | dwarf_vma offset_size, | |
2113 | int dwarf_version, | |
2114 | debug_info * debug_info_p, | |
2115 | int do_loc, | |
2116 | struct dwarf_section * section, | |
2117 | struct cu_tu_set * this_set, | |
ec1b0fbb NC |
2118 | char delimiter, |
2119 | int level) | |
19e6b90e | 2120 | { |
cd30bcef | 2121 | dwarf_signed_vma svalue; |
ec1b0fbb NC |
2122 | dwarf_vma uvalue = 0; |
2123 | unsigned char * block_start = NULL; | |
2124 | unsigned char * orig_data = data; | |
19e6b90e | 2125 | |
f41e4712 | 2126 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 2127 | { |
f41e4712 | 2128 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
2129 | return data; |
2130 | } | |
2131 | ||
19e6b90e L |
2132 | switch (form) |
2133 | { | |
2134 | default: | |
2135 | break; | |
2136 | ||
2137 | case DW_FORM_ref_addr: | |
2138 | if (dwarf_version == 2) | |
0c588247 | 2139 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
932fd279 | 2140 | else if (dwarf_version == 3 || dwarf_version == 4) |
0c588247 | 2141 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 2142 | else |
467c65bc NC |
2143 | error (_("Internal error: DWARF version is not 2, 3 or 4.\n")); |
2144 | ||
19e6b90e L |
2145 | break; |
2146 | ||
2147 | case DW_FORM_addr: | |
0c588247 | 2148 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
2149 | break; |
2150 | ||
2151 | case DW_FORM_strp: | |
77145576 | 2152 | case DW_FORM_line_strp: |
932fd279 | 2153 | case DW_FORM_sec_offset: |
a081f3cd JJ |
2154 | case DW_FORM_GNU_ref_alt: |
2155 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 2156 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
2157 | break; |
2158 | ||
932fd279 JJ |
2159 | case DW_FORM_flag_present: |
2160 | uvalue = 1; | |
2161 | break; | |
2162 | ||
19e6b90e L |
2163 | case DW_FORM_ref1: |
2164 | case DW_FORM_flag: | |
2165 | case DW_FORM_data1: | |
0c588247 | 2166 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
2167 | break; |
2168 | ||
2169 | case DW_FORM_ref2: | |
2170 | case DW_FORM_data2: | |
0c588247 | 2171 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
2172 | break; |
2173 | ||
2174 | case DW_FORM_ref4: | |
2175 | case DW_FORM_data4: | |
0c588247 | 2176 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
2177 | break; |
2178 | ||
2179 | case DW_FORM_sdata: | |
cd30bcef AM |
2180 | READ_SLEB (svalue, data, end); |
2181 | uvalue = svalue; | |
19e6b90e L |
2182 | break; |
2183 | ||
4723351a | 2184 | case DW_FORM_GNU_str_index: |
19e6b90e L |
2185 | case DW_FORM_ref_udata: |
2186 | case DW_FORM_udata: | |
cd30bcef AM |
2187 | case DW_FORM_GNU_addr_index: |
2188 | READ_ULEB (uvalue, data, end); | |
19e6b90e L |
2189 | break; |
2190 | ||
2191 | case DW_FORM_indirect: | |
cd30bcef | 2192 | READ_ULEB (form, data, end); |
19e6b90e | 2193 | if (!do_loc) |
ef0b5f1c | 2194 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 | 2195 | if (form == DW_FORM_implicit_const) |
cd30bcef | 2196 | READ_SLEB (implicit_const, data, end); |
ec1b0fbb NC |
2197 | return read_and_display_attr_value (attribute, form, implicit_const, |
2198 | start, data, end, | |
2199 | cu_offset, pointer_size, | |
19e6b90e | 2200 | offset_size, dwarf_version, |
ec4d4525 | 2201 | debug_info_p, do_loc, |
ec1b0fbb | 2202 | section, this_set, delimiter, level); |
19e6b90e L |
2203 | } |
2204 | ||
2205 | switch (form) | |
2206 | { | |
2207 | case DW_FORM_ref_addr: | |
2208 | if (!do_loc) | |
ef0b5f1c | 2209 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
19e6b90e L |
2210 | break; |
2211 | ||
a081f3cd JJ |
2212 | case DW_FORM_GNU_ref_alt: |
2213 | if (!do_loc) | |
ef0b5f1c | 2214 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
dda8d76d | 2215 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
2216 | break; |
2217 | ||
19e6b90e L |
2218 | case DW_FORM_ref1: |
2219 | case DW_FORM_ref2: | |
2220 | case DW_FORM_ref4: | |
2221 | case DW_FORM_ref_udata: | |
2222 | if (!do_loc) | |
ef0b5f1c | 2223 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
2224 | break; |
2225 | ||
2226 | case DW_FORM_data4: | |
2227 | case DW_FORM_addr: | |
932fd279 | 2228 | case DW_FORM_sec_offset: |
19e6b90e | 2229 | if (!do_loc) |
ef0b5f1c | 2230 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2231 | break; |
2232 | ||
932fd279 | 2233 | case DW_FORM_flag_present: |
19e6b90e L |
2234 | case DW_FORM_flag: |
2235 | case DW_FORM_data1: | |
2236 | case DW_FORM_data2: | |
2237 | case DW_FORM_sdata: | |
2238 | case DW_FORM_udata: | |
2239 | if (!do_loc) | |
ef0b5f1c | 2240 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
2241 | break; |
2242 | ||
77145576 JK |
2243 | case DW_FORM_implicit_const: |
2244 | if (!do_loc) | |
2245 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
2246 | break; | |
2247 | ||
19e6b90e L |
2248 | case DW_FORM_ref8: |
2249 | case DW_FORM_data8: | |
2bc8690c | 2250 | if (!do_loc) |
19e6b90e | 2251 | { |
74bc6052 | 2252 | dwarf_vma high_bits; |
a69c4772 | 2253 | dwarf_vma utmp; |
74bc6052 CC |
2254 | char buf[64]; |
2255 | ||
0c588247 | 2256 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
2257 | utmp = uvalue; |
2258 | if (form == DW_FORM_ref8) | |
2259 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 2260 | printf ("%c0x%s", delimiter, |
a69c4772 | 2261 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 2262 | } |
0c588247 | 2263 | |
19e6b90e L |
2264 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2265 | && num_debug_info_entries == 0) | |
2266 | { | |
2267 | if (sizeof (uvalue) == 8) | |
0c588247 | 2268 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 2269 | else |
467c65bc | 2270 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 2271 | } |
0c588247 | 2272 | |
19e6b90e L |
2273 | data += 8; |
2274 | break; | |
2275 | ||
2f6cd591 JK |
2276 | case DW_FORM_data16: |
2277 | if (!do_loc) | |
2278 | { | |
2279 | dwarf_vma left_high_bits, left_low_bits; | |
2280 | dwarf_vma right_high_bits, right_low_bits; | |
2281 | ||
2282 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
2283 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
2284 | if (byte_get == byte_get_little_endian) | |
2285 | { | |
2286 | /* Swap them. */ | |
2287 | left_high_bits ^= right_high_bits; | |
2288 | right_high_bits ^= left_high_bits; | |
2289 | left_high_bits ^= right_high_bits; | |
2290 | left_low_bits ^= right_low_bits; | |
2291 | right_low_bits ^= left_low_bits; | |
2292 | left_low_bits ^= right_low_bits; | |
2293 | } | |
2294 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
2295 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
2296 | left_high_bits, left_low_bits, right_high_bits, | |
2297 | right_low_bits); | |
2298 | } | |
2299 | data += 16; | |
2300 | break; | |
2301 | ||
19e6b90e L |
2302 | case DW_FORM_string: |
2303 | if (!do_loc) | |
ef0b5f1c | 2304 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 2305 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
2306 | break; |
2307 | ||
2308 | case DW_FORM_block: | |
932fd279 | 2309 | case DW_FORM_exprloc: |
cd30bcef AM |
2310 | READ_ULEB (uvalue, data, end); |
2311 | do_block: | |
2312 | block_start = data; | |
a1165289 NC |
2313 | if (block_start >= end) |
2314 | { | |
2315 | warn (_("Block ends prematurely\n")); | |
2316 | uvalue = 0; | |
2317 | block_start = end; | |
2318 | } | |
afc72f15 NC |
2319 | |
2320 | uvalue = check_uvalue (block_start, uvalue, end); | |
2321 | ||
19e6b90e L |
2322 | if (do_loc) |
2323 | data = block_start + uvalue; | |
2324 | else | |
ef0b5f1c | 2325 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2326 | break; |
2327 | ||
2328 | case DW_FORM_block1: | |
cd30bcef AM |
2329 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
2330 | goto do_block; | |
19e6b90e L |
2331 | |
2332 | case DW_FORM_block2: | |
cd30bcef AM |
2333 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
2334 | goto do_block; | |
19e6b90e L |
2335 | |
2336 | case DW_FORM_block4: | |
cd30bcef AM |
2337 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
2338 | goto do_block; | |
19e6b90e L |
2339 | |
2340 | case DW_FORM_strp: | |
2341 | if (!do_loc) | |
ef0b5f1c | 2342 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, |
47704ddf KT |
2343 | dwarf_vmatoa ("x", uvalue), |
2344 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
2345 | break; |
2346 | ||
77145576 JK |
2347 | case DW_FORM_line_strp: |
2348 | if (!do_loc) | |
2349 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2350 | dwarf_vmatoa ("x", uvalue), | |
2351 | fetch_indirect_line_string (uvalue)); | |
2352 | break; | |
2353 | ||
4723351a CC |
2354 | case DW_FORM_GNU_str_index: |
2355 | if (!do_loc) | |
b4eb7656 | 2356 | { |
d85bf2ba NC |
2357 | const char * suffix = strrchr (section->name, '.'); |
2358 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
b4eb7656 | 2359 | |
ef0b5f1c | 2360 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2361 | dwarf_vmatoa ("x", uvalue), |
2362 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2363 | } | |
4723351a CC |
2364 | break; |
2365 | ||
a081f3cd JJ |
2366 | case DW_FORM_GNU_strp_alt: |
2367 | if (!do_loc) | |
dda8d76d NC |
2368 | { |
2369 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2370 | dwarf_vmatoa ("x", uvalue), | |
2371 | fetch_alt_indirect_string (uvalue)); | |
2372 | } | |
a081f3cd JJ |
2373 | break; |
2374 | ||
19e6b90e L |
2375 | case DW_FORM_indirect: |
2376 | /* Handled above. */ | |
2377 | break; | |
2378 | ||
2b6f5997 CC |
2379 | case DW_FORM_ref_sig8: |
2380 | if (!do_loc) | |
2381 | { | |
74bc6052 CC |
2382 | dwarf_vma high_bits; |
2383 | char buf[64]; | |
2384 | ||
0c588247 | 2385 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
ef0b5f1c | 2386 | printf ("%csignature: 0x%s", delimiter, |
74bc6052 | 2387 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); |
2b6f5997 | 2388 | } |
74bc6052 | 2389 | data += 8; |
2b6f5997 CC |
2390 | break; |
2391 | ||
4723351a CC |
2392 | case DW_FORM_GNU_addr_index: |
2393 | if (!do_loc) | |
ef0b5f1c | 2394 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2395 | dwarf_vmatoa ("x", uvalue), |
2396 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
4723351a CC |
2397 | break; |
2398 | ||
19e6b90e L |
2399 | default: |
2400 | warn (_("Unrecognized form: %lu\n"), form); | |
2401 | break; | |
2402 | } | |
2403 | ||
19e6b90e | 2404 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2405 | && num_debug_info_entries == 0 |
2406 | && debug_info_p != NULL) | |
19e6b90e L |
2407 | { |
2408 | switch (attribute) | |
2409 | { | |
2410 | case DW_AT_frame_base: | |
2411 | have_frame_base = 1; | |
1a0670f3 | 2412 | /* Fall through. */ |
19e6b90e | 2413 | case DW_AT_location: |
9f272209 | 2414 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2415 | case DW_AT_string_length: |
2416 | case DW_AT_return_addr: | |
19e6b90e L |
2417 | case DW_AT_data_member_location: |
2418 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2419 | case DW_AT_segment: |
2420 | case DW_AT_static_link: | |
2421 | case DW_AT_use_location: | |
bc0a77d2 | 2422 | case DW_AT_call_value: |
629e7ca8 | 2423 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2424 | case DW_AT_call_data_value: |
629e7ca8 | 2425 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2426 | case DW_AT_call_target: |
629e7ca8 | 2427 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2428 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2429 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2430 | if ((dwarf_version < 4 |
212b6063 | 2431 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2432 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2433 | { |
2434 | /* Process location list. */ | |
91d6fa6a | 2435 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2436 | unsigned int num = debug_info_p->num_loc_offsets; |
2437 | ||
91d6fa6a | 2438 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2439 | { |
91d6fa6a | 2440 | lmax += 1024; |
467c65bc | 2441 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2442 | xcrealloc (debug_info_p->loc_offsets, |
2443 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2444 | debug_info_p->loc_views = (dwarf_vma *) |
2445 | xcrealloc (debug_info_p->loc_views, | |
2446 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2447 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2448 | xcrealloc (debug_info_p->have_frame_base, |
2449 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2450 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2451 | } |
341f9135 | 2452 | if (this_set != NULL) |
b4eb7656 | 2453 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2454 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2455 | if (attribute != DW_AT_GNU_locviews) |
2456 | { | |
a7504f87 NC |
2457 | /* Corrupt DWARF info can produce more offsets than views. |
2458 | See PR 23062 for an example. */ | |
2459 | if (debug_info_p->num_loc_offsets | |
2460 | > debug_info_p->num_loc_views) | |
2461 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2462 | else | |
2463 | { | |
2464 | debug_info_p->loc_offsets [num] = uvalue; | |
2465 | debug_info_p->num_loc_offsets++; | |
2466 | } | |
9f272209 AO |
2467 | } |
2468 | else | |
2469 | { | |
2470 | assert (debug_info_p->num_loc_views <= num); | |
2471 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2472 | if (num > debug_info_p->num_loc_offsets) |
2473 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2474 | else | |
2475 | { | |
2476 | debug_info_p->loc_views [num] = uvalue; | |
2477 | debug_info_p->num_loc_views++; | |
2478 | } | |
9f272209 | 2479 | } |
19e6b90e L |
2480 | } |
2481 | break; | |
e2a0d921 | 2482 | |
19e6b90e L |
2483 | case DW_AT_low_pc: |
2484 | if (need_base_address) | |
2485 | debug_info_p->base_address = uvalue; | |
2486 | break; | |
2487 | ||
4723351a | 2488 | case DW_AT_GNU_addr_base: |
b4eb7656 | 2489 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2490 | break; |
2491 | ||
2492 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2493 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2494 | break; |
2495 | ||
19e6b90e | 2496 | case DW_AT_ranges: |
b4eb7656 | 2497 | if ((dwarf_version < 4 |
212b6063 | 2498 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2499 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2500 | { |
2501 | /* Process range list. */ | |
91d6fa6a | 2502 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2503 | unsigned int num = debug_info_p->num_range_lists; |
2504 | ||
91d6fa6a | 2505 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2506 | { |
91d6fa6a | 2507 | lmax += 1024; |
467c65bc | 2508 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2509 | xcrealloc (debug_info_p->range_lists, |
2510 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2511 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2512 | } |
2513 | debug_info_p->range_lists [num] = uvalue; | |
2514 | debug_info_p->num_range_lists++; | |
2515 | } | |
2516 | break; | |
2517 | ||
d85bf2ba NC |
2518 | case DW_AT_GNU_dwo_name: |
2519 | case DW_AT_dwo_name: | |
2520 | if (need_dwo_info) | |
2521 | switch (form) | |
2522 | { | |
2523 | case DW_FORM_strp: | |
24841daa | 2524 | add_dwo_name ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba NC |
2525 | break; |
2526 | case DW_FORM_GNU_str_index: | |
24841daa | 2527 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2528 | break; |
2529 | case DW_FORM_string: | |
24841daa | 2530 | add_dwo_name ((const char *) orig_data); |
d85bf2ba NC |
2531 | break; |
2532 | default: | |
2533 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2534 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2535 | break; |
2536 | } | |
2537 | break; | |
2538 | ||
2539 | case DW_AT_comp_dir: | |
2540 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2541 | if (need_dwo_info) | |
2542 | switch (form) | |
2543 | { | |
2544 | case DW_FORM_strp: | |
24841daa | 2545 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba NC |
2546 | break; |
2547 | case DW_FORM_line_strp: | |
24841daa | 2548 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue)); |
d85bf2ba NC |
2549 | break; |
2550 | case DW_FORM_GNU_str_index: | |
24841daa | 2551 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2552 | break; |
2553 | case DW_FORM_string: | |
24841daa | 2554 | add_dwo_dir ((const char *) orig_data); |
d85bf2ba NC |
2555 | break; |
2556 | default: | |
2557 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2558 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2559 | break; |
2560 | } | |
2561 | break; | |
2562 | ||
2563 | case DW_AT_GNU_dwo_id: | |
2564 | if (need_dwo_info) | |
2565 | switch (form) | |
2566 | { | |
2567 | case DW_FORM_data8: | |
24841daa NC |
2568 | /* FIXME: Record the length of the ID as well ? */ |
2569 | add_dwo_id ((const char *) (data - 8)); | |
d85bf2ba NC |
2570 | break; |
2571 | default: | |
2572 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2573 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2574 | break; |
2575 | } | |
2576 | break; | |
2577 | ||
19e6b90e L |
2578 | default: |
2579 | break; | |
2580 | } | |
2581 | } | |
2582 | ||
4ccf1e31 | 2583 | if (do_loc || attribute == 0) |
19e6b90e L |
2584 | return data; |
2585 | ||
ec4d4525 | 2586 | /* For some attributes we can display further information. */ |
19e6b90e L |
2587 | switch (attribute) |
2588 | { | |
ec1b0fbb | 2589 | case DW_AT_type: |
b3fe587e AM |
2590 | if (level >= 0 && level < MAX_CU_NESTING |
2591 | && uvalue < (size_t) (end - start)) | |
ec1b0fbb NC |
2592 | { |
2593 | bfd_boolean is_signed = FALSE; | |
2594 | ||
2595 | get_type_signedness (start, start + uvalue, end, pointer_size, | |
2596 | offset_size, dwarf_version, & is_signed, FALSE); | |
2597 | level_type_signed[level] = is_signed; | |
2598 | } | |
2599 | break; | |
2600 | ||
19e6b90e | 2601 | case DW_AT_inline: |
2e9e81a8 | 2602 | printf ("\t"); |
19e6b90e L |
2603 | switch (uvalue) |
2604 | { | |
2605 | case DW_INL_not_inlined: | |
2606 | printf (_("(not inlined)")); | |
2607 | break; | |
2608 | case DW_INL_inlined: | |
2609 | printf (_("(inlined)")); | |
2610 | break; | |
2611 | case DW_INL_declared_not_inlined: | |
2612 | printf (_("(declared as inline but ignored)")); | |
2613 | break; | |
2614 | case DW_INL_declared_inlined: | |
2615 | printf (_("(declared as inline and inlined)")); | |
2616 | break; | |
2617 | default: | |
47704ddf KT |
2618 | printf (_(" (Unknown inline attribute value: %s)"), |
2619 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
2620 | break; |
2621 | } | |
2622 | break; | |
2623 | ||
2624 | case DW_AT_language: | |
2e9e81a8 | 2625 | printf ("\t"); |
19e6b90e L |
2626 | switch (uvalue) |
2627 | { | |
4b78141a | 2628 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 2629 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
2630 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
2631 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 2632 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
2633 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
2634 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
2635 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
2636 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 2637 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 2638 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 2639 | /* DWARF 2.1 values. */ |
4b78141a | 2640 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
2641 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
2642 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
2643 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
2644 | /* DWARF 3 values. */ |
2645 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
2646 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
2647 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
2648 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
2649 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
2650 | /* DWARF 4 values. */ |
2651 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 2652 | /* DWARF 5 values. */ |
2008a0db | 2653 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 2654 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
2655 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
2656 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
2657 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 2658 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
2659 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
2660 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 2661 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
2662 | case DW_LANG_Swift: printf ("(Swift)"); break; |
2663 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
2664 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 2665 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
2666 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
2667 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 2668 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
2669 | /* MIPS extension. */ |
2670 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
2671 | /* UPC extension. */ | |
2672 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
2673 | default: | |
4b78141a | 2674 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 2675 | printf (_("(implementation defined: %s)"), |
467c65bc | 2676 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 2677 | else |
9cf03b7e | 2678 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2679 | break; |
2680 | } | |
2681 | break; | |
2682 | ||
2683 | case DW_AT_encoding: | |
2e9e81a8 | 2684 | printf ("\t"); |
19e6b90e L |
2685 | switch (uvalue) |
2686 | { | |
2687 | case DW_ATE_void: printf ("(void)"); break; | |
2688 | case DW_ATE_address: printf ("(machine address)"); break; | |
2689 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
2690 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
2691 | case DW_ATE_float: printf ("(float)"); break; | |
2692 | case DW_ATE_signed: printf ("(signed)"); break; | |
2693 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
2694 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
2695 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 2696 | /* DWARF 2.1 values: */ |
19e6b90e L |
2697 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
2698 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
2699 | /* DWARF 3 values: */ |
2700 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
2701 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
2702 | case DW_ATE_edited: printf ("(edited)"); break; | |
2703 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
2704 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
2705 | /* DWARF 4 values: */ |
2706 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
2707 | /* DWARF 5 values: */ | |
2708 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
2709 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
2710 | ||
e2a0d921 NC |
2711 | /* HP extensions: */ |
2712 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
2713 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
2714 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
2715 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
2716 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
2717 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
2718 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
2719 | ||
19e6b90e L |
2720 | default: |
2721 | if (uvalue >= DW_ATE_lo_user | |
2722 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 2723 | printf (_("(user defined type)")); |
19e6b90e | 2724 | else |
9cf03b7e | 2725 | printf (_("(unknown type)")); |
19e6b90e L |
2726 | break; |
2727 | } | |
2728 | break; | |
2729 | ||
2730 | case DW_AT_accessibility: | |
2e9e81a8 | 2731 | printf ("\t"); |
19e6b90e L |
2732 | switch (uvalue) |
2733 | { | |
2734 | case DW_ACCESS_public: printf ("(public)"); break; | |
2735 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
2736 | case DW_ACCESS_private: printf ("(private)"); break; | |
2737 | default: | |
9cf03b7e | 2738 | printf (_("(unknown accessibility)")); |
19e6b90e L |
2739 | break; |
2740 | } | |
2741 | break; | |
2742 | ||
2743 | case DW_AT_visibility: | |
2e9e81a8 | 2744 | printf ("\t"); |
19e6b90e L |
2745 | switch (uvalue) |
2746 | { | |
2747 | case DW_VIS_local: printf ("(local)"); break; | |
2748 | case DW_VIS_exported: printf ("(exported)"); break; | |
2749 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 2750 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
2751 | } |
2752 | break; | |
2753 | ||
04914e37 NC |
2754 | case DW_AT_endianity: |
2755 | printf ("\t"); | |
2756 | switch (uvalue) | |
2757 | { | |
2758 | case DW_END_default: printf ("(default)"); break; | |
2759 | case DW_END_big: printf ("(big)"); break; | |
2760 | case DW_END_little: printf ("(little)"); break; | |
2761 | default: | |
2762 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
2763 | printf (_("(user specified)")); | |
2764 | else | |
2765 | printf (_("(unknown endianity)")); | |
2766 | break; | |
2767 | } | |
2768 | break; | |
2769 | ||
19e6b90e | 2770 | case DW_AT_virtuality: |
2e9e81a8 | 2771 | printf ("\t"); |
19e6b90e L |
2772 | switch (uvalue) |
2773 | { | |
2774 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
2775 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
2776 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 2777 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
2778 | } |
2779 | break; | |
2780 | ||
2781 | case DW_AT_identifier_case: | |
2e9e81a8 | 2782 | printf ("\t"); |
19e6b90e L |
2783 | switch (uvalue) |
2784 | { | |
2785 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
2786 | case DW_ID_up_case: printf ("(up_case)"); break; | |
2787 | case DW_ID_down_case: printf ("(down_case)"); break; | |
2788 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 2789 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
2790 | } |
2791 | break; | |
2792 | ||
2793 | case DW_AT_calling_convention: | |
2e9e81a8 | 2794 | printf ("\t"); |
19e6b90e L |
2795 | switch (uvalue) |
2796 | { | |
2797 | case DW_CC_normal: printf ("(normal)"); break; | |
2798 | case DW_CC_program: printf ("(program)"); break; | |
2799 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
2800 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
2801 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
2802 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
2803 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
2804 | default: |
2805 | if (uvalue >= DW_CC_lo_user | |
2806 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 2807 | printf (_("(user defined)")); |
19e6b90e | 2808 | else |
9cf03b7e | 2809 | printf (_("(unknown convention)")); |
19e6b90e L |
2810 | } |
2811 | break; | |
2812 | ||
2813 | case DW_AT_ordering: | |
2e9e81a8 | 2814 | printf ("\t"); |
19e6b90e L |
2815 | switch (uvalue) |
2816 | { | |
04914e37 | 2817 | case 255: |
9cf03b7e | 2818 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
2819 | case 0: printf ("(row major)"); break; |
2820 | case 1: printf ("(column major)"); break; | |
2821 | } | |
2822 | break; | |
2823 | ||
04914e37 NC |
2824 | case DW_AT_decimal_sign: |
2825 | printf ("\t"); | |
2826 | switch (uvalue) | |
2827 | { | |
2828 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
2829 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
2830 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
2831 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
2832 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
2833 | default: printf (_("(unrecognised)")); break; | |
2834 | } | |
2835 | break; | |
2836 | ||
2837 | case DW_AT_defaulted: | |
2838 | printf ("\t"); | |
2839 | switch (uvalue) | |
2840 | { | |
2841 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
2842 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
2843 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
2844 | default: printf (_("(unrecognised)")); break; | |
2845 | } | |
2846 | break; | |
2847 | ||
2848 | case DW_AT_discr_list: | |
2849 | printf ("\t"); | |
ec1b0fbb | 2850 | display_discr_list (form, uvalue, data, end, level); |
04914e37 NC |
2851 | break; |
2852 | ||
19e6b90e L |
2853 | case DW_AT_frame_base: |
2854 | have_frame_base = 1; | |
1a0670f3 | 2855 | /* Fall through. */ |
19e6b90e | 2856 | case DW_AT_location: |
e2a0d921 NC |
2857 | case DW_AT_string_length: |
2858 | case DW_AT_return_addr: | |
19e6b90e L |
2859 | case DW_AT_data_member_location: |
2860 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2861 | case DW_AT_segment: |
2862 | case DW_AT_static_link: | |
2863 | case DW_AT_use_location: | |
bc0a77d2 | 2864 | case DW_AT_call_value: |
629e7ca8 | 2865 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2866 | case DW_AT_call_data_value: |
629e7ca8 | 2867 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2868 | case DW_AT_call_target: |
629e7ca8 | 2869 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2870 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2871 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 2872 | if ((dwarf_version < 4 |
b4eb7656 | 2873 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2874 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 2875 | printf (_(" (location list)")); |
e2a0d921 | 2876 | /* Fall through. */ |
19e6b90e L |
2877 | case DW_AT_allocated: |
2878 | case DW_AT_associated: | |
2879 | case DW_AT_data_location: | |
2880 | case DW_AT_stride: | |
2881 | case DW_AT_upper_bound: | |
cecf136e | 2882 | case DW_AT_lower_bound: |
19e6b90e L |
2883 | if (block_start) |
2884 | { | |
2885 | int need_frame_base; | |
2886 | ||
2e9e81a8 | 2887 | printf ("\t("); |
19e6b90e L |
2888 | need_frame_base = decode_location_expression (block_start, |
2889 | pointer_size, | |
b7807392 JJ |
2890 | offset_size, |
2891 | dwarf_version, | |
19e6b90e | 2892 | uvalue, |
f1c4cc75 | 2893 | cu_offset, section); |
19e6b90e L |
2894 | printf (")"); |
2895 | if (need_frame_base && !have_frame_base) | |
2896 | printf (_(" [without DW_AT_frame_base]")); | |
2897 | } | |
19e6b90e L |
2898 | break; |
2899 | ||
c54207d3 NC |
2900 | case DW_AT_data_bit_offset: |
2901 | case DW_AT_byte_size: | |
2902 | case DW_AT_bit_size: | |
2903 | case DW_AT_string_length_byte_size: | |
2904 | case DW_AT_string_length_bit_size: | |
2905 | case DW_AT_bit_stride: | |
2906 | if (form == DW_FORM_exprloc) | |
2907 | { | |
2908 | printf ("\t("); | |
2909 | (void) decode_location_expression (block_start, pointer_size, | |
2910 | offset_size, dwarf_version, | |
2911 | uvalue, cu_offset, section); | |
2912 | printf (")"); | |
2913 | } | |
2914 | break; | |
2915 | ||
ec4d4525 NC |
2916 | case DW_AT_import: |
2917 | { | |
a081f3cd JJ |
2918 | if (form == DW_FORM_ref_sig8 |
2919 | || form == DW_FORM_GNU_ref_alt) | |
b4eb7656 | 2920 | break; |
2b6f5997 | 2921 | |
ec4d4525 NC |
2922 | if (form == DW_FORM_ref1 |
2923 | || form == DW_FORM_ref2 | |
a7a0b6a5 JK |
2924 | || form == DW_FORM_ref4 |
2925 | || form == DW_FORM_ref_udata) | |
ec4d4525 NC |
2926 | uvalue += cu_offset; |
2927 | ||
6e3d6dc1 | 2928 | if (uvalue >= section->size) |
f3853b34 | 2929 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), |
47704ddf KT |
2930 | dwarf_vmatoa ("x", uvalue), |
2931 | (unsigned long) (orig_data - section->start)); | |
6e3d6dc1 NC |
2932 | else |
2933 | { | |
2934 | unsigned long abbrev_number; | |
cd30bcef AM |
2935 | abbrev_entry *entry; |
2936 | unsigned char *p = section->start + uvalue; | |
6e3d6dc1 | 2937 | |
cd30bcef | 2938 | READ_ULEB (abbrev_number, p, end); |
cecf136e | 2939 | |
2e9e81a8 | 2940 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
afd6e1ff JJ |
2941 | /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
2942 | use different abbrev table, and we don't track .debug_info chunks | |
2943 | yet. */ | |
2944 | if (form != DW_FORM_ref_addr) | |
2945 | { | |
2946 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
2947 | if (entry->entry == abbrev_number) | |
2948 | break; | |
2949 | if (entry != NULL) | |
2950 | printf (" (%s)", get_TAG_name (entry->tag)); | |
2951 | } | |
6e3d6dc1 NC |
2952 | printf ("]"); |
2953 | } | |
ec4d4525 NC |
2954 | } |
2955 | break; | |
2956 | ||
19e6b90e L |
2957 | default: |
2958 | break; | |
2959 | } | |
2960 | ||
2961 | return data; | |
2962 | } | |
2963 | ||
19e6b90e | 2964 | static unsigned char * |
dda8d76d NC |
2965 | read_and_display_attr (unsigned long attribute, |
2966 | unsigned long form, | |
2967 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 2968 | unsigned char * start, |
dda8d76d NC |
2969 | unsigned char * data, |
2970 | unsigned char * end, | |
2971 | dwarf_vma cu_offset, | |
2972 | dwarf_vma pointer_size, | |
2973 | dwarf_vma offset_size, | |
2974 | int dwarf_version, | |
2975 | debug_info * debug_info_p, | |
2976 | int do_loc, | |
2977 | struct dwarf_section * section, | |
ec1b0fbb NC |
2978 | struct cu_tu_set * this_set, |
2979 | int level) | |
19e6b90e L |
2980 | { |
2981 | if (!do_loc) | |
750f03b7 | 2982 | printf (" %-18s:", get_AT_name (attribute)); |
ec1b0fbb NC |
2983 | data = read_and_display_attr_value (attribute, form, implicit_const, |
2984 | start, data, end, | |
f6f0e17b | 2985 | cu_offset, pointer_size, offset_size, |
19e6b90e | 2986 | dwarf_version, debug_info_p, |
ec1b0fbb | 2987 | do_loc, section, this_set, ' ', level); |
19e6b90e L |
2988 | if (!do_loc) |
2989 | printf ("\n"); | |
2990 | return data; | |
2991 | } | |
2992 | ||
dda8d76d | 2993 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
2994 | following debug links, then attempt to load the requested section |
2995 | from one of the separate debug info files. */ | |
dda8d76d NC |
2996 | |
2997 | static bfd_boolean | |
2998 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, | |
24841daa | 2999 | void * handle) |
dda8d76d | 3000 | { |
24841daa | 3001 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 3002 | { |
24841daa NC |
3003 | if (debug_displays[sec_enum].section.filename == NULL) |
3004 | { | |
3005 | /* See if we can associate a filename with this section. */ | |
3006 | separate_info * i; | |
3007 | ||
3008 | for (i = first_separate_info; i != NULL; i = i->next) | |
3009 | if (i->handle == handle) | |
3010 | { | |
3011 | debug_displays[sec_enum].section.filename = i->filename; | |
3012 | break; | |
3013 | } | |
3014 | } | |
3015 | ||
dda8d76d NC |
3016 | return TRUE; |
3017 | } | |
3018 | ||
24841daa NC |
3019 | if (do_follow_links) |
3020 | { | |
3021 | separate_info * i; | |
3022 | ||
3023 | for (i = first_separate_info; i != NULL; i = i->next) | |
3024 | { | |
3025 | if (load_debug_section (sec_enum, i->handle)) | |
3026 | { | |
3027 | debug_displays[sec_enum].section.filename = i->filename; | |
3028 | ||
3029 | /* FIXME: We should check to see if any of the remaining debug info | |
3030 | files also contain this section, and, umm, do something about it. */ | |
3031 | return TRUE; | |
3032 | } | |
3033 | } | |
3034 | } | |
dda8d76d NC |
3035 | |
3036 | return FALSE; | |
3037 | } | |
3038 | ||
3039 | static void | |
3040 | introduce (struct dwarf_section * section, bfd_boolean raw) | |
3041 | { | |
3042 | if (raw) | |
3043 | { | |
3044 | if (do_follow_links && section->filename) | |
3045 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
3046 | section->name, section->filename); | |
3047 | else | |
3048 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
3049 | } | |
3050 | else | |
3051 | { | |
3052 | if (do_follow_links && section->filename) | |
3053 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
3054 | section->name, section->filename); | |
3055 | else | |
3056 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3057 | } | |
3058 | } | |
3059 | ||
d85bf2ba NC |
3060 | /* Process the contents of a .debug_info section. |
3061 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
3062 | and we do not want to display anything to the user. | |
3063 | If do_types is TRUE, we are processing a .debug_types section instead of | |
3064 | a .debug_info section. | |
3065 | The information displayed is restricted by the values in DWARF_START_DIE | |
3066 | and DWARF_CUTOFF_LEVEL. | |
3067 | Returns TRUE upon success. Otherwise an error or warning message is | |
3068 | printed and FALSE is returned. */ | |
19e6b90e | 3069 | |
d85bf2ba NC |
3070 | static bfd_boolean |
3071 | process_debug_info (struct dwarf_section * section, | |
3072 | void * file, | |
3073 | enum dwarf_section_display_enum abbrev_sec, | |
3074 | bfd_boolean do_loc, | |
3075 | bfd_boolean do_types) | |
19e6b90e L |
3076 | { |
3077 | unsigned char *start = section->start; | |
3078 | unsigned char *end = start + section->size; | |
3079 | unsigned char *section_begin; | |
3080 | unsigned int unit; | |
3081 | unsigned int num_units = 0; | |
3082 | ||
3083 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3084 | && num_debug_info_entries == 0 |
3085 | && ! do_types) | |
19e6b90e | 3086 | { |
767221a9 | 3087 | dwarf_vma length; |
19e6b90e L |
3088 | |
3089 | /* First scan the section to get the number of comp units. */ | |
3090 | for (section_begin = start, num_units = 0; section_begin < end; | |
3091 | num_units ++) | |
3092 | { | |
3093 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
3094 | will be the length. For a 64-bit DWARF section, it'll be | |
3095 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 3096 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
3097 | |
3098 | if (length == 0xffffffff) | |
3099 | { | |
0c588247 | 3100 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
3101 | section_begin += length + 12; |
3102 | } | |
ec4d4525 NC |
3103 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
3104 | { | |
767221a9 NC |
3105 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
3106 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3107 | return FALSE; |
ec4d4525 | 3108 | } |
19e6b90e L |
3109 | else |
3110 | section_begin += length + 4; | |
aca88567 NC |
3111 | |
3112 | /* Negative values are illegal, they may even cause infinite | |
3113 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
3114 | relocations to an object file, or if the file is corrupt. */ |
3115 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 3116 | { |
767221a9 NC |
3117 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
3118 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3119 | return FALSE; |
aca88567 | 3120 | } |
19e6b90e L |
3121 | } |
3122 | ||
3123 | if (num_units == 0) | |
3124 | { | |
f41e4712 | 3125 | error (_("No comp units in %s section ?\n"), section->name); |
d85bf2ba | 3126 | return FALSE; |
19e6b90e L |
3127 | } |
3128 | ||
3129 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 3130 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 3131 | sizeof (* debug_information)); |
19e6b90e L |
3132 | if (debug_information == NULL) |
3133 | { | |
f41e4712 | 3134 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 3135 | num_units); |
82b1b41b | 3136 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
d85bf2ba | 3137 | return FALSE; |
19e6b90e | 3138 | } |
d85bf2ba | 3139 | |
03a91817 NC |
3140 | /* PR 17531: file: 92ca3797. |
3141 | We cannot rely upon the debug_information array being initialised | |
3142 | before it is used. A corrupt file could easily contain references | |
3143 | to a unit for which information has not been made available. So | |
3144 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
3145 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
3146 | ||
82b1b41b | 3147 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
3148 | } |
3149 | ||
3150 | if (!do_loc) | |
3151 | { | |
dda8d76d NC |
3152 | load_debug_section_with_follow (str, file); |
3153 | load_debug_section_with_follow (line_str, file); | |
3154 | load_debug_section_with_follow (str_dwo, file); | |
3155 | load_debug_section_with_follow (str_index, file); | |
3156 | load_debug_section_with_follow (str_index_dwo, file); | |
3157 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e L |
3158 | } |
3159 | ||
dda8d76d | 3160 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 3161 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
3162 | { |
3163 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 3164 | debug_displays [abbrev_sec].section.uncompressed_name); |
d85bf2ba | 3165 | return FALSE; |
19e6b90e L |
3166 | } |
3167 | ||
dda8d76d NC |
3168 | if (!do_loc && dwarf_start_die == 0) |
3169 | introduce (section, FALSE); | |
3170 | ||
19e6b90e L |
3171 | for (section_begin = start, unit = 0; start < end; unit++) |
3172 | { | |
3173 | DWARF2_Internal_CompUnit compunit; | |
3174 | unsigned char *hdrptr; | |
19e6b90e | 3175 | unsigned char *tags; |
fd2f0033 | 3176 | int level, last_level, saved_level; |
467c65bc | 3177 | dwarf_vma cu_offset; |
e98fdf1a | 3178 | unsigned long sec_off; |
bf5117e3 | 3179 | unsigned int offset_size; |
19485196 | 3180 | unsigned int initial_length_size; |
74bc6052 CC |
3181 | dwarf_vma signature_high = 0; |
3182 | dwarf_vma signature_low = 0; | |
767221a9 | 3183 | dwarf_vma type_offset = 0; |
341f9135 CC |
3184 | struct cu_tu_set *this_set; |
3185 | dwarf_vma abbrev_base; | |
3186 | size_t abbrev_size; | |
19e6b90e L |
3187 | |
3188 | hdrptr = start; | |
3189 | ||
0c588247 | 3190 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
3191 | |
3192 | if (compunit.cu_length == 0xffffffff) | |
3193 | { | |
0c588247 | 3194 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
3195 | offset_size = 8; |
3196 | initial_length_size = 12; | |
3197 | } | |
3198 | else | |
3199 | { | |
3200 | offset_size = 4; | |
3201 | initial_length_size = 4; | |
3202 | } | |
3203 | ||
0c588247 | 3204 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
3205 | |
3206 | cu_offset = start - section_begin; | |
19e6b90e | 3207 | |
341f9135 CC |
3208 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3209 | ||
77145576 JK |
3210 | if (compunit.cu_version < 5) |
3211 | { | |
3212 | compunit.cu_unit_type = DW_UT_compile; | |
3213 | /* Initialize it due to a false compiler warning. */ | |
3214 | compunit.cu_pointer_size = -1; | |
3215 | } | |
3216 | else | |
3217 | { | |
3218 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3219 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3220 | ||
3221 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3222 | } | |
3223 | ||
0c588247 | 3224 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 3225 | |
341f9135 CC |
3226 | if (this_set == NULL) |
3227 | { | |
3228 | abbrev_base = 0; | |
3229 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3230 | } | |
3231 | else | |
3232 | { | |
3233 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3234 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3235 | } | |
3236 | ||
77145576 JK |
3237 | if (compunit.cu_version < 5) |
3238 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3239 | ||
f41e4712 NC |
3240 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
3241 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
3242 | { | |
3243 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
3244 | compunit.cu_pointer_size, offset_size); | |
3245 | compunit.cu_pointer_size = offset_size; | |
3246 | } | |
2b6f5997 CC |
3247 | |
3248 | if (do_types) | |
b4eb7656 | 3249 | { |
0c588247 | 3250 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 3251 | hdrptr += 8; |
0c588247 | 3252 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 3253 | } |
2b6f5997 | 3254 | |
ae7e7825 NC |
3255 | if (dwarf_start_die > (cu_offset + compunit.cu_length |
3256 | + initial_length_size)) | |
3257 | { | |
3258 | start = section_begin + cu_offset + compunit.cu_length | |
3259 | + initial_length_size; | |
3260 | continue; | |
3261 | } | |
3262 | ||
19e6b90e | 3263 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 CC |
3264 | && num_debug_info_entries == 0 |
3265 | && ! do_types) | |
19e6b90e L |
3266 | { |
3267 | debug_information [unit].cu_offset = cu_offset; | |
3268 | debug_information [unit].pointer_size | |
3269 | = compunit.cu_pointer_size; | |
b7807392 JJ |
3270 | debug_information [unit].offset_size = offset_size; |
3271 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 3272 | debug_information [unit].base_address = 0; |
4723351a CC |
3273 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
3274 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
3275 | debug_information [unit].loc_offsets = NULL; |
3276 | debug_information [unit].have_frame_base = NULL; | |
3277 | debug_information [unit].max_loc_offsets = 0; | |
3278 | debug_information [unit].num_loc_offsets = 0; | |
3279 | debug_information [unit].range_lists = NULL; | |
3280 | debug_information [unit].max_range_lists= 0; | |
3281 | debug_information [unit].num_range_lists = 0; | |
3282 | } | |
3283 | ||
fd2f0033 | 3284 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 3285 | { |
47704ddf KT |
3286 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3287 | dwarf_vmatoa ("x", cu_offset)); | |
3288 | printf (_(" Length: 0x%s (%s)\n"), | |
3289 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3290 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3291 | printf (_(" Version: %d\n"), compunit.cu_version); |
7282333f AM |
3292 | printf (_(" Abbrev Offset: 0x%s\n"), |
3293 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3294 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3295 | if (do_types) |
3296 | { | |
74bc6052 CC |
3297 | char buf[64]; |
3298 | ||
3299 | printf (_(" Signature: 0x%s\n"), | |
3300 | dwarf_vmatoa64 (signature_high, signature_low, | |
3301 | buf, sizeof (buf))); | |
3302 | printf (_(" Type Offset: 0x%s\n"), | |
3303 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3304 | } |
341f9135 CC |
3305 | if (this_set != NULL) |
3306 | { | |
3307 | dwarf_vma *offsets = this_set->section_offsets; | |
3308 | size_t *sizes = this_set->section_sizes; | |
3309 | ||
3310 | printf (_(" Section contributions:\n")); | |
3311 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3312 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3313 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3314 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3315 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3316 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3317 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3318 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3319 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3320 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3321 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3322 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3323 | } | |
19e6b90e L |
3324 | } |
3325 | ||
e98fdf1a AM |
3326 | sec_off = cu_offset + initial_length_size; |
3327 | if (sec_off + compunit.cu_length < sec_off | |
3328 | || sec_off + compunit.cu_length > section->size) | |
460c89ff | 3329 | { |
e98fdf1a AM |
3330 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
3331 | section->name, | |
3332 | (unsigned long) cu_offset, | |
19485196 NC |
3333 | dwarf_vmatoa ("x", compunit.cu_length)); |
3334 | num_units = unit; | |
3335 | break; | |
3336 | } | |
3337 | ||
460c89ff NS |
3338 | tags = hdrptr; |
3339 | start += compunit.cu_length + initial_length_size; | |
3340 | ||
77145576 | 3341 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3342 | { |
47704ddf KT |
3343 | warn (_("CU at offset %s contains corrupt or " |
3344 | "unsupported version number: %d.\n"), | |
3345 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3346 | continue; |
3347 | } | |
3348 | ||
77145576 JK |
3349 | if (compunit.cu_unit_type != DW_UT_compile |
3350 | && compunit.cu_unit_type != DW_UT_type) | |
3351 | { | |
3352 | warn (_("CU at offset %s contains corrupt or " | |
3353 | "unsupported unit type: %d.\n"), | |
3354 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3355 | continue; | |
3356 | } | |
3357 | ||
19e6b90e L |
3358 | free_abbrevs (); |
3359 | ||
d493b283 | 3360 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 3361 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
3362 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
3363 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 3364 | (unsigned long) abbrev_size); |
b4eb7656 | 3365 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
3366 | else if ((abbrev_base + abbrev_size) |
3367 | > debug_displays [abbrev_sec].section.size) | |
3368 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
3369 | (unsigned long) abbrev_base + abbrev_size, | |
3370 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff NS |
3371 | else |
3372 | process_abbrev_section | |
341f9135 CC |
3373 | (((unsigned char *) debug_displays [abbrev_sec].section.start |
3374 | + abbrev_base + compunit.cu_abbrev_offset), | |
3375 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3376 | + abbrev_base + abbrev_size)); | |
19e6b90e L |
3377 | |
3378 | level = 0; | |
fd2f0033 TT |
3379 | last_level = level; |
3380 | saved_level = -1; | |
19e6b90e L |
3381 | while (tags < start) |
3382 | { | |
19e6b90e | 3383 | unsigned long abbrev_number; |
ec4d4525 | 3384 | unsigned long die_offset; |
19e6b90e L |
3385 | abbrev_entry *entry; |
3386 | abbrev_attr *attr; | |
fd2f0033 | 3387 | int do_printing = 1; |
19e6b90e | 3388 | |
ec4d4525 NC |
3389 | die_offset = tags - section_begin; |
3390 | ||
cd30bcef | 3391 | READ_ULEB (abbrev_number, tags, start); |
19e6b90e | 3392 | |
eb7cc021 JK |
3393 | /* A null DIE marks the end of a list of siblings or it may also be |
3394 | a section padding. */ | |
19e6b90e L |
3395 | if (abbrev_number == 0) |
3396 | { | |
eb7cc021 JK |
3397 | /* Check if it can be a section padding for the last CU. */ |
3398 | if (level == 0 && start == end) | |
3399 | { | |
3400 | unsigned char *chk; | |
3401 | ||
3402 | for (chk = tags; chk < start; chk++) | |
3403 | if (*chk != 0) | |
3404 | break; | |
3405 | if (chk == start) | |
3406 | break; | |
3407 | } | |
3408 | ||
4337774f TT |
3409 | if (!do_loc && die_offset >= dwarf_start_die |
3410 | && (dwarf_cutoff_level == -1 | |
3411 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3412 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3413 | level, die_offset); | |
3414 | ||
19e6b90e | 3415 | --level; |
ec4d4525 NC |
3416 | if (level < 0) |
3417 | { | |
3418 | static unsigned num_bogus_warns = 0; | |
3419 | ||
3420 | if (num_bogus_warns < 3) | |
3421 | { | |
4723351a CC |
3422 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3423 | die_offset, section->name); | |
ec4d4525 NC |
3424 | num_bogus_warns ++; |
3425 | if (num_bogus_warns == 3) | |
3426 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3427 | } | |
3428 | } | |
fd2f0033 | 3429 | if (dwarf_start_die != 0 && level < saved_level) |
d85bf2ba | 3430 | return TRUE; |
19e6b90e L |
3431 | continue; |
3432 | } | |
3433 | ||
4b78141a | 3434 | if (!do_loc) |
fd2f0033 TT |
3435 | { |
3436 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
3437 | do_printing = 0; | |
3438 | else | |
3439 | { | |
3440 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
3441 | saved_level = level; | |
3442 | do_printing = (dwarf_cutoff_level == -1 | |
3443 | || level < dwarf_cutoff_level); | |
3444 | if (do_printing) | |
3445 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
3446 | level, die_offset, abbrev_number); | |
3447 | else if (dwarf_cutoff_level == -1 | |
3448 | || last_level < dwarf_cutoff_level) | |
3449 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
3450 | last_level = level; | |
3451 | } | |
3452 | } | |
cecf136e | 3453 | |
19e6b90e L |
3454 | /* Scan through the abbreviation list until we reach the |
3455 | correct entry. */ | |
3456 | for (entry = first_abbrev; | |
3457 | entry && entry->entry != abbrev_number; | |
3458 | entry = entry->next) | |
3459 | continue; | |
3460 | ||
3461 | if (entry == NULL) | |
3462 | { | |
fd2f0033 | 3463 | if (!do_loc && do_printing) |
4b78141a NC |
3464 | { |
3465 | printf ("\n"); | |
3466 | fflush (stdout); | |
3467 | } | |
f3853b34 | 3468 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 3469 | die_offset, abbrev_number); |
d85bf2ba | 3470 | return FALSE; |
19e6b90e L |
3471 | } |
3472 | ||
fd2f0033 | 3473 | if (!do_loc && do_printing) |
cc5914eb | 3474 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 3475 | |
19e6b90e L |
3476 | switch (entry->tag) |
3477 | { | |
3478 | default: | |
3479 | need_base_address = 0; | |
3480 | break; | |
3481 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
3482 | need_base_address = 1; |
3483 | need_dwo_info = do_loc; | |
19e6b90e L |
3484 | break; |
3485 | case DW_TAG_entry_point: | |
19e6b90e L |
3486 | case DW_TAG_subprogram: |
3487 | need_base_address = 0; | |
3488 | /* Assuming that there is no DW_AT_frame_base. */ | |
3489 | have_frame_base = 0; | |
3490 | break; | |
3491 | } | |
3492 | ||
9f272209 AO |
3493 | debug_info *debug_info_p = |
3494 | (debug_information && unit < alloc_num_debug_info_entries) | |
3495 | ? debug_information + unit : NULL; | |
3496 | ||
3497 | assert (!debug_info_p | |
3498 | || (debug_info_p->num_loc_offsets | |
3499 | == debug_info_p->num_loc_views)); | |
3500 | ||
399c99f7 L |
3501 | for (attr = entry->first_attr; |
3502 | attr && attr->attribute; | |
3503 | attr = attr->next) | |
4b78141a | 3504 | { |
fd2f0033 | 3505 | if (! do_loc && do_printing) |
4b78141a | 3506 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 | 3507 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
3508 | tags = read_and_display_attr (attr->attribute, |
3509 | attr->form, | |
77145576 | 3510 | attr->implicit_const, |
ec1b0fbb | 3511 | section_begin, |
341f9135 | 3512 | tags, |
f6f0e17b | 3513 | end, |
341f9135 | 3514 | cu_offset, |
4b78141a NC |
3515 | compunit.cu_pointer_size, |
3516 | offset_size, | |
3517 | compunit.cu_version, | |
9f272209 | 3518 | debug_info_p, |
341f9135 CC |
3519 | do_loc || ! do_printing, |
3520 | section, | |
ec1b0fbb NC |
3521 | this_set, |
3522 | level); | |
4b78141a | 3523 | } |
cecf136e | 3524 | |
9f272209 AO |
3525 | /* If a locview attribute appears before a location one, |
3526 | make sure we don't associate it with an earlier | |
3527 | loclist. */ | |
3528 | if (debug_info_p) | |
3529 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
3530 | { | |
3531 | case 1: | |
3532 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
3533 | debug_info_p->num_loc_views++; | |
3534 | assert (debug_info_p->num_loc_views | |
3535 | == debug_info_p->num_loc_offsets); | |
3536 | break; | |
3537 | ||
3538 | case 0: | |
3539 | break; | |
3540 | ||
3541 | case -1: | |
3542 | warn(_("DIE has locviews without loclist\n")); | |
3543 | debug_info_p->num_loc_views--; | |
3544 | break; | |
3545 | ||
3546 | default: | |
3547 | assert (0); | |
3548 | } | |
3549 | ||
b4eb7656 AM |
3550 | if (entry->children) |
3551 | ++level; | |
3552 | } | |
19e6b90e | 3553 | } |
cecf136e | 3554 | |
19e6b90e L |
3555 | /* Set num_debug_info_entries here so that it can be used to check if |
3556 | we need to process .debug_loc and .debug_ranges sections. */ | |
3557 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3558 | && num_debug_info_entries == 0 |
3559 | && ! do_types) | |
82b1b41b | 3560 | { |
b4eb7656 | 3561 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
3562 | num_debug_info_entries = alloc_num_debug_info_entries; |
3563 | else | |
3564 | num_debug_info_entries = num_units; | |
3565 | } | |
cecf136e | 3566 | |
19e6b90e | 3567 | if (!do_loc) |
467c65bc | 3568 | printf ("\n"); |
cecf136e | 3569 | |
d85bf2ba | 3570 | return TRUE; |
19e6b90e L |
3571 | } |
3572 | ||
3573 | /* Locate and scan the .debug_info section in the file and record the pointer | |
3574 | sizes and offsets for the compilation units in it. Usually an executable | |
3575 | will have just one pointer size, but this is not guaranteed, and so we try | |
3576 | not to make any assumptions. Returns zero upon failure, or the number of | |
3577 | compilation units upon success. */ | |
3578 | ||
3579 | static unsigned int | |
3580 | load_debug_info (void * file) | |
3581 | { | |
1febe64d | 3582 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 3583 | section then do not bother to repeat the task. */ |
cc86f28f | 3584 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
3585 | return 0; |
3586 | ||
19e6b90e L |
3587 | /* If we already have the information there is nothing else to do. */ |
3588 | if (num_debug_info_entries > 0) | |
3589 | return num_debug_info_entries; | |
3590 | ||
341f9135 | 3591 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 3592 | (void) load_cu_tu_indexes (file); |
341f9135 | 3593 | |
dda8d76d | 3594 | if (load_debug_section_with_follow (info, file) |
d85bf2ba | 3595 | && process_debug_info (&debug_displays [info].section, file, abbrev, TRUE, FALSE)) |
19e6b90e | 3596 | return num_debug_info_entries; |
82b1b41b | 3597 | |
dda8d76d | 3598 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 3599 | && process_debug_info (&debug_displays [info_dwo].section, file, |
d85bf2ba | 3600 | abbrev_dwo, TRUE, FALSE)) |
4723351a | 3601 | return num_debug_info_entries; |
1febe64d | 3602 | |
cc86f28f | 3603 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 3604 | return 0; |
19e6b90e L |
3605 | } |
3606 | ||
b40bf0a2 NC |
3607 | /* Read a DWARF .debug_line section header starting at DATA. |
3608 | Upon success returns an updated DATA pointer and the LINFO | |
3609 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
3610 | Otherwise returns NULL. */ | |
19e6b90e | 3611 | |
b40bf0a2 NC |
3612 | static unsigned char * |
3613 | read_debug_line_header (struct dwarf_section * section, | |
3614 | unsigned char * data, | |
3615 | unsigned char * end, | |
3616 | DWARF2_Internal_LineInfo * linfo, | |
3617 | unsigned char ** end_of_sequence) | |
3618 | { | |
3619 | unsigned char *hdrptr; | |
b40bf0a2 | 3620 | unsigned int initial_length_size; |
77145576 | 3621 | unsigned char address_size, segment_selector_size; |
19e6b90e | 3622 | |
b40bf0a2 NC |
3623 | /* Extract information from the Line Number Program Header. |
3624 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 3625 | hdrptr = data; |
19e6b90e | 3626 | |
b40bf0a2 NC |
3627 | /* Get and check the length of the block. */ |
3628 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 3629 | |
b40bf0a2 | 3630 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
3631 | { |
3632 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 3633 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 3634 | linfo->li_offset_size = 8; |
f41e4712 NC |
3635 | initial_length_size = 12; |
3636 | } | |
3637 | else | |
3638 | { | |
77145576 | 3639 | linfo->li_offset_size = 4; |
f41e4712 NC |
3640 | initial_length_size = 4; |
3641 | } | |
19e6b90e | 3642 | |
b40bf0a2 | 3643 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 3644 | { |
8fcc61b4 NC |
3645 | /* If the length field has a relocation against it, then we should |
3646 | not complain if it is inaccurate (and probably negative). This | |
3647 | happens in object files when the .debug_line section is actually | |
3648 | comprised of several different .debug_line.* sections, (some of | |
3649 | which may be removed by linker garbage collection), and a relocation | |
3650 | is used to compute the correct length once that is done. */ | |
77145576 | 3651 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 3652 | { |
8fcc61b4 | 3653 | linfo->li_length = (end - data) - initial_length_size; |
b40bf0a2 NC |
3654 | } |
3655 | else | |
3656 | { | |
8fcc61b4 NC |
3657 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
3658 | (long) linfo->li_length); | |
b40bf0a2 NC |
3659 | return NULL; |
3660 | } | |
f41e4712 | 3661 | } |
19e6b90e | 3662 | |
b40bf0a2 NC |
3663 | /* Get and check the version number. */ |
3664 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
3665 | ||
3666 | if (linfo->li_version != 2 | |
3667 | && linfo->li_version != 3 | |
77145576 JK |
3668 | && linfo->li_version != 4 |
3669 | && linfo->li_version != 5) | |
f41e4712 | 3670 | { |
77145576 JK |
3671 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
3672 | "is currently supported.\n")); | |
b40bf0a2 | 3673 | return NULL; |
f41e4712 | 3674 | } |
19e6b90e | 3675 | |
77145576 JK |
3676 | if (linfo->li_version >= 5) |
3677 | { | |
3678 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
3679 | ||
3680 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
3681 | if (segment_selector_size != 0) | |
3682 | { | |
3683 | warn (_("The %s section contains " | |
3684 | "unsupported segment selector size: %d.\n"), | |
3685 | section->name, segment_selector_size); | |
3686 | return 0; | |
3687 | } | |
3688 | } | |
3689 | ||
3690 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
3691 | linfo->li_offset_size, end); | |
b40bf0a2 | 3692 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 3693 | |
b40bf0a2 | 3694 | if (linfo->li_version >= 4) |
f41e4712 | 3695 | { |
b40bf0a2 | 3696 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 3697 | |
b40bf0a2 | 3698 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
3699 | { |
3700 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 3701 | return NULL; |
a233b20c | 3702 | } |
f41e4712 NC |
3703 | } |
3704 | else | |
b40bf0a2 | 3705 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 3706 | |
b40bf0a2 | 3707 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 3708 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
3709 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
3710 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 3711 | |
b40bf0a2 | 3712 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 3713 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
3714 | if (* end_of_sequence > end) |
3715 | { | |
4c219c2e AM |
3716 | warn (_("Line length %s extends beyond end of section\n"), |
3717 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
3718 | * end_of_sequence = end; |
3719 | return NULL; | |
3720 | } | |
3721 | ||
b40bf0a2 NC |
3722 | return hdrptr; |
3723 | } | |
19e6b90e | 3724 | |
77145576 | 3725 | static unsigned char * |
dda8d76d NC |
3726 | display_formatted_table (unsigned char * data, |
3727 | unsigned char * start, | |
3728 | unsigned char * end, | |
3729 | const DWARF2_Internal_LineInfo * linfo, | |
3730 | struct dwarf_section * section, | |
7b8d9e8c | 3731 | bfd_boolean is_dir) |
77145576 JK |
3732 | { |
3733 | unsigned char *format_start, format_count, *format, formati; | |
3734 | dwarf_vma data_count, datai; | |
cd30bcef | 3735 | unsigned int namepass, last_entry = 0; |
77145576 JK |
3736 | |
3737 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
3738 | format_start = data; | |
3739 | for (formati = 0; formati < format_count; formati++) | |
3740 | { | |
cd30bcef AM |
3741 | SKIP_ULEB (data, end); |
3742 | SKIP_ULEB (data, end); | |
77145576 JK |
3743 | if (data == end) |
3744 | { | |
7b8d9e8c AM |
3745 | if (is_dir) |
3746 | warn (_("Corrupt directory format table entry\n")); | |
3747 | else | |
3748 | warn (_("Corrupt file name format table entry\n")); | |
77145576 JK |
3749 | return data; |
3750 | } | |
3751 | } | |
3752 | ||
cd30bcef | 3753 | READ_ULEB (data_count, data, end); |
77145576 JK |
3754 | if (data == end) |
3755 | { | |
7b8d9e8c AM |
3756 | if (is_dir) |
3757 | warn (_("Corrupt directory list\n")); | |
3758 | else | |
3759 | warn (_("Corrupt file name list\n")); | |
77145576 JK |
3760 | return data; |
3761 | } | |
3762 | ||
3763 | if (data_count == 0) | |
3764 | { | |
7b8d9e8c AM |
3765 | if (is_dir) |
3766 | printf (_("\n The Directory Table is empty.\n")); | |
3767 | else | |
3768 | printf (_("\n The File Name Table is empty.\n")); | |
77145576 JK |
3769 | return data; |
3770 | } | |
3771 | ||
7b8d9e8c AM |
3772 | if (is_dir) |
3773 | printf (_("\n The Directory Table (offset 0x%lx):\n"), | |
3774 | (long) (data - start)); | |
3775 | else | |
3776 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
3777 | (long) (data - start)); | |
77145576 JK |
3778 | |
3779 | printf (_(" Entry")); | |
3780 | /* Delay displaying name as the last entry for better screen layout. */ | |
3781 | for (namepass = 0; namepass < 2; namepass++) | |
3782 | { | |
3783 | format = format_start; | |
3784 | for (formati = 0; formati < format_count; formati++) | |
3785 | { | |
3786 | dwarf_vma content_type; | |
3787 | ||
cd30bcef | 3788 | READ_ULEB (content_type, format, end); |
77145576 JK |
3789 | if ((content_type == DW_LNCT_path) == (namepass == 1)) |
3790 | switch (content_type) | |
3791 | { | |
3792 | case DW_LNCT_path: | |
3793 | printf (_("\tName")); | |
3794 | break; | |
3795 | case DW_LNCT_directory_index: | |
3796 | printf (_("\tDir")); | |
3797 | break; | |
3798 | case DW_LNCT_timestamp: | |
3799 | printf (_("\tTime")); | |
3800 | break; | |
3801 | case DW_LNCT_size: | |
3802 | printf (_("\tSize")); | |
3803 | break; | |
3804 | case DW_LNCT_MD5: | |
3805 | printf (_("\tMD5")); | |
3806 | break; | |
3807 | default: | |
3808 | printf (_("\t(Unknown format content type %s)"), | |
3809 | dwarf_vmatoa ("u", content_type)); | |
3810 | } | |
cd30bcef | 3811 | SKIP_ULEB (format, end); |
77145576 JK |
3812 | } |
3813 | } | |
3814 | putchar ('\n'); | |
3815 | ||
3816 | for (datai = 0; datai < data_count; datai++) | |
3817 | { | |
3818 | unsigned char *datapass = data; | |
3819 | ||
3820 | printf (" %d", last_entry++); | |
3821 | /* Delay displaying name as the last entry for better screen layout. */ | |
3822 | for (namepass = 0; namepass < 2; namepass++) | |
3823 | { | |
3824 | format = format_start; | |
3825 | data = datapass; | |
3826 | for (formati = 0; formati < format_count; formati++) | |
3827 | { | |
3828 | dwarf_vma content_type, form; | |
3829 | ||
cd30bcef AM |
3830 | READ_ULEB (content_type, format, end); |
3831 | READ_ULEB (form, format, end); | |
3832 | data = read_and_display_attr_value (0, form, 0, start, data, end, | |
3833 | 0, 0, linfo->li_offset_size, | |
77145576 JK |
3834 | linfo->li_version, NULL, |
3835 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
ec1b0fbb | 3836 | section, NULL, '\t', -1); |
77145576 JK |
3837 | } |
3838 | } | |
3839 | if (data == end) | |
3840 | { | |
7b8d9e8c AM |
3841 | if (is_dir) |
3842 | warn (_("Corrupt directory entries list\n")); | |
3843 | else | |
3844 | warn (_("Corrupt file name entries list\n")); | |
77145576 JK |
3845 | return data; |
3846 | } | |
3847 | putchar ('\n'); | |
3848 | } | |
3849 | return data; | |
3850 | } | |
3851 | ||
b40bf0a2 | 3852 | static int |
dda8d76d NC |
3853 | display_debug_lines_raw (struct dwarf_section * section, |
3854 | unsigned char * data, | |
3855 | unsigned char * end, | |
3856 | void * file) | |
b40bf0a2 NC |
3857 | { |
3858 | unsigned char *start = section->start; | |
ba8826a8 | 3859 | int verbose_view = 0; |
19e6b90e | 3860 | |
dda8d76d | 3861 | introduce (section, TRUE); |
19e6b90e | 3862 | |
b40bf0a2 NC |
3863 | while (data < end) |
3864 | { | |
3865 | static DWARF2_Internal_LineInfo saved_linfo; | |
3866 | DWARF2_Internal_LineInfo linfo; | |
3867 | unsigned char *standard_opcodes; | |
3868 | unsigned char *end_of_sequence; | |
fe59e83d | 3869 | int i; |
19e6b90e | 3870 | |
4925cdd7 NC |
3871 | if (const_strneq (section->name, ".debug_line.") |
3872 | /* Note: the following does not apply to .debug_line.dwo sections. | |
3873 | These are full debug_line sections. */ | |
3874 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 3875 | { |
b40bf0a2 NC |
3876 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
3877 | section containing just the Line Number Statements. They are | |
3878 | created by the assembler and intended to be used alongside gcc's | |
3879 | -ffunction-sections command line option. When the linker's | |
3880 | garbage collection decides to discard a .text.<foo> section it | |
3881 | can then also discard the line number information in .debug_line.<foo>. | |
3882 | ||
4925cdd7 | 3883 | Since the section is a fragment it does not have the details |
b40bf0a2 | 3884 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 3885 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
3886 | end_of_sequence = end; |
3887 | standard_opcodes = NULL; | |
3888 | linfo = saved_linfo; | |
058037d3 NC |
3889 | /* PR 17531: file: 0522b371. */ |
3890 | if (linfo.li_line_range == 0) | |
3891 | { | |
1306a742 | 3892 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
3893 | return 0; |
3894 | } | |
b40bf0a2 | 3895 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3896 | } |
19e6b90e L |
3897 | else |
3898 | { | |
b40bf0a2 | 3899 | unsigned char * hdrptr; |
19e6b90e | 3900 | |
b40bf0a2 NC |
3901 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
3902 | & end_of_sequence)) == NULL) | |
3903 | return 0; | |
19e6b90e | 3904 | |
b40bf0a2 NC |
3905 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
3906 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
3907 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
77ef8654 | 3908 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
3909 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
3910 | if (linfo.li_version >= 4) | |
3911 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
3912 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
3913 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
3914 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
3915 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 3916 | |
0a9d414a NC |
3917 | /* PR 17512: file: 1665-6428-0.004. */ |
3918 | if (linfo.li_line_range == 0) | |
3919 | { | |
3920 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
3921 | linfo.li_line_range = 1; | |
3922 | } | |
77ef8654 | 3923 | |
b40bf0a2 | 3924 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 3925 | |
b40bf0a2 NC |
3926 | /* Display the contents of the Opcodes table. */ |
3927 | standard_opcodes = hdrptr; | |
19e6b90e | 3928 | |
6937bb54 NC |
3929 | /* PR 17512: file: 002-417945-0.004. */ |
3930 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
3931 | { | |
3932 | warn (_("Line Base extends beyond end of section\n")); | |
3933 | return 0; | |
3934 | } | |
3935 | ||
b40bf0a2 | 3936 | printf (_("\n Opcodes:\n")); |
19e6b90e | 3937 | |
b40bf0a2 | 3938 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
3939 | printf (ngettext (" Opcode %d has %d arg\n", |
3940 | " Opcode %d has %d args\n", | |
3941 | standard_opcodes[i - 1]), | |
3942 | i, standard_opcodes[i - 1]); | |
19e6b90e | 3943 | |
b40bf0a2 NC |
3944 | /* Display the contents of the Directory table. */ |
3945 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 3946 | |
77145576 | 3947 | if (linfo.li_version >= 5) |
b40bf0a2 | 3948 | { |
dda8d76d | 3949 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 3950 | |
77145576 | 3951 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 3952 | TRUE); |
77145576 | 3953 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 3954 | FALSE); |
77145576 JK |
3955 | } |
3956 | else | |
3957 | { | |
3958 | if (*data == 0) | |
3959 | printf (_("\n The Directory Table is empty.\n")); | |
3960 | else | |
a233b20c | 3961 | { |
77145576 | 3962 | unsigned int last_dir_entry = 0; |
6937bb54 | 3963 | |
77145576 JK |
3964 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
3965 | (long)(data - start)); | |
19e6b90e | 3966 | |
77145576 JK |
3967 | while (data < end && *data != 0) |
3968 | { | |
3969 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 3970 | |
77145576 JK |
3971 | data += strnlen ((char *) data, end - data) + 1; |
3972 | } | |
19e6b90e | 3973 | |
77145576 JK |
3974 | /* PR 17512: file: 002-132094-0.004. */ |
3975 | if (data >= end - 1) | |
3976 | break; | |
3977 | } | |
19e6b90e | 3978 | |
77145576 JK |
3979 | /* Skip the NUL at the end of the table. */ |
3980 | data++; | |
19e6b90e | 3981 | |
77145576 JK |
3982 | /* Display the contents of the File Name table. */ |
3983 | if (*data == 0) | |
3984 | printf (_("\n The File Name Table is empty.\n")); | |
3985 | else | |
3986 | { | |
3987 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
3988 | (long)(data - start)); | |
3989 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 3990 | |
77145576 | 3991 | while (data < end && *data != 0) |
b40bf0a2 | 3992 | { |
77145576 | 3993 | unsigned char *name; |
cd30bcef | 3994 | dwarf_vma val; |
77145576 JK |
3995 | |
3996 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
3997 | name = data; | |
3998 | data += strnlen ((char *) data, end - data) + 1; | |
3999 | ||
cd30bcef AM |
4000 | READ_ULEB (val, data, end); |
4001 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4002 | READ_ULEB (val, data, end); | |
4003 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
4004 | READ_ULEB (val, data, end); | |
4005 | printf ("%s\t", dwarf_vmatoa ("u", val)); | |
77145576 JK |
4006 | printf ("%.*s\n", (int)(end - name), name); |
4007 | ||
4008 | if (data == end) | |
4009 | { | |
4010 | warn (_("Corrupt file name table entry\n")); | |
4011 | break; | |
4012 | } | |
b40bf0a2 | 4013 | } |
a233b20c | 4014 | } |
77145576 JK |
4015 | |
4016 | /* Skip the NUL at the end of the table. */ | |
4017 | data++; | |
b40bf0a2 | 4018 | } |
19e6b90e | 4019 | |
b40bf0a2 NC |
4020 | putchar ('\n'); |
4021 | saved_linfo = linfo; | |
4022 | } | |
19e6b90e | 4023 | |
b40bf0a2 NC |
4024 | /* Now display the statements. */ |
4025 | if (data >= end_of_sequence) | |
4026 | printf (_(" No Line Number Statements.\n")); | |
4027 | else | |
4028 | { | |
4029 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 4030 | |
b40bf0a2 NC |
4031 | while (data < end_of_sequence) |
4032 | { | |
4033 | unsigned char op_code; | |
4034 | dwarf_signed_vma adv; | |
4035 | dwarf_vma uladv; | |
19e6b90e | 4036 | |
fe59e83d CC |
4037 | printf (" [0x%08lx]", (long)(data - start)); |
4038 | ||
b40bf0a2 | 4039 | op_code = *data++; |
19e6b90e | 4040 | |
b40bf0a2 | 4041 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 4042 | { |
b40bf0a2 NC |
4043 | op_code -= linfo.li_opcode_base; |
4044 | uladv = (op_code / linfo.li_line_range); | |
4045 | if (linfo.li_max_ops_per_insn == 1) | |
4046 | { | |
4047 | uladv *= linfo.li_min_insn_length; | |
4048 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4049 | if (uladv) |
4050 | state_machine_regs.view = 0; | |
b40bf0a2 | 4051 | printf (_(" Special opcode %d: " |
ba8826a8 | 4052 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 4053 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4054 | dwarf_vmatoa ("x", state_machine_regs.address), |
4055 | verbose_view && uladv | |
4056 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4057 | } |
4058 | else | |
4059 | { | |
ba8826a8 AO |
4060 | unsigned addrdelta |
4061 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
4062 | / linfo.li_max_ops_per_insn) |
4063 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
4064 | |
4065 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
4066 | state_machine_regs.op_index |
4067 | = (state_machine_regs.op_index + uladv) | |
4068 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4069 | if (addrdelta) |
4070 | state_machine_regs.view = 0; | |
b40bf0a2 | 4071 | printf (_(" Special opcode %d: " |
ba8826a8 | 4072 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
4073 | op_code, dwarf_vmatoa ("u", uladv), |
4074 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4075 | state_machine_regs.op_index, |
4076 | verbose_view && addrdelta | |
4077 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4078 | } |
4079 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
4080 | state_machine_regs.line += adv; | |
ba8826a8 | 4081 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 4082 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
4083 | if (verbose_view || state_machine_regs.view) |
4084 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4085 | else | |
4086 | putchar ('\n'); | |
4087 | state_machine_regs.view++; | |
19e6b90e | 4088 | } |
cd30bcef AM |
4089 | else |
4090 | switch (op_code) | |
4091 | { | |
4092 | case DW_LNS_extended_op: | |
4093 | data += process_extended_line_op (data, | |
4094 | linfo.li_default_is_stmt, | |
4095 | end); | |
4096 | break; | |
4097 | ||
4098 | case DW_LNS_copy: | |
4099 | printf (_(" Copy")); | |
4100 | if (verbose_view || state_machine_regs.view) | |
4101 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4102 | else | |
4103 | putchar ('\n'); | |
4104 | state_machine_regs.view++; | |
4105 | break; | |
4106 | ||
4107 | case DW_LNS_advance_pc: | |
4108 | READ_ULEB (uladv, data, end); | |
4109 | if (linfo.li_max_ops_per_insn == 1) | |
4110 | { | |
4111 | uladv *= linfo.li_min_insn_length; | |
4112 | state_machine_regs.address += uladv; | |
4113 | if (uladv) | |
4114 | state_machine_regs.view = 0; | |
4115 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
4116 | dwarf_vmatoa ("u", uladv), | |
4117 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4118 | verbose_view && uladv | |
4119 | ? _(" (reset view)") : ""); | |
4120 | } | |
4121 | else | |
4122 | { | |
4123 | unsigned addrdelta | |
4124 | = ((state_machine_regs.op_index + uladv) | |
4125 | / linfo.li_max_ops_per_insn) | |
4126 | * linfo.li_min_insn_length; | |
4127 | state_machine_regs.address | |
4128 | += addrdelta; | |
4129 | state_machine_regs.op_index | |
4130 | = (state_machine_regs.op_index + uladv) | |
4131 | % linfo.li_max_ops_per_insn; | |
4132 | if (addrdelta) | |
4133 | state_machine_regs.view = 0; | |
4134 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
4135 | dwarf_vmatoa ("u", uladv), | |
4136 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4137 | state_machine_regs.op_index, | |
4138 | verbose_view && addrdelta | |
4139 | ? _(" (reset view)") : ""); | |
4140 | } | |
4141 | break; | |
4142 | ||
4143 | case DW_LNS_advance_line: | |
4144 | READ_SLEB (adv, data, end); | |
4145 | state_machine_regs.line += adv; | |
4146 | printf (_(" Advance Line by %s to %d\n"), | |
4147 | dwarf_vmatoa ("d", adv), | |
4148 | state_machine_regs.line); | |
4149 | break; | |
4150 | ||
4151 | case DW_LNS_set_file: | |
4152 | READ_ULEB (uladv, data, end); | |
4153 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
4154 | dwarf_vmatoa ("u", uladv)); | |
4155 | state_machine_regs.file = uladv; | |
4156 | break; | |
4157 | ||
4158 | case DW_LNS_set_column: | |
4159 | READ_ULEB (uladv, data, end); | |
4160 | printf (_(" Set column to %s\n"), | |
4161 | dwarf_vmatoa ("u", uladv)); | |
4162 | state_machine_regs.column = uladv; | |
4163 | break; | |
4164 | ||
4165 | case DW_LNS_negate_stmt: | |
4166 | adv = state_machine_regs.is_stmt; | |
4167 | adv = ! adv; | |
4168 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
4169 | state_machine_regs.is_stmt = adv; | |
4170 | break; | |
4171 | ||
4172 | case DW_LNS_set_basic_block: | |
4173 | printf (_(" Set basic block\n")); | |
4174 | state_machine_regs.basic_block = 1; | |
4175 | break; | |
4176 | ||
4177 | case DW_LNS_const_add_pc: | |
4178 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4179 | if (linfo.li_max_ops_per_insn) | |
4180 | { | |
4181 | uladv *= linfo.li_min_insn_length; | |
4182 | state_machine_regs.address += uladv; | |
4183 | if (uladv) | |
4184 | state_machine_regs.view = 0; | |
4185 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
4186 | dwarf_vmatoa ("u", uladv), | |
4187 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4188 | verbose_view && uladv | |
4189 | ? _(" (reset view)") : ""); | |
4190 | } | |
4191 | else | |
4192 | { | |
4193 | unsigned addrdelta | |
4194 | = ((state_machine_regs.op_index + uladv) | |
4195 | / linfo.li_max_ops_per_insn) | |
4196 | * linfo.li_min_insn_length; | |
4197 | state_machine_regs.address | |
4198 | += addrdelta; | |
4199 | state_machine_regs.op_index | |
4200 | = (state_machine_regs.op_index + uladv) | |
4201 | % linfo.li_max_ops_per_insn; | |
4202 | if (addrdelta) | |
4203 | state_machine_regs.view = 0; | |
4204 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
4205 | dwarf_vmatoa ("u", uladv), | |
4206 | dwarf_vmatoa ("x", state_machine_regs.address), | |
4207 | state_machine_regs.op_index, | |
4208 | verbose_view && addrdelta | |
4209 | ? _(" (reset view)") : ""); | |
4210 | } | |
4211 | break; | |
4212 | ||
4213 | case DW_LNS_fixed_advance_pc: | |
4214 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4215 | state_machine_regs.address += uladv; | |
4216 | state_machine_regs.op_index = 0; | |
4217 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
4218 | dwarf_vmatoa ("u", uladv), | |
4219 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
4220 | /* Do NOT reset view. */ | |
4221 | break; | |
4222 | ||
4223 | case DW_LNS_set_prologue_end: | |
4224 | printf (_(" Set prologue_end to true\n")); | |
4225 | break; | |
4226 | ||
4227 | case DW_LNS_set_epilogue_begin: | |
4228 | printf (_(" Set epilogue_begin to true\n")); | |
4229 | break; | |
4230 | ||
4231 | case DW_LNS_set_isa: | |
4232 | READ_ULEB (uladv, data, end); | |
4233 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
4234 | break; | |
4235 | ||
4236 | default: | |
4237 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4238 | ||
4239 | if (standard_opcodes != NULL) | |
4240 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4241 | { | |
4242 | READ_ULEB (uladv, data, end); | |
4243 | printf ("0x%s%s", dwarf_vmatoa ("x", uladv), | |
4244 | i == 1 ? "" : ", "); | |
4245 | } | |
4246 | putchar ('\n'); | |
4247 | break; | |
4248 | } | |
19e6b90e | 4249 | } |
b40bf0a2 | 4250 | putchar ('\n'); |
19e6b90e | 4251 | } |
19e6b90e L |
4252 | } |
4253 | ||
4254 | return 1; | |
4255 | } | |
4256 | ||
a262ae96 NC |
4257 | typedef struct |
4258 | { | |
467c65bc NC |
4259 | unsigned char *name; |
4260 | unsigned int directory_index; | |
4261 | unsigned int modification_date; | |
4262 | unsigned int length; | |
a262ae96 NC |
4263 | } File_Entry; |
4264 | ||
4265 | /* Output a decoded representation of the .debug_line section. */ | |
4266 | ||
4267 | static int | |
dda8d76d | 4268 | display_debug_lines_decoded (struct dwarf_section * section, |
ec1b0fbb | 4269 | unsigned char * start, |
dda8d76d NC |
4270 | unsigned char * data, |
4271 | unsigned char * end, | |
4272 | void * fileptr) | |
a262ae96 | 4273 | { |
b40bf0a2 NC |
4274 | static DWARF2_Internal_LineInfo saved_linfo; |
4275 | ||
dda8d76d | 4276 | introduce (section, FALSE); |
a262ae96 NC |
4277 | |
4278 | while (data < end) | |
4279 | { | |
4280 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4281 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4282 | unsigned char *standard_opcodes; |
4283 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4284 | int i; |
4285 | File_Entry *file_table = NULL; | |
143a3db0 | 4286 | unsigned int n_files = 0; |
a262ae96 | 4287 | unsigned char **directory_table = NULL; |
77145576 | 4288 | dwarf_vma n_directories = 0; |
a262ae96 | 4289 | |
4925cdd7 NC |
4290 | if (const_strneq (section->name, ".debug_line.") |
4291 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4292 | These are full debug_line sections. */ | |
4293 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4294 | { |
4925cdd7 | 4295 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4296 | end_of_sequence = end; |
4297 | standard_opcodes = NULL; | |
4298 | linfo = saved_linfo; | |
058037d3 NC |
4299 | /* PR 17531: file: 0522b371. */ |
4300 | if (linfo.li_line_range == 0) | |
4301 | { | |
1306a742 | 4302 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4303 | return 0; |
4304 | } | |
b40bf0a2 | 4305 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4306 | } |
a262ae96 | 4307 | else |
b4eb7656 | 4308 | { |
b40bf0a2 | 4309 | unsigned char *hdrptr; |
a262ae96 | 4310 | |
b40bf0a2 NC |
4311 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4312 | & end_of_sequence)) == NULL) | |
a233b20c | 4313 | return 0; |
0c588247 | 4314 | |
058037d3 NC |
4315 | /* PR 17531: file: 0522b371. */ |
4316 | if (linfo.li_line_range == 0) | |
4317 | { | |
4318 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4319 | linfo.li_line_range = 1; | |
4320 | } | |
b40bf0a2 | 4321 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4322 | |
b40bf0a2 NC |
4323 | /* Save a pointer to the contents of the Opcodes table. */ |
4324 | standard_opcodes = hdrptr; | |
a262ae96 | 4325 | |
b40bf0a2 NC |
4326 | /* Traverse the Directory table just to count entries. */ |
4327 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4328 | /* PR 20440 */ |
4329 | if (data >= end) | |
4330 | { | |
4331 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4332 | linfo.li_opcode_base); | |
4333 | return 0; | |
4334 | } | |
4335 | ||
77145576 | 4336 | if (linfo.li_version >= 5) |
b40bf0a2 | 4337 | { |
77145576 JK |
4338 | unsigned char *format_start, format_count, *format; |
4339 | dwarf_vma formati, entryi; | |
a262ae96 | 4340 | |
dda8d76d | 4341 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4342 | |
4343 | /* Skip directories format. */ | |
4344 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
4345 | format_start = data; | |
4346 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4347 | { |
cd30bcef AM |
4348 | SKIP_ULEB (data, end); |
4349 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4350 | } |
a262ae96 | 4351 | |
cd30bcef | 4352 | READ_ULEB (n_directories, data, end); |
77145576 | 4353 | if (data == end) |
d8024a91 | 4354 | { |
77145576 | 4355 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
4356 | break; |
4357 | } | |
4358 | ||
b40bf0a2 NC |
4359 | directory_table = (unsigned char **) |
4360 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 4361 | |
77145576 | 4362 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 4363 | { |
77145576 | 4364 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 4365 | |
77145576 JK |
4366 | format = format_start; |
4367 | for (formati = 0; formati < format_count; formati++) | |
4368 | { | |
4369 | dwarf_vma content_type, form; | |
4370 | dwarf_vma uvalue; | |
4371 | ||
cd30bcef AM |
4372 | READ_ULEB (content_type, format, end); |
4373 | READ_ULEB (form, format, end); | |
77145576 JK |
4374 | if (data == end) |
4375 | { | |
4376 | warn (_("Corrupt directories list\n")); | |
4377 | break; | |
4378 | } | |
4379 | switch (content_type) | |
4380 | { | |
4381 | case DW_LNCT_path: | |
4382 | switch (form) | |
4383 | { | |
4384 | case DW_FORM_string: | |
4385 | *pathp = data; | |
4386 | break; | |
4387 | case DW_FORM_line_strp: | |
4388 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4389 | end); | |
4390 | /* Remove const by the cast. */ | |
4391 | *pathp = (unsigned char *) | |
4392 | fetch_indirect_line_string (uvalue); | |
4393 | break; | |
4394 | } | |
4395 | break; | |
4396 | } | |
cd30bcef AM |
4397 | data = read_and_display_attr_value (0, form, 0, start, |
4398 | data, end, 0, 0, | |
77145576 JK |
4399 | linfo.li_offset_size, |
4400 | linfo.li_version, | |
4401 | NULL, 1, section, | |
ec1b0fbb | 4402 | NULL, '\t', -1); |
77145576 JK |
4403 | } |
4404 | if (data == end) | |
4405 | { | |
4406 | warn (_("Corrupt directories list\n")); | |
4407 | break; | |
4408 | } | |
4409 | } | |
a262ae96 | 4410 | |
77145576 JK |
4411 | /* Skip files format. */ |
4412 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
4413 | format_start = data; | |
4414 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4415 | { |
cd30bcef AM |
4416 | SKIP_ULEB (data, end); |
4417 | SKIP_ULEB (data, end); | |
b40bf0a2 | 4418 | } |
a262ae96 | 4419 | |
cd30bcef | 4420 | READ_ULEB (n_files, data, end); |
77145576 | 4421 | if (data == end) |
d8024a91 | 4422 | { |
77145576 | 4423 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
4424 | break; |
4425 | } | |
4426 | ||
77145576 JK |
4427 | file_table = (File_Entry *) xcalloc (1, n_files |
4428 | * sizeof (File_Entry)); | |
a262ae96 | 4429 | |
77145576 | 4430 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 4431 | { |
77145576 | 4432 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 4433 | |
77145576 JK |
4434 | format = format_start; |
4435 | for (formati = 0; formati < format_count; formati++) | |
4436 | { | |
4437 | dwarf_vma content_type, form; | |
4438 | dwarf_vma uvalue; | |
cd30bcef | 4439 | unsigned char *tmp; |
77145576 | 4440 | |
cd30bcef AM |
4441 | READ_ULEB (content_type, format, end); |
4442 | READ_ULEB (form, format, end); | |
77145576 JK |
4443 | if (data == end) |
4444 | { | |
4445 | warn (_("Corrupt file name list\n")); | |
4446 | break; | |
4447 | } | |
4448 | switch (content_type) | |
4449 | { | |
4450 | case DW_LNCT_path: | |
4451 | switch (form) | |
4452 | { | |
4453 | case DW_FORM_string: | |
4454 | file->name = data; | |
4455 | break; | |
4456 | case DW_FORM_line_strp: | |
4457 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4458 | end); | |
4459 | /* Remove const by the cast. */ | |
4460 | file->name = (unsigned char *) | |
4461 | fetch_indirect_line_string (uvalue); | |
4462 | break; | |
4463 | } | |
4464 | break; | |
4465 | case DW_LNCT_directory_index: | |
4466 | switch (form) | |
4467 | { | |
4468 | case DW_FORM_data1: | |
4469 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
4470 | end); | |
4471 | break; | |
4472 | case DW_FORM_data2: | |
4473 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
4474 | end); | |
4475 | break; | |
4476 | case DW_FORM_udata: | |
cd30bcef AM |
4477 | tmp = data; |
4478 | READ_ULEB (file->directory_index, tmp, end); | |
77145576 JK |
4479 | break; |
4480 | } | |
4481 | break; | |
4482 | } | |
cd30bcef AM |
4483 | data = read_and_display_attr_value (0, form, 0, start, |
4484 | data, end, 0, 0, | |
77145576 JK |
4485 | linfo.li_offset_size, |
4486 | linfo.li_version, | |
4487 | NULL, 1, section, | |
ec1b0fbb | 4488 | NULL, '\t', -1); |
77145576 JK |
4489 | } |
4490 | if (data == end) | |
4491 | { | |
4492 | warn (_("Corrupt file name list\n")); | |
4493 | break; | |
4494 | } | |
4495 | } | |
4496 | } | |
4497 | else | |
4498 | { | |
4499 | if (*data != 0) | |
b40bf0a2 | 4500 | { |
77145576 JK |
4501 | unsigned char *ptr_directory_table = data; |
4502 | ||
4503 | while (data < end && *data != 0) | |
4504 | { | |
4505 | data += strnlen ((char *) data, end - data) + 1; | |
4506 | n_directories++; | |
4507 | } | |
4508 | ||
4509 | /* PR 20440 */ | |
4510 | if (data >= end) | |
4511 | { | |
4512 | warn (_("directory table ends unexpectedly\n")); | |
4513 | n_directories = 0; | |
4514 | break; | |
4515 | } | |
4516 | ||
4517 | /* Go through the directory table again to save the directories. */ | |
4518 | directory_table = (unsigned char **) | |
4519 | xmalloc (n_directories * sizeof (unsigned char *)); | |
4520 | ||
4521 | i = 0; | |
4522 | while (*ptr_directory_table != 0) | |
4523 | { | |
4524 | directory_table[i] = ptr_directory_table; | |
4525 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
4526 | ptr_directory_table - end) + 1; | |
4527 | i++; | |
4528 | } | |
b40bf0a2 | 4529 | } |
77145576 JK |
4530 | /* Skip the NUL at the end of the table. */ |
4531 | data++; | |
4532 | ||
4533 | /* Traverse the File Name table just to count the entries. */ | |
4534 | if (data < end && *data != 0) | |
b40bf0a2 | 4535 | { |
77145576 JK |
4536 | unsigned char *ptr_file_name_table = data; |
4537 | ||
4538 | while (data < end && *data != 0) | |
db9537d2 | 4539 | { |
cd30bcef AM |
4540 | /* Skip Name, directory index, last modification |
4541 | time and length of file. */ | |
77145576 | 4542 | data += strnlen ((char *) data, end - data) + 1; |
cd30bcef AM |
4543 | SKIP_ULEB (data, end); |
4544 | SKIP_ULEB (data, end); | |
4545 | SKIP_ULEB (data, end); | |
77145576 | 4546 | n_files++; |
db9537d2 | 4547 | } |
a262ae96 | 4548 | |
77145576 JK |
4549 | if (data >= end) |
4550 | { | |
4551 | warn (_("file table ends unexpectedly\n")); | |
4552 | n_files = 0; | |
4553 | break; | |
4554 | } | |
4555 | ||
4556 | /* Go through the file table again to save the strings. */ | |
4557 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 4558 | |
77145576 JK |
4559 | i = 0; |
4560 | while (*ptr_file_name_table != 0) | |
4561 | { | |
77145576 JK |
4562 | file_table[i].name = ptr_file_name_table; |
4563 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
4564 | end - ptr_file_name_table) + 1; | |
4565 | ||
4566 | /* We are not interested in directory, time or size. */ | |
cd30bcef AM |
4567 | READ_ULEB (file_table[i].directory_index, |
4568 | ptr_file_name_table, end); | |
4569 | READ_ULEB (file_table[i].modification_date, | |
4570 | ptr_file_name_table, end); | |
4571 | READ_ULEB (file_table[i].length, | |
4572 | ptr_file_name_table, end); | |
77145576 JK |
4573 | i++; |
4574 | } | |
4575 | i = 0; | |
b40bf0a2 | 4576 | } |
77145576 JK |
4577 | |
4578 | /* Skip the NUL at the end of the table. */ | |
4579 | data++; | |
b40bf0a2 | 4580 | } |
cc5914eb | 4581 | |
77145576 | 4582 | /* Print the Compilation Unit's name and a header. */ |
f082820d AM |
4583 | if (file_table == NULL) |
4584 | ; | |
4585 | else if (directory_table == NULL) | |
4586 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
4587 | else |
4588 | { | |
4589 | unsigned int ix = file_table[0].directory_index; | |
4590 | const char *directory; | |
4591 | ||
4592 | if (ix == 0) | |
4593 | directory = "."; | |
4594 | /* PR 20439 */ | |
4595 | else if (n_directories == 0) | |
4596 | directory = _("<unknown>"); | |
4597 | else if (ix > n_directories) | |
4598 | { | |
4599 | warn (_("directory index %u > number of directories %s\n"), | |
4600 | ix, dwarf_vmatoa ("u", n_directories)); | |
4601 | directory = _("<corrupt>"); | |
4602 | } | |
4603 | else | |
4604 | directory = (char *) directory_table[ix - 1]; | |
4605 | ||
4606 | if (do_wide || strlen (directory) < 76) | |
4607 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
4608 | else | |
4609 | printf ("%s:\n", file_table[0].name); | |
77145576 | 4610 | } |
a262ae96 | 4611 | |
17f6ade2 | 4612 | printf (_("File name Line number Starting address View Stmt\n")); |
b40bf0a2 NC |
4613 | saved_linfo = linfo; |
4614 | } | |
a262ae96 NC |
4615 | |
4616 | /* This loop iterates through the Dwarf Line Number Program. */ | |
4617 | while (data < end_of_sequence) | |
b4eb7656 | 4618 | { |
a262ae96 | 4619 | unsigned char op_code; |
ba8826a8 | 4620 | int xop; |
b4eb7656 AM |
4621 | int adv; |
4622 | unsigned long int uladv; | |
b4eb7656 | 4623 | int is_special_opcode = 0; |
a262ae96 | 4624 | |
b4eb7656 | 4625 | op_code = *data++; |
ba8826a8 | 4626 | xop = op_code; |
a262ae96 | 4627 | |
b4eb7656 | 4628 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 4629 | { |
91d6fa6a | 4630 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
4631 | uladv = (op_code / linfo.li_line_range); |
4632 | if (linfo.li_max_ops_per_insn == 1) | |
4633 | { | |
4634 | uladv *= linfo.li_min_insn_length; | |
4635 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4636 | if (uladv) |
4637 | state_machine_regs.view = 0; | |
a233b20c JJ |
4638 | } |
4639 | else | |
4640 | { | |
ba8826a8 AO |
4641 | unsigned addrdelta |
4642 | = ((state_machine_regs.op_index + uladv) | |
4643 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4644 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4645 | state_machine_regs.address |
4646 | += addrdelta; | |
a233b20c JJ |
4647 | state_machine_regs.op_index |
4648 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 4649 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
4650 | if (addrdelta) |
4651 | state_machine_regs.view = 0; | |
a233b20c | 4652 | } |
a262ae96 | 4653 | |
b4eb7656 AM |
4654 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
4655 | state_machine_regs.line += adv; | |
4656 | is_special_opcode = 1; | |
ba8826a8 | 4657 | /* Increment view after printing this row. */ |
b4eb7656 | 4658 | } |
cd30bcef AM |
4659 | else |
4660 | switch (op_code) | |
4661 | { | |
4662 | case DW_LNS_extended_op: | |
4663 | { | |
4664 | unsigned int ext_op_code_len; | |
4665 | unsigned char ext_op_code; | |
4666 | unsigned char *op_code_end; | |
4667 | unsigned char *op_code_data = data; | |
4668 | ||
4669 | READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence); | |
4670 | op_code_end = op_code_data + ext_op_code_len; | |
4671 | if (ext_op_code_len == 0 || op_code_end > end_of_sequence) | |
4672 | { | |
4673 | warn (_("Badly formed extended line op encountered!\n")); | |
4674 | break; | |
4675 | } | |
4676 | ext_op_code = *op_code_data++; | |
4677 | xop = ext_op_code; | |
4678 | xop = -xop; | |
4679 | ||
4680 | switch (ext_op_code) | |
4681 | { | |
4682 | case DW_LNE_end_sequence: | |
4683 | /* Reset stuff after printing this row. */ | |
4684 | break; | |
4685 | case DW_LNE_set_address: | |
4686 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
4687 | op_code_data, | |
4688 | op_code_end - op_code_data, | |
4689 | op_code_end); | |
4690 | state_machine_regs.op_index = 0; | |
4691 | state_machine_regs.view = 0; | |
4692 | break; | |
4693 | case DW_LNE_define_file: | |
4694 | file_table = (File_Entry *) xrealloc | |
4695 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
4696 | ||
4697 | ++state_machine_regs.last_file_entry; | |
4698 | /* Source file name. */ | |
4699 | file_table[n_files].name = op_code_data; | |
4700 | op_code_data += strlen ((char *) op_code_data) + 1; | |
4701 | /* Directory index. */ | |
4702 | READ_ULEB (file_table[n_files].directory_index, | |
4703 | op_code_data, op_code_end); | |
4704 | /* Last modification time. */ | |
4705 | READ_ULEB (file_table[n_files].modification_date, | |
4706 | op_code_data, op_code_end); | |
4707 | /* File length. */ | |
4708 | READ_ULEB (file_table[n_files].length, | |
4709 | op_code_data, op_code_end); | |
4710 | n_files++; | |
4711 | break; | |
4712 | ||
4713 | case DW_LNE_set_discriminator: | |
4714 | case DW_LNE_HP_set_sequence: | |
4715 | /* Simply ignored. */ | |
4716 | break; | |
4717 | ||
4718 | default: | |
4719 | printf (_("UNKNOWN (%u): length %ld\n"), | |
27653fba | 4720 | ext_op_code, (long int) (op_code_data - data)); |
cd30bcef AM |
4721 | break; |
4722 | } | |
4723 | data = op_code_end; | |
4724 | break; | |
4725 | } | |
4726 | case DW_LNS_copy: | |
4727 | /* Increment view after printing this row. */ | |
4728 | break; | |
4729 | ||
4730 | case DW_LNS_advance_pc: | |
4731 | READ_ULEB (uladv, data, end); | |
4732 | if (linfo.li_max_ops_per_insn == 1) | |
4733 | { | |
4734 | uladv *= linfo.li_min_insn_length; | |
4735 | state_machine_regs.address += uladv; | |
4736 | if (uladv) | |
4737 | state_machine_regs.view = 0; | |
4738 | } | |
4739 | else | |
4740 | { | |
4741 | unsigned addrdelta | |
4742 | = ((state_machine_regs.op_index + uladv) | |
4743 | / linfo.li_max_ops_per_insn) | |
4744 | * linfo.li_min_insn_length; | |
4745 | state_machine_regs.address | |
4746 | += addrdelta; | |
4747 | state_machine_regs.op_index | |
4748 | = (state_machine_regs.op_index + uladv) | |
4749 | % linfo.li_max_ops_per_insn; | |
4750 | if (addrdelta) | |
4751 | state_machine_regs.view = 0; | |
4752 | } | |
4753 | break; | |
4754 | ||
4755 | case DW_LNS_advance_line: | |
4756 | READ_SLEB (adv, data, end); | |
4757 | state_machine_regs.line += adv; | |
4758 | break; | |
4759 | ||
4760 | case DW_LNS_set_file: | |
4761 | READ_ULEB (uladv, data, end); | |
4762 | state_machine_regs.file = uladv; | |
4763 | ||
4764 | { | |
4765 | unsigned file = state_machine_regs.file - 1; | |
4766 | unsigned dir; | |
4767 | ||
4768 | if (file_table == NULL || n_files == 0) | |
4769 | printf (_("\n [Use file table entry %d]\n"), file); | |
4770 | /* PR 20439 */ | |
4771 | else if (file >= n_files) | |
4772 | { | |
4773 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
4774 | printf (_("\n <over large file table index %u>"), file); | |
4775 | } | |
4776 | else if ((dir = file_table[file].directory_index) == 0) | |
4777 | /* If directory index is 0, that means current directory. */ | |
4778 | printf ("\n./%s:[++]\n", file_table[file].name); | |
4779 | else if (directory_table == NULL || n_directories == 0) | |
4780 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
4781 | file_table[file].name, dir); | |
4782 | /* PR 20439 */ | |
4783 | else if (dir > n_directories) | |
4784 | { | |
4785 | warn (_("directory index %u > number of directories %s\n"), | |
4786 | dir, dwarf_vmatoa ("u", n_directories)); | |
4787 | printf (_("\n <over large directory table entry %u>\n"), dir); | |
4788 | } | |
4789 | else | |
4790 | printf ("\n%s/%s:\n", | |
4791 | /* The directory index starts counting at 1. */ | |
4792 | directory_table[dir - 1], file_table[file].name); | |
4793 | } | |
4794 | break; | |
4795 | ||
4796 | case DW_LNS_set_column: | |
4797 | READ_ULEB (uladv, data, end); | |
4798 | state_machine_regs.column = uladv; | |
4799 | break; | |
4800 | ||
4801 | case DW_LNS_negate_stmt: | |
4802 | adv = state_machine_regs.is_stmt; | |
4803 | adv = ! adv; | |
4804 | state_machine_regs.is_stmt = adv; | |
4805 | break; | |
4806 | ||
4807 | case DW_LNS_set_basic_block: | |
4808 | state_machine_regs.basic_block = 1; | |
4809 | break; | |
4810 | ||
4811 | case DW_LNS_const_add_pc: | |
4812 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4813 | if (linfo.li_max_ops_per_insn == 1) | |
4814 | { | |
4815 | uladv *= linfo.li_min_insn_length; | |
4816 | state_machine_regs.address += uladv; | |
4817 | if (uladv) | |
4818 | state_machine_regs.view = 0; | |
4819 | } | |
4820 | else | |
4821 | { | |
4822 | unsigned addrdelta | |
4823 | = ((state_machine_regs.op_index + uladv) | |
4824 | / linfo.li_max_ops_per_insn) | |
4825 | * linfo.li_min_insn_length; | |
4826 | state_machine_regs.address | |
4827 | += addrdelta; | |
4828 | state_machine_regs.op_index | |
4829 | = (state_machine_regs.op_index + uladv) | |
4830 | % linfo.li_max_ops_per_insn; | |
4831 | if (addrdelta) | |
4832 | state_machine_regs.view = 0; | |
4833 | } | |
4834 | break; | |
4835 | ||
4836 | case DW_LNS_fixed_advance_pc: | |
4837 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4838 | state_machine_regs.address += uladv; | |
4839 | state_machine_regs.op_index = 0; | |
4840 | /* Do NOT reset view. */ | |
4841 | break; | |
4842 | ||
4843 | case DW_LNS_set_prologue_end: | |
4844 | break; | |
4845 | ||
4846 | case DW_LNS_set_epilogue_begin: | |
4847 | break; | |
4848 | ||
4849 | case DW_LNS_set_isa: | |
4850 | READ_ULEB (uladv, data, end); | |
4851 | printf (_(" Set ISA to %lu\n"), uladv); | |
4852 | break; | |
4853 | ||
4854 | default: | |
4855 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4856 | ||
4857 | if (standard_opcodes != NULL) | |
4858 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4859 | { | |
4860 | dwarf_vma val; | |
4861 | ||
4862 | READ_ULEB (val, data, end); | |
4863 | printf ("0x%s%s", dwarf_vmatoa ("x", val), | |
4864 | i == 1 ? "" : ", "); | |
4865 | } | |
4866 | putchar ('\n'); | |
4867 | break; | |
4868 | } | |
a262ae96 | 4869 | |
b4eb7656 AM |
4870 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
4871 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
4872 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
4873 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
4874 | { |
4875 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
4876 | char *fileName; | |
4877 | char *newFileName = NULL; | |
4878 | size_t fileNameLength; | |
b40bf0a2 NC |
4879 | |
4880 | if (file_table) | |
db9537d2 NC |
4881 | { |
4882 | unsigned indx = state_machine_regs.file - 1; | |
4883 | /* PR 20439 */ | |
4884 | if (indx >= n_files) | |
4885 | { | |
4886 | warn (_("corrupt file index %u encountered\n"), indx); | |
4887 | fileName = _("<corrupt>"); | |
4888 | } | |
4889 | else | |
4890 | fileName = (char *) file_table[indx].name; | |
4891 | } | |
b40bf0a2 | 4892 | else |
db9537d2 | 4893 | fileName = _("<unknown>"); |
b40bf0a2 NC |
4894 | |
4895 | fileNameLength = strlen (fileName); | |
a262ae96 | 4896 | |
b4eb7656 AM |
4897 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
4898 | { | |
4899 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
4900 | /* Truncate file name */ | |
4901 | strncpy (newFileName, | |
4902 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
4903 | MAX_FILENAME_LENGTH + 1); | |
4904 | } | |
4905 | else | |
4906 | { | |
4907 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
4908 | strncpy (newFileName, fileName, fileNameLength + 1); | |
4909 | } | |
4910 | ||
4911 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) | |
4912 | { | |
a233b20c | 4913 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 4914 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 4915 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4916 | state_machine_regs.address); |
4917 | else | |
ba8826a8 | 4918 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 4919 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4920 | state_machine_regs.address, |
4921 | state_machine_regs.op_index); | |
b4eb7656 AM |
4922 | } |
4923 | else | |
4924 | { | |
a233b20c | 4925 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 4926 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 4927 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4928 | state_machine_regs.address); |
4929 | else | |
ba8826a8 | 4930 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 4931 | newFileName, state_machine_regs.line, |
a233b20c JJ |
4932 | state_machine_regs.address, |
4933 | state_machine_regs.op_index); | |
b4eb7656 | 4934 | } |
a262ae96 | 4935 | |
ba8826a8 | 4936 | if (state_machine_regs.view) |
17f6ade2 | 4937 | printf (" %6u", state_machine_regs.view); |
ba8826a8 | 4938 | else |
17f6ade2 JD |
4939 | printf (" "); |
4940 | ||
4941 | if (state_machine_regs.is_stmt) | |
4942 | printf (" x"); | |
4943 | ||
4944 | putchar ('\n'); | |
ba8826a8 AO |
4945 | state_machine_regs.view++; |
4946 | ||
4947 | if (xop == -DW_LNE_end_sequence) | |
4948 | { | |
4949 | reset_state_machine (linfo.li_default_is_stmt); | |
4950 | putchar ('\n'); | |
4951 | } | |
a262ae96 | 4952 | |
b4eb7656 AM |
4953 | free (newFileName); |
4954 | } | |
4955 | } | |
b40bf0a2 NC |
4956 | |
4957 | if (file_table) | |
4958 | { | |
4959 | free (file_table); | |
4960 | file_table = NULL; | |
4961 | n_files = 0; | |
4962 | } | |
4963 | ||
4964 | if (directory_table) | |
4965 | { | |
4966 | free (directory_table); | |
4967 | directory_table = NULL; | |
4968 | n_directories = 0; | |
4969 | } | |
4970 | ||
a262ae96 NC |
4971 | putchar ('\n'); |
4972 | } | |
4973 | ||
4974 | return 1; | |
4975 | } | |
4976 | ||
4977 | static int | |
77145576 | 4978 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
4979 | { |
4980 | unsigned char *data = section->start; | |
4981 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
4982 | int retValRaw = 1; |
4983 | int retValDecoded = 1; | |
a262ae96 | 4984 | |
008f4c78 NC |
4985 | if (do_debug_lines == 0) |
4986 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
4987 | ||
4cb93e3b | 4988 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 4989 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 4990 | |
4cb93e3b | 4991 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
ec1b0fbb | 4992 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
a262ae96 | 4993 | |
4cb93e3b | 4994 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
4995 | return 0; |
4996 | ||
4997 | return 1; | |
4998 | } | |
4999 | ||
6e3d6dc1 NC |
5000 | static debug_info * |
5001 | find_debug_info_for_offset (unsigned long offset) | |
5002 | { | |
5003 | unsigned int i; | |
5004 | ||
5005 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
5006 | return NULL; | |
5007 | ||
5008 | for (i = 0; i < num_debug_info_entries; i++) | |
5009 | if (debug_information[i].cu_offset == offset) | |
5010 | return debug_information + i; | |
5011 | ||
5012 | return NULL; | |
5013 | } | |
5014 | ||
459d52c8 DE |
5015 | static const char * |
5016 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
5017 | { | |
5018 | /* See gdb/gdb-index.h. */ | |
5019 | static const char * const kinds[] = | |
5020 | { | |
5021 | N_ ("no info"), | |
5022 | N_ ("type"), | |
5023 | N_ ("variable"), | |
5024 | N_ ("function"), | |
5025 | N_ ("other"), | |
5026 | N_ ("unused5"), | |
5027 | N_ ("unused6"), | |
5028 | N_ ("unused7") | |
5029 | }; | |
5030 | ||
5031 | return _ (kinds[kind]); | |
5032 | } | |
5033 | ||
19e6b90e | 5034 | static int |
459d52c8 DE |
5035 | display_debug_pubnames_worker (struct dwarf_section *section, |
5036 | void *file ATTRIBUTE_UNUSED, | |
5037 | int is_gnu) | |
19e6b90e | 5038 | { |
91d6fa6a | 5039 | DWARF2_Internal_PubNames names; |
19e6b90e L |
5040 | unsigned char *start = section->start; |
5041 | unsigned char *end = start + section->size; | |
5042 | ||
6e3d6dc1 NC |
5043 | /* It does not matter if this load fails, |
5044 | we test for that later on. */ | |
5045 | load_debug_info (file); | |
5046 | ||
dda8d76d | 5047 | introduce (section, FALSE); |
19e6b90e L |
5048 | |
5049 | while (start < end) | |
5050 | { | |
5051 | unsigned char *data; | |
e98fdf1a | 5052 | unsigned long sec_off; |
bf5117e3 | 5053 | unsigned int offset_size, initial_length_size; |
19e6b90e | 5054 | |
e98fdf1a | 5055 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 5056 | if (names.pn_length == 0xffffffff) |
19e6b90e | 5057 | { |
e98fdf1a | 5058 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e L |
5059 | offset_size = 8; |
5060 | initial_length_size = 12; | |
5061 | } | |
5062 | else | |
5063 | { | |
5064 | offset_size = 4; | |
5065 | initial_length_size = 4; | |
5066 | } | |
5067 | ||
e98fdf1a AM |
5068 | sec_off = start - section->start; |
5069 | if (sec_off + names.pn_length < sec_off | |
5070 | || sec_off + names.pn_length > section->size) | |
5071 | { | |
5072 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
5073 | section->name, | |
5074 | sec_off - initial_length_size, | |
5075 | dwarf_vmatoa ("x", names.pn_length)); | |
5076 | break; | |
5077 | } | |
5078 | ||
5079 | data = start; | |
5080 | start += names.pn_length; | |
5081 | ||
0c588247 NC |
5082 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
5083 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
5084 | |
5085 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
5086 | && num_debug_info_entries > 0 | |
91d6fa6a | 5087 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 5088 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 5089 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 5090 | |
0c588247 | 5091 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 5092 | |
058037d3 NC |
5093 | printf (_(" Length: %ld\n"), |
5094 | (long) names.pn_length); | |
5095 | printf (_(" Version: %d\n"), | |
5096 | names.pn_version); | |
5097 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
5098 | (unsigned long) names.pn_offset); | |
5099 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
5100 | (long) names.pn_size); | |
19e6b90e | 5101 | |
91d6fa6a | 5102 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
5103 | { |
5104 | static int warned = 0; | |
5105 | ||
5106 | if (! warned) | |
5107 | { | |
5108 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
5109 | warned = 1; | |
5110 | } | |
5111 | ||
5112 | continue; | |
5113 | } | |
5114 | ||
459d52c8 DE |
5115 | if (is_gnu) |
5116 | printf (_("\n Offset Kind Name\n")); | |
5117 | else | |
5118 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 5119 | |
e98fdf1a | 5120 | while (1) |
19e6b90e | 5121 | { |
f41e4712 | 5122 | bfd_size_type maxprint; |
e98fdf1a | 5123 | dwarf_vma offset; |
f41e4712 | 5124 | |
0c588247 | 5125 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e | 5126 | |
e98fdf1a AM |
5127 | if (offset == 0) |
5128 | break; | |
b4eb7656 | 5129 | |
e98fdf1a AM |
5130 | data += offset_size; |
5131 | if (data >= end) | |
5132 | break; | |
5133 | maxprint = (end - data) - 1; | |
f41e4712 | 5134 | |
e98fdf1a AM |
5135 | if (is_gnu) |
5136 | { | |
5137 | unsigned int kind_data; | |
5138 | gdb_index_symbol_kind kind; | |
5139 | const char *kind_name; | |
5140 | int is_static; | |
5141 | ||
5142 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
5143 | data++; | |
5144 | maxprint --; | |
5145 | /* GCC computes the kind as the upper byte in the CU index | |
5146 | word, and then right shifts it by the CU index size. | |
5147 | Left shift KIND to where the gdb-index.h accessor macros | |
5148 | can use it. */ | |
5149 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
5150 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
5151 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
5152 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
5153 | printf (" %-6lx %s,%-10s %.*s\n", | |
5154 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
5155 | kind_name, (int) maxprint, data); | |
19e6b90e | 5156 | } |
e98fdf1a AM |
5157 | else |
5158 | printf (" %-6lx\t%.*s\n", | |
5159 | (unsigned long) offset, (int) maxprint, data); | |
5160 | ||
5161 | data += strnlen ((char *) data, maxprint) + 1; | |
5162 | if (data >= end) | |
5163 | break; | |
19e6b90e | 5164 | } |
19e6b90e L |
5165 | } |
5166 | ||
5167 | printf ("\n"); | |
5168 | return 1; | |
5169 | } | |
5170 | ||
459d52c8 DE |
5171 | static int |
5172 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
5173 | { | |
5174 | return display_debug_pubnames_worker (section, file, 0); | |
5175 | } | |
5176 | ||
5177 | static int | |
5178 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
5179 | { | |
5180 | return display_debug_pubnames_worker (section, file, 1); | |
5181 | } | |
5182 | ||
19e6b90e L |
5183 | static int |
5184 | display_debug_macinfo (struct dwarf_section *section, | |
5185 | void *file ATTRIBUTE_UNUSED) | |
5186 | { | |
5187 | unsigned char *start = section->start; | |
5188 | unsigned char *end = start + section->size; | |
5189 | unsigned char *curr = start; | |
19e6b90e L |
5190 | enum dwarf_macinfo_record_type op; |
5191 | ||
dda8d76d | 5192 | introduce (section, FALSE); |
19e6b90e L |
5193 | |
5194 | while (curr < end) | |
5195 | { | |
5196 | unsigned int lineno; | |
0c588247 | 5197 | const unsigned char *string; |
19e6b90e | 5198 | |
3f5e193b | 5199 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
5200 | curr++; |
5201 | ||
5202 | switch (op) | |
5203 | { | |
5204 | case DW_MACINFO_start_file: | |
5205 | { | |
5206 | unsigned int filenum; | |
5207 | ||
cd30bcef AM |
5208 | READ_ULEB (lineno, curr, end); |
5209 | READ_ULEB (filenum, curr, end); | |
19e6b90e L |
5210 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), |
5211 | lineno, filenum); | |
5212 | } | |
5213 | break; | |
5214 | ||
5215 | case DW_MACINFO_end_file: | |
5216 | printf (_(" DW_MACINFO_end_file\n")); | |
5217 | break; | |
5218 | ||
5219 | case DW_MACINFO_define: | |
cd30bcef | 5220 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5221 | string = curr; |
5222 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5223 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
5224 | lineno, string); | |
5225 | break; | |
5226 | ||
5227 | case DW_MACINFO_undef: | |
cd30bcef | 5228 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5229 | string = curr; |
5230 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5231 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
5232 | lineno, string); | |
5233 | break; | |
5234 | ||
5235 | case DW_MACINFO_vendor_ext: | |
5236 | { | |
5237 | unsigned int constant; | |
5238 | ||
cd30bcef | 5239 | READ_ULEB (constant, curr, end); |
0c588247 NC |
5240 | string = curr; |
5241 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5242 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
5243 | constant, string); | |
5244 | } | |
5245 | break; | |
5246 | } | |
5247 | } | |
5248 | ||
5249 | return 1; | |
5250 | } | |
5251 | ||
4ccf1e31 JJ |
5252 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5253 | filename and dirname corresponding to file name table entry with index | |
5254 | FILEIDX. Return NULL on failure. */ | |
5255 | ||
5256 | static unsigned char * | |
f6f0e17b NC |
5257 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5258 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5259 | unsigned char **dir_name) |
5260 | { | |
5261 | struct dwarf_section *section = &debug_displays [line].section; | |
5262 | unsigned char *hdrptr, *dirtable, *file_name; | |
5263 | unsigned int offset_size, initial_length_size; | |
cd30bcef | 5264 | unsigned int version, opcode_base; |
4ccf1e31 | 5265 | dwarf_vma length, diridx; |
f6f0e17b | 5266 | const unsigned char * end; |
4ccf1e31 JJ |
5267 | |
5268 | *dir_name = NULL; | |
5269 | if (section->start == NULL | |
5270 | || line_offset >= section->size | |
5271 | || fileidx == 0) | |
5272 | return NULL; | |
5273 | ||
5274 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5275 | end = section->start + section->size; |
0c588247 NC |
5276 | |
5277 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5278 | if (length == 0xffffffff) |
5279 | { | |
5280 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5281 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
5282 | offset_size = 8; |
5283 | initial_length_size = 12; | |
5284 | } | |
5285 | else | |
5286 | { | |
5287 | offset_size = 4; | |
5288 | initial_length_size = 4; | |
5289 | } | |
e98fdf1a AM |
5290 | if (length + initial_length_size < length |
5291 | || length + initial_length_size > section->size) | |
4ccf1e31 | 5292 | return NULL; |
0c588247 NC |
5293 | |
5294 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5295 | if (version != 2 && version != 3 && version != 4) |
5296 | return NULL; | |
5297 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5298 | if (version >= 4) | |
5299 | hdrptr++; /* Skip max_ops_per_insn. */ | |
5300 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
5301 | |
5302 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
5303 | if (opcode_base == 0) |
5304 | return NULL; | |
0c588247 | 5305 | |
4ccf1e31 | 5306 | hdrptr += opcode_base - 1; |
5c1c468d NC |
5307 | if (hdrptr >= end) |
5308 | return NULL; | |
5309 | ||
4ccf1e31 JJ |
5310 | dirtable = hdrptr; |
5311 | /* Skip over dirname table. */ | |
5312 | while (*hdrptr != '\0') | |
5c1c468d NC |
5313 | { |
5314 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; | |
5315 | if (hdrptr >= end) | |
5316 | return NULL; | |
5317 | } | |
4ccf1e31 | 5318 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 5319 | |
4ccf1e31 | 5320 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 5321 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 5322 | { |
0c588247 | 5323 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
cd30bcef AM |
5324 | SKIP_ULEB (hdrptr, end); |
5325 | SKIP_ULEB (hdrptr, end); | |
5326 | SKIP_ULEB (hdrptr, end); | |
4ccf1e31 | 5327 | } |
5c1c468d | 5328 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 5329 | return NULL; |
5c1c468d | 5330 | |
4ccf1e31 | 5331 | file_name = hdrptr; |
0c588247 | 5332 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
5c1c468d NC |
5333 | if (hdrptr >= end) |
5334 | return NULL; | |
cd30bcef | 5335 | READ_ULEB (diridx, hdrptr, end); |
4ccf1e31 JJ |
5336 | if (diridx == 0) |
5337 | return file_name; | |
5c1c468d | 5338 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
0c588247 | 5339 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
5c1c468d | 5340 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
5341 | return NULL; |
5342 | *dir_name = dirtable; | |
5343 | return file_name; | |
5344 | } | |
5345 | ||
5346 | static int | |
5347 | display_debug_macro (struct dwarf_section *section, | |
5348 | void *file) | |
5349 | { | |
5350 | unsigned char *start = section->start; | |
5351 | unsigned char *end = start + section->size; | |
5352 | unsigned char *curr = start; | |
5353 | unsigned char *extended_op_buf[256]; | |
4ccf1e31 | 5354 | |
dda8d76d NC |
5355 | load_debug_section_with_follow (str, file); |
5356 | load_debug_section_with_follow (line, file); | |
4ccf1e31 | 5357 | |
dda8d76d | 5358 | introduce (section, FALSE); |
4ccf1e31 JJ |
5359 | |
5360 | while (curr < end) | |
5361 | { | |
5362 | unsigned int lineno, version, flags; | |
5363 | unsigned int offset_size = 4; | |
0c588247 | 5364 | const unsigned char *string; |
4ccf1e31 JJ |
5365 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
5366 | unsigned char **extended_ops = NULL; | |
5367 | ||
0c588247 | 5368 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 5369 | if (version != 4 && version != 5) |
4ccf1e31 | 5370 | { |
7a7e1061 | 5371 | error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"), |
4ccf1e31 JJ |
5372 | section->name); |
5373 | return 0; | |
5374 | } | |
5375 | ||
0c588247 | 5376 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
4ccf1e31 JJ |
5377 | if (flags & 1) |
5378 | offset_size = 8; | |
5379 | printf (_(" Offset: 0x%lx\n"), | |
5380 | (unsigned long) sec_offset); | |
5381 | printf (_(" Version: %d\n"), version); | |
5382 | printf (_(" Offset size: %d\n"), offset_size); | |
5383 | if (flags & 2) | |
5384 | { | |
0c588247 | 5385 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
5386 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
5387 | (unsigned long) line_offset); | |
5388 | } | |
5389 | if (flags & 4) | |
5390 | { | |
0c588247 | 5391 | unsigned int i, count, op; |
4ccf1e31 | 5392 | dwarf_vma nargs, n; |
0c588247 NC |
5393 | |
5394 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 5395 | |
4ccf1e31 JJ |
5396 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
5397 | extended_ops = extended_op_buf; | |
5398 | if (count) | |
5399 | { | |
5400 | printf (_(" Extension opcode arguments:\n")); | |
5401 | for (i = 0; i < count; i++) | |
5402 | { | |
0c588247 | 5403 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 5404 | extended_ops[op] = curr; |
cd30bcef | 5405 | READ_ULEB (nargs, curr, end); |
4ccf1e31 | 5406 | if (nargs == 0) |
7a7e1061 | 5407 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
5408 | else |
5409 | { | |
7a7e1061 | 5410 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
5411 | for (n = 0; n < nargs; n++) |
5412 | { | |
0c588247 NC |
5413 | unsigned int form; |
5414 | ||
5415 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
5416 | printf ("%s%s", get_FORM_name (form), |
5417 | n == nargs - 1 ? "\n" : ", "); | |
5418 | switch (form) | |
5419 | { | |
5420 | case DW_FORM_data1: | |
5421 | case DW_FORM_data2: | |
5422 | case DW_FORM_data4: | |
5423 | case DW_FORM_data8: | |
5424 | case DW_FORM_sdata: | |
5425 | case DW_FORM_udata: | |
5426 | case DW_FORM_block: | |
5427 | case DW_FORM_block1: | |
5428 | case DW_FORM_block2: | |
5429 | case DW_FORM_block4: | |
5430 | case DW_FORM_flag: | |
5431 | case DW_FORM_string: | |
5432 | case DW_FORM_strp: | |
5433 | case DW_FORM_sec_offset: | |
5434 | break; | |
5435 | default: | |
5436 | error (_("Invalid extension opcode form %s\n"), | |
5437 | get_FORM_name (form)); | |
5438 | return 0; | |
5439 | } | |
5440 | } | |
5441 | } | |
5442 | } | |
5443 | } | |
5444 | } | |
5445 | printf ("\n"); | |
5446 | ||
5447 | while (1) | |
5448 | { | |
5449 | unsigned int op; | |
5450 | ||
5451 | if (curr >= end) | |
5452 | { | |
5453 | error (_(".debug_macro section not zero terminated\n")); | |
5454 | return 0; | |
5455 | } | |
5456 | ||
0c588247 | 5457 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
5458 | if (op == 0) |
5459 | break; | |
5460 | ||
5461 | switch (op) | |
5462 | { | |
7a7e1061 | 5463 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
5464 | { |
5465 | unsigned int filenum; | |
5466 | unsigned char *file_name = NULL, *dir_name = NULL; | |
5467 | ||
cd30bcef AM |
5468 | READ_ULEB (lineno, curr, end); |
5469 | READ_ULEB (filenum, curr, end); | |
4ccf1e31 JJ |
5470 | |
5471 | if ((flags & 2) == 0) | |
7a7e1061 | 5472 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
5473 | else |
5474 | file_name | |
5475 | = get_line_filename_and_dirname (line_offset, filenum, | |
5476 | &dir_name); | |
5477 | if (file_name == NULL) | |
7a7e1061 | 5478 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
5479 | lineno, filenum); |
5480 | else | |
7a7e1061 | 5481 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
5482 | lineno, filenum, |
5483 | dir_name != NULL ? (const char *) dir_name : "", | |
5484 | dir_name != NULL ? "/" : "", file_name); | |
5485 | } | |
5486 | break; | |
5487 | ||
7a7e1061 JK |
5488 | case DW_MACRO_end_file: |
5489 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
5490 | break; |
5491 | ||
7a7e1061 | 5492 | case DW_MACRO_define: |
cd30bcef | 5493 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5494 | string = curr; |
5495 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 5496 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5497 | lineno, string); |
5498 | break; | |
5499 | ||
7a7e1061 | 5500 | case DW_MACRO_undef: |
cd30bcef | 5501 | READ_ULEB (lineno, curr, end); |
0c588247 NC |
5502 | string = curr; |
5503 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 5504 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5505 | lineno, string); |
5506 | break; | |
5507 | ||
7a7e1061 | 5508 | case DW_MACRO_define_strp: |
cd30bcef | 5509 | READ_ULEB (lineno, curr, end); |
0c588247 | 5510 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5511 | string = fetch_indirect_string (offset); |
7a7e1061 | 5512 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5513 | lineno, string); |
5514 | break; | |
5515 | ||
7a7e1061 | 5516 | case DW_MACRO_undef_strp: |
cd30bcef | 5517 | READ_ULEB (lineno, curr, end); |
0c588247 | 5518 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5519 | string = fetch_indirect_string (offset); |
7a7e1061 | 5520 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5521 | lineno, string); |
5522 | break; | |
5523 | ||
7a7e1061 | 5524 | case DW_MACRO_import: |
0c588247 | 5525 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5526 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
5527 | (unsigned long) offset); |
5528 | break; | |
5529 | ||
7a7e1061 | 5530 | case DW_MACRO_define_sup: |
cd30bcef | 5531 | READ_ULEB (lineno, curr, end); |
0c588247 | 5532 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5533 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5534 | lineno, (unsigned long) offset); |
5535 | break; | |
5536 | ||
7a7e1061 | 5537 | case DW_MACRO_undef_sup: |
cd30bcef | 5538 | READ_ULEB (lineno, curr, end); |
0c588247 | 5539 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5540 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5541 | lineno, (unsigned long) offset); |
5542 | break; | |
5543 | ||
7a7e1061 | 5544 | case DW_MACRO_import_sup: |
0c588247 | 5545 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5546 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
5547 | (unsigned long) offset); |
5548 | break; | |
5549 | ||
4ccf1e31 JJ |
5550 | default: |
5551 | if (extended_ops == NULL || extended_ops[op] == NULL) | |
5552 | { | |
5553 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
5554 | return 0; | |
5555 | } | |
5556 | else | |
5557 | { | |
5558 | /* Skip over unhandled opcodes. */ | |
5559 | dwarf_vma nargs, n; | |
5560 | unsigned char *desc = extended_ops[op]; | |
cd30bcef | 5561 | READ_ULEB (nargs, desc, end); |
4ccf1e31 JJ |
5562 | if (nargs == 0) |
5563 | { | |
7a7e1061 | 5564 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
5565 | break; |
5566 | } | |
7a7e1061 | 5567 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
5568 | for (n = 0; n < nargs; n++) |
5569 | { | |
0c588247 NC |
5570 | int val; |
5571 | ||
77145576 | 5572 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 5573 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 5574 | curr |
77145576 | 5575 | = read_and_display_attr_value (0, val, 0, |
ec1b0fbb | 5576 | start, curr, end, 0, 0, offset_size, |
341f9135 | 5577 | version, NULL, 0, NULL, |
ec1b0fbb | 5578 | NULL, ' ', -1); |
4ccf1e31 JJ |
5579 | if (n != nargs - 1) |
5580 | printf (","); | |
5581 | } | |
5582 | printf ("\n"); | |
5583 | } | |
5584 | break; | |
5585 | } | |
5586 | } | |
5587 | ||
5588 | printf ("\n"); | |
b4eb7656 | 5589 | } |
4ccf1e31 JJ |
5590 | |
5591 | return 1; | |
5592 | } | |
5593 | ||
19e6b90e L |
5594 | static int |
5595 | display_debug_abbrev (struct dwarf_section *section, | |
5596 | void *file ATTRIBUTE_UNUSED) | |
5597 | { | |
5598 | abbrev_entry *entry; | |
5599 | unsigned char *start = section->start; | |
5600 | unsigned char *end = start + section->size; | |
5601 | ||
dda8d76d | 5602 | introduce (section, FALSE); |
19e6b90e L |
5603 | |
5604 | do | |
5605 | { | |
7282333f AM |
5606 | unsigned char *last; |
5607 | ||
19e6b90e L |
5608 | free_abbrevs (); |
5609 | ||
7282333f | 5610 | last = start; |
19e6b90e L |
5611 | start = process_abbrev_section (start, end); |
5612 | ||
5613 | if (first_abbrev == NULL) | |
5614 | continue; | |
5615 | ||
7282333f | 5616 | printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start)); |
19e6b90e L |
5617 | |
5618 | for (entry = first_abbrev; entry; entry = entry->next) | |
5619 | { | |
5620 | abbrev_attr *attr; | |
5621 | ||
cc5914eb | 5622 | printf (" %ld %s [%s]\n", |
19e6b90e L |
5623 | entry->entry, |
5624 | get_TAG_name (entry->tag), | |
5625 | entry->children ? _("has children") : _("no children")); | |
5626 | ||
5627 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
5628 | { |
5629 | printf (" %-18s %s", | |
5630 | get_AT_name (attr->attribute), | |
5631 | get_FORM_name (attr->form)); | |
5632 | if (attr->form == DW_FORM_implicit_const) | |
5633 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
5634 | putchar ('\n'); | |
5635 | } | |
19e6b90e L |
5636 | } |
5637 | } | |
5638 | while (start); | |
5639 | ||
5640 | printf ("\n"); | |
5641 | ||
5642 | return 1; | |
5643 | } | |
5644 | ||
42bcef4a AB |
5645 | /* Return true when ADDR is the maximum address, when addresses are |
5646 | POINTER_SIZE bytes long. */ | |
5647 | ||
5648 | static bfd_boolean | |
5649 | is_max_address (dwarf_vma addr, unsigned int pointer_size) | |
5650 | { | |
5651 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
5652 | return ((addr & mask) == mask); | |
5653 | } | |
5654 | ||
9f272209 AO |
5655 | /* Display a view pair list starting at *VSTART_PTR and ending at |
5656 | VLISTEND within SECTION. */ | |
5657 | ||
5658 | static void | |
5659 | display_view_pair_list (struct dwarf_section *section, | |
5660 | unsigned char **vstart_ptr, | |
5661 | unsigned int debug_info_entry, | |
5662 | unsigned char *vlistend) | |
5663 | { | |
5664 | unsigned char *vstart = *vstart_ptr; | |
5665 | unsigned char *section_end = section->start + section->size; | |
5666 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
5667 | ||
5668 | if (vlistend < section_end) | |
5669 | section_end = vlistend; | |
5670 | ||
5671 | putchar ('\n'); | |
5672 | ||
5673 | while (vstart < section_end) | |
5674 | { | |
5675 | dwarf_vma off = vstart - section->start; | |
5676 | dwarf_vma vbegin, vend; | |
5677 | ||
cd30bcef | 5678 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 | 5679 | if (vstart == section_end) |
cd30bcef | 5680 | break; |
9f272209 | 5681 | |
cd30bcef | 5682 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
5683 | printf (" %8.8lx ", (unsigned long) off); |
5684 | ||
5685 | print_dwarf_view (vbegin, pointer_size, 1); | |
5686 | print_dwarf_view (vend, pointer_size, 1); | |
5687 | printf (_("location view pair\n")); | |
5688 | } | |
5689 | ||
5690 | putchar ('\n'); | |
5691 | *vstart_ptr = vstart; | |
5692 | } | |
5693 | ||
4723351a CC |
5694 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
5695 | ||
5696 | static void | |
5697 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
5698 | unsigned char **start_ptr, |
5699 | unsigned int debug_info_entry, | |
359ca075 JK |
5700 | dwarf_vma offset, |
5701 | dwarf_vma base_address, | |
9f272209 | 5702 | unsigned char **vstart_ptr, |
b4eb7656 | 5703 | int has_frame_base) |
4723351a | 5704 | { |
9f272209 | 5705 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 5706 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
5707 | unsigned long cu_offset; |
5708 | unsigned int pointer_size; | |
5709 | unsigned int offset_size; | |
5710 | int dwarf_version; | |
4723351a CC |
5711 | |
5712 | dwarf_vma begin; | |
5713 | dwarf_vma end; | |
5714 | unsigned short length; | |
5715 | int need_frame_base; | |
5716 | ||
82b1b41b NC |
5717 | if (debug_info_entry >= num_debug_info_entries) |
5718 | { | |
5719 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
5720 | debug_info_entry); | |
5721 | return; | |
5722 | } | |
b4eb7656 | 5723 | |
82b1b41b NC |
5724 | cu_offset = debug_information [debug_info_entry].cu_offset; |
5725 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5726 | offset_size = debug_information [debug_info_entry].offset_size; | |
5727 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 5728 | |
f41e4712 NC |
5729 | if (pointer_size < 2 || pointer_size > 8) |
5730 | { | |
5731 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5732 | pointer_size, debug_info_entry); | |
5733 | return; | |
5734 | } | |
5735 | ||
4723351a CC |
5736 | while (1) |
5737 | { | |
359ca075 | 5738 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 5739 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 5740 | |
4723351a | 5741 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
5742 | { |
5743 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5744 | (unsigned long) offset); |
b4eb7656 AM |
5745 | break; |
5746 | } | |
4723351a | 5747 | |
359ca075 | 5748 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 5749 | |
0c588247 NC |
5750 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
5751 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 5752 | |
4723351a | 5753 | if (begin == 0 && end == 0) |
b4eb7656 | 5754 | { |
d1c4b12b NC |
5755 | /* PR 18374: In a object file we can have a location list that |
5756 | starts with a begin and end of 0 because there are relocations | |
5757 | that need to be applied to the addresses. Actually applying | |
5758 | the relocations now does not help as they will probably resolve | |
5759 | to 0, since the object file has not been fully linked. Real | |
5760 | end of list markers will not have any relocations against them. */ | |
5761 | if (! reloc_at (section, off) | |
5762 | && ! reloc_at (section, off + pointer_size)) | |
5763 | { | |
5764 | printf (_("<End of list>\n")); | |
5765 | break; | |
5766 | } | |
b4eb7656 | 5767 | } |
4723351a CC |
5768 | |
5769 | /* Check base address specifiers. */ | |
42bcef4a AB |
5770 | if (is_max_address (begin, pointer_size) |
5771 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
5772 | { |
5773 | base_address = end; | |
5774 | print_dwarf_vma (begin, pointer_size); | |
5775 | print_dwarf_vma (end, pointer_size); | |
5776 | printf (_("(base address)\n")); | |
5777 | continue; | |
5778 | } | |
4723351a | 5779 | |
9f272209 AO |
5780 | if (vstart) |
5781 | { | |
9f272209 AO |
5782 | off = offset + (vstart - *start_ptr); |
5783 | ||
cd30bcef | 5784 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
5785 | print_dwarf_view (vbegin, pointer_size, 1); |
5786 | ||
cd30bcef | 5787 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
5788 | print_dwarf_view (vend, pointer_size, 1); |
5789 | ||
5790 | printf (_("views at %8.8lx for:\n %*s "), | |
5791 | (unsigned long) off, 8, ""); | |
5792 | } | |
5793 | ||
4723351a | 5794 | if (start + 2 > section_end) |
b4eb7656 AM |
5795 | { |
5796 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5797 | (unsigned long) offset); |
b4eb7656 AM |
5798 | break; |
5799 | } | |
4723351a | 5800 | |
0c588247 | 5801 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
5802 | |
5803 | if (start + length > section_end) | |
b4eb7656 AM |
5804 | { |
5805 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5806 | (unsigned long) offset); |
b4eb7656 AM |
5807 | break; |
5808 | } | |
4723351a CC |
5809 | |
5810 | print_dwarf_vma (begin + base_address, pointer_size); | |
5811 | print_dwarf_vma (end + base_address, pointer_size); | |
5812 | ||
5813 | putchar ('('); | |
5814 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
5815 | pointer_size, |
5816 | offset_size, | |
5817 | dwarf_version, | |
5818 | length, | |
5819 | cu_offset, section); | |
4723351a CC |
5820 | putchar (')'); |
5821 | ||
5822 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 5823 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 5824 | |
9f272209 | 5825 | if (begin == end && vbegin == vend) |
b4eb7656 | 5826 | fputs (_(" (start == end)"), stdout); |
9f272209 | 5827 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 5828 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
5829 | |
5830 | putchar ('\n'); | |
5831 | ||
5832 | start += length; | |
5833 | } | |
5834 | ||
5835 | *start_ptr = start; | |
9f272209 | 5836 | *vstart_ptr = vstart; |
4723351a CC |
5837 | } |
5838 | ||
77145576 JK |
5839 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
5840 | ||
5841 | static void | |
5842 | display_loclists_list (struct dwarf_section *section, | |
5843 | unsigned char **start_ptr, | |
5844 | unsigned int debug_info_entry, | |
5845 | dwarf_vma offset, | |
5846 | dwarf_vma base_address, | |
9f272209 | 5847 | unsigned char **vstart_ptr, |
77145576 JK |
5848 | int has_frame_base) |
5849 | { | |
9f272209 | 5850 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
5851 | unsigned char *section_end = section->start + section->size; |
5852 | unsigned long cu_offset; | |
5853 | unsigned int pointer_size; | |
5854 | unsigned int offset_size; | |
5855 | int dwarf_version; | |
77145576 | 5856 | |
9dfd0db9 | 5857 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
5858 | dwarf_vma begin = -1, vbegin = -1; |
5859 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
5860 | dwarf_vma length; |
5861 | int need_frame_base; | |
5862 | ||
5863 | if (debug_info_entry >= num_debug_info_entries) | |
5864 | { | |
5865 | warn (_("No debug information available for " | |
5866 | "loclists lists of entry: %u\n"), | |
5867 | debug_info_entry); | |
5868 | return; | |
5869 | } | |
5870 | ||
5871 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
5872 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5873 | offset_size = debug_information [debug_info_entry].offset_size; | |
5874 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
5875 | ||
5876 | if (pointer_size < 2 || pointer_size > 8) | |
5877 | { | |
5878 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5879 | pointer_size, debug_info_entry); | |
5880 | return; | |
5881 | } | |
5882 | ||
5883 | while (1) | |
5884 | { | |
5885 | dwarf_vma off = offset + (start - *start_ptr); | |
5886 | enum dwarf_location_list_entry_type llet; | |
5887 | ||
5888 | if (start + 1 > section_end) | |
5889 | { | |
5890 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
5891 | (unsigned long) offset); | |
5892 | break; | |
5893 | } | |
5894 | ||
5895 | printf (" %8.8lx ", (unsigned long) off); | |
5896 | ||
5897 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
5898 | ||
9f272209 AO |
5899 | if (vstart && llet == DW_LLE_offset_pair) |
5900 | { | |
5901 | off = offset + (vstart - *start_ptr); | |
5902 | ||
cd30bcef | 5903 | READ_ULEB (vbegin, vstart, section_end); |
9f272209 AO |
5904 | print_dwarf_view (vbegin, pointer_size, 1); |
5905 | ||
cd30bcef | 5906 | READ_ULEB (vend, vstart, section_end); |
9f272209 AO |
5907 | print_dwarf_view (vend, pointer_size, 1); |
5908 | ||
5909 | printf (_("views at %8.8lx for:\n %*s "), | |
5910 | (unsigned long) off, 8, ""); | |
5911 | } | |
5912 | ||
77145576 JK |
5913 | switch (llet) |
5914 | { | |
5915 | case DW_LLE_end_of_list: | |
5916 | printf (_("<End of list>\n")); | |
5917 | break; | |
5918 | case DW_LLE_offset_pair: | |
cd30bcef AM |
5919 | READ_ULEB (begin, start, section_end); |
5920 | READ_ULEB (end, start, section_end); | |
77145576 JK |
5921 | break; |
5922 | case DW_LLE_base_address: | |
5923 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
5924 | section_end); | |
5925 | print_dwarf_vma (base_address, pointer_size); | |
5926 | printf (_("(base address)\n")); | |
5927 | break; | |
9f272209 AO |
5928 | #ifdef DW_LLE_view_pair |
5929 | case DW_LLE_view_pair: | |
5930 | if (vstart) | |
5931 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
cd30bcef | 5932 | READ_ULEB (vbegin, start, section_end); |
9f272209 AO |
5933 | print_dwarf_view (vbegin, pointer_size, 1); |
5934 | ||
cd30bcef | 5935 | READ_ULEB (vend, start, section_end); |
9f272209 AO |
5936 | print_dwarf_view (vend, pointer_size, 1); |
5937 | ||
5938 | printf (_("views for:\n")); | |
5939 | continue; | |
5940 | #endif | |
77145576 JK |
5941 | default: |
5942 | error (_("Invalid location list entry type %d\n"), llet); | |
5943 | return; | |
5944 | } | |
5945 | if (llet == DW_LLE_end_of_list) | |
5946 | break; | |
5947 | if (llet != DW_LLE_offset_pair) | |
5948 | continue; | |
5949 | ||
5950 | if (start + 2 > section_end) | |
5951 | { | |
5952 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
5953 | (unsigned long) offset); | |
5954 | break; | |
5955 | } | |
5956 | ||
cd30bcef | 5957 | READ_ULEB (length, start, section_end); |
77145576 JK |
5958 | |
5959 | print_dwarf_vma (begin + base_address, pointer_size); | |
5960 | print_dwarf_vma (end + base_address, pointer_size); | |
5961 | ||
5962 | putchar ('('); | |
5963 | need_frame_base = decode_location_expression (start, | |
5964 | pointer_size, | |
5965 | offset_size, | |
5966 | dwarf_version, | |
5967 | length, | |
5968 | cu_offset, section); | |
5969 | putchar (')'); | |
5970 | ||
5971 | if (need_frame_base && !has_frame_base) | |
5972 | printf (_(" [without DW_AT_frame_base]")); | |
5973 | ||
9f272209 | 5974 | if (begin == end && vbegin == vend) |
77145576 | 5975 | fputs (_(" (start == end)"), stdout); |
9f272209 | 5976 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
5977 | fputs (_(" (start > end)"), stdout); |
5978 | ||
5979 | putchar ('\n'); | |
5980 | ||
5981 | start += length; | |
9f272209 | 5982 | vbegin = vend = -1; |
77145576 JK |
5983 | } |
5984 | ||
9f272209 AO |
5985 | if (vbegin != vm1 || vend != vm1) |
5986 | printf (_("Trailing view pair not used in a range")); | |
5987 | ||
77145576 | 5988 | *start_ptr = start; |
9f272209 | 5989 | *vstart_ptr = vstart; |
77145576 JK |
5990 | } |
5991 | ||
fab128ef CC |
5992 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
5993 | right-adjusted in a field of length LEN, and followed by a space. */ | |
5994 | ||
5995 | static void | |
5996 | print_addr_index (unsigned int idx, unsigned int len) | |
5997 | { | |
5998 | static char buf[15]; | |
5999 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 6000 | printf ("%*s ", len, buf); |
fab128ef CC |
6001 | } |
6002 | ||
4723351a CC |
6003 | /* Display a location list from a .dwo section. It uses address indexes rather |
6004 | than embedded addresses. This code closely follows display_loc_list, but the | |
6005 | two are sufficiently different that combining things is very ugly. */ | |
6006 | ||
6007 | static void | |
6008 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
6009 | unsigned char **start_ptr, |
6010 | unsigned int debug_info_entry, | |
359ca075 | 6011 | dwarf_vma offset, |
9f272209 | 6012 | unsigned char **vstart_ptr, |
b4eb7656 | 6013 | int has_frame_base) |
4723351a | 6014 | { |
9f272209 | 6015 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6016 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6017 | unsigned long cu_offset; |
6018 | unsigned int pointer_size; | |
6019 | unsigned int offset_size; | |
6020 | int dwarf_version; | |
4723351a CC |
6021 | int entry_type; |
6022 | unsigned short length; | |
6023 | int need_frame_base; | |
fab128ef | 6024 | unsigned int idx; |
4723351a | 6025 | |
82b1b41b NC |
6026 | if (debug_info_entry >= num_debug_info_entries) |
6027 | { | |
6028 | warn (_("No debug information for loc lists of entry: %u\n"), | |
6029 | debug_info_entry); | |
6030 | return; | |
6031 | } | |
6032 | ||
6033 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6034 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6035 | offset_size = debug_information [debug_info_entry].offset_size; | |
6036 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6037 | ||
f41e4712 NC |
6038 | if (pointer_size < 2 || pointer_size > 8) |
6039 | { | |
6040 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6041 | pointer_size, debug_info_entry); | |
6042 | return; | |
6043 | } | |
6044 | ||
4723351a CC |
6045 | while (1) |
6046 | { | |
359ca075 | 6047 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 6048 | |
fab128ef | 6049 | if (start >= section_end) |
b4eb7656 AM |
6050 | { |
6051 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6052 | (unsigned long) offset); |
b4eb7656 AM |
6053 | break; |
6054 | } | |
4723351a | 6055 | |
0c588247 | 6056 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
6057 | |
6058 | if (vstart) | |
6059 | switch (entry_type) | |
6060 | { | |
6061 | default: | |
6062 | break; | |
6063 | ||
6064 | case 2: | |
6065 | case 3: | |
6066 | case 4: | |
6067 | { | |
6068 | dwarf_vma view; | |
6069 | dwarf_vma off = offset + (vstart - *start_ptr); | |
6070 | ||
cd30bcef | 6071 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6072 | print_dwarf_view (view, 8, 1); |
6073 | ||
cd30bcef | 6074 | READ_ULEB (view, vstart, section_end); |
9f272209 AO |
6075 | print_dwarf_view (view, 8, 1); |
6076 | ||
6077 | printf (_("views at %8.8lx for:\n %*s "), | |
6078 | (unsigned long) off, 8, ""); | |
6079 | ||
6080 | } | |
6081 | break; | |
6082 | } | |
6083 | ||
4723351a | 6084 | switch (entry_type) |
b4eb7656 AM |
6085 | { |
6086 | case 0: /* A terminating entry. */ | |
6087 | *start_ptr = start; | |
9f272209 | 6088 | *vstart_ptr = vstart; |
b4eb7656 AM |
6089 | printf (_("<End of list>\n")); |
6090 | return; | |
6091 | case 1: /* A base-address entry. */ | |
cd30bcef | 6092 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6093 | print_addr_index (idx, 8); |
9f272209 | 6094 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
6095 | printf (_("(base address selection entry)\n")); |
6096 | continue; | |
6097 | case 2: /* A start/end entry. */ | |
cd30bcef | 6098 | READ_ULEB (idx, start, section_end); |
b4eb7656 | 6099 | print_addr_index (idx, 8); |
cd30bcef | 6100 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6101 | print_addr_index (idx, 8); |
6102 | break; | |
6103 | case 3: /* A start/length entry. */ | |
cd30bcef | 6104 | READ_ULEB (idx, start, section_end); |
b4eb7656 AM |
6105 | print_addr_index (idx, 8); |
6106 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6107 | printf ("%08x ", idx); | |
6108 | break; | |
6109 | case 4: /* An offset pair entry. */ | |
6110 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6111 | printf ("%08x ", idx); | |
6112 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6113 | printf ("%08x ", idx); | |
6114 | break; | |
6115 | default: | |
6116 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
6117 | *start_ptr = start; | |
9f272209 | 6118 | *vstart_ptr = vstart; |
b4eb7656 AM |
6119 | return; |
6120 | } | |
4723351a CC |
6121 | |
6122 | if (start + 2 > section_end) | |
b4eb7656 AM |
6123 | { |
6124 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6125 | (unsigned long) offset); |
b4eb7656 AM |
6126 | break; |
6127 | } | |
4723351a | 6128 | |
0c588247 | 6129 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6130 | if (start + length > section_end) |
b4eb7656 AM |
6131 | { |
6132 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6133 | (unsigned long) offset); |
b4eb7656 AM |
6134 | break; |
6135 | } | |
4723351a CC |
6136 | |
6137 | putchar ('('); | |
6138 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6139 | pointer_size, |
6140 | offset_size, | |
6141 | dwarf_version, | |
6142 | length, | |
6143 | cu_offset, section); | |
4723351a CC |
6144 | putchar (')'); |
6145 | ||
6146 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6147 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
6148 | |
6149 | putchar ('\n'); | |
6150 | ||
6151 | start += length; | |
6152 | } | |
6153 | ||
6154 | *start_ptr = start; | |
9f272209 | 6155 | *vstart_ptr = vstart; |
4723351a CC |
6156 | } |
6157 | ||
9f272209 AO |
6158 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
6159 | loc_views. */ | |
51d0d03f | 6160 | |
9f272209 | 6161 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
6162 | |
6163 | static int | |
6164 | loc_offsets_compar (const void *ap, const void *bp) | |
6165 | { | |
6166 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
6167 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
6168 | ||
9f272209 AO |
6169 | int ret = (a > b) - (b > a); |
6170 | if (ret) | |
6171 | return ret; | |
6172 | ||
6173 | a = loc_views[*(const unsigned int *) ap]; | |
6174 | b = loc_views[*(const unsigned int *) bp]; | |
6175 | ||
6176 | ret = (a > b) - (b > a); | |
6177 | ||
6178 | return ret; | |
51d0d03f JJ |
6179 | } |
6180 | ||
19e6b90e L |
6181 | static int |
6182 | display_debug_loc (struct dwarf_section *section, void *file) | |
6183 | { | |
9f272209 | 6184 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
6185 | unsigned long bytes; |
6186 | unsigned char *section_begin = start; | |
6187 | unsigned int num_loc_list = 0; | |
6188 | unsigned long last_offset = 0; | |
9f272209 | 6189 | unsigned long last_view = 0; |
19e6b90e L |
6190 | unsigned int first = 0; |
6191 | unsigned int i; | |
6192 | unsigned int j; | |
6193 | int seen_first_offset = 0; | |
51d0d03f | 6194 | int locs_sorted = 1; |
9f272209 | 6195 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6196 | unsigned int *array = NULL; |
4723351a | 6197 | const char *suffix = strrchr (section->name, '.'); |
24841daa | 6198 | bfd_boolean is_dwo = FALSE; |
77145576 JK |
6199 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6200 | dwarf_vma expected_start = 0; | |
4723351a CC |
6201 | |
6202 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
24841daa | 6203 | is_dwo = TRUE; |
19e6b90e L |
6204 | |
6205 | bytes = section->size; | |
19e6b90e L |
6206 | |
6207 | if (bytes == 0) | |
6208 | { | |
6209 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6210 | return 0; | |
6211 | } | |
6212 | ||
77145576 JK |
6213 | if (is_loclists) |
6214 | { | |
6215 | unsigned char *hdrptr = section_begin; | |
6216 | dwarf_vma ll_length; | |
6217 | unsigned short ll_version; | |
6218 | unsigned char *end = section_begin + section->size; | |
6219 | unsigned char address_size, segment_selector_size; | |
6220 | uint32_t offset_entry_count; | |
6221 | ||
6222 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6223 | if (ll_length == 0xffffffff) | |
6224 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6225 | ||
6226 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6227 | if (ll_version != 5) | |
6228 | { | |
6229 | warn (_("The %s section contains corrupt or " | |
6230 | "unsupported version number: %d.\n"), | |
6231 | section->name, ll_version); | |
6232 | return 0; | |
6233 | } | |
6234 | ||
6235 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6236 | ||
6237 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6238 | if (segment_selector_size != 0) | |
6239 | { | |
6240 | warn (_("The %s section contains " | |
6241 | "unsupported segment selector size: %d.\n"), | |
6242 | section->name, segment_selector_size); | |
6243 | return 0; | |
6244 | } | |
6245 | ||
6246 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
6247 | if (offset_entry_count != 0) | |
6248 | { | |
6249 | warn (_("The %s section contains " | |
6250 | "unsupported offset entry count: %d.\n"), | |
6251 | section->name, offset_entry_count); | |
6252 | return 0; | |
6253 | } | |
6254 | ||
6255 | expected_start = hdrptr - section_begin; | |
6256 | } | |
6257 | ||
1febe64d NC |
6258 | if (load_debug_info (file) == 0) |
6259 | { | |
6260 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6261 | section->name); | |
6262 | return 0; | |
6263 | } | |
19e6b90e L |
6264 | |
6265 | /* Check the order of location list in .debug_info section. If | |
6266 | offsets of location lists are in the ascending order, we can | |
6267 | use `debug_information' directly. */ | |
6268 | for (i = 0; i < num_debug_info_entries; i++) | |
6269 | { | |
6270 | unsigned int num; | |
6271 | ||
6272 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
6273 | if (num > num_loc_list) |
6274 | num_loc_list = num; | |
19e6b90e L |
6275 | |
6276 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 6277 | if (locs_sorted && num != 0) |
19e6b90e L |
6278 | { |
6279 | if (!seen_first_offset) | |
6280 | { | |
6281 | /* This is the first location list. */ | |
6282 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 6283 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
6284 | first = i; |
6285 | seen_first_offset = 1; | |
6286 | j = 1; | |
6287 | } | |
6288 | else | |
6289 | j = 0; | |
6290 | ||
6291 | for (; j < num; j++) | |
6292 | { | |
6293 | if (last_offset > | |
9f272209 AO |
6294 | debug_information [i].loc_offsets [j] |
6295 | || (last_offset == debug_information [i].loc_offsets [j] | |
6296 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 6297 | { |
51d0d03f | 6298 | locs_sorted = 0; |
19e6b90e L |
6299 | break; |
6300 | } | |
6301 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 6302 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
6303 | } |
6304 | } | |
6305 | } | |
6306 | ||
19e6b90e L |
6307 | if (!seen_first_offset) |
6308 | error (_("No location lists in .debug_info section!\n")); | |
6309 | ||
d4bfc77b | 6310 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
6311 | && debug_information [first].loc_offsets [0] != expected_start |
6312 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
6313 | warn (_("Location lists in %s section start at 0x%s\n"), |
6314 | section->name, | |
6315 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 6316 | |
51d0d03f JJ |
6317 | if (!locs_sorted) |
6318 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d NC |
6319 | |
6320 | introduce (section, FALSE); | |
6321 | ||
d1c4b12b NC |
6322 | if (reloc_at (section, 0)) |
6323 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 6324 | |
d1c4b12b | 6325 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
6326 | |
6327 | seen_first_offset = 0; | |
6328 | for (i = first; i < num_debug_info_entries; i++) | |
6329 | { | |
9f272209 | 6330 | dwarf_vma offset, voffset; |
359ca075 | 6331 | dwarf_vma base_address; |
d1c4b12b | 6332 | unsigned int k; |
19e6b90e L |
6333 | int has_frame_base; |
6334 | ||
51d0d03f JJ |
6335 | if (!locs_sorted) |
6336 | { | |
6337 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
6338 | array[k] = k; | |
6339 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 6340 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
6341 | qsort (array, debug_information [i].num_loc_offsets, |
6342 | sizeof (*array), loc_offsets_compar); | |
6343 | } | |
19e6b90e | 6344 | |
9f272209 | 6345 | int adjacent_view_loclists = 1; |
51d0d03f | 6346 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 6347 | { |
51d0d03f JJ |
6348 | j = locs_sorted ? k : array[k]; |
6349 | if (k | |
9f272209 | 6350 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 6351 | ? k - 1 : array [k - 1]] |
9f272209 AO |
6352 | == debug_information [i].loc_offsets [j]) |
6353 | && (debug_information [i].loc_views [locs_sorted | |
6354 | ? k - 1 : array [k - 1]] | |
6355 | == debug_information [i].loc_views [j])) | |
51d0d03f | 6356 | continue; |
19e6b90e | 6357 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 6358 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 6359 | next = section_begin + offset; |
9f272209 AO |
6360 | voffset = debug_information [i].loc_views [j]; |
6361 | if (voffset != vm1) | |
6362 | vnext = section_begin + voffset; | |
6363 | else | |
6364 | vnext = NULL; | |
19e6b90e L |
6365 | base_address = debug_information [i].base_address; |
6366 | ||
9f272209 AO |
6367 | if (vnext && vnext < next) |
6368 | { | |
6369 | vstart = vnext; | |
6370 | display_view_pair_list (section, &vstart, i, next); | |
6371 | if (start == vnext) | |
6372 | start = vstart; | |
6373 | } | |
6374 | ||
6375 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
6376 | seen_first_offset = 1; |
6377 | else | |
6378 | { | |
6379 | if (start < next) | |
6380 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6381 | (unsigned long) (start - section_begin), |
c8071705 | 6382 | (unsigned long) offset); |
19e6b90e L |
6383 | else if (start > next) |
6384 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6385 | (unsigned long) (start - section_begin), |
c8071705 | 6386 | (unsigned long) offset); |
19e6b90e L |
6387 | } |
6388 | start = next; | |
9f272209 | 6389 | vstart = vnext; |
19e6b90e L |
6390 | |
6391 | if (offset >= bytes) | |
6392 | { | |
6393 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 6394 | (unsigned long) offset); |
19e6b90e L |
6395 | continue; |
6396 | } | |
6397 | ||
9f272209 AO |
6398 | if (vnext && voffset >= bytes) |
6399 | { | |
6400 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
6401 | (unsigned long) voffset); | |
6402 | continue; | |
6403 | } | |
6404 | ||
77145576 JK |
6405 | if (!is_loclists) |
6406 | { | |
6407 | if (is_dwo) | |
6408 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 6409 | &vstart, has_frame_base); |
77145576 JK |
6410 | else |
6411 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 6412 | &vstart, has_frame_base); |
77145576 | 6413 | } |
b4eb7656 | 6414 | else |
77145576 JK |
6415 | { |
6416 | if (is_dwo) | |
6417 | warn (_("DWO is not yet supported.\n")); | |
6418 | else | |
6419 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
6420 | &vstart, has_frame_base); |
6421 | } | |
6422 | ||
6423 | /* FIXME: this arrangement is quite simplistic. Nothing | |
6424 | requires locview lists to be adjacent to corresponding | |
6425 | loclists, and a single loclist could be augmented by | |
6426 | different locview lists, and vice-versa, unlikely as it | |
6427 | is that it would make sense to do so. Hopefully we'll | |
6428 | have view pair support built into loclists before we ever | |
6429 | need to address all these possibilities. */ | |
6430 | if (adjacent_view_loclists && vnext | |
6431 | && vnext != start && vstart != next) | |
6432 | { | |
6433 | adjacent_view_loclists = 0; | |
6434 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 6435 | } |
9f272209 AO |
6436 | |
6437 | if (vnext && vnext == start) | |
6438 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
6439 | } |
6440 | } | |
031cd65f | 6441 | |
4723351a | 6442 | if (start < section->start + section->size) |
d3a49aa8 AM |
6443 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
6444 | "There are %ld unused bytes at the end of section %s\n", | |
6445 | (long) (section->start + section->size - start)), | |
4723351a | 6446 | (long) (section->start + section->size - start), section->name); |
98fb390a | 6447 | putchar ('\n'); |
51d0d03f | 6448 | free (array); |
19e6b90e L |
6449 | return 1; |
6450 | } | |
6451 | ||
6452 | static int | |
6453 | display_debug_str (struct dwarf_section *section, | |
6454 | void *file ATTRIBUTE_UNUSED) | |
6455 | { | |
6456 | unsigned char *start = section->start; | |
6457 | unsigned long bytes = section->size; | |
6458 | dwarf_vma addr = section->address; | |
6459 | ||
6460 | if (bytes == 0) | |
6461 | { | |
6462 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6463 | return 0; | |
6464 | } | |
6465 | ||
dda8d76d | 6466 | introduce (section, FALSE); |
19e6b90e L |
6467 | |
6468 | while (bytes) | |
6469 | { | |
6470 | int j; | |
6471 | int k; | |
6472 | int lbytes; | |
6473 | ||
6474 | lbytes = (bytes > 16 ? 16 : bytes); | |
6475 | ||
6476 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
6477 | ||
6478 | for (j = 0; j < 16; j++) | |
6479 | { | |
6480 | if (j < lbytes) | |
6481 | printf ("%2.2x", start[j]); | |
6482 | else | |
6483 | printf (" "); | |
6484 | ||
6485 | if ((j & 3) == 3) | |
6486 | printf (" "); | |
6487 | } | |
6488 | ||
6489 | for (j = 0; j < lbytes; j++) | |
6490 | { | |
6491 | k = start[j]; | |
6492 | if (k >= ' ' && k < 0x80) | |
6493 | printf ("%c", k); | |
6494 | else | |
6495 | printf ("."); | |
6496 | } | |
6497 | ||
6498 | putchar ('\n'); | |
6499 | ||
6500 | start += lbytes; | |
6501 | addr += lbytes; | |
6502 | bytes -= lbytes; | |
6503 | } | |
6504 | ||
6505 | putchar ('\n'); | |
6506 | ||
6507 | return 1; | |
6508 | } | |
6509 | ||
19e6b90e L |
6510 | static int |
6511 | display_debug_info (struct dwarf_section *section, void *file) | |
6512 | { | |
d85bf2ba | 6513 | return process_debug_info (section, file, section->abbrev_sec, FALSE, FALSE); |
19e6b90e L |
6514 | } |
6515 | ||
2b6f5997 CC |
6516 | static int |
6517 | display_debug_types (struct dwarf_section *section, void *file) | |
6518 | { | |
d85bf2ba | 6519 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
6f875884 TG |
6520 | } |
6521 | ||
6522 | static int | |
6523 | display_trace_info (struct dwarf_section *section, void *file) | |
6524 | { | |
d85bf2ba | 6525 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
2b6f5997 | 6526 | } |
19e6b90e L |
6527 | |
6528 | static int | |
6529 | display_debug_aranges (struct dwarf_section *section, | |
6530 | void *file ATTRIBUTE_UNUSED) | |
6531 | { | |
6532 | unsigned char *start = section->start; | |
6533 | unsigned char *end = start + section->size; | |
6534 | ||
dda8d76d | 6535 | introduce (section, FALSE); |
19e6b90e | 6536 | |
6e3d6dc1 NC |
6537 | /* It does not matter if this load fails, |
6538 | we test for that later on. */ | |
6539 | load_debug_info (file); | |
6540 | ||
19e6b90e L |
6541 | while (start < end) |
6542 | { | |
6543 | unsigned char *hdrptr; | |
6544 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 6545 | unsigned char *addr_ranges; |
2d9472a2 NC |
6546 | dwarf_vma length; |
6547 | dwarf_vma address; | |
e98fdf1a | 6548 | unsigned long sec_off; |
53b8873b | 6549 | unsigned char address_size; |
19e6b90e | 6550 | int excess; |
bf5117e3 NC |
6551 | unsigned int offset_size; |
6552 | unsigned int initial_length_size; | |
19e6b90e L |
6553 | |
6554 | hdrptr = start; | |
6555 | ||
0c588247 | 6556 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
6557 | if (arange.ar_length == 0xffffffff) |
6558 | { | |
0c588247 | 6559 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
6560 | offset_size = 8; |
6561 | initial_length_size = 12; | |
6562 | } | |
6563 | else | |
6564 | { | |
6565 | offset_size = 4; | |
6566 | initial_length_size = 4; | |
6567 | } | |
6568 | ||
e98fdf1a AM |
6569 | sec_off = hdrptr - section->start; |
6570 | if (sec_off + arange.ar_length < sec_off | |
6571 | || sec_off + arange.ar_length > section->size) | |
6572 | { | |
6573 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
6574 | section->name, | |
6575 | sec_off - initial_length_size, | |
6576 | dwarf_vmatoa ("x", arange.ar_length)); | |
6577 | break; | |
6578 | } | |
6579 | ||
0c588247 NC |
6580 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
6581 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 6582 | |
6e3d6dc1 NC |
6583 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
6584 | && num_debug_info_entries > 0 | |
6585 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
6586 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 6587 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 6588 | |
0c588247 NC |
6589 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
6590 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
6591 | |
6592 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
6593 | { | |
67f101ee NC |
6594 | /* PR 19872: A version number of 0 probably means that there is |
6595 | padding at the end of the .debug_aranges section. Gold puts | |
6596 | it there when performing an incremental link, for example. | |
6597 | So do not generate a warning in this case. */ | |
6598 | if (arange.ar_version) | |
6599 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
6600 | break; |
6601 | } | |
6602 | ||
47704ddf KT |
6603 | printf (_(" Length: %ld\n"), |
6604 | (long) arange.ar_length); | |
19e6b90e | 6605 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
6606 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
6607 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
6608 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
6609 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
6610 | ||
53b8873b NC |
6611 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
6612 | ||
f41e4712 NC |
6613 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
6614 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
6615 | { |
6616 | error (_("Invalid address size in %s section!\n"), | |
6617 | section->name); | |
6618 | break; | |
6619 | } | |
6620 | ||
53b8873b NC |
6621 | /* The DWARF spec does not require that the address size be a power |
6622 | of two, but we do. This will have to change if we ever encounter | |
6623 | an uneven architecture. */ | |
6624 | if ((address_size & (address_size - 1)) != 0) | |
6625 | { | |
6626 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
6627 | break; | |
6628 | } | |
cecf136e | 6629 | |
209c9a13 NC |
6630 | if (address_size > 4) |
6631 | printf (_("\n Address Length\n")); | |
6632 | else | |
6633 | printf (_("\n Address Length\n")); | |
19e6b90e | 6634 | |
91d6fa6a | 6635 | addr_ranges = hdrptr; |
19e6b90e | 6636 | |
53b8873b NC |
6637 | /* Must pad to an alignment boundary that is twice the address size. */ |
6638 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 6639 | if (excess) |
91d6fa6a | 6640 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 6641 | |
e98fdf1a | 6642 | start += arange.ar_length + initial_length_size; |
1617e571 | 6643 | |
91d6fa6a | 6644 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 6645 | { |
0c588247 NC |
6646 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
6647 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 6648 | |
80c35038 | 6649 | printf (" "); |
2d9472a2 NC |
6650 | print_dwarf_vma (address, address_size); |
6651 | print_dwarf_vma (length, address_size); | |
6652 | putchar ('\n'); | |
19e6b90e | 6653 | } |
19e6b90e L |
6654 | } |
6655 | ||
6656 | printf ("\n"); | |
6657 | ||
6658 | return 1; | |
6659 | } | |
6660 | ||
4723351a CC |
6661 | /* Comparison function for qsort. */ |
6662 | static int | |
6663 | comp_addr_base (const void * v0, const void * v1) | |
6664 | { | |
d367307b AM |
6665 | debug_info *info0 = *(debug_info **) v0; |
6666 | debug_info *info1 = *(debug_info **) v1; | |
4723351a CC |
6667 | return info0->addr_base - info1->addr_base; |
6668 | } | |
6669 | ||
6670 | /* Display the debug_addr section. */ | |
6671 | static int | |
6672 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 6673 | void *file) |
4723351a CC |
6674 | { |
6675 | debug_info **debug_addr_info; | |
6676 | unsigned char *entry; | |
6677 | unsigned char *end; | |
6678 | unsigned int i; | |
6679 | unsigned int count; | |
6680 | ||
6681 | if (section->size == 0) | |
6682 | { | |
6683 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6684 | return 0; | |
6685 | } | |
6686 | ||
6687 | if (load_debug_info (file) == 0) | |
6688 | { | |
6689 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6690 | section->name); | |
6691 | return 0; | |
6692 | } | |
6693 | ||
dda8d76d | 6694 | introduce (section, FALSE); |
4723351a | 6695 | |
1306a742 NC |
6696 | /* PR 17531: file: cf38d01b. |
6697 | We use xcalloc because a corrupt file may not have initialised all of the | |
6698 | fields in the debug_info structure, which means that the sort below might | |
6699 | try to move uninitialised data. */ | |
6700 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 6701 | sizeof (debug_info *)); |
4723351a CC |
6702 | |
6703 | count = 0; | |
6704 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 6705 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
6706 | { |
6707 | /* PR 17531: file: cf38d01b. */ | |
6708 | if (debug_information[i].addr_base >= section->size) | |
6709 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
6710 | (unsigned long) debug_information[i].addr_base, i); | |
6711 | else | |
6712 | debug_addr_info [count++] = debug_information + i; | |
6713 | } | |
4723351a CC |
6714 | |
6715 | /* Add a sentinel to make iteration convenient. */ | |
6716 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
6717 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 6718 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 6719 | |
4723351a CC |
6720 | for (i = 0; i < count; i++) |
6721 | { | |
6722 | unsigned int idx; | |
fab128ef | 6723 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
6724 | |
6725 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 6726 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 6727 | |
fab128ef | 6728 | printf (_("\tIndex\tAddress\n")); |
4723351a CC |
6729 | entry = section->start + debug_addr_info [i]->addr_base; |
6730 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
6731 | idx = 0; | |
6732 | while (entry < end) | |
b4eb7656 AM |
6733 | { |
6734 | dwarf_vma base = byte_get (entry, address_size); | |
6735 | printf (_("\t%d:\t"), idx); | |
6736 | print_dwarf_vma (base, address_size); | |
6737 | printf ("\n"); | |
6738 | entry += address_size; | |
6739 | idx++; | |
6740 | } | |
4723351a CC |
6741 | } |
6742 | printf ("\n"); | |
6743 | ||
6744 | free (debug_addr_info); | |
6745 | return 1; | |
6746 | } | |
6747 | ||
6748 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 6749 | |
4723351a CC |
6750 | static int |
6751 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 6752 | void *file ATTRIBUTE_UNUSED) |
4723351a CC |
6753 | { |
6754 | if (section->size == 0) | |
6755 | { | |
6756 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6757 | return 0; | |
6758 | } | |
6759 | /* TODO: Dump the contents. This is made somewhat difficult by not knowing | |
6760 | what the offset size is for this section. */ | |
6761 | return 1; | |
6762 | } | |
6763 | ||
01a8f077 JK |
6764 | /* Each debug_information[x].range_lists[y] gets this representation for |
6765 | sorting purposes. */ | |
6766 | ||
6767 | struct range_entry | |
467c65bc NC |
6768 | { |
6769 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 6770 | dwarf_vma ranges_offset; |
01a8f077 | 6771 | |
467c65bc NC |
6772 | /* Original debug_information to find parameters of the data. */ |
6773 | debug_info *debug_info_p; | |
6774 | }; | |
01a8f077 JK |
6775 | |
6776 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
6777 | ||
6778 | static int | |
6779 | range_entry_compar (const void *ap, const void *bp) | |
6780 | { | |
3f5e193b NC |
6781 | const struct range_entry *a_re = (const struct range_entry *) ap; |
6782 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
6783 | const dwarf_vma a = a_re->ranges_offset; |
6784 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
6785 | |
6786 | return (a > b) - (b > a); | |
6787 | } | |
6788 | ||
77145576 JK |
6789 | static void |
6790 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
6791 | unsigned int pointer_size, unsigned long offset, | |
6792 | unsigned long base_address) | |
6793 | { | |
6794 | while (start < finish) | |
6795 | { | |
6796 | dwarf_vma begin; | |
6797 | dwarf_vma end; | |
6798 | ||
6799 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6800 | if (start >= finish) | |
6801 | break; | |
6802 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
6803 | ||
d11ae95e | 6804 | |
77145576 JK |
6805 | printf (" %8.8lx ", offset); |
6806 | ||
6807 | if (begin == 0 && end == 0) | |
6808 | { | |
6809 | printf (_("<End of list>\n")); | |
6810 | break; | |
6811 | } | |
6812 | ||
6813 | /* Check base address specifiers. */ | |
6814 | if (is_max_address (begin, pointer_size) | |
6815 | && !is_max_address (end, pointer_size)) | |
6816 | { | |
6817 | base_address = end; | |
6818 | print_dwarf_vma (begin, pointer_size); | |
6819 | print_dwarf_vma (end, pointer_size); | |
6820 | printf ("(base address)\n"); | |
6821 | continue; | |
6822 | } | |
6823 | ||
6824 | print_dwarf_vma (begin + base_address, pointer_size); | |
6825 | print_dwarf_vma (end + base_address, pointer_size); | |
6826 | ||
6827 | if (begin == end) | |
6828 | fputs (_("(start == end)"), stdout); | |
6829 | else if (begin > end) | |
6830 | fputs (_("(start > end)"), stdout); | |
6831 | ||
6832 | putchar ('\n'); | |
6833 | } | |
6834 | } | |
6835 | ||
6836 | static void | |
6837 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
6838 | unsigned int pointer_size, unsigned long offset, | |
6839 | unsigned long base_address) | |
6840 | { | |
6841 | unsigned char *next = start; | |
6842 | ||
6843 | while (1) | |
6844 | { | |
6845 | unsigned long off = offset + (start - next); | |
6846 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
6847 | /* Initialize it due to a false compiler warning. */ |
6848 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
6849 | |
6850 | if (start + 1 > finish) | |
6851 | { | |
6852 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
6853 | offset); | |
6854 | break; | |
6855 | } | |
6856 | ||
6857 | printf (" %8.8lx ", off); | |
6858 | ||
6859 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
6860 | ||
6861 | switch (rlet) | |
6862 | { | |
6863 | case DW_RLE_end_of_list: | |
6864 | printf (_("<End of list>\n")); | |
6865 | break; | |
6866 | case DW_RLE_base_address: | |
6867 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
6868 | print_dwarf_vma (base_address, pointer_size); | |
6869 | printf (_("(base address)\n")); | |
6870 | break; | |
6871 | case DW_RLE_start_length: | |
6872 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
cd30bcef | 6873 | READ_ULEB (length, start, finish); |
77145576 JK |
6874 | end = begin + length; |
6875 | break; | |
6876 | case DW_RLE_offset_pair: | |
cd30bcef AM |
6877 | READ_ULEB (begin, start, finish); |
6878 | READ_ULEB (end, start, finish); | |
77145576 JK |
6879 | break; |
6880 | case DW_RLE_start_end: | |
6881 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
6882 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
6883 | break; | |
6884 | default: | |
6885 | error (_("Invalid range list entry type %d\n"), rlet); | |
6886 | rlet = DW_RLE_end_of_list; | |
6887 | break; | |
6888 | } | |
6889 | if (rlet == DW_RLE_end_of_list) | |
6890 | break; | |
6891 | if (rlet == DW_RLE_base_address) | |
6892 | continue; | |
6893 | ||
6894 | print_dwarf_vma (begin + base_address, pointer_size); | |
6895 | print_dwarf_vma (end + base_address, pointer_size); | |
6896 | ||
6897 | if (begin == end) | |
6898 | fputs (_("(start == end)"), stdout); | |
6899 | else if (begin > end) | |
6900 | fputs (_("(start > end)"), stdout); | |
6901 | ||
6902 | putchar ('\n'); | |
6903 | } | |
6904 | } | |
6905 | ||
19e6b90e L |
6906 | static int |
6907 | display_debug_ranges (struct dwarf_section *section, | |
6908 | void *file ATTRIBUTE_UNUSED) | |
6909 | { | |
6910 | unsigned char *start = section->start; | |
a2ff7a4b | 6911 | unsigned char *last_start = start; |
f6f0e17b | 6912 | unsigned long bytes = section->size; |
19e6b90e | 6913 | unsigned char *section_begin = start; |
f6f0e17b | 6914 | unsigned char *finish = start + bytes; |
01a8f077 JK |
6915 | unsigned int num_range_list, i; |
6916 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
6917 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
6918 | /* Initialize it due to a false compiler warning. */ | |
6919 | unsigned char address_size = 0; | |
19e6b90e | 6920 | |
19e6b90e L |
6921 | if (bytes == 0) |
6922 | { | |
6923 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6924 | return 0; | |
6925 | } | |
6926 | ||
77145576 JK |
6927 | if (is_rnglists) |
6928 | { | |
6929 | dwarf_vma initial_length; | |
6930 | unsigned int initial_length_size; | |
6931 | unsigned char segment_selector_size; | |
6932 | unsigned int offset_size, offset_entry_count; | |
6933 | unsigned short version; | |
6934 | ||
6935 | /* Get and check the length of the block. */ | |
6936 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
6937 | ||
6938 | if (initial_length == 0xffffffff) | |
6939 | { | |
6940 | /* This section is 64-bit DWARF 3. */ | |
6941 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
6942 | offset_size = 8; | |
6943 | initial_length_size = 12; | |
6944 | } | |
6945 | else | |
6946 | { | |
6947 | offset_size = 4; | |
6948 | initial_length_size = 4; | |
6949 | } | |
6950 | ||
6951 | if (initial_length + initial_length_size > section->size) | |
6952 | { | |
6953 | /* If the length field has a relocation against it, then we should | |
6954 | not complain if it is inaccurate (and probably negative). | |
6955 | It is copied from .debug_line handling code. */ | |
6956 | if (reloc_at (section, (start - section->start) - offset_size)) | |
6957 | { | |
6958 | initial_length = (finish - start) - initial_length_size; | |
6959 | } | |
6960 | else | |
6961 | { | |
6962 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
6963 | (long) initial_length); | |
6964 | return 0; | |
6965 | } | |
6966 | } | |
6967 | ||
6968 | /* Get and check the version number. */ | |
6969 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
6970 | ||
6971 | if (version != 5) | |
6972 | { | |
6973 | warn (_("Only DWARF version 5 debug_rnglists info " | |
6974 | "is currently supported.\n")); | |
6975 | return 0; | |
6976 | } | |
6977 | ||
6978 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
6979 | ||
6980 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
6981 | if (segment_selector_size != 0) | |
6982 | { | |
6983 | warn (_("The %s section contains " | |
6984 | "unsupported segment selector size: %d.\n"), | |
6985 | section->name, segment_selector_size); | |
6986 | return 0; | |
6987 | } | |
6988 | ||
6989 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
6990 | if (offset_entry_count != 0) | |
6991 | { | |
6992 | warn (_("The %s section contains " | |
6993 | "unsupported offset entry count: %u.\n"), | |
6994 | section->name, offset_entry_count); | |
6995 | return 0; | |
6996 | } | |
6997 | } | |
6998 | ||
1febe64d NC |
6999 | if (load_debug_info (file) == 0) |
7000 | { | |
7001 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7002 | section->name); | |
7003 | return 0; | |
7004 | } | |
19e6b90e | 7005 | |
01a8f077 | 7006 | num_range_list = 0; |
19e6b90e | 7007 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 7008 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 7009 | |
01a8f077 | 7010 | if (num_range_list == 0) |
4723351a CC |
7011 | { |
7012 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 7013 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
7014 | printf (_("No range lists in .debug_info section.\n")); |
7015 | return 1; | |
7016 | } | |
19e6b90e | 7017 | |
3f5e193b NC |
7018 | range_entries = (struct range_entry *) |
7019 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 7020 | range_entry_fill = range_entries; |
19e6b90e | 7021 | |
01a8f077 JK |
7022 | for (i = 0; i < num_debug_info_entries; i++) |
7023 | { | |
7024 | debug_info *debug_info_p = &debug_information[i]; | |
7025 | unsigned int j; | |
7026 | ||
7027 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
7028 | { | |
7029 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
7030 | range_entry_fill->debug_info_p = debug_info_p; | |
7031 | range_entry_fill++; | |
19e6b90e L |
7032 | } |
7033 | } | |
7034 | ||
01a8f077 JK |
7035 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
7036 | range_entry_compar); | |
19e6b90e | 7037 | |
d493b283 | 7038 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 7039 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 7040 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 7041 | |
dda8d76d NC |
7042 | introduce (section, FALSE); |
7043 | ||
19e6b90e L |
7044 | printf (_(" Offset Begin End\n")); |
7045 | ||
01a8f077 | 7046 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 7047 | { |
01a8f077 JK |
7048 | struct range_entry *range_entry = &range_entries[i]; |
7049 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 7050 | unsigned int pointer_size; |
359ca075 | 7051 | dwarf_vma offset; |
01a8f077 | 7052 | unsigned char *next; |
359ca075 | 7053 | dwarf_vma base_address; |
19e6b90e | 7054 | |
77145576 | 7055 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 7056 | offset = range_entry->ranges_offset; |
01a8f077 JK |
7057 | next = section_begin + offset; |
7058 | base_address = debug_info_p->base_address; | |
cecf136e | 7059 | |
f41e4712 NC |
7060 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
7061 | if (pointer_size < 2 || pointer_size > 8) | |
7062 | { | |
7063 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 7064 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
7065 | continue; |
7066 | } | |
b4eb7656 | 7067 | |
d11ae95e NC |
7068 | if (next < section_begin || next >= finish) |
7069 | { | |
7070 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
7071 | (unsigned long) offset, i); | |
7072 | continue; | |
7073 | } | |
7074 | ||
4723351a | 7075 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 7076 | { |
01a8f077 JK |
7077 | if (start < next) |
7078 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
7079 | (unsigned long) (start - section_begin), | |
7080 | (unsigned long) (next - section_begin), section->name); | |
7081 | else if (start > next) | |
a2ff7a4b AM |
7082 | { |
7083 | if (next == last_start) | |
7084 | continue; | |
7085 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
7086 | (unsigned long) (start - section_begin), | |
7087 | (unsigned long) (next - section_begin), section->name); | |
7088 | } | |
01a8f077 | 7089 | } |
d11ae95e | 7090 | |
01a8f077 | 7091 | start = next; |
a2ff7a4b | 7092 | last_start = next; |
19e6b90e | 7093 | |
77145576 JK |
7094 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
7095 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
7096 | } |
7097 | putchar ('\n'); | |
01a8f077 JK |
7098 | |
7099 | free (range_entries); | |
7100 | ||
19e6b90e L |
7101 | return 1; |
7102 | } | |
7103 | ||
7104 | typedef struct Frame_Chunk | |
7105 | { | |
7106 | struct Frame_Chunk *next; | |
7107 | unsigned char *chunk_start; | |
a1165289 | 7108 | unsigned int ncols; |
19e6b90e L |
7109 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
7110 | short int *col_type; | |
7111 | int *col_offset; | |
7112 | char *augmentation; | |
7113 | unsigned int code_factor; | |
7114 | int data_factor; | |
bf5117e3 NC |
7115 | dwarf_vma pc_begin; |
7116 | dwarf_vma pc_range; | |
32ef3000 | 7117 | unsigned int cfa_reg; |
c8071705 | 7118 | dwarf_vma cfa_offset; |
a1165289 | 7119 | unsigned int ra; |
19e6b90e L |
7120 | unsigned char fde_encoding; |
7121 | unsigned char cfa_exp; | |
604282a7 JJ |
7122 | unsigned char ptr_size; |
7123 | unsigned char segment_size; | |
19e6b90e L |
7124 | } |
7125 | Frame_Chunk; | |
7126 | ||
1296bc99 AB |
7127 | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); |
7128 | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; | |
665ce1f6 L |
7129 | static const char *const *dwarf_regnames; |
7130 | static unsigned int dwarf_regnames_count; | |
7131 | ||
1296bc99 | 7132 | |
19e6b90e L |
7133 | /* A marker for a col_type that means this column was never referenced |
7134 | in the frame info. */ | |
7135 | #define DW_CFA_unreferenced (-1) | |
7136 | ||
a1165289 | 7137 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
7138 | -1 for invalid reg. */ |
7139 | ||
7140 | static int | |
7141 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 7142 | { |
a1165289 | 7143 | unsigned int prev = fc->ncols; |
19e6b90e | 7144 | |
665ce1f6 L |
7145 | if (reg < (unsigned int) fc->ncols) |
7146 | return 0; | |
7147 | ||
d9acf707 | 7148 | if (dwarf_regnames_count > 0 |
665ce1f6 L |
7149 | && reg > dwarf_regnames_count) |
7150 | return -1; | |
19e6b90e L |
7151 | |
7152 | fc->ncols = reg + 1; | |
a1165289 NC |
7153 | /* PR 17512: file: 10450-2643-0.004. |
7154 | If reg == -1 then this can happen... */ | |
7155 | if (fc->ncols == 0) | |
7156 | return -1; | |
7157 | ||
06614111 | 7158 | /* PR 17512: file: 2844a11d. */ |
d9acf707 | 7159 | if (fc->ncols > 1024 && dwarf_regnames_count == 0) |
06614111 NC |
7160 | { |
7161 | error (_("Unfeasibly large register number: %u\n"), reg); | |
7162 | fc->ncols = 0; | |
7163 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
7164 | we ever encounter a valid binary that exceeds it. */ | |
7165 | return -1; | |
7166 | } | |
7167 | ||
3f5e193b | 7168 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 7169 | sizeof (short int)); |
3f5e193b | 7170 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 7171 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
7172 | if (fc->col_type == NULL || fc->col_offset == NULL) |
7173 | { | |
7174 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
7175 | fc->ncols); | |
7176 | fc->ncols = 0; | |
7177 | return -1; | |
7178 | } | |
19e6b90e L |
7179 | |
7180 | while (prev < fc->ncols) | |
7181 | { | |
7182 | fc->col_type[prev] = DW_CFA_unreferenced; | |
7183 | fc->col_offset[prev] = 0; | |
7184 | prev++; | |
7185 | } | |
665ce1f6 | 7186 | return 1; |
19e6b90e L |
7187 | } |
7188 | ||
2dc4cec1 L |
7189 | static const char *const dwarf_regnames_i386[] = |
7190 | { | |
43234a1e L |
7191 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
7192 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7193 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7194 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
7195 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
7196 | NULL, NULL, /* 19 - 20 */ | |
7197 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
7198 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
7199 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
7200 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
7201 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
7202 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7203 | "tr", "ldtr", /* 48 - 49 */ | |
7204 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7205 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7206 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7207 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7208 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7209 | NULL, NULL, NULL, /* 90 - 92 */ | |
7210 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
7211 | }; |
7212 | ||
3d875af5 L |
7213 | static const char *const dwarf_regnames_iamcu[] = |
7214 | { | |
7215 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
7216 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7217 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7218 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
7219 | NULL, NULL, /* 19 - 20 */ | |
7220 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
7221 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
7222 | NULL, NULL, NULL, /* 37 - 39 */ | |
7223 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7224 | "tr", "ldtr", /* 48 - 49 */ | |
7225 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7226 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7227 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7228 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7229 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7230 | NULL, NULL, NULL, /* 90 - 92 */ | |
7231 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
7232 | }; | |
7233 | ||
99f6fdd9 | 7234 | static void |
b129eb0e RH |
7235 | init_dwarf_regnames_i386 (void) |
7236 | { | |
7237 | dwarf_regnames = dwarf_regnames_i386; | |
7238 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
1296bc99 | 7239 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
7240 | } |
7241 | ||
99f6fdd9 | 7242 | static void |
3d875af5 L |
7243 | init_dwarf_regnames_iamcu (void) |
7244 | { | |
7245 | dwarf_regnames = dwarf_regnames_iamcu; | |
7246 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
1296bc99 | 7247 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
3d875af5 L |
7248 | } |
7249 | ||
2dc4cec1 L |
7250 | static const char *const dwarf_regnames_x86_64[] = |
7251 | { | |
7252 | "rax", "rdx", "rcx", "rbx", | |
7253 | "rsi", "rdi", "rbp", "rsp", | |
7254 | "r8", "r9", "r10", "r11", | |
7255 | "r12", "r13", "r14", "r15", | |
7256 | "rip", | |
7257 | "xmm0", "xmm1", "xmm2", "xmm3", | |
7258 | "xmm4", "xmm5", "xmm6", "xmm7", | |
7259 | "xmm8", "xmm9", "xmm10", "xmm11", | |
7260 | "xmm12", "xmm13", "xmm14", "xmm15", | |
7261 | "st0", "st1", "st2", "st3", | |
7262 | "st4", "st5", "st6", "st7", | |
7263 | "mm0", "mm1", "mm2", "mm3", | |
7264 | "mm4", "mm5", "mm6", "mm7", | |
7265 | "rflags", | |
7266 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
7267 | "fs.base", "gs.base", NULL, NULL, | |
7268 | "tr", "ldtr", | |
43234a1e L |
7269 | "mxcsr", "fcw", "fsw", |
7270 | "xmm16", "xmm17", "xmm18", "xmm19", | |
7271 | "xmm20", "xmm21", "xmm22", "xmm23", | |
7272 | "xmm24", "xmm25", "xmm26", "xmm27", | |
7273 | "xmm28", "xmm29", "xmm30", "xmm31", | |
7274 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
7275 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
7276 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
7277 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
7278 | NULL, NULL, NULL, /* 115 - 117 */ | |
7279 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
7280 | }; |
7281 | ||
99f6fdd9 | 7282 | static void |
b129eb0e RH |
7283 | init_dwarf_regnames_x86_64 (void) |
7284 | { | |
7285 | dwarf_regnames = dwarf_regnames_x86_64; | |
7286 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
1296bc99 | 7287 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
7288 | } |
7289 | ||
4ee22035 RH |
7290 | static const char *const dwarf_regnames_aarch64[] = |
7291 | { | |
b4eb7656 AM |
7292 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
7293 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
7294 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
7295 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
7296 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
fab7c86e TC |
7297 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
7298 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", | |
7299 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", | |
b4eb7656 AM |
7300 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
7301 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
7302 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
7303 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
fab7c86e TC |
7304 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
7305 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", | |
7306 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", | |
7307 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", | |
4ee22035 RH |
7308 | }; |
7309 | ||
99f6fdd9 | 7310 | static void |
4ee22035 RH |
7311 | init_dwarf_regnames_aarch64 (void) |
7312 | { | |
7313 | dwarf_regnames = dwarf_regnames_aarch64; | |
7314 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
1296bc99 | 7315 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
4ee22035 RH |
7316 | } |
7317 | ||
d6bb17b0 AA |
7318 | static const char *const dwarf_regnames_s390[] = |
7319 | { | |
7320 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
7321 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7322 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7323 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
7324 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
7325 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
7326 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
7327 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
7328 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
7329 | "pswm", "pswa", | |
7330 | NULL, NULL, | |
7331 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
7332 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
7333 | }; | |
7334 | ||
99f6fdd9 | 7335 | static void |
d6bb17b0 AA |
7336 | init_dwarf_regnames_s390 (void) |
7337 | { | |
7338 | dwarf_regnames = dwarf_regnames_s390; | |
7339 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
1296bc99 | 7340 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
d6bb17b0 AA |
7341 | } |
7342 | ||
5bb0830d AB |
7343 | static const char *const dwarf_regnames_riscv[] = |
7344 | { | |
7345 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
7346 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
7347 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
7348 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
7349 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
7350 | "fs0", "fs1", /* 40 - 41 */ | |
7351 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
7352 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
7353 | "fs10", "fs11", /* 58 - 59 */ | |
7354 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
7355 | }; | |
7356 | ||
4762fe62 AB |
7357 | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles |
7358 | the large number of CSRs. */ | |
7359 | ||
7360 | static const char * | |
7361 | regname_internal_riscv (unsigned int regno) | |
7362 | { | |
7363 | const char *name = NULL; | |
7364 | ||
7365 | /* Lookup in the table first, this covers GPR and FPR. */ | |
7366 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) | |
7367 | name = dwarf_regnames_riscv [regno]; | |
7368 | else if (regno >= 4096 && regno <= 8191) | |
7369 | { | |
7370 | /* This might be a CSR, these live in a sparse number space from 4096 | |
7371 | to 8191 These numbers are defined in the RISC-V ELF ABI | |
7372 | document. */ | |
7373 | switch (regno) | |
7374 | { | |
7375 | #define DECLARE_CSR(NAME,VALUE) case VALUE + 4096: name = #NAME; break; | |
7376 | #include "opcode/riscv-opc.h" | |
7377 | #undef DECLARE_CSR | |
7378 | ||
7379 | default: | |
7380 | { | |
7381 | static char csr_name[10]; | |
7382 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); | |
7383 | name = csr_name; | |
7384 | } | |
7385 | break; | |
7386 | } | |
7387 | } | |
7388 | ||
7389 | return name; | |
7390 | } | |
7391 | ||
99f6fdd9 | 7392 | static void |
5bb0830d AB |
7393 | init_dwarf_regnames_riscv (void) |
7394 | { | |
4762fe62 AB |
7395 | dwarf_regnames = NULL; |
7396 | dwarf_regnames_count = 8192; | |
7397 | dwarf_regnames_lookup_func = regname_internal_riscv; | |
5bb0830d AB |
7398 | } |
7399 | ||
2dc4cec1 | 7400 | void |
955ff7fc | 7401 | init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) |
2dc4cec1 | 7402 | { |
1296bc99 AB |
7403 | dwarf_regnames_lookup_func = NULL; |
7404 | ||
2dc4cec1 L |
7405 | switch (e_machine) |
7406 | { | |
7407 | case EM_386: | |
b129eb0e | 7408 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
7409 | break; |
7410 | ||
3d875af5 L |
7411 | case EM_IAMCU: |
7412 | init_dwarf_regnames_iamcu (); | |
7413 | break; | |
7414 | ||
2dc4cec1 | 7415 | case EM_X86_64: |
7f502d6c | 7416 | case EM_L1OM: |
7a9068fe | 7417 | case EM_K1OM: |
b129eb0e | 7418 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
7419 | break; |
7420 | ||
4ee22035 RH |
7421 | case EM_AARCH64: |
7422 | init_dwarf_regnames_aarch64 (); | |
7423 | break; | |
7424 | ||
d6bb17b0 AA |
7425 | case EM_S390: |
7426 | init_dwarf_regnames_s390 (); | |
7427 | break; | |
7428 | ||
5bb0830d AB |
7429 | case EM_RISCV: |
7430 | init_dwarf_regnames_riscv (); | |
7431 | break; | |
7432 | ||
2dc4cec1 L |
7433 | default: |
7434 | break; | |
7435 | } | |
7436 | } | |
7437 | ||
229a22cf AB |
7438 | /* Initialize the DWARF register name lookup state based on the |
7439 | architecture and specific machine type of a BFD. */ | |
7440 | ||
7441 | void | |
7442 | init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, | |
7443 | unsigned long mach) | |
7444 | { | |
1296bc99 AB |
7445 | dwarf_regnames_lookup_func = NULL; |
7446 | ||
229a22cf AB |
7447 | switch (arch) |
7448 | { | |
7449 | case bfd_arch_i386: | |
7450 | switch (mach) | |
7451 | { | |
7452 | case bfd_mach_x86_64: | |
7453 | case bfd_mach_x86_64_intel_syntax: | |
7454 | case bfd_mach_x86_64_nacl: | |
7455 | case bfd_mach_x64_32: | |
7456 | case bfd_mach_x64_32_intel_syntax: | |
7457 | case bfd_mach_x64_32_nacl: | |
7458 | init_dwarf_regnames_x86_64 (); | |
7459 | break; | |
7460 | ||
7461 | default: | |
7462 | init_dwarf_regnames_i386 (); | |
7463 | break; | |
7464 | } | |
7465 | break; | |
7466 | ||
7467 | case bfd_arch_iamcu: | |
7468 | init_dwarf_regnames_iamcu (); | |
7469 | break; | |
7470 | ||
7471 | case bfd_arch_aarch64: | |
7472 | init_dwarf_regnames_aarch64(); | |
7473 | break; | |
7474 | ||
7475 | case bfd_arch_s390: | |
7476 | init_dwarf_regnames_s390 (); | |
7477 | break; | |
7478 | ||
7479 | case bfd_arch_riscv: | |
7480 | init_dwarf_regnames_riscv (); | |
7481 | break; | |
7482 | ||
7483 | default: | |
7484 | break; | |
7485 | } | |
7486 | } | |
7487 | ||
2dc4cec1 | 7488 | static const char * |
1296bc99 | 7489 | regname_internal_by_table_only (unsigned int regno) |
2dc4cec1 | 7490 | { |
1296bc99 | 7491 | if (dwarf_regnames != NULL |
2dc4cec1 L |
7492 | && regno < dwarf_regnames_count |
7493 | && dwarf_regnames [regno] != NULL) | |
1296bc99 AB |
7494 | return dwarf_regnames [regno]; |
7495 | ||
7496 | return NULL; | |
7497 | } | |
7498 | ||
7499 | static const char * | |
7500 | regname (unsigned int regno, int name_only_p) | |
7501 | { | |
7502 | static char reg[64]; | |
7503 | ||
7504 | const char *name = NULL; | |
7505 | ||
7506 | if (dwarf_regnames_lookup_func != NULL) | |
7507 | name = dwarf_regnames_lookup_func (regno); | |
7508 | ||
7509 | if (name != NULL) | |
2dc4cec1 | 7510 | { |
1296bc99 AB |
7511 | if (name_only_p) |
7512 | return name; | |
7513 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); | |
2dc4cec1 L |
7514 | } |
7515 | else | |
7516 | snprintf (reg, sizeof (reg), "r%d", regno); | |
7517 | return reg; | |
7518 | } | |
7519 | ||
19e6b90e | 7520 | static void |
a1165289 | 7521 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 7522 | { |
a1165289 | 7523 | unsigned int r; |
19e6b90e L |
7524 | char tmp[100]; |
7525 | ||
d8024a91 | 7526 | if (*max_regs != fc->ncols) |
19e6b90e L |
7527 | *max_regs = fc->ncols; |
7528 | ||
7529 | if (*need_col_headers) | |
7530 | { | |
91d6fa6a | 7531 | static const char *sloc = " LOC"; |
2dc4cec1 | 7532 | |
19e6b90e L |
7533 | *need_col_headers = 0; |
7534 | ||
91d6fa6a | 7535 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
7536 | |
7537 | for (r = 0; r < *max_regs; r++) | |
7538 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7539 | { | |
7540 | if (r == fc->ra) | |
50751e18 | 7541 | printf ("ra "); |
19e6b90e | 7542 | else |
2dc4cec1 | 7543 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
7544 | } |
7545 | ||
7546 | printf ("\n"); | |
7547 | } | |
7548 | ||
bf5117e3 | 7549 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
7550 | if (fc->cfa_exp) |
7551 | strcpy (tmp, "exp"); | |
7552 | else | |
c8071705 | 7553 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
7554 | printf ("%-8s ", tmp); |
7555 | ||
7556 | for (r = 0; r < fc->ncols; r++) | |
7557 | { | |
7558 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7559 | { | |
7560 | switch (fc->col_type[r]) | |
7561 | { | |
7562 | case DW_CFA_undefined: | |
7563 | strcpy (tmp, "u"); | |
7564 | break; | |
7565 | case DW_CFA_same_value: | |
7566 | strcpy (tmp, "s"); | |
7567 | break; | |
7568 | case DW_CFA_offset: | |
7569 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
7570 | break; | |
12eae2d3 JJ |
7571 | case DW_CFA_val_offset: |
7572 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
7573 | break; | |
19e6b90e | 7574 | case DW_CFA_register: |
2dc4cec1 | 7575 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
7576 | break; |
7577 | case DW_CFA_expression: | |
7578 | strcpy (tmp, "exp"); | |
7579 | break; | |
12eae2d3 JJ |
7580 | case DW_CFA_val_expression: |
7581 | strcpy (tmp, "vexp"); | |
7582 | break; | |
19e6b90e L |
7583 | default: |
7584 | strcpy (tmp, "n/a"); | |
7585 | break; | |
7586 | } | |
2dc4cec1 | 7587 | printf ("%-5s ", tmp); |
19e6b90e L |
7588 | } |
7589 | } | |
7590 | printf ("\n"); | |
7591 | } | |
7592 | ||
49727e46 | 7593 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 7594 | |
49727e46 AM |
7595 | static unsigned char * |
7596 | read_cie (unsigned char *start, unsigned char *end, | |
7597 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 7598 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
7599 | { |
7600 | int version; | |
7601 | Frame_Chunk *fc; | |
49727e46 | 7602 | unsigned char *augmentation_data = NULL; |
bf59c5d5 | 7603 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 7604 | |
041830e0 | 7605 | * p_cie = NULL; |
f41e4712 NC |
7606 | /* PR 17512: file: 001-228113-0.004. */ |
7607 | if (start >= end) | |
7608 | return end; | |
7609 | ||
49727e46 AM |
7610 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
7611 | memset (fc, 0, sizeof (Frame_Chunk)); | |
7612 | ||
7613 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
7614 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
7615 | ||
7616 | version = *start++; | |
7617 | ||
7618 | fc->augmentation = (char *) start; | |
f41e4712 NC |
7619 | /* PR 17512: file: 001-228113-0.004. |
7620 | Skip past augmentation name, but avoid running off the end of the data. */ | |
7621 | while (start < end) | |
7622 | if (* start ++ == '\0') | |
7623 | break; | |
7624 | if (start == end) | |
7625 | { | |
7626 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 7627 | goto fail; |
f41e4712 | 7628 | } |
49727e46 AM |
7629 | |
7630 | if (strcmp (fc->augmentation, "eh") == 0) | |
7631 | start += eh_addr_size; | |
7632 | ||
7633 | if (version >= 4) | |
7634 | { | |
7635 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
7636 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
7637 | { | |
7638 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 7639 | goto fail; |
77ef8654 NC |
7640 | } |
7641 | ||
49727e46 | 7642 | GET (fc->segment_size, 1); |
77ef8654 NC |
7643 | /* PR 17512: file: e99d2804. */ |
7644 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
7645 | { | |
7646 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 7647 | goto fail; |
77ef8654 NC |
7648 | } |
7649 | ||
49727e46 AM |
7650 | eh_addr_size = fc->ptr_size; |
7651 | } | |
7652 | else | |
7653 | { | |
7654 | fc->ptr_size = eh_addr_size; | |
7655 | fc->segment_size = 0; | |
7656 | } | |
442a6ce8 | 7657 | |
cd30bcef AM |
7658 | READ_ULEB (fc->code_factor, start, end); |
7659 | READ_SLEB (fc->data_factor, start, end); | |
442a6ce8 | 7660 | |
49727e46 AM |
7661 | if (version == 1) |
7662 | { | |
7663 | GET (fc->ra, 1); | |
7664 | } | |
7665 | else | |
7666 | { | |
cd30bcef | 7667 | READ_ULEB (fc->ra, start, end); |
49727e46 AM |
7668 | } |
7669 | ||
7670 | if (fc->augmentation[0] == 'z') | |
7671 | { | |
cd30bcef | 7672 | READ_ULEB (augmentation_data_len, start, end); |
49727e46 | 7673 | augmentation_data = start; |
a1165289 | 7674 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 7675 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 7676 | { |
bf59c5d5 NC |
7677 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
7678 | dwarf_vmatoa ("x", augmentation_data_len), | |
7679 | (unsigned long) (end - start)); | |
442a6ce8 | 7680 | goto fail; |
a1165289 | 7681 | } |
9c0f3d3f | 7682 | start += augmentation_data_len; |
49727e46 AM |
7683 | } |
7684 | ||
7685 | if (augmentation_data_len) | |
7686 | { | |
058037d3 NC |
7687 | unsigned char *p; |
7688 | unsigned char *q; | |
7689 | unsigned char *qend; | |
b4eb7656 | 7690 | |
49727e46 AM |
7691 | p = (unsigned char *) fc->augmentation + 1; |
7692 | q = augmentation_data; | |
058037d3 NC |
7693 | qend = q + augmentation_data_len; |
7694 | ||
9c0f3d3f | 7695 | while (p < end && q < qend) |
49727e46 AM |
7696 | { |
7697 | if (*p == 'L') | |
7698 | q++; | |
7699 | else if (*p == 'P') | |
7700 | q += 1 + size_of_encoded_value (*q); | |
7701 | else if (*p == 'R') | |
7702 | fc->fde_encoding = *q++; | |
7703 | else if (*p == 'S') | |
7704 | ; | |
09038062 ST |
7705 | else if (*p == 'B') |
7706 | ; | |
49727e46 AM |
7707 | else |
7708 | break; | |
7709 | p++; | |
7710 | } | |
c361b9ac NC |
7711 | /* Note - it is OK if this loop terminates with q < qend. |
7712 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
7713 | } |
7714 | ||
7715 | *p_cie = fc; | |
7716 | if (p_version) | |
7717 | *p_version = version; | |
7718 | if (p_aug_len) | |
7719 | { | |
7720 | *p_aug_len = augmentation_data_len; | |
7721 | *p_aug = augmentation_data; | |
7722 | } | |
7723 | return start; | |
442a6ce8 NC |
7724 | |
7725 | fail: | |
7726 | free (fc->col_offset); | |
7727 | free (fc->col_type); | |
7728 | free (fc); | |
7729 | return end; | |
49727e46 AM |
7730 | } |
7731 | ||
d85bf2ba NC |
7732 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
7733 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
7734 | PRINTED contains the number of characters already written to the current | |
7735 | output line. */ | |
bf59c5d5 NC |
7736 | |
7737 | static void | |
d85bf2ba NC |
7738 | display_data (bfd_size_type printed, |
7739 | const unsigned char * data, | |
7740 | const bfd_size_type len) | |
bf59c5d5 | 7741 | { |
d85bf2ba NC |
7742 | if (do_wide || len < ((80 - printed) / 3)) |
7743 | for (printed = 0; printed < len; ++printed) | |
7744 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
7745 | else |
7746 | { | |
d85bf2ba | 7747 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 7748 | { |
d85bf2ba | 7749 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 7750 | putchar ('\n'); |
d85bf2ba | 7751 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
7752 | } |
7753 | } | |
d85bf2ba NC |
7754 | } |
7755 | ||
7756 | /* Prints out the contents on the augmentation data array. | |
7757 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
7758 | ||
7759 | static void | |
7760 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
7761 | { | |
7762 | bfd_size_type i; | |
7763 | ||
7764 | i = printf (_(" Augmentation data: ")); | |
7765 | display_data (i, data, len); | |
bf59c5d5 NC |
7766 | } |
7767 | ||
19e6b90e L |
7768 | static int |
7769 | display_debug_frames (struct dwarf_section *section, | |
7770 | void *file ATTRIBUTE_UNUSED) | |
7771 | { | |
7772 | unsigned char *start = section->start; | |
7773 | unsigned char *end = start + section->size; | |
7774 | unsigned char *section_start = start; | |
3391569f NC |
7775 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
7776 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 7777 | Frame_Chunk *rs; |
3391569f | 7778 | bfd_boolean is_eh = strcmp (section->name, ".eh_frame") == 0; |
a1165289 | 7779 | unsigned int max_regs = 0; |
665ce1f6 | 7780 | const char *bad_reg = _("bad register: "); |
77ef8654 | 7781 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 7782 | |
dda8d76d | 7783 | introduce (section, FALSE); |
19e6b90e L |
7784 | |
7785 | while (start < end) | |
7786 | { | |
7787 | unsigned char *saved_start; | |
7788 | unsigned char *block_end; | |
bf5117e3 NC |
7789 | dwarf_vma length; |
7790 | dwarf_vma cie_id; | |
19e6b90e L |
7791 | Frame_Chunk *fc; |
7792 | Frame_Chunk *cie; | |
7793 | int need_col_headers = 1; | |
7794 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 7795 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
7796 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
7797 | unsigned int offset_size; | |
7798 | unsigned int initial_length_size; | |
5b6312fd | 7799 | bfd_boolean all_nops; |
19e6b90e L |
7800 | |
7801 | saved_start = start; | |
19e6b90e | 7802 | |
0c588247 | 7803 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 7804 | |
19e6b90e L |
7805 | if (length == 0) |
7806 | { | |
7807 | printf ("\n%08lx ZERO terminator\n\n", | |
7808 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
7809 | /* Skip any zero terminators that directly follow. |
7810 | A corrupt section size could have loaded a whole | |
7811 | slew of zero filled memory bytes. eg | |
7812 | PR 17512: file: 070-19381-0.004. */ | |
7813 | while (start < end && * start == 0) | |
7814 | ++ start; | |
b758e50f | 7815 | continue; |
19e6b90e L |
7816 | } |
7817 | ||
7818 | if (length == 0xffffffff) | |
7819 | { | |
0c588247 | 7820 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
7821 | offset_size = 8; |
7822 | initial_length_size = 12; | |
7823 | } | |
7824 | else | |
7825 | { | |
7826 | offset_size = 4; | |
7827 | initial_length_size = 4; | |
7828 | } | |
7829 | ||
7830 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 7831 | if (block_end > end || block_end < start) |
53b8873b | 7832 | { |
bf5117e3 NC |
7833 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
7834 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
7835 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
7836 | block_end = end; |
7837 | } | |
0c588247 NC |
7838 | |
7839 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 7840 | |
846a11e4 NC |
7841 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
7842 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
7843 | { |
7844 | int version; | |
a1165289 | 7845 | unsigned int mreg; |
19e6b90e | 7846 | |
49727e46 AM |
7847 | start = read_cie (start, end, &cie, &version, |
7848 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
7849 | /* PR 17512: file: 027-135133-0.005. */ |
7850 | if (cie == NULL) | |
7851 | break; | |
a1165289 | 7852 | |
49727e46 | 7853 | fc = cie; |
19e6b90e L |
7854 | fc->next = chunks; |
7855 | chunks = fc; | |
7856 | fc->chunk_start = saved_start; | |
a1165289 | 7857 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
7858 | if (mreg < fc->ra) |
7859 | mreg = fc->ra; | |
06614111 NC |
7860 | if (frame_need_space (fc, mreg) < 0) |
7861 | break; | |
49727e46 AM |
7862 | if (fc->fde_encoding) |
7863 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 7864 | |
bf5117e3 NC |
7865 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
7866 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 7867 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 7868 | |
19e6b90e | 7869 | if (do_debug_frames_interp) |
bf5117e3 NC |
7870 | { |
7871 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
7872 | fc->code_factor, fc->data_factor, fc->ra); | |
7873 | } | |
19e6b90e L |
7874 | else |
7875 | { | |
bf5117e3 | 7876 | printf ("CIE\n"); |
19e6b90e L |
7877 | printf (" Version: %d\n", version); |
7878 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
7879 | if (version >= 4) |
7880 | { | |
7881 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
7882 | printf (" Segment Size: %u\n", fc->segment_size); | |
7883 | } | |
19e6b90e L |
7884 | printf (" Code alignment factor: %u\n", fc->code_factor); |
7885 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
7886 | printf (" Return address column: %d\n", fc->ra); | |
7887 | ||
7888 | if (augmentation_data_len) | |
bf59c5d5 | 7889 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 7890 | |
19e6b90e L |
7891 | putchar ('\n'); |
7892 | } | |
19e6b90e L |
7893 | } |
7894 | else | |
7895 | { | |
7896 | unsigned char *look_for; | |
7897 | static Frame_Chunk fde_fc; | |
604282a7 | 7898 | unsigned long segment_selector; |
19e6b90e | 7899 | |
49727e46 AM |
7900 | if (is_eh) |
7901 | { | |
7902 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
7903 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
7904 | } | |
7905 | else | |
7906 | look_for = section_start + cie_id; | |
19e6b90e | 7907 | |
49727e46 AM |
7908 | if (look_for <= saved_start) |
7909 | { | |
7910 | for (cie = chunks; cie ; cie = cie->next) | |
7911 | if (cie->chunk_start == look_for) | |
7912 | break; | |
7913 | } | |
7914 | else | |
7915 | { | |
7916 | for (cie = forward_refs; cie ; cie = cie->next) | |
7917 | if (cie->chunk_start == look_for) | |
7918 | break; | |
7919 | if (!cie) | |
7920 | { | |
7921 | unsigned int off_size; | |
7922 | unsigned char *cie_scan; | |
19e6b90e | 7923 | |
49727e46 AM |
7924 | cie_scan = look_for; |
7925 | off_size = 4; | |
7926 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
7927 | if (length == 0xffffffff) | |
7928 | { | |
7929 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
7930 | off_size = 8; | |
7931 | } | |
7932 | if (length != 0) | |
7933 | { | |
7934 | dwarf_vma c_id; | |
7935 | ||
7936 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
7937 | if (is_eh | |
7938 | ? c_id == 0 | |
7939 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
7940 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
7941 | { | |
7942 | int version; | |
a1165289 | 7943 | unsigned int mreg; |
49727e46 AM |
7944 | |
7945 | read_cie (cie_scan, end, &cie, &version, | |
7946 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
7947 | /* PR 17512: file: 3450-2098-0.004. */ |
7948 | if (cie == NULL) | |
7949 | { | |
7950 | warn (_("Failed to read CIE information\n")); | |
7951 | break; | |
7952 | } | |
49727e46 AM |
7953 | cie->next = forward_refs; |
7954 | forward_refs = cie; | |
7955 | cie->chunk_start = look_for; | |
a1165289 | 7956 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
7957 | if (mreg < cie->ra) |
7958 | mreg = cie->ra; | |
06614111 NC |
7959 | if (frame_need_space (cie, mreg) < 0) |
7960 | { | |
7961 | warn (_("Invalid max register\n")); | |
7962 | break; | |
7963 | } | |
49727e46 AM |
7964 | if (cie->fde_encoding) |
7965 | encoded_ptr_size | |
7966 | = size_of_encoded_value (cie->fde_encoding); | |
7967 | } | |
7968 | } | |
7969 | } | |
7970 | } | |
7971 | ||
7972 | fc = &fde_fc; | |
7973 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
7974 | |
7975 | if (!cie) | |
7976 | { | |
bf5117e3 NC |
7977 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
7978 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
7979 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 7980 | fc->ncols = 0; |
3f5e193b NC |
7981 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
7982 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
7983 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
7984 | { | |
7985 | warn (_("Invalid max register\n")); | |
7986 | break; | |
7987 | } | |
19e6b90e L |
7988 | cie = fc; |
7989 | fc->augmentation = ""; | |
7990 | fc->fde_encoding = 0; | |
604282a7 JJ |
7991 | fc->ptr_size = eh_addr_size; |
7992 | fc->segment_size = 0; | |
19e6b90e L |
7993 | } |
7994 | else | |
7995 | { | |
7996 | fc->ncols = cie->ncols; | |
3f5e193b NC |
7997 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
7998 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
7999 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
8000 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
8001 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
8002 | fc->ptr_size = cie->ptr_size; |
8003 | eh_addr_size = cie->ptr_size; | |
8004 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
8005 | fc->code_factor = cie->code_factor; |
8006 | fc->data_factor = cie->data_factor; | |
8007 | fc->cfa_reg = cie->cfa_reg; | |
8008 | fc->cfa_offset = cie->cfa_offset; | |
8009 | fc->ra = cie->ra; | |
06614111 NC |
8010 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
8011 | { | |
8012 | warn (_("Invalid max register\n")); | |
8013 | break; | |
8014 | } | |
19e6b90e L |
8015 | fc->fde_encoding = cie->fde_encoding; |
8016 | } | |
8017 | ||
8018 | if (fc->fde_encoding) | |
8019 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
8020 | ||
604282a7 JJ |
8021 | segment_selector = 0; |
8022 | if (fc->segment_size) | |
c8071705 NC |
8023 | { |
8024 | if (fc->segment_size > sizeof (segment_selector)) | |
8025 | { | |
8026 | /* PR 17512: file: 9e196b3e. */ | |
8027 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
8028 | fc->segment_size = 4; | |
8029 | } | |
8030 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
8031 | } | |
041830e0 NC |
8032 | |
8033 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 8034 | |
0c588247 NC |
8035 | /* FIXME: It appears that sometimes the final pc_range value is |
8036 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
8037 | run of the "objcopy on compressed debug sections" test for an | |
8038 | example of this. */ | |
8039 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 8040 | |
19e6b90e L |
8041 | if (cie->augmentation[0] == 'z') |
8042 | { | |
cd30bcef | 8043 | READ_ULEB (augmentation_data_len, start, end); |
19e6b90e | 8044 | augmentation_data = start; |
bf59c5d5 | 8045 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
d292364e | 8046 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
0a9d414a | 8047 | { |
d292364e AM |
8048 | warn (_("Augmentation data too long: 0x%s, " |
8049 | "expected at most %#lx\n"), | |
8050 | dwarf_vmatoa ("x", augmentation_data_len), | |
8051 | (unsigned long) (end - start)); | |
0a9d414a NC |
8052 | start = end; |
8053 | augmentation_data = NULL; | |
8054 | augmentation_data_len = 0; | |
8055 | } | |
d292364e | 8056 | start += augmentation_data_len; |
19e6b90e L |
8057 | } |
8058 | ||
bf5117e3 NC |
8059 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
8060 | (unsigned long)(saved_start - section_start), | |
8061 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 8062 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 8063 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 8064 | |
604282a7 JJ |
8065 | if (fc->segment_size) |
8066 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
8067 | |
8068 | printf ("%s..%s\n", | |
8069 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
8070 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
8071 | ||
19e6b90e L |
8072 | if (! do_debug_frames_interp && augmentation_data_len) |
8073 | { | |
bf59c5d5 | 8074 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
8075 | putchar ('\n'); |
8076 | } | |
8077 | } | |
8078 | ||
8079 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
8080 | we're about to interpret instructions for the chunk. */ | |
8081 | /* ??? At present we need to do this always, since this sizes the | |
8082 | fc->col_type and fc->col_offset arrays, which we write into always. | |
8083 | We should probably split the interpreted and non-interpreted bits | |
8084 | into two different routines, since there's so much that doesn't | |
8085 | really overlap between them. */ | |
8086 | if (1 || do_debug_frames_interp) | |
8087 | { | |
8088 | /* Start by making a pass over the chunk, allocating storage | |
8089 | and taking note of what registers are used. */ | |
8090 | unsigned char *tmp = start; | |
8091 | ||
8092 | while (start < block_end) | |
8093 | { | |
041830e0 NC |
8094 | unsigned int reg, op, opa; |
8095 | unsigned long temp; | |
5929c344 | 8096 | unsigned char * new_start; |
19e6b90e L |
8097 | |
8098 | op = *start++; | |
8099 | opa = op & 0x3f; | |
8100 | if (op & 0xc0) | |
8101 | op &= 0xc0; | |
8102 | ||
8103 | /* Warning: if you add any more cases to this switch, be | |
8104 | sure to add them to the corresponding switch below. */ | |
8105 | switch (op) | |
8106 | { | |
8107 | case DW_CFA_advance_loc: | |
8108 | break; | |
8109 | case DW_CFA_offset: | |
cd30bcef | 8110 | SKIP_ULEB (start, end); |
665ce1f6 L |
8111 | if (frame_need_space (fc, opa) >= 0) |
8112 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8113 | break; |
8114 | case DW_CFA_restore: | |
665ce1f6 L |
8115 | if (frame_need_space (fc, opa) >= 0) |
8116 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8117 | break; |
8118 | case DW_CFA_set_loc: | |
8119 | start += encoded_ptr_size; | |
8120 | break; | |
8121 | case DW_CFA_advance_loc1: | |
8122 | start += 1; | |
8123 | break; | |
8124 | case DW_CFA_advance_loc2: | |
8125 | start += 2; | |
8126 | break; | |
8127 | case DW_CFA_advance_loc4: | |
8128 | start += 4; | |
8129 | break; | |
8130 | case DW_CFA_offset_extended: | |
12eae2d3 | 8131 | case DW_CFA_val_offset: |
cd30bcef AM |
8132 | READ_ULEB (reg, start, end); |
8133 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8134 | if (frame_need_space (fc, reg) >= 0) |
8135 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8136 | break; |
8137 | case DW_CFA_restore_extended: | |
cd30bcef | 8138 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8139 | if (frame_need_space (fc, reg) >= 0) |
8140 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8141 | break; |
8142 | case DW_CFA_undefined: | |
cd30bcef | 8143 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8144 | if (frame_need_space (fc, reg) >= 0) |
8145 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8146 | break; |
8147 | case DW_CFA_same_value: | |
cd30bcef | 8148 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8149 | if (frame_need_space (fc, reg) >= 0) |
8150 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8151 | break; |
8152 | case DW_CFA_register: | |
cd30bcef AM |
8153 | READ_ULEB (reg, start, end); |
8154 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8155 | if (frame_need_space (fc, reg) >= 0) |
8156 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8157 | break; |
8158 | case DW_CFA_def_cfa: | |
cd30bcef AM |
8159 | SKIP_ULEB (start, end); |
8160 | SKIP_ULEB (start, end); | |
19e6b90e L |
8161 | break; |
8162 | case DW_CFA_def_cfa_register: | |
cd30bcef | 8163 | SKIP_ULEB (start, end); |
19e6b90e L |
8164 | break; |
8165 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 8166 | SKIP_ULEB (start, end); |
19e6b90e L |
8167 | break; |
8168 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 8169 | READ_ULEB (temp, start, end); |
5929c344 NC |
8170 | new_start = start + temp; |
8171 | if (new_start < start) | |
041830e0 NC |
8172 | { |
8173 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
8174 | start = block_end; | |
8175 | } | |
8176 | else | |
5929c344 | 8177 | start = new_start; |
19e6b90e L |
8178 | break; |
8179 | case DW_CFA_expression: | |
12eae2d3 | 8180 | case DW_CFA_val_expression: |
cd30bcef AM |
8181 | READ_ULEB (reg, start, end); |
8182 | READ_ULEB (temp, start, end); | |
5929c344 NC |
8183 | new_start = start + temp; |
8184 | if (new_start < start) | |
041830e0 | 8185 | { |
b4eb7656 | 8186 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
8187 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
8188 | start = block_end; | |
8189 | } | |
8190 | else | |
5929c344 | 8191 | start = new_start; |
665ce1f6 L |
8192 | if (frame_need_space (fc, reg) >= 0) |
8193 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8194 | break; |
8195 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 8196 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
8197 | READ_ULEB (reg, start, end); |
8198 | SKIP_SLEB (start, end); | |
665ce1f6 L |
8199 | if (frame_need_space (fc, reg) >= 0) |
8200 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8201 | break; |
8202 | case DW_CFA_def_cfa_sf: | |
cd30bcef AM |
8203 | SKIP_ULEB (start, end); |
8204 | SKIP_SLEB (start, end); | |
19e6b90e L |
8205 | break; |
8206 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 8207 | SKIP_SLEB (start, end); |
19e6b90e L |
8208 | break; |
8209 | case DW_CFA_MIPS_advance_loc8: | |
8210 | start += 8; | |
8211 | break; | |
8212 | case DW_CFA_GNU_args_size: | |
cd30bcef | 8213 | SKIP_ULEB (start, end); |
19e6b90e L |
8214 | break; |
8215 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
8216 | READ_ULEB (reg, start, end); |
8217 | SKIP_ULEB (start, end); | |
665ce1f6 L |
8218 | if (frame_need_space (fc, reg) >= 0) |
8219 | fc->col_type[reg] = DW_CFA_undefined; | |
8220 | break; | |
19e6b90e L |
8221 | default: |
8222 | break; | |
8223 | } | |
8224 | } | |
8225 | start = tmp; | |
8226 | } | |
8227 | ||
5b6312fd NC |
8228 | all_nops = TRUE; |
8229 | ||
19e6b90e L |
8230 | /* Now we know what registers are used, make a second pass over |
8231 | the chunk, this time actually printing out the info. */ | |
8232 | ||
8233 | while (start < block_end) | |
8234 | { | |
362beea4 | 8235 | unsigned char * tmp; |
19e6b90e | 8236 | unsigned op, opa; |
7f2c8a1d NC |
8237 | unsigned long ul, roffs; |
8238 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
8239 | are various functions, notably frame_space_needed() that assume that | |
8240 | reg is an unsigned int. */ | |
8241 | unsigned int reg; | |
8242 | dwarf_signed_vma l; | |
bf5117e3 | 8243 | dwarf_vma ofs; |
19e6b90e | 8244 | dwarf_vma vma; |
665ce1f6 | 8245 | const char *reg_prefix = ""; |
19e6b90e L |
8246 | |
8247 | op = *start++; | |
8248 | opa = op & 0x3f; | |
8249 | if (op & 0xc0) | |
8250 | op &= 0xc0; | |
8251 | ||
5b6312fd NC |
8252 | /* Make a note if something other than DW_CFA_nop happens. */ |
8253 | if (op != DW_CFA_nop) | |
8254 | all_nops = FALSE; | |
8255 | ||
19e6b90e L |
8256 | /* Warning: if you add any more cases to this switch, be |
8257 | sure to add them to the corresponding switch above. */ | |
8258 | switch (op) | |
8259 | { | |
8260 | case DW_CFA_advance_loc: | |
8261 | if (do_debug_frames_interp) | |
8262 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8263 | else | |
bf5117e3 | 8264 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 8265 | opa * fc->code_factor, |
b4eb7656 | 8266 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
8267 | fc->pc_begin + opa * fc->code_factor, |
8268 | fc->ptr_size)); | |
19e6b90e L |
8269 | fc->pc_begin += opa * fc->code_factor; |
8270 | break; | |
8271 | ||
8272 | case DW_CFA_offset: | |
cd30bcef | 8273 | READ_ULEB (roffs, start, end); |
665ce1f6 L |
8274 | if (opa >= (unsigned int) fc->ncols) |
8275 | reg_prefix = bad_reg; | |
8276 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8277 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
8278 | reg_prefix, regname (opa, 0), | |
8279 | roffs * fc->data_factor); | |
8280 | if (*reg_prefix == '\0') | |
8281 | { | |
8282 | fc->col_type[opa] = DW_CFA_offset; | |
8283 | fc->col_offset[opa] = roffs * fc->data_factor; | |
8284 | } | |
19e6b90e L |
8285 | break; |
8286 | ||
8287 | case DW_CFA_restore: | |
50751e18 | 8288 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
8289 | reg_prefix = bad_reg; |
8290 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8291 | printf (" DW_CFA_restore: %s%s\n", | |
8292 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
8293 | if (*reg_prefix != '\0') |
8294 | break; | |
8295 | ||
8296 | if (opa >= (unsigned int) cie->ncols | |
8297 | || (do_debug_frames_interp | |
8298 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
8299 | { | |
8300 | fc->col_type[opa] = DW_CFA_undefined; | |
8301 | fc->col_offset[opa] = 0; | |
8302 | } | |
8303 | else | |
665ce1f6 L |
8304 | { |
8305 | fc->col_type[opa] = cie->col_type[opa]; | |
8306 | fc->col_offset[opa] = cie->col_offset[opa]; | |
8307 | } | |
19e6b90e L |
8308 | break; |
8309 | ||
8310 | case DW_CFA_set_loc: | |
6937bb54 | 8311 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
8312 | if (do_debug_frames_interp) |
8313 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8314 | else | |
bf5117e3 NC |
8315 | printf (" DW_CFA_set_loc: %s\n", |
8316 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
8317 | fc->pc_begin = vma; |
8318 | break; | |
8319 | ||
8320 | case DW_CFA_advance_loc1: | |
0c588247 | 8321 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
8322 | if (do_debug_frames_interp) |
8323 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8324 | else | |
bf5117e3 NC |
8325 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
8326 | (unsigned long) (ofs * fc->code_factor), | |
8327 | dwarf_vmatoa_1 (NULL, | |
8328 | fc->pc_begin + ofs * fc->code_factor, | |
8329 | fc->ptr_size)); | |
19e6b90e L |
8330 | fc->pc_begin += ofs * fc->code_factor; |
8331 | break; | |
8332 | ||
8333 | case DW_CFA_advance_loc2: | |
6937bb54 | 8334 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
8335 | if (do_debug_frames_interp) |
8336 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8337 | else | |
bf5117e3 NC |
8338 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
8339 | (unsigned long) (ofs * fc->code_factor), | |
8340 | dwarf_vmatoa_1 (NULL, | |
8341 | fc->pc_begin + ofs * fc->code_factor, | |
8342 | fc->ptr_size)); | |
19e6b90e L |
8343 | fc->pc_begin += ofs * fc->code_factor; |
8344 | break; | |
8345 | ||
8346 | case DW_CFA_advance_loc4: | |
6937bb54 | 8347 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
8348 | if (do_debug_frames_interp) |
8349 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8350 | else | |
bf5117e3 NC |
8351 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
8352 | (unsigned long) (ofs * fc->code_factor), | |
8353 | dwarf_vmatoa_1 (NULL, | |
8354 | fc->pc_begin + ofs * fc->code_factor, | |
8355 | fc->ptr_size)); | |
19e6b90e L |
8356 | fc->pc_begin += ofs * fc->code_factor; |
8357 | break; | |
8358 | ||
8359 | case DW_CFA_offset_extended: | |
cd30bcef AM |
8360 | READ_ULEB (reg, start, end); |
8361 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
8362 | if (reg >= (unsigned int) fc->ncols) |
8363 | reg_prefix = bad_reg; | |
8364 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8365 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
8366 | reg_prefix, regname (reg, 0), | |
8367 | roffs * fc->data_factor); | |
8368 | if (*reg_prefix == '\0') | |
8369 | { | |
8370 | fc->col_type[reg] = DW_CFA_offset; | |
8371 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8372 | } | |
19e6b90e L |
8373 | break; |
8374 | ||
12eae2d3 | 8375 | case DW_CFA_val_offset: |
cd30bcef AM |
8376 | READ_ULEB (reg, start, end); |
8377 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
8378 | if (reg >= (unsigned int) fc->ncols) |
8379 | reg_prefix = bad_reg; | |
8380 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8381 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
8382 | reg_prefix, regname (reg, 0), |
8383 | roffs * fc->data_factor); | |
8384 | if (*reg_prefix == '\0') | |
8385 | { | |
8386 | fc->col_type[reg] = DW_CFA_val_offset; | |
8387 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8388 | } | |
12eae2d3 JJ |
8389 | break; |
8390 | ||
19e6b90e | 8391 | case DW_CFA_restore_extended: |
cd30bcef | 8392 | READ_ULEB (reg, start, end); |
50751e18 | 8393 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
8394 | reg_prefix = bad_reg; |
8395 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8396 | printf (" DW_CFA_restore_extended: %s%s\n", | |
8397 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
8398 | if (*reg_prefix != '\0') |
8399 | break; | |
8400 | ||
8401 | if (reg >= (unsigned int) cie->ncols) | |
8402 | { | |
8403 | fc->col_type[reg] = DW_CFA_undefined; | |
8404 | fc->col_offset[reg] = 0; | |
8405 | } | |
8406 | else | |
665ce1f6 L |
8407 | { |
8408 | fc->col_type[reg] = cie->col_type[reg]; | |
8409 | fc->col_offset[reg] = cie->col_offset[reg]; | |
8410 | } | |
19e6b90e L |
8411 | break; |
8412 | ||
8413 | case DW_CFA_undefined: | |
cd30bcef | 8414 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8415 | if (reg >= (unsigned int) fc->ncols) |
8416 | reg_prefix = bad_reg; | |
8417 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8418 | printf (" DW_CFA_undefined: %s%s\n", | |
8419 | reg_prefix, regname (reg, 0)); | |
8420 | if (*reg_prefix == '\0') | |
8421 | { | |
8422 | fc->col_type[reg] = DW_CFA_undefined; | |
8423 | fc->col_offset[reg] = 0; | |
8424 | } | |
19e6b90e L |
8425 | break; |
8426 | ||
8427 | case DW_CFA_same_value: | |
cd30bcef | 8428 | READ_ULEB (reg, start, end); |
665ce1f6 L |
8429 | if (reg >= (unsigned int) fc->ncols) |
8430 | reg_prefix = bad_reg; | |
8431 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8432 | printf (" DW_CFA_same_value: %s%s\n", | |
8433 | reg_prefix, regname (reg, 0)); | |
8434 | if (*reg_prefix == '\0') | |
8435 | { | |
8436 | fc->col_type[reg] = DW_CFA_same_value; | |
8437 | fc->col_offset[reg] = 0; | |
8438 | } | |
19e6b90e L |
8439 | break; |
8440 | ||
8441 | case DW_CFA_register: | |
cd30bcef AM |
8442 | READ_ULEB (reg, start, end); |
8443 | READ_ULEB (roffs, start, end); | |
665ce1f6 L |
8444 | if (reg >= (unsigned int) fc->ncols) |
8445 | reg_prefix = bad_reg; | |
8446 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 8447 | { |
665ce1f6 L |
8448 | printf (" DW_CFA_register: %s%s in ", |
8449 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
8450 | puts (regname (roffs, 0)); |
8451 | } | |
665ce1f6 L |
8452 | if (*reg_prefix == '\0') |
8453 | { | |
8454 | fc->col_type[reg] = DW_CFA_register; | |
8455 | fc->col_offset[reg] = roffs; | |
8456 | } | |
19e6b90e L |
8457 | break; |
8458 | ||
8459 | case DW_CFA_remember_state: | |
8460 | if (! do_debug_frames_interp) | |
8461 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 8462 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 8463 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
8464 | rs->cfa_reg = fc->cfa_reg; |
8465 | rs->ra = fc->ra; | |
8466 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 8467 | rs->ncols = fc->ncols; |
3f5e193b | 8468 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 8469 | sizeof (* rs->col_type)); |
d71ad7fc RC |
8470 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
8471 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
8472 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
8473 | rs->next = remembered_state; |
8474 | remembered_state = rs; | |
8475 | break; | |
8476 | ||
8477 | case DW_CFA_restore_state: | |
8478 | if (! do_debug_frames_interp) | |
8479 | printf (" DW_CFA_restore_state\n"); | |
8480 | rs = remembered_state; | |
8481 | if (rs) | |
8482 | { | |
8483 | remembered_state = rs->next; | |
d71ad7fc RC |
8484 | fc->cfa_offset = rs->cfa_offset; |
8485 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
8486 | fc->ra = rs->ra; |
8487 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
8488 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
8489 | { | |
1306a742 | 8490 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
8491 | fc->ncols = 0; |
8492 | break; | |
8493 | } | |
d71ad7fc | 8494 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 8495 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 8496 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
8497 | free (rs->col_type); |
8498 | free (rs->col_offset); | |
8499 | free (rs); | |
8500 | } | |
8501 | else if (do_debug_frames_interp) | |
8502 | printf ("Mismatched DW_CFA_restore_state\n"); | |
8503 | break; | |
8504 | ||
8505 | case DW_CFA_def_cfa: | |
cd30bcef AM |
8506 | READ_ULEB (fc->cfa_reg, start, end); |
8507 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
8508 | fc->cfa_exp = 0; |
8509 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8510 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 8511 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8512 | break; |
8513 | ||
8514 | case DW_CFA_def_cfa_register: | |
cd30bcef | 8515 | READ_ULEB (fc->cfa_reg, start, end); |
19e6b90e L |
8516 | fc->cfa_exp = 0; |
8517 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
8518 | printf (" DW_CFA_def_cfa_register: %s\n", |
8519 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
8520 | break; |
8521 | ||
8522 | case DW_CFA_def_cfa_offset: | |
cd30bcef | 8523 | READ_ULEB (fc->cfa_offset, start, end); |
19e6b90e | 8524 | if (! do_debug_frames_interp) |
c8071705 | 8525 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8526 | break; |
8527 | ||
8528 | case DW_CFA_nop: | |
8529 | if (! do_debug_frames_interp) | |
8530 | printf (" DW_CFA_nop\n"); | |
8531 | break; | |
8532 | ||
8533 | case DW_CFA_def_cfa_expression: | |
cd30bcef | 8534 | READ_ULEB (ul, start, end); |
7460c0ab | 8535 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 8536 | { |
a1165289 | 8537 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8538 | break; |
8539 | } | |
19e6b90e L |
8540 | if (! do_debug_frames_interp) |
8541 | { | |
8542 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
8543 | decode_location_expression (start, eh_addr_size, 0, -1, |
8544 | ul, 0, section); | |
19e6b90e L |
8545 | printf (")\n"); |
8546 | } | |
8547 | fc->cfa_exp = 1; | |
8548 | start += ul; | |
8549 | break; | |
8550 | ||
8551 | case DW_CFA_expression: | |
cd30bcef AM |
8552 | READ_ULEB (reg, start, end); |
8553 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
8554 | if (reg >= (unsigned int) fc->ncols) |
8555 | reg_prefix = bad_reg; | |
6937bb54 | 8556 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 8557 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
8558 | tmp = start + ul; |
8559 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8560 | { |
a1165289 | 8561 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8562 | break; |
8563 | } | |
665ce1f6 | 8564 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 8565 | { |
665ce1f6 L |
8566 | printf (" DW_CFA_expression: %s%s (", |
8567 | reg_prefix, regname (reg, 0)); | |
b7807392 | 8568 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 8569 | ul, 0, section); |
19e6b90e L |
8570 | printf (")\n"); |
8571 | } | |
665ce1f6 L |
8572 | if (*reg_prefix == '\0') |
8573 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 8574 | start = tmp; |
19e6b90e L |
8575 | break; |
8576 | ||
12eae2d3 | 8577 | case DW_CFA_val_expression: |
cd30bcef AM |
8578 | READ_ULEB (reg, start, end); |
8579 | READ_ULEB (ul, start, end); | |
665ce1f6 L |
8580 | if (reg >= (unsigned int) fc->ncols) |
8581 | reg_prefix = bad_reg; | |
362beea4 NC |
8582 | tmp = start + ul; |
8583 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8584 | { |
a1165289 | 8585 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
8586 | break; |
8587 | } | |
665ce1f6 | 8588 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 8589 | { |
665ce1f6 L |
8590 | printf (" DW_CFA_val_expression: %s%s (", |
8591 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
8592 | decode_location_expression (start, eh_addr_size, 0, -1, |
8593 | ul, 0, section); | |
12eae2d3 JJ |
8594 | printf (")\n"); |
8595 | } | |
665ce1f6 L |
8596 | if (*reg_prefix == '\0') |
8597 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 8598 | start = tmp; |
12eae2d3 JJ |
8599 | break; |
8600 | ||
19e6b90e | 8601 | case DW_CFA_offset_extended_sf: |
cd30bcef AM |
8602 | READ_ULEB (reg, start, end); |
8603 | READ_SLEB (l, start, end); | |
665ce1f6 L |
8604 | if (frame_need_space (fc, reg) < 0) |
8605 | reg_prefix = bad_reg; | |
8606 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8607 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
8608 | reg_prefix, regname (reg, 0), | |
c8071705 | 8609 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8610 | if (*reg_prefix == '\0') |
8611 | { | |
8612 | fc->col_type[reg] = DW_CFA_offset; | |
8613 | fc->col_offset[reg] = l * fc->data_factor; | |
8614 | } | |
19e6b90e L |
8615 | break; |
8616 | ||
12eae2d3 | 8617 | case DW_CFA_val_offset_sf: |
cd30bcef AM |
8618 | READ_ULEB (reg, start, end); |
8619 | READ_SLEB (l, start, end); | |
665ce1f6 L |
8620 | if (frame_need_space (fc, reg) < 0) |
8621 | reg_prefix = bad_reg; | |
8622 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8623 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 8624 | reg_prefix, regname (reg, 0), |
c8071705 | 8625 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8626 | if (*reg_prefix == '\0') |
8627 | { | |
8628 | fc->col_type[reg] = DW_CFA_val_offset; | |
8629 | fc->col_offset[reg] = l * fc->data_factor; | |
8630 | } | |
12eae2d3 JJ |
8631 | break; |
8632 | ||
19e6b90e | 8633 | case DW_CFA_def_cfa_sf: |
cd30bcef AM |
8634 | READ_ULEB (fc->cfa_reg, start, end); |
8635 | READ_ULEB (fc->cfa_offset, start, end); | |
19e6b90e L |
8636 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
8637 | fc->cfa_exp = 0; | |
8638 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8639 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 8640 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8641 | break; |
8642 | ||
8643 | case DW_CFA_def_cfa_offset_sf: | |
cd30bcef | 8644 | READ_ULEB (fc->cfa_offset, start, end); |
c8071705 | 8645 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 8646 | if (! do_debug_frames_interp) |
c8071705 | 8647 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8648 | break; |
8649 | ||
8650 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 8651 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
8652 | if (do_debug_frames_interp) |
8653 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8654 | else | |
bf5117e3 NC |
8655 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
8656 | (unsigned long) (ofs * fc->code_factor), | |
8657 | dwarf_vmatoa_1 (NULL, | |
8658 | fc->pc_begin + ofs * fc->code_factor, | |
8659 | fc->ptr_size)); | |
19e6b90e L |
8660 | fc->pc_begin += ofs * fc->code_factor; |
8661 | break; | |
8662 | ||
8663 | case DW_CFA_GNU_window_save: | |
8664 | if (! do_debug_frames_interp) | |
8665 | printf (" DW_CFA_GNU_window_save\n"); | |
8666 | break; | |
8667 | ||
8668 | case DW_CFA_GNU_args_size: | |
cd30bcef | 8669 | READ_ULEB (ul, start, end); |
19e6b90e L |
8670 | if (! do_debug_frames_interp) |
8671 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
8672 | break; | |
8673 | ||
8674 | case DW_CFA_GNU_negative_offset_extended: | |
cd30bcef AM |
8675 | READ_ULEB (reg, start, end); |
8676 | READ_SLEB (l, start, end); | |
7f2c8a1d | 8677 | l = - l; |
665ce1f6 L |
8678 | if (frame_need_space (fc, reg) < 0) |
8679 | reg_prefix = bad_reg; | |
8680 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8681 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
8682 | reg_prefix, regname (reg, 0), | |
c8071705 | 8683 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8684 | if (*reg_prefix == '\0') |
8685 | { | |
8686 | fc->col_type[reg] = DW_CFA_offset; | |
8687 | fc->col_offset[reg] = l * fc->data_factor; | |
8688 | } | |
19e6b90e L |
8689 | break; |
8690 | ||
8691 | default: | |
53b8873b NC |
8692 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
8693 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
8694 | else | |
f41e4712 | 8695 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
8696 | start = block_end; |
8697 | } | |
8698 | } | |
8699 | ||
5b6312fd NC |
8700 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
8701 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
8702 | frame_display_row (fc, &need_col_headers, &max_regs); |
8703 | ||
8704 | start = block_end; | |
604282a7 | 8705 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
8706 | } |
8707 | ||
8708 | printf ("\n"); | |
8709 | ||
3391569f NC |
8710 | while (remembered_state != NULL) |
8711 | { | |
8712 | rs = remembered_state; | |
8713 | remembered_state = rs->next; | |
8714 | free (rs->col_type); | |
8715 | free (rs->col_offset); | |
8716 | rs->next = NULL; /* Paranoia. */ | |
8717 | free (rs); | |
8718 | } | |
8719 | ||
8720 | while (chunks != NULL) | |
8721 | { | |
8722 | rs = chunks; | |
8723 | chunks = rs->next; | |
8724 | free (rs->col_type); | |
8725 | free (rs->col_offset); | |
8726 | rs->next = NULL; /* Paranoia. */ | |
8727 | free (rs); | |
8728 | } | |
8729 | ||
8730 | while (forward_refs != NULL) | |
8731 | { | |
8732 | rs = forward_refs; | |
8733 | forward_refs = rs->next; | |
8734 | free (rs->col_type); | |
8735 | free (rs->col_offset); | |
8736 | rs->next = NULL; /* Paranoia. */ | |
8737 | free (rs); | |
8738 | } | |
8739 | ||
19e6b90e L |
8740 | return 1; |
8741 | } | |
8742 | ||
8743 | #undef GET | |
19e6b90e | 8744 | |
61364358 JK |
8745 | static int |
8746 | display_debug_names (struct dwarf_section *section, void *file) | |
8747 | { | |
8748 | unsigned char *hdrptr = section->start; | |
8749 | dwarf_vma unit_length; | |
8750 | unsigned char *unit_start; | |
8751 | const unsigned char *const section_end = section->start + section->size; | |
8752 | unsigned char *unit_end; | |
8753 | ||
dda8d76d | 8754 | introduce (section, FALSE); |
61364358 | 8755 | |
dda8d76d | 8756 | load_debug_section_with_follow (str, file); |
61364358 JK |
8757 | |
8758 | for (; hdrptr < section_end; hdrptr = unit_end) | |
8759 | { | |
8760 | unsigned int offset_size; | |
8761 | uint16_t dwarf_version, padding; | |
8762 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
8763 | uint32_t bucket_count, name_count, abbrev_table_size; | |
8764 | uint32_t augmentation_string_size; | |
8765 | unsigned int i; | |
e98fdf1a | 8766 | unsigned long sec_off; |
48467cb9 TV |
8767 | bfd_boolean augmentation_printable; |
8768 | const char *augmentation_string; | |
61364358 JK |
8769 | |
8770 | unit_start = hdrptr; | |
8771 | ||
8772 | /* Get and check the length of the block. */ | |
8773 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
8774 | ||
8775 | if (unit_length == 0xffffffff) | |
8776 | { | |
8777 | /* This section is 64-bit DWARF. */ | |
8778 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
8779 | offset_size = 8; | |
8780 | } | |
8781 | else | |
8782 | offset_size = 4; | |
8783 | unit_end = hdrptr + unit_length; | |
8784 | ||
e98fdf1a AM |
8785 | sec_off = hdrptr - section->start; |
8786 | if (sec_off + unit_length < sec_off | |
8787 | || sec_off + unit_length > section->size) | |
61364358 | 8788 | { |
e98fdf1a AM |
8789 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
8790 | section->name, | |
8791 | (unsigned long) (unit_start - section->start), | |
8792 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
8793 | return 0; |
8794 | } | |
8795 | ||
8796 | /* Get and check the version number. */ | |
8797 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
8798 | printf (_("Version %ld\n"), (long) dwarf_version); | |
8799 | ||
8800 | /* Prior versions did not exist, and future versions may not be | |
8801 | backwards compatible. */ | |
8802 | if (dwarf_version != 5) | |
8803 | { | |
8804 | warn (_("Only DWARF version 5 .debug_names " | |
8805 | "is currently supported.\n")); | |
8806 | return 0; | |
8807 | } | |
8808 | ||
8809 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
8810 | if (padding != 0) | |
8811 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
8812 | padding); | |
8813 | ||
8814 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
8815 | if (comp_unit_count == 0) | |
8816 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
8817 | ||
8818 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
8819 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
8820 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
8821 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
8822 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
8823 | ||
8824 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
8825 | if (augmentation_string_size % 4 != 0) | |
8826 | { | |
8827 | warn (_("Augmentation string length %u must be rounded up " | |
8828 | "to a multiple of 4 in .debug_names.\n"), | |
8829 | augmentation_string_size); | |
8830 | augmentation_string_size += (-augmentation_string_size) & 3; | |
8831 | } | |
48467cb9 | 8832 | |
61364358 | 8833 | printf (_("Augmentation string:")); |
48467cb9 TV |
8834 | |
8835 | augmentation_printable = TRUE; | |
8836 | augmentation_string = (const char *) hdrptr; | |
8837 | ||
61364358 JK |
8838 | for (i = 0; i < augmentation_string_size; i++) |
8839 | { | |
8840 | unsigned char uc; | |
8841 | ||
8842 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
8843 | printf (" %02x", uc); | |
48467cb9 TV |
8844 | |
8845 | if (uc != 0 && !ISPRINT (uc)) | |
8846 | augmentation_printable = FALSE; | |
8847 | } | |
8848 | ||
8849 | if (augmentation_printable) | |
8850 | { | |
8851 | printf (" (\""); | |
8852 | for (i = 0; | |
8853 | i < augmentation_string_size && augmentation_string[i]; | |
8854 | ++i) | |
8855 | putchar (augmentation_string[i]); | |
8856 | printf ("\")"); | |
61364358 | 8857 | } |
61364358 JK |
8858 | putchar ('\n'); |
8859 | ||
8860 | printf (_("CU table:\n")); | |
8861 | for (i = 0; i < comp_unit_count; i++) | |
8862 | { | |
8863 | uint64_t cu_offset; | |
8864 | ||
8865 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
8866 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
8867 | } | |
8868 | putchar ('\n'); | |
8869 | ||
8870 | printf (_("TU table:\n")); | |
8871 | for (i = 0; i < local_type_unit_count; i++) | |
8872 | { | |
8873 | uint64_t tu_offset; | |
8874 | ||
8875 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
8876 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
8877 | } | |
8878 | putchar ('\n'); | |
8879 | ||
8880 | printf (_("Foreign TU table:\n")); | |
8881 | for (i = 0; i < foreign_type_unit_count; i++) | |
8882 | { | |
8883 | uint64_t signature; | |
8884 | ||
8885 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
8886 | printf (_("[%3u] "), i); | |
8887 | print_dwarf_vma (signature, 8); | |
8888 | putchar ('\n'); | |
8889 | } | |
8890 | putchar ('\n'); | |
8891 | ||
8892 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
8893 | hdrptr += bucket_count * sizeof (uint32_t); | |
8894 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
8895 | hdrptr += name_count * sizeof (uint32_t); | |
8896 | unsigned char *const name_table_string_offsets = hdrptr; | |
8897 | hdrptr += name_count * offset_size; | |
8898 | unsigned char *const name_table_entry_offsets = hdrptr; | |
8899 | hdrptr += name_count * offset_size; | |
8900 | unsigned char *const abbrev_table = hdrptr; | |
8901 | hdrptr += abbrev_table_size; | |
8902 | const unsigned char *const abbrev_table_end = hdrptr; | |
8903 | unsigned char *const entry_pool = hdrptr; | |
8904 | if (hdrptr > unit_end) | |
8905 | { | |
8906 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
8907 | "for unit 0x%lx in the debug_names\n"), | |
8908 | (long) (hdrptr - section->start), | |
8909 | (long) (unit_end - section->start), | |
8910 | (long) (unit_start - section->start)); | |
8911 | return 0; | |
8912 | } | |
8913 | ||
8914 | size_t buckets_filled = 0; | |
8915 | size_t bucketi; | |
8916 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
8917 | { | |
8918 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
8919 | ||
8920 | if (bucket != 0) | |
8921 | ++buckets_filled; | |
8922 | } | |
d3a49aa8 AM |
8923 | printf (ngettext ("Used %zu of %lu bucket.\n", |
8924 | "Used %zu of %lu buckets.\n", | |
8925 | bucket_count), | |
8926 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 8927 | |
0a79bef4 | 8928 | uint32_t hash_prev = 0; |
61364358 JK |
8929 | size_t hash_clash_count = 0; |
8930 | size_t longest_clash = 0; | |
8931 | size_t this_length = 0; | |
8932 | size_t hashi; | |
8933 | for (hashi = 0; hashi < name_count; hashi++) | |
8934 | { | |
8935 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
8936 | ||
8937 | if (hashi > 0) | |
8938 | { | |
8939 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
8940 | { | |
8941 | ++hash_clash_count; | |
8942 | ++this_length; | |
8943 | longest_clash = MAX (longest_clash, this_length); | |
8944 | } | |
8945 | else | |
8946 | this_length = 0; | |
8947 | } | |
8948 | hash_prev = hash_this; | |
8949 | } | |
8950 | printf (_("Out of %lu items there are %zu bucket clashes" | |
8951 | " (longest of %zu entries).\n"), | |
8952 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
8953 | assert (name_count == buckets_filled + hash_clash_count); | |
8954 | ||
8955 | struct abbrev_lookup_entry | |
8956 | { | |
8957 | dwarf_vma abbrev_tag; | |
8958 | unsigned char *abbrev_lookup_ptr; | |
8959 | }; | |
8960 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
8961 | size_t abbrev_lookup_used = 0; | |
8962 | size_t abbrev_lookup_allocated = 0; | |
8963 | ||
8964 | unsigned char *abbrevptr = abbrev_table; | |
8965 | for (;;) | |
8966 | { | |
cd30bcef AM |
8967 | dwarf_vma abbrev_tag; |
8968 | ||
8969 | READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end); | |
61364358 JK |
8970 | if (abbrev_tag == 0) |
8971 | break; | |
8972 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
8973 | { | |
8974 | abbrev_lookup_allocated = MAX (0x100, | |
8975 | abbrev_lookup_allocated * 2); | |
8976 | abbrev_lookup = xrealloc (abbrev_lookup, | |
8977 | (abbrev_lookup_allocated | |
8978 | * sizeof (*abbrev_lookup))); | |
8979 | } | |
8980 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
8981 | struct abbrev_lookup_entry *entry; | |
8982 | for (entry = abbrev_lookup; | |
8983 | entry < abbrev_lookup + abbrev_lookup_used; | |
8984 | entry++) | |
8985 | if (entry->abbrev_tag == abbrev_tag) | |
8986 | { | |
8987 | warn (_("Duplicate abbreviation tag %lu " | |
8988 | "in unit 0x%lx in the debug_names\n"), | |
8989 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
8990 | break; | |
8991 | } | |
8992 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
8993 | entry->abbrev_tag = abbrev_tag; | |
8994 | entry->abbrev_lookup_ptr = abbrevptr; | |
8995 | ||
8996 | /* Skip DWARF tag. */ | |
cd30bcef | 8997 | SKIP_ULEB (abbrevptr, abbrev_table_end); |
61364358 JK |
8998 | for (;;) |
8999 | { | |
cd30bcef AM |
9000 | dwarf_vma xindex, form; |
9001 | ||
9002 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9003 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9004 | if (xindex == 0 && form == 0) |
61364358 JK |
9005 | break; |
9006 | } | |
9007 | } | |
9008 | ||
9009 | printf (_("\nSymbol table:\n")); | |
9010 | uint32_t namei; | |
9011 | for (namei = 0; namei < name_count; ++namei) | |
9012 | { | |
9013 | uint64_t string_offset, entry_offset; | |
9014 | ||
9015 | SAFE_BYTE_GET (string_offset, | |
9016 | name_table_string_offsets + namei * offset_size, | |
9017 | offset_size, unit_end); | |
9018 | SAFE_BYTE_GET (entry_offset, | |
9019 | name_table_entry_offsets + namei * offset_size, | |
9020 | offset_size, unit_end); | |
9021 | ||
9022 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
9023 | fetch_indirect_string (string_offset)); | |
9024 | ||
9025 | unsigned char *entryptr = entry_pool + entry_offset; | |
9026 | ||
9027 | // We need to scan first whether there is a single or multiple | |
9028 | // entries. TAGNO is -2 for the first entry, it is -1 for the | |
9029 | // initial tag read of the second entry, then it becomes 0 for the | |
9030 | // first entry for real printing etc. | |
9031 | int tagno = -2; | |
9032 | /* Initialize it due to a false compiler warning. */ | |
9033 | dwarf_vma second_abbrev_tag = -1; | |
9034 | for (;;) | |
9035 | { | |
cd30bcef AM |
9036 | dwarf_vma abbrev_tag; |
9037 | dwarf_vma dwarf_tag; | |
9038 | const struct abbrev_lookup_entry *entry; | |
9039 | ||
9040 | READ_ULEB (abbrev_tag, entryptr, unit_end); | |
61364358 JK |
9041 | if (tagno == -1) |
9042 | { | |
9043 | second_abbrev_tag = abbrev_tag; | |
9044 | tagno = 0; | |
9045 | entryptr = entry_pool + entry_offset; | |
9046 | continue; | |
9047 | } | |
9048 | if (abbrev_tag == 0) | |
9049 | break; | |
9050 | if (tagno >= 0) | |
9051 | printf ("%s<%lu>", | |
9052 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
9053 | (unsigned long) abbrev_tag); | |
9054 | ||
61364358 JK |
9055 | for (entry = abbrev_lookup; |
9056 | entry < abbrev_lookup + abbrev_lookup_used; | |
9057 | entry++) | |
9058 | if (entry->abbrev_tag == abbrev_tag) | |
9059 | break; | |
9060 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
9061 | { | |
9062 | warn (_("Undefined abbreviation tag %lu " | |
9063 | "in unit 0x%lx in the debug_names\n"), | |
9064 | (long) abbrev_tag, | |
9065 | (long) (unit_start - section->start)); | |
9066 | break; | |
9067 | } | |
9068 | abbrevptr = entry->abbrev_lookup_ptr; | |
cd30bcef | 9069 | READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end); |
61364358 JK |
9070 | if (tagno >= 0) |
9071 | printf (" %s", get_TAG_name (dwarf_tag)); | |
9072 | for (;;) | |
9073 | { | |
cd30bcef AM |
9074 | dwarf_vma xindex, form; |
9075 | ||
9076 | READ_ULEB (xindex, abbrevptr, abbrev_table_end); | |
9077 | READ_ULEB (form, abbrevptr, abbrev_table_end); | |
1d827a72 | 9078 | if (xindex == 0 && form == 0) |
61364358 JK |
9079 | break; |
9080 | ||
9081 | if (tagno >= 0) | |
1d827a72 | 9082 | printf (" %s", get_IDX_name (xindex)); |
ec1b0fbb NC |
9083 | entryptr = read_and_display_attr_value (0, form, 0, |
9084 | unit_start, entryptr, unit_end, | |
9085 | 0, 0, offset_size, | |
61364358 JK |
9086 | dwarf_version, NULL, |
9087 | (tagno < 0), NULL, | |
ec1b0fbb | 9088 | NULL, '=', -1); |
61364358 JK |
9089 | } |
9090 | ++tagno; | |
9091 | } | |
9092 | if (tagno <= 0) | |
9093 | printf (_(" <no entries>")); | |
9094 | putchar ('\n'); | |
9095 | } | |
9096 | ||
9097 | free (abbrev_lookup); | |
9098 | } | |
9099 | ||
9100 | return 1; | |
9101 | } | |
9102 | ||
dda8d76d | 9103 | static int |
d85bf2ba NC |
9104 | display_debug_links (struct dwarf_section * section, |
9105 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
9106 | { |
9107 | const unsigned char * filename; | |
9108 | unsigned int filelen; | |
9109 | ||
9110 | introduce (section, FALSE); | |
9111 | ||
9112 | /* The .gnu_debuglink section is formatted as: | |
9113 | (c-string) Filename. | |
9114 | (padding) If needed to reach a 4 byte boundary. | |
9115 | (uint32_t) CRC32 value. | |
9116 | ||
9117 | The .gun_debugaltlink section is formatted as: | |
9118 | (c-string) Filename. | |
9119 | (binary) Build-ID. */ | |
9120 | ||
9121 | filename = section->start; | |
9122 | filelen = strnlen ((const char *) filename, section->size); | |
9123 | if (filelen == section->size) | |
9124 | { | |
9125 | warn (_("The debuglink filename is corrupt/missing\n")); | |
9126 | return 0; | |
9127 | } | |
9128 | ||
9129 | printf (_(" Separate debug info file: %s\n"), filename); | |
9130 | ||
9131 | if (const_strneq (section->name, ".gnu_debuglink")) | |
9132 | { | |
9133 | unsigned int crc32; | |
9134 | unsigned int crc_offset; | |
9135 | ||
9136 | crc_offset = filelen + 1; | |
9137 | crc_offset = (crc_offset + 3) & ~3; | |
9138 | if (crc_offset + 4 > section->size) | |
9139 | { | |
9140 | warn (_("CRC offset missing/truncated\n")); | |
9141 | return 0; | |
9142 | } | |
9143 | ||
9144 | crc32 = byte_get (filename + crc_offset, 4); | |
9145 | ||
9146 | printf (_(" CRC value: %#x\n"), crc32); | |
9147 | ||
9148 | if (crc_offset + 4 < section->size) | |
9149 | { | |
9150 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
9151 | (long)(section->size - (crc_offset + 4))); | |
9152 | return 0; | |
9153 | } | |
9154 | } | |
9155 | else /* const_strneq (section->name, ".gnu_debugaltlink") */ | |
9156 | { | |
9157 | const unsigned char * build_id = section->start + filelen + 1; | |
9158 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
9159 | bfd_size_type printed; | |
9160 | ||
9161 | /* FIXME: Should we support smaller build-id notes ? */ | |
9162 | if (build_id_len < 0x14) | |
9163 | { | |
9164 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
9165 | return 0; | |
9166 | } | |
9167 | ||
9168 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 9169 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
9170 | putchar ('\n'); |
9171 | } | |
9172 | ||
9173 | putchar ('\n'); | |
9174 | return 1; | |
9175 | } | |
9176 | ||
5bbdf3d5 DE |
9177 | static int |
9178 | display_gdb_index (struct dwarf_section *section, | |
9179 | void *file ATTRIBUTE_UNUSED) | |
9180 | { | |
9181 | unsigned char *start = section->start; | |
9182 | uint32_t version; | |
9183 | uint32_t cu_list_offset, tu_list_offset; | |
9184 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
9185 | unsigned int cu_list_elements, tu_list_elements; | |
9186 | unsigned int address_table_size, symbol_table_slots; | |
9187 | unsigned char *cu_list, *tu_list; | |
9188 | unsigned char *address_table, *symbol_table, *constant_pool; | |
9189 | unsigned int i; | |
9190 | ||
9191 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
9192 | ||
dda8d76d | 9193 | introduce (section, FALSE); |
5bbdf3d5 DE |
9194 | |
9195 | if (section->size < 6 * sizeof (uint32_t)) | |
9196 | { | |
9197 | warn (_("Truncated header in the %s section.\n"), section->name); | |
9198 | return 0; | |
9199 | } | |
9200 | ||
9201 | version = byte_get_little_endian (start, 4); | |
da88a764 | 9202 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
9203 | |
9204 | /* Prior versions are obsolete, and future versions may not be | |
9205 | backwards compatible. */ | |
aa170720 | 9206 | if (version < 3 || version > 8) |
5bbdf3d5 | 9207 | { |
da88a764 | 9208 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
9209 | return 0; |
9210 | } | |
8d6eee87 TT |
9211 | if (version < 4) |
9212 | warn (_("The address table data in version 3 may be wrong.\n")); | |
9213 | if (version < 5) | |
9214 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
9215 | if (version < 6) | |
9216 | warn (_("Version 5 does not include inlined functions.\n")); | |
9217 | if (version < 7) | |
9218 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
9219 | /* Version 7 indices generated by Gold have bad type unit references, |
9220 | PR binutils/15021. But we don't know if the index was generated by | |
9221 | Gold or not, so to avoid worrying users with gdb-generated indices | |
9222 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
9223 | |
9224 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
9225 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
9226 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
9227 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
9228 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
9229 | ||
9230 | if (cu_list_offset > section->size | |
9231 | || tu_list_offset > section->size | |
9232 | || address_table_offset > section->size | |
9233 | || symbol_table_offset > section->size | |
9234 | || constant_pool_offset > section->size) | |
9235 | { | |
9236 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
9237 | return 0; | |
9238 | } | |
9239 | ||
53774b7e NC |
9240 | /* PR 17531: file: 418d0a8a. */ |
9241 | if (tu_list_offset < cu_list_offset) | |
9242 | { | |
9243 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
9244 | tu_list_offset, cu_list_offset); | |
9245 | return 0; | |
9246 | } | |
9247 | ||
5bbdf3d5 | 9248 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
9249 | |
9250 | if (address_table_offset < tu_list_offset) | |
9251 | { | |
9252 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
9253 | address_table_offset, tu_list_offset); | |
9254 | return 0; | |
9255 | } | |
9256 | ||
5bbdf3d5 | 9257 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
9258 | |
9259 | /* PR 17531: file: 18a47d3d. */ | |
9260 | if (symbol_table_offset < address_table_offset) | |
9261 | { | |
13bace4a | 9262 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
9263 | symbol_table_offset, address_table_offset); |
9264 | return 0; | |
9265 | } | |
9266 | ||
5bbdf3d5 | 9267 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
9268 | |
9269 | if (constant_pool_offset < symbol_table_offset) | |
9270 | { | |
9271 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
9272 | constant_pool_offset, symbol_table_offset); | |
9273 | return 0; | |
9274 | } | |
9275 | ||
5bbdf3d5 DE |
9276 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
9277 | ||
9278 | cu_list = start + cu_list_offset; | |
9279 | tu_list = start + tu_list_offset; | |
9280 | address_table = start + address_table_offset; | |
9281 | symbol_table = start + symbol_table_offset; | |
9282 | constant_pool = start + constant_pool_offset; | |
9283 | ||
28d909e5 | 9284 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 9285 | { |
1306a742 | 9286 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
9287 | return 0; |
9288 | } | |
b4eb7656 | 9289 | |
5bbdf3d5 DE |
9290 | printf (_("\nCU table:\n")); |
9291 | for (i = 0; i < cu_list_elements; i += 2) | |
9292 | { | |
9293 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
9294 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
9295 | ||
9296 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
9297 | (unsigned long) cu_offset, | |
9298 | (unsigned long) (cu_offset + cu_length - 1)); | |
9299 | } | |
9300 | ||
9301 | printf (_("\nTU table:\n")); | |
9302 | for (i = 0; i < tu_list_elements; i += 3) | |
9303 | { | |
9304 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
9305 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
9306 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
9307 | ||
9308 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
9309 | (unsigned long) tu_offset, | |
9310 | (unsigned long) type_offset); | |
9311 | print_dwarf_vma (signature, 8); | |
9312 | printf ("\n"); | |
9313 | } | |
9314 | ||
9315 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
9316 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
9317 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
9318 | { |
9319 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
9320 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
9321 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
9322 | ||
9323 | print_dwarf_vma (low, 8); | |
9324 | print_dwarf_vma (high, 8); | |
da88a764 | 9325 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
9326 | } |
9327 | ||
9328 | printf (_("\nSymbol table:\n")); | |
9329 | for (i = 0; i < symbol_table_slots; ++i) | |
9330 | { | |
9331 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
9332 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
9333 | uint32_t num_cus, cu; | |
9334 | ||
9335 | if (name_offset != 0 | |
9336 | || cu_vector_offset != 0) | |
9337 | { | |
9338 | unsigned int j; | |
362beea4 | 9339 | unsigned char * adr; |
5bbdf3d5 | 9340 | |
362beea4 | 9341 | adr = constant_pool + name_offset; |
53774b7e | 9342 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 9343 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
9344 | { |
9345 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
9346 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
9347 | name_offset, i); | |
9348 | } | |
9349 | else | |
acff9664 NC |
9350 | printf ("[%3u] %.*s:", i, |
9351 | (int) (section->size - (constant_pool_offset + name_offset)), | |
9352 | constant_pool + name_offset); | |
53774b7e | 9353 | |
362beea4 NC |
9354 | adr = constant_pool + cu_vector_offset; |
9355 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
9356 | { |
9357 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
9358 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
9359 | cu_vector_offset, i); | |
9360 | continue; | |
9361 | } | |
57028622 | 9362 | |
362beea4 | 9363 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 9364 | |
362beea4 | 9365 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 9366 | if (num_cus * 4 < num_cus |
362beea4 NC |
9367 | || adr >= section->start + section->size |
9368 | || adr < constant_pool) | |
53774b7e NC |
9369 | { |
9370 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 9371 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
9372 | num_cus, i); |
9373 | continue; | |
9374 | } | |
9375 | ||
8d6eee87 TT |
9376 | if (num_cus > 1) |
9377 | printf ("\n"); | |
f3853b34 | 9378 | |
5bbdf3d5 DE |
9379 | for (j = 0; j < num_cus; ++j) |
9380 | { | |
7c1cef97 | 9381 | int is_static; |
8d6eee87 TT |
9382 | gdb_index_symbol_kind kind; |
9383 | ||
5bbdf3d5 | 9384 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 9385 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
9386 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
9387 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 9388 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 9389 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
9390 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
9391 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 9392 | else |
8d6eee87 TT |
9393 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
9394 | ||
459d52c8 DE |
9395 | printf (" [%s, %s]", |
9396 | is_static ? _("static") : _("global"), | |
9397 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
9398 | if (num_cus > 1) |
9399 | printf ("\n"); | |
5bbdf3d5 | 9400 | } |
8d6eee87 TT |
9401 | if (num_cus <= 1) |
9402 | printf ("\n"); | |
5bbdf3d5 DE |
9403 | } |
9404 | } | |
9405 | ||
9406 | return 1; | |
9407 | } | |
9408 | ||
657d0d47 CC |
9409 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
9410 | ||
9411 | static void | |
9412 | prealloc_cu_tu_list (unsigned int nshndx) | |
9413 | { | |
9414 | if (shndx_pool == NULL) | |
9415 | { | |
9416 | shndx_pool_size = nshndx; | |
9417 | shndx_pool_used = 0; | |
9418 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
9419 | sizeof (unsigned int)); | |
9420 | } | |
9421 | else | |
9422 | { | |
9423 | shndx_pool_size = shndx_pool_used + nshndx; | |
9424 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
9425 | sizeof (unsigned int)); | |
9426 | } | |
9427 | } | |
9428 | ||
9429 | static void | |
9430 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
9431 | { | |
9432 | if (shndx_pool_used >= shndx_pool_size) | |
9433 | { | |
9434 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9435 | return; | |
9436 | } | |
9437 | shndx_pool [shndx_pool_used++] = shndx; | |
9438 | } | |
9439 | ||
9440 | static void | |
9441 | end_cu_tu_entry (void) | |
9442 | { | |
9443 | if (shndx_pool_used >= shndx_pool_size) | |
9444 | { | |
9445 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9446 | return; | |
9447 | } | |
9448 | shndx_pool [shndx_pool_used++] = 0; | |
9449 | } | |
9450 | ||
341f9135 CC |
9451 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
9452 | ||
9453 | static const char * | |
9454 | get_DW_SECT_short_name (unsigned int dw_sect) | |
9455 | { | |
9456 | static char buf[16]; | |
9457 | ||
9458 | switch (dw_sect) | |
9459 | { | |
9460 | case DW_SECT_INFO: | |
9461 | return "info"; | |
9462 | case DW_SECT_TYPES: | |
9463 | return "types"; | |
9464 | case DW_SECT_ABBREV: | |
9465 | return "abbrev"; | |
9466 | case DW_SECT_LINE: | |
9467 | return "line"; | |
9468 | case DW_SECT_LOC: | |
9469 | return "loc"; | |
9470 | case DW_SECT_STR_OFFSETS: | |
9471 | return "str_off"; | |
9472 | case DW_SECT_MACINFO: | |
9473 | return "macinfo"; | |
9474 | case DW_SECT_MACRO: | |
9475 | return "macro"; | |
9476 | default: | |
b4eb7656 | 9477 | break; |
341f9135 CC |
9478 | } |
9479 | ||
9480 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
9481 | return buf; | |
9482 | } | |
9483 | ||
9484 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
9485 | These sections are extensions for Fission. | |
9486 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
9487 | |
9488 | static int | |
9489 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
9490 | { | |
9491 | unsigned char *phdr = section->start; | |
9492 | unsigned char *limit = phdr + section->size; | |
9493 | unsigned char *phash; | |
9494 | unsigned char *pindex; | |
9495 | unsigned char *ppool; | |
9496 | unsigned int version; | |
341f9135 | 9497 | unsigned int ncols = 0; |
657d0d47 CC |
9498 | unsigned int nused; |
9499 | unsigned int nslots; | |
9500 | unsigned int i; | |
341f9135 CC |
9501 | unsigned int j; |
9502 | dwarf_vma signature_high; | |
9503 | dwarf_vma signature_low; | |
9504 | char buf[64]; | |
657d0d47 | 9505 | |
6937bb54 NC |
9506 | /* PR 17512: file: 002-168123-0.004. */ |
9507 | if (phdr == NULL) | |
9508 | { | |
9509 | warn (_("Section %s is empty\n"), section->name); | |
9510 | return 0; | |
9511 | } | |
9512 | /* PR 17512: file: 002-376-0.004. */ | |
9513 | if (section->size < 24) | |
9514 | { | |
72c61a0d | 9515 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
9516 | section->name); |
9517 | return 0; | |
9518 | } | |
9519 | ||
9520 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 9521 | if (version >= 2) |
6937bb54 NC |
9522 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
9523 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
9524 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
9525 | ||
657d0d47 | 9526 | phash = phdr + 16; |
8e2e3c6c AM |
9527 | pindex = phash + (size_t) nslots * 8; |
9528 | ppool = pindex + (size_t) nslots * 4; | |
57028622 | 9529 | |
657d0d47 CC |
9530 | if (do_display) |
9531 | { | |
dda8d76d NC |
9532 | introduce (section, FALSE); |
9533 | ||
8e2e3c6c | 9534 | printf (_(" Version: %u\n"), version); |
341f9135 | 9535 | if (version >= 2) |
8e2e3c6c AM |
9536 | printf (_(" Number of columns: %u\n"), ncols); |
9537 | printf (_(" Number of used entries: %u\n"), nused); | |
9538 | printf (_(" Number of slots: %u\n\n"), nslots); | |
657d0d47 CC |
9539 | } |
9540 | ||
8e2e3c6c AM |
9541 | /* PR 17531: file: 45d69832. */ |
9542 | if ((size_t) nslots * 8 / 8 != nslots | |
9543 | || phash < phdr || phash > limit | |
9544 | || pindex < phash || pindex > limit | |
9545 | || ppool < pindex || ppool > limit) | |
657d0d47 | 9546 | { |
8e2e3c6c AM |
9547 | warn (ngettext ("Section %s is too small for %u slot\n", |
9548 | "Section %s is too small for %u slots\n", | |
9549 | nslots), | |
657d0d47 CC |
9550 | section->name, nslots); |
9551 | return 0; | |
9552 | } | |
9553 | ||
341f9135 | 9554 | if (version == 1) |
657d0d47 | 9555 | { |
341f9135 CC |
9556 | if (!do_display) |
9557 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
9558 | for (i = 0; i < nslots; i++) | |
657d0d47 | 9559 | { |
341f9135 CC |
9560 | unsigned char *shndx_list; |
9561 | unsigned int shndx; | |
9562 | ||
6937bb54 | 9563 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 9564 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 9565 | { |
6937bb54 | 9566 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 9567 | shndx_list = ppool + j * 4; |
f3853b34 NC |
9568 | /* PR 17531: file: 705e010d. */ |
9569 | if (shndx_list < ppool) | |
9570 | { | |
9571 | warn (_("Section index pool located before start of section\n")); | |
9572 | return 0; | |
9573 | } | |
9574 | ||
341f9135 CC |
9575 | if (do_display) |
9576 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
9577 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9578 | buf, sizeof (buf))); | |
9579 | for (;;) | |
657d0d47 | 9580 | { |
341f9135 CC |
9581 | if (shndx_list >= limit) |
9582 | { | |
9583 | warn (_("Section %s too small for shndx pool\n"), | |
9584 | section->name); | |
9585 | return 0; | |
9586 | } | |
6937bb54 | 9587 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
9588 | if (shndx == 0) |
9589 | break; | |
9590 | if (do_display) | |
9591 | printf (" %d", shndx); | |
9592 | else | |
9593 | add_shndx_to_cu_tu_entry (shndx); | |
9594 | shndx_list += 4; | |
657d0d47 | 9595 | } |
657d0d47 | 9596 | if (do_display) |
341f9135 | 9597 | printf ("\n"); |
657d0d47 | 9598 | else |
341f9135 CC |
9599 | end_cu_tu_entry (); |
9600 | } | |
9601 | phash += 8; | |
9602 | pindex += 4; | |
9603 | } | |
9604 | } | |
9605 | else if (version == 2) | |
9606 | { | |
9607 | unsigned int val; | |
9608 | unsigned int dw_sect; | |
9609 | unsigned char *ph = phash; | |
9610 | unsigned char *pi = pindex; | |
8e2e3c6c AM |
9611 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
9612 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
9613 | unsigned char *pend = psizes + (size_t) nused * ncols * 4; | |
341f9135 CC |
9614 | bfd_boolean is_tu_index; |
9615 | struct cu_tu_set *this_set = NULL; | |
9616 | unsigned int row; | |
9617 | unsigned char *prow; | |
9618 | ||
9619 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
9620 | ||
362beea4 | 9621 | /* PR 17531: file: 0dd159bf. |
8e2e3c6c AM |
9622 | Check for integer overflow (can occur when size_t is 32-bit) |
9623 | with overlarge ncols or nused values. */ | |
4ac948a0 NC |
9624 | if (ncols > 0 |
9625 | && ((size_t) ncols * 4 / 4 != ncols | |
9626 | || (size_t) nused * ncols * 4 / ((size_t) ncols * 4) != nused | |
9627 | || poffsets < ppool || poffsets > limit | |
9628 | || psizes < poffsets || psizes > limit | |
9629 | || pend < psizes || pend > limit)) | |
341f9135 CC |
9630 | { |
9631 | warn (_("Section %s too small for offset and size tables\n"), | |
9632 | section->name); | |
9633 | return 0; | |
9634 | } | |
9635 | ||
9636 | if (do_display) | |
9637 | { | |
9638 | printf (_(" Offset table\n")); | |
9639 | printf (" slot %-16s ", | |
9640 | is_tu_index ? _("signature") : _("dwo_id")); | |
9641 | } | |
9642 | else | |
9643 | { | |
9644 | if (is_tu_index) | |
9645 | { | |
9646 | tu_count = nused; | |
72c61a0d | 9647 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 9648 | this_set = tu_sets; |
657d0d47 | 9649 | } |
657d0d47 | 9650 | else |
341f9135 CC |
9651 | { |
9652 | cu_count = nused; | |
72c61a0d | 9653 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
9654 | this_set = cu_sets; |
9655 | } | |
9656 | } | |
6937bb54 | 9657 | |
341f9135 CC |
9658 | if (do_display) |
9659 | { | |
9660 | for (j = 0; j < ncols; j++) | |
9661 | { | |
6937bb54 | 9662 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
9663 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
9664 | } | |
9665 | printf ("\n"); | |
9666 | } | |
6937bb54 | 9667 | |
341f9135 CC |
9668 | for (i = 0; i < nslots; i++) |
9669 | { | |
6937bb54 NC |
9670 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9671 | ||
9672 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9673 | if (row != 0) |
9674 | { | |
591f7597 | 9675 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 9676 | if (row > nused) |
591f7597 NC |
9677 | { |
9678 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
9679 | row, nused); | |
9680 | return 0; | |
9681 | } | |
9682 | ||
341f9135 | 9683 | if (!do_display) |
6aea08d9 NC |
9684 | { |
9685 | size_t num_copy = sizeof (uint64_t); | |
9686 | ||
9687 | /* PR 23064: Beware of buffer overflow. */ | |
9688 | if (ph + num_copy < limit) | |
9689 | memcpy (&this_set[row - 1].signature, ph, num_copy); | |
9690 | else | |
9691 | { | |
9692 | warn (_("Signature (%p) extends beyond end of space in section\n"), ph); | |
9693 | return 0; | |
9694 | } | |
9695 | } | |
6937bb54 | 9696 | |
341f9135 | 9697 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
9698 | /* PR 17531: file: b8ce60a8. */ |
9699 | if (prow < poffsets || prow > limit) | |
9700 | { | |
9701 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
9702 | row, ncols); | |
9703 | return 0; | |
9704 | } | |
3aade688 | 9705 | |
341f9135 CC |
9706 | if (do_display) |
9707 | printf (_(" [%3d] 0x%s"), | |
9708 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9709 | buf, sizeof (buf))); | |
9710 | for (j = 0; j < ncols; j++) | |
9711 | { | |
6937bb54 | 9712 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
9713 | if (do_display) |
9714 | printf (" %8d", val); | |
9715 | else | |
9716 | { | |
6937bb54 | 9717 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
9718 | |
9719 | /* PR 17531: file: 10796eb3. */ | |
9720 | if (dw_sect >= DW_SECT_MAX) | |
9721 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
9722 | else | |
9723 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
9724 | } |
9725 | } | |
6937bb54 | 9726 | |
341f9135 CC |
9727 | if (do_display) |
9728 | printf ("\n"); | |
9729 | } | |
9730 | ph += 8; | |
9731 | pi += 4; | |
9732 | } | |
9733 | ||
9734 | ph = phash; | |
9735 | pi = pindex; | |
9736 | if (do_display) | |
b4eb7656 | 9737 | { |
341f9135 CC |
9738 | printf ("\n"); |
9739 | printf (_(" Size table\n")); | |
9740 | printf (" slot %-16s ", | |
9741 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 9742 | } |
6937bb54 | 9743 | |
341f9135 CC |
9744 | for (j = 0; j < ncols; j++) |
9745 | { | |
6937bb54 | 9746 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
9747 | if (do_display) |
9748 | printf (" %8s", get_DW_SECT_short_name (val)); | |
9749 | } | |
6937bb54 | 9750 | |
341f9135 CC |
9751 | if (do_display) |
9752 | printf ("\n"); | |
6937bb54 | 9753 | |
341f9135 CC |
9754 | for (i = 0; i < nslots; i++) |
9755 | { | |
6937bb54 NC |
9756 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9757 | ||
9758 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9759 | if (row != 0) |
9760 | { | |
9761 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 9762 | |
341f9135 CC |
9763 | if (do_display) |
9764 | printf (_(" [%3d] 0x%s"), | |
9765 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9766 | buf, sizeof (buf))); | |
6937bb54 | 9767 | |
341f9135 CC |
9768 | for (j = 0; j < ncols; j++) |
9769 | { | |
6937bb54 | 9770 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
9771 | if (do_display) |
9772 | printf (" %8d", val); | |
9773 | else | |
9774 | { | |
6937bb54 | 9775 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
9776 | if (dw_sect >= DW_SECT_MAX) |
9777 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
9778 | else | |
341f9135 CC |
9779 | this_set [row - 1].section_sizes [dw_sect] = val; |
9780 | } | |
9781 | } | |
6937bb54 | 9782 | |
341f9135 CC |
9783 | if (do_display) |
9784 | printf ("\n"); | |
9785 | } | |
6937bb54 | 9786 | |
341f9135 CC |
9787 | ph += 8; |
9788 | pi += 4; | |
657d0d47 | 9789 | } |
657d0d47 | 9790 | } |
341f9135 | 9791 | else if (do_display) |
6937bb54 | 9792 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
9793 | |
9794 | if (do_display) | |
9795 | printf ("\n"); | |
9796 | ||
9797 | return 1; | |
9798 | } | |
9799 | ||
9800 | /* Load the CU and TU indexes if present. This will build a list of | |
9801 | section sets that we can use to associate a .debug_info.dwo section | |
9802 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
9803 | ||
43a444f9 | 9804 | static bfd_boolean |
657d0d47 CC |
9805 | load_cu_tu_indexes (void *file) |
9806 | { | |
43a444f9 NC |
9807 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
9808 | ||
657d0d47 CC |
9809 | /* If we have already loaded (or tried to load) the CU and TU indexes |
9810 | then do not bother to repeat the task. */ | |
43a444f9 NC |
9811 | if (cu_tu_indexes_read == -1) |
9812 | { | |
9813 | cu_tu_indexes_read = TRUE; | |
9814 | ||
dda8d76d | 9815 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 NC |
9816 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
9817 | cu_tu_indexes_read = FALSE; | |
9818 | ||
dda8d76d | 9819 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 NC |
9820 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
9821 | cu_tu_indexes_read = FALSE; | |
9822 | } | |
657d0d47 | 9823 | |
43a444f9 | 9824 | return (bfd_boolean) cu_tu_indexes_read; |
657d0d47 CC |
9825 | } |
9826 | ||
9827 | /* Find the set of sections that includes section SHNDX. */ | |
9828 | ||
9829 | unsigned int * | |
9830 | find_cu_tu_set (void *file, unsigned int shndx) | |
9831 | { | |
9832 | unsigned int i; | |
9833 | ||
43a444f9 NC |
9834 | if (! load_cu_tu_indexes (file)) |
9835 | return NULL; | |
657d0d47 CC |
9836 | |
9837 | /* Find SHNDX in the shndx pool. */ | |
9838 | for (i = 0; i < shndx_pool_used; i++) | |
9839 | if (shndx_pool [i] == shndx) | |
9840 | break; | |
9841 | ||
9842 | if (i >= shndx_pool_used) | |
9843 | return NULL; | |
9844 | ||
9845 | /* Now backup to find the first entry in the set. */ | |
9846 | while (i > 0 && shndx_pool [i - 1] != 0) | |
9847 | i--; | |
9848 | ||
9849 | return shndx_pool + i; | |
9850 | } | |
9851 | ||
9852 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
9853 | ||
9854 | static int | |
9855 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
9856 | { | |
9857 | return process_cu_tu_index (section, 1); | |
9858 | } | |
9859 | ||
19e6b90e L |
9860 | static int |
9861 | display_debug_not_supported (struct dwarf_section *section, | |
9862 | void *file ATTRIBUTE_UNUSED) | |
9863 | { | |
9864 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
9865 | section->name); | |
9866 | ||
9867 | return 1; | |
9868 | } | |
9869 | ||
1306a742 NC |
9870 | /* Like malloc, but takes two parameters like calloc. |
9871 | Verifies that the first parameter is not too large. | |
82b1b41b | 9872 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 9873 | |
19e6b90e L |
9874 | void * |
9875 | cmalloc (size_t nmemb, size_t size) | |
9876 | { | |
9877 | /* Check for overflow. */ | |
9878 | if (nmemb >= ~(size_t) 0 / size) | |
9879 | return NULL; | |
82b1b41b NC |
9880 | |
9881 | return xmalloc (nmemb * size); | |
19e6b90e L |
9882 | } |
9883 | ||
1306a742 NC |
9884 | /* Like xmalloc, but takes two parameters like calloc. |
9885 | Verifies that the first parameter is not too large. | |
9886 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 9887 | |
72c61a0d | 9888 | void * |
1306a742 | 9889 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
9890 | { |
9891 | /* Check for overflow. */ | |
9892 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
9893 | { |
9894 | fprintf (stderr, | |
9895 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
9896 | (long) nmemb); | |
9897 | xexit (1); | |
9898 | } | |
72c61a0d | 9899 | |
1306a742 | 9900 | return xmalloc (nmemb * size); |
72c61a0d NC |
9901 | } |
9902 | ||
1306a742 NC |
9903 | /* Like xrealloc, but takes three parameters. |
9904 | Verifies that the second parameter is not too large. | |
9905 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 9906 | |
19e6b90e | 9907 | void * |
1306a742 | 9908 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
9909 | { |
9910 | /* Check for overflow. */ | |
9911 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 9912 | { |
dda8d76d NC |
9913 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
9914 | (long) nmemb); | |
8490fb40 NC |
9915 | xexit (1); |
9916 | } | |
82b1b41b | 9917 | |
1306a742 | 9918 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
9919 | } |
9920 | ||
1306a742 | 9921 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 9922 | |
19e6b90e | 9923 | void * |
1306a742 | 9924 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
9925 | { |
9926 | /* Check for overflow. */ | |
9927 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 9928 | { |
dda8d76d NC |
9929 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
9930 | (long) nmemb); | |
8490fb40 NC |
9931 | xexit (1); |
9932 | } | |
82b1b41b | 9933 | |
1306a742 | 9934 | return xcalloc (nmemb, size); |
19e6b90e L |
9935 | } |
9936 | ||
dda8d76d NC |
9937 | static unsigned long |
9938 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
9939 | const unsigned char * buf, | |
9940 | bfd_size_type len) | |
9941 | { | |
9942 | static const unsigned long crc32_table[256] = | |
9943 | { | |
9944 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
9945 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
9946 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
9947 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
9948 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
9949 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
9950 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
9951 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
9952 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
9953 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
9954 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
9955 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
9956 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
9957 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
9958 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
9959 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
9960 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
9961 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
9962 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
9963 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
9964 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
9965 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
9966 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
9967 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
9968 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
9969 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
9970 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
9971 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
9972 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
9973 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
9974 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
9975 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
9976 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
9977 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
9978 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
9979 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
9980 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
9981 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
9982 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
9983 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
9984 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
9985 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
9986 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
9987 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
9988 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
9989 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
9990 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
9991 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
9992 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
9993 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
9994 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
9995 | 0x2d02ef8d | |
9996 | }; | |
9997 | const unsigned char *end; | |
9998 | ||
9999 | crc = ~crc & 0xffffffff; | |
10000 | for (end = buf + len; buf < end; ++ buf) | |
10001 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
10002 | return ~crc & 0xffffffff; | |
10003 | } | |
10004 | ||
10005 | typedef bfd_boolean (* check_func_type) (const char *, void *); | |
10006 | typedef const char * (* parse_func_type) (struct dwarf_section *, void *); | |
10007 | ||
10008 | static bfd_boolean | |
10009 | check_gnu_debuglink (const char * pathname, void * crc_pointer) | |
10010 | { | |
10011 | static unsigned char buffer [8 * 1024]; | |
10012 | FILE * f; | |
10013 | bfd_size_type count; | |
10014 | unsigned long crc = 0; | |
10015 | void * sep_data; | |
10016 | ||
10017 | sep_data = open_debug_file (pathname); | |
10018 | if (sep_data == NULL) | |
10019 | return FALSE; | |
10020 | ||
10021 | /* Yes - we are opening the file twice... */ | |
10022 | f = fopen (pathname, "rb"); | |
10023 | if (f == NULL) | |
10024 | { | |
10025 | /* Paranoia: This should never happen. */ | |
10026 | close_debug_file (sep_data); | |
10027 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
10028 | return FALSE; | |
10029 | } | |
10030 | ||
10031 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
10032 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
10033 | ||
10034 | fclose (f); | |
10035 | ||
10036 | if (crc != * (unsigned long *) crc_pointer) | |
10037 | { | |
10038 | close_debug_file (sep_data); | |
10039 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
10040 | pathname); | |
10041 | return FALSE; | |
10042 | } | |
10043 | ||
10044 | return TRUE; | |
10045 | } | |
10046 | ||
10047 | static const char * | |
10048 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
10049 | { | |
10050 | const char * name; | |
10051 | unsigned int crc_offset; | |
10052 | unsigned long * crc32 = (unsigned long *) data; | |
10053 | ||
10054 | /* The name is first. | |
10055 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
10056 | name = (const char *) section->start; | |
10057 | ||
39f0547e | 10058 | |
dda8d76d NC |
10059 | crc_offset = strnlen (name, section->size) + 1; |
10060 | crc_offset = (crc_offset + 3) & ~3; | |
10061 | if (crc_offset + 4 > section->size) | |
10062 | return NULL; | |
10063 | ||
10064 | * crc32 = byte_get (section->start + crc_offset, 4); | |
10065 | return name; | |
10066 | } | |
10067 | ||
10068 | static bfd_boolean | |
10069 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) | |
10070 | { | |
10071 | void * sep_data = open_debug_file (filename); | |
10072 | ||
10073 | if (sep_data == NULL) | |
10074 | return FALSE; | |
10075 | ||
10076 | /* FIXME: We should now extract the build-id in the separate file | |
10077 | and check it... */ | |
10078 | ||
10079 | return TRUE; | |
10080 | } | |
10081 | ||
10082 | typedef struct build_id_data | |
10083 | { | |
10084 | bfd_size_type len; | |
10085 | const unsigned char * data; | |
10086 | } Build_id_data; | |
10087 | ||
10088 | static const char * | |
10089 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
10090 | { | |
10091 | const char * name; | |
10092 | bfd_size_type namelen; | |
10093 | bfd_size_type id_len; | |
10094 | Build_id_data * build_id_data; | |
10095 | ||
10096 | /* The name is first. | |
10097 | The build-id follows immediately, with no padding, up to the section's end. */ | |
10098 | ||
10099 | name = (const char *) section->start; | |
10100 | namelen = strnlen (name, section->size) + 1; | |
10101 | if (namelen >= section->size) | |
10102 | return NULL; | |
10103 | ||
10104 | id_len = section->size - namelen; | |
10105 | if (id_len < 0x14) | |
10106 | return NULL; | |
10107 | ||
10108 | build_id_data = calloc (1, sizeof * build_id_data); | |
10109 | if (build_id_data == NULL) | |
10110 | return NULL; | |
10111 | ||
10112 | build_id_data->len = id_len; | |
10113 | build_id_data->data = section->start + namelen; | |
10114 | ||
10115 | * (Build_id_data **) data = build_id_data; | |
10116 | ||
10117 | return name; | |
10118 | } | |
10119 | ||
24841daa NC |
10120 | static void |
10121 | add_separate_debug_file (const char * filename, void * handle) | |
10122 | { | |
10123 | separate_info * i = xmalloc (sizeof * i); | |
10124 | ||
10125 | i->filename = filename; | |
10126 | i->handle = handle; | |
10127 | i->next = first_separate_info; | |
10128 | first_separate_info = i; | |
10129 | } | |
10130 | ||
dda8d76d NC |
10131 | static void * |
10132 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 10133 | struct dwarf_section * xlink, |
dda8d76d NC |
10134 | parse_func_type parse_func, |
10135 | check_func_type check_func, | |
10136 | void * func_data) | |
10137 | { | |
10138 | const char * separate_filename; | |
24841daa | 10139 | char * debug_filename; |
dda8d76d NC |
10140 | char * canon_dir; |
10141 | size_t canon_dirlen; | |
10142 | size_t dirlen; | |
10143 | ||
2b63c337 | 10144 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
10145 | { |
10146 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 10147 | xlink->name ? xlink->name : xlink->uncompressed_name); |
dda8d76d NC |
10148 | return FALSE; |
10149 | } | |
10150 | ||
10151 | /* Attempt to locate the separate file. | |
10152 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
10153 | ||
10154 | canon_dir = lrealpath (main_filename); | |
10155 | ||
10156 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) | |
10157 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
10158 | break; | |
10159 | canon_dir[canon_dirlen] = '\0'; | |
10160 | ||
10161 | #ifndef DEBUGDIR | |
10162 | #define DEBUGDIR "/lib/debug" | |
10163 | #endif | |
10164 | #ifndef EXTRA_DEBUG_ROOT1 | |
10165 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
10166 | #endif | |
10167 | #ifndef EXTRA_DEBUG_ROOT2 | |
10168 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
10169 | #endif | |
10170 | ||
24841daa NC |
10171 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
10172 | + canon_dirlen | |
10173 | + strlen (".debug/") | |
dda8d76d | 10174 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 10175 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
10176 | #endif |
10177 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 10178 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 10179 | #endif |
24841daa NC |
10180 | + strlen (separate_filename) |
10181 | + 1); | |
10182 | if (debug_filename == NULL) | |
dda8d76d NC |
10183 | { |
10184 | warn (_("Out of memory")); | |
3391569f | 10185 | free (canon_dir); |
dda8d76d NC |
10186 | return NULL; |
10187 | } | |
10188 | ||
10189 | /* First try in the current directory. */ | |
24841daa NC |
10190 | sprintf (debug_filename, "%s", separate_filename); |
10191 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10192 | goto found; |
10193 | ||
10194 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
10195 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10196 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10197 | goto found; |
10198 | ||
10199 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
10200 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10201 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10202 | goto found; |
10203 | ||
10204 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
10205 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10206 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10207 | goto found; |
10208 | ||
10209 | #ifdef EXTRA_DEBUG_ROOT1 | |
10210 | /* Try the first extra debug file root. */ | |
24841daa NC |
10211 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10212 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 10213 | goto found; |
39f0547e NC |
10214 | |
10215 | /* Try the first extra debug file root. */ | |
10216 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
10217 | if (check_func (debug_filename, func_data)) | |
10218 | goto found; | |
dda8d76d NC |
10219 | #endif |
10220 | ||
10221 | #ifdef EXTRA_DEBUG_ROOT2 | |
10222 | /* Try the second extra debug file root. */ | |
24841daa NC |
10223 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10224 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10225 | goto found; |
10226 | #endif | |
10227 | ||
24841daa NC |
10228 | /* Then try in the global debug_filename directory. */ |
10229 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
10230 | dirlen = strlen (DEBUGDIR) - 1; |
10231 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
10232 | strcat (debug_filename, "/"); |
10233 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 10234 | |
24841daa | 10235 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
10236 | goto found; |
10237 | ||
10238 | /* Failed to find the file. */ | |
10239 | warn (_("could not find separate debug file '%s'\n"), separate_filename); | |
24841daa | 10240 | warn (_("tried: %s\n"), debug_filename); |
dda8d76d NC |
10241 | |
10242 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa NC |
10243 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10244 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10245 | #endif |
10246 | ||
10247 | #ifdef EXTRA_DEBUG_ROOT1 | |
39f0547e NC |
10248 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); |
10249 | warn (_("tried: %s\n"), debug_filename); | |
10250 | ||
24841daa NC |
10251 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10252 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10253 | #endif |
10254 | ||
24841daa NC |
10255 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10256 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10257 | |
24841daa NC |
10258 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10259 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10260 | |
24841daa NC |
10261 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10262 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10263 | |
24841daa NC |
10264 | sprintf (debug_filename, "%s", separate_filename); |
10265 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10266 | |
10267 | free (canon_dir); | |
24841daa | 10268 | free (debug_filename); |
dda8d76d NC |
10269 | return NULL; |
10270 | ||
10271 | found: | |
10272 | free (canon_dir); | |
10273 | ||
24841daa NC |
10274 | void * debug_handle; |
10275 | ||
dda8d76d | 10276 | /* Now open the file.... */ |
24841daa | 10277 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 10278 | { |
24841daa NC |
10279 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
10280 | free (debug_filename); | |
dda8d76d NC |
10281 | return FALSE; |
10282 | } | |
10283 | ||
10284 | /* FIXME: We do not check to see if there are any other separate debug info | |
10285 | files that would also match. */ | |
10286 | ||
24841daa NC |
10287 | printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debug_filename); |
10288 | add_separate_debug_file (debug_filename, debug_handle); | |
dda8d76d | 10289 | |
24841daa | 10290 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 10291 | the structure returned by open_debug_file(). */ |
24841daa | 10292 | return debug_handle; |
dda8d76d NC |
10293 | } |
10294 | ||
d85bf2ba NC |
10295 | /* Attempt to load a separate dwarf object file. */ |
10296 | ||
10297 | static void * | |
24841daa | 10298 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 10299 | { |
24841daa NC |
10300 | char * separate_filename; |
10301 | void * separate_handle; | |
d85bf2ba NC |
10302 | |
10303 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
24841daa NC |
10304 | separate_filename = concat (dir, "/", name, NULL); |
10305 | if (separate_filename == NULL) | |
d85bf2ba NC |
10306 | { |
10307 | warn (_("Out of memory allocating dwo filename\n")); | |
10308 | return NULL; | |
10309 | } | |
10310 | ||
24841daa | 10311 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 10312 | { |
24841daa NC |
10313 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
10314 | free (separate_filename); | |
d85bf2ba NC |
10315 | return NULL; |
10316 | } | |
10317 | ||
10318 | /* FIXME: We should check the dwo_id. */ | |
10319 | ||
24841daa NC |
10320 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
10321 | add_separate_debug_file (separate_filename, separate_handle); | |
10322 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
10323 | return separate_handle; | |
d85bf2ba NC |
10324 | } |
10325 | ||
24841daa NC |
10326 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
10327 | Returns TRUE if any were found, FALSE otherwise. | |
10328 | If TRUE is returned then the linked list starting at first_separate_info | |
10329 | will be populated with open file handles. */ | |
dda8d76d | 10330 | |
24841daa NC |
10331 | bfd_boolean |
10332 | load_separate_debug_files (void * file, const char * filename) | |
dda8d76d | 10333 | { |
8de3a6e2 NC |
10334 | /* Skip this operation if we are not interested in debug links. */ |
10335 | if (! do_follow_links && ! do_debug_links) | |
24841daa | 10336 | return FALSE; |
8de3a6e2 | 10337 | |
24841daa | 10338 | /* See if there are any dwo links. */ |
d85bf2ba NC |
10339 | if (load_debug_section (str, file) |
10340 | && load_debug_section (abbrev, file) | |
10341 | && load_debug_section (info, file)) | |
10342 | { | |
24841daa | 10343 | free_dwo_info (); |
d85bf2ba NC |
10344 | |
10345 | if (process_debug_info (& debug_displays[info].section, file, abbrev, TRUE, FALSE)) | |
10346 | { | |
24841daa NC |
10347 | bfd_boolean introduced = FALSE; |
10348 | dwo_info * dwinfo; | |
10349 | const char * dir = NULL; | |
10350 | const char * id = NULL; | |
10351 | ||
10352 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 10353 | { |
24841daa | 10354 | switch (dwinfo->type) |
d85bf2ba | 10355 | { |
24841daa NC |
10356 | case DWO_NAME: |
10357 | if (do_debug_links) | |
10358 | { | |
10359 | if (! introduced) | |
10360 | { | |
10361 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
10362 | debug_displays [info].section.uncompressed_name); | |
10363 | introduced = TRUE; | |
10364 | } | |
d85bf2ba | 10365 | |
24841daa NC |
10366 | printf (_(" Name: %s\n"), dwinfo->value); |
10367 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); | |
10368 | if (id != NULL) | |
10369 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
10370 | else | |
10371 | printf (_(" ID: <unknown>\n")); | |
10372 | printf ("\n\n"); | |
10373 | } | |
10374 | ||
10375 | if (do_follow_links) | |
10376 | load_dwo_file (filename, dwinfo->value, dir, id); | |
10377 | break; | |
10378 | ||
10379 | case DWO_DIR: | |
10380 | dir = dwinfo->value; | |
10381 | break; | |
10382 | ||
10383 | case DWO_ID: | |
10384 | id = dwinfo->value; | |
10385 | break; | |
10386 | ||
10387 | default: | |
10388 | error (_("Unexpected DWO INFO type")); | |
10389 | break; | |
10390 | } | |
d85bf2ba NC |
10391 | } |
10392 | } | |
10393 | } | |
10394 | ||
dda8d76d | 10395 | if (! do_follow_links) |
8de3a6e2 NC |
10396 | /* The other debug links will be displayed by display_debug_links() |
10397 | so we do not need to do any further processing here. */ | |
24841daa | 10398 | return FALSE; |
dda8d76d NC |
10399 | |
10400 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
10401 | /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */ | |
10402 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ | |
d85bf2ba | 10403 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 10404 | |
dda8d76d NC |
10405 | if (load_debug_section (gnu_debugaltlink, file)) |
10406 | { | |
10407 | Build_id_data * build_id_data; | |
10408 | ||
24841daa NC |
10409 | load_separate_debug_info (filename, |
10410 | & debug_displays[gnu_debugaltlink].section, | |
10411 | parse_gnu_debugaltlink, | |
10412 | check_gnu_debugaltlink, | |
10413 | & build_id_data); | |
dda8d76d NC |
10414 | } |
10415 | ||
10416 | if (load_debug_section (gnu_debuglink, file)) | |
10417 | { | |
10418 | unsigned long crc32; | |
10419 | ||
24841daa NC |
10420 | load_separate_debug_info (filename, |
10421 | & debug_displays[gnu_debuglink].section, | |
10422 | parse_gnu_debuglink, | |
10423 | check_gnu_debuglink, | |
10424 | & crc32); | |
dda8d76d NC |
10425 | } |
10426 | ||
24841daa NC |
10427 | if (first_separate_info != NULL) |
10428 | return TRUE; | |
10429 | ||
dda8d76d | 10430 | do_follow_links = 0; |
24841daa | 10431 | return FALSE; |
dda8d76d NC |
10432 | } |
10433 | ||
19e6b90e L |
10434 | void |
10435 | free_debug_memory (void) | |
10436 | { | |
3f5e193b | 10437 | unsigned int i; |
19e6b90e L |
10438 | |
10439 | free_abbrevs (); | |
10440 | ||
10441 | for (i = 0; i < max; i++) | |
3f5e193b | 10442 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 10443 | |
cc86f28f | 10444 | if (debug_information != NULL) |
19e6b90e | 10445 | { |
cc86f28f | 10446 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) |
19e6b90e | 10447 | { |
cc86f28f | 10448 | for (i = 0; i < num_debug_info_entries; i++) |
19e6b90e | 10449 | { |
cc86f28f NC |
10450 | if (!debug_information [i].max_loc_offsets) |
10451 | { | |
10452 | free (debug_information [i].loc_offsets); | |
10453 | free (debug_information [i].have_frame_base); | |
10454 | } | |
10455 | if (!debug_information [i].max_range_lists) | |
10456 | free (debug_information [i].range_lists); | |
19e6b90e | 10457 | } |
19e6b90e L |
10458 | } |
10459 | free (debug_information); | |
10460 | debug_information = NULL; | |
82b1b41b | 10461 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 10462 | } |
dda8d76d | 10463 | |
24841daa NC |
10464 | separate_info * d; |
10465 | separate_info * next; | |
dda8d76d | 10466 | |
24841daa NC |
10467 | for (d = first_separate_info; d != NULL; d = next) |
10468 | { | |
10469 | close_debug_file (d->handle); | |
10470 | free ((void *) d->filename); | |
10471 | next = d->next; | |
10472 | free ((void *) d); | |
dda8d76d | 10473 | } |
24841daa NC |
10474 | first_separate_info = NULL; |
10475 | ||
10476 | free_dwo_info (); | |
19e6b90e L |
10477 | } |
10478 | ||
4cb93e3b TG |
10479 | void |
10480 | dwarf_select_sections_by_names (const char *names) | |
10481 | { | |
10482 | typedef struct | |
10483 | { | |
10484 | const char * option; | |
10485 | int * variable; | |
f9f0e732 | 10486 | int val; |
4cb93e3b TG |
10487 | } |
10488 | debug_dump_long_opts; | |
10489 | ||
10490 | static const debug_dump_long_opts opts_table [] = | |
10491 | { | |
10492 | /* Please keep this table alpha- sorted. */ | |
10493 | { "Ranges", & do_debug_ranges, 1 }, | |
10494 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 10495 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 10496 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
10497 | { "cu_index", & do_debug_cu_index, 1 }, |
10498 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 10499 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
10500 | { "frames", & do_debug_frames, 1 }, |
10501 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
10502 | /* The special .gdb_index section. */ |
10503 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
10504 | { "info", & do_debug_info, 1 }, |
10505 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 10506 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
10507 | { "loc", & do_debug_loc, 1 }, |
10508 | { "macro", & do_debug_macinfo, 1 }, | |
10509 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 10510 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 10511 | /* This entry is for compatibility |
4cb93e3b TG |
10512 | with earlier versions of readelf. */ |
10513 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 10514 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 10515 | { "str", & do_debug_str, 1 }, |
6f875884 TG |
10516 | /* These trace_* sections are used by Itanium VMS. */ |
10517 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
10518 | { "trace_aranges", & do_trace_aranges, 1 }, | |
10519 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
10520 | { NULL, NULL, 0 } |
10521 | }; | |
10522 | ||
10523 | const char *p; | |
467c65bc | 10524 | |
4cb93e3b TG |
10525 | p = names; |
10526 | while (*p) | |
10527 | { | |
10528 | const debug_dump_long_opts * entry; | |
467c65bc | 10529 | |
4cb93e3b TG |
10530 | for (entry = opts_table; entry->option; entry++) |
10531 | { | |
10532 | size_t len = strlen (entry->option); | |
467c65bc | 10533 | |
4cb93e3b TG |
10534 | if (strncmp (p, entry->option, len) == 0 |
10535 | && (p[len] == ',' || p[len] == '\0')) | |
10536 | { | |
10537 | * entry->variable |= entry->val; | |
467c65bc | 10538 | |
4cb93e3b TG |
10539 | /* The --debug-dump=frames-interp option also |
10540 | enables the --debug-dump=frames option. */ | |
10541 | if (do_debug_frames_interp) | |
10542 | do_debug_frames = 1; | |
10543 | ||
10544 | p += len; | |
10545 | break; | |
10546 | } | |
10547 | } | |
467c65bc | 10548 | |
4cb93e3b TG |
10549 | if (entry->option == NULL) |
10550 | { | |
10551 | warn (_("Unrecognized debug option '%s'\n"), p); | |
10552 | p = strchr (p, ','); | |
10553 | if (p == NULL) | |
10554 | break; | |
10555 | } | |
467c65bc | 10556 | |
4cb93e3b TG |
10557 | if (*p == ',') |
10558 | p++; | |
10559 | } | |
10560 | } | |
10561 | ||
10562 | void | |
10563 | dwarf_select_sections_by_letters (const char *letters) | |
10564 | { | |
91d6fa6a | 10565 | unsigned int lindex = 0; |
4cb93e3b | 10566 | |
91d6fa6a NC |
10567 | while (letters[lindex]) |
10568 | switch (letters[lindex++]) | |
4cb93e3b | 10569 | { |
dda8d76d NC |
10570 | case 'A': do_debug_addr = 1; break; |
10571 | case 'a': do_debug_abbrevs = 1; break; | |
10572 | case 'c': do_debug_cu_index = 1; break; | |
10573 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
10574 | case 'f': do_debug_frames = 1; break; | |
10575 | case 'g': do_gdb_index = 1; break; | |
10576 | case 'i': do_debug_info = 1; break; | |
10577 | case 'K': do_follow_links = 1; break; | |
10578 | case 'k': do_debug_links = 1; break; | |
10579 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
10580 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
10581 | case 'm': do_debug_macinfo = 1; break; | |
10582 | case 'o': do_debug_loc = 1; break; | |
10583 | case 'p': do_debug_pubnames = 1; break; | |
10584 | case 'R': do_debug_ranges = 1; break; | |
10585 | case 'r': do_debug_aranges = 1; break; | |
10586 | case 's': do_debug_str = 1; break; | |
10587 | case 'T': do_trace_aranges = 1; break; | |
10588 | case 't': do_debug_pubtypes = 1; break; | |
10589 | case 'U': do_trace_info = 1; break; | |
10590 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 10591 | |
4cb93e3b | 10592 | default: |
7cc78d07 | 10593 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
10594 | break; |
10595 | } | |
10596 | } | |
10597 | ||
10598 | void | |
10599 | dwarf_select_sections_all (void) | |
10600 | { | |
10601 | do_debug_info = 1; | |
10602 | do_debug_abbrevs = 1; | |
10603 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
10604 | do_debug_pubnames = 1; | |
f9f0e732 | 10605 | do_debug_pubtypes = 1; |
4cb93e3b TG |
10606 | do_debug_aranges = 1; |
10607 | do_debug_ranges = 1; | |
10608 | do_debug_frames = 1; | |
10609 | do_debug_macinfo = 1; | |
10610 | do_debug_str = 1; | |
10611 | do_debug_loc = 1; | |
5bbdf3d5 | 10612 | do_gdb_index = 1; |
6f875884 TG |
10613 | do_trace_info = 1; |
10614 | do_trace_abbrevs = 1; | |
10615 | do_trace_aranges = 1; | |
657d0d47 CC |
10616 | do_debug_addr = 1; |
10617 | do_debug_cu_index = 1; | |
dda8d76d NC |
10618 | do_follow_links = 1; |
10619 | do_debug_links = 1; | |
4cb93e3b TG |
10620 | } |
10621 | ||
dda8d76d NC |
10622 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL |
10623 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL | |
10624 | ||
10625 | /* N.B. The order here must match the order in section_display_enum. */ | |
10626 | ||
19e6b90e L |
10627 | struct dwarf_section_display debug_displays[] = |
10628 | { | |
dda8d76d NC |
10629 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, |
10630 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE }, | |
10631 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
10632 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE }, | |
10633 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
10634 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE }, | |
10635 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, | |
10636 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
10637 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
10638 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
10639 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
10640 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
10641 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10642 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10643 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE }, | |
10644 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, | |
10645 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
10646 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
10647 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10648 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10649 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE }, | |
10650 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10651 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE }, | |
10652 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE }, | |
10653 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE }, | |
10654 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE }, | |
10655 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE }, | |
10656 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE }, | |
10657 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
10658 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE }, | |
10659 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
10660 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10661 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
10662 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
10663 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE }, | |
10664 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, | |
10665 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, | |
10666 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE }, | |
10667 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
10668 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
10669 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
10670 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
10671 | /* Separate debug info files can containt their own .debug_str section, | |
10672 | and this might be in *addition* to a .debug_str section already present | |
10673 | in the main file. Hence we need to have two entries for .debug_str. */ | |
10674 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
19e6b90e | 10675 | }; |
b451e98a JK |
10676 | |
10677 | /* A static assertion. */ | |
10678 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |