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 JK |
40 | static const char *regname (unsigned int regno, int row); |
41 | ||
19e6b90e L |
42 | static int have_frame_base; |
43 | static int need_base_address; | |
44 | ||
19e6b90e | 45 | static unsigned int num_debug_info_entries = 0; |
82b1b41b | 46 | static unsigned int alloc_num_debug_info_entries = 0; |
19e6b90e | 47 | static debug_info *debug_information = NULL; |
cc86f28f NC |
48 | /* Special value for num_debug_info_entries to indicate |
49 | that the .debug_info section could not be loaded/parsed. */ | |
50 | #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 | |
19e6b90e | 51 | |
24841daa NC |
52 | /* A .debug_info section can contain multiple links to separate |
53 | DWO object files. We use these structures to record these links. */ | |
54 | typedef enum dwo_type | |
55 | { | |
56 | DWO_NAME, | |
57 | DWO_DIR, | |
58 | DWO_ID | |
59 | } dwo_type; | |
60 | ||
61 | typedef struct dwo_info | |
62 | { | |
63 | dwo_type type; | |
64 | const char * value; | |
65 | struct dwo_info * next; | |
66 | } dwo_info; | |
67 | ||
68 | static dwo_info * first_dwo_info = NULL; | |
69 | static bfd_boolean need_dwo_info; | |
70 | ||
71 | separate_info * first_separate_info = NULL; | |
d85bf2ba | 72 | |
77ef8654 | 73 | unsigned int eh_addr_size; |
19e6b90e L |
74 | |
75 | int do_debug_info; | |
76 | int do_debug_abbrevs; | |
77 | int do_debug_lines; | |
78 | int do_debug_pubnames; | |
f9f0e732 | 79 | int do_debug_pubtypes; |
19e6b90e L |
80 | int do_debug_aranges; |
81 | int do_debug_ranges; | |
82 | int do_debug_frames; | |
83 | int do_debug_frames_interp; | |
84 | int do_debug_macinfo; | |
85 | int do_debug_str; | |
86 | int do_debug_loc; | |
5bbdf3d5 | 87 | int do_gdb_index; |
6f875884 TG |
88 | int do_trace_info; |
89 | int do_trace_abbrevs; | |
90 | int do_trace_aranges; | |
657d0d47 CC |
91 | int do_debug_addr; |
92 | int do_debug_cu_index; | |
a262ae96 | 93 | int do_wide; |
dda8d76d NC |
94 | int do_debug_links; |
95 | int do_follow_links; | |
19e6b90e | 96 | |
fd2f0033 TT |
97 | int dwarf_cutoff_level = -1; |
98 | unsigned long dwarf_start_die; | |
99 | ||
4723351a CC |
100 | int dwarf_check = 0; |
101 | ||
9f272209 AO |
102 | /* Convenient constant, to avoid having to cast -1 to dwarf_vma when |
103 | testing whether e.g. a locview list is present. */ | |
104 | static const dwarf_vma vm1 = -1; | |
105 | ||
341f9135 CC |
106 | /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
107 | sections. For version 1 package files, each set is stored in SHNDX_POOL | |
108 | as a zero-terminated list of section indexes comprising one set of debug | |
109 | sections from a .dwo file. */ | |
110 | ||
341f9135 CC |
111 | static unsigned int *shndx_pool = NULL; |
112 | static unsigned int shndx_pool_size = 0; | |
113 | static unsigned int shndx_pool_used = 0; | |
114 | ||
115 | /* For version 2 package files, each set contains an array of section offsets | |
116 | and an array of section sizes, giving the offset and size of the | |
117 | contribution from a CU or TU within one of the debug sections. | |
118 | When displaying debug info from a package file, we need to use these | |
119 | tables to locate the corresponding contributions to each section. */ | |
120 | ||
121 | struct cu_tu_set | |
122 | { | |
ec1b0fbb NC |
123 | uint64_t signature; |
124 | dwarf_vma section_offsets[DW_SECT_MAX]; | |
125 | size_t section_sizes[DW_SECT_MAX]; | |
341f9135 CC |
126 | }; |
127 | ||
128 | static int cu_count = 0; | |
129 | static int tu_count = 0; | |
130 | static struct cu_tu_set *cu_sets = NULL; | |
131 | static struct cu_tu_set *tu_sets = NULL; | |
132 | ||
43a444f9 | 133 | static bfd_boolean load_cu_tu_indexes (void *); |
341f9135 | 134 | |
ec1b0fbb NC |
135 | /* An array that indicates for a given level of CU nesting whether |
136 | the latest DW_AT_type seen for that level was a signed type or | |
137 | an unsigned type. */ | |
138 | #define MAX_CU_NESTING (1 << 8) | |
139 | static bfd_boolean level_type_signed[MAX_CU_NESTING]; | |
140 | ||
4cb93e3b TG |
141 | /* Values for do_debug_lines. */ |
142 | #define FLAG_DEBUG_LINES_RAW 1 | |
143 | #define FLAG_DEBUG_LINES_DECODED 2 | |
144 | ||
77ef8654 | 145 | static unsigned int |
f1c4cc75 RH |
146 | size_of_encoded_value (int encoding) |
147 | { | |
148 | switch (encoding & 0x7) | |
149 | { | |
150 | default: /* ??? */ | |
151 | case 0: return eh_addr_size; | |
152 | case 2: return 2; | |
153 | case 3: return 4; | |
154 | case 4: return 8; | |
155 | } | |
156 | } | |
157 | ||
158 | static dwarf_vma | |
041830e0 | 159 | get_encoded_value (unsigned char **pdata, |
bad62cf5 | 160 | int encoding, |
041830e0 NC |
161 | struct dwarf_section *section, |
162 | unsigned char * end) | |
f1c4cc75 | 163 | { |
041830e0 | 164 | unsigned char * data = * pdata; |
6937bb54 | 165 | unsigned int size = size_of_encoded_value (encoding); |
bad62cf5 | 166 | dwarf_vma val; |
f1c4cc75 | 167 | |
041830e0 NC |
168 | if (data + size >= end) |
169 | { | |
170 | warn (_("Encoded value extends past end of section\n")); | |
171 | * pdata = end; | |
172 | return 0; | |
173 | } | |
174 | ||
6937bb54 NC |
175 | /* PR 17512: file: 002-829853-0.004. */ |
176 | if (size > 8) | |
177 | { | |
178 | warn (_("Encoded size of %d is too large to read\n"), size); | |
179 | * pdata = end; | |
180 | return 0; | |
181 | } | |
182 | ||
0a9d414a NC |
183 | /* PR 17512: file: 1085-5603-0.004. */ |
184 | if (size == 0) | |
185 | { | |
186 | warn (_("Encoded size of 0 is too small to read\n")); | |
187 | * pdata = end; | |
188 | return 0; | |
189 | } | |
190 | ||
f1c4cc75 | 191 | if (encoding & DW_EH_PE_signed) |
bad62cf5 | 192 | val = byte_get_signed (data, size); |
f1c4cc75 | 193 | else |
bad62cf5 AM |
194 | val = byte_get (data, size); |
195 | ||
196 | if ((encoding & 0x70) == DW_EH_PE_pcrel) | |
197 | val += section->address + (data - section->start); | |
041830e0 NC |
198 | |
199 | * pdata = data + size; | |
bad62cf5 | 200 | return val; |
f1c4cc75 RH |
201 | } |
202 | ||
4c219c2e AM |
203 | #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG |
204 | # ifndef __MINGW32__ | |
205 | # define DWARF_VMA_FMT "ll" | |
206 | # define DWARF_VMA_FMT_LONG "%16.16llx" | |
207 | # else | |
208 | # define DWARF_VMA_FMT "I64" | |
209 | # define DWARF_VMA_FMT_LONG "%016I64x" | |
210 | # endif | |
2e14fae2 | 211 | #else |
4c219c2e AM |
212 | # define DWARF_VMA_FMT "l" |
213 | # define DWARF_VMA_FMT_LONG "%16.16lx" | |
2d9472a2 NC |
214 | #endif |
215 | ||
bf5117e3 NC |
216 | /* Convert a dwarf vma value into a string. Returns a pointer to a static |
217 | buffer containing the converted VALUE. The value is converted according | |
218 | to the printf formating character FMTCH. If NUM_BYTES is non-zero then | |
219 | it specifies the maximum number of bytes to be displayed in the converted | |
220 | value and FMTCH is ignored - hex is always used. */ | |
467c65bc | 221 | |
47704ddf | 222 | static const char * |
bf5117e3 | 223 | dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
47704ddf KT |
224 | { |
225 | /* As dwarf_vmatoa is used more then once in a printf call | |
226 | for output, we are cycling through an fixed array of pointers | |
227 | for return address. */ | |
228 | static int buf_pos = 0; | |
467c65bc NC |
229 | static struct dwarf_vmatoa_buf |
230 | { | |
47704ddf KT |
231 | char place[64]; |
232 | } buf[16]; | |
47704ddf KT |
233 | char *ret; |
234 | ||
47704ddf | 235 | ret = buf[buf_pos++].place; |
467c65bc | 236 | buf_pos %= ARRAY_SIZE (buf); |
47704ddf | 237 | |
bf5117e3 NC |
238 | if (num_bytes) |
239 | { | |
222c2bf0 | 240 | /* Printf does not have a way of specifying a maximum field width for an |
bf5117e3 NC |
241 | integer value, so we print the full value into a buffer and then select |
242 | the precision we need. */ | |
243 | snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); | |
244 | if (num_bytes > 8) | |
245 | num_bytes = 8; | |
246 | return ret + (16 - 2 * num_bytes); | |
247 | } | |
248 | else | |
249 | { | |
250 | char fmt[32]; | |
251 | ||
0bae9e9e NC |
252 | if (fmtch) |
253 | sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); | |
254 | else | |
255 | sprintf (fmt, "%%%s", DWARF_VMA_FMT); | |
bf5117e3 NC |
256 | snprintf (ret, sizeof (buf[0].place), fmt, value); |
257 | return ret; | |
258 | } | |
259 | } | |
47704ddf | 260 | |
bf5117e3 NC |
261 | static inline const char * |
262 | dwarf_vmatoa (const char * fmtch, dwarf_vma value) | |
263 | { | |
264 | return dwarf_vmatoa_1 (fmtch, value, 0); | |
265 | } | |
266 | ||
267 | /* Print a dwarf_vma value (typically an address, offset or length) in | |
268 | hexadecimal format, followed by a space. The length of the VALUE (and | |
269 | hence the precision displayed) is determined by the NUM_BYTES parameter. */ | |
270 | ||
271 | static void | |
272 | print_dwarf_vma (dwarf_vma value, unsigned num_bytes) | |
273 | { | |
274 | printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); | |
47704ddf KT |
275 | } |
276 | ||
9f272209 AO |
277 | /* Print a view number in hexadecimal value, with the same width |
278 | print_dwarf_vma would have printed it with the same num_bytes. | |
279 | Print blanks for zero view, unless force is nonzero. */ | |
280 | ||
281 | static void | |
282 | print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force) | |
283 | { | |
284 | int len; | |
285 | if (!num_bytes) | |
286 | len = 4; | |
287 | else | |
288 | len = num_bytes * 2; | |
289 | ||
290 | assert (value == (unsigned long) value); | |
291 | if (value || force) | |
292 | printf ("v%0*lx ", len - 1, (unsigned long) value); | |
293 | else | |
294 | printf ("%*s", len + 1, ""); | |
295 | } | |
296 | ||
74bc6052 CC |
297 | /* Format a 64-bit value, given as two 32-bit values, in hex. |
298 | For reentrancy, this uses a buffer provided by the caller. */ | |
299 | ||
300 | static const char * | |
301 | dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, | |
302 | unsigned int buf_len) | |
303 | { | |
304 | int len = 0; | |
305 | ||
306 | if (hvalue == 0) | |
307 | snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); | |
308 | else | |
309 | { | |
310 | len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); | |
311 | snprintf (buf + len, buf_len - len, | |
312 | "%08" DWARF_VMA_FMT "x", lvalue); | |
313 | } | |
314 | ||
315 | return buf; | |
316 | } | |
317 | ||
f6f0e17b NC |
318 | /* Read in a LEB128 encoded value starting at address DATA. |
319 | If SIGN is true, return a signed LEB128 value. | |
320 | If LENGTH_RETURN is not NULL, return in it the number of bytes read. | |
321 | No bytes will be read at address END or beyond. */ | |
322 | ||
467c65bc | 323 | dwarf_vma |
f6f0e17b NC |
324 | read_leb128 (unsigned char *data, |
325 | unsigned int *length_return, | |
326 | bfd_boolean sign, | |
327 | const unsigned char * const end) | |
19e6b90e | 328 | { |
467c65bc | 329 | dwarf_vma result = 0; |
19e6b90e L |
330 | unsigned int num_read = 0; |
331 | unsigned int shift = 0; | |
f6f0e17b | 332 | unsigned char byte = 0; |
19e6b90e | 333 | |
f6f0e17b | 334 | while (data < end) |
19e6b90e L |
335 | { |
336 | byte = *data++; | |
337 | num_read++; | |
338 | ||
467c65bc | 339 | result |= ((dwarf_vma) (byte & 0x7f)) << shift; |
19e6b90e L |
340 | |
341 | shift += 7; | |
f6f0e17b NC |
342 | if ((byte & 0x80) == 0) |
343 | break; | |
77ef8654 NC |
344 | |
345 | /* PR 17512: file: 0ca183b8. | |
346 | FIXME: Should we signal this error somehow ? */ | |
f641dd96 | 347 | if (shift >= sizeof (result) * 8) |
77ef8654 | 348 | break; |
19e6b90e | 349 | } |
19e6b90e L |
350 | |
351 | if (length_return != NULL) | |
352 | *length_return = num_read; | |
353 | ||
354 | if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) | |
c4e0beac | 355 | result |= -((dwarf_vma) 1 << shift); |
19e6b90e L |
356 | |
357 | return result; | |
358 | } | |
359 | ||
467c65bc | 360 | /* Create a signed version to avoid painful typecasts. */ |
f6f0e17b NC |
361 | static inline dwarf_signed_vma |
362 | read_sleb128 (unsigned char * data, | |
363 | unsigned int * length_return, | |
364 | const unsigned char * const end) | |
365 | { | |
366 | return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end); | |
367 | } | |
368 | ||
369 | static inline dwarf_vma | |
370 | read_uleb128 (unsigned char * data, | |
371 | unsigned int * length_return, | |
372 | const unsigned char * const end) | |
467c65bc | 373 | { |
f6f0e17b | 374 | return read_leb128 (data, length_return, FALSE, end); |
467c65bc NC |
375 | } |
376 | ||
7f2c8a1d NC |
377 | #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return |
378 | #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return | |
379 | ||
380 | #define READ_ULEB(var) \ | |
381 | do \ | |
382 | { \ | |
383 | dwarf_vma _val; \ | |
384 | \ | |
385 | (var) = _val = read_uleb128 (start, &length_return, end); \ | |
386 | if ((var) != _val) \ | |
66cfc0fd AM |
387 | error (_("Internal error: %s:%d: LEB value (%s) " \ |
388 | "too large for containing variable\n"), \ | |
389 | __FILE__, __LINE__, dwarf_vmatoa ("u", _val)); \ | |
7f2c8a1d NC |
390 | start += length_return; \ |
391 | } \ | |
392 | while (0) | |
393 | ||
394 | #define READ_SLEB(var) \ | |
395 | do \ | |
396 | { \ | |
397 | dwarf_signed_vma _val; \ | |
398 | \ | |
399 | (var) = _val = read_sleb128 (start, &length_return, end); \ | |
400 | if ((var) != _val) \ | |
66cfc0fd AM |
401 | error (_("Internal error: %s:%d: LEB value (%s) " \ |
402 | "too large for containing variable\n"), \ | |
403 | __FILE__, __LINE__, dwarf_vmatoa ("d", _val)); \ | |
7f2c8a1d NC |
404 | start += length_return; \ |
405 | } \ | |
406 | while (0) | |
407 | ||
d11ae95e NC |
408 | /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value. |
409 | Checks to make sure that the read will not reach or pass END | |
410 | and that VAL is big enough to hold AMOUNT bytes. */ | |
0c588247 NC |
411 | #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
412 | do \ | |
413 | { \ | |
414 | unsigned int amount = (AMOUNT); \ | |
34b9f729 NC |
415 | if (sizeof (VAL) < amount) \ |
416 | { \ | |
d3a49aa8 AM |
417 | error (ngettext ("internal error: attempt to read %d byte " \ |
418 | "of data in to %d sized variable", \ | |
419 | "internal error: attempt to read %d bytes " \ | |
420 | "of data in to %d sized variable", \ | |
421 | amount), \ | |
34b9f729 NC |
422 | amount, (int) sizeof (VAL)); \ |
423 | amount = sizeof (VAL); \ | |
424 | } \ | |
0c588247 NC |
425 | if (((PTR) + amount) >= (END)) \ |
426 | { \ | |
427 | if ((PTR) < (END)) \ | |
428 | amount = (END) - (PTR); \ | |
429 | else \ | |
430 | amount = 0; \ | |
431 | } \ | |
6937bb54 | 432 | if (amount == 0 || amount > 8) \ |
0c588247 | 433 | VAL = 0; \ |
6937bb54 NC |
434 | else \ |
435 | VAL = byte_get ((PTR), amount); \ | |
0c588247 NC |
436 | } \ |
437 | while (0) | |
438 | ||
d11ae95e | 439 | /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
440 | #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
441 | do \ | |
442 | { \ | |
443 | SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
444 | PTR += AMOUNT; \ | |
445 | } \ | |
446 | while (0) | |
447 | ||
d11ae95e | 448 | /* Like SAFE_BYTE_GET, but reads a signed value. */ |
0c588247 NC |
449 | #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
450 | do \ | |
451 | { \ | |
452 | unsigned int amount = (AMOUNT); \ | |
453 | if (((PTR) + amount) >= (END)) \ | |
454 | { \ | |
455 | if ((PTR) < (END)) \ | |
456 | amount = (END) - (PTR); \ | |
457 | else \ | |
458 | amount = 0; \ | |
459 | } \ | |
460 | if (amount) \ | |
461 | VAL = byte_get_signed ((PTR), amount); \ | |
462 | else \ | |
463 | VAL = 0; \ | |
464 | } \ | |
465 | while (0) | |
466 | ||
d11ae95e | 467 | /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */ |
0c588247 NC |
468 | #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
469 | do \ | |
470 | { \ | |
471 | SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ | |
472 | PTR += AMOUNT; \ | |
473 | } \ | |
474 | while (0) | |
475 | ||
476 | #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ | |
477 | do \ | |
478 | { \ | |
87bc83b3 | 479 | if (((PTR) + 8) <= (END)) \ |
0c588247 NC |
480 | { \ |
481 | byte_get_64 ((PTR), (HIGH), (LOW)); \ | |
482 | } \ | |
483 | else \ | |
484 | { \ | |
0c588247 NC |
485 | * (LOW) = * (HIGH) = 0; \ |
486 | } \ | |
487 | } \ | |
488 | while (0) | |
489 | ||
19e6b90e L |
490 | typedef struct State_Machine_Registers |
491 | { | |
467c65bc | 492 | dwarf_vma address; |
ba8826a8 | 493 | unsigned int view; |
19e6b90e L |
494 | unsigned int file; |
495 | unsigned int line; | |
496 | unsigned int column; | |
497 | int is_stmt; | |
498 | int basic_block; | |
a233b20c JJ |
499 | unsigned char op_index; |
500 | unsigned char end_sequence; | |
ba8826a8 AO |
501 | /* This variable hold the number of the last entry seen |
502 | in the File Table. */ | |
19e6b90e L |
503 | unsigned int last_file_entry; |
504 | } SMR; | |
505 | ||
506 | static SMR state_machine_regs; | |
507 | ||
508 | static void | |
509 | reset_state_machine (int is_stmt) | |
510 | { | |
511 | state_machine_regs.address = 0; | |
ba8826a8 | 512 | state_machine_regs.view = 0; |
a233b20c | 513 | state_machine_regs.op_index = 0; |
19e6b90e L |
514 | state_machine_regs.file = 1; |
515 | state_machine_regs.line = 1; | |
516 | state_machine_regs.column = 0; | |
517 | state_machine_regs.is_stmt = is_stmt; | |
518 | state_machine_regs.basic_block = 0; | |
519 | state_machine_regs.end_sequence = 0; | |
520 | state_machine_regs.last_file_entry = 0; | |
521 | } | |
522 | ||
523 | /* Handled an extend line op. | |
524 | Returns the number of bytes read. */ | |
525 | ||
526 | static int | |
f6f0e17b NC |
527 | process_extended_line_op (unsigned char * data, |
528 | int is_stmt, | |
529 | unsigned char * end) | |
19e6b90e L |
530 | { |
531 | unsigned char op_code; | |
532 | unsigned int bytes_read; | |
533 | unsigned int len; | |
534 | unsigned char *name; | |
143a3db0 | 535 | unsigned char *orig_data = data; |
f6f0e17b | 536 | dwarf_vma adr; |
19e6b90e | 537 | |
f6f0e17b | 538 | len = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
539 | data += bytes_read; |
540 | ||
e44c58ce | 541 | if (len == 0 || data == end || len > (uintptr_t) (end - data)) |
19e6b90e | 542 | { |
f41e4712 | 543 | warn (_("Badly formed extended line op encountered!\n")); |
19e6b90e L |
544 | return bytes_read; |
545 | } | |
546 | ||
547 | len += bytes_read; | |
548 | op_code = *data++; | |
549 | ||
550 | printf (_(" Extended opcode %d: "), op_code); | |
551 | ||
552 | switch (op_code) | |
553 | { | |
554 | case DW_LNE_end_sequence: | |
555 | printf (_("End of Sequence\n\n")); | |
556 | reset_state_machine (is_stmt); | |
557 | break; | |
558 | ||
559 | case DW_LNE_set_address: | |
6937bb54 NC |
560 | /* PR 17512: file: 002-100480-0.004. */ |
561 | if (len - bytes_read - 1 > 8) | |
77ef8654 NC |
562 | { |
563 | warn (_("Length (%d) of DW_LNE_set_address op is too long\n"), | |
564 | len - bytes_read - 1); | |
565 | adr = 0; | |
566 | } | |
567 | else | |
568 | SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end); | |
47704ddf | 569 | printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
19e6b90e | 570 | state_machine_regs.address = adr; |
ba8826a8 | 571 | state_machine_regs.view = 0; |
a233b20c | 572 | state_machine_regs.op_index = 0; |
19e6b90e L |
573 | break; |
574 | ||
575 | case DW_LNE_define_file: | |
143a3db0 | 576 | printf (_("define new File Table entry\n")); |
19e6b90e | 577 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
cc5914eb | 578 | printf (" %d\t", ++state_machine_regs.last_file_entry); |
f6f0e17b | 579 | |
d949ff56 NC |
580 | { |
581 | size_t l; | |
582 | ||
583 | name = data; | |
584 | l = strnlen ((char *) data, end - data); | |
585 | data += len + 1; | |
586 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
587 | data += bytes_read; | |
588 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
589 | data += bytes_read; | |
590 | printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
591 | data += bytes_read; | |
592 | printf ("%.*s\n\n", (int) l, name); | |
593 | } | |
f6f0e17b NC |
594 | |
595 | if (((unsigned int) (data - orig_data) != len) || data == end) | |
b4eb7656 | 596 | warn (_("DW_LNE_define_file: Bad opcode length\n")); |
19e6b90e L |
597 | break; |
598 | ||
ed4a4bdf | 599 | case DW_LNE_set_discriminator: |
47704ddf | 600 | printf (_("set Discriminator to %s\n"), |
f6f0e17b | 601 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
ed4a4bdf CC |
602 | break; |
603 | ||
e2a0d921 NC |
604 | /* HP extensions. */ |
605 | case DW_LNE_HP_negate_is_UV_update: | |
ed4a4bdf | 606 | printf ("DW_LNE_HP_negate_is_UV_update\n"); |
e2a0d921 NC |
607 | break; |
608 | case DW_LNE_HP_push_context: | |
ed4a4bdf | 609 | printf ("DW_LNE_HP_push_context\n"); |
e2a0d921 NC |
610 | break; |
611 | case DW_LNE_HP_pop_context: | |
ed4a4bdf | 612 | printf ("DW_LNE_HP_pop_context\n"); |
e2a0d921 NC |
613 | break; |
614 | case DW_LNE_HP_set_file_line_column: | |
ed4a4bdf | 615 | printf ("DW_LNE_HP_set_file_line_column\n"); |
e2a0d921 NC |
616 | break; |
617 | case DW_LNE_HP_set_routine_name: | |
ed4a4bdf | 618 | printf ("DW_LNE_HP_set_routine_name\n"); |
e2a0d921 NC |
619 | break; |
620 | case DW_LNE_HP_set_sequence: | |
ed4a4bdf | 621 | printf ("DW_LNE_HP_set_sequence\n"); |
e2a0d921 NC |
622 | break; |
623 | case DW_LNE_HP_negate_post_semantics: | |
ed4a4bdf | 624 | printf ("DW_LNE_HP_negate_post_semantics\n"); |
e2a0d921 NC |
625 | break; |
626 | case DW_LNE_HP_negate_function_exit: | |
ed4a4bdf | 627 | printf ("DW_LNE_HP_negate_function_exit\n"); |
e2a0d921 NC |
628 | break; |
629 | case DW_LNE_HP_negate_front_end_logical: | |
ed4a4bdf | 630 | printf ("DW_LNE_HP_negate_front_end_logical\n"); |
e2a0d921 NC |
631 | break; |
632 | case DW_LNE_HP_define_proc: | |
ed4a4bdf | 633 | printf ("DW_LNE_HP_define_proc\n"); |
e2a0d921 | 634 | break; |
43294ab7 TG |
635 | case DW_LNE_HP_source_file_correlation: |
636 | { | |
b4eb7656 AM |
637 | unsigned char *edata = data + len - bytes_read - 1; |
638 | ||
639 | printf ("DW_LNE_HP_source_file_correlation\n"); | |
640 | ||
641 | while (data < edata) | |
642 | { | |
643 | unsigned int opc; | |
644 | ||
645 | opc = read_uleb128 (data, & bytes_read, edata); | |
646 | data += bytes_read; | |
647 | ||
648 | switch (opc) | |
649 | { | |
650 | case DW_LNE_HP_SFC_formfeed: | |
651 | printf (" DW_LNE_HP_SFC_formfeed\n"); | |
652 | break; | |
653 | case DW_LNE_HP_SFC_set_listing_line: | |
654 | printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", | |
655 | dwarf_vmatoa ("u", | |
656 | read_uleb128 (data, & bytes_read, edata))); | |
657 | data += bytes_read; | |
658 | break; | |
659 | case DW_LNE_HP_SFC_associate: | |
660 | printf (" DW_LNE_HP_SFC_associate "); | |
661 | printf ("(%s", | |
662 | dwarf_vmatoa ("u", | |
663 | read_uleb128 (data, & bytes_read, edata))); | |
664 | data += bytes_read; | |
665 | printf (",%s", | |
666 | dwarf_vmatoa ("u", | |
667 | read_uleb128 (data, & bytes_read, edata))); | |
668 | data += bytes_read; | |
669 | printf (",%s)\n", | |
670 | dwarf_vmatoa ("u", | |
671 | read_uleb128 (data, & bytes_read, edata))); | |
672 | data += bytes_read; | |
673 | break; | |
674 | default: | |
675 | printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); | |
676 | data = edata; | |
677 | break; | |
678 | } | |
679 | } | |
43294ab7 TG |
680 | } |
681 | break; | |
cecf136e | 682 | |
19e6b90e | 683 | default: |
7e665af3 | 684 | { |
b4eb7656 AM |
685 | unsigned int rlen = len - bytes_read - 1; |
686 | ||
687 | if (op_code >= DW_LNE_lo_user | |
688 | /* The test against DW_LNW_hi_user is redundant due to | |
689 | the limited range of the unsigned char data type used | |
690 | for op_code. */ | |
691 | /*&& op_code <= DW_LNE_hi_user*/) | |
692 | printf (_("user defined: ")); | |
693 | else | |
694 | printf (_("UNKNOWN: ")); | |
695 | printf (_("length %d ["), rlen); | |
696 | for (; rlen; rlen--) | |
697 | printf (" %02x", *data++); | |
698 | printf ("]\n"); | |
7e665af3 | 699 | } |
19e6b90e L |
700 | break; |
701 | } | |
702 | ||
703 | return len; | |
704 | } | |
705 | ||
0c588247 | 706 | static const unsigned char * |
467c65bc | 707 | fetch_indirect_string (dwarf_vma offset) |
19e6b90e L |
708 | { |
709 | struct dwarf_section *section = &debug_displays [str].section; | |
d949ff56 | 710 | const unsigned char * ret; |
19e6b90e L |
711 | |
712 | if (section->start == NULL) | |
0c588247 | 713 | return (const unsigned char *) _("<no .debug_str section>"); |
19e6b90e | 714 | |
d949ff56 | 715 | if (offset >= section->size) |
19e6b90e | 716 | { |
467c65bc NC |
717 | warn (_("DW_FORM_strp offset too big: %s\n"), |
718 | dwarf_vmatoa ("x", offset)); | |
0c588247 | 719 | return (const unsigned char *) _("<offset is too big>"); |
19e6b90e L |
720 | } |
721 | ||
d949ff56 NC |
722 | ret = section->start + offset; |
723 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
724 | NUL byte. Since our caller is expecting to receive a well formed C | |
725 | string we test for the lack of a terminating byte here. */ | |
726 | if (strnlen ((const char *) ret, section->size - offset) | |
727 | == section->size - offset) | |
728 | ret = (const unsigned char *) | |
729 | _("<no NUL byte at end of .debug_str section>"); | |
730 | ||
731 | return ret; | |
19e6b90e L |
732 | } |
733 | ||
77145576 JK |
734 | static const unsigned char * |
735 | fetch_indirect_line_string (dwarf_vma offset) | |
736 | { | |
737 | struct dwarf_section *section = &debug_displays [line_str].section; | |
d949ff56 | 738 | const unsigned char * ret; |
77145576 JK |
739 | |
740 | if (section->start == NULL) | |
741 | return (const unsigned char *) _("<no .debug_line_str section>"); | |
742 | ||
d949ff56 | 743 | if (offset >= section->size) |
77145576 JK |
744 | { |
745 | warn (_("DW_FORM_line_strp offset too big: %s\n"), | |
746 | dwarf_vmatoa ("x", offset)); | |
747 | return (const unsigned char *) _("<offset is too big>"); | |
748 | } | |
749 | ||
d949ff56 NC |
750 | ret = section->start + offset; |
751 | /* Unfortunately we cannot rely upon the .debug_line_str section ending | |
752 | with a NUL byte. Since our caller is expecting to receive a well formed | |
753 | C string we test for the lack of a terminating byte here. */ | |
754 | if (strnlen ((const char *) ret, section->size - offset) | |
755 | == section->size - offset) | |
756 | ret = (const unsigned char *) | |
757 | _("<no NUL byte at end of .debug_line_str section>"); | |
758 | ||
759 | return ret; | |
77145576 JK |
760 | } |
761 | ||
4723351a | 762 | static const char * |
341f9135 | 763 | fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
d85bf2ba | 764 | dwarf_vma offset_size, bfd_boolean dwo) |
4723351a CC |
765 | { |
766 | enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; | |
767 | enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; | |
768 | struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; | |
769 | struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; | |
770 | dwarf_vma index_offset = idx * offset_size; | |
771 | dwarf_vma str_offset; | |
d949ff56 | 772 | const char * ret; |
4723351a CC |
773 | |
774 | if (index_section->start == NULL) | |
775 | return (dwo ? _("<no .debug_str_offsets.dwo section>") | |
776 | : _("<no .debug_str_offsets section>")); | |
777 | ||
341f9135 CC |
778 | if (this_set != NULL) |
779 | index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; | |
d949ff56 | 780 | if (index_offset >= index_section->size) |
4723351a CC |
781 | { |
782 | warn (_("DW_FORM_GNU_str_index offset too big: %s\n"), | |
783 | dwarf_vmatoa ("x", index_offset)); | |
784 | return _("<index offset is too big>"); | |
785 | } | |
786 | ||
787 | if (str_section->start == NULL) | |
788 | return (dwo ? _("<no .debug_str.dwo section>") | |
789 | : _("<no .debug_str section>")); | |
790 | ||
791 | str_offset = byte_get (index_section->start + index_offset, offset_size); | |
792 | str_offset -= str_section->address; | |
d949ff56 | 793 | if (str_offset >= str_section->size) |
4723351a CC |
794 | { |
795 | warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), | |
796 | dwarf_vmatoa ("x", str_offset)); | |
797 | return _("<indirect index offset is too big>"); | |
798 | } | |
799 | ||
d949ff56 NC |
800 | ret = (const char *) str_section->start + str_offset; |
801 | /* Unfortunately we cannot rely upon str_section ending with a NUL byte. | |
802 | Since our caller is expecting to receive a well formed C string we test | |
803 | for the lack of a terminating byte here. */ | |
804 | if (strnlen (ret, str_section->size - str_offset) | |
805 | == str_section->size - str_offset) | |
806 | ret = (const char *) _("<no NUL byte at end of section>"); | |
807 | ||
808 | return ret; | |
4723351a CC |
809 | } |
810 | ||
811 | static const char * | |
812 | fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) | |
813 | { | |
814 | struct dwarf_section *section = &debug_displays [debug_addr].section; | |
815 | ||
816 | if (section->start == NULL) | |
817 | return (_("<no .debug_addr section>")); | |
818 | ||
819 | if (offset + bytes > section->size) | |
820 | { | |
821 | warn (_("Offset into section %s too big: %s\n"), | |
b4eb7656 | 822 | section->name, dwarf_vmatoa ("x", offset)); |
4723351a CC |
823 | return "<offset too big>"; |
824 | } | |
825 | ||
826 | return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); | |
827 | } | |
828 | ||
829 | ||
19e6b90e L |
830 | /* FIXME: There are better and more efficient ways to handle |
831 | these structures. For now though, I just want something that | |
832 | is simple to implement. */ | |
833 | typedef struct abbrev_attr | |
834 | { | |
835 | unsigned long attribute; | |
836 | unsigned long form; | |
77145576 | 837 | bfd_signed_vma implicit_const; |
19e6b90e L |
838 | struct abbrev_attr *next; |
839 | } | |
840 | abbrev_attr; | |
841 | ||
842 | typedef struct abbrev_entry | |
843 | { | |
844 | unsigned long entry; | |
845 | unsigned long tag; | |
846 | int children; | |
847 | struct abbrev_attr *first_attr; | |
848 | struct abbrev_attr *last_attr; | |
849 | struct abbrev_entry *next; | |
850 | } | |
851 | abbrev_entry; | |
852 | ||
853 | static abbrev_entry *first_abbrev = NULL; | |
854 | static abbrev_entry *last_abbrev = NULL; | |
855 | ||
856 | static void | |
857 | free_abbrevs (void) | |
858 | { | |
91d6fa6a | 859 | abbrev_entry *abbrv; |
19e6b90e | 860 | |
91d6fa6a | 861 | for (abbrv = first_abbrev; abbrv;) |
19e6b90e | 862 | { |
91d6fa6a | 863 | abbrev_entry *next_abbrev = abbrv->next; |
19e6b90e L |
864 | abbrev_attr *attr; |
865 | ||
91d6fa6a | 866 | for (attr = abbrv->first_attr; attr;) |
19e6b90e | 867 | { |
91d6fa6a | 868 | abbrev_attr *next_attr = attr->next; |
19e6b90e L |
869 | |
870 | free (attr); | |
91d6fa6a | 871 | attr = next_attr; |
19e6b90e L |
872 | } |
873 | ||
91d6fa6a NC |
874 | free (abbrv); |
875 | abbrv = next_abbrev; | |
19e6b90e L |
876 | } |
877 | ||
878 | last_abbrev = first_abbrev = NULL; | |
879 | } | |
880 | ||
881 | static void | |
882 | add_abbrev (unsigned long number, unsigned long tag, int children) | |
883 | { | |
884 | abbrev_entry *entry; | |
885 | ||
3f5e193b | 886 | entry = (abbrev_entry *) malloc (sizeof (*entry)); |
19e6b90e L |
887 | if (entry == NULL) |
888 | /* ugg */ | |
889 | return; | |
890 | ||
891 | entry->entry = number; | |
892 | entry->tag = tag; | |
893 | entry->children = children; | |
894 | entry->first_attr = NULL; | |
895 | entry->last_attr = NULL; | |
896 | entry->next = NULL; | |
897 | ||
898 | if (first_abbrev == NULL) | |
899 | first_abbrev = entry; | |
900 | else | |
901 | last_abbrev->next = entry; | |
902 | ||
903 | last_abbrev = entry; | |
904 | } | |
905 | ||
906 | static void | |
77145576 JK |
907 | add_abbrev_attr (unsigned long attribute, unsigned long form, |
908 | bfd_signed_vma implicit_const) | |
19e6b90e L |
909 | { |
910 | abbrev_attr *attr; | |
911 | ||
3f5e193b | 912 | attr = (abbrev_attr *) malloc (sizeof (*attr)); |
19e6b90e L |
913 | if (attr == NULL) |
914 | /* ugg */ | |
915 | return; | |
916 | ||
917 | attr->attribute = attribute; | |
918 | attr->form = form; | |
77145576 | 919 | attr->implicit_const = implicit_const; |
19e6b90e L |
920 | attr->next = NULL; |
921 | ||
922 | if (last_abbrev->first_attr == NULL) | |
923 | last_abbrev->first_attr = attr; | |
924 | else | |
925 | last_abbrev->last_attr->next = attr; | |
926 | ||
927 | last_abbrev->last_attr = attr; | |
928 | } | |
929 | ||
930 | /* Processes the (partial) contents of a .debug_abbrev section. | |
931 | Returns NULL if the end of the section was encountered. | |
932 | Returns the address after the last byte read if the end of | |
933 | an abbreviation set was found. */ | |
934 | ||
935 | static unsigned char * | |
936 | process_abbrev_section (unsigned char *start, unsigned char *end) | |
937 | { | |
938 | if (first_abbrev != NULL) | |
939 | return NULL; | |
940 | ||
941 | while (start < end) | |
942 | { | |
943 | unsigned int bytes_read; | |
944 | unsigned long entry; | |
945 | unsigned long tag; | |
946 | unsigned long attribute; | |
947 | int children; | |
948 | ||
f6f0e17b | 949 | entry = read_uleb128 (start, & bytes_read, end); |
19e6b90e L |
950 | start += bytes_read; |
951 | ||
952 | /* A single zero is supposed to end the section according | |
953 | to the standard. If there's more, then signal that to | |
954 | the caller. */ | |
f6f0e17b NC |
955 | if (start == end) |
956 | return NULL; | |
19e6b90e | 957 | if (entry == 0) |
f6f0e17b | 958 | return start; |
19e6b90e | 959 | |
f6f0e17b | 960 | tag = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 961 | start += bytes_read; |
f6f0e17b NC |
962 | if (start == end) |
963 | return NULL; | |
19e6b90e L |
964 | |
965 | children = *start++; | |
966 | ||
967 | add_abbrev (entry, tag, children); | |
968 | ||
969 | do | |
970 | { | |
971 | unsigned long form; | |
77145576 JK |
972 | /* Initialize it due to a false compiler warning. */ |
973 | bfd_signed_vma implicit_const = -1; | |
19e6b90e | 974 | |
f6f0e17b | 975 | attribute = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 976 | start += bytes_read; |
f6f0e17b NC |
977 | if (start == end) |
978 | break; | |
19e6b90e | 979 | |
f6f0e17b | 980 | form = read_uleb128 (start, & bytes_read, end); |
19e6b90e | 981 | start += bytes_read; |
f6f0e17b NC |
982 | if (start == end) |
983 | break; | |
19e6b90e | 984 | |
77145576 JK |
985 | if (form == DW_FORM_implicit_const) |
986 | { | |
987 | implicit_const = read_sleb128 (start, & bytes_read, end); | |
988 | start += bytes_read; | |
989 | if (start == end) | |
990 | break; | |
991 | } | |
992 | ||
993 | add_abbrev_attr (attribute, form, implicit_const); | |
19e6b90e L |
994 | } |
995 | while (attribute != 0); | |
996 | } | |
997 | ||
399c99f7 L |
998 | /* Report the missing single zero which ends the section. */ |
999 | error (_(".debug_abbrev section not zero terminated\n")); | |
1000 | ||
19e6b90e L |
1001 | return NULL; |
1002 | } | |
1003 | ||
a19c41a7 | 1004 | static const char * |
19e6b90e L |
1005 | get_TAG_name (unsigned long tag) |
1006 | { | |
04914e37 | 1007 | const char *name = get_DW_TAG_name ((unsigned int) tag); |
a19c41a7 TT |
1008 | |
1009 | if (name == NULL) | |
19e6b90e | 1010 | { |
a19c41a7 | 1011 | static char buffer[100]; |
19e6b90e | 1012 | |
04914e37 NC |
1013 | if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
1014 | snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag); | |
1015 | else | |
1016 | snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag); | |
a19c41a7 | 1017 | return buffer; |
19e6b90e | 1018 | } |
a19c41a7 TT |
1019 | |
1020 | return name; | |
19e6b90e L |
1021 | } |
1022 | ||
a19c41a7 | 1023 | static const char * |
19e6b90e L |
1024 | get_FORM_name (unsigned long form) |
1025 | { | |
399c99f7 | 1026 | const char *name; |
bf5117e3 | 1027 | |
399c99f7 L |
1028 | if (form == 0) |
1029 | return "DW_FORM value: 0"; | |
a19c41a7 | 1030 | |
399c99f7 | 1031 | name = get_DW_FORM_name (form); |
a19c41a7 | 1032 | if (name == NULL) |
19e6b90e | 1033 | { |
a19c41a7 | 1034 | static char buffer[100]; |
19e6b90e | 1035 | |
a19c41a7 TT |
1036 | snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
1037 | return buffer; | |
19e6b90e | 1038 | } |
a19c41a7 TT |
1039 | |
1040 | return name; | |
19e6b90e L |
1041 | } |
1042 | ||
61364358 JK |
1043 | static const char * |
1044 | get_IDX_name (unsigned long idx) | |
1045 | { | |
1046 | const char *name = get_DW_IDX_name ((unsigned int) idx); | |
1047 | ||
1048 | if (name == NULL) | |
1049 | { | |
1050 | static char buffer[100]; | |
1051 | ||
1052 | snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); | |
1053 | return buffer; | |
1054 | } | |
1055 | ||
1056 | return name; | |
1057 | } | |
1058 | ||
19e6b90e | 1059 | static unsigned char * |
0c588247 NC |
1060 | display_block (unsigned char *data, |
1061 | dwarf_vma length, | |
ef0b5f1c | 1062 | const unsigned char * const end, char delimiter) |
19e6b90e | 1063 | { |
0c588247 NC |
1064 | dwarf_vma maxlen; |
1065 | ||
ef0b5f1c | 1066 | printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length)); |
a1165289 NC |
1067 | if (data > end) |
1068 | return (unsigned char *) end; | |
19e6b90e | 1069 | |
0c588247 NC |
1070 | maxlen = (dwarf_vma) (end - data); |
1071 | length = length > maxlen ? maxlen : length; | |
1072 | ||
19e6b90e L |
1073 | while (length --) |
1074 | printf ("%lx ", (unsigned long) byte_get (data++, 1)); | |
1075 | ||
1076 | return data; | |
1077 | } | |
1078 | ||
1079 | static int | |
1080 | decode_location_expression (unsigned char * data, | |
1081 | unsigned int pointer_size, | |
b7807392 JJ |
1082 | unsigned int offset_size, |
1083 | int dwarf_version, | |
467c65bc NC |
1084 | dwarf_vma length, |
1085 | dwarf_vma cu_offset, | |
f1c4cc75 | 1086 | struct dwarf_section * section) |
19e6b90e L |
1087 | { |
1088 | unsigned op; | |
1089 | unsigned int bytes_read; | |
467c65bc | 1090 | dwarf_vma uvalue; |
0c588247 | 1091 | dwarf_signed_vma svalue; |
19e6b90e L |
1092 | unsigned char *end = data + length; |
1093 | int need_frame_base = 0; | |
1094 | ||
1095 | while (data < end) | |
1096 | { | |
1097 | op = *data++; | |
1098 | ||
1099 | switch (op) | |
1100 | { | |
1101 | case DW_OP_addr: | |
0c588247 NC |
1102 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
1103 | printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
1104 | break; |
1105 | case DW_OP_deref: | |
1106 | printf ("DW_OP_deref"); | |
1107 | break; | |
1108 | case DW_OP_const1u: | |
0c588247 NC |
1109 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1110 | printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1111 | break; |
1112 | case DW_OP_const1s: | |
0c588247 NC |
1113 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
1114 | printf ("DW_OP_const1s: %ld", (long) svalue); | |
19e6b90e L |
1115 | break; |
1116 | case DW_OP_const2u: | |
87bc83b3 | 1117 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
0c588247 | 1118 | printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
19e6b90e L |
1119 | break; |
1120 | case DW_OP_const2s: | |
0c588247 NC |
1121 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1122 | printf ("DW_OP_const2s: %ld", (long) svalue); | |
19e6b90e L |
1123 | break; |
1124 | case DW_OP_const4u: | |
0c588247 NC |
1125 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1126 | printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); | |
19e6b90e L |
1127 | break; |
1128 | case DW_OP_const4s: | |
0c588247 NC |
1129 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1130 | printf ("DW_OP_const4s: %ld", (long) svalue); | |
19e6b90e L |
1131 | break; |
1132 | case DW_OP_const8u: | |
0c588247 NC |
1133 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
1134 | printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); | |
1135 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1136 | printf ("%lu", (unsigned long) uvalue); | |
19e6b90e L |
1137 | break; |
1138 | case DW_OP_const8s: | |
0c588247 NC |
1139 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
1140 | printf ("DW_OP_const8s: %ld ", (long) svalue); | |
1141 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); | |
1142 | printf ("%ld", (long) svalue); | |
19e6b90e L |
1143 | break; |
1144 | case DW_OP_constu: | |
467c65bc | 1145 | printf ("DW_OP_constu: %s", |
f6f0e17b | 1146 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1147 | data += bytes_read; |
1148 | break; | |
1149 | case DW_OP_consts: | |
467c65bc | 1150 | printf ("DW_OP_consts: %s", |
f6f0e17b | 1151 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1152 | data += bytes_read; |
1153 | break; | |
1154 | case DW_OP_dup: | |
1155 | printf ("DW_OP_dup"); | |
1156 | break; | |
1157 | case DW_OP_drop: | |
1158 | printf ("DW_OP_drop"); | |
1159 | break; | |
1160 | case DW_OP_over: | |
1161 | printf ("DW_OP_over"); | |
1162 | break; | |
1163 | case DW_OP_pick: | |
0c588247 NC |
1164 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1165 | printf ("DW_OP_pick: %ld", (unsigned long) uvalue); | |
19e6b90e L |
1166 | break; |
1167 | case DW_OP_swap: | |
1168 | printf ("DW_OP_swap"); | |
1169 | break; | |
1170 | case DW_OP_rot: | |
1171 | printf ("DW_OP_rot"); | |
1172 | break; | |
1173 | case DW_OP_xderef: | |
1174 | printf ("DW_OP_xderef"); | |
1175 | break; | |
1176 | case DW_OP_abs: | |
1177 | printf ("DW_OP_abs"); | |
1178 | break; | |
1179 | case DW_OP_and: | |
1180 | printf ("DW_OP_and"); | |
1181 | break; | |
1182 | case DW_OP_div: | |
1183 | printf ("DW_OP_div"); | |
1184 | break; | |
1185 | case DW_OP_minus: | |
1186 | printf ("DW_OP_minus"); | |
1187 | break; | |
1188 | case DW_OP_mod: | |
1189 | printf ("DW_OP_mod"); | |
1190 | break; | |
1191 | case DW_OP_mul: | |
1192 | printf ("DW_OP_mul"); | |
1193 | break; | |
1194 | case DW_OP_neg: | |
1195 | printf ("DW_OP_neg"); | |
1196 | break; | |
1197 | case DW_OP_not: | |
1198 | printf ("DW_OP_not"); | |
1199 | break; | |
1200 | case DW_OP_or: | |
1201 | printf ("DW_OP_or"); | |
1202 | break; | |
1203 | case DW_OP_plus: | |
1204 | printf ("DW_OP_plus"); | |
1205 | break; | |
1206 | case DW_OP_plus_uconst: | |
467c65bc | 1207 | printf ("DW_OP_plus_uconst: %s", |
f6f0e17b | 1208 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1209 | data += bytes_read; |
1210 | break; | |
1211 | case DW_OP_shl: | |
1212 | printf ("DW_OP_shl"); | |
1213 | break; | |
1214 | case DW_OP_shr: | |
1215 | printf ("DW_OP_shr"); | |
1216 | break; | |
1217 | case DW_OP_shra: | |
1218 | printf ("DW_OP_shra"); | |
1219 | break; | |
1220 | case DW_OP_xor: | |
1221 | printf ("DW_OP_xor"); | |
1222 | break; | |
1223 | case DW_OP_bra: | |
0c588247 NC |
1224 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1225 | printf ("DW_OP_bra: %ld", (long) svalue); | |
19e6b90e L |
1226 | break; |
1227 | case DW_OP_eq: | |
1228 | printf ("DW_OP_eq"); | |
1229 | break; | |
1230 | case DW_OP_ge: | |
1231 | printf ("DW_OP_ge"); | |
1232 | break; | |
1233 | case DW_OP_gt: | |
1234 | printf ("DW_OP_gt"); | |
1235 | break; | |
1236 | case DW_OP_le: | |
1237 | printf ("DW_OP_le"); | |
1238 | break; | |
1239 | case DW_OP_lt: | |
1240 | printf ("DW_OP_lt"); | |
1241 | break; | |
1242 | case DW_OP_ne: | |
1243 | printf ("DW_OP_ne"); | |
1244 | break; | |
1245 | case DW_OP_skip: | |
0c588247 NC |
1246 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
1247 | printf ("DW_OP_skip: %ld", (long) svalue); | |
19e6b90e L |
1248 | break; |
1249 | ||
1250 | case DW_OP_lit0: | |
1251 | case DW_OP_lit1: | |
1252 | case DW_OP_lit2: | |
1253 | case DW_OP_lit3: | |
1254 | case DW_OP_lit4: | |
1255 | case DW_OP_lit5: | |
1256 | case DW_OP_lit6: | |
1257 | case DW_OP_lit7: | |
1258 | case DW_OP_lit8: | |
1259 | case DW_OP_lit9: | |
1260 | case DW_OP_lit10: | |
1261 | case DW_OP_lit11: | |
1262 | case DW_OP_lit12: | |
1263 | case DW_OP_lit13: | |
1264 | case DW_OP_lit14: | |
1265 | case DW_OP_lit15: | |
1266 | case DW_OP_lit16: | |
1267 | case DW_OP_lit17: | |
1268 | case DW_OP_lit18: | |
1269 | case DW_OP_lit19: | |
1270 | case DW_OP_lit20: | |
1271 | case DW_OP_lit21: | |
1272 | case DW_OP_lit22: | |
1273 | case DW_OP_lit23: | |
1274 | case DW_OP_lit24: | |
1275 | case DW_OP_lit25: | |
1276 | case DW_OP_lit26: | |
1277 | case DW_OP_lit27: | |
1278 | case DW_OP_lit28: | |
1279 | case DW_OP_lit29: | |
1280 | case DW_OP_lit30: | |
1281 | case DW_OP_lit31: | |
1282 | printf ("DW_OP_lit%d", op - DW_OP_lit0); | |
1283 | break; | |
1284 | ||
1285 | case DW_OP_reg0: | |
1286 | case DW_OP_reg1: | |
1287 | case DW_OP_reg2: | |
1288 | case DW_OP_reg3: | |
1289 | case DW_OP_reg4: | |
1290 | case DW_OP_reg5: | |
1291 | case DW_OP_reg6: | |
1292 | case DW_OP_reg7: | |
1293 | case DW_OP_reg8: | |
1294 | case DW_OP_reg9: | |
1295 | case DW_OP_reg10: | |
1296 | case DW_OP_reg11: | |
1297 | case DW_OP_reg12: | |
1298 | case DW_OP_reg13: | |
1299 | case DW_OP_reg14: | |
1300 | case DW_OP_reg15: | |
1301 | case DW_OP_reg16: | |
1302 | case DW_OP_reg17: | |
1303 | case DW_OP_reg18: | |
1304 | case DW_OP_reg19: | |
1305 | case DW_OP_reg20: | |
1306 | case DW_OP_reg21: | |
1307 | case DW_OP_reg22: | |
1308 | case DW_OP_reg23: | |
1309 | case DW_OP_reg24: | |
1310 | case DW_OP_reg25: | |
1311 | case DW_OP_reg26: | |
1312 | case DW_OP_reg27: | |
1313 | case DW_OP_reg28: | |
1314 | case DW_OP_reg29: | |
1315 | case DW_OP_reg30: | |
1316 | case DW_OP_reg31: | |
18464d4d JK |
1317 | printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
1318 | regname (op - DW_OP_reg0, 1)); | |
19e6b90e L |
1319 | break; |
1320 | ||
1321 | case DW_OP_breg0: | |
1322 | case DW_OP_breg1: | |
1323 | case DW_OP_breg2: | |
1324 | case DW_OP_breg3: | |
1325 | case DW_OP_breg4: | |
1326 | case DW_OP_breg5: | |
1327 | case DW_OP_breg6: | |
1328 | case DW_OP_breg7: | |
1329 | case DW_OP_breg8: | |
1330 | case DW_OP_breg9: | |
1331 | case DW_OP_breg10: | |
1332 | case DW_OP_breg11: | |
1333 | case DW_OP_breg12: | |
1334 | case DW_OP_breg13: | |
1335 | case DW_OP_breg14: | |
1336 | case DW_OP_breg15: | |
1337 | case DW_OP_breg16: | |
1338 | case DW_OP_breg17: | |
1339 | case DW_OP_breg18: | |
1340 | case DW_OP_breg19: | |
1341 | case DW_OP_breg20: | |
1342 | case DW_OP_breg21: | |
1343 | case DW_OP_breg22: | |
1344 | case DW_OP_breg23: | |
1345 | case DW_OP_breg24: | |
1346 | case DW_OP_breg25: | |
1347 | case DW_OP_breg26: | |
1348 | case DW_OP_breg27: | |
1349 | case DW_OP_breg28: | |
1350 | case DW_OP_breg29: | |
1351 | case DW_OP_breg30: | |
1352 | case DW_OP_breg31: | |
467c65bc | 1353 | printf ("DW_OP_breg%d (%s): %s", |
47704ddf | 1354 | op - DW_OP_breg0, |
18464d4d | 1355 | regname (op - DW_OP_breg0, 1), |
f6f0e17b | 1356 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1357 | data += bytes_read; |
1358 | break; | |
1359 | ||
1360 | case DW_OP_regx: | |
f6f0e17b | 1361 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1362 | data += bytes_read; |
467c65bc NC |
1363 | printf ("DW_OP_regx: %s (%s)", |
1364 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); | |
19e6b90e L |
1365 | break; |
1366 | case DW_OP_fbreg: | |
1367 | need_frame_base = 1; | |
467c65bc | 1368 | printf ("DW_OP_fbreg: %s", |
f6f0e17b | 1369 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1370 | data += bytes_read; |
1371 | break; | |
1372 | case DW_OP_bregx: | |
f6f0e17b | 1373 | uvalue = read_uleb128 (data, &bytes_read, end); |
19e6b90e | 1374 | data += bytes_read; |
467c65bc NC |
1375 | printf ("DW_OP_bregx: %s (%s) %s", |
1376 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), | |
f6f0e17b | 1377 | dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
19e6b90e L |
1378 | data += bytes_read; |
1379 | break; | |
1380 | case DW_OP_piece: | |
467c65bc | 1381 | printf ("DW_OP_piece: %s", |
f6f0e17b | 1382 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
19e6b90e L |
1383 | data += bytes_read; |
1384 | break; | |
1385 | case DW_OP_deref_size: | |
0c588247 NC |
1386 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1387 | printf ("DW_OP_deref_size: %ld", (long) uvalue); | |
19e6b90e L |
1388 | break; |
1389 | case DW_OP_xderef_size: | |
0c588247 NC |
1390 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
1391 | printf ("DW_OP_xderef_size: %ld", (long) uvalue); | |
19e6b90e L |
1392 | break; |
1393 | case DW_OP_nop: | |
1394 | printf ("DW_OP_nop"); | |
1395 | break; | |
1396 | ||
1397 | /* DWARF 3 extensions. */ | |
1398 | case DW_OP_push_object_address: | |
1399 | printf ("DW_OP_push_object_address"); | |
1400 | break; | |
1401 | case DW_OP_call2: | |
d85bf2ba | 1402 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1403 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1404 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
467c65bc | 1405 | printf ("DW_OP_call2: <0x%s>", |
0c588247 | 1406 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1407 | break; |
1408 | case DW_OP_call4: | |
d85bf2ba | 1409 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
19e6b90e | 1410 | this ought to be an 8-byte wide computation. */ |
0c588247 | 1411 | SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
467c65bc | 1412 | printf ("DW_OP_call4: <0x%s>", |
0c588247 | 1413 | dwarf_vmatoa ("x", svalue + cu_offset)); |
19e6b90e L |
1414 | break; |
1415 | case DW_OP_call_ref: | |
d85bf2ba | 1416 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
e2a0d921 | 1417 | this ought to be an 8-byte wide computation. */ |
b7807392 JJ |
1418 | if (dwarf_version == -1) |
1419 | { | |
1420 | printf (_("(DW_OP_call_ref in frame info)")); | |
1421 | /* No way to tell where the next op is, so just bail. */ | |
1422 | return need_frame_base; | |
1423 | } | |
1424 | if (dwarf_version == 2) | |
1425 | { | |
0c588247 | 1426 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1427 | } |
1428 | else | |
1429 | { | |
0c588247 | 1430 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1431 | } |
0c588247 | 1432 | printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
19e6b90e | 1433 | break; |
a87b0a59 NS |
1434 | case DW_OP_form_tls_address: |
1435 | printf ("DW_OP_form_tls_address"); | |
1436 | break; | |
e2a0d921 NC |
1437 | case DW_OP_call_frame_cfa: |
1438 | printf ("DW_OP_call_frame_cfa"); | |
1439 | break; | |
1440 | case DW_OP_bit_piece: | |
1441 | printf ("DW_OP_bit_piece: "); | |
9cf03b7e | 1442 | printf (_("size: %s "), |
f6f0e17b | 1443 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 | 1444 | data += bytes_read; |
9cf03b7e | 1445 | printf (_("offset: %s "), |
f6f0e17b | 1446 | dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
e2a0d921 NC |
1447 | data += bytes_read; |
1448 | break; | |
19e6b90e | 1449 | |
3244e8f5 JJ |
1450 | /* DWARF 4 extensions. */ |
1451 | case DW_OP_stack_value: | |
1452 | printf ("DW_OP_stack_value"); | |
1453 | break; | |
1454 | ||
1455 | case DW_OP_implicit_value: | |
1456 | printf ("DW_OP_implicit_value"); | |
f6f0e17b | 1457 | uvalue = read_uleb128 (data, &bytes_read, end); |
3244e8f5 | 1458 | data += bytes_read; |
ef0b5f1c | 1459 | data = display_block (data, uvalue, end, ' '); |
3244e8f5 JJ |
1460 | break; |
1461 | ||
19e6b90e L |
1462 | /* GNU extensions. */ |
1463 | case DW_OP_GNU_push_tls_address: | |
9cf03b7e | 1464 | printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
e2a0d921 NC |
1465 | break; |
1466 | case DW_OP_GNU_uninit: | |
1467 | printf ("DW_OP_GNU_uninit"); | |
1468 | /* FIXME: Is there data associated with this OP ? */ | |
1469 | break; | |
f1c4cc75 RH |
1470 | case DW_OP_GNU_encoded_addr: |
1471 | { | |
6937bb54 | 1472 | int encoding = 0; |
f1c4cc75 | 1473 | dwarf_vma addr; |
467c65bc | 1474 | |
6937bb54 NC |
1475 | if (data < end) |
1476 | encoding = *data++; | |
041830e0 | 1477 | addr = get_encoded_value (&data, encoding, section, end); |
f1c4cc75 RH |
1478 | |
1479 | printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); | |
1480 | print_dwarf_vma (addr, pointer_size); | |
1481 | } | |
1482 | break; | |
bc0a77d2 | 1483 | case DW_OP_implicit_pointer: |
b7807392 | 1484 | case DW_OP_GNU_implicit_pointer: |
d85bf2ba | 1485 | /* FIXME: Strictly speaking for 64-bit DWARF3 files |
b7807392 JJ |
1486 | this ought to be an 8-byte wide computation. */ |
1487 | if (dwarf_version == -1) | |
1488 | { | |
bc0a77d2 JK |
1489 | printf (_("(%s in frame info)"), |
1490 | (op == DW_OP_implicit_pointer | |
1491 | ? "DW_OP_implicit_pointer" | |
1492 | : "DW_OP_GNU_implicit_pointer")); | |
b7807392 JJ |
1493 | /* No way to tell where the next op is, so just bail. */ |
1494 | return need_frame_base; | |
1495 | } | |
1496 | if (dwarf_version == 2) | |
1497 | { | |
0c588247 | 1498 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
b7807392 JJ |
1499 | } |
1500 | else | |
1501 | { | |
0c588247 | 1502 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
b7807392 | 1503 | } |
bc0a77d2 JK |
1504 | printf ("%s: <0x%s> %s", |
1505 | (op == DW_OP_implicit_pointer | |
1506 | ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), | |
0c588247 NC |
1507 | dwarf_vmatoa ("x", uvalue), |
1508 | dwarf_vmatoa ("d", read_sleb128 (data, | |
1509 | &bytes_read, end))); | |
1510 | data += bytes_read; | |
b7807392 | 1511 | break; |
77145576 | 1512 | case DW_OP_entry_value: |
0892011d | 1513 | case DW_OP_GNU_entry_value: |
f6f0e17b | 1514 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1515 | data += bytes_read; |
058037d3 NC |
1516 | /* PR 17531: file: 0cc9cd00. */ |
1517 | if (uvalue > (dwarf_vma) (end - data)) | |
1518 | uvalue = end - data; | |
77145576 JK |
1519 | printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
1520 | : "DW_OP_GNU_entry_value")); | |
0892011d JJ |
1521 | if (decode_location_expression (data, pointer_size, offset_size, |
1522 | dwarf_version, uvalue, | |
1523 | cu_offset, section)) | |
1524 | need_frame_base = 1; | |
1525 | putchar (')'); | |
1526 | data += uvalue; | |
6937bb54 NC |
1527 | if (data > end) |
1528 | data = end; | |
0892011d | 1529 | break; |
bc0a77d2 | 1530 | case DW_OP_const_type: |
0892011d | 1531 | case DW_OP_GNU_const_type: |
f6f0e17b | 1532 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1533 | data += bytes_read; |
bc0a77d2 JK |
1534 | printf ("%s: <0x%s> ", |
1535 | (op == DW_OP_const_type ? "DW_OP_const_type" | |
1536 | : "DW_OP_GNU_const_type"), | |
0892011d | 1537 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0c588247 | 1538 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
ef0b5f1c | 1539 | data = display_block (data, uvalue, end, ' '); |
0892011d | 1540 | break; |
bc0a77d2 | 1541 | case DW_OP_regval_type: |
0892011d | 1542 | case DW_OP_GNU_regval_type: |
f6f0e17b | 1543 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1544 | data += bytes_read; |
bc0a77d2 JK |
1545 | printf ("%s: %s (%s)", |
1546 | (op == DW_OP_regval_type ? "DW_OP_regval_type" | |
1547 | : "DW_OP_GNU_regval_type"), | |
0892011d | 1548 | dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
f6f0e17b | 1549 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1550 | data += bytes_read; |
1551 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1552 | break; | |
bc0a77d2 | 1553 | case DW_OP_deref_type: |
0892011d | 1554 | case DW_OP_GNU_deref_type: |
0c588247 | 1555 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
bc0a77d2 JK |
1556 | printf ("%s: %ld", |
1557 | (op == DW_OP_deref_type ? "DW_OP_deref_type" | |
1558 | : "DW_OP_GNU_deref_type"), | |
1559 | (long) uvalue); | |
f6f0e17b | 1560 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d JJ |
1561 | data += bytes_read; |
1562 | printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); | |
1563 | break; | |
bc0a77d2 | 1564 | case DW_OP_convert: |
0892011d | 1565 | case DW_OP_GNU_convert: |
f6f0e17b | 1566 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1567 | data += bytes_read; |
bc0a77d2 JK |
1568 | printf ("%s <0x%s>", |
1569 | (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), | |
f8b999f9 | 1570 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
0892011d | 1571 | break; |
bc0a77d2 | 1572 | case DW_OP_reinterpret: |
0892011d | 1573 | case DW_OP_GNU_reinterpret: |
f6f0e17b | 1574 | uvalue = read_uleb128 (data, &bytes_read, end); |
0892011d | 1575 | data += bytes_read; |
bc0a77d2 JK |
1576 | printf ("%s <0x%s>", |
1577 | (op == DW_OP_reinterpret ? "DW_OP_reinterpret" | |
1578 | : "DW_OP_GNU_reinterpret"), | |
f8b999f9 JJ |
1579 | dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
1580 | break; | |
1581 | case DW_OP_GNU_parameter_ref: | |
0c588247 | 1582 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
f8b999f9 | 1583 | printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
0c588247 | 1584 | dwarf_vmatoa ("x", cu_offset + uvalue)); |
0892011d | 1585 | break; |
b4eb7656 AM |
1586 | case DW_OP_GNU_addr_index: |
1587 | uvalue = read_uleb128 (data, &bytes_read, end); | |
1588 | data += bytes_read; | |
1589 | printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1590 | break; | |
1591 | case DW_OP_GNU_const_index: | |
1592 | uvalue = read_uleb128 (data, &bytes_read, end); | |
1593 | data += bytes_read; | |
1594 | printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1595 | break; | |
f384a1f0 KB |
1596 | case DW_OP_GNU_variable_value: |
1597 | /* FIXME: Strictly speaking for 64-bit DWARF3 files | |
1598 | this ought to be an 8-byte wide computation. */ | |
1599 | if (dwarf_version == -1) | |
1600 | { | |
1601 | printf (_("(DW_OP_GNU_variable_value in frame info)")); | |
1602 | /* No way to tell where the next op is, so just bail. */ | |
1603 | return need_frame_base; | |
1604 | } | |
1605 | if (dwarf_version == 2) | |
1606 | { | |
1607 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1608 | } | |
1609 | else | |
1610 | { | |
1611 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1612 | } | |
1613 | printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue)); | |
1614 | break; | |
e2a0d921 NC |
1615 | |
1616 | /* HP extensions. */ | |
1617 | case DW_OP_HP_is_value: | |
1618 | printf ("DW_OP_HP_is_value"); | |
1619 | /* FIXME: Is there data associated with this OP ? */ | |
1620 | break; | |
1621 | case DW_OP_HP_fltconst4: | |
1622 | printf ("DW_OP_HP_fltconst4"); | |
1623 | /* FIXME: Is there data associated with this OP ? */ | |
1624 | break; | |
1625 | case DW_OP_HP_fltconst8: | |
1626 | printf ("DW_OP_HP_fltconst8"); | |
1627 | /* FIXME: Is there data associated with this OP ? */ | |
1628 | break; | |
1629 | case DW_OP_HP_mod_range: | |
1630 | printf ("DW_OP_HP_mod_range"); | |
1631 | /* FIXME: Is there data associated with this OP ? */ | |
1632 | break; | |
1633 | case DW_OP_HP_unmod_range: | |
1634 | printf ("DW_OP_HP_unmod_range"); | |
1635 | /* FIXME: Is there data associated with this OP ? */ | |
1636 | break; | |
1637 | case DW_OP_HP_tls: | |
1638 | printf ("DW_OP_HP_tls"); | |
1639 | /* FIXME: Is there data associated with this OP ? */ | |
19e6b90e L |
1640 | break; |
1641 | ||
35d60fe4 NC |
1642 | /* PGI (STMicroelectronics) extensions. */ |
1643 | case DW_OP_PGI_omp_thread_num: | |
1644 | /* Pushes the thread number for the current thread as it would be | |
1645 | returned by the standard OpenMP library function: | |
1646 | omp_get_thread_num(). The "current thread" is the thread for | |
1647 | which the expression is being evaluated. */ | |
1648 | printf ("DW_OP_PGI_omp_thread_num"); | |
1649 | break; | |
1650 | ||
19e6b90e L |
1651 | default: |
1652 | if (op >= DW_OP_lo_user | |
1653 | && op <= DW_OP_hi_user) | |
0502a2b4 | 1654 | printf (_("(User defined location op 0x%x)"), op); |
19e6b90e | 1655 | else |
0502a2b4 | 1656 | printf (_("(Unknown location op 0x%x)"), op); |
19e6b90e L |
1657 | /* No way to tell where the next op is, so just bail. */ |
1658 | return need_frame_base; | |
1659 | } | |
1660 | ||
1661 | /* Separate the ops. */ | |
1662 | if (data < end) | |
1663 | printf ("; "); | |
1664 | } | |
1665 | ||
1666 | return need_frame_base; | |
1667 | } | |
1668 | ||
341f9135 CC |
1669 | /* Find the CU or TU set corresponding to the given CU_OFFSET. |
1670 | This is used for DWARF package files. */ | |
1671 | ||
1672 | static struct cu_tu_set * | |
1673 | find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) | |
1674 | { | |
1675 | struct cu_tu_set *p; | |
1676 | unsigned int nsets; | |
1677 | unsigned int dw_sect; | |
1678 | ||
1679 | if (do_types) | |
1680 | { | |
1681 | p = tu_sets; | |
1682 | nsets = tu_count; | |
1683 | dw_sect = DW_SECT_TYPES; | |
1684 | } | |
1685 | else | |
1686 | { | |
1687 | p = cu_sets; | |
1688 | nsets = cu_count; | |
1689 | dw_sect = DW_SECT_INFO; | |
1690 | } | |
1691 | while (nsets > 0) | |
1692 | { | |
1693 | if (p->section_offsets [dw_sect] == cu_offset) | |
1694 | return p; | |
1695 | p++; | |
1696 | nsets--; | |
1697 | } | |
1698 | return NULL; | |
1699 | } | |
1700 | ||
a69c4772 NC |
1701 | /* Add INC to HIGH_BITS:LOW_BITS. */ |
1702 | static void | |
1703 | add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) | |
1704 | { | |
1705 | dwarf_vma tmp = * low_bits; | |
1706 | ||
1707 | tmp += inc; | |
1708 | ||
1709 | /* FIXME: There is probably a better way of handling this: | |
1710 | ||
1711 | We need to cope with dwarf_vma being a 32-bit or 64-bit | |
1712 | type. Plus regardless of its size LOW_BITS is meant to | |
1713 | only hold 32-bits, so if there is overflow or wrap around | |
1714 | we must propagate into HIGH_BITS. */ | |
1715 | if (tmp < * low_bits) | |
1716 | { | |
1717 | ++ * high_bits; | |
1718 | } | |
1719 | else if (sizeof (tmp) > 8 | |
1720 | && (tmp >> 31) > 1) | |
1721 | { | |
1722 | ++ * high_bits; | |
1723 | tmp &= 0xFFFFFFFF; | |
1724 | } | |
1725 | ||
1726 | * low_bits = tmp; | |
1727 | } | |
1728 | ||
dda8d76d NC |
1729 | static const char * |
1730 | fetch_alt_indirect_string (dwarf_vma offset) | |
1731 | { | |
24841daa | 1732 | separate_info * i; |
dda8d76d NC |
1733 | |
1734 | if (! do_follow_links) | |
1735 | return ""; | |
1736 | ||
24841daa NC |
1737 | if (first_separate_info == NULL) |
1738 | return _("<no links available>"); | |
dda8d76d | 1739 | |
24841daa NC |
1740 | for (i = first_separate_info; i != NULL; i = i->next) |
1741 | { | |
1742 | struct dwarf_section * section; | |
1743 | const char * ret; | |
dda8d76d | 1744 | |
24841daa NC |
1745 | if (! load_debug_section (separate_debug_str, i->handle)) |
1746 | continue; | |
dda8d76d | 1747 | |
24841daa | 1748 | section = &debug_displays [separate_debug_str].section; |
dda8d76d | 1749 | |
24841daa NC |
1750 | if (section->start == NULL) |
1751 | continue; | |
dda8d76d | 1752 | |
24841daa NC |
1753 | if (offset >= section->size) |
1754 | continue; | |
1755 | ||
1756 | ret = (const char *) (section->start + offset); | |
1757 | /* Unfortunately we cannot rely upon the .debug_str section ending with a | |
1758 | NUL byte. Since our caller is expecting to receive a well formed C | |
1759 | string we test for the lack of a terminating byte here. */ | |
1760 | if (strnlen ((const char *) ret, section->size - offset) | |
1761 | == section->size - offset) | |
1762 | return _("<no NUL byte at end of alt .debug_str section>"); | |
1763 | ||
1764 | return ret; | |
1765 | } | |
1766 | ||
1767 | warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"), | |
1768 | dwarf_vmatoa ("x", offset)); | |
1769 | return _("<offset is too big>"); | |
dda8d76d NC |
1770 | } |
1771 | ||
d85bf2ba NC |
1772 | static const char * |
1773 | get_AT_name (unsigned long attribute) | |
1774 | { | |
1775 | const char *name; | |
1776 | ||
1777 | if (attribute == 0) | |
1778 | return "DW_AT value: 0"; | |
1779 | ||
1780 | /* One value is shared by the MIPS and HP extensions: */ | |
1781 | if (attribute == DW_AT_MIPS_fde) | |
1782 | return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; | |
1783 | ||
1784 | name = get_DW_AT_name (attribute); | |
1785 | ||
1786 | if (name == NULL) | |
1787 | { | |
1788 | static char buffer[100]; | |
1789 | ||
1790 | snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), | |
1791 | attribute); | |
1792 | return buffer; | |
1793 | } | |
1794 | ||
1795 | return name; | |
1796 | } | |
1797 | ||
24841daa NC |
1798 | static void |
1799 | add_dwo_info (const char * field, dwo_type type) | |
1800 | { | |
1801 | dwo_info * dwinfo = xmalloc (sizeof * dwinfo); | |
1802 | ||
1803 | dwinfo->type = type; | |
1804 | dwinfo->value = field; | |
1805 | dwinfo->next = first_dwo_info; | |
1806 | first_dwo_info = dwinfo; | |
1807 | } | |
1808 | ||
1809 | static void | |
1810 | add_dwo_name (const char * name) | |
1811 | { | |
1812 | add_dwo_info (name, DWO_NAME); | |
1813 | } | |
1814 | ||
1815 | static void | |
1816 | add_dwo_dir (const char * dir) | |
1817 | { | |
1818 | add_dwo_info (dir, DWO_DIR); | |
1819 | } | |
1820 | ||
1821 | static void | |
1822 | add_dwo_id (const char * id) | |
1823 | { | |
1824 | add_dwo_info (id, DWO_ID); | |
1825 | } | |
1826 | ||
1827 | static void | |
1828 | free_dwo_info (void) | |
1829 | { | |
1830 | dwo_info * dwinfo; | |
1831 | dwo_info * next; | |
1832 | ||
1833 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) | |
1834 | { | |
1835 | next = dwinfo->next; | |
1836 | free (dwinfo); | |
1837 | } | |
1838 | first_dwo_info = NULL; | |
1839 | } | |
1840 | ||
afc72f15 NC |
1841 | /* Ensure that START + UVALUE is less than END. |
1842 | Return an adjusted UVALUE if necessary to ensure this relationship. */ | |
1843 | ||
1844 | static inline dwarf_vma | |
1845 | check_uvalue (const unsigned char * start, | |
1846 | dwarf_vma uvalue, | |
1847 | const unsigned char * end) | |
1848 | { | |
1849 | dwarf_vma max_uvalue = end - start; | |
1850 | ||
1851 | /* FIXME: Testing "(start + uvalue) < start" miscompiles with gcc 4.8.3 | |
1852 | running on an x86_64 host in 32-bit mode. So we pre-compute the value | |
1853 | here. */ | |
1854 | const unsigned char * ptr = start + uvalue; | |
1855 | ||
1856 | /* See PR 17512: file: 008-103549-0.001:0.1. | |
1857 | and PR 24829 for examples of where these tests are triggered. */ | |
1858 | if (uvalue > max_uvalue | |
1859 | || ptr > end | |
1860 | || ptr < start) | |
1861 | { | |
1862 | warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); | |
1863 | uvalue = max_uvalue; | |
1864 | } | |
1865 | ||
1866 | return uvalue; | |
1867 | } | |
1868 | ||
ec1b0fbb NC |
1869 | static unsigned char * |
1870 | skip_attr_bytes (unsigned long form, | |
1871 | unsigned char * data, | |
1872 | unsigned const char * end, | |
1873 | dwarf_vma pointer_size, | |
1874 | dwarf_vma offset_size, | |
1875 | int dwarf_version, | |
1876 | dwarf_vma * value_return) | |
1877 | { | |
1878 | unsigned int bytes_read; | |
1879 | dwarf_vma uvalue = 0; | |
1880 | ||
1881 | * value_return = 0; | |
1882 | ||
1883 | switch (form) | |
1884 | { | |
1885 | case DW_FORM_ref_addr: | |
1886 | if (dwarf_version == 2) | |
1887 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1888 | else if (dwarf_version == 3 || dwarf_version == 4) | |
1889 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1890 | else | |
1891 | return NULL; | |
1892 | break; | |
1893 | ||
1894 | case DW_FORM_addr: | |
1895 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); | |
1896 | break; | |
1897 | ||
1898 | case DW_FORM_strp: | |
1899 | case DW_FORM_line_strp: | |
1900 | case DW_FORM_sec_offset: | |
1901 | case DW_FORM_GNU_ref_alt: | |
1902 | case DW_FORM_GNU_strp_alt: | |
1903 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); | |
1904 | break; | |
1905 | ||
1906 | case DW_FORM_flag_present: | |
1907 | uvalue = 1; | |
1908 | break; | |
1909 | ||
1910 | case DW_FORM_ref1: | |
1911 | case DW_FORM_flag: | |
1912 | case DW_FORM_data1: | |
1913 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); | |
1914 | break; | |
1915 | ||
1916 | case DW_FORM_ref2: | |
1917 | case DW_FORM_data2: | |
1918 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); | |
1919 | break; | |
1920 | ||
1921 | case DW_FORM_ref4: | |
1922 | case DW_FORM_data4: | |
1923 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); | |
1924 | break; | |
1925 | ||
1926 | case DW_FORM_sdata: | |
1927 | uvalue = read_sleb128 (data, & bytes_read, end); | |
1928 | data += bytes_read; | |
1929 | break; | |
1930 | ||
1931 | case DW_FORM_ref_udata: | |
1932 | case DW_FORM_udata: | |
1933 | case DW_FORM_GNU_str_index: | |
1934 | case DW_FORM_GNU_addr_index: | |
1935 | uvalue = read_uleb128 (data, & bytes_read, end); | |
1936 | data += bytes_read; | |
1937 | break; | |
1938 | ||
1939 | case DW_FORM_ref8: | |
1940 | case DW_FORM_data8: | |
1941 | data += 8; | |
1942 | break; | |
1943 | ||
1944 | case DW_FORM_data16: | |
1945 | data += 16; | |
1946 | break; | |
1947 | ||
1948 | case DW_FORM_string: | |
1949 | data += strnlen ((char *) data, end - data) + 1; | |
1950 | break; | |
1951 | ||
1952 | case DW_FORM_block: | |
1953 | case DW_FORM_exprloc: | |
1954 | uvalue = read_uleb128 (data, & bytes_read, end); | |
1955 | data += bytes_read + uvalue; | |
1956 | break; | |
1957 | ||
1958 | case DW_FORM_block1: | |
1959 | SAFE_BYTE_GET (uvalue, data, 1, end); | |
1960 | data += 1 + uvalue; | |
1961 | break; | |
1962 | ||
1963 | case DW_FORM_block2: | |
1964 | SAFE_BYTE_GET (uvalue, data, 2, end); | |
1965 | data += 2 + uvalue; | |
1966 | break; | |
1967 | ||
1968 | case DW_FORM_block4: | |
1969 | SAFE_BYTE_GET (uvalue, data, 4, end); | |
1970 | data += 4 + uvalue; | |
1971 | break; | |
1972 | ||
1973 | case DW_FORM_ref_sig8: | |
1974 | data += 8; | |
1975 | break; | |
1976 | ||
1977 | case DW_FORM_indirect: | |
1978 | /* FIXME: Handle this form. */ | |
1979 | default: | |
1980 | return NULL; | |
1981 | } | |
1982 | ||
1983 | * value_return = uvalue; | |
1984 | if (data > end) | |
1985 | data = (unsigned char *) end; | |
1986 | return data; | |
1987 | } | |
1988 | ||
1989 | /* Return IS_SIGNED set to TRUE if the type at | |
1990 | DATA can be determined to be a signed type. */ | |
1991 | ||
1992 | static void | |
1993 | get_type_signedness (unsigned char * start, | |
1994 | unsigned char * data, | |
1995 | unsigned const char * end, | |
1996 | dwarf_vma pointer_size, | |
1997 | dwarf_vma offset_size, | |
1998 | int dwarf_version, | |
1999 | bfd_boolean * is_signed, | |
2000 | bfd_boolean is_nested) | |
2001 | { | |
2002 | unsigned long abbrev_number; | |
2003 | unsigned int bytes_read; | |
2004 | abbrev_entry * entry; | |
2005 | abbrev_attr * attr; | |
2006 | ||
2007 | * is_signed = FALSE; | |
2008 | ||
2009 | if (data >= end) | |
2010 | return; | |
2011 | ||
2012 | abbrev_number = read_uleb128 (data, & bytes_read, end); | |
2013 | data += bytes_read; | |
2014 | ||
2015 | for (entry = first_abbrev; | |
2016 | entry != NULL && entry->entry != abbrev_number; | |
2017 | entry = entry->next) | |
2018 | continue; | |
2019 | ||
2020 | if (entry == NULL) | |
2021 | /* FIXME: Issue a warning ? */ | |
2022 | return; | |
2023 | ||
2024 | for (attr = entry->first_attr; | |
2025 | attr != NULL && attr->attribute; | |
2026 | attr = attr->next) | |
2027 | { | |
2028 | dwarf_vma uvalue = 0; | |
2029 | ||
2030 | data = skip_attr_bytes (attr->form, data, end, pointer_size, | |
2031 | offset_size, dwarf_version, & uvalue); | |
2032 | if (data == NULL) | |
2033 | return; | |
2034 | ||
2035 | switch (attr->attribute) | |
2036 | { | |
2037 | #if 0 /* FIXME: It would be nice to print the name of the type, | |
2038 | but this would mean updating a lot of binutils tests. */ | |
2039 | case DW_AT_name: | |
2040 | if (attr->form == DW_FORM_strp) | |
2041 | printf ("%s", fetch_indirect_string (uvalue)); | |
2042 | break; | |
2043 | #endif | |
2044 | case DW_AT_type: | |
2045 | /* Recurse. */ | |
2046 | if (is_nested) | |
2047 | { | |
2048 | /* FIXME: Warn - or is this expected ? | |
2049 | NB/ We need to avoid infinite recursion. */ | |
2050 | return; | |
2051 | } | |
2052 | get_type_signedness (start, start + uvalue, end, pointer_size, | |
2053 | offset_size, dwarf_version, is_signed, TRUE); | |
2054 | break; | |
2055 | ||
2056 | case DW_AT_encoding: | |
2057 | /* Determine signness. */ | |
2058 | switch (uvalue) | |
2059 | { | |
2060 | case DW_ATE_address: | |
2061 | /* FIXME - some architectures have signed addresses. */ | |
2062 | case DW_ATE_boolean: | |
2063 | case DW_ATE_unsigned: | |
2064 | case DW_ATE_unsigned_char: | |
2065 | case DW_ATE_unsigned_fixed: | |
2066 | * is_signed = FALSE; | |
2067 | break; | |
2068 | ||
2069 | default: | |
2070 | case DW_ATE_complex_float: | |
2071 | case DW_ATE_float: | |
2072 | case DW_ATE_signed: | |
2073 | case DW_ATE_signed_char: | |
2074 | case DW_ATE_imaginary_float: | |
2075 | case DW_ATE_decimal_float: | |
2076 | case DW_ATE_signed_fixed: | |
2077 | * is_signed = TRUE; | |
2078 | break; | |
2079 | } | |
2080 | break; | |
2081 | } | |
2082 | } | |
2083 | } | |
2084 | ||
2085 | static void | |
2086 | read_and_print_leb128 (unsigned char * data, | |
2087 | unsigned int * bytes_read, | |
2088 | unsigned const char * end, | |
2089 | bfd_boolean is_signed) | |
2090 | { | |
2091 | if (is_signed) | |
2092 | { | |
2093 | dwarf_signed_vma sval = read_sleb128 (data, bytes_read, end); | |
2094 | printf ("%ld", (long) sval); | |
2095 | } | |
2096 | else | |
2097 | { | |
2098 | dwarf_vma uval = read_uleb128 (data, bytes_read, end); | |
2099 | printf ("%lu", (unsigned long) uval); | |
2100 | } | |
2101 | } | |
2102 | ||
2103 | static void | |
2104 | display_discr_list (unsigned long form, | |
2105 | dwarf_vma uvalue, | |
2106 | unsigned char * data, | |
2107 | unsigned const char * end, | |
2108 | int level) | |
2109 | { | |
2110 | if (uvalue == 0) | |
2111 | { | |
2112 | printf ("[default]"); | |
2113 | return; | |
2114 | } | |
2115 | ||
2116 | switch (form) | |
2117 | { | |
2118 | case DW_FORM_block: | |
2119 | case DW_FORM_block1: | |
2120 | case DW_FORM_block2: | |
2121 | case DW_FORM_block4: | |
2122 | /* Move data pointer back to the start of the byte array. */ | |
2123 | data -= uvalue; | |
2124 | break; | |
2125 | default: | |
2126 | printf ("<corrupt>\n"); | |
2127 | warn (_("corrupt discr_list - not using a block form\n")); | |
2128 | return; | |
2129 | } | |
2130 | ||
2131 | if (uvalue < 2) | |
2132 | { | |
2133 | printf ("<corrupt>\n"); | |
2134 | warn (_("corrupt discr_list - block not long enough\n")); | |
2135 | return; | |
2136 | } | |
2137 | ||
2138 | bfd_boolean is_signed = | |
2139 | (level > 0 && level <= MAX_CU_NESTING) | |
2140 | ? level_type_signed [level - 1] : FALSE; | |
2141 | ||
2142 | printf ("("); | |
2143 | while (uvalue) | |
2144 | { | |
2145 | unsigned char discriminant; | |
2146 | unsigned int bytes_read; | |
2147 | ||
2148 | SAFE_BYTE_GET (discriminant, data, 1, end); | |
2149 | -- uvalue; | |
2150 | data ++; | |
2151 | ||
2152 | assert (uvalue > 0); | |
2153 | switch (discriminant) | |
2154 | { | |
2155 | case DW_DSC_label: | |
2156 | printf ("label "); | |
2157 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2158 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2159 | uvalue -= bytes_read; | |
2160 | data += bytes_read; | |
2161 | break; | |
2162 | ||
2163 | case DW_DSC_range: | |
2164 | printf ("range "); | |
2165 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2166 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2167 | uvalue -= bytes_read; | |
2168 | data += bytes_read; | |
2169 | ||
2170 | printf (".."); | |
2171 | read_and_print_leb128 (data, & bytes_read, end, is_signed); | |
2172 | assert (bytes_read <= uvalue && bytes_read > 0); | |
2173 | uvalue -= bytes_read; | |
2174 | data += bytes_read; | |
2175 | break; | |
2176 | ||
2177 | default: | |
2178 | printf ("<corrupt>\n"); | |
2179 | warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"), | |
2180 | discriminant); | |
2181 | return; | |
2182 | } | |
2183 | ||
2184 | if (uvalue) | |
2185 | printf (", "); | |
2186 | } | |
2187 | ||
2188 | if (is_signed) | |
2189 | printf (")(signed)"); | |
2190 | else | |
2191 | printf (")(unsigned)"); | |
2192 | } | |
2193 | ||
19e6b90e | 2194 | static unsigned char * |
dda8d76d NC |
2195 | read_and_display_attr_value (unsigned long attribute, |
2196 | unsigned long form, | |
2197 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 2198 | unsigned char * start, |
dda8d76d NC |
2199 | unsigned char * data, |
2200 | unsigned char * end, | |
2201 | dwarf_vma cu_offset, | |
2202 | dwarf_vma pointer_size, | |
2203 | dwarf_vma offset_size, | |
2204 | int dwarf_version, | |
2205 | debug_info * debug_info_p, | |
2206 | int do_loc, | |
2207 | struct dwarf_section * section, | |
2208 | struct cu_tu_set * this_set, | |
ec1b0fbb NC |
2209 | char delimiter, |
2210 | int level) | |
19e6b90e | 2211 | { |
ec1b0fbb NC |
2212 | dwarf_vma uvalue = 0; |
2213 | unsigned char * block_start = NULL; | |
2214 | unsigned char * orig_data = data; | |
2215 | unsigned int bytes_read; | |
19e6b90e | 2216 | |
f41e4712 | 2217 | if (data > end || (data == end && form != DW_FORM_flag_present)) |
0c588247 | 2218 | { |
f41e4712 | 2219 | warn (_("Corrupt attribute\n")); |
0c588247 NC |
2220 | return data; |
2221 | } | |
2222 | ||
19e6b90e L |
2223 | switch (form) |
2224 | { | |
2225 | default: | |
2226 | break; | |
2227 | ||
2228 | case DW_FORM_ref_addr: | |
2229 | if (dwarf_version == 2) | |
0c588247 | 2230 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
932fd279 | 2231 | else if (dwarf_version == 3 || dwarf_version == 4) |
0c588247 | 2232 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e | 2233 | else |
467c65bc NC |
2234 | error (_("Internal error: DWARF version is not 2, 3 or 4.\n")); |
2235 | ||
19e6b90e L |
2236 | break; |
2237 | ||
2238 | case DW_FORM_addr: | |
0c588247 | 2239 | SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
19e6b90e L |
2240 | break; |
2241 | ||
2242 | case DW_FORM_strp: | |
77145576 | 2243 | case DW_FORM_line_strp: |
932fd279 | 2244 | case DW_FORM_sec_offset: |
a081f3cd JJ |
2245 | case DW_FORM_GNU_ref_alt: |
2246 | case DW_FORM_GNU_strp_alt: | |
0c588247 | 2247 | SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
19e6b90e L |
2248 | break; |
2249 | ||
932fd279 JJ |
2250 | case DW_FORM_flag_present: |
2251 | uvalue = 1; | |
2252 | break; | |
2253 | ||
19e6b90e L |
2254 | case DW_FORM_ref1: |
2255 | case DW_FORM_flag: | |
2256 | case DW_FORM_data1: | |
0c588247 | 2257 | SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
19e6b90e L |
2258 | break; |
2259 | ||
2260 | case DW_FORM_ref2: | |
2261 | case DW_FORM_data2: | |
0c588247 | 2262 | SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
19e6b90e L |
2263 | break; |
2264 | ||
2265 | case DW_FORM_ref4: | |
2266 | case DW_FORM_data4: | |
0c588247 | 2267 | SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
19e6b90e L |
2268 | break; |
2269 | ||
2270 | case DW_FORM_sdata: | |
f6f0e17b | 2271 | uvalue = read_sleb128 (data, & bytes_read, end); |
19e6b90e L |
2272 | data += bytes_read; |
2273 | break; | |
2274 | ||
4723351a | 2275 | case DW_FORM_GNU_str_index: |
f6f0e17b | 2276 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
2277 | data += bytes_read; |
2278 | break; | |
2279 | ||
19e6b90e L |
2280 | case DW_FORM_ref_udata: |
2281 | case DW_FORM_udata: | |
f6f0e17b | 2282 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
2283 | data += bytes_read; |
2284 | break; | |
2285 | ||
2286 | case DW_FORM_indirect: | |
f6f0e17b | 2287 | form = read_uleb128 (data, & bytes_read, end); |
19e6b90e L |
2288 | data += bytes_read; |
2289 | if (!do_loc) | |
ef0b5f1c | 2290 | printf ("%c%s", delimiter, get_FORM_name (form)); |
77145576 JK |
2291 | if (form == DW_FORM_implicit_const) |
2292 | { | |
2293 | implicit_const = read_sleb128 (data, & bytes_read, end); | |
2294 | data += bytes_read; | |
2295 | } | |
ec1b0fbb NC |
2296 | return read_and_display_attr_value (attribute, form, implicit_const, |
2297 | start, data, end, | |
2298 | cu_offset, pointer_size, | |
19e6b90e | 2299 | offset_size, dwarf_version, |
ec4d4525 | 2300 | debug_info_p, do_loc, |
ec1b0fbb | 2301 | section, this_set, delimiter, level); |
4723351a | 2302 | case DW_FORM_GNU_addr_index: |
f6f0e17b | 2303 | uvalue = read_uleb128 (data, & bytes_read, end); |
4723351a CC |
2304 | data += bytes_read; |
2305 | break; | |
19e6b90e L |
2306 | } |
2307 | ||
2308 | switch (form) | |
2309 | { | |
2310 | case DW_FORM_ref_addr: | |
2311 | if (!do_loc) | |
ef0b5f1c | 2312 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
19e6b90e L |
2313 | break; |
2314 | ||
a081f3cd JJ |
2315 | case DW_FORM_GNU_ref_alt: |
2316 | if (!do_loc) | |
ef0b5f1c | 2317 | printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue)); |
dda8d76d | 2318 | /* FIXME: Follow the reference... */ |
a081f3cd JJ |
2319 | break; |
2320 | ||
19e6b90e L |
2321 | case DW_FORM_ref1: |
2322 | case DW_FORM_ref2: | |
2323 | case DW_FORM_ref4: | |
2324 | case DW_FORM_ref_udata: | |
2325 | if (!do_loc) | |
ef0b5f1c | 2326 | printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset)); |
19e6b90e L |
2327 | break; |
2328 | ||
2329 | case DW_FORM_data4: | |
2330 | case DW_FORM_addr: | |
932fd279 | 2331 | case DW_FORM_sec_offset: |
19e6b90e | 2332 | if (!do_loc) |
ef0b5f1c | 2333 | printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2334 | break; |
2335 | ||
932fd279 | 2336 | case DW_FORM_flag_present: |
19e6b90e L |
2337 | case DW_FORM_flag: |
2338 | case DW_FORM_data1: | |
2339 | case DW_FORM_data2: | |
2340 | case DW_FORM_sdata: | |
2341 | case DW_FORM_udata: | |
2342 | if (!do_loc) | |
ef0b5f1c | 2343 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue)); |
19e6b90e L |
2344 | break; |
2345 | ||
77145576 JK |
2346 | case DW_FORM_implicit_const: |
2347 | if (!do_loc) | |
2348 | printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const)); | |
2349 | break; | |
2350 | ||
19e6b90e L |
2351 | case DW_FORM_ref8: |
2352 | case DW_FORM_data8: | |
2bc8690c | 2353 | if (!do_loc) |
19e6b90e | 2354 | { |
74bc6052 | 2355 | dwarf_vma high_bits; |
a69c4772 | 2356 | dwarf_vma utmp; |
74bc6052 CC |
2357 | char buf[64]; |
2358 | ||
0c588247 | 2359 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
a69c4772 NC |
2360 | utmp = uvalue; |
2361 | if (form == DW_FORM_ref8) | |
2362 | add64 (& high_bits, & utmp, cu_offset); | |
ef0b5f1c | 2363 | printf ("%c0x%s", delimiter, |
a69c4772 | 2364 | dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
19e6b90e | 2365 | } |
0c588247 | 2366 | |
19e6b90e L |
2367 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2368 | && num_debug_info_entries == 0) | |
2369 | { | |
2370 | if (sizeof (uvalue) == 8) | |
0c588247 | 2371 | SAFE_BYTE_GET (uvalue, data, 8, end); |
19e6b90e | 2372 | else |
467c65bc | 2373 | error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
19e6b90e | 2374 | } |
0c588247 | 2375 | |
19e6b90e L |
2376 | data += 8; |
2377 | break; | |
2378 | ||
2f6cd591 JK |
2379 | case DW_FORM_data16: |
2380 | if (!do_loc) | |
2381 | { | |
2382 | dwarf_vma left_high_bits, left_low_bits; | |
2383 | dwarf_vma right_high_bits, right_low_bits; | |
2384 | ||
2385 | SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end); | |
2386 | SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end); | |
2387 | if (byte_get == byte_get_little_endian) | |
2388 | { | |
2389 | /* Swap them. */ | |
2390 | left_high_bits ^= right_high_bits; | |
2391 | right_high_bits ^= left_high_bits; | |
2392 | left_high_bits ^= right_high_bits; | |
2393 | left_low_bits ^= right_low_bits; | |
2394 | right_low_bits ^= left_low_bits; | |
2395 | left_low_bits ^= right_low_bits; | |
2396 | } | |
2397 | printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x" | |
2398 | "%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x", | |
2399 | left_high_bits, left_low_bits, right_high_bits, | |
2400 | right_low_bits); | |
2401 | } | |
2402 | data += 16; | |
2403 | break; | |
2404 | ||
19e6b90e L |
2405 | case DW_FORM_string: |
2406 | if (!do_loc) | |
ef0b5f1c | 2407 | printf ("%c%.*s", delimiter, (int) (end - data), data); |
0c588247 | 2408 | data += strnlen ((char *) data, end - data) + 1; |
19e6b90e L |
2409 | break; |
2410 | ||
2411 | case DW_FORM_block: | |
932fd279 | 2412 | case DW_FORM_exprloc: |
f6f0e17b | 2413 | uvalue = read_uleb128 (data, & bytes_read, end); |
19e6b90e | 2414 | block_start = data + bytes_read; |
a1165289 NC |
2415 | if (block_start >= end) |
2416 | { | |
2417 | warn (_("Block ends prematurely\n")); | |
2418 | uvalue = 0; | |
2419 | block_start = end; | |
2420 | } | |
afc72f15 NC |
2421 | |
2422 | uvalue = check_uvalue (block_start, uvalue, end); | |
2423 | ||
19e6b90e L |
2424 | if (do_loc) |
2425 | data = block_start + uvalue; | |
2426 | else | |
ef0b5f1c | 2427 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2428 | break; |
2429 | ||
2430 | case DW_FORM_block1: | |
0c588247 | 2431 | SAFE_BYTE_GET (uvalue, data, 1, end); |
19e6b90e | 2432 | block_start = data + 1; |
a1165289 NC |
2433 | if (block_start >= end) |
2434 | { | |
2435 | warn (_("Block ends prematurely\n")); | |
2436 | uvalue = 0; | |
2437 | block_start = end; | |
2438 | } | |
afc72f15 NC |
2439 | |
2440 | uvalue = check_uvalue (block_start, uvalue, end); | |
2441 | ||
19e6b90e L |
2442 | if (do_loc) |
2443 | data = block_start + uvalue; | |
2444 | else | |
ef0b5f1c | 2445 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2446 | break; |
2447 | ||
2448 | case DW_FORM_block2: | |
0c588247 | 2449 | SAFE_BYTE_GET (uvalue, data, 2, end); |
19e6b90e | 2450 | block_start = data + 2; |
a1165289 NC |
2451 | if (block_start >= end) |
2452 | { | |
2453 | warn (_("Block ends prematurely\n")); | |
2454 | uvalue = 0; | |
2455 | block_start = end; | |
2456 | } | |
afc72f15 NC |
2457 | |
2458 | uvalue = check_uvalue (block_start, uvalue, end); | |
2459 | ||
19e6b90e L |
2460 | if (do_loc) |
2461 | data = block_start + uvalue; | |
2462 | else | |
ef0b5f1c | 2463 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2464 | break; |
2465 | ||
2466 | case DW_FORM_block4: | |
0c588247 | 2467 | SAFE_BYTE_GET (uvalue, data, 4, end); |
19e6b90e | 2468 | block_start = data + 4; |
a1165289 NC |
2469 | /* PR 17512: file: 3371-3907-0.004. */ |
2470 | if (block_start >= end) | |
2471 | { | |
2472 | warn (_("Block ends prematurely\n")); | |
2473 | uvalue = 0; | |
2474 | block_start = end; | |
2475 | } | |
afc72f15 NC |
2476 | |
2477 | uvalue = check_uvalue (block_start, uvalue, end); | |
2478 | ||
19e6b90e L |
2479 | if (do_loc) |
2480 | data = block_start + uvalue; | |
2481 | else | |
ef0b5f1c | 2482 | data = display_block (block_start, uvalue, end, delimiter); |
19e6b90e L |
2483 | break; |
2484 | ||
2485 | case DW_FORM_strp: | |
2486 | if (!do_loc) | |
ef0b5f1c | 2487 | printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter, |
47704ddf KT |
2488 | dwarf_vmatoa ("x", uvalue), |
2489 | fetch_indirect_string (uvalue)); | |
19e6b90e L |
2490 | break; |
2491 | ||
77145576 JK |
2492 | case DW_FORM_line_strp: |
2493 | if (!do_loc) | |
2494 | printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter, | |
2495 | dwarf_vmatoa ("x", uvalue), | |
2496 | fetch_indirect_line_string (uvalue)); | |
2497 | break; | |
2498 | ||
4723351a CC |
2499 | case DW_FORM_GNU_str_index: |
2500 | if (!do_loc) | |
b4eb7656 | 2501 | { |
d85bf2ba NC |
2502 | const char * suffix = strrchr (section->name, '.'); |
2503 | bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE; | |
b4eb7656 | 2504 | |
ef0b5f1c | 2505 | printf (_("%c(indexed string: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2506 | dwarf_vmatoa ("x", uvalue), |
2507 | fetch_indexed_string (uvalue, this_set, offset_size, dwo)); | |
2508 | } | |
4723351a CC |
2509 | break; |
2510 | ||
a081f3cd JJ |
2511 | case DW_FORM_GNU_strp_alt: |
2512 | if (!do_loc) | |
dda8d76d NC |
2513 | { |
2514 | printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter, | |
2515 | dwarf_vmatoa ("x", uvalue), | |
2516 | fetch_alt_indirect_string (uvalue)); | |
2517 | } | |
a081f3cd JJ |
2518 | break; |
2519 | ||
19e6b90e L |
2520 | case DW_FORM_indirect: |
2521 | /* Handled above. */ | |
2522 | break; | |
2523 | ||
2b6f5997 CC |
2524 | case DW_FORM_ref_sig8: |
2525 | if (!do_loc) | |
2526 | { | |
74bc6052 CC |
2527 | dwarf_vma high_bits; |
2528 | char buf[64]; | |
2529 | ||
0c588247 | 2530 | SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
ef0b5f1c | 2531 | printf ("%csignature: 0x%s", delimiter, |
74bc6052 | 2532 | dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); |
2b6f5997 | 2533 | } |
74bc6052 | 2534 | data += 8; |
2b6f5997 CC |
2535 | break; |
2536 | ||
4723351a CC |
2537 | case DW_FORM_GNU_addr_index: |
2538 | if (!do_loc) | |
ef0b5f1c | 2539 | printf (_("%c(addr_index: 0x%s): %s"), delimiter, |
b4eb7656 AM |
2540 | dwarf_vmatoa ("x", uvalue), |
2541 | fetch_indexed_value (uvalue * pointer_size, pointer_size)); | |
4723351a CC |
2542 | break; |
2543 | ||
19e6b90e L |
2544 | default: |
2545 | warn (_("Unrecognized form: %lu\n"), form); | |
2546 | break; | |
2547 | } | |
2548 | ||
19e6b90e | 2549 | if ((do_loc || do_debug_loc || do_debug_ranges) |
fd2f0033 TT |
2550 | && num_debug_info_entries == 0 |
2551 | && debug_info_p != NULL) | |
19e6b90e L |
2552 | { |
2553 | switch (attribute) | |
2554 | { | |
2555 | case DW_AT_frame_base: | |
2556 | have_frame_base = 1; | |
1a0670f3 | 2557 | /* Fall through. */ |
19e6b90e | 2558 | case DW_AT_location: |
9f272209 | 2559 | case DW_AT_GNU_locviews: |
e2a0d921 NC |
2560 | case DW_AT_string_length: |
2561 | case DW_AT_return_addr: | |
19e6b90e L |
2562 | case DW_AT_data_member_location: |
2563 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
2564 | case DW_AT_segment: |
2565 | case DW_AT_static_link: | |
2566 | case DW_AT_use_location: | |
bc0a77d2 | 2567 | case DW_AT_call_value: |
629e7ca8 | 2568 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 2569 | case DW_AT_call_data_value: |
629e7ca8 | 2570 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 2571 | case DW_AT_call_target: |
629e7ca8 | 2572 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 2573 | case DW_AT_call_target_clobbered: |
629e7ca8 | 2574 | case DW_AT_GNU_call_site_target_clobbered: |
b4eb7656 | 2575 | if ((dwarf_version < 4 |
212b6063 | 2576 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2577 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2578 | { |
2579 | /* Process location list. */ | |
91d6fa6a | 2580 | unsigned int lmax = debug_info_p->max_loc_offsets; |
19e6b90e L |
2581 | unsigned int num = debug_info_p->num_loc_offsets; |
2582 | ||
91d6fa6a | 2583 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2584 | { |
91d6fa6a | 2585 | lmax += 1024; |
467c65bc | 2586 | debug_info_p->loc_offsets = (dwarf_vma *) |
b4eb7656 AM |
2587 | xcrealloc (debug_info_p->loc_offsets, |
2588 | lmax, sizeof (*debug_info_p->loc_offsets)); | |
9f272209 AO |
2589 | debug_info_p->loc_views = (dwarf_vma *) |
2590 | xcrealloc (debug_info_p->loc_views, | |
2591 | lmax, sizeof (*debug_info_p->loc_views)); | |
3f5e193b | 2592 | debug_info_p->have_frame_base = (int *) |
b4eb7656 AM |
2593 | xcrealloc (debug_info_p->have_frame_base, |
2594 | lmax, sizeof (*debug_info_p->have_frame_base)); | |
91d6fa6a | 2595 | debug_info_p->max_loc_offsets = lmax; |
19e6b90e | 2596 | } |
341f9135 | 2597 | if (this_set != NULL) |
b4eb7656 | 2598 | uvalue += this_set->section_offsets [DW_SECT_LOC]; |
19e6b90e | 2599 | debug_info_p->have_frame_base [num] = have_frame_base; |
9f272209 AO |
2600 | if (attribute != DW_AT_GNU_locviews) |
2601 | { | |
a7504f87 NC |
2602 | /* Corrupt DWARF info can produce more offsets than views. |
2603 | See PR 23062 for an example. */ | |
2604 | if (debug_info_p->num_loc_offsets | |
2605 | > debug_info_p->num_loc_views) | |
2606 | warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); | |
2607 | else | |
2608 | { | |
2609 | debug_info_p->loc_offsets [num] = uvalue; | |
2610 | debug_info_p->num_loc_offsets++; | |
2611 | } | |
9f272209 AO |
2612 | } |
2613 | else | |
2614 | { | |
2615 | assert (debug_info_p->num_loc_views <= num); | |
2616 | num = debug_info_p->num_loc_views; | |
a7504f87 NC |
2617 | if (num > debug_info_p->num_loc_offsets) |
2618 | warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); | |
2619 | else | |
2620 | { | |
2621 | debug_info_p->loc_views [num] = uvalue; | |
2622 | debug_info_p->num_loc_views++; | |
2623 | } | |
9f272209 | 2624 | } |
19e6b90e L |
2625 | } |
2626 | break; | |
e2a0d921 | 2627 | |
19e6b90e L |
2628 | case DW_AT_low_pc: |
2629 | if (need_base_address) | |
2630 | debug_info_p->base_address = uvalue; | |
2631 | break; | |
2632 | ||
4723351a | 2633 | case DW_AT_GNU_addr_base: |
b4eb7656 | 2634 | debug_info_p->addr_base = uvalue; |
4723351a CC |
2635 | break; |
2636 | ||
2637 | case DW_AT_GNU_ranges_base: | |
b4eb7656 | 2638 | debug_info_p->ranges_base = uvalue; |
4723351a CC |
2639 | break; |
2640 | ||
19e6b90e | 2641 | case DW_AT_ranges: |
b4eb7656 | 2642 | if ((dwarf_version < 4 |
212b6063 | 2643 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 2644 | || form == DW_FORM_sec_offset) |
19e6b90e L |
2645 | { |
2646 | /* Process range list. */ | |
91d6fa6a | 2647 | unsigned int lmax = debug_info_p->max_range_lists; |
19e6b90e L |
2648 | unsigned int num = debug_info_p->num_range_lists; |
2649 | ||
91d6fa6a | 2650 | if (lmax == 0 || num >= lmax) |
19e6b90e | 2651 | { |
91d6fa6a | 2652 | lmax += 1024; |
467c65bc | 2653 | debug_info_p->range_lists = (dwarf_vma *) |
b4eb7656 AM |
2654 | xcrealloc (debug_info_p->range_lists, |
2655 | lmax, sizeof (*debug_info_p->range_lists)); | |
91d6fa6a | 2656 | debug_info_p->max_range_lists = lmax; |
19e6b90e L |
2657 | } |
2658 | debug_info_p->range_lists [num] = uvalue; | |
2659 | debug_info_p->num_range_lists++; | |
2660 | } | |
2661 | break; | |
2662 | ||
d85bf2ba NC |
2663 | case DW_AT_GNU_dwo_name: |
2664 | case DW_AT_dwo_name: | |
2665 | if (need_dwo_info) | |
2666 | switch (form) | |
2667 | { | |
2668 | case DW_FORM_strp: | |
24841daa | 2669 | add_dwo_name ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba NC |
2670 | break; |
2671 | case DW_FORM_GNU_str_index: | |
24841daa | 2672 | add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2673 | break; |
2674 | case DW_FORM_string: | |
24841daa | 2675 | add_dwo_name ((const char *) orig_data); |
d85bf2ba NC |
2676 | break; |
2677 | default: | |
2678 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2679 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2680 | break; |
2681 | } | |
2682 | break; | |
2683 | ||
2684 | case DW_AT_comp_dir: | |
2685 | /* FIXME: Also extract a build-id in a CU/TU. */ | |
2686 | if (need_dwo_info) | |
2687 | switch (form) | |
2688 | { | |
2689 | case DW_FORM_strp: | |
24841daa | 2690 | add_dwo_dir ((const char *) fetch_indirect_string (uvalue)); |
d85bf2ba NC |
2691 | break; |
2692 | case DW_FORM_line_strp: | |
24841daa | 2693 | add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue)); |
d85bf2ba NC |
2694 | break; |
2695 | case DW_FORM_GNU_str_index: | |
24841daa | 2696 | add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, FALSE)); |
d85bf2ba NC |
2697 | break; |
2698 | case DW_FORM_string: | |
24841daa | 2699 | add_dwo_dir ((const char *) orig_data); |
d85bf2ba NC |
2700 | break; |
2701 | default: | |
2702 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2703 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2704 | break; |
2705 | } | |
2706 | break; | |
2707 | ||
2708 | case DW_AT_GNU_dwo_id: | |
2709 | if (need_dwo_info) | |
2710 | switch (form) | |
2711 | { | |
2712 | case DW_FORM_data8: | |
24841daa NC |
2713 | /* FIXME: Record the length of the ID as well ? */ |
2714 | add_dwo_id ((const char *) (data - 8)); | |
d85bf2ba NC |
2715 | break; |
2716 | default: | |
2717 | warn (_("Unsupported form (%s) for attribute %s\n"), | |
2718 | get_FORM_name (form), get_AT_name (attribute)); | |
d85bf2ba NC |
2719 | break; |
2720 | } | |
2721 | break; | |
2722 | ||
19e6b90e L |
2723 | default: |
2724 | break; | |
2725 | } | |
2726 | } | |
2727 | ||
4ccf1e31 | 2728 | if (do_loc || attribute == 0) |
19e6b90e L |
2729 | return data; |
2730 | ||
ec4d4525 | 2731 | /* For some attributes we can display further information. */ |
19e6b90e L |
2732 | switch (attribute) |
2733 | { | |
ec1b0fbb NC |
2734 | case DW_AT_type: |
2735 | if (level >= 0 && level < MAX_CU_NESTING) | |
2736 | { | |
2737 | bfd_boolean is_signed = FALSE; | |
2738 | ||
2739 | get_type_signedness (start, start + uvalue, end, pointer_size, | |
2740 | offset_size, dwarf_version, & is_signed, FALSE); | |
2741 | level_type_signed[level] = is_signed; | |
2742 | } | |
2743 | break; | |
2744 | ||
19e6b90e | 2745 | case DW_AT_inline: |
2e9e81a8 | 2746 | printf ("\t"); |
19e6b90e L |
2747 | switch (uvalue) |
2748 | { | |
2749 | case DW_INL_not_inlined: | |
2750 | printf (_("(not inlined)")); | |
2751 | break; | |
2752 | case DW_INL_inlined: | |
2753 | printf (_("(inlined)")); | |
2754 | break; | |
2755 | case DW_INL_declared_not_inlined: | |
2756 | printf (_("(declared as inline but ignored)")); | |
2757 | break; | |
2758 | case DW_INL_declared_inlined: | |
2759 | printf (_("(declared as inline and inlined)")); | |
2760 | break; | |
2761 | default: | |
47704ddf KT |
2762 | printf (_(" (Unknown inline attribute value: %s)"), |
2763 | dwarf_vmatoa ("x", uvalue)); | |
19e6b90e L |
2764 | break; |
2765 | } | |
2766 | break; | |
2767 | ||
2768 | case DW_AT_language: | |
2e9e81a8 | 2769 | printf ("\t"); |
19e6b90e L |
2770 | switch (uvalue) |
2771 | { | |
4b78141a | 2772 | /* Ordered by the numeric value of these constants. */ |
19e6b90e | 2773 | case DW_LANG_C89: printf ("(ANSI C)"); break; |
4b78141a NC |
2774 | case DW_LANG_C: printf ("(non-ANSI C)"); break; |
2775 | case DW_LANG_Ada83: printf ("(Ada)"); break; | |
19e6b90e | 2776 | case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
4b78141a NC |
2777 | case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
2778 | case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; | |
19e6b90e L |
2779 | case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
2780 | case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; | |
19e6b90e | 2781 | case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
4b78141a | 2782 | case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
19e6b90e | 2783 | /* DWARF 2.1 values. */ |
4b78141a | 2784 | case DW_LANG_Java: printf ("(Java)"); break; |
19e6b90e L |
2785 | case DW_LANG_C99: printf ("(ANSI C99)"); break; |
2786 | case DW_LANG_Ada95: printf ("(ADA 95)"); break; | |
2787 | case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; | |
4b78141a NC |
2788 | /* DWARF 3 values. */ |
2789 | case DW_LANG_PLI: printf ("(PLI)"); break; | |
2790 | case DW_LANG_ObjC: printf ("(Objective C)"); break; | |
2791 | case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; | |
2792 | case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; | |
2793 | case DW_LANG_D: printf ("(D)"); break; | |
2b6f5997 CC |
2794 | /* DWARF 4 values. */ |
2795 | case DW_LANG_Python: printf ("(Python)"); break; | |
3362e0d9 | 2796 | /* DWARF 5 values. */ |
2008a0db | 2797 | case DW_LANG_OpenCL: printf ("(OpenCL)"); break; |
3362e0d9 | 2798 | case DW_LANG_Go: printf ("(Go)"); break; |
2008a0db TT |
2799 | case DW_LANG_Modula3: printf ("(Modula 3)"); break; |
2800 | case DW_LANG_Haskell: printf ("(Haskell)"); break; | |
2801 | case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; | |
8bc10620 | 2802 | case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
2008a0db TT |
2803 | case DW_LANG_OCaml: printf ("(OCaml)"); break; |
2804 | case DW_LANG_Rust: printf ("(Rust)"); break; | |
6ddfe5b4 | 2805 | case DW_LANG_C11: printf ("(C11)"); break; |
2008a0db TT |
2806 | case DW_LANG_Swift: printf ("(Swift)"); break; |
2807 | case DW_LANG_Julia: printf ("(Julia)"); break; | |
2808 | case DW_LANG_Dylan: printf ("(Dylan)"); break; | |
8bc10620 | 2809 | case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
5a195044 MW |
2810 | case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
2811 | case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; | |
2008a0db | 2812 | case DW_LANG_RenderScript: printf ("(RenderScript)"); break; |
19e6b90e L |
2813 | /* MIPS extension. */ |
2814 | case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; | |
2815 | /* UPC extension. */ | |
2816 | case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; | |
2817 | default: | |
4b78141a | 2818 | if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
9cf03b7e | 2819 | printf (_("(implementation defined: %s)"), |
467c65bc | 2820 | dwarf_vmatoa ("x", uvalue)); |
4b78141a | 2821 | else |
9cf03b7e | 2822 | printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
19e6b90e L |
2823 | break; |
2824 | } | |
2825 | break; | |
2826 | ||
2827 | case DW_AT_encoding: | |
2e9e81a8 | 2828 | printf ("\t"); |
19e6b90e L |
2829 | switch (uvalue) |
2830 | { | |
2831 | case DW_ATE_void: printf ("(void)"); break; | |
2832 | case DW_ATE_address: printf ("(machine address)"); break; | |
2833 | case DW_ATE_boolean: printf ("(boolean)"); break; | |
2834 | case DW_ATE_complex_float: printf ("(complex float)"); break; | |
2835 | case DW_ATE_float: printf ("(float)"); break; | |
2836 | case DW_ATE_signed: printf ("(signed)"); break; | |
2837 | case DW_ATE_signed_char: printf ("(signed char)"); break; | |
2838 | case DW_ATE_unsigned: printf ("(unsigned)"); break; | |
2839 | case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; | |
e2a0d921 | 2840 | /* DWARF 2.1 values: */ |
19e6b90e L |
2841 | case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
2842 | case DW_ATE_decimal_float: printf ("(decimal float)"); break; | |
e2a0d921 NC |
2843 | /* DWARF 3 values: */ |
2844 | case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; | |
2845 | case DW_ATE_numeric_string: printf ("(numeric_string)"); break; | |
2846 | case DW_ATE_edited: printf ("(edited)"); break; | |
2847 | case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; | |
2848 | case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; | |
04914e37 NC |
2849 | /* DWARF 4 values: */ |
2850 | case DW_ATE_UTF: printf ("(unicode string)"); break; | |
2851 | /* DWARF 5 values: */ | |
2852 | case DW_ATE_UCS: printf ("(UCS)"); break; | |
2853 | case DW_ATE_ASCII: printf ("(ASCII)"); break; | |
2854 | ||
e2a0d921 NC |
2855 | /* HP extensions: */ |
2856 | case DW_ATE_HP_float80: printf ("(HP_float80)"); break; | |
2857 | case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; | |
2858 | case DW_ATE_HP_float128: printf ("(HP_float128)"); break; | |
2859 | case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; | |
2860 | case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; | |
2861 | case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; | |
2862 | case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; | |
2863 | ||
19e6b90e L |
2864 | default: |
2865 | if (uvalue >= DW_ATE_lo_user | |
2866 | && uvalue <= DW_ATE_hi_user) | |
9cf03b7e | 2867 | printf (_("(user defined type)")); |
19e6b90e | 2868 | else |
9cf03b7e | 2869 | printf (_("(unknown type)")); |
19e6b90e L |
2870 | break; |
2871 | } | |
2872 | break; | |
2873 | ||
2874 | case DW_AT_accessibility: | |
2e9e81a8 | 2875 | printf ("\t"); |
19e6b90e L |
2876 | switch (uvalue) |
2877 | { | |
2878 | case DW_ACCESS_public: printf ("(public)"); break; | |
2879 | case DW_ACCESS_protected: printf ("(protected)"); break; | |
2880 | case DW_ACCESS_private: printf ("(private)"); break; | |
2881 | default: | |
9cf03b7e | 2882 | printf (_("(unknown accessibility)")); |
19e6b90e L |
2883 | break; |
2884 | } | |
2885 | break; | |
2886 | ||
2887 | case DW_AT_visibility: | |
2e9e81a8 | 2888 | printf ("\t"); |
19e6b90e L |
2889 | switch (uvalue) |
2890 | { | |
2891 | case DW_VIS_local: printf ("(local)"); break; | |
2892 | case DW_VIS_exported: printf ("(exported)"); break; | |
2893 | case DW_VIS_qualified: printf ("(qualified)"); break; | |
9cf03b7e | 2894 | default: printf (_("(unknown visibility)")); break; |
19e6b90e L |
2895 | } |
2896 | break; | |
2897 | ||
04914e37 NC |
2898 | case DW_AT_endianity: |
2899 | printf ("\t"); | |
2900 | switch (uvalue) | |
2901 | { | |
2902 | case DW_END_default: printf ("(default)"); break; | |
2903 | case DW_END_big: printf ("(big)"); break; | |
2904 | case DW_END_little: printf ("(little)"); break; | |
2905 | default: | |
2906 | if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user) | |
2907 | printf (_("(user specified)")); | |
2908 | else | |
2909 | printf (_("(unknown endianity)")); | |
2910 | break; | |
2911 | } | |
2912 | break; | |
2913 | ||
19e6b90e | 2914 | case DW_AT_virtuality: |
2e9e81a8 | 2915 | printf ("\t"); |
19e6b90e L |
2916 | switch (uvalue) |
2917 | { | |
2918 | case DW_VIRTUALITY_none: printf ("(none)"); break; | |
2919 | case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; | |
2920 | case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; | |
9cf03b7e | 2921 | default: printf (_("(unknown virtuality)")); break; |
19e6b90e L |
2922 | } |
2923 | break; | |
2924 | ||
2925 | case DW_AT_identifier_case: | |
2e9e81a8 | 2926 | printf ("\t"); |
19e6b90e L |
2927 | switch (uvalue) |
2928 | { | |
2929 | case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; | |
2930 | case DW_ID_up_case: printf ("(up_case)"); break; | |
2931 | case DW_ID_down_case: printf ("(down_case)"); break; | |
2932 | case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; | |
9cf03b7e | 2933 | default: printf (_("(unknown case)")); break; |
19e6b90e L |
2934 | } |
2935 | break; | |
2936 | ||
2937 | case DW_AT_calling_convention: | |
2e9e81a8 | 2938 | printf ("\t"); |
19e6b90e L |
2939 | switch (uvalue) |
2940 | { | |
2941 | case DW_CC_normal: printf ("(normal)"); break; | |
2942 | case DW_CC_program: printf ("(program)"); break; | |
2943 | case DW_CC_nocall: printf ("(nocall)"); break; | |
04914e37 NC |
2944 | case DW_CC_pass_by_reference: printf ("(pass by ref)"); break; |
2945 | case DW_CC_pass_by_value: printf ("(pass by value)"); break; | |
2946 | case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break; | |
2947 | case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break; | |
19e6b90e L |
2948 | default: |
2949 | if (uvalue >= DW_CC_lo_user | |
2950 | && uvalue <= DW_CC_hi_user) | |
9cf03b7e | 2951 | printf (_("(user defined)")); |
19e6b90e | 2952 | else |
9cf03b7e | 2953 | printf (_("(unknown convention)")); |
19e6b90e L |
2954 | } |
2955 | break; | |
2956 | ||
2957 | case DW_AT_ordering: | |
2e9e81a8 | 2958 | printf ("\t"); |
19e6b90e L |
2959 | switch (uvalue) |
2960 | { | |
04914e37 | 2961 | case 255: |
9cf03b7e | 2962 | case -1: printf (_("(undefined)")); break; |
19e6b90e L |
2963 | case 0: printf ("(row major)"); break; |
2964 | case 1: printf ("(column major)"); break; | |
2965 | } | |
2966 | break; | |
2967 | ||
04914e37 NC |
2968 | case DW_AT_decimal_sign: |
2969 | printf ("\t"); | |
2970 | switch (uvalue) | |
2971 | { | |
2972 | case DW_DS_unsigned: printf (_("(unsigned)")); break; | |
2973 | case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break; | |
2974 | case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break; | |
2975 | case DW_DS_leading_separate: printf (_("(leading separate)")); break; | |
2976 | case DW_DS_trailing_separate: printf (_("(trailing separate)")); break; | |
2977 | default: printf (_("(unrecognised)")); break; | |
2978 | } | |
2979 | break; | |
2980 | ||
2981 | case DW_AT_defaulted: | |
2982 | printf ("\t"); | |
2983 | switch (uvalue) | |
2984 | { | |
2985 | case DW_DEFAULTED_no: printf (_("(no)")); break; | |
2986 | case DW_DEFAULTED_in_class: printf (_("(in class)")); break; | |
2987 | case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break; | |
2988 | default: printf (_("(unrecognised)")); break; | |
2989 | } | |
2990 | break; | |
2991 | ||
2992 | case DW_AT_discr_list: | |
2993 | printf ("\t"); | |
ec1b0fbb | 2994 | display_discr_list (form, uvalue, data, end, level); |
04914e37 NC |
2995 | break; |
2996 | ||
19e6b90e L |
2997 | case DW_AT_frame_base: |
2998 | have_frame_base = 1; | |
1a0670f3 | 2999 | /* Fall through. */ |
19e6b90e | 3000 | case DW_AT_location: |
e2a0d921 NC |
3001 | case DW_AT_string_length: |
3002 | case DW_AT_return_addr: | |
19e6b90e L |
3003 | case DW_AT_data_member_location: |
3004 | case DW_AT_vtable_elem_location: | |
e2a0d921 NC |
3005 | case DW_AT_segment: |
3006 | case DW_AT_static_link: | |
3007 | case DW_AT_use_location: | |
bc0a77d2 | 3008 | case DW_AT_call_value: |
629e7ca8 | 3009 | case DW_AT_GNU_call_site_value: |
bc0a77d2 | 3010 | case DW_AT_call_data_value: |
629e7ca8 | 3011 | case DW_AT_GNU_call_site_data_value: |
bc0a77d2 | 3012 | case DW_AT_call_target: |
629e7ca8 | 3013 | case DW_AT_GNU_call_site_target: |
bc0a77d2 | 3014 | case DW_AT_call_target_clobbered: |
629e7ca8 | 3015 | case DW_AT_GNU_call_site_target_clobbered: |
212b6063 | 3016 | if ((dwarf_version < 4 |
b4eb7656 | 3017 | && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
932fd279 | 3018 | || form == DW_FORM_sec_offset) |
2e9e81a8 | 3019 | printf (_(" (location list)")); |
e2a0d921 | 3020 | /* Fall through. */ |
19e6b90e L |
3021 | case DW_AT_allocated: |
3022 | case DW_AT_associated: | |
3023 | case DW_AT_data_location: | |
3024 | case DW_AT_stride: | |
3025 | case DW_AT_upper_bound: | |
cecf136e | 3026 | case DW_AT_lower_bound: |
19e6b90e L |
3027 | if (block_start) |
3028 | { | |
3029 | int need_frame_base; | |
3030 | ||
2e9e81a8 | 3031 | printf ("\t("); |
19e6b90e L |
3032 | need_frame_base = decode_location_expression (block_start, |
3033 | pointer_size, | |
b7807392 JJ |
3034 | offset_size, |
3035 | dwarf_version, | |
19e6b90e | 3036 | uvalue, |
f1c4cc75 | 3037 | cu_offset, section); |
19e6b90e L |
3038 | printf (")"); |
3039 | if (need_frame_base && !have_frame_base) | |
3040 | printf (_(" [without DW_AT_frame_base]")); | |
3041 | } | |
19e6b90e L |
3042 | break; |
3043 | ||
c54207d3 NC |
3044 | case DW_AT_data_bit_offset: |
3045 | case DW_AT_byte_size: | |
3046 | case DW_AT_bit_size: | |
3047 | case DW_AT_string_length_byte_size: | |
3048 | case DW_AT_string_length_bit_size: | |
3049 | case DW_AT_bit_stride: | |
3050 | if (form == DW_FORM_exprloc) | |
3051 | { | |
3052 | printf ("\t("); | |
3053 | (void) decode_location_expression (block_start, pointer_size, | |
3054 | offset_size, dwarf_version, | |
3055 | uvalue, cu_offset, section); | |
3056 | printf (")"); | |
3057 | } | |
3058 | break; | |
3059 | ||
ec4d4525 NC |
3060 | case DW_AT_import: |
3061 | { | |
a081f3cd JJ |
3062 | if (form == DW_FORM_ref_sig8 |
3063 | || form == DW_FORM_GNU_ref_alt) | |
b4eb7656 | 3064 | break; |
2b6f5997 | 3065 | |
ec4d4525 NC |
3066 | if (form == DW_FORM_ref1 |
3067 | || form == DW_FORM_ref2 | |
a7a0b6a5 JK |
3068 | || form == DW_FORM_ref4 |
3069 | || form == DW_FORM_ref_udata) | |
ec4d4525 NC |
3070 | uvalue += cu_offset; |
3071 | ||
6e3d6dc1 | 3072 | if (uvalue >= section->size) |
f3853b34 | 3073 | warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), |
47704ddf KT |
3074 | dwarf_vmatoa ("x", uvalue), |
3075 | (unsigned long) (orig_data - section->start)); | |
6e3d6dc1 NC |
3076 | else |
3077 | { | |
3078 | unsigned long abbrev_number; | |
3079 | abbrev_entry * entry; | |
3080 | ||
f6f0e17b | 3081 | abbrev_number = read_uleb128 (section->start + uvalue, NULL, end); |
cecf136e | 3082 | |
2e9e81a8 | 3083 | printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
afd6e1ff JJ |
3084 | /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
3085 | use different abbrev table, and we don't track .debug_info chunks | |
3086 | yet. */ | |
3087 | if (form != DW_FORM_ref_addr) | |
3088 | { | |
3089 | for (entry = first_abbrev; entry != NULL; entry = entry->next) | |
3090 | if (entry->entry == abbrev_number) | |
3091 | break; | |
3092 | if (entry != NULL) | |
3093 | printf (" (%s)", get_TAG_name (entry->tag)); | |
3094 | } | |
6e3d6dc1 NC |
3095 | printf ("]"); |
3096 | } | |
ec4d4525 NC |
3097 | } |
3098 | break; | |
3099 | ||
19e6b90e L |
3100 | default: |
3101 | break; | |
3102 | } | |
3103 | ||
3104 | return data; | |
3105 | } | |
3106 | ||
19e6b90e | 3107 | static unsigned char * |
dda8d76d NC |
3108 | read_and_display_attr (unsigned long attribute, |
3109 | unsigned long form, | |
3110 | dwarf_signed_vma implicit_const, | |
ec1b0fbb | 3111 | unsigned char * start, |
dda8d76d NC |
3112 | unsigned char * data, |
3113 | unsigned char * end, | |
3114 | dwarf_vma cu_offset, | |
3115 | dwarf_vma pointer_size, | |
3116 | dwarf_vma offset_size, | |
3117 | int dwarf_version, | |
3118 | debug_info * debug_info_p, | |
3119 | int do_loc, | |
3120 | struct dwarf_section * section, | |
ec1b0fbb NC |
3121 | struct cu_tu_set * this_set, |
3122 | int level) | |
19e6b90e L |
3123 | { |
3124 | if (!do_loc) | |
750f03b7 | 3125 | printf (" %-18s:", get_AT_name (attribute)); |
ec1b0fbb NC |
3126 | data = read_and_display_attr_value (attribute, form, implicit_const, |
3127 | start, data, end, | |
f6f0e17b | 3128 | cu_offset, pointer_size, offset_size, |
19e6b90e | 3129 | dwarf_version, debug_info_p, |
ec1b0fbb | 3130 | do_loc, section, this_set, ' ', level); |
19e6b90e L |
3131 | if (!do_loc) |
3132 | printf ("\n"); | |
3133 | return data; | |
3134 | } | |
3135 | ||
dda8d76d | 3136 | /* Like load_debug_section, but if the ordinary call fails, and we are |
24841daa NC |
3137 | following debug links, then attempt to load the requested section |
3138 | from one of the separate debug info files. */ | |
dda8d76d NC |
3139 | |
3140 | static bfd_boolean | |
3141 | load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum, | |
24841daa | 3142 | void * handle) |
dda8d76d | 3143 | { |
24841daa | 3144 | if (load_debug_section (sec_enum, handle)) |
dda8d76d | 3145 | { |
24841daa NC |
3146 | if (debug_displays[sec_enum].section.filename == NULL) |
3147 | { | |
3148 | /* See if we can associate a filename with this section. */ | |
3149 | separate_info * i; | |
3150 | ||
3151 | for (i = first_separate_info; i != NULL; i = i->next) | |
3152 | if (i->handle == handle) | |
3153 | { | |
3154 | debug_displays[sec_enum].section.filename = i->filename; | |
3155 | break; | |
3156 | } | |
3157 | } | |
3158 | ||
dda8d76d NC |
3159 | return TRUE; |
3160 | } | |
3161 | ||
24841daa NC |
3162 | if (do_follow_links) |
3163 | { | |
3164 | separate_info * i; | |
3165 | ||
3166 | for (i = first_separate_info; i != NULL; i = i->next) | |
3167 | { | |
3168 | if (load_debug_section (sec_enum, i->handle)) | |
3169 | { | |
3170 | debug_displays[sec_enum].section.filename = i->filename; | |
3171 | ||
3172 | /* FIXME: We should check to see if any of the remaining debug info | |
3173 | files also contain this section, and, umm, do something about it. */ | |
3174 | return TRUE; | |
3175 | } | |
3176 | } | |
3177 | } | |
dda8d76d NC |
3178 | |
3179 | return FALSE; | |
3180 | } | |
3181 | ||
3182 | static void | |
3183 | introduce (struct dwarf_section * section, bfd_boolean raw) | |
3184 | { | |
3185 | if (raw) | |
3186 | { | |
3187 | if (do_follow_links && section->filename) | |
3188 | printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"), | |
3189 | section->name, section->filename); | |
3190 | else | |
3191 | printf (_("Raw dump of debug contents of section %s:\n\n"), section->name); | |
3192 | } | |
3193 | else | |
3194 | { | |
3195 | if (do_follow_links && section->filename) | |
3196 | printf (_("Contents of the %s section (loaded from %s):\n\n"), | |
3197 | section->name, section->filename); | |
3198 | else | |
3199 | printf (_("Contents of the %s section:\n\n"), section->name); | |
3200 | } | |
3201 | } | |
3202 | ||
d85bf2ba NC |
3203 | /* Process the contents of a .debug_info section. |
3204 | If do_loc is TRUE then we are scanning for location lists and dwo tags | |
3205 | and we do not want to display anything to the user. | |
3206 | If do_types is TRUE, we are processing a .debug_types section instead of | |
3207 | a .debug_info section. | |
3208 | The information displayed is restricted by the values in DWARF_START_DIE | |
3209 | and DWARF_CUTOFF_LEVEL. | |
3210 | Returns TRUE upon success. Otherwise an error or warning message is | |
3211 | printed and FALSE is returned. */ | |
19e6b90e | 3212 | |
d85bf2ba NC |
3213 | static bfd_boolean |
3214 | process_debug_info (struct dwarf_section * section, | |
3215 | void * file, | |
3216 | enum dwarf_section_display_enum abbrev_sec, | |
3217 | bfd_boolean do_loc, | |
3218 | bfd_boolean do_types) | |
19e6b90e L |
3219 | { |
3220 | unsigned char *start = section->start; | |
3221 | unsigned char *end = start + section->size; | |
3222 | unsigned char *section_begin; | |
3223 | unsigned int unit; | |
3224 | unsigned int num_units = 0; | |
3225 | ||
3226 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3227 | && num_debug_info_entries == 0 |
3228 | && ! do_types) | |
19e6b90e | 3229 | { |
767221a9 | 3230 | dwarf_vma length; |
19e6b90e L |
3231 | |
3232 | /* First scan the section to get the number of comp units. */ | |
3233 | for (section_begin = start, num_units = 0; section_begin < end; | |
3234 | num_units ++) | |
3235 | { | |
3236 | /* Read the first 4 bytes. For a 32-bit DWARF section, this | |
3237 | will be the length. For a 64-bit DWARF section, it'll be | |
3238 | the escape code 0xffffffff followed by an 8 byte length. */ | |
0c588247 | 3239 | SAFE_BYTE_GET (length, section_begin, 4, end); |
19e6b90e L |
3240 | |
3241 | if (length == 0xffffffff) | |
3242 | { | |
0c588247 | 3243 | SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
19e6b90e L |
3244 | section_begin += length + 12; |
3245 | } | |
ec4d4525 NC |
3246 | else if (length >= 0xfffffff0 && length < 0xffffffff) |
3247 | { | |
767221a9 NC |
3248 | warn (_("Reserved length value (0x%s) found in section %s\n"), |
3249 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3250 | return FALSE; |
ec4d4525 | 3251 | } |
19e6b90e L |
3252 | else |
3253 | section_begin += length + 4; | |
aca88567 NC |
3254 | |
3255 | /* Negative values are illegal, they may even cause infinite | |
3256 | looping. This can happen if we can't accurately apply | |
f3853b34 NC |
3257 | relocations to an object file, or if the file is corrupt. */ |
3258 | if ((signed long) length <= 0 || section_begin < start) | |
aca88567 | 3259 | { |
767221a9 NC |
3260 | warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
3261 | dwarf_vmatoa ("x", length), section->name); | |
d85bf2ba | 3262 | return FALSE; |
aca88567 | 3263 | } |
19e6b90e L |
3264 | } |
3265 | ||
3266 | if (num_units == 0) | |
3267 | { | |
f41e4712 | 3268 | error (_("No comp units in %s section ?\n"), section->name); |
d85bf2ba | 3269 | return FALSE; |
19e6b90e L |
3270 | } |
3271 | ||
3272 | /* Then allocate an array to hold the information. */ | |
3f5e193b | 3273 | debug_information = (debug_info *) cmalloc (num_units, |
1306a742 | 3274 | sizeof (* debug_information)); |
19e6b90e L |
3275 | if (debug_information == NULL) |
3276 | { | |
f41e4712 | 3277 | error (_("Not enough memory for a debug info array of %u entries\n"), |
19e6b90e | 3278 | num_units); |
82b1b41b | 3279 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
d85bf2ba | 3280 | return FALSE; |
19e6b90e | 3281 | } |
d85bf2ba | 3282 | |
03a91817 NC |
3283 | /* PR 17531: file: 92ca3797. |
3284 | We cannot rely upon the debug_information array being initialised | |
3285 | before it is used. A corrupt file could easily contain references | |
3286 | to a unit for which information has not been made available. So | |
3287 | we ensure that the array is zeroed here. */ | |
b4eb7656 AM |
3288 | memset (debug_information, 0, num_units * sizeof (*debug_information)); |
3289 | ||
82b1b41b | 3290 | alloc_num_debug_info_entries = num_units; |
19e6b90e L |
3291 | } |
3292 | ||
3293 | if (!do_loc) | |
3294 | { | |
dda8d76d NC |
3295 | load_debug_section_with_follow (str, file); |
3296 | load_debug_section_with_follow (line_str, file); | |
3297 | load_debug_section_with_follow (str_dwo, file); | |
3298 | load_debug_section_with_follow (str_index, file); | |
3299 | load_debug_section_with_follow (str_index_dwo, file); | |
3300 | load_debug_section_with_follow (debug_addr, file); | |
19e6b90e L |
3301 | } |
3302 | ||
dda8d76d | 3303 | load_debug_section_with_follow (abbrev_sec, file); |
6f875884 | 3304 | if (debug_displays [abbrev_sec].section.start == NULL) |
19e6b90e L |
3305 | { |
3306 | warn (_("Unable to locate %s section!\n"), | |
dda8d76d | 3307 | debug_displays [abbrev_sec].section.uncompressed_name); |
d85bf2ba | 3308 | return FALSE; |
19e6b90e L |
3309 | } |
3310 | ||
dda8d76d NC |
3311 | if (!do_loc && dwarf_start_die == 0) |
3312 | introduce (section, FALSE); | |
3313 | ||
19e6b90e L |
3314 | for (section_begin = start, unit = 0; start < end; unit++) |
3315 | { | |
3316 | DWARF2_Internal_CompUnit compunit; | |
3317 | unsigned char *hdrptr; | |
19e6b90e | 3318 | unsigned char *tags; |
fd2f0033 | 3319 | int level, last_level, saved_level; |
467c65bc | 3320 | dwarf_vma cu_offset; |
e98fdf1a | 3321 | unsigned long sec_off; |
bf5117e3 | 3322 | unsigned int offset_size; |
19485196 | 3323 | unsigned int initial_length_size; |
74bc6052 CC |
3324 | dwarf_vma signature_high = 0; |
3325 | dwarf_vma signature_low = 0; | |
767221a9 | 3326 | dwarf_vma type_offset = 0; |
341f9135 CC |
3327 | struct cu_tu_set *this_set; |
3328 | dwarf_vma abbrev_base; | |
3329 | size_t abbrev_size; | |
19e6b90e L |
3330 | |
3331 | hdrptr = start; | |
3332 | ||
0c588247 | 3333 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
19e6b90e L |
3334 | |
3335 | if (compunit.cu_length == 0xffffffff) | |
3336 | { | |
0c588247 | 3337 | SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
19e6b90e L |
3338 | offset_size = 8; |
3339 | initial_length_size = 12; | |
3340 | } | |
3341 | else | |
3342 | { | |
3343 | offset_size = 4; | |
3344 | initial_length_size = 4; | |
3345 | } | |
3346 | ||
0c588247 | 3347 | SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
19e6b90e L |
3348 | |
3349 | cu_offset = start - section_begin; | |
19e6b90e | 3350 | |
341f9135 CC |
3351 | this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
3352 | ||
77145576 JK |
3353 | if (compunit.cu_version < 5) |
3354 | { | |
3355 | compunit.cu_unit_type = DW_UT_compile; | |
3356 | /* Initialize it due to a false compiler warning. */ | |
3357 | compunit.cu_pointer_size = -1; | |
3358 | } | |
3359 | else | |
3360 | { | |
3361 | SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end); | |
3362 | do_types = (compunit.cu_unit_type == DW_UT_type); | |
3363 | ||
3364 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3365 | } | |
3366 | ||
0c588247 | 3367 | SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
19e6b90e | 3368 | |
341f9135 CC |
3369 | if (this_set == NULL) |
3370 | { | |
3371 | abbrev_base = 0; | |
3372 | abbrev_size = debug_displays [abbrev_sec].section.size; | |
3373 | } | |
3374 | else | |
3375 | { | |
3376 | abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; | |
3377 | abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; | |
3378 | } | |
3379 | ||
77145576 JK |
3380 | if (compunit.cu_version < 5) |
3381 | SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); | |
3382 | ||
f41e4712 NC |
3383 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
3384 | if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) | |
3385 | { | |
3386 | warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), | |
3387 | compunit.cu_pointer_size, offset_size); | |
3388 | compunit.cu_pointer_size = offset_size; | |
3389 | } | |
2b6f5997 CC |
3390 | |
3391 | if (do_types) | |
b4eb7656 | 3392 | { |
0c588247 | 3393 | SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
f048b142 | 3394 | hdrptr += 8; |
0c588247 | 3395 | SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
b4eb7656 | 3396 | } |
2b6f5997 | 3397 | |
ae7e7825 NC |
3398 | if (dwarf_start_die > (cu_offset + compunit.cu_length |
3399 | + initial_length_size)) | |
3400 | { | |
3401 | start = section_begin + cu_offset + compunit.cu_length | |
3402 | + initial_length_size; | |
3403 | continue; | |
3404 | } | |
3405 | ||
19e6b90e | 3406 | if ((do_loc || do_debug_loc || do_debug_ranges) |
2b6f5997 CC |
3407 | && num_debug_info_entries == 0 |
3408 | && ! do_types) | |
19e6b90e L |
3409 | { |
3410 | debug_information [unit].cu_offset = cu_offset; | |
3411 | debug_information [unit].pointer_size | |
3412 | = compunit.cu_pointer_size; | |
b7807392 JJ |
3413 | debug_information [unit].offset_size = offset_size; |
3414 | debug_information [unit].dwarf_version = compunit.cu_version; | |
19e6b90e | 3415 | debug_information [unit].base_address = 0; |
4723351a CC |
3416 | debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
3417 | debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; | |
19e6b90e L |
3418 | debug_information [unit].loc_offsets = NULL; |
3419 | debug_information [unit].have_frame_base = NULL; | |
3420 | debug_information [unit].max_loc_offsets = 0; | |
3421 | debug_information [unit].num_loc_offsets = 0; | |
3422 | debug_information [unit].range_lists = NULL; | |
3423 | debug_information [unit].max_range_lists= 0; | |
3424 | debug_information [unit].num_range_lists = 0; | |
3425 | } | |
3426 | ||
fd2f0033 | 3427 | if (!do_loc && dwarf_start_die == 0) |
19e6b90e | 3428 | { |
47704ddf KT |
3429 | printf (_(" Compilation Unit @ offset 0x%s:\n"), |
3430 | dwarf_vmatoa ("x", cu_offset)); | |
3431 | printf (_(" Length: 0x%s (%s)\n"), | |
3432 | dwarf_vmatoa ("x", compunit.cu_length), | |
49e7b350 | 3433 | offset_size == 8 ? "64-bit" : "32-bit"); |
19e6b90e | 3434 | printf (_(" Version: %d\n"), compunit.cu_version); |
7282333f AM |
3435 | printf (_(" Abbrev Offset: 0x%s\n"), |
3436 | dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); | |
19e6b90e | 3437 | printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
2b6f5997 CC |
3438 | if (do_types) |
3439 | { | |
74bc6052 CC |
3440 | char buf[64]; |
3441 | ||
3442 | printf (_(" Signature: 0x%s\n"), | |
3443 | dwarf_vmatoa64 (signature_high, signature_low, | |
3444 | buf, sizeof (buf))); | |
3445 | printf (_(" Type Offset: 0x%s\n"), | |
3446 | dwarf_vmatoa ("x", type_offset)); | |
2b6f5997 | 3447 | } |
341f9135 CC |
3448 | if (this_set != NULL) |
3449 | { | |
3450 | dwarf_vma *offsets = this_set->section_offsets; | |
3451 | size_t *sizes = this_set->section_sizes; | |
3452 | ||
3453 | printf (_(" Section contributions:\n")); | |
3454 | printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), | |
3455 | dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), | |
3456 | dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); | |
3457 | printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), | |
3458 | dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), | |
3459 | dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); | |
3460 | printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), | |
3461 | dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), | |
3462 | dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); | |
3463 | printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), | |
3464 | dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), | |
3465 | dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); | |
3466 | } | |
19e6b90e L |
3467 | } |
3468 | ||
e98fdf1a AM |
3469 | sec_off = cu_offset + initial_length_size; |
3470 | if (sec_off + compunit.cu_length < sec_off | |
3471 | || sec_off + compunit.cu_length > section->size) | |
460c89ff | 3472 | { |
e98fdf1a AM |
3473 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
3474 | section->name, | |
3475 | (unsigned long) cu_offset, | |
19485196 NC |
3476 | dwarf_vmatoa ("x", compunit.cu_length)); |
3477 | num_units = unit; | |
3478 | break; | |
3479 | } | |
3480 | ||
460c89ff NS |
3481 | tags = hdrptr; |
3482 | start += compunit.cu_length + initial_length_size; | |
3483 | ||
77145576 | 3484 | if (compunit.cu_version < 2 || compunit.cu_version > 5) |
19e6b90e | 3485 | { |
47704ddf KT |
3486 | warn (_("CU at offset %s contains corrupt or " |
3487 | "unsupported version number: %d.\n"), | |
3488 | dwarf_vmatoa ("x", cu_offset), compunit.cu_version); | |
19e6b90e L |
3489 | continue; |
3490 | } | |
3491 | ||
77145576 JK |
3492 | if (compunit.cu_unit_type != DW_UT_compile |
3493 | && compunit.cu_unit_type != DW_UT_type) | |
3494 | { | |
3495 | warn (_("CU at offset %s contains corrupt or " | |
3496 | "unsupported unit type: %d.\n"), | |
3497 | dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type); | |
3498 | continue; | |
3499 | } | |
3500 | ||
19e6b90e L |
3501 | free_abbrevs (); |
3502 | ||
d493b283 | 3503 | /* Process the abbrevs used by this compilation unit. */ |
341f9135 | 3504 | if (compunit.cu_abbrev_offset >= abbrev_size) |
ec4d4525 NC |
3505 | warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
3506 | (unsigned long) compunit.cu_abbrev_offset, | |
341f9135 | 3507 | (unsigned long) abbrev_size); |
b4eb7656 | 3508 | /* PR 17531: file:4bcd9ce9. */ |
a0a3b04c L |
3509 | else if ((abbrev_base + abbrev_size) |
3510 | > debug_displays [abbrev_sec].section.size) | |
3511 | warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), | |
3512 | (unsigned long) abbrev_base + abbrev_size, | |
3513 | (unsigned long) debug_displays [abbrev_sec].section.size); | |
460c89ff NS |
3514 | else |
3515 | process_abbrev_section | |
341f9135 CC |
3516 | (((unsigned char *) debug_displays [abbrev_sec].section.start |
3517 | + abbrev_base + compunit.cu_abbrev_offset), | |
3518 | ((unsigned char *) debug_displays [abbrev_sec].section.start | |
3519 | + abbrev_base + abbrev_size)); | |
19e6b90e L |
3520 | |
3521 | level = 0; | |
fd2f0033 TT |
3522 | last_level = level; |
3523 | saved_level = -1; | |
19e6b90e L |
3524 | while (tags < start) |
3525 | { | |
3526 | unsigned int bytes_read; | |
3527 | unsigned long abbrev_number; | |
ec4d4525 | 3528 | unsigned long die_offset; |
19e6b90e L |
3529 | abbrev_entry *entry; |
3530 | abbrev_attr *attr; | |
fd2f0033 | 3531 | int do_printing = 1; |
19e6b90e | 3532 | |
ec4d4525 NC |
3533 | die_offset = tags - section_begin; |
3534 | ||
f6f0e17b | 3535 | abbrev_number = read_uleb128 (tags, & bytes_read, start); |
19e6b90e L |
3536 | tags += bytes_read; |
3537 | ||
eb7cc021 JK |
3538 | /* A null DIE marks the end of a list of siblings or it may also be |
3539 | a section padding. */ | |
19e6b90e L |
3540 | if (abbrev_number == 0) |
3541 | { | |
eb7cc021 JK |
3542 | /* Check if it can be a section padding for the last CU. */ |
3543 | if (level == 0 && start == end) | |
3544 | { | |
3545 | unsigned char *chk; | |
3546 | ||
3547 | for (chk = tags; chk < start; chk++) | |
3548 | if (*chk != 0) | |
3549 | break; | |
3550 | if (chk == start) | |
3551 | break; | |
3552 | } | |
3553 | ||
4337774f TT |
3554 | if (!do_loc && die_offset >= dwarf_start_die |
3555 | && (dwarf_cutoff_level == -1 | |
3556 | || level < dwarf_cutoff_level)) | |
399c99f7 L |
3557 | printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
3558 | level, die_offset); | |
3559 | ||
19e6b90e | 3560 | --level; |
ec4d4525 NC |
3561 | if (level < 0) |
3562 | { | |
3563 | static unsigned num_bogus_warns = 0; | |
3564 | ||
3565 | if (num_bogus_warns < 3) | |
3566 | { | |
4723351a CC |
3567 | warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
3568 | die_offset, section->name); | |
ec4d4525 NC |
3569 | num_bogus_warns ++; |
3570 | if (num_bogus_warns == 3) | |
3571 | warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); | |
3572 | } | |
3573 | } | |
fd2f0033 | 3574 | if (dwarf_start_die != 0 && level < saved_level) |
d85bf2ba | 3575 | return TRUE; |
19e6b90e L |
3576 | continue; |
3577 | } | |
3578 | ||
4b78141a | 3579 | if (!do_loc) |
fd2f0033 TT |
3580 | { |
3581 | if (dwarf_start_die != 0 && die_offset < dwarf_start_die) | |
3582 | do_printing = 0; | |
3583 | else | |
3584 | { | |
3585 | if (dwarf_start_die != 0 && die_offset == dwarf_start_die) | |
3586 | saved_level = level; | |
3587 | do_printing = (dwarf_cutoff_level == -1 | |
3588 | || level < dwarf_cutoff_level); | |
3589 | if (do_printing) | |
3590 | printf (_(" <%d><%lx>: Abbrev Number: %lu"), | |
3591 | level, die_offset, abbrev_number); | |
3592 | else if (dwarf_cutoff_level == -1 | |
3593 | || last_level < dwarf_cutoff_level) | |
3594 | printf (_(" <%d><%lx>: ...\n"), level, die_offset); | |
3595 | last_level = level; | |
3596 | } | |
3597 | } | |
cecf136e | 3598 | |
19e6b90e L |
3599 | /* Scan through the abbreviation list until we reach the |
3600 | correct entry. */ | |
3601 | for (entry = first_abbrev; | |
3602 | entry && entry->entry != abbrev_number; | |
3603 | entry = entry->next) | |
3604 | continue; | |
3605 | ||
3606 | if (entry == NULL) | |
3607 | { | |
fd2f0033 | 3608 | if (!do_loc && do_printing) |
4b78141a NC |
3609 | { |
3610 | printf ("\n"); | |
3611 | fflush (stdout); | |
3612 | } | |
f3853b34 | 3613 | warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
cc86f28f | 3614 | die_offset, abbrev_number); |
d85bf2ba | 3615 | return FALSE; |
19e6b90e L |
3616 | } |
3617 | ||
fd2f0033 | 3618 | if (!do_loc && do_printing) |
cc5914eb | 3619 | printf (" (%s)\n", get_TAG_name (entry->tag)); |
cecf136e | 3620 | |
19e6b90e L |
3621 | switch (entry->tag) |
3622 | { | |
3623 | default: | |
3624 | need_base_address = 0; | |
3625 | break; | |
3626 | case DW_TAG_compile_unit: | |
d85bf2ba NC |
3627 | need_base_address = 1; |
3628 | need_dwo_info = do_loc; | |
19e6b90e L |
3629 | break; |
3630 | case DW_TAG_entry_point: | |
19e6b90e L |
3631 | case DW_TAG_subprogram: |
3632 | need_base_address = 0; | |
3633 | /* Assuming that there is no DW_AT_frame_base. */ | |
3634 | have_frame_base = 0; | |
3635 | break; | |
3636 | } | |
3637 | ||
9f272209 AO |
3638 | debug_info *debug_info_p = |
3639 | (debug_information && unit < alloc_num_debug_info_entries) | |
3640 | ? debug_information + unit : NULL; | |
3641 | ||
3642 | assert (!debug_info_p | |
3643 | || (debug_info_p->num_loc_offsets | |
3644 | == debug_info_p->num_loc_views)); | |
3645 | ||
399c99f7 L |
3646 | for (attr = entry->first_attr; |
3647 | attr && attr->attribute; | |
3648 | attr = attr->next) | |
4b78141a | 3649 | { |
fd2f0033 | 3650 | if (! do_loc && do_printing) |
4b78141a | 3651 | /* Show the offset from where the tag was extracted. */ |
fd2f0033 | 3652 | printf (" <%lx>", (unsigned long)(tags - section_begin)); |
4b78141a NC |
3653 | tags = read_and_display_attr (attr->attribute, |
3654 | attr->form, | |
77145576 | 3655 | attr->implicit_const, |
ec1b0fbb | 3656 | section_begin, |
341f9135 | 3657 | tags, |
f6f0e17b | 3658 | end, |
341f9135 | 3659 | cu_offset, |
4b78141a NC |
3660 | compunit.cu_pointer_size, |
3661 | offset_size, | |
3662 | compunit.cu_version, | |
9f272209 | 3663 | debug_info_p, |
341f9135 CC |
3664 | do_loc || ! do_printing, |
3665 | section, | |
ec1b0fbb NC |
3666 | this_set, |
3667 | level); | |
4b78141a | 3668 | } |
cecf136e | 3669 | |
9f272209 AO |
3670 | /* If a locview attribute appears before a location one, |
3671 | make sure we don't associate it with an earlier | |
3672 | loclist. */ | |
3673 | if (debug_info_p) | |
3674 | switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views) | |
3675 | { | |
3676 | case 1: | |
3677 | debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1; | |
3678 | debug_info_p->num_loc_views++; | |
3679 | assert (debug_info_p->num_loc_views | |
3680 | == debug_info_p->num_loc_offsets); | |
3681 | break; | |
3682 | ||
3683 | case 0: | |
3684 | break; | |
3685 | ||
3686 | case -1: | |
3687 | warn(_("DIE has locviews without loclist\n")); | |
3688 | debug_info_p->num_loc_views--; | |
3689 | break; | |
3690 | ||
3691 | default: | |
3692 | assert (0); | |
3693 | } | |
3694 | ||
b4eb7656 AM |
3695 | if (entry->children) |
3696 | ++level; | |
3697 | } | |
19e6b90e | 3698 | } |
cecf136e | 3699 | |
19e6b90e L |
3700 | /* Set num_debug_info_entries here so that it can be used to check if |
3701 | we need to process .debug_loc and .debug_ranges sections. */ | |
3702 | if ((do_loc || do_debug_loc || do_debug_ranges) | |
2b6f5997 CC |
3703 | && num_debug_info_entries == 0 |
3704 | && ! do_types) | |
82b1b41b | 3705 | { |
b4eb7656 | 3706 | if (num_units > alloc_num_debug_info_entries) |
82b1b41b NC |
3707 | num_debug_info_entries = alloc_num_debug_info_entries; |
3708 | else | |
3709 | num_debug_info_entries = num_units; | |
3710 | } | |
cecf136e | 3711 | |
19e6b90e | 3712 | if (!do_loc) |
467c65bc | 3713 | printf ("\n"); |
cecf136e | 3714 | |
d85bf2ba | 3715 | return TRUE; |
19e6b90e L |
3716 | } |
3717 | ||
3718 | /* Locate and scan the .debug_info section in the file and record the pointer | |
3719 | sizes and offsets for the compilation units in it. Usually an executable | |
3720 | will have just one pointer size, but this is not guaranteed, and so we try | |
3721 | not to make any assumptions. Returns zero upon failure, or the number of | |
3722 | compilation units upon success. */ | |
3723 | ||
3724 | static unsigned int | |
3725 | load_debug_info (void * file) | |
3726 | { | |
1febe64d | 3727 | /* If we have already tried and failed to load the .debug_info |
657d0d47 | 3728 | section then do not bother to repeat the task. */ |
cc86f28f | 3729 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
1febe64d NC |
3730 | return 0; |
3731 | ||
19e6b90e L |
3732 | /* If we already have the information there is nothing else to do. */ |
3733 | if (num_debug_info_entries > 0) | |
3734 | return num_debug_info_entries; | |
3735 | ||
341f9135 | 3736 | /* If this is a DWARF package file, load the CU and TU indexes. */ |
43a444f9 | 3737 | (void) load_cu_tu_indexes (file); |
341f9135 | 3738 | |
dda8d76d | 3739 | if (load_debug_section_with_follow (info, file) |
d85bf2ba | 3740 | && process_debug_info (&debug_displays [info].section, file, abbrev, TRUE, FALSE)) |
19e6b90e | 3741 | return num_debug_info_entries; |
82b1b41b | 3742 | |
dda8d76d | 3743 | if (load_debug_section_with_follow (info_dwo, file) |
82b1b41b | 3744 | && process_debug_info (&debug_displays [info_dwo].section, file, |
d85bf2ba | 3745 | abbrev_dwo, TRUE, FALSE)) |
4723351a | 3746 | return num_debug_info_entries; |
1febe64d | 3747 | |
cc86f28f | 3748 | num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
1febe64d | 3749 | return 0; |
19e6b90e L |
3750 | } |
3751 | ||
b40bf0a2 NC |
3752 | /* Read a DWARF .debug_line section header starting at DATA. |
3753 | Upon success returns an updated DATA pointer and the LINFO | |
3754 | structure and the END_OF_SEQUENCE pointer will be filled in. | |
3755 | Otherwise returns NULL. */ | |
19e6b90e | 3756 | |
b40bf0a2 NC |
3757 | static unsigned char * |
3758 | read_debug_line_header (struct dwarf_section * section, | |
3759 | unsigned char * data, | |
3760 | unsigned char * end, | |
3761 | DWARF2_Internal_LineInfo * linfo, | |
3762 | unsigned char ** end_of_sequence) | |
3763 | { | |
3764 | unsigned char *hdrptr; | |
b40bf0a2 | 3765 | unsigned int initial_length_size; |
77145576 | 3766 | unsigned char address_size, segment_selector_size; |
19e6b90e | 3767 | |
b40bf0a2 NC |
3768 | /* Extract information from the Line Number Program Header. |
3769 | (section 6.2.4 in the Dwarf3 doc). */ | |
6937bb54 | 3770 | hdrptr = data; |
19e6b90e | 3771 | |
b40bf0a2 NC |
3772 | /* Get and check the length of the block. */ |
3773 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); | |
19e6b90e | 3774 | |
b40bf0a2 | 3775 | if (linfo->li_length == 0xffffffff) |
f41e4712 NC |
3776 | { |
3777 | /* This section is 64-bit DWARF 3. */ | |
b40bf0a2 | 3778 | SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
77145576 | 3779 | linfo->li_offset_size = 8; |
f41e4712 NC |
3780 | initial_length_size = 12; |
3781 | } | |
3782 | else | |
3783 | { | |
77145576 | 3784 | linfo->li_offset_size = 4; |
f41e4712 NC |
3785 | initial_length_size = 4; |
3786 | } | |
19e6b90e | 3787 | |
b40bf0a2 | 3788 | if (linfo->li_length + initial_length_size > section->size) |
f41e4712 | 3789 | { |
8fcc61b4 NC |
3790 | /* If the length field has a relocation against it, then we should |
3791 | not complain if it is inaccurate (and probably negative). This | |
3792 | happens in object files when the .debug_line section is actually | |
3793 | comprised of several different .debug_line.* sections, (some of | |
3794 | which may be removed by linker garbage collection), and a relocation | |
3795 | is used to compute the correct length once that is done. */ | |
77145576 | 3796 | if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size)) |
b40bf0a2 | 3797 | { |
8fcc61b4 | 3798 | linfo->li_length = (end - data) - initial_length_size; |
b40bf0a2 NC |
3799 | } |
3800 | else | |
3801 | { | |
8fcc61b4 NC |
3802 | warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
3803 | (long) linfo->li_length); | |
b40bf0a2 NC |
3804 | return NULL; |
3805 | } | |
f41e4712 | 3806 | } |
19e6b90e | 3807 | |
b40bf0a2 NC |
3808 | /* Get and check the version number. */ |
3809 | SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); | |
3810 | ||
3811 | if (linfo->li_version != 2 | |
3812 | && linfo->li_version != 3 | |
77145576 JK |
3813 | && linfo->li_version != 4 |
3814 | && linfo->li_version != 5) | |
f41e4712 | 3815 | { |
77145576 JK |
3816 | warn (_("Only DWARF version 2, 3, 4 and 5 line info " |
3817 | "is currently supported.\n")); | |
b40bf0a2 | 3818 | return NULL; |
f41e4712 | 3819 | } |
19e6b90e | 3820 | |
77145576 JK |
3821 | if (linfo->li_version >= 5) |
3822 | { | |
3823 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
3824 | ||
3825 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
3826 | if (segment_selector_size != 0) | |
3827 | { | |
3828 | warn (_("The %s section contains " | |
3829 | "unsupported segment selector size: %d.\n"), | |
3830 | section->name, segment_selector_size); | |
3831 | return 0; | |
3832 | } | |
3833 | } | |
3834 | ||
3835 | SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, | |
3836 | linfo->li_offset_size, end); | |
b40bf0a2 | 3837 | SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
0c588247 | 3838 | |
b40bf0a2 | 3839 | if (linfo->li_version >= 4) |
f41e4712 | 3840 | { |
b40bf0a2 | 3841 | SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
0c588247 | 3842 | |
b40bf0a2 | 3843 | if (linfo->li_max_ops_per_insn == 0) |
f41e4712 NC |
3844 | { |
3845 | warn (_("Invalid maximum operations per insn.\n")); | |
b40bf0a2 | 3846 | return NULL; |
a233b20c | 3847 | } |
f41e4712 NC |
3848 | } |
3849 | else | |
b40bf0a2 | 3850 | linfo->li_max_ops_per_insn = 1; |
0c588247 | 3851 | |
b40bf0a2 | 3852 | SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
65879393 | 3853 | SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
b40bf0a2 NC |
3854 | SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
3855 | SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); | |
19e6b90e | 3856 | |
b40bf0a2 | 3857 | * end_of_sequence = data + linfo->li_length + initial_length_size; |
b4eb7656 | 3858 | /* PR 17512: file:002-117414-0.004. */ |
6937bb54 NC |
3859 | if (* end_of_sequence > end) |
3860 | { | |
4c219c2e AM |
3861 | warn (_("Line length %s extends beyond end of section\n"), |
3862 | dwarf_vmatoa ("u", linfo->li_length)); | |
6937bb54 NC |
3863 | * end_of_sequence = end; |
3864 | return NULL; | |
3865 | } | |
3866 | ||
b40bf0a2 NC |
3867 | return hdrptr; |
3868 | } | |
19e6b90e | 3869 | |
77145576 | 3870 | static unsigned char * |
dda8d76d NC |
3871 | display_formatted_table (unsigned char * data, |
3872 | unsigned char * start, | |
3873 | unsigned char * end, | |
3874 | const DWARF2_Internal_LineInfo * linfo, | |
3875 | struct dwarf_section * section, | |
7b8d9e8c | 3876 | bfd_boolean is_dir) |
77145576 JK |
3877 | { |
3878 | unsigned char *format_start, format_count, *format, formati; | |
3879 | dwarf_vma data_count, datai; | |
3880 | unsigned int bytes_read, namepass, last_entry = 0; | |
3881 | ||
3882 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
3883 | format_start = data; | |
3884 | for (formati = 0; formati < format_count; formati++) | |
3885 | { | |
3886 | read_uleb128 (data, & bytes_read, end); | |
3887 | data += bytes_read; | |
3888 | read_uleb128 (data, & bytes_read, end); | |
3889 | data += bytes_read; | |
3890 | if (data == end) | |
3891 | { | |
7b8d9e8c AM |
3892 | if (is_dir) |
3893 | warn (_("Corrupt directory format table entry\n")); | |
3894 | else | |
3895 | warn (_("Corrupt file name format table entry\n")); | |
77145576 JK |
3896 | return data; |
3897 | } | |
3898 | } | |
3899 | ||
3900 | data_count = read_uleb128 (data, & bytes_read, end); | |
3901 | data += bytes_read; | |
3902 | if (data == end) | |
3903 | { | |
7b8d9e8c AM |
3904 | if (is_dir) |
3905 | warn (_("Corrupt directory list\n")); | |
3906 | else | |
3907 | warn (_("Corrupt file name list\n")); | |
77145576 JK |
3908 | return data; |
3909 | } | |
3910 | ||
3911 | if (data_count == 0) | |
3912 | { | |
7b8d9e8c AM |
3913 | if (is_dir) |
3914 | printf (_("\n The Directory Table is empty.\n")); | |
3915 | else | |
3916 | printf (_("\n The File Name Table is empty.\n")); | |
77145576 JK |
3917 | return data; |
3918 | } | |
3919 | ||
7b8d9e8c AM |
3920 | if (is_dir) |
3921 | printf (_("\n The Directory Table (offset 0x%lx):\n"), | |
3922 | (long) (data - start)); | |
3923 | else | |
3924 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
3925 | (long) (data - start)); | |
77145576 JK |
3926 | |
3927 | printf (_(" Entry")); | |
3928 | /* Delay displaying name as the last entry for better screen layout. */ | |
3929 | for (namepass = 0; namepass < 2; namepass++) | |
3930 | { | |
3931 | format = format_start; | |
3932 | for (formati = 0; formati < format_count; formati++) | |
3933 | { | |
3934 | dwarf_vma content_type; | |
3935 | ||
3936 | content_type = read_uleb128 (format, & bytes_read, end); | |
3937 | format += bytes_read; | |
3938 | if ((content_type == DW_LNCT_path) == (namepass == 1)) | |
3939 | switch (content_type) | |
3940 | { | |
3941 | case DW_LNCT_path: | |
3942 | printf (_("\tName")); | |
3943 | break; | |
3944 | case DW_LNCT_directory_index: | |
3945 | printf (_("\tDir")); | |
3946 | break; | |
3947 | case DW_LNCT_timestamp: | |
3948 | printf (_("\tTime")); | |
3949 | break; | |
3950 | case DW_LNCT_size: | |
3951 | printf (_("\tSize")); | |
3952 | break; | |
3953 | case DW_LNCT_MD5: | |
3954 | printf (_("\tMD5")); | |
3955 | break; | |
3956 | default: | |
3957 | printf (_("\t(Unknown format content type %s)"), | |
3958 | dwarf_vmatoa ("u", content_type)); | |
3959 | } | |
3960 | read_uleb128 (format, & bytes_read, end); | |
3961 | format += bytes_read; | |
3962 | } | |
3963 | } | |
3964 | putchar ('\n'); | |
3965 | ||
3966 | for (datai = 0; datai < data_count; datai++) | |
3967 | { | |
3968 | unsigned char *datapass = data; | |
3969 | ||
3970 | printf (" %d", last_entry++); | |
3971 | /* Delay displaying name as the last entry for better screen layout. */ | |
3972 | for (namepass = 0; namepass < 2; namepass++) | |
3973 | { | |
3974 | format = format_start; | |
3975 | data = datapass; | |
3976 | for (formati = 0; formati < format_count; formati++) | |
3977 | { | |
3978 | dwarf_vma content_type, form; | |
3979 | ||
3980 | content_type = read_uleb128 (format, & bytes_read, end); | |
3981 | format += bytes_read; | |
3982 | form = read_uleb128 (format, & bytes_read, end); | |
3983 | format += bytes_read; | |
ec1b0fbb | 3984 | data = read_and_display_attr_value (0, form, 0, start, data, end, 0, 0, |
77145576 JK |
3985 | linfo->li_offset_size, |
3986 | linfo->li_version, NULL, | |
3987 | ((content_type == DW_LNCT_path) != (namepass == 1)), | |
ec1b0fbb | 3988 | section, NULL, '\t', -1); |
77145576 JK |
3989 | } |
3990 | } | |
3991 | if (data == end) | |
3992 | { | |
7b8d9e8c AM |
3993 | if (is_dir) |
3994 | warn (_("Corrupt directory entries list\n")); | |
3995 | else | |
3996 | warn (_("Corrupt file name entries list\n")); | |
77145576 JK |
3997 | return data; |
3998 | } | |
3999 | putchar ('\n'); | |
4000 | } | |
4001 | return data; | |
4002 | } | |
4003 | ||
b40bf0a2 | 4004 | static int |
dda8d76d NC |
4005 | display_debug_lines_raw (struct dwarf_section * section, |
4006 | unsigned char * data, | |
4007 | unsigned char * end, | |
4008 | void * file) | |
b40bf0a2 NC |
4009 | { |
4010 | unsigned char *start = section->start; | |
ba8826a8 | 4011 | int verbose_view = 0; |
19e6b90e | 4012 | |
dda8d76d | 4013 | introduce (section, TRUE); |
19e6b90e | 4014 | |
b40bf0a2 NC |
4015 | while (data < end) |
4016 | { | |
4017 | static DWARF2_Internal_LineInfo saved_linfo; | |
4018 | DWARF2_Internal_LineInfo linfo; | |
4019 | unsigned char *standard_opcodes; | |
4020 | unsigned char *end_of_sequence; | |
fe59e83d | 4021 | int i; |
19e6b90e | 4022 | |
4925cdd7 NC |
4023 | if (const_strneq (section->name, ".debug_line.") |
4024 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4025 | These are full debug_line sections. */ | |
4026 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
19e6b90e | 4027 | { |
b40bf0a2 NC |
4028 | /* Sections named .debug_line.<foo> are fragments of a .debug_line |
4029 | section containing just the Line Number Statements. They are | |
4030 | created by the assembler and intended to be used alongside gcc's | |
4031 | -ffunction-sections command line option. When the linker's | |
4032 | garbage collection decides to discard a .text.<foo> section it | |
4033 | can then also discard the line number information in .debug_line.<foo>. | |
4034 | ||
4925cdd7 | 4035 | Since the section is a fragment it does not have the details |
b40bf0a2 | 4036 | needed to fill out a LineInfo structure, so instead we use the |
4925cdd7 | 4037 | details from the last full debug_line section that we processed. */ |
b40bf0a2 NC |
4038 | end_of_sequence = end; |
4039 | standard_opcodes = NULL; | |
4040 | linfo = saved_linfo; | |
058037d3 NC |
4041 | /* PR 17531: file: 0522b371. */ |
4042 | if (linfo.li_line_range == 0) | |
4043 | { | |
1306a742 | 4044 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4045 | return 0; |
4046 | } | |
b40bf0a2 | 4047 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4048 | } |
19e6b90e L |
4049 | else |
4050 | { | |
b40bf0a2 | 4051 | unsigned char * hdrptr; |
19e6b90e | 4052 | |
b40bf0a2 NC |
4053 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4054 | & end_of_sequence)) == NULL) | |
4055 | return 0; | |
19e6b90e | 4056 | |
b40bf0a2 NC |
4057 | printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
4058 | printf (_(" Length: %ld\n"), (long) linfo.li_length); | |
4059 | printf (_(" DWARF Version: %d\n"), linfo.li_version); | |
77ef8654 | 4060 | printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
b40bf0a2 NC |
4061 | printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
4062 | if (linfo.li_version >= 4) | |
4063 | printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); | |
4064 | printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); | |
4065 | printf (_(" Line Base: %d\n"), linfo.li_line_base); | |
4066 | printf (_(" Line Range: %d\n"), linfo.li_line_range); | |
4067 | printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); | |
19e6b90e | 4068 | |
0a9d414a NC |
4069 | /* PR 17512: file: 1665-6428-0.004. */ |
4070 | if (linfo.li_line_range == 0) | |
4071 | { | |
4072 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4073 | linfo.li_line_range = 1; | |
4074 | } | |
77ef8654 | 4075 | |
b40bf0a2 | 4076 | reset_state_machine (linfo.li_default_is_stmt); |
19e6b90e | 4077 | |
b40bf0a2 NC |
4078 | /* Display the contents of the Opcodes table. */ |
4079 | standard_opcodes = hdrptr; | |
19e6b90e | 4080 | |
6937bb54 NC |
4081 | /* PR 17512: file: 002-417945-0.004. */ |
4082 | if (standard_opcodes + linfo.li_opcode_base >= end) | |
4083 | { | |
4084 | warn (_("Line Base extends beyond end of section\n")); | |
4085 | return 0; | |
4086 | } | |
4087 | ||
b40bf0a2 | 4088 | printf (_("\n Opcodes:\n")); |
19e6b90e | 4089 | |
b40bf0a2 | 4090 | for (i = 1; i < linfo.li_opcode_base; i++) |
d3a49aa8 AM |
4091 | printf (ngettext (" Opcode %d has %d arg\n", |
4092 | " Opcode %d has %d args\n", | |
4093 | standard_opcodes[i - 1]), | |
4094 | i, standard_opcodes[i - 1]); | |
19e6b90e | 4095 | |
b40bf0a2 NC |
4096 | /* Display the contents of the Directory table. */ |
4097 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
19e6b90e | 4098 | |
77145576 | 4099 | if (linfo.li_version >= 5) |
b40bf0a2 | 4100 | { |
dda8d76d | 4101 | load_debug_section_with_follow (line_str, file); |
19e6b90e | 4102 | |
77145576 | 4103 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 4104 | TRUE); |
77145576 | 4105 | data = display_formatted_table (data, start, end, &linfo, section, |
7b8d9e8c | 4106 | FALSE); |
77145576 JK |
4107 | } |
4108 | else | |
4109 | { | |
4110 | if (*data == 0) | |
4111 | printf (_("\n The Directory Table is empty.\n")); | |
4112 | else | |
a233b20c | 4113 | { |
77145576 | 4114 | unsigned int last_dir_entry = 0; |
6937bb54 | 4115 | |
77145576 JK |
4116 | printf (_("\n The Directory Table (offset 0x%lx):\n"), |
4117 | (long)(data - start)); | |
19e6b90e | 4118 | |
77145576 JK |
4119 | while (data < end && *data != 0) |
4120 | { | |
4121 | printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); | |
19e6b90e | 4122 | |
77145576 JK |
4123 | data += strnlen ((char *) data, end - data) + 1; |
4124 | } | |
19e6b90e | 4125 | |
77145576 JK |
4126 | /* PR 17512: file: 002-132094-0.004. */ |
4127 | if (data >= end - 1) | |
4128 | break; | |
4129 | } | |
19e6b90e | 4130 | |
77145576 JK |
4131 | /* Skip the NUL at the end of the table. */ |
4132 | data++; | |
19e6b90e | 4133 | |
77145576 JK |
4134 | /* Display the contents of the File Name table. */ |
4135 | if (*data == 0) | |
4136 | printf (_("\n The File Name Table is empty.\n")); | |
4137 | else | |
4138 | { | |
4139 | printf (_("\n The File Name Table (offset 0x%lx):\n"), | |
4140 | (long)(data - start)); | |
4141 | printf (_(" Entry\tDir\tTime\tSize\tName\n")); | |
19e6b90e | 4142 | |
77145576 | 4143 | while (data < end && *data != 0) |
b40bf0a2 | 4144 | { |
77145576 JK |
4145 | unsigned char *name; |
4146 | unsigned int bytes_read; | |
4147 | ||
4148 | printf (" %d\t", ++state_machine_regs.last_file_entry); | |
4149 | name = data; | |
4150 | data += strnlen ((char *) data, end - data) + 1; | |
4151 | ||
4152 | printf ("%s\t", | |
4153 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
4154 | data += bytes_read; | |
4155 | printf ("%s\t", | |
4156 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
4157 | data += bytes_read; | |
4158 | printf ("%s\t", | |
4159 | dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); | |
4160 | data += bytes_read; | |
4161 | printf ("%.*s\n", (int)(end - name), name); | |
4162 | ||
4163 | if (data == end) | |
4164 | { | |
4165 | warn (_("Corrupt file name table entry\n")); | |
4166 | break; | |
4167 | } | |
b40bf0a2 | 4168 | } |
a233b20c | 4169 | } |
77145576 JK |
4170 | |
4171 | /* Skip the NUL at the end of the table. */ | |
4172 | data++; | |
b40bf0a2 | 4173 | } |
19e6b90e | 4174 | |
b40bf0a2 NC |
4175 | putchar ('\n'); |
4176 | saved_linfo = linfo; | |
4177 | } | |
19e6b90e | 4178 | |
b40bf0a2 NC |
4179 | /* Now display the statements. */ |
4180 | if (data >= end_of_sequence) | |
4181 | printf (_(" No Line Number Statements.\n")); | |
4182 | else | |
4183 | { | |
4184 | printf (_(" Line Number Statements:\n")); | |
19e6b90e | 4185 | |
b40bf0a2 NC |
4186 | while (data < end_of_sequence) |
4187 | { | |
4188 | unsigned char op_code; | |
4189 | dwarf_signed_vma adv; | |
4190 | dwarf_vma uladv; | |
4191 | unsigned int bytes_read; | |
19e6b90e | 4192 | |
fe59e83d CC |
4193 | printf (" [0x%08lx]", (long)(data - start)); |
4194 | ||
b40bf0a2 | 4195 | op_code = *data++; |
19e6b90e | 4196 | |
b40bf0a2 | 4197 | if (op_code >= linfo.li_opcode_base) |
19e6b90e | 4198 | { |
b40bf0a2 NC |
4199 | op_code -= linfo.li_opcode_base; |
4200 | uladv = (op_code / linfo.li_line_range); | |
4201 | if (linfo.li_max_ops_per_insn == 1) | |
4202 | { | |
4203 | uladv *= linfo.li_min_insn_length; | |
4204 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4205 | if (uladv) |
4206 | state_machine_regs.view = 0; | |
b40bf0a2 | 4207 | printf (_(" Special opcode %d: " |
ba8826a8 | 4208 | "advance Address by %s to 0x%s%s"), |
b40bf0a2 | 4209 | op_code, dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4210 | dwarf_vmatoa ("x", state_machine_regs.address), |
4211 | verbose_view && uladv | |
4212 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4213 | } |
4214 | else | |
4215 | { | |
ba8826a8 AO |
4216 | unsigned addrdelta |
4217 | = ((state_machine_regs.op_index + uladv) | |
b40bf0a2 NC |
4218 | / linfo.li_max_ops_per_insn) |
4219 | * linfo.li_min_insn_length; | |
ba8826a8 AO |
4220 | |
4221 | state_machine_regs.address += addrdelta; | |
b40bf0a2 NC |
4222 | state_machine_regs.op_index |
4223 | = (state_machine_regs.op_index + uladv) | |
4224 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4225 | if (addrdelta) |
4226 | state_machine_regs.view = 0; | |
b40bf0a2 | 4227 | printf (_(" Special opcode %d: " |
ba8826a8 | 4228 | "advance Address by %s to 0x%s[%d]%s"), |
b40bf0a2 NC |
4229 | op_code, dwarf_vmatoa ("u", uladv), |
4230 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4231 | state_machine_regs.op_index, |
4232 | verbose_view && addrdelta | |
4233 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4234 | } |
4235 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; | |
4236 | state_machine_regs.line += adv; | |
ba8826a8 | 4237 | printf (_(" and Line by %s to %d"), |
b40bf0a2 | 4238 | dwarf_vmatoa ("d", adv), state_machine_regs.line); |
ba8826a8 AO |
4239 | if (verbose_view || state_machine_regs.view) |
4240 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4241 | else | |
4242 | putchar ('\n'); | |
4243 | state_machine_regs.view++; | |
19e6b90e | 4244 | } |
b40bf0a2 NC |
4245 | else switch (op_code) |
4246 | { | |
4247 | case DW_LNS_extended_op: | |
4248 | data += process_extended_line_op (data, linfo.li_default_is_stmt, end); | |
4249 | break; | |
4250 | ||
4251 | case DW_LNS_copy: | |
ba8826a8 AO |
4252 | printf (_(" Copy")); |
4253 | if (verbose_view || state_machine_regs.view) | |
4254 | printf (_(" (view %u)\n"), state_machine_regs.view); | |
4255 | else | |
4256 | putchar ('\n'); | |
4257 | state_machine_regs.view++; | |
b40bf0a2 NC |
4258 | break; |
4259 | ||
4260 | case DW_LNS_advance_pc: | |
4261 | uladv = read_uleb128 (data, & bytes_read, end); | |
4262 | data += bytes_read; | |
4263 | if (linfo.li_max_ops_per_insn == 1) | |
4264 | { | |
4265 | uladv *= linfo.li_min_insn_length; | |
4266 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4267 | if (uladv) |
4268 | state_machine_regs.view = 0; | |
4269 | printf (_(" Advance PC by %s to 0x%s%s\n"), | |
b40bf0a2 | 4270 | dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4271 | dwarf_vmatoa ("x", state_machine_regs.address), |
4272 | verbose_view && uladv | |
4273 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4274 | } |
4275 | else | |
4276 | { | |
ba8826a8 AO |
4277 | unsigned addrdelta |
4278 | = ((state_machine_regs.op_index + uladv) | |
4279 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4280 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4281 | state_machine_regs.address |
4282 | += addrdelta; | |
b40bf0a2 NC |
4283 | state_machine_regs.op_index |
4284 | = (state_machine_regs.op_index + uladv) | |
4285 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4286 | if (addrdelta) |
4287 | state_machine_regs.view = 0; | |
4288 | printf (_(" Advance PC by %s to 0x%s[%d]%s\n"), | |
b40bf0a2 NC |
4289 | dwarf_vmatoa ("u", uladv), |
4290 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4291 | state_machine_regs.op_index, |
4292 | verbose_view && addrdelta | |
4293 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4294 | } |
4295 | break; | |
4296 | ||
4297 | case DW_LNS_advance_line: | |
4298 | adv = read_sleb128 (data, & bytes_read, end); | |
4299 | data += bytes_read; | |
4300 | state_machine_regs.line += adv; | |
4301 | printf (_(" Advance Line by %s to %d\n"), | |
4302 | dwarf_vmatoa ("d", adv), | |
4303 | state_machine_regs.line); | |
4304 | break; | |
4305 | ||
4306 | case DW_LNS_set_file: | |
4307 | adv = read_uleb128 (data, & bytes_read, end); | |
4308 | data += bytes_read; | |
4309 | printf (_(" Set File Name to entry %s in the File Name Table\n"), | |
4310 | dwarf_vmatoa ("d", adv)); | |
4311 | state_machine_regs.file = adv; | |
4312 | break; | |
4313 | ||
4314 | case DW_LNS_set_column: | |
4315 | uladv = read_uleb128 (data, & bytes_read, end); | |
4316 | data += bytes_read; | |
4317 | printf (_(" Set column to %s\n"), | |
4318 | dwarf_vmatoa ("u", uladv)); | |
4319 | state_machine_regs.column = uladv; | |
4320 | break; | |
4321 | ||
4322 | case DW_LNS_negate_stmt: | |
4323 | adv = state_machine_regs.is_stmt; | |
4324 | adv = ! adv; | |
4325 | printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv)); | |
4326 | state_machine_regs.is_stmt = adv; | |
4327 | break; | |
4328 | ||
4329 | case DW_LNS_set_basic_block: | |
4330 | printf (_(" Set basic block\n")); | |
4331 | state_machine_regs.basic_block = 1; | |
4332 | break; | |
4333 | ||
4334 | case DW_LNS_const_add_pc: | |
4335 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
4336 | if (linfo.li_max_ops_per_insn) | |
4337 | { | |
4338 | uladv *= linfo.li_min_insn_length; | |
4339 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4340 | if (uladv) |
4341 | state_machine_regs.view = 0; | |
4342 | printf (_(" Advance PC by constant %s to 0x%s%s\n"), | |
b40bf0a2 | 4343 | dwarf_vmatoa ("u", uladv), |
ba8826a8 AO |
4344 | dwarf_vmatoa ("x", state_machine_regs.address), |
4345 | verbose_view && uladv | |
4346 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4347 | } |
4348 | else | |
4349 | { | |
ba8826a8 AO |
4350 | unsigned addrdelta |
4351 | = ((state_machine_regs.op_index + uladv) | |
4352 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4353 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4354 | state_machine_regs.address |
4355 | += addrdelta; | |
b40bf0a2 NC |
4356 | state_machine_regs.op_index |
4357 | = (state_machine_regs.op_index + uladv) | |
4358 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4359 | if (addrdelta) |
4360 | state_machine_regs.view = 0; | |
4361 | printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"), | |
b40bf0a2 NC |
4362 | dwarf_vmatoa ("u", uladv), |
4363 | dwarf_vmatoa ("x", state_machine_regs.address), | |
ba8826a8 AO |
4364 | state_machine_regs.op_index, |
4365 | verbose_view && addrdelta | |
4366 | ? _(" (reset view)") : ""); | |
b40bf0a2 NC |
4367 | } |
4368 | break; | |
4369 | ||
4370 | case DW_LNS_fixed_advance_pc: | |
4371 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
4372 | state_machine_regs.address += uladv; | |
4373 | state_machine_regs.op_index = 0; | |
4374 | printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), | |
4375 | dwarf_vmatoa ("u", uladv), | |
4376 | dwarf_vmatoa ("x", state_machine_regs.address)); | |
ba8826a8 | 4377 | /* Do NOT reset view. */ |
b40bf0a2 NC |
4378 | break; |
4379 | ||
4380 | case DW_LNS_set_prologue_end: | |
4381 | printf (_(" Set prologue_end to true\n")); | |
4382 | break; | |
4383 | ||
4384 | case DW_LNS_set_epilogue_begin: | |
4385 | printf (_(" Set epilogue_begin to true\n")); | |
4386 | break; | |
4387 | ||
4388 | case DW_LNS_set_isa: | |
4389 | uladv = read_uleb128 (data, & bytes_read, end); | |
4390 | data += bytes_read; | |
4391 | printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); | |
4392 | break; | |
4393 | ||
4394 | default: | |
4395 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
4396 | ||
4397 | if (standard_opcodes != NULL) | |
4398 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
4399 | { | |
4400 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
4401 | &bytes_read, end)), | |
4402 | i == 1 ? "" : ", "); | |
4403 | data += bytes_read; | |
4404 | } | |
4405 | putchar ('\n'); | |
4406 | break; | |
4407 | } | |
19e6b90e | 4408 | } |
b40bf0a2 | 4409 | putchar ('\n'); |
19e6b90e | 4410 | } |
19e6b90e L |
4411 | } |
4412 | ||
4413 | return 1; | |
4414 | } | |
4415 | ||
a262ae96 NC |
4416 | typedef struct |
4417 | { | |
467c65bc NC |
4418 | unsigned char *name; |
4419 | unsigned int directory_index; | |
4420 | unsigned int modification_date; | |
4421 | unsigned int length; | |
a262ae96 NC |
4422 | } File_Entry; |
4423 | ||
4424 | /* Output a decoded representation of the .debug_line section. */ | |
4425 | ||
4426 | static int | |
dda8d76d | 4427 | display_debug_lines_decoded (struct dwarf_section * section, |
ec1b0fbb | 4428 | unsigned char * start, |
dda8d76d NC |
4429 | unsigned char * data, |
4430 | unsigned char * end, | |
4431 | void * fileptr) | |
a262ae96 | 4432 | { |
b40bf0a2 NC |
4433 | static DWARF2_Internal_LineInfo saved_linfo; |
4434 | ||
dda8d76d | 4435 | introduce (section, FALSE); |
a262ae96 NC |
4436 | |
4437 | while (data < end) | |
4438 | { | |
4439 | /* This loop amounts to one iteration per compilation unit. */ | |
91d6fa6a | 4440 | DWARF2_Internal_LineInfo linfo; |
a262ae96 NC |
4441 | unsigned char *standard_opcodes; |
4442 | unsigned char *end_of_sequence; | |
a262ae96 NC |
4443 | int i; |
4444 | File_Entry *file_table = NULL; | |
143a3db0 | 4445 | unsigned int n_files = 0; |
a262ae96 | 4446 | unsigned char **directory_table = NULL; |
77145576 | 4447 | dwarf_vma n_directories = 0; |
a262ae96 | 4448 | |
4925cdd7 NC |
4449 | if (const_strneq (section->name, ".debug_line.") |
4450 | /* Note: the following does not apply to .debug_line.dwo sections. | |
4451 | These are full debug_line sections. */ | |
4452 | && strcmp (section->name, ".debug_line.dwo") != 0) | |
b4eb7656 | 4453 | { |
4925cdd7 | 4454 | /* See comment in display_debug_lines_raw(). */ |
b40bf0a2 NC |
4455 | end_of_sequence = end; |
4456 | standard_opcodes = NULL; | |
4457 | linfo = saved_linfo; | |
058037d3 NC |
4458 | /* PR 17531: file: 0522b371. */ |
4459 | if (linfo.li_line_range == 0) | |
4460 | { | |
1306a742 | 4461 | warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
058037d3 NC |
4462 | return 0; |
4463 | } | |
b40bf0a2 | 4464 | reset_state_machine (linfo.li_default_is_stmt); |
b4eb7656 | 4465 | } |
a262ae96 | 4466 | else |
b4eb7656 | 4467 | { |
b40bf0a2 | 4468 | unsigned char *hdrptr; |
a262ae96 | 4469 | |
b40bf0a2 NC |
4470 | if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
4471 | & end_of_sequence)) == NULL) | |
a233b20c | 4472 | return 0; |
0c588247 | 4473 | |
058037d3 NC |
4474 | /* PR 17531: file: 0522b371. */ |
4475 | if (linfo.li_line_range == 0) | |
4476 | { | |
4477 | warn (_("Line range of 0 is invalid, using 1 instead\n")); | |
4478 | linfo.li_line_range = 1; | |
4479 | } | |
b40bf0a2 | 4480 | reset_state_machine (linfo.li_default_is_stmt); |
a262ae96 | 4481 | |
b40bf0a2 NC |
4482 | /* Save a pointer to the contents of the Opcodes table. */ |
4483 | standard_opcodes = hdrptr; | |
a262ae96 | 4484 | |
b40bf0a2 NC |
4485 | /* Traverse the Directory table just to count entries. */ |
4486 | data = standard_opcodes + linfo.li_opcode_base - 1; | |
d8024a91 NC |
4487 | /* PR 20440 */ |
4488 | if (data >= end) | |
4489 | { | |
4490 | warn (_("opcode base of %d extends beyond end of section\n"), | |
4491 | linfo.li_opcode_base); | |
4492 | return 0; | |
4493 | } | |
4494 | ||
77145576 | 4495 | if (linfo.li_version >= 5) |
b40bf0a2 | 4496 | { |
77145576 JK |
4497 | unsigned char *format_start, format_count, *format; |
4498 | dwarf_vma formati, entryi; | |
4499 | unsigned int bytes_read; | |
a262ae96 | 4500 | |
dda8d76d | 4501 | load_debug_section_with_follow (line_str, fileptr); |
77145576 JK |
4502 | |
4503 | /* Skip directories format. */ | |
4504 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
4505 | format_start = data; | |
4506 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4507 | { |
77145576 JK |
4508 | read_uleb128 (data, & bytes_read, end); |
4509 | data += bytes_read; | |
4510 | read_uleb128 (data, & bytes_read, end); | |
4511 | data += bytes_read; | |
b40bf0a2 | 4512 | } |
a262ae96 | 4513 | |
77145576 JK |
4514 | n_directories = read_uleb128 (data, & bytes_read, end); |
4515 | data += bytes_read; | |
4516 | if (data == end) | |
d8024a91 | 4517 | { |
77145576 | 4518 | warn (_("Corrupt directories list\n")); |
d8024a91 NC |
4519 | break; |
4520 | } | |
4521 | ||
b40bf0a2 NC |
4522 | directory_table = (unsigned char **) |
4523 | xmalloc (n_directories * sizeof (unsigned char *)); | |
a262ae96 | 4524 | |
77145576 | 4525 | for (entryi = 0; entryi < n_directories; entryi++) |
b40bf0a2 | 4526 | { |
77145576 | 4527 | unsigned char **pathp = &directory_table[entryi]; |
a262ae96 | 4528 | |
77145576 JK |
4529 | format = format_start; |
4530 | for (formati = 0; formati < format_count; formati++) | |
4531 | { | |
4532 | dwarf_vma content_type, form; | |
4533 | dwarf_vma uvalue; | |
4534 | ||
4535 | content_type = read_uleb128 (format, & bytes_read, end); | |
4536 | format += bytes_read; | |
4537 | form = read_uleb128 (format, & bytes_read, end); | |
4538 | format += bytes_read; | |
4539 | if (data == end) | |
4540 | { | |
4541 | warn (_("Corrupt directories list\n")); | |
4542 | break; | |
4543 | } | |
4544 | switch (content_type) | |
4545 | { | |
4546 | case DW_LNCT_path: | |
4547 | switch (form) | |
4548 | { | |
4549 | case DW_FORM_string: | |
4550 | *pathp = data; | |
4551 | break; | |
4552 | case DW_FORM_line_strp: | |
4553 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4554 | end); | |
4555 | /* Remove const by the cast. */ | |
4556 | *pathp = (unsigned char *) | |
4557 | fetch_indirect_line_string (uvalue); | |
4558 | break; | |
4559 | } | |
4560 | break; | |
4561 | } | |
ec1b0fbb | 4562 | data = read_and_display_attr_value (0, form, 0, start, data, end, |
77145576 JK |
4563 | 0, 0, |
4564 | linfo.li_offset_size, | |
4565 | linfo.li_version, | |
4566 | NULL, 1, section, | |
ec1b0fbb | 4567 | NULL, '\t', -1); |
77145576 JK |
4568 | } |
4569 | if (data == end) | |
4570 | { | |
4571 | warn (_("Corrupt directories list\n")); | |
4572 | break; | |
4573 | } | |
4574 | } | |
a262ae96 | 4575 | |
77145576 JK |
4576 | /* Skip files format. */ |
4577 | SAFE_BYTE_GET_AND_INC (format_count, data, 1, end); | |
4578 | format_start = data; | |
4579 | for (formati = 0; formati < format_count; formati++) | |
b40bf0a2 | 4580 | { |
b40bf0a2 NC |
4581 | read_uleb128 (data, & bytes_read, end); |
4582 | data += bytes_read; | |
4583 | read_uleb128 (data, & bytes_read, end); | |
4584 | data += bytes_read; | |
b40bf0a2 | 4585 | } |
a262ae96 | 4586 | |
77145576 JK |
4587 | n_files = read_uleb128 (data, & bytes_read, end); |
4588 | data += bytes_read; | |
4589 | if (data == end) | |
d8024a91 | 4590 | { |
77145576 | 4591 | warn (_("Corrupt file name list\n")); |
d8024a91 NC |
4592 | break; |
4593 | } | |
4594 | ||
77145576 JK |
4595 | file_table = (File_Entry *) xcalloc (1, n_files |
4596 | * sizeof (File_Entry)); | |
a262ae96 | 4597 | |
77145576 | 4598 | for (entryi = 0; entryi < n_files; entryi++) |
b40bf0a2 | 4599 | { |
77145576 | 4600 | File_Entry *file = &file_table[entryi]; |
a262ae96 | 4601 | |
77145576 JK |
4602 | format = format_start; |
4603 | for (formati = 0; formati < format_count; formati++) | |
4604 | { | |
4605 | dwarf_vma content_type, form; | |
4606 | dwarf_vma uvalue; | |
4607 | ||
4608 | content_type = read_uleb128 (format, & bytes_read, end); | |
4609 | format += bytes_read; | |
4610 | form = read_uleb128 (format, & bytes_read, end); | |
4611 | format += bytes_read; | |
4612 | if (data == end) | |
4613 | { | |
4614 | warn (_("Corrupt file name list\n")); | |
4615 | break; | |
4616 | } | |
4617 | switch (content_type) | |
4618 | { | |
4619 | case DW_LNCT_path: | |
4620 | switch (form) | |
4621 | { | |
4622 | case DW_FORM_string: | |
4623 | file->name = data; | |
4624 | break; | |
4625 | case DW_FORM_line_strp: | |
4626 | SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size, | |
4627 | end); | |
4628 | /* Remove const by the cast. */ | |
4629 | file->name = (unsigned char *) | |
4630 | fetch_indirect_line_string (uvalue); | |
4631 | break; | |
4632 | } | |
4633 | break; | |
4634 | case DW_LNCT_directory_index: | |
4635 | switch (form) | |
4636 | { | |
4637 | case DW_FORM_data1: | |
4638 | SAFE_BYTE_GET (file->directory_index, data, 1, | |
4639 | end); | |
4640 | break; | |
4641 | case DW_FORM_data2: | |
4642 | SAFE_BYTE_GET (file->directory_index, data, 2, | |
4643 | end); | |
4644 | break; | |
4645 | case DW_FORM_udata: | |
4646 | file->directory_index = read_uleb128 (data, NULL, | |
4647 | end); | |
4648 | break; | |
4649 | } | |
4650 | break; | |
4651 | } | |
ec1b0fbb | 4652 | data = read_and_display_attr_value (0, form, 0, start, data, end, |
77145576 JK |
4653 | 0, 0, |
4654 | linfo.li_offset_size, | |
4655 | linfo.li_version, | |
4656 | NULL, 1, section, | |
ec1b0fbb | 4657 | NULL, '\t', -1); |
77145576 JK |
4658 | } |
4659 | if (data == end) | |
4660 | { | |
4661 | warn (_("Corrupt file name list\n")); | |
4662 | break; | |
4663 | } | |
4664 | } | |
4665 | } | |
4666 | else | |
4667 | { | |
4668 | if (*data != 0) | |
b40bf0a2 | 4669 | { |
77145576 JK |
4670 | unsigned char *ptr_directory_table = data; |
4671 | ||
4672 | while (data < end && *data != 0) | |
4673 | { | |
4674 | data += strnlen ((char *) data, end - data) + 1; | |
4675 | n_directories++; | |
4676 | } | |
4677 | ||
4678 | /* PR 20440 */ | |
4679 | if (data >= end) | |
4680 | { | |
4681 | warn (_("directory table ends unexpectedly\n")); | |
4682 | n_directories = 0; | |
4683 | break; | |
4684 | } | |
4685 | ||
4686 | /* Go through the directory table again to save the directories. */ | |
4687 | directory_table = (unsigned char **) | |
4688 | xmalloc (n_directories * sizeof (unsigned char *)); | |
4689 | ||
4690 | i = 0; | |
4691 | while (*ptr_directory_table != 0) | |
4692 | { | |
4693 | directory_table[i] = ptr_directory_table; | |
4694 | ptr_directory_table += strnlen ((char *) ptr_directory_table, | |
4695 | ptr_directory_table - end) + 1; | |
4696 | i++; | |
4697 | } | |
b40bf0a2 | 4698 | } |
77145576 JK |
4699 | /* Skip the NUL at the end of the table. */ |
4700 | data++; | |
4701 | ||
4702 | /* Traverse the File Name table just to count the entries. */ | |
4703 | if (data < end && *data != 0) | |
b40bf0a2 | 4704 | { |
77145576 JK |
4705 | unsigned char *ptr_file_name_table = data; |
4706 | ||
4707 | while (data < end && *data != 0) | |
db9537d2 | 4708 | { |
77145576 JK |
4709 | unsigned int bytes_read; |
4710 | ||
4711 | /* Skip Name, directory index, last modification time and length | |
4712 | of file. */ | |
4713 | data += strnlen ((char *) data, end - data) + 1; | |
4714 | read_uleb128 (data, & bytes_read, end); | |
4715 | data += bytes_read; | |
4716 | read_uleb128 (data, & bytes_read, end); | |
4717 | data += bytes_read; | |
4718 | read_uleb128 (data, & bytes_read, end); | |
4719 | data += bytes_read; | |
4720 | ||
4721 | n_files++; | |
db9537d2 | 4722 | } |
a262ae96 | 4723 | |
77145576 JK |
4724 | if (data >= end) |
4725 | { | |
4726 | warn (_("file table ends unexpectedly\n")); | |
4727 | n_files = 0; | |
4728 | break; | |
4729 | } | |
4730 | ||
4731 | /* Go through the file table again to save the strings. */ | |
4732 | file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry)); | |
0c588247 | 4733 | |
77145576 JK |
4734 | i = 0; |
4735 | while (*ptr_file_name_table != 0) | |
4736 | { | |
4737 | unsigned int bytes_read; | |
4738 | ||
4739 | file_table[i].name = ptr_file_name_table; | |
4740 | ptr_file_name_table += strnlen ((char *) ptr_file_name_table, | |
4741 | end - ptr_file_name_table) + 1; | |
4742 | ||
4743 | /* We are not interested in directory, time or size. */ | |
4744 | file_table[i].directory_index = read_uleb128 (ptr_file_name_table, | |
4745 | & bytes_read, end); | |
4746 | ptr_file_name_table += bytes_read; | |
4747 | file_table[i].modification_date = read_uleb128 (ptr_file_name_table, | |
4748 | & bytes_read, end); | |
4749 | ptr_file_name_table += bytes_read; | |
4750 | file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end); | |
4751 | ptr_file_name_table += bytes_read; | |
4752 | i++; | |
4753 | } | |
4754 | i = 0; | |
b40bf0a2 | 4755 | } |
77145576 JK |
4756 | |
4757 | /* Skip the NUL at the end of the table. */ | |
4758 | data++; | |
b40bf0a2 | 4759 | } |
cc5914eb | 4760 | |
77145576 | 4761 | /* Print the Compilation Unit's name and a header. */ |
f082820d AM |
4762 | if (file_table == NULL) |
4763 | ; | |
4764 | else if (directory_table == NULL) | |
4765 | printf (_("CU: %s:\n"), file_table[0].name); | |
77145576 JK |
4766 | else |
4767 | { | |
4768 | unsigned int ix = file_table[0].directory_index; | |
4769 | const char *directory; | |
4770 | ||
4771 | if (ix == 0) | |
4772 | directory = "."; | |
4773 | /* PR 20439 */ | |
4774 | else if (n_directories == 0) | |
4775 | directory = _("<unknown>"); | |
4776 | else if (ix > n_directories) | |
4777 | { | |
4778 | warn (_("directory index %u > number of directories %s\n"), | |
4779 | ix, dwarf_vmatoa ("u", n_directories)); | |
4780 | directory = _("<corrupt>"); | |
4781 | } | |
4782 | else | |
4783 | directory = (char *) directory_table[ix - 1]; | |
4784 | ||
4785 | if (do_wide || strlen (directory) < 76) | |
4786 | printf (_("CU: %s/%s:\n"), directory, file_table[0].name); | |
4787 | else | |
4788 | printf ("%s:\n", file_table[0].name); | |
77145576 | 4789 | } |
a262ae96 | 4790 | |
17f6ade2 | 4791 | printf (_("File name Line number Starting address View Stmt\n")); |
b40bf0a2 NC |
4792 | saved_linfo = linfo; |
4793 | } | |
a262ae96 NC |
4794 | |
4795 | /* This loop iterates through the Dwarf Line Number Program. */ | |
4796 | while (data < end_of_sequence) | |
b4eb7656 | 4797 | { |
a262ae96 | 4798 | unsigned char op_code; |
ba8826a8 | 4799 | int xop; |
b4eb7656 AM |
4800 | int adv; |
4801 | unsigned long int uladv; | |
4802 | unsigned int bytes_read; | |
4803 | int is_special_opcode = 0; | |
a262ae96 | 4804 | |
b4eb7656 | 4805 | op_code = *data++; |
ba8826a8 | 4806 | xop = op_code; |
a262ae96 | 4807 | |
b4eb7656 | 4808 | if (op_code >= linfo.li_opcode_base) |
a262ae96 | 4809 | { |
91d6fa6a | 4810 | op_code -= linfo.li_opcode_base; |
a233b20c JJ |
4811 | uladv = (op_code / linfo.li_line_range); |
4812 | if (linfo.li_max_ops_per_insn == 1) | |
4813 | { | |
4814 | uladv *= linfo.li_min_insn_length; | |
4815 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4816 | if (uladv) |
4817 | state_machine_regs.view = 0; | |
a233b20c JJ |
4818 | } |
4819 | else | |
4820 | { | |
ba8826a8 AO |
4821 | unsigned addrdelta |
4822 | = ((state_machine_regs.op_index + uladv) | |
4823 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4824 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4825 | state_machine_regs.address |
4826 | += addrdelta; | |
a233b20c JJ |
4827 | state_machine_regs.op_index |
4828 | = (state_machine_regs.op_index + uladv) | |
b40bf0a2 | 4829 | % linfo.li_max_ops_per_insn; |
ba8826a8 AO |
4830 | if (addrdelta) |
4831 | state_machine_regs.view = 0; | |
a233b20c | 4832 | } |
a262ae96 | 4833 | |
b4eb7656 AM |
4834 | adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
4835 | state_machine_regs.line += adv; | |
4836 | is_special_opcode = 1; | |
ba8826a8 | 4837 | /* Increment view after printing this row. */ |
b4eb7656 AM |
4838 | } |
4839 | else switch (op_code) | |
b40bf0a2 NC |
4840 | { |
4841 | case DW_LNS_extended_op: | |
4842 | { | |
4843 | unsigned int ext_op_code_len; | |
4844 | unsigned char ext_op_code; | |
4845 | unsigned char *op_code_data = data; | |
4846 | ||
4847 | ext_op_code_len = read_uleb128 (op_code_data, &bytes_read, | |
4848 | end_of_sequence); | |
4849 | op_code_data += bytes_read; | |
4850 | ||
4851 | if (ext_op_code_len == 0) | |
4852 | { | |
f41e4712 | 4853 | warn (_("Badly formed extended line op encountered!\n")); |
b40bf0a2 NC |
4854 | break; |
4855 | } | |
4856 | ext_op_code_len += bytes_read; | |
4857 | ext_op_code = *op_code_data++; | |
ba8826a8 AO |
4858 | xop = ext_op_code; |
4859 | xop = -xop; | |
b40bf0a2 NC |
4860 | |
4861 | switch (ext_op_code) | |
4862 | { | |
4863 | case DW_LNE_end_sequence: | |
ba8826a8 | 4864 | /* Reset stuff after printing this row. */ |
b40bf0a2 NC |
4865 | break; |
4866 | case DW_LNE_set_address: | |
4867 | SAFE_BYTE_GET_AND_INC (state_machine_regs.address, | |
87bc83b3 CC |
4868 | op_code_data, |
4869 | ext_op_code_len - bytes_read - 1, | |
b40bf0a2 NC |
4870 | end); |
4871 | state_machine_regs.op_index = 0; | |
ba8826a8 | 4872 | state_machine_regs.view = 0; |
b40bf0a2 NC |
4873 | break; |
4874 | case DW_LNE_define_file: | |
4875 | { | |
4876 | file_table = (File_Entry *) xrealloc | |
4877 | (file_table, (n_files + 1) * sizeof (File_Entry)); | |
4878 | ||
4879 | ++state_machine_regs.last_file_entry; | |
4880 | /* Source file name. */ | |
4881 | file_table[n_files].name = op_code_data; | |
4882 | op_code_data += strlen ((char *) op_code_data) + 1; | |
4883 | /* Directory index. */ | |
4884 | file_table[n_files].directory_index = | |
4885 | read_uleb128 (op_code_data, & bytes_read, | |
4886 | end_of_sequence); | |
4887 | op_code_data += bytes_read; | |
4888 | /* Last modification time. */ | |
4889 | file_table[n_files].modification_date = | |
4890 | read_uleb128 (op_code_data, & bytes_read, | |
4891 | end_of_sequence); | |
4892 | op_code_data += bytes_read; | |
4893 | /* File length. */ | |
4894 | file_table[n_files].length = | |
4895 | read_uleb128 (op_code_data, & bytes_read, | |
4896 | end_of_sequence); | |
4897 | ||
4898 | n_files++; | |
4899 | break; | |
4900 | } | |
4901 | case DW_LNE_set_discriminator: | |
4902 | case DW_LNE_HP_set_sequence: | |
4903 | /* Simply ignored. */ | |
4904 | break; | |
4905 | ||
4906 | default: | |
4907 | printf (_("UNKNOWN (%u): length %d\n"), | |
4908 | ext_op_code, ext_op_code_len - bytes_read); | |
4909 | break; | |
4910 | } | |
4911 | data += ext_op_code_len; | |
4912 | break; | |
4913 | } | |
4914 | case DW_LNS_copy: | |
ba8826a8 | 4915 | /* Increment view after printing this row. */ |
b40bf0a2 NC |
4916 | break; |
4917 | ||
4918 | case DW_LNS_advance_pc: | |
4919 | uladv = read_uleb128 (data, & bytes_read, end); | |
4920 | data += bytes_read; | |
4921 | if (linfo.li_max_ops_per_insn == 1) | |
4922 | { | |
4923 | uladv *= linfo.li_min_insn_length; | |
4924 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
4925 | if (uladv) |
4926 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4927 | } |
4928 | else | |
4929 | { | |
ba8826a8 AO |
4930 | unsigned addrdelta |
4931 | = ((state_machine_regs.op_index + uladv) | |
4932 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 4933 | * linfo.li_min_insn_length; |
ba8826a8 AO |
4934 | state_machine_regs.address |
4935 | += addrdelta; | |
b40bf0a2 NC |
4936 | state_machine_regs.op_index |
4937 | = (state_machine_regs.op_index + uladv) | |
4938 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
4939 | if (addrdelta) |
4940 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
4941 | } |
4942 | break; | |
4943 | ||
4944 | case DW_LNS_advance_line: | |
4945 | adv = read_sleb128 (data, & bytes_read, end); | |
4946 | data += bytes_read; | |
4947 | state_machine_regs.line += adv; | |
4948 | break; | |
4949 | ||
4950 | case DW_LNS_set_file: | |
4951 | adv = read_uleb128 (data, & bytes_read, end); | |
4952 | data += bytes_read; | |
4953 | state_machine_regs.file = adv; | |
4954 | ||
db9537d2 NC |
4955 | { |
4956 | unsigned file = state_machine_regs.file - 1; | |
4957 | unsigned dir; | |
4958 | ||
4959 | if (file_table == NULL || n_files == 0) | |
4960 | printf (_("\n [Use file table entry %d]\n"), file); | |
4961 | /* PR 20439 */ | |
4962 | else if (file >= n_files) | |
4963 | { | |
4964 | warn (_("file index %u > number of files %u\n"), file + 1, n_files); | |
4965 | printf (_("\n <over large file table index %u>"), file); | |
4966 | } | |
4967 | else if ((dir = file_table[file].directory_index) == 0) | |
4968 | /* If directory index is 0, that means current directory. */ | |
4969 | printf ("\n./%s:[++]\n", file_table[file].name); | |
4970 | else if (directory_table == NULL || n_directories == 0) | |
4971 | printf (_("\n [Use file %s in directory table entry %d]\n"), | |
4972 | file_table[file].name, dir); | |
4973 | /* PR 20439 */ | |
4974 | else if (dir > n_directories) | |
4975 | { | |
77145576 JK |
4976 | warn (_("directory index %u > number of directories %s\n"), |
4977 | dir, dwarf_vmatoa ("u", n_directories)); | |
db9537d2 NC |
4978 | printf (_("\n <over large directory table entry %u>\n"), dir); |
4979 | } | |
4980 | else | |
4981 | printf ("\n%s/%s:\n", | |
4982 | /* The directory index starts counting at 1. */ | |
4983 | directory_table[dir - 1], file_table[file].name); | |
4984 | } | |
b40bf0a2 NC |
4985 | break; |
4986 | ||
4987 | case DW_LNS_set_column: | |
4988 | uladv = read_uleb128 (data, & bytes_read, end); | |
4989 | data += bytes_read; | |
4990 | state_machine_regs.column = uladv; | |
4991 | break; | |
4992 | ||
4993 | case DW_LNS_negate_stmt: | |
4994 | adv = state_machine_regs.is_stmt; | |
4995 | adv = ! adv; | |
4996 | state_machine_regs.is_stmt = adv; | |
4997 | break; | |
4998 | ||
4999 | case DW_LNS_set_basic_block: | |
5000 | state_machine_regs.basic_block = 1; | |
5001 | break; | |
5002 | ||
5003 | case DW_LNS_const_add_pc: | |
5004 | uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range); | |
5005 | if (linfo.li_max_ops_per_insn == 1) | |
5006 | { | |
5007 | uladv *= linfo.li_min_insn_length; | |
5008 | state_machine_regs.address += uladv; | |
ba8826a8 AO |
5009 | if (uladv) |
5010 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
5011 | } |
5012 | else | |
5013 | { | |
ba8826a8 AO |
5014 | unsigned addrdelta |
5015 | = ((state_machine_regs.op_index + uladv) | |
5016 | / linfo.li_max_ops_per_insn) | |
b40bf0a2 | 5017 | * linfo.li_min_insn_length; |
ba8826a8 AO |
5018 | state_machine_regs.address |
5019 | += addrdelta; | |
b40bf0a2 NC |
5020 | state_machine_regs.op_index |
5021 | = (state_machine_regs.op_index + uladv) | |
5022 | % linfo.li_max_ops_per_insn; | |
ba8826a8 AO |
5023 | if (addrdelta) |
5024 | state_machine_regs.view = 0; | |
b40bf0a2 NC |
5025 | } |
5026 | break; | |
5027 | ||
5028 | case DW_LNS_fixed_advance_pc: | |
5029 | SAFE_BYTE_GET_AND_INC (uladv, data, 2, end); | |
5030 | state_machine_regs.address += uladv; | |
5031 | state_machine_regs.op_index = 0; | |
ba8826a8 | 5032 | /* Do NOT reset view. */ |
b40bf0a2 NC |
5033 | break; |
5034 | ||
5035 | case DW_LNS_set_prologue_end: | |
5036 | break; | |
5037 | ||
5038 | case DW_LNS_set_epilogue_begin: | |
5039 | break; | |
5040 | ||
5041 | case DW_LNS_set_isa: | |
5042 | uladv = read_uleb128 (data, & bytes_read, end); | |
5043 | data += bytes_read; | |
5044 | printf (_(" Set ISA to %lu\n"), uladv); | |
5045 | break; | |
5046 | ||
5047 | default: | |
5048 | printf (_(" Unknown opcode %d with operands: "), op_code); | |
5049 | ||
5050 | if (standard_opcodes != NULL) | |
5051 | for (i = standard_opcodes[op_code - 1]; i > 0 ; --i) | |
5052 | { | |
5053 | printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data, | |
5054 | &bytes_read, end)), | |
5055 | i == 1 ? "" : ", "); | |
5056 | data += bytes_read; | |
5057 | } | |
5058 | putchar ('\n'); | |
5059 | break; | |
5060 | } | |
a262ae96 | 5061 | |
b4eb7656 AM |
5062 | /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row |
5063 | to the DWARF address/line matrix. */ | |
ba8826a8 AO |
5064 | if ((is_special_opcode) || (xop == -DW_LNE_end_sequence) |
5065 | || (xop == DW_LNS_copy)) | |
b4eb7656 AM |
5066 | { |
5067 | const unsigned int MAX_FILENAME_LENGTH = 35; | |
5068 | char *fileName; | |
5069 | char *newFileName = NULL; | |
5070 | size_t fileNameLength; | |
b40bf0a2 NC |
5071 | |
5072 | if (file_table) | |
db9537d2 NC |
5073 | { |
5074 | unsigned indx = state_machine_regs.file - 1; | |
5075 | /* PR 20439 */ | |
5076 | if (indx >= n_files) | |
5077 | { | |
5078 | warn (_("corrupt file index %u encountered\n"), indx); | |
5079 | fileName = _("<corrupt>"); | |
5080 | } | |
5081 | else | |
5082 | fileName = (char *) file_table[indx].name; | |
5083 | } | |
b40bf0a2 | 5084 | else |
db9537d2 | 5085 | fileName = _("<unknown>"); |
b40bf0a2 NC |
5086 | |
5087 | fileNameLength = strlen (fileName); | |
a262ae96 | 5088 | |
b4eb7656 AM |
5089 | if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide)) |
5090 | { | |
5091 | newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1); | |
5092 | /* Truncate file name */ | |
5093 | strncpy (newFileName, | |
5094 | fileName + fileNameLength - MAX_FILENAME_LENGTH, | |
5095 | MAX_FILENAME_LENGTH + 1); | |
5096 | } | |
5097 | else | |
5098 | { | |
5099 | newFileName = (char *) xmalloc (fileNameLength + 1); | |
5100 | strncpy (newFileName, fileName, fileNameLength + 1); | |
5101 | } | |
5102 | ||
5103 | if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH)) | |
5104 | { | |
a233b20c | 5105 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 5106 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 5107 | newFileName, state_machine_regs.line, |
a233b20c JJ |
5108 | state_machine_regs.address); |
5109 | else | |
ba8826a8 | 5110 | printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 5111 | newFileName, state_machine_regs.line, |
a233b20c JJ |
5112 | state_machine_regs.address, |
5113 | state_machine_regs.op_index); | |
b4eb7656 AM |
5114 | } |
5115 | else | |
5116 | { | |
a233b20c | 5117 | if (linfo.li_max_ops_per_insn == 1) |
ba8826a8 | 5118 | printf ("%s %11d %#18" DWARF_VMA_FMT "x", |
467c65bc | 5119 | newFileName, state_machine_regs.line, |
a233b20c JJ |
5120 | state_machine_regs.address); |
5121 | else | |
ba8826a8 | 5122 | printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]", |
467c65bc | 5123 | newFileName, state_machine_regs.line, |
a233b20c JJ |
5124 | state_machine_regs.address, |
5125 | state_machine_regs.op_index); | |
b4eb7656 | 5126 | } |
a262ae96 | 5127 | |
ba8826a8 | 5128 | if (state_machine_regs.view) |
17f6ade2 | 5129 | printf (" %6u", state_machine_regs.view); |
ba8826a8 | 5130 | else |
17f6ade2 JD |
5131 | printf (" "); |
5132 | ||
5133 | if (state_machine_regs.is_stmt) | |
5134 | printf (" x"); | |
5135 | ||
5136 | putchar ('\n'); | |
ba8826a8 AO |
5137 | state_machine_regs.view++; |
5138 | ||
5139 | if (xop == -DW_LNE_end_sequence) | |
5140 | { | |
5141 | reset_state_machine (linfo.li_default_is_stmt); | |
5142 | putchar ('\n'); | |
5143 | } | |
a262ae96 | 5144 | |
b4eb7656 AM |
5145 | free (newFileName); |
5146 | } | |
5147 | } | |
b40bf0a2 NC |
5148 | |
5149 | if (file_table) | |
5150 | { | |
5151 | free (file_table); | |
5152 | file_table = NULL; | |
5153 | n_files = 0; | |
5154 | } | |
5155 | ||
5156 | if (directory_table) | |
5157 | { | |
5158 | free (directory_table); | |
5159 | directory_table = NULL; | |
5160 | n_directories = 0; | |
5161 | } | |
5162 | ||
a262ae96 NC |
5163 | putchar ('\n'); |
5164 | } | |
5165 | ||
5166 | return 1; | |
5167 | } | |
5168 | ||
5169 | static int | |
77145576 | 5170 | display_debug_lines (struct dwarf_section *section, void *file) |
a262ae96 NC |
5171 | { |
5172 | unsigned char *data = section->start; | |
5173 | unsigned char *end = data + section->size; | |
4cb93e3b TG |
5174 | int retValRaw = 1; |
5175 | int retValDecoded = 1; | |
a262ae96 | 5176 | |
008f4c78 NC |
5177 | if (do_debug_lines == 0) |
5178 | do_debug_lines |= FLAG_DEBUG_LINES_RAW; | |
5179 | ||
4cb93e3b | 5180 | if (do_debug_lines & FLAG_DEBUG_LINES_RAW) |
77145576 | 5181 | retValRaw = display_debug_lines_raw (section, data, end, file); |
a262ae96 | 5182 | |
4cb93e3b | 5183 | if (do_debug_lines & FLAG_DEBUG_LINES_DECODED) |
ec1b0fbb | 5184 | retValDecoded = display_debug_lines_decoded (section, data, data, end, file); |
a262ae96 | 5185 | |
4cb93e3b | 5186 | if (!retValRaw || !retValDecoded) |
a262ae96 NC |
5187 | return 0; |
5188 | ||
5189 | return 1; | |
5190 | } | |
5191 | ||
6e3d6dc1 NC |
5192 | static debug_info * |
5193 | find_debug_info_for_offset (unsigned long offset) | |
5194 | { | |
5195 | unsigned int i; | |
5196 | ||
5197 | if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) | |
5198 | return NULL; | |
5199 | ||
5200 | for (i = 0; i < num_debug_info_entries; i++) | |
5201 | if (debug_information[i].cu_offset == offset) | |
5202 | return debug_information + i; | |
5203 | ||
5204 | return NULL; | |
5205 | } | |
5206 | ||
459d52c8 DE |
5207 | static const char * |
5208 | get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind) | |
5209 | { | |
5210 | /* See gdb/gdb-index.h. */ | |
5211 | static const char * const kinds[] = | |
5212 | { | |
5213 | N_ ("no info"), | |
5214 | N_ ("type"), | |
5215 | N_ ("variable"), | |
5216 | N_ ("function"), | |
5217 | N_ ("other"), | |
5218 | N_ ("unused5"), | |
5219 | N_ ("unused6"), | |
5220 | N_ ("unused7") | |
5221 | }; | |
5222 | ||
5223 | return _ (kinds[kind]); | |
5224 | } | |
5225 | ||
19e6b90e | 5226 | static int |
459d52c8 DE |
5227 | display_debug_pubnames_worker (struct dwarf_section *section, |
5228 | void *file ATTRIBUTE_UNUSED, | |
5229 | int is_gnu) | |
19e6b90e | 5230 | { |
91d6fa6a | 5231 | DWARF2_Internal_PubNames names; |
19e6b90e L |
5232 | unsigned char *start = section->start; |
5233 | unsigned char *end = start + section->size; | |
5234 | ||
6e3d6dc1 NC |
5235 | /* It does not matter if this load fails, |
5236 | we test for that later on. */ | |
5237 | load_debug_info (file); | |
5238 | ||
dda8d76d | 5239 | introduce (section, FALSE); |
19e6b90e L |
5240 | |
5241 | while (start < end) | |
5242 | { | |
5243 | unsigned char *data; | |
e98fdf1a | 5244 | unsigned long sec_off; |
bf5117e3 | 5245 | unsigned int offset_size, initial_length_size; |
19e6b90e | 5246 | |
e98fdf1a | 5247 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end); |
91d6fa6a | 5248 | if (names.pn_length == 0xffffffff) |
19e6b90e | 5249 | { |
e98fdf1a | 5250 | SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end); |
19e6b90e L |
5251 | offset_size = 8; |
5252 | initial_length_size = 12; | |
5253 | } | |
5254 | else | |
5255 | { | |
5256 | offset_size = 4; | |
5257 | initial_length_size = 4; | |
5258 | } | |
5259 | ||
e98fdf1a AM |
5260 | sec_off = start - section->start; |
5261 | if (sec_off + names.pn_length < sec_off | |
5262 | || sec_off + names.pn_length > section->size) | |
5263 | { | |
5264 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
5265 | section->name, | |
5266 | sec_off - initial_length_size, | |
5267 | dwarf_vmatoa ("x", names.pn_length)); | |
5268 | break; | |
5269 | } | |
5270 | ||
5271 | data = start; | |
5272 | start += names.pn_length; | |
5273 | ||
0c588247 NC |
5274 | SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end); |
5275 | SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end); | |
6e3d6dc1 NC |
5276 | |
5277 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE | |
5278 | && num_debug_info_entries > 0 | |
91d6fa6a | 5279 | && find_debug_info_for_offset (names.pn_offset) == NULL) |
6e3d6dc1 | 5280 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), |
47704ddf | 5281 | (unsigned long) names.pn_offset, section->name); |
cecf136e | 5282 | |
0c588247 | 5283 | SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end); |
19e6b90e | 5284 | |
058037d3 NC |
5285 | printf (_(" Length: %ld\n"), |
5286 | (long) names.pn_length); | |
5287 | printf (_(" Version: %d\n"), | |
5288 | names.pn_version); | |
5289 | printf (_(" Offset into .debug_info section: 0x%lx\n"), | |
5290 | (unsigned long) names.pn_offset); | |
5291 | printf (_(" Size of area in .debug_info section: %ld\n"), | |
5292 | (long) names.pn_size); | |
19e6b90e | 5293 | |
91d6fa6a | 5294 | if (names.pn_version != 2 && names.pn_version != 3) |
19e6b90e L |
5295 | { |
5296 | static int warned = 0; | |
5297 | ||
5298 | if (! warned) | |
5299 | { | |
5300 | warn (_("Only DWARF 2 and 3 pubnames are currently supported\n")); | |
5301 | warned = 1; | |
5302 | } | |
5303 | ||
5304 | continue; | |
5305 | } | |
5306 | ||
459d52c8 DE |
5307 | if (is_gnu) |
5308 | printf (_("\n Offset Kind Name\n")); | |
5309 | else | |
5310 | printf (_("\n Offset\tName\n")); | |
19e6b90e | 5311 | |
e98fdf1a | 5312 | while (1) |
19e6b90e | 5313 | { |
f41e4712 | 5314 | bfd_size_type maxprint; |
e98fdf1a | 5315 | dwarf_vma offset; |
f41e4712 | 5316 | |
0c588247 | 5317 | SAFE_BYTE_GET (offset, data, offset_size, end); |
19e6b90e | 5318 | |
e98fdf1a AM |
5319 | if (offset == 0) |
5320 | break; | |
b4eb7656 | 5321 | |
e98fdf1a AM |
5322 | data += offset_size; |
5323 | if (data >= end) | |
5324 | break; | |
5325 | maxprint = (end - data) - 1; | |
f41e4712 | 5326 | |
e98fdf1a AM |
5327 | if (is_gnu) |
5328 | { | |
5329 | unsigned int kind_data; | |
5330 | gdb_index_symbol_kind kind; | |
5331 | const char *kind_name; | |
5332 | int is_static; | |
5333 | ||
5334 | SAFE_BYTE_GET (kind_data, data, 1, end); | |
5335 | data++; | |
5336 | maxprint --; | |
5337 | /* GCC computes the kind as the upper byte in the CU index | |
5338 | word, and then right shifts it by the CU index size. | |
5339 | Left shift KIND to where the gdb-index.h accessor macros | |
5340 | can use it. */ | |
5341 | kind_data <<= GDB_INDEX_CU_BITSIZE; | |
5342 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data); | |
5343 | kind_name = get_gdb_index_symbol_kind_name (kind); | |
5344 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data); | |
5345 | printf (" %-6lx %s,%-10s %.*s\n", | |
5346 | (unsigned long) offset, is_static ? _("s") : _("g"), | |
5347 | kind_name, (int) maxprint, data); | |
19e6b90e | 5348 | } |
e98fdf1a AM |
5349 | else |
5350 | printf (" %-6lx\t%.*s\n", | |
5351 | (unsigned long) offset, (int) maxprint, data); | |
5352 | ||
5353 | data += strnlen ((char *) data, maxprint) + 1; | |
5354 | if (data >= end) | |
5355 | break; | |
19e6b90e | 5356 | } |
19e6b90e L |
5357 | } |
5358 | ||
5359 | printf ("\n"); | |
5360 | return 1; | |
5361 | } | |
5362 | ||
459d52c8 DE |
5363 | static int |
5364 | display_debug_pubnames (struct dwarf_section *section, void *file) | |
5365 | { | |
5366 | return display_debug_pubnames_worker (section, file, 0); | |
5367 | } | |
5368 | ||
5369 | static int | |
5370 | display_debug_gnu_pubnames (struct dwarf_section *section, void *file) | |
5371 | { | |
5372 | return display_debug_pubnames_worker (section, file, 1); | |
5373 | } | |
5374 | ||
19e6b90e L |
5375 | static int |
5376 | display_debug_macinfo (struct dwarf_section *section, | |
5377 | void *file ATTRIBUTE_UNUSED) | |
5378 | { | |
5379 | unsigned char *start = section->start; | |
5380 | unsigned char *end = start + section->size; | |
5381 | unsigned char *curr = start; | |
5382 | unsigned int bytes_read; | |
5383 | enum dwarf_macinfo_record_type op; | |
5384 | ||
dda8d76d | 5385 | introduce (section, FALSE); |
19e6b90e L |
5386 | |
5387 | while (curr < end) | |
5388 | { | |
5389 | unsigned int lineno; | |
0c588247 | 5390 | const unsigned char *string; |
19e6b90e | 5391 | |
3f5e193b | 5392 | op = (enum dwarf_macinfo_record_type) *curr; |
19e6b90e L |
5393 | curr++; |
5394 | ||
5395 | switch (op) | |
5396 | { | |
5397 | case DW_MACINFO_start_file: | |
5398 | { | |
5399 | unsigned int filenum; | |
5400 | ||
f6f0e17b | 5401 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5402 | curr += bytes_read; |
f6f0e17b | 5403 | filenum = read_uleb128 (curr, & bytes_read, end); |
19e6b90e L |
5404 | curr += bytes_read; |
5405 | ||
5406 | printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), | |
5407 | lineno, filenum); | |
5408 | } | |
5409 | break; | |
5410 | ||
5411 | case DW_MACINFO_end_file: | |
5412 | printf (_(" DW_MACINFO_end_file\n")); | |
5413 | break; | |
5414 | ||
5415 | case DW_MACINFO_define: | |
f6f0e17b | 5416 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5417 | curr += bytes_read; |
0c588247 NC |
5418 | string = curr; |
5419 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5420 | printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), |
5421 | lineno, string); | |
5422 | break; | |
5423 | ||
5424 | case DW_MACINFO_undef: | |
f6f0e17b | 5425 | lineno = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5426 | curr += bytes_read; |
0c588247 NC |
5427 | string = curr; |
5428 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5429 | printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), |
5430 | lineno, string); | |
5431 | break; | |
5432 | ||
5433 | case DW_MACINFO_vendor_ext: | |
5434 | { | |
5435 | unsigned int constant; | |
5436 | ||
f6f0e17b | 5437 | constant = read_uleb128 (curr, & bytes_read, end); |
19e6b90e | 5438 | curr += bytes_read; |
0c588247 NC |
5439 | string = curr; |
5440 | curr += strnlen ((char *) string, end - string) + 1; | |
19e6b90e L |
5441 | printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), |
5442 | constant, string); | |
5443 | } | |
5444 | break; | |
5445 | } | |
5446 | } | |
5447 | ||
5448 | return 1; | |
5449 | } | |
5450 | ||
4ccf1e31 JJ |
5451 | /* Given LINE_OFFSET into the .debug_line section, attempt to return |
5452 | filename and dirname corresponding to file name table entry with index | |
5453 | FILEIDX. Return NULL on failure. */ | |
5454 | ||
5455 | static unsigned char * | |
f6f0e17b NC |
5456 | get_line_filename_and_dirname (dwarf_vma line_offset, |
5457 | dwarf_vma fileidx, | |
4ccf1e31 JJ |
5458 | unsigned char **dir_name) |
5459 | { | |
5460 | struct dwarf_section *section = &debug_displays [line].section; | |
5461 | unsigned char *hdrptr, *dirtable, *file_name; | |
5462 | unsigned int offset_size, initial_length_size; | |
5463 | unsigned int version, opcode_base, bytes_read; | |
5464 | dwarf_vma length, diridx; | |
f6f0e17b | 5465 | const unsigned char * end; |
4ccf1e31 JJ |
5466 | |
5467 | *dir_name = NULL; | |
5468 | if (section->start == NULL | |
5469 | || line_offset >= section->size | |
5470 | || fileidx == 0) | |
5471 | return NULL; | |
5472 | ||
5473 | hdrptr = section->start + line_offset; | |
f6f0e17b | 5474 | end = section->start + section->size; |
0c588247 NC |
5475 | |
5476 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end); | |
4ccf1e31 JJ |
5477 | if (length == 0xffffffff) |
5478 | { | |
5479 | /* This section is 64-bit DWARF 3. */ | |
0c588247 | 5480 | SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end); |
4ccf1e31 JJ |
5481 | offset_size = 8; |
5482 | initial_length_size = 12; | |
5483 | } | |
5484 | else | |
5485 | { | |
5486 | offset_size = 4; | |
5487 | initial_length_size = 4; | |
5488 | } | |
e98fdf1a AM |
5489 | if (length + initial_length_size < length |
5490 | || length + initial_length_size > section->size) | |
4ccf1e31 | 5491 | return NULL; |
0c588247 NC |
5492 | |
5493 | SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end); | |
4ccf1e31 JJ |
5494 | if (version != 2 && version != 3 && version != 4) |
5495 | return NULL; | |
5496 | hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */ | |
5497 | if (version >= 4) | |
5498 | hdrptr++; /* Skip max_ops_per_insn. */ | |
5499 | hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */ | |
0c588247 NC |
5500 | |
5501 | SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end); | |
4ccf1e31 JJ |
5502 | if (opcode_base == 0) |
5503 | return NULL; | |
0c588247 | 5504 | |
4ccf1e31 | 5505 | hdrptr += opcode_base - 1; |
5c1c468d NC |
5506 | if (hdrptr >= end) |
5507 | return NULL; | |
5508 | ||
4ccf1e31 JJ |
5509 | dirtable = hdrptr; |
5510 | /* Skip over dirname table. */ | |
5511 | while (*hdrptr != '\0') | |
5c1c468d NC |
5512 | { |
5513 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; | |
5514 | if (hdrptr >= end) | |
5515 | return NULL; | |
5516 | } | |
4ccf1e31 | 5517 | hdrptr++; /* Skip the NUL at the end of the table. */ |
5c1c468d | 5518 | |
4ccf1e31 | 5519 | /* Now skip over preceding filename table entries. */ |
5c1c468d | 5520 | for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--) |
4ccf1e31 | 5521 | { |
0c588247 | 5522 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
f6f0e17b | 5523 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 5524 | hdrptr += bytes_read; |
f6f0e17b | 5525 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 | 5526 | hdrptr += bytes_read; |
f6f0e17b | 5527 | read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
5528 | hdrptr += bytes_read; |
5529 | } | |
5c1c468d | 5530 | if (hdrptr >= end || *hdrptr == '\0') |
4ccf1e31 | 5531 | return NULL; |
5c1c468d | 5532 | |
4ccf1e31 | 5533 | file_name = hdrptr; |
0c588247 | 5534 | hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1; |
5c1c468d NC |
5535 | if (hdrptr >= end) |
5536 | return NULL; | |
f6f0e17b | 5537 | diridx = read_uleb128 (hdrptr, &bytes_read, end); |
4ccf1e31 JJ |
5538 | if (diridx == 0) |
5539 | return file_name; | |
5c1c468d | 5540 | for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--) |
0c588247 | 5541 | dirtable += strnlen ((char *) dirtable, end - dirtable) + 1; |
5c1c468d | 5542 | if (dirtable >= end || *dirtable == '\0') |
4ccf1e31 JJ |
5543 | return NULL; |
5544 | *dir_name = dirtable; | |
5545 | return file_name; | |
5546 | } | |
5547 | ||
5548 | static int | |
5549 | display_debug_macro (struct dwarf_section *section, | |
5550 | void *file) | |
5551 | { | |
5552 | unsigned char *start = section->start; | |
5553 | unsigned char *end = start + section->size; | |
5554 | unsigned char *curr = start; | |
5555 | unsigned char *extended_op_buf[256]; | |
5556 | unsigned int bytes_read; | |
5557 | ||
dda8d76d NC |
5558 | load_debug_section_with_follow (str, file); |
5559 | load_debug_section_with_follow (line, file); | |
4ccf1e31 | 5560 | |
dda8d76d | 5561 | introduce (section, FALSE); |
4ccf1e31 JJ |
5562 | |
5563 | while (curr < end) | |
5564 | { | |
5565 | unsigned int lineno, version, flags; | |
5566 | unsigned int offset_size = 4; | |
0c588247 | 5567 | const unsigned char *string; |
4ccf1e31 JJ |
5568 | dwarf_vma line_offset = 0, sec_offset = curr - start, offset; |
5569 | unsigned char **extended_ops = NULL; | |
5570 | ||
0c588247 | 5571 | SAFE_BYTE_GET_AND_INC (version, curr, 2, end); |
7a7e1061 | 5572 | if (version != 4 && version != 5) |
4ccf1e31 | 5573 | { |
7a7e1061 | 5574 | error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"), |
4ccf1e31 JJ |
5575 | section->name); |
5576 | return 0; | |
5577 | } | |
5578 | ||
0c588247 | 5579 | SAFE_BYTE_GET_AND_INC (flags, curr, 1, end); |
4ccf1e31 JJ |
5580 | if (flags & 1) |
5581 | offset_size = 8; | |
5582 | printf (_(" Offset: 0x%lx\n"), | |
5583 | (unsigned long) sec_offset); | |
5584 | printf (_(" Version: %d\n"), version); | |
5585 | printf (_(" Offset size: %d\n"), offset_size); | |
5586 | if (flags & 2) | |
5587 | { | |
0c588247 | 5588 | SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end); |
4ccf1e31 JJ |
5589 | printf (_(" Offset into .debug_line: 0x%lx\n"), |
5590 | (unsigned long) line_offset); | |
5591 | } | |
5592 | if (flags & 4) | |
5593 | { | |
0c588247 | 5594 | unsigned int i, count, op; |
4ccf1e31 | 5595 | dwarf_vma nargs, n; |
0c588247 NC |
5596 | |
5597 | SAFE_BYTE_GET_AND_INC (count, curr, 1, end); | |
bf5117e3 | 5598 | |
4ccf1e31 JJ |
5599 | memset (extended_op_buf, 0, sizeof (extended_op_buf)); |
5600 | extended_ops = extended_op_buf; | |
5601 | if (count) | |
5602 | { | |
5603 | printf (_(" Extension opcode arguments:\n")); | |
5604 | for (i = 0; i < count; i++) | |
5605 | { | |
0c588247 | 5606 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 | 5607 | extended_ops[op] = curr; |
f6f0e17b | 5608 | nargs = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
5609 | curr += bytes_read; |
5610 | if (nargs == 0) | |
7a7e1061 | 5611 | printf (_(" DW_MACRO_%02x has no arguments\n"), op); |
4ccf1e31 JJ |
5612 | else |
5613 | { | |
7a7e1061 | 5614 | printf (_(" DW_MACRO_%02x arguments: "), op); |
4ccf1e31 JJ |
5615 | for (n = 0; n < nargs; n++) |
5616 | { | |
0c588247 NC |
5617 | unsigned int form; |
5618 | ||
5619 | SAFE_BYTE_GET_AND_INC (form, curr, 1, end); | |
4ccf1e31 JJ |
5620 | printf ("%s%s", get_FORM_name (form), |
5621 | n == nargs - 1 ? "\n" : ", "); | |
5622 | switch (form) | |
5623 | { | |
5624 | case DW_FORM_data1: | |
5625 | case DW_FORM_data2: | |
5626 | case DW_FORM_data4: | |
5627 | case DW_FORM_data8: | |
5628 | case DW_FORM_sdata: | |
5629 | case DW_FORM_udata: | |
5630 | case DW_FORM_block: | |
5631 | case DW_FORM_block1: | |
5632 | case DW_FORM_block2: | |
5633 | case DW_FORM_block4: | |
5634 | case DW_FORM_flag: | |
5635 | case DW_FORM_string: | |
5636 | case DW_FORM_strp: | |
5637 | case DW_FORM_sec_offset: | |
5638 | break; | |
5639 | default: | |
5640 | error (_("Invalid extension opcode form %s\n"), | |
5641 | get_FORM_name (form)); | |
5642 | return 0; | |
5643 | } | |
5644 | } | |
5645 | } | |
5646 | } | |
5647 | } | |
5648 | } | |
5649 | printf ("\n"); | |
5650 | ||
5651 | while (1) | |
5652 | { | |
5653 | unsigned int op; | |
5654 | ||
5655 | if (curr >= end) | |
5656 | { | |
5657 | error (_(".debug_macro section not zero terminated\n")); | |
5658 | return 0; | |
5659 | } | |
5660 | ||
0c588247 | 5661 | SAFE_BYTE_GET_AND_INC (op, curr, 1, end); |
4ccf1e31 JJ |
5662 | if (op == 0) |
5663 | break; | |
5664 | ||
5665 | switch (op) | |
5666 | { | |
7a7e1061 | 5667 | case DW_MACRO_start_file: |
4ccf1e31 JJ |
5668 | { |
5669 | unsigned int filenum; | |
5670 | unsigned char *file_name = NULL, *dir_name = NULL; | |
5671 | ||
f6f0e17b | 5672 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5673 | curr += bytes_read; |
f6f0e17b | 5674 | filenum = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 JJ |
5675 | curr += bytes_read; |
5676 | ||
5677 | if ((flags & 2) == 0) | |
7a7e1061 | 5678 | error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n")); |
4ccf1e31 JJ |
5679 | else |
5680 | file_name | |
5681 | = get_line_filename_and_dirname (line_offset, filenum, | |
5682 | &dir_name); | |
5683 | if (file_name == NULL) | |
7a7e1061 | 5684 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"), |
4ccf1e31 JJ |
5685 | lineno, filenum); |
5686 | else | |
7a7e1061 | 5687 | printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"), |
4ccf1e31 JJ |
5688 | lineno, filenum, |
5689 | dir_name != NULL ? (const char *) dir_name : "", | |
5690 | dir_name != NULL ? "/" : "", file_name); | |
5691 | } | |
5692 | break; | |
5693 | ||
7a7e1061 JK |
5694 | case DW_MACRO_end_file: |
5695 | printf (_(" DW_MACRO_end_file\n")); | |
4ccf1e31 JJ |
5696 | break; |
5697 | ||
7a7e1061 | 5698 | case DW_MACRO_define: |
f6f0e17b | 5699 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5700 | curr += bytes_read; |
0c588247 NC |
5701 | string = curr; |
5702 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 5703 | printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5704 | lineno, string); |
5705 | break; | |
5706 | ||
7a7e1061 | 5707 | case DW_MACRO_undef: |
f6f0e17b | 5708 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5709 | curr += bytes_read; |
0c588247 NC |
5710 | string = curr; |
5711 | curr += strnlen ((char *) string, end - string) + 1; | |
7a7e1061 | 5712 | printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5713 | lineno, string); |
5714 | break; | |
5715 | ||
7a7e1061 | 5716 | case DW_MACRO_define_strp: |
f6f0e17b | 5717 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5718 | curr += bytes_read; |
0c588247 | 5719 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5720 | string = fetch_indirect_string (offset); |
7a7e1061 | 5721 | printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5722 | lineno, string); |
5723 | break; | |
5724 | ||
7a7e1061 | 5725 | case DW_MACRO_undef_strp: |
f6f0e17b | 5726 | lineno = read_uleb128 (curr, &bytes_read, end); |
4ccf1e31 | 5727 | curr += bytes_read; |
0c588247 | 5728 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
4ccf1e31 | 5729 | string = fetch_indirect_string (offset); |
7a7e1061 | 5730 | printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"), |
4ccf1e31 JJ |
5731 | lineno, string); |
5732 | break; | |
5733 | ||
7a7e1061 | 5734 | case DW_MACRO_import: |
0c588247 | 5735 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5736 | printf (_(" DW_MACRO_import - offset : 0x%lx\n"), |
4ccf1e31 JJ |
5737 | (unsigned long) offset); |
5738 | break; | |
5739 | ||
7a7e1061 | 5740 | case DW_MACRO_define_sup: |
f6f0e17b | 5741 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 5742 | curr += bytes_read; |
0c588247 | 5743 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5744 | printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5745 | lineno, (unsigned long) offset); |
5746 | break; | |
5747 | ||
7a7e1061 | 5748 | case DW_MACRO_undef_sup: |
f6f0e17b | 5749 | lineno = read_uleb128 (curr, &bytes_read, end); |
a081f3cd | 5750 | curr += bytes_read; |
0c588247 | 5751 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5752 | printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"), |
a081f3cd JJ |
5753 | lineno, (unsigned long) offset); |
5754 | break; | |
5755 | ||
7a7e1061 | 5756 | case DW_MACRO_import_sup: |
0c588247 | 5757 | SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end); |
7a7e1061 | 5758 | printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"), |
a081f3cd JJ |
5759 | (unsigned long) offset); |
5760 | break; | |
5761 | ||
4ccf1e31 JJ |
5762 | default: |
5763 | if (extended_ops == NULL || extended_ops[op] == NULL) | |
5764 | { | |
5765 | error (_(" Unknown macro opcode %02x seen\n"), op); | |
5766 | return 0; | |
5767 | } | |
5768 | else | |
5769 | { | |
5770 | /* Skip over unhandled opcodes. */ | |
5771 | dwarf_vma nargs, n; | |
5772 | unsigned char *desc = extended_ops[op]; | |
f6f0e17b | 5773 | nargs = read_uleb128 (desc, &bytes_read, end); |
4ccf1e31 JJ |
5774 | desc += bytes_read; |
5775 | if (nargs == 0) | |
5776 | { | |
7a7e1061 | 5777 | printf (_(" DW_MACRO_%02x\n"), op); |
4ccf1e31 JJ |
5778 | break; |
5779 | } | |
7a7e1061 | 5780 | printf (_(" DW_MACRO_%02x -"), op); |
4ccf1e31 JJ |
5781 | for (n = 0; n < nargs; n++) |
5782 | { | |
0c588247 NC |
5783 | int val; |
5784 | ||
77145576 | 5785 | /* DW_FORM_implicit_const is not expected here. */ |
0c588247 | 5786 | SAFE_BYTE_GET_AND_INC (val, desc, 1, end); |
4ccf1e31 | 5787 | curr |
77145576 | 5788 | = read_and_display_attr_value (0, val, 0, |
ec1b0fbb | 5789 | start, curr, end, 0, 0, offset_size, |
341f9135 | 5790 | version, NULL, 0, NULL, |
ec1b0fbb | 5791 | NULL, ' ', -1); |
4ccf1e31 JJ |
5792 | if (n != nargs - 1) |
5793 | printf (","); | |
5794 | } | |
5795 | printf ("\n"); | |
5796 | } | |
5797 | break; | |
5798 | } | |
5799 | } | |
5800 | ||
5801 | printf ("\n"); | |
b4eb7656 | 5802 | } |
4ccf1e31 JJ |
5803 | |
5804 | return 1; | |
5805 | } | |
5806 | ||
19e6b90e L |
5807 | static int |
5808 | display_debug_abbrev (struct dwarf_section *section, | |
5809 | void *file ATTRIBUTE_UNUSED) | |
5810 | { | |
5811 | abbrev_entry *entry; | |
5812 | unsigned char *start = section->start; | |
5813 | unsigned char *end = start + section->size; | |
5814 | ||
dda8d76d | 5815 | introduce (section, FALSE); |
19e6b90e L |
5816 | |
5817 | do | |
5818 | { | |
7282333f AM |
5819 | unsigned char *last; |
5820 | ||
19e6b90e L |
5821 | free_abbrevs (); |
5822 | ||
7282333f | 5823 | last = start; |
19e6b90e L |
5824 | start = process_abbrev_section (start, end); |
5825 | ||
5826 | if (first_abbrev == NULL) | |
5827 | continue; | |
5828 | ||
7282333f | 5829 | printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start)); |
19e6b90e L |
5830 | |
5831 | for (entry = first_abbrev; entry; entry = entry->next) | |
5832 | { | |
5833 | abbrev_attr *attr; | |
5834 | ||
cc5914eb | 5835 | printf (" %ld %s [%s]\n", |
19e6b90e L |
5836 | entry->entry, |
5837 | get_TAG_name (entry->tag), | |
5838 | entry->children ? _("has children") : _("no children")); | |
5839 | ||
5840 | for (attr = entry->first_attr; attr; attr = attr->next) | |
77145576 JK |
5841 | { |
5842 | printf (" %-18s %s", | |
5843 | get_AT_name (attr->attribute), | |
5844 | get_FORM_name (attr->form)); | |
5845 | if (attr->form == DW_FORM_implicit_const) | |
5846 | printf (": %" BFD_VMA_FMT "d", attr->implicit_const); | |
5847 | putchar ('\n'); | |
5848 | } | |
19e6b90e L |
5849 | } |
5850 | } | |
5851 | while (start); | |
5852 | ||
5853 | printf ("\n"); | |
5854 | ||
5855 | return 1; | |
5856 | } | |
5857 | ||
42bcef4a AB |
5858 | /* Return true when ADDR is the maximum address, when addresses are |
5859 | POINTER_SIZE bytes long. */ | |
5860 | ||
5861 | static bfd_boolean | |
5862 | is_max_address (dwarf_vma addr, unsigned int pointer_size) | |
5863 | { | |
5864 | dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1)); | |
5865 | return ((addr & mask) == mask); | |
5866 | } | |
5867 | ||
9f272209 AO |
5868 | /* Display a view pair list starting at *VSTART_PTR and ending at |
5869 | VLISTEND within SECTION. */ | |
5870 | ||
5871 | static void | |
5872 | display_view_pair_list (struct dwarf_section *section, | |
5873 | unsigned char **vstart_ptr, | |
5874 | unsigned int debug_info_entry, | |
5875 | unsigned char *vlistend) | |
5876 | { | |
5877 | unsigned char *vstart = *vstart_ptr; | |
5878 | unsigned char *section_end = section->start + section->size; | |
5879 | unsigned int pointer_size = debug_information [debug_info_entry].pointer_size; | |
5880 | ||
5881 | if (vlistend < section_end) | |
5882 | section_end = vlistend; | |
5883 | ||
5884 | putchar ('\n'); | |
5885 | ||
5886 | while (vstart < section_end) | |
5887 | { | |
5888 | dwarf_vma off = vstart - section->start; | |
5889 | dwarf_vma vbegin, vend; | |
5890 | ||
5891 | unsigned int bytes_read; | |
5892 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
5893 | vstart += bytes_read; | |
5894 | if (vstart == section_end) | |
5895 | { | |
5896 | vstart -= bytes_read; | |
5897 | break; | |
5898 | } | |
5899 | ||
5900 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
5901 | vstart += bytes_read; | |
5902 | ||
5903 | printf (" %8.8lx ", (unsigned long) off); | |
5904 | ||
5905 | print_dwarf_view (vbegin, pointer_size, 1); | |
5906 | print_dwarf_view (vend, pointer_size, 1); | |
5907 | printf (_("location view pair\n")); | |
5908 | } | |
5909 | ||
5910 | putchar ('\n'); | |
5911 | *vstart_ptr = vstart; | |
5912 | } | |
5913 | ||
4723351a CC |
5914 | /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */ |
5915 | ||
5916 | static void | |
5917 | display_loc_list (struct dwarf_section *section, | |
b4eb7656 AM |
5918 | unsigned char **start_ptr, |
5919 | unsigned int debug_info_entry, | |
359ca075 JK |
5920 | dwarf_vma offset, |
5921 | dwarf_vma base_address, | |
9f272209 | 5922 | unsigned char **vstart_ptr, |
b4eb7656 | 5923 | int has_frame_base) |
4723351a | 5924 | { |
9f272209 | 5925 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 5926 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
5927 | unsigned long cu_offset; |
5928 | unsigned int pointer_size; | |
5929 | unsigned int offset_size; | |
5930 | int dwarf_version; | |
4723351a CC |
5931 | |
5932 | dwarf_vma begin; | |
5933 | dwarf_vma end; | |
5934 | unsigned short length; | |
5935 | int need_frame_base; | |
5936 | ||
82b1b41b NC |
5937 | if (debug_info_entry >= num_debug_info_entries) |
5938 | { | |
5939 | warn (_("No debug information available for loc lists of entry: %u\n"), | |
5940 | debug_info_entry); | |
5941 | return; | |
5942 | } | |
b4eb7656 | 5943 | |
82b1b41b NC |
5944 | cu_offset = debug_information [debug_info_entry].cu_offset; |
5945 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
5946 | offset_size = debug_information [debug_info_entry].offset_size; | |
5947 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
b4eb7656 | 5948 | |
f41e4712 NC |
5949 | if (pointer_size < 2 || pointer_size > 8) |
5950 | { | |
5951 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
5952 | pointer_size, debug_info_entry); | |
5953 | return; | |
5954 | } | |
5955 | ||
4723351a CC |
5956 | while (1) |
5957 | { | |
359ca075 | 5958 | dwarf_vma off = offset + (start - *start_ptr); |
9f272209 | 5959 | dwarf_vma vbegin = vm1, vend = vm1; |
d1c4b12b | 5960 | |
4723351a | 5961 | if (start + 2 * pointer_size > section_end) |
b4eb7656 AM |
5962 | { |
5963 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 5964 | (unsigned long) offset); |
b4eb7656 AM |
5965 | break; |
5966 | } | |
4723351a | 5967 | |
359ca075 | 5968 | printf (" %8.8lx ", (unsigned long) off); |
fab128ef | 5969 | |
0c588247 NC |
5970 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end); |
5971 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end); | |
4723351a | 5972 | |
4723351a | 5973 | if (begin == 0 && end == 0) |
b4eb7656 | 5974 | { |
d1c4b12b NC |
5975 | /* PR 18374: In a object file we can have a location list that |
5976 | starts with a begin and end of 0 because there are relocations | |
5977 | that need to be applied to the addresses. Actually applying | |
5978 | the relocations now does not help as they will probably resolve | |
5979 | to 0, since the object file has not been fully linked. Real | |
5980 | end of list markers will not have any relocations against them. */ | |
5981 | if (! reloc_at (section, off) | |
5982 | && ! reloc_at (section, off + pointer_size)) | |
5983 | { | |
5984 | printf (_("<End of list>\n")); | |
5985 | break; | |
5986 | } | |
b4eb7656 | 5987 | } |
4723351a CC |
5988 | |
5989 | /* Check base address specifiers. */ | |
42bcef4a AB |
5990 | if (is_max_address (begin, pointer_size) |
5991 | && !is_max_address (end, pointer_size)) | |
b4eb7656 AM |
5992 | { |
5993 | base_address = end; | |
5994 | print_dwarf_vma (begin, pointer_size); | |
5995 | print_dwarf_vma (end, pointer_size); | |
5996 | printf (_("(base address)\n")); | |
5997 | continue; | |
5998 | } | |
4723351a | 5999 | |
9f272209 AO |
6000 | if (vstart) |
6001 | { | |
6002 | unsigned int bytes_read; | |
6003 | ||
6004 | off = offset + (vstart - *start_ptr); | |
6005 | ||
6006 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
6007 | vstart += bytes_read; | |
6008 | print_dwarf_view (vbegin, pointer_size, 1); | |
6009 | ||
6010 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
6011 | vstart += bytes_read; | |
6012 | print_dwarf_view (vend, pointer_size, 1); | |
6013 | ||
6014 | printf (_("views at %8.8lx for:\n %*s "), | |
6015 | (unsigned long) off, 8, ""); | |
6016 | } | |
6017 | ||
4723351a | 6018 | if (start + 2 > section_end) |
b4eb7656 AM |
6019 | { |
6020 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6021 | (unsigned long) offset); |
b4eb7656 AM |
6022 | break; |
6023 | } | |
4723351a | 6024 | |
0c588247 | 6025 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a CC |
6026 | |
6027 | if (start + length > section_end) | |
b4eb7656 AM |
6028 | { |
6029 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6030 | (unsigned long) offset); |
b4eb7656 AM |
6031 | break; |
6032 | } | |
4723351a CC |
6033 | |
6034 | print_dwarf_vma (begin + base_address, pointer_size); | |
6035 | print_dwarf_vma (end + base_address, pointer_size); | |
6036 | ||
6037 | putchar ('('); | |
6038 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6039 | pointer_size, |
6040 | offset_size, | |
6041 | dwarf_version, | |
6042 | length, | |
6043 | cu_offset, section); | |
4723351a CC |
6044 | putchar (')'); |
6045 | ||
6046 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6047 | printf (_(" [without DW_AT_frame_base]")); |
4723351a | 6048 | |
9f272209 | 6049 | if (begin == end && vbegin == vend) |
b4eb7656 | 6050 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6051 | else if (begin > end || (begin == end && vbegin > vend)) |
b4eb7656 | 6052 | fputs (_(" (start > end)"), stdout); |
4723351a CC |
6053 | |
6054 | putchar ('\n'); | |
6055 | ||
6056 | start += length; | |
6057 | } | |
6058 | ||
6059 | *start_ptr = start; | |
9f272209 | 6060 | *vstart_ptr = vstart; |
4723351a CC |
6061 | } |
6062 | ||
77145576 JK |
6063 | /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */ |
6064 | ||
6065 | static void | |
6066 | display_loclists_list (struct dwarf_section *section, | |
6067 | unsigned char **start_ptr, | |
6068 | unsigned int debug_info_entry, | |
6069 | dwarf_vma offset, | |
6070 | dwarf_vma base_address, | |
9f272209 | 6071 | unsigned char **vstart_ptr, |
77145576 JK |
6072 | int has_frame_base) |
6073 | { | |
9f272209 | 6074 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
77145576 JK |
6075 | unsigned char *section_end = section->start + section->size; |
6076 | unsigned long cu_offset; | |
6077 | unsigned int pointer_size; | |
6078 | unsigned int offset_size; | |
6079 | int dwarf_version; | |
6080 | unsigned int bytes_read; | |
6081 | ||
9dfd0db9 | 6082 | /* Initialize it due to a false compiler warning. */ |
9f272209 AO |
6083 | dwarf_vma begin = -1, vbegin = -1; |
6084 | dwarf_vma end = -1, vend = -1; | |
77145576 JK |
6085 | dwarf_vma length; |
6086 | int need_frame_base; | |
6087 | ||
6088 | if (debug_info_entry >= num_debug_info_entries) | |
6089 | { | |
6090 | warn (_("No debug information available for " | |
6091 | "loclists lists of entry: %u\n"), | |
6092 | debug_info_entry); | |
6093 | return; | |
6094 | } | |
6095 | ||
6096 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6097 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6098 | offset_size = debug_information [debug_info_entry].offset_size; | |
6099 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6100 | ||
6101 | if (pointer_size < 2 || pointer_size > 8) | |
6102 | { | |
6103 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6104 | pointer_size, debug_info_entry); | |
6105 | return; | |
6106 | } | |
6107 | ||
6108 | while (1) | |
6109 | { | |
6110 | dwarf_vma off = offset + (start - *start_ptr); | |
6111 | enum dwarf_location_list_entry_type llet; | |
6112 | ||
6113 | if (start + 1 > section_end) | |
6114 | { | |
6115 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6116 | (unsigned long) offset); | |
6117 | break; | |
6118 | } | |
6119 | ||
6120 | printf (" %8.8lx ", (unsigned long) off); | |
6121 | ||
6122 | SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end); | |
6123 | ||
9f272209 AO |
6124 | if (vstart && llet == DW_LLE_offset_pair) |
6125 | { | |
6126 | off = offset + (vstart - *start_ptr); | |
6127 | ||
6128 | vbegin = read_uleb128 (vstart, &bytes_read, section_end); | |
6129 | vstart += bytes_read; | |
6130 | print_dwarf_view (vbegin, pointer_size, 1); | |
6131 | ||
6132 | vend = read_uleb128 (vstart, &bytes_read, section_end); | |
6133 | vstart += bytes_read; | |
6134 | print_dwarf_view (vend, pointer_size, 1); | |
6135 | ||
6136 | printf (_("views at %8.8lx for:\n %*s "), | |
6137 | (unsigned long) off, 8, ""); | |
6138 | } | |
6139 | ||
77145576 JK |
6140 | switch (llet) |
6141 | { | |
6142 | case DW_LLE_end_of_list: | |
6143 | printf (_("<End of list>\n")); | |
6144 | break; | |
6145 | case DW_LLE_offset_pair: | |
6146 | begin = read_uleb128 (start, &bytes_read, section_end); | |
6147 | start += bytes_read; | |
6148 | end = read_uleb128 (start, &bytes_read, section_end); | |
6149 | start += bytes_read; | |
6150 | break; | |
6151 | case DW_LLE_base_address: | |
6152 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, | |
6153 | section_end); | |
6154 | print_dwarf_vma (base_address, pointer_size); | |
6155 | printf (_("(base address)\n")); | |
6156 | break; | |
9f272209 AO |
6157 | #ifdef DW_LLE_view_pair |
6158 | case DW_LLE_view_pair: | |
6159 | if (vstart) | |
6160 | printf (_("View pair entry in loclist with locviews attribute\n")); | |
6161 | vbegin = read_uleb128 (start, &bytes_read, section_end); | |
6162 | start += bytes_read; | |
6163 | print_dwarf_view (vbegin, pointer_size, 1); | |
6164 | ||
6165 | vend = read_uleb128 (start, &bytes_read, section_end); | |
6166 | start += bytes_read; | |
6167 | print_dwarf_view (vend, pointer_size, 1); | |
6168 | ||
6169 | printf (_("views for:\n")); | |
6170 | continue; | |
6171 | #endif | |
77145576 JK |
6172 | default: |
6173 | error (_("Invalid location list entry type %d\n"), llet); | |
6174 | return; | |
6175 | } | |
6176 | if (llet == DW_LLE_end_of_list) | |
6177 | break; | |
6178 | if (llet != DW_LLE_offset_pair) | |
6179 | continue; | |
6180 | ||
6181 | if (start + 2 > section_end) | |
6182 | { | |
6183 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
6184 | (unsigned long) offset); | |
6185 | break; | |
6186 | } | |
6187 | ||
6188 | length = read_uleb128 (start, &bytes_read, section_end); | |
6189 | start += bytes_read; | |
6190 | ||
6191 | print_dwarf_vma (begin + base_address, pointer_size); | |
6192 | print_dwarf_vma (end + base_address, pointer_size); | |
6193 | ||
6194 | putchar ('('); | |
6195 | need_frame_base = decode_location_expression (start, | |
6196 | pointer_size, | |
6197 | offset_size, | |
6198 | dwarf_version, | |
6199 | length, | |
6200 | cu_offset, section); | |
6201 | putchar (')'); | |
6202 | ||
6203 | if (need_frame_base && !has_frame_base) | |
6204 | printf (_(" [without DW_AT_frame_base]")); | |
6205 | ||
9f272209 | 6206 | if (begin == end && vbegin == vend) |
77145576 | 6207 | fputs (_(" (start == end)"), stdout); |
9f272209 | 6208 | else if (begin > end || (begin == end && vbegin > vend)) |
77145576 JK |
6209 | fputs (_(" (start > end)"), stdout); |
6210 | ||
6211 | putchar ('\n'); | |
6212 | ||
6213 | start += length; | |
9f272209 | 6214 | vbegin = vend = -1; |
77145576 JK |
6215 | } |
6216 | ||
9f272209 AO |
6217 | if (vbegin != vm1 || vend != vm1) |
6218 | printf (_("Trailing view pair not used in a range")); | |
6219 | ||
77145576 | 6220 | *start_ptr = start; |
9f272209 | 6221 | *vstart_ptr = vstart; |
77145576 JK |
6222 | } |
6223 | ||
fab128ef CC |
6224 | /* Print a .debug_addr table index in decimal, surrounded by square brackets, |
6225 | right-adjusted in a field of length LEN, and followed by a space. */ | |
6226 | ||
6227 | static void | |
6228 | print_addr_index (unsigned int idx, unsigned int len) | |
6229 | { | |
6230 | static char buf[15]; | |
6231 | snprintf (buf, sizeof (buf), "[%d]", idx); | |
341f9135 | 6232 | printf ("%*s ", len, buf); |
fab128ef CC |
6233 | } |
6234 | ||
4723351a CC |
6235 | /* Display a location list from a .dwo section. It uses address indexes rather |
6236 | than embedded addresses. This code closely follows display_loc_list, but the | |
6237 | two are sufficiently different that combining things is very ugly. */ | |
6238 | ||
6239 | static void | |
6240 | display_loc_list_dwo (struct dwarf_section *section, | |
b4eb7656 AM |
6241 | unsigned char **start_ptr, |
6242 | unsigned int debug_info_entry, | |
359ca075 | 6243 | dwarf_vma offset, |
9f272209 | 6244 | unsigned char **vstart_ptr, |
b4eb7656 | 6245 | int has_frame_base) |
4723351a | 6246 | { |
9f272209 | 6247 | unsigned char *start = *start_ptr, *vstart = *vstart_ptr; |
4723351a | 6248 | unsigned char *section_end = section->start + section->size; |
82b1b41b NC |
6249 | unsigned long cu_offset; |
6250 | unsigned int pointer_size; | |
6251 | unsigned int offset_size; | |
6252 | int dwarf_version; | |
4723351a CC |
6253 | int entry_type; |
6254 | unsigned short length; | |
6255 | int need_frame_base; | |
fab128ef | 6256 | unsigned int idx; |
4723351a CC |
6257 | unsigned int bytes_read; |
6258 | ||
82b1b41b NC |
6259 | if (debug_info_entry >= num_debug_info_entries) |
6260 | { | |
6261 | warn (_("No debug information for loc lists of entry: %u\n"), | |
6262 | debug_info_entry); | |
6263 | return; | |
6264 | } | |
6265 | ||
6266 | cu_offset = debug_information [debug_info_entry].cu_offset; | |
6267 | pointer_size = debug_information [debug_info_entry].pointer_size; | |
6268 | offset_size = debug_information [debug_info_entry].offset_size; | |
6269 | dwarf_version = debug_information [debug_info_entry].dwarf_version; | |
6270 | ||
f41e4712 NC |
6271 | if (pointer_size < 2 || pointer_size > 8) |
6272 | { | |
6273 | warn (_("Invalid pointer size (%d) in debug info for entry %d\n"), | |
6274 | pointer_size, debug_info_entry); | |
6275 | return; | |
6276 | } | |
6277 | ||
4723351a CC |
6278 | while (1) |
6279 | { | |
359ca075 | 6280 | printf (" %8.8lx ", (unsigned long) (offset + (start - *start_ptr))); |
4723351a | 6281 | |
fab128ef | 6282 | if (start >= section_end) |
b4eb7656 AM |
6283 | { |
6284 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6285 | (unsigned long) offset); |
b4eb7656 AM |
6286 | break; |
6287 | } | |
4723351a | 6288 | |
0c588247 | 6289 | SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end); |
9f272209 AO |
6290 | |
6291 | if (vstart) | |
6292 | switch (entry_type) | |
6293 | { | |
6294 | default: | |
6295 | break; | |
6296 | ||
6297 | case 2: | |
6298 | case 3: | |
6299 | case 4: | |
6300 | { | |
6301 | dwarf_vma view; | |
6302 | dwarf_vma off = offset + (vstart - *start_ptr); | |
6303 | ||
6304 | view = read_uleb128 (vstart, &bytes_read, section_end); | |
6305 | vstart += bytes_read; | |
6306 | print_dwarf_view (view, 8, 1); | |
6307 | ||
6308 | view = read_uleb128 (vstart, &bytes_read, section_end); | |
6309 | vstart += bytes_read; | |
6310 | print_dwarf_view (view, 8, 1); | |
6311 | ||
6312 | printf (_("views at %8.8lx for:\n %*s "), | |
6313 | (unsigned long) off, 8, ""); | |
6314 | ||
6315 | } | |
6316 | break; | |
6317 | } | |
6318 | ||
4723351a | 6319 | switch (entry_type) |
b4eb7656 AM |
6320 | { |
6321 | case 0: /* A terminating entry. */ | |
6322 | *start_ptr = start; | |
9f272209 | 6323 | *vstart_ptr = vstart; |
b4eb7656 AM |
6324 | printf (_("<End of list>\n")); |
6325 | return; | |
6326 | case 1: /* A base-address entry. */ | |
6327 | idx = read_uleb128 (start, &bytes_read, section_end); | |
6328 | start += bytes_read; | |
6329 | print_addr_index (idx, 8); | |
9f272209 | 6330 | printf ("%*s", 9 + (vstart ? 2 * 6 : 0), ""); |
b4eb7656 AM |
6331 | printf (_("(base address selection entry)\n")); |
6332 | continue; | |
6333 | case 2: /* A start/end entry. */ | |
6334 | idx = read_uleb128 (start, &bytes_read, section_end); | |
6335 | start += bytes_read; | |
6336 | print_addr_index (idx, 8); | |
6337 | idx = read_uleb128 (start, &bytes_read, section_end); | |
6338 | start += bytes_read; | |
6339 | print_addr_index (idx, 8); | |
6340 | break; | |
6341 | case 3: /* A start/length entry. */ | |
6342 | idx = read_uleb128 (start, &bytes_read, section_end); | |
6343 | start += bytes_read; | |
6344 | print_addr_index (idx, 8); | |
6345 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6346 | printf ("%08x ", idx); | |
6347 | break; | |
6348 | case 4: /* An offset pair entry. */ | |
6349 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6350 | printf ("%08x ", idx); | |
6351 | SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end); | |
6352 | printf ("%08x ", idx); | |
6353 | break; | |
6354 | default: | |
6355 | warn (_("Unknown location list entry type 0x%x.\n"), entry_type); | |
6356 | *start_ptr = start; | |
9f272209 | 6357 | *vstart_ptr = vstart; |
b4eb7656 AM |
6358 | return; |
6359 | } | |
4723351a CC |
6360 | |
6361 | if (start + 2 > section_end) | |
b4eb7656 AM |
6362 | { |
6363 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6364 | (unsigned long) offset); |
b4eb7656 AM |
6365 | break; |
6366 | } | |
4723351a | 6367 | |
0c588247 | 6368 | SAFE_BYTE_GET_AND_INC (length, start, 2, section_end); |
4723351a | 6369 | if (start + length > section_end) |
b4eb7656 AM |
6370 | { |
6371 | warn (_("Location list starting at offset 0x%lx is not terminated.\n"), | |
359ca075 | 6372 | (unsigned long) offset); |
b4eb7656 AM |
6373 | break; |
6374 | } | |
4723351a CC |
6375 | |
6376 | putchar ('('); | |
6377 | need_frame_base = decode_location_expression (start, | |
b4eb7656 AM |
6378 | pointer_size, |
6379 | offset_size, | |
6380 | dwarf_version, | |
6381 | length, | |
6382 | cu_offset, section); | |
4723351a CC |
6383 | putchar (')'); |
6384 | ||
6385 | if (need_frame_base && !has_frame_base) | |
b4eb7656 | 6386 | printf (_(" [without DW_AT_frame_base]")); |
4723351a CC |
6387 | |
6388 | putchar ('\n'); | |
6389 | ||
6390 | start += length; | |
6391 | } | |
6392 | ||
6393 | *start_ptr = start; | |
9f272209 | 6394 | *vstart_ptr = vstart; |
4723351a CC |
6395 | } |
6396 | ||
9f272209 AO |
6397 | /* Sort array of indexes in ascending order of loc_offsets[idx] and |
6398 | loc_views. */ | |
51d0d03f | 6399 | |
9f272209 | 6400 | static dwarf_vma *loc_offsets, *loc_views; |
51d0d03f JJ |
6401 | |
6402 | static int | |
6403 | loc_offsets_compar (const void *ap, const void *bp) | |
6404 | { | |
6405 | dwarf_vma a = loc_offsets[*(const unsigned int *) ap]; | |
6406 | dwarf_vma b = loc_offsets[*(const unsigned int *) bp]; | |
6407 | ||
9f272209 AO |
6408 | int ret = (a > b) - (b > a); |
6409 | if (ret) | |
6410 | return ret; | |
6411 | ||
6412 | a = loc_views[*(const unsigned int *) ap]; | |
6413 | b = loc_views[*(const unsigned int *) bp]; | |
6414 | ||
6415 | ret = (a > b) - (b > a); | |
6416 | ||
6417 | return ret; | |
51d0d03f JJ |
6418 | } |
6419 | ||
19e6b90e L |
6420 | static int |
6421 | display_debug_loc (struct dwarf_section *section, void *file) | |
6422 | { | |
9f272209 | 6423 | unsigned char *start = section->start, *vstart = NULL; |
19e6b90e L |
6424 | unsigned long bytes; |
6425 | unsigned char *section_begin = start; | |
6426 | unsigned int num_loc_list = 0; | |
6427 | unsigned long last_offset = 0; | |
9f272209 | 6428 | unsigned long last_view = 0; |
19e6b90e L |
6429 | unsigned int first = 0; |
6430 | unsigned int i; | |
6431 | unsigned int j; | |
6432 | int seen_first_offset = 0; | |
51d0d03f | 6433 | int locs_sorted = 1; |
9f272209 | 6434 | unsigned char *next = start, *vnext = vstart; |
51d0d03f | 6435 | unsigned int *array = NULL; |
4723351a | 6436 | const char *suffix = strrchr (section->name, '.'); |
24841daa | 6437 | bfd_boolean is_dwo = FALSE; |
77145576 JK |
6438 | int is_loclists = strstr (section->name, "debug_loclists") != NULL; |
6439 | dwarf_vma expected_start = 0; | |
4723351a CC |
6440 | |
6441 | if (suffix && strcmp (suffix, ".dwo") == 0) | |
24841daa | 6442 | is_dwo = TRUE; |
19e6b90e L |
6443 | |
6444 | bytes = section->size; | |
19e6b90e L |
6445 | |
6446 | if (bytes == 0) | |
6447 | { | |
6448 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6449 | return 0; | |
6450 | } | |
6451 | ||
77145576 JK |
6452 | if (is_loclists) |
6453 | { | |
6454 | unsigned char *hdrptr = section_begin; | |
6455 | dwarf_vma ll_length; | |
6456 | unsigned short ll_version; | |
6457 | unsigned char *end = section_begin + section->size; | |
6458 | unsigned char address_size, segment_selector_size; | |
6459 | uint32_t offset_entry_count; | |
6460 | ||
6461 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end); | |
6462 | if (ll_length == 0xffffffff) | |
6463 | SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end); | |
6464 | ||
6465 | SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end); | |
6466 | if (ll_version != 5) | |
6467 | { | |
6468 | warn (_("The %s section contains corrupt or " | |
6469 | "unsupported version number: %d.\n"), | |
6470 | section->name, ll_version); | |
6471 | return 0; | |
6472 | } | |
6473 | ||
6474 | SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end); | |
6475 | ||
6476 | SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end); | |
6477 | if (segment_selector_size != 0) | |
6478 | { | |
6479 | warn (_("The %s section contains " | |
6480 | "unsupported segment selector size: %d.\n"), | |
6481 | section->name, segment_selector_size); | |
6482 | return 0; | |
6483 | } | |
6484 | ||
6485 | SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end); | |
6486 | if (offset_entry_count != 0) | |
6487 | { | |
6488 | warn (_("The %s section contains " | |
6489 | "unsupported offset entry count: %d.\n"), | |
6490 | section->name, offset_entry_count); | |
6491 | return 0; | |
6492 | } | |
6493 | ||
6494 | expected_start = hdrptr - section_begin; | |
6495 | } | |
6496 | ||
1febe64d NC |
6497 | if (load_debug_info (file) == 0) |
6498 | { | |
6499 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6500 | section->name); | |
6501 | return 0; | |
6502 | } | |
19e6b90e L |
6503 | |
6504 | /* Check the order of location list in .debug_info section. If | |
6505 | offsets of location lists are in the ascending order, we can | |
6506 | use `debug_information' directly. */ | |
6507 | for (i = 0; i < num_debug_info_entries; i++) | |
6508 | { | |
6509 | unsigned int num; | |
6510 | ||
6511 | num = debug_information [i].num_loc_offsets; | |
51d0d03f JJ |
6512 | if (num > num_loc_list) |
6513 | num_loc_list = num; | |
19e6b90e L |
6514 | |
6515 | /* Check if we can use `debug_information' directly. */ | |
51d0d03f | 6516 | if (locs_sorted && num != 0) |
19e6b90e L |
6517 | { |
6518 | if (!seen_first_offset) | |
6519 | { | |
6520 | /* This is the first location list. */ | |
6521 | last_offset = debug_information [i].loc_offsets [0]; | |
9f272209 | 6522 | last_view = debug_information [i].loc_views [0]; |
19e6b90e L |
6523 | first = i; |
6524 | seen_first_offset = 1; | |
6525 | j = 1; | |
6526 | } | |
6527 | else | |
6528 | j = 0; | |
6529 | ||
6530 | for (; j < num; j++) | |
6531 | { | |
6532 | if (last_offset > | |
9f272209 AO |
6533 | debug_information [i].loc_offsets [j] |
6534 | || (last_offset == debug_information [i].loc_offsets [j] | |
6535 | && last_view > debug_information [i].loc_views [j])) | |
19e6b90e | 6536 | { |
51d0d03f | 6537 | locs_sorted = 0; |
19e6b90e L |
6538 | break; |
6539 | } | |
6540 | last_offset = debug_information [i].loc_offsets [j]; | |
9f272209 | 6541 | last_view = debug_information [i].loc_views [j]; |
19e6b90e L |
6542 | } |
6543 | } | |
6544 | } | |
6545 | ||
19e6b90e L |
6546 | if (!seen_first_offset) |
6547 | error (_("No location lists in .debug_info section!\n")); | |
6548 | ||
d4bfc77b | 6549 | if (debug_information [first].num_loc_offsets > 0 |
9f272209 AO |
6550 | && debug_information [first].loc_offsets [0] != expected_start |
6551 | && debug_information [first].loc_views [0] != expected_start) | |
47704ddf KT |
6552 | warn (_("Location lists in %s section start at 0x%s\n"), |
6553 | section->name, | |
6554 | dwarf_vmatoa ("x", debug_information [first].loc_offsets [0])); | |
19e6b90e | 6555 | |
51d0d03f JJ |
6556 | if (!locs_sorted) |
6557 | array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int)); | |
dda8d76d NC |
6558 | |
6559 | introduce (section, FALSE); | |
6560 | ||
d1c4b12b NC |
6561 | if (reloc_at (section, 0)) |
6562 | printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n")); | |
dda8d76d | 6563 | |
d1c4b12b | 6564 | printf (_(" Offset Begin End Expression\n")); |
19e6b90e L |
6565 | |
6566 | seen_first_offset = 0; | |
6567 | for (i = first; i < num_debug_info_entries; i++) | |
6568 | { | |
9f272209 | 6569 | dwarf_vma offset, voffset; |
359ca075 | 6570 | dwarf_vma base_address; |
d1c4b12b | 6571 | unsigned int k; |
19e6b90e L |
6572 | int has_frame_base; |
6573 | ||
51d0d03f JJ |
6574 | if (!locs_sorted) |
6575 | { | |
6576 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) | |
6577 | array[k] = k; | |
6578 | loc_offsets = debug_information [i].loc_offsets; | |
9f272209 | 6579 | loc_views = debug_information [i].loc_views; |
51d0d03f JJ |
6580 | qsort (array, debug_information [i].num_loc_offsets, |
6581 | sizeof (*array), loc_offsets_compar); | |
6582 | } | |
19e6b90e | 6583 | |
9f272209 | 6584 | int adjacent_view_loclists = 1; |
51d0d03f | 6585 | for (k = 0; k < debug_information [i].num_loc_offsets; k++) |
19e6b90e | 6586 | { |
51d0d03f JJ |
6587 | j = locs_sorted ? k : array[k]; |
6588 | if (k | |
9f272209 | 6589 | && (debug_information [i].loc_offsets [locs_sorted |
51d0d03f | 6590 | ? k - 1 : array [k - 1]] |
9f272209 AO |
6591 | == debug_information [i].loc_offsets [j]) |
6592 | && (debug_information [i].loc_views [locs_sorted | |
6593 | ? k - 1 : array [k - 1]] | |
6594 | == debug_information [i].loc_views [j])) | |
51d0d03f | 6595 | continue; |
19e6b90e | 6596 | has_frame_base = debug_information [i].have_frame_base [j]; |
d493b283 | 6597 | offset = debug_information [i].loc_offsets [j]; |
19e6b90e | 6598 | next = section_begin + offset; |
9f272209 AO |
6599 | voffset = debug_information [i].loc_views [j]; |
6600 | if (voffset != vm1) | |
6601 | vnext = section_begin + voffset; | |
6602 | else | |
6603 | vnext = NULL; | |
19e6b90e L |
6604 | base_address = debug_information [i].base_address; |
6605 | ||
9f272209 AO |
6606 | if (vnext && vnext < next) |
6607 | { | |
6608 | vstart = vnext; | |
6609 | display_view_pair_list (section, &vstart, i, next); | |
6610 | if (start == vnext) | |
6611 | start = vstart; | |
6612 | } | |
6613 | ||
6614 | if (!seen_first_offset || !adjacent_view_loclists) | |
19e6b90e L |
6615 | seen_first_offset = 1; |
6616 | else | |
6617 | { | |
6618 | if (start < next) | |
6619 | warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6620 | (unsigned long) (start - section_begin), |
c8071705 | 6621 | (unsigned long) offset); |
19e6b90e L |
6622 | else if (start > next) |
6623 | warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"), | |
0af1713e | 6624 | (unsigned long) (start - section_begin), |
c8071705 | 6625 | (unsigned long) offset); |
19e6b90e L |
6626 | } |
6627 | start = next; | |
9f272209 | 6628 | vstart = vnext; |
19e6b90e L |
6629 | |
6630 | if (offset >= bytes) | |
6631 | { | |
6632 | warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
359ca075 | 6633 | (unsigned long) offset); |
19e6b90e L |
6634 | continue; |
6635 | } | |
6636 | ||
9f272209 AO |
6637 | if (vnext && voffset >= bytes) |
6638 | { | |
6639 | warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"), | |
6640 | (unsigned long) voffset); | |
6641 | continue; | |
6642 | } | |
6643 | ||
77145576 JK |
6644 | if (!is_loclists) |
6645 | { | |
6646 | if (is_dwo) | |
6647 | display_loc_list_dwo (section, &start, i, offset, | |
9f272209 | 6648 | &vstart, has_frame_base); |
77145576 JK |
6649 | else |
6650 | display_loc_list (section, &start, i, offset, base_address, | |
9f272209 | 6651 | &vstart, has_frame_base); |
77145576 | 6652 | } |
b4eb7656 | 6653 | else |
77145576 JK |
6654 | { |
6655 | if (is_dwo) | |
6656 | warn (_("DWO is not yet supported.\n")); | |
6657 | else | |
6658 | display_loclists_list (section, &start, i, offset, base_address, | |
9f272209 AO |
6659 | &vstart, has_frame_base); |
6660 | } | |
6661 | ||
6662 | /* FIXME: this arrangement is quite simplistic. Nothing | |
6663 | requires locview lists to be adjacent to corresponding | |
6664 | loclists, and a single loclist could be augmented by | |
6665 | different locview lists, and vice-versa, unlikely as it | |
6666 | is that it would make sense to do so. Hopefully we'll | |
6667 | have view pair support built into loclists before we ever | |
6668 | need to address all these possibilities. */ | |
6669 | if (adjacent_view_loclists && vnext | |
6670 | && vnext != start && vstart != next) | |
6671 | { | |
6672 | adjacent_view_loclists = 0; | |
6673 | warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n")); | |
77145576 | 6674 | } |
9f272209 AO |
6675 | |
6676 | if (vnext && vnext == start) | |
6677 | display_view_pair_list (section, &start, i, vstart); | |
19e6b90e L |
6678 | } |
6679 | } | |
031cd65f | 6680 | |
4723351a | 6681 | if (start < section->start + section->size) |
d3a49aa8 AM |
6682 | warn (ngettext ("There is %ld unused byte at the end of section %s\n", |
6683 | "There are %ld unused bytes at the end of section %s\n", | |
6684 | (long) (section->start + section->size - start)), | |
4723351a | 6685 | (long) (section->start + section->size - start), section->name); |
98fb390a | 6686 | putchar ('\n'); |
51d0d03f | 6687 | free (array); |
19e6b90e L |
6688 | return 1; |
6689 | } | |
6690 | ||
6691 | static int | |
6692 | display_debug_str (struct dwarf_section *section, | |
6693 | void *file ATTRIBUTE_UNUSED) | |
6694 | { | |
6695 | unsigned char *start = section->start; | |
6696 | unsigned long bytes = section->size; | |
6697 | dwarf_vma addr = section->address; | |
6698 | ||
6699 | if (bytes == 0) | |
6700 | { | |
6701 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6702 | return 0; | |
6703 | } | |
6704 | ||
dda8d76d | 6705 | introduce (section, FALSE); |
19e6b90e L |
6706 | |
6707 | while (bytes) | |
6708 | { | |
6709 | int j; | |
6710 | int k; | |
6711 | int lbytes; | |
6712 | ||
6713 | lbytes = (bytes > 16 ? 16 : bytes); | |
6714 | ||
6715 | printf (" 0x%8.8lx ", (unsigned long) addr); | |
6716 | ||
6717 | for (j = 0; j < 16; j++) | |
6718 | { | |
6719 | if (j < lbytes) | |
6720 | printf ("%2.2x", start[j]); | |
6721 | else | |
6722 | printf (" "); | |
6723 | ||
6724 | if ((j & 3) == 3) | |
6725 | printf (" "); | |
6726 | } | |
6727 | ||
6728 | for (j = 0; j < lbytes; j++) | |
6729 | { | |
6730 | k = start[j]; | |
6731 | if (k >= ' ' && k < 0x80) | |
6732 | printf ("%c", k); | |
6733 | else | |
6734 | printf ("."); | |
6735 | } | |
6736 | ||
6737 | putchar ('\n'); | |
6738 | ||
6739 | start += lbytes; | |
6740 | addr += lbytes; | |
6741 | bytes -= lbytes; | |
6742 | } | |
6743 | ||
6744 | putchar ('\n'); | |
6745 | ||
6746 | return 1; | |
6747 | } | |
6748 | ||
19e6b90e L |
6749 | static int |
6750 | display_debug_info (struct dwarf_section *section, void *file) | |
6751 | { | |
d85bf2ba | 6752 | return process_debug_info (section, file, section->abbrev_sec, FALSE, FALSE); |
19e6b90e L |
6753 | } |
6754 | ||
2b6f5997 CC |
6755 | static int |
6756 | display_debug_types (struct dwarf_section *section, void *file) | |
6757 | { | |
d85bf2ba | 6758 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
6f875884 TG |
6759 | } |
6760 | ||
6761 | static int | |
6762 | display_trace_info (struct dwarf_section *section, void *file) | |
6763 | { | |
d85bf2ba | 6764 | return process_debug_info (section, file, section->abbrev_sec, FALSE, TRUE); |
2b6f5997 | 6765 | } |
19e6b90e L |
6766 | |
6767 | static int | |
6768 | display_debug_aranges (struct dwarf_section *section, | |
6769 | void *file ATTRIBUTE_UNUSED) | |
6770 | { | |
6771 | unsigned char *start = section->start; | |
6772 | unsigned char *end = start + section->size; | |
6773 | ||
dda8d76d | 6774 | introduce (section, FALSE); |
19e6b90e | 6775 | |
6e3d6dc1 NC |
6776 | /* It does not matter if this load fails, |
6777 | we test for that later on. */ | |
6778 | load_debug_info (file); | |
6779 | ||
19e6b90e L |
6780 | while (start < end) |
6781 | { | |
6782 | unsigned char *hdrptr; | |
6783 | DWARF2_Internal_ARange arange; | |
91d6fa6a | 6784 | unsigned char *addr_ranges; |
2d9472a2 NC |
6785 | dwarf_vma length; |
6786 | dwarf_vma address; | |
e98fdf1a | 6787 | unsigned long sec_off; |
53b8873b | 6788 | unsigned char address_size; |
19e6b90e | 6789 | int excess; |
bf5117e3 NC |
6790 | unsigned int offset_size; |
6791 | unsigned int initial_length_size; | |
19e6b90e L |
6792 | |
6793 | hdrptr = start; | |
6794 | ||
0c588247 | 6795 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end); |
19e6b90e L |
6796 | if (arange.ar_length == 0xffffffff) |
6797 | { | |
0c588247 | 6798 | SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end); |
19e6b90e L |
6799 | offset_size = 8; |
6800 | initial_length_size = 12; | |
6801 | } | |
6802 | else | |
6803 | { | |
6804 | offset_size = 4; | |
6805 | initial_length_size = 4; | |
6806 | } | |
6807 | ||
e98fdf1a AM |
6808 | sec_off = hdrptr - section->start; |
6809 | if (sec_off + arange.ar_length < sec_off | |
6810 | || sec_off + arange.ar_length > section->size) | |
6811 | { | |
6812 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), | |
6813 | section->name, | |
6814 | sec_off - initial_length_size, | |
6815 | dwarf_vmatoa ("x", arange.ar_length)); | |
6816 | break; | |
6817 | } | |
6818 | ||
0c588247 NC |
6819 | SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end); |
6820 | SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end); | |
19e6b90e | 6821 | |
6e3d6dc1 NC |
6822 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE |
6823 | && num_debug_info_entries > 0 | |
6824 | && find_debug_info_for_offset (arange.ar_info_offset) == NULL) | |
6825 | warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"), | |
47704ddf | 6826 | (unsigned long) arange.ar_info_offset, section->name); |
6e3d6dc1 | 6827 | |
0c588247 NC |
6828 | SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end); |
6829 | SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end); | |
19e6b90e L |
6830 | |
6831 | if (arange.ar_version != 2 && arange.ar_version != 3) | |
6832 | { | |
67f101ee NC |
6833 | /* PR 19872: A version number of 0 probably means that there is |
6834 | padding at the end of the .debug_aranges section. Gold puts | |
6835 | it there when performing an incremental link, for example. | |
6836 | So do not generate a warning in this case. */ | |
6837 | if (arange.ar_version) | |
6838 | warn (_("Only DWARF 2 and 3 aranges are currently supported.\n")); | |
19e6b90e L |
6839 | break; |
6840 | } | |
6841 | ||
47704ddf KT |
6842 | printf (_(" Length: %ld\n"), |
6843 | (long) arange.ar_length); | |
19e6b90e | 6844 | printf (_(" Version: %d\n"), arange.ar_version); |
47704ddf KT |
6845 | printf (_(" Offset into .debug_info: 0x%lx\n"), |
6846 | (unsigned long) arange.ar_info_offset); | |
19e6b90e L |
6847 | printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size); |
6848 | printf (_(" Segment Size: %d\n"), arange.ar_segment_size); | |
6849 | ||
53b8873b NC |
6850 | address_size = arange.ar_pointer_size + arange.ar_segment_size; |
6851 | ||
f41e4712 NC |
6852 | /* PR 17512: file: 001-108546-0.001:0.1. */ |
6853 | if (address_size == 0 || address_size > 8) | |
b3681d67 L |
6854 | { |
6855 | error (_("Invalid address size in %s section!\n"), | |
6856 | section->name); | |
6857 | break; | |
6858 | } | |
6859 | ||
53b8873b NC |
6860 | /* The DWARF spec does not require that the address size be a power |
6861 | of two, but we do. This will have to change if we ever encounter | |
6862 | an uneven architecture. */ | |
6863 | if ((address_size & (address_size - 1)) != 0) | |
6864 | { | |
6865 | warn (_("Pointer size + Segment size is not a power of two.\n")); | |
6866 | break; | |
6867 | } | |
cecf136e | 6868 | |
209c9a13 NC |
6869 | if (address_size > 4) |
6870 | printf (_("\n Address Length\n")); | |
6871 | else | |
6872 | printf (_("\n Address Length\n")); | |
19e6b90e | 6873 | |
91d6fa6a | 6874 | addr_ranges = hdrptr; |
19e6b90e | 6875 | |
53b8873b NC |
6876 | /* Must pad to an alignment boundary that is twice the address size. */ |
6877 | excess = (hdrptr - start) % (2 * address_size); | |
19e6b90e | 6878 | if (excess) |
91d6fa6a | 6879 | addr_ranges += (2 * address_size) - excess; |
19e6b90e | 6880 | |
e98fdf1a | 6881 | start += arange.ar_length + initial_length_size; |
1617e571 | 6882 | |
91d6fa6a | 6883 | while (addr_ranges + 2 * address_size <= start) |
19e6b90e | 6884 | { |
0c588247 NC |
6885 | SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end); |
6886 | SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end); | |
19e6b90e | 6887 | |
80c35038 | 6888 | printf (" "); |
2d9472a2 NC |
6889 | print_dwarf_vma (address, address_size); |
6890 | print_dwarf_vma (length, address_size); | |
6891 | putchar ('\n'); | |
19e6b90e | 6892 | } |
19e6b90e L |
6893 | } |
6894 | ||
6895 | printf ("\n"); | |
6896 | ||
6897 | return 1; | |
6898 | } | |
6899 | ||
4723351a CC |
6900 | /* Comparison function for qsort. */ |
6901 | static int | |
6902 | comp_addr_base (const void * v0, const void * v1) | |
6903 | { | |
d367307b AM |
6904 | debug_info *info0 = *(debug_info **) v0; |
6905 | debug_info *info1 = *(debug_info **) v1; | |
4723351a CC |
6906 | return info0->addr_base - info1->addr_base; |
6907 | } | |
6908 | ||
6909 | /* Display the debug_addr section. */ | |
6910 | static int | |
6911 | display_debug_addr (struct dwarf_section *section, | |
b4eb7656 | 6912 | void *file) |
4723351a CC |
6913 | { |
6914 | debug_info **debug_addr_info; | |
6915 | unsigned char *entry; | |
6916 | unsigned char *end; | |
6917 | unsigned int i; | |
6918 | unsigned int count; | |
6919 | ||
6920 | if (section->size == 0) | |
6921 | { | |
6922 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6923 | return 0; | |
6924 | } | |
6925 | ||
6926 | if (load_debug_info (file) == 0) | |
6927 | { | |
6928 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
6929 | section->name); | |
6930 | return 0; | |
6931 | } | |
6932 | ||
dda8d76d | 6933 | introduce (section, FALSE); |
4723351a | 6934 | |
1306a742 NC |
6935 | /* PR 17531: file: cf38d01b. |
6936 | We use xcalloc because a corrupt file may not have initialised all of the | |
6937 | fields in the debug_info structure, which means that the sort below might | |
6938 | try to move uninitialised data. */ | |
6939 | debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1), | |
b4eb7656 | 6940 | sizeof (debug_info *)); |
4723351a CC |
6941 | |
6942 | count = 0; | |
6943 | for (i = 0; i < num_debug_info_entries; i++) | |
82b1b41b | 6944 | if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE) |
1306a742 NC |
6945 | { |
6946 | /* PR 17531: file: cf38d01b. */ | |
6947 | if (debug_information[i].addr_base >= section->size) | |
6948 | warn (_("Corrupt address base (%lx) found in debug section %u\n"), | |
6949 | (unsigned long) debug_information[i].addr_base, i); | |
6950 | else | |
6951 | debug_addr_info [count++] = debug_information + i; | |
6952 | } | |
4723351a CC |
6953 | |
6954 | /* Add a sentinel to make iteration convenient. */ | |
6955 | debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info)); | |
6956 | debug_addr_info [count]->addr_base = section->size; | |
4723351a | 6957 | qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base); |
1306a742 | 6958 | |
4723351a CC |
6959 | for (i = 0; i < count; i++) |
6960 | { | |
6961 | unsigned int idx; | |
fab128ef | 6962 | unsigned int address_size = debug_addr_info [i]->pointer_size; |
4723351a CC |
6963 | |
6964 | printf (_(" For compilation unit at offset 0x%s:\n"), | |
b4eb7656 | 6965 | dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset)); |
4723351a | 6966 | |
fab128ef | 6967 | printf (_("\tIndex\tAddress\n")); |
4723351a CC |
6968 | entry = section->start + debug_addr_info [i]->addr_base; |
6969 | end = section->start + debug_addr_info [i + 1]->addr_base; | |
6970 | idx = 0; | |
6971 | while (entry < end) | |
b4eb7656 AM |
6972 | { |
6973 | dwarf_vma base = byte_get (entry, address_size); | |
6974 | printf (_("\t%d:\t"), idx); | |
6975 | print_dwarf_vma (base, address_size); | |
6976 | printf ("\n"); | |
6977 | entry += address_size; | |
6978 | idx++; | |
6979 | } | |
4723351a CC |
6980 | } |
6981 | printf ("\n"); | |
6982 | ||
6983 | free (debug_addr_info); | |
6984 | return 1; | |
6985 | } | |
6986 | ||
6987 | /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */ | |
24841daa | 6988 | |
4723351a CC |
6989 | static int |
6990 | display_debug_str_offsets (struct dwarf_section *section, | |
b4eb7656 | 6991 | void *file ATTRIBUTE_UNUSED) |
4723351a CC |
6992 | { |
6993 | if (section->size == 0) | |
6994 | { | |
6995 | printf (_("\nThe %s section is empty.\n"), section->name); | |
6996 | return 0; | |
6997 | } | |
6998 | /* TODO: Dump the contents. This is made somewhat difficult by not knowing | |
6999 | what the offset size is for this section. */ | |
7000 | return 1; | |
7001 | } | |
7002 | ||
01a8f077 JK |
7003 | /* Each debug_information[x].range_lists[y] gets this representation for |
7004 | sorting purposes. */ | |
7005 | ||
7006 | struct range_entry | |
467c65bc NC |
7007 | { |
7008 | /* The debug_information[x].range_lists[y] value. */ | |
359ca075 | 7009 | dwarf_vma ranges_offset; |
01a8f077 | 7010 | |
467c65bc NC |
7011 | /* Original debug_information to find parameters of the data. */ |
7012 | debug_info *debug_info_p; | |
7013 | }; | |
01a8f077 JK |
7014 | |
7015 | /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */ | |
7016 | ||
7017 | static int | |
7018 | range_entry_compar (const void *ap, const void *bp) | |
7019 | { | |
3f5e193b NC |
7020 | const struct range_entry *a_re = (const struct range_entry *) ap; |
7021 | const struct range_entry *b_re = (const struct range_entry *) bp; | |
359ca075 JK |
7022 | const dwarf_vma a = a_re->ranges_offset; |
7023 | const dwarf_vma b = b_re->ranges_offset; | |
01a8f077 JK |
7024 | |
7025 | return (a > b) - (b > a); | |
7026 | } | |
7027 | ||
77145576 JK |
7028 | static void |
7029 | display_debug_ranges_list (unsigned char *start, unsigned char *finish, | |
7030 | unsigned int pointer_size, unsigned long offset, | |
7031 | unsigned long base_address) | |
7032 | { | |
7033 | while (start < finish) | |
7034 | { | |
7035 | dwarf_vma begin; | |
7036 | dwarf_vma end; | |
7037 | ||
7038 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7039 | if (start >= finish) | |
7040 | break; | |
7041 | SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7042 | ||
d11ae95e | 7043 | |
77145576 JK |
7044 | printf (" %8.8lx ", offset); |
7045 | ||
7046 | if (begin == 0 && end == 0) | |
7047 | { | |
7048 | printf (_("<End of list>\n")); | |
7049 | break; | |
7050 | } | |
7051 | ||
7052 | /* Check base address specifiers. */ | |
7053 | if (is_max_address (begin, pointer_size) | |
7054 | && !is_max_address (end, pointer_size)) | |
7055 | { | |
7056 | base_address = end; | |
7057 | print_dwarf_vma (begin, pointer_size); | |
7058 | print_dwarf_vma (end, pointer_size); | |
7059 | printf ("(base address)\n"); | |
7060 | continue; | |
7061 | } | |
7062 | ||
7063 | print_dwarf_vma (begin + base_address, pointer_size); | |
7064 | print_dwarf_vma (end + base_address, pointer_size); | |
7065 | ||
7066 | if (begin == end) | |
7067 | fputs (_("(start == end)"), stdout); | |
7068 | else if (begin > end) | |
7069 | fputs (_("(start > end)"), stdout); | |
7070 | ||
7071 | putchar ('\n'); | |
7072 | } | |
7073 | } | |
7074 | ||
7075 | static void | |
7076 | display_debug_rnglists_list (unsigned char *start, unsigned char *finish, | |
7077 | unsigned int pointer_size, unsigned long offset, | |
7078 | unsigned long base_address) | |
7079 | { | |
7080 | unsigned char *next = start; | |
7081 | ||
7082 | while (1) | |
7083 | { | |
7084 | unsigned long off = offset + (start - next); | |
7085 | enum dwarf_range_list_entry rlet; | |
9dfd0db9 JK |
7086 | /* Initialize it due to a false compiler warning. */ |
7087 | dwarf_vma begin = -1, length, end = -1; | |
77145576 JK |
7088 | unsigned int bytes_read; |
7089 | ||
7090 | if (start + 1 > finish) | |
7091 | { | |
7092 | warn (_("Range list starting at offset 0x%lx is not terminated.\n"), | |
7093 | offset); | |
7094 | break; | |
7095 | } | |
7096 | ||
7097 | printf (" %8.8lx ", off); | |
7098 | ||
7099 | SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish); | |
7100 | ||
7101 | switch (rlet) | |
7102 | { | |
7103 | case DW_RLE_end_of_list: | |
7104 | printf (_("<End of list>\n")); | |
7105 | break; | |
7106 | case DW_RLE_base_address: | |
7107 | SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish); | |
7108 | print_dwarf_vma (base_address, pointer_size); | |
7109 | printf (_("(base address)\n")); | |
7110 | break; | |
7111 | case DW_RLE_start_length: | |
7112 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7113 | length = read_uleb128 (start, &bytes_read, finish); | |
7114 | start += bytes_read; | |
7115 | end = begin + length; | |
7116 | break; | |
7117 | case DW_RLE_offset_pair: | |
7118 | begin = read_uleb128 (start, &bytes_read, finish); | |
7119 | start += bytes_read; | |
7120 | end = read_uleb128 (start, &bytes_read, finish); | |
7121 | start += bytes_read; | |
7122 | break; | |
7123 | case DW_RLE_start_end: | |
7124 | SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish); | |
7125 | SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish); | |
7126 | break; | |
7127 | default: | |
7128 | error (_("Invalid range list entry type %d\n"), rlet); | |
7129 | rlet = DW_RLE_end_of_list; | |
7130 | break; | |
7131 | } | |
7132 | if (rlet == DW_RLE_end_of_list) | |
7133 | break; | |
7134 | if (rlet == DW_RLE_base_address) | |
7135 | continue; | |
7136 | ||
7137 | print_dwarf_vma (begin + base_address, pointer_size); | |
7138 | print_dwarf_vma (end + base_address, pointer_size); | |
7139 | ||
7140 | if (begin == end) | |
7141 | fputs (_("(start == end)"), stdout); | |
7142 | else if (begin > end) | |
7143 | fputs (_("(start > end)"), stdout); | |
7144 | ||
7145 | putchar ('\n'); | |
7146 | } | |
7147 | } | |
7148 | ||
19e6b90e L |
7149 | static int |
7150 | display_debug_ranges (struct dwarf_section *section, | |
7151 | void *file ATTRIBUTE_UNUSED) | |
7152 | { | |
7153 | unsigned char *start = section->start; | |
a2ff7a4b | 7154 | unsigned char *last_start = start; |
f6f0e17b | 7155 | unsigned long bytes = section->size; |
19e6b90e | 7156 | unsigned char *section_begin = start; |
f6f0e17b | 7157 | unsigned char *finish = start + bytes; |
01a8f077 JK |
7158 | unsigned int num_range_list, i; |
7159 | struct range_entry *range_entries, *range_entry_fill; | |
77145576 JK |
7160 | int is_rnglists = strstr (section->name, "debug_rnglists") != NULL; |
7161 | /* Initialize it due to a false compiler warning. */ | |
7162 | unsigned char address_size = 0; | |
19e6b90e | 7163 | |
19e6b90e L |
7164 | if (bytes == 0) |
7165 | { | |
7166 | printf (_("\nThe %s section is empty.\n"), section->name); | |
7167 | return 0; | |
7168 | } | |
7169 | ||
77145576 JK |
7170 | if (is_rnglists) |
7171 | { | |
7172 | dwarf_vma initial_length; | |
7173 | unsigned int initial_length_size; | |
7174 | unsigned char segment_selector_size; | |
7175 | unsigned int offset_size, offset_entry_count; | |
7176 | unsigned short version; | |
7177 | ||
7178 | /* Get and check the length of the block. */ | |
7179 | SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish); | |
7180 | ||
7181 | if (initial_length == 0xffffffff) | |
7182 | { | |
7183 | /* This section is 64-bit DWARF 3. */ | |
7184 | SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish); | |
7185 | offset_size = 8; | |
7186 | initial_length_size = 12; | |
7187 | } | |
7188 | else | |
7189 | { | |
7190 | offset_size = 4; | |
7191 | initial_length_size = 4; | |
7192 | } | |
7193 | ||
7194 | if (initial_length + initial_length_size > section->size) | |
7195 | { | |
7196 | /* If the length field has a relocation against it, then we should | |
7197 | not complain if it is inaccurate (and probably negative). | |
7198 | It is copied from .debug_line handling code. */ | |
7199 | if (reloc_at (section, (start - section->start) - offset_size)) | |
7200 | { | |
7201 | initial_length = (finish - start) - initial_length_size; | |
7202 | } | |
7203 | else | |
7204 | { | |
7205 | warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"), | |
7206 | (long) initial_length); | |
7207 | return 0; | |
7208 | } | |
7209 | } | |
7210 | ||
7211 | /* Get and check the version number. */ | |
7212 | SAFE_BYTE_GET_AND_INC (version, start, 2, finish); | |
7213 | ||
7214 | if (version != 5) | |
7215 | { | |
7216 | warn (_("Only DWARF version 5 debug_rnglists info " | |
7217 | "is currently supported.\n")); | |
7218 | return 0; | |
7219 | } | |
7220 | ||
7221 | SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish); | |
7222 | ||
7223 | SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish); | |
7224 | if (segment_selector_size != 0) | |
7225 | { | |
7226 | warn (_("The %s section contains " | |
7227 | "unsupported segment selector size: %d.\n"), | |
7228 | section->name, segment_selector_size); | |
7229 | return 0; | |
7230 | } | |
7231 | ||
7232 | SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish); | |
7233 | if (offset_entry_count != 0) | |
7234 | { | |
7235 | warn (_("The %s section contains " | |
7236 | "unsupported offset entry count: %u.\n"), | |
7237 | section->name, offset_entry_count); | |
7238 | return 0; | |
7239 | } | |
7240 | } | |
7241 | ||
1febe64d NC |
7242 | if (load_debug_info (file) == 0) |
7243 | { | |
7244 | warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"), | |
7245 | section->name); | |
7246 | return 0; | |
7247 | } | |
19e6b90e | 7248 | |
01a8f077 | 7249 | num_range_list = 0; |
19e6b90e | 7250 | for (i = 0; i < num_debug_info_entries; i++) |
01a8f077 | 7251 | num_range_list += debug_information [i].num_range_lists; |
19e6b90e | 7252 | |
01a8f077 | 7253 | if (num_range_list == 0) |
4723351a CC |
7254 | { |
7255 | /* This can happen when the file was compiled with -gsplit-debug | |
b4eb7656 | 7256 | which removes references to range lists from the primary .o file. */ |
4723351a CC |
7257 | printf (_("No range lists in .debug_info section.\n")); |
7258 | return 1; | |
7259 | } | |
19e6b90e | 7260 | |
3f5e193b NC |
7261 | range_entries = (struct range_entry *) |
7262 | xmalloc (sizeof (*range_entries) * num_range_list); | |
01a8f077 | 7263 | range_entry_fill = range_entries; |
19e6b90e | 7264 | |
01a8f077 JK |
7265 | for (i = 0; i < num_debug_info_entries; i++) |
7266 | { | |
7267 | debug_info *debug_info_p = &debug_information[i]; | |
7268 | unsigned int j; | |
7269 | ||
7270 | for (j = 0; j < debug_info_p->num_range_lists; j++) | |
7271 | { | |
7272 | range_entry_fill->ranges_offset = debug_info_p->range_lists[j]; | |
7273 | range_entry_fill->debug_info_p = debug_info_p; | |
7274 | range_entry_fill++; | |
19e6b90e L |
7275 | } |
7276 | } | |
7277 | ||
01a8f077 JK |
7278 | qsort (range_entries, num_range_list, sizeof (*range_entries), |
7279 | range_entry_compar); | |
19e6b90e | 7280 | |
d493b283 | 7281 | if (dwarf_check != 0 && range_entries[0].ranges_offset != 0) |
19e6b90e | 7282 | warn (_("Range lists in %s section start at 0x%lx\n"), |
359ca075 | 7283 | section->name, (unsigned long) range_entries[0].ranges_offset); |
19e6b90e | 7284 | |
dda8d76d NC |
7285 | introduce (section, FALSE); |
7286 | ||
19e6b90e L |
7287 | printf (_(" Offset Begin End\n")); |
7288 | ||
01a8f077 | 7289 | for (i = 0; i < num_range_list; i++) |
19e6b90e | 7290 | { |
01a8f077 JK |
7291 | struct range_entry *range_entry = &range_entries[i]; |
7292 | debug_info *debug_info_p = range_entry->debug_info_p; | |
19e6b90e | 7293 | unsigned int pointer_size; |
359ca075 | 7294 | dwarf_vma offset; |
01a8f077 | 7295 | unsigned char *next; |
359ca075 | 7296 | dwarf_vma base_address; |
19e6b90e | 7297 | |
77145576 | 7298 | pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size); |
d493b283 | 7299 | offset = range_entry->ranges_offset; |
01a8f077 JK |
7300 | next = section_begin + offset; |
7301 | base_address = debug_info_p->base_address; | |
cecf136e | 7302 | |
f41e4712 NC |
7303 | /* PR 17512: file: 001-101485-0.001:0.1. */ |
7304 | if (pointer_size < 2 || pointer_size > 8) | |
7305 | { | |
7306 | warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"), | |
359ca075 | 7307 | pointer_size, (unsigned long) offset); |
f41e4712 NC |
7308 | continue; |
7309 | } | |
b4eb7656 | 7310 | |
d11ae95e NC |
7311 | if (next < section_begin || next >= finish) |
7312 | { | |
7313 | warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"), | |
7314 | (unsigned long) offset, i); | |
7315 | continue; | |
7316 | } | |
7317 | ||
4723351a | 7318 | if (dwarf_check != 0 && i > 0) |
19e6b90e | 7319 | { |
01a8f077 JK |
7320 | if (start < next) |
7321 | warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"), | |
7322 | (unsigned long) (start - section_begin), | |
7323 | (unsigned long) (next - section_begin), section->name); | |
7324 | else if (start > next) | |
a2ff7a4b AM |
7325 | { |
7326 | if (next == last_start) | |
7327 | continue; | |
7328 | warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"), | |
7329 | (unsigned long) (start - section_begin), | |
7330 | (unsigned long) (next - section_begin), section->name); | |
7331 | } | |
01a8f077 | 7332 | } |
d11ae95e | 7333 | |
01a8f077 | 7334 | start = next; |
a2ff7a4b | 7335 | last_start = next; |
19e6b90e | 7336 | |
77145576 JK |
7337 | (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list) |
7338 | (start, finish, pointer_size, offset, base_address); | |
19e6b90e L |
7339 | } |
7340 | putchar ('\n'); | |
01a8f077 JK |
7341 | |
7342 | free (range_entries); | |
7343 | ||
19e6b90e L |
7344 | return 1; |
7345 | } | |
7346 | ||
7347 | typedef struct Frame_Chunk | |
7348 | { | |
7349 | struct Frame_Chunk *next; | |
7350 | unsigned char *chunk_start; | |
a1165289 | 7351 | unsigned int ncols; |
19e6b90e L |
7352 | /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */ |
7353 | short int *col_type; | |
7354 | int *col_offset; | |
7355 | char *augmentation; | |
7356 | unsigned int code_factor; | |
7357 | int data_factor; | |
bf5117e3 NC |
7358 | dwarf_vma pc_begin; |
7359 | dwarf_vma pc_range; | |
32ef3000 | 7360 | unsigned int cfa_reg; |
c8071705 | 7361 | dwarf_vma cfa_offset; |
a1165289 | 7362 | unsigned int ra; |
19e6b90e L |
7363 | unsigned char fde_encoding; |
7364 | unsigned char cfa_exp; | |
604282a7 JJ |
7365 | unsigned char ptr_size; |
7366 | unsigned char segment_size; | |
19e6b90e L |
7367 | } |
7368 | Frame_Chunk; | |
7369 | ||
665ce1f6 L |
7370 | static const char *const *dwarf_regnames; |
7371 | static unsigned int dwarf_regnames_count; | |
7372 | ||
19e6b90e L |
7373 | /* A marker for a col_type that means this column was never referenced |
7374 | in the frame info. */ | |
7375 | #define DW_CFA_unreferenced (-1) | |
7376 | ||
a1165289 | 7377 | /* Return 0 if no more space is needed, 1 if more space is needed, |
665ce1f6 L |
7378 | -1 for invalid reg. */ |
7379 | ||
7380 | static int | |
7381 | frame_need_space (Frame_Chunk *fc, unsigned int reg) | |
19e6b90e | 7382 | { |
a1165289 | 7383 | unsigned int prev = fc->ncols; |
19e6b90e | 7384 | |
665ce1f6 L |
7385 | if (reg < (unsigned int) fc->ncols) |
7386 | return 0; | |
7387 | ||
7388 | if (dwarf_regnames_count | |
7389 | && reg > dwarf_regnames_count) | |
7390 | return -1; | |
19e6b90e L |
7391 | |
7392 | fc->ncols = reg + 1; | |
a1165289 NC |
7393 | /* PR 17512: file: 10450-2643-0.004. |
7394 | If reg == -1 then this can happen... */ | |
7395 | if (fc->ncols == 0) | |
7396 | return -1; | |
7397 | ||
06614111 NC |
7398 | /* PR 17512: file: 2844a11d. */ |
7399 | if (fc->ncols > 1024) | |
7400 | { | |
7401 | error (_("Unfeasibly large register number: %u\n"), reg); | |
7402 | fc->ncols = 0; | |
7403 | /* FIXME: 1024 is an arbitrary limit. Increase it if | |
7404 | we ever encounter a valid binary that exceeds it. */ | |
7405 | return -1; | |
7406 | } | |
7407 | ||
3f5e193b | 7408 | fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols, |
b4eb7656 | 7409 | sizeof (short int)); |
3f5e193b | 7410 | fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int)); |
b4eb7656 | 7411 | /* PR 17512: file:002-10025-0.005. */ |
041830e0 NC |
7412 | if (fc->col_type == NULL || fc->col_offset == NULL) |
7413 | { | |
7414 | error (_("Out of memory allocating %u columns in dwarf frame arrays\n"), | |
7415 | fc->ncols); | |
7416 | fc->ncols = 0; | |
7417 | return -1; | |
7418 | } | |
19e6b90e L |
7419 | |
7420 | while (prev < fc->ncols) | |
7421 | { | |
7422 | fc->col_type[prev] = DW_CFA_unreferenced; | |
7423 | fc->col_offset[prev] = 0; | |
7424 | prev++; | |
7425 | } | |
665ce1f6 | 7426 | return 1; |
19e6b90e L |
7427 | } |
7428 | ||
2dc4cec1 L |
7429 | static const char *const dwarf_regnames_i386[] = |
7430 | { | |
43234a1e L |
7431 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ |
7432 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7433 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7434 | "st0", "st1", "st2", "st3", /* 11 - 14 */ | |
7435 | "st4", "st5", "st6", "st7", /* 15 - 18 */ | |
7436 | NULL, NULL, /* 19 - 20 */ | |
7437 | "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */ | |
7438 | "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */ | |
7439 | "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */ | |
7440 | "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */ | |
7441 | "fcw", "fsw", "mxcsr", /* 37 - 39 */ | |
7442 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7443 | "tr", "ldtr", /* 48 - 49 */ | |
7444 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7445 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7446 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7447 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7448 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7449 | NULL, NULL, NULL, /* 90 - 92 */ | |
7450 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */ | |
2dc4cec1 L |
7451 | }; |
7452 | ||
3d875af5 L |
7453 | static const char *const dwarf_regnames_iamcu[] = |
7454 | { | |
7455 | "eax", "ecx", "edx", "ebx", /* 0 - 3 */ | |
7456 | "esp", "ebp", "esi", "edi", /* 4 - 7 */ | |
7457 | "eip", "eflags", NULL, /* 8 - 10 */ | |
7458 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */ | |
7459 | NULL, NULL, /* 19 - 20 */ | |
7460 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */ | |
7461 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */ | |
7462 | NULL, NULL, NULL, /* 37 - 39 */ | |
7463 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */ | |
7464 | "tr", "ldtr", /* 48 - 49 */ | |
7465 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */ | |
7466 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */ | |
7467 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */ | |
7468 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */ | |
7469 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */ | |
7470 | NULL, NULL, NULL, /* 90 - 92 */ | |
7471 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */ | |
7472 | }; | |
7473 | ||
b129eb0e RH |
7474 | void |
7475 | init_dwarf_regnames_i386 (void) | |
7476 | { | |
7477 | dwarf_regnames = dwarf_regnames_i386; | |
7478 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386); | |
7479 | } | |
7480 | ||
3d875af5 L |
7481 | void |
7482 | init_dwarf_regnames_iamcu (void) | |
7483 | { | |
7484 | dwarf_regnames = dwarf_regnames_iamcu; | |
7485 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu); | |
7486 | } | |
7487 | ||
2dc4cec1 L |
7488 | static const char *const dwarf_regnames_x86_64[] = |
7489 | { | |
7490 | "rax", "rdx", "rcx", "rbx", | |
7491 | "rsi", "rdi", "rbp", "rsp", | |
7492 | "r8", "r9", "r10", "r11", | |
7493 | "r12", "r13", "r14", "r15", | |
7494 | "rip", | |
7495 | "xmm0", "xmm1", "xmm2", "xmm3", | |
7496 | "xmm4", "xmm5", "xmm6", "xmm7", | |
7497 | "xmm8", "xmm9", "xmm10", "xmm11", | |
7498 | "xmm12", "xmm13", "xmm14", "xmm15", | |
7499 | "st0", "st1", "st2", "st3", | |
7500 | "st4", "st5", "st6", "st7", | |
7501 | "mm0", "mm1", "mm2", "mm3", | |
7502 | "mm4", "mm5", "mm6", "mm7", | |
7503 | "rflags", | |
7504 | "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, | |
7505 | "fs.base", "gs.base", NULL, NULL, | |
7506 | "tr", "ldtr", | |
43234a1e L |
7507 | "mxcsr", "fcw", "fsw", |
7508 | "xmm16", "xmm17", "xmm18", "xmm19", | |
7509 | "xmm20", "xmm21", "xmm22", "xmm23", | |
7510 | "xmm24", "xmm25", "xmm26", "xmm27", | |
7511 | "xmm28", "xmm29", "xmm30", "xmm31", | |
7512 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */ | |
7513 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */ | |
7514 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */ | |
7515 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */ | |
7516 | NULL, NULL, NULL, /* 115 - 117 */ | |
7517 | "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" | |
2dc4cec1 L |
7518 | }; |
7519 | ||
b129eb0e RH |
7520 | void |
7521 | init_dwarf_regnames_x86_64 (void) | |
7522 | { | |
7523 | dwarf_regnames = dwarf_regnames_x86_64; | |
7524 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64); | |
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 | ||
7547 | void | |
7548 | init_dwarf_regnames_aarch64 (void) | |
7549 | { | |
7550 | dwarf_regnames = dwarf_regnames_aarch64; | |
7551 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64); | |
7552 | } | |
7553 | ||
d6bb17b0 AA |
7554 | static const char *const dwarf_regnames_s390[] = |
7555 | { | |
7556 | /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */ | |
7557 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7558 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
7559 | "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7", | |
7560 | "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15", | |
7561 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
7562 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
7563 | "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", | |
7564 | "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", | |
7565 | "pswm", "pswa", | |
7566 | NULL, NULL, | |
7567 | "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23", | |
7568 | "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31", | |
7569 | }; | |
7570 | ||
7571 | void | |
7572 | init_dwarf_regnames_s390 (void) | |
7573 | { | |
7574 | dwarf_regnames = dwarf_regnames_s390; | |
7575 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390); | |
7576 | } | |
7577 | ||
5bb0830d AB |
7578 | static const char *const dwarf_regnames_riscv[] = |
7579 | { | |
7580 | "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */ | |
7581 | "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */ | |
7582 | "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */ | |
7583 | "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */ | |
7584 | "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */ | |
7585 | "fs0", "fs1", /* 40 - 41 */ | |
7586 | "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */ | |
7587 | "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */ | |
7588 | "fs10", "fs11", /* 58 - 59 */ | |
7589 | "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */ | |
7590 | }; | |
7591 | ||
7592 | void | |
7593 | init_dwarf_regnames_riscv (void) | |
7594 | { | |
7595 | dwarf_regnames = dwarf_regnames_riscv; | |
7596 | dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_riscv); | |
7597 | } | |
7598 | ||
2dc4cec1 L |
7599 | void |
7600 | init_dwarf_regnames (unsigned int e_machine) | |
7601 | { | |
7602 | switch (e_machine) | |
7603 | { | |
7604 | case EM_386: | |
b129eb0e | 7605 | init_dwarf_regnames_i386 (); |
2dc4cec1 L |
7606 | break; |
7607 | ||
3d875af5 L |
7608 | case EM_IAMCU: |
7609 | init_dwarf_regnames_iamcu (); | |
7610 | break; | |
7611 | ||
2dc4cec1 | 7612 | case EM_X86_64: |
7f502d6c | 7613 | case EM_L1OM: |
7a9068fe | 7614 | case EM_K1OM: |
b129eb0e | 7615 | init_dwarf_regnames_x86_64 (); |
2dc4cec1 L |
7616 | break; |
7617 | ||
4ee22035 RH |
7618 | case EM_AARCH64: |
7619 | init_dwarf_regnames_aarch64 (); | |
7620 | break; | |
7621 | ||
d6bb17b0 AA |
7622 | case EM_S390: |
7623 | init_dwarf_regnames_s390 (); | |
7624 | break; | |
7625 | ||
5bb0830d AB |
7626 | case EM_RISCV: |
7627 | init_dwarf_regnames_riscv (); | |
7628 | break; | |
7629 | ||
2dc4cec1 L |
7630 | default: |
7631 | break; | |
7632 | } | |
7633 | } | |
7634 | ||
7635 | static const char * | |
7636 | regname (unsigned int regno, int row) | |
7637 | { | |
7638 | static char reg[64]; | |
7f2c8a1d | 7639 | |
2dc4cec1 L |
7640 | if (dwarf_regnames |
7641 | && regno < dwarf_regnames_count | |
7642 | && dwarf_regnames [regno] != NULL) | |
7643 | { | |
7644 | if (row) | |
7645 | return dwarf_regnames [regno]; | |
7646 | snprintf (reg, sizeof (reg), "r%d (%s)", regno, | |
7647 | dwarf_regnames [regno]); | |
7648 | } | |
7649 | else | |
7650 | snprintf (reg, sizeof (reg), "r%d", regno); | |
7651 | return reg; | |
7652 | } | |
7653 | ||
19e6b90e | 7654 | static void |
a1165289 | 7655 | frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs) |
19e6b90e | 7656 | { |
a1165289 | 7657 | unsigned int r; |
19e6b90e L |
7658 | char tmp[100]; |
7659 | ||
d8024a91 | 7660 | if (*max_regs != fc->ncols) |
19e6b90e L |
7661 | *max_regs = fc->ncols; |
7662 | ||
7663 | if (*need_col_headers) | |
7664 | { | |
91d6fa6a | 7665 | static const char *sloc = " LOC"; |
2dc4cec1 | 7666 | |
19e6b90e L |
7667 | *need_col_headers = 0; |
7668 | ||
91d6fa6a | 7669 | printf ("%-*s CFA ", eh_addr_size * 2, sloc); |
19e6b90e L |
7670 | |
7671 | for (r = 0; r < *max_regs; r++) | |
7672 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7673 | { | |
7674 | if (r == fc->ra) | |
50751e18 | 7675 | printf ("ra "); |
19e6b90e | 7676 | else |
2dc4cec1 | 7677 | printf ("%-5s ", regname (r, 1)); |
19e6b90e L |
7678 | } |
7679 | ||
7680 | printf ("\n"); | |
7681 | } | |
7682 | ||
bf5117e3 | 7683 | print_dwarf_vma (fc->pc_begin, eh_addr_size); |
19e6b90e L |
7684 | if (fc->cfa_exp) |
7685 | strcpy (tmp, "exp"); | |
7686 | else | |
c8071705 | 7687 | sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset); |
19e6b90e L |
7688 | printf ("%-8s ", tmp); |
7689 | ||
7690 | for (r = 0; r < fc->ncols; r++) | |
7691 | { | |
7692 | if (fc->col_type[r] != DW_CFA_unreferenced) | |
7693 | { | |
7694 | switch (fc->col_type[r]) | |
7695 | { | |
7696 | case DW_CFA_undefined: | |
7697 | strcpy (tmp, "u"); | |
7698 | break; | |
7699 | case DW_CFA_same_value: | |
7700 | strcpy (tmp, "s"); | |
7701 | break; | |
7702 | case DW_CFA_offset: | |
7703 | sprintf (tmp, "c%+d", fc->col_offset[r]); | |
7704 | break; | |
12eae2d3 JJ |
7705 | case DW_CFA_val_offset: |
7706 | sprintf (tmp, "v%+d", fc->col_offset[r]); | |
7707 | break; | |
19e6b90e | 7708 | case DW_CFA_register: |
2dc4cec1 | 7709 | sprintf (tmp, "%s", regname (fc->col_offset[r], 0)); |
19e6b90e L |
7710 | break; |
7711 | case DW_CFA_expression: | |
7712 | strcpy (tmp, "exp"); | |
7713 | break; | |
12eae2d3 JJ |
7714 | case DW_CFA_val_expression: |
7715 | strcpy (tmp, "vexp"); | |
7716 | break; | |
19e6b90e L |
7717 | default: |
7718 | strcpy (tmp, "n/a"); | |
7719 | break; | |
7720 | } | |
2dc4cec1 | 7721 | printf ("%-5s ", tmp); |
19e6b90e L |
7722 | } |
7723 | } | |
7724 | printf ("\n"); | |
7725 | } | |
7726 | ||
49727e46 | 7727 | #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end) |
19e6b90e | 7728 | |
49727e46 AM |
7729 | static unsigned char * |
7730 | read_cie (unsigned char *start, unsigned char *end, | |
7731 | Frame_Chunk **p_cie, int *p_version, | |
bf59c5d5 | 7732 | bfd_size_type *p_aug_len, unsigned char **p_aug) |
49727e46 AM |
7733 | { |
7734 | int version; | |
7735 | Frame_Chunk *fc; | |
7736 | unsigned int length_return; | |
7737 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 7738 | bfd_size_type augmentation_data_len = 0; |
49727e46 | 7739 | |
041830e0 | 7740 | * p_cie = NULL; |
f41e4712 NC |
7741 | /* PR 17512: file: 001-228113-0.004. */ |
7742 | if (start >= end) | |
7743 | return end; | |
7744 | ||
49727e46 AM |
7745 | fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
7746 | memset (fc, 0, sizeof (Frame_Chunk)); | |
7747 | ||
7748 | fc->col_type = (short int *) xmalloc (sizeof (short int)); | |
7749 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
7750 | ||
7751 | version = *start++; | |
7752 | ||
7753 | fc->augmentation = (char *) start; | |
f41e4712 NC |
7754 | /* PR 17512: file: 001-228113-0.004. |
7755 | Skip past augmentation name, but avoid running off the end of the data. */ | |
7756 | while (start < end) | |
7757 | if (* start ++ == '\0') | |
7758 | break; | |
7759 | if (start == end) | |
7760 | { | |
7761 | warn (_("No terminator for augmentation name\n")); | |
442a6ce8 | 7762 | goto fail; |
f41e4712 | 7763 | } |
49727e46 AM |
7764 | |
7765 | if (strcmp (fc->augmentation, "eh") == 0) | |
7766 | start += eh_addr_size; | |
7767 | ||
7768 | if (version >= 4) | |
7769 | { | |
7770 | GET (fc->ptr_size, 1); | |
77ef8654 NC |
7771 | if (fc->ptr_size < 1 || fc->ptr_size > 8) |
7772 | { | |
7773 | warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size); | |
442a6ce8 | 7774 | goto fail; |
77ef8654 NC |
7775 | } |
7776 | ||
49727e46 | 7777 | GET (fc->segment_size, 1); |
77ef8654 NC |
7778 | /* PR 17512: file: e99d2804. */ |
7779 | if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8) | |
7780 | { | |
7781 | warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size); | |
442a6ce8 | 7782 | goto fail; |
77ef8654 NC |
7783 | } |
7784 | ||
49727e46 AM |
7785 | eh_addr_size = fc->ptr_size; |
7786 | } | |
7787 | else | |
7788 | { | |
7789 | fc->ptr_size = eh_addr_size; | |
7790 | fc->segment_size = 0; | |
7791 | } | |
442a6ce8 | 7792 | |
7f2c8a1d NC |
7793 | READ_ULEB (fc->code_factor); |
7794 | READ_SLEB (fc->data_factor); | |
442a6ce8 | 7795 | |
49727e46 AM |
7796 | if (version == 1) |
7797 | { | |
7798 | GET (fc->ra, 1); | |
7799 | } | |
7800 | else | |
7801 | { | |
7f2c8a1d | 7802 | READ_ULEB (fc->ra); |
49727e46 AM |
7803 | } |
7804 | ||
7805 | if (fc->augmentation[0] == 'z') | |
7806 | { | |
7f2c8a1d | 7807 | READ_ULEB (augmentation_data_len); |
49727e46 | 7808 | augmentation_data = start; |
a1165289 | 7809 | /* PR 17512: file: 11042-2589-0.004. */ |
bf59c5d5 | 7810 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
a1165289 | 7811 | { |
bf59c5d5 NC |
7812 | warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"), |
7813 | dwarf_vmatoa ("x", augmentation_data_len), | |
7814 | (unsigned long) (end - start)); | |
442a6ce8 | 7815 | goto fail; |
a1165289 | 7816 | } |
9c0f3d3f | 7817 | start += augmentation_data_len; |
49727e46 AM |
7818 | } |
7819 | ||
7820 | if (augmentation_data_len) | |
7821 | { | |
058037d3 NC |
7822 | unsigned char *p; |
7823 | unsigned char *q; | |
7824 | unsigned char *qend; | |
b4eb7656 | 7825 | |
49727e46 AM |
7826 | p = (unsigned char *) fc->augmentation + 1; |
7827 | q = augmentation_data; | |
058037d3 NC |
7828 | qend = q + augmentation_data_len; |
7829 | ||
9c0f3d3f | 7830 | while (p < end && q < qend) |
49727e46 AM |
7831 | { |
7832 | if (*p == 'L') | |
7833 | q++; | |
7834 | else if (*p == 'P') | |
7835 | q += 1 + size_of_encoded_value (*q); | |
7836 | else if (*p == 'R') | |
7837 | fc->fde_encoding = *q++; | |
7838 | else if (*p == 'S') | |
7839 | ; | |
09038062 ST |
7840 | else if (*p == 'B') |
7841 | ; | |
49727e46 AM |
7842 | else |
7843 | break; | |
7844 | p++; | |
7845 | } | |
c361b9ac NC |
7846 | /* Note - it is OK if this loop terminates with q < qend. |
7847 | Padding may have been inserted to align the end of the CIE. */ | |
49727e46 AM |
7848 | } |
7849 | ||
7850 | *p_cie = fc; | |
7851 | if (p_version) | |
7852 | *p_version = version; | |
7853 | if (p_aug_len) | |
7854 | { | |
7855 | *p_aug_len = augmentation_data_len; | |
7856 | *p_aug = augmentation_data; | |
7857 | } | |
7858 | return start; | |
442a6ce8 NC |
7859 | |
7860 | fail: | |
7861 | free (fc->col_offset); | |
7862 | free (fc->col_type); | |
7863 | free (fc); | |
7864 | return end; | |
49727e46 AM |
7865 | } |
7866 | ||
d85bf2ba NC |
7867 | /* Prints out the contents on the DATA array formatted as unsigned bytes. |
7868 | If do_wide is not enabled, then formats the output to fit into 80 columns. | |
7869 | PRINTED contains the number of characters already written to the current | |
7870 | output line. */ | |
bf59c5d5 NC |
7871 | |
7872 | static void | |
d85bf2ba NC |
7873 | display_data (bfd_size_type printed, |
7874 | const unsigned char * data, | |
7875 | const bfd_size_type len) | |
bf59c5d5 | 7876 | { |
d85bf2ba NC |
7877 | if (do_wide || len < ((80 - printed) / 3)) |
7878 | for (printed = 0; printed < len; ++printed) | |
7879 | printf (" %02x", data[printed]); | |
bf59c5d5 NC |
7880 | else |
7881 | { | |
d85bf2ba | 7882 | for (printed = 0; printed < len; ++printed) |
bf59c5d5 | 7883 | { |
d85bf2ba | 7884 | if (printed % (80 / 3) == 0) |
bf59c5d5 | 7885 | putchar ('\n'); |
d85bf2ba | 7886 | printf (" %02x", data[printed]); |
bf59c5d5 NC |
7887 | } |
7888 | } | |
d85bf2ba NC |
7889 | } |
7890 | ||
7891 | /* Prints out the contents on the augmentation data array. | |
7892 | If do_wide is not enabled, then formats the output to fit into 80 columns. */ | |
7893 | ||
7894 | static void | |
7895 | display_augmentation_data (const unsigned char * data, const bfd_size_type len) | |
7896 | { | |
7897 | bfd_size_type i; | |
7898 | ||
7899 | i = printf (_(" Augmentation data: ")); | |
7900 | display_data (i, data, len); | |
bf59c5d5 NC |
7901 | } |
7902 | ||
19e6b90e L |
7903 | static int |
7904 | display_debug_frames (struct dwarf_section *section, | |
7905 | void *file ATTRIBUTE_UNUSED) | |
7906 | { | |
7907 | unsigned char *start = section->start; | |
7908 | unsigned char *end = start + section->size; | |
7909 | unsigned char *section_start = start; | |
3391569f NC |
7910 | Frame_Chunk *chunks = NULL, *forward_refs = NULL; |
7911 | Frame_Chunk *remembered_state = NULL; | |
19e6b90e | 7912 | Frame_Chunk *rs; |
3391569f | 7913 | bfd_boolean is_eh = strcmp (section->name, ".eh_frame") == 0; |
19e6b90e | 7914 | unsigned int length_return; |
a1165289 | 7915 | unsigned int max_regs = 0; |
665ce1f6 | 7916 | const char *bad_reg = _("bad register: "); |
77ef8654 | 7917 | unsigned int saved_eh_addr_size = eh_addr_size; |
19e6b90e | 7918 | |
dda8d76d | 7919 | introduce (section, FALSE); |
19e6b90e L |
7920 | |
7921 | while (start < end) | |
7922 | { | |
7923 | unsigned char *saved_start; | |
7924 | unsigned char *block_end; | |
bf5117e3 NC |
7925 | dwarf_vma length; |
7926 | dwarf_vma cie_id; | |
19e6b90e L |
7927 | Frame_Chunk *fc; |
7928 | Frame_Chunk *cie; | |
7929 | int need_col_headers = 1; | |
7930 | unsigned char *augmentation_data = NULL; | |
bf59c5d5 | 7931 | bfd_size_type augmentation_data_len = 0; |
bf5117e3 NC |
7932 | unsigned int encoded_ptr_size = saved_eh_addr_size; |
7933 | unsigned int offset_size; | |
7934 | unsigned int initial_length_size; | |
5b6312fd | 7935 | bfd_boolean all_nops; |
19e6b90e L |
7936 | |
7937 | saved_start = start; | |
19e6b90e | 7938 | |
0c588247 | 7939 | SAFE_BYTE_GET_AND_INC (length, start, 4, end); |
041830e0 | 7940 | |
19e6b90e L |
7941 | if (length == 0) |
7942 | { | |
7943 | printf ("\n%08lx ZERO terminator\n\n", | |
7944 | (unsigned long)(saved_start - section_start)); | |
6937bb54 NC |
7945 | /* Skip any zero terminators that directly follow. |
7946 | A corrupt section size could have loaded a whole | |
7947 | slew of zero filled memory bytes. eg | |
7948 | PR 17512: file: 070-19381-0.004. */ | |
7949 | while (start < end && * start == 0) | |
7950 | ++ start; | |
b758e50f | 7951 | continue; |
19e6b90e L |
7952 | } |
7953 | ||
7954 | if (length == 0xffffffff) | |
7955 | { | |
0c588247 | 7956 | SAFE_BYTE_GET_AND_INC (length, start, 8, end); |
19e6b90e L |
7957 | offset_size = 8; |
7958 | initial_length_size = 12; | |
7959 | } | |
7960 | else | |
7961 | { | |
7962 | offset_size = 4; | |
7963 | initial_length_size = 4; | |
7964 | } | |
7965 | ||
7966 | block_end = saved_start + length + initial_length_size; | |
041830e0 | 7967 | if (block_end > end || block_end < start) |
53b8873b | 7968 | { |
bf5117e3 NC |
7969 | warn ("Invalid length 0x%s in FDE at %#08lx\n", |
7970 | dwarf_vmatoa_1 (NULL, length, offset_size), | |
7971 | (unsigned long) (saved_start - section_start)); | |
53b8873b NC |
7972 | block_end = end; |
7973 | } | |
0c588247 NC |
7974 | |
7975 | SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end); | |
19e6b90e | 7976 | |
846a11e4 NC |
7977 | if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID) |
7978 | || (offset_size == 8 && cie_id == DW64_CIE_ID))) | |
19e6b90e L |
7979 | { |
7980 | int version; | |
a1165289 | 7981 | unsigned int mreg; |
19e6b90e | 7982 | |
49727e46 AM |
7983 | start = read_cie (start, end, &cie, &version, |
7984 | &augmentation_data_len, &augmentation_data); | |
041830e0 NC |
7985 | /* PR 17512: file: 027-135133-0.005. */ |
7986 | if (cie == NULL) | |
7987 | break; | |
a1165289 | 7988 | |
49727e46 | 7989 | fc = cie; |
19e6b90e L |
7990 | fc->next = chunks; |
7991 | chunks = fc; | |
7992 | fc->chunk_start = saved_start; | |
a1165289 | 7993 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
7994 | if (mreg < fc->ra) |
7995 | mreg = fc->ra; | |
06614111 NC |
7996 | if (frame_need_space (fc, mreg) < 0) |
7997 | break; | |
49727e46 AM |
7998 | if (fc->fde_encoding) |
7999 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
19e6b90e | 8000 | |
bf5117e3 NC |
8001 | printf ("\n%08lx ", (unsigned long) (saved_start - section_start)); |
8002 | print_dwarf_vma (length, fc->ptr_size); | |
9c41109d | 8003 | print_dwarf_vma (cie_id, offset_size); |
bf5117e3 | 8004 | |
19e6b90e | 8005 | if (do_debug_frames_interp) |
bf5117e3 NC |
8006 | { |
8007 | printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation, | |
8008 | fc->code_factor, fc->data_factor, fc->ra); | |
8009 | } | |
19e6b90e L |
8010 | else |
8011 | { | |
bf5117e3 | 8012 | printf ("CIE\n"); |
19e6b90e L |
8013 | printf (" Version: %d\n", version); |
8014 | printf (" Augmentation: \"%s\"\n", fc->augmentation); | |
604282a7 JJ |
8015 | if (version >= 4) |
8016 | { | |
8017 | printf (" Pointer Size: %u\n", fc->ptr_size); | |
8018 | printf (" Segment Size: %u\n", fc->segment_size); | |
8019 | } | |
19e6b90e L |
8020 | printf (" Code alignment factor: %u\n", fc->code_factor); |
8021 | printf (" Data alignment factor: %d\n", fc->data_factor); | |
8022 | printf (" Return address column: %d\n", fc->ra); | |
8023 | ||
8024 | if (augmentation_data_len) | |
bf59c5d5 | 8025 | display_augmentation_data (augmentation_data, augmentation_data_len); |
a1165289 | 8026 | |
19e6b90e L |
8027 | putchar ('\n'); |
8028 | } | |
19e6b90e L |
8029 | } |
8030 | else | |
8031 | { | |
8032 | unsigned char *look_for; | |
8033 | static Frame_Chunk fde_fc; | |
604282a7 | 8034 | unsigned long segment_selector; |
19e6b90e | 8035 | |
49727e46 AM |
8036 | if (is_eh) |
8037 | { | |
8038 | dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1); | |
8039 | look_for = start - 4 - ((cie_id ^ sign) - sign); | |
8040 | } | |
8041 | else | |
8042 | look_for = section_start + cie_id; | |
19e6b90e | 8043 | |
49727e46 AM |
8044 | if (look_for <= saved_start) |
8045 | { | |
8046 | for (cie = chunks; cie ; cie = cie->next) | |
8047 | if (cie->chunk_start == look_for) | |
8048 | break; | |
8049 | } | |
8050 | else | |
8051 | { | |
8052 | for (cie = forward_refs; cie ; cie = cie->next) | |
8053 | if (cie->chunk_start == look_for) | |
8054 | break; | |
8055 | if (!cie) | |
8056 | { | |
8057 | unsigned int off_size; | |
8058 | unsigned char *cie_scan; | |
19e6b90e | 8059 | |
49727e46 AM |
8060 | cie_scan = look_for; |
8061 | off_size = 4; | |
8062 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end); | |
8063 | if (length == 0xffffffff) | |
8064 | { | |
8065 | SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end); | |
8066 | off_size = 8; | |
8067 | } | |
8068 | if (length != 0) | |
8069 | { | |
8070 | dwarf_vma c_id; | |
8071 | ||
8072 | SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end); | |
8073 | if (is_eh | |
8074 | ? c_id == 0 | |
8075 | : ((off_size == 4 && c_id == DW_CIE_ID) | |
8076 | || (off_size == 8 && c_id == DW64_CIE_ID))) | |
8077 | { | |
8078 | int version; | |
a1165289 | 8079 | unsigned int mreg; |
49727e46 AM |
8080 | |
8081 | read_cie (cie_scan, end, &cie, &version, | |
8082 | &augmentation_data_len, &augmentation_data); | |
a1165289 NC |
8083 | /* PR 17512: file: 3450-2098-0.004. */ |
8084 | if (cie == NULL) | |
8085 | { | |
8086 | warn (_("Failed to read CIE information\n")); | |
8087 | break; | |
8088 | } | |
49727e46 AM |
8089 | cie->next = forward_refs; |
8090 | forward_refs = cie; | |
8091 | cie->chunk_start = look_for; | |
a1165289 | 8092 | mreg = max_regs > 0 ? max_regs - 1 : 0; |
49727e46 AM |
8093 | if (mreg < cie->ra) |
8094 | mreg = cie->ra; | |
06614111 NC |
8095 | if (frame_need_space (cie, mreg) < 0) |
8096 | { | |
8097 | warn (_("Invalid max register\n")); | |
8098 | break; | |
8099 | } | |
49727e46 AM |
8100 | if (cie->fde_encoding) |
8101 | encoded_ptr_size | |
8102 | = size_of_encoded_value (cie->fde_encoding); | |
8103 | } | |
8104 | } | |
8105 | } | |
8106 | } | |
8107 | ||
8108 | fc = &fde_fc; | |
8109 | memset (fc, 0, sizeof (Frame_Chunk)); | |
19e6b90e L |
8110 | |
8111 | if (!cie) | |
8112 | { | |
bf5117e3 NC |
8113 | warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n", |
8114 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), | |
8115 | (unsigned long) (saved_start - section_start)); | |
19e6b90e | 8116 | fc->ncols = 0; |
3f5e193b NC |
8117 | fc->col_type = (short int *) xmalloc (sizeof (short int)); |
8118 | fc->col_offset = (int *) xmalloc (sizeof (int)); | |
06614111 NC |
8119 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0) |
8120 | { | |
8121 | warn (_("Invalid max register\n")); | |
8122 | break; | |
8123 | } | |
19e6b90e L |
8124 | cie = fc; |
8125 | fc->augmentation = ""; | |
8126 | fc->fde_encoding = 0; | |
604282a7 JJ |
8127 | fc->ptr_size = eh_addr_size; |
8128 | fc->segment_size = 0; | |
19e6b90e L |
8129 | } |
8130 | else | |
8131 | { | |
8132 | fc->ncols = cie->ncols; | |
3f5e193b NC |
8133 | fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int)); |
8134 | fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int)); | |
19e6b90e L |
8135 | memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int)); |
8136 | memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int)); | |
8137 | fc->augmentation = cie->augmentation; | |
604282a7 JJ |
8138 | fc->ptr_size = cie->ptr_size; |
8139 | eh_addr_size = cie->ptr_size; | |
8140 | fc->segment_size = cie->segment_size; | |
19e6b90e L |
8141 | fc->code_factor = cie->code_factor; |
8142 | fc->data_factor = cie->data_factor; | |
8143 | fc->cfa_reg = cie->cfa_reg; | |
8144 | fc->cfa_offset = cie->cfa_offset; | |
8145 | fc->ra = cie->ra; | |
06614111 NC |
8146 | if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0) |
8147 | { | |
8148 | warn (_("Invalid max register\n")); | |
8149 | break; | |
8150 | } | |
19e6b90e L |
8151 | fc->fde_encoding = cie->fde_encoding; |
8152 | } | |
8153 | ||
8154 | if (fc->fde_encoding) | |
8155 | encoded_ptr_size = size_of_encoded_value (fc->fde_encoding); | |
8156 | ||
604282a7 JJ |
8157 | segment_selector = 0; |
8158 | if (fc->segment_size) | |
c8071705 NC |
8159 | { |
8160 | if (fc->segment_size > sizeof (segment_selector)) | |
8161 | { | |
8162 | /* PR 17512: file: 9e196b3e. */ | |
8163 | warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size); | |
8164 | fc->segment_size = 4; | |
8165 | } | |
8166 | SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end); | |
8167 | } | |
041830e0 NC |
8168 | |
8169 | fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end); | |
19e6b90e | 8170 | |
0c588247 NC |
8171 | /* FIXME: It appears that sometimes the final pc_range value is |
8172 | encoded in less than encoded_ptr_size bytes. See the x86_64 | |
8173 | run of the "objcopy on compressed debug sections" test for an | |
8174 | example of this. */ | |
8175 | SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end); | |
bf5117e3 | 8176 | |
19e6b90e L |
8177 | if (cie->augmentation[0] == 'z') |
8178 | { | |
7f2c8a1d | 8179 | READ_ULEB (augmentation_data_len); |
19e6b90e | 8180 | augmentation_data = start; |
bf59c5d5 | 8181 | /* PR 17512 file: 722-8446-0.004 and PR 22386. */ |
d292364e | 8182 | if (augmentation_data_len > (bfd_size_type) (end - start)) |
0a9d414a | 8183 | { |
d292364e AM |
8184 | warn (_("Augmentation data too long: 0x%s, " |
8185 | "expected at most %#lx\n"), | |
8186 | dwarf_vmatoa ("x", augmentation_data_len), | |
8187 | (unsigned long) (end - start)); | |
0a9d414a NC |
8188 | start = end; |
8189 | augmentation_data = NULL; | |
8190 | augmentation_data_len = 0; | |
8191 | } | |
d292364e | 8192 | start += augmentation_data_len; |
19e6b90e L |
8193 | } |
8194 | ||
bf5117e3 NC |
8195 | printf ("\n%08lx %s %s FDE cie=%08lx pc=", |
8196 | (unsigned long)(saved_start - section_start), | |
8197 | dwarf_vmatoa_1 (NULL, length, fc->ptr_size), | |
9c41109d | 8198 | dwarf_vmatoa_1 (NULL, cie_id, offset_size), |
604282a7 | 8199 | (unsigned long)(cie->chunk_start - section_start)); |
bf5117e3 | 8200 | |
604282a7 JJ |
8201 | if (fc->segment_size) |
8202 | printf ("%04lx:", segment_selector); | |
bf5117e3 NC |
8203 | |
8204 | printf ("%s..%s\n", | |
8205 | dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size), | |
8206 | dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size)); | |
8207 | ||
19e6b90e L |
8208 | if (! do_debug_frames_interp && augmentation_data_len) |
8209 | { | |
bf59c5d5 | 8210 | display_augmentation_data (augmentation_data, augmentation_data_len); |
19e6b90e L |
8211 | putchar ('\n'); |
8212 | } | |
8213 | } | |
8214 | ||
8215 | /* At this point, fc is the current chunk, cie (if any) is set, and | |
8216 | we're about to interpret instructions for the chunk. */ | |
8217 | /* ??? At present we need to do this always, since this sizes the | |
8218 | fc->col_type and fc->col_offset arrays, which we write into always. | |
8219 | We should probably split the interpreted and non-interpreted bits | |
8220 | into two different routines, since there's so much that doesn't | |
8221 | really overlap between them. */ | |
8222 | if (1 || do_debug_frames_interp) | |
8223 | { | |
8224 | /* Start by making a pass over the chunk, allocating storage | |
8225 | and taking note of what registers are used. */ | |
8226 | unsigned char *tmp = start; | |
8227 | ||
8228 | while (start < block_end) | |
8229 | { | |
041830e0 NC |
8230 | unsigned int reg, op, opa; |
8231 | unsigned long temp; | |
5929c344 | 8232 | unsigned char * new_start; |
19e6b90e L |
8233 | |
8234 | op = *start++; | |
8235 | opa = op & 0x3f; | |
8236 | if (op & 0xc0) | |
8237 | op &= 0xc0; | |
8238 | ||
8239 | /* Warning: if you add any more cases to this switch, be | |
8240 | sure to add them to the corresponding switch below. */ | |
8241 | switch (op) | |
8242 | { | |
8243 | case DW_CFA_advance_loc: | |
8244 | break; | |
8245 | case DW_CFA_offset: | |
7f2c8a1d | 8246 | SKIP_ULEB (); |
665ce1f6 L |
8247 | if (frame_need_space (fc, opa) >= 0) |
8248 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8249 | break; |
8250 | case DW_CFA_restore: | |
665ce1f6 L |
8251 | if (frame_need_space (fc, opa) >= 0) |
8252 | fc->col_type[opa] = DW_CFA_undefined; | |
19e6b90e L |
8253 | break; |
8254 | case DW_CFA_set_loc: | |
8255 | start += encoded_ptr_size; | |
8256 | break; | |
8257 | case DW_CFA_advance_loc1: | |
8258 | start += 1; | |
8259 | break; | |
8260 | case DW_CFA_advance_loc2: | |
8261 | start += 2; | |
8262 | break; | |
8263 | case DW_CFA_advance_loc4: | |
8264 | start += 4; | |
8265 | break; | |
8266 | case DW_CFA_offset_extended: | |
12eae2d3 | 8267 | case DW_CFA_val_offset: |
7f2c8a1d NC |
8268 | READ_ULEB (reg); |
8269 | SKIP_ULEB (); | |
665ce1f6 L |
8270 | if (frame_need_space (fc, reg) >= 0) |
8271 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8272 | break; |
8273 | case DW_CFA_restore_extended: | |
7f2c8a1d | 8274 | READ_ULEB (reg); |
665ce1f6 L |
8275 | if (frame_need_space (fc, reg) >= 0) |
8276 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8277 | break; |
8278 | case DW_CFA_undefined: | |
7f2c8a1d | 8279 | READ_ULEB (reg); |
665ce1f6 L |
8280 | if (frame_need_space (fc, reg) >= 0) |
8281 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8282 | break; |
8283 | case DW_CFA_same_value: | |
7f2c8a1d | 8284 | READ_ULEB (reg); |
665ce1f6 L |
8285 | if (frame_need_space (fc, reg) >= 0) |
8286 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8287 | break; |
8288 | case DW_CFA_register: | |
7f2c8a1d NC |
8289 | READ_ULEB (reg); |
8290 | SKIP_ULEB (); | |
665ce1f6 L |
8291 | if (frame_need_space (fc, reg) >= 0) |
8292 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8293 | break; |
8294 | case DW_CFA_def_cfa: | |
7f2c8a1d NC |
8295 | SKIP_ULEB (); |
8296 | SKIP_ULEB (); | |
19e6b90e L |
8297 | break; |
8298 | case DW_CFA_def_cfa_register: | |
7f2c8a1d | 8299 | SKIP_ULEB (); |
19e6b90e L |
8300 | break; |
8301 | case DW_CFA_def_cfa_offset: | |
7f2c8a1d | 8302 | SKIP_ULEB (); |
19e6b90e L |
8303 | break; |
8304 | case DW_CFA_def_cfa_expression: | |
7f2c8a1d | 8305 | READ_ULEB (temp); |
5929c344 NC |
8306 | new_start = start + temp; |
8307 | if (new_start < start) | |
041830e0 NC |
8308 | { |
8309 | warn (_("Corrupt CFA_def expression value: %lu\n"), temp); | |
8310 | start = block_end; | |
8311 | } | |
8312 | else | |
5929c344 | 8313 | start = new_start; |
19e6b90e L |
8314 | break; |
8315 | case DW_CFA_expression: | |
12eae2d3 | 8316 | case DW_CFA_val_expression: |
7f2c8a1d NC |
8317 | READ_ULEB (reg); |
8318 | READ_ULEB (temp); | |
5929c344 NC |
8319 | new_start = start + temp; |
8320 | if (new_start < start) | |
041830e0 | 8321 | { |
b4eb7656 | 8322 | /* PR 17512: file:306-192417-0.005. */ |
041830e0 NC |
8323 | warn (_("Corrupt CFA expression value: %lu\n"), temp); |
8324 | start = block_end; | |
8325 | } | |
8326 | else | |
5929c344 | 8327 | start = new_start; |
665ce1f6 L |
8328 | if (frame_need_space (fc, reg) >= 0) |
8329 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8330 | break; |
8331 | case DW_CFA_offset_extended_sf: | |
12eae2d3 | 8332 | case DW_CFA_val_offset_sf: |
7f2c8a1d NC |
8333 | READ_ULEB (reg); |
8334 | SKIP_SLEB (); | |
665ce1f6 L |
8335 | if (frame_need_space (fc, reg) >= 0) |
8336 | fc->col_type[reg] = DW_CFA_undefined; | |
19e6b90e L |
8337 | break; |
8338 | case DW_CFA_def_cfa_sf: | |
7f2c8a1d NC |
8339 | SKIP_ULEB (); |
8340 | SKIP_SLEB (); | |
19e6b90e L |
8341 | break; |
8342 | case DW_CFA_def_cfa_offset_sf: | |
7f2c8a1d | 8343 | SKIP_SLEB (); |
19e6b90e L |
8344 | break; |
8345 | case DW_CFA_MIPS_advance_loc8: | |
8346 | start += 8; | |
8347 | break; | |
8348 | case DW_CFA_GNU_args_size: | |
7f2c8a1d | 8349 | SKIP_ULEB (); |
19e6b90e L |
8350 | break; |
8351 | case DW_CFA_GNU_negative_offset_extended: | |
7f2c8a1d NC |
8352 | READ_ULEB (reg); |
8353 | SKIP_ULEB (); | |
665ce1f6 L |
8354 | if (frame_need_space (fc, reg) >= 0) |
8355 | fc->col_type[reg] = DW_CFA_undefined; | |
8356 | break; | |
19e6b90e L |
8357 | default: |
8358 | break; | |
8359 | } | |
8360 | } | |
8361 | start = tmp; | |
8362 | } | |
8363 | ||
5b6312fd NC |
8364 | all_nops = TRUE; |
8365 | ||
19e6b90e L |
8366 | /* Now we know what registers are used, make a second pass over |
8367 | the chunk, this time actually printing out the info. */ | |
8368 | ||
8369 | while (start < block_end) | |
8370 | { | |
362beea4 | 8371 | unsigned char * tmp; |
19e6b90e | 8372 | unsigned op, opa; |
7f2c8a1d NC |
8373 | unsigned long ul, roffs; |
8374 | /* Note: It is tempting to use an unsigned long for 'reg' but there | |
8375 | are various functions, notably frame_space_needed() that assume that | |
8376 | reg is an unsigned int. */ | |
8377 | unsigned int reg; | |
8378 | dwarf_signed_vma l; | |
bf5117e3 | 8379 | dwarf_vma ofs; |
19e6b90e | 8380 | dwarf_vma vma; |
665ce1f6 | 8381 | const char *reg_prefix = ""; |
19e6b90e L |
8382 | |
8383 | op = *start++; | |
8384 | opa = op & 0x3f; | |
8385 | if (op & 0xc0) | |
8386 | op &= 0xc0; | |
8387 | ||
5b6312fd NC |
8388 | /* Make a note if something other than DW_CFA_nop happens. */ |
8389 | if (op != DW_CFA_nop) | |
8390 | all_nops = FALSE; | |
8391 | ||
19e6b90e L |
8392 | /* Warning: if you add any more cases to this switch, be |
8393 | sure to add them to the corresponding switch above. */ | |
8394 | switch (op) | |
8395 | { | |
8396 | case DW_CFA_advance_loc: | |
8397 | if (do_debug_frames_interp) | |
8398 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8399 | else | |
bf5117e3 | 8400 | printf (" DW_CFA_advance_loc: %d to %s\n", |
19e6b90e | 8401 | opa * fc->code_factor, |
b4eb7656 | 8402 | dwarf_vmatoa_1 (NULL, |
bf5117e3 NC |
8403 | fc->pc_begin + opa * fc->code_factor, |
8404 | fc->ptr_size)); | |
19e6b90e L |
8405 | fc->pc_begin += opa * fc->code_factor; |
8406 | break; | |
8407 | ||
8408 | case DW_CFA_offset: | |
7f2c8a1d | 8409 | READ_ULEB (roffs); |
665ce1f6 L |
8410 | if (opa >= (unsigned int) fc->ncols) |
8411 | reg_prefix = bad_reg; | |
8412 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8413 | printf (" DW_CFA_offset: %s%s at cfa%+ld\n", | |
8414 | reg_prefix, regname (opa, 0), | |
8415 | roffs * fc->data_factor); | |
8416 | if (*reg_prefix == '\0') | |
8417 | { | |
8418 | fc->col_type[opa] = DW_CFA_offset; | |
8419 | fc->col_offset[opa] = roffs * fc->data_factor; | |
8420 | } | |
19e6b90e L |
8421 | break; |
8422 | ||
8423 | case DW_CFA_restore: | |
50751e18 | 8424 | if (opa >= (unsigned int) fc->ncols) |
665ce1f6 L |
8425 | reg_prefix = bad_reg; |
8426 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8427 | printf (" DW_CFA_restore: %s%s\n", | |
8428 | reg_prefix, regname (opa, 0)); | |
50751e18 AK |
8429 | if (*reg_prefix != '\0') |
8430 | break; | |
8431 | ||
8432 | if (opa >= (unsigned int) cie->ncols | |
8433 | || (do_debug_frames_interp | |
8434 | && cie->col_type[opa] == DW_CFA_unreferenced)) | |
8435 | { | |
8436 | fc->col_type[opa] = DW_CFA_undefined; | |
8437 | fc->col_offset[opa] = 0; | |
8438 | } | |
8439 | else | |
665ce1f6 L |
8440 | { |
8441 | fc->col_type[opa] = cie->col_type[opa]; | |
8442 | fc->col_offset[opa] = cie->col_offset[opa]; | |
8443 | } | |
19e6b90e L |
8444 | break; |
8445 | ||
8446 | case DW_CFA_set_loc: | |
6937bb54 | 8447 | vma = get_encoded_value (&start, fc->fde_encoding, section, block_end); |
19e6b90e L |
8448 | if (do_debug_frames_interp) |
8449 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8450 | else | |
bf5117e3 NC |
8451 | printf (" DW_CFA_set_loc: %s\n", |
8452 | dwarf_vmatoa_1 (NULL, vma, fc->ptr_size)); | |
19e6b90e L |
8453 | fc->pc_begin = vma; |
8454 | break; | |
8455 | ||
8456 | case DW_CFA_advance_loc1: | |
0c588247 | 8457 | SAFE_BYTE_GET_AND_INC (ofs, start, 1, end); |
19e6b90e L |
8458 | if (do_debug_frames_interp) |
8459 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8460 | else | |
bf5117e3 NC |
8461 | printf (" DW_CFA_advance_loc1: %ld to %s\n", |
8462 | (unsigned long) (ofs * fc->code_factor), | |
8463 | dwarf_vmatoa_1 (NULL, | |
8464 | fc->pc_begin + ofs * fc->code_factor, | |
8465 | fc->ptr_size)); | |
19e6b90e L |
8466 | fc->pc_begin += ofs * fc->code_factor; |
8467 | break; | |
8468 | ||
8469 | case DW_CFA_advance_loc2: | |
6937bb54 | 8470 | SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end); |
19e6b90e L |
8471 | if (do_debug_frames_interp) |
8472 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8473 | else | |
bf5117e3 NC |
8474 | printf (" DW_CFA_advance_loc2: %ld to %s\n", |
8475 | (unsigned long) (ofs * fc->code_factor), | |
8476 | dwarf_vmatoa_1 (NULL, | |
8477 | fc->pc_begin + ofs * fc->code_factor, | |
8478 | fc->ptr_size)); | |
19e6b90e L |
8479 | fc->pc_begin += ofs * fc->code_factor; |
8480 | break; | |
8481 | ||
8482 | case DW_CFA_advance_loc4: | |
6937bb54 | 8483 | SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end); |
19e6b90e L |
8484 | if (do_debug_frames_interp) |
8485 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8486 | else | |
bf5117e3 NC |
8487 | printf (" DW_CFA_advance_loc4: %ld to %s\n", |
8488 | (unsigned long) (ofs * fc->code_factor), | |
8489 | dwarf_vmatoa_1 (NULL, | |
8490 | fc->pc_begin + ofs * fc->code_factor, | |
8491 | fc->ptr_size)); | |
19e6b90e L |
8492 | fc->pc_begin += ofs * fc->code_factor; |
8493 | break; | |
8494 | ||
8495 | case DW_CFA_offset_extended: | |
7f2c8a1d NC |
8496 | READ_ULEB (reg); |
8497 | READ_ULEB (roffs); | |
665ce1f6 L |
8498 | if (reg >= (unsigned int) fc->ncols) |
8499 | reg_prefix = bad_reg; | |
8500 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8501 | printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n", | |
8502 | reg_prefix, regname (reg, 0), | |
8503 | roffs * fc->data_factor); | |
8504 | if (*reg_prefix == '\0') | |
8505 | { | |
8506 | fc->col_type[reg] = DW_CFA_offset; | |
8507 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8508 | } | |
19e6b90e L |
8509 | break; |
8510 | ||
12eae2d3 | 8511 | case DW_CFA_val_offset: |
7f2c8a1d NC |
8512 | READ_ULEB (reg); |
8513 | READ_ULEB (roffs); | |
665ce1f6 L |
8514 | if (reg >= (unsigned int) fc->ncols) |
8515 | reg_prefix = bad_reg; | |
8516 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8517 | printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n", |
665ce1f6 L |
8518 | reg_prefix, regname (reg, 0), |
8519 | roffs * fc->data_factor); | |
8520 | if (*reg_prefix == '\0') | |
8521 | { | |
8522 | fc->col_type[reg] = DW_CFA_val_offset; | |
8523 | fc->col_offset[reg] = roffs * fc->data_factor; | |
8524 | } | |
12eae2d3 JJ |
8525 | break; |
8526 | ||
19e6b90e | 8527 | case DW_CFA_restore_extended: |
7f2c8a1d | 8528 | READ_ULEB (reg); |
50751e18 | 8529 | if (reg >= (unsigned int) fc->ncols) |
665ce1f6 L |
8530 | reg_prefix = bad_reg; |
8531 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8532 | printf (" DW_CFA_restore_extended: %s%s\n", | |
8533 | reg_prefix, regname (reg, 0)); | |
50751e18 AK |
8534 | if (*reg_prefix != '\0') |
8535 | break; | |
8536 | ||
8537 | if (reg >= (unsigned int) cie->ncols) | |
8538 | { | |
8539 | fc->col_type[reg] = DW_CFA_undefined; | |
8540 | fc->col_offset[reg] = 0; | |
8541 | } | |
8542 | else | |
665ce1f6 L |
8543 | { |
8544 | fc->col_type[reg] = cie->col_type[reg]; | |
8545 | fc->col_offset[reg] = cie->col_offset[reg]; | |
8546 | } | |
19e6b90e L |
8547 | break; |
8548 | ||
8549 | case DW_CFA_undefined: | |
7f2c8a1d | 8550 | READ_ULEB (reg); |
665ce1f6 L |
8551 | if (reg >= (unsigned int) fc->ncols) |
8552 | reg_prefix = bad_reg; | |
8553 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8554 | printf (" DW_CFA_undefined: %s%s\n", | |
8555 | reg_prefix, regname (reg, 0)); | |
8556 | if (*reg_prefix == '\0') | |
8557 | { | |
8558 | fc->col_type[reg] = DW_CFA_undefined; | |
8559 | fc->col_offset[reg] = 0; | |
8560 | } | |
19e6b90e L |
8561 | break; |
8562 | ||
8563 | case DW_CFA_same_value: | |
7f2c8a1d | 8564 | READ_ULEB (reg); |
665ce1f6 L |
8565 | if (reg >= (unsigned int) fc->ncols) |
8566 | reg_prefix = bad_reg; | |
8567 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8568 | printf (" DW_CFA_same_value: %s%s\n", | |
8569 | reg_prefix, regname (reg, 0)); | |
8570 | if (*reg_prefix == '\0') | |
8571 | { | |
8572 | fc->col_type[reg] = DW_CFA_same_value; | |
8573 | fc->col_offset[reg] = 0; | |
8574 | } | |
19e6b90e L |
8575 | break; |
8576 | ||
8577 | case DW_CFA_register: | |
7f2c8a1d NC |
8578 | READ_ULEB (reg); |
8579 | READ_ULEB (roffs); | |
665ce1f6 L |
8580 | if (reg >= (unsigned int) fc->ncols) |
8581 | reg_prefix = bad_reg; | |
8582 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
2dc4cec1 | 8583 | { |
665ce1f6 L |
8584 | printf (" DW_CFA_register: %s%s in ", |
8585 | reg_prefix, regname (reg, 0)); | |
2dc4cec1 L |
8586 | puts (regname (roffs, 0)); |
8587 | } | |
665ce1f6 L |
8588 | if (*reg_prefix == '\0') |
8589 | { | |
8590 | fc->col_type[reg] = DW_CFA_register; | |
8591 | fc->col_offset[reg] = roffs; | |
8592 | } | |
19e6b90e L |
8593 | break; |
8594 | ||
8595 | case DW_CFA_remember_state: | |
8596 | if (! do_debug_frames_interp) | |
8597 | printf (" DW_CFA_remember_state\n"); | |
3f5e193b | 8598 | rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk)); |
b4eb7656 | 8599 | rs->cfa_offset = fc->cfa_offset; |
d71ad7fc RC |
8600 | rs->cfa_reg = fc->cfa_reg; |
8601 | rs->ra = fc->ra; | |
8602 | rs->cfa_exp = fc->cfa_exp; | |
19e6b90e | 8603 | rs->ncols = fc->ncols; |
3f5e193b | 8604 | rs->col_type = (short int *) xcmalloc (rs->ncols, |
b4eb7656 | 8605 | sizeof (* rs->col_type)); |
d71ad7fc RC |
8606 | rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset)); |
8607 | memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type)); | |
8608 | memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset)); | |
19e6b90e L |
8609 | rs->next = remembered_state; |
8610 | remembered_state = rs; | |
8611 | break; | |
8612 | ||
8613 | case DW_CFA_restore_state: | |
8614 | if (! do_debug_frames_interp) | |
8615 | printf (" DW_CFA_restore_state\n"); | |
8616 | rs = remembered_state; | |
8617 | if (rs) | |
8618 | { | |
8619 | remembered_state = rs->next; | |
d71ad7fc RC |
8620 | fc->cfa_offset = rs->cfa_offset; |
8621 | fc->cfa_reg = rs->cfa_reg; | |
b4eb7656 AM |
8622 | fc->ra = rs->ra; |
8623 | fc->cfa_exp = rs->cfa_exp; | |
06614111 NC |
8624 | if (frame_need_space (fc, rs->ncols - 1) < 0) |
8625 | { | |
1306a742 | 8626 | warn (_("Invalid column number in saved frame state\n")); |
06614111 NC |
8627 | fc->ncols = 0; |
8628 | break; | |
8629 | } | |
d71ad7fc | 8630 | memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type)); |
19e6b90e | 8631 | memcpy (fc->col_offset, rs->col_offset, |
d71ad7fc | 8632 | rs->ncols * sizeof (* rs->col_offset)); |
19e6b90e L |
8633 | free (rs->col_type); |
8634 | free (rs->col_offset); | |
8635 | free (rs); | |
8636 | } | |
8637 | else if (do_debug_frames_interp) | |
8638 | printf ("Mismatched DW_CFA_restore_state\n"); | |
8639 | break; | |
8640 | ||
8641 | case DW_CFA_def_cfa: | |
32ef3000 | 8642 | READ_ULEB (fc->cfa_reg); |
7f2c8a1d | 8643 | READ_ULEB (fc->cfa_offset); |
19e6b90e L |
8644 | fc->cfa_exp = 0; |
8645 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8646 | printf (" DW_CFA_def_cfa: %s ofs %d\n", |
c8071705 | 8647 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8648 | break; |
8649 | ||
8650 | case DW_CFA_def_cfa_register: | |
32ef3000 | 8651 | READ_ULEB (fc->cfa_reg); |
19e6b90e L |
8652 | fc->cfa_exp = 0; |
8653 | if (! do_debug_frames_interp) | |
2dc4cec1 L |
8654 | printf (" DW_CFA_def_cfa_register: %s\n", |
8655 | regname (fc->cfa_reg, 0)); | |
19e6b90e L |
8656 | break; |
8657 | ||
8658 | case DW_CFA_def_cfa_offset: | |
7f2c8a1d | 8659 | READ_ULEB (fc->cfa_offset); |
19e6b90e | 8660 | if (! do_debug_frames_interp) |
c8071705 | 8661 | printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8662 | break; |
8663 | ||
8664 | case DW_CFA_nop: | |
8665 | if (! do_debug_frames_interp) | |
8666 | printf (" DW_CFA_nop\n"); | |
8667 | break; | |
8668 | ||
8669 | case DW_CFA_def_cfa_expression: | |
7f2c8a1d | 8670 | READ_ULEB (ul); |
7460c0ab | 8671 | if (start >= block_end || ul > (unsigned long) (block_end - start)) |
6937bb54 | 8672 | { |
a1165289 | 8673 | printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8674 | break; |
8675 | } | |
19e6b90e L |
8676 | if (! do_debug_frames_interp) |
8677 | { | |
8678 | printf (" DW_CFA_def_cfa_expression ("); | |
b7807392 JJ |
8679 | decode_location_expression (start, eh_addr_size, 0, -1, |
8680 | ul, 0, section); | |
19e6b90e L |
8681 | printf (")\n"); |
8682 | } | |
8683 | fc->cfa_exp = 1; | |
8684 | start += ul; | |
8685 | break; | |
8686 | ||
8687 | case DW_CFA_expression: | |
7f2c8a1d NC |
8688 | READ_ULEB (reg); |
8689 | READ_ULEB (ul); | |
665ce1f6 L |
8690 | if (reg >= (unsigned int) fc->ncols) |
8691 | reg_prefix = bad_reg; | |
6937bb54 | 8692 | /* PR 17512: file: 069-133014-0.006. */ |
06614111 | 8693 | /* PR 17512: file: 98c02eb4. */ |
362beea4 NC |
8694 | tmp = start + ul; |
8695 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8696 | { |
a1165289 | 8697 | printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul); |
6937bb54 NC |
8698 | break; |
8699 | } | |
665ce1f6 | 8700 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
19e6b90e | 8701 | { |
665ce1f6 L |
8702 | printf (" DW_CFA_expression: %s%s (", |
8703 | reg_prefix, regname (reg, 0)); | |
b7807392 | 8704 | decode_location_expression (start, eh_addr_size, 0, -1, |
f1c4cc75 | 8705 | ul, 0, section); |
19e6b90e L |
8706 | printf (")\n"); |
8707 | } | |
665ce1f6 L |
8708 | if (*reg_prefix == '\0') |
8709 | fc->col_type[reg] = DW_CFA_expression; | |
362beea4 | 8710 | start = tmp; |
19e6b90e L |
8711 | break; |
8712 | ||
12eae2d3 | 8713 | case DW_CFA_val_expression: |
7f2c8a1d NC |
8714 | READ_ULEB (reg); |
8715 | READ_ULEB (ul); | |
665ce1f6 L |
8716 | if (reg >= (unsigned int) fc->ncols) |
8717 | reg_prefix = bad_reg; | |
362beea4 NC |
8718 | tmp = start + ul; |
8719 | if (start >= block_end || tmp > block_end || tmp < start) | |
6937bb54 | 8720 | { |
a1165289 | 8721 | printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul); |
6937bb54 NC |
8722 | break; |
8723 | } | |
665ce1f6 | 8724 | if (! do_debug_frames_interp || *reg_prefix != '\0') |
12eae2d3 | 8725 | { |
665ce1f6 L |
8726 | printf (" DW_CFA_val_expression: %s%s (", |
8727 | reg_prefix, regname (reg, 0)); | |
b7807392 JJ |
8728 | decode_location_expression (start, eh_addr_size, 0, -1, |
8729 | ul, 0, section); | |
12eae2d3 JJ |
8730 | printf (")\n"); |
8731 | } | |
665ce1f6 L |
8732 | if (*reg_prefix == '\0') |
8733 | fc->col_type[reg] = DW_CFA_val_expression; | |
362beea4 | 8734 | start = tmp; |
12eae2d3 JJ |
8735 | break; |
8736 | ||
19e6b90e | 8737 | case DW_CFA_offset_extended_sf: |
7f2c8a1d NC |
8738 | READ_ULEB (reg); |
8739 | READ_SLEB (l); | |
665ce1f6 L |
8740 | if (frame_need_space (fc, reg) < 0) |
8741 | reg_prefix = bad_reg; | |
8742 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8743 | printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n", | |
8744 | reg_prefix, regname (reg, 0), | |
c8071705 | 8745 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8746 | if (*reg_prefix == '\0') |
8747 | { | |
8748 | fc->col_type[reg] = DW_CFA_offset; | |
8749 | fc->col_offset[reg] = l * fc->data_factor; | |
8750 | } | |
19e6b90e L |
8751 | break; |
8752 | ||
12eae2d3 | 8753 | case DW_CFA_val_offset_sf: |
7f2c8a1d NC |
8754 | READ_ULEB (reg); |
8755 | READ_SLEB (l); | |
665ce1f6 L |
8756 | if (frame_need_space (fc, reg) < 0) |
8757 | reg_prefix = bad_reg; | |
8758 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
084303b8 | 8759 | printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n", |
665ce1f6 | 8760 | reg_prefix, regname (reg, 0), |
c8071705 | 8761 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8762 | if (*reg_prefix == '\0') |
8763 | { | |
8764 | fc->col_type[reg] = DW_CFA_val_offset; | |
8765 | fc->col_offset[reg] = l * fc->data_factor; | |
8766 | } | |
12eae2d3 JJ |
8767 | break; |
8768 | ||
19e6b90e | 8769 | case DW_CFA_def_cfa_sf: |
32ef3000 | 8770 | READ_ULEB (fc->cfa_reg); |
7f2c8a1d | 8771 | READ_ULEB (fc->cfa_offset); |
19e6b90e L |
8772 | fc->cfa_offset = fc->cfa_offset * fc->data_factor; |
8773 | fc->cfa_exp = 0; | |
8774 | if (! do_debug_frames_interp) | |
2dc4cec1 | 8775 | printf (" DW_CFA_def_cfa_sf: %s ofs %d\n", |
c8071705 | 8776 | regname (fc->cfa_reg, 0), (int) fc->cfa_offset); |
19e6b90e L |
8777 | break; |
8778 | ||
8779 | case DW_CFA_def_cfa_offset_sf: | |
7f2c8a1d | 8780 | READ_ULEB (fc->cfa_offset); |
c8071705 | 8781 | fc->cfa_offset *= fc->data_factor; |
19e6b90e | 8782 | if (! do_debug_frames_interp) |
c8071705 | 8783 | printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset); |
19e6b90e L |
8784 | break; |
8785 | ||
8786 | case DW_CFA_MIPS_advance_loc8: | |
6937bb54 | 8787 | SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end); |
19e6b90e L |
8788 | if (do_debug_frames_interp) |
8789 | frame_display_row (fc, &need_col_headers, &max_regs); | |
8790 | else | |
bf5117e3 NC |
8791 | printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n", |
8792 | (unsigned long) (ofs * fc->code_factor), | |
8793 | dwarf_vmatoa_1 (NULL, | |
8794 | fc->pc_begin + ofs * fc->code_factor, | |
8795 | fc->ptr_size)); | |
19e6b90e L |
8796 | fc->pc_begin += ofs * fc->code_factor; |
8797 | break; | |
8798 | ||
8799 | case DW_CFA_GNU_window_save: | |
8800 | if (! do_debug_frames_interp) | |
8801 | printf (" DW_CFA_GNU_window_save\n"); | |
8802 | break; | |
8803 | ||
8804 | case DW_CFA_GNU_args_size: | |
7f2c8a1d | 8805 | READ_ULEB (ul); |
19e6b90e L |
8806 | if (! do_debug_frames_interp) |
8807 | printf (" DW_CFA_GNU_args_size: %ld\n", ul); | |
8808 | break; | |
8809 | ||
8810 | case DW_CFA_GNU_negative_offset_extended: | |
7f2c8a1d NC |
8811 | READ_ULEB (reg); |
8812 | READ_SLEB (l); | |
8813 | l = - l; | |
665ce1f6 L |
8814 | if (frame_need_space (fc, reg) < 0) |
8815 | reg_prefix = bad_reg; | |
8816 | if (! do_debug_frames_interp || *reg_prefix != '\0') | |
8817 | printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n", | |
8818 | reg_prefix, regname (reg, 0), | |
c8071705 | 8819 | (long)(l * fc->data_factor)); |
665ce1f6 L |
8820 | if (*reg_prefix == '\0') |
8821 | { | |
8822 | fc->col_type[reg] = DW_CFA_offset; | |
8823 | fc->col_offset[reg] = l * fc->data_factor; | |
8824 | } | |
19e6b90e L |
8825 | break; |
8826 | ||
8827 | default: | |
53b8873b NC |
8828 | if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user) |
8829 | printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op); | |
8830 | else | |
f41e4712 | 8831 | warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op); |
19e6b90e L |
8832 | start = block_end; |
8833 | } | |
8834 | } | |
8835 | ||
5b6312fd NC |
8836 | /* Interpret the CFA - as long as it is not completely full of NOPs. */ |
8837 | if (do_debug_frames_interp && ! all_nops) | |
19e6b90e L |
8838 | frame_display_row (fc, &need_col_headers, &max_regs); |
8839 | ||
8840 | start = block_end; | |
604282a7 | 8841 | eh_addr_size = saved_eh_addr_size; |
19e6b90e L |
8842 | } |
8843 | ||
8844 | printf ("\n"); | |
8845 | ||
3391569f NC |
8846 | while (remembered_state != NULL) |
8847 | { | |
8848 | rs = remembered_state; | |
8849 | remembered_state = rs->next; | |
8850 | free (rs->col_type); | |
8851 | free (rs->col_offset); | |
8852 | rs->next = NULL; /* Paranoia. */ | |
8853 | free (rs); | |
8854 | } | |
8855 | ||
8856 | while (chunks != NULL) | |
8857 | { | |
8858 | rs = chunks; | |
8859 | chunks = rs->next; | |
8860 | free (rs->col_type); | |
8861 | free (rs->col_offset); | |
8862 | rs->next = NULL; /* Paranoia. */ | |
8863 | free (rs); | |
8864 | } | |
8865 | ||
8866 | while (forward_refs != NULL) | |
8867 | { | |
8868 | rs = forward_refs; | |
8869 | forward_refs = rs->next; | |
8870 | free (rs->col_type); | |
8871 | free (rs->col_offset); | |
8872 | rs->next = NULL; /* Paranoia. */ | |
8873 | free (rs); | |
8874 | } | |
8875 | ||
19e6b90e L |
8876 | return 1; |
8877 | } | |
8878 | ||
8879 | #undef GET | |
19e6b90e | 8880 | |
61364358 JK |
8881 | static int |
8882 | display_debug_names (struct dwarf_section *section, void *file) | |
8883 | { | |
8884 | unsigned char *hdrptr = section->start; | |
8885 | dwarf_vma unit_length; | |
8886 | unsigned char *unit_start; | |
8887 | const unsigned char *const section_end = section->start + section->size; | |
8888 | unsigned char *unit_end; | |
8889 | ||
dda8d76d | 8890 | introduce (section, FALSE); |
61364358 | 8891 | |
dda8d76d | 8892 | load_debug_section_with_follow (str, file); |
61364358 JK |
8893 | |
8894 | for (; hdrptr < section_end; hdrptr = unit_end) | |
8895 | { | |
8896 | unsigned int offset_size; | |
8897 | uint16_t dwarf_version, padding; | |
8898 | uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count; | |
8899 | uint32_t bucket_count, name_count, abbrev_table_size; | |
8900 | uint32_t augmentation_string_size; | |
8901 | unsigned int i; | |
e98fdf1a | 8902 | unsigned long sec_off; |
48467cb9 TV |
8903 | bfd_boolean augmentation_printable; |
8904 | const char *augmentation_string; | |
61364358 JK |
8905 | |
8906 | unit_start = hdrptr; | |
8907 | ||
8908 | /* Get and check the length of the block. */ | |
8909 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end); | |
8910 | ||
8911 | if (unit_length == 0xffffffff) | |
8912 | { | |
8913 | /* This section is 64-bit DWARF. */ | |
8914 | SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end); | |
8915 | offset_size = 8; | |
8916 | } | |
8917 | else | |
8918 | offset_size = 4; | |
8919 | unit_end = hdrptr + unit_length; | |
8920 | ||
e98fdf1a AM |
8921 | sec_off = hdrptr - section->start; |
8922 | if (sec_off + unit_length < sec_off | |
8923 | || sec_off + unit_length > section->size) | |
61364358 | 8924 | { |
e98fdf1a AM |
8925 | warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"), |
8926 | section->name, | |
8927 | (unsigned long) (unit_start - section->start), | |
8928 | dwarf_vmatoa ("x", unit_length)); | |
61364358 JK |
8929 | return 0; |
8930 | } | |
8931 | ||
8932 | /* Get and check the version number. */ | |
8933 | SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end); | |
8934 | printf (_("Version %ld\n"), (long) dwarf_version); | |
8935 | ||
8936 | /* Prior versions did not exist, and future versions may not be | |
8937 | backwards compatible. */ | |
8938 | if (dwarf_version != 5) | |
8939 | { | |
8940 | warn (_("Only DWARF version 5 .debug_names " | |
8941 | "is currently supported.\n")); | |
8942 | return 0; | |
8943 | } | |
8944 | ||
8945 | SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end); | |
8946 | if (padding != 0) | |
8947 | warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"), | |
8948 | padding); | |
8949 | ||
8950 | SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end); | |
8951 | if (comp_unit_count == 0) | |
8952 | warn (_("Compilation unit count must be >= 1 in .debug_names\n")); | |
8953 | ||
8954 | SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end); | |
8955 | SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end); | |
8956 | SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end); | |
8957 | SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end); | |
8958 | SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end); | |
8959 | ||
8960 | SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end); | |
8961 | if (augmentation_string_size % 4 != 0) | |
8962 | { | |
8963 | warn (_("Augmentation string length %u must be rounded up " | |
8964 | "to a multiple of 4 in .debug_names.\n"), | |
8965 | augmentation_string_size); | |
8966 | augmentation_string_size += (-augmentation_string_size) & 3; | |
8967 | } | |
48467cb9 | 8968 | |
61364358 | 8969 | printf (_("Augmentation string:")); |
48467cb9 TV |
8970 | |
8971 | augmentation_printable = TRUE; | |
8972 | augmentation_string = (const char *) hdrptr; | |
8973 | ||
61364358 JK |
8974 | for (i = 0; i < augmentation_string_size; i++) |
8975 | { | |
8976 | unsigned char uc; | |
8977 | ||
8978 | SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end); | |
8979 | printf (" %02x", uc); | |
48467cb9 TV |
8980 | |
8981 | if (uc != 0 && !ISPRINT (uc)) | |
8982 | augmentation_printable = FALSE; | |
8983 | } | |
8984 | ||
8985 | if (augmentation_printable) | |
8986 | { | |
8987 | printf (" (\""); | |
8988 | for (i = 0; | |
8989 | i < augmentation_string_size && augmentation_string[i]; | |
8990 | ++i) | |
8991 | putchar (augmentation_string[i]); | |
8992 | printf ("\")"); | |
61364358 | 8993 | } |
61364358 JK |
8994 | putchar ('\n'); |
8995 | ||
8996 | printf (_("CU table:\n")); | |
8997 | for (i = 0; i < comp_unit_count; i++) | |
8998 | { | |
8999 | uint64_t cu_offset; | |
9000 | ||
9001 | SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end); | |
9002 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset); | |
9003 | } | |
9004 | putchar ('\n'); | |
9005 | ||
9006 | printf (_("TU table:\n")); | |
9007 | for (i = 0; i < local_type_unit_count; i++) | |
9008 | { | |
9009 | uint64_t tu_offset; | |
9010 | ||
9011 | SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end); | |
9012 | printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset); | |
9013 | } | |
9014 | putchar ('\n'); | |
9015 | ||
9016 | printf (_("Foreign TU table:\n")); | |
9017 | for (i = 0; i < foreign_type_unit_count; i++) | |
9018 | { | |
9019 | uint64_t signature; | |
9020 | ||
9021 | SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end); | |
9022 | printf (_("[%3u] "), i); | |
9023 | print_dwarf_vma (signature, 8); | |
9024 | putchar ('\n'); | |
9025 | } | |
9026 | putchar ('\n'); | |
9027 | ||
9028 | const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; | |
9029 | hdrptr += bucket_count * sizeof (uint32_t); | |
9030 | const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; | |
9031 | hdrptr += name_count * sizeof (uint32_t); | |
9032 | unsigned char *const name_table_string_offsets = hdrptr; | |
9033 | hdrptr += name_count * offset_size; | |
9034 | unsigned char *const name_table_entry_offsets = hdrptr; | |
9035 | hdrptr += name_count * offset_size; | |
9036 | unsigned char *const abbrev_table = hdrptr; | |
9037 | hdrptr += abbrev_table_size; | |
9038 | const unsigned char *const abbrev_table_end = hdrptr; | |
9039 | unsigned char *const entry_pool = hdrptr; | |
9040 | if (hdrptr > unit_end) | |
9041 | { | |
9042 | warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx " | |
9043 | "for unit 0x%lx in the debug_names\n"), | |
9044 | (long) (hdrptr - section->start), | |
9045 | (long) (unit_end - section->start), | |
9046 | (long) (unit_start - section->start)); | |
9047 | return 0; | |
9048 | } | |
9049 | ||
9050 | size_t buckets_filled = 0; | |
9051 | size_t bucketi; | |
9052 | for (bucketi = 0; bucketi < bucket_count; bucketi++) | |
9053 | { | |
9054 | const uint32_t bucket = hash_table_buckets[bucketi]; | |
9055 | ||
9056 | if (bucket != 0) | |
9057 | ++buckets_filled; | |
9058 | } | |
d3a49aa8 AM |
9059 | printf (ngettext ("Used %zu of %lu bucket.\n", |
9060 | "Used %zu of %lu buckets.\n", | |
9061 | bucket_count), | |
9062 | buckets_filled, (unsigned long) bucket_count); | |
61364358 | 9063 | |
0a79bef4 | 9064 | uint32_t hash_prev = 0; |
61364358 JK |
9065 | size_t hash_clash_count = 0; |
9066 | size_t longest_clash = 0; | |
9067 | size_t this_length = 0; | |
9068 | size_t hashi; | |
9069 | for (hashi = 0; hashi < name_count; hashi++) | |
9070 | { | |
9071 | const uint32_t hash_this = hash_table_hashes[hashi]; | |
9072 | ||
9073 | if (hashi > 0) | |
9074 | { | |
9075 | if (hash_prev % bucket_count == hash_this % bucket_count) | |
9076 | { | |
9077 | ++hash_clash_count; | |
9078 | ++this_length; | |
9079 | longest_clash = MAX (longest_clash, this_length); | |
9080 | } | |
9081 | else | |
9082 | this_length = 0; | |
9083 | } | |
9084 | hash_prev = hash_this; | |
9085 | } | |
9086 | printf (_("Out of %lu items there are %zu bucket clashes" | |
9087 | " (longest of %zu entries).\n"), | |
9088 | (unsigned long) name_count, hash_clash_count, longest_clash); | |
9089 | assert (name_count == buckets_filled + hash_clash_count); | |
9090 | ||
9091 | struct abbrev_lookup_entry | |
9092 | { | |
9093 | dwarf_vma abbrev_tag; | |
9094 | unsigned char *abbrev_lookup_ptr; | |
9095 | }; | |
9096 | struct abbrev_lookup_entry *abbrev_lookup = NULL; | |
9097 | size_t abbrev_lookup_used = 0; | |
9098 | size_t abbrev_lookup_allocated = 0; | |
9099 | ||
9100 | unsigned char *abbrevptr = abbrev_table; | |
9101 | for (;;) | |
9102 | { | |
9103 | unsigned int bytes_read; | |
9104 | const dwarf_vma abbrev_tag = read_uleb128 (abbrevptr, &bytes_read, | |
9105 | abbrev_table_end); | |
9106 | abbrevptr += bytes_read; | |
9107 | if (abbrev_tag == 0) | |
9108 | break; | |
9109 | if (abbrev_lookup_used == abbrev_lookup_allocated) | |
9110 | { | |
9111 | abbrev_lookup_allocated = MAX (0x100, | |
9112 | abbrev_lookup_allocated * 2); | |
9113 | abbrev_lookup = xrealloc (abbrev_lookup, | |
9114 | (abbrev_lookup_allocated | |
9115 | * sizeof (*abbrev_lookup))); | |
9116 | } | |
9117 | assert (abbrev_lookup_used < abbrev_lookup_allocated); | |
9118 | struct abbrev_lookup_entry *entry; | |
9119 | for (entry = abbrev_lookup; | |
9120 | entry < abbrev_lookup + abbrev_lookup_used; | |
9121 | entry++) | |
9122 | if (entry->abbrev_tag == abbrev_tag) | |
9123 | { | |
9124 | warn (_("Duplicate abbreviation tag %lu " | |
9125 | "in unit 0x%lx in the debug_names\n"), | |
9126 | (long) abbrev_tag, (long) (unit_start - section->start)); | |
9127 | break; | |
9128 | } | |
9129 | entry = &abbrev_lookup[abbrev_lookup_used++]; | |
9130 | entry->abbrev_tag = abbrev_tag; | |
9131 | entry->abbrev_lookup_ptr = abbrevptr; | |
9132 | ||
9133 | /* Skip DWARF tag. */ | |
9134 | read_uleb128 (abbrevptr, &bytes_read, abbrev_table_end); | |
9135 | abbrevptr += bytes_read; | |
9136 | for (;;) | |
9137 | { | |
1d827a72 L |
9138 | const dwarf_vma xindex = read_uleb128 (abbrevptr, |
9139 | &bytes_read, | |
9140 | abbrev_table_end); | |
61364358 JK |
9141 | abbrevptr += bytes_read; |
9142 | const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read, | |
9143 | abbrev_table_end); | |
9144 | abbrevptr += bytes_read; | |
1d827a72 | 9145 | if (xindex == 0 && form == 0) |
61364358 JK |
9146 | break; |
9147 | } | |
9148 | } | |
9149 | ||
9150 | printf (_("\nSymbol table:\n")); | |
9151 | uint32_t namei; | |
9152 | for (namei = 0; namei < name_count; ++namei) | |
9153 | { | |
9154 | uint64_t string_offset, entry_offset; | |
9155 | ||
9156 | SAFE_BYTE_GET (string_offset, | |
9157 | name_table_string_offsets + namei * offset_size, | |
9158 | offset_size, unit_end); | |
9159 | SAFE_BYTE_GET (entry_offset, | |
9160 | name_table_entry_offsets + namei * offset_size, | |
9161 | offset_size, unit_end); | |
9162 | ||
9163 | printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], | |
9164 | fetch_indirect_string (string_offset)); | |
9165 | ||
9166 | unsigned char *entryptr = entry_pool + entry_offset; | |
9167 | ||
9168 | // We need to scan first whether there is a single or multiple | |
9169 | // entries. TAGNO is -2 for the first entry, it is -1 for the | |
9170 | // initial tag read of the second entry, then it becomes 0 for the | |
9171 | // first entry for real printing etc. | |
9172 | int tagno = -2; | |
9173 | /* Initialize it due to a false compiler warning. */ | |
9174 | dwarf_vma second_abbrev_tag = -1; | |
9175 | for (;;) | |
9176 | { | |
9177 | unsigned int bytes_read; | |
9178 | const dwarf_vma abbrev_tag = read_uleb128 (entryptr, &bytes_read, | |
9179 | unit_end); | |
9180 | entryptr += bytes_read; | |
9181 | if (tagno == -1) | |
9182 | { | |
9183 | second_abbrev_tag = abbrev_tag; | |
9184 | tagno = 0; | |
9185 | entryptr = entry_pool + entry_offset; | |
9186 | continue; | |
9187 | } | |
9188 | if (abbrev_tag == 0) | |
9189 | break; | |
9190 | if (tagno >= 0) | |
9191 | printf ("%s<%lu>", | |
9192 | (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"), | |
9193 | (unsigned long) abbrev_tag); | |
9194 | ||
9195 | const struct abbrev_lookup_entry *entry; | |
9196 | for (entry = abbrev_lookup; | |
9197 | entry < abbrev_lookup + abbrev_lookup_used; | |
9198 | entry++) | |
9199 | if (entry->abbrev_tag == abbrev_tag) | |
9200 | break; | |
9201 | if (entry >= abbrev_lookup + abbrev_lookup_used) | |
9202 | { | |
9203 | warn (_("Undefined abbreviation tag %lu " | |
9204 | "in unit 0x%lx in the debug_names\n"), | |
9205 | (long) abbrev_tag, | |
9206 | (long) (unit_start - section->start)); | |
9207 | break; | |
9208 | } | |
9209 | abbrevptr = entry->abbrev_lookup_ptr; | |
9210 | const dwarf_vma dwarf_tag = read_uleb128 (abbrevptr, &bytes_read, | |
9211 | abbrev_table_end); | |
9212 | abbrevptr += bytes_read; | |
9213 | if (tagno >= 0) | |
9214 | printf (" %s", get_TAG_name (dwarf_tag)); | |
9215 | for (;;) | |
9216 | { | |
1d827a72 L |
9217 | const dwarf_vma xindex = read_uleb128 (abbrevptr, |
9218 | &bytes_read, | |
9219 | abbrev_table_end); | |
61364358 JK |
9220 | abbrevptr += bytes_read; |
9221 | const dwarf_vma form = read_uleb128 (abbrevptr, &bytes_read, | |
9222 | abbrev_table_end); | |
9223 | abbrevptr += bytes_read; | |
1d827a72 | 9224 | if (xindex == 0 && form == 0) |
61364358 JK |
9225 | break; |
9226 | ||
9227 | if (tagno >= 0) | |
1d827a72 | 9228 | printf (" %s", get_IDX_name (xindex)); |
ec1b0fbb NC |
9229 | entryptr = read_and_display_attr_value (0, form, 0, |
9230 | unit_start, entryptr, unit_end, | |
9231 | 0, 0, offset_size, | |
61364358 JK |
9232 | dwarf_version, NULL, |
9233 | (tagno < 0), NULL, | |
ec1b0fbb | 9234 | NULL, '=', -1); |
61364358 JK |
9235 | } |
9236 | ++tagno; | |
9237 | } | |
9238 | if (tagno <= 0) | |
9239 | printf (_(" <no entries>")); | |
9240 | putchar ('\n'); | |
9241 | } | |
9242 | ||
9243 | free (abbrev_lookup); | |
9244 | } | |
9245 | ||
9246 | return 1; | |
9247 | } | |
9248 | ||
dda8d76d | 9249 | static int |
d85bf2ba NC |
9250 | display_debug_links (struct dwarf_section * section, |
9251 | void * file ATTRIBUTE_UNUSED) | |
dda8d76d NC |
9252 | { |
9253 | const unsigned char * filename; | |
9254 | unsigned int filelen; | |
9255 | ||
9256 | introduce (section, FALSE); | |
9257 | ||
9258 | /* The .gnu_debuglink section is formatted as: | |
9259 | (c-string) Filename. | |
9260 | (padding) If needed to reach a 4 byte boundary. | |
9261 | (uint32_t) CRC32 value. | |
9262 | ||
9263 | The .gun_debugaltlink section is formatted as: | |
9264 | (c-string) Filename. | |
9265 | (binary) Build-ID. */ | |
9266 | ||
9267 | filename = section->start; | |
9268 | filelen = strnlen ((const char *) filename, section->size); | |
9269 | if (filelen == section->size) | |
9270 | { | |
9271 | warn (_("The debuglink filename is corrupt/missing\n")); | |
9272 | return 0; | |
9273 | } | |
9274 | ||
9275 | printf (_(" Separate debug info file: %s\n"), filename); | |
9276 | ||
9277 | if (const_strneq (section->name, ".gnu_debuglink")) | |
9278 | { | |
9279 | unsigned int crc32; | |
9280 | unsigned int crc_offset; | |
9281 | ||
9282 | crc_offset = filelen + 1; | |
9283 | crc_offset = (crc_offset + 3) & ~3; | |
9284 | if (crc_offset + 4 > section->size) | |
9285 | { | |
9286 | warn (_("CRC offset missing/truncated\n")); | |
9287 | return 0; | |
9288 | } | |
9289 | ||
9290 | crc32 = byte_get (filename + crc_offset, 4); | |
9291 | ||
9292 | printf (_(" CRC value: %#x\n"), crc32); | |
9293 | ||
9294 | if (crc_offset + 4 < section->size) | |
9295 | { | |
9296 | warn (_("There are %#lx extraneous bytes at the end of the section\n"), | |
9297 | (long)(section->size - (crc_offset + 4))); | |
9298 | return 0; | |
9299 | } | |
9300 | } | |
9301 | else /* const_strneq (section->name, ".gnu_debugaltlink") */ | |
9302 | { | |
9303 | const unsigned char * build_id = section->start + filelen + 1; | |
9304 | bfd_size_type build_id_len = section->size - (filelen + 1); | |
9305 | bfd_size_type printed; | |
9306 | ||
9307 | /* FIXME: Should we support smaller build-id notes ? */ | |
9308 | if (build_id_len < 0x14) | |
9309 | { | |
9310 | warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len); | |
9311 | return 0; | |
9312 | } | |
9313 | ||
9314 | printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len); | |
d85bf2ba | 9315 | display_data (printed, build_id, build_id_len); |
dda8d76d NC |
9316 | putchar ('\n'); |
9317 | } | |
9318 | ||
9319 | putchar ('\n'); | |
9320 | return 1; | |
9321 | } | |
9322 | ||
5bbdf3d5 DE |
9323 | static int |
9324 | display_gdb_index (struct dwarf_section *section, | |
9325 | void *file ATTRIBUTE_UNUSED) | |
9326 | { | |
9327 | unsigned char *start = section->start; | |
9328 | uint32_t version; | |
9329 | uint32_t cu_list_offset, tu_list_offset; | |
9330 | uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; | |
9331 | unsigned int cu_list_elements, tu_list_elements; | |
9332 | unsigned int address_table_size, symbol_table_slots; | |
9333 | unsigned char *cu_list, *tu_list; | |
9334 | unsigned char *address_table, *symbol_table, *constant_pool; | |
9335 | unsigned int i; | |
9336 | ||
9337 | /* The documentation for the format of this file is in gdb/dwarf2read.c. */ | |
9338 | ||
dda8d76d | 9339 | introduce (section, FALSE); |
5bbdf3d5 DE |
9340 | |
9341 | if (section->size < 6 * sizeof (uint32_t)) | |
9342 | { | |
9343 | warn (_("Truncated header in the %s section.\n"), section->name); | |
9344 | return 0; | |
9345 | } | |
9346 | ||
9347 | version = byte_get_little_endian (start, 4); | |
da88a764 | 9348 | printf (_("Version %ld\n"), (long) version); |
5bbdf3d5 DE |
9349 | |
9350 | /* Prior versions are obsolete, and future versions may not be | |
9351 | backwards compatible. */ | |
aa170720 | 9352 | if (version < 3 || version > 8) |
5bbdf3d5 | 9353 | { |
da88a764 | 9354 | warn (_("Unsupported version %lu.\n"), (unsigned long) version); |
5bbdf3d5 DE |
9355 | return 0; |
9356 | } | |
8d6eee87 TT |
9357 | if (version < 4) |
9358 | warn (_("The address table data in version 3 may be wrong.\n")); | |
9359 | if (version < 5) | |
9360 | warn (_("Version 4 does not support case insensitive lookups.\n")); | |
9361 | if (version < 6) | |
9362 | warn (_("Version 5 does not include inlined functions.\n")); | |
9363 | if (version < 7) | |
9364 | warn (_("Version 6 does not include symbol attributes.\n")); | |
aa170720 DE |
9365 | /* Version 7 indices generated by Gold have bad type unit references, |
9366 | PR binutils/15021. But we don't know if the index was generated by | |
9367 | Gold or not, so to avoid worrying users with gdb-generated indices | |
9368 | we say nothing for version 7 here. */ | |
5bbdf3d5 DE |
9369 | |
9370 | cu_list_offset = byte_get_little_endian (start + 4, 4); | |
9371 | tu_list_offset = byte_get_little_endian (start + 8, 4); | |
9372 | address_table_offset = byte_get_little_endian (start + 12, 4); | |
9373 | symbol_table_offset = byte_get_little_endian (start + 16, 4); | |
9374 | constant_pool_offset = byte_get_little_endian (start + 20, 4); | |
9375 | ||
9376 | if (cu_list_offset > section->size | |
9377 | || tu_list_offset > section->size | |
9378 | || address_table_offset > section->size | |
9379 | || symbol_table_offset > section->size | |
9380 | || constant_pool_offset > section->size) | |
9381 | { | |
9382 | warn (_("Corrupt header in the %s section.\n"), section->name); | |
9383 | return 0; | |
9384 | } | |
9385 | ||
53774b7e NC |
9386 | /* PR 17531: file: 418d0a8a. */ |
9387 | if (tu_list_offset < cu_list_offset) | |
9388 | { | |
9389 | warn (_("TU offset (%x) is less than CU offset (%x)\n"), | |
9390 | tu_list_offset, cu_list_offset); | |
9391 | return 0; | |
9392 | } | |
9393 | ||
5bbdf3d5 | 9394 | cu_list_elements = (tu_list_offset - cu_list_offset) / 8; |
53774b7e NC |
9395 | |
9396 | if (address_table_offset < tu_list_offset) | |
9397 | { | |
9398 | warn (_("Address table offset (%x) is less than TU offset (%x)\n"), | |
9399 | address_table_offset, tu_list_offset); | |
9400 | return 0; | |
9401 | } | |
9402 | ||
5bbdf3d5 | 9403 | tu_list_elements = (address_table_offset - tu_list_offset) / 8; |
53774b7e NC |
9404 | |
9405 | /* PR 17531: file: 18a47d3d. */ | |
9406 | if (symbol_table_offset < address_table_offset) | |
9407 | { | |
13bace4a | 9408 | warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"), |
53774b7e NC |
9409 | symbol_table_offset, address_table_offset); |
9410 | return 0; | |
9411 | } | |
9412 | ||
5bbdf3d5 | 9413 | address_table_size = symbol_table_offset - address_table_offset; |
53774b7e NC |
9414 | |
9415 | if (constant_pool_offset < symbol_table_offset) | |
9416 | { | |
9417 | warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"), | |
9418 | constant_pool_offset, symbol_table_offset); | |
9419 | return 0; | |
9420 | } | |
9421 | ||
5bbdf3d5 DE |
9422 | symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; |
9423 | ||
9424 | cu_list = start + cu_list_offset; | |
9425 | tu_list = start + tu_list_offset; | |
9426 | address_table = start + address_table_offset; | |
9427 | symbol_table = start + symbol_table_offset; | |
9428 | constant_pool = start + constant_pool_offset; | |
9429 | ||
28d909e5 | 9430 | if (address_table + address_table_size > section->start + section->size) |
acff9664 | 9431 | { |
1306a742 | 9432 | warn (_("Address table extends beyond end of section.\n")); |
acff9664 NC |
9433 | return 0; |
9434 | } | |
b4eb7656 | 9435 | |
5bbdf3d5 DE |
9436 | printf (_("\nCU table:\n")); |
9437 | for (i = 0; i < cu_list_elements; i += 2) | |
9438 | { | |
9439 | uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8); | |
9440 | uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8); | |
9441 | ||
9442 | printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2, | |
9443 | (unsigned long) cu_offset, | |
9444 | (unsigned long) (cu_offset + cu_length - 1)); | |
9445 | } | |
9446 | ||
9447 | printf (_("\nTU table:\n")); | |
9448 | for (i = 0; i < tu_list_elements; i += 3) | |
9449 | { | |
9450 | uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8); | |
9451 | uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8); | |
9452 | uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8); | |
9453 | ||
9454 | printf (_("[%3u] 0x%lx 0x%lx "), i / 3, | |
9455 | (unsigned long) tu_offset, | |
9456 | (unsigned long) type_offset); | |
9457 | print_dwarf_vma (signature, 8); | |
9458 | printf ("\n"); | |
9459 | } | |
9460 | ||
9461 | printf (_("\nAddress table:\n")); | |
acff9664 NC |
9462 | for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4); |
9463 | i += 2 * 8 + 4) | |
5bbdf3d5 DE |
9464 | { |
9465 | uint64_t low = byte_get_little_endian (address_table + i, 8); | |
9466 | uint64_t high = byte_get_little_endian (address_table + i + 8, 8); | |
9467 | uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4); | |
9468 | ||
9469 | print_dwarf_vma (low, 8); | |
9470 | print_dwarf_vma (high, 8); | |
da88a764 | 9471 | printf (_("%lu\n"), (unsigned long) cu_index); |
5bbdf3d5 DE |
9472 | } |
9473 | ||
9474 | printf (_("\nSymbol table:\n")); | |
9475 | for (i = 0; i < symbol_table_slots; ++i) | |
9476 | { | |
9477 | uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4); | |
9478 | uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4); | |
9479 | uint32_t num_cus, cu; | |
9480 | ||
9481 | if (name_offset != 0 | |
9482 | || cu_vector_offset != 0) | |
9483 | { | |
9484 | unsigned int j; | |
362beea4 | 9485 | unsigned char * adr; |
5bbdf3d5 | 9486 | |
362beea4 | 9487 | adr = constant_pool + name_offset; |
53774b7e | 9488 | /* PR 17531: file: 5b7b07ad. */ |
362beea4 | 9489 | if (adr < constant_pool || adr >= section->start + section->size) |
53774b7e NC |
9490 | { |
9491 | printf (_("[%3u] <corrupt offset: %x>"), i, name_offset); | |
9492 | warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"), | |
9493 | name_offset, i); | |
9494 | } | |
9495 | else | |
acff9664 NC |
9496 | printf ("[%3u] %.*s:", i, |
9497 | (int) (section->size - (constant_pool_offset + name_offset)), | |
9498 | constant_pool + name_offset); | |
53774b7e | 9499 | |
362beea4 NC |
9500 | adr = constant_pool + cu_vector_offset; |
9501 | if (adr < constant_pool || adr >= section->start + section->size - 3) | |
53774b7e NC |
9502 | { |
9503 | printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset); | |
9504 | warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"), | |
9505 | cu_vector_offset, i); | |
9506 | continue; | |
9507 | } | |
57028622 | 9508 | |
362beea4 | 9509 | num_cus = byte_get_little_endian (adr, 4); |
53774b7e | 9510 | |
362beea4 | 9511 | adr = constant_pool + cu_vector_offset + 4 + num_cus * 4; |
acff9664 | 9512 | if (num_cus * 4 < num_cus |
362beea4 NC |
9513 | || adr >= section->start + section->size |
9514 | || adr < constant_pool) | |
53774b7e NC |
9515 | { |
9516 | printf ("<invalid number of CUs: %d>\n", num_cus); | |
acff9664 | 9517 | warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"), |
53774b7e NC |
9518 | num_cus, i); |
9519 | continue; | |
9520 | } | |
9521 | ||
8d6eee87 TT |
9522 | if (num_cus > 1) |
9523 | printf ("\n"); | |
f3853b34 | 9524 | |
5bbdf3d5 DE |
9525 | for (j = 0; j < num_cus; ++j) |
9526 | { | |
7c1cef97 | 9527 | int is_static; |
8d6eee87 TT |
9528 | gdb_index_symbol_kind kind; |
9529 | ||
5bbdf3d5 | 9530 | cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4); |
7c1cef97 | 9531 | is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu); |
8d6eee87 TT |
9532 | kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu); |
9533 | cu = GDB_INDEX_CU_VALUE (cu); | |
5bbdf3d5 | 9534 | /* Convert to TU number if it's for a type unit. */ |
ad6b52dd | 9535 | if (cu >= cu_list_elements / 2) |
8d6eee87 TT |
9536 | printf ("%cT%lu", num_cus > 1 ? '\t' : ' ', |
9537 | (unsigned long) (cu - cu_list_elements / 2)); | |
5bbdf3d5 | 9538 | else |
8d6eee87 TT |
9539 | printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu); |
9540 | ||
459d52c8 DE |
9541 | printf (" [%s, %s]", |
9542 | is_static ? _("static") : _("global"), | |
9543 | get_gdb_index_symbol_kind_name (kind)); | |
8d6eee87 TT |
9544 | if (num_cus > 1) |
9545 | printf ("\n"); | |
5bbdf3d5 | 9546 | } |
8d6eee87 TT |
9547 | if (num_cus <= 1) |
9548 | printf ("\n"); | |
5bbdf3d5 DE |
9549 | } |
9550 | } | |
9551 | ||
9552 | return 1; | |
9553 | } | |
9554 | ||
657d0d47 CC |
9555 | /* Pre-allocate enough space for the CU/TU sets needed. */ |
9556 | ||
9557 | static void | |
9558 | prealloc_cu_tu_list (unsigned int nshndx) | |
9559 | { | |
9560 | if (shndx_pool == NULL) | |
9561 | { | |
9562 | shndx_pool_size = nshndx; | |
9563 | shndx_pool_used = 0; | |
9564 | shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size, | |
9565 | sizeof (unsigned int)); | |
9566 | } | |
9567 | else | |
9568 | { | |
9569 | shndx_pool_size = shndx_pool_used + nshndx; | |
9570 | shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size, | |
9571 | sizeof (unsigned int)); | |
9572 | } | |
9573 | } | |
9574 | ||
9575 | static void | |
9576 | add_shndx_to_cu_tu_entry (unsigned int shndx) | |
9577 | { | |
9578 | if (shndx_pool_used >= shndx_pool_size) | |
9579 | { | |
9580 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9581 | return; | |
9582 | } | |
9583 | shndx_pool [shndx_pool_used++] = shndx; | |
9584 | } | |
9585 | ||
9586 | static void | |
9587 | end_cu_tu_entry (void) | |
9588 | { | |
9589 | if (shndx_pool_used >= shndx_pool_size) | |
9590 | { | |
9591 | error (_("Internal error: out of space in the shndx pool.\n")); | |
9592 | return; | |
9593 | } | |
9594 | shndx_pool [shndx_pool_used++] = 0; | |
9595 | } | |
9596 | ||
341f9135 CC |
9597 | /* Return the short name of a DWARF section given by a DW_SECT enumerator. */ |
9598 | ||
9599 | static const char * | |
9600 | get_DW_SECT_short_name (unsigned int dw_sect) | |
9601 | { | |
9602 | static char buf[16]; | |
9603 | ||
9604 | switch (dw_sect) | |
9605 | { | |
9606 | case DW_SECT_INFO: | |
9607 | return "info"; | |
9608 | case DW_SECT_TYPES: | |
9609 | return "types"; | |
9610 | case DW_SECT_ABBREV: | |
9611 | return "abbrev"; | |
9612 | case DW_SECT_LINE: | |
9613 | return "line"; | |
9614 | case DW_SECT_LOC: | |
9615 | return "loc"; | |
9616 | case DW_SECT_STR_OFFSETS: | |
9617 | return "str_off"; | |
9618 | case DW_SECT_MACINFO: | |
9619 | return "macinfo"; | |
9620 | case DW_SECT_MACRO: | |
9621 | return "macro"; | |
9622 | default: | |
b4eb7656 | 9623 | break; |
341f9135 CC |
9624 | } |
9625 | ||
9626 | snprintf (buf, sizeof (buf), "%d", dw_sect); | |
9627 | return buf; | |
9628 | } | |
9629 | ||
9630 | /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. | |
9631 | These sections are extensions for Fission. | |
9632 | See http://gcc.gnu.org/wiki/DebugFissionDWP. */ | |
657d0d47 CC |
9633 | |
9634 | static int | |
9635 | process_cu_tu_index (struct dwarf_section *section, int do_display) | |
9636 | { | |
9637 | unsigned char *phdr = section->start; | |
9638 | unsigned char *limit = phdr + section->size; | |
9639 | unsigned char *phash; | |
9640 | unsigned char *pindex; | |
9641 | unsigned char *ppool; | |
9642 | unsigned int version; | |
341f9135 | 9643 | unsigned int ncols = 0; |
657d0d47 CC |
9644 | unsigned int nused; |
9645 | unsigned int nslots; | |
9646 | unsigned int i; | |
341f9135 CC |
9647 | unsigned int j; |
9648 | dwarf_vma signature_high; | |
9649 | dwarf_vma signature_low; | |
9650 | char buf[64]; | |
657d0d47 | 9651 | |
6937bb54 NC |
9652 | /* PR 17512: file: 002-168123-0.004. */ |
9653 | if (phdr == NULL) | |
9654 | { | |
9655 | warn (_("Section %s is empty\n"), section->name); | |
9656 | return 0; | |
9657 | } | |
9658 | /* PR 17512: file: 002-376-0.004. */ | |
9659 | if (section->size < 24) | |
9660 | { | |
72c61a0d | 9661 | warn (_("Section %s is too small to contain a CU/TU header\n"), |
6937bb54 NC |
9662 | section->name); |
9663 | return 0; | |
9664 | } | |
9665 | ||
9666 | SAFE_BYTE_GET (version, phdr, 4, limit); | |
341f9135 | 9667 | if (version >= 2) |
6937bb54 NC |
9668 | SAFE_BYTE_GET (ncols, phdr + 4, 4, limit); |
9669 | SAFE_BYTE_GET (nused, phdr + 8, 4, limit); | |
9670 | SAFE_BYTE_GET (nslots, phdr + 12, 4, limit); | |
9671 | ||
657d0d47 | 9672 | phash = phdr + 16; |
8e2e3c6c AM |
9673 | pindex = phash + (size_t) nslots * 8; |
9674 | ppool = pindex + (size_t) nslots * 4; | |
57028622 | 9675 | |
657d0d47 CC |
9676 | if (do_display) |
9677 | { | |
dda8d76d NC |
9678 | introduce (section, FALSE); |
9679 | ||
8e2e3c6c | 9680 | printf (_(" Version: %u\n"), version); |
341f9135 | 9681 | if (version >= 2) |
8e2e3c6c AM |
9682 | printf (_(" Number of columns: %u\n"), ncols); |
9683 | printf (_(" Number of used entries: %u\n"), nused); | |
9684 | printf (_(" Number of slots: %u\n\n"), nslots); | |
657d0d47 CC |
9685 | } |
9686 | ||
8e2e3c6c AM |
9687 | /* PR 17531: file: 45d69832. */ |
9688 | if ((size_t) nslots * 8 / 8 != nslots | |
9689 | || phash < phdr || phash > limit | |
9690 | || pindex < phash || pindex > limit | |
9691 | || ppool < pindex || ppool > limit) | |
657d0d47 | 9692 | { |
8e2e3c6c AM |
9693 | warn (ngettext ("Section %s is too small for %u slot\n", |
9694 | "Section %s is too small for %u slots\n", | |
9695 | nslots), | |
657d0d47 CC |
9696 | section->name, nslots); |
9697 | return 0; | |
9698 | } | |
9699 | ||
341f9135 | 9700 | if (version == 1) |
657d0d47 | 9701 | { |
341f9135 CC |
9702 | if (!do_display) |
9703 | prealloc_cu_tu_list ((limit - ppool) / 4); | |
9704 | for (i = 0; i < nslots; i++) | |
657d0d47 | 9705 | { |
341f9135 CC |
9706 | unsigned char *shndx_list; |
9707 | unsigned int shndx; | |
9708 | ||
6937bb54 | 9709 | SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit); |
341f9135 | 9710 | if (signature_high != 0 || signature_low != 0) |
657d0d47 | 9711 | { |
6937bb54 | 9712 | SAFE_BYTE_GET (j, pindex, 4, limit); |
341f9135 | 9713 | shndx_list = ppool + j * 4; |
f3853b34 NC |
9714 | /* PR 17531: file: 705e010d. */ |
9715 | if (shndx_list < ppool) | |
9716 | { | |
9717 | warn (_("Section index pool located before start of section\n")); | |
9718 | return 0; | |
9719 | } | |
9720 | ||
341f9135 CC |
9721 | if (do_display) |
9722 | printf (_(" [%3d] Signature: 0x%s Sections: "), | |
9723 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9724 | buf, sizeof (buf))); | |
9725 | for (;;) | |
657d0d47 | 9726 | { |
341f9135 CC |
9727 | if (shndx_list >= limit) |
9728 | { | |
9729 | warn (_("Section %s too small for shndx pool\n"), | |
9730 | section->name); | |
9731 | return 0; | |
9732 | } | |
6937bb54 | 9733 | SAFE_BYTE_GET (shndx, shndx_list, 4, limit); |
341f9135 CC |
9734 | if (shndx == 0) |
9735 | break; | |
9736 | if (do_display) | |
9737 | printf (" %d", shndx); | |
9738 | else | |
9739 | add_shndx_to_cu_tu_entry (shndx); | |
9740 | shndx_list += 4; | |
657d0d47 | 9741 | } |
657d0d47 | 9742 | if (do_display) |
341f9135 | 9743 | printf ("\n"); |
657d0d47 | 9744 | else |
341f9135 CC |
9745 | end_cu_tu_entry (); |
9746 | } | |
9747 | phash += 8; | |
9748 | pindex += 4; | |
9749 | } | |
9750 | } | |
9751 | else if (version == 2) | |
9752 | { | |
9753 | unsigned int val; | |
9754 | unsigned int dw_sect; | |
9755 | unsigned char *ph = phash; | |
9756 | unsigned char *pi = pindex; | |
8e2e3c6c AM |
9757 | unsigned char *poffsets = ppool + (size_t) ncols * 4; |
9758 | unsigned char *psizes = poffsets + (size_t) nused * ncols * 4; | |
9759 | unsigned char *pend = psizes + (size_t) nused * ncols * 4; | |
341f9135 CC |
9760 | bfd_boolean is_tu_index; |
9761 | struct cu_tu_set *this_set = NULL; | |
9762 | unsigned int row; | |
9763 | unsigned char *prow; | |
9764 | ||
9765 | is_tu_index = strcmp (section->name, ".debug_tu_index") == 0; | |
9766 | ||
362beea4 | 9767 | /* PR 17531: file: 0dd159bf. |
8e2e3c6c AM |
9768 | Check for integer overflow (can occur when size_t is 32-bit) |
9769 | with overlarge ncols or nused values. */ | |
4ac948a0 NC |
9770 | if (ncols > 0 |
9771 | && ((size_t) ncols * 4 / 4 != ncols | |
9772 | || (size_t) nused * ncols * 4 / ((size_t) ncols * 4) != nused | |
9773 | || poffsets < ppool || poffsets > limit | |
9774 | || psizes < poffsets || psizes > limit | |
9775 | || pend < psizes || pend > limit)) | |
341f9135 CC |
9776 | { |
9777 | warn (_("Section %s too small for offset and size tables\n"), | |
9778 | section->name); | |
9779 | return 0; | |
9780 | } | |
9781 | ||
9782 | if (do_display) | |
9783 | { | |
9784 | printf (_(" Offset table\n")); | |
9785 | printf (" slot %-16s ", | |
9786 | is_tu_index ? _("signature") : _("dwo_id")); | |
9787 | } | |
9788 | else | |
9789 | { | |
9790 | if (is_tu_index) | |
9791 | { | |
9792 | tu_count = nused; | |
72c61a0d | 9793 | tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 | 9794 | this_set = tu_sets; |
657d0d47 | 9795 | } |
657d0d47 | 9796 | else |
341f9135 CC |
9797 | { |
9798 | cu_count = nused; | |
72c61a0d | 9799 | cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set)); |
341f9135 CC |
9800 | this_set = cu_sets; |
9801 | } | |
9802 | } | |
6937bb54 | 9803 | |
341f9135 CC |
9804 | if (do_display) |
9805 | { | |
9806 | for (j = 0; j < ncols; j++) | |
9807 | { | |
6937bb54 | 9808 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
341f9135 CC |
9809 | printf (" %8s", get_DW_SECT_short_name (dw_sect)); |
9810 | } | |
9811 | printf ("\n"); | |
9812 | } | |
6937bb54 | 9813 | |
341f9135 CC |
9814 | for (i = 0; i < nslots; i++) |
9815 | { | |
6937bb54 NC |
9816 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9817 | ||
9818 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9819 | if (row != 0) |
9820 | { | |
591f7597 | 9821 | /* PR 17531: file: a05f6ab3. */ |
ef77750e | 9822 | if (row > nused) |
591f7597 NC |
9823 | { |
9824 | warn (_("Row index (%u) is larger than number of used entries (%u)\n"), | |
9825 | row, nused); | |
9826 | return 0; | |
9827 | } | |
9828 | ||
341f9135 | 9829 | if (!do_display) |
6aea08d9 NC |
9830 | { |
9831 | size_t num_copy = sizeof (uint64_t); | |
9832 | ||
9833 | /* PR 23064: Beware of buffer overflow. */ | |
9834 | if (ph + num_copy < limit) | |
9835 | memcpy (&this_set[row - 1].signature, ph, num_copy); | |
9836 | else | |
9837 | { | |
9838 | warn (_("Signature (%p) extends beyond end of space in section\n"), ph); | |
9839 | return 0; | |
9840 | } | |
9841 | } | |
6937bb54 | 9842 | |
341f9135 | 9843 | prow = poffsets + (row - 1) * ncols * 4; |
ffc0f143 NC |
9844 | /* PR 17531: file: b8ce60a8. */ |
9845 | if (prow < poffsets || prow > limit) | |
9846 | { | |
9847 | warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"), | |
9848 | row, ncols); | |
9849 | return 0; | |
9850 | } | |
3aade688 | 9851 | |
341f9135 CC |
9852 | if (do_display) |
9853 | printf (_(" [%3d] 0x%s"), | |
9854 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9855 | buf, sizeof (buf))); | |
9856 | for (j = 0; j < ncols; j++) | |
9857 | { | |
6937bb54 | 9858 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
9859 | if (do_display) |
9860 | printf (" %8d", val); | |
9861 | else | |
9862 | { | |
6937bb54 | 9863 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
9864 | |
9865 | /* PR 17531: file: 10796eb3. */ | |
9866 | if (dw_sect >= DW_SECT_MAX) | |
9867 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
9868 | else | |
9869 | this_set [row - 1].section_offsets [dw_sect] = val; | |
341f9135 CC |
9870 | } |
9871 | } | |
6937bb54 | 9872 | |
341f9135 CC |
9873 | if (do_display) |
9874 | printf ("\n"); | |
9875 | } | |
9876 | ph += 8; | |
9877 | pi += 4; | |
9878 | } | |
9879 | ||
9880 | ph = phash; | |
9881 | pi = pindex; | |
9882 | if (do_display) | |
b4eb7656 | 9883 | { |
341f9135 CC |
9884 | printf ("\n"); |
9885 | printf (_(" Size table\n")); | |
9886 | printf (" slot %-16s ", | |
9887 | is_tu_index ? _("signature") : _("dwo_id")); | |
b4eb7656 | 9888 | } |
6937bb54 | 9889 | |
341f9135 CC |
9890 | for (j = 0; j < ncols; j++) |
9891 | { | |
6937bb54 | 9892 | SAFE_BYTE_GET (val, ppool + j * 4, 4, limit); |
341f9135 CC |
9893 | if (do_display) |
9894 | printf (" %8s", get_DW_SECT_short_name (val)); | |
9895 | } | |
6937bb54 | 9896 | |
341f9135 CC |
9897 | if (do_display) |
9898 | printf ("\n"); | |
6937bb54 | 9899 | |
341f9135 CC |
9900 | for (i = 0; i < nslots; i++) |
9901 | { | |
6937bb54 NC |
9902 | SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit); |
9903 | ||
9904 | SAFE_BYTE_GET (row, pi, 4, limit); | |
341f9135 CC |
9905 | if (row != 0) |
9906 | { | |
9907 | prow = psizes + (row - 1) * ncols * 4; | |
6937bb54 | 9908 | |
341f9135 CC |
9909 | if (do_display) |
9910 | printf (_(" [%3d] 0x%s"), | |
9911 | i, dwarf_vmatoa64 (signature_high, signature_low, | |
9912 | buf, sizeof (buf))); | |
6937bb54 | 9913 | |
341f9135 CC |
9914 | for (j = 0; j < ncols; j++) |
9915 | { | |
6937bb54 | 9916 | SAFE_BYTE_GET (val, prow + j * 4, 4, limit); |
341f9135 CC |
9917 | if (do_display) |
9918 | printf (" %8d", val); | |
9919 | else | |
9920 | { | |
6937bb54 | 9921 | SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit); |
82b1b41b NC |
9922 | if (dw_sect >= DW_SECT_MAX) |
9923 | warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect); | |
9924 | else | |
341f9135 CC |
9925 | this_set [row - 1].section_sizes [dw_sect] = val; |
9926 | } | |
9927 | } | |
6937bb54 | 9928 | |
341f9135 CC |
9929 | if (do_display) |
9930 | printf ("\n"); | |
9931 | } | |
6937bb54 | 9932 | |
341f9135 CC |
9933 | ph += 8; |
9934 | pi += 4; | |
657d0d47 | 9935 | } |
657d0d47 | 9936 | } |
341f9135 | 9937 | else if (do_display) |
6937bb54 | 9938 | printf (_(" Unsupported version (%d)\n"), version); |
657d0d47 CC |
9939 | |
9940 | if (do_display) | |
9941 | printf ("\n"); | |
9942 | ||
9943 | return 1; | |
9944 | } | |
9945 | ||
9946 | /* Load the CU and TU indexes if present. This will build a list of | |
9947 | section sets that we can use to associate a .debug_info.dwo section | |
9948 | with its associated .debug_abbrev.dwo section in a .dwp file. */ | |
9949 | ||
43a444f9 | 9950 | static bfd_boolean |
657d0d47 CC |
9951 | load_cu_tu_indexes (void *file) |
9952 | { | |
43a444f9 NC |
9953 | static int cu_tu_indexes_read = -1; /* Tri-state variable. */ |
9954 | ||
657d0d47 CC |
9955 | /* If we have already loaded (or tried to load) the CU and TU indexes |
9956 | then do not bother to repeat the task. */ | |
43a444f9 NC |
9957 | if (cu_tu_indexes_read == -1) |
9958 | { | |
9959 | cu_tu_indexes_read = TRUE; | |
9960 | ||
dda8d76d | 9961 | if (load_debug_section_with_follow (dwp_cu_index, file)) |
43a444f9 NC |
9962 | if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0)) |
9963 | cu_tu_indexes_read = FALSE; | |
9964 | ||
dda8d76d | 9965 | if (load_debug_section_with_follow (dwp_tu_index, file)) |
43a444f9 NC |
9966 | if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0)) |
9967 | cu_tu_indexes_read = FALSE; | |
9968 | } | |
657d0d47 | 9969 | |
43a444f9 | 9970 | return (bfd_boolean) cu_tu_indexes_read; |
657d0d47 CC |
9971 | } |
9972 | ||
9973 | /* Find the set of sections that includes section SHNDX. */ | |
9974 | ||
9975 | unsigned int * | |
9976 | find_cu_tu_set (void *file, unsigned int shndx) | |
9977 | { | |
9978 | unsigned int i; | |
9979 | ||
43a444f9 NC |
9980 | if (! load_cu_tu_indexes (file)) |
9981 | return NULL; | |
657d0d47 CC |
9982 | |
9983 | /* Find SHNDX in the shndx pool. */ | |
9984 | for (i = 0; i < shndx_pool_used; i++) | |
9985 | if (shndx_pool [i] == shndx) | |
9986 | break; | |
9987 | ||
9988 | if (i >= shndx_pool_used) | |
9989 | return NULL; | |
9990 | ||
9991 | /* Now backup to find the first entry in the set. */ | |
9992 | while (i > 0 && shndx_pool [i - 1] != 0) | |
9993 | i--; | |
9994 | ||
9995 | return shndx_pool + i; | |
9996 | } | |
9997 | ||
9998 | /* Display a .debug_cu_index or .debug_tu_index section. */ | |
9999 | ||
10000 | static int | |
10001 | display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED) | |
10002 | { | |
10003 | return process_cu_tu_index (section, 1); | |
10004 | } | |
10005 | ||
19e6b90e L |
10006 | static int |
10007 | display_debug_not_supported (struct dwarf_section *section, | |
10008 | void *file ATTRIBUTE_UNUSED) | |
10009 | { | |
10010 | printf (_("Displaying the debug contents of section %s is not yet supported.\n"), | |
10011 | section->name); | |
10012 | ||
10013 | return 1; | |
10014 | } | |
10015 | ||
1306a742 NC |
10016 | /* Like malloc, but takes two parameters like calloc. |
10017 | Verifies that the first parameter is not too large. | |
82b1b41b | 10018 | Note: does *not* initialise the allocated memory to zero. */ |
dda8d76d | 10019 | |
19e6b90e L |
10020 | void * |
10021 | cmalloc (size_t nmemb, size_t size) | |
10022 | { | |
10023 | /* Check for overflow. */ | |
10024 | if (nmemb >= ~(size_t) 0 / size) | |
10025 | return NULL; | |
82b1b41b NC |
10026 | |
10027 | return xmalloc (nmemb * size); | |
19e6b90e L |
10028 | } |
10029 | ||
1306a742 NC |
10030 | /* Like xmalloc, but takes two parameters like calloc. |
10031 | Verifies that the first parameter is not too large. | |
10032 | Note: does *not* initialise the allocated memory to zero. */ | |
dda8d76d | 10033 | |
72c61a0d | 10034 | void * |
1306a742 | 10035 | xcmalloc (size_t nmemb, size_t size) |
72c61a0d NC |
10036 | { |
10037 | /* Check for overflow. */ | |
10038 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 NC |
10039 | { |
10040 | fprintf (stderr, | |
10041 | _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"), | |
10042 | (long) nmemb); | |
10043 | xexit (1); | |
10044 | } | |
72c61a0d | 10045 | |
1306a742 | 10046 | return xmalloc (nmemb * size); |
72c61a0d NC |
10047 | } |
10048 | ||
1306a742 NC |
10049 | /* Like xrealloc, but takes three parameters. |
10050 | Verifies that the second parameter is not too large. | |
10051 | Note: does *not* initialise any new memory to zero. */ | |
dda8d76d | 10052 | |
19e6b90e | 10053 | void * |
1306a742 | 10054 | xcrealloc (void *ptr, size_t nmemb, size_t size) |
19e6b90e L |
10055 | { |
10056 | /* Check for overflow. */ | |
10057 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10058 | { |
dda8d76d NC |
10059 | error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"), |
10060 | (long) nmemb); | |
8490fb40 NC |
10061 | xexit (1); |
10062 | } | |
82b1b41b | 10063 | |
1306a742 | 10064 | return xrealloc (ptr, nmemb * size); |
19e6b90e L |
10065 | } |
10066 | ||
1306a742 | 10067 | /* Like xcalloc, but verifies that the first parameter is not too large. */ |
dda8d76d | 10068 | |
19e6b90e | 10069 | void * |
1306a742 | 10070 | xcalloc2 (size_t nmemb, size_t size) |
19e6b90e L |
10071 | { |
10072 | /* Check for overflow. */ | |
10073 | if (nmemb >= ~(size_t) 0 / size) | |
8490fb40 | 10074 | { |
dda8d76d NC |
10075 | error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"), |
10076 | (long) nmemb); | |
8490fb40 NC |
10077 | xexit (1); |
10078 | } | |
82b1b41b | 10079 | |
1306a742 | 10080 | return xcalloc (nmemb, size); |
19e6b90e L |
10081 | } |
10082 | ||
dda8d76d NC |
10083 | static unsigned long |
10084 | calc_gnu_debuglink_crc32 (unsigned long crc, | |
10085 | const unsigned char * buf, | |
10086 | bfd_size_type len) | |
10087 | { | |
10088 | static const unsigned long crc32_table[256] = | |
10089 | { | |
10090 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, | |
10091 | 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, | |
10092 | 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, | |
10093 | 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, | |
10094 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, | |
10095 | 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, | |
10096 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, | |
10097 | 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, | |
10098 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, | |
10099 | 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, | |
10100 | 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, | |
10101 | 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, | |
10102 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, | |
10103 | 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, | |
10104 | 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, | |
10105 | 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, | |
10106 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, | |
10107 | 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, | |
10108 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, | |
10109 | 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, | |
10110 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, | |
10111 | 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, | |
10112 | 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, | |
10113 | 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, | |
10114 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, | |
10115 | 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, | |
10116 | 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, | |
10117 | 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, | |
10118 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, | |
10119 | 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, | |
10120 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, | |
10121 | 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, | |
10122 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, | |
10123 | 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, | |
10124 | 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, | |
10125 | 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, | |
10126 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, | |
10127 | 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, | |
10128 | 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, | |
10129 | 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, | |
10130 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, | |
10131 | 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, | |
10132 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, | |
10133 | 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, | |
10134 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, | |
10135 | 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, | |
10136 | 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, | |
10137 | 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, | |
10138 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, | |
10139 | 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, | |
10140 | 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, | |
10141 | 0x2d02ef8d | |
10142 | }; | |
10143 | const unsigned char *end; | |
10144 | ||
10145 | crc = ~crc & 0xffffffff; | |
10146 | for (end = buf + len; buf < end; ++ buf) | |
10147 | crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); | |
10148 | return ~crc & 0xffffffff; | |
10149 | } | |
10150 | ||
10151 | typedef bfd_boolean (* check_func_type) (const char *, void *); | |
10152 | typedef const char * (* parse_func_type) (struct dwarf_section *, void *); | |
10153 | ||
10154 | static bfd_boolean | |
10155 | check_gnu_debuglink (const char * pathname, void * crc_pointer) | |
10156 | { | |
10157 | static unsigned char buffer [8 * 1024]; | |
10158 | FILE * f; | |
10159 | bfd_size_type count; | |
10160 | unsigned long crc = 0; | |
10161 | void * sep_data; | |
10162 | ||
10163 | sep_data = open_debug_file (pathname); | |
10164 | if (sep_data == NULL) | |
10165 | return FALSE; | |
10166 | ||
10167 | /* Yes - we are opening the file twice... */ | |
10168 | f = fopen (pathname, "rb"); | |
10169 | if (f == NULL) | |
10170 | { | |
10171 | /* Paranoia: This should never happen. */ | |
10172 | close_debug_file (sep_data); | |
10173 | warn (_("Unable to reopen separate debug info file: %s\n"), pathname); | |
10174 | return FALSE; | |
10175 | } | |
10176 | ||
10177 | while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0) | |
10178 | crc = calc_gnu_debuglink_crc32 (crc, buffer, count); | |
10179 | ||
10180 | fclose (f); | |
10181 | ||
10182 | if (crc != * (unsigned long *) crc_pointer) | |
10183 | { | |
10184 | close_debug_file (sep_data); | |
10185 | warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"), | |
10186 | pathname); | |
10187 | return FALSE; | |
10188 | } | |
10189 | ||
10190 | return TRUE; | |
10191 | } | |
10192 | ||
10193 | static const char * | |
10194 | parse_gnu_debuglink (struct dwarf_section * section, void * data) | |
10195 | { | |
10196 | const char * name; | |
10197 | unsigned int crc_offset; | |
10198 | unsigned long * crc32 = (unsigned long *) data; | |
10199 | ||
10200 | /* The name is first. | |
10201 | The CRC value is stored after the filename, aligned up to 4 bytes. */ | |
10202 | name = (const char *) section->start; | |
10203 | ||
39f0547e | 10204 | |
dda8d76d NC |
10205 | crc_offset = strnlen (name, section->size) + 1; |
10206 | crc_offset = (crc_offset + 3) & ~3; | |
10207 | if (crc_offset + 4 > section->size) | |
10208 | return NULL; | |
10209 | ||
10210 | * crc32 = byte_get (section->start + crc_offset, 4); | |
10211 | return name; | |
10212 | } | |
10213 | ||
10214 | static bfd_boolean | |
10215 | check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED) | |
10216 | { | |
10217 | void * sep_data = open_debug_file (filename); | |
10218 | ||
10219 | if (sep_data == NULL) | |
10220 | return FALSE; | |
10221 | ||
10222 | /* FIXME: We should now extract the build-id in the separate file | |
10223 | and check it... */ | |
10224 | ||
10225 | return TRUE; | |
10226 | } | |
10227 | ||
10228 | typedef struct build_id_data | |
10229 | { | |
10230 | bfd_size_type len; | |
10231 | const unsigned char * data; | |
10232 | } Build_id_data; | |
10233 | ||
10234 | static const char * | |
10235 | parse_gnu_debugaltlink (struct dwarf_section * section, void * data) | |
10236 | { | |
10237 | const char * name; | |
10238 | bfd_size_type namelen; | |
10239 | bfd_size_type id_len; | |
10240 | Build_id_data * build_id_data; | |
10241 | ||
10242 | /* The name is first. | |
10243 | The build-id follows immediately, with no padding, up to the section's end. */ | |
10244 | ||
10245 | name = (const char *) section->start; | |
10246 | namelen = strnlen (name, section->size) + 1; | |
10247 | if (namelen >= section->size) | |
10248 | return NULL; | |
10249 | ||
10250 | id_len = section->size - namelen; | |
10251 | if (id_len < 0x14) | |
10252 | return NULL; | |
10253 | ||
10254 | build_id_data = calloc (1, sizeof * build_id_data); | |
10255 | if (build_id_data == NULL) | |
10256 | return NULL; | |
10257 | ||
10258 | build_id_data->len = id_len; | |
10259 | build_id_data->data = section->start + namelen; | |
10260 | ||
10261 | * (Build_id_data **) data = build_id_data; | |
10262 | ||
10263 | return name; | |
10264 | } | |
10265 | ||
24841daa NC |
10266 | static void |
10267 | add_separate_debug_file (const char * filename, void * handle) | |
10268 | { | |
10269 | separate_info * i = xmalloc (sizeof * i); | |
10270 | ||
10271 | i->filename = filename; | |
10272 | i->handle = handle; | |
10273 | i->next = first_separate_info; | |
10274 | first_separate_info = i; | |
10275 | } | |
10276 | ||
dda8d76d NC |
10277 | static void * |
10278 | load_separate_debug_info (const char * main_filename, | |
2b63c337 | 10279 | struct dwarf_section * xlink, |
dda8d76d NC |
10280 | parse_func_type parse_func, |
10281 | check_func_type check_func, | |
10282 | void * func_data) | |
10283 | { | |
10284 | const char * separate_filename; | |
24841daa | 10285 | char * debug_filename; |
dda8d76d NC |
10286 | char * canon_dir; |
10287 | size_t canon_dirlen; | |
10288 | size_t dirlen; | |
10289 | ||
2b63c337 | 10290 | if ((separate_filename = parse_func (xlink, func_data)) == NULL) |
dda8d76d NC |
10291 | { |
10292 | warn (_("Corrupt debuglink section: %s\n"), | |
2b63c337 | 10293 | xlink->name ? xlink->name : xlink->uncompressed_name); |
dda8d76d NC |
10294 | return FALSE; |
10295 | } | |
10296 | ||
10297 | /* Attempt to locate the separate file. | |
10298 | This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */ | |
10299 | ||
10300 | canon_dir = lrealpath (main_filename); | |
10301 | ||
10302 | for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--) | |
10303 | if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1])) | |
10304 | break; | |
10305 | canon_dir[canon_dirlen] = '\0'; | |
10306 | ||
10307 | #ifndef DEBUGDIR | |
10308 | #define DEBUGDIR "/lib/debug" | |
10309 | #endif | |
10310 | #ifndef EXTRA_DEBUG_ROOT1 | |
10311 | #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug" | |
10312 | #endif | |
10313 | #ifndef EXTRA_DEBUG_ROOT2 | |
10314 | #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr" | |
10315 | #endif | |
10316 | ||
24841daa NC |
10317 | debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1 |
10318 | + canon_dirlen | |
10319 | + strlen (".debug/") | |
dda8d76d | 10320 | #ifdef EXTRA_DEBUG_ROOT1 |
24841daa | 10321 | + strlen (EXTRA_DEBUG_ROOT1) |
dda8d76d NC |
10322 | #endif |
10323 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa | 10324 | + strlen (EXTRA_DEBUG_ROOT2) |
dda8d76d | 10325 | #endif |
24841daa NC |
10326 | + strlen (separate_filename) |
10327 | + 1); | |
10328 | if (debug_filename == NULL) | |
dda8d76d NC |
10329 | { |
10330 | warn (_("Out of memory")); | |
3391569f | 10331 | free (canon_dir); |
dda8d76d NC |
10332 | return NULL; |
10333 | } | |
10334 | ||
10335 | /* First try in the current directory. */ | |
24841daa NC |
10336 | sprintf (debug_filename, "%s", separate_filename); |
10337 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10338 | goto found; |
10339 | ||
10340 | /* Then try in a subdirectory called .debug. */ | |
24841daa NC |
10341 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10342 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10343 | goto found; |
10344 | ||
10345 | /* Then try in the same directory as the original file. */ | |
24841daa NC |
10346 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10347 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10348 | goto found; |
10349 | ||
10350 | /* And the .debug subdirectory of that directory. */ | |
24841daa NC |
10351 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10352 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10353 | goto found; |
10354 | ||
10355 | #ifdef EXTRA_DEBUG_ROOT1 | |
10356 | /* Try the first extra debug file root. */ | |
24841daa NC |
10357 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10358 | if (check_func (debug_filename, func_data)) | |
dda8d76d | 10359 | goto found; |
39f0547e NC |
10360 | |
10361 | /* Try the first extra debug file root. */ | |
10362 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); | |
10363 | if (check_func (debug_filename, func_data)) | |
10364 | goto found; | |
dda8d76d NC |
10365 | #endif |
10366 | ||
10367 | #ifdef EXTRA_DEBUG_ROOT2 | |
10368 | /* Try the second extra debug file root. */ | |
24841daa NC |
10369 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10370 | if (check_func (debug_filename, func_data)) | |
dda8d76d NC |
10371 | goto found; |
10372 | #endif | |
10373 | ||
24841daa NC |
10374 | /* Then try in the global debug_filename directory. */ |
10375 | strcpy (debug_filename, DEBUGDIR); | |
dda8d76d NC |
10376 | dirlen = strlen (DEBUGDIR) - 1; |
10377 | if (dirlen > 0 && DEBUGDIR[dirlen] != '/') | |
24841daa NC |
10378 | strcat (debug_filename, "/"); |
10379 | strcat (debug_filename, (const char *) separate_filename); | |
dda8d76d | 10380 | |
24841daa | 10381 | if (check_func (debug_filename, func_data)) |
dda8d76d NC |
10382 | goto found; |
10383 | ||
10384 | /* Failed to find the file. */ | |
10385 | warn (_("could not find separate debug file '%s'\n"), separate_filename); | |
24841daa | 10386 | warn (_("tried: %s\n"), debug_filename); |
dda8d76d NC |
10387 | |
10388 | #ifdef EXTRA_DEBUG_ROOT2 | |
24841daa NC |
10389 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename); |
10390 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10391 | #endif |
10392 | ||
10393 | #ifdef EXTRA_DEBUG_ROOT1 | |
39f0547e NC |
10394 | sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename); |
10395 | warn (_("tried: %s\n"), debug_filename); | |
10396 | ||
24841daa NC |
10397 | sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename); |
10398 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10399 | #endif |
10400 | ||
24841daa NC |
10401 | sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename); |
10402 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10403 | |
24841daa NC |
10404 | sprintf (debug_filename, "%s%s", canon_dir, separate_filename); |
10405 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10406 | |
24841daa NC |
10407 | sprintf (debug_filename, ".debug/%s", separate_filename); |
10408 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d | 10409 | |
24841daa NC |
10410 | sprintf (debug_filename, "%s", separate_filename); |
10411 | warn (_("tried: %s\n"), debug_filename); | |
dda8d76d NC |
10412 | |
10413 | free (canon_dir); | |
24841daa | 10414 | free (debug_filename); |
dda8d76d NC |
10415 | return NULL; |
10416 | ||
10417 | found: | |
10418 | free (canon_dir); | |
10419 | ||
24841daa NC |
10420 | void * debug_handle; |
10421 | ||
dda8d76d | 10422 | /* Now open the file.... */ |
24841daa | 10423 | if ((debug_handle = open_debug_file (debug_filename)) == NULL) |
dda8d76d | 10424 | { |
24841daa NC |
10425 | warn (_("failed to open separate debug file: %s\n"), debug_filename); |
10426 | free (debug_filename); | |
dda8d76d NC |
10427 | return FALSE; |
10428 | } | |
10429 | ||
10430 | /* FIXME: We do not check to see if there are any other separate debug info | |
10431 | files that would also match. */ | |
10432 | ||
24841daa NC |
10433 | printf (_("%s: Found separate debug info file: %s\n\n"), main_filename, debug_filename); |
10434 | add_separate_debug_file (debug_filename, debug_handle); | |
dda8d76d | 10435 | |
24841daa | 10436 | /* Do not free debug_filename - it might be referenced inside |
dda8d76d | 10437 | the structure returned by open_debug_file(). */ |
24841daa | 10438 | return debug_handle; |
dda8d76d NC |
10439 | } |
10440 | ||
d85bf2ba NC |
10441 | /* Attempt to load a separate dwarf object file. */ |
10442 | ||
10443 | static void * | |
24841daa | 10444 | load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED) |
d85bf2ba | 10445 | { |
24841daa NC |
10446 | char * separate_filename; |
10447 | void * separate_handle; | |
d85bf2ba NC |
10448 | |
10449 | /* FIXME: Skip adding / if dwo_dir ends in /. */ | |
24841daa NC |
10450 | separate_filename = concat (dir, "/", name, NULL); |
10451 | if (separate_filename == NULL) | |
d85bf2ba NC |
10452 | { |
10453 | warn (_("Out of memory allocating dwo filename\n")); | |
10454 | return NULL; | |
10455 | } | |
10456 | ||
24841daa | 10457 | if ((separate_handle = open_debug_file (separate_filename)) == NULL) |
d85bf2ba | 10458 | { |
24841daa NC |
10459 | warn (_("Unable to load dwo file: %s\n"), separate_filename); |
10460 | free (separate_filename); | |
d85bf2ba NC |
10461 | return NULL; |
10462 | } | |
10463 | ||
10464 | /* FIXME: We should check the dwo_id. */ | |
10465 | ||
24841daa NC |
10466 | printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename); |
10467 | add_separate_debug_file (separate_filename, separate_handle); | |
10468 | /* Note - separate_filename will be freed in free_debug_memory(). */ | |
10469 | return separate_handle; | |
d85bf2ba NC |
10470 | } |
10471 | ||
24841daa NC |
10472 | /* Load the separate debug info file(s) attached to FILE, if any exist. |
10473 | Returns TRUE if any were found, FALSE otherwise. | |
10474 | If TRUE is returned then the linked list starting at first_separate_info | |
10475 | will be populated with open file handles. */ | |
dda8d76d | 10476 | |
24841daa NC |
10477 | bfd_boolean |
10478 | load_separate_debug_files (void * file, const char * filename) | |
dda8d76d | 10479 | { |
8de3a6e2 NC |
10480 | /* Skip this operation if we are not interested in debug links. */ |
10481 | if (! do_follow_links && ! do_debug_links) | |
24841daa | 10482 | return FALSE; |
8de3a6e2 | 10483 | |
24841daa | 10484 | /* See if there are any dwo links. */ |
d85bf2ba NC |
10485 | if (load_debug_section (str, file) |
10486 | && load_debug_section (abbrev, file) | |
10487 | && load_debug_section (info, file)) | |
10488 | { | |
24841daa | 10489 | free_dwo_info (); |
d85bf2ba NC |
10490 | |
10491 | if (process_debug_info (& debug_displays[info].section, file, abbrev, TRUE, FALSE)) | |
10492 | { | |
24841daa NC |
10493 | bfd_boolean introduced = FALSE; |
10494 | dwo_info * dwinfo; | |
10495 | const char * dir = NULL; | |
10496 | const char * id = NULL; | |
10497 | ||
10498 | for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next) | |
d85bf2ba | 10499 | { |
24841daa | 10500 | switch (dwinfo->type) |
d85bf2ba | 10501 | { |
24841daa NC |
10502 | case DWO_NAME: |
10503 | if (do_debug_links) | |
10504 | { | |
10505 | if (! introduced) | |
10506 | { | |
10507 | printf (_("The %s section contains link(s) to dwo file(s):\n\n"), | |
10508 | debug_displays [info].section.uncompressed_name); | |
10509 | introduced = TRUE; | |
10510 | } | |
d85bf2ba | 10511 | |
24841daa NC |
10512 | printf (_(" Name: %s\n"), dwinfo->value); |
10513 | printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>")); | |
10514 | if (id != NULL) | |
10515 | display_data (printf (_(" ID: ")), (unsigned char *) id, 8); | |
10516 | else | |
10517 | printf (_(" ID: <unknown>\n")); | |
10518 | printf ("\n\n"); | |
10519 | } | |
10520 | ||
10521 | if (do_follow_links) | |
10522 | load_dwo_file (filename, dwinfo->value, dir, id); | |
10523 | break; | |
10524 | ||
10525 | case DWO_DIR: | |
10526 | dir = dwinfo->value; | |
10527 | break; | |
10528 | ||
10529 | case DWO_ID: | |
10530 | id = dwinfo->value; | |
10531 | break; | |
10532 | ||
10533 | default: | |
10534 | error (_("Unexpected DWO INFO type")); | |
10535 | break; | |
10536 | } | |
d85bf2ba NC |
10537 | } |
10538 | } | |
10539 | } | |
10540 | ||
dda8d76d | 10541 | if (! do_follow_links) |
8de3a6e2 NC |
10542 | /* The other debug links will be displayed by display_debug_links() |
10543 | so we do not need to do any further processing here. */ | |
24841daa | 10544 | return FALSE; |
dda8d76d NC |
10545 | |
10546 | /* FIXME: We do not check for the presence of both link sections in the same file. */ | |
10547 | /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */ | |
10548 | /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */ | |
d85bf2ba | 10549 | /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */ |
dda8d76d | 10550 | |
dda8d76d NC |
10551 | if (load_debug_section (gnu_debugaltlink, file)) |
10552 | { | |
10553 | Build_id_data * build_id_data; | |
10554 | ||
24841daa NC |
10555 | load_separate_debug_info (filename, |
10556 | & debug_displays[gnu_debugaltlink].section, | |
10557 | parse_gnu_debugaltlink, | |
10558 | check_gnu_debugaltlink, | |
10559 | & build_id_data); | |
dda8d76d NC |
10560 | } |
10561 | ||
10562 | if (load_debug_section (gnu_debuglink, file)) | |
10563 | { | |
10564 | unsigned long crc32; | |
10565 | ||
24841daa NC |
10566 | load_separate_debug_info (filename, |
10567 | & debug_displays[gnu_debuglink].section, | |
10568 | parse_gnu_debuglink, | |
10569 | check_gnu_debuglink, | |
10570 | & crc32); | |
dda8d76d NC |
10571 | } |
10572 | ||
24841daa NC |
10573 | if (first_separate_info != NULL) |
10574 | return TRUE; | |
10575 | ||
dda8d76d | 10576 | do_follow_links = 0; |
24841daa | 10577 | return FALSE; |
dda8d76d NC |
10578 | } |
10579 | ||
19e6b90e L |
10580 | void |
10581 | free_debug_memory (void) | |
10582 | { | |
3f5e193b | 10583 | unsigned int i; |
19e6b90e L |
10584 | |
10585 | free_abbrevs (); | |
10586 | ||
10587 | for (i = 0; i < max; i++) | |
3f5e193b | 10588 | free_debug_section ((enum dwarf_section_display_enum) i); |
19e6b90e | 10589 | |
cc86f28f | 10590 | if (debug_information != NULL) |
19e6b90e | 10591 | { |
cc86f28f | 10592 | if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE) |
19e6b90e | 10593 | { |
cc86f28f | 10594 | for (i = 0; i < num_debug_info_entries; i++) |
19e6b90e | 10595 | { |
cc86f28f NC |
10596 | if (!debug_information [i].max_loc_offsets) |
10597 | { | |
10598 | free (debug_information [i].loc_offsets); | |
10599 | free (debug_information [i].have_frame_base); | |
10600 | } | |
10601 | if (!debug_information [i].max_range_lists) | |
10602 | free (debug_information [i].range_lists); | |
19e6b90e | 10603 | } |
19e6b90e L |
10604 | } |
10605 | free (debug_information); | |
10606 | debug_information = NULL; | |
82b1b41b | 10607 | alloc_num_debug_info_entries = num_debug_info_entries = 0; |
19e6b90e | 10608 | } |
dda8d76d | 10609 | |
24841daa NC |
10610 | separate_info * d; |
10611 | separate_info * next; | |
dda8d76d | 10612 | |
24841daa NC |
10613 | for (d = first_separate_info; d != NULL; d = next) |
10614 | { | |
10615 | close_debug_file (d->handle); | |
10616 | free ((void *) d->filename); | |
10617 | next = d->next; | |
10618 | free ((void *) d); | |
dda8d76d | 10619 | } |
24841daa NC |
10620 | first_separate_info = NULL; |
10621 | ||
10622 | free_dwo_info (); | |
19e6b90e L |
10623 | } |
10624 | ||
4cb93e3b TG |
10625 | void |
10626 | dwarf_select_sections_by_names (const char *names) | |
10627 | { | |
10628 | typedef struct | |
10629 | { | |
10630 | const char * option; | |
10631 | int * variable; | |
f9f0e732 | 10632 | int val; |
4cb93e3b TG |
10633 | } |
10634 | debug_dump_long_opts; | |
10635 | ||
10636 | static const debug_dump_long_opts opts_table [] = | |
10637 | { | |
10638 | /* Please keep this table alpha- sorted. */ | |
10639 | { "Ranges", & do_debug_ranges, 1 }, | |
10640 | { "abbrev", & do_debug_abbrevs, 1 }, | |
657d0d47 | 10641 | { "addr", & do_debug_addr, 1 }, |
4cb93e3b | 10642 | { "aranges", & do_debug_aranges, 1 }, |
657d0d47 CC |
10643 | { "cu_index", & do_debug_cu_index, 1 }, |
10644 | { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED }, | |
dda8d76d | 10645 | { "follow-links", & do_follow_links, 1 }, |
4cb93e3b TG |
10646 | { "frames", & do_debug_frames, 1 }, |
10647 | { "frames-interp", & do_debug_frames_interp, 1 }, | |
657d0d47 CC |
10648 | /* The special .gdb_index section. */ |
10649 | { "gdb_index", & do_gdb_index, 1 }, | |
4cb93e3b TG |
10650 | { "info", & do_debug_info, 1 }, |
10651 | { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */ | |
dda8d76d | 10652 | { "links", & do_debug_links, 1 }, |
4cb93e3b TG |
10653 | { "loc", & do_debug_loc, 1 }, |
10654 | { "macro", & do_debug_macinfo, 1 }, | |
10655 | { "pubnames", & do_debug_pubnames, 1 }, | |
357da287 | 10656 | { "pubtypes", & do_debug_pubtypes, 1 }, |
222c2bf0 | 10657 | /* This entry is for compatibility |
4cb93e3b TG |
10658 | with earlier versions of readelf. */ |
10659 | { "ranges", & do_debug_aranges, 1 }, | |
657d0d47 | 10660 | { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, |
4cb93e3b | 10661 | { "str", & do_debug_str, 1 }, |
6f875884 TG |
10662 | /* These trace_* sections are used by Itanium VMS. */ |
10663 | { "trace_abbrev", & do_trace_abbrevs, 1 }, | |
10664 | { "trace_aranges", & do_trace_aranges, 1 }, | |
10665 | { "trace_info", & do_trace_info, 1 }, | |
4cb93e3b TG |
10666 | { NULL, NULL, 0 } |
10667 | }; | |
10668 | ||
10669 | const char *p; | |
467c65bc | 10670 | |
4cb93e3b TG |
10671 | p = names; |
10672 | while (*p) | |
10673 | { | |
10674 | const debug_dump_long_opts * entry; | |
467c65bc | 10675 | |
4cb93e3b TG |
10676 | for (entry = opts_table; entry->option; entry++) |
10677 | { | |
10678 | size_t len = strlen (entry->option); | |
467c65bc | 10679 | |
4cb93e3b TG |
10680 | if (strncmp (p, entry->option, len) == 0 |
10681 | && (p[len] == ',' || p[len] == '\0')) | |
10682 | { | |
10683 | * entry->variable |= entry->val; | |
467c65bc | 10684 | |
4cb93e3b TG |
10685 | /* The --debug-dump=frames-interp option also |
10686 | enables the --debug-dump=frames option. */ | |
10687 | if (do_debug_frames_interp) | |
10688 | do_debug_frames = 1; | |
10689 | ||
10690 | p += len; | |
10691 | break; | |
10692 | } | |
10693 | } | |
467c65bc | 10694 | |
4cb93e3b TG |
10695 | if (entry->option == NULL) |
10696 | { | |
10697 | warn (_("Unrecognized debug option '%s'\n"), p); | |
10698 | p = strchr (p, ','); | |
10699 | if (p == NULL) | |
10700 | break; | |
10701 | } | |
467c65bc | 10702 | |
4cb93e3b TG |
10703 | if (*p == ',') |
10704 | p++; | |
10705 | } | |
10706 | } | |
10707 | ||
10708 | void | |
10709 | dwarf_select_sections_by_letters (const char *letters) | |
10710 | { | |
91d6fa6a | 10711 | unsigned int lindex = 0; |
4cb93e3b | 10712 | |
91d6fa6a NC |
10713 | while (letters[lindex]) |
10714 | switch (letters[lindex++]) | |
4cb93e3b | 10715 | { |
dda8d76d NC |
10716 | case 'A': do_debug_addr = 1; break; |
10717 | case 'a': do_debug_abbrevs = 1; break; | |
10718 | case 'c': do_debug_cu_index = 1; break; | |
10719 | case 'F': do_debug_frames_interp = 1; /* Fall through. */ | |
10720 | case 'f': do_debug_frames = 1; break; | |
10721 | case 'g': do_gdb_index = 1; break; | |
10722 | case 'i': do_debug_info = 1; break; | |
10723 | case 'K': do_follow_links = 1; break; | |
10724 | case 'k': do_debug_links = 1; break; | |
10725 | case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break; | |
10726 | case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break; | |
10727 | case 'm': do_debug_macinfo = 1; break; | |
10728 | case 'o': do_debug_loc = 1; break; | |
10729 | case 'p': do_debug_pubnames = 1; break; | |
10730 | case 'R': do_debug_ranges = 1; break; | |
10731 | case 'r': do_debug_aranges = 1; break; | |
10732 | case 's': do_debug_str = 1; break; | |
10733 | case 'T': do_trace_aranges = 1; break; | |
10734 | case 't': do_debug_pubtypes = 1; break; | |
10735 | case 'U': do_trace_info = 1; break; | |
10736 | case 'u': do_trace_abbrevs = 1; break; | |
467c65bc | 10737 | |
4cb93e3b | 10738 | default: |
7cc78d07 | 10739 | warn (_("Unrecognized debug option '%s'\n"), letters); |
4cb93e3b TG |
10740 | break; |
10741 | } | |
10742 | } | |
10743 | ||
10744 | void | |
10745 | dwarf_select_sections_all (void) | |
10746 | { | |
10747 | do_debug_info = 1; | |
10748 | do_debug_abbrevs = 1; | |
10749 | do_debug_lines = FLAG_DEBUG_LINES_RAW; | |
10750 | do_debug_pubnames = 1; | |
f9f0e732 | 10751 | do_debug_pubtypes = 1; |
4cb93e3b TG |
10752 | do_debug_aranges = 1; |
10753 | do_debug_ranges = 1; | |
10754 | do_debug_frames = 1; | |
10755 | do_debug_macinfo = 1; | |
10756 | do_debug_str = 1; | |
10757 | do_debug_loc = 1; | |
5bbdf3d5 | 10758 | do_gdb_index = 1; |
6f875884 TG |
10759 | do_trace_info = 1; |
10760 | do_trace_abbrevs = 1; | |
10761 | do_trace_aranges = 1; | |
657d0d47 CC |
10762 | do_debug_addr = 1; |
10763 | do_debug_cu_index = 1; | |
dda8d76d NC |
10764 | do_follow_links = 1; |
10765 | do_debug_links = 1; | |
4cb93e3b TG |
10766 | } |
10767 | ||
dda8d76d NC |
10768 | #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL |
10769 | #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL | |
10770 | ||
10771 | /* N.B. The order here must match the order in section_display_enum. */ | |
10772 | ||
19e6b90e L |
10773 | struct dwarf_section_display debug_displays[] = |
10774 | { | |
dda8d76d NC |
10775 | { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, |
10776 | { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, TRUE }, | |
10777 | { { ".debug_frame", ".zdebug_frame", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
10778 | { { ".debug_info", ".zdebug_info", ABBREV (abbrev)}, display_debug_info, &do_debug_info, TRUE }, | |
10779 | { { ".debug_line", ".zdebug_line", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
10780 | { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, FALSE }, | |
10781 | { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, FALSE }, | |
10782 | { { ".eh_frame", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, TRUE }, | |
10783 | { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
10784 | { { ".debug_macro", ".zdebug_macro", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
10785 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
10786 | { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
10787 | { { ".debug_loc", ".zdebug_loc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10788 | { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10789 | { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, FALSE }, | |
10790 | { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE }, | |
10791 | { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
10792 | { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, TRUE }, | |
10793 | { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10794 | { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10795 | { { ".debug_types", ".zdebug_types", ABBREV (abbrev) }, display_debug_types, &do_debug_info, TRUE }, | |
10796 | { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS }, display_debug_not_supported, NULL, FALSE }, | |
10797 | { { ".gdb_index", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, FALSE }, | |
10798 | { { ".debug_names", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, FALSE }, | |
10799 | { { ".trace_info", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, TRUE }, | |
10800 | { { ".trace_abbrev", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, FALSE }, | |
10801 | { { ".trace_aranges", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, FALSE }, | |
10802 | { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, TRUE }, | |
10803 | { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, FALSE }, | |
10804 | { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, TRUE }, | |
10805 | { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS }, display_debug_lines, &do_debug_lines, TRUE }, | |
10806 | { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS }, display_debug_loc, &do_debug_loc, TRUE }, | |
10807 | { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, TRUE }, | |
10808 | { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, FALSE }, | |
10809 | { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS }, display_debug_str, &do_debug_str, TRUE }, | |
10810 | { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, | |
10811 | { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS }, display_debug_str_offsets, NULL, FALSE }, | |
10812 | { { ".debug_addr", ".zdebug_addr", NO_ABBREVS }, display_debug_addr, &do_debug_addr, TRUE }, | |
10813 | { { ".debug_cu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
10814 | { { ".debug_tu_index", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, FALSE }, | |
10815 | { { ".gnu_debuglink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
10816 | { { ".gnu_debugaltlink", "", NO_ABBREVS }, display_debug_links, &do_debug_links, FALSE }, | |
10817 | /* Separate debug info files can containt their own .debug_str section, | |
10818 | and this might be in *addition* to a .debug_str section already present | |
10819 | in the main file. Hence we need to have two entries for .debug_str. */ | |
10820 | { { ".debug_str", ".zdebug_str", NO_ABBREVS }, display_debug_str, &do_debug_str, FALSE }, | |
19e6b90e | 10821 | }; |
b451e98a JK |
10822 | |
10823 | /* A static assertion. */ | |
10824 | extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1]; |