Commit | Line | Data |
---|---|---|
19e6b90e | 1 | /* dwarf.c -- display DWARF contents of a BFD binary file |
82704155 | 2 | Copyright (C) 2005-2019 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. | |
322 | No bytes will be read at address END or beyond. */ | |
323 | ||
467c65bc | 324 | dwarf_vma |
f6f0e17b NC |
325 | read_leb128 (unsigned char *data, |
326 | unsigned int *length_return, | |
327 | bfd_boolean sign, | |
328 | const unsigned char * const end) | |
19e6b90e | 329 | { |
467c65bc | 330 | dwarf_vma result = 0; |
19e6b90e L |
331 | unsigned int num_read = 0; |
332 | unsigned int shift = 0; | |
f6f0e17b | 333 | unsigned char byte = 0; |
19e6b90e | 334 | |
f6f0e17b | 335 | while (data < end) |
19e6b90e L |
336 | { |
337 | byte = *data++; | |
338 | num_read++; | |
339 | ||
467c65bc | 340 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; |
19e6b90e L |
341 | |
342 | shift += 7; | |
f6f0e17b NC |
343 | if ((byte & 0x80) == 0) |
344 | break; | |
77ef8654 NC |
345 | |
346 | /* PR 17512: file: 0ca183b8. | |
347 | FIXME: Should we signal this error somehow ? */ | |
f641dd96 | 348 | if (shift >= sizeof (result) * 8) |
77ef8654 | 349 | break; |
19e6b90e | 350 | } |
19e6b90e L |
351 | |
352 | if (length_return != NULL) | |
353 | *length_return = num_read; | |
354 | ||
355 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) | |
c4e0beac | 356 | result |= -((dwarf_vma) 1 << shift); |
19e6b90e L |
357 | |
358 | return result; | |
359 | } | |
360 | ||
467c65bc | 361 | /* Create a signed version to avoid painful typecasts. */ |
f6f0e17b NC |
362 | static inline dwarf_signed_vma |
363 | read_sleb128 (unsigned char * data, | |
364 | unsigned int * length_return, | |
365 | const unsigned char * const end) | |
366 | { | |
367 | return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end); | |
368 | } | |
369 | ||
370 | static inline dwarf_vma | |
371 | read_uleb128 (unsigned char * data, | |
372 | unsigned int * length_return, | |
373 | const unsigned char * const end) | |
467c65bc | 374 | { |
f6f0e17b | 375 | return read_leb128 (data, length_return, FALSE, end); |
467c65bc NC |
376 | } |
377 | ||
7f2c8a1d NC |
378 | #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return |
379 | #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return | |
380 | ||
381 | #define READ_ULEB(var) \ | |
382 | do \ | |
383 | { \ | |
384 | dwarf_vma _val; \ | |
385 | \ | |
386 | (var) = _val = read_uleb128 (start, &length_return, end); \ | |
387 | if ((var) != _val) \ | |
66cfc0fd AM |
388 | error (_("Internal error: %s:%d: LEB value (%s) " \ |
389 | "too large for containing variable\n"), \ | |
390 | __FILE__, __LINE__, dwarf_vmatoa ("u", _val)); \ | |
7f2c8a1d NC |
391 | start += length_return; \ |
392 | } \ | |
393 | while (0) | |
394 | ||
395 | #define READ_SLEB(var) \ | |
396 | do \ | |
397 | { \ | |
398 | dwarf_signed_vma _val; \ | |
399 | \ | |
400 | (var) = _val = read_sleb128 (start, &length_return, end); \ | |
401 | if ((var) != _val) \ | |
66cfc0fd AM |
402 | error (_("Internal error: %s:%d: LEB value (%s) " \ |
403 | "too large for containing variable\n"), \ | |
404 | __FILE__, __LINE__, dwarf_vmatoa ("d", _val)); \ | |
7f2c8a1d NC |
405 | start += length_return; \ |
406 | } \ | |
407 | while (0) | |
408 | ||
d11ae95e NC |
409 | /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value. |
410 | Checks to make sure that the read will not reach or pass END | |
411 | and that VAL is big enough to hold AMOUNT bytes. */ | |
0c588247 NC |
412 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
413 | do \ | |
414 | { \ | |
415 | unsigned int amount = (AMOUNT); \ | |
34b9f729 NC |
416 | if (sizeof (VAL) < amount) \ |
417 | { \ | |
d3a49aa8 AM |
418 | error (ngettext ("internal error: attempt to read %d byte " \ |
419 | "of data in to %d sized variable", \ | |
420 | "internal error: attempt to read %d bytes " \ | |
421 | "of data in to %d sized variable", \ | |
422 | amount), \ | |
34b9f729 NC |
423 | amount, (int) sizeof (VAL)); \ |
424 | amount = sizeof (VAL); \ | |
425 | } \ | |
0c588247 NC |
426 | if (((PTR) + amount) >= (END)) \ |
427 | { \ | |
428 | if ((PTR) < (END)) \ | |
429 | amount = (END) - (PTR); \ | |
430 | else \ | |
431 | amount = 0; \ | |
432 | } \ | |
6937bb54 | 433 | if (amount == 0 || amount > 8) \ |
0c588247 | 434 | VAL = 0; \ |
6937bb54 NC |
435 | else \ |
436 | VAL = byte_get ((PTR), amount); \ | |
0c588247 NC |
437 | } \ |
438 | while (0) | |
439 | ||
d11ae95e | 440 | /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
441 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
442 | do \ | |
443 | { \ | |
444 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
445 | PTR += AMOUNT; \ | |
446 | } \ | |
447 | while (0) | |
448 | ||
d11ae95e | 449 | /* Like SAFE_BYTE_GET, but reads a signed value. */ |
0c588247 NC |
450 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
451 | do \ | |
452 | { \ | |
453 | unsigned int amount = (AMOUNT); \ | |
454 | if (((PTR) + amount) >= (END)) \ | |
455 | { \ | |
456 | if ((PTR) < (END)) \ | |
457 | amount = (END) - (PTR); \ | |
458 | else \ | |
459 | amount = 0; \ | |
460 | } \ | |
461 | if (amount) \ | |
462 | VAL = byte_get_signed ((PTR), amount); \ | |
463 | else \ | |
464 | VAL = 0; \ | |
465 | } \ | |
466 | while (0) | |
467 | ||
d11ae95e | 468 | /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
469 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
470 | do \ | |
471 | { \ | |
472 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
473 | PTR += AMOUNT; \ | |
474 | } \ | |
475 | while (0) | |
476 | ||
477 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ | |
478 | do \ | |
479 | { \ | |
87bc83b3 | 480 | if (((PTR) + 8) <= (END)) \ |
0c588247 NC |
481 | { \ |
482 | byte_get_64 ((PTR), (HIGH), (LOW)); \ | |
483 | } \ | |
484 | else \ | |
485 | { \ | |
0c588247 NC |
486 | * (LOW) = * (HIGH) = 0; \ |
487 | } \ | |
488 | } \ | |
489 | while (0) | |
490 | ||
19e6b90e L |
491 | typedef struct State_Machine_Registers |
492 | { | |
467c65bc | 493 | dwarf_vma address; |
ba8826a8 | 494 | unsigned int view; |
19e6b90e L |
495 | unsigned int file; |
496 | unsigned int line; | |
497 | unsigned int column; | |
498 | int is_stmt; | |
499 | int basic_block; | |
a233b20c JJ |
500 | unsigned char op_index; |
501 | unsigned char end_sequence; | |
ba8826a8 AO |
502 | /* This variable hold the number of the last entry seen |
503 | in the File Table. */ | |
19e6b90e L |
504 | unsigned int last_file_entry; |
505 | } SMR; | |
506 | ||
507 | static SMR state_machine_regs; | |
508 | ||
509 | static void | |
510 | reset_state_machine (int is_stmt) | |
511 | { | |
512 | state_machine_regs.address = 0; | |
ba8826a8 | 513 | state_machine_regs.view = 0; |
a233b20c | 514 | state_machine_regs.op_index = 0; |
19e6b90e L |
515 | state_machine_regs.file = 1; |
516 | state_machine_regs.line = 1; | |
517 | state_machine_regs.column = 0; | |
518 | state_machine_regs.is_stmt = is_stmt; | |
519 | state_machine_regs.basic_block = 0; | |
520 | state_machine_regs.end_sequence = 0; | |
521 | state_machine_regs.last_file_entry = 0; | |
522 | } | |
523 | ||
524 | /* Handled an extend line op. | |
525 | Returns the number of bytes read. */ | |
526 | ||
527 | static int | |
f6f0e17b NC |
528 | process_extended_line_op (unsigned char * data, |
529 | int is_stmt, | |
530 | unsigned char * end) | |
19e6b90e L |
531 | { |
532 | unsigned char op_code; | |
533 | unsigned int bytes_read; | |
534 | unsigned int len; | |
535 | unsigned char *name; | |
143a3db0 | 536 | unsigned char *orig_data = data; |
f6f0e17b | 537 | dwarf_vma adr; |
19e6b90e | 538 | |
f6f0e17b | 539 | len = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
540 | data += bytes_read; |
541 | ||
e44c58ce | 542 | if (len == 0 || data == end || len > (uintptr_t) (end - data)) |
19e6b90e | 543 | { |
f41e4712 | 544 | warn (_("Badly formed extended line op encountered!\n")); |
19e6b90e L |
545 | return bytes_read; |
546 | } | |
547 | ||
548 | len += bytes_read; | |
549 | op_code = *data++; | |
550 | ||
551 | printf (_(" Extended opcode %d: "), op_code); | |
552 | ||
553 | switch (op_code) | |
554 | { | |
555 | case DW_LNE_end_sequence: | |
556 | printf (_("End of Sequence\n\n")); | |
557 | reset_state_machine (is_stmt); | |
558 | break; | |
559 | ||
560 | case DW_LNE_set_address: | |
6937bb54 NC |
561 | /* PR 17512: file: 002-100480-0.004. */ |
562 | if (len - bytes_read - 1 > 8) | |
77ef8654 NC |
563 | { |
564 | warn (_("Length (%d) of DW_LNE_set_address op is too long\n"), | |
565 | len - bytes_read - 1); | |
566 | adr = 0; | |
567 | } | |
568 | else | |
569 | SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end); | |
47704ddf | 570 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 571 | state_machine_regs.address = adr; |
ba8826a8 | 572 | state_machine_regs.view = 0; |
a233b20c | 573 | state_machine_regs.op_index = 0; |
19e6b90e L |
574 | break; |
575 | ||
576 | case DW_LNE_define_file: | |
143a3db0 | 577 | printf (_("define new File Table entry\n")); |
19e6b90e | 578 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 579 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 580 | |
d949ff56 NC |
581 | { |
582 | size_t l; | |
583 | ||
584 | name = data; | |
585 | l = strnlen ((char *) data, end - data); | |
586 | data += len + 1; | |
587 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
588 | data += bytes_read; | |
589 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
590 | data += bytes_read; | |
591 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
592 | data += bytes_read; | |
593 | printf ("%.*s\n\n", (int) l, name); | |
594 | } | |
f6f0e17b NC |
595 | |
596 | if (((unsigned int) (data - orig_data) != len) || data == end) | |
b4eb7656 | 597 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
598 | break; |
599 | ||
ed4a4bdf | 600 | case DW_LNE_set_discriminator: |
47704ddf | 601 | printf (_("set Discriminator to %s\n"), |
f6f0e17b | 602 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
ed4a4bdf CC |
603 | break; |
604 | ||
e2a0d921 NC |
605 | /* HP extensions. */ |
606 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 607 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
608 | break; |
609 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 610 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
611 | break; |
612 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 613 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
614 | break; |
615 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 616 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
617 | break; |
618 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 619 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
620 | break; |
621 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 622 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
623 | break; |
624 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 625 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
626 | break; |
627 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 628 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
629 | break; |
630 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 631 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
632 | break; |
633 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 634 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 635 | break; |
43294ab7 TG |
636 | case DW_LNE_HP_source_file_correlation: |
637 | { | |
b4eb7656 AM |
638 | unsigned char *edata = data + len - bytes_read - 1; |
639 | ||
640 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
641 | ||
642 | while (data < edata) | |
643 | { | |
644 | unsigned int opc; | |
645 | ||
646 | opc = read_uleb128 (data, & bytes_read, edata); | |
647 | data += bytes_read; | |
648 | ||
649 | switch (opc) | |
650 | { | |
651 | case DW_LNE_HP_SFC_formfeed: | |
652 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
653 | break; | |
654 | case DW_LNE_HP_SFC_set_listing_line: | |
655 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", | |
656 | dwarf_vmatoa ("u", | |
657 | read_uleb128 (data, & bytes_read, edata))); | |
658 | data += bytes_read; | |
659 | break; | |
660 | case DW_LNE_HP_SFC_associate: | |
661 | printf (" DW_LNE_HP_SFC_associate "); | |
662 | printf ("(%s", | |
663 | dwarf_vmatoa ("u", | |
664 | read_uleb128 (data, & bytes_read, edata))); | |
665 | data += bytes_read; | |
666 | printf (",%s", | |
667 | dwarf_vmatoa ("u", | |
668 | read_uleb128 (data, & bytes_read, edata))); | |
669 | data += bytes_read; | |
670 | printf (",%s)\n", | |
671 | dwarf_vmatoa ("u", | |
672 | read_uleb128 (data, & bytes_read, edata))); | |
673 | data += bytes_read; | |
674 | break; | |
675 | default: | |
676 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
677 | data = edata; | |
678 | break; | |
679 | } | |
680 | } | |
43294ab7 TG |
681 | } |
682 | break; | |
cecf136e | 683 | |
19e6b90e | 684 | default: |
7e665af3 | 685 | { |
b4eb7656 AM |
686 | unsigned int rlen = len - bytes_read - 1; |
687 | ||
688 | if (op_code >= DW_LNE_lo_user | |
689 | /* The test against DW_LNW_hi_user is redundant due to | |
690 | the limited range of the unsigned char data type used | |
691 | for op_code. */ | |
692 | /*&& op_code <= DW_LNE_hi_user*/) | |
693 | printf (_("user defined: ")); | |
694 | else | |
695 | printf (_("UNKNOWN: ")); | |
696 | printf (_("length %d ["), rlen); | |
697 | for (; rlen; rlen--) | |
698 | printf (" %02x", *data++); | |
699 | printf ("]\n"); | |
7e665af3 | 700 | } |
19e6b90e L |
701 | break; |
702 | } | |
703 | ||
704 | return len; | |
705 | } | |
706 | ||
0c588247 | 707 | static const unsigned char * |
467c65bc | 708 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
709 | { |
710 | struct dwarf_section *section = &debug_displays [str].section; | |
d949ff56 | 711 | const unsigned char * ret; |
19e6b90e L |
712 | |
713 | if (section->start == NULL) | |
0c588247 | 714 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e | 715 | |
d949ff56 | 716 | if (offset >= section->size) |
19e6b90e | 717 | { |
467c65bc NC |
718 | warn (_("DW_FORM_strp offset too big: %s\n"), |
719 | dwarf_vmatoa ("x", offset)); | |
0c588247 | 720 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
721 | } |
722 | ||
d949ff56 NC |
723 | ret = section->start + offset; |
724 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
725 | NUL byte. Since our caller is expecting to receive a well formed C | |
726 | string we test for the lack of a terminating byte here. */ | |
727 | if (strnlen ((const char *) ret, section->size - offset) | |
728 | == section->size - offset) | |
729 | ret = (const unsigned char *) | |
730 | _("<no NUL byte at end of .debug_str section>"); | |
731 | ||
732 | return ret; | |
19e6b90e L |
733 | } |
734 | ||
77145576 JK |
735 | static const unsigned char * |
736 | fetch_indirect_line_string (dwarf_vma offset) | |
737 | { | |
738 | struct dwarf_section *section = &debug_displays [line_str].section; | |
d949ff56 | 739 | const unsigned char * ret; |
77145576 JK |
740 | |
741 | if (section->start == NULL) | |
742 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
743 | ||
d949ff56 | 744 | if (offset >= section->size) |
77145576 JK |
745 | { |
746 | warn (_("DW_FORM_line_strp offset too big: %s\n"), | |
747 | dwarf_vmatoa ("x", offset)); | |
748 | return (const unsigned char *) _("<offset is too big>"); | |
749 | } | |
750 | ||
d949ff56 NC |
751 | ret = section->start + offset; |
752 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
753 | with a NUL byte. Since our caller is expecting to receive a well formed | |
754 | C string we test for the lack of a terminating byte here. */ | |
755 | if (strnlen ((const char *) ret, section->size - offset) | |
756 | == section->size - offset) | |
757 | ret = (const unsigned char *) | |
758 | _("<no NUL byte at end of .debug_line_str section>"); | |
759 | ||
760 | return ret; | |
77145576 JK |
761 | } |
762 | ||
4723351a | 763 | static const char * |
341f9135 | 764 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
d85bf2ba | 765 | dwarf_vma offset_size, bfd_boolean dwo) |
4723351a CC |
766 | { |
767 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
768 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
769 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
770 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
771 | dwarf_vma index_offset = idx * offset_size; | |
772 | dwarf_vma str_offset; | |
d949ff56 | 773 | const char * ret; |
4723351a CC |
774 | |
775 | if (index_section->start == NULL) | |
776 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
777 | : _("<no .debug_str_offsets section>")); | |
778 | ||
341f9135 CC |
779 | if (this_set != NULL) |
780 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
d949ff56 | 781 | if (index_offset >= index_section->size) |
4723351a CC |
782 | { |
783 | warn (_("DW_FORM_GNU_str_index offset too big: %s\n"), | |
784 | dwarf_vmatoa ("x", index_offset)); | |
785 | return _("<index offset is too big>"); | |
786 | } | |
787 | ||
788 | if (str_section->start == NULL) | |
789 | return (dwo ? _("<no .debug_str.dwo section>") | |
790 | : _("<no .debug_str section>")); | |
791 | ||
792 | str_offset = byte_get (index_section->start + index_offset, offset_size); | |
793 | str_offset -= str_section->address; | |
d949ff56 | 794 | if (str_offset >= str_section->size) |
4723351a CC |
795 | { |
796 | warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), | |
797 | dwarf_vmatoa ("x", str_offset)); | |
798 | return _("<indirect index offset is too big>"); | |
799 | } | |
800 | ||
d949ff56 NC |
801 | ret = (const char *) str_section->start + str_offset; |
802 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. | |
803 | Since our caller is expecting to receive a well formed C string we test | |
804 | for the lack of a terminating byte here. */ | |
805 | if (strnlen (ret, str_section->size - str_offset) | |
806 | == str_section->size - str_offset) | |
807 | ret = (const char *) _("<no NUL byte at end of section>"); | |
808 | ||
809 | return ret; | |
4723351a CC |
810 | } |
811 | ||
812 | static const char * | |
813 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
814 | { | |
815 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
816 | ||
817 | if (section->start == NULL) | |
818 | return (_("<no .debug_addr section>")); | |
819 | ||
820 | if (offset + bytes > section->size) | |
821 | { | |
822 | warn (_("Offset into section %s too big: %s\n"), | |
b4eb7656 | 823 | section->name, dwarf_vmatoa ("x", offset)); |
4723351a CC |
824 | return "<offset too big>"; |
825 | } | |
826 | ||
827 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
828 | } | |
829 | ||
830 | ||
19e6b90e L |
831 | /* FIXME: There are better and more efficient ways to handle |
832 | these structures. For now though, I just want something that | |
833 | is simple to implement. */ | |
834 | typedef struct abbrev_attr | |
835 | { | |
836 | unsigned long attribute; | |
837 | unsigned long form; | |
77145576 | 838 | bfd_signed_vma implicit_const; |
19e6b90e L |
839 | struct abbrev_attr *next; |
840 | } | |
841 | abbrev_attr; | |
842 | ||
843 | typedef struct abbrev_entry | |
844 | { | |
845 | unsigned long entry; | |
846 | unsigned long tag; | |
847 | int children; | |
848 | struct abbrev_attr *first_attr; | |
849 | struct abbrev_attr *last_attr; | |
850 | struct abbrev_entry *next; | |
851 | } | |
852 | abbrev_entry; | |
853 | ||
854 | static abbrev_entry *first_abbrev = NULL; | |
855 | static abbrev_entry *last_abbrev = NULL; | |
856 | ||
857 | static void | |
858 | free_abbrevs (void) | |
859 | { | |
91d6fa6a | 860 | abbrev_entry *abbrv; |
19e6b90e | 861 | |
91d6fa6a | 862 | for (abbrv = first_abbrev; abbrv;) |
19e6b90e | 863 | { |
91d6fa6a | 864 | abbrev_entry *next_abbrev = abbrv->next; |
19e6b90e L |
865 | abbrev_attr *attr; |
866 | ||
91d6fa6a | 867 | for (attr = abbrv->first_attr; attr;) |
19e6b90e | 868 | { |
91d6fa6a | 869 | abbrev_attr *next_attr = attr->next; |
19e6b90e L |
870 | |
871 | free (attr); | |
91d6fa6a | 872 | attr = next_attr; |
19e6b90e L |
873 | } |
874 | ||
91d6fa6a NC |
875 | free (abbrv); |
876 | abbrv = next_abbrev; | |
19e6b90e L |
877 | } |
878 | ||
879 | last_abbrev = first_abbrev = NULL; | |
880 | } | |
881 | ||
882 | static void | |
883 | add_abbrev (unsigned long number, unsigned long tag, int children) | |
884 | { | |
885 | abbrev_entry *entry; | |
886 | ||
3f5e193b | 887 | entry = (abbrev_entry *) malloc (sizeof (*entry)); |
19e6b90e L |
888 | if (entry == NULL) |
889 | /* ugg */ | |
890 | return; | |
891 | ||
892 | entry->entry = number; | |
893 | entry->tag = tag; | |
894 | entry->children = children; | |
895 | entry->first_attr = NULL; | |
896 | entry->last_attr = NULL; | |
897 | entry->next = NULL; | |
898 | ||
899 | if (first_abbrev == NULL) | |
900 | first_abbrev = entry; | |
901 | else | |
902 | last_abbrev->next = entry; | |
903 | ||
904 | last_abbrev = entry; | |
905 | } | |
906 | ||
907 | static void | |
77145576 JK |
908 | add_abbrev_attr (unsigned long attribute, unsigned long form, |
909 | bfd_signed_vma implicit_const) | |
19e6b90e L |
910 | { |
911 | abbrev_attr *attr; | |
912 | ||
3f5e193b | 913 | attr = (abbrev_attr *) malloc (sizeof (*attr)); |
19e6b90e L |
914 | if (attr == NULL) |
915 | /* ugg */ | |
916 | return; | |
917 | ||
918 | attr->attribute = attribute; | |
919 | attr->form = form; | |
77145576 | 920 | attr->implicit_const = implicit_const; |
19e6b90e L |
921 | attr->next = NULL; |
922 | ||
923 | if (last_abbrev->first_attr == NULL) | |
924 | last_abbrev->first_attr = attr; | |
925 | else | |
926 | last_abbrev->last_attr->next = attr; | |
927 | ||
928 | last_abbrev->last_attr = attr; | |
929 | } | |
930 | ||
931 | /* Processes the (partial) contents of a .debug_abbrev section. | |
932 | Returns NULL if the end of the section was encountered. | |
933 | Returns the address after the last byte read if the end of | |
934 | an abbreviation set was found. */ | |
935 | ||
936 | static unsigned char * | |
937 | process_abbrev_section (unsigned char *start, unsigned char *end) | |
938 | { | |
939 | if (first_abbrev != NULL) | |
940 | return NULL; | |
941 | ||
942 | while (start < end) | |
943 | { | |
944 | unsigned int bytes_read; | |
945 | unsigned long entry; | |
946 | unsigned long tag; | |
947 | unsigned long attribute; | |
948 | int children; | |
949 | ||
f6f0e17b | 950 | entry = read_uleb128 (start, & bytes_read, end); |
19e6b90e L |
951 | start += bytes_read; |
952 | ||
953 | /* A single zero is supposed to end the section according | |
954 | to the standard. If there's more, then signal that to | |
955 | the caller. */ | |
f6f0e17b NC |
956 | if (start == end) |
957 | return NULL; | |
19e6b90e | 958 | if (entry == 0) |
f6f0e17b | 959 | return start; |
19e6b90e | 960 | |
f6f0e17b | 961 | tag = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 962 | start += bytes_read; |
f6f0e17b NC |
963 | if (start == end) |
964 | return NULL; | |
19e6b90e L |
965 | |
966 | children = *start++; | |
967 | ||
968 | add_abbrev (entry, tag, children); | |
969 | ||
970 | do | |
971 | { | |
972 | unsigned long form; | |
77145576 JK |
973 | /* Initialize it due to a false compiler warning. */ |
974 | bfd_signed_vma implicit_const = -1; | |
19e6b90e | 975 | |
f6f0e17b | 976 | attribute = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 977 | start += bytes_read; |
f6f0e17b NC |
978 | if (start == end) |
979 | break; | |
19e6b90e | 980 | |
f6f0e17b | 981 | form = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 982 | start += bytes_read; |
f6f0e17b NC |
983 | if (start == end) |
984 | break; | |
19e6b90e | 985 | |
77145576 JK |
986 | if (form == DW_FORM_implicit_const) |
987 | { | |
988 | implicit_const = read_sleb128 (start, & bytes_read, end); | |
989 | start += bytes_read; | |
990 | if (start == end) | |
991 | break; | |
992 | } | |
993 | ||
994 | add_abbrev_attr (attribute, form, implicit_const); | |
19e6b90e L |
995 | } |
996 | while (attribute != 0); | |
997 | } | |
998 | ||
399c99f7 L |
999 | /* Report the missing single zero which ends the section. */ |
1000 | error (_(".debug_abbrev section not zero terminated\n")); | |
1001 | ||
19e6b90e L |
1002 | return NULL; |
1003 | } | |
1004 | ||
a19c41a7 | 1005 | static const char * |
19e6b90e L |
1006 | get_TAG_name (unsigned long tag) |
1007 | { | |
04914e37 | 1008 | const char *name = get_DW_TAG_name ((unsigned int) tag); |
a19c41a7 TT |
1009 | |
1010 | if (name == NULL) | |
19e6b90e | 1011 | { |
a19c41a7 | 1012 | static char buffer[100]; |
19e6b90e | 1013 | |
04914e37 NC |
1014 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
1015 | snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag); | |
1016 | else | |
1017 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag); | |
a19c41a7 | 1018 | return buffer; |
19e6b90e | 1019 | } |
a19c41a7 TT |
1020 | |
1021 | return name; | |
19e6b90e L |
1022 | } |
1023 | ||
a19c41a7 | 1024 | static const char * |
19e6b90e L |
1025 | get_FORM_name (unsigned long form) |
1026 | { | |
399c99f7 | 1027 | const char *name; |
bf5117e3 | 1028 | |
399c99f7 L |
1029 | if (form == 0) |
1030 | return "DW_FORM value: 0"; | |
a19c41a7 | 1031 | |
399c99f7 | 1032 | name = get_DW_FORM_name (form); |
a19c41a7 | 1033 | if (name == NULL) |
19e6b90e | 1034 | { |
a19c41a7 | 1035 | static char buffer[100]; |
19e6b90e | 1036 | |
a19c41a7 TT |
1037 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
1038 | return buffer; | |
19e6b90e | 1039 | } |
a19c41a7 TT |
1040 | |
1041 | return name; | |
19e6b90e L |
1042 | } |
1043 | ||
61364358 JK |
1044 | static const char * |
1045 | get_IDX_name (unsigned long idx) | |
1046 | { | |
1047 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
1048 | ||
1049 | if (name == NULL) | |
1050 | { | |
1051 | static char buffer[100]; | |
1052 | ||
1053 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1054 | return buffer; | |
1055 | } | |
1056 | ||
1057 | return name; | |
1058 | } | |
1059 | ||
19e6b90e | 1060 | static unsigned char * |
0c588247 NC |
1061 | display_block (unsigned char *data, |
1062 | dwarf_vma length, | |
ef0b5f1c | 1063 | const unsigned char * const end, char delimiter) |
19e6b90e | 1064 | { |
0c588247 NC |
1065 | dwarf_vma maxlen; |
1066 | ||
ef0b5f1c | 1067 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
1068 | if (data > end) |
1069 | return (unsigned char *) end; | |
19e6b90e | 1070 | |
0c588247 NC |
1071 | maxlen = (dwarf_vma) (end - data); |
1072 | length = length > maxlen ? maxlen : length; | |
1073 | ||
19e6b90e L |
1074 | while (length --) |
1075 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1076 | ||
1077 | return data; | |
1078 | } | |
1079 | ||
1080 | static int | |
1081 | decode_location_expression (unsigned char * data, | |
1082 | unsigned int pointer_size, | |
b7807392 JJ |
1083 | unsigned int offset_size, |
1084 | int dwarf_version, | |
467c65bc NC |
1085 | dwarf_vma length, |
1086 | dwarf_vma cu_offset, | |
f1c4cc75 | 1087 | struct dwarf_section * section) |
19e6b90e L |
1088 | { |
1089 | unsigned op; | |
1090 | unsigned int bytes_read; | |
467c65bc | 1091 | dwarf_vma uvalue; |
0c588247 | 1092 | dwarf_signed_vma svalue; |
19e6b90e L |
1093 | unsigned char *end = data + length; |
1094 | int need_frame_base = 0; | |
1095 | ||
1096 | while (data < end) | |
1097 | { | |
1098 | op = *data++; | |
1099 | ||
1100 | switch (op) | |
1101 | { | |
1102 | case DW_OP_addr: | |
0c588247 NC |
1103 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1104 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1105 | break; |
1106 | case DW_OP_deref: | |
1107 | printf ("DW_OP_deref"); | |
1108 | break; | |
1109 | case DW_OP_const1u: | |
0c588247 NC |
1110 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1111 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1112 | break; |
1113 | case DW_OP_const1s: | |
0c588247 NC |
1114 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1115 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1116 | break; |
1117 | case DW_OP_const2u: | |
87bc83b3 | 1118 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1119 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1120 | break; |
1121 | case DW_OP_const2s: | |
0c588247 NC |
1122 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1123 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1124 | break; |
1125 | case DW_OP_const4u: | |
0c588247 NC |
1126 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1127 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1128 | break; |
1129 | case DW_OP_const4s: | |
0c588247 NC |
1130 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1131 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1132 | break; |
1133 | case DW_OP_const8u: | |
0c588247 NC |
1134 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1135 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1136 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1137 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1138 | break; |
1139 | case DW_OP_const8s: | |
0c588247 NC |
1140 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1141 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1142 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1143 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1144 | break; |
1145 | case DW_OP_constu: | |
467c65bc | 1146 | printf ("DW_OP_constu: %s", |
f6f0e17b | 1147 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1148 | data += bytes_read; |
1149 | break; | |
1150 | case DW_OP_consts: | |
467c65bc | 1151 | printf ("DW_OP_consts: %s", |
f6f0e17b | 1152 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1153 | data += bytes_read; |
1154 | break; | |
1155 | case DW_OP_dup: | |
1156 | printf ("DW_OP_dup"); | |
1157 | break; | |
1158 | case DW_OP_drop: | |
1159 | printf ("DW_OP_drop"); | |
1160 | break; | |
1161 | case DW_OP_over: | |
1162 | printf ("DW_OP_over"); | |
1163 | break; | |
1164 | case DW_OP_pick: | |
0c588247 NC |
1165 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1166 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1167 | break; |
1168 | case DW_OP_swap: | |
1169 | printf ("DW_OP_swap"); | |
1170 | break; | |
1171 | case DW_OP_rot: | |
1172 | printf ("DW_OP_rot"); | |
1173 | break; | |
1174 | case DW_OP_xderef: | |
1175 | printf ("DW_OP_xderef"); | |
1176 | break; | |
1177 | case DW_OP_abs: | |
1178 | printf ("DW_OP_abs"); | |
1179 | break; | |
1180 | case DW_OP_and: | |
1181 | printf ("DW_OP_and"); | |
1182 | break; | |
1183 | case DW_OP_div: | |
1184 | printf ("DW_OP_div"); | |
1185 | break; | |
1186 | case DW_OP_minus: | |
1187 | printf ("DW_OP_minus"); | |
1188 | break; | |
1189 | case DW_OP_mod: | |
1190 | printf ("DW_OP_mod"); | |
1191 | break; | |
1192 | case DW_OP_mul: | |
1193 | printf ("DW_OP_mul"); | |
1194 | break; | |
1195 | case DW_OP_neg: | |
1196 | printf ("DW_OP_neg"); | |
1197 | break; | |
1198 | case DW_OP_not: | |
1199 | printf ("DW_OP_not"); | |
1200 | break; | |
1201 | case DW_OP_or: | |
1202 | printf ("DW_OP_or"); | |
1203 | break; | |
1204 | case DW_OP_plus: | |
1205 | printf ("DW_OP_plus"); | |
1206 | break; | |
1207 | case DW_OP_plus_uconst: | |
467c65bc | 1208 | printf ("DW_OP_plus_uconst: %s", |
f6f0e17b | 1209 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1210 | data += bytes_read; |
1211 | break; | |
1212 | case DW_OP_shl: | |
1213 | printf ("DW_OP_shl"); | |
1214 | break; | |
1215 | case DW_OP_shr: | |
1216 | printf ("DW_OP_shr"); | |
1217 | break; | |
1218 | case DW_OP_shra: | |
1219 | printf ("DW_OP_shra"); | |
1220 | break; | |
1221 | case DW_OP_xor: | |
1222 | printf ("DW_OP_xor"); | |
1223 | break; | |
1224 | case DW_OP_bra: | |
0c588247 NC |
1225 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1226 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1227 | break; |
1228 | case DW_OP_eq: | |
1229 | printf ("DW_OP_eq"); | |
1230 | break; | |
1231 | case DW_OP_ge: | |
1232 | printf ("DW_OP_ge"); | |
1233 | break; | |
1234 | case DW_OP_gt: | |
1235 | printf ("DW_OP_gt"); | |
1236 | break; | |
1237 | case DW_OP_le: | |
1238 | printf ("DW_OP_le"); | |
1239 | break; | |
1240 | case DW_OP_lt: | |
1241 | printf ("DW_OP_lt"); | |
1242 | break; | |
1243 | case DW_OP_ne: | |
1244 | printf ("DW_OP_ne"); | |
1245 | break; | |
1246 | case DW_OP_skip: | |
0c588247 NC |
1247 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1248 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1249 | break; |
1250 | ||
1251 | case DW_OP_lit0: | |
1252 | case DW_OP_lit1: | |
1253 | case DW_OP_lit2: | |
1254 | case DW_OP_lit3: | |
1255 | case DW_OP_lit4: | |
1256 | case DW_OP_lit5: | |
1257 | case DW_OP_lit6: | |
1258 | case DW_OP_lit7: | |
1259 | case DW_OP_lit8: | |
1260 | case DW_OP_lit9: | |
1261 | case DW_OP_lit10: | |
1262 | case DW_OP_lit11: | |
1263 | case DW_OP_lit12: | |
1264 | case DW_OP_lit13: | |
1265 | case DW_OP_lit14: | |
1266 | case DW_OP_lit15: | |
1267 | case DW_OP_lit16: | |
1268 | case DW_OP_lit17: | |
1269 | case DW_OP_lit18: | |
1270 | case DW_OP_lit19: | |
1271 | case DW_OP_lit20: | |
1272 | case DW_OP_lit21: | |
1273 | case DW_OP_lit22: | |
1274 | case DW_OP_lit23: | |
1275 | case DW_OP_lit24: | |
1276 | case DW_OP_lit25: | |
1277 | case DW_OP_lit26: | |
1278 | case DW_OP_lit27: | |
1279 | case DW_OP_lit28: | |
1280 | case DW_OP_lit29: | |
1281 | case DW_OP_lit30: | |
1282 | case DW_OP_lit31: | |
1283 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1284 | break; | |
1285 | ||
1286 | case DW_OP_reg0: | |
1287 | case DW_OP_reg1: | |
1288 | case DW_OP_reg2: | |
1289 | case DW_OP_reg3: | |
1290 | case DW_OP_reg4: | |
1291 | case DW_OP_reg5: | |
1292 | case DW_OP_reg6: | |
1293 | case DW_OP_reg7: | |
1294 | case DW_OP_reg8: | |
1295 | case DW_OP_reg9: | |
1296 | case DW_OP_reg10: | |
1297 | case DW_OP_reg11: | |
1298 | case DW_OP_reg12: | |
1299 | case DW_OP_reg13: | |
1300 | case DW_OP_reg14: | |
1301 | case DW_OP_reg15: | |
1302 | case DW_OP_reg16: | |
1303 | case DW_OP_reg17: | |
1304 | case DW_OP_reg18: | |
1305 | case DW_OP_reg19: | |
1306 | case DW_OP_reg20: | |
1307 | case DW_OP_reg21: | |
1308 | case DW_OP_reg22: | |
1309 | case DW_OP_reg23: | |
1310 | case DW_OP_reg24: | |
1311 | case DW_OP_reg25: | |
1312 | case DW_OP_reg26: | |
1313 | case DW_OP_reg27: | |
1314 | case DW_OP_reg28: | |
1315 | case DW_OP_reg29: | |
1316 | case DW_OP_reg30: | |
1317 | case DW_OP_reg31: | |
18464d4d JK |
1318 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1319 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1320 | break; |
1321 | ||
1322 | case DW_OP_breg0: | |
1323 | case DW_OP_breg1: | |
1324 | case DW_OP_breg2: | |
1325 | case DW_OP_breg3: | |
1326 | case DW_OP_breg4: | |
1327 | case DW_OP_breg5: | |
1328 | case DW_OP_breg6: | |
1329 | case DW_OP_breg7: | |
1330 | case DW_OP_breg8: | |
1331 | case DW_OP_breg9: | |
1332 | case DW_OP_breg10: | |
1333 | case DW_OP_breg11: | |
1334 | case DW_OP_breg12: | |
1335 | case DW_OP_breg13: | |
1336 | case DW_OP_breg14: | |
1337 | case DW_OP_breg15: | |
1338 | case DW_OP_breg16: | |
1339 | case DW_OP_breg17: | |
1340 | case DW_OP_breg18: | |
1341 | case DW_OP_breg19: | |
1342 | case DW_OP_breg20: | |
1343 | case DW_OP_breg21: | |
1344 | case DW_OP_breg22: | |
1345 | case DW_OP_breg23: | |
1346 | case DW_OP_breg24: | |
1347 | case DW_OP_breg25: | |
1348 | case DW_OP_breg26: | |
1349 | case DW_OP_breg27: | |
1350 | case DW_OP_breg28: | |
1351 | case DW_OP_breg29: | |
1352 | case DW_OP_breg30: | |
1353 | case DW_OP_breg31: | |
467c65bc | 1354 | printf ("DW_OP_breg%d (%s): %s", |
47704ddf | 1355 | op - DW_OP_breg0, |
18464d4d | 1356 | regname (op - DW_OP_breg0, 1), |
f6f0e17b | 1357 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1358 | data += bytes_read; |
1359 | break; | |
1360 | ||
1361 | case DW_OP_regx: | |
f6f0e17b | 1362 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1363 | data += bytes_read; |
467c65bc NC |
1364 | printf ("DW_OP_regx: %s (%s)", |
1365 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1366 | break; |
1367 | case DW_OP_fbreg: | |
1368 | need_frame_base = 1; | |
467c65bc | 1369 | printf ("DW_OP_fbreg: %s", |
f6f0e17b | 1370 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1371 | data += bytes_read; |
1372 | break; | |
1373 | case DW_OP_bregx: | |
f6f0e17b | 1374 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1375 | data += bytes_read; |
467c65bc NC |
1376 | printf ("DW_OP_bregx: %s (%s) %s", |
1377 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
f6f0e17b | 1378 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1379 | data += bytes_read; |
1380 | break; | |
1381 | case DW_OP_piece: | |
467c65bc | 1382 | printf ("DW_OP_piece: %s", |
f6f0e17b | 1383 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1384 | data += bytes_read; |
1385 | break; | |
1386 | case DW_OP_deref_size: | |
0c588247 NC |
1387 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1388 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1389 | break; |
1390 | case DW_OP_xderef_size: | |
0c588247 NC |
1391 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1392 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1393 | break; |
1394 | case DW_OP_nop: | |
1395 | printf ("DW_OP_nop"); | |
1396 | break; | |
1397 | ||
1398 | /* DWARF 3 extensions. */ | |
1399 | case DW_OP_push_object_address: | |
1400 | printf ("DW_OP_push_object_address"); | |
1401 | break; | |
1402 | case DW_OP_call2: | |
d85bf2ba | 1403 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1404 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1405 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1406 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1407 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1408 | break; |
1409 | case DW_OP_call4: | |
d85bf2ba | 1410 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1411 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1412 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1413 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1414 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1415 | break; |
1416 | case DW_OP_call_ref: | |
d85bf2ba | 1417 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
e2a0d921 | 1418 | this ought to be an 8-byte wide computation. */ |
b7807392 JJ |
1419 | if (dwarf_version == -1) |
1420 | { | |
1421 | printf (_("(DW_OP_call_ref in frame info)")); | |
1422 | /* No way to tell where the next op is, so just bail. */ | |
1423 | return need_frame_base; | |
1424 | } | |
1425 | if (dwarf_version == 2) | |
1426 | { | |
0c588247 | 1427 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1428 | } |
1429 | else | |
1430 | { | |
0c588247 | 1431 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1432 | } |
0c588247 | 1433 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1434 | break; |
a87b0a59 NS |
1435 | case DW_OP_form_tls_address: |
1436 | printf ("DW_OP_form_tls_address"); | |
1437 | break; | |
e2a0d921 NC |
1438 | case DW_OP_call_frame_cfa: |
1439 | printf ("DW_OP_call_frame_cfa"); | |
1440 | break; | |
1441 | case DW_OP_bit_piece: | |
1442 | printf ("DW_OP_bit_piece: "); | |
9cf03b7e | 1443 | printf (_("size: %s "), |
f6f0e17b | 1444 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 | 1445 | data += bytes_read; |
9cf03b7e | 1446 | printf (_("offset: %s "), |
f6f0e17b | 1447 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 NC |
1448 | data += bytes_read; |
1449 | break; | |
19e6b90e | 1450 | |
3244e8f5 JJ |
1451 | /* DWARF 4 extensions. */ |
1452 | case DW_OP_stack_value: | |
1453 | printf ("DW_OP_stack_value"); | |
1454 | break; | |
1455 | ||
1456 | case DW_OP_implicit_value: | |
1457 | printf ("DW_OP_implicit_value"); | |
f6f0e17b | 1458 | uvalue = read_uleb128 (data, &bytes_read, end); |
3244e8f5 | 1459 | data += bytes_read; |
ef0b5f1c | 1460 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1461 | break; |
1462 | ||
19e6b90e L |
1463 | /* GNU extensions. */ |
1464 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1465 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1466 | break; |
1467 | case DW_OP_GNU_uninit: | |
1468 | printf ("DW_OP_GNU_uninit"); | |
1469 | /* FIXME: Is there data associated with this OP ? */ | |
1470 | break; | |
f1c4cc75 RH |
1471 | case DW_OP_GNU_encoded_addr: |
1472 | { | |
6937bb54 | 1473 | int encoding = 0; |
f1c4cc75 | 1474 | dwarf_vma addr; |
467c65bc | 1475 | |
6937bb54 NC |
1476 | if (data < end) |
1477 | encoding = *data++; | |
041830e0 | 1478 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1479 | |
1480 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1481 | print_dwarf_vma (addr, pointer_size); | |
1482 | } | |
1483 | break; | |
bc0a77d2 | 1484 | case DW_OP_implicit_pointer: |
b7807392 | 1485 | case DW_OP_GNU_implicit_pointer: |
d85bf2ba | 1486 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
b7807392 JJ |
1487 | this ought to be an 8-byte wide computation. */ |
1488 | if (dwarf_version == -1) | |
1489 | { | |
bc0a77d2 JK |
1490 | printf (_("(%s in frame info)"), |
1491 | (op == DW_OP_implicit_pointer | |
1492 | ? "DW_OP_implicit_pointer" | |
1493 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1494 | /* No way to tell where the next op is, so just bail. */ |
1495 | return need_frame_base; | |
1496 | } | |
1497 | if (dwarf_version == 2) | |
1498 | { | |
0c588247 | 1499 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1500 | } |
1501 | else | |
1502 | { | |
0c588247 | 1503 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1504 | } |
bc0a77d2 JK |
1505 | printf ("%s: <0x%s> %s", |
1506 | (op == DW_OP_implicit_pointer | |
1507 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 NC |
1508 | dwarf_vmatoa ("x", uvalue), |
1509 | dwarf_vmatoa ("d", read_sleb128 (data, | |
1510 | &bytes_read, end))); | |
1511 | data += bytes_read; | |
b7807392 | 1512 | break; |
77145576 | 1513 | case DW_OP_entry_value: |
0892011d | 1514 | case DW_OP_GNU_entry_value: |
f6f0e17b | 1515 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1516 | data += bytes_read; |
058037d3 NC |
1517 | /* PR 17531: file: 0cc9cd00. */ |
1518 | if (uvalue > (dwarf_vma) (end - data)) | |
1519 | uvalue = end - data; | |
77145576 JK |
1520 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1521 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1522 | if (decode_location_expression (data, pointer_size, offset_size, |
1523 | dwarf_version, uvalue, | |
1524 | cu_offset, section)) | |
1525 | need_frame_base = 1; | |
1526 | putchar (')'); | |
1527 | data += uvalue; | |
6937bb54 NC |
1528 | if (data > end) |
1529 | data = end; | |
0892011d | 1530 | break; |
bc0a77d2 | 1531 | case DW_OP_const_type: |
0892011d | 1532 | case DW_OP_GNU_const_type: |
f6f0e17b | 1533 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1534 | data += bytes_read; |
bc0a77d2 JK |
1535 | printf ("%s: <0x%s> ", |
1536 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1537 | : "DW_OP_GNU_const_type"), | |
0892011d | 1538 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1539 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1540 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1541 | break; |
bc0a77d2 | 1542 | case DW_OP_regval_type: |
0892011d | 1543 | case DW_OP_GNU_regval_type: |
f6f0e17b | 1544 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1545 | data += bytes_read; |
bc0a77d2 JK |
1546 | printf ("%s: %s (%s)", |
1547 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1548 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1549 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
f6f0e17b | 1550 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1551 | data += bytes_read; |
1552 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1553 | break; | |
bc0a77d2 | 1554 | case DW_OP_deref_type: |
0892011d | 1555 | case DW_OP_GNU_deref_type: |
0c588247 | 1556 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1557 | printf ("%s: %ld", |
1558 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1559 | : "DW_OP_GNU_deref_type"), | |
1560 | (long) uvalue); | |
f6f0e17b | 1561 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1562 | data += bytes_read; |
1563 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1564 | break; | |
bc0a77d2 | 1565 | case DW_OP_convert: |
0892011d | 1566 | case DW_OP_GNU_convert: |
f6f0e17b | 1567 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1568 | data += bytes_read; |
bc0a77d2 JK |
1569 | printf ("%s <0x%s>", |
1570 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1571 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1572 | break; |
bc0a77d2 | 1573 | case DW_OP_reinterpret: |
0892011d | 1574 | case DW_OP_GNU_reinterpret: |
f6f0e17b | 1575 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1576 | data += bytes_read; |
bc0a77d2 JK |
1577 | printf ("%s <0x%s>", |
1578 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1579 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1580 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1581 | break; | |
1582 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1583 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1584 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1585 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1586 | break; |
b4eb7656 AM |
1587 | case DW_OP_GNU_addr_index: |
1588 | uvalue = read_uleb128 (data, &bytes_read, end); | |
1589 | data += bytes_read; | |
1590 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1591 | break; | |
1592 | case DW_OP_GNU_const_index: | |
1593 | uvalue = read_uleb128 (data, &bytes_read, end); | |
1594 | data += bytes_read; | |
1595 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1596 | break; | |
f384a1f0 KB |
1597 | case DW_OP_GNU_variable_value: |
1598 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1599 | this ought to be an 8-byte wide computation. */ | |
1600 | if (dwarf_version == -1) | |
1601 | { | |
1602 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1603 | /* No way to tell where the next op is, so just bail. */ | |
1604 | return need_frame_base; | |
1605 | } | |
1606 | if (dwarf_version == 2) | |
1607 | { | |
1608 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1609 | } | |
1610 | else | |
1611 | { | |
1612 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1613 | } | |
1614 | printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1615 | break; | |
e2a0d921 NC |
1616 | |
1617 | /* HP extensions. */ | |
1618 | case DW_OP_HP_is_value: | |
1619 | printf ("DW_OP_HP_is_value"); | |
1620 | /* FIXME: Is there data associated with this OP ? */ | |
1621 | break; | |
1622 | case DW_OP_HP_fltconst4: | |
1623 | printf ("DW_OP_HP_fltconst4"); | |
1624 | /* FIXME: Is there data associated with this OP ? */ | |
1625 | break; | |
1626 | case DW_OP_HP_fltconst8: | |
1627 | printf ("DW_OP_HP_fltconst8"); | |
1628 | /* FIXME: Is there data associated with this OP ? */ | |
1629 | break; | |
1630 | case DW_OP_HP_mod_range: | |
1631 | printf ("DW_OP_HP_mod_range"); | |
1632 | /* FIXME: Is there data associated with this OP ? */ | |
1633 | break; | |
1634 | case DW_OP_HP_unmod_range: | |
1635 | printf ("DW_OP_HP_unmod_range"); | |
1636 | /* FIXME: Is there data associated with this OP ? */ | |
1637 | break; | |
1638 | case DW_OP_HP_tls: | |
1639 | printf ("DW_OP_HP_tls"); | |
1640 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1641 | break; |
1642 | ||
35d60fe4 NC |
1643 | /* PGI (STMicroelectronics) extensions. */ |
1644 | case DW_OP_PGI_omp_thread_num: | |
1645 | /* Pushes the thread number for the current thread as it would be | |
1646 | returned by the standard OpenMP library function: | |
1647 | omp_get_thread_num(). The "current thread" is the thread for | |
1648 | which the expression is being evaluated. */ | |
1649 | printf ("DW_OP_PGI_omp_thread_num"); | |
1650 | break; | |
1651 | ||
19e6b90e L |
1652 | default: |
1653 | if (op >= DW_OP_lo_user | |
1654 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1655 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1656 | else |
0502a2b4 | 1657 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1658 | /* No way to tell where the next op is, so just bail. */ |
1659 | return need_frame_base; | |
1660 | } | |
1661 | ||
1662 | /* Separate the ops. */ | |
1663 | if (data < end) | |
1664 | printf ("; "); | |
1665 | } | |
1666 | ||
1667 | return need_frame_base; | |
1668 | } | |
1669 | ||
341f9135 CC |
1670 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1671 | This is used for DWARF package files. */ | |
1672 | ||
1673 | static struct cu_tu_set * | |
1674 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1675 | { | |
1676 | struct cu_tu_set *p; | |
1677 | unsigned int nsets; | |
1678 | unsigned int dw_sect; | |
1679 | ||
1680 | if (do_types) | |
1681 | { | |
1682 | p = tu_sets; | |
1683 | nsets = tu_count; | |
1684 | dw_sect = DW_SECT_TYPES; | |
1685 | } | |
1686 | else | |
1687 | { | |
1688 | p = cu_sets; | |
1689 | nsets = cu_count; | |
1690 | dw_sect = DW_SECT_INFO; | |
1691 | } | |
1692 | while (nsets > 0) | |
1693 | { | |
1694 | if (p->section_offsets [dw_sect] == cu_offset) | |
1695 | return p; | |
1696 | p++; | |
1697 | nsets--; | |
1698 | } | |
1699 | return NULL; | |
1700 | } | |
1701 | ||
a69c4772 NC |
1702 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1703 | static void | |
1704 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1705 | { | |
1706 | dwarf_vma tmp = * low_bits; | |
1707 | ||
1708 | tmp += inc; | |
1709 | ||
1710 | /* FIXME: There is probably a better way of handling this: | |
1711 | ||
1712 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1713 | type. Plus regardless of its size LOW_BITS is meant to | |
1714 | only hold 32-bits, so if there is overflow or wrap around | |
1715 | we must propagate into HIGH_BITS. */ | |
1716 | if (tmp < * low_bits) | |
1717 | { | |
1718 | ++ * high_bits; | |
1719 | } | |
1720 | else if (sizeof (tmp) > 8 | |
1721 | && (tmp >> 31) > 1) | |
1722 | { | |
1723 | ++ * high_bits; | |
1724 | tmp &= 0xFFFFFFFF; | |
1725 | } | |
1726 | ||
1727 | * low_bits = tmp; | |
1728 | } | |
1729 | ||
dda8d76d NC |
1730 | static const char * |
1731 | fetch_alt_indirect_string (dwarf_vma offset) | |
1732 | { | |
24841daa | 1733 | separate_info * i; |
dda8d76d NC |
1734 | |
1735 | if (! do_follow_links) | |
1736 | return ""; | |
1737 | ||
24841daa NC |
1738 | if (first_separate_info == NULL) |
1739 | return _("<no links available>"); | |
dda8d76d | 1740 | |
24841daa NC |
1741 | for (i = first_separate_info; i != NULL; i = i->next) |
1742 | { | |
1743 | struct dwarf_section * section; | |
1744 | const char * ret; | |
dda8d76d | 1745 | |
24841daa NC |
1746 | if (! load_debug_section (separate_debug_str, i->handle)) |
1747 | continue; | |
dda8d76d | 1748 | |
24841daa | 1749 | section = &debug_displays [separate_debug_str].section; |
dda8d76d | 1750 | |
24841daa NC |
1751 | if (section->start == NULL) |
1752 | continue; | |
dda8d76d | 1753 | |
24841daa NC |
1754 | if (offset >= section->size) |
1755 | continue; | |
1756 | ||
1757 | ret = (const char *) (section->start + offset); | |
1758 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1759 | NUL byte. Since our caller is expecting to receive a well formed C | |
1760 | string we test for the lack of a terminating byte here. */ | |
1761 | if (strnlen ((const char *) ret, section->size - offset) | |
1762 | == section->size - offset) | |
1763 | return _("<no NUL byte at end of alt .debug_str section>"); | |
1764 | ||
1765 | return ret; | |
1766 | } | |
1767 | ||
1768 | warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"), | |
1769 | dwarf_vmatoa ("x", offset)); | |
1770 | return _("<offset is too big>"); | |
dda8d76d NC |
1771 | } |
1772 | ||
d85bf2ba NC |
1773 | static const char * |
1774 | get_AT_name (unsigned long attribute) | |
1775 | { | |
1776 | const char *name; | |
1777 | ||
1778 | if (attribute == 0) | |
1779 | return "DW_AT value: 0"; | |
1780 | ||
1781 | /* One value is shared by the MIPS and HP extensions: */ | |
1782 | if (attribute == DW_AT_MIPS_fde) | |
1783 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1784 | ||
1785 | name = get_DW_AT_name (attribute); | |
1786 | ||
1787 | if (name == NULL) | |
1788 | { | |
1789 | static char buffer[100]; | |
1790 | ||
1791 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1792 | attribute); | |
1793 | return buffer; | |
1794 | } | |
1795 | ||
1796 | return name; | |
1797 | } | |
1798 | ||
24841daa NC |
1799 | static void |
1800 | add_dwo_info (const char * field, dwo_type type) | |
1801 | { | |
1802 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); | |
1803 | ||
1804 | dwinfo->type = type; | |
1805 | dwinfo->value = field; | |
1806 | dwinfo->next = first_dwo_info; | |
1807 | first_dwo_info = dwinfo; | |
1808 | } | |
1809 | ||
1810 | static void | |
1811 | add_dwo_name (const char * name) | |
1812 | { | |
1813 | add_dwo_info (name, DWO_NAME); | |
1814 | } | |
1815 | ||
1816 | static void | |
1817 | add_dwo_dir (const char * dir) | |
1818 | { | |
1819 | add_dwo_info (dir, DWO_DIR); | |
1820 | } | |
1821 | ||
1822 | static void | |
1823 | add_dwo_id (const char * id) | |
1824 | { | |
1825 | add_dwo_info (id, DWO_ID); | |
1826 | } | |
1827 | ||
1828 | static void | |
1829 | free_dwo_info (void) | |
1830 | { | |
1831 | dwo_info * dwinfo; | |
1832 | dwo_info * next; | |
1833 | ||
1834 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) | |
1835 | { | |
1836 | next = dwinfo->next; | |
1837 | free (dwinfo); | |
1838 | } | |
1839 | first_dwo_info = NULL; | |
1840 | } | |
1841 | ||
afc72f15 NC |
1842 | /* Ensure that START + UVALUE is less than END. |
1843 | Return an adjusted UVALUE if necessary to ensure this relationship. */ | |
1844 | ||
1845 | static inline dwarf_vma | |
1846 | check_uvalue (const unsigned char * start, | |
1847 | dwarf_vma uvalue, | |
1848 | const unsigned char * end) | |
1849 | { | |
1850 | dwarf_vma max_uvalue = end - start; | |
1851 | ||
afc72f15 NC |
1852 | /* See PR 17512: file: 008-103549-0.001:0.1. |
1853 | and PR 24829 for examples of where these tests are triggered. */ | |
a85eba51 | 1854 | if (uvalue > max_uvalue) |
afc72f15 NC |
1855 | { |
1856 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1857 | uvalue = max_uvalue; | |
1858 | } | |
1859 | ||
1860 | return uvalue; | |
1861 | } | |
1862 | ||
ec1b0fbb NC |
1863 | static unsigned char * |
1864 | skip_attr_bytes (unsigned long form, | |
1865 | unsigned char * data, | |
1866 | unsigned const char * end, | |
1867 | dwarf_vma pointer_size, | |
1868 | dwarf_vma offset_size, | |
1869 | int dwarf_version, | |
1870 | dwarf_vma * value_return) | |
1871 | { | |
1872 | unsigned int bytes_read; | |
1873 | dwarf_vma uvalue = 0; | |
1874 | ||
1875 | * value_return = 0; | |
1876 | ||
1877 | switch (form) | |
1878 | { | |
1879 | case DW_FORM_ref_addr: | |
1880 | if (dwarf_version == 2) | |
1881 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1882 | else if (dwarf_version == 3 || dwarf_version == 4) | |
1883 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1884 | else | |
1885 | return NULL; | |
1886 | break; | |
1887 | ||
1888 | case DW_FORM_addr: | |
1889 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1890 | break; | |
1891 | ||
1892 | case DW_FORM_strp: | |
1893 | case DW_FORM_line_strp: | |
1894 | case DW_FORM_sec_offset: | |
1895 | case DW_FORM_GNU_ref_alt: | |
1896 | case DW_FORM_GNU_strp_alt: | |
1897 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1898 | break; | |
1899 | ||
1900 | case DW_FORM_flag_present: | |
1901 | uvalue = 1; | |
1902 | break; | |
1903 | ||
1904 | case DW_FORM_ref1: | |
1905 | case DW_FORM_flag: | |
1906 | case DW_FORM_data1: | |
1907 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
1908 | break; | |
1909 | ||
1910 | case DW_FORM_ref2: | |
1911 | case DW_FORM_data2: | |
1912 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); | |
1913 | break; | |
1914 | ||
1915 | case DW_FORM_ref4: | |
1916 | case DW_FORM_data4: | |
1917 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1918 | break; | |
1919 | ||
1920 | case DW_FORM_sdata: | |
1921 | uvalue = read_sleb128 (data, & bytes_read, end); | |
1922 | data += bytes_read; | |
1923 | break; | |
1924 | ||
1925 | case DW_FORM_ref_udata: | |
1926 | case DW_FORM_udata: | |
1927 | case DW_FORM_GNU_str_index: | |
1928 | case DW_FORM_GNU_addr_index: | |
1929 | uvalue = read_uleb128 (data, & bytes_read, end); | |
1930 | data += bytes_read; | |
1931 | break; | |
1932 | ||
1933 | case DW_FORM_ref8: | |
1934 | case DW_FORM_data8: | |
1935 | data += 8; | |
1936 | break; | |
1937 | ||
1938 | case DW_FORM_data16: | |
1939 | data += 16; | |
1940 | break; | |
1941 | ||
1942 | case DW_FORM_string: | |
1943 | data += strnlen ((char *) data, end - data) + 1; | |
1944 | break; | |
1945 | ||
1946 | case DW_FORM_block: | |
1947 | case DW_FORM_exprloc: | |
1948 | uvalue = read_uleb128 (data, & bytes_read, end); | |
1949 | data += bytes_read + uvalue; | |
1950 | break; | |
1951 | ||
1952 | case DW_FORM_block1: | |
1953 | SAFE_BYTE_GET (uvalue, data, 1, end); | |
1954 | data += 1 + uvalue; | |
1955 | break; | |
1956 | ||
1957 | case DW_FORM_block2: | |
1958 | SAFE_BYTE_GET (uvalue, data, 2, end); | |
1959 | data += 2 + uvalue; | |
1960 | break; | |
1961 | ||
1962 | case DW_FORM_block4: | |
1963 | SAFE_BYTE_GET (uvalue, data, 4, end); | |
1964 | data += 4 + uvalue; | |
1965 | break; | |
1966 | ||
1967 | case DW_FORM_ref_sig8: | |
1968 | data += 8; | |
1969 | break; | |
1970 | ||
1971 | case DW_FORM_indirect: | |
1972 | /* FIXME: Handle this form. */ | |
1973 | default: | |
1974 | return NULL; | |
1975 | } | |
1976 | ||
1977 | * value_return = uvalue; | |
1978 | if (data > end) | |
1979 | data = (unsigned char *) end; | |
1980 | return data; | |
1981 | } | |
1982 | ||
1983 | /* Return IS_SIGNED set to TRUE if the type at | |
1984 | DATA can be determined to be a signed type. */ | |
1985 | ||
1986 | static void | |
1987 | get_type_signedness (unsigned char * start, | |
1988 | unsigned char * data, | |
1989 | unsigned const char * end, | |
1990 | dwarf_vma pointer_size, | |
1991 | dwarf_vma offset_size, | |
1992 | int dwarf_version, | |
1993 | bfd_boolean * is_signed, | |
1994 | bfd_boolean is_nested) | |
1995 | { | |
1996 | unsigned long abbrev_number; | |
1997 | unsigned int bytes_read; | |
1998 | abbrev_entry * entry; | |
1999 | abbrev_attr * attr; | |
2000 | ||
2001 | * is_signed = FALSE; | |
2002 | ||
ec1b0fbb NC |
2003 | abbrev_number = read_uleb128 (data, & bytes_read, end); |
2004 | data += bytes_read; | |
2005 | ||
2006 | for (entry = first_abbrev; | |
2007 | entry != NULL && entry->entry != abbrev_number; | |
2008 | entry = entry->next) | |
2009 | continue; | |
2010 | ||
2011 | if (entry == NULL) | |
2012 | /* FIXME: Issue a warning ? */ | |
2013 | return; | |
2014 | ||
2015 | for (attr = entry->first_attr; | |
2016 | attr != NULL && attr->attribute; | |
2017 | attr = attr->next) | |
2018 | { | |
2019 | dwarf_vma uvalue = 0; | |
2020 | ||
2021 | data = skip_attr_bytes (attr->form, data, end, pointer_size, | |
2022 | offset_size, dwarf_version, & uvalue); | |
2023 | if (data == NULL) | |
2024 | return; | |
2025 | ||
2026 | switch (attr->attribute) | |
2027 | { | |
2028 | #if 0 /* FIXME: It would be nice to print the name of the type, | |
2029 | but this would mean updating a lot of binutils tests. */ | |
2030 | case DW_AT_name: | |
2031 | if (attr->form == DW_FORM_strp) | |
2032 | printf ("%s", fetch_indirect_string (uvalue)); | |
2033 | break; | |
2034 | #endif | |
2035 | case DW_AT_type: | |
2036 | /* Recurse. */ | |
2037 | if (is_nested) | |
2038 | { | |
2039 | /* FIXME: Warn - or is this expected ? | |
2040 | NB/ We need to avoid infinite recursion. */ | |
2041 | return; | |
2042 | } | |
b3fe587e AM |
2043 | if (uvalue >= (size_t) (end - start)) |
2044 | return; | |
ec1b0fbb NC |
2045 | get_type_signedness (start, start + uvalue, end, pointer_size, |
2046 | offset_size, dwarf_version, is_signed, TRUE); | |
2047 | break; | |
2048 | ||
2049 | case DW_AT_encoding: | |
2050 | /* Determine signness. */ | |
2051 | switch (uvalue) | |
2052 | { | |
2053 | case DW_ATE_address: | |
2054 | /* FIXME - some architectures have signed addresses. */ | |
2055 | case DW_ATE_boolean: | |
2056 | case DW_ATE_unsigned: | |
2057 | case DW_ATE_unsigned_char: | |
2058 | case DW_ATE_unsigned_fixed: | |
2059 | * is_signed = FALSE; | |
2060 | break; | |
2061 | ||
2062 | default: | |
2063 | case DW_ATE_complex_float: | |
2064 | case DW_ATE_float: | |
2065 | case DW_ATE_signed: | |
2066 | case DW_ATE_signed_char: | |
2067 | case DW_ATE_imaginary_float: | |
2068 | case DW_ATE_decimal_float: | |
2069 | case DW_ATE_signed_fixed: | |
2070 | * is_signed = TRUE; | |
2071 | break; | |
2072 | } | |
2073 | break; | |
2074 | } | |
2075 | } | |
2076 | } | |
2077 | ||
2078 | static void | |
2079 | read_and_print_leb128 (unsigned char * data, | |
2080 | unsigned int * bytes_read, | |
2081 | unsigned const char * end, | |
2082 | bfd_boolean is_signed) | |
2083 | { | |
2084 | if (is_signed) | |
2085 | { | |
2086 | dwarf_signed_vma sval = read_sleb128 (data, bytes_read, end); | |
2087 | printf ("%ld", (long) sval); | |
2088 | } | |
2089 | else | |
2090 | { | |
2091 | dwarf_vma uval = read_uleb128 (data, bytes_read, end); | |
2092 | printf ("%lu", (unsigned long) uval); | |
2093 | } | |
2094 | } | |
2095 | ||
2096 | static void | |
2097 | display_discr_list (unsigned long form, | |
2098 | dwarf_vma uvalue, | |
2099 | unsigned char * data, | |
2100 | unsigned const char * end, | |
2101 | int level) | |
2102 | { | |
2103 | if (uvalue == 0) | |
2104 | { | |
2105 | printf ("[default]"); | |
2106 | return; | |
2107 | } | |
2108 | ||
2109 | switch (form) | |
2110 | { | |
2111 | case DW_FORM_block: | |
2112 | case DW_FORM_block1: | |
2113 | case DW_FORM_block2: | |
2114 | case DW_FORM_block4: | |
2115 | /* Move data pointer back to the start of the byte array. */ | |
2116 | data -= uvalue; | |
2117 | break; | |
2118 | default: | |
2119 | printf ("<corrupt>\n"); | |
2120 | warn (_("corrupt discr_list - not using a block form\n")); | |
2121 | return; | |
2122 | } | |
2123 | ||
2124 | if (uvalue < 2) | |
2125 | { | |
2126 | printf ("<corrupt>\n"); | |
2127 | warn (_("corrupt discr_list - block not long enough\n")); | |
2128 | return; | |
2129 | } | |
2130 | ||
2131 | bfd_boolean is_signed = | |
2132 | (level > 0 && level <= MAX_CU_NESTING) | |
2133 | ? level_type_signed [level - 1] : FALSE; | |
2134 | ||
2135 | printf ("("); | |
2136 | while (uvalue) | |
2137 | { | |
2138 | unsigned char discriminant; | |
2139 | unsigned int bytes_read; | |
2140 | ||
2141 | SAFE_BYTE_GET (discriminant, data, 1, end); | |
2142 | -- uvalue; | |
2143 | data ++; | |
2144 | ||
2145 | assert (uvalue > 0); | |
2146 | switch (discriminant) | |
2147 | { | |
2148 | case DW_DSC_label: | |
2149 | printf ("label "); | |
2150 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2151 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2152 | uvalue -= bytes_read; | |
2153 | data += bytes_read; | |
2154 | break; | |
2155 | ||
2156 | case DW_DSC_range: | |
2157 | printf ("range "); | |
2158 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2159 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2160 | uvalue -= bytes_read; | |
2161 | data += bytes_read; | |
2162 | ||
2163 | printf (".."); | |
2164 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2165 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2166 | uvalue -= bytes_read; | |
2167 | data += bytes_read; | |
2168 | break; | |
2169 | ||
2170 | default: | |
2171 | printf ("<corrupt>\n"); | |
2172 | warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"), | |
2173 | discriminant); | |
2174 | return; | |
2175 | } | |
2176 | ||
2177 | if (uvalue) | |
2178 | printf (", "); | |
2179 | } | |
2180 | ||
2181 | if (is_signed) | |
2182 | printf (")(signed)"); | |
2183 | else | |
2184 | printf (")(unsigned)"); | |
2185 | } | |
2186 | ||
19e6b90e | 2187 | static unsigned char * |
dda8d76d NC |
2188 | read_and_display_attr_value (unsigned long attribute, |
2189 | unsigned long form, | |
2190 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 2191 | unsigned char * start, |
dda8d76d NC |
2192 | unsigned char * data, |
2193 | unsigned char * end, | |
2194 | dwarf_vma cu_offset, | |
2195 | dwarf_vma pointer_size, | |
2196 | dwarf_vma offset_size, | |
2197 | int dwarf_version, | |
2198 | debug_info * debug_info_p, | |
2199 | int do_loc, | |
2200 | struct dwarf_section * section, | |
2201 | struct cu_tu_set * this_set, | |
ec1b0fbb NC |
2202 | char delimiter, |
2203 | int level) | |
19e6b90e | 2204 | { |
ec1b0fbb NC |
2205 | dwarf_vma uvalue = 0; |
2206 | unsigned char * block_start = NULL; | |
2207 | unsigned char * orig_data = data; | |
2208 | unsigned int bytes_read; | |
19e6b90e | 2209 | |
f41e4712 | 2210 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 2211 | { |
f41e4712 | 2212 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
2213 | return data; |
2214 | } | |
2215 | ||
19e6b90e L |
2216 | switch (form) |
2217 | { | |
2218 | default: | |
2219 | break; | |
2220 | ||
2221 | case DW_FORM_ref_addr: | |
2222 | if (dwarf_version == 2) | |
0c588247 | 2223 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
932fd279 | 2224 | else if (dwarf_version == 3 || dwarf_version == 4) |
0c588247 | 2225 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 2226 | else |
467c65bc NC |
2227 | error (_("Internal error: DWARF version is not 2, 3 or 4.\n")); |
2228 | ||
19e6b90e L |
2229 | break; |
2230 | ||
2231 | case DW_FORM_addr: | |
0c588247 | 2232 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
2233 | break; |
2234 | ||
2235 | case DW_FORM_strp: | |
77145576 | 2236 | case DW_FORM_line_strp: |
932fd279 | 2237 | case DW_FORM_sec_offset: |
a081f3cd JJ |
2238 | case DW_FORM_GNU_ref_alt: |
2239 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 2240 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
2241 | break; |
2242 | ||
932fd279 JJ |
2243 | case DW_FORM_flag_present: |
2244 | uvalue = 1; | |
2245 | break; | |
2246 | ||
19e6b90e L |
2247 | case DW_FORM_ref1: |
2248 | case DW_FORM_flag: | |
2249 | case DW_FORM_data1: | |
0c588247 | 2250 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
2251 | break; |
2252 | ||
2253 | case DW_FORM_ref2: | |
2254 | case DW_FORM_data2: | |
0c588247 | 2255 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
2256 | break; |
2257 | ||
2258 | case DW_FORM_ref4: | |
2259 | case DW_FORM_data4: | |
0c588247 | 2260 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
2261 | break; |
2262 | ||
2263 | case DW_FORM_sdata: | |
f6f0e17b | 2264 | uvalue = read_sleb128 (data, & bytes_read, end); |
19e6b90e L |
2265 | data += bytes_read; |
2266 | break; | |
2267 | ||
4723351a | 2268 | case DW_FORM_GNU_str_index: |
f6f0e17b | 2269 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
2270 | data += bytes_read; |
2271 | break; | |
2272 | ||
19e6b90e L |
2273 | case DW_FORM_ref_udata: |
2274 | case DW_FORM_udata: | |
f6f0e17b | 2275 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
2276 | data += bytes_read; |
2277 | break; | |
2278 | ||
2279 | case DW_FORM_indirect: | |
f6f0e17b | 2280 | form = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
2281 | data += bytes_read; |
2282 | if (!do_loc) | |
ef0b5f1c | 2283 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 JK |
2284 | if (form == DW_FORM_implicit_const) |
2285 | { | |
2286 | implicit_const = read_sleb128 (data, & bytes_read, end); | |
2287 | data += bytes_read; | |
2288 | } | |
ec1b0fbb NC |
2289 | return read_and_display_attr_value (attribute, form, implicit_const, |
2290 | start, data, end, | |
2291 | cu_offset, pointer_size, | |
19e6b90e | 2292 | offset_size, dwarf_version, |
ec4d4525 | 2293 | debug_info_p, do_loc, |
ec1b0fbb | 2294 | section, this_set, delimiter, level); |
4723351a | 2295 | case DW_FORM_GNU_addr_index: |
f6f0e17b | 2296 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
2297 | data += bytes_read; |
2298 | break; | |
19e6b90e L |
2299 | } |
2300 | ||
2301 | switch (form) | |
2302 | { | |
2303 | case DW_FORM_ref_addr: | |
2304 | if (!do_loc) | |
ef0b5f1c | 2305 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
19e6b90e L |
2306 | break; |
2307 | ||
a081f3cd JJ |
2308 | case DW_FORM_GNU_ref_alt: |
2309 | if (!do_loc) | |
ef0b5f1c | 2310 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
dda8d76d | 2311 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
2312 | break; |
2313 | ||
19e6b90e L |
2314 | case DW_FORM_ref1: |
2315 | case DW_FORM_ref2: | |
2316 | case DW_FORM_ref4: | |
2317 | case DW_FORM_ref_udata: | |
2318 | if (!do_loc) | |
ef0b5f1c | 2319 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
2320 | break; |
2321 | ||
2322 | case DW_FORM_data4: | |
2323 | case DW_FORM_addr: | |
932fd279 | 2324 | case DW_FORM_sec_offset: |
19e6b90e | 2325 | if (!do_loc) |
ef0b5f1c | 2326 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2327 | break; |
2328 | ||
932fd279 | 2329 | case DW_FORM_flag_present: |
19e6b90e L |
2330 | case DW_FORM_flag: |
2331 | case DW_FORM_data1: | |
2332 | case DW_FORM_data2: | |
2333 | case DW_FORM_sdata: | |
2334 | case DW_FORM_udata: | |
2335 | if (!do_loc) | |
ef0b5f1c | 2336 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
2337 | break; |
2338 | ||
77145576 JK |
2339 | case DW_FORM_implicit_const: |
2340 | if (!do_loc) | |
2341 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
2342 | break; | |
2343 | ||
19e6b90e L |
2344 | case DW_FORM_ref8: |
2345 | case DW_FORM_data8: | |
2bc8690c | 2346 | if (!do_loc) |
19e6b90e | 2347 | { |
74bc6052 | 2348 | dwarf_vma high_bits; |
a69c4772 | 2349 | dwarf_vma utmp; |
74bc6052 CC |
2350 | char buf[64]; |
2351 | ||
0c588247 | 2352 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
2353 | utmp = uvalue; |
2354 | if (form == DW_FORM_ref8) | |
2355 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 2356 | printf ("%c0x%s", delimiter, |
a69c4772 | 2357 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 2358 | } |
0c588247 | 2359 | |
19e6b90e L |
2360 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2361 | && num_debug_info_entries == 0) | |
2362 | { | |
2363 | if (sizeof (uvalue) == 8) | |
0c588247 | 2364 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 2365 | else |
467c65bc | 2366 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 2367 | } |
0c588247 | 2368 | |
19e6b90e L |
2369 | data += 8; |
2370 | break; | |
2371 | ||
2f6cd591 JK |
2372 | case DW_FORM_data16: |
2373 | if (!do_loc) | |
2374 | { | |
2375 | dwarf_vma left_high_bits, left_low_bits; | |
2376 | dwarf_vma right_high_bits, right_low_bits; | |
2377 | ||
2378 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
2379 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
2380 | if (byte_get == byte_get_little_endian) | |
2381 | { | |
2382 | /* Swap them. */ | |
2383 | left_high_bits ^= right_high_bits; | |
2384 | right_high_bits ^= left_high_bits; | |
2385 | left_high_bits ^= right_high_bits; | |
2386 | left_low_bits ^= right_low_bits; | |
2387 | right_low_bits ^= left_low_bits; | |
2388 | left_low_bits ^= right_low_bits; | |
2389 | } | |
2390 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
2391 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
2392 | left_high_bits, left_low_bits, right_high_bits, | |
2393 | right_low_bits); | |
2394 | } | |
2395 | data += 16; | |
2396 | break; | |
2397 | ||
19e6b90e L |
2398 | case DW_FORM_string: |
2399 | if (!do_loc) | |
ef0b5f1c | 2400 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 2401 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
2402 | break; |
2403 | ||
2404 | case DW_FORM_block: | |
932fd279 | 2405 | case DW_FORM_exprloc: |
f6f0e17b | 2406 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e | 2407 | block_start = data + bytes_read; |
a1165289 NC |
2408 | if (block_start >= end) |
2409 | { | |
2410 | warn (_("Block ends prematurely\n")); | |
2411 | uvalue = 0; | |
2412 | block_start = end; | |
2413 | } | |
afc72f15 NC |
2414 | |
2415 | uvalue = check_uvalue (block_start, uvalue, end); | |
2416 | ||
19e6b90e L |
2417 | if (do_loc) |
2418 | data = block_start + uvalue; | |
2419 | else | |
ef0b5f1c | 2420 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2421 | break; |
2422 | ||
2423 | case DW_FORM_block1: | |
0c588247 | 2424 | SAFE_BYTE_GET (uvalue, data, 1, end); |
19e6b90e | 2425 | block_start = data + 1; |
a1165289 NC |
2426 | if (block_start >= end) |
2427 | { | |
2428 | warn (_("Block ends prematurely\n")); | |
2429 | uvalue = 0; | |
2430 | block_start = end; | |
2431 | } | |
afc72f15 NC |
2432 | |
2433 | uvalue = check_uvalue (block_start, uvalue, end); | |
2434 | ||
19e6b90e L |
2435 | if (do_loc) |
2436 | data = block_start + uvalue; | |
2437 | else | |
ef0b5f1c | 2438 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2439 | break; |
2440 | ||
2441 | case DW_FORM_block2: | |
0c588247 | 2442 | SAFE_BYTE_GET (uvalue, data, 2, end); |
19e6b90e | 2443 | block_start = data + 2; |
a1165289 NC |
2444 | if (block_start >= end) |
2445 | { | |
2446 | warn (_("Block ends prematurely\n")); | |
2447 | uvalue = 0; | |
2448 | block_start = end; | |
2449 | } | |
afc72f15 NC |
2450 | |
2451 | uvalue = check_uvalue (block_start, uvalue, end); | |
2452 | ||
19e6b90e L |
2453 | if (do_loc) |
2454 | data = block_start + uvalue; | |
2455 | else | |
ef0b5f1c | 2456 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2457 | break; |
2458 | ||
2459 | case DW_FORM_block4: | |
0c588247 | 2460 | SAFE_BYTE_GET (uvalue, data, 4, end); |
19e6b90e | 2461 | block_start = data + 4; |
a1165289 NC |
2462 | /* PR 17512: file: 3371-3907-0.004. */ |
2463 | if (block_start >= end) | |
2464 | { | |
2465 | warn (_("Block ends prematurely\n")); | |
2466 | uvalue = 0; | |
2467 | block_start = end; | |
2468 | } | |
afc72f15 NC |
2469 | |
2470 | uvalue = check_uvalue (block_start, uvalue, end); | |
2471 | ||
19e6b90e L |
2472 | if (do_loc) |
2473 | data = block_start + uvalue; | |
2474 | else | |
ef0b5f1c | 2475 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2476 | break; |
2477 | ||
2478 | case DW_FORM_strp: | |
2479 | if (!do_loc) | |
ef0b5f1c | 2480 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, |
47704ddf KT |
2481 | dwarf_vmatoa ("x", uvalue), |
2482 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
2483 | break; |
2484 | ||
77145576 JK |
2485 | case DW_FORM_line_strp: |
2486 | if (!do_loc) | |
2487 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2488 | dwarf_vmatoa ("x", uvalue), | |
2489 | fetch_indirect_line_string (uvalue)); | |
2490 | break; | |
2491 | ||
4723351a CC |
2492 | case DW_FORM_GNU_str_index: |
2493 | if (!do_loc) | |
b4eb7656 | 2494 | { |
d85bf2ba NC |
2495 | const char * suffix = strrchr (section->name, '.'); |
2496 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
b4eb7656 | 2497 | |
ef0b5f1c | 2498 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2499 | dwarf_vmatoa ("x", uvalue), |
2500 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2501 | } | |
4723351a CC |
2502 | break; |
2503 | ||
a081f3cd JJ |
2504 | case DW_FORM_GNU_strp_alt: |
2505 | if (!do_loc) | |
dda8d76d NC |
2506 | { |
2507 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2508 | dwarf_vmatoa ("x", uvalue), | |
2509 | fetch_alt_indirect_string (uvalue)); | |
2510 | } | |
a081f3cd JJ |
2511 | break; |
2512 | ||
19e6b90e L |
2513 | case DW_FORM_indirect: |
2514 | /* Handled above. */ | |
2515 | break; | |
2516 | ||
2b6f5997 CC |
2517 | case DW_FORM_ref_sig8: |
2518 | if (!do_loc) | |
2519 | { | |
74bc6052 CC |
2520 | dwarf_vma high_bits; |
2521 | char buf[64]; | |
2522 | ||
0c588247 | 2523 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
ef0b5f1c | 2524 | printf ("%csignature: 0x%s", delimiter, |
74bc6052 | 2525 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); |
2b6f5997 | 2526 | } |
74bc6052 | 2527 | data += 8; |
2b6f5997 CC |
2528 | break; |
2529 | ||
4723351a CC |
2530 | case DW_FORM_GNU_addr_index: |
2531 | if (!do_loc) | |
ef0b5f1c | 2532 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2533 | dwarf_vmatoa ("x", uvalue), |
2534 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
4723351a CC |
2535 | break; |
2536 | ||
19e6b90e L |
2537 | default: |
2538 | warn (_("Unrecognized form: %lu\n"), form); | |
2539 | break; | |
2540 | } | |
2541 | ||
19e6b90e | 2542 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2543 | && num_debug_info_entries == 0 |
2544 | && debug_info_p != NULL) | |
19e6b90e L |
2545 | { |
2546 | switch (attribute) | |
2547 | { | |
2548 | case DW_AT_frame_base: | |
2549 | have_frame_base = 1; | |
1a0670f3 | 2550 | /* Fall through. */ |
19e6b90e | 2551 | case DW_AT_location: |
9f272209 | 2552 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2553 | case DW_AT_string_length: |
2554 | case DW_AT_return_addr: | |
19e6b90e L |
2555 | case DW_AT_data_member_location: |
2556 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2557 | case DW_AT_segment: |
2558 | case DW_AT_static_link: | |
2559 | case DW_AT_use_location: | |
bc0a77d2 | 2560 | case DW_AT_call_value: |
629e7ca8 | 2561 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2562 | case DW_AT_call_data_value: |
629e7ca8 | 2563 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2564 | case DW_AT_call_target: |
629e7ca8 | 2565 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2566 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2567 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2568 | if ((dwarf_version < 4 |
212b6063 | 2569 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2570 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2571 | { |
2572 | /* Process location list. */ | |
91d6fa6a | 2573 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2574 | unsigned int num = debug_info_p->num_loc_offsets; |
2575 | ||
91d6fa6a | 2576 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2577 | { |
91d6fa6a | 2578 | lmax += 1024; |
467c65bc | 2579 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2580 | xcrealloc (debug_info_p->loc_offsets, |
2581 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2582 | debug_info_p->loc_views = (dwarf_vma *) |
2583 | xcrealloc (debug_info_p->loc_views, | |
2584 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2585 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2586 | xcrealloc (debug_info_p->have_frame_base, |
2587 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2588 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2589 | } |
341f9135 | 2590 | if (this_set != NULL) |
b4eb7656 | 2591 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2592 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2593 | if (attribute != DW_AT_GNU_locviews) |
2594 | { | |
a7504f87 NC |
2595 | /* Corrupt DWARF info can produce more offsets than views. |
2596 | See PR 23062 for an example. */ | |
2597 | if (debug_info_p->num_loc_offsets | |
2598 | > debug_info_p->num_loc_views) | |
2599 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2600 | else | |
2601 | { | |
2602 | debug_info_p->loc_offsets [num] = uvalue; | |
2603 | debug_info_p->num_loc_offsets++; | |
2604 | } | |
9f272209 AO |
2605 | } |
2606 | else | |
2607 | { | |
2608 | assert (debug_info_p->num_loc_views <= num); | |
2609 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2610 | if (num > debug_info_p->num_loc_offsets) |
2611 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2612 | else | |
2613 | { | |
2614 | debug_info_p->loc_views [num] = uvalue; | |
2615 | debug_info_p->num_loc_views++; | |
2616 | } | |
9f272209 | 2617 | } |
19e6b90e L |
2618 | } |
2619 | break; | |
e2a0d921 | 2620 | |
19e6b90e L |
2621 | case DW_AT_low_pc: |
2622 | if (need_base_address) | |
2623 | debug_info_p->base_address = uvalue; | |
2624 | break; | |
2625 | ||
4723351a | 2626 | case DW_AT_GNU_addr_base: |
b4eb7656 | 2627 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2628 | break; |
2629 | ||
2630 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2631 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2632 | break; |
2633 | ||
19e6b90e | 2634 | case DW_AT_ranges: |
b4eb7656 | 2635 | if ((dwarf_version < 4 |
212b6063 | 2636 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2637 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2638 | { |
2639 | /* Process range list. */ | |
91d6fa6a | 2640 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2641 | unsigned int num = debug_info_p->num_range_lists; |
2642 | ||
91d6fa6a | 2643 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2644 | { |
91d6fa6a | 2645 | lmax += 1024; |
467c65bc | 2646 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2647 | xcrealloc (debug_info_p->range_lists, |
2648 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2649 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2650 | } |
2651 | debug_info_p->range_lists [num] = uvalue; | |
2652 | debug_info_p->num_range_lists++; | |
2653 | } | |
2654 | break; | |
2655 | ||
d85bf2ba NC |
2656 | case DW_AT_GNU_dwo_name: |
2657 | case DW_AT_dwo_name: | |
2658 | if (need_dwo_info) | |
2659 | switch (form) | |
2660 | { | |
2661 | case DW_FORM_strp: | |
24841daa | 2662 | add_dwo_name ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba NC |
2663 | break; |
2664 | case DW_FORM_GNU_str_index: | |
24841daa | 2665 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2666 | break; |
2667 | case DW_FORM_string: | |
24841daa | 2668 | add_dwo_name ((const char *) orig_data); |
d85bf2ba NC |
2669 | break; |
2670 | default: | |
2671 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2672 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2673 | break; |
2674 | } | |
2675 | break; | |
2676 | ||
2677 | case DW_AT_comp_dir: | |
2678 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2679 | if (need_dwo_info) | |
2680 | switch (form) | |
2681 | { | |
2682 | case DW_FORM_strp: | |
24841daa | 2683 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba NC |
2684 | break; |
2685 | case DW_FORM_line_strp: | |
24841daa | 2686 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue)); |
d85bf2ba NC |
2687 | break; |
2688 | case DW_FORM_GNU_str_index: | |
24841daa | 2689 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2690 | break; |
2691 | case DW_FORM_string: | |
24841daa | 2692 | add_dwo_dir ((const char *) orig_data); |
d85bf2ba NC |
2693 | break; |
2694 | default: | |
2695 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2696 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2697 | break; |
2698 | } | |
2699 | break; | |
2700 | ||
2701 | case DW_AT_GNU_dwo_id: | |
2702 | if (need_dwo_info) | |
2703 | switch (form) | |
2704 | { | |
2705 | case DW_FORM_data8: | |
24841daa NC |
2706 | /* FIXME: Record the length of the ID as well ? */ |
2707 | add_dwo_id ((const char *) (data - 8)); | |
d85bf2ba NC |
2708 | break; |
2709 | default: | |
2710 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2711 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2712 | break; |
2713 | } | |
2714 | break; | |
2715 | ||
19e6b90e L |
2716 | default: |
2717 | break; | |
2718 | } | |
2719 | } | |
2720 | ||
4ccf1e31 | 2721 | if (do_loc || attribute == 0) |
19e6b90e L |
2722 | return data; |
2723 | ||
ec4d4525 | 2724 | /* For some attributes we can display further information. */ |
19e6b90e L |
2725 | switch (attribute) |
2726 | { | |
ec1b0fbb | 2727 | case DW_AT_type: |
b3fe587e AM |
2728 | if (level >= 0 && level < MAX_CU_NESTING |
2729 | && uvalue < (size_t) (end - start)) | |
ec1b0fbb NC |
2730 | { |
2731 | bfd_boolean is_signed = FALSE; | |
2732 | ||
2733 | get_type_signedness (start, start + uvalue, end, pointer_size, | |
2734 | offset_size, dwarf_version, & is_signed, FALSE); | |
2735 | level_type_signed[level] = is_signed; | |
2736 | } | |
2737 | break; | |
2738 | ||
19e6b90e | 2739 | case DW_AT_inline: |
2e9e81a8 | 2740 | printf ("\t"); |
19e6b90e L |
2741 | switch (uvalue) |
2742 | { | |
2743 | case DW_INL_not_inlined: | |
2744 | printf (_("(not inlined)")); | |
2745 | break; | |
2746 | case DW_INL_inlined: | |
2747 | printf (_("(inlined)")); | |
2748 | break; | |
2749 | case DW_INL_declared_not_inlined: | |
2750 | printf (_("(declared as inline but ignored)")); | |
2751 | break; | |
2752 | case DW_INL_declared_inlined: | |
2753 | printf (_("(declared as inline and inlined)")); | |
2754 | break; | |
2755 | default: | |
47704ddf KT |
2756 | printf (_(" (Unknown inline attribute value: %s)"), |
2757 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
2758 | break; |
2759 | } | |
2760 | break; | |
2761 | ||
2762 | case DW_AT_language: | |
2e9e81a8 | 2763 | printf ("\t"); |
19e6b90e L |
2764 | switch (uvalue) |
2765 | { | |
4b78141a | 2766 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 2767 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
2768 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
2769 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 2770 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
2771 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
2772 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
2773 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
2774 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 2775 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 2776 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 2777 | /* DWARF 2.1 values. */ |
4b78141a | 2778 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
2779 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
2780 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
2781 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
2782 | /* DWARF 3 values. */ |
2783 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
2784 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
2785 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
2786 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
2787 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
2788 | /* DWARF 4 values. */ |
2789 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 2790 | /* DWARF 5 values. */ |
2008a0db | 2791 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 2792 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
2793 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
2794 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
2795 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 2796 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
2797 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
2798 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 2799 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
2800 | case DW_LANG_Swift: printf ("(Swift)"); break; |
2801 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
2802 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 2803 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
2804 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
2805 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 2806 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
2807 | /* MIPS extension. */ |
2808 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
2809 | /* UPC extension. */ | |
2810 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
2811 | default: | |
4b78141a | 2812 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 2813 | printf (_("(implementation defined: %s)"), |
467c65bc | 2814 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 2815 | else |
9cf03b7e | 2816 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2817 | break; |
2818 | } | |
2819 | break; | |
2820 | ||
2821 | case DW_AT_encoding: | |
2e9e81a8 | 2822 | printf ("\t"); |
19e6b90e L |
2823 | switch (uvalue) |
2824 | { | |
2825 | case DW_ATE_void: printf ("(void)"); break; | |
2826 | case DW_ATE_address: printf ("(machine address)"); break; | |
2827 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
2828 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
2829 | case DW_ATE_float: printf ("(float)"); break; | |
2830 | case DW_ATE_signed: printf ("(signed)"); break; | |
2831 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
2832 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
2833 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 2834 | /* DWARF 2.1 values: */ |
19e6b90e L |
2835 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
2836 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
2837 | /* DWARF 3 values: */ |
2838 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
2839 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
2840 | case DW_ATE_edited: printf ("(edited)"); break; | |
2841 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
2842 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
2843 | /* DWARF 4 values: */ |
2844 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
2845 | /* DWARF 5 values: */ | |
2846 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
2847 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
2848 | ||
e2a0d921 NC |
2849 | /* HP extensions: */ |
2850 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
2851 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
2852 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
2853 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
2854 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
2855 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
2856 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
2857 | ||
19e6b90e L |
2858 | default: |
2859 | if (uvalue >= DW_ATE_lo_user | |
2860 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 2861 | printf (_("(user defined type)")); |
19e6b90e | 2862 | else |
9cf03b7e | 2863 | printf (_("(unknown type)")); |
19e6b90e L |
2864 | break; |
2865 | } | |
2866 | break; | |
2867 | ||
2868 | case DW_AT_accessibility: | |
2e9e81a8 | 2869 | printf ("\t"); |
19e6b90e L |
2870 | switch (uvalue) |
2871 | { | |
2872 | case DW_ACCESS_public: printf ("(public)"); break; | |
2873 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
2874 | case DW_ACCESS_private: printf ("(private)"); break; | |
2875 | default: | |
9cf03b7e | 2876 | printf (_("(unknown accessibility)")); |
19e6b90e L |
2877 | break; |
2878 | } | |
2879 | break; | |
2880 | ||
2881 | case DW_AT_visibility: | |
2e9e81a8 | 2882 | printf ("\t"); |
19e6b90e L |
2883 | switch (uvalue) |
2884 | { | |
2885 | case DW_VIS_local: printf ("(local)"); break; | |
2886 | case DW_VIS_exported: printf ("(exported)"); break; | |
2887 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 2888 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
2889 | } |
2890 | break; | |
2891 | ||
04914e37 NC |
2892 | case DW_AT_endianity: |
2893 | printf ("\t"); | |
2894 | switch (uvalue) | |
2895 | { | |
2896 | case DW_END_default: printf ("(default)"); break; | |
2897 | case DW_END_big: printf ("(big)"); break; | |
2898 | case DW_END_little: printf ("(little)"); break; | |
2899 | default: | |
2900 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
2901 | printf (_("(user specified)")); | |
2902 | else | |
2903 | printf (_("(unknown endianity)")); | |
2904 | break; | |
2905 | } | |
2906 | break; | |
2907 | ||
19e6b90e | 2908 | case DW_AT_virtuality: |
2e9e81a8 | 2909 | printf ("\t"); |
19e6b90e L |
2910 | switch (uvalue) |
2911 | { | |
2912 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
2913 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
2914 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 2915 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
2916 | } |
2917 | break; | |
2918 | ||
2919 | case DW_AT_identifier_case: | |
2e9e81a8 | 2920 | printf ("\t"); |
19e6b90e L |
2921 | switch (uvalue) |
2922 | { | |
2923 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
2924 | case DW_ID_up_case: printf ("(up_case)"); break; | |
2925 | case DW_ID_down_case: printf ("(down_case)"); break; | |
2926 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 2927 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
2928 | } |
2929 | break; | |
2930 | ||
2931 | case DW_AT_calling_convention: | |
2e9e81a8 | 2932 | printf ("\t"); |
19e6b90e L |
2933 | switch (uvalue) |
2934 | { | |
2935 | case DW_CC_normal: printf ("(normal)"); break; | |
2936 | case DW_CC_program: printf ("(program)"); break; | |
2937 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
2938 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
2939 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
2940 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
2941 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
2942 | default: |
2943 | if (uvalue >= DW_CC_lo_user | |
2944 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 2945 | printf (_("(user defined)")); |
19e6b90e | 2946 | else |
9cf03b7e | 2947 | printf (_("(unknown convention)")); |
19e6b90e L |
2948 | } |
2949 | break; | |
2950 | ||
2951 | case DW_AT_ordering: | |
2e9e81a8 | 2952 | printf ("\t"); |
19e6b90e L |
2953 | switch (uvalue) |
2954 | { | |
04914e37 | 2955 | case 255: |
9cf03b7e | 2956 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
2957 | case 0: printf ("(row major)"); break; |
2958 | case 1: printf ("(column major)"); break; | |
2959 | } | |
2960 | break; | |
2961 | ||
04914e37 NC |
2962 | case DW_AT_decimal_sign: |
2963 | printf ("\t"); | |
2964 | switch (uvalue) | |
2965 | { | |
2966 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
2967 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
2968 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
2969 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
2970 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
2971 | default: printf (_("(unrecognised)")); break; | |
2972 | } | |
2973 | break; | |
2974 | ||
2975 | case DW_AT_defaulted: | |
2976 | printf ("\t"); | |
2977 | switch (uvalue) | |
2978 | { | |
2979 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
2980 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
2981 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
2982 | default: printf (_("(unrecognised)")); break; | |
2983 | } | |
2984 | break; | |
2985 | ||
2986 | case DW_AT_discr_list: | |
2987 | printf ("\t"); | |
ec1b0fbb | 2988 | display_discr_list (form, uvalue, data, end, level); |
04914e37 NC |
2989 | break; |
2990 | ||
19e6b90e L |
2991 | case DW_AT_frame_base: |
2992 | have_frame_base = 1; | |
1a0670f3 | 2993 | /* Fall through. */ |
19e6b90e | 2994 | case DW_AT_location: |
e2a0d921 NC |
2995 | case DW_AT_string_length: |
2996 | case DW_AT_return_addr: | |
19e6b90e L |
2997 | case DW_AT_data_member_location: |
2998 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2999 | case DW_AT_segment: |
3000 | case DW_AT_static_link: | |
3001 | case DW_AT_use_location: | |
bc0a77d2 | 3002 | case DW_AT_call_value: |
629e7ca8 | 3003 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 3004 | case DW_AT_call_data_value: |
629e7ca8 | 3005 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 3006 | case DW_AT_call_target: |
629e7ca8 | 3007 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 3008 | case DW_AT_call_target_clobbered: |
629e7ca8 | 3009 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 3010 | if ((dwarf_version < 4 |
b4eb7656 | 3011 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 3012 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 3013 | printf (_(" (location list)")); |
e2a0d921 | 3014 | /* Fall through. */ |
19e6b90e L |
3015 | case DW_AT_allocated: |
3016 | case DW_AT_associated: | |
3017 | case DW_AT_data_location: | |
3018 | case DW_AT_stride: | |
3019 | case DW_AT_upper_bound: | |
cecf136e | 3020 | case DW_AT_lower_bound: |
19e6b90e L |
3021 | if (block_start) |
3022 | { | |
3023 | int need_frame_base; | |
3024 | ||
2e9e81a8 | 3025 | printf ("\t("); |
19e6b90e L |
3026 | need_frame_base = decode_location_expression (block_start, |
3027 | pointer_size, | |
b7807392 JJ |
3028 | offset_size, |
3029 | dwarf_version, | |
19e6b90e | 3030 | uvalue, |
f1c4cc75 | 3031 | cu_offset, section); |
19e6b90e L |
3032 | printf (")"); |
3033 | if (need_frame_base && !have_frame_base) | |
3034 | printf (_(" [without DW_AT_frame_base]")); | |
3035 | } | |
19e6b90e L |
3036 | break; |
3037 | ||
c54207d3 NC |
3038 | case DW_AT_data_bit_offset: |
3039 | case DW_AT_byte_size: | |
3040 | case DW_AT_bit_size: | |
3041 | case DW_AT_string_length_byte_size: | |
3042 | case DW_AT_string_length_bit_size: | |
3043 | case DW_AT_bit_stride: | |
3044 | if (form == DW_FORM_exprloc) | |
3045 | { | |
3046 | printf ("\t("); | |
3047 | (void) decode_location_expression (block_start, pointer_size, | |
3048 | offset_size, dwarf_version, | |
3049 | uvalue, cu_offset, section); | |
3050 | printf (")"); | |
3051 | } | |
3052 | break; | |
3053 | ||
ec4d4525 NC |
3054 | case DW_AT_import: |
3055 | { | |
a081f3cd JJ |
3056 | if (form == DW_FORM_ref_sig8 |
3057 | || form == DW_FORM_GNU_ref_alt) | |
b4eb7656 | 3058 | break; |
2b6f5997 | 3059 | |
ec4d4525 NC |
3060 | if (form == DW_FORM_ref1 |
3061 | || form == DW_FORM_ref2 | |
a7a0b6a5 JK |
3062 | || form == DW_FORM_ref4 |
3063 | || form == DW_FORM_ref_udata) | |
ec4d4525 NC |
3064 | uvalue += cu_offset; |
3065 | ||
6e3d6dc1 | 3066 | if (uvalue >= section->size) |
f3853b34 | 3067 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), |
47704ddf KT |
3068 | dwarf_vmatoa ("x", uvalue), |
3069 | (unsigned long) (orig_data - section->start)); | |
6e3d6dc1 NC |
3070 | else |
3071 | { | |
3072 | unsigned long abbrev_number; | |
3073 | abbrev_entry * entry; | |
3074 | ||
f6f0e17b | 3075 | abbrev_number = read_uleb128 (section->start + uvalue, NULL, end); |
cecf136e | 3076 | |
2e9e81a8 | 3077 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
afd6e1ff JJ |
3078 | /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
3079 | use different abbrev table, and we don't track .debug_info chunks | |
3080 | yet. */ | |
3081 | if (form != DW_FORM_ref_addr) | |
3082 | { | |
3083 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
3084 | if (entry->entry == abbrev_number) | |
3085 | break; | |
3086 | if (entry != NULL) | |
3087 | printf (" (%s)", get_TAG_name (entry->tag)); | |
3088 | } | |
6e3d6dc1 NC |
3089 | printf ("]"); |
3090 | } | |
ec4d4525 NC |
3091 | } |
3092 | break; | |
3093 | ||
19e6b90e L |
3094 | default: |
3095 | break; | |
3096 | } | |
3097 | ||
3098 | return data; | |
3099 | } | |
3100 | ||
19e6b90e | 3101 | static unsigned char * |
dda8d76d NC |
3102 | read_and_display_attr (unsigned long attribute, |
3103 | unsigned long form, | |
3104 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 3105 | unsigned char * start, |
dda8d76d NC |
3106 | unsigned char * data, |
3107 | unsigned char * end, | |
3108 | dwarf_vma cu_offset, | |
3109 | dwarf_vma pointer_size, | |
3110 | dwarf_vma offset_size, | |
3111 | int dwarf_version, | |
3112 | debug_info * debug_info_p, | |
3113 | int do_loc, | |
3114 | struct dwarf_section * section, | |
ec1b0fbb NC |
3115 | struct cu_tu_set * this_set, |
3116 | int level) | |
19e6b90e L |
3117 | { |
3118 | if (!do_loc) | |
750f03b7 | 3119 | printf (" %-18s:", get_AT_name (attribute)); |
ec1b0fbb NC |
3120 | data = read_and_display_attr_value (attribute, form, implicit_const, |
3121 | start, data, end, | |
f6f0e17b | 3122 | cu_offset, pointer_size, offset_size, |
19e6b90e | 3123 | dwarf_version, debug_info_p, |
ec1b0fbb | 3124 | do_loc, section, this_set, ' ', level); |
19e6b90e L |
3125 | if (!do_loc) |
3126 | printf ("\n"); | |
3127 | return data; | |
3128 | } | |
3129 | ||
dda8d76d | 3130 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
3131 | following debug links, then attempt to load the requested section |
3132 | from one of the separate debug info files. */ | |
dda8d76d NC |
3133 | |
3134 | static bfd_boolean | |
3135 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, | |
24841daa | 3136 | void * handle) |
dda8d76d | 3137 | { |
24841daa | 3138 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 3139 | { |
24841daa NC |
3140 | if (debug_displays[sec_enum].section.filename == NULL) |
3141 | { | |
3142 | /* See if we can associate a filename with this section. */ | |
3143 | separate_info * i; | |
3144 | ||
3145 | for (i = first_separate_info; i != NULL; i = i->next) | |
3146 | if (i->handle == handle) | |
3147 | { | |
3148 | debug_displays[sec_enum].section.filename = i->filename; | |
3149 | break; | |
3150 | } | |
3151 | } | |
3152 | ||
dda8d76d NC |
3153 | return TRUE; |
3154 | } | |
3155 | ||
24841daa NC |
3156 | if (do_follow_links) |
3157 | { | |
3158 | separate_info * i; | |
3159 | ||
3160 | for (i = first_separate_info; i != NULL; i = i->next) | |
3161 | { | |
3162 | if (load_debug_section (sec_enum, i->handle)) | |
3163 | { | |
3164 | debug_displays[sec_enum].section.filename = i->filename; | |
3165 | ||
3166 | /* FIXME: We should check to see if any of the remaining debug info | |
3167 | files also contain this section, and, umm, do something about it. */ | |
3168 | return TRUE; | |
3169 | } | |
3170 | } | |
3171 | } | |
dda8d76d NC |
3172 | |
3173 | return FALSE; | |
3174 | } | |
3175 | ||
3176 | static void | |
3177 | introduce (struct dwarf_section * section, bfd_boolean raw) | |
3178 | { | |
3179 | if (raw) | |
3180 | { | |
3181 | if (do_follow_links && section->filename) | |
3182 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
3183 | section->name, section->filename); | |
3184 | else | |
3185 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
3186 | } | |
3187 | else | |
3188 | { | |
3189 | if (do_follow_links && section->filename) | |
3190 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
3191 | section->name, section->filename); | |
3192 | else | |
3193 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3194 | } | |
3195 | } | |
3196 | ||
d85bf2ba NC |
3197 | /* Process the contents of a .debug_info section. |
3198 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
3199 | and we do not want to display anything to the user. | |
3200 | If do_types is TRUE, we are processing a .debug_types section instead of | |
3201 | a .debug_info section. | |
3202 | The information displayed is restricted by the values in DWARF_START_DIE | |
3203 | and DWARF_CUTOFF_LEVEL. | |
3204 | Returns TRUE upon success. Otherwise an error or warning message is | |
3205 | printed and FALSE is returned. */ | |
19e6b90e | 3206 | |
d85bf2ba NC |
3207 | static bfd_boolean |
3208 | process_debug_info (struct dwarf_section * section, | |
3209 | void * file, | |
3210 | enum dwarf_section_display_enum abbrev_sec, | |
3211 | bfd_boolean do_loc, | |
3212 | bfd_boolean do_types) | |
19e6b90e L |
3213 | { |
3214 | unsigned char *start = section->start; | |
3215 | unsigned char *end = start + section->size; | |
3216 | unsigned char *section_begin; | |
3217 | unsigned int unit; | |
3218 | unsigned int num_units = 0; | |
3219 | ||
3220 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3221 | && num_debug_info_entries == 0 |
3222 | && ! do_types) | |
19e6b90e | 3223 | { |
767221a9 | 3224 | dwarf_vma length; |
19e6b90e L |
3225 | |
3226 | /* First scan the section to get the number of comp units. */ | |
3227 | for (section_begin = start, num_units = 0; section_begin < end; | |
3228 | num_units ++) | |
3229 | { | |
3230 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
3231 | will be the length. For a 64-bit DWARF section, it'll be | |
3232 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 3233 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
3234 | |
3235 | if (length == 0xffffffff) | |
3236 | { | |
0c588247 | 3237 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
3238 | section_begin += length + 12; |
3239 | } | |
ec4d4525 NC |
3240 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
3241 | { | |
767221a9 NC |
3242 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
3243 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3244 | return FALSE; |
ec4d4525 | 3245 | } |
19e6b90e L |
3246 | else |
3247 | section_begin += length + 4; | |
aca88567 NC |
3248 | |
3249 | /* Negative values are illegal, they may even cause infinite | |
3250 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
3251 | relocations to an object file, or if the file is corrupt. */ |
3252 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 3253 | { |
767221a9 NC |
3254 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
3255 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3256 | return FALSE; |
aca88567 | 3257 | } |
19e6b90e L |
3258 | } |
3259 | ||
3260 | if (num_units == 0) | |
3261 | { | |
f41e4712 | 3262 | error (_("No comp units in %s section ?\n"), section->name); |
d85bf2ba | 3263 | return FALSE; |
19e6b90e L |
3264 | } |
3265 | ||
3266 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 3267 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 3268 | sizeof (* debug_information)); |
19e6b90e L |
3269 | if (debug_information == NULL) |
3270 | { | |
f41e4712 | 3271 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 3272 | num_units); |
82b1b41b | 3273 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
d85bf2ba | 3274 | return FALSE; |
19e6b90e | 3275 | } |
d85bf2ba | 3276 | |
03a91817 NC |
3277 | /* PR 17531: file: 92ca3797. |
3278 | We cannot rely upon the debug_information array being initialised | |
3279 | before it is used. A corrupt file could easily contain references | |
3280 | to a unit for which information has not been made available. So | |
3281 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
3282 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
3283 | ||
82b1b41b | 3284 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
3285 | } |
3286 | ||
3287 | if (!do_loc) | |
3288 | { | |
dda8d76d NC |
3289 | load_debug_section_with_follow (str, file); |
3290 | load_debug_section_with_follow (line_str, file); | |
3291 | load_debug_section_with_follow (str_dwo, file); | |
3292 | load_debug_section_with_follow (str_index, file); | |
3293 | load_debug_section_with_follow (str_index_dwo, file); | |
3294 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e L |
3295 | } |
3296 | ||
dda8d76d | 3297 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 3298 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
3299 | { |
3300 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 3301 | debug_displays [abbrev_sec].section.uncompressed_name); |
d85bf2ba | 3302 | return FALSE; |
19e6b90e L |
3303 | } |
3304 | ||
dda8d76d NC |
3305 | if (!do_loc && dwarf_start_die == 0) |
3306 | introduce (section, FALSE); | |
3307 | ||
19e6b90e L |
3308 | for (section_begin = start, unit = 0; start < end; unit++) |
3309 | { | |
3310 | DWARF2_Internal_CompUnit compunit; | |
3311 | unsigned char *hdrptr; | |
19e6b90e | 3312 | unsigned char *tags; |
fd2f0033 | 3313 | int level, last_level, saved_level; |
467c65bc | 3314 | dwarf_vma cu_offset; |
e98fdf1a | 3315 | unsigned long sec_off; |
bf5117e3 | 3316 | unsigned int offset_size; |
19485196 | 3317 | unsigned int initial_length_size; |
74bc6052 CC |
3318 | dwarf_vma signature_high = 0; |
3319 | dwarf_vma signature_low = 0; | |
767221a9 | 3320 | dwarf_vma type_offset = 0; |
341f9135 CC |
3321 | struct cu_tu_set *this_set; |
3322 | dwarf_vma abbrev_base; | |
3323 | size_t abbrev_size; | |
19e6b90e L |
3324 | |
3325 | hdrptr = start; | |
3326 | ||
0c588247 | 3327 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
3328 | |
3329 | if (compunit.cu_length == 0xffffffff) | |
3330 | { | |
0c588247 | 3331 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
3332 | offset_size = 8; |
3333 | initial_length_size = 12; | |
3334 | } | |
3335 | else | |
3336 | { | |
3337 | offset_size = 4; | |
3338 | initial_length_size = 4; | |
3339 | } | |
3340 | ||
0c588247 | 3341 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
3342 | |
3343 | cu_offset = start - section_begin; | |
19e6b90e | 3344 | |
341f9135 CC |
3345 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3346 | ||
77145576 JK |
3347 | if (compunit.cu_version < 5) |
3348 | { | |
3349 | compunit.cu_unit_type = DW_UT_compile; | |
3350 | /* Initialize it due to a false compiler warning. */ | |
3351 | compunit.cu_pointer_size = -1; | |
3352 | } | |
3353 | else | |
3354 | { | |
3355 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3356 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3357 | ||
3358 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3359 | } | |
3360 | ||
0c588247 | 3361 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 3362 | |
341f9135 CC |
3363 | if (this_set == NULL) |
3364 | { | |
3365 | abbrev_base = 0; | |
3366 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3367 | } | |
3368 | else | |
3369 | { | |
3370 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3371 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3372 | } | |
3373 | ||
77145576 JK |
3374 | if (compunit.cu_version < 5) |
3375 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3376 | ||
f41e4712 NC |
3377 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
3378 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
3379 | { | |
3380 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
3381 | compunit.cu_pointer_size, offset_size); | |
3382 | compunit.cu_pointer_size = offset_size; | |
3383 | } | |
2b6f5997 CC |
3384 | |
3385 | if (do_types) | |
b4eb7656 | 3386 | { |
0c588247 | 3387 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 3388 | hdrptr += 8; |
0c588247 | 3389 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 3390 | } |
2b6f5997 | 3391 | |
ae7e7825 NC |
3392 | if (dwarf_start_die > (cu_offset + compunit.cu_length |
3393 | + initial_length_size)) | |
3394 | { | |
3395 | start = section_begin + cu_offset + compunit.cu_length | |
3396 | + initial_length_size; | |
3397 | continue; | |
3398 | } | |
3399 | ||
19e6b90e | 3400 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 CC |
3401 | && num_debug_info_entries == 0 |
3402 | && ! do_types) | |
19e6b90e L |
3403 | { |
3404 | debug_information [unit].cu_offset = cu_offset; | |
3405 | debug_information [unit].pointer_size | |
3406 | = compunit.cu_pointer_size; | |
b7807392 JJ |
3407 | debug_information [unit].offset_size = offset_size; |
3408 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 3409 | debug_information [unit].base_address = 0; |
4723351a CC |
3410 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
3411 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
3412 | debug_information [unit].loc_offsets = NULL; |
3413 | debug_information [unit].have_frame_base = NULL; | |
3414 | debug_information [unit].max_loc_offsets = 0; | |
3415 | debug_information [unit].num_loc_offsets = 0; | |
3416 | debug_information [unit].range_lists = NULL; | |
3417 | debug_information [unit].max_range_lists= 0; | |
3418 | debug_information [unit].num_range_lists = 0; | |
3419 | } | |
3420 | ||
fd2f0033 | 3421 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 3422 | { |
47704ddf KT |
3423 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3424 | dwarf_vmatoa ("x", cu_offset)); | |
3425 | printf (_(" Length: 0x%s (%s)\n"), | |
3426 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3427 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3428 | printf (_(" Version: %d\n"), compunit.cu_version); |
7282333f AM |
3429 | printf (_(" Abbrev Offset: 0x%s\n"), |
3430 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3431 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3432 | if (do_types) |
3433 | { | |
74bc6052 CC |
3434 | char buf[64]; |
3435 | ||
3436 | printf (_(" Signature: 0x%s\n"), | |
3437 | dwarf_vmatoa64 (signature_high, signature_low, | |
3438 | buf, sizeof (buf))); | |
3439 | printf (_(" Type Offset: 0x%s\n"), | |
3440 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3441 | } |
341f9135 CC |
3442 | if (this_set != NULL) |
3443 | { | |
3444 | dwarf_vma *offsets = this_set->section_offsets; | |
3445 | size_t *sizes = this_set->section_sizes; | |
3446 | ||
3447 | printf (_(" Section contributions:\n")); | |
3448 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3449 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3450 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3451 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3452 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3453 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3454 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3455 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3456 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3457 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3458 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3459 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3460 | } | |
19e6b90e L |
3461 | } |
3462 | ||
e98fdf1a AM |
3463 | sec_off = cu_offset + initial_length_size; |
3464 | if (sec_off + compunit.cu_length < sec_off | |
3465 | || sec_off + compunit.cu_length > section->size) | |
460c89ff | 3466 | { |
e98fdf1a AM |
3467 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
3468 | section->name, | |
3469 | (unsigned long) cu_offset, | |
19485196 NC |
3470 | dwarf_vmatoa ("x", compunit.cu_length)); |
3471 | num_units = unit; | |
3472 | break; | |
3473 | } | |
3474 | ||
460c89ff NS |
3475 | tags = hdrptr; |
3476 | start += compunit.cu_length + initial_length_size; | |
3477 | ||
77145576 | 3478 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3479 | { |
47704ddf KT |
3480 | warn (_("CU at offset %s contains corrupt or " |
3481 | "unsupported version number: %d.\n"), | |
3482 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3483 | continue; |
3484 | } | |
3485 | ||
77145576 JK |
3486 | if (compunit.cu_unit_type != DW_UT_compile |
3487 | && compunit.cu_unit_type != DW_UT_type) | |
3488 | { | |
3489 | warn (_("CU at offset %s contains corrupt or " | |
3490 | "unsupported unit type: %d.\n"), | |
3491 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3492 | continue; | |
3493 | } | |
3494 | ||
19e6b90e L |
3495 | free_abbrevs (); |
3496 | ||
d493b283 | 3497 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 3498 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
3499 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
3500 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 3501 | (unsigned long) abbrev_size); |
b4eb7656 | 3502 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
3503 | else if ((abbrev_base + abbrev_size) |
3504 | > debug_displays [abbrev_sec].section.size) | |
3505 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
3506 | (unsigned long) abbrev_base + abbrev_size, | |
3507 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff NS |
3508 | else |
3509 | process_abbrev_section | |
341f9135 CC |
3510 | (((unsigned char *) debug_displays [abbrev_sec].section.start |
3511 | + abbrev_base + compunit.cu_abbrev_offset), | |
3512 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3513 | + abbrev_base + abbrev_size)); | |
19e6b90e L |
3514 | |
3515 | level = 0; | |
fd2f0033 TT |
3516 | last_level = level; |
3517 | saved_level = -1; | |
19e6b90e L |
3518 | while (tags < start) |
3519 | { | |
3520 | unsigned int bytes_read; | |
3521 | unsigned long abbrev_number; | |
ec4d4525 | 3522 | unsigned long die_offset; |
19e6b90e L |
3523 | abbrev_entry *entry; |
3524 | abbrev_attr *attr; | |
fd2f0033 | 3525 | int do_printing = 1; |
19e6b90e | 3526 | |
ec4d4525 NC |
3527 | die_offset = tags - section_begin; |
3528 | ||
f6f0e17b | 3529 | abbrev_number = read_uleb128 (tags, & bytes_read, start); |
19e6b90e L |
3530 | tags += bytes_read; |
3531 | ||
eb7cc021 JK |
3532 | /* A null DIE marks the end of a list of siblings or it may also be |
3533 | a section padding. */ | |
19e6b90e L |
3534 | if (abbrev_number == 0) |
3535 | { | |
eb7cc021 JK |
3536 | /* Check if it can be a section padding for the last CU. */ |
3537 | if (level == 0 && start == end) | |
3538 | { | |
3539 | unsigned char *chk; | |
3540 | ||
3541 | for (chk = tags; chk < start; chk++) | |
3542 | if (*chk != 0) | |
3543 | break; | |
3544 | if (chk == start) | |
3545 | break; | |
3546 | } | |
3547 | ||
4337774f TT |
3548 | if (!do_loc && die_offset >= dwarf_start_die |
3549 | && (dwarf_cutoff_level == -1 | |
3550 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3551 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3552 | level, die_offset); | |
3553 | ||
19e6b90e | 3554 | --level; |
ec4d4525 NC |
3555 | if (level < 0) |
3556 | { | |
3557 | static unsigned num_bogus_warns = 0; | |
3558 | ||
3559 | if (num_bogus_warns < 3) | |
3560 | { | |
4723351a CC |
3561 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3562 | die_offset, section->name); | |
ec4d4525 NC |
3563 | num_bogus_warns ++; |
3564 | if (num_bogus_warns == 3) | |
3565 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3566 | } | |
3567 | } | |
fd2f0033 | 3568 | if (dwarf_start_die != 0 && level < saved_level) |
d85bf2ba | 3569 | return TRUE; |
19e6b90e L |
3570 | continue; |
3571 | } | |
3572 | ||
4b78141a | 3573 | if (!do_loc) |
fd2f0033 TT |
3574 | { |
3575 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
3576 | do_printing = 0; | |
3577 | else | |
3578 | { | |
3579 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
3580 | saved_level = level; | |
3581 | do_printing = (dwarf_cutoff_level == -1 | |
3582 | || level < dwarf_cutoff_level); | |
3583 | if (do_printing) | |
3584 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
3585 | level, die_offset, abbrev_number); | |
3586 | else if (dwarf_cutoff_level == -1 | |
3587 | || last_level < dwarf_cutoff_level) | |
3588 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
3589 | last_level = level; | |
3590 | } | |
3591 | } | |
cecf136e | 3592 | |
19e6b90e L |
3593 | /* Scan through the abbreviation list until we reach the |
3594 | correct entry. */ | |
3595 | for (entry = first_abbrev; | |
3596 | entry && entry->entry != abbrev_number; | |
3597 | entry = entry->next) | |
3598 | continue; | |
3599 | ||
3600 | if (entry == NULL) | |
3601 | { | |
fd2f0033 | 3602 | if (!do_loc && do_printing) |
4b78141a NC |
3603 | { |
3604 | printf ("\n"); | |
3605 | fflush (stdout); | |
3606 | } | |
f3853b34 | 3607 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 3608 | die_offset, abbrev_number); |
d85bf2ba | 3609 | return FALSE; |
19e6b90e L |
3610 | } |
3611 | ||
fd2f0033 | 3612 | if (!do_loc && do_printing) |
cc5914eb | 3613 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 3614 | |
19e6b90e L |
3615 | switch (entry->tag) |
3616 | { | |
3617 | default: | |
3618 | need_base_address = 0; | |
3619 | break; | |
3620 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
3621 | need_base_address = 1; |
3622 | need_dwo_info = do_loc; | |
19e6b90e L |
3623 | break; |
3624 | case DW_TAG_entry_point: | |
19e6b90e L |
3625 | case DW_TAG_subprogram: |
3626 | need_base_address = 0; | |
3627 | /* Assuming that there is no DW_AT_frame_base. */ | |
3628 | have_frame_base = 0; | |
3629 | break; | |
3630 | } | |
3631 | ||
9f272209 AO |
3632 | debug_info *debug_info_p = |
3633 | (debug_information && unit < alloc_num_debug_info_entries) | |
3634 | ? debug_information + unit : NULL; | |
3635 | ||
3636 | assert (!debug_info_p | |
3637 | || (debug_info_p->num_loc_offsets | |
3638 | == debug_info_p->num_loc_views)); | |
3639 | ||
399c99f7 L |
3640 | for (attr = entry->first_attr; |
3641 | attr && attr->attribute; | |
3642 | attr = attr->next) | |
4b78141a | 3643 | { |
fd2f0033 | 3644 | if (! do_loc && do_printing) |
4b78141a | 3645 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 | 3646 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
3647 | tags = read_and_display_attr (attr->attribute, |
3648 | attr->form, | |
77145576 | 3649 | attr->implicit_const, |
ec1b0fbb | 3650 | section_begin, |
341f9135 | 3651 | tags, |
f6f0e17b | 3652 | end, |
341f9135 | 3653 | cu_offset, |
4b78141a NC |
3654 | compunit.cu_pointer_size, |
3655 | offset_size, | |
3656 | compunit.cu_version, | |
9f272209 | 3657 | debug_info_p, |
341f9135 CC |
3658 | do_loc || ! do_printing, |
3659 | section, | |
ec1b0fbb NC |
3660 | this_set, |
3661 | level); | |
4b78141a | 3662 | } |
cecf136e | 3663 | |
9f272209 AO |
3664 | /* If a locview attribute appears before a location one, |
3665 | make sure we don't associate it with an earlier | |
3666 | loclist. */ | |
3667 | if (debug_info_p) | |
3668 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
3669 | { | |
3670 | case 1: | |
3671 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
3672 | debug_info_p->num_loc_views++; | |
3673 | assert (debug_info_p->num_loc_views | |
3674 | == debug_info_p->num_loc_offsets); | |
3675 | break; | |
3676 | ||
3677 | case 0: | |
3678 | break; | |
3679 | ||
3680 | case -1: | |
3681 | warn(_("DIE has locviews without loclist\n")); | |
3682 | debug_info_p->num_loc_views--; | |
3683 | break; | |
3684 | ||
3685 | default: | |
3686 | assert (0); | |
3687 | } | |
3688 | ||
b4eb7656 AM |
3689 | if (entry->children) |
3690 | ++level; | |
3691 | } | |
19e6b90e | 3692 | } |
cecf136e | 3693 | |
19e6b90e L |
3694 | /* Set num_debug_info_entries here so that it can be used to check if |
3695 | we need to process .debug_loc and .debug_ranges sections. */ | |
3696 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3697 | && num_debug_info_entries == 0 |
3698 | && ! do_types) | |
82b1b41b | 3699 | { |
b4eb7656 | 3700 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
3701 | num_debug_info_entries = alloc_num_debug_info_entries; |
3702 | else | |
3703 | num_debug_info_entries = num_units; | |
3704 | } | |
cecf136e | 3705 | |
19e6b90e | 3706 | if (!do_loc) |
467c65bc | 3707 | printf ("\n"); |
cecf136e | 3708 | |
d85bf2ba | 3709 | return TRUE; |
19e6b90e L |
3710 | } |
3711 | ||
3712 | /* Locate and scan the .debug_info section in the file and record the pointer | |
3713 | sizes and offsets for the compilation units in it. Usually an executable | |
3714 | will have just one pointer size, but this is not guaranteed, and so we try | |
3715 | not to make any assumptions. Returns zero upon failure, or the number of | |
3716 | compilation units upon success. */ | |
3717 | ||
3718 | static unsigned int | |
3719 | load_debug_info (void * file) | |
3720 | { | |
1febe64d | 3721 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 3722 | section then do not bother to repeat the task. */ |
cc86f28f | 3723 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
3724 | return 0; |
3725 | ||
19e6b90e L |
3726 | /* If we already have the information there is nothing else to do. */ |
3727 | if (num_debug_info_entries > 0) | |
3728 | return num_debug_info_entries; | |
3729 | ||
341f9135 | 3730 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 3731 | (void) load_cu_tu_indexes (file); |
341f9135 | 3732 | |
dda8d76d | 3733 | if (load_debug_section_with_follow (info, file) |
d85bf2ba | 3734 | && process_debug_info (&debug_displays [info].section, file, abbrev, TRUE, FALSE)) |
19e6b90e | 3735 | return num_debug_info_entries; |
82b1b41b | 3736 | |
dda8d76d | 3737 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 3738 | && process_debug_info (&debug_displays [info_dwo].section, file, |
d85bf2ba | 3739 | abbrev_dwo, TRUE, FALSE)) |
4723351a | 3740 | return num_debug_info_entries; |
1febe64d | 3741 | |
cc86f28f | 3742 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 3743 | return 0; |
19e6b90e L |
3744 | } |
3745 | ||
b40bf0a2 NC |
3746 | /* Read a DWARF .debug_line section header starting at DATA. |
3747 | Upon success returns an updated DATA pointer and the LINFO | |
3748 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
3749 | Otherwise returns NULL. */ | |
19e6b90e | 3750 | |
b40bf0a2 NC |
3751 | static unsigned char * |
3752 | read_debug_line_header (struct dwarf_section * section, | |
3753 | unsigned char * data, | |
3754 | unsigned char * end, | |
3755 | DWARF2_Internal_LineInfo * linfo, | |
3756 | unsigned char ** end_of_sequence) | |
3757 | { | |
3758 | unsigned char *hdrptr; | |
b40bf0a2 | 3759 | unsigned int initial_length_size; |
77145576 | 3760 | unsigned char address_size, segment_selector_size; |
19e6b90e | 3761 | |
b40bf0a2 NC |
3762 | /* Extract information from the Line Number Program Header. |
3763 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 3764 | hdrptr = data; |
19e6b90e | 3765 | |
b40bf0a2 NC |
3766 | /* Get and check the length of the block. */ |
3767 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 3768 | |
b40bf0a2 | 3769 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
3770 | { |
3771 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 3772 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 3773 | linfo->li_offset_size = 8; |
f41e4712 NC |
3774 | initial_length_size = 12; |
3775 | } | |
3776 | else | |
3777 | { | |
77145576 | 3778 | linfo->li_offset_size = 4; |
f41e4712 NC |
3779 | initial_length_size = 4; |
3780 | } | |
19e6b90e | 3781 | |
b40bf0a2 | 3782 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 3783 | { |
8fcc61b4 NC |
3784 | /* If the length field has a relocation against it, then we should |
3785 | not complain if it is inaccurate (and probably negative). This | |
3786 | happens in object files when the .debug_line section is actually | |
3787 | comprised of several different .debug_line.* sections, (some of | |
3788 | which may be removed by linker garbage collection), and a relocation | |
3789 | is used to compute the correct length once that is done. */ | |
77145576 | 3790 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 3791 | { |
8fcc61b4 | 3792 | linfo->li_length = (end - data) - initial_length_size; |
b40bf0a2 NC |
3793 | } |
3794 | else | |
3795 | { | |
8fcc61b4 NC |
3796 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
3797 | (long) linfo->li_length); | |
b40bf0a2 NC |
3798 | return NULL; |
3799 | } | |
f41e4712 | 3800 | } |
19e6b90e | 3801 | |
b40bf0a2 NC |
3802 | /* Get and check the version number. */ |
3803 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
3804 | ||
3805 | if (linfo->li_version != 2 | |
3806 | && linfo->li_version != 3 | |
77145576 JK |
3807 | && linfo->li_version != 4 |
3808 | && linfo->li_version != 5) | |
f41e4712 | 3809 | { |
77145576 JK |
3810 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
3811 | "is currently supported.\n")); | |
b40bf0a2 | 3812 | return NULL; |
f41e4712 | 3813 | } |
19e6b90e | 3814 | |
77145576 JK |
3815 | if (linfo->li_version >= 5) |
3816 | { | |
3817 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
3818 | ||
3819 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
3820 | if (segment_selector_size != 0) | |
3821 | { | |
3822 | warn (_("The %s section contains " | |
3823 | "unsupported segment selector size: %d.\n"), | |
3824 | section->name, segment_selector_size); | |
3825 | return 0; | |
3826 | } | |
3827 | } | |
3828 | ||
3829 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
3830 | linfo->li_offset_size, end); | |
b40bf0a2 | 3831 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 3832 | |
b40bf0a2 | 3833 | if (linfo->li_version >= 4) |
f41e4712 | 3834 | { |
b40bf0a2 | 3835 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 3836 | |
b40bf0a2 | 3837 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
3838 | { |
3839 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 3840 | return NULL; |
a233b20c | 3841 | } |
f41e4712 NC |
3842 | } |
3843 | else | |
b40bf0a2 | 3844 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 3845 | |
b40bf0a2 | 3846 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 3847 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
3848 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
3849 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 3850 | |
b40bf0a2 | 3851 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 3852 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
3853 | if (* end_of_sequence > end) |
3854 | { | |
4c219c2e AM |
3855 | warn (_("Line length %s extends beyond end of section\n"), |
3856 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
3857 | * end_of_sequence = end; |
3858 | return NULL; | |
3859 | } | |
3860 | ||
b40bf0a2 NC |
3861 | return hdrptr; |
3862 | } | |
19e6b90e | 3863 | |
77145576 | 3864 | static unsigned char * |
dda8d76d NC |
3865 | display_formatted_table (unsigned char * data, |
3866 | unsigned char * start, | |
3867 | unsigned char * end, | |
3868 | const DWARF2_Internal_LineInfo * linfo, | |
3869 | struct dwarf_section * section, | |
7b8d9e8c | 3870 | bfd_boolean is_dir) |
77145576 JK |
3871 | { |
3872 | unsigned char *format_start, format_count, *format, formati; | |
3873 | dwarf_vma data_count, datai; | |
3874 | unsigned int bytes_read, namepass, last_entry = 0; | |
3875 | ||
3876 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
3877 | format_start = data; | |
3878 | for (formati = 0; formati < format_count; formati++) | |
3879 | { | |
3880 | read_uleb128 (data, & bytes_read, end); | |
3881 | data += bytes_read; | |
3882 | read_uleb128 (data, & bytes_read, end); | |
3883 | data += bytes_read; | |
3884 | if (data == end) | |
3885 | { | |
7b8d9e8c AM |
3886 | if (is_dir) |
3887 | warn (_("Corrupt directory format table entry\n")); | |
3888 | else | |
3889 | warn (_("Corrupt file name format table entry\n")); | |
77145576 JK |
3890 | return data; |
3891 | } | |
3892 | } | |
3893 | ||
3894 | data_count = read_uleb128 (data, & bytes_read, end); | |
3895 | data += bytes_read; | |
3896 | if (data == end) | |
3897 | { | |
7b8d9e8c AM |
3898 | if (is_dir) |
3899 | warn (_("Corrupt directory list\n")); | |
3900 | else | |
3901 | warn (_("Corrupt file name list\n")); | |
77145576 JK |
3902 | return data; |
3903 | } | |
3904 | ||
3905 | if (data_count == 0) | |
3906 | { | |
7b8d9e8c AM |
3907 | if (is_dir) |
3908 | printf (_("\n The Directory Table is empty.\n")); | |
3909 | else | |
3910 | printf (_("\n The File Name Table is empty.\n")); | |
77145576 JK |
3911 | return data; |
3912 | } | |
3913 | ||
7b8d9e8c AM |
3914 | if (is_dir) |
3915 | printf (_("\n The Directory Table (offset 0x%lx):\n"), | |
3916 | (long) (data - start)); | |
3917 | else | |
3918 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
3919 | (long) (data - start)); | |
77145576 JK |
3920 | |
3921 | printf (_(" Entry")); | |
3922 | /* Delay displaying name as the last entry for better screen layout. */ | |
3923 | for (namepass = 0; namepass < 2; namepass++) | |
3924 | { | |
3925 | format = format_start; | |
3926 | for (formati = 0; formati < format_count; formati++) | |
3927 | { | |
3928 | dwarf_vma content_type; | |
3929 | ||
3930 | content_type = read_uleb128 (format, & bytes_read, end); | |
3931 | format += bytes_read; | |
3932 | if ((content_type == DW_LNCT_path) == (namepass == 1)) | |
3933 | switch (content_type) | |
3934 | { | |
3935 | case DW_LNCT_path: | |
3936 | printf (_("\tName")); | |
3937 | break; | |
3938 | case DW_LNCT_directory_index: | |
3939 | printf (_("\tDir")); | |
3940 | break; | |
3941 | case DW_LNCT_timestamp: | |
3942 | printf (_("\tTime")); | |
3943 | break; | |
3944 | case DW_LNCT_size: | |
3945 | printf (_("\tSize")); | |
3946 | break; | |
3947 | case DW_LNCT_MD5: | |
3948 | printf (_("\tMD5")); | |
3949 | break; | |
3950 | default: | |
3951 | printf (_("\t(Unknown format content type %s)"), | |
3952 | dwarf_vmatoa ("u", content_type)); | |
3953 | } | |
3954 | read_uleb128 (format, & bytes_read, end); | |
3955 | format += bytes_read; | |
3956 | } | |
3957 | } | |
3958 | putchar ('\n'); | |
3959 | ||
3960 | for (datai = 0; datai < data_count; datai++) | |
3961 | { | |
3962 | unsigned char *datapass = data; | |
3963 | ||
3964 | printf (" %d", last_entry++); | |
3965 | /* Delay displaying name as the last entry for better screen layout. */ | |
3966 | for (namepass = 0; namepass < 2; namepass++) | |
3967 | { | |
3968 | format = format_start; | |
3969 | data = datapass; | |
3970 | for (formati = 0; formati < format_count; formati++) | |
3971 | { | |
3972 | dwarf_vma content_type, form; | |
3973 | ||
3974 | content_type = read_uleb128 (format, & bytes_read, end); | |
3975 | format += bytes_read; | |
3976 | form = read_uleb128 (format, & bytes_read, end); | |
3977 | format += bytes_read; | |
ec1b0fbb | 3978 | data = read_and_display_attr_value (0, form, 0, start, data, end, 0, 0, |
77145576 JK |
3979 | linfo->li_offset_size, |
3980 | linfo->li_version, NULL, | |
3981 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
ec1b0fbb | 3982 | section, NULL, '\t', -1); |
77145576 JK |
3983 | } |
3984 | } | |
3985 | if (data == end) | |
3986 | { | |
7b8d9e8c AM |
3987 | if (is_dir) |
3988 | warn (_("Corrupt directory entries list\n")); | |
3989 | else | |
3990 | warn (_("Corrupt file name entries list\n")); | |
77145576 JK |
3991 | return data; |
3992 | } | |
3993 | putchar ('\n'); | |
3994 | } | |
3995 | return data; | |
3996 | } | |
3997 | ||
b40bf0a2 | 3998 | static int |
dda8d76d NC |
3999 | display_debug_lines_raw (struct dwarf_section * section, |
4000 | unsigned char * data, | |
4001 | unsigned char * end, | |
4002 | void * file) | |
b40bf0a2 NC |
4003 | { |
4004 | unsigned char *start = section->start; | |
ba8826a8 | 4005 | int verbose_view = 0; |
19e6b90e | 4006 | |
dda8d76d | 4007 | introduce (section, TRUE); |
19e6b90e | 4008 | |
b40bf0a2 NC |
4009 | while (data < end) |
4010 | { | |
4011 | static DWARF2_Internal_LineInfo saved_linfo; | |
4012 | DWARF2_Internal_LineInfo linfo; | |
4013 | unsigned char *standard_opcodes; | |
4014 | unsigned char *end_of_sequence; | |
fe59e83d | 4015 | int i; |
19e6b90e | 4016 | |
4925cdd7 NC |
4017 | if (const_strneq (section->name, ".debug_line.") |
4018 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4019 | These are full debug_line sections. */ | |
4020 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 4021 | { |
b40bf0a2 NC |
4022 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
4023 | section containing just the Line Number Statements. They are | |
4024 | created by the assembler and intended to be used alongside gcc's | |
4025 | -ffunction-sections command line option. When the linker's | |
4026 | garbage collection decides to discard a .text.<foo> section it | |
4027 | can then also discard the line number information in .debug_line.<foo>. | |
4028 | ||
4925cdd7 | 4029 | Since the section is a fragment it does not have the details |
b40bf0a2 | 4030 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 4031 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
4032 | end_of_sequence = end; |
4033 | standard_opcodes = NULL; | |
4034 | linfo = saved_linfo; | |
058037d3 NC |
4035 | /* PR 17531: file: 0522b371. */ |
4036 | if (linfo.li_line_range == 0) | |
4037 | { | |
1306a742 | 4038 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4039 | return 0; |
4040 | } | |
b40bf0a2 | 4041 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4042 | } |
19e6b90e L |
4043 | else |
4044 | { | |
b40bf0a2 | 4045 | unsigned char * hdrptr; |
19e6b90e | 4046 | |
b40bf0a2 NC |
4047 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4048 | & end_of_sequence)) == NULL) | |
4049 | return 0; | |
19e6b90e | 4050 | |
b40bf0a2 NC |
4051 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
4052 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
4053 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
77ef8654 | 4054 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
4055 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
4056 | if (linfo.li_version >= 4) | |
4057 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
4058 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
4059 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
4060 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
4061 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 4062 | |
0a9d414a NC |
4063 | /* PR 17512: file: 1665-6428-0.004. */ |
4064 | if (linfo.li_line_range == 0) | |
4065 | { | |
4066 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4067 | linfo.li_line_range = 1; | |
4068 | } | |
77ef8654 | 4069 | |
b40bf0a2 | 4070 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4071 | |
b40bf0a2 NC |
4072 | /* Display the contents of the Opcodes table. */ |
4073 | standard_opcodes = hdrptr; | |
19e6b90e | 4074 | |
6937bb54 NC |
4075 | /* PR 17512: file: 002-417945-0.004. */ |
4076 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
4077 | { | |
4078 | warn (_("Line Base extends beyond end of section\n")); | |
4079 | return 0; | |
4080 | } | |
4081 | ||
b40bf0a2 | 4082 | printf (_("\n Opcodes:\n")); |
19e6b90e | 4083 | |
b40bf0a2 | 4084 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
4085 | printf (ngettext (" Opcode %d has %d arg\n", |
4086 | " Opcode %d has %d args\n", | |
4087 | standard_opcodes[i - 1]), | |
4088 | i, standard_opcodes[i - 1]); | |
19e6b90e | 4089 | |
b40bf0a2 NC |
4090 | /* Display the contents of the Directory table. */ |
4091 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 4092 | |
77145576 | 4093 | if (linfo.li_version >= 5) |
b40bf0a2 | 4094 | { |
dda8d76d | 4095 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 4096 | |
77145576 | 4097 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 4098 | TRUE); |
77145576 | 4099 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 4100 | FALSE); |
77145576 JK |
4101 | } |
4102 | else | |
4103 | { | |
4104 | if (*data == 0) | |
4105 | printf (_("\n The Directory Table is empty.\n")); | |
4106 | else | |
a233b20c | 4107 | { |
77145576 | 4108 | unsigned int last_dir_entry = 0; |
6937bb54 | 4109 | |
77145576 JK |
4110 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
4111 | (long)(data - start)); | |
19e6b90e | 4112 | |
77145576 JK |
4113 | while (data < end && *data != 0) |
4114 | { | |
4115 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 4116 | |
77145576 JK |
4117 | data += strnlen ((char *) data, end - data) + 1; |
4118 | } | |
19e6b90e | 4119 | |
77145576 JK |
4120 | /* PR 17512: file: 002-132094-0.004. */ |
4121 | if (data >= end - 1) | |
4122 | break; | |
4123 | } | |
19e6b90e | 4124 | |
77145576 JK |
4125 | /* Skip the NUL at the end of the table. */ |
4126 | data++; | |
19e6b90e | 4127 | |
77145576 JK |
4128 | /* Display the contents of the File Name table. */ |
4129 | if (*data == 0) | |
4130 | printf (_("\n The File Name Table is empty.\n")); | |
4131 | else | |
4132 | { | |
4133 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
4134 | (long)(data - start)); | |
4135 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 4136 | |
77145576 | 4137 | while (data < end && *data != 0) |
b40bf0a2 | 4138 | { |
77145576 JK |
4139 | unsigned char *name; |
4140 | unsigned int bytes_read; | |
4141 | ||
4142 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
4143 | name = data; | |
4144 | data += strnlen ((char *) data, end - data) + 1; | |
4145 | ||
4146 | printf ("%s\t", | |
4147 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
4148 | data += bytes_read; | |
4149 | printf ("%s\t", | |
4150 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
4151 | data += bytes_read; | |
4152 | printf ("%s\t", | |
4153 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
4154 | data += bytes_read; | |
4155 | printf ("%.*s\n", (int)(end - name), name); | |
4156 | ||
4157 | if (data == end) | |
4158 | { | |
4159 | warn (_("Corrupt file name table entry\n")); | |
4160 | break; | |
4161 | } | |
b40bf0a2 | 4162 | } |
a233b20c | 4163 | } |
77145576 JK |
4164 | |
4165 | /* Skip the NUL at the end of the table. */ | |
4166 | data++; | |
b40bf0a2 | 4167 | } |
19e6b90e | 4168 | |
b40bf0a2 NC |
4169 | putchar ('\n'); |
4170 | saved_linfo = linfo; | |
4171 | } | |
19e6b90e | 4172 | |
b40bf0a2 NC |
4173 | /* Now display the statements. */ |
4174 | if (data >= end_of_sequence) | |
4175 | printf (_(" No Line Number Statements.\n")); | |
4176 | else | |
4177 | { | |
4178 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 4179 | |
b40bf0a2 NC |
4180 | while (data < end_of_sequence) |
4181 | { | |
4182 | unsigned char op_code; | |
4183 | dwarf_signed_vma adv; | |
4184 | dwarf_vma uladv; | |
4185 | unsigned int bytes_read; | |
19e6b90e | 4186 | |
fe59e83d CC |
4187 | printf (" [0x%08lx]", (long)(data - start)); |
4188 | ||
b40bf0a2 | 4189 | op_code = *data++; |
19e6b90e | 4190 | |
b40bf0a2 | 4191 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 4192 | { |
b40bf0a2 NC |
4193 | op_code -= linfo.li_opcode_base; |
4194 | uladv = (op_code / linfo.li_line_range); | |
4195 | if (linfo.li_max_ops_per_insn == 1) | |
4196 | { | |
4197 | uladv *= linfo.li_min_insn_length; | |
4198 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4199 | if (uladv) |
4200 | state_machine_regs.view = 0; | |
b40bf0a2 | 4201 | printf (_(" Special opcode %d: " |
ba8826a8 | 4202 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 4203 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4204 | dwarf_vmatoa ("x", state_machine_regs.address), |
4205 | verbose_view && uladv | |
4206 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4207 | } |
4208 | else | |
4209 | { | |
ba8826a8 AO |
4210 | unsigned addrdelta |
4211 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
4212 | / linfo.li_max_ops_per_insn) |
4213 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
4214 | |
4215 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
4216 | state_machine_regs.op_index |
4217 | = (state_machine_regs.op_index + uladv) | |
4218 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4219 | if (addrdelta) |
4220 | state_machine_regs.view = 0; | |
b40bf0a2 | 4221 | printf (_(" Special opcode %d: " |
ba8826a8 | 4222 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
4223 | op_code, dwarf_vmatoa ("u", uladv), |
4224 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4225 | state_machine_regs.op_index, |
4226 | verbose_view && addrdelta | |
4227 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4228 | } |
4229 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
4230 | state_machine_regs.line += adv; | |
ba8826a8 | 4231 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 4232 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
4233 | if (verbose_view || state_machine_regs.view) |
4234 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4235 | else | |
4236 | putchar ('\n'); | |
4237 | state_machine_regs.view++; | |
19e6b90e | 4238 | } |
b40bf0a2 NC |
4239 | else switch (op_code) |
4240 | { | |
4241 | case DW_LNS_extended_op: | |
4242 | data += process_extended_line_op (data, linfo.li_default_is_stmt, end); | |
4243 | break; | |
4244 | ||
4245 | case DW_LNS_copy: | |
ba8826a8 AO |
4246 | printf (_(" Copy")); |
4247 | if (verbose_view || state_machine_regs.view) | |
4248 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4249 | else | |
4250 | putchar ('\n'); | |
4251 | state_machine_regs.view++; | |
b40bf0a2 NC |
4252 | break; |
4253 | ||
4254 | case DW_LNS_advance_pc: | |
4255 | uladv = read_uleb128 (data, & bytes_read, end); | |
4256 | data += bytes_read; | |
4257 | if (linfo.li_max_ops_per_insn == 1) | |
4258 | { | |
4259 | uladv *= linfo.li_min_insn_length; | |
4260 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4261 | if (uladv) |
4262 | state_machine_regs.view = 0; | |
4263 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
b40bf0a2 | 4264 | dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4265 | dwarf_vmatoa ("x", state_machine_regs.address), |
4266 | verbose_view && uladv | |
4267 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4268 | } |
4269 | else | |
4270 | { | |
ba8826a8 AO |
4271 | unsigned addrdelta |
4272 | = ((state_machine_regs.op_index + uladv) | |
4273 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4274 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4275 | state_machine_regs.address |
4276 | += addrdelta; | |
b40bf0a2 NC |
4277 | state_machine_regs.op_index |
4278 | = (state_machine_regs.op_index + uladv) | |
4279 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4280 | if (addrdelta) |
4281 | state_machine_regs.view = 0; | |
4282 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
b40bf0a2 NC |
4283 | dwarf_vmatoa ("u", uladv), |
4284 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4285 | state_machine_regs.op_index, |
4286 | verbose_view && addrdelta | |
4287 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4288 | } |
4289 | break; | |
4290 | ||
4291 | case DW_LNS_advance_line: | |
4292 | adv = read_sleb128 (data, & bytes_read, end); | |
4293 | data += bytes_read; | |
4294 | state_machine_regs.line += adv; | |
4295 | printf (_(" Advance Line by %s to %d\n"), | |
4296 | dwarf_vmatoa ("d", adv), | |
4297 | state_machine_regs.line); | |
4298 | break; | |
4299 | ||
4300 | case DW_LNS_set_file: | |
4301 | adv = read_uleb128 (data, & bytes_read, end); | |
4302 | data += bytes_read; | |
4303 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
4304 | dwarf_vmatoa ("d", adv)); | |
4305 | state_machine_regs.file = adv; | |
4306 | break; | |
4307 | ||
4308 | case DW_LNS_set_column: | |
4309 | uladv = read_uleb128 (data, & bytes_read, end); | |
4310 | data += bytes_read; | |
4311 | printf (_(" Set column to %s\n"), | |
4312 | dwarf_vmatoa ("u", uladv)); | |
4313 | state_machine_regs.column = uladv; | |
4314 | break; | |
4315 | ||
4316 | case DW_LNS_negate_stmt: | |
4317 | adv = state_machine_regs.is_stmt; | |
4318 | adv = ! adv; | |
4319 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
4320 | state_machine_regs.is_stmt = adv; | |
4321 | break; | |
4322 | ||
4323 | case DW_LNS_set_basic_block: | |
4324 | printf (_(" Set basic block\n")); | |
4325 | state_machine_regs.basic_block = 1; | |
4326 | break; | |
4327 | ||
4328 | case DW_LNS_const_add_pc: | |
4329 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4330 | if (linfo.li_max_ops_per_insn) | |
4331 | { | |
4332 | uladv *= linfo.li_min_insn_length; | |
4333 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4334 | if (uladv) |
4335 | state_machine_regs.view = 0; | |
4336 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
b40bf0a2 | 4337 | dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4338 | dwarf_vmatoa ("x", state_machine_regs.address), |
4339 | verbose_view && uladv | |
4340 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4341 | } |
4342 | else | |
4343 | { | |
ba8826a8 AO |
4344 | unsigned addrdelta |
4345 | = ((state_machine_regs.op_index + uladv) | |
4346 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4347 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4348 | state_machine_regs.address |
4349 | += addrdelta; | |
b40bf0a2 NC |
4350 | state_machine_regs.op_index |
4351 | = (state_machine_regs.op_index + uladv) | |
4352 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4353 | if (addrdelta) |
4354 | state_machine_regs.view = 0; | |
4355 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
b40bf0a2 NC |
4356 | dwarf_vmatoa ("u", uladv), |
4357 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4358 | state_machine_regs.op_index, |
4359 | verbose_view && addrdelta | |
4360 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4361 | } |
4362 | break; | |
4363 | ||
4364 | case DW_LNS_fixed_advance_pc: | |
4365 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4366 | state_machine_regs.address += uladv; | |
4367 | state_machine_regs.op_index = 0; | |
4368 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
4369 | dwarf_vmatoa ("u", uladv), | |
4370 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
ba8826a8 | 4371 | /* Do NOT reset view. */ |
b40bf0a2 NC |
4372 | break; |
4373 | ||
4374 | case DW_LNS_set_prologue_end: | |
4375 | printf (_(" Set prologue_end to true\n")); | |
4376 | break; | |
4377 | ||
4378 | case DW_LNS_set_epilogue_begin: | |
4379 | printf (_(" Set epilogue_begin to true\n")); | |
4380 | break; | |
4381 | ||
4382 | case DW_LNS_set_isa: | |
4383 | uladv = read_uleb128 (data, & bytes_read, end); | |
4384 | data += bytes_read; | |
4385 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
4386 | break; | |
4387 | ||
4388 | default: | |
4389 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4390 | ||
4391 | if (standard_opcodes != NULL) | |
4392 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4393 | { | |
4394 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
4395 | &bytes_read, end)), | |
4396 | i == 1 ? "" : ", "); | |
4397 | data += bytes_read; | |
4398 | } | |
4399 | putchar ('\n'); | |
4400 | break; | |
4401 | } | |
19e6b90e | 4402 | } |
b40bf0a2 | 4403 | putchar ('\n'); |
19e6b90e | 4404 | } |
19e6b90e L |
4405 | } |
4406 | ||
4407 | return 1; | |
4408 | } | |
4409 | ||
a262ae96 NC |
4410 | typedef struct |
4411 | { | |
467c65bc NC |
4412 | unsigned char *name; |
4413 | unsigned int directory_index; | |
4414 | unsigned int modification_date; | |
4415 | unsigned int length; | |
a262ae96 NC |
4416 | } File_Entry; |
4417 | ||
4418 | /* Output a decoded representation of the .debug_line section. */ | |
4419 | ||
4420 | static int | |
dda8d76d | 4421 | display_debug_lines_decoded (struct dwarf_section * section, |
ec1b0fbb | 4422 | unsigned char * start, |
dda8d76d NC |
4423 | unsigned char * data, |
4424 | unsigned char * end, | |
4425 | void * fileptr) | |
a262ae96 | 4426 | { |
b40bf0a2 NC |
4427 | static DWARF2_Internal_LineInfo saved_linfo; |
4428 | ||
dda8d76d | 4429 | introduce (section, FALSE); |
a262ae96 NC |
4430 | |
4431 | while (data < end) | |
4432 | { | |
4433 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4434 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4435 | unsigned char *standard_opcodes; |
4436 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4437 | int i; |
4438 | File_Entry *file_table = NULL; | |
143a3db0 | 4439 | unsigned int n_files = 0; |
a262ae96 | 4440 | unsigned char **directory_table = NULL; |
77145576 | 4441 | dwarf_vma n_directories = 0; |
a262ae96 | 4442 | |
4925cdd7 NC |
4443 | if (const_strneq (section->name, ".debug_line.") |
4444 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4445 | These are full debug_line sections. */ | |
4446 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4447 | { |
4925cdd7 | 4448 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4449 | end_of_sequence = end; |
4450 | standard_opcodes = NULL; | |
4451 | linfo = saved_linfo; | |
058037d3 NC |
4452 | /* PR 17531: file: 0522b371. */ |
4453 | if (linfo.li_line_range == 0) | |
4454 | { | |
1306a742 | 4455 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4456 | return 0; |
4457 | } | |
b40bf0a2 | 4458 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4459 | } |
a262ae96 | 4460 | else |
b4eb7656 | 4461 | { |
b40bf0a2 | 4462 | unsigned char *hdrptr; |
a262ae96 | 4463 | |
b40bf0a2 NC |
4464 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4465 | & end_of_sequence)) == NULL) | |
a233b20c | 4466 | return 0; |
0c588247 | 4467 | |
058037d3 NC |
4468 | /* PR 17531: file: 0522b371. */ |
4469 | if (linfo.li_line_range == 0) | |
4470 | { | |
4471 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4472 | linfo.li_line_range = 1; | |
4473 | } | |
b40bf0a2 | 4474 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4475 | |
b40bf0a2 NC |
4476 | /* Save a pointer to the contents of the Opcodes table. */ |
4477 | standard_opcodes = hdrptr; | |
a262ae96 | 4478 | |
b40bf0a2 NC |
4479 | /* Traverse the Directory table just to count entries. */ |
4480 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4481 | /* PR 20440 */ |
4482 | if (data >= end) | |
4483 | { | |
4484 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4485 | linfo.li_opcode_base); | |
4486 | return 0; | |
4487 | } | |
4488 | ||
77145576 | 4489 | if (linfo.li_version >= 5) |
b40bf0a2 | 4490 | { |
77145576 JK |
4491 | unsigned char *format_start, format_count, *format; |
4492 | dwarf_vma formati, entryi; | |
4493 | unsigned int bytes_read; | |
a262ae96 | 4494 | |
dda8d76d | 4495 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4496 | |
4497 | /* Skip directories format. */ | |
4498 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
4499 | format_start = data; | |
4500 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4501 | { |
77145576 JK |
4502 | read_uleb128 (data, & bytes_read, end); |
4503 | data += bytes_read; | |
4504 | read_uleb128 (data, & bytes_read, end); | |
4505 | data += bytes_read; | |
b40bf0a2 | 4506 | } |
a262ae96 | 4507 | |
77145576 JK |
4508 | n_directories = read_uleb128 (data, & bytes_read, end); |
4509 | data += bytes_read; | |
4510 | if (data == end) | |
d8024a91 | 4511 | { |
77145576 | 4512 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
4513 | break; |
4514 | } | |
4515 | ||
b40bf0a2 NC |
4516 | directory_table = (unsigned char **) |
4517 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 4518 | |
77145576 | 4519 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 4520 | { |
77145576 | 4521 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 4522 | |
77145576 JK |
4523 | format = format_start; |
4524 | for (formati = 0; formati < format_count; formati++) | |
4525 | { | |
4526 | dwarf_vma content_type, form; | |
4527 | dwarf_vma uvalue; | |
4528 | ||
4529 | content_type = read_uleb128 (format, & bytes_read, end); | |
4530 | format += bytes_read; | |
4531 | form = read_uleb128 (format, & bytes_read, end); | |
4532 | format += bytes_read; | |
4533 | if (data == end) | |
4534 | { | |
4535 | warn (_("Corrupt directories list\n")); | |
4536 | break; | |
4537 | } | |
4538 | switch (content_type) | |
4539 | { | |
4540 | case DW_LNCT_path: | |
4541 | switch (form) | |
4542 | { | |
4543 | case DW_FORM_string: | |
4544 | *pathp = data; | |
4545 | break; | |
4546 | case DW_FORM_line_strp: | |
4547 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4548 | end); | |
4549 | /* Remove const by the cast. */ | |
4550 | *pathp = (unsigned char *) | |
4551 | fetch_indirect_line_string (uvalue); | |
4552 | break; | |
4553 | } | |
4554 | break; | |
4555 | } | |
ec1b0fbb | 4556 | data = read_and_display_attr_value (0, form, 0, start, data, end, |
77145576 JK |
4557 | 0, 0, |
4558 | linfo.li_offset_size, | |
4559 | linfo.li_version, | |
4560 | NULL, 1, section, | |
ec1b0fbb | 4561 | NULL, '\t', -1); |
77145576 JK |
4562 | } |
4563 | if (data == end) | |
4564 | { | |
4565 | warn (_("Corrupt directories list\n")); | |
4566 | break; | |
4567 | } | |
4568 | } | |
a262ae96 | 4569 | |
77145576 JK |
4570 | /* Skip files format. */ |
4571 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
4572 | format_start = data; | |
4573 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4574 | { |
b40bf0a2 NC |
4575 | read_uleb128 (data, & bytes_read, end); |
4576 | data += bytes_read; | |
4577 | read_uleb128 (data, & bytes_read, end); | |
4578 | data += bytes_read; | |
b40bf0a2 | 4579 | } |
a262ae96 | 4580 | |
77145576 JK |
4581 | n_files = read_uleb128 (data, & bytes_read, end); |
4582 | data += bytes_read; | |
4583 | if (data == end) | |
d8024a91 | 4584 | { |
77145576 | 4585 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
4586 | break; |
4587 | } | |
4588 | ||
77145576 JK |
4589 | file_table = (File_Entry *) xcalloc (1, n_files |
4590 | * sizeof (File_Entry)); | |
a262ae96 | 4591 | |
77145576 | 4592 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 4593 | { |
77145576 | 4594 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 4595 | |
77145576 JK |
4596 | format = format_start; |
4597 | for (formati = 0; formati < format_count; formati++) | |
4598 | { | |
4599 | dwarf_vma content_type, form; | |
4600 | dwarf_vma uvalue; | |
4601 | ||
4602 | content_type = read_uleb128 (format, & bytes_read, end); | |
4603 | format += bytes_read; | |
4604 | form = read_uleb128 (format, & bytes_read, end); | |
4605 | format += bytes_read; | |
4606 | if (data == end) | |
4607 | { | |
4608 | warn (_("Corrupt file name list\n")); | |
4609 | break; | |
4610 | } | |
4611 | switch (content_type) | |
4612 | { | |
4613 | case DW_LNCT_path: | |
4614 | switch (form) | |
4615 | { | |
4616 | case DW_FORM_string: | |
4617 | file->name = data; | |
4618 | break; | |
4619 | case DW_FORM_line_strp: | |
4620 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4621 | end); | |
4622 | /* Remove const by the cast. */ | |
4623 | file->name = (unsigned char *) | |
4624 | fetch_indirect_line_string (uvalue); | |
4625 | break; | |
4626 | } | |
4627 | break; | |
4628 | case DW_LNCT_directory_index: | |
4629 | switch (form) | |
4630 | { | |
4631 | case DW_FORM_data1: | |
4632 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
4633 | end); | |
4634 | break; | |
4635 | case DW_FORM_data2: | |
4636 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
4637 | end); | |
4638 | break; | |
4639 | case DW_FORM_udata: | |
4640 | file->directory_index = read_uleb128 (data, NULL, | |
4641 | end); | |
4642 | break; | |
4643 | } | |
4644 | break; | |
4645 | } | |
ec1b0fbb | 4646 | data = read_and_display_attr_value (0, form, 0, start, data, end, |
77145576 JK |
4647 | 0, 0, |
4648 | linfo.li_offset_size, | |
4649 | linfo.li_version, | |
4650 | NULL, 1, section, | |
ec1b0fbb | 4651 | NULL, '\t', -1); |
77145576 JK |
4652 | } |
4653 | if (data == end) | |
4654 | { | |
4655 | warn (_("Corrupt file name list\n")); | |
4656 | break; | |
4657 | } | |
4658 | } | |
4659 | } | |
4660 | else | |
4661 | { | |
4662 | if (*data != 0) | |
b40bf0a2 | 4663 | { |
77145576 JK |
4664 | unsigned char *ptr_directory_table = data; |
4665 | ||
4666 | while (data < end && *data != 0) | |
4667 | { | |
4668 | data += strnlen ((char *) data, end - data) + 1; | |
4669 | n_directories++; | |
4670 | } | |
4671 | ||
4672 | /* PR 20440 */ | |
4673 | if (data >= end) | |
4674 | { | |
4675 | warn (_("directory table ends unexpectedly\n")); | |
4676 | n_directories = 0; | |
4677 | break; | |
4678 | } | |
4679 | ||
4680 | /* Go through the directory table again to save the directories. */ | |
4681 | directory_table = (unsigned char **) | |
4682 | xmalloc (n_directories * sizeof (unsigned char *)); | |
4683 | ||
4684 | i = 0; | |
4685 | while (*ptr_directory_table != 0) | |
4686 | { | |
4687 | directory_table[i] = ptr_directory_table; | |
4688 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
4689 | ptr_directory_table - end) + 1; | |
4690 | i++; | |
4691 | } | |
b40bf0a2 | 4692 | } |
77145576 JK |
4693 | /* Skip the NUL at the end of the table. */ |
4694 | data++; | |
4695 | ||
4696 | /* Traverse the File Name table just to count the entries. */ | |
4697 | if (data < end && *data != 0) | |
b40bf0a2 | 4698 | { |
77145576 JK |
4699 | unsigned char *ptr_file_name_table = data; |
4700 | ||
4701 | while (data < end && *data != 0) | |
db9537d2 | 4702 | { |
77145576 JK |
4703 | unsigned int bytes_read; |
4704 | ||
4705 | /* Skip Name, directory index, last modification time and length | |
4706 | of file. */ | |
4707 | data += strnlen ((char *) data, end - data) + 1; | |
4708 | read_uleb128 (data, & bytes_read, end); | |
4709 | data += bytes_read; | |
4710 | read_uleb128 (data, & bytes_read, end); | |
4711 | data += bytes_read; | |
4712 | read_uleb128 (data, & bytes_read, end); | |
4713 | data += bytes_read; | |
4714 | ||
4715 | n_files++; | |
db9537d2 | 4716 | } |
a262ae96 | 4717 | |
77145576 JK |
4718 | if (data >= end) |
4719 | { | |
4720 | warn (_("file table ends unexpectedly\n")); | |
4721 | n_files = 0; | |
4722 | break; | |
4723 | } | |
4724 | ||
4725 | /* Go through the file table again to save the strings. */ | |
4726 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 4727 | |
77145576 JK |
4728 | i = 0; |
4729 | while (*ptr_file_name_table != 0) | |
4730 | { | |
4731 | unsigned int bytes_read; | |
4732 | ||
4733 | file_table[i].name = ptr_file_name_table; | |
4734 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
4735 | end - ptr_file_name_table) + 1; | |
4736 | ||
4737 | /* We are not interested in directory, time or size. */ | |
4738 | file_table[i].directory_index = read_uleb128 (ptr_file_name_table, | |
4739 | & bytes_read, end); | |
4740 | ptr_file_name_table += bytes_read; | |
4741 | file_table[i].modification_date = read_uleb128 (ptr_file_name_table, | |
4742 | & bytes_read, end); | |
4743 | ptr_file_name_table += bytes_read; | |
4744 | file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end); | |
4745 | ptr_file_name_table += bytes_read; | |
4746 | i++; | |
4747 | } | |
4748 | i = 0; | |
b40bf0a2 | 4749 | } |
77145576 JK |
4750 | |
4751 | /* Skip the NUL at the end of the table. */ | |
4752 | data++; | |
b40bf0a2 | 4753 | } |
cc5914eb | 4754 | |
77145576 | 4755 | /* Print the Compilation Unit's name and a header. */ |
f082820d AM |
4756 | if (file_table == NULL) |
4757 | ; | |
4758 | else if (directory_table == NULL) | |
4759 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
4760 | else |
4761 | { | |
4762 | unsigned int ix = file_table[0].directory_index; | |
4763 | const char *directory; | |
4764 | ||
4765 | if (ix == 0) | |
4766 | directory = "."; | |
4767 | /* PR 20439 */ | |
4768 | else if (n_directories == 0) | |
4769 | directory = _("<unknown>"); | |
4770 | else if (ix > n_directories) | |
4771 | { | |
4772 | warn (_("directory index %u > number of directories %s\n"), | |
4773 | ix, dwarf_vmatoa ("u", n_directories)); | |
4774 | directory = _("<corrupt>"); | |
4775 | } | |
4776 | else | |
4777 | directory = (char *) directory_table[ix - 1]; | |
4778 | ||
4779 | if (do_wide || strlen (directory) < 76) | |
4780 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
4781 | else | |
4782 | printf ("%s:\n", file_table[0].name); | |
77145576 | 4783 | } |
a262ae96 | 4784 | |
17f6ade2 | 4785 | printf (_("File name Line number Starting address View Stmt\n")); |
b40bf0a2 NC |
4786 | saved_linfo = linfo; |
4787 | } | |
a262ae96 NC |
4788 | |
4789 | /* This loop iterates through the Dwarf Line Number Program. */ | |
4790 | while (data < end_of_sequence) | |
b4eb7656 | 4791 | { |
a262ae96 | 4792 | unsigned char op_code; |
ba8826a8 | 4793 | int xop; |
b4eb7656 AM |
4794 | int adv; |
4795 | unsigned long int uladv; | |
4796 | unsigned int bytes_read; | |
4797 | int is_special_opcode = 0; | |
a262ae96 | 4798 | |
b4eb7656 | 4799 | op_code = *data++; |
ba8826a8 | 4800 | xop = op_code; |
a262ae96 | 4801 | |
b4eb7656 | 4802 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 4803 | { |
91d6fa6a | 4804 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
4805 | uladv = (op_code / linfo.li_line_range); |
4806 | if (linfo.li_max_ops_per_insn == 1) | |
4807 | { | |
4808 | uladv *= linfo.li_min_insn_length; | |
4809 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4810 | if (uladv) |
4811 | state_machine_regs.view = 0; | |
a233b20c JJ |
4812 | } |
4813 | else | |
4814 | { | |
ba8826a8 AO |
4815 | unsigned addrdelta |
4816 | = ((state_machine_regs.op_index + uladv) | |
4817 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4818 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4819 | state_machine_regs.address |
4820 | += addrdelta; | |
a233b20c JJ |
4821 | state_machine_regs.op_index |
4822 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 4823 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
4824 | if (addrdelta) |
4825 | state_machine_regs.view = 0; | |
a233b20c | 4826 | } |
a262ae96 | 4827 | |
b4eb7656 AM |
4828 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
4829 | state_machine_regs.line += adv; | |
4830 | is_special_opcode = 1; | |
ba8826a8 | 4831 | /* Increment view after printing this row. */ |
b4eb7656 AM |
4832 | } |
4833 | else switch (op_code) | |
b40bf0a2 NC |
4834 | { |
4835 | case DW_LNS_extended_op: | |
4836 | { | |
4837 | unsigned int ext_op_code_len; | |
4838 | unsigned char ext_op_code; | |
4839 | unsigned char *op_code_data = data; | |
4840 | ||
4841 | ext_op_code_len = read_uleb128 (op_code_data, &bytes_read, | |
4842 | end_of_sequence); | |
4843 | op_code_data += bytes_read; | |
4844 | ||
4845 | if (ext_op_code_len == 0) | |
4846 | { | |
f41e4712 | 4847 | warn (_("Badly formed extended line op encountered!\n")); |
b40bf0a2 NC |
4848 | break; |
4849 | } | |
4850 | ext_op_code_len += bytes_read; | |
4851 | ext_op_code = *op_code_data++; | |
ba8826a8 AO |
4852 | xop = ext_op_code; |
4853 | xop = -xop; | |
b40bf0a2 NC |
4854 | |
4855 | switch (ext_op_code) | |
4856 | { | |
4857 | case DW_LNE_end_sequence: | |
ba8826a8 | 4858 | /* Reset stuff after printing this row. */ |
b40bf0a2 NC |
4859 | break; |
4860 | case DW_LNE_set_address: | |
4861 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
87bc83b3 CC |
4862 | op_code_data, |
4863 | ext_op_code_len - bytes_read - 1, | |
b40bf0a2 NC |
4864 | end); |
4865 | state_machine_regs.op_index = 0; | |
ba8826a8 | 4866 | state_machine_regs.view = 0; |
b40bf0a2 NC |
4867 | break; |
4868 | case DW_LNE_define_file: | |
4869 | { | |
4870 | file_table = (File_Entry *) xrealloc | |
4871 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
4872 | ||
4873 | ++state_machine_regs.last_file_entry; | |
4874 | /* Source file name. */ | |
4875 | file_table[n_files].name = op_code_data; | |
4876 | op_code_data += strlen ((char *) op_code_data) + 1; | |
4877 | /* Directory index. */ | |
4878 | file_table[n_files].directory_index = | |
4879 | read_uleb128 (op_code_data, & bytes_read, | |
4880 | end_of_sequence); | |
4881 | op_code_data += bytes_read; | |
4882 | /* Last modification time. */ | |
4883 | file_table[n_files].modification_date = | |
4884 | read_uleb128 (op_code_data, & bytes_read, | |
4885 | end_of_sequence); | |
4886 | op_code_data += bytes_read; | |
4887 | /* File length. */ | |
4888 | file_table[n_files].length = | |
4889 | read_uleb128 (op_code_data, & bytes_read, | |
4890 | end_of_sequence); | |
4891 | ||
4892 | n_files++; | |
4893 | break; | |
4894 | } | |
4895 | case DW_LNE_set_discriminator: | |
4896 | case DW_LNE_HP_set_sequence: | |
4897 | /* Simply ignored. */ | |
4898 | break; | |
4899 | ||
4900 | default: | |
4901 | printf (_("UNKNOWN (%u): length %d\n"), | |
4902 | ext_op_code, ext_op_code_len - bytes_read); | |
4903 | break; | |
4904 | } | |
4905 | data += ext_op_code_len; | |
4906 | break; | |
4907 | } | |
4908 | case DW_LNS_copy: | |
ba8826a8 | 4909 | /* Increment view after printing this row. */ |
b40bf0a2 NC |
4910 | break; |
4911 | ||
4912 | case DW_LNS_advance_pc: | |
4913 | uladv = read_uleb128 (data, & bytes_read, end); | |
4914 | data += bytes_read; | |
4915 | if (linfo.li_max_ops_per_insn == 1) | |
4916 | { | |
4917 | uladv *= linfo.li_min_insn_length; | |
4918 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4919 | if (uladv) |
4920 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4921 | } |
4922 | else | |
4923 | { | |
ba8826a8 AO |
4924 | unsigned addrdelta |
4925 | = ((state_machine_regs.op_index + uladv) | |
4926 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4927 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4928 | state_machine_regs.address |
4929 | += addrdelta; | |
b40bf0a2 NC |
4930 | state_machine_regs.op_index |
4931 | = (state_machine_regs.op_index + uladv) | |
4932 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4933 | if (addrdelta) |
4934 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4935 | } |
4936 | break; | |
4937 | ||
4938 | case DW_LNS_advance_line: | |
4939 | adv = read_sleb128 (data, & bytes_read, end); | |
4940 | data += bytes_read; | |
4941 | state_machine_regs.line += adv; | |
4942 | break; | |
4943 | ||
4944 | case DW_LNS_set_file: | |
4945 | adv = read_uleb128 (data, & bytes_read, end); | |
4946 | data += bytes_read; | |
4947 | state_machine_regs.file = adv; | |
4948 | ||
db9537d2 NC |
4949 | { |
4950 | unsigned file = state_machine_regs.file - 1; | |
4951 | unsigned dir; | |
4952 | ||
4953 | if (file_table == NULL || n_files == 0) | |
4954 | printf (_("\n [Use file table entry %d]\n"), file); | |
4955 | /* PR 20439 */ | |
4956 | else if (file >= n_files) | |
4957 | { | |
4958 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
4959 | printf (_("\n <over large file table index %u>"), file); | |
4960 | } | |
4961 | else if ((dir = file_table[file].directory_index) == 0) | |
4962 | /* If directory index is 0, that means current directory. */ | |
4963 | printf ("\n./%s:[++]\n", file_table[file].name); | |
4964 | else if (directory_table == NULL || n_directories == 0) | |
4965 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
4966 | file_table[file].name, dir); | |
4967 | /* PR 20439 */ | |
4968 | else if (dir > n_directories) | |
4969 | { | |
77145576 JK |
4970 | warn (_("directory index %u > number of directories %s\n"), |
4971 | dir, dwarf_vmatoa ("u", n_directories)); | |
db9537d2 NC |
4972 | printf (_("\n <over large directory table entry %u>\n"), dir); |
4973 | } | |
4974 | else | |
4975 | printf ("\n%s/%s:\n", | |
4976 | /* The directory index starts counting at 1. */ | |
4977 | directory_table[dir - 1], file_table[file].name); | |
4978 | } | |
b40bf0a2 NC |
4979 | break; |
4980 | ||
4981 | case DW_LNS_set_column: | |
4982 | uladv = read_uleb128 (data, & bytes_read, end); | |
4983 | data += bytes_read; | |
4984 | state_machine_regs.column = uladv; | |
4985 | break; | |
4986 | ||
4987 | case DW_LNS_negate_stmt: | |
4988 | adv = state_machine_regs.is_stmt; | |
4989 | adv = ! adv; | |
4990 | state_machine_regs.is_stmt = adv; | |
4991 | break; | |
4992 | ||
4993 | case DW_LNS_set_basic_block: | |
4994 | state_machine_regs.basic_block = 1; | |
4995 | break; | |
4996 | ||
4997 | case DW_LNS_const_add_pc: | |
4998 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4999 | if (linfo.li_max_ops_per_insn == 1) | |
5000 | { | |
5001 | uladv *= linfo.li_min_insn_length; | |
5002 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
5003 | if (uladv) |
5004 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
5005 | } |
5006 | else | |
5007 | { | |
ba8826a8 AO |
5008 | unsigned addrdelta |
5009 | = ((state_machine_regs.op_index + uladv) | |
5010 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 5011 | * linfo.li_min_insn_length; |
ba8826a8 AO |
5012 | state_machine_regs.address |
5013 | += addrdelta; | |
b40bf0a2 NC |
5014 | state_machine_regs.op_index |
5015 | = (state_machine_regs.op_index + uladv) | |
5016 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
5017 | if (addrdelta) |
5018 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
5019 | } |
5020 | break; | |
5021 | ||
5022 | case DW_LNS_fixed_advance_pc: | |
5023 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
5024 | state_machine_regs.address += uladv; | |
5025 | state_machine_regs.op_index = 0; | |
ba8826a8 | 5026 | /* Do NOT reset view. */ |
b40bf0a2 NC |
5027 | break; |
5028 | ||
5029 | case DW_LNS_set_prologue_end: | |
5030 | break; | |
5031 | ||
5032 | case DW_LNS_set_epilogue_begin: | |
5033 | break; | |
5034 | ||
5035 | case DW_LNS_set_isa: | |
5036 | uladv = read_uleb128 (data, & bytes_read, end); | |
5037 | data += bytes_read; | |
5038 | printf (_(" Set ISA to %lu\n"), uladv); | |
5039 | break; | |
5040 | ||
5041 | default: | |
5042 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
5043 | ||
5044 | if (standard_opcodes != NULL) | |
5045 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
5046 | { | |
5047 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
5048 | &bytes_read, end)), | |
5049 | i == 1 ? "" : ", "); | |
5050 | data += bytes_read; | |
5051 | } | |
5052 | putchar ('\n'); | |
5053 | break; | |
5054 | } | |
a262ae96 | 5055 | |
b4eb7656 AM |
5056 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
5057 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
5058 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
5059 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
5060 | { |
5061 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
5062 | char *fileName; | |
5063 | char *newFileName = NULL; | |
5064 | size_t fileNameLength; | |
b40bf0a2 NC |
5065 | |
5066 | if (file_table) | |
db9537d2 NC |
5067 | { |
5068 | unsigned indx = state_machine_regs.file - 1; | |
5069 | /* PR 20439 */ | |
5070 | if (indx >= n_files) | |
5071 | { | |
5072 | warn (_("corrupt file index %u encountered\n"), indx); | |
5073 | fileName = _("<corrupt>"); | |
5074 | } | |
5075 | else | |
5076 | fileName = (char *) file_table[indx].name; | |
5077 | } | |
b40bf0a2 | 5078 | else |
db9537d2 | 5079 | fileName = _("<unknown>"); |
b40bf0a2 NC |
5080 | |
5081 | fileNameLength = strlen (fileName); | |
a262ae96 | 5082 | |
b4eb7656 AM |
5083 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
5084 | { | |
5085 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
5086 | /* Truncate file name */ | |
5087 | strncpy (newFileName, | |
5088 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
5089 | MAX_FILENAME_LENGTH + 1); | |
5090 | } | |
5091 | else | |
5092 | { | |
5093 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
5094 | strncpy (newFileName, fileName, fileNameLength + 1); | |
5095 | } | |
5096 | ||
5097 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) | |
5098 | { | |
a233b20c | 5099 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 5100 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 5101 | newFileName, state_machine_regs.line, |
a233b20c JJ |
5102 | state_machine_regs.address); |
5103 | else | |
ba8826a8 | 5104 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 5105 | newFileName, state_machine_regs.line, |
a233b20c JJ |
5106 | state_machine_regs.address, |
5107 | state_machine_regs.op_index); | |
b4eb7656 AM |
5108 | } |
5109 | else | |
5110 | { | |
a233b20c | 5111 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 5112 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 5113 | newFileName, state_machine_regs.line, |
a233b20c JJ |
5114 | state_machine_regs.address); |
5115 | else | |
ba8826a8 | 5116 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 5117 | newFileName, state_machine_regs.line, |
a233b20c JJ |
5118 | state_machine_regs.address, |
5119 | state_machine_regs.op_index); | |
b4eb7656 | 5120 | } |
a262ae96 | 5121 | |
ba8826a8 | 5122 | if (state_machine_regs.view) |
17f6ade2 | 5123 | printf (" %6u", state_machine_regs.view); |
ba8826a8 | 5124 | else |
17f6ade2 JD |
5125 | printf (" "); |
5126 | ||
5127 | if (state_machine_regs.is_stmt) | |
5128 | printf (" x"); | |
5129 | ||
5130 | putchar ('\n'); | |
ba8826a8 AO |
5131 | state_machine_regs.view++; |
5132 | ||
5133 | if (xop == -DW_LNE_end_sequence) | |
5134 | { | |
5135 | reset_state_machine (linfo.li_default_is_stmt); | |
5136 | putchar ('\n'); | |
5137 | } | |
a262ae96 | 5138 | |
b4eb7656 AM |
5139 | free (newFileName); |
5140 | } | |
5141 | } | |
b40bf0a2 NC |
5142 | |
5143 | if (file_table) | |
5144 | { | |
5145 | free (file_table); | |
5146 | file_table = NULL; | |
5147 | n_files = 0; | |
5148 | } | |
5149 | ||
5150 | if (directory_table) | |
5151 | { | |
5152 | free (directory_table); | |
5153 | directory_table = NULL; | |
5154 | n_directories = 0; | |
5155 | } | |
5156 | ||
a262ae96 NC |
5157 | putchar ('\n'); |
5158 | } | |
5159 | ||
5160 | return 1; | |
5161 | } | |
5162 | ||
5163 | static int | |
77145576 | 5164 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
5165 | { |
5166 | unsigned char *data = section->start; | |
5167 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
5168 | int retValRaw = 1; |
5169 | int retValDecoded = 1; | |
a262ae96 | 5170 | |
008f4c78 NC |
5171 | if (do_debug_lines == 0) |
5172 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
5173 | ||
4cb93e3b | 5174 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 5175 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 5176 | |
4cb93e3b | 5177 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
ec1b0fbb | 5178 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
a262ae96 | 5179 | |
4cb93e3b | 5180 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
5181 | return 0; |
5182 | ||
5183 | return 1; | |
5184 | } | |
5185 | ||
6e3d6dc1 NC |
5186 | static debug_info * |
5187 | find_debug_info_for_offset (unsigned long offset) | |
5188 | { | |
5189 | unsigned int i; | |
5190 | ||
5191 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
5192 | return NULL; | |
5193 | ||
5194 | for (i = 0; i < num_debug_info_entries; i++) | |
5195 | if (debug_information[i].cu_offset == offset) | |
5196 | return debug_information + i; | |
5197 | ||
5198 | return NULL; | |
5199 | } | |
5200 | ||
459d52c8 DE |
5201 | static const char * |
5202 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
5203 | { | |
5204 | /* See gdb/gdb-index.h. */ | |
5205 | static const char * const kinds[] = | |
5206 | { | |
5207 | N_ ("no info"), | |
5208 | N_ ("type"), | |
5209 | N_ ("variable"), | |
5210 | N_ ("function"), | |
5211 | N_ ("other"), | |
5212 | N_ ("unused5"), | |
5213 | N_ ("unused6"), | |
5214 | N_ ("unused7") | |
5215 | }; | |
5216 | ||
5217 | return _ (kinds[kind]); | |
5218 | } | |
5219 | ||
19e6b90e | 5220 | static int |
459d52c8 DE |
5221 | display_debug_pubnames_worker (struct dwarf_section *section, |
5222 | void *file ATTRIBUTE_UNUSED, | |
5223 | int is_gnu) | |
19e6b90e | 5224 | { |
91d6fa6a | 5225 | DWARF2_Internal_PubNames names; |
19e6b90e L |
5226 | unsigned char *start = section->start; |
5227 | unsigned char *end = start + section->size; | |
5228 | ||
6e3d6dc1 NC |
5229 | /* It does not matter if this load fails, |
5230 | we test for that later on. */ | |
5231 | load_debug_info (file); | |
5232 | ||
dda8d76d | 5233 | introduce (section, FALSE); |
19e6b90e L |
5234 | |
5235 | while (start < end) | |
5236 | { | |
5237 | unsigned char *data; | |
e98fdf1a | 5238 | unsigned long sec_off; |
bf5117e3 | 5239 | unsigned int offset_size, initial_length_size; |
19e6b90e | 5240 | |
e98fdf1a | 5241 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 5242 | if (names.pn_length == 0xffffffff) |
19e6b90e | 5243 | { |
e98fdf1a | 5244 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e L |
5245 | offset_size = 8; |
5246 | initial_length_size = 12; | |
5247 | } | |
5248 | else | |
5249 | { | |
5250 | offset_size = 4; | |
5251 | initial_length_size = 4; | |
5252 | } | |
5253 | ||
e98fdf1a AM |
5254 | sec_off = start - section->start; |
5255 | if (sec_off + names.pn_length < sec_off | |
5256 | || sec_off + names.pn_length > section->size) | |
5257 | { | |
5258 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
5259 | section->name, | |
5260 | sec_off - initial_length_size, | |
5261 | dwarf_vmatoa ("x", names.pn_length)); | |
5262 | break; | |
5263 | } | |
5264 | ||
5265 | data = start; | |
5266 | start += names.pn_length; | |
5267 | ||
0c588247 NC |
5268 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
5269 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
5270 | |
5271 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
5272 | && num_debug_info_entries > 0 | |
91d6fa6a | 5273 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 5274 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 5275 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 5276 | |
0c588247 | 5277 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 5278 | |
058037d3 NC |
5279 | printf (_(" Length: %ld\n"), |
5280 | (long) names.pn_length); | |
5281 | printf (_(" Version: %d\n"), | |
5282 | names.pn_version); | |
5283 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
5284 | (unsigned long) names.pn_offset); | |
5285 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
5286 | (long) names.pn_size); | |
19e6b90e | 5287 | |
91d6fa6a | 5288 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
5289 | { |
5290 | static int warned = 0; | |
5291 | ||
5292 | if (! warned) | |
5293 | { | |
5294 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
5295 | warned = 1; | |
5296 | } | |
5297 | ||
5298 | continue; | |
5299 | } | |
5300 | ||
459d52c8 DE |
5301 | if (is_gnu) |
5302 | printf (_("\n Offset Kind Name\n")); | |
5303 | else | |
5304 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 5305 | |
e98fdf1a | 5306 | while (1) |
19e6b90e | 5307 | { |
f41e4712 | 5308 | bfd_size_type maxprint; |
e98fdf1a | 5309 | dwarf_vma offset; |
f41e4712 | 5310 | |
0c588247 | 5311 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e | 5312 | |
e98fdf1a AM |
5313 | if (offset == 0) |
5314 | break; | |
b4eb7656 | 5315 | |
e98fdf1a AM |
5316 | data += offset_size; |
5317 | if (data >= end) | |
5318 | break; | |
5319 | maxprint = (end - data) - 1; | |
f41e4712 | 5320 | |
e98fdf1a AM |
5321 | if (is_gnu) |
5322 | { | |
5323 | unsigned int kind_data; | |
5324 | gdb_index_symbol_kind kind; | |
5325 | const char *kind_name; | |
5326 | int is_static; | |
5327 | ||
5328 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
5329 | data++; | |
5330 | maxprint --; | |
5331 | /* GCC computes the kind as the upper byte in the CU index | |
5332 | word, and then right shifts it by the CU index size. | |
5333 | Left shift KIND to where the gdb-index.h accessor macros | |
5334 | can use it. */ | |
5335 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
5336 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
5337 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
5338 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
5339 | printf (" %-6lx %s,%-10s %.*s\n", | |
5340 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
5341 | kind_name, (int) maxprint, data); | |
19e6b90e | 5342 | } |
e98fdf1a AM |
5343 | else |
5344 | printf (" %-6lx\t%.*s\n", | |
5345 | (unsigned long) offset, (int) maxprint, data); | |
5346 | ||
5347 | data += strnlen ((char *) data, maxprint) + 1; | |
5348 | if (data >= end) | |
5349 | break; | |
19e6b90e | 5350 | } |
19e6b90e L |
5351 | } |
5352 | ||
5353 | printf ("\n"); | |
5354 | return 1; | |
5355 | } | |
5356 | ||
459d52c8 DE |
5357 | static int |
5358 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
5359 | { | |
5360 | return display_debug_pubnames_worker (section, file, 0); | |
5361 | } | |
5362 | ||
5363 | static int | |
5364 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
5365 | { | |
5366 | return display_debug_pubnames_worker (section, file, 1); | |
5367 | } | |
5368 | ||
19e6b90e L |
5369 | static int |
5370 | display_debug_macinfo (struct dwarf_section *section, | |
5371 | void *file ATTRIBUTE_UNUSED) | |
5372 | { | |
5373 | unsigned char *start = section->start; | |
5374 | unsigned char *end = start + section->size; | |
5375 | unsigned char *curr = start; | |
5376 | unsigned int bytes_read; | |
5377 | enum dwarf_macinfo_record_type op; | |
5378 | ||
dda8d76d | 5379 | introduce (section, FALSE); |
19e6b90e L |
5380 | |
5381 | while (curr < end) | |
5382 | { | |
5383 | unsigned int lineno; | |
0c588247 | 5384 | const unsigned char *string; |
19e6b90e | 5385 | |
3f5e193b | 5386 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
5387 | curr++; |
5388 | ||
5389 | switch (op) | |
5390 | { | |
5391 | case DW_MACINFO_start_file: | |
5392 | { | |
5393 | unsigned int filenum; | |
5394 | ||
f6f0e17b | 5395 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5396 | curr += bytes_read; |
f6f0e17b | 5397 | filenum = read_uleb128 (curr, & bytes_read, end); |
19e6b90e L |
5398 | curr += bytes_read; |
5399 | ||
5400 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), | |
5401 | lineno, filenum); | |
5402 | } | |
5403 | break; | |
5404 | ||
5405 | case DW_MACINFO_end_file: | |
5406 | printf (_(" DW_MACINFO_end_file\n")); | |
5407 | break; | |
5408 | ||
5409 | case DW_MACINFO_define: | |
f6f0e17b | 5410 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5411 | curr += bytes_read; |
0c588247 NC |
5412 | string = curr; |
5413 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5414 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
5415 | lineno, string); | |
5416 | break; | |
5417 | ||
5418 | case DW_MACINFO_undef: | |
f6f0e17b | 5419 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5420 | curr += bytes_read; |
0c588247 NC |
5421 | string = curr; |
5422 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5423 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
5424 | lineno, string); | |
5425 | break; | |
5426 | ||
5427 | case DW_MACINFO_vendor_ext: | |
5428 | { | |
5429 | unsigned int constant; | |
5430 | ||
f6f0e17b | 5431 | constant = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5432 | curr += bytes_read; |
0c588247 NC |
5433 | string = curr; |
5434 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5435 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
5436 | constant, string); | |
5437 | } | |
5438 | break; | |
5439 | } | |
5440 | } | |
5441 | ||
5442 | return 1; | |
5443 | } | |
5444 | ||
4ccf1e31 JJ |
5445 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5446 | filename and dirname corresponding to file name table entry with index | |
5447 | FILEIDX. Return NULL on failure. */ | |
5448 | ||
5449 | static unsigned char * | |
f6f0e17b NC |
5450 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5451 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5452 | unsigned char **dir_name) |
5453 | { | |
5454 | struct dwarf_section *section = &debug_displays [line].section; | |
5455 | unsigned char *hdrptr, *dirtable, *file_name; | |
5456 | unsigned int offset_size, initial_length_size; | |
5457 | unsigned int version, opcode_base, bytes_read; | |
5458 | dwarf_vma length, diridx; | |
f6f0e17b | 5459 | const unsigned char * end; |
4ccf1e31 JJ |
5460 | |
5461 | *dir_name = NULL; | |
5462 | if (section->start == NULL | |
5463 | || line_offset >= section->size | |
5464 | || fileidx == 0) | |
5465 | return NULL; | |
5466 | ||
5467 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5468 | end = section->start + section->size; |
0c588247 NC |
5469 | |
5470 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5471 | if (length == 0xffffffff) |
5472 | { | |
5473 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5474 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
5475 | offset_size = 8; |
5476 | initial_length_size = 12; | |
5477 | } | |
5478 | else | |
5479 | { | |
5480 | offset_size = 4; | |
5481 | initial_length_size = 4; | |
5482 | } | |
e98fdf1a AM |
5483 | if (length + initial_length_size < length |
5484 | || length + initial_length_size > section->size) | |
4ccf1e31 | 5485 | return NULL; |
0c588247 NC |
5486 | |
5487 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5488 | if (version != 2 && version != 3 && version != 4) |
5489 | return NULL; | |
5490 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5491 | if (version >= 4) | |
5492 | hdrptr++; /* Skip max_ops_per_insn. */ | |
5493 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
5494 | |
5495 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
5496 | if (opcode_base == 0) |
5497 | return NULL; | |
0c588247 | 5498 | |
4ccf1e31 | 5499 | hdrptr += opcode_base - 1; |
5c1c468d NC |
5500 | if (hdrptr >= end) |
5501 | return NULL; | |
5502 | ||
4ccf1e31 JJ |
5503 | dirtable = hdrptr; |
5504 | /* Skip over dirname table. */ | |
5505 | while (*hdrptr != '\0') | |
5c1c468d NC |
5506 | { |
5507 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; | |
5508 | if (hdrptr >= end) | |
5509 | return NULL; | |
5510 | } | |
4ccf1e31 | 5511 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 5512 | |
4ccf1e31 | 5513 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 5514 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 5515 | { |
0c588247 | 5516 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
f6f0e17b | 5517 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 5518 | hdrptr += bytes_read; |
f6f0e17b | 5519 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 5520 | hdrptr += bytes_read; |
f6f0e17b | 5521 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
5522 | hdrptr += bytes_read; |
5523 | } | |
5c1c468d | 5524 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 5525 | return NULL; |
5c1c468d | 5526 | |
4ccf1e31 | 5527 | file_name = hdrptr; |
0c588247 | 5528 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
5c1c468d NC |
5529 | if (hdrptr >= end) |
5530 | return NULL; | |
f6f0e17b | 5531 | diridx = read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
5532 | if (diridx == 0) |
5533 | return file_name; | |
5c1c468d | 5534 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
0c588247 | 5535 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
5c1c468d | 5536 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
5537 | return NULL; |
5538 | *dir_name = dirtable; | |
5539 | return file_name; | |
5540 | } | |
5541 | ||
5542 | static int | |
5543 | display_debug_macro (struct dwarf_section *section, | |
5544 | void *file) | |
5545 | { | |
5546 | unsigned char *start = section->start; | |
5547 | unsigned char *end = start + section->size; | |
5548 | unsigned char *curr = start; | |
5549 | unsigned char *extended_op_buf[256]; | |
5550 | unsigned int bytes_read; | |
5551 | ||
dda8d76d NC |
5552 | load_debug_section_with_follow (str, file); |
5553 | load_debug_section_with_follow (line, file); | |
4ccf1e31 | 5554 | |
dda8d76d | 5555 | introduce (section, FALSE); |
4ccf1e31 JJ |
5556 | |
5557 | while (curr < end) | |
5558 | { | |
5559 | unsigned int lineno, version, flags; | |
5560 | unsigned int offset_size = 4; | |
0c588247 | 5561 | const unsigned char *string; |
4ccf1e31 JJ |
5562 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
5563 | unsigned char **extended_ops = NULL; | |
5564 | ||
0c588247 | 5565 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 5566 | if (version != 4 && version != 5) |
4ccf1e31 | 5567 | { |
7a7e1061 | 5568 | error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"), |
4ccf1e31 JJ |
5569 | section->name); |
5570 | return 0; | |
5571 | } | |
5572 | ||
0c588247 | 5573 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
4ccf1e31 JJ |
5574 | if (flags & 1) |
5575 | offset_size = 8; | |
5576 | printf (_(" Offset: 0x%lx\n"), | |
5577 | (unsigned long) sec_offset); | |
5578 | printf (_(" Version: %d\n"), version); | |
5579 | printf (_(" Offset size: %d\n"), offset_size); | |
5580 | if (flags & 2) | |
5581 | { | |
0c588247 | 5582 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
5583 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
5584 | (unsigned long) line_offset); | |
5585 | } | |
5586 | if (flags & 4) | |
5587 | { | |
0c588247 | 5588 | unsigned int i, count, op; |
4ccf1e31 | 5589 | dwarf_vma nargs, n; |
0c588247 NC |
5590 | |
5591 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 5592 | |
4ccf1e31 JJ |
5593 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
5594 | extended_ops = extended_op_buf; | |
5595 | if (count) | |
5596 | { | |
5597 | printf (_(" Extension opcode arguments:\n")); | |
5598 | for (i = 0; i < count; i++) | |
5599 | { | |
0c588247 | 5600 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 5601 | extended_ops[op] = curr; |
f6f0e17b | 5602 | nargs = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
5603 | curr += bytes_read; |
5604 | if (nargs == 0) | |
7a7e1061 | 5605 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
5606 | else |
5607 | { | |
7a7e1061 | 5608 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
5609 | for (n = 0; n < nargs; n++) |
5610 | { | |
0c588247 NC |
5611 | unsigned int form; |
5612 | ||
5613 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
5614 | printf ("%s%s", get_FORM_name (form), |
5615 | n == nargs - 1 ? "\n" : ", "); | |
5616 | switch (form) | |
5617 | { | |
5618 | case DW_FORM_data1: | |
5619 | case DW_FORM_data2: | |
5620 | case DW_FORM_data4: | |
5621 | case DW_FORM_data8: | |
5622 | case DW_FORM_sdata: | |
5623 | case DW_FORM_udata: | |
5624 | case DW_FORM_block: | |
5625 | case DW_FORM_block1: | |
5626 | case DW_FORM_block2: | |
5627 | case DW_FORM_block4: | |
5628 | case DW_FORM_flag: | |
5629 | case DW_FORM_string: | |
5630 | case DW_FORM_strp: | |
5631 | case DW_FORM_sec_offset: | |
5632 | break; | |
5633 | default: | |
5634 | error (_("Invalid extension opcode form %s\n"), | |
5635 | get_FORM_name (form)); | |
5636 | return 0; | |
5637 | } | |
5638 | } | |
5639 | } | |
5640 | } | |
5641 | } | |
5642 | } | |
5643 | printf ("\n"); | |
5644 | ||
5645 | while (1) | |
5646 | { | |
5647 | unsigned int op; | |
5648 | ||
5649 | if (curr >= end) | |
5650 | { | |
5651 | error (_(".debug_macro section not zero terminated\n")); | |
5652 | return 0; | |
5653 | } | |
5654 | ||
0c588247 | 5655 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
5656 | if (op == 0) |
5657 | break; | |
5658 | ||
5659 | switch (op) | |
5660 | { | |
7a7e1061 | 5661 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
5662 | { |
5663 | unsigned int filenum; | |
5664 | unsigned char *file_name = NULL, *dir_name = NULL; | |
5665 | ||
f6f0e17b | 5666 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5667 | curr += bytes_read; |
f6f0e17b | 5668 | filenum = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
5669 | curr += bytes_read; |
5670 | ||
5671 | if ((flags & 2) == 0) | |
7a7e1061 | 5672 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
5673 | else |
5674 | file_name | |
5675 | = get_line_filename_and_dirname (line_offset, filenum, | |
5676 | &dir_name); | |
5677 | if (file_name == NULL) | |
7a7e1061 | 5678 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
5679 | lineno, filenum); |
5680 | else | |
7a7e1061 | 5681 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
5682 | lineno, filenum, |
5683 | dir_name != NULL ? (const char *) dir_name : "", | |
5684 | dir_name != NULL ? "/" : "", file_name); | |
5685 | } | |
5686 | break; | |
5687 | ||
7a7e1061 JK |
5688 | case DW_MACRO_end_file: |
5689 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
5690 | break; |
5691 | ||
7a7e1061 | 5692 | case DW_MACRO_define: |
f6f0e17b | 5693 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5694 | curr += bytes_read; |
0c588247 NC |
5695 | string = curr; |
5696 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 5697 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5698 | lineno, string); |
5699 | break; | |
5700 | ||
7a7e1061 | 5701 | case DW_MACRO_undef: |
f6f0e17b | 5702 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5703 | curr += bytes_read; |
0c588247 NC |
5704 | string = curr; |
5705 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 5706 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5707 | lineno, string); |
5708 | break; | |
5709 | ||
7a7e1061 | 5710 | case DW_MACRO_define_strp: |
f6f0e17b | 5711 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5712 | curr += bytes_read; |
0c588247 | 5713 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5714 | string = fetch_indirect_string (offset); |
7a7e1061 | 5715 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5716 | lineno, string); |
5717 | break; | |
5718 | ||
7a7e1061 | 5719 | case DW_MACRO_undef_strp: |
f6f0e17b | 5720 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5721 | curr += bytes_read; |
0c588247 | 5722 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5723 | string = fetch_indirect_string (offset); |
7a7e1061 | 5724 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5725 | lineno, string); |
5726 | break; | |
5727 | ||
7a7e1061 | 5728 | case DW_MACRO_import: |
0c588247 | 5729 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5730 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
5731 | (unsigned long) offset); |
5732 | break; | |
5733 | ||
7a7e1061 | 5734 | case DW_MACRO_define_sup: |
f6f0e17b | 5735 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 5736 | curr += bytes_read; |
0c588247 | 5737 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5738 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5739 | lineno, (unsigned long) offset); |
5740 | break; | |
5741 | ||
7a7e1061 | 5742 | case DW_MACRO_undef_sup: |
f6f0e17b | 5743 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 5744 | curr += bytes_read; |
0c588247 | 5745 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5746 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5747 | lineno, (unsigned long) offset); |
5748 | break; | |
5749 | ||
7a7e1061 | 5750 | case DW_MACRO_import_sup: |
0c588247 | 5751 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5752 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
5753 | (unsigned long) offset); |
5754 | break; | |
5755 | ||
4ccf1e31 JJ |
5756 | default: |
5757 | if (extended_ops == NULL || extended_ops[op] == NULL) | |
5758 | { | |
5759 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
5760 | return 0; | |
5761 | } | |
5762 | else | |
5763 | { | |
5764 | /* Skip over unhandled opcodes. */ | |
5765 | dwarf_vma nargs, n; | |
5766 | unsigned char *desc = extended_ops[op]; | |
f6f0e17b | 5767 | nargs = read_uleb128 (desc, &bytes_read, end); |
4ccf1e31 JJ |
5768 | desc += bytes_read; |
5769 | if (nargs == 0) | |
5770 | { | |
7a7e1061 | 5771 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
5772 | break; |
5773 | } | |
7a7e1061 | 5774 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
5775 | for (n = 0; n < nargs; n++) |
5776 | { | |
0c588247 NC |
5777 | int val; |
5778 | ||
77145576 | 5779 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 5780 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 5781 | curr |
77145576 | 5782 | = read_and_display_attr_value (0, val, 0, |
ec1b0fbb | 5783 | start, curr, end, 0, 0, offset_size, |
341f9135 | 5784 | version, NULL, 0, NULL, |
ec1b0fbb | 5785 | NULL, ' ', -1); |
4ccf1e31 JJ |
5786 | if (n != nargs - 1) |
5787 | printf (","); | |
5788 | } | |
5789 | printf ("\n"); | |
5790 | } | |
5791 | break; | |
5792 | } | |
5793 | } | |
5794 | ||
5795 | printf ("\n"); | |
b4eb7656 | 5796 | } |
4ccf1e31 JJ |
5797 | |
5798 | return 1; | |
5799 | } | |
5800 | ||
19e6b90e L |
5801 | static int |
5802 | display_debug_abbrev (struct dwarf_section *section, | |
5803 | void *file ATTRIBUTE_UNUSED) | |
5804 | { | |
5805 | abbrev_entry *entry; | |
5806 | unsigned char *start = section->start; | |
5807 | unsigned char *end = start + section->size; | |
5808 | ||
dda8d76d | 5809 | introduce (section, FALSE); |
19e6b90e L |
5810 | |
5811 | do | |
5812 | { | |
7282333f AM |
5813 | unsigned char *last; |
5814 | ||
19e6b90e L |
5815 | free_abbrevs (); |
5816 | ||
7282333f | 5817 | last = start; |
19e6b90e L |
5818 | start = process_abbrev_section (start, end); |
5819 | ||
5820 | if (first_abbrev == NULL) | |
5821 | continue; | |
5822 | ||
7282333f | 5823 | printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start)); |
19e6b90e L |
5824 | |
5825 | for (entry = first_abbrev; entry; entry = entry->next) | |
5826 | { | |
5827 | abbrev_attr *attr; | |
5828 | ||
cc5914eb | 5829 | printf (" %ld %s [%s]\n", |
19e6b90e L |
5830 | entry->entry, |
5831 | get_TAG_name (entry->tag), | |
5832 | entry->children ? _("has children") : _("no children")); | |
5833 | ||
5834 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
5835 | { |
5836 | printf (" %-18s %s", | |
5837 | get_AT_name (attr->attribute), | |
5838 | get_FORM_name (attr->form)); | |
5839 | if (attr->form == DW_FORM_implicit_const) | |
5840 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
5841 | putchar ('\n'); | |
5842 | } | |
19e6b90e L |
5843 | } |
5844 | } | |
5845 | while (start); | |
5846 | ||
5847 | printf ("\n"); | |
5848 | ||
5849 | return 1; | |
5850 | } | |
5851 | ||
42bcef4a AB |
5852 | /* Return true when ADDR is the maximum address, when addresses are |
5853 | POINTER_SIZE bytes long. */ | |
5854 | ||
5855 | static bfd_boolean | |
5856 | is_max_address (dwarf_vma addr, unsigned int pointer_size) | |
5857 | { | |
5858 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
5859 | return ((addr & mask) == mask); | |
5860 | } | |
5861 | ||
9f272209 AO |
5862 | /* Display a view pair list starting at *VSTART_PTR and ending at |
5863 | VLISTEND within SECTION. */ | |
5864 | ||
5865 | static void | |
5866 | display_view_pair_list (struct dwarf_section *section, | |
5867 | unsigned char **vstart_ptr, | |
5868 | unsigned int debug_info_entry, | |
5869 | unsigned char *vlistend) | |
5870 | { | |
5871 | unsigned char *vstart = *vstart_ptr; | |
5872 | unsigned char *section_end = section->start + section->size; | |
5873 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
5874 | ||
5875 | if (vlistend < section_end) | |
5876 | section_end = vlistend; | |
5877 | ||
5878 | putchar ('\n'); | |
5879 | ||
5880 | while (vstart < section_end) | |
5881 | { | |
5882 | dwarf_vma off = vstart - section->start; | |
5883 | dwarf_vma vbegin, vend; | |
5884 | ||
5885 | unsigned int bytes_read; | |
5886 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
5887 | vstart += bytes_read; | |
5888 | if (vstart == section_end) | |
5889 | { | |
5890 | vstart -= bytes_read; | |
5891 | break; | |
5892 | } | |
5893 | ||
5894 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
5895 | vstart += bytes_read; | |
5896 | ||
5897 | printf (" %8.8lx ", (unsigned long) off); | |
5898 | ||
5899 | print_dwarf_view (vbegin, pointer_size, 1); | |
5900 | print_dwarf_view (vend, pointer_size, 1); | |
5901 | printf (_("location view pair\n")); | |
5902 | } | |
5903 | ||
5904 | putchar ('\n'); | |
5905 | *vstart_ptr = vstart; | |
5906 | } | |
5907 | ||
4723351a CC |
5908 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
5909 | ||
5910 | static void | |
5911 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
5912 | unsigned char **start_ptr, |
5913 | unsigned int debug_info_entry, | |
359ca075 JK |
5914 | dwarf_vma offset, |
5915 | dwarf_vma base_address, | |
9f272209 | 5916 | unsigned char **vstart_ptr, |
b4eb7656 | 5917 | int has_frame_base) |
4723351a | 5918 | { |
9f272209 | 5919 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 5920 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
5921 | unsigned long cu_offset; |
5922 | unsigned int pointer_size; | |
5923 | unsigned int offset_size; | |
5924 | int dwarf_version; | |
4723351a CC |
5925 | |
5926 | dwarf_vma begin; | |
5927 | dwarf_vma end; | |
5928 | unsigned short length; | |
5929 | int need_frame_base; | |
5930 | ||
82b1b41b NC |
5931 | if (debug_info_entry >= num_debug_info_entries) |
5932 | { | |
5933 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
5934 | debug_info_entry); | |
5935 | return; | |
5936 | } | |
b4eb7656 | 5937 | |
82b1b41b NC |
5938 | cu_offset = debug_information [debug_info_entry].cu_offset; |
5939 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5940 | offset_size = debug_information [debug_info_entry].offset_size; | |
5941 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 5942 | |
f41e4712 NC |
5943 | if (pointer_size < 2 || pointer_size > 8) |
5944 | { | |
5945 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5946 | pointer_size, debug_info_entry); | |
5947 | return; | |
5948 | } | |
5949 | ||
4723351a CC |
5950 | while (1) |
5951 | { | |
359ca075 | 5952 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 5953 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 5954 | |
4723351a | 5955 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
5956 | { |
5957 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5958 | (unsigned long) offset); |
b4eb7656 AM |
5959 | break; |
5960 | } | |
4723351a | 5961 | |
359ca075 | 5962 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 5963 | |
0c588247 NC |
5964 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
5965 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 5966 | |
4723351a | 5967 | if (begin == 0 && end == 0) |
b4eb7656 | 5968 | { |
d1c4b12b NC |
5969 | /* PR 18374: In a object file we can have a location list that |
5970 | starts with a begin and end of 0 because there are relocations | |
5971 | that need to be applied to the addresses. Actually applying | |
5972 | the relocations now does not help as they will probably resolve | |
5973 | to 0, since the object file has not been fully linked. Real | |
5974 | end of list markers will not have any relocations against them. */ | |
5975 | if (! reloc_at (section, off) | |
5976 | && ! reloc_at (section, off + pointer_size)) | |
5977 | { | |
5978 | printf (_("<End of list>\n")); | |
5979 | break; | |
5980 | } | |
b4eb7656 | 5981 | } |
4723351a CC |
5982 | |
5983 | /* Check base address specifiers. */ | |
42bcef4a AB |
5984 | if (is_max_address (begin, pointer_size) |
5985 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
5986 | { |
5987 | base_address = end; | |
5988 | print_dwarf_vma (begin, pointer_size); | |
5989 | print_dwarf_vma (end, pointer_size); | |
5990 | printf (_("(base address)\n")); | |
5991 | continue; | |
5992 | } | |
4723351a | 5993 | |
9f272209 AO |
5994 | if (vstart) |
5995 | { | |
5996 | unsigned int bytes_read; | |
5997 | ||
5998 | off = offset + (vstart - *start_ptr); | |
5999 | ||
6000 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
6001 | vstart += bytes_read; | |
6002 | print_dwarf_view (vbegin, pointer_size, 1); | |
6003 | ||
6004 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
6005 | vstart += bytes_read; | |
6006 | print_dwarf_view (vend, pointer_size, 1); | |
6007 | ||
6008 | printf (_("views at %8.8lx for:\n %*s "), | |
6009 | (unsigned long) off, 8, ""); | |
6010 | } | |
6011 | ||
4723351a | 6012 | if (start + 2 > section_end) |
b4eb7656 AM |
6013 | { |
6014 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6015 | (unsigned long) offset); |
b4eb7656 AM |
6016 | break; |
6017 | } | |
4723351a | 6018 | |
0c588247 | 6019 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
6020 | |
6021 | if (start + length > section_end) | |
b4eb7656 AM |
6022 | { |
6023 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6024 | (unsigned long) offset); |
b4eb7656 AM |
6025 | break; |
6026 | } | |
4723351a CC |
6027 | |
6028 | print_dwarf_vma (begin + base_address, pointer_size); | |
6029 | print_dwarf_vma (end + base_address, pointer_size); | |
6030 | ||
6031 | putchar ('('); | |
6032 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6033 | pointer_size, |
6034 | offset_size, | |
6035 | dwarf_version, | |
6036 | length, | |
6037 | cu_offset, section); | |
4723351a CC |
6038 | putchar (')'); |
6039 | ||
6040 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6041 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 6042 | |
9f272209 | 6043 | if (begin == end && vbegin == vend) |
b4eb7656 | 6044 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6045 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 6046 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
6047 | |
6048 | putchar ('\n'); | |
6049 | ||
6050 | start += length; | |
6051 | } | |
6052 | ||
6053 | *start_ptr = start; | |
9f272209 | 6054 | *vstart_ptr = vstart; |
4723351a CC |
6055 | } |
6056 | ||
77145576 JK |
6057 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
6058 | ||
6059 | static void | |
6060 | display_loclists_list (struct dwarf_section *section, | |
6061 | unsigned char **start_ptr, | |
6062 | unsigned int debug_info_entry, | |
6063 | dwarf_vma offset, | |
6064 | dwarf_vma base_address, | |
9f272209 | 6065 | unsigned char **vstart_ptr, |
77145576 JK |
6066 | int has_frame_base) |
6067 | { | |
9f272209 | 6068 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
6069 | unsigned char *section_end = section->start + section->size; |
6070 | unsigned long cu_offset; | |
6071 | unsigned int pointer_size; | |
6072 | unsigned int offset_size; | |
6073 | int dwarf_version; | |
6074 | unsigned int bytes_read; | |
6075 | ||
9dfd0db9 | 6076 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
6077 | dwarf_vma begin = -1, vbegin = -1; |
6078 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
6079 | dwarf_vma length; |
6080 | int need_frame_base; | |
6081 | ||
6082 | if (debug_info_entry >= num_debug_info_entries) | |
6083 | { | |
6084 | warn (_("No debug information available for " | |
6085 | "loclists lists of entry: %u\n"), | |
6086 | debug_info_entry); | |
6087 | return; | |
6088 | } | |
6089 | ||
6090 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6091 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6092 | offset_size = debug_information [debug_info_entry].offset_size; | |
6093 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6094 | ||
6095 | if (pointer_size < 2 || pointer_size > 8) | |
6096 | { | |
6097 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6098 | pointer_size, debug_info_entry); | |
6099 | return; | |
6100 | } | |
6101 | ||
6102 | while (1) | |
6103 | { | |
6104 | dwarf_vma off = offset + (start - *start_ptr); | |
6105 | enum dwarf_location_list_entry_type llet; | |
6106 | ||
6107 | if (start + 1 > section_end) | |
6108 | { | |
6109 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6110 | (unsigned long) offset); | |
6111 | break; | |
6112 | } | |
6113 | ||
6114 | printf (" %8.8lx ", (unsigned long) off); | |
6115 | ||
6116 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
6117 | ||
9f272209 AO |
6118 | if (vstart && llet == DW_LLE_offset_pair) |
6119 | { | |
6120 | off = offset + (vstart - *start_ptr); | |
6121 | ||
6122 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
6123 | vstart += bytes_read; | |
6124 | print_dwarf_view (vbegin, pointer_size, 1); | |
6125 | ||
6126 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
6127 | vstart += bytes_read; | |
6128 | print_dwarf_view (vend, pointer_size, 1); | |
6129 | ||
6130 | printf (_("views at %8.8lx for:\n %*s "), | |
6131 | (unsigned long) off, 8, ""); | |
6132 | } | |
6133 | ||
77145576 JK |
6134 | switch (llet) |
6135 | { | |
6136 | case DW_LLE_end_of_list: | |
6137 | printf (_("<End of list>\n")); | |
6138 | break; | |
6139 | case DW_LLE_offset_pair: | |
6140 | begin = read_uleb128 (start, &bytes_read, section_end); | |
6141 | start += bytes_read; | |
6142 | end = read_uleb128 (start, &bytes_read, section_end); | |
6143 | start += bytes_read; | |
6144 | break; | |
6145 | case DW_LLE_base_address: | |
6146 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
6147 | section_end); | |
6148 | print_dwarf_vma (base_address, pointer_size); | |
6149 | printf (_("(base address)\n")); | |
6150 | break; | |
9f272209 AO |
6151 | #ifdef DW_LLE_view_pair |
6152 | case DW_LLE_view_pair: | |
6153 | if (vstart) | |
6154 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
6155 | vbegin = read_uleb128 (start, &bytes_read, section_end); | |
6156 | start += bytes_read; | |
6157 | print_dwarf_view (vbegin, pointer_size, 1); | |
6158 | ||
6159 | vend = read_uleb128 (start, &bytes_read, section_end); | |
6160 | start += bytes_read; | |
6161 | print_dwarf_view (vend, pointer_size, 1); | |
6162 | ||
6163 | printf (_("views for:\n")); | |
6164 | continue; | |
6165 | #endif | |
77145576 JK |
6166 | default: |
6167 | error (_("Invalid location list entry type %d\n"), llet); | |
6168 | return; | |
6169 | } | |
6170 | if (llet == DW_LLE_end_of_list) | |
6171 | break; | |
6172 | if (llet != DW_LLE_offset_pair) | |
6173 | continue; | |
6174 | ||
6175 | if (start + 2 > section_end) | |
6176 | { | |
6177 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6178 | (unsigned long) offset); | |
6179 | break; | |
6180 | } | |
6181 | ||
6182 | length = read_uleb128 (start, &bytes_read, section_end); | |
6183 | start += bytes_read; | |
6184 | ||
6185 | print_dwarf_vma (begin + base_address, pointer_size); | |
6186 | print_dwarf_vma (end + base_address, pointer_size); | |
6187 | ||
6188 | putchar ('('); | |
6189 | need_frame_base = decode_location_expression (start, | |
6190 | pointer_size, | |
6191 | offset_size, | |
6192 | dwarf_version, | |
6193 | length, | |
6194 | cu_offset, section); | |
6195 | putchar (')'); | |
6196 | ||
6197 | if (need_frame_base && !has_frame_base) | |
6198 | printf (_(" [without DW_AT_frame_base]")); | |
6199 | ||
9f272209 | 6200 | if (begin == end && vbegin == vend) |
77145576 | 6201 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6202 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
6203 | fputs (_(" (start > end)"), stdout); |
6204 | ||
6205 | putchar ('\n'); | |
6206 | ||
6207 | start += length; | |
9f272209 | 6208 | vbegin = vend = -1; |
77145576 JK |
6209 | } |
6210 | ||
9f272209 AO |
6211 | if (vbegin != vm1 || vend != vm1) |
6212 | printf (_("Trailing view pair not used in a range")); | |
6213 | ||
77145576 | 6214 | *start_ptr = start; |
9f272209 | 6215 | *vstart_ptr = vstart; |
77145576 JK |
6216 | } |
6217 | ||
fab128ef CC |
6218 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
6219 | right-adjusted in a field of length LEN, and followed by a space. */ | |
6220 | ||
6221 | static void | |
6222 | print_addr_index (unsigned int idx, unsigned int len) | |
6223 | { | |
6224 | static char buf[15]; | |
6225 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 6226 | printf ("%*s ", len, buf); |
fab128ef CC |
6227 | } |
6228 | ||
4723351a CC |
6229 | /* Display a location list from a .dwo section. It uses address indexes rather |
6230 | than embedded addresses. This code closely follows display_loc_list, but the | |
6231 | two are sufficiently different that combining things is very ugly. */ | |
6232 | ||
6233 | static void | |
6234 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
6235 | unsigned char **start_ptr, |
6236 | unsigned int debug_info_entry, | |
359ca075 | 6237 | dwarf_vma offset, |
9f272209 | 6238 | unsigned char **vstart_ptr, |
b4eb7656 | 6239 | int has_frame_base) |
4723351a | 6240 | { |
9f272209 | 6241 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6242 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6243 | unsigned long cu_offset; |
6244 | unsigned int pointer_size; | |
6245 | unsigned int offset_size; | |
6246 | int dwarf_version; | |
4723351a CC |
6247 | int entry_type; |
6248 | unsigned short length; | |
6249 | int need_frame_base; | |
fab128ef | 6250 | unsigned int idx; |
4723351a CC |
6251 | unsigned int bytes_read; |
6252 | ||
82b1b41b NC |
6253 | if (debug_info_entry >= num_debug_info_entries) |
6254 | { | |
6255 | warn (_("No debug information for loc lists of entry: %u\n"), | |
6256 | debug_info_entry); | |
6257 | return; | |
6258 | } | |
6259 | ||
6260 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6261 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6262 | offset_size = debug_information [debug_info_entry].offset_size; | |
6263 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6264 | ||
f41e4712 NC |
6265 | if (pointer_size < 2 || pointer_size > 8) |
6266 | { | |
6267 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6268 | pointer_size, debug_info_entry); | |
6269 | return; | |
6270 | } | |
6271 | ||
4723351a CC |
6272 | while (1) |
6273 | { | |
359ca075 | 6274 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 6275 | |
fab128ef | 6276 | if (start >= section_end) |
b4eb7656 AM |
6277 | { |
6278 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6279 | (unsigned long) offset); |
b4eb7656 AM |
6280 | break; |
6281 | } | |
4723351a | 6282 | |
0c588247 | 6283 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
6284 | |
6285 | if (vstart) | |
6286 | switch (entry_type) | |
6287 | { | |
6288 | default: | |
6289 | break; | |
6290 | ||
6291 | case 2: | |
6292 | case 3: | |
6293 | case 4: | |
6294 | { | |
6295 | dwarf_vma view; | |
6296 | dwarf_vma off = offset + (vstart - *start_ptr); | |
6297 | ||
6298 | view = read_uleb128 (vstart, &bytes_read, section_end); | |
6299 | vstart += bytes_read; | |
6300 | print_dwarf_view (view, 8, 1); | |
6301 | ||
6302 | view = read_uleb128 (vstart, &bytes_read, section_end); | |
6303 | vstart += bytes_read; | |
6304 | print_dwarf_view (view, 8, 1); | |
6305 | ||
6306 | printf (_("views at %8.8lx for:\n %*s "), | |
6307 | (unsigned long) off, 8, ""); | |
6308 | ||
6309 | } | |
6310 | break; | |
6311 | } | |
6312 | ||
4723351a | 6313 | switch (entry_type) |
b4eb7656 AM |
6314 | { |
6315 | case 0: /* A terminating entry. */ | |
6316 | *start_ptr = start; | |
9f272209 | 6317 | *vstart_ptr = vstart; |
b4eb7656 AM |
6318 | printf (_("<End of list>\n")); |
6319 | return; | |
6320 | case 1: /* A base-address entry. */ | |
6321 | idx = read_uleb128 (start, &bytes_read, section_end); | |
6322 | start += bytes_read; | |
6323 | print_addr_index (idx, 8); | |
9f272209 | 6324 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
6325 | printf (_("(base address selection entry)\n")); |
6326 | continue; | |
6327 | case 2: /* A start/end entry. */ | |
6328 | idx = read_uleb128 (start, &bytes_read, section_end); | |
6329 | start += bytes_read; | |
6330 | print_addr_index (idx, 8); | |
6331 | idx = read_uleb128 (start, &bytes_read, section_end); | |
6332 | start += bytes_read; | |
6333 | print_addr_index (idx, 8); | |
6334 | break; | |
6335 | case 3: /* A start/length entry. */ | |
6336 | idx = read_uleb128 (start, &bytes_read, section_end); | |
6337 | start += bytes_read; | |
6338 | print_addr_index (idx, 8); | |
6339 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6340 | printf ("%08x ", idx); | |
6341 | break; | |
6342 | case 4: /* An offset pair entry. */ | |
6343 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6344 | printf ("%08x ", idx); | |
6345 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6346 | printf ("%08x ", idx); | |
6347 | break; | |
6348 | default: | |
6349 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
6350 | *start_ptr = start; | |
9f272209 | 6351 | *vstart_ptr = vstart; |
b4eb7656 AM |
6352 | return; |
6353 | } | |
4723351a CC |
6354 | |
6355 | if (start + 2 > section_end) | |
b4eb7656 AM |
6356 | { |
6357 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6358 | (unsigned long) offset); |
b4eb7656 AM |
6359 | break; |
6360 | } | |
4723351a | 6361 | |
0c588247 | 6362 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6363 | if (start + length > section_end) |
b4eb7656 AM |
6364 | { |
6365 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6366 | (unsigned long) offset); |
b4eb7656 AM |
6367 | break; |
6368 | } | |
4723351a CC |
6369 | |
6370 | putchar ('('); | |
6371 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6372 | pointer_size, |
6373 | offset_size, | |
6374 | dwarf_version, | |
6375 | length, | |
6376 | cu_offset, section); | |
4723351a CC |
6377 | putchar (')'); |
6378 | ||
6379 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6380 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
6381 | |
6382 | putchar ('\n'); | |
6383 | ||
6384 | start += length; | |
6385 | } | |
6386 | ||
6387 | *start_ptr = start; | |
9f272209 | 6388 | *vstart_ptr = vstart; |
4723351a CC |
6389 | } |
6390 | ||
9f272209 AO |
6391 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
6392 | loc_views. */ | |
51d0d03f | 6393 | |
9f272209 | 6394 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
6395 | |
6396 | static int | |
6397 | loc_offsets_compar (const void *ap, const void *bp) | |
6398 | { | |
6399 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
6400 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
6401 | ||
9f272209 AO |
6402 | int ret = (a > b) - (b > a); |
6403 | if (ret) | |
6404 | return ret; | |
6405 | ||
6406 | a = loc_views[*(const unsigned int *) ap]; | |
6407 | b = loc_views[*(const unsigned int *) bp]; | |
6408 | ||
6409 | ret = (a > b) - (b > a); | |
6410 | ||
6411 | return ret; | |
51d0d03f JJ |
6412 | } |
6413 | ||
19e6b90e L |
6414 | static int |
6415 | display_debug_loc (struct dwarf_section *section, void *file) | |
6416 | { | |
9f272209 | 6417 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
6418 | unsigned long bytes; |
6419 | unsigned char *section_begin = start; | |
6420 | unsigned int num_loc_list = 0; | |
6421 | unsigned long last_offset = 0; | |
9f272209 | 6422 | unsigned long last_view = 0; |
19e6b90e L |
6423 | unsigned int first = 0; |
6424 | unsigned int i; | |
6425 | unsigned int j; | |
6426 | int seen_first_offset = 0; | |
51d0d03f | 6427 | int locs_sorted = 1; |
9f272209 | 6428 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6429 | unsigned int *array = NULL; |
4723351a | 6430 | const char *suffix = strrchr (section->name, '.'); |
24841daa | 6431 | bfd_boolean is_dwo = FALSE; |
77145576 JK |
6432 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6433 | dwarf_vma expected_start = 0; | |
4723351a CC |
6434 | |
6435 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
24841daa | 6436 | is_dwo = TRUE; |
19e6b90e L |
6437 | |
6438 | bytes = section->size; | |
19e6b90e L |
6439 | |
6440 | if (bytes == 0) | |
6441 | { | |
6442 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6443 | return 0; | |
6444 | } | |
6445 | ||
77145576 JK |
6446 | if (is_loclists) |
6447 | { | |
6448 | unsigned char *hdrptr = section_begin; | |
6449 | dwarf_vma ll_length; | |
6450 | unsigned short ll_version; | |
6451 | unsigned char *end = section_begin + section->size; | |
6452 | unsigned char address_size, segment_selector_size; | |
6453 | uint32_t offset_entry_count; | |
6454 | ||
6455 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6456 | if (ll_length == 0xffffffff) | |
6457 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6458 | ||
6459 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6460 | if (ll_version != 5) | |
6461 | { | |
6462 | warn (_("The %s section contains corrupt or " | |
6463 | "unsupported version number: %d.\n"), | |
6464 | section->name, ll_version); | |
6465 | return 0; | |
6466 | } | |
6467 | ||
6468 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6469 | ||
6470 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6471 | if (segment_selector_size != 0) | |
6472 | { | |
6473 | warn (_("The %s section contains " | |
6474 | "unsupported segment selector size: %d.\n"), | |
6475 | section->name, segment_selector_size); | |
6476 | return 0; | |
6477 | } | |
6478 | ||
6479 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
6480 | if (offset_entry_count != 0) | |
6481 | { | |
6482 | warn (_("The %s section contains " | |
6483 | "unsupported offset entry count: %d.\n"), | |
6484 | section->name, offset_entry_count); | |
6485 | return 0; | |
6486 | } | |
6487 | ||
6488 | expected_start = hdrptr - section_begin; | |
6489 | } | |
6490 | ||
1febe64d NC |
6491 | if (load_debug_info (file) == 0) |
6492 | { | |
6493 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6494 | section->name); | |
6495 | return 0; | |
6496 | } | |
19e6b90e L |
6497 | |
6498 | /* Check the order of location list in .debug_info section. If | |
6499 | offsets of location lists are in the ascending order, we can | |
6500 | use `debug_information' directly. */ | |
6501 | for (i = 0; i < num_debug_info_entries; i++) | |
6502 | { | |
6503 | unsigned int num; | |
6504 | ||
6505 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
6506 | if (num > num_loc_list) |
6507 | num_loc_list = num; | |
19e6b90e L |
6508 | |
6509 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 6510 | if (locs_sorted && num != 0) |
19e6b90e L |
6511 | { |
6512 | if (!seen_first_offset) | |
6513 | { | |
6514 | /* This is the first location list. */ | |
6515 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 6516 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
6517 | first = i; |
6518 | seen_first_offset = 1; | |
6519 | j = 1; | |
6520 | } | |
6521 | else | |
6522 | j = 0; | |
6523 | ||
6524 | for (; j < num; j++) | |
6525 | { | |
6526 | if (last_offset > | |
9f272209 AO |
6527 | debug_information [i].loc_offsets [j] |
6528 | || (last_offset == debug_information [i].loc_offsets [j] | |
6529 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 6530 | { |
51d0d03f | 6531 | locs_sorted = 0; |
19e6b90e L |
6532 | break; |
6533 | } | |
6534 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 6535 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
6536 | } |
6537 | } | |
6538 | } | |
6539 | ||
19e6b90e L |
6540 | if (!seen_first_offset) |
6541 | error (_("No location lists in .debug_info section!\n")); | |
6542 | ||
d4bfc77b | 6543 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
6544 | && debug_information [first].loc_offsets [0] != expected_start |
6545 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
6546 | warn (_("Location lists in %s section start at 0x%s\n"), |
6547 | section->name, | |
6548 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 6549 | |
51d0d03f JJ |
6550 | if (!locs_sorted) |
6551 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d NC |
6552 | |
6553 | introduce (section, FALSE); | |
6554 | ||
d1c4b12b NC |
6555 | if (reloc_at (section, 0)) |
6556 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 6557 | |
d1c4b12b | 6558 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
6559 | |
6560 | seen_first_offset = 0; | |
6561 | for (i = first; i < num_debug_info_entries; i++) | |
6562 | { | |
9f272209 | 6563 | dwarf_vma offset, voffset; |
359ca075 | 6564 | dwarf_vma base_address; |
d1c4b12b | 6565 | unsigned int k; |
19e6b90e L |
6566 | int has_frame_base; |
6567 | ||
51d0d03f JJ |
6568 | if (!locs_sorted) |
6569 | { | |
6570 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
6571 | array[k] = k; | |
6572 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 6573 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
6574 | qsort (array, debug_information [i].num_loc_offsets, |
6575 | sizeof (*array), loc_offsets_compar); | |
6576 | } | |
19e6b90e | 6577 | |
9f272209 | 6578 | int adjacent_view_loclists = 1; |
51d0d03f | 6579 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 6580 | { |
51d0d03f JJ |
6581 | j = locs_sorted ? k : array[k]; |
6582 | if (k | |
9f272209 | 6583 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 6584 | ? k - 1 : array [k - 1]] |
9f272209 AO |
6585 | == debug_information [i].loc_offsets [j]) |
6586 | && (debug_information [i].loc_views [locs_sorted | |
6587 | ? k - 1 : array [k - 1]] | |
6588 | == debug_information [i].loc_views [j])) | |
51d0d03f | 6589 | continue; |
19e6b90e | 6590 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 6591 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 6592 | next = section_begin + offset; |
9f272209 AO |
6593 | voffset = debug_information [i].loc_views [j]; |
6594 | if (voffset != vm1) | |
6595 | vnext = section_begin + voffset; | |
6596 | else | |
6597 | vnext = NULL; | |
19e6b90e L |
6598 | base_address = debug_information [i].base_address; |
6599 | ||
9f272209 AO |
6600 | if (vnext && vnext < next) |
6601 | { | |
6602 | vstart = vnext; | |
6603 | display_view_pair_list (section, &vstart, i, next); | |
6604 | if (start == vnext) | |
6605 | start = vstart; | |
6606 | } | |
6607 | ||
6608 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
6609 | seen_first_offset = 1; |
6610 | else | |
6611 | { | |
6612 | if (start < next) | |
6613 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6614 | (unsigned long) (start - section_begin), |
c8071705 | 6615 | (unsigned long) offset); |
19e6b90e L |
6616 | else if (start > next) |
6617 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6618 | (unsigned long) (start - section_begin), |
c8071705 | 6619 | (unsigned long) offset); |
19e6b90e L |
6620 | } |
6621 | start = next; | |
9f272209 | 6622 | vstart = vnext; |
19e6b90e L |
6623 | |
6624 | if (offset >= bytes) | |
6625 | { | |
6626 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 6627 | (unsigned long) offset); |
19e6b90e L |
6628 | continue; |
6629 | } | |
6630 | ||
9f272209 AO |
6631 | if (vnext && voffset >= bytes) |
6632 | { | |
6633 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
6634 | (unsigned long) voffset); | |
6635 | continue; | |
6636 | } | |
6637 | ||
77145576 JK |
6638 | if (!is_loclists) |
6639 | { | |
6640 | if (is_dwo) | |
6641 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 6642 | &vstart, has_frame_base); |
77145576 JK |
6643 | else |
6644 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 6645 | &vstart, has_frame_base); |
77145576 | 6646 | } |
b4eb7656 | 6647 | else |
77145576 JK |
6648 | { |
6649 | if (is_dwo) | |
6650 | warn (_("DWO is not yet supported.\n")); | |
6651 | else | |
6652 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
6653 | &vstart, has_frame_base); |
6654 | } | |
6655 | ||
6656 | /* FIXME: this arrangement is quite simplistic. Nothing | |
6657 | requires locview lists to be adjacent to corresponding | |
6658 | loclists, and a single loclist could be augmented by | |
6659 | different locview lists, and vice-versa, unlikely as it | |
6660 | is that it would make sense to do so. Hopefully we'll | |
6661 | have view pair support built into loclists before we ever | |
6662 | need to address all these possibilities. */ | |
6663 | if (adjacent_view_loclists && vnext | |
6664 | && vnext != start && vstart != next) | |
6665 | { | |
6666 | adjacent_view_loclists = 0; | |
6667 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 6668 | } |
9f272209 AO |
6669 | |
6670 | if (vnext && vnext == start) | |
6671 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
6672 | } |
6673 | } | |
031cd65f | 6674 | |
4723351a | 6675 | if (start < section->start + section->size) |
d3a49aa8 AM |
6676 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
6677 | "There are %ld unused bytes at the end of section %s\n", | |
6678 | (long) (section->start + section->size - start)), | |
4723351a | 6679 | (long) (section->start + section->size - start), section->name); |
98fb390a | 6680 | putchar ('\n'); |
51d0d03f | 6681 | free (array); |
19e6b90e L |
6682 | return 1; |
6683 | } | |
6684 | ||
6685 | static int | |
6686 | display_debug_str (struct dwarf_section *section, | |
6687 | void *file ATTRIBUTE_UNUSED) | |
6688 | { | |
6689 | unsigned char *start = section->start; | |
6690 | unsigned long bytes = section->size; | |
6691 | dwarf_vma addr = section->address; | |
6692 | ||
6693 | if (bytes == 0) | |
6694 | { | |
6695 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6696 | return 0; | |
6697 | } | |
6698 | ||
dda8d76d | 6699 | introduce (section, FALSE); |
19e6b90e L |
6700 | |
6701 | while (bytes) | |
6702 | { | |
6703 | int j; | |
6704 | int k; | |
6705 | int lbytes; | |
6706 | ||
6707 | lbytes = (bytes > 16 ? 16 : bytes); | |
6708 | ||
6709 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
6710 | ||
6711 | for (j = 0; j < 16; j++) | |
6712 | { | |
6713 | if (j < lbytes) | |
6714 | printf ("%2.2x", start[j]); | |
6715 | else | |
6716 | printf (" "); | |
6717 | ||
6718 | if ((j & 3) == 3) | |
6719 | printf (" "); | |
6720 | } | |
6721 | ||
6722 | for (j = 0; j < lbytes; j++) | |
6723 | { | |
6724 | k = start[j]; | |
6725 | if (k >= ' ' && k < 0x80) | |
6726 | printf ("%c", k); | |
6727 | else | |
6728 | printf ("."); | |
6729 | } | |
6730 | ||
6731 | putchar ('\n'); | |
6732 | ||
6733 | start += lbytes; | |
6734 | addr += lbytes; | |
6735 | bytes -= lbytes; | |
6736 | } | |
6737 | ||
6738 | putchar ('\n'); | |
6739 | ||
6740 | return 1; | |
6741 | } | |
6742 | ||
19e6b90e L |
6743 | static int |
6744 | display_debug_info (struct dwarf_section *section, void *file) | |
6745 | { | |
d85bf2ba | 6746 | return process_debug_info (section, file, section->abbrev_sec, FALSE, FALSE); |
19e6b90e L |
6747 | } |
6748 | ||
2b6f5997 CC |
6749 | static int |
6750 | display_debug_types (struct dwarf_section *section, void *file) | |
6751 | { | |
d85bf2ba | 6752 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
6f875884 TG |
6753 | } |
6754 | ||
6755 | static int | |
6756 | display_trace_info (struct dwarf_section *section, void *file) | |
6757 | { | |
d85bf2ba | 6758 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
2b6f5997 | 6759 | } |
19e6b90e L |
6760 | |
6761 | static int | |
6762 | display_debug_aranges (struct dwarf_section *section, | |
6763 | void *file ATTRIBUTE_UNUSED) | |
6764 | { | |
6765 | unsigned char *start = section->start; | |
6766 | unsigned char *end = start + section->size; | |
6767 | ||
dda8d76d | 6768 | introduce (section, FALSE); |
19e6b90e | 6769 | |
6e3d6dc1 NC |
6770 | /* It does not matter if this load fails, |
6771 | we test for that later on. */ | |
6772 | load_debug_info (file); | |
6773 | ||
19e6b90e L |
6774 | while (start < end) |
6775 | { | |
6776 | unsigned char *hdrptr; | |
6777 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 6778 | unsigned char *addr_ranges; |
2d9472a2 NC |
6779 | dwarf_vma length; |
6780 | dwarf_vma address; | |
e98fdf1a | 6781 | unsigned long sec_off; |
53b8873b | 6782 | unsigned char address_size; |
19e6b90e | 6783 | int excess; |
bf5117e3 NC |
6784 | unsigned int offset_size; |
6785 | unsigned int initial_length_size; | |
19e6b90e L |
6786 | |
6787 | hdrptr = start; | |
6788 | ||
0c588247 | 6789 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
6790 | if (arange.ar_length == 0xffffffff) |
6791 | { | |
0c588247 | 6792 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
6793 | offset_size = 8; |
6794 | initial_length_size = 12; | |
6795 | } | |
6796 | else | |
6797 | { | |
6798 | offset_size = 4; | |
6799 | initial_length_size = 4; | |
6800 | } | |
6801 | ||
e98fdf1a AM |
6802 | sec_off = hdrptr - section->start; |
6803 | if (sec_off + arange.ar_length < sec_off | |
6804 | || sec_off + arange.ar_length > section->size) | |
6805 | { | |
6806 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
6807 | section->name, | |
6808 | sec_off - initial_length_size, | |
6809 | dwarf_vmatoa ("x", arange.ar_length)); | |
6810 | break; | |
6811 | } | |
6812 | ||
0c588247 NC |
6813 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
6814 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 6815 | |
6e3d6dc1 NC |
6816 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
6817 | && num_debug_info_entries > 0 | |
6818 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
6819 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 6820 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 6821 | |
0c588247 NC |
6822 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
6823 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
6824 | |
6825 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
6826 | { | |
67f101ee NC |
6827 | /* PR 19872: A version number of 0 probably means that there is |
6828 | padding at the end of the .debug_aranges section. Gold puts | |
6829 | it there when performing an incremental link, for example. | |
6830 | So do not generate a warning in this case. */ | |
6831 | if (arange.ar_version) | |
6832 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
6833 | break; |
6834 | } | |
6835 | ||
47704ddf KT |
6836 | printf (_(" Length: %ld\n"), |
6837 | (long) arange.ar_length); | |
19e6b90e | 6838 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
6839 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
6840 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
6841 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
6842 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
6843 | ||
53b8873b NC |
6844 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
6845 | ||
f41e4712 NC |
6846 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
6847 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
6848 | { |
6849 | error (_("Invalid address size in %s section!\n"), | |
6850 | section->name); | |
6851 | break; | |
6852 | } | |
6853 | ||
53b8873b NC |
6854 | /* The DWARF spec does not require that the address size be a power |
6855 | of two, but we do. This will have to change if we ever encounter | |
6856 | an uneven architecture. */ | |
6857 | if ((address_size & (address_size - 1)) != 0) | |
6858 | { | |
6859 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
6860 | break; | |
6861 | } | |
cecf136e | 6862 | |
209c9a13 NC |
6863 | if (address_size > 4) |
6864 | printf (_("\n Address Length\n")); | |
6865 | else | |
6866 | printf (_("\n Address Length\n")); | |
19e6b90e | 6867 | |
91d6fa6a | 6868 | addr_ranges = hdrptr; |
19e6b90e | 6869 | |
53b8873b NC |
6870 | /* Must pad to an alignment boundary that is twice the address size. */ |
6871 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 6872 | if (excess) |
91d6fa6a | 6873 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 6874 | |
e98fdf1a | 6875 | start += arange.ar_length + initial_length_size; |
1617e571 | 6876 | |
91d6fa6a | 6877 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 6878 | { |
0c588247 NC |
6879 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
6880 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 6881 | |
80c35038 | 6882 | printf (" "); |
2d9472a2 NC |
6883 | print_dwarf_vma (address, address_size); |
6884 | print_dwarf_vma (length, address_size); | |
6885 | putchar ('\n'); | |
19e6b90e | 6886 | } |
19e6b90e L |
6887 | } |
6888 | ||
6889 | printf ("\n"); | |
6890 | ||
6891 | return 1; | |
6892 | } | |
6893 | ||
4723351a CC |
6894 | /* Comparison function for qsort. */ |
6895 | static int | |
6896 | comp_addr_base (const void * v0, const void * v1) | |
6897 | { | |
d367307b AM |
6898 | debug_info *info0 = *(debug_info **) v0; |
6899 | debug_info *info1 = *(debug_info **) v1; | |
4723351a CC |
6900 | return info0->addr_base - info1->addr_base; |
6901 | } | |
6902 | ||
6903 | /* Display the debug_addr section. */ | |
6904 | static int | |
6905 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 6906 | void *file) |
4723351a CC |
6907 | { |
6908 | debug_info **debug_addr_info; | |
6909 | unsigned char *entry; | |
6910 | unsigned char *end; | |
6911 | unsigned int i; | |
6912 | unsigned int count; | |
6913 | ||
6914 | if (section->size == 0) | |
6915 | { | |
6916 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6917 | return 0; | |
6918 | } | |
6919 | ||
6920 | if (load_debug_info (file) == 0) | |
6921 | { | |
6922 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6923 | section->name); | |
6924 | return 0; | |
6925 | } | |
6926 | ||
dda8d76d | 6927 | introduce (section, FALSE); |
4723351a | 6928 | |
1306a742 NC |
6929 | /* PR 17531: file: cf38d01b. |
6930 | We use xcalloc because a corrupt file may not have initialised all of the | |
6931 | fields in the debug_info structure, which means that the sort below might | |
6932 | try to move uninitialised data. */ | |
6933 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 6934 | sizeof (debug_info *)); |
4723351a CC |
6935 | |
6936 | count = 0; | |
6937 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 6938 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
6939 | { |
6940 | /* PR 17531: file: cf38d01b. */ | |
6941 | if (debug_information[i].addr_base >= section->size) | |
6942 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
6943 | (unsigned long) debug_information[i].addr_base, i); | |
6944 | else | |
6945 | debug_addr_info [count++] = debug_information + i; | |
6946 | } | |
4723351a CC |
6947 | |
6948 | /* Add a sentinel to make iteration convenient. */ | |
6949 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
6950 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 6951 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 6952 | |
4723351a CC |
6953 | for (i = 0; i < count; i++) |
6954 | { | |
6955 | unsigned int idx; | |
fab128ef | 6956 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
6957 | |
6958 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 6959 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 6960 | |
fab128ef | 6961 | printf (_("\tIndex\tAddress\n")); |
4723351a CC |
6962 | entry = section->start + debug_addr_info [i]->addr_base; |
6963 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
6964 | idx = 0; | |
6965 | while (entry < end) | |
b4eb7656 AM |
6966 | { |
6967 | dwarf_vma base = byte_get (entry, address_size); | |
6968 | printf (_("\t%d:\t"), idx); | |
6969 | print_dwarf_vma (base, address_size); | |
6970 | printf ("\n"); | |
6971 | entry += address_size; | |
6972 | idx++; | |
6973 | } | |
4723351a CC |
6974 | } |
6975 | printf ("\n"); | |
6976 | ||
6977 | free (debug_addr_info); | |
6978 | return 1; | |
6979 | } | |
6980 | ||
6981 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 6982 | |
4723351a CC |
6983 | static int |
6984 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 6985 | void *file ATTRIBUTE_UNUSED) |
4723351a CC |
6986 | { |
6987 | if (section->size == 0) | |
6988 | { | |
6989 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6990 | return 0; | |
6991 | } | |
6992 | /* TODO: Dump the contents. This is made somewhat difficult by not knowing | |
6993 | what the offset size is for this section. */ | |
6994 | return 1; | |
6995 | } | |
6996 | ||
01a8f077 JK |
6997 | /* Each debug_information[x].range_lists[y] gets this representation for |
6998 | sorting purposes. */ | |
6999 | ||
7000 | struct range_entry | |
467c65bc NC |
7001 | { |
7002 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 7003 | dwarf_vma ranges_offset; |
01a8f077 | 7004 | |
467c65bc NC |
7005 | /* Original debug_information to find parameters of the data. */ |
7006 | debug_info *debug_info_p; | |
7007 | }; | |
01a8f077 JK |
7008 | |
7009 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
7010 | ||
7011 | static int | |
7012 | range_entry_compar (const void *ap, const void *bp) | |
7013 | { | |
3f5e193b NC |
7014 | const struct range_entry *a_re = (const struct range_entry *) ap; |
7015 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
7016 | const dwarf_vma a = a_re->ranges_offset; |
7017 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
7018 | |
7019 | return (a > b) - (b > a); | |
7020 | } | |
7021 | ||
77145576 JK |
7022 | static void |
7023 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
7024 | unsigned int pointer_size, unsigned long offset, | |
7025 | unsigned long base_address) | |
7026 | { | |
7027 | while (start < finish) | |
7028 | { | |
7029 | dwarf_vma begin; | |
7030 | dwarf_vma end; | |
7031 | ||
7032 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7033 | if (start >= finish) | |
7034 | break; | |
7035 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7036 | ||
d11ae95e | 7037 | |
77145576 JK |
7038 | printf (" %8.8lx ", offset); |
7039 | ||
7040 | if (begin == 0 && end == 0) | |
7041 | { | |
7042 | printf (_("<End of list>\n")); | |
7043 | break; | |
7044 | } | |
7045 | ||
7046 | /* Check base address specifiers. */ | |
7047 | if (is_max_address (begin, pointer_size) | |
7048 | && !is_max_address (end, pointer_size)) | |
7049 | { | |
7050 | base_address = end; | |
7051 | print_dwarf_vma (begin, pointer_size); | |
7052 | print_dwarf_vma (end, pointer_size); | |
7053 | printf ("(base address)\n"); | |
7054 | continue; | |
7055 | } | |
7056 | ||
7057 | print_dwarf_vma (begin + base_address, pointer_size); | |
7058 | print_dwarf_vma (end + base_address, pointer_size); | |
7059 | ||
7060 | if (begin == end) | |
7061 | fputs (_("(start == end)"), stdout); | |
7062 | else if (begin > end) | |
7063 | fputs (_("(start > end)"), stdout); | |
7064 | ||
7065 | putchar ('\n'); | |
7066 | } | |
7067 | } | |
7068 | ||
7069 | static void | |
7070 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
7071 | unsigned int pointer_size, unsigned long offset, | |
7072 | unsigned long base_address) | |
7073 | { | |
7074 | unsigned char *next = start; | |
7075 | ||
7076 | while (1) | |
7077 | { | |
7078 | unsigned long off = offset + (start - next); | |
7079 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
7080 | /* Initialize it due to a false compiler warning. */ |
7081 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
7082 | unsigned int bytes_read; |
7083 | ||
7084 | if (start + 1 > finish) | |
7085 | { | |
7086 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
7087 | offset); | |
7088 | break; | |
7089 | } | |
7090 | ||
7091 | printf (" %8.8lx ", off); | |
7092 | ||
7093 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
7094 | ||
7095 | switch (rlet) | |
7096 | { | |
7097 | case DW_RLE_end_of_list: | |
7098 | printf (_("<End of list>\n")); | |
7099 | break; | |
7100 | case DW_RLE_base_address: | |
7101 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
7102 | print_dwarf_vma (base_address, pointer_size); | |
7103 | printf (_("(base address)\n")); | |
7104 | break; | |
7105 | case DW_RLE_start_length: | |
7106 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7107 | length = read_uleb128 (start, &bytes_read, finish); | |
7108 | start += bytes_read; | |
7109 | end = begin + length; | |
7110 | break; | |
7111 | case DW_RLE_offset_pair: | |
7112 | begin = read_uleb128 (start, &bytes_read, finish); | |
7113 | start += bytes_read; | |
7114 | end = read_uleb128 (start, &bytes_read, finish); | |
7115 | start += bytes_read; | |
7116 | break; | |
7117 | case DW_RLE_start_end: | |
7118 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7119 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7120 | break; | |
7121 | default: | |
7122 | error (_("Invalid range list entry type %d\n"), rlet); | |
7123 | rlet = DW_RLE_end_of_list; | |
7124 | break; | |
7125 | } | |
7126 | if (rlet == DW_RLE_end_of_list) | |
7127 | break; | |
7128 | if (rlet == DW_RLE_base_address) | |
7129 | continue; | |
7130 | ||
7131 | print_dwarf_vma (begin + base_address, pointer_size); | |
7132 | print_dwarf_vma (end + base_address, pointer_size); | |
7133 | ||
7134 | if (begin == end) | |
7135 | fputs (_("(start == end)"), stdout); | |
7136 | else if (begin > end) | |
7137 | fputs (_("(start > end)"), stdout); | |
7138 | ||
7139 | putchar ('\n'); | |
7140 | } | |
7141 | } | |
7142 | ||
19e6b90e L |
7143 | static int |
7144 | display_debug_ranges (struct dwarf_section *section, | |
7145 | void *file ATTRIBUTE_UNUSED) | |
7146 | { | |
7147 | unsigned char *start = section->start; | |
a2ff7a4b | 7148 | unsigned char *last_start = start; |
f6f0e17b | 7149 | unsigned long bytes = section->size; |
19e6b90e | 7150 | unsigned char *section_begin = start; |
f6f0e17b | 7151 | unsigned char *finish = start + bytes; |
01a8f077 JK |
7152 | unsigned int num_range_list, i; |
7153 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
7154 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
7155 | /* Initialize it due to a false compiler warning. */ | |
7156 | unsigned char address_size = 0; | |
19e6b90e | 7157 | |
19e6b90e L |
7158 | if (bytes == 0) |
7159 | { | |
7160 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7161 | return 0; | |
7162 | } | |
7163 | ||
77145576 JK |
7164 | if (is_rnglists) |
7165 | { | |
7166 | dwarf_vma initial_length; | |
7167 | unsigned int initial_length_size; | |
7168 | unsigned char segment_selector_size; | |
7169 | unsigned int offset_size, offset_entry_count; | |
7170 | unsigned short version; | |
7171 | ||
7172 | /* Get and check the length of the block. */ | |
7173 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
7174 | ||
7175 | if (initial_length == 0xffffffff) | |
7176 | { | |
7177 | /* This section is 64-bit DWARF 3. */ | |
7178 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
7179 | offset_size = 8; | |
7180 | initial_length_size = 12; | |
7181 | } | |
7182 | else | |
7183 | { | |
7184 | offset_size = 4; | |
7185 | initial_length_size = 4; | |
7186 | } | |
7187 | ||
7188 | if (initial_length + initial_length_size > section->size) | |
7189 | { | |
7190 | /* If the length field has a relocation against it, then we should | |
7191 | not complain if it is inaccurate (and probably negative). | |
7192 | It is copied from .debug_line handling code. */ | |
7193 | if (reloc_at (section, (start - section->start) - offset_size)) | |
7194 | { | |
7195 | initial_length = (finish - start) - initial_length_size; | |
7196 | } | |
7197 | else | |
7198 | { | |
7199 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
7200 | (long) initial_length); | |
7201 | return 0; | |
7202 | } | |
7203 | } | |
7204 | ||
7205 | /* Get and check the version number. */ | |
7206 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
7207 | ||
7208 | if (version != 5) | |
7209 | { | |
7210 | warn (_("Only DWARF version 5 debug_rnglists info " | |
7211 | "is currently supported.\n")); | |
7212 | return 0; | |
7213 | } | |
7214 | ||
7215 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
7216 | ||
7217 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
7218 | if (segment_selector_size != 0) | |
7219 | { | |
7220 | warn (_("The %s section contains " | |
7221 | "unsupported segment selector size: %d.\n"), | |
7222 | section->name, segment_selector_size); | |
7223 | return 0; | |
7224 | } | |
7225 | ||
7226 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
7227 | if (offset_entry_count != 0) | |
7228 | { | |
7229 | warn (_("The %s section contains " | |
7230 | "unsupported offset entry count: %u.\n"), | |
7231 | section->name, offset_entry_count); | |
7232 | return 0; | |
7233 | } | |
7234 | } | |
7235 | ||
1febe64d NC |
7236 | if (load_debug_info (file) == 0) |
7237 | { | |
7238 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7239 | section->name); | |
7240 | return 0; | |
7241 | } | |
19e6b90e | 7242 | |
01a8f077 | 7243 | num_range_list = 0; |
19e6b90e | 7244 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 7245 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 7246 | |
01a8f077 | 7247 | if (num_range_list == 0) |
4723351a CC |
7248 | { |
7249 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 7250 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
7251 | printf (_("No range lists in .debug_info section.\n")); |
7252 | return 1; | |
7253 | } | |
19e6b90e | 7254 | |
3f5e193b NC |
7255 | range_entries = (struct range_entry *) |
7256 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 7257 | range_entry_fill = range_entries; |
19e6b90e | 7258 | |
01a8f077 JK |
7259 | for (i = 0; i < num_debug_info_entries; i++) |
7260 | { | |
7261 | debug_info *debug_info_p = &debug_information[i]; | |
7262 | unsigned int j; | |
7263 | ||
7264 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
7265 | { | |
7266 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
7267 | range_entry_fill->debug_info_p = debug_info_p; | |
7268 | range_entry_fill++; | |
19e6b90e L |
7269 | } |
7270 | } | |
7271 | ||
01a8f077 JK |
7272 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
7273 | range_entry_compar); | |
19e6b90e | 7274 | |
d493b283 | 7275 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 7276 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 7277 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 7278 | |
dda8d76d NC |
7279 | introduce (section, FALSE); |
7280 | ||
19e6b90e L |
7281 | printf (_(" Offset Begin End\n")); |
7282 | ||
01a8f077 | 7283 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 7284 | { |
01a8f077 JK |
7285 | struct range_entry *range_entry = &range_entries[i]; |
7286 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 7287 | unsigned int pointer_size; |
359ca075 | 7288 | dwarf_vma offset; |
01a8f077 | 7289 | unsigned char *next; |
359ca075 | 7290 | dwarf_vma base_address; |
19e6b90e | 7291 | |
77145576 | 7292 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 7293 | offset = range_entry->ranges_offset; |
01a8f077 JK |
7294 | next = section_begin + offset; |
7295 | base_address = debug_info_p->base_address; | |
cecf136e | 7296 | |
f41e4712 NC |
7297 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
7298 | if (pointer_size < 2 || pointer_size > 8) | |
7299 | { | |
7300 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 7301 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
7302 | continue; |
7303 | } | |
b4eb7656 | 7304 | |
d11ae95e NC |
7305 | if (next < section_begin || next >= finish) |
7306 | { | |
7307 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
7308 | (unsigned long) offset, i); | |
7309 | continue; | |
7310 | } | |
7311 | ||
4723351a | 7312 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 7313 | { |
01a8f077 JK |
7314 | if (start < next) |
7315 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
7316 | (unsigned long) (start - section_begin), | |
7317 | (unsigned long) (next - section_begin), section->name); | |
7318 | else if (start > next) | |
a2ff7a4b AM |
7319 | { |
7320 | if (next == last_start) | |
7321 | continue; | |
7322 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
7323 | (unsigned long) (start - section_begin), | |
7324 | (unsigned long) (next - section_begin), section->name); | |
7325 | } | |
01a8f077 | 7326 | } |
d11ae95e | 7327 | |
01a8f077 | 7328 | start = next; |
a2ff7a4b | 7329 | last_start = next; |
19e6b90e | 7330 | |
77145576 JK |
7331 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
7332 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
7333 | } |
7334 | putchar ('\n'); | |
01a8f077 JK |
7335 | |
7336 | free (range_entries); | |
7337 | ||
19e6b90e L |
7338 | return 1; |
7339 | } | |
7340 | ||
7341 | typedef struct Frame_Chunk | |
7342 | { | |
7343 | struct Frame_Chunk *next; | |
7344 | unsigned char *chunk_start; | |
a1165289 | 7345 | unsigned int ncols; |
19e6b90e L |
7346 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
7347 | short int *col_type; | |
7348 | int *col_offset; | |
7349 | char *augmentation; | |
7350 | unsigned int code_factor; | |
7351 | int data_factor; | |
bf5117e3 NC |
7352 | dwarf_vma pc_begin; |
7353 | dwarf_vma pc_range; | |
32ef3000 | 7354 | unsigned int cfa_reg; |
c8071705 | 7355 | dwarf_vma cfa_offset; |
a1165289 | 7356 | unsigned int ra; |
19e6b90e L |
7357 | unsigned char fde_encoding; |
7358 | unsigned char cfa_exp; | |
604282a7 JJ |
7359 | unsigned char ptr_size; |
7360 | unsigned char segment_size; | |
19e6b90e L |
7361 | } |
7362 | Frame_Chunk; | |
7363 | ||
1296bc99 AB |
7364 | typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int); |
7365 | static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func; | |
665ce1f6 L |
7366 | static const char *const *dwarf_regnames; |
7367 | static unsigned int dwarf_regnames_count; | |
7368 | ||
1296bc99 | 7369 | |
19e6b90e L |
7370 | /* A marker for a col_type that means this column was never referenced |
7371 | in the frame info. */ | |
7372 | #define DW_CFA_unreferenced (-1) | |
7373 | ||
a1165289 | 7374 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
7375 | -1 for invalid reg. */ |
7376 | ||
7377 | static int | |
7378 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 7379 | { |
a1165289 | 7380 | unsigned int prev = fc->ncols; |
19e6b90e | 7381 | |
665ce1f6 L |
7382 | if (reg < (unsigned int) fc->ncols) |
7383 | return 0; | |
7384 | ||
d9acf707 | 7385 | if (dwarf_regnames_count > 0 |
665ce1f6 L |
7386 | && reg > dwarf_regnames_count) |
7387 | return -1; | |
19e6b90e L |
7388 | |
7389 | fc->ncols = reg + 1; | |
a1165289 NC |
7390 | /* PR 17512: file: 10450-2643-0.004. |
7391 | If reg == -1 then this can happen... */ | |
7392 | if (fc->ncols == 0) | |
7393 | return -1; | |
7394 | ||
06614111 | 7395 | /* PR 17512: file: 2844a11d. */ |
d9acf707 | 7396 | if (fc->ncols > 1024 && dwarf_regnames_count == 0) |
06614111 NC |
7397 | { |
7398 | error (_("Unfeasibly large register number: %u\n"), reg); | |
7399 | fc->ncols = 0; | |
7400 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
7401 | we ever encounter a valid binary that exceeds it. */ | |
7402 | return -1; | |
7403 | } | |
7404 | ||
3f5e193b | 7405 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 7406 | sizeof (short int)); |
3f5e193b | 7407 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 7408 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
7409 | if (fc->col_type == NULL || fc->col_offset == NULL) |
7410 | { | |
7411 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
7412 | fc->ncols); | |
7413 | fc->ncols = 0; | |
7414 | return -1; | |
7415 | } | |
19e6b90e L |
7416 | |
7417 | while (prev < fc->ncols) | |
7418 | { | |
7419 | fc->col_type[prev] = DW_CFA_unreferenced; | |
7420 | fc->col_offset[prev] = 0; | |
7421 | prev++; | |
7422 | } | |
665ce1f6 | 7423 | return 1; |
19e6b90e L |
7424 | } |
7425 | ||
2dc4cec1 L |
7426 | static const char *const dwarf_regnames_i386[] = |
7427 | { | |
43234a1e L |
7428 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
7429 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7430 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7431 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
7432 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
7433 | NULL, NULL, /* 19 - 20 */ | |
7434 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
7435 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
7436 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
7437 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
7438 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
7439 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7440 | "tr", "ldtr", /* 48 - 49 */ | |
7441 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7442 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7443 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7444 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7445 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7446 | NULL, NULL, NULL, /* 90 - 92 */ | |
7447 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
7448 | }; |
7449 | ||
3d875af5 L |
7450 | static const char *const dwarf_regnames_iamcu[] = |
7451 | { | |
7452 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
7453 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7454 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7455 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
7456 | NULL, NULL, /* 19 - 20 */ | |
7457 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
7458 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
7459 | NULL, NULL, NULL, /* 37 - 39 */ | |
7460 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7461 | "tr", "ldtr", /* 48 - 49 */ | |
7462 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7463 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7464 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7465 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7466 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7467 | NULL, NULL, NULL, /* 90 - 92 */ | |
7468 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
7469 | }; | |
7470 | ||
99f6fdd9 | 7471 | static void |
b129eb0e RH |
7472 | init_dwarf_regnames_i386 (void) |
7473 | { | |
7474 | dwarf_regnames = dwarf_regnames_i386; | |
7475 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
1296bc99 | 7476 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
7477 | } |
7478 | ||
99f6fdd9 | 7479 | static void |
3d875af5 L |
7480 | init_dwarf_regnames_iamcu (void) |
7481 | { | |
7482 | dwarf_regnames = dwarf_regnames_iamcu; | |
7483 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
1296bc99 | 7484 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
3d875af5 L |
7485 | } |
7486 | ||
2dc4cec1 L |
7487 | static const char *const dwarf_regnames_x86_64[] = |
7488 | { | |
7489 | "rax", "rdx", "rcx", "rbx", | |
7490 | "rsi", "rdi", "rbp", "rsp", | |
7491 | "r8", "r9", "r10", "r11", | |
7492 | "r12", "r13", "r14", "r15", | |
7493 | "rip", | |
7494 | "xmm0", "xmm1", "xmm2", "xmm3", | |
7495 | "xmm4", "xmm5", "xmm6", "xmm7", | |
7496 | "xmm8", "xmm9", "xmm10", "xmm11", | |
7497 | "xmm12", "xmm13", "xmm14", "xmm15", | |
7498 | "st0", "st1", "st2", "st3", | |
7499 | "st4", "st5", "st6", "st7", | |
7500 | "mm0", "mm1", "mm2", "mm3", | |
7501 | "mm4", "mm5", "mm6", "mm7", | |
7502 | "rflags", | |
7503 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
7504 | "fs.base", "gs.base", NULL, NULL, | |
7505 | "tr", "ldtr", | |
43234a1e L |
7506 | "mxcsr", "fcw", "fsw", |
7507 | "xmm16", "xmm17", "xmm18", "xmm19", | |
7508 | "xmm20", "xmm21", "xmm22", "xmm23", | |
7509 | "xmm24", "xmm25", "xmm26", "xmm27", | |
7510 | "xmm28", "xmm29", "xmm30", "xmm31", | |
7511 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
7512 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
7513 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
7514 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
7515 | NULL, NULL, NULL, /* 115 - 117 */ | |
7516 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
7517 | }; |
7518 | ||
99f6fdd9 | 7519 | static void |
b129eb0e RH |
7520 | init_dwarf_regnames_x86_64 (void) |
7521 | { | |
7522 | dwarf_regnames = dwarf_regnames_x86_64; | |
7523 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
1296bc99 | 7524 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
b129eb0e RH |
7525 | } |
7526 | ||
4ee22035 RH |
7527 | static const char *const dwarf_regnames_aarch64[] = |
7528 | { | |
b4eb7656 AM |
7529 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
7530 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
4ee22035 RH |
7531 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", |
7532 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp", | |
7533 | NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL, | |
fab7c86e TC |
7534 | NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr", |
7535 | "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", | |
7536 | "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", | |
b4eb7656 AM |
7537 | "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", |
7538 | "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", | |
4ee22035 RH |
7539 | "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", |
7540 | "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", | |
fab7c86e TC |
7541 | "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", |
7542 | "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", | |
7543 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", | |
7544 | "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", | |
4ee22035 RH |
7545 | }; |
7546 | ||
99f6fdd9 | 7547 | static void |
4ee22035 RH |
7548 | init_dwarf_regnames_aarch64 (void) |
7549 | { | |
7550 | dwarf_regnames = dwarf_regnames_aarch64; | |
7551 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
1296bc99 | 7552 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
4ee22035 RH |
7553 | } |
7554 | ||
d6bb17b0 AA |
7555 | static const char *const dwarf_regnames_s390[] = |
7556 | { | |
7557 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
7558 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7559 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7560 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
7561 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
7562 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
7563 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
7564 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
7565 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
7566 | "pswm", "pswa", | |
7567 | NULL, NULL, | |
7568 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
7569 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
7570 | }; | |
7571 | ||
99f6fdd9 | 7572 | static void |
d6bb17b0 AA |
7573 | init_dwarf_regnames_s390 (void) |
7574 | { | |
7575 | dwarf_regnames = dwarf_regnames_s390; | |
7576 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
1296bc99 | 7577 | dwarf_regnames_lookup_func = regname_internal_by_table_only; |
d6bb17b0 AA |
7578 | } |
7579 | ||
5bb0830d AB |
7580 | static const char *const dwarf_regnames_riscv[] = |
7581 | { | |
7582 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
7583 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
7584 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
7585 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
7586 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
7587 | "fs0", "fs1", /* 40 - 41 */ | |
7588 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
7589 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
7590 | "fs10", "fs11", /* 58 - 59 */ | |
7591 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
7592 | }; | |
7593 | ||
4762fe62 AB |
7594 | /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles |
7595 | the large number of CSRs. */ | |
7596 | ||
7597 | static const char * | |
7598 | regname_internal_riscv (unsigned int regno) | |
7599 | { | |
7600 | const char *name = NULL; | |
7601 | ||
7602 | /* Lookup in the table first, this covers GPR and FPR. */ | |
7603 | if (regno < ARRAY_SIZE (dwarf_regnames_riscv)) | |
7604 | name = dwarf_regnames_riscv [regno]; | |
7605 | else if (regno >= 4096 && regno <= 8191) | |
7606 | { | |
7607 | /* This might be a CSR, these live in a sparse number space from 4096 | |
7608 | to 8191 These numbers are defined in the RISC-V ELF ABI | |
7609 | document. */ | |
7610 | switch (regno) | |
7611 | { | |
7612 | #define DECLARE_CSR(NAME,VALUE) case VALUE + 4096: name = #NAME; break; | |
7613 | #include "opcode/riscv-opc.h" | |
7614 | #undef DECLARE_CSR | |
7615 | ||
7616 | default: | |
7617 | { | |
7618 | static char csr_name[10]; | |
7619 | snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096)); | |
7620 | name = csr_name; | |
7621 | } | |
7622 | break; | |
7623 | } | |
7624 | } | |
7625 | ||
7626 | return name; | |
7627 | } | |
7628 | ||
99f6fdd9 | 7629 | static void |
5bb0830d AB |
7630 | init_dwarf_regnames_riscv (void) |
7631 | { | |
4762fe62 AB |
7632 | dwarf_regnames = NULL; |
7633 | dwarf_regnames_count = 8192; | |
7634 | dwarf_regnames_lookup_func = regname_internal_riscv; | |
5bb0830d AB |
7635 | } |
7636 | ||
2dc4cec1 | 7637 | void |
955ff7fc | 7638 | init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine) |
2dc4cec1 | 7639 | { |
1296bc99 AB |
7640 | dwarf_regnames_lookup_func = NULL; |
7641 | ||
2dc4cec1 L |
7642 | switch (e_machine) |
7643 | { | |
7644 | case EM_386: | |
b129eb0e | 7645 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
7646 | break; |
7647 | ||
3d875af5 L |
7648 | case EM_IAMCU: |
7649 | init_dwarf_regnames_iamcu (); | |
7650 | break; | |
7651 | ||
2dc4cec1 | 7652 | case EM_X86_64: |
7f502d6c | 7653 | case EM_L1OM: |
7a9068fe | 7654 | case EM_K1OM: |
b129eb0e | 7655 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
7656 | break; |
7657 | ||
4ee22035 RH |
7658 | case EM_AARCH64: |
7659 | init_dwarf_regnames_aarch64 (); | |
7660 | break; | |
7661 | ||
d6bb17b0 AA |
7662 | case EM_S390: |
7663 | init_dwarf_regnames_s390 (); | |
7664 | break; | |
7665 | ||
5bb0830d AB |
7666 | case EM_RISCV: |
7667 | init_dwarf_regnames_riscv (); | |
7668 | break; | |
7669 | ||
2dc4cec1 L |
7670 | default: |
7671 | break; | |
7672 | } | |
7673 | } | |
7674 | ||
229a22cf AB |
7675 | /* Initialize the DWARF register name lookup state based on the |
7676 | architecture and specific machine type of a BFD. */ | |
7677 | ||
7678 | void | |
7679 | init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch, | |
7680 | unsigned long mach) | |
7681 | { | |
1296bc99 AB |
7682 | dwarf_regnames_lookup_func = NULL; |
7683 | ||
229a22cf AB |
7684 | switch (arch) |
7685 | { | |
7686 | case bfd_arch_i386: | |
7687 | switch (mach) | |
7688 | { | |
7689 | case bfd_mach_x86_64: | |
7690 | case bfd_mach_x86_64_intel_syntax: | |
7691 | case bfd_mach_x86_64_nacl: | |
7692 | case bfd_mach_x64_32: | |
7693 | case bfd_mach_x64_32_intel_syntax: | |
7694 | case bfd_mach_x64_32_nacl: | |
7695 | init_dwarf_regnames_x86_64 (); | |
7696 | break; | |
7697 | ||
7698 | default: | |
7699 | init_dwarf_regnames_i386 (); | |
7700 | break; | |
7701 | } | |
7702 | break; | |
7703 | ||
7704 | case bfd_arch_iamcu: | |
7705 | init_dwarf_regnames_iamcu (); | |
7706 | break; | |
7707 | ||
7708 | case bfd_arch_aarch64: | |
7709 | init_dwarf_regnames_aarch64(); | |
7710 | break; | |
7711 | ||
7712 | case bfd_arch_s390: | |
7713 | init_dwarf_regnames_s390 (); | |
7714 | break; | |
7715 | ||
7716 | case bfd_arch_riscv: | |
7717 | init_dwarf_regnames_riscv (); | |
7718 | break; | |
7719 | ||
7720 | default: | |
7721 | break; | |
7722 | } | |
7723 | } | |
7724 | ||
2dc4cec1 | 7725 | static const char * |
1296bc99 | 7726 | regname_internal_by_table_only (unsigned int regno) |
2dc4cec1 | 7727 | { |
1296bc99 | 7728 | if (dwarf_regnames != NULL |
2dc4cec1 L |
7729 | && regno < dwarf_regnames_count |
7730 | && dwarf_regnames [regno] != NULL) | |
1296bc99 AB |
7731 | return dwarf_regnames [regno]; |
7732 | ||
7733 | return NULL; | |
7734 | } | |
7735 | ||
7736 | static const char * | |
7737 | regname (unsigned int regno, int name_only_p) | |
7738 | { | |
7739 | static char reg[64]; | |
7740 | ||
7741 | const char *name = NULL; | |
7742 | ||
7743 | if (dwarf_regnames_lookup_func != NULL) | |
7744 | name = dwarf_regnames_lookup_func (regno); | |
7745 | ||
7746 | if (name != NULL) | |
2dc4cec1 | 7747 | { |
1296bc99 AB |
7748 | if (name_only_p) |
7749 | return name; | |
7750 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, name); | |
2dc4cec1 L |
7751 | } |
7752 | else | |
7753 | snprintf (reg, sizeof (reg), "r%d", regno); | |
7754 | return reg; | |
7755 | } | |
7756 | ||
19e6b90e | 7757 | static void |
a1165289 | 7758 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 7759 | { |
a1165289 | 7760 | unsigned int r; |
19e6b90e L |
7761 | char tmp[100]; |
7762 | ||
d8024a91 | 7763 | if (*max_regs != fc->ncols) |
19e6b90e L |
7764 | *max_regs = fc->ncols; |
7765 | ||
7766 | if (*need_col_headers) | |
7767 | { | |
91d6fa6a | 7768 | static const char *sloc = " LOC"; |
2dc4cec1 | 7769 | |
19e6b90e L |
7770 | *need_col_headers = 0; |
7771 | ||
91d6fa6a | 7772 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
7773 | |
7774 | for (r = 0; r < *max_regs; r++) | |
7775 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7776 | { | |
7777 | if (r == fc->ra) | |
50751e18 | 7778 | printf ("ra "); |
19e6b90e | 7779 | else |
2dc4cec1 | 7780 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
7781 | } |
7782 | ||
7783 | printf ("\n"); | |
7784 | } | |
7785 | ||
bf5117e3 | 7786 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
7787 | if (fc->cfa_exp) |
7788 | strcpy (tmp, "exp"); | |
7789 | else | |
c8071705 | 7790 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
7791 | printf ("%-8s ", tmp); |
7792 | ||
7793 | for (r = 0; r < fc->ncols; r++) | |
7794 | { | |
7795 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7796 | { | |
7797 | switch (fc->col_type[r]) | |
7798 | { | |
7799 | case DW_CFA_undefined: | |
7800 | strcpy (tmp, "u"); | |
7801 | break; | |
7802 | case DW_CFA_same_value: | |
7803 | strcpy (tmp, "s"); | |
7804 | break; | |
7805 | case DW_CFA_offset: | |
7806 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
7807 | break; | |
12eae2d3 JJ |
7808 | case DW_CFA_val_offset: |
7809 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
7810 | break; | |
19e6b90e | 7811 | case DW_CFA_register: |
2dc4cec1 | 7812 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
7813 | break; |
7814 | case DW_CFA_expression: | |
7815 | strcpy (tmp, "exp"); | |
7816 | break; | |
12eae2d3 JJ |
7817 | case DW_CFA_val_expression: |
7818 | strcpy (tmp, "vexp"); | |
7819 | break; | |
19e6b90e L |
7820 | default: |
7821 | strcpy (tmp, "n/a"); | |
7822 | break; | |
7823 | } | |
2dc4cec1 | 7824 | printf ("%-5s ", tmp); |
19e6b90e L |
7825 | } |
7826 | } | |
7827 | printf ("\n"); | |
7828 | } | |
7829 | ||
49727e46 | 7830 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 7831 | |
49727e46 AM |
7832 | static unsigned char * |
7833 | read_cie (unsigned char *start, unsigned char *end, | |
7834 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 7835 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
7836 | { |
7837 | int version; | |
7838 | Frame_Chunk *fc; | |
7839 | unsigned int length_return; | |
7840 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 7841 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 7842 | |
041830e0 | 7843 | * p_cie = NULL; |
f41e4712 NC |
7844 | /* PR 17512: file: 001-228113-0.004. */ |
7845 | if (start >= end) | |
7846 | return end; | |
7847 | ||
49727e46 AM |
7848 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
7849 | memset (fc, 0, sizeof (Frame_Chunk)); | |
7850 | ||
7851 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
7852 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
7853 | ||
7854 | version = *start++; | |
7855 | ||
7856 | fc->augmentation = (char *) start; | |
f41e4712 NC |
7857 | /* PR 17512: file: 001-228113-0.004. |
7858 | Skip past augmentation name, but avoid running off the end of the data. */ | |
7859 | while (start < end) | |
7860 | if (* start ++ == '\0') | |
7861 | break; | |
7862 | if (start == end) | |
7863 | { | |
7864 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 7865 | goto fail; |
f41e4712 | 7866 | } |
49727e46 AM |
7867 | |
7868 | if (strcmp (fc->augmentation, "eh") == 0) | |
7869 | start += eh_addr_size; | |
7870 | ||
7871 | if (version >= 4) | |
7872 | { | |
7873 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
7874 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
7875 | { | |
7876 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 7877 | goto fail; |
77ef8654 NC |
7878 | } |
7879 | ||
49727e46 | 7880 | GET (fc->segment_size, 1); |
77ef8654 NC |
7881 | /* PR 17512: file: e99d2804. */ |
7882 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
7883 | { | |
7884 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 7885 | goto fail; |
77ef8654 NC |
7886 | } |
7887 | ||
49727e46 AM |
7888 | eh_addr_size = fc->ptr_size; |
7889 | } | |
7890 | else | |
7891 | { | |
7892 | fc->ptr_size = eh_addr_size; | |
7893 | fc->segment_size = 0; | |
7894 | } | |
442a6ce8 | 7895 | |
7f2c8a1d NC |
7896 | READ_ULEB (fc->code_factor); |
7897 | READ_SLEB (fc->data_factor); | |
442a6ce8 | 7898 | |
49727e46 AM |
7899 | if (version == 1) |
7900 | { | |
7901 | GET (fc->ra, 1); | |
7902 | } | |
7903 | else | |
7904 | { | |
7f2c8a1d | 7905 | READ_ULEB (fc->ra); |
49727e46 AM |
7906 | } |
7907 | ||
7908 | if (fc->augmentation[0] == 'z') | |
7909 | { | |
7f2c8a1d | 7910 | READ_ULEB (augmentation_data_len); |
49727e46 | 7911 | augmentation_data = start; |
a1165289 | 7912 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 7913 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 7914 | { |
bf59c5d5 NC |
7915 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
7916 | dwarf_vmatoa ("x", augmentation_data_len), | |
7917 | (unsigned long) (end - start)); | |
442a6ce8 | 7918 | goto fail; |
a1165289 | 7919 | } |
9c0f3d3f | 7920 | start += augmentation_data_len; |
49727e46 AM |
7921 | } |
7922 | ||
7923 | if (augmentation_data_len) | |
7924 | { | |
058037d3 NC |
7925 | unsigned char *p; |
7926 | unsigned char *q; | |
7927 | unsigned char *qend; | |
b4eb7656 | 7928 | |
49727e46 AM |
7929 | p = (unsigned char *) fc->augmentation + 1; |
7930 | q = augmentation_data; | |
058037d3 NC |
7931 | qend = q + augmentation_data_len; |
7932 | ||
9c0f3d3f | 7933 | while (p < end && q < qend) |
49727e46 AM |
7934 | { |
7935 | if (*p == 'L') | |
7936 | q++; | |
7937 | else if (*p == 'P') | |
7938 | q += 1 + size_of_encoded_value (*q); | |
7939 | else if (*p == 'R') | |
7940 | fc->fde_encoding = *q++; | |
7941 | else if (*p == 'S') | |
7942 | ; | |
09038062 ST |
7943 | else if (*p == 'B') |
7944 | ; | |
49727e46 AM |
7945 | else |
7946 | break; | |
7947 | p++; | |
7948 | } | |
c361b9ac NC |
7949 | /* Note - it is OK if this loop terminates with q < qend. |
7950 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
7951 | } |
7952 | ||
7953 | *p_cie = fc; | |
7954 | if (p_version) | |
7955 | *p_version = version; | |
7956 | if (p_aug_len) | |
7957 | { | |
7958 | *p_aug_len = augmentation_data_len; | |
7959 | *p_aug = augmentation_data; | |
7960 | } | |
7961 | return start; | |
442a6ce8 NC |
7962 | |
7963 | fail: | |
7964 | free (fc->col_offset); | |
7965 | free (fc->col_type); | |
7966 | free (fc); | |
7967 | return end; | |
49727e46 AM |
7968 | } |
7969 | ||
d85bf2ba NC |
7970 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
7971 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
7972 | PRINTED contains the number of characters already written to the current | |
7973 | output line. */ | |
bf59c5d5 NC |
7974 | |
7975 | static void | |
d85bf2ba NC |
7976 | display_data (bfd_size_type printed, |
7977 | const unsigned char * data, | |
7978 | const bfd_size_type len) | |
bf59c5d5 | 7979 | { |
d85bf2ba NC |
7980 | if (do_wide || len < ((80 - printed) / 3)) |
7981 | for (printed = 0; printed < len; ++printed) | |
7982 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
7983 | else |
7984 | { | |
d85bf2ba | 7985 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 7986 | { |
d85bf2ba | 7987 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 7988 | putchar ('\n'); |
d85bf2ba | 7989 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
7990 | } |
7991 | } | |
d85bf2ba NC |
7992 | } |
7993 | ||
7994 | /* Prints out the contents on the augmentation data array. | |
7995 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
7996 | ||
7997 | static void | |
7998 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
7999 | { | |
8000 | bfd_size_type i; | |
8001 | ||
8002 | i = printf (_(" Augmentation data: ")); | |
8003 | display_data (i, data, len); | |
bf59c5d5 NC |
8004 | } |
8005 | ||
19e6b90e L |
8006 | static int |
8007 | display_debug_frames (struct dwarf_section *section, | |
8008 | void *file ATTRIBUTE_UNUSED) | |
8009 | { | |
8010 | unsigned char *start = section->start; | |
8011 | unsigned char *end = start + section->size; | |
8012 | unsigned char *section_start = start; | |
3391569f NC |
8013 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
8014 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 8015 | Frame_Chunk *rs; |
3391569f | 8016 | bfd_boolean is_eh = strcmp (section->name, ".eh_frame") == 0; |
19e6b90e | 8017 | unsigned int length_return; |
a1165289 | 8018 | unsigned int max_regs = 0; |
665ce1f6 | 8019 | const char *bad_reg = _("bad register: "); |
77ef8654 | 8020 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 8021 | |
dda8d76d | 8022 | introduce (section, FALSE); |
19e6b90e L |
8023 | |
8024 | while (start < end) | |
8025 | { | |
8026 | unsigned char *saved_start; | |
8027 | unsigned char *block_end; | |
bf5117e3 NC |
8028 | dwarf_vma length; |
8029 | dwarf_vma cie_id; | |
19e6b90e L |
8030 | Frame_Chunk *fc; |
8031 | Frame_Chunk *cie; | |
8032 | int need_col_headers = 1; | |
8033 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 8034 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
8035 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
8036 | unsigned int offset_size; | |
8037 | unsigned int initial_length_size; | |
5b6312fd | 8038 | bfd_boolean all_nops; |
19e6b90e L |
8039 | |
8040 | saved_start = start; | |
19e6b90e | 8041 | |
0c588247 | 8042 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 8043 | |
19e6b90e L |
8044 | if (length == 0) |
8045 | { | |
8046 | printf ("\n%08lx ZERO terminator\n\n", | |
8047 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
8048 | /* Skip any zero terminators that directly follow. |
8049 | A corrupt section size could have loaded a whole | |
8050 | slew of zero filled memory bytes. eg | |
8051 | PR 17512: file: 070-19381-0.004. */ | |
8052 | while (start < end && * start == 0) | |
8053 | ++ start; | |
b758e50f | 8054 | continue; |
19e6b90e L |
8055 | } |
8056 | ||
8057 | if (length == 0xffffffff) | |
8058 | { | |
0c588247 | 8059 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
8060 | offset_size = 8; |
8061 | initial_length_size = 12; | |
8062 | } | |
8063 | else | |
8064 | { | |
8065 | offset_size = 4; | |
8066 | initial_length_size = 4; | |
8067 | } | |
8068 | ||
8069 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 8070 | if (block_end > end || block_end < start) |
53b8873b | 8071 | { |
bf5117e3 NC |
8072 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
8073 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
8074 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
8075 | block_end = end; |
8076 | } | |
0c588247 NC |
8077 | |
8078 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 8079 | |
846a11e4 NC |
8080 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
8081 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
8082 | { |
8083 | int version; | |
a1165289 | 8084 | unsigned int mreg; |
19e6b90e | 8085 | |
49727e46 AM |
8086 | start = read_cie (start, end, &cie, &version, |
8087 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
8088 | /* PR 17512: file: 027-135133-0.005. */ |
8089 | if (cie == NULL) | |
8090 | break; | |
a1165289 | 8091 | |
49727e46 | 8092 | fc = cie; |
19e6b90e L |
8093 | fc->next = chunks; |
8094 | chunks = fc; | |
8095 | fc->chunk_start = saved_start; | |
a1165289 | 8096 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8097 | if (mreg < fc->ra) |
8098 | mreg = fc->ra; | |
06614111 NC |
8099 | if (frame_need_space (fc, mreg) < 0) |
8100 | break; | |
49727e46 AM |
8101 | if (fc->fde_encoding) |
8102 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 8103 | |
bf5117e3 NC |
8104 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
8105 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 8106 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 8107 | |
19e6b90e | 8108 | if (do_debug_frames_interp) |
bf5117e3 NC |
8109 | { |
8110 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
8111 | fc->code_factor, fc->data_factor, fc->ra); | |
8112 | } | |
19e6b90e L |
8113 | else |
8114 | { | |
bf5117e3 | 8115 | printf ("CIE\n"); |
19e6b90e L |
8116 | printf (" Version: %d\n", version); |
8117 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
8118 | if (version >= 4) |
8119 | { | |
8120 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
8121 | printf (" Segment Size: %u\n", fc->segment_size); | |
8122 | } | |
19e6b90e L |
8123 | printf (" Code alignment factor: %u\n", fc->code_factor); |
8124 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
8125 | printf (" Return address column: %d\n", fc->ra); | |
8126 | ||
8127 | if (augmentation_data_len) | |
bf59c5d5 | 8128 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 8129 | |
19e6b90e L |
8130 | putchar ('\n'); |
8131 | } | |
19e6b90e L |
8132 | } |
8133 | else | |
8134 | { | |
8135 | unsigned char *look_for; | |
8136 | static Frame_Chunk fde_fc; | |
604282a7 | 8137 | unsigned long segment_selector; |
19e6b90e | 8138 | |
49727e46 AM |
8139 | if (is_eh) |
8140 | { | |
8141 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
8142 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
8143 | } | |
8144 | else | |
8145 | look_for = section_start + cie_id; | |
19e6b90e | 8146 | |
49727e46 AM |
8147 | if (look_for <= saved_start) |
8148 | { | |
8149 | for (cie = chunks; cie ; cie = cie->next) | |
8150 | if (cie->chunk_start == look_for) | |
8151 | break; | |
8152 | } | |
8153 | else | |
8154 | { | |
8155 | for (cie = forward_refs; cie ; cie = cie->next) | |
8156 | if (cie->chunk_start == look_for) | |
8157 | break; | |
8158 | if (!cie) | |
8159 | { | |
8160 | unsigned int off_size; | |
8161 | unsigned char *cie_scan; | |
19e6b90e | 8162 | |
49727e46 AM |
8163 | cie_scan = look_for; |
8164 | off_size = 4; | |
8165 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
8166 | if (length == 0xffffffff) | |
8167 | { | |
8168 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
8169 | off_size = 8; | |
8170 | } | |
8171 | if (length != 0) | |
8172 | { | |
8173 | dwarf_vma c_id; | |
8174 | ||
8175 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
8176 | if (is_eh | |
8177 | ? c_id == 0 | |
8178 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
8179 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
8180 | { | |
8181 | int version; | |
a1165289 | 8182 | unsigned int mreg; |
49727e46 AM |
8183 | |
8184 | read_cie (cie_scan, end, &cie, &version, | |
8185 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
8186 | /* PR 17512: file: 3450-2098-0.004. */ |
8187 | if (cie == NULL) | |
8188 | { | |
8189 | warn (_("Failed to read CIE information\n")); | |
8190 | break; | |
8191 | } | |
49727e46 AM |
8192 | cie->next = forward_refs; |
8193 | forward_refs = cie; | |
8194 | cie->chunk_start = look_for; | |
a1165289 | 8195 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8196 | if (mreg < cie->ra) |
8197 | mreg = cie->ra; | |
06614111 NC |
8198 | if (frame_need_space (cie, mreg) < 0) |
8199 | { | |
8200 | warn (_("Invalid max register\n")); | |
8201 | break; | |
8202 | } | |
49727e46 AM |
8203 | if (cie->fde_encoding) |
8204 | encoded_ptr_size | |
8205 | = size_of_encoded_value (cie->fde_encoding); | |
8206 | } | |
8207 | } | |
8208 | } | |
8209 | } | |
8210 | ||
8211 | fc = &fde_fc; | |
8212 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
8213 | |
8214 | if (!cie) | |
8215 | { | |
bf5117e3 NC |
8216 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
8217 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
8218 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 8219 | fc->ncols = 0; |
3f5e193b NC |
8220 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
8221 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
8222 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
8223 | { | |
8224 | warn (_("Invalid max register\n")); | |
8225 | break; | |
8226 | } | |
19e6b90e L |
8227 | cie = fc; |
8228 | fc->augmentation = ""; | |
8229 | fc->fde_encoding = 0; | |
604282a7 JJ |
8230 | fc->ptr_size = eh_addr_size; |
8231 | fc->segment_size = 0; | |
19e6b90e L |
8232 | } |
8233 | else | |
8234 | { | |
8235 | fc->ncols = cie->ncols; | |
3f5e193b NC |
8236 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
8237 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
8238 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
8239 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
8240 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
8241 | fc->ptr_size = cie->ptr_size; |
8242 | eh_addr_size = cie->ptr_size; | |
8243 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
8244 | fc->code_factor = cie->code_factor; |
8245 | fc->data_factor = cie->data_factor; | |
8246 | fc->cfa_reg = cie->cfa_reg; | |
8247 | fc->cfa_offset = cie->cfa_offset; | |
8248 | fc->ra = cie->ra; | |
06614111 NC |
8249 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
8250 | { | |
8251 | warn (_("Invalid max register\n")); | |
8252 | break; | |
8253 | } | |
19e6b90e L |
8254 | fc->fde_encoding = cie->fde_encoding; |
8255 | } | |
8256 | ||
8257 | if (fc->fde_encoding) | |
8258 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
8259 | ||
604282a7 JJ |
8260 | segment_selector = 0; |
8261 | if (fc->segment_size) | |
c8071705 NC |
8262 | { |
8263 | if (fc->segment_size > sizeof (segment_selector)) | |
8264 | { | |
8265 | /* PR 17512: file: 9e196b3e. */ | |
8266 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
8267 | fc->segment_size = 4; | |
8268 | } | |
8269 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
8270 | } | |
041830e0 NC |
8271 | |
8272 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 8273 | |
0c588247 NC |
8274 | /* FIXME: It appears that sometimes the final pc_range value is |
8275 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
8276 | run of the "objcopy on compressed debug sections" test for an | |
8277 | example of this. */ | |
8278 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 8279 | |
19e6b90e L |
8280 | if (cie->augmentation[0] == 'z') |
8281 | { | |
7f2c8a1d | 8282 | READ_ULEB (augmentation_data_len); |
19e6b90e | 8283 | augmentation_data = start; |
bf59c5d5 | 8284 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
d292364e | 8285 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
0a9d414a | 8286 | { |
d292364e AM |
8287 | warn (_("Augmentation data too long: 0x%s, " |
8288 | "expected at most %#lx\n"), | |
8289 | dwarf_vmatoa ("x", augmentation_data_len), | |
8290 | (unsigned long) (end - start)); | |
0a9d414a NC |
8291 | start = end; |
8292 | augmentation_data = NULL; | |
8293 | augmentation_data_len = 0; | |
8294 | } | |
d292364e | 8295 | start += augmentation_data_len; |
19e6b90e L |
8296 | } |
8297 | ||
bf5117e3 NC |
8298 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
8299 | (unsigned long)(saved_start - section_start), | |
8300 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 8301 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 8302 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 8303 | |
604282a7 JJ |
8304 | if (fc->segment_size) |
8305 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
8306 | |
8307 | printf ("%s..%s\n", | |
8308 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
8309 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
8310 | ||
19e6b90e L |
8311 | if (! do_debug_frames_interp && augmentation_data_len) |
8312 | { | |
bf59c5d5 | 8313 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
8314 | putchar ('\n'); |
8315 | } | |
8316 | } | |
8317 | ||
8318 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
8319 | we're about to interpret instructions for the chunk. */ | |
8320 | /* ??? At present we need to do this always, since this sizes the | |
8321 | fc->col_type and fc->col_offset arrays, which we write into always. | |
8322 | We should probably split the interpreted and non-interpreted bits | |
8323 | into two different routines, since there's so much that doesn't | |
8324 | really overlap between them. */ | |
8325 | if (1 || do_debug_frames_interp) | |
8326 | { | |
8327 | /* Start by making a pass over the chunk, allocating storage | |
8328 | and taking note of what registers are used. */ | |
8329 | unsigned char *tmp = start; | |
8330 | ||
8331 | while (start < block_end) | |
8332 | { | |
041830e0 NC |
8333 | unsigned int reg, op, opa; |
8334 | unsigned long temp; | |
5929c344 | 8335 | unsigned char * new_start; |
19e6b90e L |
8336 | |
8337 | op = *start++; | |
8338 | opa = op & 0x3f; | |
8339 | if (op & 0xc0) | |
8340 | op &= 0xc0; | |
8341 | ||
8342 | /* Warning: if you add any more cases to this switch, be | |
8343 | sure to add them to the corresponding switch below. */ | |
8344 | switch (op) | |
8345 | { | |
8346 | case DW_CFA_advance_loc: | |
8347 | break; | |
8348 | case DW_CFA_offset: | |
7f2c8a1d | 8349 | SKIP_ULEB (); |
665ce1f6 L |
8350 | if (frame_need_space (fc, opa) >= 0) |
8351 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8352 | break; |
8353 | case DW_CFA_restore: | |
665ce1f6 L |
8354 | if (frame_need_space (fc, opa) >= 0) |
8355 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8356 | break; |
8357 | case DW_CFA_set_loc: | |
8358 | start += encoded_ptr_size; | |
8359 | break; | |
8360 | case DW_CFA_advance_loc1: | |
8361 | start += 1; | |
8362 | break; | |
8363 | case DW_CFA_advance_loc2: | |
8364 | start += 2; | |
8365 | break; | |
8366 | case DW_CFA_advance_loc4: | |
8367 | start += 4; | |
8368 | break; | |
8369 | case DW_CFA_offset_extended: | |
12eae2d3 | 8370 | case DW_CFA_val_offset: |
7f2c8a1d NC |
8371 | READ_ULEB (reg); |
8372 | SKIP_ULEB (); | |
665ce1f6 L |
8373 | if (frame_need_space (fc, reg) >= 0) |
8374 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8375 | break; |
8376 | case DW_CFA_restore_extended: | |
7f2c8a1d | 8377 | READ_ULEB (reg); |
665ce1f6 L |
8378 | if (frame_need_space (fc, reg) >= 0) |
8379 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8380 | break; |
8381 | case DW_CFA_undefined: | |
7f2c8a1d | 8382 | READ_ULEB (reg); |
665ce1f6 L |
8383 | if (frame_need_space (fc, reg) >= 0) |
8384 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8385 | break; |
8386 | case DW_CFA_same_value: | |
7f2c8a1d | 8387 | READ_ULEB (reg); |
665ce1f6 L |
8388 | if (frame_need_space (fc, reg) >= 0) |
8389 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8390 | break; |
8391 | case DW_CFA_register: | |
7f2c8a1d NC |
8392 | READ_ULEB (reg); |
8393 | SKIP_ULEB (); | |
665ce1f6 L |
8394 | if (frame_need_space (fc, reg) >= 0) |
8395 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8396 | break; |
8397 | case DW_CFA_def_cfa: | |
7f2c8a1d NC |
8398 | SKIP_ULEB (); |
8399 | SKIP_ULEB (); | |
19e6b90e L |
8400 | break; |
8401 | case DW_CFA_def_cfa_register: | |
7f2c8a1d | 8402 | SKIP_ULEB (); |
19e6b90e L |
8403 | break; |
8404 | case DW_CFA_def_cfa_offset: | |
7f2c8a1d | 8405 | SKIP_ULEB (); |
19e6b90e L |
8406 | break; |
8407 | case DW_CFA_def_cfa_expression: | |
7f2c8a1d | 8408 | READ_ULEB (temp); |
5929c344 NC |
8409 | new_start = start + temp; |
8410 | if (new_start < start) | |
041830e0 NC |
8411 | { |
8412 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
8413 | start = block_end; | |
8414 | } | |
8415 | else | |
5929c344 | 8416 | start = new_start; |
19e6b90e L |
8417 | break; |
8418 | case DW_CFA_expression: | |
12eae2d3 | 8419 | case DW_CFA_val_expression: |
7f2c8a1d NC |
8420 | READ_ULEB (reg); |
8421 | READ_ULEB (temp); | |
5929c344 NC |
8422 | new_start = start + temp; |
8423 | if (new_start < start) | |
041830e0 | 8424 | { |
b4eb7656 | 8425 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
8426 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
8427 | start = block_end; | |
8428 | } | |
8429 | else | |
5929c344 | 8430 | start = new_start; |
665ce1f6 L |
8431 | if (frame_need_space (fc, reg) >= 0) |
8432 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8433 | break; |
8434 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 8435 | case DW_CFA_val_offset_sf: |
7f2c8a1d NC |
8436 | READ_ULEB (reg); |
8437 | SKIP_SLEB (); | |
665ce1f6 L |
8438 | if (frame_need_space (fc, reg) >= 0) |
8439 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8440 | break; |
8441 | case DW_CFA_def_cfa_sf: | |
7f2c8a1d NC |
8442 | SKIP_ULEB (); |
8443 | SKIP_SLEB (); | |
19e6b90e L |
8444 | break; |
8445 | case DW_CFA_def_cfa_offset_sf: | |
7f2c8a1d | 8446 | SKIP_SLEB (); |
19e6b90e L |
8447 | break; |
8448 | case DW_CFA_MIPS_advance_loc8: | |
8449 | start += 8; | |
8450 | break; | |
8451 | case DW_CFA_GNU_args_size: | |
7f2c8a1d | 8452 | SKIP_ULEB (); |
19e6b90e L |
8453 | break; |
8454 | case DW_CFA_GNU_negative_offset_extended: | |
7f2c8a1d NC |
8455 | READ_ULEB (reg); |
8456 | SKIP_ULEB (); | |
665ce1f6 L |
8457 | if (frame_need_space (fc, reg) >= 0) |
8458 | fc->col_type[reg] = DW_CFA_undefined; | |
8459 | break; | |
19e6b90e L |
8460 | default: |
8461 | break; | |
8462 | } | |
8463 | } | |
8464 | start = tmp; | |
8465 | } | |
8466 | ||
5b6312fd NC |
8467 | all_nops = TRUE; |
8468 | ||
19e6b90e L |
8469 | /* Now we know what registers are used, make a second pass over |
8470 | the chunk, this time actually printing out the info. */ | |
8471 | ||
8472 | while (start < block_end) | |
8473 | { | |
362beea4 | 8474 | unsigned char * tmp; |
19e6b90e | 8475 | unsigned op, opa; |
7f2c8a1d NC |
8476 | unsigned long ul, roffs; |
8477 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
8478 | are various functions, notably frame_space_needed() that assume that | |
8479 | reg is an unsigned int. */ | |
8480 | unsigned int reg; | |
8481 | dwarf_signed_vma l; | |
bf5117e3 | 8482 | dwarf_vma ofs; |
19e6b90e | 8483 | dwarf_vma vma; |
665ce1f6 | 8484 | const char *reg_prefix = ""; |
19e6b90e L |
8485 | |
8486 | op = *start++; | |
8487 | opa = op & 0x3f; | |
8488 | if (op & 0xc0) | |
8489 | op &= 0xc0; | |
8490 | ||
5b6312fd NC |
8491 | /* Make a note if something other than DW_CFA_nop happens. */ |
8492 | if (op != DW_CFA_nop) | |
8493 | all_nops = FALSE; | |
8494 | ||
19e6b90e L |
8495 | /* Warning: if you add any more cases to this switch, be |
8496 | sure to add them to the corresponding switch above. */ | |
8497 | switch (op) | |
8498 | { | |
8499 | case DW_CFA_advance_loc: | |
8500 | if (do_debug_frames_interp) | |
8501 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8502 | else | |
bf5117e3 | 8503 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 8504 | opa * fc->code_factor, |
b4eb7656 | 8505 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
8506 | fc->pc_begin + opa * fc->code_factor, |
8507 | fc->ptr_size)); | |
19e6b90e L |
8508 | fc->pc_begin += opa * fc->code_factor; |
8509 | break; | |
8510 | ||
8511 | case DW_CFA_offset: | |
7f2c8a1d | 8512 | READ_ULEB (roffs); |
665ce1f6 L |
8513 | if (opa >= (unsigned int) fc->ncols) |
8514 | reg_prefix = bad_reg; | |
8515 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8516 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
8517 | reg_prefix, regname (opa, 0), | |
8518 | roffs * fc->data_factor); | |
8519 | if (*reg_prefix == '\0') | |
8520 | { | |
8521 | fc->col_type[opa] = DW_CFA_offset; | |
8522 | fc->col_offset[opa] = roffs * fc->data_factor; | |
8523 | } | |
19e6b90e L |
8524 | break; |
8525 | ||
8526 | case DW_CFA_restore: | |
50751e18 | 8527 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
8528 | reg_prefix = bad_reg; |
8529 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8530 | printf (" DW_CFA_restore: %s%s\n", | |
8531 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
8532 | if (*reg_prefix != '\0') |
8533 | break; | |
8534 | ||
8535 | if (opa >= (unsigned int) cie->ncols | |
8536 | || (do_debug_frames_interp | |
8537 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
8538 | { | |
8539 | fc->col_type[opa] = DW_CFA_undefined; | |
8540 | fc->col_offset[opa] = 0; | |
8541 | } | |
8542 | else | |
665ce1f6 L |
8543 | { |
8544 | fc->col_type[opa] = cie->col_type[opa]; | |
8545 | fc->col_offset[opa] = cie->col_offset[opa]; | |
8546 | } | |
19e6b90e L |
8547 | break; |
8548 | ||
8549 | case DW_CFA_set_loc: | |
6937bb54 | 8550 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
8551 | if (do_debug_frames_interp) |
8552 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8553 | else | |
bf5117e3 NC |
8554 | printf (" DW_CFA_set_loc: %s\n", |
8555 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
8556 | fc->pc_begin = vma; |
8557 | break; | |
8558 | ||
8559 | case DW_CFA_advance_loc1: | |
0c588247 | 8560 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
8561 | if (do_debug_frames_interp) |
8562 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8563 | else | |
bf5117e3 NC |
8564 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
8565 | (unsigned long) (ofs * fc->code_factor), | |
8566 | dwarf_vmatoa_1 (NULL, | |
8567 | fc->pc_begin + ofs * fc->code_factor, | |
8568 | fc->ptr_size)); | |
19e6b90e L |
8569 | fc->pc_begin += ofs * fc->code_factor; |
8570 | break; | |
8571 | ||
8572 | case DW_CFA_advance_loc2: | |
6937bb54 | 8573 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
8574 | if (do_debug_frames_interp) |
8575 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8576 | else | |
bf5117e3 NC |
8577 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
8578 | (unsigned long) (ofs * fc->code_factor), | |
8579 | dwarf_vmatoa_1 (NULL, | |
8580 | fc->pc_begin + ofs * fc->code_factor, | |
8581 | fc->ptr_size)); | |
19e6b90e L |
8582 | fc->pc_begin += ofs * fc->code_factor; |
8583 | break; | |
8584 | ||
8585 | case DW_CFA_advance_loc4: | |
6937bb54 | 8586 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
8587 | if (do_debug_frames_interp) |
8588 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8589 | else | |
bf5117e3 NC |
8590 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
8591 | (unsigned long) (ofs * fc->code_factor), | |
8592 | dwarf_vmatoa_1 (NULL, | |
8593 | fc->pc_begin + ofs * fc->code_factor, | |
8594 | fc->ptr_size)); | |
19e6b90e L |
8595 | fc->pc_begin += ofs * fc->code_factor; |
8596 | break; | |
8597 | ||
8598 | case DW_CFA_offset_extended: | |
7f2c8a1d NC |
8599 | READ_ULEB (reg); |
8600 | READ_ULEB (roffs); | |
665ce1f6 L |
8601 | if (reg >= (unsigned int) fc->ncols) |
8602 | reg_prefix = bad_reg; | |
8603 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8604 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
8605 | reg_prefix, regname (reg, 0), | |
8606 | roffs * fc->data_factor); | |
8607 | if (*reg_prefix == '\0') | |
8608 | { | |
8609 | fc->col_type[reg] = DW_CFA_offset; | |
8610 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8611 | } | |
19e6b90e L |
8612 | break; |
8613 | ||
12eae2d3 | 8614 | case DW_CFA_val_offset: |
7f2c8a1d NC |
8615 | READ_ULEB (reg); |
8616 | READ_ULEB (roffs); | |
665ce1f6 L |
8617 | if (reg >= (unsigned int) fc->ncols) |
8618 | reg_prefix = bad_reg; | |
8619 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8620 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
8621 | reg_prefix, regname (reg, 0), |
8622 | roffs * fc->data_factor); | |
8623 | if (*reg_prefix == '\0') | |
8624 | { | |
8625 | fc->col_type[reg] = DW_CFA_val_offset; | |
8626 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8627 | } | |
12eae2d3 JJ |
8628 | break; |
8629 | ||
19e6b90e | 8630 | case DW_CFA_restore_extended: |
7f2c8a1d | 8631 | READ_ULEB (reg); |
50751e18 | 8632 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
8633 | reg_prefix = bad_reg; |
8634 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8635 | printf (" DW_CFA_restore_extended: %s%s\n", | |
8636 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
8637 | if (*reg_prefix != '\0') |
8638 | break; | |
8639 | ||
8640 | if (reg >= (unsigned int) cie->ncols) | |
8641 | { | |
8642 | fc->col_type[reg] = DW_CFA_undefined; | |
8643 | fc->col_offset[reg] = 0; | |
8644 | } | |
8645 | else | |
665ce1f6 L |
8646 | { |
8647 | fc->col_type[reg] = cie->col_type[reg]; | |
8648 | fc->col_offset[reg] = cie->col_offset[reg]; | |
8649 | } | |
19e6b90e L |
8650 | break; |
8651 | ||
8652 | case DW_CFA_undefined: | |
7f2c8a1d | 8653 | READ_ULEB (reg); |
665ce1f6 L |
8654 | if (reg >= (unsigned int) fc->ncols) |
8655 | reg_prefix = bad_reg; | |
8656 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8657 | printf (" DW_CFA_undefined: %s%s\n", | |
8658 | reg_prefix, regname (reg, 0)); | |
8659 | if (*reg_prefix == '\0') | |
8660 | { | |
8661 | fc->col_type[reg] = DW_CFA_undefined; | |
8662 | fc->col_offset[reg] = 0; | |
8663 | } | |
19e6b90e L |
8664 | break; |
8665 | ||
8666 | case DW_CFA_same_value: | |
7f2c8a1d | 8667 | READ_ULEB (reg); |
665ce1f6 L |
8668 | if (reg >= (unsigned int) fc->ncols) |
8669 | reg_prefix = bad_reg; | |
8670 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8671 | printf (" DW_CFA_same_value: %s%s\n", | |
8672 | reg_prefix, regname (reg, 0)); | |
8673 | if (*reg_prefix == '\0') | |
8674 | { | |
8675 | fc->col_type[reg] = DW_CFA_same_value; | |
8676 | fc->col_offset[reg] = 0; | |
8677 | } | |
19e6b90e L |
8678 | break; |
8679 | ||
8680 | case DW_CFA_register: | |
7f2c8a1d NC |
8681 | READ_ULEB (reg); |
8682 | READ_ULEB (roffs); | |
665ce1f6 L |
8683 | if (reg >= (unsigned int) fc->ncols) |
8684 | reg_prefix = bad_reg; | |
8685 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 8686 | { |
665ce1f6 L |
8687 | printf (" DW_CFA_register: %s%s in ", |
8688 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
8689 | puts (regname (roffs, 0)); |
8690 | } | |
665ce1f6 L |
8691 | if (*reg_prefix == '\0') |
8692 | { | |
8693 | fc->col_type[reg] = DW_CFA_register; | |
8694 | fc->col_offset[reg] = roffs; | |
8695 | } | |
19e6b90e L |
8696 | break; |
8697 | ||
8698 | case DW_CFA_remember_state: | |
8699 | if (! do_debug_frames_interp) | |
8700 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 8701 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 8702 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
8703 | rs->cfa_reg = fc->cfa_reg; |
8704 | rs->ra = fc->ra; | |
8705 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 8706 | rs->ncols = fc->ncols; |
3f5e193b | 8707 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 8708 | sizeof (* rs->col_type)); |
d71ad7fc RC |
8709 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
8710 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
8711 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
8712 | rs->next = remembered_state; |
8713 | remembered_state = rs; | |
8714 | break; | |
8715 | ||
8716 | case DW_CFA_restore_state: | |
8717 | if (! do_debug_frames_interp) | |
8718 | printf (" DW_CFA_restore_state\n"); | |
8719 | rs = remembered_state; | |
8720 | if (rs) | |
8721 | { | |
8722 | remembered_state = rs->next; | |
d71ad7fc RC |
8723 | fc->cfa_offset = rs->cfa_offset; |
8724 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
8725 | fc->ra = rs->ra; |
8726 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
8727 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
8728 | { | |
1306a742 | 8729 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
8730 | fc->ncols = 0; |
8731 | break; | |
8732 | } | |
d71ad7fc | 8733 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 8734 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 8735 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
8736 | free (rs->col_type); |
8737 | free (rs->col_offset); | |
8738 | free (rs); | |
8739 | } | |
8740 | else if (do_debug_frames_interp) | |
8741 | printf ("Mismatched DW_CFA_restore_state\n"); | |
8742 | break; | |
8743 | ||
8744 | case DW_CFA_def_cfa: | |
32ef3000 | 8745 | READ_ULEB (fc->cfa_reg); |
7f2c8a1d | 8746 | READ_ULEB (fc->cfa_offset); |
19e6b90e L |
8747 | fc->cfa_exp = 0; |
8748 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8749 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 8750 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8751 | break; |
8752 | ||
8753 | case DW_CFA_def_cfa_register: | |
32ef3000 | 8754 | READ_ULEB (fc->cfa_reg); |
19e6b90e L |
8755 | fc->cfa_exp = 0; |
8756 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
8757 | printf (" DW_CFA_def_cfa_register: %s\n", |
8758 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
8759 | break; |
8760 | ||
8761 | case DW_CFA_def_cfa_offset: | |
7f2c8a1d | 8762 | READ_ULEB (fc->cfa_offset); |
19e6b90e | 8763 | if (! do_debug_frames_interp) |
c8071705 | 8764 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8765 | break; |
8766 | ||
8767 | case DW_CFA_nop: | |
8768 | if (! do_debug_frames_interp) | |
8769 | printf (" DW_CFA_nop\n"); | |
8770 | break; | |
8771 | ||
8772 | case DW_CFA_def_cfa_expression: | |
7f2c8a1d | 8773 | READ_ULEB (ul); |
7460c0ab | 8774 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 8775 | { |
a1165289 | 8776 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8777 | break; |
8778 | } | |
19e6b90e L |
8779 | if (! do_debug_frames_interp) |
8780 | { | |
8781 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
8782 | decode_location_expression (start, eh_addr_size, 0, -1, |
8783 | ul, 0, section); | |
19e6b90e L |
8784 | printf (")\n"); |
8785 | } | |
8786 | fc->cfa_exp = 1; | |
8787 | start += ul; | |
8788 | break; | |
8789 | ||
8790 | case DW_CFA_expression: | |
7f2c8a1d NC |
8791 | READ_ULEB (reg); |
8792 | READ_ULEB (ul); | |
665ce1f6 L |
8793 | if (reg >= (unsigned int) fc->ncols) |
8794 | reg_prefix = bad_reg; | |
6937bb54 | 8795 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 8796 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
8797 | tmp = start + ul; |
8798 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8799 | { |
a1165289 | 8800 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8801 | break; |
8802 | } | |
665ce1f6 | 8803 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 8804 | { |
665ce1f6 L |
8805 | printf (" DW_CFA_expression: %s%s (", |
8806 | reg_prefix, regname (reg, 0)); | |
b7807392 | 8807 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 8808 | ul, 0, section); |
19e6b90e L |
8809 | printf (")\n"); |
8810 | } | |
665ce1f6 L |
8811 | if (*reg_prefix == '\0') |
8812 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 8813 | start = tmp; |
19e6b90e L |
8814 | break; |
8815 | ||
12eae2d3 | 8816 | case DW_CFA_val_expression: |
7f2c8a1d NC |
8817 | READ_ULEB (reg); |
8818 | READ_ULEB (ul); | |
665ce1f6 L |
8819 | if (reg >= (unsigned int) fc->ncols) |
8820 | reg_prefix = bad_reg; | |
362beea4 NC |
8821 | tmp = start + ul; |
8822 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8823 | { |
a1165289 | 8824 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
8825 | break; |
8826 | } | |
665ce1f6 | 8827 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 8828 | { |
665ce1f6 L |
8829 | printf (" DW_CFA_val_expression: %s%s (", |
8830 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
8831 | decode_location_expression (start, eh_addr_size, 0, -1, |
8832 | ul, 0, section); | |
12eae2d3 JJ |
8833 | printf (")\n"); |
8834 | } | |
665ce1f6 L |
8835 | if (*reg_prefix == '\0') |
8836 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 8837 | start = tmp; |
12eae2d3 JJ |
8838 | break; |
8839 | ||
19e6b90e | 8840 | case DW_CFA_offset_extended_sf: |
7f2c8a1d NC |
8841 | READ_ULEB (reg); |
8842 | READ_SLEB (l); | |
665ce1f6 L |
8843 | if (frame_need_space (fc, reg) < 0) |
8844 | reg_prefix = bad_reg; | |
8845 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8846 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
8847 | reg_prefix, regname (reg, 0), | |
c8071705 | 8848 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8849 | if (*reg_prefix == '\0') |
8850 | { | |
8851 | fc->col_type[reg] = DW_CFA_offset; | |
8852 | fc->col_offset[reg] = l * fc->data_factor; | |
8853 | } | |
19e6b90e L |
8854 | break; |
8855 | ||
12eae2d3 | 8856 | case DW_CFA_val_offset_sf: |
7f2c8a1d NC |
8857 | READ_ULEB (reg); |
8858 | READ_SLEB (l); | |
665ce1f6 L |
8859 | if (frame_need_space (fc, reg) < 0) |
8860 | reg_prefix = bad_reg; | |
8861 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8862 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 8863 | reg_prefix, regname (reg, 0), |
c8071705 | 8864 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8865 | if (*reg_prefix == '\0') |
8866 | { | |
8867 | fc->col_type[reg] = DW_CFA_val_offset; | |
8868 | fc->col_offset[reg] = l * fc->data_factor; | |
8869 | } | |
12eae2d3 JJ |
8870 | break; |
8871 | ||
19e6b90e | 8872 | case DW_CFA_def_cfa_sf: |
32ef3000 | 8873 | READ_ULEB (fc->cfa_reg); |
7f2c8a1d | 8874 | READ_ULEB (fc->cfa_offset); |
19e6b90e L |
8875 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
8876 | fc->cfa_exp = 0; | |
8877 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8878 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 8879 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8880 | break; |
8881 | ||
8882 | case DW_CFA_def_cfa_offset_sf: | |
7f2c8a1d | 8883 | READ_ULEB (fc->cfa_offset); |
c8071705 | 8884 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 8885 | if (! do_debug_frames_interp) |
c8071705 | 8886 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8887 | break; |
8888 | ||
8889 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 8890 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
8891 | if (do_debug_frames_interp) |
8892 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8893 | else | |
bf5117e3 NC |
8894 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
8895 | (unsigned long) (ofs * fc->code_factor), | |
8896 | dwarf_vmatoa_1 (NULL, | |
8897 | fc->pc_begin + ofs * fc->code_factor, | |
8898 | fc->ptr_size)); | |
19e6b90e L |
8899 | fc->pc_begin += ofs * fc->code_factor; |
8900 | break; | |
8901 | ||
8902 | case DW_CFA_GNU_window_save: | |
8903 | if (! do_debug_frames_interp) | |
8904 | printf (" DW_CFA_GNU_window_save\n"); | |
8905 | break; | |
8906 | ||
8907 | case DW_CFA_GNU_args_size: | |
7f2c8a1d | 8908 | READ_ULEB (ul); |
19e6b90e L |
8909 | if (! do_debug_frames_interp) |
8910 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
8911 | break; | |
8912 | ||
8913 | case DW_CFA_GNU_negative_offset_extended: | |
7f2c8a1d NC |
8914 | READ_ULEB (reg); |
8915 | READ_SLEB (l); | |
8916 | l = - l; | |
665ce1f6 L |
8917 | if (frame_need_space (fc, reg) < 0) |
8918 | reg_prefix = bad_reg; | |
8919 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8920 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
8921 | reg_prefix, regname (reg, 0), | |
c8071705 | 8922 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8923 | if (*reg_prefix == '\0') |
8924 | { | |
8925 | fc->col_type[reg] = DW_CFA_offset; | |
8926 | fc->col_offset[reg] = l * fc->data_factor; | |
8927 | } | |
19e6b90e L |
8928 | break; |
8929 | ||
8930 | default: | |
53b8873b NC |
8931 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
8932 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
8933 | else | |
f41e4712 | 8934 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
8935 | start = block_end; |
8936 | } | |
8937 | } | |
8938 | ||
5b6312fd NC |
8939 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
8940 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
8941 | frame_display_row (fc, &need_col_headers, &max_regs); |
8942 | ||
8943 | start = block_end; | |
604282a7 | 8944 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
8945 | } |
8946 | ||
8947 | printf ("\n"); | |
8948 | ||
3391569f NC |
8949 | while (remembered_state != NULL) |
8950 | { | |
8951 | rs = remembered_state; | |
8952 | remembered_state = rs->next; | |
8953 | free (rs->col_type); | |
8954 | free (rs->col_offset); | |
8955 | rs->next = NULL; /* Paranoia. */ | |
8956 | free (rs); | |
8957 | } | |
8958 | ||
8959 | while (chunks != NULL) | |
8960 | { | |
8961 | rs = chunks; | |
8962 | chunks = rs->next; | |
8963 | free (rs->col_type); | |
8964 | free (rs->col_offset); | |
8965 | rs->next = NULL; /* Paranoia. */ | |
8966 | free (rs); | |
8967 | } | |
8968 | ||
8969 | while (forward_refs != NULL) | |
8970 | { | |
8971 | rs = forward_refs; | |
8972 | forward_refs = rs->next; | |
8973 | free (rs->col_type); | |
8974 | free (rs->col_offset); | |
8975 | rs->next = NULL; /* Paranoia. */ | |
8976 | free (rs); | |
8977 | } | |
8978 | ||
19e6b90e L |
8979 | return 1; |
8980 | } | |
8981 | ||
8982 | #undef GET | |
19e6b90e | 8983 | |
61364358 JK |
8984 | static int |
8985 | display_debug_names (struct dwarf_section *section, void *file) | |
8986 | { | |
8987 | unsigned char *hdrptr = section->start; | |
8988 | dwarf_vma unit_length; | |
8989 | unsigned char *unit_start; | |
8990 | const unsigned char *const section_end = section->start + section->size; | |
8991 | unsigned char *unit_end; | |
8992 | ||
dda8d76d | 8993 | introduce (section, FALSE); |
61364358 | 8994 | |
dda8d76d | 8995 | load_debug_section_with_follow (str, file); |
61364358 JK |
8996 | |
8997 | for (; hdrptr < section_end; hdrptr = unit_end) | |
8998 | { | |
8999 | unsigned int offset_size; | |
9000 | uint16_t dwarf_version, padding; | |
9001 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
9002 | uint32_t bucket_count, name_count, abbrev_table_size; | |
9003 | uint32_t augmentation_string_size; | |
9004 | unsigned int i; | |
e98fdf1a | 9005 | unsigned long sec_off; |
48467cb9 TV |
9006 | bfd_boolean augmentation_printable; |
9007 | const char *augmentation_string; | |
61364358 JK |
9008 | |
9009 | unit_start = hdrptr; | |
9010 | ||
9011 | /* Get and check the length of the block. */ | |
9012 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
9013 | ||
9014 | if (unit_length == 0xffffffff) | |
9015 | { | |
9016 | /* This section is 64-bit DWARF. */ | |
9017 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
9018 | offset_size = 8; | |
9019 | } | |
9020 | else | |
9021 | offset_size = 4; | |
9022 | unit_end = hdrptr + unit_length; | |
9023 | ||
e98fdf1a AM |
9024 | sec_off = hdrptr - section->start; |
9025 | if (sec_off + unit_length < sec_off | |
9026 | || sec_off + unit_length > section->size) | |
61364358 | 9027 | { |
e98fdf1a AM |
9028 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
9029 | section->name, | |
9030 | (unsigned long) (unit_start - section->start), | |
9031 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
9032 | return 0; |
9033 | } | |
9034 | ||
9035 | /* Get and check the version number. */ | |
9036 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
9037 | printf (_("Version %ld\n"), (long) dwarf_version); | |
9038 | ||
9039 | /* Prior versions did not exist, and future versions may not be | |
9040 | backwards compatible. */ | |
9041 | if (dwarf_version != 5) | |
9042 | { | |
9043 | warn (_("Only DWARF version 5 .debug_names " | |
9044 | "is currently supported.\n")); | |
9045 | return 0; | |
9046 | } | |
9047 | ||
9048 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
9049 | if (padding != 0) | |
9050 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
9051 | padding); | |
9052 | ||
9053 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
9054 | if (comp_unit_count == 0) | |
9055 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
9056 | ||
9057 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
9058 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
9059 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
9060 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
9061 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
9062 | ||
9063 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
9064 | if (augmentation_string_size % 4 != 0) | |
9065 | { | |
9066 | warn (_("Augmentation string length %u must be rounded up " | |
9067 | "to a multiple of 4 in .debug_names.\n"), | |
9068 | augmentation_string_size); | |
9069 | augmentation_string_size += (-augmentation_string_size) & 3; | |
9070 | } | |
48467cb9 | 9071 | |
61364358 | 9072 | printf (_("Augmentation string:")); |
48467cb9 TV |
9073 | |
9074 | augmentation_printable = TRUE; | |
9075 | augmentation_string = (const char *) hdrptr; | |
9076 | ||
61364358 JK |
9077 | for (i = 0; i < augmentation_string_size; i++) |
9078 | { | |
9079 | unsigned char uc; | |
9080 | ||
9081 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
9082 | printf (" %02x", uc); | |
48467cb9 TV |
9083 | |
9084 | if (uc != 0 && !ISPRINT (uc)) | |
9085 | augmentation_printable = FALSE; | |
9086 | } | |
9087 | ||
9088 | if (augmentation_printable) | |
9089 | { | |
9090 | printf (" (\""); | |
9091 | for (i = 0; | |
9092 | i < augmentation_string_size && augmentation_string[i]; | |
9093 | ++i) | |
9094 | putchar (augmentation_string[i]); | |
9095 | printf ("\")"); | |
61364358 | 9096 | } |
61364358 JK |
9097 | putchar ('\n'); |
9098 | ||
9099 | printf (_("CU table:\n")); | |
9100 | for (i = 0; i < comp_unit_count; i++) | |
9101 | { | |
9102 | uint64_t cu_offset; | |
9103 | ||
9104 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
9105 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
9106 | } | |
9107 | putchar ('\n'); | |
9108 | ||
9109 | printf (_("TU table:\n")); | |
9110 | for (i = 0; i < local_type_unit_count; i++) | |
9111 | { | |
9112 | uint64_t tu_offset; | |
9113 | ||
9114 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
9115 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
9116 | } | |
9117 | putchar ('\n'); | |
9118 | ||
9119 | printf (_("Foreign TU table:\n")); | |
9120 | for (i = 0; i < foreign_type_unit_count; i++) | |
9121 | { | |
9122 | uint64_t signature; | |
9123 | ||
9124 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
9125 | printf (_("[%3u] "), i); | |
9126 | print_dwarf_vma (signature, 8); | |
9127 | putchar ('\n'); | |
9128 | } | |
9129 | putchar ('\n'); | |
9130 | ||
9131 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
9132 | hdrptr += bucket_count * sizeof (uint32_t); | |
9133 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
9134 | hdrptr += name_count * sizeof (uint32_t); | |
9135 | unsigned char *const name_table_string_offsets = hdrptr; | |
9136 | hdrptr += name_count * offset_size; | |
9137 | unsigned char *const name_table_entry_offsets = hdrptr; | |
9138 | hdrptr += name_count * offset_size; | |
9139 | unsigned char *const abbrev_table = hdrptr; | |
9140 | hdrptr += abbrev_table_size; | |
9141 | const unsigned char *const abbrev_table_end = hdrptr; | |
9142 | unsigned char *const entry_pool = hdrptr; | |
9143 | if (hdrptr > unit_end) | |
9144 | { | |
9145 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
9146 | "for unit 0x%lx in the debug_names\n"), | |
9147 | (long) (hdrptr - section->start), | |
9148 | (long) (unit_end - section->start), | |
9149 | (long) (unit_start - section->start)); | |
9150 | return 0; | |
9151 | } | |
9152 | ||
9153 | size_t buckets_filled = 0; | |
9154 | size_t bucketi; | |
9155 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
9156 | { | |
9157 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
9158 | ||
9159 | if (bucket != 0) | |
9160 | ++buckets_filled; | |
9161 | } | |
d3a49aa8 AM |
9162 | printf (ngettext ("Used %zu of %lu bucket.\n", |
9163 | "Used %zu of %lu buckets.\n", | |
9164 | bucket_count), | |
9165 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 9166 | |
0a79bef4 | 9167 | uint32_t hash_prev = 0; |
61364358 JK |
9168 | size_t hash_clash_count = 0; |
9169 | size_t longest_clash = 0; | |
9170 | size_t this_length = 0; | |
9171 | size_t hashi; | |
9172 | for (hashi = 0; hashi < name_count; hashi++) | |
9173 | { | |
9174 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
9175 | ||
9176 | if (hashi > 0) | |
9177 | { | |
9178 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
9179 | { | |
9180 | ++hash_clash_count; | |
9181 | ++this_length; | |
9182 | longest_clash = MAX (longest_clash, this_length); | |
9183 | } | |
9184 | else | |
9185 | this_length = 0; | |
9186 | } | |
9187 | hash_prev = hash_this; | |
9188 | } | |
9189 | printf (_("Out of %lu items there are %zu bucket clashes" | |
9190 | " (longest of %zu entries).\n"), | |
9191 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
9192 | assert (name_count == buckets_filled + hash_clash_count); | |
9193 | ||
9194 | struct abbrev_lookup_entry | |
9195 | { | |
9196 | dwarf_vma abbrev_tag; | |
9197 | unsigned char *abbrev_lookup_ptr; | |
9198 | }; | |
9199 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
9200 | size_t abbrev_lookup_used = 0; | |
9201 | size_t abbrev_lookup_allocated = 0; | |
9202 | ||
9203 | unsigned char *abbrevptr = abbrev_table; | |
9204 | for (;;) | |
9205 | { | |
9206 | unsigned int bytes_read; | |
9207 | const dwarf_vma abbrev_tag = read_uleb128 (abbrevptr, &bytes_read, | |
9208 | abbrev_table_end); | |
9209 | abbrevptr += bytes_read; | |
9210 | if (abbrev_tag == 0) | |
9211 | break; | |
9212 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
9213 | { | |
9214 | abbrev_lookup_allocated = MAX (0x100, | |
9215 | abbrev_lookup_allocated * 2); | |
9216 | abbrev_lookup = xrealloc (abbrev_lookup, | |
9217 | (abbrev_lookup_allocated | |
9218 | * sizeof (*abbrev_lookup))); | |
9219 | } | |
9220 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
9221 | struct abbrev_lookup_entry *entry; | |
9222 | for (entry = abbrev_lookup; | |
9223 | entry < abbrev_lookup + abbrev_lookup_used; | |
9224 | entry++) | |
9225 | if (entry->abbrev_tag == abbrev_tag) | |
9226 | { | |
9227 | warn (_("Duplicate abbreviation tag %lu " | |
9228 | "in unit 0x%lx in the debug_names\n"), | |
9229 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
9230 | break; | |
9231 | } | |
9232 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
9233 | entry->abbrev_tag = abbrev_tag; | |
9234 | entry->abbrev_lookup_ptr = abbrevptr; | |
9235 | ||
9236 | /* Skip DWARF tag. */ | |
9237 | read_uleb128 (abbrevptr, &bytes_read, abbrev_table_end); | |
9238 | abbrevptr += bytes_read; | |
9239 | for (;;) | |
9240 | { | |
1d827a72 L |
9241 | const dwarf_vma xindex = read_uleb128 (abbrevptr, |
9242 | &bytes_read, | |
9243 | abbrev_table_end); | |
61364358 JK |
9244 | abbrevptr += bytes_read; |
9245 | const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read, | |
9246 | abbrev_table_end); | |
9247 | abbrevptr += bytes_read; | |
1d827a72 | 9248 | if (xindex == 0 && form == 0) |
61364358 JK |
9249 | break; |
9250 | } | |
9251 | } | |
9252 | ||
9253 | printf (_("\nSymbol table:\n")); | |
9254 | uint32_t namei; | |
9255 | for (namei = 0; namei < name_count; ++namei) | |
9256 | { | |
9257 | uint64_t string_offset, entry_offset; | |
9258 | ||
9259 | SAFE_BYTE_GET (string_offset, | |
9260 | name_table_string_offsets + namei * offset_size, | |
9261 | offset_size, unit_end); | |
9262 | SAFE_BYTE_GET (entry_offset, | |
9263 | name_table_entry_offsets + namei * offset_size, | |
9264 | offset_size, unit_end); | |
9265 | ||
9266 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
9267 | fetch_indirect_string (string_offset)); | |
9268 | ||
9269 | unsigned char *entryptr = entry_pool + entry_offset; | |
9270 | ||
9271 | // We need to scan first whether there is a single or multiple | |
9272 | // entries. TAGNO is -2 for the first entry, it is -1 for the | |
9273 | // initial tag read of the second entry, then it becomes 0 for the | |
9274 | // first entry for real printing etc. | |
9275 | int tagno = -2; | |
9276 | /* Initialize it due to a false compiler warning. */ | |
9277 | dwarf_vma second_abbrev_tag = -1; | |
9278 | for (;;) | |
9279 | { | |
9280 | unsigned int bytes_read; | |
9281 | const dwarf_vma abbrev_tag = read_uleb128 (entryptr, &bytes_read, | |
9282 | unit_end); | |
9283 | entryptr += bytes_read; | |
9284 | if (tagno == -1) | |
9285 | { | |
9286 | second_abbrev_tag = abbrev_tag; | |
9287 | tagno = 0; | |
9288 | entryptr = entry_pool + entry_offset; | |
9289 | continue; | |
9290 | } | |
9291 | if (abbrev_tag == 0) | |
9292 | break; | |
9293 | if (tagno >= 0) | |
9294 | printf ("%s<%lu>", | |
9295 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
9296 | (unsigned long) abbrev_tag); | |
9297 | ||
9298 | const struct abbrev_lookup_entry *entry; | |
9299 | for (entry = abbrev_lookup; | |
9300 | entry < abbrev_lookup + abbrev_lookup_used; | |
9301 | entry++) | |
9302 | if (entry->abbrev_tag == abbrev_tag) | |
9303 | break; | |
9304 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
9305 | { | |
9306 | warn (_("Undefined abbreviation tag %lu " | |
9307 | "in unit 0x%lx in the debug_names\n"), | |
9308 | (long) abbrev_tag, | |
9309 | (long) (unit_start - section->start)); | |
9310 | break; | |
9311 | } | |
9312 | abbrevptr = entry->abbrev_lookup_ptr; | |
9313 | const dwarf_vma dwarf_tag = read_uleb128 (abbrevptr, &bytes_read, | |
9314 | abbrev_table_end); | |
9315 | abbrevptr += bytes_read; | |
9316 | if (tagno >= 0) | |
9317 | printf (" %s", get_TAG_name (dwarf_tag)); | |
9318 | for (;;) | |
9319 | { | |
1d827a72 L |
9320 | const dwarf_vma xindex = read_uleb128 (abbrevptr, |
9321 | &bytes_read, | |
9322 | abbrev_table_end); | |
61364358 JK |
9323 | abbrevptr += bytes_read; |
9324 | const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read, | |
9325 | abbrev_table_end); | |
9326 | abbrevptr += bytes_read; | |
1d827a72 | 9327 | if (xindex == 0 && form == 0) |
61364358 JK |
9328 | break; |
9329 | ||
9330 | if (tagno >= 0) | |
1d827a72 | 9331 | printf (" %s", get_IDX_name (xindex)); |
ec1b0fbb NC |
9332 | entryptr = read_and_display_attr_value (0, form, 0, |
9333 | unit_start, entryptr, unit_end, | |
9334 | 0, 0, offset_size, | |
61364358 JK |
9335 | dwarf_version, NULL, |
9336 | (tagno < 0), NULL, | |
ec1b0fbb | 9337 | NULL, '=', -1); |
61364358 JK |
9338 | } |
9339 | ++tagno; | |
9340 | } | |
9341 | if (tagno <= 0) | |
9342 | printf (_(" <no entries>")); | |
9343 | putchar ('\n'); | |
9344 | } | |
9345 | ||
9346 | free (abbrev_lookup); | |
9347 | } | |
9348 | ||
9349 | return 1; | |
9350 | } | |
9351 | ||
dda8d76d | 9352 | static int |
d85bf2ba NC |
9353 | display_debug_links (struct dwarf_section * section, |
9354 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
9355 | { |
9356 | const unsigned char * filename; | |
9357 | unsigned int filelen; | |
9358 | ||
9359 | introduce (section, FALSE); | |
9360 | ||
9361 | /* The .gnu_debuglink section is formatted as: | |
9362 | (c-string) Filename. | |
9363 | (padding) If needed to reach a 4 byte boundary. | |
9364 | (uint32_t) CRC32 value. | |
9365 | ||
9366 | The .gun_debugaltlink section is formatted as: | |
9367 | (c-string) Filename. | |
9368 | (binary) Build-ID. */ | |
9369 | ||
9370 | filename = section->start; | |
9371 | filelen = strnlen ((const char *) filename, section->size); | |
9372 | if (filelen == section->size) | |
9373 | { | |
9374 | warn (_("The debuglink filename is corrupt/missing\n")); | |
9375 | return 0; | |
9376 | } | |
9377 | ||
9378 | printf (_(" Separate debug info file: %s\n"), filename); | |
9379 | ||
9380 | if (const_strneq (section->name, ".gnu_debuglink")) | |
9381 | { | |
9382 | unsigned int crc32; | |
9383 | unsigned int crc_offset; | |
9384 | ||
9385 | crc_offset = filelen + 1; | |
9386 | crc_offset = (crc_offset + 3) & ~3; | |
9387 | if (crc_offset + 4 > section->size) | |
9388 | { | |
9389 | warn (_("CRC offset missing/truncated\n")); | |
9390 | return 0; | |
9391 | } | |
9392 | ||
9393 | crc32 = byte_get (filename + crc_offset, 4); | |
9394 | ||
9395 | printf (_(" CRC value: %#x\n"), crc32); | |
9396 | ||
9397 | if (crc_offset + 4 < section->size) | |
9398 | { | |
9399 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
9400 | (long)(section->size - (crc_offset + 4))); | |
9401 | return 0; | |
9402 | } | |
9403 | } | |
9404 | else /* const_strneq (section->name, ".gnu_debugaltlink") */ | |
9405 | { | |
9406 | const unsigned char * build_id = section->start + filelen + 1; | |
9407 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
9408 | bfd_size_type printed; | |
9409 | ||
9410 | /* FIXME: Should we support smaller build-id notes ? */ | |
9411 | if (build_id_len < 0x14) | |
9412 | { | |
9413 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
9414 | return 0; | |
9415 | } | |
9416 | ||
9417 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 9418 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
9419 | putchar ('\n'); |
9420 | } | |
9421 | ||
9422 | putchar ('\n'); | |
9423 | return 1; | |
9424 | } | |
9425 | ||
5bbdf3d5 DE |
9426 | static int |
9427 | display_gdb_index (struct dwarf_section *section, | |
9428 | void *file ATTRIBUTE_UNUSED) | |
9429 | { | |
9430 | unsigned char *start = section->start; | |
9431 | uint32_t version; | |
9432 | uint32_t cu_list_offset, tu_list_offset; | |
9433 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
9434 | unsigned int cu_list_elements, tu_list_elements; | |
9435 | unsigned int address_table_size, symbol_table_slots; | |
9436 | unsigned char *cu_list, *tu_list; | |
9437 | unsigned char *address_table, *symbol_table, *constant_pool; | |
9438 | unsigned int i; | |
9439 | ||
9440 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
9441 | ||
dda8d76d | 9442 | introduce (section, FALSE); |
5bbdf3d5 DE |
9443 | |
9444 | if (section->size < 6 * sizeof (uint32_t)) | |
9445 | { | |
9446 | warn (_("Truncated header in the %s section.\n"), section->name); | |
9447 | return 0; | |
9448 | } | |
9449 | ||
9450 | version = byte_get_little_endian (start, 4); | |
da88a764 | 9451 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
9452 | |
9453 | /* Prior versions are obsolete, and future versions may not be | |
9454 | backwards compatible. */ | |
aa170720 | 9455 | if (version < 3 || version > 8) |
5bbdf3d5 | 9456 | { |
da88a764 | 9457 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
9458 | return 0; |
9459 | } | |
8d6eee87 TT |
9460 | if (version < 4) |
9461 | warn (_("The address table data in version 3 may be wrong.\n")); | |
9462 | if (version < 5) | |
9463 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
9464 | if (version < 6) | |
9465 | warn (_("Version 5 does not include inlined functions.\n")); | |
9466 | if (version < 7) | |
9467 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
9468 | /* Version 7 indices generated by Gold have bad type unit references, |
9469 | PR binutils/15021. But we don't know if the index was generated by | |
9470 | Gold or not, so to avoid worrying users with gdb-generated indices | |
9471 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
9472 | |
9473 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
9474 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
9475 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
9476 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
9477 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
9478 | ||
9479 | if (cu_list_offset > section->size | |
9480 | || tu_list_offset > section->size | |
9481 | || address_table_offset > section->size | |
9482 | || symbol_table_offset > section->size | |
9483 | || constant_pool_offset > section->size) | |
9484 | { | |
9485 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
9486 | return 0; | |
9487 | } | |
9488 | ||
53774b7e NC |
9489 | /* PR 17531: file: 418d0a8a. */ |
9490 | if (tu_list_offset < cu_list_offset) | |
9491 | { | |
9492 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
9493 | tu_list_offset, cu_list_offset); | |
9494 | return 0; | |
9495 | } | |
9496 | ||
5bbdf3d5 | 9497 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
9498 | |
9499 | if (address_table_offset < tu_list_offset) | |
9500 | { | |
9501 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
9502 | address_table_offset, tu_list_offset); | |
9503 | return 0; | |
9504 | } | |
9505 | ||
5bbdf3d5 | 9506 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
9507 | |
9508 | /* PR 17531: file: 18a47d3d. */ | |
9509 | if (symbol_table_offset < address_table_offset) | |
9510 | { | |
13bace4a | 9511 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
9512 | symbol_table_offset, address_table_offset); |
9513 | return 0; | |
9514 | } | |
9515 | ||
5bbdf3d5 | 9516 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
9517 | |
9518 | if (constant_pool_offset < symbol_table_offset) | |
9519 | { | |
9520 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
9521 | constant_pool_offset, symbol_table_offset); | |
9522 | return 0; | |
9523 | } | |
9524 | ||
5bbdf3d5 DE |
9525 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
9526 | ||
9527 | cu_list = start + cu_list_offset; | |
9528 | tu_list = start + tu_list_offset; | |
9529 | address_table = start + address_table_offset; | |
9530 | symbol_table = start + symbol_table_offset; | |
9531 | constant_pool = start + constant_pool_offset; | |
9532 | ||
28d909e5 | 9533 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 9534 | { |
1306a742 | 9535 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
9536 | return 0; |
9537 | } | |
b4eb7656 | 9538 | |
5bbdf3d5 DE |
9539 | printf (_("\nCU table:\n")); |
9540 | for (i = 0; i < cu_list_elements; i += 2) | |
9541 | { | |
9542 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
9543 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
9544 | ||
9545 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
9546 | (unsigned long) cu_offset, | |
9547 | (unsigned long) (cu_offset + cu_length - 1)); | |
9548 | } | |
9549 | ||
9550 | printf (_("\nTU table:\n")); | |
9551 | for (i = 0; i < tu_list_elements; i += 3) | |
9552 | { | |
9553 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
9554 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
9555 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
9556 | ||
9557 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
9558 | (unsigned long) tu_offset, | |
9559 | (unsigned long) type_offset); | |
9560 | print_dwarf_vma (signature, 8); | |
9561 | printf ("\n"); | |
9562 | } | |
9563 | ||
9564 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
9565 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
9566 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
9567 | { |
9568 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
9569 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
9570 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
9571 | ||
9572 | print_dwarf_vma (low, 8); | |
9573 | print_dwarf_vma (high, 8); | |
da88a764 | 9574 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
9575 | } |
9576 | ||
9577 | printf (_("\nSymbol table:\n")); | |
9578 | for (i = 0; i < symbol_table_slots; ++i) | |
9579 | { | |
9580 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
9581 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
9582 | uint32_t num_cus, cu; | |
9583 | ||
9584 | if (name_offset != 0 | |
9585 | || cu_vector_offset != 0) | |
9586 | { | |
9587 | unsigned int j; | |
362beea4 | 9588 | unsigned char * adr; |
5bbdf3d5 | 9589 | |
362beea4 | 9590 | adr = constant_pool + name_offset; |
53774b7e | 9591 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 9592 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
9593 | { |
9594 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
9595 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
9596 | name_offset, i); | |
9597 | } | |
9598 | else | |
acff9664 NC |
9599 | printf ("[%3u] %.*s:", i, |
9600 | (int) (section->size - (constant_pool_offset + name_offset)), | |
9601 | constant_pool + name_offset); | |
53774b7e | 9602 | |
362beea4 NC |
9603 | adr = constant_pool + cu_vector_offset; |
9604 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
9605 | { |
9606 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
9607 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
9608 | cu_vector_offset, i); | |
9609 | continue; | |
9610 | } | |
57028622 | 9611 | |
362beea4 | 9612 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 9613 | |
362beea4 | 9614 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 9615 | if (num_cus * 4 < num_cus |
362beea4 NC |
9616 | || adr >= section->start + section->size |
9617 | || adr < constant_pool) | |
53774b7e NC |
9618 | { |
9619 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 9620 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
9621 | num_cus, i); |
9622 | continue; | |
9623 | } | |
9624 | ||
8d6eee87 TT |
9625 | if (num_cus > 1) |
9626 | printf ("\n"); | |
f3853b34 | 9627 | |
5bbdf3d5 DE |
9628 | for (j = 0; j < num_cus; ++j) |
9629 | { | |
7c1cef97 | 9630 | int is_static; |
8d6eee87 TT |
9631 | gdb_index_symbol_kind kind; |
9632 | ||
5bbdf3d5 | 9633 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 9634 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
9635 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
9636 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 9637 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 9638 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
9639 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
9640 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 9641 | else |
8d6eee87 TT |
9642 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
9643 | ||
459d52c8 DE |
9644 | printf (" [%s, %s]", |
9645 | is_static ? _("static") : _("global"), | |
9646 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
9647 | if (num_cus > 1) |
9648 | printf ("\n"); | |
5bbdf3d5 | 9649 | } |
8d6eee87 TT |
9650 | if (num_cus <= 1) |
9651 | printf ("\n"); | |
5bbdf3d5 DE |
9652 | } |
9653 | } | |
9654 | ||
9655 | return 1; | |
9656 | } | |
9657 | ||
657d0d47 CC |
9658 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
9659 | ||
9660 | static void | |
9661 | prealloc_cu_tu_list (unsigned int nshndx) | |
9662 | { | |
9663 | if (shndx_pool == NULL) | |
9664 | { | |
9665 | shndx_pool_size = nshndx; | |
9666 | shndx_pool_used = 0; | |
9667 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
9668 | sizeof (unsigned int)); | |
9669 | } | |
9670 | else | |
9671 | { | |
9672 | shndx_pool_size = shndx_pool_used + nshndx; | |
9673 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
9674 | sizeof (unsigned int)); | |
9675 | } | |
9676 | } | |
9677 | ||
9678 | static void | |
9679 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
9680 | { | |
9681 | if (shndx_pool_used >= shndx_pool_size) | |
9682 | { | |
9683 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9684 | return; | |
9685 | } | |
9686 | shndx_pool [shndx_pool_used++] = shndx; | |
9687 | } | |
9688 | ||
9689 | static void | |
9690 | end_cu_tu_entry (void) | |
9691 | { | |
9692 | if (shndx_pool_used >= shndx_pool_size) | |
9693 | { | |
9694 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9695 | return; | |
9696 | } | |
9697 | shndx_pool [shndx_pool_used++] = 0; | |
9698 | } | |
9699 | ||
341f9135 CC |
9700 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
9701 | ||
9702 | static const char * | |
9703 | get_DW_SECT_short_name (unsigned int dw_sect) | |
9704 | { | |
9705 | static char buf[16]; | |
9706 | ||
9707 | switch (dw_sect) | |
9708 | { | |
9709 | case DW_SECT_INFO: | |
9710 | return "info"; | |
9711 | case DW_SECT_TYPES: | |
9712 | return "types"; | |
9713 | case DW_SECT_ABBREV: | |
9714 | return "abbrev"; | |
9715 | case DW_SECT_LINE: | |
9716 | return "line"; | |
9717 | case DW_SECT_LOC: | |
9718 | return "loc"; | |
9719 | case DW_SECT_STR_OFFSETS: | |
9720 | return "str_off"; | |
9721 | case DW_SECT_MACINFO: | |
9722 | return "macinfo"; | |
9723 | case DW_SECT_MACRO: | |
9724 | return "macro"; | |
9725 | default: | |
b4eb7656 | 9726 | break; |
341f9135 CC |
9727 | } |
9728 | ||
9729 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
9730 | return buf; | |
9731 | } | |
9732 | ||
9733 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
9734 | These sections are extensions for Fission. | |
9735 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
9736 | |
9737 | static int | |
9738 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
9739 | { | |
9740 | unsigned char *phdr = section->start; | |
9741 | unsigned char *limit = phdr + section->size; | |
9742 | unsigned char *phash; | |
9743 | unsigned char *pindex; | |
9744 | unsigned char *ppool; | |
9745 | unsigned int version; | |
341f9135 | 9746 | unsigned int ncols = 0; |
657d0d47 CC |
9747 | unsigned int nused; |
9748 | unsigned int nslots; | |
9749 | unsigned int i; | |
341f9135 CC |
9750 | unsigned int j; |
9751 | dwarf_vma signature_high; | |
9752 | dwarf_vma signature_low; | |
9753 | char buf[64]; | |
657d0d47 | 9754 | |
6937bb54 NC |
9755 | /* PR 17512: file: 002-168123-0.004. */ |
9756 | if (phdr == NULL) | |
9757 | { | |
9758 | warn (_("Section %s is empty\n"), section->name); | |
9759 | return 0; | |
9760 | } | |
9761 | /* PR 17512: file: 002-376-0.004. */ | |
9762 | if (section->size < 24) | |
9763 | { | |
72c61a0d | 9764 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
9765 | section->name); |
9766 | return 0; | |
9767 | } | |
9768 | ||
9769 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 9770 | if (version >= 2) |
6937bb54 NC |
9771 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
9772 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
9773 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
9774 | ||
657d0d47 | 9775 | phash = phdr + 16; |
8e2e3c6c AM |
9776 | pindex = phash + (size_t) nslots * 8; |
9777 | ppool = pindex + (size_t) nslots * 4; | |
57028622 | 9778 | |
657d0d47 CC |
9779 | if (do_display) |
9780 | { | |
dda8d76d NC |
9781 | introduce (section, FALSE); |
9782 | ||
8e2e3c6c | 9783 | printf (_(" Version: %u\n"), version); |
341f9135 | 9784 | if (version >= 2) |
8e2e3c6c AM |
9785 | printf (_(" Number of columns: %u\n"), ncols); |
9786 | printf (_(" Number of used entries: %u\n"), nused); | |
9787 | printf (_(" Number of slots: %u\n\n"), nslots); | |
657d0d47 CC |
9788 | } |
9789 | ||
8e2e3c6c AM |
9790 | /* PR 17531: file: 45d69832. */ |
9791 | if ((size_t) nslots * 8 / 8 != nslots | |
9792 | || phash < phdr || phash > limit | |
9793 | || pindex < phash || pindex > limit | |
9794 | || ppool < pindex || ppool > limit) | |
657d0d47 | 9795 | { |
8e2e3c6c AM |
9796 | warn (ngettext ("Section %s is too small for %u slot\n", |
9797 | "Section %s is too small for %u slots\n", | |
9798 | nslots), | |
657d0d47 CC |
9799 | section->name, nslots); |
9800 | return 0; | |
9801 | } | |
9802 | ||
341f9135 | 9803 | if (version == 1) |
657d0d47 | 9804 | { |
341f9135 CC |
9805 | if (!do_display) |
9806 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
9807 | for (i = 0; i < nslots; i++) | |
657d0d47 | 9808 | { |
341f9135 CC |
9809 | unsigned char *shndx_list; |
9810 | unsigned int shndx; | |
9811 | ||
6937bb54 | 9812 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 9813 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 9814 | { |
6937bb54 | 9815 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 9816 | shndx_list = ppool + j * 4; |
f3853b34 NC |
9817 | /* PR 17531: file: 705e010d. */ |
9818 | if (shndx_list < ppool) | |
9819 | { | |
9820 | warn (_("Section index pool located before start of section\n")); | |
9821 | return 0; | |
9822 | } | |
9823 | ||
341f9135 CC |
9824 | if (do_display) |
9825 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
9826 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9827 | buf, sizeof (buf))); | |
9828 | for (;;) | |
657d0d47 | 9829 | { |
341f9135 CC |
9830 | if (shndx_list >= limit) |
9831 | { | |
9832 | warn (_("Section %s too small for shndx pool\n"), | |
9833 | section->name); | |
9834 | return 0; | |
9835 | } | |
6937bb54 | 9836 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
9837 | if (shndx == 0) |
9838 | break; | |
9839 | if (do_display) | |
9840 | printf (" %d", shndx); | |
9841 | else | |
9842 | add_shndx_to_cu_tu_entry (shndx); | |
9843 | shndx_list += 4; | |
657d0d47 | 9844 | } |
657d0d47 | 9845 | if (do_display) |
341f9135 | 9846 | printf ("\n"); |
657d0d47 | 9847 | else |
341f9135 CC |
9848 | end_cu_tu_entry (); |
9849 | } | |
9850 | phash += 8; | |
9851 | pindex += 4; | |
9852 | } | |
9853 | } | |
9854 | else if (version == 2) | |
9855 | { | |
9856 | unsigned int val; | |
9857 | unsigned int dw_sect; | |
9858 | unsigned char *ph = phash; | |
9859 | unsigned char *pi = pindex; | |
8e2e3c6c AM |
9860 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
9861 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
9862 | unsigned char *pend = psizes + (size_t) nused * ncols * 4; | |
341f9135 CC |
9863 | bfd_boolean is_tu_index; |
9864 | struct cu_tu_set *this_set = NULL; | |
9865 | unsigned int row; | |
9866 | unsigned char *prow; | |
9867 | ||
9868 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
9869 | ||
362beea4 | 9870 | /* PR 17531: file: 0dd159bf. |
8e2e3c6c AM |
9871 | Check for integer overflow (can occur when size_t is 32-bit) |
9872 | with overlarge ncols or nused values. */ | |
4ac948a0 NC |
9873 | if (ncols > 0 |
9874 | && ((size_t) ncols * 4 / 4 != ncols | |
9875 | || (size_t) nused * ncols * 4 / ((size_t) ncols * 4) != nused | |
9876 | || poffsets < ppool || poffsets > limit | |
9877 | || psizes < poffsets || psizes > limit | |
9878 | || pend < psizes || pend > limit)) | |
341f9135 CC |
9879 | { |
9880 | warn (_("Section %s too small for offset and size tables\n"), | |
9881 | section->name); | |
9882 | return 0; | |
9883 | } | |
9884 | ||
9885 | if (do_display) | |
9886 | { | |
9887 | printf (_(" Offset table\n")); | |
9888 | printf (" slot %-16s ", | |
9889 | is_tu_index ? _("signature") : _("dwo_id")); | |
9890 | } | |
9891 | else | |
9892 | { | |
9893 | if (is_tu_index) | |
9894 | { | |
9895 | tu_count = nused; | |
72c61a0d | 9896 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 9897 | this_set = tu_sets; |
657d0d47 | 9898 | } |
657d0d47 | 9899 | else |
341f9135 CC |
9900 | { |
9901 | cu_count = nused; | |
72c61a0d | 9902 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
9903 | this_set = cu_sets; |
9904 | } | |
9905 | } | |
6937bb54 | 9906 | |
341f9135 CC |
9907 | if (do_display) |
9908 | { | |
9909 | for (j = 0; j < ncols; j++) | |
9910 | { | |
6937bb54 | 9911 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
9912 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
9913 | } | |
9914 | printf ("\n"); | |
9915 | } | |
6937bb54 | 9916 | |
341f9135 CC |
9917 | for (i = 0; i < nslots; i++) |
9918 | { | |
6937bb54 NC |
9919 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9920 | ||
9921 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9922 | if (row != 0) |
9923 | { | |
591f7597 | 9924 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 9925 | if (row > nused) |
591f7597 NC |
9926 | { |
9927 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
9928 | row, nused); | |
9929 | return 0; | |
9930 | } | |
9931 | ||
341f9135 | 9932 | if (!do_display) |
6aea08d9 NC |
9933 | { |
9934 | size_t num_copy = sizeof (uint64_t); | |
9935 | ||
9936 | /* PR 23064: Beware of buffer overflow. */ | |
9937 | if (ph + num_copy < limit) | |
9938 | memcpy (&this_set[row - 1].signature, ph, num_copy); | |
9939 | else | |
9940 | { | |
9941 | warn (_("Signature (%p) extends beyond end of space in section\n"), ph); | |
9942 | return 0; | |
9943 | } | |
9944 | } | |
6937bb54 | 9945 | |
341f9135 | 9946 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
9947 | /* PR 17531: file: b8ce60a8. */ |
9948 | if (prow < poffsets || prow > limit) | |
9949 | { | |
9950 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
9951 | row, ncols); | |
9952 | return 0; | |
9953 | } | |
3aade688 | 9954 | |
341f9135 CC |
9955 | if (do_display) |
9956 | printf (_(" [%3d] 0x%s"), | |
9957 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9958 | buf, sizeof (buf))); | |
9959 | for (j = 0; j < ncols; j++) | |
9960 | { | |
6937bb54 | 9961 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
9962 | if (do_display) |
9963 | printf (" %8d", val); | |
9964 | else | |
9965 | { | |
6937bb54 | 9966 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
9967 | |
9968 | /* PR 17531: file: 10796eb3. */ | |
9969 | if (dw_sect >= DW_SECT_MAX) | |
9970 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
9971 | else | |
9972 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
9973 | } |
9974 | } | |
6937bb54 | 9975 | |
341f9135 CC |
9976 | if (do_display) |
9977 | printf ("\n"); | |
9978 | } | |
9979 | ph += 8; | |
9980 | pi += 4; | |
9981 | } | |
9982 | ||
9983 | ph = phash; | |
9984 | pi = pindex; | |
9985 | if (do_display) | |
b4eb7656 | 9986 | { |
341f9135 CC |
9987 | printf ("\n"); |
9988 | printf (_(" Size table\n")); | |
9989 | printf (" slot %-16s ", | |
9990 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 9991 | } |
6937bb54 | 9992 | |
341f9135 CC |
9993 | for (j = 0; j < ncols; j++) |
9994 | { | |
6937bb54 | 9995 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
9996 | if (do_display) |
9997 | printf (" %8s", get_DW_SECT_short_name (val)); | |
9998 | } | |
6937bb54 | 9999 | |
341f9135 CC |
10000 | if (do_display) |
10001 | printf ("\n"); | |
6937bb54 | 10002 | |
341f9135 CC |
10003 | for (i = 0; i < nslots; i++) |
10004 | { | |
6937bb54 NC |
10005 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
10006 | ||
10007 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
10008 | if (row != 0) |
10009 | { | |
10010 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 10011 | |
341f9135 CC |
10012 | if (do_display) |
10013 | printf (_(" [%3d] 0x%s"), | |
10014 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
10015 | buf, sizeof (buf))); | |
6937bb54 | 10016 | |
341f9135 CC |
10017 | for (j = 0; j < ncols; j++) |
10018 | { | |
6937bb54 | 10019 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
10020 | if (do_display) |
10021 | printf (" %8d", val); | |
10022 | else | |
10023 | { | |
6937bb54 | 10024 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
10025 | if (dw_sect >= DW_SECT_MAX) |
10026 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
10027 | else | |
341f9135 CC |
10028 | this_set [row - 1].section_sizes [dw_sect] = val; |
10029 | } | |
10030 | } | |
6937bb54 | 10031 | |
341f9135 CC |
10032 | if (do_display) |
10033 | printf ("\n"); | |
10034 | } | |
6937bb54 | 10035 | |
341f9135 CC |
10036 | ph += 8; |
10037 | pi += 4; | |
657d0d47 | 10038 | } |
657d0d47 | 10039 | } |
341f9135 | 10040 | else if (do_display) |
6937bb54 | 10041 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
10042 | |
10043 | if (do_display) | |
10044 | printf ("\n"); | |
10045 | ||
10046 | return 1; | |
10047 | } | |
10048 | ||
10049 | /* Load the CU and TU indexes if present. This will build a list of | |
10050 | section sets that we can use to associate a .debug_info.dwo section | |
10051 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
10052 | ||
43a444f9 | 10053 | static bfd_boolean |
657d0d47 CC |
10054 | load_cu_tu_indexes (void *file) |
10055 | { | |
43a444f9 NC |
10056 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
10057 | ||
657d0d47 CC |
10058 | /* If we have already loaded (or tried to load) the CU and TU indexes |
10059 | then do not bother to repeat the task. */ | |
43a444f9 NC |
10060 | if (cu_tu_indexes_read == -1) |
10061 | { | |
10062 | cu_tu_indexes_read = TRUE; | |
10063 | ||
dda8d76d | 10064 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 NC |
10065 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
10066 | cu_tu_indexes_read = FALSE; | |
10067 | ||
dda8d76d | 10068 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 NC |
10069 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
10070 | cu_tu_indexes_read = FALSE; | |
10071 | } | |
657d0d47 | 10072 | |
43a444f9 | 10073 | return (bfd_boolean) cu_tu_indexes_read; |
657d0d47 CC |
10074 | } |
10075 | ||
10076 | /* Find the set of sections that includes section SHNDX. */ | |
10077 | ||
10078 | unsigned int * | |
10079 | find_cu_tu_set (void *file, unsigned int shndx) | |
10080 | { | |
10081 | unsigned int i; | |
10082 | ||
43a444f9 NC |
10083 | if (! load_cu_tu_indexes (file)) |
10084 | return NULL; | |
657d0d47 CC |
10085 | |
10086 | /* Find SHNDX in the shndx pool. */ | |
10087 | for (i = 0; i < shndx_pool_used; i++) | |
10088 | if (shndx_pool [i] == shndx) | |
10089 | break; | |
10090 | ||
10091 | if (i >= shndx_pool_used) | |
10092 | return NULL; | |
10093 | ||
10094 | /* Now backup to find the first entry in the set. */ | |
10095 | while (i > 0 && shndx_pool [i - 1] != 0) | |
10096 | i--; | |
10097 | ||
10098 | return shndx_pool + i; | |
10099 | } | |
10100 | ||
10101 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
10102 | ||
10103 | static int | |
10104 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
10105 | { | |
10106 | return process_cu_tu_index (section, 1); | |
10107 | } | |
10108 | ||
19e6b90e L |
10109 | static int |
10110 | display_debug_not_supported (struct dwarf_section *section, | |
10111 | void *file ATTRIBUTE_UNUSED) | |
10112 | { | |
10113 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
10114 | section->name); | |
10115 | ||
10116 | return 1; | |
10117 | } | |
10118 | ||
1306a742 NC |
10119 | /* Like malloc, but takes two parameters like calloc. |
10120 | Verifies that the first parameter is not too large. | |
82b1b41b | 10121 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 10122 | |
19e6b90e L |
10123 | void * |
10124 | cmalloc (size_t nmemb, size_t size) | |
10125 | { | |
10126 | /* Check for overflow. */ | |
10127 | if (nmemb >= ~(size_t) 0 / size) | |
10128 | return NULL; | |
82b1b41b NC |
10129 | |
10130 | return xmalloc (nmemb * size); | |
19e6b90e L |
10131 | } |
10132 | ||
1306a742 NC |
10133 | /* Like xmalloc, but takes two parameters like calloc. |
10134 | Verifies that the first parameter is not too large. | |
10135 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 10136 | |
72c61a0d | 10137 | void * |
1306a742 | 10138 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
10139 | { |
10140 | /* Check for overflow. */ | |
10141 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
10142 | { |
10143 | fprintf (stderr, | |
10144 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
10145 | (long) nmemb); | |
10146 | xexit (1); | |
10147 | } | |
72c61a0d | 10148 | |
1306a742 | 10149 | return xmalloc (nmemb * size); |
72c61a0d NC |
10150 | } |
10151 | ||
1306a742 NC |
10152 | /* Like xrealloc, but takes three parameters. |
10153 | Verifies that the second parameter is not too large. | |
10154 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 10155 | |
19e6b90e | 10156 | void * |
1306a742 | 10157 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
10158 | { |
10159 | /* Check for overflow. */ | |
10160 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10161 | { |
dda8d76d NC |
10162 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
10163 | (long) nmemb); | |
8490fb40 NC |
10164 | xexit (1); |
10165 | } | |
82b1b41b | 10166 | |
1306a742 | 10167 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
10168 | } |
10169 | ||
1306a742 | 10170 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 10171 | |
19e6b90e | 10172 | void * |
1306a742 | 10173 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
10174 | { |
10175 | /* Check for overflow. */ | |
10176 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10177 | { |
dda8d76d NC |
10178 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
10179 | (long) nmemb); | |
8490fb40 NC |
10180 | xexit (1); |
10181 | } | |
82b1b41b | 10182 | |
1306a742 | 10183 | return xcalloc (nmemb, size); |
19e6b90e L |
10184 | } |
10185 | ||
dda8d76d NC |
10186 | static unsigned long |
10187 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
10188 | const unsigned char * buf, | |
10189 | bfd_size_type len) | |
10190 | { | |
10191 | static const unsigned long crc32_table[256] = | |
10192 | { | |
10193 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
10194 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
10195 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
10196 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
10197 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
10198 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
10199 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
10200 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
10201 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
10202 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
10203 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
10204 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
10205 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
10206 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
10207 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
10208 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
10209 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
10210 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
10211 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
10212 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
10213 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
10214 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
10215 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
10216 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
10217 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
10218 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
10219 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
10220 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
10221 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
10222 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
10223 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
10224 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
10225 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
10226 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
10227 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
10228 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
10229 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
10230 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
10231 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
10232 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
10233 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
10234 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
10235 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
10236 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
10237 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
10238 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
10239 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
10240 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
10241 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
10242 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
10243 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
10244 | 0x2d02ef8d | |
10245 | }; | |
10246 | const unsigned char *end; | |
10247 | ||
10248 | crc = ~crc & 0xffffffff; | |
10249 | for (end = buf + len; buf < end; ++ buf) | |
10250 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
10251 | return ~crc & 0xffffffff; | |
10252 | } | |
10253 | ||
10254 | typedef bfd_boolean (* check_func_type) (const char *, void *); | |
10255 | typedef const char * (* parse_func_type) (struct dwarf_section *, void *); | |
10256 | ||
10257 | static bfd_boolean | |
10258 | check_gnu_debuglink (const char * pathname, void * crc_pointer) | |
10259 | { | |
10260 | static unsigned char buffer [8 * 1024]; | |
10261 | FILE * f; | |
10262 | bfd_size_type count; | |
10263 | unsigned long crc = 0; | |
10264 | void * sep_data; | |
10265 | ||
10266 | sep_data = open_debug_file (pathname); | |
10267 | if (sep_data == NULL) | |
10268 | return FALSE; | |
10269 | ||
10270 | /* Yes - we are opening the file twice... */ | |
10271 | f = fopen (pathname, "rb"); | |
10272 | if (f == NULL) | |
10273 | { | |
10274 | /* Paranoia: This should never happen. */ | |
10275 | close_debug_file (sep_data); | |
10276 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
10277 | return FALSE; | |
10278 | } | |
10279 | ||
10280 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
10281 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
10282 | ||
10283 | fclose (f); | |
10284 | ||
10285 | if (crc != * (unsigned long *) crc_pointer) | |
10286 | { | |
10287 | close_debug_file (sep_data); | |
10288 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
10289 | pathname); | |
10290 | return FALSE; | |
10291 | } | |
10292 | ||
10293 | return TRUE; | |
10294 | } | |
10295 | ||
10296 | static const char * | |
10297 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
10298 | { | |
10299 | const char * name; | |
10300 | unsigned int crc_offset; | |
10301 | unsigned long * crc32 = (unsigned long *) data; | |
10302 | ||
10303 | /* The name is first. | |
10304 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
10305 | name = (const char *) section->start; | |
10306 | ||
39f0547e | 10307 | |
dda8d76d NC |
10308 | crc_offset = strnlen (name, section->size) + 1; |
10309 | crc_offset = (crc_offset + 3) & ~3; | |
10310 | if (crc_offset + 4 > section->size) | |
10311 | return NULL; | |
10312 | ||
10313 | * crc32 = byte_get (section->start + crc_offset, 4); | |
10314 | return name; | |
10315 | } | |
10316 | ||
10317 | static bfd_boolean | |
10318 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) | |
10319 | { | |
10320 | void * sep_data = open_debug_file (filename); | |
10321 | ||
10322 | if (sep_data == NULL) | |
10323 | return FALSE; | |
10324 | ||
10325 | /* FIXME: We should now extract the build-id in the separate file | |
10326 | and check it... */ | |
10327 | ||
10328 | return TRUE; | |
10329 | } | |
10330 | ||
10331 | typedef struct build_id_data | |
10332 | { | |
10333 | bfd_size_type len; | |
10334 | const unsigned char * data; | |
10335 | } Build_id_data; | |
10336 | ||
10337 | static const char * | |
10338 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
10339 | { | |
10340 | const char * name; | |
10341 | bfd_size_type namelen; | |
10342 | bfd_size_type id_len; | |
10343 | Build_id_data * build_id_data; | |
10344 | ||
10345 | /* The name is first. | |
10346 | The build-id follows immediately, with no padding, up to the section's end. */ | |
10347 | ||
10348 | name = (const char *) section->start; | |
10349 | namelen = strnlen (name, section->size) + 1; | |
10350 | if (namelen >= section->size) | |
10351 | return NULL; | |
10352 | ||
10353 | id_len = section->size - namelen; | |
10354 | if (id_len < 0x14) | |
10355 | return NULL; | |
10356 | ||
10357 | build_id_data = calloc (1, sizeof * build_id_data); | |
10358 | if (build_id_data == NULL) | |
10359 | return NULL; | |
10360 | ||
10361 | build_id_data->len = id_len; | |
10362 | build_id_data->data = section->start + namelen; | |
10363 | ||
10364 | * (Build_id_data **) data = build_id_data; | |
10365 | ||
10366 | return name; | |
10367 | } | |
10368 | ||
24841daa NC |
10369 | static void |
10370 | add_separate_debug_file (const char * filename, void * handle) | |
10371 | { | |
10372 | separate_info * i = xmalloc (sizeof * i); | |
10373 | ||
10374 | i->filename = filename; | |
10375 | i->handle = handle; | |
10376 | i->next = first_separate_info; | |
10377 | first_separate_info = i; | |
10378 | } | |
10379 | ||
dda8d76d NC |
10380 | static void * |
10381 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 10382 | struct dwarf_section * xlink, |
dda8d76d NC |
10383 | parse_func_type parse_func, |
10384 | check_func_type check_func, | |
10385 | void * func_data) | |
10386 | { | |
10387 | const char * separate_filename; | |
24841daa | 10388 | char * debug_filename; |
dda8d76d NC |
10389 | char * canon_dir; |
10390 | size_t canon_dirlen; | |
10391 | size_t dirlen; | |
10392 | ||
2b63c337 | 10393 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
10394 | { |
10395 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 10396 | xlink->name ? xlink->name : xlink->uncompressed_name); |
dda8d76d NC |
10397 | return FALSE; |
10398 | } | |
10399 | ||
10400 | /* Attempt to locate the separate file. | |
10401 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
10402 | ||
10403 | canon_dir = lrealpath (main_filename); | |
10404 | ||
10405 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) | |
10406 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
10407 | break; | |
10408 | canon_dir[canon_dirlen] = '\0'; | |
10409 | ||
10410 | #ifndef DEBUGDIR | |
10411 | #define DEBUGDIR "/lib/debug" | |
10412 | #endif | |
10413 | #ifndef EXTRA_DEBUG_ROOT1 | |
10414 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
10415 | #endif | |
10416 | #ifndef EXTRA_DEBUG_ROOT2 | |
10417 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
10418 | #endif | |
10419 | ||
24841daa NC |
10420 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
10421 | + canon_dirlen | |
10422 | + strlen (".debug/") | |
dda8d76d | 10423 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 10424 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
10425 | #endif |
10426 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 10427 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 10428 | #endif |
24841daa NC |
10429 | + strlen (separate_filename) |
10430 | + 1); | |
10431 | if (debug_filename == NULL) | |
dda8d76d NC |
10432 | { |
10433 | warn (_("Out of memory")); | |
3391569f | 10434 | free (canon_dir); |
dda8d76d NC |
10435 | return NULL; |
10436 | } | |
10437 | ||
10438 | /* First try in the current directory. */ | |
24841daa NC |
10439 | sprintf (debug_filename, "%s", separate_filename); |
10440 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10441 | goto found; |
10442 | ||
10443 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
10444 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10445 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10446 | goto found; |
10447 | ||
10448 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
10449 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10450 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10451 | goto found; |
10452 | ||
10453 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
10454 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10455 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10456 | goto found; |
10457 | ||
10458 | #ifdef EXTRA_DEBUG_ROOT1 | |
10459 | /* Try the first extra debug file root. */ | |
24841daa NC |
10460 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10461 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 10462 | goto found; |
39f0547e NC |
10463 | |
10464 | /* Try the first extra debug file root. */ | |
10465 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
10466 | if (check_func (debug_filename, func_data)) | |
10467 | goto found; | |
dda8d76d NC |
10468 | #endif |
10469 | ||
10470 | #ifdef EXTRA_DEBUG_ROOT2 | |
10471 | /* Try the second extra debug file root. */ | |
24841daa NC |
10472 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10473 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10474 | goto found; |
10475 | #endif | |
10476 | ||
24841daa NC |
10477 | /* Then try in the global debug_filename directory. */ |
10478 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
10479 | dirlen = strlen (DEBUGDIR) - 1; |
10480 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
10481 | strcat (debug_filename, "/"); |
10482 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 10483 | |
24841daa | 10484 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
10485 | goto found; |
10486 | ||
10487 | /* Failed to find the file. */ | |
10488 | warn (_("could not find separate debug file '%s'\n"), separate_filename); | |
24841daa | 10489 | warn (_("tried: %s\n"), debug_filename); |
dda8d76d NC |
10490 | |
10491 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa NC |
10492 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10493 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10494 | #endif |
10495 | ||
10496 | #ifdef EXTRA_DEBUG_ROOT1 | |
39f0547e NC |
10497 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); |
10498 | warn (_("tried: %s\n"), debug_filename); | |
10499 | ||
24841daa NC |
10500 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10501 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10502 | #endif |
10503 | ||
24841daa NC |
10504 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10505 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10506 | |
24841daa NC |
10507 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10508 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10509 | |
24841daa NC |
10510 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10511 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10512 | |
24841daa NC |
10513 | sprintf (debug_filename, "%s", separate_filename); |
10514 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10515 | |
10516 | free (canon_dir); | |
24841daa | 10517 | free (debug_filename); |
dda8d76d NC |
10518 | return NULL; |
10519 | ||
10520 | found: | |
10521 | free (canon_dir); | |
10522 | ||
24841daa NC |
10523 | void * debug_handle; |
10524 | ||
dda8d76d | 10525 | /* Now open the file.... */ |
24841daa | 10526 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 10527 | { |
24841daa NC |
10528 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
10529 | free (debug_filename); | |
dda8d76d NC |
10530 | return FALSE; |
10531 | } | |
10532 | ||
10533 | /* FIXME: We do not check to see if there are any other separate debug info | |
10534 | files that would also match. */ | |
10535 | ||
24841daa NC |
10536 | printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debug_filename); |
10537 | add_separate_debug_file (debug_filename, debug_handle); | |
dda8d76d | 10538 | |
24841daa | 10539 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 10540 | the structure returned by open_debug_file(). */ |
24841daa | 10541 | return debug_handle; |
dda8d76d NC |
10542 | } |
10543 | ||
d85bf2ba NC |
10544 | /* Attempt to load a separate dwarf object file. */ |
10545 | ||
10546 | static void * | |
24841daa | 10547 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 10548 | { |
24841daa NC |
10549 | char * separate_filename; |
10550 | void * separate_handle; | |
d85bf2ba NC |
10551 | |
10552 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
24841daa NC |
10553 | separate_filename = concat (dir, "/", name, NULL); |
10554 | if (separate_filename == NULL) | |
d85bf2ba NC |
10555 | { |
10556 | warn (_("Out of memory allocating dwo filename\n")); | |
10557 | return NULL; | |
10558 | } | |
10559 | ||
24841daa | 10560 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 10561 | { |
24841daa NC |
10562 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
10563 | free (separate_filename); | |
d85bf2ba NC |
10564 | return NULL; |
10565 | } | |
10566 | ||
10567 | /* FIXME: We should check the dwo_id. */ | |
10568 | ||
24841daa NC |
10569 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
10570 | add_separate_debug_file (separate_filename, separate_handle); | |
10571 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
10572 | return separate_handle; | |
d85bf2ba NC |
10573 | } |
10574 | ||
24841daa NC |
10575 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
10576 | Returns TRUE if any were found, FALSE otherwise. | |
10577 | If TRUE is returned then the linked list starting at first_separate_info | |
10578 | will be populated with open file handles. */ | |
dda8d76d | 10579 | |
24841daa NC |
10580 | bfd_boolean |
10581 | load_separate_debug_files (void * file, const char * filename) | |
dda8d76d | 10582 | { |
8de3a6e2 NC |
10583 | /* Skip this operation if we are not interested in debug links. */ |
10584 | if (! do_follow_links && ! do_debug_links) | |
24841daa | 10585 | return FALSE; |
8de3a6e2 | 10586 | |
24841daa | 10587 | /* See if there are any dwo links. */ |
d85bf2ba NC |
10588 | if (load_debug_section (str, file) |
10589 | && load_debug_section (abbrev, file) | |
10590 | && load_debug_section (info, file)) | |
10591 | { | |
24841daa | 10592 | free_dwo_info (); |
d85bf2ba NC |
10593 | |
10594 | if (process_debug_info (& debug_displays[info].section, file, abbrev, TRUE, FALSE)) | |
10595 | { | |
24841daa NC |
10596 | bfd_boolean introduced = FALSE; |
10597 | dwo_info * dwinfo; | |
10598 | const char * dir = NULL; | |
10599 | const char * id = NULL; | |
10600 | ||
10601 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 10602 | { |
24841daa | 10603 | switch (dwinfo->type) |
d85bf2ba | 10604 | { |
24841daa NC |
10605 | case DWO_NAME: |
10606 | if (do_debug_links) | |
10607 | { | |
10608 | if (! introduced) | |
10609 | { | |
10610 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
10611 | debug_displays [info].section.uncompressed_name); | |
10612 | introduced = TRUE; | |
10613 | } | |
d85bf2ba | 10614 | |
24841daa NC |
10615 | printf (_(" Name: %s\n"), dwinfo->value); |
10616 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); | |
10617 | if (id != NULL) | |
10618 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
10619 | else | |
10620 | printf (_(" ID: <unknown>\n")); | |
10621 | printf ("\n\n"); | |
10622 | } | |
10623 | ||
10624 | if (do_follow_links) | |
10625 | load_dwo_file (filename, dwinfo->value, dir, id); | |
10626 | break; | |
10627 | ||
10628 | case DWO_DIR: | |
10629 | dir = dwinfo->value; | |
10630 | break; | |
10631 | ||
10632 | case DWO_ID: | |
10633 | id = dwinfo->value; | |
10634 | break; | |
10635 | ||
10636 | default: | |
10637 | error (_("Unexpected DWO INFO type")); | |
10638 | break; | |
10639 | } | |
d85bf2ba NC |
10640 | } |
10641 | } | |
10642 | } | |
10643 | ||
dda8d76d | 10644 | if (! do_follow_links) |
8de3a6e2 NC |
10645 | /* The other debug links will be displayed by display_debug_links() |
10646 | so we do not need to do any further processing here. */ | |
24841daa | 10647 | return FALSE; |
dda8d76d NC |
10648 | |
10649 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
10650 | /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */ | |
10651 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ | |
d85bf2ba | 10652 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 10653 | |
dda8d76d NC |
10654 | if (load_debug_section (gnu_debugaltlink, file)) |
10655 | { | |
10656 | Build_id_data * build_id_data; | |
10657 | ||
24841daa NC |
10658 | load_separate_debug_info (filename, |
10659 | & debug_displays[gnu_debugaltlink].section, | |
10660 | parse_gnu_debugaltlink, | |
10661 | check_gnu_debugaltlink, | |
10662 | & build_id_data); | |
dda8d76d NC |
10663 | } |
10664 | ||
10665 | if (load_debug_section (gnu_debuglink, file)) | |
10666 | { | |
10667 | unsigned long crc32; | |
10668 | ||
24841daa NC |
10669 | load_separate_debug_info (filename, |
10670 | & debug_displays[gnu_debuglink].section, | |
10671 | parse_gnu_debuglink, | |
10672 | check_gnu_debuglink, | |
10673 | & crc32); | |
dda8d76d NC |
10674 | } |
10675 | ||
24841daa NC |
10676 | if (first_separate_info != NULL) |
10677 | return TRUE; | |
10678 | ||
dda8d76d | 10679 | do_follow_links = 0; |
24841daa | 10680 | return FALSE; |
dda8d76d NC |
10681 | } |
10682 | ||
19e6b90e L |
10683 | void |
10684 | free_debug_memory (void) | |
10685 | { | |
3f5e193b | 10686 | unsigned int i; |
19e6b90e L |
10687 | |
10688 | free_abbrevs (); | |
10689 | ||
10690 | for (i = 0; i < max; i++) | |
3f5e193b | 10691 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 10692 | |
cc86f28f | 10693 | if (debug_information != NULL) |
19e6b90e | 10694 | { |
cc86f28f | 10695 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) |
19e6b90e | 10696 | { |
cc86f28f | 10697 | for (i = 0; i < num_debug_info_entries; i++) |
19e6b90e | 10698 | { |
cc86f28f NC |
10699 | if (!debug_information [i].max_loc_offsets) |
10700 | { | |
10701 | free (debug_information [i].loc_offsets); | |
10702 | free (debug_information [i].have_frame_base); | |
10703 | } | |
10704 | if (!debug_information [i].max_range_lists) | |
10705 | free (debug_information [i].range_lists); | |
19e6b90e | 10706 | } |
19e6b90e L |
10707 | } |
10708 | free (debug_information); | |
10709 | debug_information = NULL; | |
82b1b41b | 10710 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 10711 | } |
dda8d76d | 10712 | |
24841daa NC |
10713 | separate_info * d; |
10714 | separate_info * next; | |
dda8d76d | 10715 | |
24841daa NC |
10716 | for (d = first_separate_info; d != NULL; d = next) |
10717 | { | |
10718 | close_debug_file (d->handle); | |
10719 | free ((void *) d->filename); | |
10720 | next = d->next; | |
10721 | free ((void *) d); | |
dda8d76d | 10722 | } |
24841daa NC |
10723 | first_separate_info = NULL; |
10724 | ||
10725 | free_dwo_info (); | |
19e6b90e L |
10726 | } |
10727 | ||
4cb93e3b TG |
10728 | void |
10729 | dwarf_select_sections_by_names (const char *names) | |
10730 | { | |
10731 | typedef struct | |
10732 | { | |
10733 | const char * option; | |
10734 | int * variable; | |
f9f0e732 | 10735 | int val; |
4cb93e3b TG |
10736 | } |
10737 | debug_dump_long_opts; | |
10738 | ||
10739 | static const debug_dump_long_opts opts_table [] = | |
10740 | { | |
10741 | /* Please keep this table alpha- sorted. */ | |
10742 | { "Ranges", & do_debug_ranges, 1 }, | |
10743 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 10744 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 10745 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
10746 | { "cu_index", & do_debug_cu_index, 1 }, |
10747 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 10748 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
10749 | { "frames", & do_debug_frames, 1 }, |
10750 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
10751 | /* The special .gdb_index section. */ |
10752 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
10753 | { "info", & do_debug_info, 1 }, |
10754 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 10755 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
10756 | { "loc", & do_debug_loc, 1 }, |
10757 | { "macro", & do_debug_macinfo, 1 }, | |
10758 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 10759 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 10760 | /* This entry is for compatibility |
4cb93e3b TG |
10761 | with earlier versions of readelf. */ |
10762 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 10763 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 10764 | { "str", & do_debug_str, 1 }, |
6f875884 TG |
10765 | /* These trace_* sections are used by Itanium VMS. */ |
10766 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
10767 | { "trace_aranges", & do_trace_aranges, 1 }, | |
10768 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
10769 | { NULL, NULL, 0 } |
10770 | }; | |
10771 | ||
10772 | const char *p; | |
467c65bc | 10773 | |
4cb93e3b TG |
10774 | p = names; |
10775 | while (*p) | |
10776 | { | |
10777 | const debug_dump_long_opts * entry; | |
467c65bc | 10778 | |
4cb93e3b TG |
10779 | for (entry = opts_table; entry->option; entry++) |
10780 | { | |
10781 | size_t len = strlen (entry->option); | |
467c65bc | 10782 | |
4cb93e3b TG |
10783 | if (strncmp (p, entry->option, len) == 0 |
10784 | && (p[len] == ',' || p[len] == '\0')) | |
10785 | { | |
10786 | * entry->variable |= entry->val; | |
467c65bc | 10787 | |
4cb93e3b TG |
10788 | /* The --debug-dump=frames-interp option also |
10789 | enables the --debug-dump=frames option. */ | |
10790 | if (do_debug_frames_interp) | |
10791 | do_debug_frames = 1; | |
10792 | ||
10793 | p += len; | |
10794 | break; | |
10795 | } | |
10796 | } | |
467c65bc | 10797 | |
4cb93e3b TG |
10798 | if (entry->option == NULL) |
10799 | { | |
10800 | warn (_("Unrecognized debug option '%s'\n"), p); | |
10801 | p = strchr (p, ','); | |
10802 | if (p == NULL) | |
10803 | break; | |
10804 | } | |
467c65bc | 10805 | |
4cb93e3b TG |
10806 | if (*p == ',') |
10807 | p++; | |
10808 | } | |
10809 | } | |
10810 | ||
10811 | void | |
10812 | dwarf_select_sections_by_letters (const char *letters) | |
10813 | { | |
91d6fa6a | 10814 | unsigned int lindex = 0; |
4cb93e3b | 10815 | |
91d6fa6a NC |
10816 | while (letters[lindex]) |
10817 | switch (letters[lindex++]) | |
4cb93e3b | 10818 | { |
dda8d76d NC |
10819 | case 'A': do_debug_addr = 1; break; |
10820 | case 'a': do_debug_abbrevs = 1; break; | |
10821 | case 'c': do_debug_cu_index = 1; break; | |
10822 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
10823 | case 'f': do_debug_frames = 1; break; | |
10824 | case 'g': do_gdb_index = 1; break; | |
10825 | case 'i': do_debug_info = 1; break; | |
10826 | case 'K': do_follow_links = 1; break; | |
10827 | case 'k': do_debug_links = 1; break; | |
10828 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
10829 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
10830 | case 'm': do_debug_macinfo = 1; break; | |
10831 | case 'o': do_debug_loc = 1; break; | |
10832 | case 'p': do_debug_pubnames = 1; break; | |
10833 | case 'R': do_debug_ranges = 1; break; | |
10834 | case 'r': do_debug_aranges = 1; break; | |
10835 | case 's': do_debug_str = 1; break; | |
10836 | case 'T': do_trace_aranges = 1; break; | |
10837 | case 't': do_debug_pubtypes = 1; break; | |
10838 | case 'U': do_trace_info = 1; break; | |
10839 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 10840 | |
4cb93e3b | 10841 | default: |
7cc78d07 | 10842 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
10843 | break; |
10844 | } | |
10845 | } | |
10846 | ||
10847 | void | |
10848 | dwarf_select_sections_all (void) | |
10849 | { | |
10850 | do_debug_info = 1; | |
10851 | do_debug_abbrevs = 1; | |
10852 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
10853 | do_debug_pubnames = 1; | |
f9f0e732 | 10854 | do_debug_pubtypes = 1; |
4cb93e3b TG |
10855 | do_debug_aranges = 1; |
10856 | do_debug_ranges = 1; | |
10857 | do_debug_frames = 1; | |
10858 | do_debug_macinfo = 1; | |
10859 | do_debug_str = 1; | |
10860 | do_debug_loc = 1; | |
5bbdf3d5 | 10861 | do_gdb_index = 1; |
6f875884 TG |
10862 | do_trace_info = 1; |
10863 | do_trace_abbrevs = 1; | |
10864 | do_trace_aranges = 1; | |
657d0d47 CC |
10865 | do_debug_addr = 1; |
10866 | do_debug_cu_index = 1; | |
dda8d76d NC |
10867 | do_follow_links = 1; |
10868 | do_debug_links = 1; | |
4cb93e3b TG |
10869 | } |
10870 | ||
dda8d76d NC |
10871 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL |
10872 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL | |
10873 | ||
10874 | /* N.B. The order here must match the order in section_display_enum. */ | |
10875 | ||
19e6b90e L |
10876 | struct dwarf_section_display debug_displays[] = |
10877 | { | |
dda8d76d NC |
10878 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, |
10879 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE }, | |
10880 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
10881 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE }, | |
10882 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
10883 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE }, | |
10884 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, | |
10885 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
10886 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
10887 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
10888 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
10889 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
10890 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10891 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10892 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE }, | |
10893 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, | |
10894 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
10895 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
10896 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10897 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10898 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE }, | |
10899 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10900 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE }, | |
10901 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE }, | |
10902 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE }, | |
10903 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE }, | |
10904 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE }, | |
10905 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE }, | |
10906 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
10907 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE }, | |
10908 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
10909 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10910 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
10911 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
10912 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE }, | |
10913 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, | |
10914 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, | |
10915 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE }, | |
10916 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
10917 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
10918 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
10919 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
10920 | /* Separate debug info files can containt their own .debug_str section, | |
10921 | and this might be in *addition* to a .debug_str section already present | |
10922 | in the main file. Hence we need to have two entries for .debug_str. */ | |
10923 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
19e6b90e | 10924 | }; |
b451e98a JK |
10925 | |
10926 | /* A static assertion. */ | |
10927 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |